From f183113d083c5e0306cc0e96f28445258419ceb5 Mon Sep 17 00:00:00 2001 From: "Andreas L. Delmelle" Date: Tue, 6 Feb 2007 20:35:49 +0000 Subject: [PATCH] Fix: override PropertyMaker.make() to properly parse font-family names containing spaces. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@504280 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/fo/properties/FontFamilyProperty.java | 50 +++++++++++++++++++ status.xml | 3 ++ test/fotree/testcases/font-family-test.fo | 49 ++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 test/fotree/testcases/font-family-test.fo diff --git a/src/java/org/apache/fop/fo/properties/FontFamilyProperty.java b/src/java/org/apache/fop/fo/properties/FontFamilyProperty.java index 48082e1d8..84000233c 100644 --- a/src/java/org/apache/fop/fo/properties/FontFamilyProperty.java +++ b/src/java/org/apache/fop/fo/properties/FontFamilyProperty.java @@ -21,6 +21,7 @@ package org.apache.fop.fo.properties; import org.apache.fop.fo.FObj; import org.apache.fop.fo.PropertyList; +import org.apache.fop.fo.expr.PropertyException; /** * Property class for the font-family property. @@ -39,6 +40,55 @@ public class FontFamilyProperty extends ListProperty { super(propId); } + /** + * @see org.apache.fop.fo.properties.PropertyMaker#make( + * org.apache.fop.fo.PropertyList, + * java.lang.String, + * org.apache.fop.fo.FObj) + */ + public Property make(PropertyList propertyList, String value, FObj fo) throws PropertyException { + ListProperty prop = new ListProperty(); + String tmpVal; + int startIndex = 0; + int commaIndex = value.indexOf(','); + int quoteIndex; + int aposIndex; + char qChar; + boolean parsed = false; + while (!parsed) { + if (commaIndex == -1) { + tmpVal = value.substring(startIndex).trim(); + parsed = true; + } else { + tmpVal = value.substring(startIndex, commaIndex).trim(); + startIndex = commaIndex + 1; + commaIndex = value.indexOf(',', startIndex); + } + aposIndex = tmpVal.indexOf('\''); + quoteIndex = tmpVal.indexOf('\"'); + if (aposIndex != -1 || quoteIndex != -1) { + qChar = (aposIndex == -1) ? '\"' : '\''; + if (tmpVal.lastIndexOf(qChar) != tmpVal.length() - 1) { + Property.log.warn("Skipping malformed value for font-family: " + + tmpVal + " in \"" + value + "\"."); + tmpVal = ""; + } else { + tmpVal = tmpVal.substring(1, tmpVal.length() - 1); + } + } + if (!"".equals(tmpVal)) { + int dblSpaceIndex = tmpVal.indexOf(" "); + while (dblSpaceIndex != -1) { + tmpVal = tmpVal.substring(0, dblSpaceIndex) + + tmpVal.substring(dblSpaceIndex + 1); + dblSpaceIndex = tmpVal.indexOf(" "); + } + prop.addProperty(new StringProperty(tmpVal)); + } + } + return prop; + } + /** * @see PropertyMaker#convertProperty */ diff --git a/status.xml b/status.xml index 49750b3d2..b1ef07f1e 100644 --- a/status.xml +++ b/status.xml @@ -28,6 +28,9 @@ + + Fix for properly parsing font-family names containing spaces. + Fix for NPE with PNG images for RTF output. diff --git a/test/fotree/testcases/font-family-test.fo b/test/fotree/testcases/font-family-test.fo new file mode 100644 index 000000000..623a29258 --- /dev/null +++ b/test/fotree/testcases/font-family-test.fo @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + Test font-family parsing + + + + Test font-family parsing + + + + Test font-family parsing + + + + Test font-family parsing + + + + Test malformed font-family parsing + + + + -- 2.39.5