Code from Vincent Hennebert's patch, attachment 18917 to bugzilla 35948. With minor changes to hardcoded pathnames, see README-foray-font.txt
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/foray-font@450479 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/README-foray-font.txt b/README-foray-font.txt
new file mode 100644
index 0000000..b1b929a
--- /dev/null
+++ b/README-foray-font.txt
@@ -0,0 +1,23 @@
+See http://issues.apache.org/bugzilla/show_bug.cgi?id=35948 for more details about
+the work being done on integrating foray-font in FOP.
+
+Currently, to run the version found in the foray-font branch:
+
+1) Compile from Eclipse, there are still many compilation errors which break
+ the ant build.
+
+2) Run from Eclipse, for the same reasons.
+ Using the following parameters should work:
+
+ ./axsl-temp-stuff/fop-foray-test.fo /tmp/output.pdf
+
+3) Create some symbolic links in /tmp/foray-links, as some filenames are hardcoded.
+
+ Here are my current links, adapt to your environment:
+
+ /tmp/foray-links/axsl -> /YOUR_BASE/axsl/trunk/axsl
+ /tmp/foray-links/axsl-temp-stuff -> /YOUR_BASE/apache/fop/branches/foray-font/axsl-temp-stuff
+ /tmp/foray-links/config/glb12.ttf -> /YOUR_BASE/apache/fop/branches/foray-font/test/resources/fonts/glb12.ttf
+ /tmp/foray-links/foray-font/resource -> /YOUR_BASE/foray/trunk/foray/foray-font/resource
+
+
\ No newline at end of file
diff --git a/axsl-temp-stuff/axsl-font-conf.xml b/axsl-temp-stuff/axsl-font-conf.xml
new file mode 100644
index 0000000..13d5fe7
--- /dev/null
+++ b/axsl-temp-stuff/axsl-font-conf.xml
@@ -0,0 +1,158 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE axsl-font-config
+SYSTEM "file:///tmp/foray-links/axsl/doc/web/dtds/0.1/en/axsl-font-config.dtd">
+
+<!-- This file is a sample aXSL font configuration file. -->
+
+<axsl-font-config embed="subset"
+ xml:base="file:///tmp/foray-links/config/">
+
+ <server setup-free-standing-fonts="true"
+ setup-system-fonts="true">
+ <parameter
+ key="base14-root"
+ value="file:///tmp/foray-links/foray-font/resource/base-14/"/>
+ </server>
+
+ <!-- The Base-14 fonts. -->
+ <font-family name="Helvetica" embed="none" xml:base="{base14-root}">
+ <family-member
+ style="normal"
+ weight="normal">
+ <font
+ id="Base14-Helvetica"
+ metrics-file="Helvetica.afm"/>
+ </family-member>
+ <family-member
+ style="italic"
+ weight="normal">
+ <font
+ id="Base14-Helvetica-Oblique"
+ metrics-file="Helvetica-Oblique.afm"/>
+ </family-member>
+ <family-member
+ style="normal"
+ weight="bold">
+ <font
+ id="Base14-Helvetica-Bold"
+ metrics-file="Helvetica-Bold.afm"/>
+ </family-member>
+ <family-member
+ style="italic"
+ weight="bold">
+ <font
+ id="Base14-Helvetica-BoldOblique"
+ metrics-file="Helvetica-BoldOblique.afm"/>
+ </family-member>
+ </font-family>
+ <font-family name="Times" embed="none" xml:base="{base14-root}">
+ <family-member
+ style="normal"
+ weight="normal">
+ <font
+ id="Base14-Times"
+ metrics-file="Times-Roman.afm"/>
+ </family-member>
+ <family-member
+ style="italic"
+ weight="normal">
+ <font
+ id="Base14-Times-Italic"
+ metrics-file="Times-Italic.afm"/>
+ </family-member>
+ <family-member
+ style="normal"
+ weight="bold">
+ <font
+ id="Base14-Times-Bold"
+ metrics-file="Times-Bold.afm"/>
+ </family-member>
+ <family-member
+ style="italic"
+ weight="bold">
+ <font
+ id="Base14-Times-BoldItalic"
+ metrics-file="Times-BoldItalic.afm"/>
+ </family-member>
+ </font-family>
+ <font-family name="Courier" embed="none" xml:base="{base14-root}">
+ <family-member
+ style="normal"
+ weight="normal">
+ <font
+ id="Base14-Courier"
+ metrics-file="Courier.afm"/>
+ </family-member>
+ <family-member
+ style="italic"
+ weight="normal">
+ <font
+ id="Base14-Courier-Oblique"
+ metrics-file="Courier-Oblique.afm"/>
+ </family-member>
+ <family-member
+ style="normal"
+ weight="bold">
+ <font
+ id="Base14-Courier-Bold"
+ metrics-file="Courier-Bold.afm"/>
+ </family-member>
+ <family-member
+ style="italic"
+ weight="bold">
+ <font
+ id="Base14-Courier-BoldOblique"
+ metrics-file="Courier-BoldOblique.afm"/>
+ </family-member>
+ </font-family>
+ <font-family name="Symbol" embed="none" xml:base="{base14-root}">
+ <family-member
+ style="normal"
+ weight="normal">
+ <font
+ id="Base14-Symbol"
+ metrics-file="Symbol.afm"/>
+ </family-member>
+ </font-family>
+ <font-family name="ZapfDingbats" embed="none" xml:base="{base14-root}">
+ <family-member
+ style="normal"
+ weight="normal">
+ <font
+ id="Base14-ZapfDingbats"
+ metrics-file="ZapfDingbats.afm"/>
+ </family-member>
+ </font-family>
+ <!-- End of Base-14 fonts. -->
+
+ <!-- Example of a TrueType font -->
+ <font-family name="Gladiator" embed="subset">
+ <family-member
+ style="normal"
+ weight="normal">
+ <font font-file="glb12.ttf"/>
+ </family-member>
+ </font-family>
+
+ <!-- Example of a Type1 font using AFM metrics and PFB outlines
+ <font-family name="BitstreamCharter" embed="subset">
+ <family-member
+ style="normal"
+ weight="normal">
+ <font
+ metrics-file="BitstreamCharterRoman.afm"
+ font-file="BitstreamCharterRoman.pfb"/>
+ </family-member>
+ </font-family>
+ -->
+
+
+ <!-- The following aliases are required by XSL-FO. -->
+ <font-family-alias alias="sans-serif" family="Helvetica"/>
+ <font-family-alias alias="serif" family="Times"/>
+ <font-family-alias alias="monospace" family="Courier"/>
+
+ <!-- The following alias is a catch-all -->
+ <font-family-alias alias="any" family="Times"/>
+
+</axsl-font-config>
diff --git a/axsl-temp-stuff/fop-foray-test.fo b/axsl-temp-stuff/fop-foray-test.fo
new file mode 100644
index 0000000..15670d1
--- /dev/null
+++ b/axsl-temp-stuff/fop-foray-test.fo
@@ -0,0 +1,207 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
+
+ <!-- defines the layout master -->
+ <fo:layout-master-set>
+ <fo:simple-page-master master-name="first"
+ page-height="29.7cm"
+ page-width="21cm"
+ margin-top="1cm"
+ margin-bottom="2cm"
+ margin-left="2.5cm"
+ margin-right="2.5cm">
+ <fo:region-body margin-top="3cm"/>
+ <fo:region-before extent="3cm"/>
+ <fo:region-after extent="1.5cm"/>
+ </fo:simple-page-master>
+ </fo:layout-master-set>
+
+ <!-- starts actual layout -->
+ <fo:page-sequence master-reference="first">
+
+
+<fo:flow flow-name="xsl-region-body">
+
+ <fo:block font-family="Gladiator" font-size="24pt">
+ This is a custom font: Gladiator
+ <fo:block font-size="12pt">
+ <fo:block>
+ Here's an e acute: é
+ </fo:block>
+ <fo:block>
+ Here's aeiou, all with circumflex: âêîôû
+ </fo:block>
+ </fo:block>
+ </fo:block>
+
+ <fo:block font-family="Helvetica" font-size="14pt">
+Helvetica
+ </fo:block>
+ <fo:block space-after.optimum="10pt" font-family="Helvetica">
+! " # $ % & ' ( ) *
++ , - . / 0 1 2 3 4
+5 6 7 8 9 : ; < = >
+? @ A B C D E F G H
+I J K L M N O P Q R
+S T U V W X Y Z [ \
+] ^ _ ` a b c d e f
+g h i j k l m n o p
+q r s t u v w x y z
+{ | } ~ ¡ ¢ £ ¤ ¥ ¦
+§ ¨ © ª « ¬ ® ¯ ° ±
+² ³ ´ µ ¶ · ¸ ¹ º »
+¼ ½ ¾ ¿ À Á Â Ã Ä Å
+Æ Ç È É Ê Ë Ì Í Î Ï
+Ð Ñ Ò Ó Ô Õ Ö × Ø Ù
+Ú Û Ü Ý Þ ß à á â ã
+ä å æ ç è é ê ë ì í
+î ï ð ñ ò ó ô õ ö ÷
+ø ù ú û ü ý þ ÿ
+Œ œ Š š Ÿ
+Ž ž ƒ ˜ – — ‘
+’ ‚ “ ” „ † ‡
+• … ‰ ‹ › ™
+ </fo:block>
+
+ <fo:block font-family="Helvetica" font-size="14pt">
+Times Roman
+ </fo:block>
+ <fo:block space-after.optimum="10pt" font-family="Times Roman">
+! " # $ % & ' ( ) *
++ , - . / 0 1 2 3 4
+5 6 7 8 9 : ; < = >
+? @ A B C D E F G H
+I J K L M N O P Q R
+S T U V W X Y Z [ \
+] ^ _ ` a b c d e f
+g h i j k l m n o p
+q r s t u v w x y z
+{ | } ~ ¡ ¢ £ ¤ ¥ ¦
+§ ¨ © ª « ¬ ® ¯ ° ±
+² ³ ´ µ ¶ · ¸ ¹ º »
+¼ ½ ¾ ¿ À Á Â Ã Ä Å
+Æ Ç È É Ê Ë Ì Í Î Ï
+Ð Ñ Ò Ó Ô Õ Ö × Ø Ù
+Ú Û Ü Ý Þ ß à á â ã
+ä å æ ç è é ê ë ì í
+î ï ð ñ ò ó ô õ ö ÷
+ø ù ú û ü ý þ ÿ Œ
+œ Š š Ÿ Ž ž ƒ
+˜ – — ‘ ’ ‚
+“ ” „ † ‡ • …
+‰ ‹ › ™
+ </fo:block>
+
+ <fo:block font-family="Helvetica" font-size="14pt">
+Courier
+ </fo:block>
+ <fo:block space-after.optimum="10pt" font-family="Courier">
+! " # $ % & ' ( ) *
++ , - . / 0 1 2 3 4
+5 6 7 8 9 : ; < = >
+? @ A B C D E F G H
+I J K L M N O P Q R
+S T U V W X Y Z [ \
+] ^ _ ` a b c d e f
+g h i j k l m n o p
+q r s t u v w x y z
+{ | } ~ ¡ ¢ £ ¤ ¥ ¦
+§ ¨ © ª « ¬ ® ¯ ° ±
+² ³ ´ µ ¶ · ¸ ¹ º »
+¼ ½ ¾ ¿ À Á Â Ã Ä Å
+Æ Ç È É Ê Ë Ì Í Î Ï
+Ð Ñ Ò Ó Ô Õ Ö × Ø Ù
+Ú Û Ü Ý Þ ß à á â ã
+ä å æ ç è é ê ë ì í
+î ï ð ñ ò ó ô õ ö ÷
+ø ù ú û ü ý þ ÿ Œ
+œ Š š Ÿ Ž
+ž ƒ ˜ – — ‘
+’ ‚ “ ” „ † ‡
+• … ‰ ‹ › ™
+ </fo:block>
+
+ <fo:block font-family="Helvetica" font-size="14pt">
+ ZapfDingbats:
+ </fo:block>
+ <fo:block space-after.optimum="10pt" font-family="ZapfDingbats">
+✁ ✂ ✃ ✄ ☎ ✆ ✇
+✈ ✉ ☛ ☞ ✌ ✍ ✎
+✏ ✐ ✑ ✒ ✓ ✔ ✕
+✖ ✗ ✘ ✙ ✚ ✛ ✜
+✝ ✞ ✟ ✠ ✡ ✢ ✣
+✤ ✥ ✦ ✧ ★ ✩ ✪
+✫ ✬ ✭ ✮ ✯ ✰ ✱
+✲ ✳ ✴ ✵ ✶ ✷ ✸
+✹ ✺ ✻ ✼ ✽ ✾ ✿
+❀ ❁ ❂ ❃ ❄ ❅ ❆
+❇ ❈ ❉ ❊ ❋ ● ❍
+■ ❏ ❐ ❑ ❒ ▲ ▼
+◆ ❖ ◗ ❘ ❙ ❚ ❛
+❜ ❝ ❞ ❡ ❢ ❣ ❤
+❥ ❦ ❧ ♣ ♦ ♥ ♠
+① ② ③ ④ ⑤ ⑥ ⑦
+⑧ ⑨ ⑩ ❶ ❷ ❸ ❹
+❺ ❻ ❼ ❽ ❾ ❿ ➀
+➁ ➂ ➃ ➄ ➅ ➆ ➇
+➈ ➉ ➊ ➋ ➌ ➍ ➎
+➏ ➐ ➑ ➒ ➓ ➔ →
+↔ ↕ ➘ ➙ ➚ ➛ ➜
+➝ ➞ ➟ ➠ ➡ ➢ ➣
+➤ ➥ ➦ ➧ ➨ ➩ ➪
+➫ ➬ ➭ ➮ ➯ ➱ ➲
+➳ ➴ ➵ ➶ ➷ ➸ ➹
+➺ ➻ ➼ ➽ ➾  
+      
+    
+ </fo:block>
+
+ <fo:block font-family="Helvetica" font-size="14pt">
+ Symbol:
+ </fo:block>
+ <fo:block space-after.optimum="10pt" font-family="Symbol">
+! # % & ( ) + , . /
+0 1 2 3 4 5 6 7 8 9
+: ; < = > ? [ ] _ m
+{ | } ¬ ° ± µ × ÷
+ƒ Α Β Γ Ε Ζ Η
+Θ Ι Κ Λ Μ Ν Ξ
+Ο Π Ρ Σ Τ Υ Φ
+Χ Ψ α β γ δ ε
+ζ η θ ι κ λ ν
+ξ ο π ρ ς σ τ
+υ φ χ ψ ω ϑ ϒ
+ϕ ϖ • … ′ ″ ⁄
+ℑ ℘ ℜ Ω ℵ ← ↑
+→ ↓ ↔ ↵ ⇐ ⇑ ⇒
+⇓ ⇔ ∀ ∂ ∃ ∅ ∆
+∇ ∈ ∉ ∋ ∏ ∑ −
+∗ √ ∝ ∞ ∠ ∧ ∨
+∩ ∪ ∫ ∴ ∼ ≅ ≈
+≠ ≡ ≤ ≥ ⊂ ⊃ ⊄
+⊆ ⊇ ⊕ ⊗ ⊥ ⋅ ⌠
+⌡ 〈 〉 ◊ ♠ ♣ ♥
+♦      
+      
+      
+      
+ 
+ </fo:block>
+
+ <fo:block font-family="Helvetica" font-size="12pt">
+ Some special characters:
+ </fo:block>
+ <fo:block space-after.optimum="10pt" font-family="Helvetica">
+Euro ( dec 8364, hex 20AC): €
+ </fo:block>
+
+
+ <fo:block space-after.optimum="10pt" font-family="Helvetica">
+
+ </fo:block>
+
+</fo:flow>
+</fo:page-sequence>
+</fo:root>
+
diff --git a/conf/fop.xconf b/conf/fop.xconf
index a3b3c23..2c10f4f 100644
--- a/conf/fop.xconf
+++ b/conf/fop.xconf
@@ -33,6 +33,9 @@
<!-- Base URL for resolving relative URLs -->
<base>.</base>
+ <!-- URL for the font-configuration file. If relative, then it is set
+ relative to the base URL -->
+ <font-config-file>/path/to/Fop/conf/fonts.xconf</font-config-file>
<!-- Source resolution in dpi (dots/pixels per inch) for determining the size of pixels in SVG and bitmap images, default: 72dpi -->
<source-resolution>72</source-resolution>
diff --git a/lib/axsl-0.2a.jar b/lib/axsl-0.2a.jar
new file mode 100644
index 0000000..d2af04d
--- /dev/null
+++ b/lib/axsl-0.2a.jar
Binary files differ
diff --git a/lib/foray-common.jar b/lib/foray-common.jar
new file mode 100644
index 0000000..1a44dd7
--- /dev/null
+++ b/lib/foray-common.jar
Binary files differ
diff --git a/lib/foray-font.jar b/lib/foray-font.jar
new file mode 100644
index 0000000..aa17e85
--- /dev/null
+++ b/lib/foray-font.jar
Binary files differ
diff --git a/lib/foray-ps.jar b/lib/foray-ps.jar
new file mode 100644
index 0000000..d9d92a7
--- /dev/null
+++ b/lib/foray-ps.jar
Binary files differ
diff --git a/src/java/org/apache/fop/apps/FOUserAgent.java b/src/java/org/apache/fop/apps/FOUserAgent.java
index 63a3859..ddd0d2a 100644
--- a/src/java/org/apache/fop/apps/FOUserAgent.java
+++ b/src/java/org/apache/fop/apps/FOUserAgent.java
@@ -21,6 +21,7 @@
// Java
import java.io.File;
+import java.net.URL;
import java.util.Date;
import java.util.Map;
import javax.xml.transform.Source;
@@ -76,6 +77,8 @@
/** The base URL for all URL resolutions, especially for external-graphics */
private String baseURL;
+ private URL fontCfgURL;
+
/** A user settable URI Resolver */
private URIResolver uriResolver = null;
@@ -295,6 +298,30 @@
}
}
+ // TODO adapt
+// if (userConfig.getChild("font-config-file", false) != null) {
+// try {
+// String fontCfgFile = userConfig.getChild("font-config-file").getValue(null);
+// if (fontCfgFile != null) {
+// File file = new File(fontCfgFile);
+// if (file.isAbsolute() || baseURL == null) {
+// fontCfgFile = "file://" + file.getCanonicalPath();
+// fontCfgFile = fontCfgFile.replace(
+// System.getProperty("file.separator").charAt(0), '/');
+// } else {
+// fontCfgFile = baseURL + fontCfgFile.replace(
+// System.getProperty("file.separator").charAt(0), '/');
+// }
+// }
+// setFontCfgURL(new URL(fontCfgFile));
+// } catch (MalformedURLException mue) {
+// log.error("Font config URL in user config is malformed!");
+// } catch (IOException ioe) {
+// log.error("Error converting relative font config file to absolute URL.");
+// }
+// log.info("Font config URL set to: " + fontCfgURL);
+// }
+
/**
* Returns the configuration subtree for a specific renderer.
* @param mimeType MIME type of the renderer
@@ -336,6 +363,14 @@
}
/**
+ * Sets the font config URL.
+ * @param fontCfgURl font config URL
+ */
+ public void setFontCfgURL(URL fontCfgURL) {
+ this.fontCfgURL = fontCfgURL;
+ }
+
+ /**
* Returns the base URL.
* @return the base URL
*/
@@ -344,6 +379,14 @@
}
/**
+ * Returns the font config URL.
+ * @return the font config URL
+ */
+ public URL getFontCfgURL() {
+ return this.fontCfgURL;
+ }
+
+ /**
* Sets the URI Resolver.
* @param resolver the new URI resolver
*/
diff --git a/src/java/org/apache/fop/area/AreaTreeHandler.java b/src/java/org/apache/fop/area/AreaTreeHandler.java
index 91a5d60..b40e4f0 100644
--- a/src/java/org/apache/fop/area/AreaTreeHandler.java
+++ b/src/java/org/apache/fop/area/AreaTreeHandler.java
@@ -48,6 +48,8 @@
import org.apache.fop.layoutmgr.LayoutManagerMaker;
import org.apache.fop.layoutmgr.LayoutManagerMapping;
+import org.axsl.fontR.FontConsumer;
+
/**
* Area tree handler for formatting objects.
*
@@ -118,7 +120,7 @@
*/
public AreaTreeHandler (FOUserAgent userAgent, String outputFormat,
OutputStream stream) throws FOPException {
- super(userAgent);
+ super(userAgent, outputFormat, log);
setupModel(userAgent, outputFormat, stream);
@@ -143,7 +145,7 @@
*/
protected void setupModel(FOUserAgent userAgent, String outputFormat,
OutputStream stream) throws FOPException {
- model = new RenderPagesModel(userAgent, outputFormat, fontInfo,
+ model = new RenderPagesModel(userAgent, outputFormat, fontConsumer,
stream);
}
diff --git a/src/java/org/apache/fop/area/AreaTreeParser.java b/src/java/org/apache/fop/area/AreaTreeParser.java
index b6d1e81..938c64e 100644
--- a/src/java/org/apache/fop/area/AreaTreeParser.java
+++ b/src/java/org/apache/fop/area/AreaTreeParser.java
@@ -55,8 +55,6 @@
import org.apache.fop.fo.ElementMappingRegistry;
import org.apache.fop.fo.expr.PropertyException;
import org.apache.fop.fo.extensions.ExtensionAttachment;
-import org.apache.fop.fonts.Font;
-import org.apache.fop.fonts.FontInfo;
import org.apache.fop.image.FopImage;
import org.apache.fop.image.ImageFactory;
import org.apache.fop.traits.BorderProps;
diff --git a/src/java/org/apache/fop/area/CachedRenderPagesModel.java b/src/java/org/apache/fop/area/CachedRenderPagesModel.java
index 4d42370..7a8b972 100644
--- a/src/java/org/apache/fop/area/CachedRenderPagesModel.java
+++ b/src/java/org/apache/fop/area/CachedRenderPagesModel.java
@@ -22,7 +22,6 @@
import org.apache.commons.io.IOUtils;
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
-import org.apache.fop.fonts.FontInfo;
import org.xml.sax.SAXException;
import java.util.Map;
@@ -38,6 +37,8 @@
import java.io.BufferedOutputStream;
import java.io.BufferedInputStream;
+import org.axsl.fontR.FontConsumer;
+
/**
* A simple cached render pages model.
* If the page is prepared for later rendering then this saves
@@ -59,8 +60,8 @@
* @throws FOPException if the renderer cannot be properly initialized
*/
public CachedRenderPagesModel (FOUserAgent userAgent, String outputFormat,
- FontInfo fontInfo, OutputStream stream) throws FOPException {
- super(userAgent, outputFormat, fontInfo, stream);
+ FontConsumer fontConsumer, OutputStream stream) throws FOPException {
+ super(userAgent, outputFormat, fontConsumer, stream);
this.baseDir = new File(System.getProperty("java.io.tmpdir"));
}
diff --git a/src/java/org/apache/fop/area/RenderPagesModel.java b/src/java/org/apache/fop/area/RenderPagesModel.java
index da9305f..a5fd2ae 100644
--- a/src/java/org/apache/fop/area/RenderPagesModel.java
+++ b/src/java/org/apache/fop/area/RenderPagesModel.java
@@ -31,9 +31,12 @@
// FOP
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
-import org.apache.fop.fonts.FontInfo;
import org.apache.fop.render.Renderer;
+import org.axsl.fontR.Font;
+import org.axsl.fontR.FontConsumer;
+import org.axsl.fontR.FontException;
+
/**
* This uses the AreaTreeModel to store the pages
* Each page is either rendered if ready or prepared
@@ -59,23 +62,29 @@
* Create a new render pages model with the given renderer.
* @param userAgent FOUserAgent object for process
* @param outputFormat the MIME type of the output format to use (ex. "application/pdf").
- * @param fontInfo FontInfo object
+ * @param fontConsumer FontConsumer object
* @param stream OutputStream
* @throws FOPException if the renderer cannot be properly initialized
*/
public RenderPagesModel (FOUserAgent userAgent, String outputFormat,
- FontInfo fontInfo, OutputStream stream) throws FOPException {
+ FontConsumer fontConsumer, OutputStream stream) throws FOPException {
super();
renderer = userAgent.getRendererFactory().createRenderer(
userAgent, outputFormat);
try {
- renderer.setupFontInfo(fontInfo);
- // check that the "any,normal,400" font exists
- if (!fontInfo.isSetupValid()) {
- throw new FOPException(
- "No default font defined by OutputConverter");
+ renderer.setupFontConsumer(fontConsumer);
+ // check that the default fallback font exists
+ try {
+ fontConsumer.selectFontXSL(Font.FONT_SELECTION_AUTO, new String[] {"any"},
+ Font.FONT_STYLE_ANY,
+ Font.FONT_WEIGHT_ANY,
+ Font.FONT_VARIANT_ANY,
+ Font.FONT_STRETCH_ANY,
+ 10000, ' ');
+ } catch (FontException e) {
+ throw new FOPException("No default font defined by OutputConverter");
}
renderer.startRenderer(stream);
} catch (IOException e) {
diff --git a/src/java/org/apache/fop/area/Trait.java b/src/java/org/apache/fop/area/Trait.java
index 6db4794..b3ded16 100644
--- a/src/java/org/apache/fop/area/Trait.java
+++ b/src/java/org/apache/fop/area/Trait.java
@@ -23,10 +23,10 @@
import java.io.Serializable;
import org.apache.fop.fo.Constants;
-import org.apache.fop.fonts.FontTriplet;
import org.apache.fop.image.FopImage;
import org.apache.fop.traits.BorderProps;
import org.apache.fop.util.ColorUtil;
+import org.axsl.fontR.FontUse;
// properties should be serialized by the holder
/**
@@ -53,12 +53,12 @@
public static final Integer EXTERNAL_LINK = new Integer(2);
/**
- * The font triplet for the current font.
+ * The font use from the font setup.
*/
public static final Integer FONT = new Integer(3);
/**
- * Font size for the current font.
+ * Font size (in millipoints) for the current font.
*/
public static final Integer FONT_SIZE = new Integer(4);
@@ -226,7 +226,7 @@
//put(ID_LINK, new TraitInfo("id-link", String.class));
put(INTERNAL_LINK, new TraitInfo("internal-link", String.class));
put(EXTERNAL_LINK, new TraitInfo("external-link", String.class));
- put(FONT, new TraitInfo("font", FontTriplet.class));
+ put(FONT, new TraitInfo("font", FontUse.class));//TODO vh: used to be FontTriplet
put(FONT_SIZE, new TraitInfo("font-size", Integer.class));
put(COLOR, new TraitInfo("color", Color.class));
put(PROD_ID, new TraitInfo("prod-id", String.class));
diff --git a/src/java/org/apache/fop/area/inline/UnresolvedPageNumber.java b/src/java/org/apache/fop/area/inline/UnresolvedPageNumber.java
index f8585e9..15ffcbd 100644
--- a/src/java/org/apache/fop/area/inline/UnresolvedPageNumber.java
+++ b/src/java/org/apache/fop/area/inline/UnresolvedPageNumber.java
@@ -21,7 +21,10 @@
import org.apache.fop.area.PageViewport;
import org.apache.fop.area.Resolvable;
-import org.apache.fop.fonts.Font;
+
+import org.axsl.fontR.Font;
+import org.axsl.fontR.FontConsumer;
+import org.axsl.fontR.FontUse;
import java.util.List;
@@ -34,6 +37,8 @@
private boolean resolved = false;
private String pageIDRef;
+ private FontConsumer fontConsumer;
+ private int fontSize;
private String text;
private boolean pageType;
@@ -43,7 +48,7 @@
public static final boolean LAST = false;
//Transient fields
- private transient Font font;
+ private transient FontUse fontUse;
/**
* Create a new unresolved page number.
@@ -51,8 +56,8 @@
* @param id the id reference for resolving this
* @param f the font for formatting the page number
*/
- public UnresolvedPageNumber(String id, Font f) {
- this(id, f, FIRST);
+ public UnresolvedPageNumber(String id, FontConsumer fc, FontUse fu, int fsize) {
+ this(id, fc, fu, fsize, FIRST);
}
/**
@@ -63,11 +68,14 @@
* @param type indicates whether the reference refers to the first or last area generated by
* a formatting object
*/
- public UnresolvedPageNumber(String id, Font f, boolean type) {
+ public UnresolvedPageNumber(String id, FontConsumer fc, FontUse fu, int fsize, boolean type) {
pageIDRef = id;
- font = f;
+ fontConsumer = fc;
+ fontUse = fu;
+ fontSize = fsize;
text = "?";
pageType = type;
+ fontUse.registerCharUsed('?');
}
/**
@@ -105,10 +113,10 @@
removeText();
addWord(page.getPageNumberString(), 0);
// update ipd
- if (font != null) {
- updateIPD(font.getWordWidth(text));
+ if (fontUse != null) {
+ updateIPD(fontUse.getFont().width(text, fontSize, 0, 0));
// set the Font object to null, as we don't need it any more
- font = null;
+ fontUse = null;
} else {
log.warn("Cannot update the IPD of an unresolved page number."
+ " No font information available.");
@@ -136,4 +144,18 @@
int lineStretch, int lineShrink) {
return true;
}
+
+ /**
+ * @param str string to be measured
+ * @return width of the string
+ */
+ private int getStringWidth(String str) {
+ int width = 0;
+ for (int count = 0; count < str.length(); count++) {
+ char c = str.charAt(count);
+ width += fontUse.getFont().width(c, fontSize);
+ fontUse.registerCharUsed(c);
+ }
+ return width;
+ }
}
diff --git a/src/java/org/apache/fop/cli/AreaTreeInputHandler.java b/src/java/org/apache/fop/cli/AreaTreeInputHandler.java
index 4662a0e..f0963e9 100644
--- a/src/java/org/apache/fop/cli/AreaTreeInputHandler.java
+++ b/src/java/org/apache/fop/cli/AreaTreeInputHandler.java
@@ -28,10 +28,14 @@
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.area.AreaTreeHandler;
import org.apache.fop.area.AreaTreeModel;
import org.apache.fop.area.AreaTreeParser;
import org.apache.fop.area.RenderPagesModel;
-import org.apache.fop.fonts.FontInfo;
+import org.apache.fop.fo.FOEventHandler;
+import org.axsl.fontR.FontConsumer;
+import org.foray.font.FOrayFontConsumer;
+import org.foray.font.FOrayFontServer;
import org.xml.sax.SAXException;
/**
@@ -61,9 +65,10 @@
/** @see org.apache.fop.cli.InputHandler */
public void renderTo(FOUserAgent userAgent, String outputFormat, OutputStream out)
throws FOPException {
- FontInfo fontInfo = new FontInfo();
+ // TODO vh: really create a new FontConsumer?
+ FontConsumer fontConsumer = FOEventHandler.getFontServer().makeFontConsumer();
AreaTreeModel treeModel = new RenderPagesModel(userAgent,
- outputFormat, fontInfo, out);
+ outputFormat, fontConsumer, out);
//Iterate over all intermediate files
AreaTreeParser parser = new AreaTreeParser();
diff --git a/src/java/org/apache/fop/cli/Main.java b/src/java/org/apache/fop/cli/Main.java
index cf793e2..28c5a71 100644
--- a/src/java/org/apache/fop/cli/Main.java
+++ b/src/java/org/apache/fop/cli/Main.java
@@ -174,6 +174,7 @@
} catch (Exception e) {
if (options != null) {
options.getLogger().error("Exception", e);
+ e.printStackTrace();
}
if (options.getOutputFile() != null) {
options.getOutputFile().delete();
diff --git a/src/java/org/apache/fop/fo/FOEventHandler.java b/src/java/org/apache/fop/fo/FOEventHandler.java
index 28dd32b..71671dd 100644
--- a/src/java/org/apache/fop/fo/FOEventHandler.java
+++ b/src/java/org/apache/fop/fo/FOEventHandler.java
@@ -20,12 +20,17 @@
package org.apache.fop.fo;
// Java
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.HashSet;
import java.util.Set;
import org.xml.sax.SAXException;
// Apache
+import org.apache.commons.logging.Log;
+
import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.MimeConstants;
import org.apache.fop.fo.flow.BasicLink;
import org.apache.fop.fo.flow.Block;
import org.apache.fop.fo.flow.BlockContainer;
@@ -46,7 +51,12 @@
import org.apache.fop.fo.flow.TableRow;
import org.apache.fop.fo.pagination.Flow;
import org.apache.fop.fo.pagination.PageSequence;
-import org.apache.fop.fonts.FontInfo;
+
+// FOrayFont
+import org.axsl.fontR.FontConsumer;
+import org.axsl.fontR.FontException;
+import org.axsl.fontR.FontServer;
+import org.foray.font.FOrayFontServer;
/**
@@ -67,11 +77,6 @@
*/
protected FOUserAgent foUserAgent;
- /**
- * The Font information relevant for this document
- */
- protected FontInfo fontInfo;
-
/**
* The current set of id's in the FO tree.
* This is used so we know if the FO tree contains duplicates.
@@ -84,6 +89,96 @@
protected PropertyListMaker propertyListMaker;
/**
+ * Font server used to provide all needed font informations.
+ */
+ protected static FontServer fontServer; // TODO vh static?
+
+// private boolean useFreeStandingFonts;
+// private boolean useSystemFonts;
+// private boolean preferFreeStandingFonts;
+
+ /**
+ * @inheritDoc
+ */
+ public static FontServer getFontServer() {
+ return fontServer;
+ }
+
+ protected FontConsumer fontConsumer;
+
+// /**
+// * @inheritDoc
+// */
+// public boolean preferFreeStandingFonts() {
+// return preferFreeStandingFonts;
+// }
+//
+// /**
+// * @inheritDoc
+// */
+// public PseudoLogger getPseudoLogger() {
+// return pseudoLogger;
+// }
+//
+// /**
+// * @inheritDoc
+// */
+// public boolean isUsingFreeStandingFonts() {
+// return useFreeStandingFonts;
+// }
+//
+// /**
+// * @inheritDoc
+// */
+// public boolean isUsingSystemFonts() {
+// return useSystemFonts;
+// }
+
+ /**
+ * Retrieve the font consumer for this document
+ * @return the FontConsumer instance for this document
+ */
+ public FontConsumer getFontConsumer() {
+ return fontConsumer;
+ }
+
+
+ public FOEventHandler(FOUserAgent foUserAgent, String outputFormat, Log log) {
+ this(foUserAgent);
+// pseudoLogger = new CommonsLogger(log);
+// if (outputFormat.equals(MimeConstants.MIME_PDF)
+// || outputFormat.equals(MimeConstants.MIME_POSTSCRIPT)) {
+// useFreeStandingFonts = true;
+// useSystemFonts = false;
+// preferFreeStandingFonts = true;
+// } else {
+// useFreeStandingFonts = false;
+// useSystemFonts = true;
+// preferFreeStandingFonts = false;
+// }
+ if (fontServer == null) {
+ try {
+ fontServer = new FOrayFontServer(log);
+ /* TODO vh: plug font config file */
+// ((FOrayFontServer) fontServer).setBaseFontURL(new java.net.URL("file:///local/home/vhennebert/Fop/Tests/Config/axsl-font-conf.xml"));
+ final String AXSL_FONT_FILE = "/tmp/foray-links/axsl-temp-stuff/axsl-font-conf.xml";
+ if(!new java.io.File(AXSL_FONT_FILE).canRead()) {
+ throw new Error("Missing aXSL config file:" + AXSL_FONT_FILE);
+ }
+ final URL url = new URL("file://" + AXSL_FONT_FILE);
+ ((FOrayFontServer) fontServer).setup(url/*foUserAgent.getFontCfgURL()*/, null);
+ } catch (MalformedURLException e) { // Should not happen
+ log.error("MalformedURLException",e);
+ } catch (FontException e) {
+ log.error("Unable to setup the font server",e);
+ }
+ }
+ fontConsumer = fontServer.makeFontConsumer();
+ /* TODO vh: will have to release */
+// fontServer.registerFontConsumer(this);
+ }
+
+ /**
* The XMLWhitespaceHandler for this tree
*/
protected XMLWhiteSpaceHandler whiteSpaceHandler = new XMLWhiteSpaceHandler();
@@ -99,7 +194,6 @@
*/
public FOEventHandler(FOUserAgent foUserAgent) {
this.foUserAgent = foUserAgent;
- this.fontInfo = new FontInfo();
}
/**
@@ -119,14 +213,6 @@
}
/**
- * Retrieve the font information for this document
- * @return the FontInfo instance for this document
- */
- public FontInfo getFontInfo() {
- return this.fontInfo;
- }
-
- /**
* Return the propertyListMaker.
*/
public PropertyListMaker getPropertyListMaker() {
diff --git a/src/java/org/apache/fop/fo/PropertyList.java b/src/java/org/apache/fop/fo/PropertyList.java
index 8b7c67a..3eb4c70 100644
--- a/src/java/org/apache/fop/fo/PropertyList.java
+++ b/src/java/org/apache/fop/fo/PropertyList.java
@@ -648,7 +648,7 @@
* @throws PropertyException if there's a problem while processing the properties
*/
public CommonFont getFontProps() throws PropertyException {
- return new CommonFont(this);
+ return new CommonFont(this, this.fobj.getFOEventHandler().getFontServer());
}
/**
diff --git a/src/java/org/apache/fop/fo/properties/CommonFont.java b/src/java/org/apache/fop/fo/properties/CommonFont.java
index 11c53ad..711dcd7 100755
--- a/src/java/org/apache/fop/fo/properties/CommonFont.java
+++ b/src/java/org/apache/fop/fo/properties/CommonFont.java
@@ -28,10 +28,12 @@
import org.apache.fop.fo.Constants;
import org.apache.fop.fo.PropertyList;
import org.apache.fop.fo.expr.PropertyException;
-import org.apache.fop.fonts.Font;
-import org.apache.fop.fonts.FontInfo;
-import org.apache.fop.fonts.FontMetrics;
-import org.apache.fop.fonts.FontTriplet;
+
+import org.axsl.fontR.Font;
+import org.axsl.fontR.FontConsumer;
+import org.axsl.fontR.FontException;
+import org.axsl.fontR.FontServer;
+import org.axsl.fontR.FontUse;
/**
* Collection of properties used in
@@ -78,13 +80,17 @@
*/
public int fontWeight;
- private Font fontState;
+ private FontServer fontServer;
+
+ private FontUse fontUse;
/**
* Create a CommonFont object.
* @param pList The PropertyList to get properties from.
+ * @param fontServer the server from which to get the font
*/
- public CommonFont(PropertyList pList) throws PropertyException {
+ public CommonFont(PropertyList pList, FontServer fontServer)
+ throws PropertyException {
List lst = pList.get(Constants.PR_FONT_FAMILY).getList();
fontFamily = new String[lst.size()];
for (int i = 0, c = lst.size(); i < c; i++) {
@@ -101,8 +107,17 @@
fontStyle = pList.get(Constants.PR_FONT_STYLE).getEnum();
fontVariant = pList.get(Constants.PR_FONT_VARIANT).getEnum();
fontWeight = pList.get(Constants.PR_FONT_WEIGHT).getEnum();
+ this.fontServer = fontServer;
}
-
+
+ /**
+ * Return the font size based on the properties.
+ * @return the font size in millipoints.
+ */
+ public int getFontSize(PercentBaseContext context) {
+ return fontSize.getValue(context);
+ }
+
/** @return the first font-family name in the list */
public String getFirstFontFamily() {
return this.fontFamily[0];
@@ -121,58 +136,78 @@
this.fontFamily = new String[] {value};
}
-
+
/**
- * Create and return a Font object based on the properties.
+ * Return a font use based on the properties.
*
- * @param fontInfo
- * @return a Font object.
+ * @param fontConsumer font consumer to which the returned font use will be associated
+ * @return a FontUse instance corresponding to the properties
*/
- public Font getFontState(FontInfo fontInfo, PercentBaseContext context) {
- if (fontState == null) {
+ public FontUse getFontState(FontConsumer fontConsumer, PercentBaseContext context) {
+ if (fontUse == null) {
/**@todo this is ugly. need to improve. */
- int font_weight = 400;
+ short font_weight = Font.FONT_WEIGHT_ANY;
if (fontWeight == Constants.EN_BOLDER) {
// +100 from inherited
} else if (fontWeight == Constants.EN_LIGHTER) {
// -100 from inherited
} else {
switch (fontWeight) {
- case Constants.EN_100: font_weight = 100; break;
- case Constants.EN_200: font_weight = 200; break;
- case Constants.EN_300: font_weight = 300; break;
- case Constants.EN_400: font_weight = 400; break;
- case Constants.EN_500: font_weight = 500; break;
- case Constants.EN_600: font_weight = 600; break;
- case Constants.EN_700: font_weight = 700; break;
- case Constants.EN_800: font_weight = 800; break;
- case Constants.EN_900: font_weight = 900; break;
+ case Constants.EN_100: font_weight = Font.FONT_WEIGHT_100; break;
+ case Constants.EN_200: font_weight = Font.FONT_WEIGHT_200; break;
+ case Constants.EN_300: font_weight = Font.FONT_WEIGHT_300; break;
+ case Constants.EN_400: font_weight = Font.FONT_WEIGHT_400; break;
+ case Constants.EN_500: font_weight = Font.FONT_WEIGHT_500; break;
+ case Constants.EN_600: font_weight = Font.FONT_WEIGHT_600; break;
+ case Constants.EN_700: font_weight = Font.FONT_WEIGHT_700; break;
+ case Constants.EN_800: font_weight = Font.FONT_WEIGHT_800; break;
+ case Constants.EN_900: font_weight = Font.FONT_WEIGHT_900; break;
}
}
- String style;
+ byte style;
switch (fontStyle) {
- case Constants.EN_ITALIC:
- style = "italic";
- break;
- case Constants.EN_OBLIQUE:
- style = "oblique";
- break;
- case Constants.EN_BACKSLANT:
- style = "backslant";
- break;
+ case Constants.EN_ITALIC: style = Font.FONT_STYLE_ITALIC; break;
+ case Constants.EN_OBLIQUE: style = Font.FONT_STYLE_OBLIQUE; break;
+ case Constants.EN_BACKSLANT: style = Font.FONT_STYLE_BACKSLANT; break;
default:
- style = "normal";
+ style = Font.FONT_STYLE_NORMAL;
}
- // NOTE: this is incomplete. font-size may be specified with
- // various kinds of keywords too
- //int fontVariant = propertyList.get("font-variant").getEnum();
- FontTriplet triplet = fontInfo.fontLookup(getFontFamily(), style,
- font_weight);
- fontState = fontInfo.getFontInstance(triplet, fontSize.getValue(context));
+ byte variant = fontVariant == Constants.EN_SMALL_CAPS ? Font.FONT_VARIANT_SMALL_CAPS
+ : Font.FONT_VARIANT_NORMAL;
+ byte stretch;
+ /* TODO vh: handle narrower and wider */
+ switch (fontStretch) {
+ case Constants.EN_NORMAL: stretch = Font.FONT_STRETCH_NORMAL; break;
+ case Constants.EN_ULTRA_CONDENSED: stretch = Font.FONT_STRETCH_ULTRA_CONDENSED; break;
+ case Constants.EN_EXTRA_CONDENSED: stretch = Font.FONT_STRETCH_EXTRA_CONDENSED; break;
+ case Constants.EN_CONDENSED: stretch = Font.FONT_STRETCH_CONDENSED; break;
+ case Constants.EN_SEMI_CONDENSED: stretch = Font.FONT_STRETCH_SEMI_CONDENSED; break;
+ case Constants.EN_SEMI_EXPANDED: stretch = Font.FONT_STRETCH_SEMI_EXPANDED; break;
+ case Constants.EN_EXPANDED: stretch = Font.FONT_STRETCH_EXPANDED; break;
+ case Constants.EN_EXTRA_EXPANDED: stretch = Font.FONT_STRETCH_EXTRA_EXPANDED; break;
+ case Constants.EN_ULTRA_EXPANDED: stretch = Font.FONT_STRETCH_ULTRA_EXPANDED; break;
+ default: stretch = Font.FONT_STRETCH_NORMAL;
+ }
+ try {
+ fontUse = fontConsumer.selectFontXSL(Font.FONT_SELECTION_AUTO/*TODO vh*/,
+ getFontFamily(), style, font_weight, variant,
+ stretch, fontSize.getValue(context), ' '/*TODO vh*/);
+ } catch (FontException e) {
+ try {
+ fontUse = fontConsumer.selectFontXSL(Font.FONT_SELECTION_AUTO, new String[] {"any"},
+ Font.FONT_STYLE_ANY,
+ Font.FONT_WEIGHT_ANY,
+ Font.FONT_VARIANT_ANY,
+ Font.FONT_STRETCH_ANY,
+ 10000, ' ');
+ } catch (FontException e1) {
+ // Should never happen (see area.RenderPagesModel)
+ }
+ }
}
- return fontState;
+ return fontUse;
}
}
diff --git a/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java b/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java
index 623c94c..c0bccc0 100644
--- a/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java
@@ -27,13 +27,15 @@
import org.apache.fop.area.Block;
import org.apache.fop.area.LineArea;
import org.apache.fop.datatypes.Length;
-import org.apache.fop.fonts.Font;
import org.apache.fop.layoutmgr.inline.InlineLayoutManager;
import org.apache.fop.layoutmgr.inline.InlineLevelLayoutManager;
import org.apache.fop.layoutmgr.inline.LineLayoutManager;
import org.apache.fop.traits.MinOptMax;
import org.apache.fop.traits.SpaceVal;
+import org.axsl.fontR.FontConsumer;
+import org.axsl.fontR.FontUse;
+
/**
* LayoutManager for a block FO.
*/
@@ -71,12 +73,14 @@
public void initialize() {
super.initialize();
- Font fs = getBlockFO().getCommonFont().getFontState(
- getBlockFO().getFOEventHandler().getFontInfo(), this);
+ FontConsumer fontConsumer = getBlockFO().getFOEventHandler().getFontConsumer();
+ FontUse fontUse = getBlockFO().getCommonFont().getFontState(
+ fontConsumer, this);
+ int fontSize = getBlockFO().getCommonFont().getFontSize(this);
- lead = fs.getAscender();
- follow = -fs.getDescender();
- middleShift = -fs.getXHeight() / 2;
+ lead = fontUse.getFont().getAscender(fontSize);
+ follow = -fontUse.getFont().getDescender(fontSize);
+ middleShift = -fontUse.getFont().getXHeight(fontSize) / 2;
lineHeight = getBlockFO().getLineHeight().getOptimum(this).getLength();
startIndent = getBlockFO().getCommonMarginBlock().startIndent.getValue(this);
endIndent = getBlockFO().getCommonMarginBlock().endIndent.getValue(this);
diff --git a/src/java/org/apache/fop/layoutmgr/TraitSetter.java b/src/java/org/apache/fop/layoutmgr/TraitSetter.java
index 2742041..0bf7072 100644
--- a/src/java/org/apache/fop/layoutmgr/TraitSetter.java
+++ b/src/java/org/apache/fop/layoutmgr/TraitSetter.java
@@ -32,9 +32,7 @@
import org.apache.fop.fo.properties.CommonMarginBlock;
import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
import org.apache.fop.fo.properties.CommonTextDecoration;
-import org.apache.fop.fonts.Font;
-import org.apache.fop.fonts.FontInfo;
-import org.apache.fop.fonts.FontTriplet;
+import org.axsl.fontR.FontUse;
/**
* This is a helper class used for setting common traits on areas.
@@ -468,9 +466,9 @@
* @param area the target are
* @param font the font to use
*/
- public static void addFontTraits(Area area, Font font) {
- area.addTrait(Trait.FONT, font.getFontTriplet());
- area.addTrait(Trait.FONT_SIZE, new Integer(font.getFontSize()));
+ public static void addFontTraits(Area area, FontUse fontUse, int fontSize) {
+ area.addTrait(Trait.FONT, fontUse);
+ area.addTrait(Trait.FONT_SIZE, new Integer(fontSize));
}
/**
diff --git a/src/java/org/apache/fop/layoutmgr/inline/AlignmentContext.java b/src/java/org/apache/fop/layoutmgr/inline/AlignmentContext.java
index ac1e12a..9122ed4 100644
--- a/src/java/org/apache/fop/layoutmgr/inline/AlignmentContext.java
+++ b/src/java/org/apache/fop/layoutmgr/inline/AlignmentContext.java
@@ -23,7 +23,8 @@
import org.apache.fop.datatypes.LengthBase;
import org.apache.fop.datatypes.SimplePercentBaseContext;
import org.apache.fop.fo.Constants;
-import org.apache.fop.fonts.Font;
+
+import org.axsl.fontR.Font;
/**
* The alignment context is carried within a LayoutContext and as
@@ -110,6 +111,7 @@
/**
* Creates a new instance of AlignmentContext
* @param font the font
+ * @param fontSize the font size in millipoints
* @param lineHeight the computed value of the lineHeight property
* @param alignmentAdjust the alignment-adjust property
* @param alignmentBaseline the alignment-baseline property
@@ -118,17 +120,18 @@
* @param parentAlignmentContext the parent alignment context
*/
public AlignmentContext(Font font
+ , int fontSize
, int lineHeight
, Length alignmentAdjust
, int alignmentBaseline
, Length baselineShift
, int dominantBaseline
, AlignmentContext parentAlignmentContext) {
- this.areaHeight = font.getAscender() - font.getDescender();
+ this.areaHeight = font.getAscender(fontSize) - font.getDescender(fontSize);
this.lineHeight = lineHeight;
this.parentAlignmentContext = parentAlignmentContext;
this.scaledBaselineTable = parentAlignmentContext.getScaledBaselineTable();
- this.xHeight = font.getXHeight();
+ this.xHeight = font.getXHeight(fontSize);
setAlignmentBaselineIdentifier(alignmentBaseline
, parentAlignmentContext.getDominantBaselineIdentifier());
setBaselineShift(baselineShift);
@@ -153,11 +156,13 @@
dominantBaselineIdentifier = dominantBaseline;
break;
}
- actualBaselineTable = ScaledBaselineTableFactory.makeFontScaledBaselineTable(font,
+ actualBaselineTable = ScaledBaselineTableFactory.makeFontScaledBaselineTable(font,
+ fontSize,
dominantBaselineIdentifier,
scaledBaselineTable.getWritingMode());
if (newScaledBaselineTableRequired) {
- scaledBaselineTable = ScaledBaselineTableFactory.makeFontScaledBaselineTable(font,
+ scaledBaselineTable = ScaledBaselineTableFactory.makeFontScaledBaselineTable(font,
+ fontSize,
dominantBaselineIdentifier,
scaledBaselineTable.getWritingMode());
}
@@ -168,19 +173,20 @@
* Creates a new instance of AlignmentContext based simply
* on the font and the writing mode.
* @param font the font
+ * @param fontSize the font size in millipoints
* @param lineHeight the computed value of the lineHeight property
* @param writingMode the current writing mode
*/
- public AlignmentContext(Font font, int lineHeight, int writingMode) {
- this.areaHeight = font.getAscender() - font.getDescender();
+ public AlignmentContext(Font font, int fontSize, int lineHeight, int writingMode) {
+ this.areaHeight = font.getAscender(fontSize) - font.getDescender(fontSize);
this.lineHeight = lineHeight;
- this.xHeight = font.getXHeight();
+ this.xHeight = font.getXHeight(fontSize);
this.parentAlignmentContext = null;
- this.scaledBaselineTable
- = ScaledBaselineTableFactory.makeFontScaledBaselineTable(font, writingMode);
+ this.scaledBaselineTable = ScaledBaselineTableFactory.
+ makeFontScaledBaselineTable(font, fontSize, writingMode);
this.actualBaselineTable = scaledBaselineTable;
this.alignmentBaselineIdentifier = getDominantBaselineIdentifier();
- this.alignmentPoint = font.getAscender();
+ this.alignmentPoint = font.getAscender(fontSize);
this.baselineShiftValue = 0;
}
diff --git a/src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java
index 26dc8c3..eae681e 100644
--- a/src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java
@@ -20,7 +20,7 @@
package org.apache.fop.layoutmgr.inline;
import org.apache.fop.fo.flow.Character;
-import org.apache.fop.fonts.Font;
+import org.apache.fop.fo.properties.CommonFont;
import org.apache.fop.layoutmgr.InlineKnuthSequence;
import org.apache.fop.layoutmgr.KnuthElement;
import org.apache.fop.layoutmgr.KnuthGlue;
@@ -40,6 +40,10 @@
import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
import org.apache.fop.layoutmgr.inline.AlignmentContext;
+import org.axsl.fontR.Font;
+import org.axsl.fontR.FontConsumer;
+import org.axsl.fontR.FontUse;
+
/**
* LayoutManager for the fo:character formatting object
*/
@@ -47,7 +51,10 @@
private Character fobj;
private MinOptMax letterSpaceIPD;
private int hyphIPD;
- private Font font;
+ private FontUse fontUse;
+ private FontConsumer fontConsumer;
+ /** Font size in millipoints */
+ private int fontSize;
private CommonBorderPaddingBackground borderProps = null;
/**
@@ -63,14 +70,18 @@
/** @see org.apache.fop.layoutmgr.LayoutManager#initialize */
public void initialize() {
- font = fobj.getCommonFont().getFontState(fobj.getFOEventHandler().getFontInfo(), this);
+ fontConsumer = fobj.getFOEventHandler().getFontConsumer();
+ CommonFont commonFont = fobj.getCommonFont();
+ fontUse = commonFont.getFontState(fontConsumer, this);
+ fontSize = commonFont.getFontSize(this);
SpaceVal ls = SpaceVal.makeLetterSpacing(fobj.getLetterSpacing());
letterSpaceIPD = ls.getSpace();
- hyphIPD = font.getCharWidth(fobj.getCommonHyphenation().hyphenationCharacter);
+ hyphIPD = fontUse.getFont().width(fobj.getCommonHyphenation().hyphenationCharacter,
+ fontSize);
borderProps = fobj.getCommonBorderPaddingBackground();
setCommonBorderPaddingBackground(borderProps);
org.apache.fop.area.inline.TextArea chArea = getCharacterInlineArea(fobj);
- chArea.setBaselineOffset(font.getAscender());
+ chArea.setBaselineOffset(fontUse.getFont().getAscender(fontSize));
setCurrentArea(chArea);
}
@@ -99,17 +110,21 @@
return null;
}
- ipd = new MinOptMax(font.getCharWidth(fobj.getCharacter()));
+ Font font = fontUse.getFont();
+ char curChar = fobj.getCharacter();
+ ipd = new MinOptMax(font.width(curChar, fontSize));
+ fontUse.registerCharUsed(curChar);
curArea.setIPD(ipd.opt);
- curArea.setBPD(font.getAscender() - font.getDescender());
+ curArea.setBPD(font.getAscender(fontSize) - font.getDescender(fontSize));
- TraitSetter.addFontTraits(curArea, font);
+ TraitSetter.addFontTraits(curArea, fontUse, fontSize);
curArea.addTrait(Trait.COLOR, fobj.getColor());
// TODO: may need some special handling for fo:character
alignmentContext = new AlignmentContext(font
- , font.getFontSize()
+ , fontSize
+ , fontSize
, fobj.getAlignmentAdjust()
, fobj.getAlignmentBaseline()
, fobj.getBaselineShift()
diff --git a/src/java/org/apache/fop/layoutmgr/inline/ExternalGraphicLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/ExternalGraphicLayoutManager.java
index ecdbd68..98128ad 100644
--- a/src/java/org/apache/fop/layoutmgr/inline/ExternalGraphicLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/inline/ExternalGraphicLayoutManager.java
@@ -19,7 +19,6 @@
package org.apache.fop.layoutmgr.inline;
-import java.awt.geom.Rectangle2D;
import org.apache.fop.area.Area;
import org.apache.fop.area.inline.Image;
import org.apache.fop.fo.flow.ExternalGraphic;
diff --git a/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java
index d3d5868..c31e58b 100755
--- a/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java
@@ -35,7 +35,6 @@
import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
import org.apache.fop.fo.properties.CommonMarginInline;
import org.apache.fop.fo.properties.SpaceProperty;
-import org.apache.fop.fonts.Font;
import org.apache.fop.layoutmgr.BlockKnuthSequence;
import org.apache.fop.layoutmgr.BlockLevelLayoutManager;
import org.apache.fop.layoutmgr.BreakElement;
@@ -51,6 +50,8 @@
import org.apache.fop.traits.MinOptMax;
import org.apache.fop.traits.SpaceVal;
+import org.axsl.fontR.FontUse;
+
/**
* LayoutManager for objects which stack children in the inline direction,
* such as Inline or Line
@@ -66,7 +67,8 @@
private Position auxiliaryPosition;
- private Font font;
+ private FontUse fontUse;
+ private int fontSize;
/** The alignment adjust property */
protected Length alignmentAdjust;
@@ -101,7 +103,9 @@
/** @see LayoutManager#initialize */
public void initialize() {
int padding = 0;
- font = fobj.getCommonFont().getFontState(fobj.getFOEventHandler().getFontInfo(), this);
+ fontUse = fobj.getCommonFont().getFontState(
+ fobj.getFOEventHandler().getFontConsumer(), this);
+ fontSize = fobj.getCommonFont().getFontSize(this);
lineHeight = fobj.getLineHeight();
borderProps = fobj.getCommonBorderPaddingBackground();
inlineProps = fobj.getCommonMarginInline();
@@ -229,12 +233,13 @@
SpaceSpecifier leadingSpace = context.getLeadingSpace();
if (fobj instanceof Title) {
- alignmentContext = new AlignmentContext(font,
+ alignmentContext = new AlignmentContext(fontUse.getFont(), fontSize,
lineHeight.getOptimum(this).getLength().getValue(this),
context.getWritingMode());
} else {
- alignmentContext = new AlignmentContext(font
+ alignmentContext = new AlignmentContext(fontUse.getFont()
+ , fontSize
, lineHeight.getOptimum(this).getLength().getValue(this)
, alignmentAdjust
, alignmentBaseline
diff --git a/src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java
index 1f47e7c..c4a8b4c 100644
--- a/src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java
@@ -25,7 +25,8 @@
import org.apache.fop.area.inline.Space;
import org.apache.fop.area.inline.TextArea;
import org.apache.fop.fo.flow.Leader;
-import org.apache.fop.fonts.Font;
+import org.apache.fop.fo.FObj;
+import org.apache.fop.fo.properties.CommonFont;
import org.apache.fop.layoutmgr.InlineKnuthSequence;
import org.apache.fop.layoutmgr.KnuthElement;
import org.apache.fop.layoutmgr.KnuthGlue;
@@ -41,15 +42,19 @@
import java.util.List;
import java.util.LinkedList;
-import org.apache.fop.fo.FObj;
+
+import org.axsl.fontR.FontConsumer;
+import org.axsl.fontR.FontUse;
/**
* LayoutManager for the fo:leader formatting object
*/
public class LeaderLayoutManager extends LeafNodeLayoutManager {
private Leader fobj;
- private Font font = null;
-
+ FontUse fontUse = null;
+ private int fontSize;
+ private FontConsumer fontConsumer;
+
private LinkedList contentList = null;
private ContentLayoutManager clm = null;
@@ -67,7 +72,10 @@
/** @see org.apache.fop.layoutmgr.LayoutManager#initialize */
public void initialize() {
- font = fobj.getCommonFont().getFontState(fobj.getFOEventHandler().getFontInfo(), this);
+ fontConsumer = fobj.getFOEventHandler().getFontConsumer();
+ CommonFont commonFont = fobj.getCommonFont();
+ fontUse = commonFont.getFontState(fontConsumer, this);
+ fontSize = commonFont.getFontSize(this);
// the property leader-alignment does not affect vertical positioning
// (see section 7.21.1 in the XSL Recommendation)
// setAlignment(node.getLeaderAlignment());
@@ -131,12 +139,13 @@
TextArea t = new TextArea();
char dot = '.'; // userAgent.getLeaderDotCharacter();
- int width = font.getCharWidth(dot);
+ int width = fontUse.getFont().width(dot, fontSize);
+ fontUse.registerCharUsed(dot);
t.addWord("" + dot, 0);
t.setIPD(width);
t.setBPD(width);
t.setBaselineOffset(width);
- TraitSetter.addFontTraits(t, font);
+ TraitSetter.addFontTraits(t, fontUse, fontSize);
t.addTrait(Trait.COLOR, fobj.getColor());
Space spacer = null;
if (fobj.getLeaderPatternWidth().getValue(this) > width) {
diff --git a/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
index e7571fd..e3c3c97 100644
--- a/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
@@ -49,16 +49,16 @@
import org.apache.fop.layoutmgr.SpaceSpecifier;
import org.apache.fop.area.Area;
import org.apache.fop.area.LineArea;
+import org.apache.fop.area.Trait;
import org.apache.fop.area.inline.InlineArea;
+import org.apache.fop.traits.MinOptMax;
import java.util.ListIterator;
import java.util.List;
import java.util.ArrayList;
import java.util.LinkedList;
-import org.apache.fop.area.Trait;
-import org.apache.fop.fonts.Font;
-import org.apache.fop.traits.MinOptMax;
+import org.axsl.fontR.FontUse;
/**
* LayoutManager for lines. It builds one or more lines containing
@@ -560,9 +560,13 @@
/** @see org.apache.fop.layoutmgr.LayoutManager */
public LinkedList getNextKnuthElements(LayoutContext context, int alignment) {
- Font fs = fobj.getCommonFont().getFontState(fobj.getFOEventHandler().getFontInfo(), this);
- alignmentContext
- = new AlignmentContext(fs, lineHeight.getValue(this), context.getWritingMode());
+ FontUse fontUse = fobj.getCommonFont().getFontState(
+ fobj.getFOEventHandler().getFontConsumer(), this);
+ int fontSize = fobj.getCommonFont().getFontSize(this);
+ alignmentContext = new AlignmentContext(fontUse.getFont(),
+ fontSize,
+ lineHeight.getValue(this),
+ context.getWritingMode());
context.setAlignmentContext(alignmentContext);
// Get a break from currently active child LM
// Set up constraints for inline level managers
diff --git a/src/java/org/apache/fop/layoutmgr/inline/PageNumberCitationLastLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/PageNumberCitationLastLayoutManager.java
index b507c39..8d45596 100644
--- a/src/java/org/apache/fop/layoutmgr/inline/PageNumberCitationLastLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/inline/PageNumberCitationLastLayoutManager.java
@@ -27,6 +27,7 @@
import org.apache.fop.area.inline.TextArea;
import org.apache.fop.layoutmgr.LayoutContext;
import org.apache.fop.layoutmgr.LayoutManager;
+import org.axsl.fontR.FontConsumer;
/**
* LayoutManager for the fo:page-number-citation-last formatting object
@@ -60,7 +61,8 @@
TextArea text = null;
resolved = false;
if (!getPSLM().associateLayoutManagerID(fobj.getRefId())) {
- text = new UnresolvedPageNumber(fobj.getRefId(), font, UnresolvedPageNumber.LAST);
+ text = new UnresolvedPageNumber(fobj.getRefId(), fontConsumer, fontUse, fontSize,
+ UnresolvedPageNumber.LAST);
getPSLM().addUnresolvedArea(fobj.getRefId(), (Resolvable)text);
String str = "MMM"; // reserve three spaces for page number
int width = getStringWidth(str);
diff --git a/src/java/org/apache/fop/layoutmgr/inline/PageNumberCitationLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/PageNumberCitationLayoutManager.java
index 8ab338e..ec1ba8b 100644
--- a/src/java/org/apache/fop/layoutmgr/inline/PageNumberCitationLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/inline/PageNumberCitationLayoutManager.java
@@ -20,26 +20,31 @@
package org.apache.fop.layoutmgr.inline;
import org.apache.fop.fo.flow.PageNumberCitation;
+import org.apache.fop.fo.properties.CommonFont;
import org.apache.fop.area.PageViewport;
import org.apache.fop.area.Resolvable;
import org.apache.fop.area.Trait;
import org.apache.fop.area.inline.InlineArea;
import org.apache.fop.area.inline.UnresolvedPageNumber;
import org.apache.fop.area.inline.TextArea;
-import org.apache.fop.fonts.Font;
import org.apache.fop.layoutmgr.LayoutContext;
import org.apache.fop.layoutmgr.LayoutManager;
import org.apache.fop.layoutmgr.PositionIterator;
import org.apache.fop.layoutmgr.TraitSetter;
+import org.axsl.fontR.Font;
+import org.axsl.fontR.FontConsumer;
+import org.axsl.fontR.FontUse;
+
/**
* LayoutManager for the fo:page-number-citation formatting object
*/
public class PageNumberCitationLayoutManager extends LeafNodeLayoutManager {
private PageNumberCitation fobj;
- /** Font for the page-number-citation */
- protected Font font;
+ FontConsumer fontConsumer;
+ FontUse fontUse;
+ int fontSize;
/** Indicates whether the page referred to by the citation has been resolved yet */
protected boolean resolved = false;
@@ -57,7 +62,10 @@
/** @see org.apache.fop.layoutmgr.LayoutManager#initialize */
public void initialize() {
- font = fobj.getCommonFont().getFontState(fobj.getFOEventHandler().getFontInfo(), this);
+ fontConsumer = fobj.getFOEventHandler().getFontConsumer();
+ CommonFont commonFont = fobj.getCommonFont();
+ fontUse = commonFont.getFontState(fontConsumer, this);
+ fontSize = commonFont.getFontSize(this);
setCommonBorderPaddingBackground(fobj.getCommonBorderPaddingBackground());
}
@@ -66,7 +74,8 @@
*/
protected AlignmentContext makeAlignmentContext(LayoutContext context) {
return new AlignmentContext(
- font
+ fontUse.getFont()
+ , fontSize
, fobj.getLineHeight().getOptimum(this).getLength().getValue(this)
, fobj.getAlignmentAdjust()
, fobj.getAlignmentBaseline()
@@ -110,7 +119,7 @@
resolved = true;
} else {
resolved = false;
- text = new UnresolvedPageNumber(fobj.getRefId(), font);
+ text = new UnresolvedPageNumber(fobj.getRefId(), fontConsumer, fontUse, fontSize);
String str = "MMM"; // reserve three spaces for page number
int width = getStringWidth(str);
text.setIPD(width);
@@ -126,9 +135,10 @@
*/
protected void updateTextAreaTraits(TextArea text) {
TraitSetter.setProducerID(text, fobj.getId());
- text.setBPD(font.getAscender() - font.getDescender());
- text.setBaselineOffset(font.getAscender());
- TraitSetter.addFontTraits(text, font);
+ Font font = fontUse.getFont();
+ text.setBPD(font.getAscender(fontSize) - font.getDescender(fontSize));
+ text.setBaselineOffset(font.getAscender(fontSize));
+ TraitSetter.addFontTraits(text, fontUse, fontSize);
text.addTrait(Trait.COLOR, fobj.getColor());
TraitSetter.addTextDecoration(text, fobj.getTextDecoration());
}
@@ -138,9 +148,10 @@
* @return width (in millipoints ??) of the string
*/
protected int getStringWidth(String str) {
+ fontUse.registerCharsUsed(str);
int width = 0;
for (int count = 0; count < str.length(); count++) {
- width += font.getCharWidth(str.charAt(count));
+ width += fontUse.getFont().width(str.charAt(count), fontSize);
}
return width;
}
diff --git a/src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java
index ff751bc..d902152 100644
--- a/src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java
@@ -20,22 +20,28 @@
package org.apache.fop.layoutmgr.inline;
import org.apache.fop.fo.flow.PageNumber;
+import org.apache.fop.fo.properties.CommonFont;
import org.apache.fop.area.inline.InlineArea;
import org.apache.fop.area.inline.TextArea;
import org.apache.fop.area.Trait;
-import org.apache.fop.fonts.Font;
import org.apache.fop.layoutmgr.LayoutContext;
import org.apache.fop.layoutmgr.TraitSetter;
import org.apache.fop.traits.MinOptMax;
+import org.axsl.fontR.Font;
+import org.axsl.fontR.FontConsumer;
+import org.axsl.fontR.FontUse;
+
/**
* LayoutManager for the fo:page-number formatting object
*/
public class PageNumberLayoutManager extends LeafNodeLayoutManager {
private PageNumber fobj;
- private Font font;
-
+ private FontConsumer fontConsumer;
+ private FontUse fontUse;
+ private int fontSize;
+
/**
* Constructor
*
@@ -49,7 +55,10 @@
/** @see org.apache.fop.layoutmgr.inline.LeafNodeLayoutManager#get(LayoutContext) */
public void initialize() {
- font = fobj.getCommonFont().getFontState(fobj.getFOEventHandler().getFontInfo(), this);
+ fontConsumer = fobj.getFOEventHandler().getFontConsumer();
+ CommonFont commonFont = fobj.getCommonFont();
+ fontUse = commonFont.getFontState(fontConsumer, this);
+ fontSize = commonFont.getFontSize(this);
setCommonBorderPaddingBackground(fobj.getCommonBorderPaddingBackground());
}
@@ -59,7 +68,8 @@
*/
protected AlignmentContext makeAlignmentContext(LayoutContext context) {
return new AlignmentContext(
- font
+ fontUse.getFont()
+ , fontSize
, fobj.getLineHeight().getOptimum(this).getLength().getValue(this)
, fobj.getAlignmentAdjust()
, fobj.getAlignmentBaseline()
@@ -75,11 +85,13 @@
TextArea text = new TextArea();
String str = getCurrentPV().getPageNumberString();
int width = getStringWidth(str);
+ fontUse.registerCharsUsed(str);
text.addWord(str, 0);
text.setIPD(width);
- text.setBPD(font.getAscender() - font.getDescender());
- text.setBaselineOffset(font.getAscender());
- TraitSetter.addFontTraits(text, font);
+ Font f = fontUse.getFont();
+ text.setBPD(f.getAscender(fontSize) - f.getDescender(fontSize));
+ text.setBaselineOffset(f.getAscender(fontSize));
+ TraitSetter.addFontTraits(text, fontUse, fontSize);
text.addTrait(Trait.COLOR, fobj.getColor());
TraitSetter.addTextDecoration(text, fobj.getTextDecoration());
@@ -121,8 +133,9 @@
*/
private int getStringWidth(String str) {
int width = 0;
+ Font f = fontUse.getFont();
for (int count = 0; count < str.length(); count++) {
- width += font.getCharWidth(str.charAt(count));
+ width += f.width(str.charAt(count), fontSize);
}
return width;
}
diff --git a/src/java/org/apache/fop/layoutmgr/inline/ScaledBaselineTableFactory.java b/src/java/org/apache/fop/layoutmgr/inline/ScaledBaselineTableFactory.java
index e47f107..4cb1b7c 100644
--- a/src/java/org/apache/fop/layoutmgr/inline/ScaledBaselineTableFactory.java
+++ b/src/java/org/apache/fop/layoutmgr/inline/ScaledBaselineTableFactory.java
@@ -20,7 +20,8 @@
package org.apache.fop.layoutmgr.inline;
import org.apache.fop.fo.Constants;
-import org.apache.fop.fonts.Font;
+
+import org.axsl.fontR.Font;
/**
@@ -34,26 +35,31 @@
* Creates a new instance of BasicScaledBaselineTable for the given
* font, baseline and writingmode.
* @param font the font for which a baseline table is requested
+ * @param fontSize the font size
* @param dominantBaselineIdentifier the dominant baseline given as an integer constant
* @param writingMode the writing mode given as an integer constant
* @return a scaled baseline table for the given font
*/
public static ScaledBaselineTable makeFontScaledBaselineTable(Font font
+ , int fontSize
, int dominantBaselineIdentifier
, int writingMode) {
- return new BasicScaledBaselineTable(font.getAscender(), font.getDescender()
- , font.getXHeight(), dominantBaselineIdentifier, writingMode);
+ return new BasicScaledBaselineTable(font.getAscender(fontSize), font.getDescender(fontSize),
+ font.getXHeight(fontSize), dominantBaselineIdentifier, writingMode);
}
/**
* Creates a new instance of BasicScaledBaselineTable for the given
* font and writingmode. It assumes an alphabetic baseline.
* @param font the font for which a baseline table is requested
+ * @param fontSize the font size
* @param writingMode the writing mode given as an integer constant
* @return a scaled baseline table for the given font
*/
- public static ScaledBaselineTable makeFontScaledBaselineTable(Font font, int writingMode) {
- return makeFontScaledBaselineTable(font, EN_ALPHABETIC, writingMode);
+ public static ScaledBaselineTable makeFontScaledBaselineTable(Font font
+ , int fontSize
+ , int writingMode) {
+ return makeFontScaledBaselineTable(font, fontSize, EN_ALPHABETIC, writingMode);
}
/**
diff --git a/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java
index 35a298d..621899b 100644
--- a/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java
@@ -29,7 +29,7 @@
import org.apache.fop.fo.Constants;
import org.apache.fop.fo.FOText;
import org.apache.fop.fo.flow.Inline;
-import org.apache.fop.fonts.Font;
+import org.apache.fop.fo.properties.CommonFont;
import org.apache.fop.layoutmgr.InlineKnuthSequence;
import org.apache.fop.layoutmgr.KnuthBox;
import org.apache.fop.layoutmgr.KnuthElement;
@@ -45,6 +45,10 @@
import org.apache.fop.traits.SpaceVal;
import org.apache.fop.util.CharUtilities;
+import org.axsl.fontR.Font;
+import org.axsl.fontR.FontConsumer;
+import org.axsl.fontR.FontUse;
+
/**
* LayoutManager for text (a sequence of characters) which generates one
* or more inline areas.
@@ -121,7 +125,6 @@
private static final char NEWLINE = '\n';
- private Font font = null;
/** Start index of first character in this parent Area */
private short iAreaStart = 0;
/** Start index of next TextArea */
@@ -145,6 +148,11 @@
/** Number of space characters after previous possible break position. */
private int iNbSpacesPending;
+ private FontUse fontUse;
+ private Font font;
+ private FontConsumer fontConsumer;
+ private int fontSize;
+
private boolean bChanged = false;
private int iReturnedIndex = 0;
private short iThisStart = 0;
@@ -175,18 +183,26 @@
/** @see org.apache.fop.layoutmgr.LayoutManager#initialize */
public void initialize() {
- font = foText.getCommonFont().getFontState(foText.getFOEventHandler().getFontInfo(), this);
+ fontConsumer = foText.getFOEventHandler().getFontConsumer();
+ CommonFont commonFont = foText.getCommonFont();
+ fontUse = commonFont.getFontState(fontConsumer, this);
+ font = fontUse.getFont();
+ fontSize = commonFont.getFontSize(this);
+ // Register the characters of this text note for later font embedding
+ for (int i = 0; i < textArray.length; i++) {
+ fontUse.registerCharUsed(textArray[i]);
+ }
// With CID fonts, space isn't neccesary currentFontState.width(32)
- spaceCharIPD = font.getCharWidth(' ');
+ spaceCharIPD = font.width(' ', fontSize);
// Use hyphenationChar property
- hyphIPD = font.getCharWidth(foText.getCommonHyphenation().hyphenationCharacter);
+ hyphIPD = font.width(foText.getCommonHyphenation().hyphenationCharacter, fontSize);
SpaceVal ls = SpaceVal.makeLetterSpacing(foText.getLetterSpacing());
halfLS = new SpaceVal(MinOptMax.multiply(ls.getSpace(), 0.5),
ls.isConditional(), ls.isForcing(), ls.getPrecedence());
- ws = SpaceVal.makeWordSpacing(foText.getWordSpacing(), ls, font);
+ ws = SpaceVal.makeWordSpacing(foText.getWordSpacing(), ls, font, fontConsumer, fontSize);
// Make half-space: <space> on either side of a word-space)
halfWS = new SpaceVal(MinOptMax.multiply(ws.getSpace(), 0.5),
ws.isConditional(), ws.isForcing(), ws.getPrecedence());
@@ -256,7 +272,7 @@
for (; iNextStart < iStopIndex; iNextStart++) {
char c = textArray[iNextStart];
- hyphIPD.opt += font.getCharWidth(c);
+ hyphIPD.opt += font.width(c, fontSize);
// letter-space?
}
// Need to include hyphen size too, but don't count it in the
@@ -325,6 +341,9 @@
// add hyphenation character if the last word is hyphenated
if (context.isLastArea() && ai.bHyphenated) {
+ // TODO vh: perhaps not the better place to register the hyphenation
+ // character for embedding
+ fontUse.registerCharUsed(foText.getCommonHyphenation().hyphenationCharacter);
realWidth.add(new MinOptMax(hyphIPD));
}
@@ -431,8 +450,8 @@
adjust);
}
textArea.setIPD(width.opt + adjust);
- textArea.setBPD(font.getAscender() - font.getDescender());
- textArea.setBaselineOffset(font.getAscender());
+ textArea.setBPD(font.getAscender(fontSize) - font.getDescender(fontSize));
+ textArea.setBaselineOffset(font.getAscender(fontSize));
if (textArea.getBPD() == alignmentContext.getHeight()) {
textArea.setOffset(0);
} else {
@@ -486,7 +505,7 @@
}
}
}
- TraitSetter.addFontTraits(textArea, font);
+ TraitSetter.addFontTraits(textArea, fontUse, fontSize);
textArea.addTrait(Trait.COLOR, foText.getColor());
TraitSetter.addTextDecoration(textArea, foText.getTextDecoration());
@@ -575,7 +594,7 @@
iNextStart++;
} else if (CharUtilities.isFixedWidthSpace(ch)) {
// create the AreaInfo object
- MinOptMax ipd = new MinOptMax(font.getCharWidth(ch));
+ MinOptMax ipd = new MinOptMax(font.width(ch, fontSize));
ai = new AreaInfo(iNextStart, (short) (iNextStart + 1),
(short) 0, (short) 0,
ipd, false, true);
@@ -616,20 +635,21 @@
//Word boundary found, process widths and kerning
int wordLength = iTempStart - iThisStart;
- boolean kerning = font.hasKerning();
+ // TODO vh: info no longer available; impact on performance?
+// boolean kerning = font.hasKerning();
MinOptMax wordIPD = new MinOptMax(0);
for (int i = iThisStart; i < iTempStart; i++) {
char c = textArray[i];
//character width
- int charWidth = font.getCharWidth(c);
+ int charWidth = font.width(c, fontSize);
wordIPD.add(charWidth);
//kerning
int kern = 0;
- if (kerning && (i > iThisStart)) {
+ if (/*kerning && */(i > iThisStart)) {
char previous = textArray[i - 1];
- kern = font.getKernValue(previous, c) * font.getFontSize() / 1000;
+ kern = font.kern(previous, c) * fontSize / 1000;
if (kern != 0) {
//log.info("Kerning between " + previous + " and " + c + ": " + kern);
addToLetterAdjust(i, kern);
@@ -771,7 +791,7 @@
//log.info("Word: " + new String(textArray, iStartIndex, iStopIndex - iStartIndex));
for (int i = iStartIndex; i < iStopIndex; i++) {
char c = textArray[i];
- newIPD.add(new MinOptMax(font.getCharWidth(c)));
+ newIPD.add(new MinOptMax(font.width(c, fontSize)));
//if (i > iStartIndex) {
if (i < iStopIndex) {
MinOptMax la = this.letterAdjustArray[i + 1];
diff --git a/src/java/org/apache/fop/pdf/PDFDocument.java b/src/java/org/apache/fop/pdf/PDFDocument.java
index 4ce82fa..db2b258 100644
--- a/src/java/org/apache/fop/pdf/PDFDocument.java
+++ b/src/java/org/apache/fop/pdf/PDFDocument.java
@@ -29,9 +29,9 @@
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Iterator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
diff --git a/src/java/org/apache/fop/pdf/PDFFactory.java b/src/java/org/apache/fop/pdf/PDFFactory.java
index 77c25bc..08b1382 100644
--- a/src/java/org/apache/fop/pdf/PDFFactory.java
+++ b/src/java/org/apache/fop/pdf/PDFFactory.java
@@ -36,26 +36,20 @@
import org.w3c.dom.Document;
// Apache libs
-import org.apache.commons.io.IOUtils;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
// FOP
-import org.apache.fop.fonts.CIDFont;
-import org.apache.fop.fonts.CustomFont;
-import org.apache.fop.fonts.Typeface;
-import org.apache.fop.fonts.FontDescriptor;
-import org.apache.fop.fonts.FontMetrics;
-import org.apache.fop.fonts.FontType;
-import org.apache.fop.fonts.LazyFont;
-import org.apache.fop.fonts.MultiByteFont;
-import org.apache.fop.fonts.truetype.FontFileReader;
-import org.apache.fop.fonts.truetype.TTFSubSetFile;
-import org.apache.fop.fonts.type1.PFBData;
-import org.apache.fop.fonts.type1.PFBParser;
+import org.apache.fop.fonts.CIDFontType;
import org.apache.xmlgraphics.xmp.Metadata;
+// FOray
+import org.axsl.fontR.Font;
+import org.axsl.fontR.FontConsumer;
+import org.axsl.fontR.FontUse;
+import org.axsl.fontR.output.FontPDF;
+
/**
* This class provides method to create and register PDF objects.
*/
@@ -988,292 +982,278 @@
}
/**
- * make a Type1 /Font object
+ * make a Type1 /Font object.
*
- * @param fontname internal name to use for this font (eg "F1")
- * @param basefont name of the base font (eg "Helvetica")
- * @param encoding character encoding scheme used by the font
- * @param metrics additional information about the font
- * @param descriptor additional information about the font
+ * @param fontUse the font
+ * @param internalName internal name of the font
+ * @param fontConsumer associated font consumer
* @return the created /Font object
*/
- public PDFFont makeFont(String fontname, String basefont,
- String encoding, FontMetrics metrics,
- FontDescriptor descriptor) {
- PDFFont preRegisteredfont = getDocument().findFont(fontname);
+ public PDFFont makeFont(FontUse fontUse, String internalName, FontConsumer fontConsumer) {
+ PDFFont preRegisteredfont = getDocument().findFont(internalName);
if (preRegisteredfont != null) {
return preRegisteredfont;
}
- if (descriptor == null) {
- PDFFont font = new PDFFont(fontname, FontType.TYPE1, basefont, encoding);
- getDocument().registerObject(font);
- return font;
+ Font font = fontUse.getFont();
+ PDFFont pdfFont;
+ if (font.isPDFStandardFont()) {
+ pdfFont = new PDFFont(internalName, PDFFont.TYPE1,
+ font.getPostscriptName(), fontUse.getEncoding().getName());
+ getDocument().registerObject(pdfFont);
} else {
- FontType fonttype = metrics.getFontType();
-
- PDFFontDescriptor pdfdesc = makeFontDescriptor(descriptor);
-
- PDFFontNonBase14 font = null;
- if (fonttype == FontType.TYPE0) {
- /*
- * Temporary commented out - customized CMaps
- * isn't needed until /ToUnicode support is added
- * PDFCMap cmap = new PDFCMap(++this.objectcount,
- * "fop-ucs-H",
- * new PDFCIDSystemInfo("Adobe",
- * "Identity",
- * 0));
- * cmap.addContents();
- * this.objects.add(cmap);
- */
- font =
- (PDFFontNonBase14)PDFFont.createFont(fontname, fonttype,
- basefont,
- "Identity-H");
+ byte fontSubType;
+ if (font.getFontComplexity() == Font.FONT_COMPOSITE) {
+ fontSubType = PDFFont.TYPE0;
+ } else if (font.getFontFormat() == Font.FORMAT_TYPE1) {
+ fontSubType = PDFFont.TYPE1;
+ } else if (font.getFontFormat() == Font.FORMAT_TRUETYPE) {
+ fontSubType = PDFFont.TRUETYPE;
} else {
-
- font =
- (PDFFontNonBase14)PDFFont.createFont(fontname, fonttype,
- basefont, encoding);
+ fontSubType = PDFFont.OTHER;
}
- getDocument().registerObject(font);
+ if (fontSubType == PDFFont.TYPE0) {
+ pdfFont = PDFFont.createFont(internalName, fontSubType,
+ font.getPostscriptName(), "Identity-H"/*fontUse.getEncoding().getName() TODO vh*/);
+ } else {
+ pdfFont = PDFFont.createFont(internalName, fontSubType,
+ font.getPostscriptName(), fontUse.getEncoding().getName());
+ }
+ getDocument().registerObject(pdfFont);
+
+ PDFFontDescriptor pdfdesc = makeFontDescriptor(fontUse, fontSubType, fontConsumer);
+ ((PDFFontNonBase14)pdfFont).setDescriptor(pdfdesc);
- font.setDescriptor(pdfdesc);
-
- if (fonttype == FontType.TYPE0) {
- CIDFont cidMetrics;
- if (metrics instanceof LazyFont) {
- cidMetrics = (CIDFont)((LazyFont) metrics).getRealFont();
- } else {
- cidMetrics = (CIDFont)metrics;
- }
- PDFCIDSystemInfo sysInfo =
- new PDFCIDSystemInfo(cidMetrics.getRegistry(),
- cidMetrics.getOrdering(),
- cidMetrics.getSupplement());
- PDFCIDFont cidFont =
- new PDFCIDFont(basefont,
- cidMetrics.getCIDType(),
- cidMetrics.getDefaultWidth(),
- getSubsetWidths(cidMetrics), sysInfo,
- (PDFCIDFontDescriptor)pdfdesc);
+ if (fontSubType == PDFFont.TYPE0) {
+ PDFCIDSystemInfo sysInfo = new PDFCIDSystemInfo("Adobe", "UCS", 0);
+ // TODO vh: does not work yet
+// PDFCMap cmap = new PDFCMap("Identity-H", sysInfo);
+// getDocument().registerObject(cmap);
+ PDFCIDFont cidFont = new PDFCIDFont(font.getPostscriptName(),
+ CIDFontType.CIDTYPE2,
+ font.getDefaultWidth(),
+ getSubsetWidths((FontPDF)fontUse.getFontOutput("application/pdf")), sysInfo,
+ (PDFCIDFontDescriptor) pdfdesc);
getDocument().registerObject(cidFont);
-
- ((PDFFontType0)font).setDescendantFonts(cidFont);
+// ((PDFFontType0) pdfFont).setCMAP(cmap);
+ ((PDFFontType0) pdfFont).setDescendantFonts(cidFont);
} else {
- int firstChar = 0;
- int lastChar = 255;
- if (metrics instanceof CustomFont) {
- CustomFont cf = (CustomFont)metrics;
- firstChar = cf.getFirstChar();
- lastChar = cf.getLastChar();
- }
- font.setWidthMetrics(firstChar,
- lastChar,
- makeArray(metrics.getWidths()));
+ FontPDF fontOutput = (FontPDF)fontUse.getFontOutput("application/pdf");/*TODO vh*/
+ int firstChar = fontOutput.getFirstIndex();
+ int lastChar = fontOutput.getLastIndex();
+ int[] widths = shortArrayToIntArray(fontOutput.getWidths());
+ ((PDFFontNonBase14)pdfFont).setWidthMetrics(firstChar, lastChar,
+ makeArray(widths));
}
-
- return font;
}
+ return pdfFont;
}
- public PDFWArray getSubsetWidths(CIDFont cidFont) {
+ public PDFWArray getSubsetWidths(FontPDF fontOutput) {
// Create widths for reencoded chars
+ // TODO vh: for now fonts aren't subsetted (I think)
PDFWArray warray = new PDFWArray();
- int[] tmpWidth = new int[cidFont.usedGlyphsCount];
-
- for (int i = 0; i < cidFont.usedGlyphsCount; i++) {
- Integer nw = (Integer)cidFont.usedGlyphsIndex.get(new Integer(i));
- int nwx = (nw == null) ? 0 : nw.intValue();
- tmpWidth[i] = cidFont.width[nwx];
- }
- warray.addEntry(0, tmpWidth);
+ warray.addEntry(0, shortArrayToIntArray(fontOutput.getWidths()));
return warray;
+// // Create widths for reencoded chars
+// PDFWArray warray = new PDFWArray();
+// int[] tmpWidth = new int[cidFont.usedGlyphsCount];
+//
+// for (int i = 0; i < cidFont.usedGlyphsCount; i++) {
+// Integer nw = (Integer)cidFont.usedGlyphsIndex.get(new Integer(i));
+// int nwx = (nw == null) ? 0 : nw.intValue();
+// tmpWidth[i] = cidFont.width[nwx];
+// }
+// warray.addEntry(0, tmpWidth);
+// return warray;
}
/**
- * make a /FontDescriptor object
+ * make a /FontDescriptor object.
*
- * @param desc the font descriptor
+ * @param fontUse the corresponding font use
+ * @param subType the font subtype; one of PDFFont.TYPE0, TYPE1, MMTYPE1, TYPE3, TRUETYPE
+ * @param fontConsumer the associated font consumer
* @return the new PDF font descriptor
*/
- public PDFFontDescriptor makeFontDescriptor(FontDescriptor desc) {
- PDFFontDescriptor descriptor = null;
-
- if (desc.getFontType() == FontType.TYPE0) {
+ public PDFFontDescriptor makeFontDescriptor(FontUse fontUse, byte subType,
+ FontConsumer fontConsumer) {
+ PDFFontDescriptor descriptor;
+ FontPDF font = (FontPDF)fontUse.getFontOutput("application/pdf");
+ if (subType == PDFFont.TYPE0) {
// CID Font
- descriptor = new PDFCIDFontDescriptor(desc.getFontName(),
- desc.getFontBBox(),
- desc.getCapHeight(),
- desc.getFlags(),
- desc.getItalicAngle(),
- desc.getStemV(), null);
+ descriptor = new PDFCIDFontDescriptor(fontUse.getPostscriptName(),
+ font.getFontBBox(),
+ fontUse.getFont().getCapHeight(1000),
+ font.getFlags(),
+ (int)fontUse.getFont().getItalicAngle()/*TODO vh*/,
+ fontUse.getFont().getStemV(), null);
} else {
// Create normal FontDescriptor
- descriptor = new PDFFontDescriptor(desc.getFontName(),
- desc.getAscender(),
- desc.getDescender(),
- desc.getCapHeight(),
- desc.getFlags(),
- new PDFRectangle(desc.getFontBBox()),
- desc.getItalicAngle(),
- desc.getStemV());
+ descriptor = new PDFFontDescriptor(fontUse.getPostscriptName(),
+ fontUse.getFont().getAscender(1000),
+ fontUse.getFont().getDescender(1000),
+ fontUse.getFont().getCapHeight(1000),
+ font.getFlags(),
+ new PDFRectangle(font.getFontBBox()),
+ fontUse.getFont().getStemV(),
+ (int)fontUse.getFont().getItalicAngle()/*TODO vh*/);
}
getDocument().registerObject(descriptor);
// Check if the font is embeddable
- if (desc.isEmbeddable()) {
- AbstractPDFStream stream = makeFontFile(desc);
+ if (fontUse.getFont().isEmbeddable()) {
+ AbstractPDFStream stream = makeFontFile(fontUse, fontConsumer);
if (stream != null) {
- descriptor.setFontFile(desc.getFontType(), stream);
+ descriptor.setFontFile(subType, stream);
getDocument().registerObject(stream);
}
- CustomFont font = getCustomFont(desc);
- if (font instanceof CIDFont) {
- CIDFont cidFont = (CIDFont)font;
- buildCIDSet(descriptor, cidFont);
- }
+ // TODO vh: re-enable
+// CustomFont font = getCustomFont(desc);
+// if (font instanceof CIDFont) {
+// CIDFont cidFont = (CIDFont)font;
+// buildCIDSet(descriptor, cidFont);
+// }
}
return descriptor;
}
- private void buildCIDSet(PDFFontDescriptor descriptor, CIDFont cidFont) {
- BitSet cidSubset = new BitSet();
- Iterator iter = cidFont.usedGlyphs.keySet().iterator();
- while (iter.hasNext()) {
- Integer cid = (Integer)iter.next();
- cidSubset.set(cid.intValue());
- }
- PDFStream cidSet = makeStream(null, true);
- ByteArrayOutputStream baout = new ByteArrayOutputStream(cidSubset.length() / 8 + 1);
- int value = 0;
- for (int i = 0, c = cidSubset.length(); i < c; i++) {
- int shift = i % 8;
- boolean b = cidSubset.get(i);
- if (b) {
- value |= 1 << 7 - shift;
- }
- if (shift == 7) {
- baout.write(value);
- value = 0;
- }
- }
- baout.write(value);
- try {
- cidSet.setData(baout.toByteArray());
- descriptor.setCIDSet(cidSet);
- } catch (IOException ioe) {
- log.error(
- "Failed to write CIDSet [" + cidFont + "] "
- + cidFont.getFontName(), ioe);
- }
- }
+ // TODO vh: re-enable
+// private void buildCIDSet(PDFFontDescriptor descriptor, CIDFont cidFont) {
+// BitSet cidSubset = new BitSet();
+// Iterator iter = cidFont.usedGlyphs.keySet().iterator();
+// while (iter.hasNext()) {
+// Integer cid = (Integer)iter.next();
+// cidSubset.set(cid.intValue());
+// }
+// PDFStream cidSet = makeStream(null, true);
+// ByteArrayOutputStream baout = new ByteArrayOutputStream(cidSubset.length() / 8 + 1);
+// int value = 0;
+// for (int i = 0, c = cidSubset.length(); i < c; i++) {
+// int shift = i % 8;
+// boolean b = cidSubset.get(i);
+// if (b) {
+// value |= 1 << 7 - shift;
+// }
+// if (shift == 7) {
+// baout.write(value);
+// value = 0;
+// }
+// }
+// baout.write(value);
+// try {
+// cidSet.setData(baout.toByteArray());
+// descriptor.setCIDSet(cidSet);
+// } catch (IOException ioe) {
+// log.error(
+// "Failed to write CIDSet [" + cidFont + "] "
+// + cidFont.getFontName(), ioe);
+// }
+// }
/**
* Embeds a font.
- * @param desc FontDescriptor of the font.
+ * @param fontUse the corresponding font use
+ * @param fontConsumer the associated font consumer
* @return PDFStream The embedded font file
*/
- public AbstractPDFStream makeFontFile(FontDescriptor desc) {
- if (desc.getFontType() == FontType.OTHER) {
- throw new IllegalArgumentException("Trying to embed unsupported font type: "
- + desc.getFontType());
- }
+ public AbstractPDFStream makeFontFile(FontUse fontUse, FontConsumer fontConsumer) {
+
+ return new PDFFontFileStream(fontUse, fontConsumer);
- CustomFont font = getCustomFont(desc);
-
- InputStream in = null;
- try {
- Source source = font.getEmbedFileSource();
- if (source == null && font.getEmbedResourceName() != null) {
- source = new StreamSource(this.getClass()
- .getResourceAsStream(font.getEmbedResourceName()));
- }
- if (source == null) {
- return null;
- }
- if (source instanceof StreamSource) {
- in = ((StreamSource) source).getInputStream();
- }
- if (in == null && source.getSystemId() != null) {
- try {
- in = new java.net.URL(source.getSystemId()).openStream();
- } catch (MalformedURLException e) {
- new FileNotFoundException(
- "File not found. URL could not be resolved: "
- + e.getMessage());
- }
- }
- if (in == null) {
- return null;
- }
- //Make sure the InputStream is decorated with a BufferedInputStream
- if (!(in instanceof java.io.BufferedInputStream)) {
- in = new java.io.BufferedInputStream(in);
- }
- if (in == null) {
- return null;
- } else {
- try {
- AbstractPDFStream embeddedFont;
- if (desc.getFontType() == FontType.TYPE0) {
- MultiByteFont mbfont = (MultiByteFont)font;
- FontFileReader reader = new FontFileReader(in);
-
- TTFSubSetFile subset = new TTFSubSetFile();
- byte[] subsetFont = subset.readFont(reader,
- mbfont.getTTCName(), mbfont.getUsedGlyphs());
- // Only TrueType CID fonts are supported now
-
- embeddedFont = new PDFTTFStream(subsetFont.length);
- ((PDFTTFStream)embeddedFont).setData(subsetFont, subsetFont.length);
- } else if (desc.getFontType() == FontType.TYPE1) {
- PFBParser parser = new PFBParser();
- PFBData pfb = parser.parsePFB(in);
- embeddedFont = new PDFT1Stream();
- ((PDFT1Stream)embeddedFont).setData(pfb);
- } else {
- byte[] file = IOUtils.toByteArray(in);
- embeddedFont = new PDFTTFStream(file.length);
- ((PDFTTFStream)embeddedFont).setData(file, file.length);
- }
-
- /*
- embeddedFont.getFilterList().addFilter("flate");
- if (getDocument().isEncryptionActive()) {
- getDocument().applyEncryption(embeddedFont);
- } else {
- embeddedFont.getFilterList().addFilter("ascii-85");
- }*/
-
- return embeddedFont;
- } finally {
- in.close();
- }
- }
- } catch (IOException ioe) {
- log.error(
- "Failed to embed font [" + desc + "] "
- + desc.getFontName(), ioe);
- return (PDFStream) null;
- }
+// CustomFont font = getCustomFont(desc);
+//
+// InputStream in = null;
+// try {
+// Source source = font.getEmbedFileSource();
+// if (source == null && font.getEmbedResourceName() != null) {
+// source = new StreamSource(this.getClass()
+// .getResourceAsStream(font.getEmbedResourceName()));
+// }
+// if (source == null) {
+// return null;
+// }
+// if (source instanceof StreamSource) {
+// in = ((StreamSource) source).getInputStream();
+// }
+// if (in == null && source.getSystemId() != null) {
+// try {
+// in = new java.net.URL(source.getSystemId()).openStream();
+// } catch (MalformedURLException e) {
+// new FileNotFoundException(
+// "File not found. URL could not be resolved: "
+// + e.getMessage());
+// }
+// }
+// if (in == null) {
+// return null;
+// }
+// //Make sure the InputStream is decorated with a BufferedInputStream
+// if (!(in instanceof java.io.BufferedInputStream)) {
+// in = new java.io.BufferedInputStream(in);
+// }
+// if (in == null) {
+// return null;
+// } else {
+// try {
+// AbstractPDFStream embeddedFont;
+// if (desc.getFontType() == FontType.TYPE0) {
+// MultiByteFont mbfont = (MultiByteFont)font;
+// FontFileReader reader = new FontFileReader(in);
+//
+// TTFSubSetFile subset = new TTFSubSetFile();
+// byte[] subsetFont = subset.readFont(reader,
+// mbfont.getTTCName(), mbfont.getUsedGlyphs());
+// // Only TrueType CID fonts are supported now
+//
+// embeddedFont = new PDFTTFStream(subsetFont.length);
+// ((PDFTTFStream)embeddedFont).setData(subsetFont, subsetFont.length);
+// } else if (desc.getFontType() == FontType.TYPE1) {
+// PFBParser parser = new PFBParser();
+// PFBData pfb = parser.parsePFB(in);
+// embeddedFont = new PDFT1Stream();
+// ((PDFT1Stream)embeddedFont).setData(pfb);
+// } else {
+// byte[] file = IOUtils.toByteArray(in);
+// embeddedFont = new PDFTTFStream(file.length);
+// ((PDFTTFStream)embeddedFont).setData(file, file.length);
+// }
+//
+// /*
+// embeddedFont.getFilterList().addFilter("flate");
+// if (getDocument().isEncryptionActive()) {
+// getDocument().applyEncryption(embeddedFont);
+// } else {
+// embeddedFont.getFilterList().addFilter("ascii-85");
+// }*/
+//
+// return embeddedFont;
+// } finally {
+// in.close();
+// }
+// }
+// } catch (IOException ioe) {
+// log.error(
+// "Failed to embed font [" + desc + "] "
+// + desc.getFontName(), ioe);
+// return (PDFStream) null;
+// }
}
- private CustomFont getCustomFont(FontDescriptor desc) {
- Typeface tempFont;
- if (desc instanceof LazyFont) {
- tempFont = ((LazyFont)desc).getRealFont();
- } else {
- tempFont = (Typeface)desc;
- }
- if (!(tempFont instanceof CustomFont)) {
- throw new IllegalArgumentException(
- "FontDescriptor must be instance of CustomFont, but is a "
- + desc.getClass().getName());
- }
- return (CustomFont)tempFont;
- }
+// private CustomFont getCustomFont(FontDescriptor desc) {
+// Typeface tempFont;
+// if (desc instanceof LazyFont) {
+// tempFont = ((LazyFont)desc).getRealFont();
+// } else {
+// tempFont = (Typeface)desc;
+// }
+// if (!(tempFont instanceof CustomFont)) {
+// throw new IllegalArgumentException(
+// "FontDescriptor must be instance of CustomFont, but is a "
+// + desc.getClass().getName());
+// }
+// return (CustomFont)tempFont;
+// }
/* ========================= streams =================================== */
@@ -1323,6 +1303,21 @@
/* ========================= misc. objects ============================= */
/**
+ * Transform an array of short into an array of int. I wish there were a
+ * better mean to do that...
+ *
+ * @param array of short
+ * @return array with the same values stored as integers
+ */
+ private static int[] shortArrayToIntArray(short[] shortArray) {
+ int[] intArray = new int[shortArray.length];
+ for (int i = 0; i < shortArray.length; i++) {
+ intArray[i] = shortArray[i];
+ }
+ return intArray;
+ }
+
+ /**
* Makes a new ICCBased color space and registers it in the resource context.
* @param res the PDF resource context to add the shading, may be null
* @param explicitName the explicit name for the color space, may be null
@@ -1345,6 +1340,7 @@
}
/**
+>>>>>>> .r448139
* make an Array object (ex. Widths array for a font)
*
* @param values the int array values
diff --git a/src/java/org/apache/fop/pdf/PDFFont.java b/src/java/org/apache/fop/pdf/PDFFont.java
index 181636c..83dfadc 100644
--- a/src/java/org/apache/fop/pdf/PDFFont.java
+++ b/src/java/org/apache/fop/pdf/PDFFont.java
@@ -19,8 +19,6 @@
package org.apache.fop.pdf;
-import org.apache.fop.fonts.FontType;
-
/**
* Class representing a /Font object.
* <p>
@@ -32,6 +30,31 @@
*/
public class PDFFont extends PDFObject {
+ /* Copied from FOray PDFFont.java */
+ /** Font subtype indicating a composite font. */
+ public static final byte TYPE0 = 0;
+
+ /** Font subtype indicating a Type 1 simple font. */
+ public static final byte TYPE1 = 1;
+
+ /** Font subtype indicating a Multiple Master Type 1 simple font. */
+ public static final byte MMTYPE1 = 2;
+
+ /** Font subtype indicating a Type 3 simple font. */
+ public static final byte TYPE3 = 3;
+
+ /** Font subtype indicating a TrueType simple font. */
+ public static final byte TRUETYPE = 4;
+
+ /** Unknown font type. */
+ public static final byte OTHER = 5;
+
+ /** Font subtype names as output in the PDF. */
+ protected static final String[] TYPE_NAMES /* The order is important here. */
+ = {"Type0", "Type1", "MMType1", "Type3", "TrueType", "Other" };
+ /* End of copy from PDFFont.java */
+
+
/**
* the internal name for the font (eg "F1")
*/
@@ -39,9 +62,9 @@
/**
* the font's subtype
- * (as defined by the constants FontType: TYPE0, TYPE1, MMTYPE1, TYPE3, TRUETYPE)
+ * (as defined by the constants in PDFFont: TYPE0, TYPE1, MMTYPE1, TYPE3, TRUETYPE)
*/
- protected FontType subtype;
+ protected byte subtype;
/**
* the base font name (eg "Helvetica")
@@ -70,7 +93,7 @@
* @param basefont the base font name
* @param encoding the character encoding schema used by the font
*/
- public PDFFont(String fontname, FontType subtype,
+ public PDFFont(String fontname, byte subtype,
String basefont,
Object encoding /* , PDFToUnicode mapping */) {
@@ -89,29 +112,27 @@
* factory method with the basic parameters
*
* @param fontname the internal name for the font
- * @param subtype the font's subtype
+ * @param subtype the font's subtype (one of TYPE0, TYPE1, MMTYPE1, TYPE3 or TRUETYPE)
* @param basefont the base font name
* @param encoding the character encoding schema used by the font
* @return the generated PDFFont object
*/
public static PDFFont createFont(String fontname,
- FontType subtype, String basefont,
+ byte subtype, String basefont,
Object encoding) {
- if (subtype == FontType.TYPE0) {
+ if (subtype == TYPE0) {
return new PDFFontType0(fontname, basefont,
encoding);
- } else if ((subtype == FontType.TYPE1)
- || (subtype == FontType.MMTYPE1)) {
- return new PDFFontType1(fontname, basefont,
- encoding);
- } else if (subtype == FontType.TYPE3) {
- //return new PDFFontType3(number, fontname, basefont, encoding);
+ } else if ((subtype == TYPE1)
+ || (subtype == MMTYPE1)) {
+ return new PDFFontType1(fontname, basefont, encoding);
+ } else if (subtype == TYPE3) {
+// //return new PDFFontType3(number, fontname, basefont, encoding);
return null; //NYI
- } else if (subtype == FontType.TRUETYPE) {
- return new PDFFontTrueType(fontname, basefont,
- encoding);
+ } else if (subtype == TRUETYPE) {
+ return new PDFFontTrueType(fontname, basefont, encoding);
} else {
- return null; // should not happend
+ return null; // should not happen
}
}
@@ -120,7 +141,7 @@
* for Type1, MMType1 and TrueType
*
* @param fontname the internal name for the font
- * @param subtype the font's subtype
+ * @param subtype the font's subtype (one of TYPE0, TYPE1, MMTYPE1, TYPE3 or TRUETYPE)
* @param basefont the base font name
* @param encoding the character encoding schema used by the font
* @param firstChar the first character code in the font
@@ -130,27 +151,27 @@
* @return the generated PDFFont object
*/
public static PDFFont createFont(String fontname,
- FontType subtype, String basefont,
+ byte subtype, String basefont,
Object encoding, int firstChar,
int lastChar, PDFArray widths,
PDFFontDescriptor descriptor) {
PDFFontNonBase14 font;
- if (subtype == FontType.TYPE0) {
+ if (subtype == TYPE0) {
font = new PDFFontType0(fontname, basefont,
encoding);
font.setDescriptor(descriptor);
return font;
- } else if ((subtype == FontType.TYPE1)
- || (subtype == FontType.MMTYPE1)) {
+ } else if ((subtype == TYPE1)
+ || (subtype == MMTYPE1)) {
font = new PDFFontType1(fontname, basefont,
encoding);
font.setWidthMetrics(firstChar, lastChar, widths);
font.setDescriptor(descriptor);
return font;
- } else if (subtype == FontType.TYPE3) {
+ } else if (subtype == TYPE3) {
return null; //NYI, should not happend
- } else if (subtype == FontType.TRUETYPE) {
+ } else if (subtype == TRUETYPE) {
font = new PDFFontTrueType(fontname, basefont,
encoding);
font.setWidthMetrics(firstChar, lastChar, widths);
@@ -174,19 +195,15 @@
* @param fontType font type
* @return String corresponding PDF name
*/
- protected String getPDFNameForFontType(FontType fontType) {
- if (fontType == FontType.TYPE0) {
- return fontType.getName();
- } else if (fontType == FontType.TYPE1) {
- return fontType.getName();
- } else if (fontType == FontType.MMTYPE1) {
- return fontType.getName();
- } else if (fontType == FontType.TYPE3) {
- return fontType.getName();
- } else if (fontType == FontType.TRUETYPE) {
- return fontType.getName();
- } else {
- throw new IllegalArgumentException("Unsupported font type: " + fontType.getName());
+ protected String getPDFNameForFontType(byte fontType) {
+ switch (fontType) {
+ case TYPE0:
+ case TYPE1:
+ case MMTYPE1:
+ case TYPE3:
+ case TRUETYPE: return TYPE_NAMES[fontType];
+ default:
+ throw new IllegalArgumentException("Unsupported font type");
}
}
diff --git a/src/java/org/apache/fop/pdf/PDFFontDescriptor.java b/src/java/org/apache/fop/pdf/PDFFontDescriptor.java
index db1e73e..ed60b12 100644
--- a/src/java/org/apache/fop/pdf/PDFFontDescriptor.java
+++ b/src/java/org/apache/fop/pdf/PDFFontDescriptor.java
@@ -19,8 +19,6 @@
package org.apache.fop.pdf;
-import org.apache.fop.fonts.FontType;
-
/**
* Class representing a font descriptor (/FontDescriptor object).
* <p>
@@ -48,7 +46,10 @@
private AbstractPDFStream cidSet;
// private String charSet = null;
- private FontType subtype;
+ /**
+ * Font type. One of PDFFont.TYPE0, TYPE1, MMTYPE1, TRUETYPE
+ */
+ private byte subtype;
/**
* Create the /FontDescriptor object
@@ -111,7 +112,7 @@
* @param subtype the font type defined in the font stream
* @param fontfile the stream containing an embedded font
*/
- public void setFontFile(FontType subtype, AbstractPDFStream fontfile) {
+ public void setFontFile(byte subtype, AbstractPDFStream fontfile) {
this.subtype = subtype;
this.fontfile = fontfile;
}
@@ -185,7 +186,7 @@
p.append(leading);
}
if (fontfile != null) {
- if (subtype == FontType.TYPE1) {
+ if (subtype == PDFFont.TYPE1) {
p.append("\n/FontFile ");
} else {
p.append("\n/FontFile2 ");
diff --git a/src/java/org/apache/fop/pdf/PDFFontNonBase14.java b/src/java/org/apache/fop/pdf/PDFFontNonBase14.java
index e479e92..4e508ec 100644
--- a/src/java/org/apache/fop/pdf/PDFFontNonBase14.java
+++ b/src/java/org/apache/fop/pdf/PDFFontNonBase14.java
@@ -19,7 +19,6 @@
package org.apache.fop.pdf;
-import org.apache.fop.fonts.FontType;
/**
* A common ancestor for Type1, TrueType, MMType1 and Type3 fonts
@@ -51,11 +50,11 @@
* Create the /Font object
*
* @param fontname the internal name for the font
- * @param subtype the font's subtype
+ * @param subtype the font's subtype (one of PDFont.TYPE0, TYPE1, MMTYPE1, TRUETYPE)
* @param basefont the base font name
* @param encoding the character encoding schema used by the font
*/
- public PDFFontNonBase14(String fontname, FontType subtype,
+ public PDFFontNonBase14(String fontname, byte subtype,
String basefont,
Object encoding) {
diff --git a/src/java/org/apache/fop/pdf/PDFFontTrueType.java b/src/java/org/apache/fop/pdf/PDFFontTrueType.java
index eb3a94a..5fd68d8 100644
--- a/src/java/org/apache/fop/pdf/PDFFontTrueType.java
+++ b/src/java/org/apache/fop/pdf/PDFFontTrueType.java
@@ -19,7 +19,6 @@
package org.apache.fop.pdf;
-import org.apache.fop.fonts.FontType;
/**
* Class representing a TrueType font.
@@ -41,7 +40,7 @@
Object encoding) {
/* generic creation of PDF object */
- super(fontname, FontType.TRUETYPE, basefont, encoding /* , mapping */);
+ super(fontname, PDFFont.TRUETYPE, basefont, encoding /* , mapping */);
}
}
diff --git a/src/java/org/apache/fop/pdf/PDFFontType0.java b/src/java/org/apache/fop/pdf/PDFFontType0.java
index 5467f12..a8ec9ed 100644
--- a/src/java/org/apache/fop/pdf/PDFFontType0.java
+++ b/src/java/org/apache/fop/pdf/PDFFontType0.java
@@ -19,7 +19,6 @@
package org.apache.fop.pdf;
-import org.apache.fop.fonts.FontType;
/**
* Class representing a Type0 font.
@@ -50,7 +49,7 @@
Object encoding) {
/* generic creation of PDF object */
- super(fontname, FontType.TYPE0, basefont, encoding /* , mapping */);
+ super(fontname, PDFFont.TYPE0, basefont, encoding /* , mapping */);
/* set fields using paramaters */
this.descendantFonts = null;
@@ -71,7 +70,7 @@
PDFCIDFont descendantFonts) {
/* generic creation of PDF object */
- super(fontname, FontType.TYPE0, basefont, encoding /* , mapping */);
+ super(fontname, PDFFont.TYPE0, basefont, encoding /* , mapping */);
/* set fields using paramaters */
this.descendantFonts = descendantFonts;
diff --git a/src/java/org/apache/fop/pdf/PDFFontType1.java b/src/java/org/apache/fop/pdf/PDFFontType1.java
index 8c9a7dc..bd9a046 100644
--- a/src/java/org/apache/fop/pdf/PDFFontType1.java
+++ b/src/java/org/apache/fop/pdf/PDFFontType1.java
@@ -19,7 +19,6 @@
package org.apache.fop.pdf;
-import org.apache.fop.fonts.FontType;
/**
* Class representing a Type1 or MMType1 font (not necessary for the base 14).
@@ -45,7 +44,7 @@
Object encoding) {
/* generic creation of PDF object */
- super(fontname, FontType.TYPE1, basefont, encoding);
+ super(fontname, PDFFont.TYPE1, basefont, encoding);
}
}
diff --git a/src/java/org/apache/fop/pdf/PDFFontType3.java b/src/java/org/apache/fop/pdf/PDFFontType3.java
index 78238d1..85838f2 100644
--- a/src/java/org/apache/fop/pdf/PDFFontType3.java
+++ b/src/java/org/apache/fop/pdf/PDFFontType3.java
@@ -19,7 +19,6 @@
package org.apache.fop.pdf;
-import org.apache.fop.fonts.FontType;
/**
* Class representing a Type3 font.
@@ -63,7 +62,7 @@
Object encoding) {
/* generic creation of PDF object */
- super(fontname, FontType.TYPE3, basefont, encoding /* , mapping */);
+ super(fontname, PDFFont.TYPE3, basefont, encoding /* , mapping */);
this.fontBBox = null;
this.fontMatrix = null;
@@ -87,7 +86,7 @@
PDFCharProcs charProcs) {
/* generic creation of PDF object */
- super(fontname, FontType.TYPE3, basefont, encoding /* , mapping */);
+ super(fontname, PDFFont.TYPE3, basefont, encoding /* , mapping */);
this.fontBBox = fontBBox;
this.fontMatrix = fontMatrix;
diff --git a/src/java/org/apache/fop/pdf/PDFResources.java b/src/java/org/apache/fop/pdf/PDFResources.java
index 2320010..a6bde85 100644
--- a/src/java/org/apache/fop/pdf/PDFResources.java
+++ b/src/java/org/apache/fop/pdf/PDFResources.java
@@ -19,17 +19,17 @@
package org.apache.fop.pdf;
-import org.apache.fop.fonts.FontInfo;
-import org.apache.fop.fonts.Typeface;
-import org.apache.fop.fonts.FontDescriptor;
import org.apache.fop.util.ColorProfileUtil;
-// Java
+//Java
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
-import java.util.HashMap;
-import java.util.HashSet;
+
+import org.axsl.fontR.FontConsumer;
+import org.axsl.fontR.FontUse;
/**
* class representing a /Resources object.
@@ -94,20 +94,14 @@
* Add the fonts in the font info to this PDF document's Font Resources.
*
* @param doc PDF document to add fonts to
- * @param fontInfo font info object to get font information from
+ * @param fontMap pairs of font names and their associated internal names
*/
- public void addFonts(PDFDocument doc, FontInfo fontInfo) {
- Map fonts = fontInfo.getUsedFonts();
- Iterator e = fonts.keySet().iterator();
- while (e.hasNext()) {
- String f = (String)e.next();
- Typeface font = (Typeface)fonts.get(f);
- FontDescriptor desc = null;
- if (font instanceof FontDescriptor) {
- desc = (FontDescriptor)font;
- }
- addFont(doc.getFactory().makeFont(
- f, font.getFontName(), font.getEncoding(), font, desc));
+ public void addFonts(PDFDocument doc, FontMap fontMap) {
+ FontConsumer fontConsumer = fontMap.getFontConsumer();
+ FontUse[] usedFontUses = fontConsumer.getUsedFontUses();
+ for (int i = 0; i < usedFontUses.length; i++) {
+ String internalName = (String) fontMap.getInternalName(usedFontUses[i]);
+ addFont(doc.getFactory().makeFont(usedFontUses[i], internalName, fontConsumer));
}
}
diff --git a/src/java/org/apache/fop/pdf/PDFText.java b/src/java/org/apache/fop/pdf/PDFText.java
index a172bed..51c22d0 100644
--- a/src/java/org/apache/fop/pdf/PDFText.java
+++ b/src/java/org/apache/fop/pdf/PDFText.java
@@ -176,11 +176,11 @@
* @param c character to encode
* @return the encoded character
*/
- public static final String toUnicodeHex(char c) {
+ public static final String toUnicodeHex(int c) {
final StringBuffer buf = new StringBuffer(4);
final byte[] uniBytes;
try {
- final char[] a = {c};
+ final char[] a = {(char)c/*TODO vh*/};
uniBytes = new String(a).getBytes("UTF-16BE");
} catch (java.io.UnsupportedEncodingException uee) {
throw new CascadingRuntimeException("Incompatible VM", uee);
diff --git a/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java b/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java
index 443d33b..ea343bc 100644
--- a/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java
+++ b/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java
@@ -35,11 +35,12 @@
import org.apache.fop.area.inline.InlineArea;
import org.apache.fop.area.inline.Viewport;
import org.apache.fop.fo.Constants;
-import org.apache.fop.fonts.FontMetrics;
import org.apache.fop.image.FopImage;
import org.apache.fop.traits.BorderProps;
import org.w3c.dom.Document;
+import org.axsl.fontR.FontUse;
+
/**
* Abstract base class for renderers like PDF and PostScript where many painting operations
* follow similar patterns which makes it possible to share some code.
@@ -571,21 +572,21 @@
/**
* Paints the text decoration marks.
- * @param fm Current typeface
+ * @param fu Current font use
* @param fontsize Current font size
* @param inline inline area to paint the marks for
* @param baseline position of the baseline
* @param startx start IPD
*/
- protected void renderTextDecoration(FontMetrics fm, int fontsize, InlineArea inline,
+ protected void renderTextDecoration(FontUse fu, int fontsize, InlineArea inline,
int baseline, int startx) {
boolean hasTextDeco = inline.hasUnderline()
|| inline.hasOverline()
|| inline.hasLineThrough();
if (hasTextDeco) {
endTextObject();
- float descender = fm.getDescender(fontsize) / 1000f;
- float capHeight = fm.getCapHeight(fontsize) / 1000f;
+ float descender = fu.getFont().getDescender(fontsize) / 1000f;
+ float capHeight = fu.getFont().getCapHeight(fontsize) / 1000f;
float halfLineWidth = (descender / -8f) / 2f;
float endx = (startx + inline.getIPD()) / 1000f;
if (inline.hasUnderline()) {
diff --git a/src/java/org/apache/fop/render/AbstractRenderer.java b/src/java/org/apache/fop/render/AbstractRenderer.java
index 562666b..f797922 100644
--- a/src/java/org/apache/fop/render/AbstractRenderer.java
+++ b/src/java/org/apache/fop/render/AbstractRenderer.java
@@ -24,8 +24,8 @@
import java.awt.geom.Rectangle2D;
import java.io.IOException;
import java.io.OutputStream;
-import java.util.List;
import java.util.Iterator;
+import java.util.List;
import java.util.Set;
// XML
@@ -33,23 +33,25 @@
// FOP
import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.area.Area;
import org.apache.fop.area.BeforeFloat;
import org.apache.fop.area.Block;
import org.apache.fop.area.BlockViewport;
import org.apache.fop.area.BodyRegion;
import org.apache.fop.area.CTM;
-import org.apache.fop.area.NormalFlow;
import org.apache.fop.area.Footnote;
import org.apache.fop.area.LineArea;
import org.apache.fop.area.MainReference;
-import org.apache.fop.area.Span;
+import org.apache.fop.area.NormalFlow;
+import org.apache.fop.area.OffDocumentItem;
import org.apache.fop.area.Page;
import org.apache.fop.area.PageViewport;
-import org.apache.fop.area.RegionViewport;
import org.apache.fop.area.RegionReference;
+import org.apache.fop.area.RegionViewport;
+import org.apache.fop.area.Span;
import org.apache.fop.area.Trait;
-import org.apache.fop.area.OffDocumentItem;
+import org.apache.fop.area.inline.Character;
import org.apache.fop.area.inline.Character;
import org.apache.fop.area.inline.Container;
import org.apache.fop.area.inline.ForeignObject;
@@ -59,13 +61,12 @@
import org.apache.fop.area.inline.InlineParent;
import org.apache.fop.area.inline.Leader;
import org.apache.fop.area.inline.Space;
+import org.apache.fop.area.inline.TextArea;
import org.apache.fop.area.inline.Viewport;
import org.apache.fop.area.inline.TextArea;
import org.apache.fop.area.inline.WordArea;
import org.apache.fop.area.inline.SpaceArea;
-import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.fo.Constants;
-import org.apache.fop.fonts.FontInfo;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -74,6 +75,8 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.axsl.fontR.FontConsumer;
+
/**
* Abstract base class for all renderers. The Abstract renderer does all the
* top level processing of the area tree and adds some abstract methods to
@@ -124,9 +127,9 @@
}
/**
- * @see org.apache.fop.render.Renderer#setupFontInfo(FontInfo)
+ * @see org.apache.fop.render.Renderer#setupFontConsumer(Consumer)
*/
- public abstract void setupFontInfo(FontInfo fontInfo);
+ public abstract void setupFontConsumer(FontConsumer fontConsumer);
/**
* @see org.apache.fop.render.Renderer#setUserAgent(FOUserAgent)
diff --git a/src/java/org/apache/fop/render/PrintRenderer.java b/src/java/org/apache/fop/render/PrintRenderer.java
index ddb3355..eb76efe 100644
--- a/src/java/org/apache/fop/render/PrintRenderer.java
+++ b/src/java/org/apache/fop/render/PrintRenderer.java
@@ -22,11 +22,6 @@
// FOP
import org.apache.fop.area.Area;
import org.apache.fop.area.Trait;
-import org.apache.fop.fonts.Font;
-import org.apache.fop.fonts.FontInfo;
-import org.apache.fop.fonts.FontResolver;
-import org.apache.fop.fonts.FontSetup;
-import org.apache.fop.fonts.FontTriplet;
import org.w3c.dom.Document;
// Java
@@ -35,25 +30,26 @@
import java.util.List;
import java.util.Map;
+// aXSL
+import org.axsl.fontR.FontConsumer;
+
/** Abstract base class of "Print" type renderers. */
public abstract class PrintRenderer extends AbstractRenderer {
- /** Font configuration */
- protected FontInfo fontInfo;
-
- /** list of fonts */
- protected List fontList = null;
+ /** Font consumer */
+ protected FontConsumer fontConsumer;
/**
- * Set up the font info
+ * Set up the font consumer
*
- * @param inFontInfo font info to set up
+ * @param inFontConsumer font consumer to set up
*/
- public void setupFontInfo(FontInfo inFontInfo) {
- this.fontInfo = inFontInfo;
- FontResolver resolver = new DefaultFontResolver(userAgent);
- FontSetup.setup(fontInfo, fontList, resolver,
- userAgent.getFactory().isBase14KerningEnabled());
+ public void setupFontConsumer(FontConsumer inFontConsumer) {
+ this.fontConsumer = inFontConsumer;
+ // TODO vh: adaptation needed
+// FontResolver resolver = new DefaultFontResolver(userAgent);
+// FontSetup.setup(fontInfo, fontList, resolver,
+// userAgent.getFactory().isBase14KerningEnabled());
}
/**
@@ -61,9 +57,11 @@
* @param area the area from which to retrieve the font triplet information
* @return the internal font key (F1, F2 etc.) or null if not found
*/
+ // TODO vh: re-enable
protected String getInternalFontNameForArea(Area area) {
- FontTriplet triplet = (FontTriplet)area.getTrait(Trait.FONT);
- return fontInfo.getInternalFontKey(triplet);
+ return null;
+// FontTriplet triplet = (FontTriplet)area.getTrait(Trait.FONT);
+// return fontInfo.getInternalFontKey(triplet);
}
/**
@@ -71,11 +69,12 @@
* @param area the area from which to retrieve the font triplet information
* @return the requested Font instance or null if not found
*/
- protected Font getFontFromArea(Area area) {
- FontTriplet triplet = (FontTriplet)area.getTrait(Trait.FONT);
- int size = ((Integer)area.getTrait(Trait.FONT_SIZE)).intValue();
- return fontInfo.getFontInstance(triplet, size);
- }
+ // TODO vh: re-enable
+// protected Font getFontFromArea(Area area) {
+// FontTriplet triplet = (FontTriplet)area.getTrait(Trait.FONT);
+// int size = ((Integer)area.getTrait(Trait.FONT_SIZE)).intValue();
+// return fontInfo.getFontInstance(triplet, size);
+// }
/**
* Lightens up a color for groove, ridge, inset and outset border effects.
diff --git a/src/java/org/apache/fop/render/Renderer.java b/src/java/org/apache/fop/render/Renderer.java
index 0b763b9..ed840fe 100644
--- a/src/java/org/apache/fop/render/Renderer.java
+++ b/src/java/org/apache/fop/render/Renderer.java
@@ -20,16 +20,17 @@
package org.apache.fop.render;
// Java
-import java.io.OutputStream;
import java.io.IOException;
+import java.io.OutputStream;
// FOP
import org.apache.fop.apps.FOPException;
-import org.apache.fop.area.PageViewport;
+import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.area.LineArea;
import org.apache.fop.area.OffDocumentItem;
-import org.apache.fop.fonts.FontInfo;
-import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.area.PageViewport;
+
+import org.axsl.fontR.FontConsumer;
/**
@@ -89,11 +90,11 @@
void setUserAgent(FOUserAgent agent);
/**
- * Set up the given FontInfo.
+ * Set up the font consumer.
*
- * @param fontInfo The font information
+ * @param fontConsumer The font consumer
*/
- void setupFontInfo(FontInfo fontInfo);
+ void setupFontConsumer(FontConsumer fontConsumer);
/**
* Reports if out of order rendering is supported. <p>
diff --git a/src/java/org/apache/fop/render/afp/AFPRenderer.java b/src/java/org/apache/fop/render/afp/AFPRenderer.java
index 8f1636b..5283b80 100644
--- a/src/java/org/apache/fop/render/afp/AFPRenderer.java
+++ b/src/java/org/apache/fop/render/afp/AFPRenderer.java
@@ -54,14 +54,6 @@
import org.apache.fop.area.inline.WordArea;
import org.apache.fop.fo.Constants;
import org.apache.fop.fo.extensions.ExtensionAttachment;
-import org.apache.fop.fonts.FontInfo;
-import org.apache.fop.fonts.FontMetrics;
-import org.apache.fop.fonts.FontTriplet;
-import org.apache.fop.fonts.FontUtil;
-import org.apache.fop.fonts.Typeface;
-import org.apache.fop.fonts.base14.Courier;
-import org.apache.fop.fonts.base14.Helvetica;
-import org.apache.fop.fonts.base14.TimesRoman;
import org.apache.fop.image.FopImage;
import org.apache.fop.image.ImageFactory;
import org.apache.fop.image.TIFFImage;
diff --git a/src/java/org/apache/fop/render/java2d/Java2DGraphicsState.java b/src/java/org/apache/fop/render/java2d/Java2DGraphicsState.java
index a24bdfb..ca109e0 100644
--- a/src/java/org/apache/fop/render/java2d/Java2DGraphicsState.java
+++ b/src/java/org/apache/fop/render/java2d/Java2DGraphicsState.java
@@ -29,7 +29,9 @@
import java.awt.geom.GeneralPath;
import org.apache.fop.fo.Constants;
-import org.apache.fop.fonts.FontInfo;
+
+import org.axsl.fontR.FontConsumer;
+import org.axsl.fontR.FontUse;
/**
* Keeps information about the current state of the Graphics2D currentGraphics.
@@ -48,8 +50,8 @@
private int currentStrokeStyle;
- /** Font configuration, passed from AWTRenderer */
- private FontInfo fontInfo;
+ /** Font consumer, passed from AWTRenderer */
+ private FontConsumer fontConsumer;
/** Initial AffinTransform passed by the renderer, includes scaling-info */
private AffineTransform initialTransform;
@@ -57,12 +59,12 @@
/**
* State for storing graphics state.
* @param graphics the graphics associated with the BufferedImage
- * @param fontInfo the FontInfo from the renderer
+ * @param fontConsumer the FontConsumer from the renderer
* @param at the initial AffineTransform containing the scale transformation
*/
- public Java2DGraphicsState(Graphics2D graphics, FontInfo fontInfo,
+ public Java2DGraphicsState(Graphics2D graphics, FontConsumer fontConsumer,
AffineTransform at) {
- this.fontInfo = fontInfo;
+ this.fontConsumer = fontConsumer;
this.currentGraphics = graphics;
this.initialTransform = at;
currentGraphics.setTransform(at);
@@ -119,25 +121,42 @@
}
/**
+<<<<<<< .mine
+ * @see org.apache.fop.render.java2d.RendererState#updateFont(org.axsl.font.FontUse,
+ * int, java.lang.StringBuffer)
+=======
* Set the current font name. Check if the font name will change and then
* set the new name.
*
* @param name the new font name
* @param size the font size
* @return true if the new Font changes the current Font
+>>>>>>> .r448139
*/
+<<<<<<< .mine
+ public boolean updateFont(FontUse fontUse, int size, StringBuffer pdf) {
+=======
public boolean updateFont(String name, int size) {
+>>>>>>> .r448139
+<<<<<<< .mine
+=======
FontMetricsMapper mapper = (FontMetricsMapper)fontInfo.getMetricsFor(name);
boolean updateName = (!mapper.getFontName().equals(
getGraph().getFont().getFontName()));
boolean updateSize = (size != (getGraph().getFont().getSize() * 1000));
+>>>>>>> .r448139
- if (updateName || updateSize) {
+ java.awt.Font awtFont = fontUse.getFont().getAWTFont(fontConsumer, size);
+ if (!getGraph().getFont().equals(awtFont)) {
// the font name and/or the font size have changed
+<<<<<<< .mine
+ currentGraphics.setFont(awtFont);
+=======
java.awt.Font font = mapper.getFont(size);
currentGraphics.setFont(font);
+>>>>>>> .r448139
return true;
} else {
return false;
diff --git a/src/java/org/apache/fop/render/java2d/Java2DRenderer.java b/src/java/org/apache/fop/render/java2d/Java2DRenderer.java
index 64421b6..92fb0fc 100644
--- a/src/java/org/apache/fop/render/java2d/Java2DRenderer.java
+++ b/src/java/org/apache/fop/render/java2d/Java2DRenderer.java
@@ -67,9 +67,6 @@
import org.apache.fop.area.inline.TextArea;
import org.apache.fop.area.inline.WordArea;
import org.apache.fop.fo.Constants;
-import org.apache.fop.fonts.Font;
-import org.apache.fop.fonts.FontInfo;
-import org.apache.fop.fonts.Typeface;
import org.apache.fop.image.FopImage;
import org.apache.fop.image.ImageFactory;
import org.apache.fop.image.XMLImage;
@@ -78,6 +75,11 @@
import org.apache.fop.render.Graphics2DAdapter;
import org.apache.fop.render.RendererContext;
import org.apache.fop.render.pdf.CTMHelper;
+
+import org.axsl.fontR.Font;
+import org.axsl.fontR.FontConsumer;
+import org.axsl.fontR.FontUse;
+
import org.apache.fop.util.CharUtilities;
/**
@@ -141,6 +143,13 @@
private Stack stateStack = new Stack();
+ /** Font consumer */
+ protected FontConsumer fontConsumer;
+
+ protected Map fontNames = new java.util.Hashtable();
+
+ protected Map fontStyles = new java.util.Hashtable();
+
/** true if the renderer has finished rendering all the pages */
private boolean renderingDone;
@@ -182,8 +191,12 @@
}
/**
- * @see org.apache.fop.render.Renderer#setupFontInfo(org.apache.fop.fonts.FontInfo)
+ * @see org.apache.fop.render.Renderer#setupFontConsumer(org.axsl.font.FontConsumer)
*/
+<<<<<<< .mine
+ public void setupFontConsumer(FontConsumer fontConsumer) {
+ this.fontConsumer = fontConsumer;
+=======
public void setupFontInfo(FontInfo inFontInfo) {
//Don't call super.setupFontInfo() here! Java2D needs a special font setup
// create a temp Image to test font metrics on
@@ -195,6 +208,7 @@
g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
RenderingHints.VALUE_FRACTIONALMETRICS_ON);
FontSetup.setup(fontInfo, g);
+>>>>>>> .r448139
}
/** @see org.apache.fop.render.Renderer#getGraphics2DAdapter() */
@@ -347,7 +361,7 @@
graphics.drawLine(0, pageHeight + 2, pageWidth + 2, pageHeight + 2);
graphics.drawLine(1, pageHeight + 3, pageWidth + 3, pageHeight + 3);
- state = new Java2DGraphicsState(graphics, this.fontInfo, at);
+ state = new Java2DGraphicsState(graphics, this.fontConsumer, at);
try {
// reset the current Positions
currentBPPosition = 0;
@@ -716,6 +730,11 @@
int bl = currentBPPosition + text.getOffset() + text.getBaselineOffset();
int saveIP = currentIPPosition;
+<<<<<<< .mine
+ FontUse fontUse = (FontUse) text.getTrait(Trait.FONT);
+ int size = ((Integer) text.getTrait(Trait.FONT_SIZE)).intValue();
+ state.updateFont(fontUse, size, null);
+=======
Font font = getFontFromArea(text);
state.updateFont(font.getFontName(), font.getFontSize());
saveGraphicsState();
@@ -727,11 +746,18 @@
currentIPPosition = saveIP + text.getAllocIPD();
//super.renderText(text);
+>>>>>>> .r448139
// rendering text decorations
+<<<<<<< .mine
+ renderTextDecoration(fontUse.getFont(), size, text, y, x);
+
+ super.renderText(text);
+=======
Typeface tf = (Typeface) fontInfo.getFonts().get(font.getFontName());
int fontsize = text.getTraitAsInteger(Trait.FONT_SIZE);
renderTextDecoration(tf, fontsize, text, bl, rx);
+>>>>>>> .r448139
}
/**
@@ -746,7 +772,13 @@
Color col = (Color) text.getTrait(Trait.COLOR);
g2d.setColor(col);
+<<<<<<< .mine
+ FontUse fontUse = (FontUse) ch.getTrait(Trait.FONT);
+ int size = ((Integer) ch.getTrait(Trait.FONT_SIZE)).intValue();
+ state.updateFont(fontUse, size, null);
+=======
float textCursor = 0;
+>>>>>>> .r448139
Iterator iter = text.getChildAreas().iterator();
while (iter.hasNext()) {
@@ -783,11 +815,24 @@
+ 2 * text.getTextLetterSpaceAdjust()
: 0);
+<<<<<<< .mine
+ String s = ch.getChar();
+ state.getGraph().drawString(s, x / 1000f, y / 1000f);
+
+ // getLogger().debug( "renderCharacter(): \"" + s + "\", x: "
+ // + x + ", y: " + y + state);
+
+ // rendering text decorations
+ renderTextDecoration(fontUse.getFont(), size, ch, y, x);
+
+ super.renderCharacter(ch);
+=======
textCursor += (font.getCharWidth(sp) + tws) / 1000f;
} else {
throw new IllegalStateException("Unsupported child element: " + child);
}
}
+>>>>>>> .r448139
}
private static int[] getGlyphOffsets(String s, Font font, TextArea text,
@@ -799,15 +844,66 @@
final char mapped = font.mapChar(c);
int wordSpace;
+<<<<<<< .mine
+ /**
+ * Paints the text decoration marks.
+ *
+ * @param fs Current font
+ * @param fontSize font size
+ * @param inline inline area to paint the marks for
+ * @param baseline position of the baseline
+ * @param startIPD start IPD
+ */
+ protected void renderTextDecoration(Font fs, int fontSize, InlineArea inline,
+ float baseline, float startIPD) {
+
+ boolean hasTextDeco = inline.hasUnderline() || inline.hasOverline()
+ || inline.hasLineThrough();
+
+ if (hasTextDeco) {
+ state.updateStroke((fs.getDescender(fontSize) / (-8 * 1000f)),
+ Constants.EN_SOLID);
+ float endIPD = startIPD + inline.getIPD();
+ if (inline.hasUnderline()) {
+ ColorType ct = (ColorType) inline
+ .getTrait(Trait.UNDERLINE_COLOR);
+ state.updateColor(ct, false, null);
+ float y = baseline - fs.getDescender(fontSize) / 2;
+ line.setLine(startIPD / 1000f, y / 1000f, endIPD / 1000f,
+ y / 1000f);
+ state.getGraph().draw(line);
+=======
if (CharUtilities.isAdjustableSpace(mapped)) {
wordSpace = text.getTextWordSpaceAdjust();
} else {
wordSpace = 0;
+>>>>>>> .r448139
}
+<<<<<<< .mine
+ if (inline.hasOverline()) {
+ ColorType ct = (ColorType) inline
+ .getTrait(Trait.OVERLINE_COLOR);
+ state.updateColor(ct, false, null);
+ float y = (float) (baseline - (1.1 * fs.getCapHeight(fontSize)));
+ line.setLine(startIPD / 1000f, y / 1000f, endIPD / 1000f,
+ y / 1000f);
+ state.getGraph().draw(line);
+ }
+ if (inline.hasLineThrough()) {
+ ColorType ct = (ColorType) inline
+ .getTrait(Trait.LINETHROUGH_COLOR);
+ state.updateColor(ct, false, null);
+ float y = (float) (baseline - (0.45 * fs.getCapHeight(fontSize)));
+ line.setLine(startIPD / 1000f, y / 1000f, endIPD / 1000f,
+ y / 1000f);
+ state.getGraph().draw(line);
+ }
+=======
int cw = font.getWidth(mapped);
int ladj = (letterAdjust != null && i < textLen - 1 ? letterAdjust[i + 1] : 0);
int tls = (i < textLen - 1 ? text.getTextLetterSpaceAdjust() : 0);
offsets[i] = cw + ladj + tls + wordSpace;
+>>>>>>> .r448139
}
return offsets;
}
@@ -998,9 +1094,15 @@
}
Graphics2D graphics = (Graphics2D) g;
try {
+<<<<<<< .mine
+ PageViewport viewport = getPageViewport(pageIndex);
+ AffineTransform at = graphics.getTransform();
+ state = new Java2DGraphicsState(graphics, this.fontConsumer, at);
+=======
PageViewport viewport = getPageViewport(pageIndex);
AffineTransform at = graphics.getTransform();
state = new Java2DGraphicsState(graphics, this.fontInfo, at);
+>>>>>>> .r448139
// reset the current Positions
currentBPPosition = 0;
diff --git a/src/java/org/apache/fop/render/pdf/PDFGraphics2DAdapter.java b/src/java/org/apache/fop/render/pdf/PDFGraphics2DAdapter.java
index ce8c231..00a411a 100644
--- a/src/java/org/apache/fop/render/pdf/PDFGraphics2DAdapter.java
+++ b/src/java/org/apache/fop/render/pdf/PDFGraphics2DAdapter.java
@@ -86,9 +86,9 @@
pdfInfo.pdfContext = pdfInfo.pdfPage;
}
PDFGraphics2D graphics = new PDFGraphics2D(textAsShapes,
- pdfInfo.fi, pdfInfo.pdfDoc,
+ renderer.getFontMap(), pdfInfo.pdfDoc,
pdfInfo.pdfContext, pdfInfo.pdfPage.referencePDF(),
- renderer.currentFontName,
+ renderer.currentFontUse,
renderer.currentFontSize);
graphics.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());
diff --git a/src/java/org/apache/fop/render/pdf/PDFRenderer.java b/src/java/org/apache/fop/render/pdf/PDFRenderer.java
index ae75b92..a2a6622 100644
--- a/src/java/org/apache/fop/render/pdf/PDFRenderer.java
+++ b/src/java/org/apache/fop/render/pdf/PDFRenderer.java
@@ -48,6 +48,7 @@
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.area.Area;
import org.apache.fop.area.CTM;
import org.apache.fop.area.LineArea;
import org.apache.fop.area.OffDocumentExtensionAttachment;
@@ -63,12 +64,10 @@
import org.apache.fop.area.inline.InlineParent;
import org.apache.fop.area.inline.WordArea;
import org.apache.fop.area.inline.SpaceArea;
-import org.apache.fop.fonts.Typeface;
-import org.apache.fop.fonts.Font;
-import org.apache.fop.fonts.FontSetup;
import org.apache.fop.image.FopImage;
import org.apache.fop.image.ImageFactory;
import org.apache.fop.image.XMLImage;
+import org.apache.fop.pdf.FontMap;
import org.apache.fop.pdf.PDFAMode;
import org.apache.fop.pdf.PDFAnnotList;
import org.apache.fop.pdf.PDFColor;
@@ -105,6 +104,10 @@
import org.apache.xmlgraphics.xmp.schemas.XMPBasicAdapter;
import org.apache.xmlgraphics.xmp.schemas.XMPBasicSchema;
+import org.axsl.fontR.Font;
+import org.axsl.fontR.FontConsumer;
+import org.axsl.fontR.FontUse;
+
/**
* Renderer that renders areas to PDF.
*/
@@ -211,11 +214,16 @@
/** drawing state */
protected PDFState currentState = null;
- /** Name of currently selected font */
- protected String currentFontName = "";
- /** Size of currently selected font */
+ /** Currently selected FontUse */
+ protected FontUse currentFontUse = null;
+ /** Size (in millipoints) of currently selected font */
protected int currentFontSize = 0;
- /** page height */
+ /**
+ * Font mappings of FontUse to internal name.
+ */
+ protected FontMap fontMap;
+
+ /** page height */
protected int pageHeight;
/** Registry of PDF filters */
@@ -231,8 +239,31 @@
*/
public PDFRenderer() {
}
-
+
/**
+ * Setup the font consumer.
+ * @param fontConsumer the font consumer.
+ */
+ public void setupFontConsumer(FontConsumer fontConsumer) {
+ super.setupFontConsumer(fontConsumer);
+ fontMap = new FontMap(fontConsumer);
+ }
+
+ /**
+ * Return the font map associated to this renderer.
+ * @return the mappings of FontUse to internal names
+ */
+ public FontMap getFontMap() {
+ return fontMap;
+ }
+
+ // TODO vh: refactor
+ protected String getInternalFontNameForArea(Area area) {
+ FontUse fontUse = (FontUse)area.getTrait(Trait.FONT);
+ return fontMap.getInternalName(fontUse);
+ }
+
+ /**
* Configure the PDF renderer.
* Get the configuration to be used for pdf stream filters,
* fonts etc.
@@ -242,13 +273,6 @@
//PDF filters
this.filterMap = PDFFilterList.buildFilterMapFromConfiguration(cfg);
- //Font configuration
- List cfgFonts = FontSetup.buildFontListFromConfiguration(cfg);
- if (this.fontList == null) {
- this.fontList = cfgFonts;
- } else {
- this.fontList.addAll(cfgFonts);
- }
String s = cfg.getChild(PDF_A_MODE, true).getValue(null);
if (s != null) {
@@ -479,7 +503,7 @@
* @see org.apache.fop.render.Renderer#stopRenderer()
*/
public void stopRenderer() throws IOException {
- pdfDoc.getResources().addFonts(pdfDoc, fontInfo);
+ pdfDoc.getResources().addFonts(pdfDoc, fontMap);
pdfDoc.outputTrailer(ostream);
this.pdfDoc = null;
@@ -494,7 +518,7 @@
currentContext = null;
currentPage = null;
currentState = null;
- currentFontName = "";
+ currentFontUse = null;
}
/**
@@ -607,7 +631,6 @@
protected void beginTextObject() {
if (!inTextMode) {
currentStream.add("BT\n");
- currentFontName = "";
inTextMode = true;
}
}
@@ -708,7 +731,7 @@
currentStream.add(CTMHelper.toPDFString(basicPageTransform, false) + " cm\n");
- currentFontName = "";
+ currentFontUse = null;
super.renderPage(page);
@@ -757,7 +780,7 @@
* @param region the RegionViewport whose region is to be drawn
*/
protected void handleRegionTraits(RegionViewport region) {
- currentFontName = "";
+ currentFontUse = null;
super.handleRegionTraits(region);
}
@@ -1141,14 +1164,15 @@
beginTextObject();
StringBuffer pdf = new StringBuffer();
- String fontName = getInternalFontNameForArea(text);
+ // TODO vh
+// String fontName = getInternalFontNameForArea(text);
+ FontUse fontUse = (FontUse) text.getTrait(Trait.FONT);
int size = ((Integer) text.getTrait(Trait.FONT_SIZE)).intValue();
// This assumes that *all* CIDFonts use a /ToUnicode mapping
- Typeface tf = (Typeface) fontInfo.getFonts().get(fontName);
- boolean useMultiByte = tf.isMultiByte();
-
- updateFont(fontName, size, pdf);
+ boolean useMultiByte = fontUse.getFont().getFontComplexity() == Font.FONT_COMPOSITE;
+
+ updateFont(fontUse, size, pdf);
Color ct = (Color) text.getTrait(Trait.COLOR);
updateColor(ct, true, pdf);
@@ -1169,22 +1193,24 @@
currentStream.add("] TJ\n");
- renderTextDecoration(tf, size, text, bl, rx);
+ renderTextDecoration(fontUse, size, text, bl, rx);
}
/**
* @see org.apache.fop.render.AbstractRenderer#renderWord(WordArea)
*/
public void renderWord(WordArea word) {
- Font font = getFontFromArea(word.getParentArea());
- Typeface tf = (Typeface) fontInfo.getFonts().get(font.getFontName());
- boolean useMultiByte = tf.isMultiByte();
+ // TODO vh
+// Font font = getFontFromArea(word.getParentArea());
+ FontUse fontUse = (FontUse) word.getParentArea().getTrait(Trait.FONT);
+ int size = ((Integer) word.getParentArea().getTrait(Trait.FONT_SIZE)).intValue();
+ boolean useMultiByte = fontUse.getFont().getFontComplexity() == Font.FONT_COMPOSITE;
StringBuffer pdf = new StringBuffer();
String s = word.getWord();
escapeText(s, word.getLetterAdjustArray(),
- font, (AbstractTextArea)word.getParentArea(), useMultiByte, pdf);
+ fontUse, size, (AbstractTextArea)word.getParentArea(), useMultiByte, pdf);
currentStream.add(pdf.toString());
@@ -1195,23 +1221,25 @@
* @see org.apache.fop.render.AbstractRenderer#renderSpace(SpaceArea)
*/
public void renderSpace(SpaceArea space) {
- Font font = getFontFromArea(space.getParentArea());
- Typeface tf = (Typeface) fontInfo.getFonts().get(font.getFontName());
- boolean useMultiByte = tf.isMultiByte();
+ // TODO vh
+// Font font = getFontFromArea(space.getParentArea());
+ FontUse fontUse = (FontUse) space.getParentArea().getTrait(Trait.FONT);
+ int size = ((Integer) space.getParentArea().getTrait(Trait.FONT_SIZE)).intValue();
+ boolean useMultiByte = fontUse.getFont().getFontComplexity() == Font.FONT_COMPOSITE;
String s = space.getSpace();
StringBuffer pdf = new StringBuffer();
AbstractTextArea textArea = (AbstractTextArea)space.getParentArea();
- escapeText(s, null, font, textArea, useMultiByte, pdf);
+ escapeText(s, null, fontUse, size, textArea, useMultiByte, pdf);
if (space.isAdjustable()) {
int tws = -((TextArea) space.getParentArea()).getTextWordSpaceAdjust()
- 2 * textArea.getTextLetterSpaceAdjust();
if (tws != 0) {
- pdf.append(format(tws / (font.getFontSize() / 1000f)));
+ pdf.append(format(tws / (size / 1000f)));
pdf.append(" ");
}
}
@@ -1225,46 +1253,46 @@
* Escapes text according to PDF rules.
* @param s Text to escape
* @param letterAdjust an array of widths for letter adjustment (may be null)
- * @param fs Font state
+ * @param fontUse Font use
* @param parentArea the parent text area to retrieve certain traits from
* @param useMultiByte Indicates the use of multi byte convention
* @param pdf target buffer for the escaped text
*/
public void escapeText(String s, int[] letterAdjust,
- Font fs, AbstractTextArea parentArea,
+ FontUse fontUse, int fontSize, AbstractTextArea parentArea,
boolean useMultiByte, StringBuffer pdf) {
String startText = useMultiByte ? "<" : "(";
String endText = useMultiByte ? "> " : ") ";
/*
boolean kerningAvailable = false;
- Map kerning = fs.getKerning();
- if (kerning != null && !kerning.isEmpty()) {
- //kerningAvailable = true;
- //TODO Reenable me when the layout engine supports kerning, too
- log.warn("Kerning support is disabled until it is supported by the layout engine!");
- }
+// TODO vh: kerning is available differently from FOrayFont
+// Map kerning = font.getKerning();
+// if (kerning != null && !kerning.isEmpty()) {
+// //kerningAvailable = true;
+// //TODO Reenable me when the layout engine supports kerning, too
+// log.warn("Kerning support is disabled until it is supported by the layout engine!");
+// }
*/
int l = s.length();
- float fontSize = fs.getFontSize() / 1000f;
boolean startPending = true;
for (int i = 0; i < l; i++) {
char orgChar = s.charAt(i);
- char ch;
+ int ch;
float glyphAdjust = 0;
- if (fs.hasChar(orgChar)) {
- ch = fs.mapChar(orgChar);
+ if (fontUse.glyphAvailable(orgChar)) {
+ ch = fontUse.encodeCharacter(orgChar);
int tls = (i < l - 1 ? parentArea.getTextLetterSpaceAdjust() : 0);
glyphAdjust -= tls;
} else {
if (CharUtilities.isFixedWidthSpace(orgChar)) {
//Fixed width space are rendered as spaces so copy/paste works in a reader
- ch = fs.mapChar(CharUtilities.SPACE);
- glyphAdjust = fs.getCharWidth(ch) - fs.getCharWidth(orgChar);
+ ch = fontUse.encodeCharacter(CharUtilities.SPACE);
+ glyphAdjust = fontUse.getFont().width(ch, fontSize) - fontUse.getFont().width(orgChar, fontSize);
} else {
- ch = fs.mapChar(orgChar);
+ ch = fontUse.encodeCharacter(orgChar);
}
}
if (letterAdjust != null && i < l - 1) {
@@ -1288,13 +1316,13 @@
break;
default:
}
- pdf.append(ch);
+ pdf.append((char)ch);
}
} else {
pdf.append(PDFText.toUnicodeHex(ch));
}
- float adjust = glyphAdjust / fontSize;
+ float adjust = glyphAdjust / (fontSize / 1000f/*TODO vh: refactor*/);
if (adjust != 0) {
pdf.append(endText).append(format(adjust)).append(' ');
@@ -1318,7 +1346,7 @@
textOpen = false;
prevWordX = 0;
prevWordY = 0;
- currentFontName = "";
+ currentFontUse = null;
}*/
}
@@ -1370,14 +1398,15 @@
updateColor(col, fill, null);
}
- private void updateFont(String name, int size, StringBuffer pdf) {
- if ((!name.equals(this.currentFontName))
+ private void updateFont(FontUse fontUse, int size, StringBuffer pdf) {
+ if ((!fontUse.equals(this.currentFontUse))
|| (size != this.currentFontSize)) {
closeText();
- this.currentFontName = name;
+ this.currentFontUse = fontUse;
this.currentFontSize = size;
- pdf = pdf.append("/" + name + " " + format((float) size / 1000f)
+ String internalName = (String) this.fontMap.getInternalName(fontUse);
+ pdf = pdf.append("/" + internalName + " " + format((float) size / 1000f)
+ " Tf\n");
}
}
@@ -1512,8 +1541,9 @@
currentContext == null ? currentPage : currentContext);
context.setProperty(PDFRendererContextConstants.PDF_CONTEXT, currentContext);
context.setProperty(PDFRendererContextConstants.PDF_STREAM, currentStream);
- context.setProperty(PDFRendererContextConstants.PDF_FONT_INFO, fontInfo);
- context.setProperty(PDFRendererContextConstants.PDF_FONT_NAME, currentFontName);
+ // TODO vh: check
+ context.setProperty(PDFRendererContextConstants.PDF_FONT_CONSUMER, fontConsumer);
+ context.setProperty(PDFRendererContextConstants.PDF_FONT_USE, currentFontUse);
context.setProperty(PDFRendererContextConstants.PDF_FONT_SIZE,
new Integer(currentFontSize));
return context;
diff --git a/src/java/org/apache/fop/render/pdf/PDFRendererContextConstants.java b/src/java/org/apache/fop/render/pdf/PDFRendererContextConstants.java
index d3efa96..52e7a19 100644
--- a/src/java/org/apache/fop/render/pdf/PDFRendererContextConstants.java
+++ b/src/java/org/apache/fop/render/pdf/PDFRendererContextConstants.java
@@ -42,10 +42,10 @@
String PDF_STREAM = "pdfStream";
/** The current font information for the pdf renderer. */
- String PDF_FONT_INFO = "fontInfo";
+ String PDF_FONT_CONSUMER = "fontConsumer";
/** The current pdf font name. */
- String PDF_FONT_NAME = "fontName";
+ String PDF_FONT_USE = "fontUse";
/** The current pdf font size. */
String PDF_FONT_SIZE = "fontSize";
diff --git a/src/java/org/apache/fop/render/pdf/PDFSVGHandler.java b/src/java/org/apache/fop/render/pdf/PDFSVGHandler.java
index cca185a..658d835 100644
--- a/src/java/org/apache/fop/render/pdf/PDFSVGHandler.java
+++ b/src/java/org/apache/fop/render/pdf/PDFSVGHandler.java
@@ -33,16 +33,18 @@
import org.apache.fop.render.RendererContextConstants;
import org.apache.fop.pdf.PDFDocument;
import org.apache.fop.pdf.PDFPage;
+import org.apache.fop.pdf.PDFResourceContext;
import org.apache.fop.pdf.PDFState;
import org.apache.fop.pdf.PDFStream;
-import org.apache.fop.pdf.PDFResourceContext;
import org.apache.fop.svg.PDFAElementBridge;
import org.apache.fop.svg.PDFBridgeContext;
import org.apache.fop.svg.PDFGraphics2D;
import org.apache.fop.svg.SVGUserAgent;
import org.apache.fop.util.QName;
import org.apache.fop.fo.extensions.ExtensionElementMapping;
-import org.apache.fop.fonts.FontInfo;
+
+import org.axsl.fontR.FontConsumer;
+import org.axsl.fontR.FontUse;
// Commons-Logging
import org.apache.commons.logging.Log;
@@ -84,8 +86,8 @@
pdfi.currentStream = (PDFStream)context.getProperty(PDF_STREAM);
pdfi.width = ((Integer)context.getProperty(WIDTH)).intValue();
pdfi.height = ((Integer)context.getProperty(HEIGHT)).intValue();
- pdfi.fi = (FontInfo)context.getProperty(PDF_FONT_INFO);
- pdfi.currentFontName = (String)context.getProperty(PDF_FONT_NAME);
+ pdfi.fc = (FontConsumer) context.getProperty(PDF_FONT_CONSUMER);
+ pdfi.currentFontUse = (FontUse)context.getProperty(PDF_FONT_USE);
pdfi.currentFontSize = ((Integer)context.getProperty(PDF_FONT_SIZE)).intValue();
pdfi.currentXPosition = ((Integer)context.getProperty(XPOS)).intValue();
pdfi.currentYPosition = ((Integer)context.getProperty(YPOS)).intValue();
@@ -119,10 +121,10 @@
public int width;
/** see PDF_HEIGHT */
public int height;
- /** see PDF_FONT_INFO */
- public FontInfo fi;
- /** see PDF_FONT_NAME */
- public String currentFontName;
+ /** see PDF_FONT_CONSUMER */
+ public FontConsumer fc;
+ /** see PDF_FONT_USE */
+ public FontUse currentFontUse;
/** see PDF_FONT_SIZE */
public int currentFontSize;
/** see PDF_XPOS */
@@ -176,10 +178,11 @@
if (cfg != null) {
strokeText = cfg.getChild("stroke-text", true).getValueAsBoolean(strokeText);
}
-
- BridgeContext ctx = new PDFBridgeContext(ua,
- (strokeText ? null : pdfInfo.fi),
- new AffineTransform());
+
+ // TODO vh: re-enable
+ BridgeContext ctx = null/*new PDFBridgeContext(ua,
+ (strokeText ? null : pdfInfo.fc),
+ new AffineTransform())*/;
GraphicsNode root;
try {
@@ -227,10 +230,11 @@
if (pdfInfo.pdfContext == null) {
pdfInfo.pdfContext = pdfInfo.pdfPage;
}
- PDFGraphics2D graphics = new PDFGraphics2D(true, pdfInfo.fi,
+ // TODO vh: re-enable
+ PDFGraphics2D graphics = null/*new PDFGraphics2D(true, pdfInfo.fc,
pdfInfo.pdfDoc,
pdfInfo.pdfContext, pdfInfo.pdfPage.referencePDF(),
- pdfInfo.currentFontName, pdfInfo.currentFontSize);
+ pdfInfo.currentFontUse, pdfInfo.currentFontSize)*/;
graphics.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());
if (!resolutionScaling.isIdentity()) {
diff --git a/src/java/org/apache/fop/render/ps/AbstractPSTranscoder.java b/src/java/org/apache/fop/render/ps/AbstractPSTranscoder.java
index 9795bd5..94db6e3 100644
--- a/src/java/org/apache/fop/render/ps/AbstractPSTranscoder.java
+++ b/src/java/org/apache/fop/render/ps/AbstractPSTranscoder.java
@@ -77,7 +77,7 @@
* Constructs a new <tt>AbstractPSTranscoder</tt>.
*/
public AbstractPSTranscoder() {
- super();
+ super(true);
}
protected abstract AbstractPSDocumentGraphics2D createDocumentGraphics2D();
diff --git a/src/java/org/apache/fop/render/ps/EPSTranscoder.java b/src/java/org/apache/fop/render/ps/EPSTranscoder.java
index a6d6c12..ee972fa 100644
--- a/src/java/org/apache/fop/render/ps/EPSTranscoder.java
+++ b/src/java/org/apache/fop/render/ps/EPSTranscoder.java
@@ -60,7 +60,7 @@
/** @see AbstractPSTranscoder#createDocumentGraphics2D() */
protected AbstractPSDocumentGraphics2D createDocumentGraphics2D() {
- return new EPSDocumentGraphics2D(false);
+ return new EPSDocumentGraphics2D(false, getFontMap());
}
}
diff --git a/src/java/org/apache/fop/render/ps/PSFontUtils.java b/src/java/org/apache/fop/render/ps/PSFontUtils.java
index 5ece1fa..a363fc5 100644
--- a/src/java/org/apache/fop/render/ps/PSFontUtils.java
+++ b/src/java/org/apache/fop/render/ps/PSFontUtils.java
@@ -21,24 +21,20 @@
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
import java.util.Iterator;
import java.util.Map;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
-import org.apache.fop.fonts.CustomFont;
-import org.apache.fop.fonts.Font;
-import org.apache.fop.fonts.FontInfo;
-import org.apache.fop.fonts.FontType;
-import org.apache.fop.fonts.LazyFont;
-import org.apache.fop.fonts.Typeface;
import org.apache.xmlgraphics.ps.DSCConstants;
import org.apache.xmlgraphics.ps.PSGenerator;
import org.apache.xmlgraphics.ps.PSResource;
+import org.axsl.fontR.Font;
+import org.axsl.fontR.FontUse;
+import org.axsl.psR.Encoding;
+
/**
* Utility code for font handling in PostScript.
*/
@@ -47,87 +43,73 @@
/**
* Generates the PostScript code for the font dictionary.
* @param gen PostScript generator to use for output
- * @param fontInfo available fonts
+ * @param fontMap mappings of FontUses to their associated internal names
* @return a Map of PSResource instances representing all defined fonts (key: font key)
* @throws IOException in case of an I/O problem
*/
- public static Map writeFontDict(PSGenerator gen, FontInfo fontInfo)
+ public static Map writeFontDict(PSGenerator gen, FontMap fontMap)
throws IOException {
gen.commentln("%FOPBeginFontDict");
gen.writeln("/FOPFonts 100 dict dup begin");
// write("/gfF1{/Helvetica findfont} bd");
// write("/gfF3{/Helvetica-Bold findfont} bd");
- Map fonts = fontInfo.getFonts();
Map fontResources = new java.util.HashMap();
- Iterator iter = fonts.keySet().iterator();
+ Iterator iter = fontMap.getMappings().iterator();
while (iter.hasNext()) {
- String key = (String)iter.next();
- Typeface tf = (Typeface)fonts.get(key);
- if (tf instanceof LazyFont) {
- tf = ((LazyFont)tf).getRealFont();
- }
- if (tf == null) {
- //This is to avoid an NPE if a malconfigured font is in the configuration but not
- //used in the document. If it were used, we wouldn't get this far.
- String fallbackKey = fontInfo.getInternalFontKey(Font.DEFAULT_FONT);
- tf = (Typeface)fonts.get(fallbackKey);
- }
- PSResource fontRes = new PSResource("font", tf.getFontName());
- fontResources.put(key, fontRes);
+ Map.Entry entry = (Map.Entry)iter.next();
+ String internalName = (String)entry.getValue();
+ FontUse fontUse = (FontUse)entry.getKey();
+ PSResource fontRes = new PSResource(PSResource.TYPE_FONT, internalName);
+ fontResources.put(internalName, fontRes);
boolean embeddedFont = false;
- if (FontType.TYPE1 == tf.getFontType()) {
- if (tf instanceof CustomFont) {
- CustomFont cf = (CustomFont)tf;
- InputStream in = getInputStreamOnFont(gen, cf);
- if (in != null) {
- gen.writeDSCComment(DSCConstants.BEGIN_RESOURCE,
- fontRes);
- embedType1Font(gen, in);
- gen.writeDSCComment(DSCConstants.END_RESOURCE);
- gen.notifyResourceUsage(fontRes, false);
- embeddedFont = true;
- }
- }
+ Font font = fontUse.getFont();
+ if (font.getFontFormat() == Font.FORMAT_TYPE1
+ && font.isEmbeddable()
+ && !font.isPDFStandardFont()) {
+ gen.writeDSCComment(DSCConstants.BEGIN_RESOURCE, fontRes);
+ gen.writeByteArr(font.getContentsPostScriptHex(fontMap.getFontConsumer()));
+ gen.writeDSCComment(DSCConstants.END_RESOURCE);
+ gen.notifyResourceUsage(fontRes, false);
+ embeddedFont = true;
}
if (!embeddedFont) {
gen.writeDSCComment(DSCConstants.INCLUDE_RESOURCE, fontRes);
//Resource usage shall be handled by renderer
//gen.notifyResourceUsage(fontRes, true);
}
- gen.commentln("%FOPBeginFontKey: " + key);
- gen.writeln("/" + key + " /" + tf.getFontName() + " def");
+ gen.commentln("%FOPBeginFontKey: " + internalName);
+ gen.writeln("/" + internalName + " /" + font.postscriptName() + " def");
gen.commentln("%FOPEndFontKey");
}
gen.writeln("end def");
gen.commentln("%FOPEndFontDict");
gen.commentln("%FOPBeginFontReencode");
defineWinAnsiEncoding(gen);
-
+
//Rewrite font encodings
- iter = fonts.keySet().iterator();
+ iter = fontMap.getMappings().iterator();
while (iter.hasNext()) {
- String key = (String)iter.next();
- Typeface fm = (Typeface)fonts.get(key);
- if (fm instanceof LazyFont && ((LazyFont)fm).getRealFont() == null) {
- continue;
- } else if (null == fm.getEncoding()) {
+ FontUse fontUse = (FontUse)((Map.Entry)iter.next()).getKey();
+ Encoding encoding = fontUse.getEncoding();
+ if (encoding == null) {
//ignore (ZapfDingbats and Symbol run through here
//TODO: ZapfDingbats and Symbol should get getEncoding() fixed!
- } else if ("WinAnsiEncoding".equals(fm.getEncoding())) {
- gen.writeln("/" + fm.getFontName() + " findfont");
+ } else if (encoding.isPredefinedPS()) {
+ gen.writeln("/" + fontUse.postscriptName() + " findfont");
gen.writeln("dup length dict begin");
gen.writeln(" {1 index /FID ne {def} {pop pop} ifelse} forall");
- gen.writeln(" /Encoding " + fm.getEncoding() + " def");
+ gen.writeln(" /Encoding " + encoding.getName() + " def");
gen.writeln(" currentdict");
gen.writeln("end");
- gen.writeln("/" + fm.getFontName() + " exch definefont pop");
+ gen.writeln("/" + fontUse.postscriptName() + " exch definefont pop");
} else {
gen.commentln("%WARNING: Only WinAnsiEncoding is supported. Font '"
- + fm.getFontName() + "' asks for: " + fm.getEncoding());
+ + fontUse.postscriptName() + "' asks for: " + encoding.getName());
}
}
gen.commentln("%FOPEndFontReencode");
+
return fontResources;
}
diff --git a/src/java/org/apache/fop/render/ps/PSRenderer.java b/src/java/org/apache/fop/render/ps/PSRenderer.java
index 75c3817..93069ae 100644
--- a/src/java/org/apache/fop/render/ps/PSRenderer.java
+++ b/src/java/org/apache/fop/render/ps/PSRenderer.java
@@ -55,13 +55,11 @@
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.fo.Constants;
import org.apache.fop.fo.extensions.ExtensionAttachment;
-import org.apache.fop.fonts.Font;
-import org.apache.fop.fonts.FontSetup;
-import org.apache.fop.fonts.Typeface;
import org.apache.fop.image.EPSImage;
import org.apache.fop.image.FopImage;
import org.apache.fop.image.ImageFactory;
import org.apache.fop.image.XMLImage;
+import org.apache.fop.pdf.FontMap;
import org.apache.fop.render.Graphics2DAdapter;
import org.apache.fop.render.AbstractPathOrientedRenderer;
import org.apache.fop.render.ImageAdapter;
@@ -69,6 +67,8 @@
import org.apache.fop.render.pdf.PDFRendererContextConstants;
import org.apache.fop.render.ps.extensions.PSSetupCode;
import org.apache.fop.util.CharUtilities;
+import org.axsl.font.FontConsumer;
+import org.axsl.font.FontUse;
import org.apache.xmlgraphics.ps.DSCConstants;
import org.apache.xmlgraphics.ps.PSGenerator;
@@ -114,6 +114,8 @@
private boolean inTextMode = false;
private boolean firstPageSequenceReceived = false;
+
+ private FontMap fontMap;
/** Used to temporarily store PSSetupCode instance until they can be written. */
private List setupCodeList;
@@ -121,20 +123,19 @@
/** This is a map of PSResource instances of all fonts defined (key: font key) */
private Map fontResources;
+ /** Set up the font consumer.
+ * @param fontConsumer the font consumer.
+ */
+ public void setupFontConsumer(FontConsumer fontConsumer) {
+ super.setupFontConsumer(fontConsumer);
+ fontMap = new FontMap(fontConsumer, true);
+ }
/**
* @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
*/
public void configure(Configuration cfg) throws ConfigurationException {
super.configure(cfg);
this.autoRotateLandscape = cfg.getChild("auto-rotate-landscape").getValueAsBoolean(false);
-
- //Font configuration
- List cfgFonts = FontSetup.buildFontListFromConfiguration(cfg);
- if (this.fontList == null) {
- this.fontList = cfgFonts;
- } else {
- this.fontList.addAll(cfgFonts);
- }
}
/**
@@ -408,12 +409,12 @@
/**
* Changes the currently used font.
- * @param name name of the font
+ * @param fontUse the new font use
* @param size font size
*/
- public void useFont(String name, int size) {
+ public void useFont(FontUse fontUse, int size) {
try {
- gen.useFont(name, size / 1000f);
+ gen.useFont(fontMap.getInternalName(fontUse), size / 1000f);
} catch (IOException ioe) {
handleIOTrouble(ioe);
}
@@ -631,12 +632,10 @@
*/
public void stopRenderer() throws IOException {
//Notify resource usage for font which are not supplied
- Map fonts = fontInfo.getUsedFonts();
- Iterator e = fonts.keySet().iterator();
- while (e.hasNext()) {
- String key = (String)e.next();
- //Typeface font = (Typeface)fonts.get(key);
- PSResource res = (PSResource)this.fontResources.get(key);
+ FontUse[] fontUses = fontConsumer.getFontServer().getUsedFontUses(fontConsumer);
+ for (int i = 0; i < fontUses.length; i++) {
+ PSResource res = (PSResource)this.fontResources.get(
+ fontMap.getInternalName(fontUses[i]));
boolean supplied = gen.isResourceSupplied(res);
if (!supplied) {
gen.notifyResourceUsage(res, true);
@@ -682,7 +681,7 @@
//Setup
gen.writeDSCComment(DSCConstants.BEGIN_SETUP);
writeSetupCodeList(setupCodeList, "SetupCode");
- this.fontResources = PSFontUtils.writeFontDict(gen, fontInfo);
+ this.fontResources = PSFontUtils.writeFontDict(gen, fontMap);
gen.writeln("FOPFonts begin");
gen.writeDSCComment(DSCConstants.END_SETUP);
} catch (IOException ioe) {
@@ -843,17 +842,21 @@
*/
public void renderText(TextArea area) {
renderInlineAreaBackAndBorders(area);
+<<<<<<< .mine
+ FontUse fontUse = (FontUse)area.getTrait(Trait.FONT);
+=======
String fontname = getInternalFontNameForArea(area);
+>>>>>>> .r448139
int fontsize = area.getTraitAsInteger(Trait.FONT_SIZE);
// This assumes that *all* CIDFonts use a /ToUnicode mapping
- Typeface tf = (Typeface) fontInfo.getFonts().get(fontname);
+// Typeface tf = (Typeface) fontInfo.getFonts().get(fontname);
//Determine position
int rx = currentIPPosition + area.getBorderAndPaddingWidthStart();
int bl = currentBPPosition + area.getOffset() + area.getBaselineOffset();
- useFont(fontname, fontsize);
+ useFont(fontUse, fontsize);
Color ct = (Color)area.getTrait(Trait.COLOR);
if (ct != null) {
try {
@@ -912,7 +915,7 @@
sb.append("(");
for (int i = 0; i < textLen; i++) {
final char c = text.charAt(i);
- final char mapped = tf.mapChar(c);
+ final char mapped = fontUse.encodeCharacter(fontConsumer, c);
PSGenerator.escapeChar(mapped, sb);
}
sb.append(") t");
@@ -921,7 +924,7 @@
int[] offsets = new int[textLen];
for (int i = 0; i < textLen; i++) {
final char c = text.charAt(i);
- final char mapped = tf.mapChar(c);
+ final char mapped = fontUse.encodeCharacter(fontConsumer, c);
int wordSpace;
if (CharUtilities.isAdjustableSpace(mapped)) {
@@ -929,10 +932,15 @@
} else {
wordSpace = 0;
}
+<<<<<<< .mine
+ int cw = fontUse.getFont().width(c, fontsize) / 1000;
+ offsets[i] = cw + area.getTextLetterSpaceAdjust() + wordSpace;
+=======
int cw = tf.getWidth(mapped, font.getFontSize()) / 1000;
int ladj = (letterAdjust != null && i < textLen - 1 ? letterAdjust[i + 1] : 0);
int tls = (i < textLen - 1 ? area.getTextLetterSpaceAdjust() : 0);
offsets[i] = cw + ladj + tls + wordSpace;
+>>>>>>> .r448139
PSGenerator.escapeChar(mapped, sb);
}
sb.append(")" + PSGenerator.LF + "[");
diff --git a/src/java/org/apache/fop/render/ps/PSSVGHandler.java b/src/java/org/apache/fop/render/ps/PSSVGHandler.java
index 191fee5..9d79290 100644
--- a/src/java/org/apache/fop/render/ps/PSSVGHandler.java
+++ b/src/java/org/apache/fop/render/ps/PSSVGHandler.java
@@ -37,7 +37,6 @@
import org.apache.batik.gvt.GraphicsNode;
// FOP
-import org.apache.fop.fonts.FontInfo;
import org.apache.fop.render.Renderer;
import org.apache.fop.render.XMLHandler;
import org.apache.fop.render.RendererContext;
@@ -48,6 +47,7 @@
// Commons-Logging
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.axsl.fontR.FontConsumer;
/**
* PostScript XML handler for SVG. Uses Apache Batik for SVG processing.
@@ -87,7 +87,8 @@
public static PSInfo getPSInfo(RendererContext context) {
PSInfo psi = new PSInfo();
psi.psGenerator = (PSGenerator)context.getProperty(PS_GENERATOR);
- psi.fontInfo = (org.apache.fop.fonts.FontInfo) context.getProperty(PS_FONT_INFO);
+ // TODO vh: re-enable
+// psi.fontConsumer = (FontConsumer) context.getProperty(PS_FONT_CONSUMER);
psi.width = ((Integer)context.getProperty(WIDTH)).intValue();
psi.height = ((Integer)context.getProperty(HEIGHT)).intValue();
psi.currentXPosition = ((Integer)context.getProperty(XPOS)).intValue();
@@ -103,8 +104,8 @@
/** see PS_GENERATOR */
private PSGenerator psGenerator;
- /** see PS_FONT_INFO */
- private org.apache.fop.fonts.FontInfo fontInfo;
+ /** see PS_FONT_CONSUMER */
+ private FontConsumer fontConsumer;
/** see WIDTH */
private int width;
/** see HEIGHT */
@@ -133,19 +134,19 @@
}
/**
- * Returns the fontInfo.
- * @return FontInfo
+ * Returns the font consumer.
+ * @return the font consumer
*/
- public FontInfo getFontInfo() {
- return fontInfo;
+ public FontConsumer getFontConsumer() {
+ return fontConsumer;
}
/**
- * Sets the fontInfo.
- * @param fontInfo The fontInfo to set
+ * Sets the font consumer.
+ * @param fontConsumer The font consumer to set
*/
- public void setFontInfo(FontInfo fontInfo) {
- this.fontInfo = fontInfo;
+ public void setFontConsumer(FontConsumer fontConsumer) {
+ this.fontConsumer = fontConsumer;
}
/**
@@ -261,7 +262,8 @@
NativeTextHandler nativeTextHandler = null;
BridgeContext ctx = new BridgeContext(ua);
if (!strokeText) {
- nativeTextHandler = new NativeTextHandler(graphics, psInfo.getFontInfo());
+ // TODO vh: re-enable
+ nativeTextHandler = null/*new NativeTextHandler(graphics, psInfo.getFontConsumer())*/;
graphics.setCustomTextHandler(nativeTextHandler);
PSTextPainter textPainter = new PSTextPainter(nativeTextHandler);
ctx.setTextPainter(textPainter);
diff --git a/src/java/org/apache/fop/render/ps/PSTextPainter.java b/src/java/org/apache/fop/render/ps/PSTextPainter.java
index 78efd56..b6ba23b 100644
--- a/src/java/org/apache/fop/render/ps/PSTextPainter.java
+++ b/src/java/org/apache/fop/render/ps/PSTextPainter.java
@@ -50,8 +50,10 @@
import org.apache.batik.gvt.font.GVTFontFamily;
import org.apache.batik.gvt.renderer.StrokingTextPainter;
-import org.apache.fop.fonts.Font;
-import org.apache.fop.fonts.FontInfo;
+import org.axsl.font.Font;
+import org.axsl.font.FontConsumer;
+import org.axsl.font.FontException;
+import org.axsl.font.FontUse;
import org.apache.fop.fonts.FontTriplet;
/**
@@ -127,7 +129,8 @@
boolean hasunsupported = false;
String text = getText(aci);
- Font font = makeFont(aci);
+ Float size = (Float)aci.getAttribute(TextAttribute.SIZE);
+ FontUse font = makeFont(aci, (size == null) ? 10000 : size.intValue() * 1000);
if (hasUnsupportedGlyphs(text, font)) {
log.trace("-> Unsupported glyphs found");
hasunsupported = true;
@@ -280,10 +283,12 @@
Paint strokePaint = tpi.strokePaint;
Stroke stroke = tpi.strokeStroke;
- Float fontSize = (Float)aci.getAttribute(TextAttribute.SIZE);
- if (fontSize == null) {
+ Float size = (Float)aci.getAttribute(TextAttribute.SIZE);
+ if (size == null) {
return loc;
}
+ int fontSize = (size == null) ? 10000 : size.intValue() * 1000;
+
Float posture = (Float)aci.getAttribute(TextAttribute.POSTURE);
Float taWeight = (Float)aci.getAttribute(TextAttribute.WEIGHT);
@@ -294,13 +299,13 @@
g2d.setPaint(foreground);
g2d.setStroke(stroke);
- Font font = makeFont(aci);
- java.awt.Font awtFont = makeAWTFont(aci, font);
+ FontUse fontUse = makeFont(aci, fontSize);
+ java.awt.Font awtFont = makeAWTFont(aci, fontUse, fontSize / 1000);
g2d.setFont(awtFont);
String txt = getText(aci);
- float advance = getStringWidth(txt, font);
+ float advance = fontUse.getFont().width(txt, fontSize, 0, 0) / 1000f;
float tx = 0;
if (anchor != null) {
switch (anchor.getType()) {
@@ -357,27 +362,29 @@
}
}
- private String getStyle(AttributedCharacterIterator aci) {
+ private byte getStyle(AttributedCharacterIterator aci) {
Float posture = (Float)aci.getAttribute(TextAttribute.POSTURE);
return ((posture != null) && (posture.floatValue() > 0.0))
- ? "italic"
- : "normal";
+ ? Font.FONT_STYLE_ITALIC
+ : Font.FONT_STYLE_NORMAL;
}
- private int getWeight(AttributedCharacterIterator aci) {
+ private short getWeight(AttributedCharacterIterator aci) {
Float taWeight = (Float)aci.getAttribute(TextAttribute.WEIGHT);
return ((taWeight != null) && (taWeight.floatValue() > 1.0))
- ? Font.BOLD
- : Font.NORMAL;
+ ? Font.FONT_WEIGHT_BOLD
+ : Font.FONT_WEIGHT_NORMAL;
}
- private Font makeFont(AttributedCharacterIterator aci) {
- Float fontSize = (Float)aci.getAttribute(TextAttribute.SIZE);
- if (fontSize == null) {
- fontSize = new Float(10.0f);
- }
- String style = getStyle(aci);
- int weight = getWeight(aci);
+ /**
+ * Make a font suitable for the given aci.
+ * @param aci
+ * @param fontSize font size in millipoints.
+ * @return a suitable font use.
+ */
+ private FontUse makeFont(AttributedCharacterIterator aci, int fontSize) {
+ byte style = getStyle(aci);
+ short weight = getWeight(aci);
boolean found = false;
FontInfo fontInfo = nativeTextHandler.getFontInfo();
@@ -386,6 +393,8 @@
GVTAttributedCharacterIterator.TextAttribute.GVT_FONT_FAMILIES);
if (gvtFonts != null) {
Iterator i = gvtFonts.iterator();
+ String[] fontFamilies = new String[gvtFonts.size()];
+ int index = 0;
while (i.hasNext()) {
GVTFontFamily fam = (GVTFontFamily) i.next();
/* (todo) Enable SVG Font painting
@@ -393,6 +402,9 @@
PROXY_PAINTER.paint(node, g2d);
return;
}*/
+<<<<<<< .mine
+ fontFamilies[index++] = fam.getFamilyName();
+=======
fontFamily = fam.getFamilyName();
if (fontInfo.hasFont(fontFamily, style, weight)) {
FontTriplet triplet = fontInfo.fontLookup(
@@ -400,53 +412,83 @@
int fsize = (int)(fontSize.floatValue() * 1000);
return fontInfo.getFontInstance(triplet, fsize);
}
+>>>>>>> .r448139
}
+ int currentPos = aci.getIndex();
+ try {
+ font = fontConsumer.getFontServer().
+ selectFontXSL(fontConsumer, fontFamilies, style, weight,
+ Font.FONT_VARIANT_NORMAL, Font.FONT_STRETCH_NORMAL,
+ fontSize, aci.first());
+ } catch (FontException f) {
+ try {
+ font = fontConsumer.getFontServer().
+ selectFontXSL(fontConsumer, new String[] {"any"}, style,
+ Font.FONT_WEIGHT_ANY,
+ Font.FONT_VARIANT_ANY,
+ Font.FONT_STRETCH_ANY,
+ fontSize, aci.first());
+ } catch (FontException e) { /* Should never happen */ }
+ }
+ aci.setIndex(currentPos);
}
+<<<<<<< .mine
+ return font;
+=======
FontTriplet triplet = fontInfo.fontLookup("any", style, Font.NORMAL);
int fsize = (int)(fontSize.floatValue() * 1000);
return fontInfo.getFontInstance(triplet, fsize);
+>>>>>>> .r448139
}
- private java.awt.Font makeAWTFont(AttributedCharacterIterator aci, Font font) {
- final String style = getStyle(aci);
- final int weight = getWeight(aci);
+ /**
+ * Make an AWT font corresponding to the given font use.
+ * @param aci
+ * @param fontUse the font use.
+ * @param fontSize the font size in points.
+ * @return the corresponding AWT font.
+ */
+ private java.awt.Font makeAWTFont(AttributedCharacterIterator aci,
+ FontUse fontUse,
+ int fontSize) {
+ final byte style = getStyle(aci);
+ final short weight = getWeight(aci);
int fStyle = java.awt.Font.PLAIN;
- if (weight == Font.BOLD) {
+ if (weight == Font.FONT_WEIGHT_BOLD) {
fStyle |= java.awt.Font.BOLD;
}
- if ("italic".equals(style)) {
+ if (style == Font.FONT_STYLE_ITALIC) {
fStyle |= java.awt.Font.ITALIC;
}
- return new java.awt.Font(font.getFontName(), fStyle,
- (int)(font.getFontSize() / 1000));
+ return new java.awt.Font(fontUse.postscriptName(), fStyle, fontSize);
}
- private float getStringWidth(String str, Font font) {
- float wordWidth = 0;
- float whitespaceWidth = font.getWidth(font.mapChar(' '));
+// private float getStringWidth(String str, Font font) {
+// float wordWidth = 0;
+// float whitespaceWidth = font.getWidth(font.mapChar(' '));
+//
+// for (int i = 0; i < str.length(); i++) {
+// float charWidth;
+// char c = str.charAt(i);
+// if (!((c == ' ') || (c == '\n') || (c == '\r') || (c == '\t'))) {
+// charWidth = font.getWidth(font.mapChar(c));
+// if (charWidth <= 0) {
+// charWidth = whitespaceWidth;
+// }
+// } else {
+// charWidth = whitespaceWidth;
+// }
+// wordWidth += charWidth;
+// }
+// return wordWidth / 1000f;
+// }
+ private boolean hasUnsupportedGlyphs(String str, FontUse font) {
for (int i = 0; i < str.length(); i++) {
float charWidth;
char c = str.charAt(i);
if (!((c == ' ') || (c == '\n') || (c == '\r') || (c == '\t'))) {
- charWidth = font.getWidth(font.mapChar(c));
- if (charWidth <= 0) {
- charWidth = whitespaceWidth;
- }
- } else {
- charWidth = whitespaceWidth;
- }
- wordWidth += charWidth;
- }
- return wordWidth / 1000f;
- }
-
- private boolean hasUnsupportedGlyphs(String str, Font font) {
- for (int i = 0; i < str.length(); i++) {
- float charWidth;
- char c = str.charAt(i);
- if (!((c == ' ') || (c == '\n') || (c == '\r') || (c == '\t'))) {
- if (!font.hasChar(c)) {
+ if (!font.glyphAvailable(c)) {
return true;
}
}
diff --git a/src/java/org/apache/fop/render/ps/PSTranscoder.java b/src/java/org/apache/fop/render/ps/PSTranscoder.java
index bc33bae..8d6c1c3 100644
--- a/src/java/org/apache/fop/render/ps/PSTranscoder.java
+++ b/src/java/org/apache/fop/render/ps/PSTranscoder.java
@@ -60,7 +60,7 @@
/** @see AbstractPSTranscoder#createDocumentGraphics2D() */
protected AbstractPSDocumentGraphics2D createDocumentGraphics2D() {
- return new PSDocumentGraphics2D(false);
+ return new PSDocumentGraphics2D(false, getFontMap());
}
}
diff --git a/src/java/org/apache/fop/render/rtf/RTFHandler.java b/src/java/org/apache/fop/render/rtf/RTFHandler.java
index c751a42..f18d561 100644
--- a/src/java/org/apache/fop/render/rtf/RTFHandler.java
+++ b/src/java/org/apache/fop/render/rtf/RTFHandler.java
@@ -93,7 +93,6 @@
import org.apache.fop.render.rtf.rtflib.rtfdoc.IRtfTableContainer;
import org.apache.fop.render.rtf.rtflib.tools.BuilderContext;
import org.apache.fop.render.rtf.rtflib.tools.TableContext;
-import org.apache.fop.fonts.FontSetup;
import org.apache.fop.image.FopImage;
import org.apache.fop.image.ImageFactory;
import org.apache.fop.image.XMLImage;
@@ -138,8 +137,6 @@
super(userAgent);
this.os = os;
bDefer = true;
-
- FontSetup.setup(fontInfo, null, new DefaultFontResolver(userAgent));
}
/**
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfListStyle.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfListStyle.java
index 7ae121c..b7925a1 100644
--- a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfListStyle.java
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfListStyle.java
@@ -87,4 +87,4 @@
public void writeLevelGroup(RtfElement element)
throws IOException {
}
-}
\ No newline at end of file
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfPageNumberCitation.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfPageNumberCitation.java
index c7f455c..c552316 100644
--- a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfPageNumberCitation.java
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfPageNumberCitation.java
@@ -109,4 +109,4 @@
public boolean isEmpty() {
return false;
}
-}
\ No newline at end of file
+}
diff --git a/src/java/org/apache/fop/render/xml/XMLRenderer.java b/src/java/org/apache/fop/render/xml/XMLRenderer.java
index fe2fdd2..99085d8 100644
--- a/src/java/org/apache/fop/render/xml/XMLRenderer.java
+++ b/src/java/org/apache/fop/render/xml/XMLRenderer.java
@@ -78,10 +78,9 @@
import org.apache.fop.area.inline.TextArea;
import org.apache.fop.area.inline.Viewport;
import org.apache.fop.area.inline.WordArea;
+import org.axsl.font.FontUse;
import org.apache.fop.fo.Constants;
import org.apache.fop.fo.extensions.ExtensionAttachment;
-import org.apache.fop.fonts.FontInfo;
-import org.apache.fop.fonts.FontSetup;
import org.apache.fop.fonts.FontTriplet;
import org.apache.fop.render.PrintRenderer;
import org.apache.fop.render.Renderer;
@@ -144,13 +143,6 @@
*/
public void configure(Configuration cfg) throws ConfigurationException {
super.configure(cfg);
- //Font configuration
- List cfgFonts = FontSetup.buildFontListFromConfiguration(cfg);
- if (this.fontList == null) {
- this.fontList = cfgFonts;
- } else {
- this.fontList.addAll(cfgFonts);
- }
}
/**
@@ -346,10 +338,11 @@
}
Object value = traitEntry.getValue();
if (key == Trait.FONT) {
- FontTriplet triplet = (FontTriplet)value;
- addAttribute("font-name", triplet.getName());
- addAttribute("font-style", triplet.getStyle());
- addAttribute("font-weight", triplet.getWeight());
+ FontUse fontUse = (FontUse) traitEntry.getValue();
+ addAttribute("font-name", fontUse.postscriptName());
+ // Style and weight should be present in the postscript name
+// addAttribute("font-style", triplet.getStyle());
+// addAttribute("font-weight", triplet.getWeight());
} else if (clazz.equals(Background.class)) {
Background bkg = (Background)value;
//TODO Remove the following line (makes changes in the test checks necessary)
diff --git a/src/java/org/apache/fop/svg/AbstractFOPTranscoder.java b/src/java/org/apache/fop/svg/AbstractFOPTranscoder.java
index b116158..d913083 100644
--- a/src/java/org/apache/fop/svg/AbstractFOPTranscoder.java
+++ b/src/java/org/apache/fop/svg/AbstractFOPTranscoder.java
@@ -19,10 +19,14 @@
package org.apache.fop.svg;
+import java.net.MalformedURLException;
+
import org.xml.sax.EntityResolver;
import org.apache.commons.logging.impl.SimpleLog;
import org.apache.commons.logging.Log;
+import org.apache.fop.pdf.FontMap;
+import org.apache.fop.tools.CommonsLogger;
import org.apache.batik.bridge.UserAgent;
import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.apache.batik.dom.util.DocumentFactory;
@@ -33,13 +37,17 @@
import org.apache.batik.transcoder.image.ImageTranscoder;
import org.apache.batik.transcoder.keys.BooleanKey;
import org.apache.batik.util.SVGConstants;
+import org.axsl.common.PseudoLogger;
+import org.axsl.font.FontConsumer;
+import org.axsl.font.FontException;
+import org.axsl.font.FontServer;
+import org.foray.font.FOrayFontServer;
import org.w3c.dom.DOMImplementation;
/**
* This is the common base class of all of FOP's transcoders.
*/
-public abstract class AbstractFOPTranscoder extends SVGAbstractTranscoder
- {
+public abstract class AbstractFOPTranscoder extends SVGAbstractTranscoder implements FontConsumer {
/**
* The key to specify whether to stroke text instead of using text
@@ -59,20 +67,89 @@
protected UserAgent userAgent = createUserAgent();
private Log logger;
+ /** PseudoLogger wrapper around logger. For adaptation to the aXSL interface. */
+ private PseudoLogger pseudoLogger;
private EntityResolver resolver;
+ private FontMap fontMap;
+
+ private FontServer fontServer;
+
/**
* Constructs a new FOP-style transcoder.
+ *
+ * @param registerAllFonts if <code>true</code>, all the fonts know by font
+ * server will be given an internal font name (this is useful for the PS
+ * transcoder). Otherwise internal names will be assigned only when needed.
*/
- public AbstractFOPTranscoder() {
+ public AbstractFOPTranscoder(boolean registerAllFonts) {
hints.put(KEY_DOCUMENT_ELEMENT_NAMESPACE_URI,
SVGConstants.SVG_NAMESPACE_URI);
hints.put(KEY_DOCUMENT_ELEMENT, SVGConstants.SVG_SVG_TAG);
hints.put(KEY_DOM_IMPLEMENTATION,
SVGDOMImplementation.getDOMImplementation());
+
+ try {
+ fontServer = new FOrayFontServer(getPseudoLogger());
+ /* TODO vh: plug font config file */
+ ((FOrayFontServer) fontServer).setBaseFontURL(new java.net.URL("file://"));
+ ((FOrayFontServer) fontServer).setup(
+// new java.net.URL("file:///path/to/axsl-font-conf.xml"), null);
+ new java.net.URL(System.getProperty("font.config.file")), null);
+ } catch (MalformedURLException e) {
+ // Should never happen
+ } catch (FontException e) {
+ // TODO vh
+ e.printStackTrace();
+ }
+
+ fontMap = new FontMap(this, registerAllFonts);
}
/**
+ * @see org.axsl.font.FontConsumer#getFontServer()
+ */
+ public FontServer getFontServer() {
+ return fontServer;
+ }
+
+ /**
+ * @see org.axsl.font.FontConsumer#getPseudoLogger()
+ */
+ public PseudoLogger getPseudoLogger() {
+ return pseudoLogger;
+ }
+
+ /**
+ * @see org.axsl.font.FontConsumer#isUsingFreeStandingFonts()
+ */
+ public boolean isUsingFreeStandingFonts() {
+ return true;
+ }
+
+ /**
+ * @see org.axsl.font.FontConsumer#isUsingSystemFonts()
+ */
+ public boolean isUsingSystemFonts() {
+ return false;
+ }
+
+ /**
+ * @see org.axsl.font.FontConsumer#preferFreeStandingFonts()
+ */
+ public boolean preferFreeStandingFonts() {
+ return true;
+ }
+
+ /**
+ * Return the mappings of FontUses to their associated internal names.
+ * @return the font map associated to this transcoder.
+ */
+ protected FontMap getFontMap() {
+ return fontMap;
+ }
+
+ /**
* Creates and returns the default user agent for this transcoder. Override
* this method if you need non-default behaviour.
* @return UserAgent the newly created user agent
@@ -83,6 +160,7 @@
public void setLogger(Log logger) {
this.logger = logger;
+ this.pseudoLogger = new CommonsLogger(logger);
}
/**
diff --git a/src/java/org/apache/fop/svg/PDFBridgeContext.java b/src/java/org/apache/fop/svg/PDFBridgeContext.java
index 3d5fc4e..606c42f 100644
--- a/src/java/org/apache/fop/svg/PDFBridgeContext.java
+++ b/src/java/org/apache/fop/svg/PDFBridgeContext.java
@@ -24,15 +24,16 @@
import org.apache.batik.bridge.BridgeContext;
import org.apache.batik.bridge.DocumentLoader;
import org.apache.batik.bridge.UserAgent;
-import org.apache.fop.fonts.FontInfo;
+
+import org.axsl.font.FontConsumer;
/**
* BridgeContext which registers the custom bridges for PDF output.
*/
public class PDFBridgeContext extends BridgeContext {
- /** The font list. */
- private final FontInfo fontInfo;
+ /** The font consumer. */
+ private final FontConsumer fontConsumer;
private AffineTransform linkTransform;
@@ -40,51 +41,51 @@
* Constructs a new bridge context.
* @param userAgent the user agent
* @param loader the Document Loader to use for referenced documents.
- * @param fontInfo the font list for the text painter, may be null
+ * @param fontConsumer the font consumer, may be null
* in which case text is painted as shapes
* @param linkTransform AffineTransform to properly place links,
* may be null
*/
public PDFBridgeContext(UserAgent userAgent,
DocumentLoader loader,
- FontInfo fontInfo,
+ FontConsumer fontConsumer,
AffineTransform linkTransform) {
super(userAgent, loader);
- this.fontInfo = fontInfo;
+ this.fontConsumer = fontConsumer;
this.linkTransform = linkTransform;
}
/**
* Constructs a new bridge context.
* @param userAgent the user agent
- * @param fontInfo the font list for the text painter, may be null
+ * @param fontConsumer the font consumer, may be null
* in which case text is painted as shapes
* @param linkTransform AffineTransform to properly place links,
* may be null
*/
- public PDFBridgeContext(UserAgent userAgent, FontInfo fontInfo,
+ public PDFBridgeContext(UserAgent userAgent, FontConsumer fontConsumer,
AffineTransform linkTransform) {
super(userAgent);
- this.fontInfo = fontInfo;
+ this.fontConsumer = fontConsumer;
this.linkTransform = linkTransform;
}
/**
* Constructs a new bridge context.
* @param userAgent the user agent
- * @param fontInfo the font list for the text painter, may be null
+ * @param fontConsumer the font consumer, may be null
* in which case text is painted as shapes
*/
- public PDFBridgeContext(UserAgent userAgent, FontInfo fontInfo) {
- this(userAgent, fontInfo, null);
+ public PDFBridgeContext(UserAgent userAgent, FontConsumer fontConsumer) {
+ this(userAgent, fontConsumer, null);
}
/** @see org.apache.batik.bridge.BridgeContext#registerSVGBridges() */
public void registerSVGBridges() {
super.registerSVGBridges();
- if (fontInfo != null) {
- putBridge(new PDFTextElementBridge(fontInfo));
+ if (fontConsumer != null) {
+ putBridge(new PDFTextElementBridge(fontConsumer));
}
PDFAElementBridge pdfAElementBridge = new PDFAElementBridge();
@@ -101,6 +102,6 @@
// Make sure any 'sub bridge contexts' also have our bridges.
public BridgeContext createBridgeContext() {
return new PDFBridgeContext(getUserAgent(), getDocumentLoader(),
- fontInfo, linkTransform);
+ fontConsumer, linkTransform);
}
}
diff --git a/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java b/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java
index 0e699de..3049ce5 100644
--- a/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java
+++ b/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java
@@ -19,6 +19,7 @@
package org.apache.fop.svg;
+import org.apache.fop.pdf.FontMap;
import org.apache.fop.pdf.PDFDocument;
import org.apache.fop.pdf.PDFFilterList;
import org.apache.fop.pdf.PDFPage;
@@ -28,8 +29,6 @@
import org.apache.fop.pdf.PDFResources;
import org.apache.fop.pdf.PDFColor;
import org.apache.fop.pdf.PDFAnnotList;
-import org.apache.fop.fonts.FontSetup;
-import org.apache.fop.fonts.FontInfo;
import org.apache.avalon.framework.CascadingRuntimeException;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.configuration.Configurable;
@@ -102,9 +101,10 @@
*
* @param textAsShapes set this to true so that text will be rendered
* using curves and not the font.
+ * @param fontMap mappings of FontUses to their associated internal names.
*/
- public PDFDocumentGraphics2D(boolean textAsShapes) {
- super(textAsShapes);
+ public PDFDocumentGraphics2D(boolean textAsShapes, FontMap fontMap) {
+ super(textAsShapes, fontMap);
this.pdfContext = new PDFContext();
if (!textAsShapes) {
@@ -129,15 +129,16 @@
*
* @param textAsShapes set this to true so that text will be rendered
* using curves and not the font.
+ * @param fontMap mappings of FontUses to their associated internal names.
* @param stream the stream that the final document should be written to.
* @param width the width of the document
* @param height the height of the document
* @throws IOException an io exception if there is a problem
* writing to the output stream
*/
- public PDFDocumentGraphics2D(boolean textAsShapes, OutputStream stream,
+ public PDFDocumentGraphics2D(boolean textAsShapes, FontMap fontMap, OutputStream stream,
int width, int height) throws IOException {
- this(textAsShapes);
+ this(textAsShapes, fontMap);
setupDocument(stream, width, height);
}
@@ -148,9 +149,10 @@
* for the bridge before the document size is known.
* The resulting document is written to the stream after rendering.
* This constructor is Avalon-style.
+ * @param fontMap mappings of FontUses to their associated internal names.
*/
- public PDFDocumentGraphics2D() {
- this(false);
+ public PDFDocumentGraphics2D(FontMap fontMap) {
+ this(false, fontMap);
}
/**
@@ -158,7 +160,6 @@
*/
public void configure(Configuration cfg) throws ConfigurationException {
this.cfg = cfg;
- this.pdfContext.setFontList(FontSetup.buildFontListFromConfiguration(cfg));
}
/**
@@ -213,14 +214,6 @@
}
/**
- * Get the font info for this pdf document.
- * @return the font information
- */
- public FontInfo getFontInfo() {
- return fontInfo;
- }
-
- /**
* Get the pdf document created by this class.
* @return the pdf document
*/
@@ -322,7 +315,7 @@
setClip(this.initialClip);
}
- currentFontName = "";
+ currentFontUse = null;
currentFontSize = 0;
if (currentStream == null) {
@@ -373,8 +366,8 @@
// restorePDFState();
closePage();
- if (fontInfo != null) {
- pdfDoc.getResources().addFonts(pdfDoc, fontInfo);
+ if (fontMap.getSize() != 0) {
+ pdfDoc.getResources().addFonts(pdfDoc, fontMap);
}
this.pdfDoc.output(outputStream);
pdfDoc.outputTrailer(outputStream);
diff --git a/src/java/org/apache/fop/svg/PDFGraphics2D.java b/src/java/org/apache/fop/svg/PDFGraphics2D.java
index 0e82197..69f223b 100644
--- a/src/java/org/apache/fop/svg/PDFGraphics2D.java
+++ b/src/java/org/apache/fop/svg/PDFGraphics2D.java
@@ -19,6 +19,7 @@
package org.apache.fop.svg;
+import org.apache.fop.pdf.FontMap;
import org.apache.fop.pdf.PDFConformanceException;
import org.apache.fop.pdf.PDFResourceContext;
import org.apache.fop.pdf.PDFResources;
@@ -34,13 +35,7 @@
import org.apache.fop.pdf.PDFLink;
import org.apache.fop.pdf.PDFAnnotList;
import org.apache.fop.pdf.BitmapImage;
-import org.apache.fop.fonts.FontInfo;
-import org.apache.fop.fonts.Font;
-import org.apache.fop.fonts.FontSetup;
-import org.apache.fop.fonts.FontTriplet;
-import org.apache.fop.fonts.LazyFont;
import org.apache.fop.image.JpegImage;
-import org.apache.fop.fonts.CIDFont;
import org.apache.fop.render.pdf.FopPDFImage;
import org.apache.xmlgraphics.java2d.AbstractGraphics2D;
@@ -53,6 +48,11 @@
import org.apache.batik.gvt.PatternPaint;
import org.apache.batik.gvt.GraphicsNode;
+import org.axsl.fontR.Font;
+import org.axsl.fontR.FontConsumer;
+import org.axsl.fontR.FontException;
+import org.axsl.fontR.FontUse;
+
import java.text.AttributedCharacterIterator;
import java.text.CharacterIterator;
import java.awt.Graphics;
@@ -141,15 +141,21 @@
protected int[] jpegCount = {0};
/**
- * The current font information.
+ * The font map.
*/
- protected FontInfo fontInfo;
+ protected FontMap fontMap;
/**
* The override font state used when drawing text and the font cannot be
* set using java fonts.
*/
- protected Font ovFontState = null;
+ protected FontUse ovFontUse = null;
+
+ /**
+ * The override font size (in millipoint) used when drawing text and the font cannot be
+ * set using java fonts.
+ */
+ protected int ovFontSize;
/**
* the current stream to add PDF commands to
@@ -157,14 +163,14 @@
protected StringWriter currentStream = new StringWriter();
/**
- * the current (internal) font name
+ * the current font use
*/
- protected String currentFontName;
+ protected FontUse currentFontUse;
/**
* the current font size in millipoints
*/
- protected float currentFontSize;
+ protected int currentFontSize;
/**
* The output stream for the pdf document.
@@ -180,21 +186,20 @@
* existing document.
*
* @param textAsShapes if true then draw text as shapes
- * @param fi the current font information
+ * @param fontMap the font map
* @param doc the pdf document for creating pdf objects
* @param page the current resource context or page
* @param pref the PDF reference of the current page
- * @param font the current font name
- * @param size the current font size
+ * @param fontUse the current font use
+ * @param size the current font size in millipoints
*/
- public PDFGraphics2D(boolean textAsShapes, FontInfo fi, PDFDocument doc,
- PDFResourceContext page, String pref, String font, float size) {
- this(textAsShapes);
+ public PDFGraphics2D(boolean textAsShapes, FontMap fontMap, PDFDocument doc,
+ PDFResourceContext page, String pref, FontUse fontUse, int size) {
+ this(textAsShapes, fontMap);
pdfDoc = doc;
resourceContext = page;
- currentFontName = font;
+ currentFontUse = fontUse;
currentFontSize = size;
- fontInfo = fi;
pageRef = pref;
graphicsState = new PDFState();
}
@@ -203,9 +208,11 @@
* Create a new PDFGraphics2D.
*
* @param textAsShapes true if drawing text as shapes
+ * @param fontMap the mappings of fonts to their corresponding internal names
*/
- protected PDFGraphics2D(boolean textAsShapes) {
+ protected PDFGraphics2D(boolean textAsShapes, FontMap fontMap) {
super(textAsShapes);
+ this.fontMap = fontMap;
}
/**
@@ -218,18 +225,27 @@
super(g);
this.pdfDoc = g.pdfDoc;
this.resourceContext = g.resourceContext;
- this.currentFontName = g.currentFontName;
+ this.currentFontUse = g.currentFontUse;
this.currentFontSize = g.currentFontSize;
- this.fontInfo = g.fontInfo;
+ this.fontMap = g.fontMap;
this.pageRef = g.pageRef;
this.graphicsState = g.graphicsState;
this.currentStream = g.currentStream;
this.jpegCount = g.jpegCount;
this.outputStream = g.outputStream;
- this.ovFontState = g.ovFontState;
+ this.ovFontUse = g.ovFontUse;
+ this.ovFontSize = g.ovFontSize;
}
/**
+ * Return the font consumer associated to this document.
+ * @return the font consumer.
+ */
+ public FontConsumer getFontConsumer() {
+ return fontMap.getFontConsumer();
+ }
+
+ /**
* Creates a new <code>Graphics</code> object that is
* a copy of this <code>Graphics</code> object.
* @return a new graphics context that is a copy of
@@ -312,15 +328,27 @@
}
/**
- * Set the override font state for drawing text.
+ * Set the override font use for drawing text.
* This is used by the PDF text painter so that it can temporarily
* set the font state when a java font cannot be used.
* The next drawString will use this font state.
*
- * @param infont the font state to use
+ * @param infont the FontUse to use
*/
- public void setOverrideFontState(Font infont) {
- ovFontState = infont;
+ public void setOverrideFontUse(FontUse infont) {
+ ovFontUse = infont;
+ }
+
+ /**
+ * Set the override font size for drawing text.
+ * This is used by the PDF text painter so that it can temporarily
+ * set the font state when a java font cannot be used.
+ * The next drawString will use this font state.
+ *
+ * @param insize the font size to use
+ */
+ public void setOverrideFontSize(int insize) {
+ ovFontSize = insize;
}
/**
@@ -655,9 +683,9 @@
*/
public void dispose() {
pdfDoc = null;
- fontInfo = null;
+ fontMap = null;
currentStream = null;
- currentFontName = null;
+ currentFontUse = null;
}
/**
@@ -1056,14 +1084,11 @@
private boolean createPattern(PatternPaint pp, boolean fill) {
preparePainting();
- FontInfo fontInfo = new FontInfo();
- FontSetup.setup(fontInfo, null, null);
-
PDFResources res = pdfDoc.getFactory().makeResources();
PDFResourceContext context = new PDFResourceContext(res);
- PDFGraphics2D pattGraphic = new PDFGraphics2D(textAsShapes, fontInfo,
+ PDFGraphics2D pattGraphic = new PDFGraphics2D(textAsShapes, fontMap,
pdfDoc, context, pageRef,
- "", 0);
+ null, 0);
pattGraphic.setGraphicContext(new GraphicContext());
pattGraphic.gc.validateTransformStack();
pattGraphic.setRenderingHints(this.getRenderingHints());
@@ -1127,7 +1152,7 @@
/** @todo see if pdfDoc and res can be linked here,
(currently res <> PDFDocument's resources) so addFonts()
can be moved to PDFDocument class */
- res.addFonts(pdfDoc, fontInfo);
+// res.addFonts(pdfDoc, fontInfo);
PDFPattern myPat = pdfDoc.getFactory().makePattern(
resourceContext, 1, res, 1, 1, bbox,
@@ -1413,35 +1438,49 @@
public void drawString(String s, float x, float y) {
preparePainting();
- Font fontState;
AffineTransform fontTransform = null;
- if (ovFontState == null) {
+ FontUse fontUse = null;
+ int size;
+ if (ovFontUse == null) {
+ FontConsumer fontConsumer = fontMap.getFontConsumer();
java.awt.Font gFont = getFont();
fontTransform = gFont.getTransform();
String n = gFont.getFamily();
if (n.equals("sanserif")) {
n = "sans-serif";
}
- float siz = gFont.getSize2D();
- String style = gFont.isItalic() ? "italic" : "normal";
- int weight = gFont.isBold() ? Font.BOLD : Font.NORMAL;
- FontTriplet triplet = fontInfo.fontLookup(n, style, weight);
- fontState = fontInfo.getFontInstance(triplet, (int)(siz * 1000 + 0.5));
+ // TODO adapt
+// size = gFont.getSize() * 1000;
+ size = (int) gFont.getSize2D() * 1000;
+ byte style = gFont.isItalic() ? Font.FONT_STYLE_ITALIC : Font.FONT_STYLE_NORMAL;
+ short weight = gFont.isBold() ? Font.FONT_WEIGHT_BOLD : Font.FONT_WEIGHT_NORMAL;
+ try {
+ fontUse = fontConsumer.selectFontXSL(Font.FONT_SELECTION_AUTO,
+ new String[] {n}, style, weight, Font.FONT_VARIANT_NORMAL,
+ Font.FONT_STRETCH_NORMAL, size, s.charAt(0));
+ } catch (FontException e) {
+ try {
+ fontUse = fontConsumer.selectFontXSL(Font.FONT_SELECTION_AUTO,
+ new String[] {"any"},
+ Font.FONT_STYLE_ANY,
+ Font.FONT_WEIGHT_ANY,
+ Font.FONT_VARIANT_ANY,
+ Font.FONT_STRETCH_ANY,
+ size, s.charAt(0));
+ } catch (FontException e1) { /* Should never happen */ }
+ }
} else {
- fontState = fontInfo.getFontInstance(
- ovFontState.getFontTriplet(), ovFontState.getFontSize());
- ovFontState = null;
+ fontUse = ovFontUse;
+ ovFontUse = null;
+ size = ovFontSize;
}
- String name;
- float size;
- name = fontState.getFontName();
- size = (float)fontState.getFontSize() / 1000f;
-
- if ((!name.equals(this.currentFontName))
+
+ if ((!fontUse.equals(this.currentFontUse))
|| (size != this.currentFontSize)) {
- this.currentFontName = name;
+ this.currentFontUse = fontUse;
this.currentFontSize = size;
- currentStream.write("/" + name + " " + size + " Tf\n");
+ String name = fontMap.getInternalName(fontUse);
+ currentStream.write("/" + name + " " + ((float)size) / 1000f + " Tf\n");
}
@@ -1465,22 +1504,15 @@
Map kerning = null;
boolean kerningAvailable = false;
+ /* TODO vh: kerning is yet unimplemented
kerning = fontState.getKerning();
if (kerning != null && !kerning.isEmpty()) {
kerningAvailable = true;
}
+ */
// This assumes that *all* CIDFonts use a /ToUnicode mapping
- boolean useMultiByte = false;
- org.apache.fop.fonts.Typeface f =
- (org.apache.fop.fonts.Typeface)fontInfo.getFonts().get(name);
- if (f instanceof LazyFont) {
- if (((LazyFont) f).getRealFont() instanceof CIDFont) {
- useMultiByte = true;
- }
- } else if (f instanceof CIDFont) {
- useMultiByte = true;
- }
+ boolean useMultiByte = fontUse.getFont().getFontComplexity() == Font.FONT_COMPOSITE;
// String startText = useMultiByte ? "<FEFF" : "(";
String startText = useMultiByte ? "<" : "(";
@@ -1513,7 +1545,7 @@
int l = s.length();
for (int i = 0; i < l; i++) {
- char ch = fontState.mapChar(s.charAt(i));
+ int ch = fontUse.encodeCharacter(s.charAt(i));
if (!useMultiByte) {
if (ch > 127) {
@@ -1534,9 +1566,9 @@
}
if (kerningAvailable && (i + 1) < l) {
- addKerning(currentStream, (new Integer((int)ch)),
- (new Integer((int)fontState.mapChar(s.charAt(i + 1)))),
- kerning, startText, endText);
+// addKerning(currentStream, (new Integer((int)ch)),
+// (new Integer((int)fontState.mapChar(s.charAt(i + 1)))),
+// kerning, startText, endText);
}
}
@@ -1631,16 +1663,17 @@
ch = iterator.next()) {
//Map attr = iterator.getAttributes();
- String name = fontState.getFontName();
- int size = fontState.getFontSize();
- if ((!name.equals(this.currentFontName))
- || (size != this.currentFontSize)) {
- this.currentFontName = name;
- this.currentFontSize = size;
- currentStream.write("/" + name + " " + (size / 1000)
- + " Tf\n");
-
- }
+ // TODO vh: commented out because obsolete
+ // anyway it couldn't work (NPE because fontState == null)
+// int size = fontState.getFontSize();
+// if ((!fontUse.equals(this.currentFontUse))
+// || (size != this.currentFontSize)) {
+// this.currentFontUse = fontUse;
+// this.currentFontSize = size;
+// currentStream.write("/" + name + " " + (size / 1000)
+// + " Tf\n");
+//
+// }
currentStream.write(PDFNumber.doubleOut(vals[0], DEC) + " "
+ PDFNumber.doubleOut(vals[1], DEC) + " "
diff --git a/src/java/org/apache/fop/svg/PDFTextElementBridge.java b/src/java/org/apache/fop/svg/PDFTextElementBridge.java
index cf9b7b7..28a3a4c 100644
--- a/src/java/org/apache/fop/svg/PDFTextElementBridge.java
+++ b/src/java/org/apache/fop/svg/PDFTextElementBridge.java
@@ -25,7 +25,7 @@
import org.apache.batik.bridge.TextUtilities;
import org.apache.batik.gvt.GraphicsNode;
-import org.apache.fop.fonts.FontInfo;
+import org.axsl.font.FontConsumer;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -42,10 +42,10 @@
/**
* Constructs a new bridge for the <text> element.
- * @param fi the font infomration
+ * @param fc the font consumer
*/
- public PDFTextElementBridge(FontInfo fi) {
- pdfTextPainter = new PDFTextPainter(fi);
+ public PDFTextElementBridge(FontConsumer fc) {
+ pdfTextPainter = new PDFTextPainter(fc);
}
/**
diff --git a/src/java/org/apache/fop/svg/PDFTextPainter.java b/src/java/org/apache/fop/svg/PDFTextPainter.java
index eddd89d..4c95c71 100644
--- a/src/java/org/apache/fop/svg/PDFTextPainter.java
+++ b/src/java/org/apache/fop/svg/PDFTextPainter.java
@@ -23,7 +23,7 @@
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
/* java.awt.Font is not imported to avoid confusion with
- org.apache.fop.fonts.Font */
+ org.axsl.font.Font */
import java.text.AttributedCharacterIterator;
import java.awt.font.TextAttribute;
import java.awt.Shape;
@@ -42,8 +42,11 @@
import org.apache.batik.bridge.SVGFontFamily;
import org.apache.batik.gvt.renderer.StrokingTextPainter;
-import org.apache.fop.fonts.Font;
-import org.apache.fop.fonts.FontInfo;
+import org.axsl.font.Font;
+import org.axsl.font.FontConsumer;
+import org.axsl.font.FontException;
+import org.axsl.font.FontServer;
+import org.axsl.font.FontUse;
import org.apache.fop.fonts.FontTriplet;
/**
@@ -61,7 +64,7 @@
* @version $Id$
*/
public class PDFTextPainter implements TextPainter {
- private FontInfo fontInfo;
+ private FontConsumer fontConsumer;
/**
* Use the stroking text painter to get the bounds and shape.
@@ -74,8 +77,8 @@
* Create a new PDF text painter with the given font information.
* @param fi the fint info
*/
- public PDFTextPainter(FontInfo fi) {
- fontInfo = fi;
+ public PDFTextPainter(FontConsumer fc) {
+ fontConsumer = fc;
}
/**
@@ -115,10 +118,12 @@
Paint forg = tpi.fillPaint;
Paint strokePaint = tpi.strokePaint;
- Float size = (Float) aci.getAttribute(TextAttribute.SIZE);
- if (size == null) {
+ Float fsize = (Float) aci.getAttribute(TextAttribute.SIZE);
+ if (fsize == null) {
return;
}
+ int size = (int) (fsize.floatValue() * 1000f);
+
Stroke stroke = tpi.strokeStroke;
/*
Float xpos = (Float) aci.getAttribute(
@@ -157,18 +162,20 @@
return;
}
- String style = ((posture != null) && (posture.floatValue() > 0.0))
- ? "italic" : "normal";
- int weight = ((taWeight != null)
- && (taWeight.floatValue() > 1.0)) ? Font.BOLD
- : Font.NORMAL;
+ byte style = ((posture != null) && (posture.floatValue() > 0.0))
+ ? Font.FONT_STYLE_ITALIC : Font.FONT_STYLE_NORMAL;
+ short weight = ((taWeight != null)
+ && (taWeight.floatValue() > 1.0)) ? Font.FONT_WEIGHT_BOLD
+ : Font.FONT_WEIGHT_NORMAL;
- Font fontState = null;
- FontInfo fi = fontInfo;
- boolean found = false;
+ FontUse fontUse = null;
+ FontServer fs = fontConsumer.getFontServer();
+ boolean found = true;
String fontFamily = null;
if (gvtFonts != null) {
Iterator i = gvtFonts.iterator();
+ String[] fontFamilies = new String[gvtFonts.size()];
+ int index = 0;
while (i.hasNext()) {
GVTFontFamily fam = (GVTFontFamily) i.next();
if (fam instanceof SVGFontFamily) {
@@ -185,44 +192,56 @@
break;
}
}
+ try {
+ fontUse = fs.selectFontXSL(fontConsumer, fontFamilies, style, weight,
+ Font.FONT_VARIANT_NORMAL, Font.FONT_STRETCH_NORMAL, size, ch);
+ fontFamily = fontUse.postscriptName();
+ } catch (FontException f) {
+ found = false;
+ }
}
if (!found) {
- FontTriplet triplet = fontInfo.fontLookup("any", style, Font.NORMAL);
- int fsize = (int)(size.floatValue() * 1000);
- fontState = fontInfo.getFontInstance(triplet, fsize);
+ try {
+ fontUse = fs.selectFontXSL(fontConsumer, new String[] {"any"},
+ Font.FONT_STYLE_ANY,
+ Font.FONT_WEIGHT_ANY,
+ Font.FONT_VARIANT_ANY,
+ Font.FONT_STRETCH_ANY,
+ size, ch);
+ } catch (FontException e) { /* Should never happen */ }
} else {
if (g2d instanceof PDFGraphics2D) {
- ((PDFGraphics2D) g2d).setOverrideFontState(fontState);
+ ((PDFGraphics2D) g2d).setOverrideFontUse(fontUse);
+ ((PDFGraphics2D) g2d).setOverrideFontSize(size);
}
}
int fStyle = java.awt.Font.PLAIN;
- if (weight == Font.BOLD) {
- if (style.equals("italic")) {
+ if (weight == Font.FONT_WEIGHT_BOLD) {
+ if (style == Font.FONT_STYLE_ITALIC) {
fStyle = java.awt.Font.BOLD | java.awt.Font.ITALIC;
} else {
fStyle = java.awt.Font.BOLD;
}
} else {
- if (style.equals("italic")) {
+ if (style == Font.FONT_STYLE_ITALIC) {
fStyle = java.awt.Font.ITALIC;
} else {
fStyle = java.awt.Font.PLAIN;
}
}
- java.awt.Font font = new java.awt.Font(fontFamily, fStyle,
- (int)(fontState.getFontSize() / 1000));
+ java.awt.Font awtFont = new java.awt.Font(fontFamily, fStyle, size / 1000);
- g2d.setFont(font);
+ g2d.setFont(awtFont);
- float advance = getStringWidth(txt, fontState);
+ float advance = fontUse.getFont().width(txt, size, 0, 0) / 1000f;
float tx = 0;
if (anchor != null) {
switch (anchor.getType()) {
case TextNode.Anchor.ANCHOR_MIDDLE:
- tx = -advance / 2;
+ tx = -advance / 2000f; // convert back into points
break;
case TextNode.Anchor.ANCHOR_END:
- tx = -advance;
+ tx = -advance / 1000f;
}
}
g2d.drawString(txt, (float)(loc.getX() + tx), (float)(loc.getY()));
@@ -259,26 +278,6 @@
return hasunsupported;
}
- private float getStringWidth(String str, Font fontState) {
- float wordWidth = 0;
- float whitespaceWidth = fontState.getWidth(fontState.mapChar(' '));
-
- for (int i = 0; i < str.length(); i++) {
- float charWidth;
- char c = str.charAt(i);
- if (!((c == ' ') || (c == '\n') || (c == '\r') || (c == '\t'))) {
- charWidth = fontState.getWidth(fontState.mapChar(c));
- if (charWidth <= 0) {
- charWidth = whitespaceWidth;
- }
- } else {
- charWidth = whitespaceWidth;
- }
- wordWidth += charWidth;
- }
- return wordWidth / 1000f;
- }
-
/**
* Get the outline shape of the text characters.
* This uses the StrokingTextPainter to get the outline
@@ -395,4 +394,3 @@
}
}
-
diff --git a/src/java/org/apache/fop/svg/PDFTranscoder.java b/src/java/org/apache/fop/svg/PDFTranscoder.java
index a90765a..b5f401d 100644
--- a/src/java/org/apache/fop/svg/PDFTranscoder.java
+++ b/src/java/org/apache/fop/svg/PDFTranscoder.java
@@ -83,7 +83,7 @@
* Constructs a new <tt>ImageTranscoder</tt>.
*/
public PDFTranscoder() {
- super();
+ super(false);
this.handler = new FOPErrorHandler();
}
@@ -119,7 +119,7 @@
TranscoderOutput output)
throws TranscoderException {
- graphics = new PDFDocumentGraphics2D();
+ graphics = new PDFDocumentGraphics2D(getFontMap());
try {
if (this.cfg != null) {
@@ -180,7 +180,7 @@
/** @see org.apache.batik.transcoder.SVGAbstractTranscoder#createBridgeContext() */
protected BridgeContext createBridgeContext() {
- BridgeContext ctx = new PDFBridgeContext(userAgent, graphics.getFontInfo());
+ BridgeContext ctx = new PDFBridgeContext(userAgent, graphics.getFontConsumer());
return ctx;
}
diff --git a/src/java/org/apache/fop/traits/SpaceVal.java b/src/java/org/apache/fop/traits/SpaceVal.java
index 0dae921..da5e214 100644
--- a/src/java/org/apache/fop/traits/SpaceVal.java
+++ b/src/java/org/apache/fop/traits/SpaceVal.java
@@ -23,7 +23,9 @@
import org.apache.fop.fo.Constants;
import org.apache.fop.fo.properties.Property;
import org.apache.fop.fo.properties.SpaceProperty;
-import org.apache.fop.fonts.Font;
+
+import org.axsl.fontR.Font;
+import org.axsl.fontR.FontConsumer;
/**
* Store a single Space property value in simplified form, with all
@@ -72,13 +74,15 @@
this.iPrecedence = iPrecedence;
}
- static public SpaceVal makeWordSpacing(Property wordSpacing,
- SpaceVal letterSpacing,
- Font fs) {
+ public static SpaceVal makeWordSpacing(Property wordSpacing,
+ SpaceVal letterSpacing,
+ Font fs,
+ FontConsumer fontConsumer,
+ int fontSize) {
if (wordSpacing.getEnum() == Constants.EN_NORMAL) {
// give word spaces the possibility to shrink by a third,
// and stretch by a half;
- int spaceCharIPD = fs.getCharWidth(' ');
+ int spaceCharIPD = fs.width(' ', fontSize);
MinOptMax space = new MinOptMax(-spaceCharIPD / 3, 0, spaceCharIPD / 2);
//TODO Adding 2 letter spaces here is not 100% correct. Spaces don't have letter spacing
return new SpaceVal(
@@ -90,7 +94,7 @@
}
}
- static public SpaceVal makeLetterSpacing(Property letterSpacing) {
+ public static SpaceVal makeLetterSpacing(Property letterSpacing) {
if (letterSpacing.getEnum() == Constants.EN_NORMAL) {
// letter spaces are set to zero (or use different values?)
return new SpaceVal(new MinOptMax(0), true, true, 0);
diff --git a/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java b/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java
index a10bfa0..dd151e5 100644
--- a/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java
+++ b/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java
@@ -154,6 +154,9 @@
//Setup FOP for area tree rendering
FOUserAgent ua = effFactory.newFOUserAgent();
ua.setBaseURL(testFile.getParentFile().toURL().toString());
+ File fontCfgFile = new File("conf/fonts.xconf");
+// File fontCfgFile = new File("../Tests/Config/axsl-font-conf.xml");
+ ua.setFontCfgURL(fontCfgFile.toURL());
XMLRenderer atrenderer = new XMLRenderer();
atrenderer.setUserAgent(ua);
atrenderer.setContentHandler(athandler);
diff --git a/test/java/org/apache/fop/threading/FOProcessorImpl.java b/test/java/org/apache/fop/threading/FOProcessorImpl.java
index b5b2ff5..6fc9c59 100644
--- a/test/java/org/apache/fop/threading/FOProcessorImpl.java
+++ b/test/java/org/apache/fop/threading/FOProcessorImpl.java
@@ -19,6 +19,7 @@
package org.apache.fop.threading;
+import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
@@ -107,4 +108,4 @@
}
}
-}
\ No newline at end of file
+}