//FOP
import org.apache.fop.apps.FOPException;
+import org.apache.fop.fonts.apps.TTFReader;
import org.xml.sax.InputSource;
/**
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);
public void characters(char[] ch, int start, int length) {
text.append(ch, start, length);
}
-
}
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
*/
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.
*/
}
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 {
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."
+ );
+ }
+ }
}