From bd3680a1e25d8c1a916fa9f58c5ab8d125bd6797 Mon Sep 17 00:00:00 2001 From: Chris Bowditch Date: Mon, 15 Aug 2005 13:23:27 +0000 Subject: [PATCH] ref to bugzilla 36180 Submitted by: Manuel Mall git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@232810 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/fonts/FontInfo.java | 61 ++++++++- .../apache/fop/render/xml/XMLRenderer.java | 19 ++- test/layoutengine/testcases/font-family.xml | 51 ++++++++ test/layoutengine/testcases/font-style.xml | 79 ++++++++++++ test/layoutengine/testcases/font-weight.xml | 121 ++++++++++++++++++ 5 files changed, 319 insertions(+), 12 deletions(-) create mode 100644 test/layoutengine/testcases/font-family.xml create mode 100644 test/layoutengine/testcases/font-style.xml create mode 100644 test/layoutengine/testcases/font-weight.xml diff --git a/src/java/org/apache/fop/fonts/FontInfo.java b/src/java/org/apache/fop/fonts/FontInfo.java index 29c49cd05..7b554f1c4 100644 --- a/src/java/org/apache/fop/fonts/FontInfo.java +++ b/src/java/org/apache/fop/fonts/FontInfo.java @@ -18,9 +18,13 @@ package org.apache.fop.fonts; -// Java +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; import java.util.Map; + /** * The FontInfo for the layout and rendering of a fo document. * This stores the list of available fonts that are setup by @@ -226,6 +230,61 @@ public class FontInfo { usedFonts.put(fontName, fonts.get(fontName)); return (FontMetrics)fonts.get(fontName); } + + /** + * Returns the first triplet matching the given font name. + * As there may be multiple triplets matching the font name + * the result set is sorted first to guarantee consistent results. + * @param fontName The font name we are looking for + * @return The first triplet for the given font name + */ + private String getTripletFor(String fontName) { + List foundTriplets = new ArrayList(); + for (Iterator iter = triplets.entrySet().iterator(); iter.hasNext(); ) { + Map.Entry tripletEntry = (Map.Entry) iter.next(); + if (fontName.equals(((String)tripletEntry.getValue()))) { + foundTriplets.add(tripletEntry.getKey()); + } + } + if (foundTriplets.size() > 0) { + Collections.sort(foundTriplets); + return (String)foundTriplets.get(0); + } + return null; + } + + /** + * Returns the font style for a particular font. + * There may be multiple font styles matching this font. Only the first + * found is returned. Searching is done on a sorted list to guarantee consistent + * results. + * @param fontName internal key + * @return font style + */ + public String getFontStyleFor(String fontName) { + String triplet = getTripletFor(fontName); + if (triplet != null) { + return triplet.substring(triplet.indexOf(',') + 1, triplet.lastIndexOf(',')); + } + return ""; + } + + /** + * Returns the font weight for a particular font. + * There may be multiple font weights matching this font. Only the first + * found is returned. Searching is done on a sorted list to guarantee consistent + * results. + * @param fontName internal key + * @return font weight + */ + public String getFontWeightFor(String fontName) { + String triplet = getTripletFor(fontName); + if (triplet != null) { + return triplet.substring(triplet.lastIndexOf(',') + 1); + } + return ""; + } + } diff --git a/src/java/org/apache/fop/render/xml/XMLRenderer.java b/src/java/org/apache/fop/render/xml/XMLRenderer.java index 48b1b6ec7..25ae777fb 100644 --- a/src/java/org/apache/fop/render/xml/XMLRenderer.java +++ b/src/java/org/apache/fop/render/xml/XMLRenderer.java @@ -37,7 +37,7 @@ import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; // FOP -import org.apache.fop.render.AbstractRenderer; +import org.apache.fop.render.PrintRenderer; import org.apache.fop.render.RendererContext; import org.apache.fop.render.XMLHandler; import org.apache.fop.apps.FOUserAgent; @@ -68,6 +68,7 @@ import org.apache.fop.area.inline.Viewport; import org.apache.fop.area.inline.TextArea; import org.apache.fop.fonts.FontSetup; import org.apache.fop.fonts.FontInfo; +import org.apache.fop.fonts.FontMetrics; /** * Renderer that renders areas to XML for debugging purposes. @@ -76,7 +77,7 @@ import org.apache.fop.fonts.FontInfo; * The output can be used to build a new area tree (@see AreaTreeBuilder) * which can be rendered to any renderer. */ -public class XMLRenderer extends AbstractRenderer { +public class XMLRenderer extends PrintRenderer { /** XML MIME type */ public static final String XML_MIME_TYPE = "application/x-fop-areatree"; @@ -130,15 +131,6 @@ public class XMLRenderer extends AbstractRenderer { this.handler = handler; } - /** - * set up the font info - * - * @param fontInfo the font info object to set up - */ - public void setupFontInfo(FontInfo fontInfo) { - FontSetup.setup(fontInfo, null); - } - private boolean isCoarseXml() { return ((Boolean) userAgent.getRendererOptions().get("fineDetail")).booleanValue(); @@ -272,6 +264,11 @@ public class XMLRenderer extends AbstractRenderer { } String value = traitEntry.getValue().toString(); addAttribute(name, value); + if ("font-family".equals(name)) { + addAttribute("font-name", fontInfo.getMetricsFor(value).getFontName()); + addAttribute("font-style", fontInfo.getFontStyleFor(value)); + addAttribute("font-weight", fontInfo.getFontWeightFor(value)); + } } } } diff --git a/test/layoutengine/testcases/font-family.xml b/test/layoutengine/testcases/font-family.xml new file mode 100644 index 000000000..2f7bb6a0e --- /dev/null +++ b/test/layoutengine/testcases/font-family.xml @@ -0,0 +1,51 @@ + + + + + +

