You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by bd...@apache.org on 2006/10/12 12:08:03 UTC
svn commit: r463180 - in
/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts: FontReader.java
apps/TTFReader.java
Author: bdelacretaz
Date: Thu Oct 12 03:08:01 2006
New Revision: 463180
URL: http://svn.apache.org/viewvc?view=rev&rev=463180
Log:
Bugzilla 40739, metrics-version attribute added to TrueType XML metrics files.
Checked when reloading the file to detect incompatible file versions.
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontReader.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/apps/TTFReader.java
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontReader.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontReader.java?view=diff&rev=463180&r1=463179&r2=463180
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontReader.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontReader.java Thu Oct 12 03:08:01 2006
@@ -35,6 +35,7 @@
//FOP
import org.apache.fop.apps.FOPException;
+import org.apache.fop.fonts.apps.TTFReader;
import org.xml.sax.InputSource;
/**
@@ -163,11 +164,13 @@
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 void characters(char[] ch, int start, int length) {
text.append(ch, start, length);
}
-
}
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/apps/TTFReader.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/apps/TTFReader.java?view=diff&rev=463180&r1=463179&r2=463180
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/apps/TTFReader.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/apps/TTFReader.java Thu Oct 12 03:08:01 2006
@@ -33,6 +33,8 @@
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 @@
*/
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 @@
}
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 {
@@ -451,6 +458,41 @@
}
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."
+ );
+ }
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org