diff options
author | Keiron Liddle <keiron@apache.org> | 2002-07-23 11:06:51 +0000 |
---|---|---|
committer | Keiron Liddle <keiron@apache.org> | 2002-07-23 11:06:51 +0000 |
commit | f6a0559f5fe65405fa202434fe514de7a0f372bc (patch) | |
tree | 95c06a67fc1eae9b0f36bf885994ec04b415b96d /src/org/apache/fop/render/pdf | |
parent | 7f263c27804a4882f33f5a423150d5cc52448361 (diff) | |
download | xmlgraphics-fop-f6a0559f5fe65405fa202434fe514de7a0f372bc.tar.gz xmlgraphics-fop-f6a0559f5fe65405fa202434fe514de7a0f372bc.zip |
cleaned up the font state a bit
exception only thrown after setup as exception indicates invalid setup
only font name key and size are set on the area tree
FontState used as handler to get metric info
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@195024 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/org/apache/fop/render/pdf')
-rw-r--r-- | src/org/apache/fop/render/pdf/FontSetup.java | 135 | ||||
-rw-r--r-- | src/org/apache/fop/render/pdf/PDFRenderer.java | 24 | ||||
-rw-r--r-- | src/org/apache/fop/render/pdf/PDFXMLHandler.java | 12 |
3 files changed, 87 insertions, 84 deletions
diff --git a/src/org/apache/fop/render/pdf/FontSetup.java b/src/org/apache/fop/render/pdf/FontSetup.java index 234c48219..221020bbe 100644 --- a/src/org/apache/fop/render/pdf/FontSetup.java +++ b/src/org/apache/fop/render/pdf/FontSetup.java @@ -60,73 +60,73 @@ public class FontSetup { // fontInfo.addMetrics("F17", new BauerBodoniBoldItalic()); /* any is treated as serif */ - fontInfo.addFontProperties("F5", "any", "normal", "normal"); - fontInfo.addFontProperties("F6", "any", "italic", "normal"); - fontInfo.addFontProperties("F6", "any", "oblique", "normal"); - fontInfo.addFontProperties("F7", "any", "normal", "bold"); - fontInfo.addFontProperties("F8", "any", "italic", "bold"); - fontInfo.addFontProperties("F8", "any", "oblique", "bold"); - - fontInfo.addFontProperties("F1", "sans-serif", "normal", "normal"); - fontInfo.addFontProperties("F2", "sans-serif", "oblique", "normal"); - fontInfo.addFontProperties("F2", "sans-serif", "italic", "normal"); - fontInfo.addFontProperties("F3", "sans-serif", "normal", "bold"); - fontInfo.addFontProperties("F4", "sans-serif", "oblique", "bold"); - fontInfo.addFontProperties("F4", "sans-serif", "italic", "bold"); - fontInfo.addFontProperties("F5", "serif", "normal", "normal"); - fontInfo.addFontProperties("F6", "serif", "oblique", "normal"); - fontInfo.addFontProperties("F6", "serif", "italic", "normal"); - fontInfo.addFontProperties("F7", "serif", "normal", "bold"); - fontInfo.addFontProperties("F8", "serif", "oblique", "bold"); - fontInfo.addFontProperties("F8", "serif", "italic", "bold"); - fontInfo.addFontProperties("F9", "monospace", "normal", "normal"); - fontInfo.addFontProperties("F10", "monospace", "oblique", "normal"); - fontInfo.addFontProperties("F10", "monospace", "italic", "normal"); - fontInfo.addFontProperties("F11", "monospace", "normal", "bold"); - fontInfo.addFontProperties("F12", "monospace", "oblique", "bold"); - fontInfo.addFontProperties("F12", "monospace", "italic", "bold"); - - fontInfo.addFontProperties("F1", "Helvetica", "normal", "normal"); - fontInfo.addFontProperties("F2", "Helvetica", "oblique", "normal"); - fontInfo.addFontProperties("F2", "Helvetica", "italic", "normal"); - fontInfo.addFontProperties("F3", "Helvetica", "normal", "bold"); - fontInfo.addFontProperties("F4", "Helvetica", "oblique", "bold"); - fontInfo.addFontProperties("F4", "Helvetica", "italic", "bold"); - fontInfo.addFontProperties("F5", "Times", "normal", "normal"); - fontInfo.addFontProperties("F6", "Times", "oblique", "normal"); - fontInfo.addFontProperties("F6", "Times", "italic", "normal"); - fontInfo.addFontProperties("F7", "Times", "normal", "bold"); - fontInfo.addFontProperties("F8", "Times", "oblique", "bold"); - fontInfo.addFontProperties("F8", "Times", "italic", "bold"); - fontInfo.addFontProperties("F9", "Courier", "normal", "normal"); - fontInfo.addFontProperties("F10", "Courier", "oblique", "normal"); - fontInfo.addFontProperties("F10", "Courier", "italic", "normal"); - fontInfo.addFontProperties("F11", "Courier", "normal", "bold"); - fontInfo.addFontProperties("F12", "Courier", "oblique", "bold"); - fontInfo.addFontProperties("F12", "Courier", "italic", "bold"); - fontInfo.addFontProperties("F13", "Symbol", "normal", "normal"); - fontInfo.addFontProperties("F14", "ZapfDingbats", "normal", "normal"); + fontInfo.addFontProperties("F5", "any", "normal", FontInfo.NORMAL); + fontInfo.addFontProperties("F6", "any", "italic", FontInfo.NORMAL); + fontInfo.addFontProperties("F6", "any", "oblique", FontInfo.NORMAL); + fontInfo.addFontProperties("F7", "any", "normal", FontInfo.BOLD); + fontInfo.addFontProperties("F8", "any", "italic", FontInfo.BOLD); + fontInfo.addFontProperties("F8", "any", "oblique", FontInfo.BOLD); + + fontInfo.addFontProperties("F1", "sans-serif", "normal", FontInfo.NORMAL); + fontInfo.addFontProperties("F2", "sans-serif", "oblique", FontInfo.NORMAL); + fontInfo.addFontProperties("F2", "sans-serif", "italic", FontInfo.NORMAL); + fontInfo.addFontProperties("F3", "sans-serif", "normal", FontInfo.BOLD); + fontInfo.addFontProperties("F4", "sans-serif", "oblique", FontInfo.BOLD); + fontInfo.addFontProperties("F4", "sans-serif", "italic", FontInfo.BOLD); + fontInfo.addFontProperties("F5", "serif", "normal", FontInfo.NORMAL); + fontInfo.addFontProperties("F6", "serif", "oblique", FontInfo.NORMAL); + fontInfo.addFontProperties("F6", "serif", "italic", FontInfo.NORMAL); + fontInfo.addFontProperties("F7", "serif", "normal", FontInfo.BOLD); + fontInfo.addFontProperties("F8", "serif", "oblique", FontInfo.BOLD); + fontInfo.addFontProperties("F8", "serif", "italic", FontInfo.BOLD); + fontInfo.addFontProperties("F9", "monospace", "normal", FontInfo.NORMAL); + fontInfo.addFontProperties("F10", "monospace", "oblique", FontInfo.NORMAL); + fontInfo.addFontProperties("F10", "monospace", "italic", FontInfo.NORMAL); + fontInfo.addFontProperties("F11", "monospace", "normal", FontInfo.BOLD); + fontInfo.addFontProperties("F12", "monospace", "oblique", FontInfo.BOLD); + fontInfo.addFontProperties("F12", "monospace", "italic", FontInfo.BOLD); + + fontInfo.addFontProperties("F1", "Helvetica", "normal", FontInfo.NORMAL); + fontInfo.addFontProperties("F2", "Helvetica", "oblique", FontInfo.NORMAL); + fontInfo.addFontProperties("F2", "Helvetica", "italic", FontInfo.NORMAL); + fontInfo.addFontProperties("F3", "Helvetica", "normal", FontInfo.BOLD); + fontInfo.addFontProperties("F4", "Helvetica", "oblique", FontInfo.BOLD); + fontInfo.addFontProperties("F4", "Helvetica", "italic", FontInfo.BOLD); + fontInfo.addFontProperties("F5", "Times", "normal", FontInfo.NORMAL); + fontInfo.addFontProperties("F6", "Times", "oblique", FontInfo.NORMAL); + fontInfo.addFontProperties("F6", "Times", "italic", FontInfo.NORMAL); + fontInfo.addFontProperties("F7", "Times", "normal", FontInfo.BOLD); + fontInfo.addFontProperties("F8", "Times", "oblique", FontInfo.BOLD); + fontInfo.addFontProperties("F8", "Times", "italic", FontInfo.BOLD); + fontInfo.addFontProperties("F9", "Courier", "normal", FontInfo.NORMAL); + fontInfo.addFontProperties("F10", "Courier", "oblique", FontInfo.NORMAL); + fontInfo.addFontProperties("F10", "Courier", "italic", FontInfo.NORMAL); + fontInfo.addFontProperties("F11", "Courier", "normal", FontInfo.BOLD); + fontInfo.addFontProperties("F12", "Courier", "oblique", FontInfo.BOLD); + fontInfo.addFontProperties("F12", "Courier", "italic", FontInfo.BOLD); + fontInfo.addFontProperties("F13", "Symbol", "normal", FontInfo.NORMAL); + fontInfo.addFontProperties("F14", "ZapfDingbats", "normal", FontInfo.NORMAL); // Custom type 1 fonts step 2/2 - // fontInfo.addFontProperties("F15", "OMEP", "normal", "normal"); - // fontInfo.addFontProperties("F16", "Garamond-LightCondensed", "normal", "normal"); - // fontInfo.addFontProperties("F17", "BauerBodoni", "italic", "bold"); + // fontInfo.addFontProperties("F15", "OMEP", "normal", FontInfo.NORMAL); + // fontInfo.addFontProperties("F16", "Garamond-LightCondensed", "normal", FontInfo.NORMAL); + // fontInfo.addFontProperties("F17", "BauerBodoni", "italic", FontInfo.BOLD); /* for compatibility with PassiveTex */ - fontInfo.addFontProperties("F5", "Times-Roman", "normal", "normal"); - fontInfo.addFontProperties("F6", "Times-Roman", "oblique", "normal"); - fontInfo.addFontProperties("F6", "Times-Roman", "italic", "normal"); - fontInfo.addFontProperties("F7", "Times-Roman", "normal", "bold"); - fontInfo.addFontProperties("F8", "Times-Roman", "oblique", "bold"); - fontInfo.addFontProperties("F8", "Times-Roman", "italic", "bold"); - fontInfo.addFontProperties("F5", "Times Roman", "normal", "normal"); - fontInfo.addFontProperties("F6", "Times Roman", "oblique", "normal"); - fontInfo.addFontProperties("F6", "Times Roman", "italic", "normal"); - fontInfo.addFontProperties("F7", "Times Roman", "normal", "bold"); - fontInfo.addFontProperties("F8", "Times Roman", "oblique", "bold"); - fontInfo.addFontProperties("F8", "Times Roman", "italic", "bold"); + fontInfo.addFontProperties("F5", "Times-Roman", "normal", FontInfo.NORMAL); + fontInfo.addFontProperties("F6", "Times-Roman", "oblique", FontInfo.NORMAL); + fontInfo.addFontProperties("F6", "Times-Roman", "italic", FontInfo.NORMAL); + fontInfo.addFontProperties("F7", "Times-Roman", "normal", FontInfo.BOLD); + fontInfo.addFontProperties("F8", "Times-Roman", "oblique", FontInfo.BOLD); + fontInfo.addFontProperties("F8", "Times-Roman", "italic", FontInfo.BOLD); + fontInfo.addFontProperties("F5", "Times Roman", "normal", FontInfo.NORMAL); + fontInfo.addFontProperties("F6", "Times Roman", "oblique", FontInfo.NORMAL); + fontInfo.addFontProperties("F6", "Times Roman", "italic", FontInfo.NORMAL); + fontInfo.addFontProperties("F7", "Times Roman", "normal", FontInfo.BOLD); + fontInfo.addFontProperties("F8", "Times Roman", "oblique", FontInfo.BOLD); + fontInfo.addFontProperties("F8", "Times Roman", "italic", FontInfo.BOLD); fontInfo.addFontProperties("F9", "Computer-Modern-Typewriter", - "normal", "normal"); + "normal", FontInfo.NORMAL); /* Add configured fonts */ addConfiguredFonts(fontInfo, 15); @@ -169,10 +169,19 @@ public class FontSetup { for (int c = 0; c < triplets.size(); c++) { FontTriplet triplet = (FontTriplet)triplets.get(c); + int weight = 400; + try { + weight = Integer.parseInt(triplet.getWeight()); + weight = ((int)weight/100) * 100; + if(weight < 100) weight = 100; + if(weight > 900) weight = 900; + } catch(NumberFormatException nfe) { + + } fontInfo.addFontProperties(internalName, triplet.getName(), triplet.getStyle(), - triplet.getWeight()); + weight); } } } catch (Exception ex) { diff --git a/src/org/apache/fop/render/pdf/PDFRenderer.java b/src/org/apache/fop/render/pdf/PDFRenderer.java index bb62565ae..ac493e142 100644 --- a/src/org/apache/fop/render/pdf/PDFRenderer.java +++ b/src/org/apache/fop/render/pdf/PDFRenderer.java @@ -25,6 +25,8 @@ import org.apache.fop.area.*; import org.apache.fop.area.inline.*; import org.apache.fop.area.inline.Character; import org.apache.fop.layout.FontState; +import org.apache.fop.layout.FontInfo; +import org.apache.fop.layout.FontMetric; import org.w3c.dom.Document; @@ -224,6 +226,7 @@ public class PDFRenderer extends PrintRenderer { currentStream.add("1 0 0 -1 0 " + (int) Math.round(pageHeight / 1000) + " cm\n"); //currentStream.add("BT\n"); + currentFontName = ""; Page p = page.getPage(); renderPageAreas(p); @@ -274,14 +277,11 @@ public class PDFRenderer extends PrintRenderer { public void renderWord(Word word) { StringBuffer pdf = new StringBuffer(); - FontState fs = null; - - fs = (FontState)word.getTrait(Trait.FONT_STATE); - String name = fs.getFontName(); - int size = fs.getFontSize(); + String name = (String)word.getTrait(Trait.FONT_NAME); + int size = ((Integer)word.getTrait(Trait.FONT_SIZE)).intValue(); // This assumes that *all* CIDFonts use a /ToUnicode mapping - Font f = (Font)fs.getFontInfo().getFonts().get(name); + Font f = (Font)fontInfo.getFonts().get(name); boolean useMultiByte = f.isMultiByte(); // String startText = useMultiByte ? "<FEFF" : "("; @@ -330,6 +330,8 @@ public class PDFRenderer extends PrintRenderer { String s = word.getWord(); + FontMetric metrics = fontInfo.getMetricsFor(name); + FontState fs = new FontState(name, metrics, size); escapeText(s, fs, useMultiByte, pdf); pdf.append(endText); @@ -566,15 +568,7 @@ public class PDFRenderer extends PrintRenderer { context.setProperty(PDFXMLHandler.PDF_STREAM, currentStream); context.setProperty(PDFXMLHandler.PDF_XPOS, new Integer(currentBlockIPPosition + (int)pos.getX())); context.setProperty(PDFXMLHandler.PDF_YPOS, new Integer(currentBPPosition + (int)pos.getY())); - FontState fs = null; - try { - fs = new FontState(fontInfo, "Helvetica", "", - "", 12 * 1000, 0); - } catch (org.apache.fop.apps.FOPException fope) { - fope.printStackTrace(); - } - - context.setProperty(PDFXMLHandler.PDF_FONT_STATE, fs); + context.setProperty(PDFXMLHandler.PDF_FONT_INFO, fontInfo); context.setProperty(PDFXMLHandler.PDF_FONT_NAME, currentFontName); context.setProperty(PDFXMLHandler.PDF_FONT_SIZE, new Integer(currentFontSize)); context.setProperty(PDFXMLHandler.PDF_WIDTH, new Integer((int)pos.getWidth())); diff --git a/src/org/apache/fop/render/pdf/PDFXMLHandler.java b/src/org/apache/fop/render/pdf/PDFXMLHandler.java index f0a524788..b91baa660 100644 --- a/src/org/apache/fop/render/pdf/PDFXMLHandler.java +++ b/src/org/apache/fop/render/pdf/PDFXMLHandler.java @@ -13,7 +13,7 @@ import org.apache.fop.render.RendererContext; import org.apache.fop.pdf.*; import org.apache.fop.svg.*; import org.apache.fop.svg.SVGUserAgent; -import org.apache.fop.layout.FontState; +import org.apache.fop.layout.FontInfo; import org.apache.batik.dom.util.DOMUtilities; @@ -50,7 +50,7 @@ public static final String PDF_PAGE = "pdfPage"; public static final String PDF_STREAM = "pdfStream"; public static final String PDF_WIDTH = "width"; public static final String PDF_HEIGHT = "height"; -public static final String PDF_FONT_STATE = "fontState"; +public static final String PDF_FONT_INFO = "fontInfo"; public static final String PDF_FONT_NAME = "fontName"; public static final String PDF_FONT_SIZE = "fontSize"; public static final String PDF_XPOS = "xpos"; @@ -80,7 +80,7 @@ public static final String PDF_YPOS = "ypos"; pdfi.currentStream = (PDFStream)context.getProperty(PDF_STREAM); pdfi.width = ((Integer)context.getProperty(PDF_WIDTH)).intValue(); pdfi.height = ((Integer)context.getProperty(PDF_HEIGHT)).intValue(); - pdfi.fs = (FontState)context.getProperty(PDF_FONT_STATE); + pdfi.fi = (FontInfo)context.getProperty(PDF_FONT_INFO); pdfi.currentFontName = (String)context.getProperty(PDF_FONT_NAME); pdfi.currentFontSize = ((Integer)context.getProperty(PDF_FONT_SIZE)).intValue(); pdfi.currentXPosition = ((Integer)context.getProperty(PDF_XPOS)).intValue(); @@ -96,7 +96,7 @@ public static final String PDF_YPOS = "ypos"; public PDFStream currentStream; int width; int height; - FontState fs; + FontInfo fi; String currentFontName; int currentFontSize; int currentXPosition; @@ -117,7 +117,7 @@ public static final String PDF_YPOS = "ypos"; GVTBuilder builder = new GVTBuilder(); BridgeContext ctx = new BridgeContext(ua); - PDFTextElementBridge tBridge = new PDFTextElementBridge(pdfInfo.fs); + PDFTextElementBridge tBridge = new PDFTextElementBridge(pdfInfo.fi); ctx.putBridge(tBridge); PDFAElementBridge aBridge = new PDFAElementBridge(); @@ -170,7 +170,7 @@ public static final String PDF_YPOS = "ypos"; + PDFNumber.doubleOut(vals[5]) + " cm\n"); } - PDFGraphics2D graphics = new PDFGraphics2D(true, pdfInfo.fs, pdfInfo.pdfDoc, + PDFGraphics2D graphics = new PDFGraphics2D(true, pdfInfo.fi, pdfInfo.pdfDoc, pdfInfo.pdfPage, pdfInfo.pdfPage.referencePDF(), pdfInfo.currentFontName, pdfInfo.currentFontSize, pdfInfo.currentXPosition, |