diff options
author | Bertrand Delacretaz <bdelacretaz@apache.org> | 2006-10-12 10:08:01 +0000 |
---|---|---|
committer | Bertrand Delacretaz <bdelacretaz@apache.org> | 2006-10-12 10:08:01 +0000 |
commit | cf184e6c725a4318bd5468991ca9f3786ebda359 (patch) | |
tree | d0c9efe5406e3a6d2db5add91dd08b29a54c3185 /src/java/org/apache/fop/fonts/apps | |
parent | d7f3c65f79be3ad7fc856562bba89a78873543df (diff) | |
download | xmlgraphics-fop-cf184e6c725a4318bd5468991ca9f3786ebda359.tar.gz xmlgraphics-fop-cf184e6c725a4318bd5468991ca9f3786ebda359.zip |
Bugzilla 40739, metrics-version attribute added to TrueType XML metrics files.
Checked when reloading the file to detect incompatible file versions.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@463180 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/fonts/apps')
-rw-r--r-- | src/java/org/apache/fop/fonts/apps/TTFReader.java | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/java/org/apache/fop/fonts/apps/TTFReader.java b/src/java/org/apache/fop/fonts/apps/TTFReader.java index fe7e01585..21c7c9a37 100644 --- a/src/java/org/apache/fop/fonts/apps/TTFReader.java +++ b/src/java/org/apache/fop/fonts/apps/TTFReader.java @@ -33,6 +33,8 @@ import org.apache.fop.fonts.truetype.TTFFile; import org.apache.fop.util.CommandLineLogger; import org.w3c.dom.Document; import org.w3c.dom.Element; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; /** * A tool which reads TTF files and generates @@ -40,6 +42,10 @@ import org.w3c.dom.Element; */ public class TTFReader extends AbstractFontReader { + /** Used to detect incompatible versions of the generated XML files */ + public static final String METRICS_VERSION_ATTR = "metrics-version"; + public static final int METRICS_VERSION = 2; + /** * Main constructor. */ @@ -232,6 +238,7 @@ public class TTFReader extends AbstractFontReader { } Element root = doc.createElement("font-metrics"); doc.appendChild(root); + root.setAttribute(METRICS_VERSION_ATTR,String.valueOf(METRICS_VERSION)); if (isCid) { root.setAttribute("type", "TYPE0"); } else { @@ -452,6 +459,41 @@ public class TTFReader extends AbstractFontReader { return stb.toString(); } + + /** Bugzilla 40739, check that attr has a metrics-version attribute + * compatible with ours. + * @param attr attributes read from the root element of a metrics XML file + * @throws SAXException if incompatible + */ + public static void checkMetricsVersion(Attributes attr) throws SAXException { + String err = null; + final String str = attr.getValue(METRICS_VERSION_ATTR); + if(str==null) { + err = "Missing " + METRICS_VERSION_ATTR + " attribute"; + } else { + int version = 0; + try { + version = Integer.parseInt(str); + if(version < METRICS_VERSION) { + err = "Incompatible " + METRICS_VERSION_ATTR + + " value (" + version + ", should be " + METRICS_VERSION + + ")" + ; + } + } catch(NumberFormatException e) { + err = "Invalid " + METRICS_VERSION_ATTR + + " attribute value (" + str + ")"; + } + } + + if(err!=null) { + throw new SAXException( + err + + " - please regenerate the font metrics file with " + + "a more recent version of FOP." + ); + } + } } |