Index: src/java/org/apache/fop/area/AreaTreeParser.java =================================================================== --- src/java/org/apache/fop/area/AreaTreeParser.java (revision 767468) +++ src/java/org/apache/fop/area/AreaTreeParser.java (working copy) @@ -1006,7 +1006,7 @@ private static final Object[] SUBSET_COLOR = new Object[] { Trait.BACKGROUND, Trait.COLOR}; private static final Object[] SUBSET_FONT = new Object[] { - Trait.FONT, Trait.FONT_SIZE, Trait.BLINK, + Trait.FONT, Trait.FONT_SIZE, Trait.FONT_STRETCH, Trait.BLINK, Trait.OVERLINE, Trait.OVERLINE_COLOR, Trait.LINETHROUGH, Trait.LINETHROUGH_COLOR, Trait.UNDERLINE, Trait.UNDERLINE_COLOR}; Index: src/java/org/apache/fop/area/Trait.java =================================================================== --- src/java/org/apache/fop/area/Trait.java (revision 767468) +++ src/java/org/apache/fop/area/Trait.java (working copy) @@ -64,6 +64,11 @@ public static final Integer FONT_SIZE = new Integer(4); /** + * Font stretch for the current font. + */ + public static final Integer FONT_STRETCH = new Integer(5); + + /** * The current color. */ public static final Integer COLOR = new Integer(7); @@ -229,6 +234,7 @@ put(EXTERNAL_LINK, new TraitInfo("external-link", String.class)); put(FONT, new TraitInfo("font", FontTriplet.class)); put(FONT_SIZE, new TraitInfo("font-size", Integer.class)); + put(FONT_STRETCH, new TraitInfo("font-stretch", Float.class)); put(COLOR, new TraitInfo("color", Color.class)); put(PROD_ID, new TraitInfo("prod-id", String.class)); put(BACKGROUND, new TraitInfo("background", Background.class)); Index: src/java/org/apache/fop/fo/properties/CommonFont.java =================================================================== --- src/java/org/apache/fop/fo/properties/CommonFont.java (revision 767468) +++ src/java/org/apache/fop/fo/properties/CommonFont.java (working copy) @@ -24,9 +24,11 @@ import org.apache.fop.datatypes.Length; import org.apache.fop.datatypes.Numeric; +import org.apache.fop.datatypes.PercentBaseContext; import org.apache.fop.fo.Constants; import org.apache.fop.fo.PropertyList; import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.fonts.Font; import org.apache.fop.fonts.FontInfo; import org.apache.fop.fonts.FontTriplet; @@ -325,6 +327,55 @@ style, font_weight); return triplets; } + + /** + * Create and return a Font based on + * the properties stored in the instance variables. + * + * @param fontInfo + * @param context + * @return a Font object. + */ + public Font getFontInstance(FontInfo fontInfo, PercentBaseContext context) { + FontTriplet triplet = getFontState(fontInfo)[0]; + + int size = fontSize.getValue(context); + + float stretch; + switch (cachedCommonFont.fontStretch.getEnum()) { + case Constants.EN_ULTRA_CONDENSED: + stretch = 0.5f; + break; + case Constants.EN_EXTRA_CONDENSED: + stretch = 0.625f; + break; + case Constants.EN_CONDENSED: + stretch = 0.75f; + break; + case Constants.EN_SEMI_CONDENSED: + stretch = 0.875f; + break; + case Constants.EN_NORMAL: + stretch = 1f; + break; + case Constants.EN_SEMI_EXPANDED: + stretch = 1.25f; + break; + case Constants.EN_EXPANDED: + stretch = 1.5f; + break; + case Constants.EN_EXTRA_EXPANDED: + stretch = 1.75f; + break; + case Constants.EN_ULTRA_EXPANDED: + stretch = 2.0f; + break; + default: + stretch = 1f; + } + + return fontInfo.getFontInstance(triplet, size, stretch); + } /** {@inheritDoc} */ public boolean equals(Object o) { Index: src/java/org/apache/fop/fonts/Font.java =================================================================== --- src/java/org/apache/fop/fonts/Font.java (revision 767468) +++ src/java/org/apache/fop/fonts/Font.java (working copy) @@ -58,6 +58,7 @@ private String fontName; private FontTriplet triplet; private int fontSize; + private float fontStretch; /** * normal or small-caps font @@ -73,11 +74,12 @@ * @param met font metrics * @param fontSize font size */ - public Font(String key, FontTriplet triplet, FontMetrics met, int fontSize) { + public Font(String key, FontTriplet triplet, FontMetrics met, int fontSize, float fontStretch) { this.fontName = key; this.triplet = triplet; this.metric = met; this.fontSize = fontSize; + this.fontStretch = fontStretch; } /** @@ -134,6 +136,18 @@ } /** + * Returns the font stretch + * @return the font stretch + */ + public float getFontStretch() { + return fontStretch; + } + + public int getStretchedFontSize() { + return (int) (getFontSize() * getFontStretch()); + } + + /** * Returns the XHeight * @return the XHeight */ @@ -182,7 +196,7 @@ */ public int getWidth(int charnum) { // returns width of given character number in millipoints - return (metric.getWidth(charnum, fontSize) / 1000); + return (int) (metric.getWidth(charnum, fontSize) * fontStretch / 1000); } /** @@ -235,6 +249,8 @@ sbuf.append(fontName); sbuf.append(','); sbuf.append(fontSize); + sbuf.append(','); + sbuf.append(fontStretch); /* sbuf.append(','); sbuf.append(fontStyle); @@ -266,7 +282,7 @@ if (width <= 0) { // Estimate the width of spaces not represented in // the font - int em = getFontSize(); //http://en.wikipedia.org/wiki/Em_(typography) + int em = getStretchedFontSize(); //http://en.wikipedia.org/wiki/Em_(typography) int en = em / 2; //http://en.wikipedia.org/wiki/En_(typography) if (c == ' ') { @@ -278,7 +294,7 @@ } else if (c == '\u2002') { width = em / 2; } else if (c == '\u2003') { - width = getFontSize(); + width = getStretchedFontSize(); } else if (c == '\u2004') { width = em / 3; } else if (c == '\u2005') { Index: src/java/org/apache/fop/fonts/FontInfo.java =================================================================== --- src/java/org/apache/fop/fonts/FontInfo.java (revision 767468) +++ src/java/org/apache/fop/fonts/FontInfo.java (working copy) @@ -282,20 +282,26 @@ * @param fontSize the font size * @return the requested Font instance */ - public Font getFontInstance(FontTriplet triplet, int fontSize) { + public Font getFontInstance(FontTriplet triplet, int fontSize, float fontStretch) { Map sizes = (Map)fontInstanceCache.get(triplet); if (sizes == null) { sizes = new java.util.HashMap(); fontInstanceCache.put(triplet, sizes); } Integer size = new Integer(fontSize); - Font font = (Font)sizes.get(size); + Map stretches = (Map)sizes.get(size); + if (stretches == null) { + stretches = new java.util.HashMap(); + sizes.put(size, stretches); + } + Float stretch = new Float(fontStretch); + Font font = (Font)stretches.get(stretch); if (font == null) { String fname = getInternalFontKey(triplet); useFont(fname); FontMetrics metrics = getMetricsFor(fname); - font = new Font(fname, triplet, metrics, fontSize); - sizes.put(size, font); + font = new Font(fname, triplet, metrics, fontSize, fontStretch); + stretches.put(stretch, font); } return font; } Index: src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java =================================================================== --- src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java (revision 767468) +++ src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java (working copy) @@ -32,7 +32,6 @@ import org.apache.fop.datatypes.Length; import org.apache.fop.fonts.Font; import org.apache.fop.fonts.FontInfo; -import org.apache.fop.fonts.FontTriplet; import org.apache.fop.layoutmgr.inline.InlineLayoutManager; import org.apache.fop.layoutmgr.inline.InlineLevelLayoutManager; import org.apache.fop.layoutmgr.inline.LineLayoutManager; @@ -82,8 +81,7 @@ public void initialize() { super.initialize(); FontInfo fi = getBlockFO().getFOEventHandler().getFontInfo(); - FontTriplet[] fontkeys = getBlockFO().getCommonFont().getFontState(fi); - Font initFont = fi.getFontInstance(fontkeys[0], getBlockFO().getCommonFont().fontSize.getValue(this)); + Font initFont = getBlockFO().getCommonFont().getFontInstance(fi, this); lead = initFont.getAscender(); follow = -initFont.getDescender(); //middleShift = -fs.getXHeight() / 2; Index: src/java/org/apache/fop/layoutmgr/inline/AbstractPageNumberCitationLayoutManager.java =================================================================== --- src/java/org/apache/fop/layoutmgr/inline/AbstractPageNumberCitationLayoutManager.java (revision 767468) +++ src/java/org/apache/fop/layoutmgr/inline/AbstractPageNumberCitationLayoutManager.java (working copy) @@ -28,7 +28,6 @@ import org.apache.fop.fo.flow.AbstractPageNumberCitation; import org.apache.fop.fonts.Font; import org.apache.fop.fonts.FontInfo; -import org.apache.fop.fonts.FontTriplet; import org.apache.fop.layoutmgr.LayoutContext; import org.apache.fop.layoutmgr.LayoutManager; import org.apache.fop.layoutmgr.PositionIterator; @@ -61,8 +60,7 @@ /** {@inheritDoc} */ public void initialize() { FontInfo fi = fobj.getFOEventHandler().getFontInfo(); - FontTriplet[] fontkeys = fobj.getCommonFont().getFontState(fi); - font = fi.getFontInstance(fontkeys[0], fobj.getCommonFont().fontSize.getValue(this)); + font = fobj.getCommonFont().getFontInstance(fi, this); setCommonBorderPaddingBackground(fobj.getCommonBorderPaddingBackground()); } Index: src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java =================================================================== --- src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java (revision 767468) +++ src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java (working copy) @@ -27,7 +27,6 @@ import org.apache.fop.fo.properties.CommonBorderPaddingBackground; import org.apache.fop.fonts.Font; import org.apache.fop.fonts.FontInfo; -import org.apache.fop.fonts.FontTriplet; import org.apache.fop.layoutmgr.InlineKnuthSequence; import org.apache.fop.layoutmgr.KnuthElement; import org.apache.fop.layoutmgr.KnuthGlue; @@ -65,8 +64,7 @@ /** {@inheritDoc} */ public void initialize() { FontInfo fi = fobj.getFOEventHandler().getFontInfo(); - FontTriplet[] fontkeys = fobj.getCommonFont().getFontState(fi); - font = fi.getFontInstance(fontkeys[0], fobj.getCommonFont().fontSize.getValue(this)); + font = fobj.getCommonFont().getFontInstance(fi, this); SpaceVal ls = SpaceVal.makeLetterSpacing(fobj.getLetterSpacing()); letterSpaceIPD = ls.getSpace(); hyphIPD = fobj.getCommonHyphenation().getHyphIPD(font); Index: src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java =================================================================== --- src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java (revision 767468) +++ src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java (working copy) @@ -40,7 +40,6 @@ import org.apache.fop.fo.properties.SpaceProperty; import org.apache.fop.fonts.Font; import org.apache.fop.fonts.FontInfo; -import org.apache.fop.fonts.FontTriplet; import org.apache.fop.layoutmgr.BlockKnuthSequence; import org.apache.fop.layoutmgr.BlockLevelLayoutManager; import org.apache.fop.layoutmgr.BreakElement; @@ -116,8 +115,7 @@ public void initialize() { int padding = 0; FontInfo fi = fobj.getFOEventHandler().getFontInfo(); - FontTriplet[] fontkeys = fobj.getCommonFont().getFontState(fi); - font = fi.getFontInstance(fontkeys[0], fobj.getCommonFont().fontSize.getValue(this)); + font = fobj.getCommonFont().getFontInstance(fi, this); lineHeight = fobj.getLineHeight(); borderProps = fobj.getCommonBorderPaddingBackground(); inlineProps = fobj.getCommonMarginInline(); Index: src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java =================================================================== --- src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java (revision 767468) +++ src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java (working copy) @@ -27,7 +27,6 @@ import org.apache.fop.fo.flow.Leader; import org.apache.fop.fonts.Font; import org.apache.fop.fonts.FontInfo; -import org.apache.fop.fonts.FontTriplet; import org.apache.fop.layoutmgr.InlineKnuthSequence; import org.apache.fop.layoutmgr.KnuthElement; import org.apache.fop.layoutmgr.KnuthGlue; @@ -70,8 +69,7 @@ /** {@inheritDoc} */ public void initialize() { FontInfo fi = fobj.getFOEventHandler().getFontInfo(); - FontTriplet[] fontkeys = fobj.getCommonFont().getFontState(fi); - font = fi.getFontInstance(fontkeys[0], fobj.getCommonFont().fontSize.getValue(this)); + font = fobj.getCommonFont().getFontInstance(fi, this); // the property leader-alignment does not affect vertical positioning // (see section 7.21.1 in the XSL Recommendation) // setAlignment(node.getLeaderAlignment()); Index: src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java =================================================================== --- src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java (revision 767468) +++ src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java (working copy) @@ -39,7 +39,6 @@ import org.apache.fop.fo.properties.CommonHyphenation; import org.apache.fop.fonts.Font; import org.apache.fop.fonts.FontInfo; -import org.apache.fop.fonts.FontTriplet; import org.apache.fop.hyphenation.Hyphenation; import org.apache.fop.hyphenation.Hyphenator; import org.apache.fop.layoutmgr.BlockLevelLayoutManager; @@ -575,8 +574,7 @@ /** {@inheritDoc} */ public LinkedList getNextKnuthElements(LayoutContext context, int alignment) { FontInfo fi = fobj.getFOEventHandler().getFontInfo(); - FontTriplet[] fontkeys = fobj.getCommonFont().getFontState(fi); - Font fs = fi.getFontInstance(fontkeys[0], fobj.getCommonFont().fontSize.getValue(this)); + Font fs = fobj.getCommonFont().getFontInstance(fi, this); alignmentContext = new AlignmentContext(fs, lineHeight.getValue(this), context.getWritingMode()); context.setAlignmentContext(alignmentContext); Index: src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java =================================================================== --- src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java (revision 767468) +++ src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java (working copy) @@ -25,7 +25,6 @@ import org.apache.fop.area.Trait; import org.apache.fop.fonts.Font; import org.apache.fop.fonts.FontInfo; -import org.apache.fop.fonts.FontTriplet; import org.apache.fop.layoutmgr.LayoutContext; import org.apache.fop.layoutmgr.TraitSetter; import org.apache.fop.traits.MinOptMax; @@ -52,8 +51,7 @@ /** {@inheritDoc} */ public void initialize() { FontInfo fi = fobj.getFOEventHandler().getFontInfo(); - FontTriplet[] fontkeys = fobj.getCommonFont().getFontState(fi); - font = fi.getFontInstance(fontkeys[0], fobj.getCommonFont().fontSize.getValue(this)); + font = fobj.getCommonFont().getFontInstance(fi, this); setCommonBorderPaddingBackground(fobj.getCommonBorderPaddingBackground()); } Index: src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java =================================================================== --- src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java (revision 767468) +++ src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java (working copy) @@ -32,7 +32,6 @@ import org.apache.fop.fo.FOText; import org.apache.fop.fonts.Font; import org.apache.fop.fonts.FontInfo; -import org.apache.fop.fonts.FontTriplet; import org.apache.fop.layoutmgr.InlineKnuthSequence; import org.apache.fop.layoutmgr.KnuthBox; import org.apache.fop.layoutmgr.KnuthElement; @@ -189,8 +188,7 @@ /** {@inheritDoc} */ public void initialize() { FontInfo fi = foText.getFOEventHandler().getFontInfo(); - FontTriplet[] fontkeys = foText.getCommonFont().getFontState(fi); - font = fi.getFontInstance(fontkeys[0], foText.getCommonFont().fontSize.getValue(this)); + font = foText.getCommonFont().getFontInstance(fi, this); // With CID fonts, space isn't neccesary currentFontState.width(32) spaceCharIPD = font.getCharWidth(' '); Index: src/java/org/apache/fop/layoutmgr/TraitSetter.java =================================================================== --- src/java/org/apache/fop/layoutmgr/TraitSetter.java (revision 767468) +++ src/java/org/apache/fop/layoutmgr/TraitSetter.java (working copy) @@ -548,6 +548,7 @@ public static void addFontTraits(Area area, Font font) { area.addTrait(Trait.FONT, font.getFontTriplet()); area.addTrait(Trait.FONT_SIZE, new Integer(font.getFontSize())); + area.addTrait(Trait.FONT_STRETCH, new Float(font.getFontStretch())); } /** Index: src/java/org/apache/fop/render/pdf/PDFRenderer.java =================================================================== --- src/java/org/apache/fop/render/pdf/PDFRenderer.java (revision 767468) +++ src/java/org/apache/fop/render/pdf/PDFRenderer.java (working copy) @@ -254,6 +254,8 @@ protected String currentFontName = ""; /** Size of currently selected font */ protected int currentFontSize = 0; + /** Stretching of currently selected font */ + protected float currentFontStretch = 0f; /** page height */ protected int pageHeight; @@ -528,6 +530,7 @@ currentPage = null; currentState = null; currentFontName = ""; + currentFontStretch = 0f; idPositions.clear(); idGoTos.clear(); @@ -668,6 +671,7 @@ if (!inTextMode) { currentStream.add("BT\n"); currentFontName = ""; + currentFontStretch = 0f; inTextMode = true; } } @@ -797,6 +801,7 @@ currentFontName = ""; + currentFontStretch = 0f; super.renderPage(page); @@ -848,6 +853,7 @@ */ protected void handleRegionTraits(RegionViewport region) { currentFontName = ""; + currentFontStretch = 0f; super.handleRegionTraits(region); } @@ -1433,12 +1439,13 @@ String fontName = getInternalFontNameForArea(text); int size = ((Integer) text.getTrait(Trait.FONT_SIZE)).intValue(); + float stretch = ((Float) text.getTrait(Trait.FONT_STRETCH)).floatValue(); // This assumes that *all* CIDFonts use a /ToUnicode mapping Typeface tf = (Typeface) fontInfo.getFonts().get(fontName); boolean useMultiByte = tf.isMultiByte(); - updateFont(fontName, size, pdf); + updateFont(fontName, size, stretch, pdf); Color ct = (Color) text.getTrait(Trait.COLOR); updateColor(ct, true, pdf); @@ -1660,7 +1667,7 @@ updateColor(col, fill, null); } - private void updateFont(String name, int size, StringBuffer pdf) { + private void updateFont(String name, int size, float stretch, StringBuffer pdf) { if ((!name.equals(this.currentFontName)) || (size != this.currentFontSize)) { closeText(); @@ -1670,6 +1677,10 @@ pdf = pdf.append("/" + name + " " + format((float) size / 1000f) + " Tf\n"); } + if (stretch != this.currentFontStretch) { + this.currentFontStretch = stretch; + pdf = pdf.append(format(stretch * 100) + " Tz\n"); + } } /** {@inheritDoc} */ @@ -1805,6 +1816,8 @@ context.setProperty(PDFRendererContextConstants.PDF_FONT_NAME, currentFontName); context.setProperty(PDFRendererContextConstants.PDF_FONT_SIZE, new Integer(currentFontSize)); + context.setProperty(PDFRendererContextConstants.PDF_FONT_STRETCH, + new Float(currentFontStretch)); return context; } Index: src/java/org/apache/fop/render/pdf/PDFRendererContextConstants.java =================================================================== --- src/java/org/apache/fop/render/pdf/PDFRendererContextConstants.java (revision 767468) +++ src/java/org/apache/fop/render/pdf/PDFRendererContextConstants.java (working copy) @@ -49,5 +49,8 @@ /** The current pdf font size. */ String PDF_FONT_SIZE = "fontSize"; + + /** The current pdf font stretch. */ + String PDF_FONT_STRETCH = "fontStretch"; } Index: src/java/org/apache/fop/render/PrintRenderer.java =================================================================== --- src/java/org/apache/fop/render/PrintRenderer.java (revision 767468) +++ src/java/org/apache/fop/render/PrintRenderer.java (working copy) @@ -95,7 +95,8 @@ protected Font getFontFromArea(Area area) { FontTriplet triplet = (FontTriplet)area.getTrait(Trait.FONT); int size = ((Integer)area.getTrait(Trait.FONT_SIZE)).intValue(); - return fontInfo.getFontInstance(triplet, size); + float stretch = ((Float)area.getTrait(Trait.FONT_STRETCH)).floatValue(); + return fontInfo.getFontInstance(triplet, size, stretch); } /** Index: src/java/org/apache/fop/render/ps/NativeTextHandler.java =================================================================== --- src/java/org/apache/fop/render/ps/NativeTextHandler.java (revision 767468) +++ src/java/org/apache/fop/render/ps/NativeTextHandler.java (working copy) @@ -20,6 +20,7 @@ package org.apache.fop.render.ps; import java.awt.Shape; +import java.awt.font.TextAttribute; import java.awt.geom.AffineTransform; import java.io.IOException; @@ -155,6 +156,13 @@ fontFamily = "sans-serif"; } int fontSize = 1000 * f.getSize(); + Float width = (Float) f.getAttributes().get(TextAttribute.WIDTH); + float fontStretch; + if (width != null) { + fontStretch = width.floatValue(); + } else { + fontStretch = 1f; + } String style = f.isItalic() ? "italic" : "normal"; int weight = f.isBold() ? Font.WEIGHT_BOLD : Font.WEIGHT_NORMAL; @@ -162,7 +170,7 @@ if (triplet == null) { triplet = fontInfo.findAdjustWeight("sans-serif", style, weight); } - return fontInfo.getFontInstance(triplet, fontSize); + return fontInfo.getFontInstance(triplet, fontSize, fontStretch); } private void establishCurrentFont() throws IOException { Index: src/java/org/apache/fop/render/ps/PSTextPainter.java =================================================================== --- src/java/org/apache/fop/render/ps/PSTextPainter.java (revision 767468) +++ src/java/org/apache/fop/render/ps/PSTextPainter.java (working copy) @@ -382,6 +382,10 @@ if (fontSize == null) { fontSize = new Float(10.0f); } + Float fontStretch = (Float)aci.getAttribute(TextAttribute.WIDTH); + if (fontStretch == null) { + fontStretch = new Float(1.0f); + } String style = getStyle(aci); int weight = getWeight(aci); @@ -402,13 +406,15 @@ FontTriplet triplet = fontInfo.fontLookup( fontFamily, style, weight); int fsize = (int)(fontSize.floatValue() * 1000); - return fontInfo.getFontInstance(triplet, fsize); + float fstretch = fontStretch.floatValue(); + return fontInfo.getFontInstance(triplet, fsize, fstretch); } } } FontTriplet triplet = fontInfo.fontLookup("any", style, Font.WEIGHT_NORMAL); int fsize = (int)(fontSize.floatValue() * 1000); - return fontInfo.getFontInstance(triplet, fsize); + float fstretch = fontStretch.floatValue(); + return fontInfo.getFontInstance(triplet, fsize, fstretch); } private java.awt.Font makeAWTFont(AttributedCharacterIterator aci, Font font) { Index: src/java/org/apache/fop/svg/PDFGraphics2D.java =================================================================== --- src/java/org/apache/fop/svg/PDFGraphics2D.java (revision 767468) +++ src/java/org/apache/fop/svg/PDFGraphics2D.java (working copy) @@ -34,6 +34,7 @@ import java.awt.Shape; import java.awt.Stroke; import java.awt.color.ColorSpace; +import java.awt.font.TextAttribute; import java.awt.geom.AffineTransform; import java.awt.geom.PathIterator; import java.awt.geom.Point2D; @@ -1323,7 +1324,7 @@ fontState = getInternalFontForAWTFont(gFont); } else { fontState = fontInfo.getFontInstance( - ovFontState.getFontTriplet(), ovFontState.getFontSize()); + ovFontState.getFontTriplet(), ovFontState.getFontSize(), ovFontState.getFontStretch()); ovFontState = null; } updateCurrentFont(fontState); @@ -1457,10 +1458,17 @@ n = "sans-serif"; } float siz = awtFont.getSize2D(); + Float width = (Float) awtFont.getAttributes().get(TextAttribute.WIDTH); + float stretch; + if (width != null) { + stretch = width.floatValue(); + } else { + stretch = 1f; + } String style = awtFont.isItalic() ? "italic" : "normal"; int weight = awtFont.isBold() ? Font.WEIGHT_BOLD : Font.WEIGHT_NORMAL; FontTriplet triplet = fontInfo.fontLookup(n, style, weight); - fontState = fontInfo.getFontInstance(triplet, (int)(siz * 1000 + 0.5)); + fontState = fontInfo.getFontInstance(triplet, (int)(siz * 1000 + 0.5), stretch); return fontState; } Index: src/java/org/apache/fop/svg/PDFTextPainter.java =================================================================== --- src/java/org/apache/fop/svg/PDFTextPainter.java (revision 767468) +++ src/java/org/apache/fop/svg/PDFTextPainter.java (working copy) @@ -271,6 +271,7 @@ Float posture = (Float) aci.getAttribute(TextAttribute.POSTURE); Float taWeight = (Float) aci.getAttribute(TextAttribute.WEIGHT); Float fontSize = (Float) aci.getAttribute(TextAttribute.SIZE); + Float fontStretch = (Float) aci.getAttribute(TextAttribute.WIDTH); String style = ((posture != null) && (posture.floatValue() > 0.0)) ? "italic" : "normal"; @@ -298,7 +299,8 @@ FontTriplet triplet = fontInfo.fontLookup(gvtFontFamily, style, weight); int fsize = (int)(fontSize.floatValue() * 1000); - fonts.add(fontInfo.getFontInstance(triplet, fsize)); + float fstretch = fontStretch.floatValue(); + fonts.add(fontInfo.getFontInstance(triplet, fsize, fstretch)); } } catch (Exception e) { //Most likely NoSuchMethodError here when using Batik 1.6 @@ -321,14 +323,16 @@ FontTriplet triplet = fontInfo.fontLookup(fontFamily, style, weight); int fsize = (int)(fontSize.floatValue() * 1000); - fonts.add(fontInfo.getFontInstance(triplet, fsize)); + float fstretch = fontStretch.floatValue(); + fonts.add(fontInfo.getFontInstance(triplet, fsize, fstretch)); } } } if (fonts.size() == 0) { FontTriplet triplet = fontInfo.fontLookup("any", style, Font.WEIGHT_NORMAL); int fsize = (int)(fontSize.floatValue() * 1000); - fonts.add(fontInfo.getFontInstance(triplet, fsize)); + float fstretch = fontStretch.floatValue(); + fonts.add(fontInfo.getFontInstance(triplet, fsize, fstretch)); if (DEBUG) { System.out.print("fallback to 'any' font"); }