View | Details | Raw Unified | Return to bug 42577
Collapse All | Expand All

(-)src/java/org/apache/fop/area/AreaTreeParser.java (-1 / +1 lines)
Lines 1006-1012 Link Here
1006
        private static final Object[] SUBSET_COLOR = new Object[] {
1006
        private static final Object[] SUBSET_COLOR = new Object[] {
1007
            Trait.BACKGROUND, Trait.COLOR};
1007
            Trait.BACKGROUND, Trait.COLOR};
1008
        private static final Object[] SUBSET_FONT = new Object[] {
1008
        private static final Object[] SUBSET_FONT = new Object[] {
1009
            Trait.FONT, Trait.FONT_SIZE, Trait.BLINK,
1009
            Trait.FONT, Trait.FONT_SIZE, Trait.FONT_STRETCH, Trait.BLINK,
1010
            Trait.OVERLINE, Trait.OVERLINE_COLOR,
1010
            Trait.OVERLINE, Trait.OVERLINE_COLOR,
1011
            Trait.LINETHROUGH, Trait.LINETHROUGH_COLOR,
1011
            Trait.LINETHROUGH, Trait.LINETHROUGH_COLOR,
1012
            Trait.UNDERLINE, Trait.UNDERLINE_COLOR};
1012
            Trait.UNDERLINE, Trait.UNDERLINE_COLOR};
(-)src/java/org/apache/fop/area/Trait.java (+6 lines)
Lines 64-69 Link Here
64
    public static final Integer FONT_SIZE = new Integer(4);
64
    public static final Integer FONT_SIZE = new Integer(4);
65
65
66
    /**
66
    /**
67
     * Font stretch for the current font.
68
     */
69
    public static final Integer FONT_STRETCH = new Integer(5);
70
71
    /**
67
     * The current color.
72
     * The current color.
68
     */
73
     */
69
    public static final Integer COLOR = new Integer(7);
74
    public static final Integer COLOR = new Integer(7);
Lines 229-234 Link Here
229
        put(EXTERNAL_LINK, new TraitInfo("external-link", String.class));
234
        put(EXTERNAL_LINK, new TraitInfo("external-link", String.class));
230
        put(FONT,         new TraitInfo("font", FontTriplet.class));
235
        put(FONT,         new TraitInfo("font", FontTriplet.class));
231
        put(FONT_SIZE,    new TraitInfo("font-size", Integer.class));
236
        put(FONT_SIZE,    new TraitInfo("font-size", Integer.class));
237
        put(FONT_STRETCH, new TraitInfo("font-stretch", Float.class));
232
        put(COLOR, new TraitInfo("color", Color.class));
238
        put(COLOR, new TraitInfo("color", Color.class));
233
        put(PROD_ID, new TraitInfo("prod-id", String.class));
239
        put(PROD_ID, new TraitInfo("prod-id", String.class));
234
        put(BACKGROUND,   new TraitInfo("background", Background.class));
240
        put(BACKGROUND,   new TraitInfo("background", Background.class));
(-)src/java/org/apache/fop/fo/properties/CommonFont.java (+51 lines)
Lines 24-32 Link Here
24
24
25
import org.apache.fop.datatypes.Length;
25
import org.apache.fop.datatypes.Length;
26
import org.apache.fop.datatypes.Numeric;
26
import org.apache.fop.datatypes.Numeric;
27
import org.apache.fop.datatypes.PercentBaseContext;
27
import org.apache.fop.fo.Constants;
28
import org.apache.fop.fo.Constants;
28
import org.apache.fop.fo.PropertyList;
29
import org.apache.fop.fo.PropertyList;
29
import org.apache.fop.fo.expr.PropertyException;
30
import org.apache.fop.fo.expr.PropertyException;
31
import org.apache.fop.fonts.Font;
30
import org.apache.fop.fonts.FontInfo;
32
import org.apache.fop.fonts.FontInfo;
31
import org.apache.fop.fonts.FontTriplet;
33
import org.apache.fop.fonts.FontTriplet;
32
34
Lines 325-330 Link Here
325
                                    style, font_weight);
327
                                    style, font_weight);
326
        return triplets;
328
        return triplets;
327
    }
329
    }
330
    
331
    /**
332
     * Create and return a <code>Font</code> based on 
333
     * the properties stored in the instance variables.
334
     * 
335
     * @param fontInfo
336
     * @param context
337
     * @return a Font object.
338
     */
339
    public Font getFontInstance(FontInfo fontInfo, PercentBaseContext context) {
340
    	FontTriplet triplet = getFontState(fontInfo)[0];
341
    	
342
    	int size = fontSize.getValue(context);
343
    	
344
    	float stretch;
345
    	switch (cachedCommonFont.fontStretch.getEnum()) {
346
    	case Constants.EN_ULTRA_CONDENSED:
347
    		stretch = 0.5f;
348
            break;
349
    	case Constants.EN_EXTRA_CONDENSED:
350
    		stretch = 0.625f;
351
            break;
352
    	case Constants.EN_CONDENSED:
353
    		stretch = 0.75f;
354
            break;
355
    	case Constants.EN_SEMI_CONDENSED:
356
    		stretch = 0.875f;
357
            break;
358
    	case Constants.EN_NORMAL:
359
    		stretch = 1f;
360
            break;
361
    	case Constants.EN_SEMI_EXPANDED:
362
    		stretch = 1.25f;
363
            break;
364
    	case Constants.EN_EXPANDED:
365
    		stretch = 1.5f;
366
            break;
367
    	case Constants.EN_EXTRA_EXPANDED:
368
    		stretch = 1.75f;
369
            break;
370
    	case Constants.EN_ULTRA_EXPANDED:
371
    		stretch = 2.0f;
372
            break;
373
    	default:
374
    		stretch = 1f;
375
    	}
376
    	
377
    	return fontInfo.getFontInstance(triplet, size, stretch);
378
    }
