aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache
diff options
context:
space:
mode:
authorChris Bowditch <cbowditch@apache.org>2005-08-15 13:23:27 +0000
committerChris Bowditch <cbowditch@apache.org>2005-08-15 13:23:27 +0000
commitbd3680a1e25d8c1a916fa9f58c5ab8d125bd6797 (patch)
tree0533d1b08d63f0be6f9647916962cc60ffe17e33 /src/java/org/apache
parent7a7d2dd354eae700455c51cbe47cfc85f3c3f945 (diff)
downloadxmlgraphics-fop-bd3680a1e25d8c1a916fa9f58c5ab8d125bd6797.tar.gz
xmlgraphics-fop-bd3680a1e25d8c1a916fa9f58c5ab8d125bd6797.zip
ref to bugzilla 36180
Submitted by: Manuel Mall <mm.at.arcus.com.au> git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@232810 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache')
-rw-r--r--src/java/org/apache/fop/fonts/FontInfo.java61
-rw-r--r--src/java/org/apache/fop/render/xml/XMLRenderer.java19
2 files changed, 68 insertions, 12 deletions
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));
+ }
}
}
}