You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by bd...@apache.org on 2006/09/27 17:32:23 UTC
svn commit: r450479 [3/4] - in /xmlgraphics/fop/branches/foray-font: ./
axsl-temp-stuff/ conf/ lib/ src/java/org/apache/fop/apps/
src/java/org/apache/fop/area/ src/java/org/apache/fop/area/inline/
src/java/org/apache/fop/cli/ src/java/org/apache/fop/fo...
Modified: xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/pdf/PDFRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/pdf/PDFRenderer.java?view=diff&rev=450479&r1=450478&r2=450479
==============================================================================
--- xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/pdf/PDFRenderer.java (original)
+++ xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/pdf/PDFRenderer.java Wed Sep 27 08:32:21 2006
@@ -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;
Modified: xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/pdf/PDFRendererContextConstants.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/pdf/PDFRendererContextConstants.java?view=diff&rev=450479&r1=450478&r2=450479
==============================================================================
--- xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/pdf/PDFRendererContextConstants.java (original)
+++ xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/pdf/PDFRendererContextConstants.java Wed Sep 27 08:32:21 2006
@@ -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";
Modified: xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/pdf/PDFSVGHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/pdf/PDFSVGHandler.java?view=diff&rev=450479&r1=450478&r2=450479
==============================================================================
--- xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/pdf/PDFSVGHandler.java (original)
+++ xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/pdf/PDFSVGHandler.java Wed Sep 27 08:32:21 2006
@@ -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()) {
Modified: xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/ps/AbstractPSTranscoder.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/ps/AbstractPSTranscoder.java?view=diff&rev=450479&r1=450478&r2=450479
==============================================================================
--- xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/ps/AbstractPSTranscoder.java (original)
+++ xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/ps/AbstractPSTranscoder.java Wed Sep 27 08:32:21 2006
@@ -77,7 +77,7 @@
* Constructs a new <tt>AbstractPSTranscoder</tt>.
*/
public AbstractPSTranscoder() {
- super();
+ super(true);
}
protected abstract AbstractPSDocumentGraphics2D createDocumentGraphics2D();
Modified: xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/ps/EPSTranscoder.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/ps/EPSTranscoder.java?view=diff&rev=450479&r1=450478&r2=450479
==============================================================================
--- xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/ps/EPSTranscoder.java (original)
+++ xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/ps/EPSTranscoder.java Wed Sep 27 08:32:21 2006
@@ -60,7 +60,7 @@
/** @see AbstractPSTranscoder#createDocumentGraphics2D() */
protected AbstractPSDocumentGraphics2D createDocumentGraphics2D() {
- return new EPSDocumentGraphics2D(false);
+ return new EPSDocumentGraphics2D(false, getFontMap());
}
}
Modified: xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/ps/PSFontUtils.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/ps/PSFontUtils.java?view=diff&rev=450479&r1=450478&r2=450479
==============================================================================
--- xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/ps/PSFontUtils.java (original)
+++ xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/ps/PSFontUtils.java Wed Sep 27 08:32:21 2006
@@ -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;
}
Modified: xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/ps/PSRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/ps/PSRenderer.java?view=diff&rev=450479&r1=450478&r2=450479
==============================================================================
--- xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/ps/PSRenderer.java (original)
+++ xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/ps/PSRenderer.java Wed Sep 27 08:32:21 2006
@@ -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 + "[");
Modified: xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/ps/PSSVGHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/ps/PSSVGHandler.java?view=diff&rev=450479&r1=450478&r2=450479
==============================================================================
--- xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/ps/PSSVGHandler.java (original)
+++ xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/ps/PSSVGHandler.java Wed Sep 27 08:32:21 2006
@@ -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);
Modified: xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/ps/PSTextPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/ps/PSTextPainter.java?view=diff&rev=450479&r1=450478&r2=450479
==============================================================================
--- xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/ps/PSTextPainter.java (original)
+++ xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/ps/PSTextPainter.java Wed Sep 27 08:32:21 2006
@@ -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(' '));
-
- 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 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, Font font) {
+ 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'))) {
- if (!font.hasChar(c)) {
+ if (!font.glyphAvailable(c)) {
return true;
}
}
Modified: xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/ps/PSTranscoder.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/ps/PSTranscoder.java?view=diff&rev=450479&r1=450478&r2=450479
==============================================================================
--- xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/ps/PSTranscoder.java (original)
+++ xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/ps/PSTranscoder.java Wed Sep 27 08:32:21 2006
@@ -60,7 +60,7 @@
/** @see AbstractPSTranscoder#createDocumentGraphics2D() */
protected AbstractPSDocumentGraphics2D createDocumentGraphics2D() {
- return new PSDocumentGraphics2D(false);
+ return new PSDocumentGraphics2D(false, getFontMap());
}
}
Modified: xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/rtf/RTFHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/rtf/RTFHandler.java?view=diff&rev=450479&r1=450478&r2=450479
==============================================================================
--- xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/rtf/RTFHandler.java (original)
+++ xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/rtf/RTFHandler.java Wed Sep 27 08:32:21 2006
@@ -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));
}
/**
Modified: xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfListStyle.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfListStyle.java?view=diff&rev=450479&r1=450478&r2=450479
==============================================================================
--- xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfListStyle.java (original)
+++ xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfListStyle.java Wed Sep 27 08:32:21 2006
@@ -87,4 +87,4 @@
public void writeLevelGroup(RtfElement element)
throws IOException {
}
-}
\ No newline at end of file
+}
Modified: xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfPageNumberCitation.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfPageNumberCitation.java?view=diff&rev=450479&r1=450478&r2=450479
==============================================================================
--- xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfPageNumberCitation.java (original)
+++ xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfPageNumberCitation.java Wed Sep 27 08:32:21 2006
@@ -109,4 +109,4 @@
public boolean isEmpty() {
return false;
}
-}
\ No newline at end of file
+}
Modified: xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/xml/XMLRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/xml/XMLRenderer.java?view=diff&rev=450479&r1=450478&r2=450479
==============================================================================
--- xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/xml/XMLRenderer.java (original)
+++ xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/render/xml/XMLRenderer.java Wed Sep 27 08:32:21 2006
@@ -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)
Modified: xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/svg/AbstractFOPTranscoder.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/svg/AbstractFOPTranscoder.java?view=diff&rev=450479&r1=450478&r2=450479
==============================================================================
--- xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/svg/AbstractFOPTranscoder.java (original)
+++ xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/svg/AbstractFOPTranscoder.java Wed Sep 27 08:32:21 2006
@@ -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);
}
/**
Modified: xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/svg/PDFBridgeContext.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/svg/PDFBridgeContext.java?view=diff&rev=450479&r1=450478&r2=450479
==============================================================================
--- xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/svg/PDFBridgeContext.java (original)
+++ xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/svg/PDFBridgeContext.java Wed Sep 27 08:32:21 2006
@@ -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);
}
}
Modified: xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java?view=diff&rev=450479&r1=450478&r2=450479
==============================================================================
--- xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java (original)
+++ xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java Wed Sep 27 08:32:21 2006
@@ -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);
Modified: xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/svg/PDFGraphics2D.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/svg/PDFGraphics2D.java?view=diff&rev=450479&r1=450478&r2=450479
==============================================================================
--- xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/svg/PDFGraphics2D.java (original)
+++ xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/svg/PDFGraphics2D.java Wed Sep 27 08:32:21 2006
@@ -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 FontUse to use
+ */
+ 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 infont the font state to use
+ * @param insize the font size to use
*/
- public void setOverrideFontState(Font infont) {
- ovFontState = infont;
+ 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;
- }
- String name;
- float size;
- name = fontState.getFontName();
- size = (float)fontState.getFontSize() / 1000f;
-
- if ((!name.equals(this.currentFontName))
+ fontUse = ovFontUse;
+ ovFontUse = null;
+ size = ovFontSize;
+ }
+
+ 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) + " "
Modified: xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/svg/PDFTextElementBridge.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/svg/PDFTextElementBridge.java?view=diff&rev=450479&r1=450478&r2=450479
==============================================================================
--- xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/svg/PDFTextElementBridge.java (original)
+++ xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/svg/PDFTextElementBridge.java Wed Sep 27 08:32:21 2006
@@ -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);
}
/**
Modified: xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/svg/PDFTextPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/svg/PDFTextPainter.java?view=diff&rev=450479&r1=450478&r2=450479
==============================================================================
--- xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/svg/PDFTextPainter.java (original)
+++ xmlgraphics/fop/branches/foray-font/src/java/org/apache/fop/svg/PDFTextPainter.java Wed Sep 27 08:32:21 2006
@@ -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;
-
- Font fontState = null;
- FontInfo fi = fontInfo;
- boolean found = false;
+ 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;
+
+ 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 @@
}
}
-
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org