328
379
329
    /** {@inheritDoc} */
380
    /** {@inheritDoc} */
330
    public boolean equals(Object o) {
381
    public boolean equals(Object o) {
(-)src/java/org/apache/fop/fonts/Font.java (-4 / +20 lines)
Lines 58-63 Link Here
58
    private String fontName;
58
    private String fontName;
59
    private FontTriplet triplet;
59
    private FontTriplet triplet;
60
    private int fontSize;
60
    private int fontSize;
61
    private float fontStretch;
61
62
62
    /**
63
    /**
63
     * normal or small-caps font
64
     * normal or small-caps font
Lines 73-83 Link Here
73
     * @param met font metrics
74
     * @param met font metrics
74
     * @param fontSize font size
75
     * @param fontSize font size
75
     */
76
     */
76
    public Font(String key, FontTriplet triplet, FontMetrics met, int fontSize) {
77
    public Font(String key, FontTriplet triplet, FontMetrics met, int fontSize, float fontStretch) {
77
        this.fontName = key;
78
        this.fontName = key;
78
        this.triplet = triplet;
79
        this.triplet = triplet;
79
        this.metric = met;
80
        this.metric = met;
80
        this.fontSize = fontSize;
81
        this.fontSize = fontSize;
82
        this.fontStretch = fontStretch;
81
    }
83
    }
82
84
83
    /**
85
    /**
Lines 134-139 Link Here
134
    }
136
    }
135
137
136
    /**
138
    /**
139
     * Returns the font stretch
140
     * @return the font stretch
141
     */
142
    public float getFontStretch() {
143
        return fontStretch;
144
    }
145
    
146
    public int getStretchedFontSize() {
147
    	return (int) (getFontSize() * getFontStretch());
148
    }
149
150
    /**
137
     * Returns the XHeight
151
     * Returns the XHeight
138
     * @return the XHeight
152
     * @return the XHeight
139
     */
153
     */
Lines 182-188 Link Here
182
     */
196
     */
183
    public int getWidth(int charnum) {
197
    public int getWidth(int charnum) {
184
        // returns width of given character number in millipoints
198
        // returns width of given character number in millipoints
185
        return (metric.getWidth(charnum, fontSize) / 1000);
199
        return (int) (metric.getWidth(charnum, fontSize) * fontStretch / 1000);
186
    }
200
    }
187
201
188
    /**
202
    /**
Lines 235-240 Link Here
235
        sbuf.append(fontName);
249
        sbuf.append(fontName);
236
        sbuf.append(',');
250
        sbuf.append(',');
237
        sbuf.append(fontSize);
251
        sbuf.append(fontSize);
252
        sbuf.append(',');
253
        sbuf.append(fontStretch);
238
        /*
254
        /*
239
        sbuf.append(',');
255
        sbuf.append(',');
240
        sbuf.append(fontStyle);
256
        sbuf.append(fontStyle);
Lines 266-272 Link Here
266
            if (width <= 0) {
282
            if (width <= 0) {
267
                // Estimate the width of spaces not represented in
283
                // Estimate the width of spaces not represented in
268
                // the font
284
                // the font
269
                int em = getFontSize(); //http://en.wikipedia.org/wiki/Em_(typography)
285
                int em = getStretchedFontSize(); //http://en.wikipedia.org/wiki/Em_(typography)
270
                int en = em / 2; //http://en.wikipedia.org/wiki/En_(typography)
286
                int en = em / 2; //http://en.wikipedia.org/wiki/En_(typography)
271
287
272
                if (c == ' ') {
288
                if (c == ' ') {
Lines 278-284 Link Here
278
                } else if (c == '\u2002') {
294
                } else if (c == '\u2002') {
279
                    width = em / 2;
295
                    width = em / 2;
280
                } else if (c == '\u2003') {
296
                } else if (c == '\u2003') {
281
                    width = getFontSize();
297
                    width = getStretchedFontSize();
282
                } else if (c == '\u2004') {
298
                } else if (c == '\u2004') {
283
                    width = em / 3;
299
                    width = em / 3;
284
                } else if (c == '\u2005') {
300
                } else if (c == '\u2005') {
(-)src/java/org/apache/fop/fonts/FontInfo.java (-4 / +10 lines)
Lines 282-301 Link Here
282
     * @param fontSize the font size
282
     * @param fontSize the font size
283
     * @return the requested Font instance
283
     * @return the requested Font instance
284
     */
284
     */
285
    public Font getFontInstance(FontTriplet triplet, int fontSize) {
285
    public Font getFontInstance(FontTriplet triplet, int fontSize, float fontStretch) {
286
        Map sizes = (Map)fontInstanceCache.get(triplet);
286
        Map sizes = (Map)fontInstanceCache.get(triplet);
287
        if (sizes == null) {
287
        if (sizes == null) {
288
            sizes = new java.util.HashMap();
288
            sizes = new java.util.HashMap();
289
            fontInstanceCache.put(triplet, sizes);
289
            fontInstanceCache.put(triplet, sizes);
290
        }
290
        }
291
        Integer size = new Integer(fontSize);
291
        Integer size = new Integer(fontSize);
292
        Font font = (Font)sizes.get(size);
292
        Map stretches = (Map)sizes.get(size);
293
        if (stretches == null) {
294
        	stretches = new java.util.HashMap();
295
        	sizes.put(size, stretches);
296
        }
297
        Float stretch = new Float(fontStretch);
298
        Font font = (Font)stretches.get(stretch);
293
        if (font == null) {
299
        if (font == null) {
294
            String fname = getInternalFontKey(triplet);
300
            String fname = getInternalFontKey(triplet);
295
            useFont(fname);
301
            useFont(fname);
296
            FontMetrics metrics = getMetricsFor(fname);
302
            FontMetrics metrics = getMetricsFor(fname);
297
            font = new Font(fname, triplet, metrics, fontSize);
303
            font = new Font(fname, triplet, metrics, fontSize, fontStretch);
298
            sizes.put(size, font);
304
            stretches.put(stretch, font);
299
        }
305
        }
300
        return font;
306
        return font;
301
    }
307
    }
(-)src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java (-3 / +1 lines)
Lines 32-38 Link Here
32
import org.apache.fop.datatypes.Length;
32
import org.apache.fop.datatypes.Length;
33
import org.apache.fop.fonts.Font;
33
import org.apache.fop.fonts.Font;
34
import org.apache.fop.fonts.FontInfo;
34
import org.apache.fop.fonts.FontInfo;
35
import org.apache.fop.fonts.FontTriplet;
36
import org.apache.fop.layoutmgr.inline.InlineLayoutManager;
35
import org.apache.fop.layoutmgr.inline.InlineLayoutManager;
37
import org.apache.fop.layoutmgr.inline.InlineLevelLayoutManager;
36
import org.apache.fop.layoutmgr.inline.InlineLevelLayoutManager;
38
import org.apache.fop.layoutmgr.inline.LineLayoutManager;
37
import org.apache.fop.layoutmgr.inline.LineLayoutManager;
Lines 82-89 Link Here
82
    public void initialize() {
81
    public void initialize() {
83
        super.initialize();
82
        super.initialize();
84
        FontInfo fi = getBlockFO().getFOEventHandler().getFontInfo();
83
        FontInfo fi = getBlockFO().getFOEventHandler().getFontInfo();
85
        FontTriplet[] fontkeys = getBlockFO().getCommonFont().getFontState(fi);
84
        Font initFont = getBlockFO().getCommonFont().getFontInstance(fi, this);
86
        Font initFont = fi.getFontInstance(fontkeys[0], getBlockFO().getCommonFont().fontSize.getValue(this));
87
        lead = initFont.getAscender();
85
        lead = initFont.getAscender();
88
        follow = -initFont.getDescender();
86
        follow = -initFont.getDescender();
89
        //middleShift = -fs.getXHeight() / 2;
87
        //middleShift = -fs.getXHeight() / 2;
(-)src/java/org/apache/fop/layoutmgr/inline/AbstractPageNumberCitationLayoutManager.java (-3 / +1 lines)
Lines 28-34 Link Here
28
import org.apache.fop.fo.flow.AbstractPageNumberCitation;
28
import org.apache.fop.fo.flow.AbstractPageNumberCitation;
29
import org.apache.fop.fonts.Font;
29
import org.apache.fop.fonts.Font;
30
import org.apache.fop.fonts.FontInfo;
30
import org.apache.fop.fonts.FontInfo;
31
import org.apache.fop.fonts.FontTriplet;
32
import org.apache.fop.layoutmgr.LayoutContext;
31
import org.apache.fop.layoutmgr.LayoutContext;
33
import org.apache.fop.layoutmgr.LayoutManager;
32
import org.apache.fop.layoutmgr.LayoutManager;
34
import org.apache.fop.layoutmgr.PositionIterator;
33
import org.apache.fop.layoutmgr.PositionIterator;
Lines 61-68 Link Here
61
    /** {@inheritDoc} */
60
    /** {@inheritDoc} */
62
    public void initialize() {
61
    public void initialize() {
63
        FontInfo fi = fobj.getFOEventHandler().getFontInfo();
62
        FontInfo fi = fobj.getFOEventHandler().getFontInfo();
64
        FontTriplet[] fontkeys = fobj.getCommonFont().getFontState(fi);
63
        font = fobj.getCommonFont().getFontInstance(fi, this);
65
        font = fi.getFontInstance(fontkeys[0], fobj.getCommonFont().fontSize.getValue(this));
66
        setCommonBorderPaddingBackground(fobj.getCommonBorderPaddingBackground());
64
        setCommonBorderPaddingBackground(fobj.getCommonBorderPaddingBackground());
67
    }
65
    }
68
66
(-)src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java (-3 / +1 lines)
Lines 27-33 Link Here
27
import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
27
import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
28
import org.apache.fop.fonts.Font;
28
import org.apache.fop.fonts.Font;
29
import org.apache.fop.fonts.FontInfo;
29
import org.apache.fop.fonts.FontInfo;
30
import org.apache.fop.fonts.FontTriplet;
31
import org.apache.fop.layoutmgr.InlineKnuthSequence;
30
import org.apache.fop.layoutmgr.InlineKnuthSequence;
32
import org.apache.fop.layoutmgr.KnuthElement;
31
import org.apache.fop.layoutmgr.KnuthElement;
33
import org.apache.fop.layoutmgr.KnuthGlue;
32
import org.apache.fop.layoutmgr.KnuthGlue;
Lines 65-72 Link Here
65
    /** {@inheritDoc} */
64
    /** {@inheritDoc} */
66
    public void initialize() {
65
    public void initialize() {
67
        FontInfo fi = fobj.getFOEventHandler().getFontInfo();
66
        FontInfo fi = fobj.getFOEventHandler().getFontInfo();
68
        FontTriplet[] fontkeys = fobj.getCommonFont().getFontState(fi);
67
        font = fobj.getCommonFont().getFontInstance(fi, this);
69
        font = fi.getFontInstance(fontkeys[0], fobj.getCommonFont().fontSize.getValue(this));
70
        SpaceVal ls = SpaceVal.makeLetterSpacing(fobj.getLetterSpacing());
68
        SpaceVal ls = SpaceVal.makeLetterSpacing(fobj.getLetterSpacing());
71
        letterSpaceIPD = ls.getSpace();
69
        letterSpaceIPD = ls.getSpace();
72
        hyphIPD = fobj.getCommonHyphenation().getHyphIPD(font);
70
        hyphIPD = fobj.getCommonHyphenation().getHyphIPD(font);
(-)src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java (-3 / +1 lines)
Lines 40-46 Link Here
40
import org.apache.fop.fo.properties.SpaceProperty;
40
import org.apache.fop.fo.properties.SpaceProperty;
41
import org.apache.fop.fonts.Font;
41
import org.apache.fop.fonts.Font;
42
import org.apache.fop.fonts.FontInfo;
42
import org.apache.fop.fonts.FontInfo;
43
import org.apache.fop.fonts.FontTriplet;
44
import org.apache.fop.layoutmgr.BlockKnuthSequence;
43
import org.apache.fop.layoutmgr.BlockKnuthSequence;
45
import org.apache.fop.layoutmgr.BlockLevelLayoutManager;
44
import org.apache.fop.layoutmgr.BlockLevelLayoutManager;
46
import org.apache.fop.layoutmgr.BreakElement;
45
import org.apache.fop.layoutmgr.BreakElement;
Lines 116-123 Link Here
116
    public void initialize() {
115
    public void initialize() {
117
        int padding = 0;
116
        int padding = 0;
118
        FontInfo fi = fobj.getFOEventHandler().getFontInfo();
117
        FontInfo fi = fobj.getFOEventHandler().getFontInfo();
119
        FontTriplet[] fontkeys = fobj.getCommonFont().getFontState(fi);
118
        font = fobj.getCommonFont().getFontInstance(fi, this);
120
        font = fi.getFontInstance(fontkeys[0], fobj.getCommonFont().fontSize.getValue(this));
121
        lineHeight = fobj.getLineHeight();
119
        lineHeight = fobj.getLineHeight();
122
        borderProps = fobj.getCommonBorderPaddingBackground();
120
        borderProps = fobj.getCommonBorderPaddingBackground();
123
        inlineProps = fobj.getCommonMarginInline();
121
        inlineProps = fobj.getCommonMarginInline();
(-)src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java (-3 / +1 lines)
Lines 27-33 Link Here
27
import org.apache.fop.fo.flow.Leader;
27
import org.apache.fop.fo.flow.Leader;
28
import org.apache.fop.fonts.Font;
28
import org.apache.fop.fonts.Font;
29
import org.apache.fop.fonts.FontInfo;
29
import org.apache.fop.fonts.FontInfo;
30
import org.apache.fop.fonts.FontTriplet;
31
import org.apache.fop.layoutmgr.InlineKnuthSequence;
30
import org.apache.fop.layoutmgr.InlineKnuthSequence;
32
import org.apache.fop.layoutmgr.KnuthElement;
31
import org.apache.fop.layoutmgr.KnuthElement;
33
import org.apache.fop.layoutmgr.KnuthGlue;
32
import org.apache.fop.layoutmgr.KnuthGlue;
Lines 70-77 Link Here
70
    /** {@inheritDoc} */
69
    /** {@inheritDoc} */
71
    public void initialize() {
70
    public void initialize() {
72
        FontInfo fi = fobj.getFOEventHandler().getFontInfo();
71
        FontInfo fi = fobj.getFOEventHandler().getFontInfo();
73
        FontTriplet[] fontkeys = fobj.getCommonFont().getFontState(fi);
72
        font = fobj.getCommonFont().getFontInstance(fi, this);
74
        font = fi.getFontInstance(fontkeys[0], fobj.getCommonFont().fontSize.getValue(this));
75
        // the property leader-alignment does not affect vertical positioning
73
        // the property leader-alignment does not affect vertical positioning
76
        // (see section 7.21.1 in the XSL Recommendation)
74
        // (see section 7.21.1 in the XSL Recommendation)
77
        // setAlignment(node.getLeaderAlignment());
75
        // setAlignment(node.getLeaderAlignment());
(-)src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java (-3 / +1 lines)
Lines 39-45 Link Here
39
import org.apache.fop.fo.properties.CommonHyphenation;
39
import org.apache.fop.fo.properties.CommonHyphenation;
40
import org.apache.fop.fonts.Font;
40
import org.apache.fop.fonts.Font;
41
import org.apache.fop.fonts.FontInfo;
41
import org.apache.fop.fonts.FontInfo;
42
import org.apache.fop.fonts.FontTriplet;
43
import org.apache.fop.hyphenation.Hyphenation;
42
import org.apache.fop.hyphenation.Hyphenation;
44
import org.apache.fop.hyphenation.Hyphenator;
43
import org.apache.fop.hyphenation.Hyphenator;
45
import org.apache.fop.layoutmgr.BlockLevelLayoutManager;
44
import org.apache.fop.layoutmgr.BlockLevelLayoutManager;
Lines 575-582 Link Here
575
    /** {@inheritDoc} */
574
    /** {@inheritDoc} */
576
    public LinkedList getNextKnuthElements(LayoutContext context, int alignment) {
575
    public LinkedList getNextKnuthElements(LayoutContext context, int alignment) {
577
        FontInfo fi = fobj.getFOEventHandler().getFontInfo();
576
        FontInfo fi = fobj.getFOEventHandler().getFontInfo();
578
        FontTriplet[] fontkeys = fobj.getCommonFont().getFontState(fi);
577
        Font fs = fobj.getCommonFont().getFontInstance(fi, this);
579
        Font fs = fi.getFontInstance(fontkeys[0], fobj.getCommonFont().fontSize.getValue(this));
580
        alignmentContext
578
        alignmentContext
581
          = new AlignmentContext(fs, lineHeight.getValue(this), context.getWritingMode());
579
          = new AlignmentContext(fs, lineHeight.getValue(this), context.getWritingMode());
582
        context.setAlignmentContext(alignmentContext);
580
        context.setAlignmentContext(alignmentContext);
(-)src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java (-3 / +1 lines)
Lines 25-31 Link Here
25
import org.apache.fop.area.Trait;
25
import org.apache.fop.area.Trait;
26
import org.apache.fop.fonts.Font;
26
import org.apache.fop.fonts.Font;
27
import org.apache.fop.fonts.FontInfo;
27
import org.apache.fop.fonts.FontInfo;
28
import org.apache.fop.fonts.FontTriplet;
29
import org.apache.fop.layoutmgr.LayoutContext;
28
import org.apache.fop.layoutmgr.LayoutContext;
30
import org.apache.fop.layoutmgr.TraitSetter;
29
import org.apache.fop.layoutmgr.TraitSetter;
31
import org.apache.fop.traits.MinOptMax;
30
import org.apache.fop.traits.MinOptMax;
Lines 52-59 Link Here
52
    /** {@inheritDoc} */
51
    /** {@inheritDoc} */
53
    public void initialize() {
52
    public void initialize() {
54
        FontInfo fi = fobj.getFOEventHandler().getFontInfo();
53
        FontInfo fi = fobj.getFOEventHandler().getFontInfo();
55
        FontTriplet[] fontkeys = fobj.getCommonFont().getFontState(fi);
54
        font = fobj.getCommonFont().getFontInstance(fi, this);
56
        font = fi.getFontInstance(fontkeys[0], fobj.getCommonFont().fontSize.getValue(this));
57
        setCommonBorderPaddingBackground(fobj.getCommonBorderPaddingBackground());
55
        setCommonBorderPaddingBackground(fobj.getCommonBorderPaddingBackground());
58
    }
56
    }
59
57
(-)src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java (-3 / +1 lines)
Lines 32-38 Link Here
32
import org.apache.fop.fo.FOText;
32
import org.apache.fop.fo.FOText;
33
import org.apache.fop.fonts.Font;
33
import org.apache.fop.fonts.Font;
34
import org.apache.fop.fonts.FontInfo;
34
import org.apache.fop.fonts.FontInfo;
35
import org.apache.fop.fonts.FontTriplet;
36
import org.apache.fop.layoutmgr.InlineKnuthSequence;
35
import org.apache.fop.layoutmgr.InlineKnuthSequence;
37
import org.apache.fop.layoutmgr.KnuthBox;
36
import org.apache.fop.layoutmgr.KnuthBox;
38
import org.apache.fop.layoutmgr.KnuthElement;
37
import org.apache.fop.layoutmgr.KnuthElement;
Lines 189-196 Link Here
189
    /** {@inheritDoc} */
188
    /** {@inheritDoc} */
190
    public void initialize() {
189
    public void initialize() {
191
        FontInfo fi = foText.getFOEventHandler().getFontInfo();
190
        FontInfo fi = foText.getFOEventHandler().getFontInfo();
192
        FontTriplet[] fontkeys = foText.getCommonFont().getFontState(fi);
191
        font = foText.getCommonFont().getFontInstance(fi, this);
193
        font = fi.getFontInstance(fontkeys[0], foText.getCommonFont().fontSize.getValue(this));
194
        
192
        
195
        // With CID fonts, space isn't neccesary currentFontState.width(32)
193
        // With CID fonts, space isn't neccesary currentFontState.width(32)
196
        spaceCharIPD = font.getCharWidth(' ');
194
        spaceCharIPD = font.getCharWidth(' ');
(-)src/java/org/apache/fop/layoutmgr/TraitSetter.java (+1 lines)
Lines 548-553 Link Here
548
    public static void addFontTraits(Area area, Font font) {
548
    public static void addFontTraits(Area area, Font font) {
549
        area.addTrait(Trait.FONT, font.getFontTriplet());
549
        area.addTrait(Trait.FONT, font.getFontTriplet());
550
        area.addTrait(Trait.FONT_SIZE, new Integer(font.getFontSize()));
550
        area.addTrait(Trait.FONT_SIZE, new Integer(font.getFontSize()));
551
        area.addTrait(Trait.FONT_STRETCH, new Float(font.getFontStretch()));
551
    }
552
    }
552
    
553
    
553
    /**
554
    /**
(-)src/java/org/apache/fop/render/pdf/PDFRenderer.java (-2 / +15 lines)
Lines 254-259 Link Here
254
    protected String currentFontName = "";
254
    protected String currentFontName = "";
255
    /** Size of currently selected font */
255
    /** Size of currently selected font */
256
    protected int currentFontSize = 0;
256
    protected int currentFontSize = 0;
257
    /** Stretching of currently selected font */
258
    protected float currentFontStretch = 0f;
257
    /** page height */
259
    /** page height */
258
    protected int pageHeight;
260
    protected int pageHeight;
259
261
Lines 528-533 Link Here
528
        currentPage = null;
530
        currentPage = null;
529
        currentState = null;
531
        currentState = null;
530
        currentFontName = "";
532
        currentFontName = "";
533
        currentFontStretch = 0f;
531
534
532
        idPositions.clear();
535
        idPositions.clear();
533
        idGoTos.clear();
536
        idGoTos.clear();
Lines 668-673 Link Here
668
        if (!inTextMode) {
671
        if (!inTextMode) {
669
            currentStream.add("BT\n");
672
            currentStream.add("BT\n");
670
            currentFontName = "";
673
            currentFontName = "";
674
            currentFontStretch = 0f;
671
            inTextMode = true;
675
            inTextMode = true;
672
        }
676
        }
673
    }
677
    }
Lines 797-802 Link Here
797
        
801
        
798
        
802
        
799
        currentFontName = "";
803
        currentFontName = "";
804
        currentFontStretch = 0f;
800
805
801
        super.renderPage(page);
806
        super.renderPage(page);
802
807
Lines 848-853 Link Here
848
     */
853
     */
849
    protected void handleRegionTraits(RegionViewport region) {
854
    protected void handleRegionTraits(RegionViewport region) {
850
        currentFontName = "";
855
        currentFontName = "";
856
        currentFontStretch = 0f;
851
        super.handleRegionTraits(region);
857
        super.handleRegionTraits(region);
852
    }
858
    }
853
859
Lines 1433-1444 Link Here
1433
1439
1434
        String fontName = getInternalFontNameForArea(text);
1440
        String fontName = getInternalFontNameForArea(text);
1435
        int size = ((Integer) text.getTrait(Trait.FONT_SIZE)).intValue();
1441
        int size = ((Integer) text.getTrait(Trait.FONT_SIZE)).intValue();
1442
        float stretch = ((Float) text.getTrait(Trait.FONT_STRETCH)).floatValue();
1436
        
1443
        
1437
        // This assumes that *all* CIDFonts use a /ToUnicode mapping
1444
        // This assumes that *all* CIDFonts use a /ToUnicode mapping
1438
        Typeface tf = (Typeface) fontInfo.getFonts().get(fontName);
1445
        Typeface tf = (Typeface) fontInfo.getFonts().get(fontName);
1439
        boolean useMultiByte = tf.isMultiByte();
1446
        boolean useMultiByte = tf.isMultiByte();
1440
        
1447
        
1441
        updateFont(fontName, size, pdf);
1448
        updateFont(fontName, size, stretch, pdf);
1442
        Color ct = (Color) text.getTrait(Trait.COLOR);
1449
        Color ct = (Color) text.getTrait(Trait.COLOR);
1443
        updateColor(ct, true, pdf);
1450
        updateColor(ct, true, pdf);
1444
1451
Lines 1660-1666 Link Here
1660
        updateColor(col, fill, null);
1667
        updateColor(col, fill, null);
1661
    }
1668
    }
1662
    
1669
    
1663
    private void updateFont(String name, int size, StringBuffer pdf) {
1670
    private void updateFont(String name, int size, float stretch, StringBuffer pdf) {
1664
        if ((!name.equals(this.currentFontName))
1671
        if ((!name.equals(this.currentFontName))
1665
                || (size != this.currentFontSize)) {
1672
                || (size != this.currentFontSize)) {
1666
            closeText();
1673
            closeText();
Lines 1670-1675 Link Here
1670
            pdf = pdf.append("/" + name + " " + format((float) size / 1000f)
1677
            pdf = pdf.append("/" + name + " " + format((float) size / 1000f)
1671
                              + " Tf\n");
1678
                              + " Tf\n");
1672
        }
1679
        }
1680
        if (stretch != this.currentFontStretch) {
1681
        	this.currentFontStretch = stretch;
1682
        	pdf = pdf.append(format(stretch * 100) + " Tz\n");
1683
        }
1673
    }
1684
    }
1674
1685
1675
    /** {@inheritDoc} */
1686
    /** {@inheritDoc} */
Lines 1805-1810 Link Here
1805
        context.setProperty(PDFRendererContextConstants.PDF_FONT_NAME, currentFontName);
1816
        context.setProperty(PDFRendererContextConstants.PDF_FONT_NAME, currentFontName);
1806
        context.setProperty(PDFRendererContextConstants.PDF_FONT_SIZE,
1817
        context.setProperty(PDFRendererContextConstants.PDF_FONT_SIZE,
1807
                            new Integer(currentFontSize));
1818
                            new Integer(currentFontSize));
1819
        context.setProperty(PDFRendererContextConstants.PDF_FONT_STRETCH,
1820
                            new Float(currentFontStretch));
1808
        return context;
1821
        return context;
1809
    }
1822
    }
1810
1823
(-)src/java/org/apache/fop/render/pdf/PDFRendererContextConstants.java (+3 lines)
Lines 49-53 Link Here
49
49
50
    /** The current pdf font size. */
50
    /** The current pdf font size. */
51
    String PDF_FONT_SIZE = "fontSize";
51
    String PDF_FONT_SIZE = "fontSize";
52
53
    /** The current pdf font stretch. */
54
    String PDF_FONT_STRETCH = "fontStretch";
52
    
55
    
53
}
56
}
(-)src/java/org/apache/fop/render/PrintRenderer.java (-1 / +2 lines)
Lines 95-101 Link Here
95
    protected Font getFontFromArea(Area area) {
95
    protected Font getFontFromArea(Area area) {
96
        FontTriplet triplet = (FontTriplet)area.getTrait(Trait.FONT);
96
        FontTriplet triplet = (FontTriplet)area.getTrait(Trait.FONT);
97
        int size = ((Integer)area.getTrait(Trait.FONT_SIZE)).intValue();
97
        int size = ((Integer)area.getTrait(Trait.FONT_SIZE)).intValue();
98
        return fontInfo.getFontInstance(triplet, size);
98
        float stretch = ((Float)area.getTrait(Trait.FONT_STRETCH)).floatValue();
99
        return fontInfo.getFontInstance(triplet, size, stretch);
99
    }
100
    }
100
    
101
    
101
    /**
102
    /**
(-)src/java/org/apache/fop/render/ps/NativeTextHandler.java (-1 / +9 lines)
Lines 20-25 Link Here
20
package org.apache.fop.render.ps;
20
package org.apache.fop.render.ps;
21
21
22
import java.awt.Shape;
22
import java.awt.Shape;
23
import java.awt.font.TextAttribute;
23
import java.awt.geom.AffineTransform;
24
import java.awt.geom.AffineTransform;
24
import java.io.IOException;
25
import java.io.IOException;
25
26
Lines 155-160 Link Here
155
            fontFamily = "sans-serif";
156
            fontFamily = "sans-serif";
156
        }
157
        }
157
        int fontSize = 1000 * f.getSize();
158
        int fontSize = 1000 * f.getSize();
159
        Float width = (Float) f.getAttributes().get(TextAttribute.WIDTH);
160
        float fontStretch;
161
        if (width != null) {
162
        	fontStretch = width.floatValue(); 
163
        } else {
164
        	fontStretch = 1f;
165
        }
158
        String style = f.isItalic() ? "italic" : "normal";
166
        String style = f.isItalic() ? "italic" : "normal";
159
        int weight = f.isBold() ? Font.WEIGHT_BOLD : Font.WEIGHT_NORMAL;
167
        int weight = f.isBold() ? Font.WEIGHT_BOLD : Font.WEIGHT_NORMAL;
160
                
168
                
Lines 162-168 Link Here
162
        if (triplet == null) {
170
        if (triplet == null) {
163
            triplet = fontInfo.findAdjustWeight("sans-serif", style, weight);
171
            triplet = fontInfo.findAdjustWeight("sans-serif", style, weight);
164
        }
172
        }
165
        return fontInfo.getFontInstance(triplet, fontSize);
173
        return fontInfo.getFontInstance(triplet, fontSize, fontStretch);
166
    }
174
    }
167
175
168
    private void establishCurrentFont() throws IOException {
176
    private void establishCurrentFont() throws IOException {
(-)src/java/org/apache/fop/render/ps/PSTextPainter.java (-2 / +8 lines)
Lines 382-387 Link Here
382
        if (fontSize == null) {
382
        if (fontSize == null) {
383
            fontSize = new Float(10.0f);
383
            fontSize = new Float(10.0f);
384
        }
384
        }
385
        Float fontStretch = (Float)aci.getAttribute(TextAttribute.WIDTH);
386
        if (fontStretch == null) {
387
        	fontStretch = new Float(1.0f);
388
        }
385
        String style = getStyle(aci);
389
        String style = getStyle(aci);
386
        int weight = getWeight(aci);
390
        int weight = getWeight(aci);
387
391
Lines 402-414 Link Here
402
                    FontTriplet triplet = fontInfo.fontLookup(
406
                    FontTriplet triplet = fontInfo.fontLookup(
403
                            fontFamily, style, weight);
407
                            fontFamily, style, weight);
404
                    int fsize = (int)(fontSize.floatValue() * 1000);
408
                    int fsize = (int)(fontSize.floatValue() * 1000);
405
                    return fontInfo.getFontInstance(triplet, fsize);
409
                    float fstretch = fontStretch.floatValue();
410
                    return fontInfo.getFontInstance(triplet, fsize, fstretch);
406
                }
411
                }
407
            }
412
            }
408
        }
413
        }
409
        FontTriplet triplet = fontInfo.fontLookup("any", style, Font.WEIGHT_NORMAL);
414
        FontTriplet triplet = fontInfo.fontLookup("any", style, Font.WEIGHT_NORMAL);
410
        int fsize = (int)(fontSize.floatValue() * 1000);
415
        int fsize = (int)(fontSize.floatValue() * 1000);
411
        return fontInfo.getFontInstance(triplet, fsize);
416
        float fstretch = fontStretch.floatValue();
417
        return fontInfo.getFontInstance(triplet, fsize, fstretch);
412
    }
418
    }
413
419
414
    private java.awt.Font makeAWTFont(AttributedCharacterIterator aci, Font font) {
420
    private java.awt.Font makeAWTFont(AttributedCharacterIterator aci, Font font) {
(-)src/java/org/apache/fop/svg/PDFGraphics2D.java (-2 / +10 lines)
Lines 34-39 Link Here
34
import java.awt.Shape;
34
import java.awt.Shape;
35
import java.awt.Stroke;
35
import java.awt.Stroke;
36
import java.awt.color.ColorSpace;
36
import java.awt.color.ColorSpace;
37
import java.awt.font.TextAttribute;
37
import java.awt.geom.AffineTransform;
38
import java.awt.geom.AffineTransform;
38
import java.awt.geom.PathIterator;
39
import java.awt.geom.PathIterator;
39
import java.awt.geom.Point2D;
40
import java.awt.geom.Point2D;
Lines 1323-1329 Link Here
1323
            fontState = getInternalFontForAWTFont(gFont);
1324
            fontState = getInternalFontForAWTFont(gFont);
1324
        } else {
1325
        } else {
1325
            fontState = fontInfo.getFontInstance(
1326
            fontState = fontInfo.getFontInstance(
1326
                    ovFontState.getFontTriplet(), ovFontState.getFontSize());
1327
                    ovFontState.getFontTriplet(), ovFontState.getFontSize(), ovFontState.getFontStretch());
1327
            ovFontState = null;
1328
            ovFontState = null;
1328
        }
1329
        }
1329
        updateCurrentFont(fontState);
1330
        updateCurrentFont(fontState);
Lines 1457-1466 Link Here
1457
            n = "sans-serif";
1458
            n = "sans-serif";
1458
        }
1459
        }
1459
        float siz = awtFont.getSize2D();
1460
        float siz = awtFont.getSize2D();
1461
        Float width = (Float) awtFont.getAttributes().get(TextAttribute.WIDTH);
1462
        float stretch;
1463
        if (width != null) {
1464
        	stretch = width.floatValue(); 
1465
        } else {
1466
        	stretch = 1f;
1467
        }
1460
        String style = awtFont.isItalic() ? "italic" : "normal";
1468
        String style = awtFont.isItalic() ? "italic" : "normal";
1461
        int weight = awtFont.isBold() ? Font.WEIGHT_BOLD : Font.WEIGHT_NORMAL;
1469
        int weight = awtFont.isBold() ? Font.WEIGHT_BOLD : Font.WEIGHT_NORMAL;
1462
        FontTriplet triplet = fontInfo.fontLookup(n, style, weight);
1470
        FontTriplet triplet = fontInfo.fontLookup(n, style, weight);
1463
        fontState = fontInfo.getFontInstance(triplet, (int)(siz * 1000 + 0.5));
1471
        fontState = fontInfo.getFontInstance(triplet, (int)(siz * 1000 + 0.5), stretch);
1464
        return fontState;
1472
        return fontState;
1465
    }
1473
    }
1466
1474
(-)src/java/org/apache/fop/svg/PDFTextPainter.java (-3 / +7 lines)
Lines 271-276 Link Here
271
        Float posture = (Float) aci.getAttribute(TextAttribute.POSTURE);
271
        Float posture = (Float) aci.getAttribute(TextAttribute.POSTURE);
272
        Float taWeight = (Float) aci.getAttribute(TextAttribute.WEIGHT);
272
        Float taWeight = (Float) aci.getAttribute(TextAttribute.WEIGHT);
273
        Float fontSize = (Float) aci.getAttribute(TextAttribute.SIZE);
273
        Float fontSize = (Float) aci.getAttribute(TextAttribute.SIZE);
274
        Float fontStretch = (Float) aci.getAttribute(TextAttribute.WIDTH);
274
275
275
        String style = ((posture != null) && (posture.floatValue() > 0.0))
276
        String style = ((posture != null) && (posture.floatValue() > 0.0))
276
                       ? "italic" : "normal";
277
                       ? "italic" : "normal";
Lines 298-304 Link Here
298
                    FontTriplet triplet = fontInfo.fontLookup(gvtFontFamily, style,
299
                    FontTriplet triplet = fontInfo.fontLookup(gvtFontFamily, style,
299
                                                       weight);
300
                                                       weight);
300
                    int fsize = (int)(fontSize.floatValue() * 1000);
301
                    int fsize = (int)(fontSize.floatValue() * 1000);
301
                    fonts.add(fontInfo.getFontInstance(triplet, fsize));
302
                    float fstretch = fontStretch.floatValue();
303
                    fonts.add(fontInfo.getFontInstance(triplet, fsize, fstretch));
302
                }
304
                }
303
            } catch (Exception e) {
305
            } catch (Exception e) {
304
                //Most likely NoSuchMethodError here when using Batik 1.6
306
                //Most likely NoSuchMethodError here when using Batik 1.6
Lines 321-334 Link Here
321
                    FontTriplet triplet = fontInfo.fontLookup(fontFamily, style,
323
                    FontTriplet triplet = fontInfo.fontLookup(fontFamily, style,
322
                                                       weight);
324
                                                       weight);
323
                    int fsize = (int)(fontSize.floatValue() * 1000);
325
                    int fsize = (int)(fontSize.floatValue() * 1000);
324
                    fonts.add(fontInfo.getFontInstance(triplet, fsize));
326
                    float fstretch = fontStretch.floatValue();
327
                    fonts.add(fontInfo.getFontInstance(triplet, fsize, fstretch));
325
                }
328
                }
326
            }
329
            }
327
        }
330
        }
328
        if (fonts.size() == 0) {
331
        if (fonts.size() == 0) {
329
            FontTriplet triplet = fontInfo.fontLookup("any", style, Font.WEIGHT_NORMAL);
332
            FontTriplet triplet = fontInfo.fontLookup("any", style, Font.WEIGHT_NORMAL);
330
            int fsize = (int)(fontSize.floatValue() * 1000);
333
            int fsize = (int)(fontSize.floatValue() * 1000);
331
            fonts.add(fontInfo.getFontInstance(triplet, fsize));
334
            float fstretch = fontStretch.floatValue();
335
            fonts.add(fontInfo.getFontInstance(triplet, fsize, fstretch));
332
            if (DEBUG) {
336
            if (DEBUG) {
333
                System.out.print("fallback to 'any' font");
337
                System.out.print("fallback to 'any' font");
334
            }
338
            }

Return to bug 42577