Commits

Anonymous committed b1997e4 Draft

fixed unusual fonts

Comments (0)

Files changed (1)

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

 import org.apache.pdfbox.pdmodel.text.PDTextState;
 import org.apache.pdfbox.util.Matrix;
 import org.apache.pdfbox.util.TextPosition;
+import org.xmlcml.cml.base.CMLConstants;
 import org.xmlcml.euclid.Angle;
 import org.xmlcml.euclid.Real;
 import org.xmlcml.euclid.Real2;
 			currentSvgText.setStroke(null);
 			currentSvgText.setFontWeight((FontWeight)null);
 			currentSvgText.setFontStyle((FontStyle)null);
+			normalizeFontFamilyNameStyleWeight();
 			try {
 				currentSvgText.setText(text.getCharacter());
 			} catch (RuntimeException e) {
-				char cc = text.getCharacter().charAt(0);
-				if (cc > 0 && cc < 31) {
-					currentSvgText.setText(BADCHAR_S+(int)cc+BADCHAR_E);
-				} else {
-					LOG.error("bad char: "+(int)cc);
-				}
+				tryToConvertStrangeCharactersOrFonts(text);
 			}
-
-			normalizeFontFamilyNameStyleWeight();
 			createGraphicsStateAndPaintAndComposite();
 			createAndReOrientateTextPosition(text, currentSvgText);
 			
 		}
 	}
 
+	private void tryToConvertStrangeCharactersOrFonts(TextPosition text) {
+		char cc = text.getCharacter().charAt(0);
+		if (cc > 0 && cc < 31) {
+			String s = interpretCharacter(currentFontFamily, cc);
+			if (s == null) {
+				s = BADCHAR_S+(int)cc+BADCHAR_E;
+			}
+			currentSvgText.setText(s);
+		} else {
+			LOG.error("bad char: "+(int)cc);
+		}
+	}
+
+	private String interpretCharacter(String fontFamily, char cc) {
+		String s = null;
+		if ("MathematicalPi-One".equals(fontFamily)) {
+			if (cc == 1) {
+				s = CMLConstants.S_PLUS;
+			}
+		} else {
+			System.out.println("unknown font for strange code points "+fontFamily);
+		}
+		return s;
+	}
+
 	private void createNewGIfCurrentFontDescriptorChanged() {
 		String formatFont = fmtFont(font);
 		if (hasChanged(currentFormatFont, formatFont)) {
 	public void resetSVG() {
 		this.svg = new SVGSVG();
 		svg.setStroke("none");
-//		svg.setFill("none");
 		svg.setStrokeWidth(0.0);
 		addNewSVGG();
 	}
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.