aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBertrand Delacretaz <bdelacretaz@apache.org>2006-10-12 10:08:01 +0000
committerBertrand Delacretaz <bdelacretaz@apache.org>2006-10-12 10:08:01 +0000
commitcf184e6c725a4318bd5468991ca9f3786ebda359 (patch)
treed0c9efe5406e3a6d2db5add91dd08b29a54c3185 /src
parentd7f3c65f79be3ad7fc856562bba89a78873543df (diff)
downloadxmlgraphics-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')
-rw-r--r--src/java/org/apache/fop/fonts/FontReader.java4
-rw-r--r--src/java/org/apache/fop/fonts/apps/TTFReader.java42
2 files changed, 45 insertions, 1 deletions
diff --git a/src/java/org/apache/fop/fonts/FontReader.java b/src/java/org/apache/fop/fonts/FontReader.java
index 0d04d6c71..7918398ca 100644
--- a/src/java/org/apache/fop/fonts/FontReader.java
+++ b/src/java/org/apache/fop/fonts/FontReader.java
@@ -35,6 +35,7 @@ import org.xml.sax.helpers.DefaultHandler;
//FOP
import org.apache.fop.apps.FOPException;
+import org.apache.fop.fonts.apps.TTFReader;
import org.xml.sax.InputSource;
/**
@@ -163,11 +164,13 @@ public class FontReader extends DefaultHandler {
multiFont = new MultiByteFont();
returnFont = multiFont;
isCID = true;
+ TTFReader.checkMetricsVersion(attributes);
} else if ("TRUETYPE".equals(attributes.getValue("type"))) {
singleFont = new SingleByteFont();
singleFont.setFontType(FontType.TRUETYPE);
returnFont = singleFont;
isCID = false;
+ TTFReader.checkMetricsVersion(attributes);
} else {
singleFont = new SingleByteFont();
singleFont.setFontType(FontType.TYPE1);
@@ -295,7 +298,6 @@ public class FontReader extends DefaultHandler {
public void characters(char[] ch, int start, int length) {
text.append(ch, start, length);
}
-
}
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."
+ );
+ }
+ }
}