Anonymous avatar Anonymous committed 83f7563 Draft

Refactor on PDFPage2SVGConverter, add fill/stroke color for text. remove unneed operations.

Comments (0)

Files changed (3)

-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
-	<name>pdf2svg</name>
-	<comment></comment>
-	<projects>
-	</projects>
-	<buildSpec>
-		<buildCommand>
-			<name>org.eclipse.jdt.core.javabuilder</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
-		<buildCommand>
-			<name>org.eclipse.m2e.core.maven2Builder</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
-	</buildSpec>
-	<natures>
-		<nature>org.eclipse.m2e.core.maven2Nature</nature>
-		<nature>org.eclipse.jdt.core.javanature</nature>
-	</natures>
-</projectDescription>
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>pdf2svg-isaac</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.wst.common.project.facet.core.builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.m2e.core.maven2Builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.maven.ide.eclipse.maven2Builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.maven.ide.eclipse.maven2Nature</nature>
+		<nature>org.eclipse.m2e.core.maven2Nature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
+	</natures>
+</projectDescription>

src/main/java/org/xmlcml/pdf2svg/PDF2SVGConverter.java

 	Double pageWidth = _DEFAULT_PAGE_WIDTH;
 	private PDFPage2SVGConverter page2svgConverter;
 	private SVGSVG currentSVGPage;
-	private boolean writeFile = true;
+	public boolean writeFile = true;
 	private boolean writeInfoFiles = false;
 	private boolean exitOnError = false;
 	

src/main/java/org/xmlcml/pdf2svg/PDFPage2SVGConverter.java

 	private BasicStroke basicStroke;
 	private SVGSVG svg;
 //	private Composite composite;
-	private Paint paint;
+//	private Paint paint;
 	private PDGraphicsState graphicsState;
 	private Matrix textPos;
 	private PDFont pdFont;
 
 	private String fontFamilyName;
 	private String fontName;
-	private Double currentFontSize;
-	private String currentFontStyle;
+//	private Double currentFontSize;
+//	private String currentFontStyle;
 //	private String currentFontWeight;
 	
 	private int nPlaces = 3;
 	 * @param page
 	 * @param converter
 	 */
-	SVGSVG convertPageToSVG(PDPage page, PDF2SVGConverter converter) {
+	public SVGSVG convertPageToSVG(PDPage page, PDF2SVGConverter converter) {
 		pageSize = null;	// reset size for each page
 		this.pdf2svgConverter = converter;
 		this.amiFontManager = converter.getAmiFontManager();
 
 		int charCode = getCharCodeAndSetEncodingAndCharname(textPosition);
 
-		createGraphicsStateAndPaintAndComposite();
+		SVGText svgText = new SVGText();
+		
+		createGraphicsStateAndPaintAndComposite(svgText);
 		getAndFormatClipPath();
 
 		if (pdf2svgConverter.useXMLLogger) {
 			}
 		}
 
-		SVGText svgText = new SVGText();
-
 		createAndReOrientateTextPosition(textPosition, svgText);
 
 		svgText.setFontWeight(amiFont.getFontWeight());
 
 		if (amiFont.isSymbol() || amiFont.getDictionaryEncoding() != null ||
 				(fontFamily != null && fontFamily.getCodePointSet() != null)) {
-			convertNonUnicodeCharacterEncodings();
-			annotateContent(svgText, textContent, charCode, charname, charCode, encoding);
+			//convertNonUnicodeCharacterEncodings();
+			//annotateContent(svgText, textContent, charCode, charname, charCode, encoding);
 		}
 
 		LOG.trace("Fn: "+fontName+"; Ff: "+fontFamilyName+"; "+textContent+"; "+charCode+"; "+charname);
 	}
 
 	private void addAttributesToSVGText(float width, SVGText svgText) {
-//		svgText.setClipPath(clipString);
+		//svgText.setClipPath(clipString);
 		setClipPath(svgText, clipString, (Integer) integerByClipStringMap.get(clipString));
-		svgText.setFontSize(currentFontSize);
-		final String stroke = getCSSColor((Color) paint);
-		svgText.setStroke(stroke);
-		svgText.setFontStyle(currentFontStyle);
+		//svgText.setFontSize(currentFontSize);
+		//final String stroke = getCSSColor((Color) paint);
+		//svgText.setStroke(stroke);
+		//svgText.setFontStyle(currentFontStyle);
 		svgText.setFontFamily(fontFamilyName);
 		setFontName(svgText, fontName);
 		setCharacterWidth(svgText, width);
 			Transform2 t2a = Transform2.getRotationAboutPoint(angle, svgText.getXY());
 			svgText.setTransform(t2a);
 		}
-		currentFontSize = scale;
-		return currentFontSize;
+		svgText.setFontSize(scale);
+		return scale;
 	}
 
 	/** changes coordinates because AWT and SVG use top-left origin while PDF uses bottom left
 		svgText.setXY(currentXY);
 	}
 
-	private void createGraphicsStateAndPaintAndComposite() {
+	private void createGraphicsStateAndPaintAndComposite(SVGText svgText) {
+		Paint paint;
 		try {
 			graphicsState = getGraphicsState();
 			ensurePageSize();
 				if (paint == null) {
 					paint = graphicsState.getNonStrokingColor().getPaint(pageSize.height);
 				}
+				svgText.setFill(getCSSColor(paint));
 				break;
 			case PDTextState.RENDERING_MODE_STROKE_TEXT:
 				// composite = graphicsState.getStrokeJavaComposite();
 				if (paint == null) {
 					paint = graphicsState.getStrokingColor().getPaint(pageSize.height);
 				}
+				Double lineWidth = graphicsState.getLineWidth();
+				svgText.setStroke(getCSSColor(paint));
+				svgText.setStrokeWidth(lineWidth);
 				break;
 			case PDTextState.RENDERING_MODE_NEITHER_FILL_NOR_STROKE_TEXT:
 				// basic support for text rendering mode "invisible"
 						+ PDTextState.RENDERING_MODE_FILL_TEXT + " instead");
 				// composite = graphicsState.getNonStrokeJavaComposite();
 				paint = graphicsState.getNonStrokingColor().getJavaColor();
+				svgText.setFill(getCSSColor(paint));
 			}
 		} catch (IOException e) {
 			throw new RuntimeException("graphics state error???", e);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.