+ This test checks the generic font families. +

+
+ + + + + + + + + + font-family not given + font-family="serif" + font-family="sans-serif" + font-family="cursive" + font-family="fantasy" + font-family="monospace" + + + + + + + + + + + + +
diff --git a/test/layoutengine/testcases/font-style.xml b/test/layoutengine/testcases/font-style.xml new file mode 100644 index 000000000..326664717 --- /dev/null +++ b/test/layoutengine/testcases/font-style.xml @@ -0,0 +1,79 @@ + + + + + +

+ This test checks font syles. +

+
+ + + + + + + + + + font-family="serif" font-style not given + font-family="serif" font-style="normal" + font-family="serif" font-style="italic" + font-family="serif" font-style="oblique" + font-family="serif" font-style="backslant" + font-family="serif" font-style="obscure" + + font-family="sans-serif" font-style not given + font-family="sans-serif" font-style="normal" + font-family="sans-serif" font-style="italic" + font-family="sans-serif" font-style="oblique" + font-family="sans-serif" font-style="backslant" + font-family="serif" font-style="obscure" + + font-family="monospace" font-style not given + font-family="monospace" font-style="normal" + font-family="monospace" font-style="italic" + font-family="monospace" font-style="oblique" + font-family="monospace" font-style="backslant" + font-family="serif" font-style="obscure" + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/test/layoutengine/testcases/font-weight.xml b/test/layoutengine/testcases/font-weight.xml new file mode 100644 index 000000000..70827a7a9 --- /dev/null +++ b/test/layoutengine/testcases/font-weight.xml @@ -0,0 +1,121 @@ + + + + + +

+ This test checks font weights. +

+
+ + + + + + + + + + font-weight not specified + font-weight="normal" + font-weight="bold" + font-weight="100" + font-weight="200" + font-weight="300" + font-weight="400" + font-weight="500" + font-weight="600" + font-weight="700" + font-weight="800" + font-weight="900" + font-weight="lighter" + font-weight="lighter" + font-weight="lighter" + font-weight="lighter" + font-weight="lighter" + font-weight="lighter" + font-weight="lighter" + font-weight="lighter" + font-weight="lighter" + + + + + + + + + + + font-weight="100" + font-weight="bolder" + font-weight="bolder" + font-weight="bolder" + font-weight="bolder" + font-weight="bolder" + font-weight="bolder" + font-weight="bolder" + font-weight="bolder" + font-weight="bolder" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
-- 2.39.5