From a9a3ea149314c75ee52f5f2f0f58c8146592736a Mon Sep 17 00:00:00 2001 From: William Victor Mote Date: Thu, 14 Aug 2003 15:31:10 +0000 Subject: move layout.FontState to fonts.Font git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196800 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/fo/PropertyManager.java | 8 +- src/java/org/apache/fop/fo/TextInfo.java | 4 +- src/java/org/apache/fop/fo/flow/Leader.java | 4 +- src/java/org/apache/fop/fo/flow/PageNumber.java | 4 +- .../org/apache/fop/fo/flow/PageNumberCitation.java | 4 +- src/java/org/apache/fop/fo/pagination/Title.java | 4 +- src/java/org/apache/fop/fonts/Font.java | 206 +++++++++++++++++++++ src/java/org/apache/fop/layout/FontState.java | 206 --------------------- .../apache/fop/layoutmgr/BlockLayoutManager.java | 1 + .../apache/fop/layoutmgr/TextLayoutManager.java | 1 + .../org/apache/fop/render/pdf/PDFRenderer.java | 6 +- .../org/apache/fop/render/ps/PSGraphics2D.java | 15 +- .../org/apache/fop/render/ps/PSTextPainter.java | 25 +-- src/java/org/apache/fop/svg/PDFGraphics2D.java | 21 ++- src/java/org/apache/fop/svg/PDFTextPainter.java | 26 +-- src/java/org/apache/fop/tools/AreaTreeBuilder.java | 8 +- src/java/org/apache/fop/util/CharUtilities.java | 4 +- 17 files changed, 276 insertions(+), 271 deletions(-) create mode 100644 src/java/org/apache/fop/fonts/Font.java delete mode 100644 src/java/org/apache/fop/layout/FontState.java (limited to 'src/java/org/apache') diff --git a/src/java/org/apache/fop/fo/PropertyManager.java b/src/java/org/apache/fop/fo/PropertyManager.java index dc5d9f918..0e73e6433 100644 --- a/src/java/org/apache/fop/fo/PropertyManager.java +++ b/src/java/org/apache/fop/fo/PropertyManager.java @@ -57,7 +57,7 @@ import java.awt.geom.Rectangle2D; // FOP import org.apache.fop.area.CTM; import org.apache.fop.datatypes.FODimension; -import org.apache.fop.layout.FontState; +import org.apache.fop.fonts.Font; import org.apache.fop.control.Document; import org.apache.fop.fo.properties.CommonBorderAndPadding; import org.apache.fop.fo.properties.CommonMarginBlock; @@ -84,7 +84,7 @@ public class PropertyManager { private PropertyList properties; private Document fontInfo = null; - private FontState fontState = null; + private Font fontState = null; private CommonBorderAndPadding borderAndPadding = null; private CommonHyphenation hyphProps = null; private TextInfo textInfo = null; @@ -133,7 +133,7 @@ public class PropertyManager { * @param fontInfo FontInfo to work with * @return a FontState object */ - public FontState getFontState(Document fontInfo) { + public Font getFontState(Document fontInfo) { if (fontState == null) { if (fontInfo == null) { fontInfo = this.fontInfo; @@ -170,7 +170,7 @@ public class PropertyManager { String fname = fontInfo.fontLookup(fontFamily, fontStyle, fontWeight); FontMetrics metrics = fontInfo.getMetricsFor(fname); - fontState = new FontState(fname, metrics, fontSize); + fontState = new Font(fname, metrics, fontSize); } return fontState; } diff --git a/src/java/org/apache/fop/fo/TextInfo.java b/src/java/org/apache/fop/fo/TextInfo.java index 860bbd119..a84ab6c3c 100644 --- a/src/java/org/apache/fop/fo/TextInfo.java +++ b/src/java/org/apache/fop/fo/TextInfo.java @@ -51,7 +51,7 @@ package org.apache.fop.fo; // FOP -import org.apache.fop.layout.FontState; +import org.apache.fop.fonts.Font; import org.apache.fop.datatypes.ColorType; import org.apache.fop.traits.SpaceVal; import org.apache.fop.fo.properties.TextTransform; @@ -61,7 +61,7 @@ import org.apache.fop.fo.properties.TextTransform; */ public class TextInfo { /** object containing the font information */ - public FontState fs; + public Font fs; /** fo:color property */ public ColorType color; /** fo:wrap-option property */ diff --git a/src/java/org/apache/fop/fo/flow/Leader.java b/src/java/org/apache/fop/fo/flow/Leader.java index 285aef2e8..9f59b44e8 100644 --- a/src/java/org/apache/fop/fo/flow/Leader.java +++ b/src/java/org/apache/fop/fo/flow/Leader.java @@ -71,7 +71,7 @@ import org.apache.fop.fo.properties.CommonAural; import org.apache.fop.fo.properties.CommonBackground; import org.apache.fop.fo.properties.CommonBorderAndPadding; import org.apache.fop.control.Document; -import org.apache.fop.layout.FontState; +import org.apache.fop.fonts.Font; import org.apache.fop.fo.properties.CommonMarginInline; import org.apache.fop.fo.properties.CommonRelativePosition; import org.apache.fop.layoutmgr.ContentLayoutManager; @@ -96,7 +96,7 @@ public class Leader extends FObjMixed { /** FontInfo for this object */ protected Document fontInfo = null; /** FontState for this object */ - protected FontState fontState; + protected Font fontState; protected InlineArea leaderArea = null; /** diff --git a/src/java/org/apache/fop/fo/flow/PageNumber.java b/src/java/org/apache/fop/fo/flow/PageNumber.java index f6488bd1a..8f9fd7d8f 100644 --- a/src/java/org/apache/fop/fo/flow/PageNumber.java +++ b/src/java/org/apache/fop/fo/flow/PageNumber.java @@ -59,7 +59,7 @@ import org.apache.fop.fo.properties.CommonAural; import org.apache.fop.fo.properties.CommonBackground; import org.apache.fop.fo.properties.CommonBorderAndPadding; import org.apache.fop.control.Document; -import org.apache.fop.layout.FontState; +import org.apache.fop.fonts.Font; import org.apache.fop.fo.properties.CommonMarginInline; import org.apache.fop.fo.properties.CommonRelativePosition; import org.apache.fop.layout.TextState; @@ -84,7 +84,7 @@ public class PageNumber extends FObj { /** FontInfo for this object */ protected Document fontInfo = null; /** FontState for this object */ - protected FontState fontState; + protected Font fontState; private float red; private float green; diff --git a/src/java/org/apache/fop/fo/flow/PageNumberCitation.java b/src/java/org/apache/fop/fo/flow/PageNumberCitation.java index 53a2bafde..a83665d9d 100644 --- a/src/java/org/apache/fop/fo/flow/PageNumberCitation.java +++ b/src/java/org/apache/fop/fo/flow/PageNumberCitation.java @@ -69,7 +69,7 @@ import org.apache.fop.fo.properties.CommonAural; import org.apache.fop.fo.properties.CommonBackground; import org.apache.fop.fo.properties.CommonBorderAndPadding; import org.apache.fop.control.Document; -import org.apache.fop.layout.FontState; +import org.apache.fop.fonts.Font; import org.apache.fop.fo.properties.CommonMarginInline; import org.apache.fop.fo.properties.CommonRelativePosition; import org.apache.fop.layout.TextState; @@ -91,7 +91,7 @@ public class PageNumberCitation extends FObj { /** FontInfo for this object **/ protected Document fontInfo = null; /** Fontstate for this object **/ - protected FontState fontState; + protected Font fontState; private float red; private float green; diff --git a/src/java/org/apache/fop/fo/pagination/Title.java b/src/java/org/apache/fop/fo/pagination/Title.java index a1b9c9d98..a4daf6138 100644 --- a/src/java/org/apache/fop/fo/pagination/Title.java +++ b/src/java/org/apache/fop/fo/pagination/Title.java @@ -62,7 +62,7 @@ import org.apache.fop.fo.properties.CommonAccessibility; import org.apache.fop.fo.properties.CommonAural; import org.apache.fop.fo.properties.CommonBackground; import org.apache.fop.fo.properties.CommonBorderAndPadding; -import org.apache.fop.layout.FontState; +import org.apache.fop.fonts.Font; import org.apache.fop.fo.properties.CommonMarginInline; import org.apache.fop.layoutmgr.ContentLayoutManager; import org.apache.fop.layoutmgr.InlineStackingLayoutManager; @@ -120,7 +120,7 @@ public class Title extends FObjMixed { CommonBackground bProps = propMgr.getBackgroundProps(); // Common Font Properties - FontState fontState = propMgr.getFontState(foInputHandler.getFontInfo()); + Font fontState = propMgr.getFontState(foInputHandler.getFontInfo()); // Common Margin Properties-Inline CommonMarginInline mProps = propMgr.getMarginInlineProps(); diff --git a/src/java/org/apache/fop/fonts/Font.java b/src/java/org/apache/fop/fonts/Font.java new file mode 100644 index 000000000..a304be560 --- /dev/null +++ b/src/java/org/apache/fop/fonts/Font.java @@ -0,0 +1,206 @@ +/* + * $Id: FontState.java,v 1.23 2003/03/06 22:19:16 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber . For more information on the Apache + * Software Foundation, please see . + */ +package org.apache.fop.fonts; + +import java.util.Map; + + + + +/** + * This class holds font state information and provides access to the font + * metrics. + */ +public class Font { + + private String fontName; + private int fontSize; + //private String fontFamily; + //private String fontStyle; + //private int fontWeight; + + /** + * normal or small-caps font + */ + //private int fontVariant; + + private FontMetrics metric; + + /** + * Main constructor + * @param key key of the font + * @param met font metrics + * @param fontSize font size + */ + public Font(String key, FontMetrics met, int fontSize) { + this.fontName = key; + this.metric = met; + this.fontSize = fontSize; + } + + /** + * Returns the font's ascender. + * @return the ascender + */ + public int getAscender() { + return metric.getAscender(fontSize) / 1000; + } + + /** + * Returns the font's CapHeight. + * @return the capital height + */ + public int getCapHeight() { + return metric.getCapHeight(fontSize) / 1000; + } + + /** + * Returns the font's Descender. + * @return the descender + */ + public int getDescender() { + return metric.getDescender(fontSize) / 1000; + } + + /** + * Returns the font's name. + * @return the font name + */ + public String getFontName() { + return fontName; + } + + /** + * Returns the font size + * @return the font size + */ + public int getFontSize() { + return fontSize; + } + + /** + * Returns the XHeight + * @return the XHeight + */ + public int getXHeight() { + return metric.getXHeight(fontSize) / 1000; + } + + /** + * Returns the font's kerning table + * @return the kerning table + */ + public Map getKerning() { + Map ret = metric.getKerningInfo(); + if (ret != null) { + return ret; + } else { + return java.util.Collections.EMPTY_MAP; + } + } + + /** + * Returns the width of a character + * @param charnum character to look up + * @return width of the character + */ + public int getWidth(int charnum) { + // returns width of given character number in millipoints + return (metric.getWidth(charnum, fontSize) / 1000); + } + + /** + * Map a java character (unicode) to a font character. + * Default uses CodePointMapping. + * @param c character to map + * @return the mapped character + */ + public char mapChar(char c) { + + if (metric instanceof org.apache.fop.fonts.Typeface) { + return ((org.apache.fop.fonts.Typeface)metric).mapChar(c); + } + + // Use default CodePointMapping + char d = CodePointMapping.getMapping("WinAnsiEncoding").mapChar(c); + if (d != 0) { + c = d; + } else { + c = '#'; + } + + return c; + } + + /** + * @see java.lang.Object#toString() + */ + public String toString() { + StringBuffer sbuf = new StringBuffer(); + sbuf.append('('); + /* + sbuf.append(fontFamily); + sbuf.append(',');*/ + sbuf.append(fontName); + sbuf.append(','); + sbuf.append(fontSize); + /* + sbuf.append(','); + sbuf.append(fontStyle); + sbuf.append(','); + sbuf.append(fontWeight);*/ + sbuf.append(')'); + return sbuf.toString(); + } +} + + + diff --git a/src/java/org/apache/fop/layout/FontState.java b/src/java/org/apache/fop/layout/FontState.java deleted file mode 100644 index 2414a2a25..000000000 --- a/src/java/org/apache/fop/layout/FontState.java +++ /dev/null @@ -1,206 +0,0 @@ -/* - * $Id: FontState.java,v 1.23 2003/03/06 22:19:16 jeremias Exp $ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modifica- - * tion, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. The end-user documentation included with the redistribution, if any, must - * include the following acknowledgment: "This product includes software - * developed by the Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, if - * and wherever such third-party acknowledgments normally appear. - * - * 4. The names "FOP" and "Apache Software Foundation" must not be used to - * endorse or promote products derived from this software without prior - * written permission. For written permission, please contact - * apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", nor may - * "Apache" appear in their name, without prior written permission of the - * Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * ============================================================================ - * - * This software consists of voluntary contributions made by many individuals - * on behalf of the Apache Software Foundation and was originally created by - * James Tauber . For more information on the Apache - * Software Foundation, please see . - */ -package org.apache.fop.layout; - -import java.util.Map; - -import org.apache.fop.fonts.CodePointMapping; -import org.apache.fop.fonts.FontMetrics; - -/** - * This class holds font state information and provides access to the font - * metrics. - */ -public class FontState { - - private String fontName; - private int fontSize; - //private String fontFamily; - //private String fontStyle; - //private int fontWeight; - - /** - * normal or small-caps font - */ - //private int fontVariant; - - private FontMetrics metric; - - /** - * Main constructor - * @param key key of the font - * @param met font metrics - * @param fontSize font size - */ - public FontState(String key, FontMetrics met, int fontSize) { - this.fontName = key; - this.metric = met; - this.fontSize = fontSize; - } - - /** - * Returns the font's ascender. - * @return the ascender - */ - public int getAscender() { - return metric.getAscender(fontSize) / 1000; - } - - /** - * Returns the font's CapHeight. - * @return the capital height - */ - public int getCapHeight() { - return metric.getCapHeight(fontSize) / 1000; - } - - /** - * Returns the font's Descender. - * @return the descender - */ - public int getDescender() { - return metric.getDescender(fontSize) / 1000; - } - - /** - * Returns the font's name. - * @return the font name - */ - public String getFontName() { - return fontName; - } - - /** - * Returns the font size - * @return the font size - */ - public int getFontSize() { - return fontSize; - } - - /** - * Returns the XHeight - * @return the XHeight - */ - public int getXHeight() { - return metric.getXHeight(fontSize) / 1000; - } - - /** - * Returns the font's kerning table - * @return the kerning table - */ - public Map getKerning() { - Map ret = metric.getKerningInfo(); - if (ret != null) { - return ret; - } else { - return java.util.Collections.EMPTY_MAP; - } - } - - /** - * Returns the width of a character - * @param charnum character to look up - * @return width of the character - */ - public int getWidth(int charnum) { - // returns width of given character number in millipoints - return (metric.getWidth(charnum, fontSize) / 1000); - } - - /** - * Map a java character (unicode) to a font character. - * Default uses CodePointMapping. - * @param c character to map - * @return the mapped character - */ - public char mapChar(char c) { - - if (metric instanceof org.apache.fop.fonts.Typeface) { - return ((org.apache.fop.fonts.Typeface)metric).mapChar(c); - } - - // Use default CodePointMapping - char d = CodePointMapping.getMapping("WinAnsiEncoding").mapChar(c); - if (d != 0) { - c = d; - } else { - c = '#'; - } - - return c; - } - - /** - * @see java.lang.Object#toString() - */ - public String toString() { - StringBuffer sbuf = new StringBuffer(); - sbuf.append('('); - /* - sbuf.append(fontFamily); - sbuf.append(',');*/ - sbuf.append(fontName); - sbuf.append(','); - sbuf.append(fontSize); - /* - sbuf.append(','); - sbuf.append(fontStyle); - sbuf.append(','); - sbuf.append(fontWeight);*/ - sbuf.append(')'); - return sbuf.toString(); - } -} - - - diff --git a/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java b/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java index 83262ec21..4061e475e 100644 --- a/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java @@ -63,6 +63,7 @@ import org.apache.fop.area.LineArea; import org.apache.fop.traits.LayoutProps; import org.apache.fop.fo.properties.CommonBorderAndPadding; import org.apache.fop.fo.properties.CommonBackground; +import org.apache.fop.fonts.*; /** * LayoutManager for a block FO. diff --git a/src/java/org/apache/fop/layoutmgr/TextLayoutManager.java b/src/java/org/apache/fop/layoutmgr/TextLayoutManager.java index e26000f04..903f8c51b 100644 --- a/src/java/org/apache/fop/layoutmgr/TextLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/TextLayoutManager.java @@ -59,6 +59,7 @@ import org.apache.fop.area.inline.InlineArea; import org.apache.fop.area.inline.Word; import org.apache.fop.area.inline.Space; import org.apache.fop.util.CharUtilities; +import org.apache.fop.fonts.*; /** * LayoutManager for text (a sequence of characters) which generates one diff --git a/src/java/org/apache/fop/render/pdf/PDFRenderer.java b/src/java/org/apache/fop/render/pdf/PDFRenderer.java index 8b469f6e2..be653326b 100644 --- a/src/java/org/apache/fop/render/pdf/PDFRenderer.java +++ b/src/java/org/apache/fop/render/pdf/PDFRenderer.java @@ -114,7 +114,7 @@ import org.apache.fop.area.inline.ForeignObject; import org.apache.fop.area.inline.Image; import org.apache.fop.area.inline.Leader; import org.apache.fop.area.inline.InlineParent; -import org.apache.fop.layout.FontState; +import org.apache.fop.fonts.Font; import org.apache.fop.traits.BorderProps; import org.apache.fop.datatypes.ColorType; @@ -920,7 +920,7 @@ public class PDFRenderer extends PrintRenderer { String s = word.getWord(); FontMetrics metrics = fontInfo.getMetricsFor(name); - FontState fs = new FontState(name, metrics, size); + Font fs = new Font(name, metrics, size); escapeText(s, fs, useMultiByte, pdf); pdf.append(endText); @@ -936,7 +936,7 @@ public class PDFRenderer extends PrintRenderer { * @param useMultiByte Indicates the use of multi byte convention * @param pdf target buffer for the escaped text */ - public void escapeText(String s, FontState fs, + public void escapeText(String s, Font fs, boolean useMultiByte, StringBuffer pdf) { String startText = useMultiByte ? "<" : "("; String endText = useMultiByte ? "> " : ") "; diff --git a/src/java/org/apache/fop/render/ps/PSGraphics2D.java b/src/java/org/apache/fop/render/ps/PSGraphics2D.java index 068d6272e..009bc9005 100644 --- a/src/java/org/apache/fop/render/ps/PSGraphics2D.java +++ b/src/java/org/apache/fop/render/ps/PSGraphics2D.java @@ -58,7 +58,8 @@ import java.awt.AlphaComposite; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Dimension; -import java.awt.Font; +/* java.awt.Font is not imported to avoid confusion with + org.apache.fop.fonts.Font */ import java.awt.GradientPaint; import java.awt.Graphics; import java.awt.Graphics2D; @@ -84,7 +85,7 @@ import java.io.IOException; // FOP import org.apache.fop.control.Document; -import org.apache.fop.layout.FontState; +import org.apache.fop.fonts.Font; // Batik import org.apache.batik.ext.awt.g2d.AbstractGraphics2D; @@ -113,10 +114,10 @@ public class PSGraphics2D extends AbstractGraphics2D { protected PSGenerator gen; /** Currently valid FontState */ - protected FontState fontState; + protected Font fontState; /** Overriding FontState */ - protected FontState overrideFontState = null; + protected Font overrideFontState = null; /** * the current (internal) font name @@ -826,7 +827,7 @@ public class PSGraphics2D extends AbstractGraphics2D { public void drawString(String s, float x, float y) { try { if (overrideFontState == null) { - Font gFont = getFont(); + java.awt.Font gFont = getFont(); String n = gFont.getFamily(); if (n.equals("sanserif")) { n = "sans-serif"; @@ -1088,7 +1089,7 @@ public class PSGraphics2D extends AbstractGraphics2D { * Sets the overrideing font state. * @param infont FontState to set */ - public void setOverrideFontState(FontState infont) { + public void setOverrideFontState(Font infont) { overrideFontState = infont; } @@ -1100,7 +1101,7 @@ public class PSGraphics2D extends AbstractGraphics2D { * @see java.awt.FontMetrics * @see java.awt.Graphics#getFontMetrics() */ - public java.awt.FontMetrics getFontMetrics(Font f) { + public java.awt.FontMetrics getFontMetrics(java.awt.Font f) { return fmg.getFontMetrics(f); } diff --git a/src/java/org/apache/fop/render/ps/PSTextPainter.java b/src/java/org/apache/fop/render/ps/PSTextPainter.java index f357fa283..bb52fef6e 100644 --- a/src/java/org/apache/fop/render/ps/PSTextPainter.java +++ b/src/java/org/apache/fop/render/ps/PSTextPainter.java @@ -53,7 +53,8 @@ package org.apache.fop.render.ps; import java.awt.Graphics2D; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; -import java.awt.Font; +/* java.awt.Font is not imported to avoid confusion with + org.apache.fop.fonts.Font */ import java.text.AttributedCharacterIterator; import java.awt.font.TextAttribute; @@ -73,7 +74,7 @@ import org.apache.batik.bridge.SVGFontFamily; import org.apache.batik.gvt.renderer.StrokingTextPainter; import org.apache.fop.fonts.FontMetrics; -import org.apache.fop.layout.FontState; +import org.apache.fop.fonts.Font; import org.apache.fop.control.Document; /** @@ -189,7 +190,7 @@ public class PSTextPainter implements TextPainter { && (taWeight.floatValue() > 1.0)) ? Document.BOLD : Document.NORMAL; - FontState fontState = null; + Font fontState = null; Document fi = fontInfo; boolean found = false; String fontFamily = null; @@ -207,7 +208,7 @@ public class PSTextPainter implements TextPainter { weight); FontMetrics metrics = fontInfo.getMetricsFor(fname); int fsize = (int)(size.floatValue() * 1000); - fontState = new FontState(fname, metrics, fsize); + fontState = new Font(fname, metrics, fsize); found = true; break; } @@ -218,27 +219,27 @@ public class PSTextPainter implements TextPainter { fontInfo.fontLookup("any", style, Document.NORMAL); FontMetrics metrics = fontInfo.getMetricsFor(fname); int fsize = (int)(size.floatValue() * 1000); - fontState = new FontState(fname, metrics, fsize); + fontState = new Font(fname, metrics, fsize); } else { if (g2d instanceof PSGraphics2D) { ((PSGraphics2D) g2d).setOverrideFontState(fontState); } } - int fStyle = Font.PLAIN; + int fStyle = java.awt.Font.PLAIN; if (weight == Document.BOLD) { if (style.equals("italic")) { - fStyle = Font.BOLD | Font.ITALIC; + fStyle = java.awt.Font.BOLD | java.awt.Font.ITALIC; } else { - fStyle = Font.BOLD; + fStyle = java.awt.Font.BOLD; } } else { if (style.equals("italic")) { - fStyle = Font.ITALIC; + fStyle = java.awt.Font.ITALIC; } else { - fStyle = Font.PLAIN; + fStyle = java.awt.Font.PLAIN; } } - Font font = new Font(fontFamily, fStyle, + java.awt.Font font = new java.awt.Font(fontFamily, fStyle, (int)(fontState.getFontSize() / 1000)); g2d.setFont(font); @@ -288,7 +289,7 @@ public class PSTextPainter implements TextPainter { return hasunsupported; } - private float getStringWidth(String str, FontState fontState) { + private float getStringWidth(String str, Font fontState) { float wordWidth = 0; float whitespaceWidth = fontState.getWidth(fontState.mapChar(' ')); diff --git a/src/java/org/apache/fop/svg/PDFGraphics2D.java b/src/java/org/apache/fop/svg/PDFGraphics2D.java index 7a7bcf364..e4e4a2f37 100644 --- a/src/java/org/apache/fop/svg/PDFGraphics2D.java +++ b/src/java/org/apache/fop/svg/PDFGraphics2D.java @@ -65,7 +65,7 @@ import org.apache.fop.pdf.PDFLink; import org.apache.fop.pdf.PDFAnnotList; import org.apache.fop.pdf.BitmapImage; import org.apache.fop.control.Document; -import org.apache.fop.layout.FontState; +import org.apache.fop.fonts.Font; import org.apache.fop.render.pdf.FontSetup; import org.apache.fop.fonts.FontMetrics; import org.apache.fop.fonts.LazyFont; @@ -87,7 +87,8 @@ import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Color; import java.awt.GraphicsConfiguration; -import java.awt.Font; +/* java.awt.Font is not imported to avoid confusion with + org.apache.fop.fonts.Font */ import java.awt.Image; import java.awt.Shape; import java.awt.Stroke; @@ -159,7 +160,7 @@ public class PDFGraphics2D extends AbstractGraphics2D { * The override font state used when drawing text and the font cannot be * set using java fonts. */ - protected FontState ovFontState = null; + protected Font ovFontState = null; /** * the current stream to add PDF commands to @@ -266,7 +267,7 @@ public class PDFGraphics2D extends AbstractGraphics2D { * * @param infont the font state to use */ - public void setOverrideFontState(FontState infont) { + public void setOverrideFontState(Font infont) { ovFontState = infont; } @@ -1198,9 +1199,9 @@ public class PDFGraphics2D extends AbstractGraphics2D { public void drawString(String s, float x, float y) { // System.out.println("drawString(String)"); - FontState fontState; + Font fontState; if (ovFontState == null) { - Font gFont = getFont(); + java.awt.Font gFont = getFont(); String n = gFont.getFamily(); if (n.equals("sanserif")) { n = "sans-serif"; @@ -1210,10 +1211,10 @@ public class PDFGraphics2D extends AbstractGraphics2D { int weight = gFont.isBold() ? Document.BOLD : Document.NORMAL; String fname = fontInfo.fontLookup(n, style, weight); FontMetrics metrics = fontInfo.getMetricsFor(fname); - fontState = new FontState(fname, metrics, siz * 1000); + fontState = new Font(fname, metrics, siz * 1000); } else { FontMetrics metrics = fontInfo.getMetricsFor(ovFontState.getFontName()); - fontState = new FontState(ovFontState.getFontName(), + fontState = new Font(ovFontState.getFontName(), metrics, ovFontState.getFontSize()); ovFontState = null; } @@ -1367,7 +1368,7 @@ public class PDFGraphics2D extends AbstractGraphics2D { float y) { System.err.println("drawString(AttributedCharacterIterator)"); - FontState fontState = null; + Font fontState = null; Shape imclip = getClip(); writeClip(imclip); @@ -1587,7 +1588,7 @@ public class PDFGraphics2D extends AbstractGraphics2D { * @see java.awt.FontMetrics * @see java.awt.Graphics#getFontMetrics() */ - public java.awt.FontMetrics getFontMetrics(Font f) { + public java.awt.FontMetrics getFontMetrics(java.awt.Font f) { return fmg.getFontMetrics(f); } diff --git a/src/java/org/apache/fop/svg/PDFTextPainter.java b/src/java/org/apache/fop/svg/PDFTextPainter.java index a3645d2e3..247b98bb9 100644 --- a/src/java/org/apache/fop/svg/PDFTextPainter.java +++ b/src/java/org/apache/fop/svg/PDFTextPainter.java @@ -53,8 +53,8 @@ package org.apache.fop.svg; import java.awt.Graphics2D; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; -import java.awt.Font; - +/* java.awt.Font is not imported to avoid confusion with + org.apache.fop.fonts.Font */ import java.text.AttributedCharacterIterator; import java.awt.font.TextAttribute; import java.awt.Shape; @@ -73,7 +73,7 @@ import org.apache.batik.bridge.SVGFontFamily; import org.apache.batik.gvt.renderer.StrokingTextPainter; import org.apache.fop.fonts.FontMetrics; -import org.apache.fop.layout.FontState; +import org.apache.fop.fonts.Font; import org.apache.fop.control.Document; /** @@ -189,7 +189,7 @@ public class PDFTextPainter implements TextPainter { && (taWeight.floatValue() > 1.0)) ? Document.BOLD : Document.NORMAL; - FontState fontState = null; + Font fontState = null; Document fi = fontInfo; boolean found = false; String fontFamily = null; @@ -207,7 +207,7 @@ public class PDFTextPainter implements TextPainter { weight); FontMetrics metrics = fontInfo.getMetricsFor(fname); int fsize = (int)(size.floatValue() * 1000); - fontState = new FontState(fname, metrics, fsize); + fontState = new Font(fname, metrics, fsize); found = true; break; } @@ -218,27 +218,27 @@ public class PDFTextPainter implements TextPainter { fontInfo.fontLookup("any", style, Document.NORMAL); FontMetrics metrics = fontInfo.getMetricsFor(fname); int fsize = (int)(size.floatValue() * 1000); - fontState = new FontState(fname, metrics, fsize); + fontState = new Font(fname, metrics, fsize); } else { if (g2d instanceof PDFGraphics2D) { ((PDFGraphics2D) g2d).setOverrideFontState(fontState); } } - int fStyle = Font.PLAIN; + int fStyle = java.awt.Font.PLAIN; if (weight == Document.BOLD) { if (style.equals("italic")) { - fStyle = Font.BOLD | Font.ITALIC; + fStyle = java.awt.Font.BOLD | java.awt.Font.ITALIC; } else { - fStyle = Font.BOLD; + fStyle = java.awt.Font.BOLD; } } else { if (style.equals("italic")) { - fStyle = Font.ITALIC; + fStyle = java.awt.Font.ITALIC; } else { - fStyle = Font.PLAIN; + fStyle = java.awt.Font.PLAIN; } } - Font font = new Font(fontFamily, fStyle, + java.awt.Font font = new java.awt.Font(fontFamily, fStyle, (int)(fontState.getFontSize() / 1000)); g2d.setFont(font); @@ -288,7 +288,7 @@ public class PDFTextPainter implements TextPainter { return hasunsupported; } - private float getStringWidth(String str, FontState fontState) { + private float getStringWidth(String str, Font fontState) { float wordWidth = 0; float whitespaceWidth = fontState.getWidth(fontState.mapChar(' ')); diff --git a/src/java/org/apache/fop/tools/AreaTreeBuilder.java b/src/java/org/apache/fop/tools/AreaTreeBuilder.java index 5f06e5bf0..16b720db2 100644 --- a/src/java/org/apache/fop/tools/AreaTreeBuilder.java +++ b/src/java/org/apache/fop/tools/AreaTreeBuilder.java @@ -101,7 +101,7 @@ import org.apache.fop.area.inline.Space; import org.apache.fop.area.inline.Viewport; import org.apache.fop.area.inline.Word; import org.apache.fop.control.Document; -import org.apache.fop.layout.FontState; +import org.apache.fop.fonts.Font; import org.apache.fop.render.Renderer; import org.apache.fop.render.pdf.PDFRenderer; import org.apache.fop.render.svg.SVGRenderer; @@ -249,7 +249,7 @@ class TreeLoader extends AbstractLogEnabled { private AreaTree areaTree; private AreaTreeModel model; private Document fontInfo; - private FontState currentFontState; + private Font currentFontState; TreeLoader(Document fi) { fontInfo = fi; @@ -562,7 +562,7 @@ class TreeLoader extends AbstractLogEnabled { String fname = fontInfo.fontLookup("sans-serif", "normal", Document.NORMAL); FontMetrics metrics = fontInfo.getMetricsFor(fname); currentFontState = - new FontState(fname, metrics, 12000); + new Font(fname, metrics, 12000); ch.setWidth(currentFontState.getWidth(ch.getChar())); ch.setOffset(currentFontState.getCapHeight()); @@ -587,7 +587,7 @@ class TreeLoader extends AbstractLogEnabled { String fname = fontInfo.fontLookup("sans-serif", "normal", Document.NORMAL); FontMetrics metrics = fontInfo.getMetricsFor(fname); currentFontState = - new FontState(fname, metrics, 12000); + new Font(fname, metrics, 12000); Word word = getWord((Element) obj); word.addTrait(Trait.FONT_NAME, fname); diff --git a/src/java/org/apache/fop/util/CharUtilities.java b/src/java/org/apache/fop/util/CharUtilities.java index 80fd7aba2..0703deaf3 100644 --- a/src/java/org/apache/fop/util/CharUtilities.java +++ b/src/java/org/apache/fop/util/CharUtilities.java @@ -50,7 +50,7 @@ */ package org.apache.fop.util; -import org.apache.fop.layout.FontState; +import org.apache.fop.fonts.Font; /** * This class provides utilities to distinguish various kinds of Unicode @@ -117,7 +117,7 @@ public class CharUtilities { * @param fs FontState to use * @return the width of the character */ - public static int getCharWidth(char c, FontState fs) { + public static int getCharWidth(char c, Font fs) { int width; if ((c == '\n') || (c == '\r') || (c == '\t') || (c == '\u00A0')) { -- cgit v1.2.3