Hi all,

As I mentioned in another email, I am trying to constrain FOP to use only 
local fonts (i.e. ones described in fop.cfg). For SVGs, I have a workaround:
- Generate fonts in SVG format using ttf2svg utility from Batik;
- Use an XSL stylesheet to embed all the fonts used by an SVG image into the 
image itself;
- Use such "preprocessed" SVG image as the input to FOP.

This does not work well with JEuclid, though. When JEuclid generates SVG from 
MathML, it performs font rendering - that is, replaces characters by actual 
paths. And again, it uses system fonts, not the fonts available in FOP - even 
if running as FOP plugin.

To work around this issue for MathML, I am currently switching from JEuclid to 
pMML2SVG (http://pmml2svg.sourceforge.net). It generates SVGs with text 
characters, not paths. But in order to do so, it needs font metrics. 
Unfortunately, font metrics produced by stock FOP TTFReader are not sufficient 
- this stylesheet also needs bounding box for each glyph. To obtain these, 
pMML2SVG currently packages an augmented TTFReader Java sources which are to 
be compiled and used in lieu of the stock one.

Given that the patch is very small and as far as I can tell, compatible with 
current users of font metrics (it just adds 4 attributes to glyph 
description), is it possible to integrate this support into stock FOP?

Patch from pMML2SVG, slightly modified to apply to FOP 1.1 sources, attached.

Regards,
Alexey.
diff -urpN fop-1.1/src/java/org/apache/fop/fonts/apps/TTFReader.java fop-1.1-modified/src/java/org/apache/fop/fonts/apps/TTFReader.java
--- fop-1.1/src/java/org/apache/fop/fonts/apps/TTFReader.java	2012-10-16 22:47:36.000000000 -0700
+++ fop-1.1-modified/src/java/org/apache/fop/fonts/apps/TTFReader.java	2012-12-27 11:45:33.775793336 -0800
@@ -401,6 +401,12 @@ public class TTFReader extends AbstractF
         for (int i = 0; i < wx.length; i++) {
             Element wxel = doc.createElement("wx");
             wxel.setAttribute("w", String.valueOf(wx[i]));
+            // Add bounding box
+            int[] bbox = ttf.getBBox(i);
+            wxel.setAttribute("xMin", String.valueOf(bbox[0]));
+            wxel.setAttribute("yMin", String.valueOf(bbox[1]));
+            wxel.setAttribute("xMax", String.valueOf(bbox[2]));
+            wxel.setAttribute("yMax", String.valueOf(bbox[3]));
             el.appendChild(wxel);
         }
     }
diff -urpN fop-1.1/src/java/org/apache/fop/fonts/truetype/TTFFile.java fop-1.1-modified/src/java/org/apache/fop/fonts/truetype/TTFFile.java
--- fop-1.1/src/java/org/apache/fop/fonts/truetype/TTFFile.java	2012-10-16 22:47:36.000000000 -0700
+++ fop-1.1-modified/src/java/org/apache/fop/fonts/truetype/TTFFile.java	2012-12-27 11:48:51.371903307 -0800
@@ -978,6 +978,20 @@ public class TTFFile {
     }
 
     /**
+     * Returns an array of (xMin,yMin,xMax,yMax) for a glyph.
+     * @return int[] Array defining bounding box.
+     */
+    public int[] getBBox(int id) {
+    	int[] bbox = new int[4];
+    	
+    	for (int i = 0; i < 4; i++) {
+    		bbox[i] = (int)convertTTFUnit2PDFUnit(mtxTab[id].getBoundingBox()[i]);
+    	}
+    	
+    	return bbox;
+    }
+
+    /**
      * Returns the width of a given character.
      * @param idx Index of the character
      * @return int Standard width

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscr...@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-h...@xmlgraphics.apache.org

Reply via email to