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

(-)src/codegen/fonts/font-file.xsl (-2 / +2 lines)
Lines 116-123 Link Here
116
        return lastChar;
116
        return lastChar;
117
    }
117
    }
118
118
119
    public int getWidth(int i,int size) {
119
    public int getWidth(int i, int size, float stretch) {
120
        return size * width[i];
120
        return size * width[i] * stretch;
121
    }
121
    }
122
122
123
    public int[] getWidths() {
123
    public int[] getWidths() {
(-)src/java/org/apache/fop/area/Trait.java (-1 / +2 lines)
Lines 23-28 Link Here
23
import java.io.Serializable;
23
import java.io.Serializable;
24
24
25
import org.apache.fop.fo.Constants;
25
import org.apache.fop.fo.Constants;
26
import org.apache.fop.fonts.FontSize;
26
import org.apache.fop.fonts.FontTriplet;
27
import org.apache.fop.fonts.FontTriplet;
27
import org.apache.fop.image.FopImage;
28
import org.apache.fop.image.FopImage;
28
import org.apache.fop.traits.BorderProps;
29
import org.apache.fop.traits.BorderProps;
Lines 227-233 Link Here
227
        put(INTERNAL_LINK, new TraitInfo("internal-link", InternalLink.class));
228
        put(INTERNAL_LINK, new TraitInfo("internal-link", InternalLink.class));
228
        put(EXTERNAL_LINK, new TraitInfo("external-link", String.class));
229
        put(EXTERNAL_LINK, new TraitInfo("external-link", String.class));
229
        put(FONT,         new TraitInfo("font", FontTriplet.class));
230
        put(FONT,         new TraitInfo("font", FontTriplet.class));
230
        put(FONT_SIZE,    new TraitInfo("font-size", Integer.class));
231
        put(FONT_SIZE,    new TraitInfo("font-size", FontSize.class));
231
        put(COLOR, new TraitInfo("color", Color.class));
232
        put(COLOR, new TraitInfo("color", Color.class));
232
        put(PROD_ID, new TraitInfo("prod-id", String.class));
233
        put(PROD_ID, new TraitInfo("prod-id", String.class));
233
        put(BACKGROUND,   new TraitInfo("background", Background.class));
234
        put(BACKGROUND,   new TraitInfo("background", Background.class));
(-)src/java/org/apache/fop/fo/properties/CommonFont.java (-1 / +33 lines)
Lines 165-176 Link Here
165
            default:
165
            default:
166
                style = "normal";
166
                style = "normal";
167
            }
167
            }
168
            
169
            float stretch = 1;
170
            switch (fontStretch) {
171
            case Constants.EN_ULTRA_CONDENSED:
172
            	stretch = 0.5f;
173
            	break;
174
            case Constants.EN_EXTRA_CONDENSED:
175
            	stretch = 0.6f;
176
            	break;
177
            case Constants.EN_CONDENSED:
178
            	stretch = 0.7f;
179
            	break;
180
            case Constants.EN_SEMI_CONDENSED:
181
            	stretch = 0.8f;
182
            	break;
183
            case Constants.EN_NORMAL:
184
            	stretch = 1.0f;
185
            	break;
186
            case Constants.EN_SEMI_EXPANDED:
187
            	stretch = 1.2f;
188
            	break;
189
            case Constants.EN_EXPANDED:
190
            	stretch = 1.4f;
191
            	break;
192
            case Constants.EN_EXTRA_EXPANDED:
193
            	stretch = 1.7f;
194
            	break;
195
            case Constants.EN_ULTRA_EXPANDED:
196
            	stretch = 2.0f;
197
            	break;
198
            }
199
            
168
            // NOTE: this is incomplete. font-size may be specified with
200
            // NOTE: this is incomplete. font-size may be specified with
169
            // various kinds of keywords too
201
            // various kinds of keywords too
170
            //int fontVariant = propertyList.get("font-variant").getEnum();
202
            //int fontVariant = propertyList.get("font-variant").getEnum();
171
            FontTriplet triplet = fontInfo.fontLookup(getFontFamily(), style,
203
            FontTriplet triplet = fontInfo.fontLookup(getFontFamily(), style,
172
                                               font_weight);
204
                                               font_weight);
173
            fontState = fontInfo.getFontInstance(triplet, fontSize.getValue(context));
205
            fontState = fontInfo.getFontInstance(triplet, fontSize.getValue(context), stretch);
174
        }
206
        }
175
        return fontState;
207
        return fontState;
176
    }
208
    }
(-)src/java/org/apache/fop/fonts/Font.java (-10 / +10 lines)
Lines 46-52 Link Here
46
46
47
    private String fontName;
47
    private String fontName;
48
    private FontTriplet triplet;
48
    private FontTriplet triplet;
49
    private int fontSize;
49
    private FontSize fontSize;
50
50
51
    /**
51
    /**
52
     * normal or small-caps font
52
     * normal or small-caps font
Lines 62-68 Link Here
62
     * @param met font metrics
62
     * @param met font metrics
63
     * @param fontSize font size
63
     * @param fontSize font size
64
     */
64
     */
65
    public Font(String key, FontTriplet triplet, FontMetrics met, int fontSize) {
65
    public Font(String key, FontTriplet triplet, FontMetrics met, FontSize fontSize) {
66
        this.fontName = key;
66
        this.fontName = key;
67
        this.triplet = triplet;
67
        this.triplet = triplet;
68
        this.metric = met;
68
        this.metric = met;
Lines 74-80 Link Here
74
     * @return the ascender
74
     * @return the ascender
75
     */
75
     */
76
    public int getAscender() {
76
    public int getAscender() {
77
        return metric.getAscender(fontSize) / 1000;
77
        return metric.getAscender(fontSize.getSize()) / 1000;
78
    }
78
    }
79
79
80
    /**
80
    /**
Lines 82-88 Link Here
82
     * @return the capital height
82
     * @return the capital height
83
     */
83
     */
84
    public int getCapHeight() {
84
    public int getCapHeight() {
85
        return metric.getCapHeight(fontSize) / 1000;
85
        return metric.getCapHeight(fontSize.getSize()) / 1000;
86
    }
86
    }
87
87
88
    /**
88
    /**
Lines 90-96 Link Here
90
     * @return the descender
90
     * @return the descender
91
     */
91
     */
92
    public int getDescender() {
92
    public int getDescender() {
93
        return metric.getDescender(fontSize) / 1000;
93
        return metric.getDescender(fontSize.getSize()) / 1000;
94
    }
94
    }
95
95
96
    /**
96
    /**
Lines 110-116 Link Here
110
     * Returns the font size
110
     * Returns the font size
111
     * @return the font size
111
     * @return the font size
112
     */
112
     */
113
    public int getFontSize() {
113
    public FontSize getFontSize() {
114
        return fontSize;
114
        return fontSize;
115
    }
115
    }
116
116
Lines 119-125 Link Here
119
     * @return the XHeight
119
     * @return the XHeight
120
     */
120
     */
121
    public int getXHeight() {
121
    public int getXHeight() {
122
        return metric.getXHeight(fontSize) / 1000;
122
        return metric.getXHeight(fontSize.getSize()) / 1000;
123
    }
123
    }
124
124
125
    /** @return true if the font has kerning info */
125
    /** @return true if the font has kerning info */
Lines 163-169 Link Here
163
     */
163
     */
164
    public int getWidth(int charnum) {
164
    public int getWidth(int charnum) {
165
        // returns width of given character number in millipoints
165
        // returns width of given character number in millipoints
166
        return (metric.getWidth(charnum, fontSize) / 1000);
166
        return (metric.getWidth(charnum, fontSize.getSize(), fontSize.getStretch()) / 1000);
167
    }
167
    }
168
168
169
    /**
169
    /**
Lines 246-252 Link Here
246
            if (width <= 0) {
246
            if (width <= 0) {
247
                // Estimate the width of spaces not represented in
247
                // Estimate the width of spaces not represented in
248
                // the font
248
                // the font
249
                int em = getFontSize(); //http://en.wikipedia.org/wiki/Em_(typography)
249
                int em = getFontSize().getSize(); //http://en.wikipedia.org/wiki/Em_(typography)
250
                int en = em / 2; //http://en.wikipedia.org/wiki/En_(typography)
250
                int en = em / 2; //http://en.wikipedia.org/wiki/En_(typography)
251
251
252
                if (c == ' ') {
252
                if (c == ' ') {
Lines 258-264 Link Here
258
                } else if (c == '\u2002') {
258
                } else if (c == '\u2002') {
259
                    width = em / 2;
259
                    width = em / 2;
260
                } else if (c == '\u2003') {
260
                } else if (c == '\u2003') {
261
                    width = getFontSize();
261
                    width = getFontSize().getSize();
262
                } else if (c == '\u2004') {
262
                } else if (c == '\u2004') {
263
                    width = em / 3;
263
                    width = em / 3;
264
                } else if (c == '\u2005') {
264
                } else if (c == '\u2005') {
(-)src/java/org/apache/fop/fonts/FontInfo.java (-3 / +22 lines)
Lines 197-215 Link Here
197
     * @return the requested Font instance
197
     * @return the requested Font instance
198
     */
198
     */
199
    public Font getFontInstance(FontTriplet triplet, int fontSize) {
199
    public Font getFontInstance(FontTriplet triplet, int fontSize) {
200
    	return getFontInstance(triplet, fontSize, 0);
201
    }
202
    
203
    /**
204
     * Retrieves a (possibly cached) Font instance based on a FontTriplet and a font size. 
205
     * @param triplet the font triplet designating the requested font
206
     * @param fontSize the font size
207
     * @return the requested Font instance
208
     */
209
    public Font getFontInstance(FontTriplet triplet, int fontSize, float fontStretch) {
210
    	return getFontInstance(triplet, new FontSize(fontSize, fontStretch));
211
    }
212
    
213
    /**
214
     * Retrieves a (possibly cached) Font instance based on a FontTriplet and a font size. 
215
     * @param triplet the font triplet designating the requested font
216
     * @param fontSize the font size
217
     * @return the requested Font instance
218
     */
219
    public Font getFontInstance(FontTriplet triplet, FontSize fontSize) {
200
        Map sizes = (Map)fontInstanceCache.get(triplet);
220
        Map sizes = (Map)fontInstanceCache.get(triplet);
201
        if (sizes == null) {
221
        if (sizes == null) {
202
            sizes = new java.util.HashMap();
222
            sizes = new java.util.HashMap();
203
            fontInstanceCache.put(triplet, sizes);
223
            fontInstanceCache.put(triplet, sizes);
204
        }
224
        }
205
        Integer size = new Integer(fontSize);
225
        Font font = (Font)sizes.get(fontSize);
206
        Font font = (Font)sizes.get(size);
207
        if (font == null) {
226
        if (font == null) {
208
            String fname = getInternalFontKey(triplet);
227
            String fname = getInternalFontKey(triplet);
209
            useFont(fname);
228
            useFont(fname);
210
            FontMetrics metrics = getMetricsFor(fname);
229
            FontMetrics metrics = getMetricsFor(fname);
211
            font = new Font(fname, triplet, metrics, fontSize);
230
            font = new Font(fname, triplet, metrics, fontSize);
212
            sizes.put(size, font);
231
            sizes.put(fontSize, font);
213
        }
232
        }
214
        return font;
233
        return font;
215
    }
234
    }
(-)src/java/org/apache/fop/fonts/FontMetrics.java (-1 / +2 lines)
Lines 87-95 Link Here
87
     * code point i.
87
     * code point i.
88
     * @param i code point index
88
     * @param i code point index
89
     * @param size font size
89
     * @param size font size
90
     * @param float horizontal scaling
90
     * @return the width of the character
91
     * @return the width of the character
91
     */
92
     */
92
    int getWidth(int i, int size);
93
    int getWidth(int i, int size, float stretch);
93
94
94
    /**
95
    /**
95
     * Return the array of widths.
96
     * Return the array of widths.
(-)src/java/org/apache/fop/fonts/FontSize.java (+64 lines)
Line 0 Link Here
1
package org.apache.fop.fonts;
2
3
/**
4
 * FontSize contains the size (in points) and the horizontal stretch factor of a font
5
 */
6
public class FontSize {
7
	
8
	private int size;
9
	private float stretch;
10
	
11
	/**
12
	 * Creates a font size
13
	 * @param size
14
	 * @param stretch
15
	 */
16
	public FontSize(int size, float stretch) {
17
		this.size = size;
18
		this.stretch = stretch;
19
	}
20
	
21
	/**
22
	 * @return the font size
23
	 */
24
	public int getSize() {
25
		return size;
26
	}
27
	
28
	/**
29
	 * @return the horizontal stretch
30
	 */
31
	public float getStretch() {
32
		return stretch;
33
	}
34
	
35
	/**
36
	 * Utility function: scales a horizontal length to the size of the font 
37
	 * @param i the length to scale
38
	 * @return i * size * stretch, cast to an int
39
	 */
40
	public int scale(int i) {
41
		return (int) (i * size * stretch);
42
	}
43
	
44
	/**
45
	 * @see java.lang.Object#equals(java.lang.Object)
46
	 */
47
	public boolean equals(Object that) {
48
		return that instanceof FontSize && equals((FontSize) that);
49
	}
50
	public boolean equals(FontSize that) {
51
		return this.size == that.size && this.stretch == that.stretch;
52
	}
53
	
54
	/**
55
	 * @see java.lang.Object#hashCode()
56
	 */
57
	public int hashCode() {
58
		int hashCode = 0;
59
		hashCode = 31 * hashCode + size;
60
		hashCode = 31 * hashCode + Float.floatToIntBits(stretch);
61
		return hashCode;
62
	}
63
64
}
(-)src/java/org/apache/fop/fonts/LazyFont.java (-2 / +2 lines)
Lines 233-241 Link Here
233
    /**
233
    /**
234
     * @see org.apache.fop.fonts.FontMetrics#getWidth(int, int)
234
     * @see org.apache.fop.fonts.FontMetrics#getWidth(int, int)
235
     */
235
     */
236
    public int getWidth(int i, int size) {
236
    public int getWidth(int i, int size, float stretch) {
237
        load(true);
237
        load(true);
238
        return realFont.getWidth(i, size);
238
        return realFont.getWidth(i, size, stretch);
239
    }
239
    }
240
240
241
    /**
241
    /**
(-)src/java/org/apache/fop/fonts/MultiByteFont.java (-4 / +3 lines)
Lines 152-164 Link Here
152
    /**
152
    /**
153
     * @see org.apache.fop.fonts.FontMetrics#getWidth(int, int)
153
     * @see org.apache.fop.fonts.FontMetrics#getWidth(int, int)
154
     */
154
     */
155
    public int getWidth(int i, int size) {
155
    public int getWidth(int i, int size, float stretch) {
156
        if (isEmbeddable()) {
156
        if (isEmbeddable()) {
157
            Integer idx = (Integer)usedGlyphsIndex.get(new Integer(i));
157
            Integer idx = (Integer)usedGlyphsIndex.get(new Integer(i));
158
            return size * width[idx.intValue()];
158
            i = idx.intValue();
159
        } else {
160
            return size * width[i];
161
        }
159
        }
160
        return (int)(size * width[i] * stretch);
162
    }
161
    }
163
162
164
    /**
163
    /**
(-)src/java/org/apache/fop/fonts/SingleByteFont.java (-2 / +2 lines)
Lines 71-78 Link Here
71
    /**
71
    /**
72
     * @see org.apache.fop.fonts.FontMetrics#getWidth(int, int)
72
     * @see org.apache.fop.fonts.FontMetrics#getWidth(int, int)
73
     */
73
     */
74
    public int getWidth(int i, int size) {
74
    public int getWidth(int i, int size, float stretch) {
75
        return size * width[i];
75
        return (int)(size * width[i] * stretch);
76
    }
76
    }
77
77
78
    /**
78
    /**
(-)src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java (-1 / +1 lines)
Lines 112-118 Link Here
112
112
113
        // TODO: may need some special handling for fo:character
113
        // TODO: may need some special handling for fo:character
114
        alignmentContext = new AlignmentContext(font
114
        alignmentContext = new AlignmentContext(font
115
                                    , font.getFontSize()
115
                                    , font.getFontSize().getSize()
116
                                    , fobj.getAlignmentAdjust()
116
                                    , fobj.getAlignmentAdjust()
117
                                    , fobj.getAlignmentBaseline()
117
                                    , fobj.getAlignmentBaseline()
118
                                    , fobj.getBaselineShift()
118
                                    , fobj.getBaselineShift()
(-)src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java (-5 / +5 lines)
Lines 608-617 Link Here
608
                            int kern = 0;
608
                            int kern = 0;
609
                            if (i > iThisStart) {
609
                            if (i > iThisStart) {
610
                                char previous = textArray[i - 1];
610
                                char previous = textArray[i - 1];
611
                                kern = font.getKernValue(previous, c) * font.getFontSize() / 1000;
611
                                kern = font.getFontSize().scale(font.getKernValue(previous, c)) / 1000;
612
                            } else if (prevAi != null && !prevAi.isSpace && prevAi.iBreakIndex > 0) {
612
                            } else if (prevAi != null && !prevAi.isSpace && prevAi.iBreakIndex > 0) {
613
                                char previous = textArray[prevAi.iBreakIndex - 1];
613
                                char previous = textArray[prevAi.iBreakIndex - 1];
614
                                kern = font.getKernValue(previous, c) * font.getFontSize() / 1000;
614
                                kern = font.getFontSize().scale(font.getKernValue(previous, c)) / 1000;
615
                            }
615
                            }
616
                            if (kern != 0) {
616
                            if (kern != 0) {
617
                                //log.info("Kerning between " + previous + " and " + c + ": " + kern);
617
                                //log.info("Kerning between " + previous + " and " + c + ": " + kern);
Lines 621-627 Link Here
621
                        }
621
                        }
622
                    }
622
                    }
623
                    if (kerning && breakOpportunity && !isSpace(ch) && lastIndex > 0 && textArray[lastIndex] == CharUtilities.SOFT_HYPHEN) {
623
                    if (kerning && breakOpportunity && !isSpace(ch) && lastIndex > 0 && textArray[lastIndex] == CharUtilities.SOFT_HYPHEN) {
624
                        int kern = font.getKernValue(textArray[lastIndex - 1], ch) * font.getFontSize() / 1000;
624
                        int kern = font.getFontSize().scale(font.getKernValue(textArray[lastIndex - 1], ch)) / 1000;
625
                        if (kern != 0) {
625
                        if (kern != 0) {
626
                            addToLetterAdjust(lastIndex, kern);
626
                            addToLetterAdjust(lastIndex, kern);
627
                        }
627
                        }
Lines 733-742 Link Here
733
                    int kern = 0;
733
                    int kern = 0;
734
                    if (i > iThisStart) {
734
                    if (i > iThisStart) {
735
                        char previous = textArray[i - 1];
735
                        char previous = textArray[i - 1];
736
                        kern = font.getKernValue(previous, c) * font.getFontSize() / 1000;
736
                        kern = font.getFontSize().scale(font.getKernValue(previous, c)) / 1000;
737
                    } else if (prevAi != null && !prevAi.isSpace) {
737
                    } else if (prevAi != null && !prevAi.isSpace) {
738
                        char previous = textArray[prevAi.iBreakIndex - 1];
738
                        char previous = textArray[prevAi.iBreakIndex - 1];
739
                        kern = font.getKernValue(previous, c) * font.getFontSize() / 1000;
739
                        kern = font.getFontSize().scale(font.getKernValue(previous, c)) / 1000;
740
                    }
740
                    }
741
                    if (kern != 0) {
741
                    if (kern != 0) {
742
                        //log.info("Kerning between " + previous + " and " + c + ": " + kern);
742
                        //log.info("Kerning between " + previous + " and " + c + ": " + kern);
(-)src/java/org/apache/fop/layoutmgr/TraitSetter.java (-1 / +1 lines)
Lines 468-474 Link Here
468
     */
468
     */
469
    public static void addFontTraits(Area area, Font font) {
469
    public static void addFontTraits(Area area, Font font) {
470
        area.addTrait(Trait.FONT, font.getFontTriplet());
470
        area.addTrait(Trait.FONT, font.getFontTriplet());
471
        area.addTrait(Trait.FONT_SIZE, new Integer(font.getFontSize()));
471
        area.addTrait(Trait.FONT_SIZE, font.getFontSize());
472
    }
472
    }
473
    
473
    
474
    /**
474
    /**
(-)src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java (+1 lines)
Lines 36-41 Link Here
36
import org.apache.fop.area.inline.Viewport;
36
import org.apache.fop.area.inline.Viewport;
37
import org.apache.fop.fo.Constants;
37
import org.apache.fop.fo.Constants;
38
import org.apache.fop.fonts.FontMetrics;
38
import org.apache.fop.fonts.FontMetrics;
39
import org.apache.fop.fonts.FontSize;
39
import org.apache.fop.image.FopImage;
40
import org.apache.fop.image.FopImage;
40
import org.apache.fop.traits.BorderProps;
41
import org.apache.fop.traits.BorderProps;
41
import org.w3c.dom.Document;
42
import org.w3c.dom.Document;
(-)src/java/org/apache/fop/render/afp/AFPRenderer.java (-4 / +10 lines)
Lines 54-59 Link Here
54
import org.apache.fop.fo.extensions.ExtensionAttachment;
54
import org.apache.fop.fo.extensions.ExtensionAttachment;
55
import org.apache.fop.fonts.FontInfo;
55
import org.apache.fop.fonts.FontInfo;
56
import org.apache.fop.fonts.FontMetrics;
56
import org.apache.fop.fonts.FontMetrics;
57
import org.apache.fop.fonts.FontSize;
57
import org.apache.fop.fonts.FontTriplet;
58
import org.apache.fop.fonts.FontTriplet;
58
import org.apache.fop.fonts.base14.Courier;
59
import org.apache.fop.fonts.base14.Courier;
59
import org.apache.fop.fonts.base14.Helvetica;
60
import org.apache.fop.fonts.base14.Helvetica;
Lines 181-186 Link Here
181
    private int _currentFontSize = 0;
182
    private int _currentFontSize = 0;
182
183
183
    /**
184
    /**
185
     * The current font stretch
186
     */
187
    private float _currentFontStretch = 1;
188
189
    /**
184
     * The Options to be set on the AFPRenderer
190
     * The Options to be set on the AFPRenderer
185
     */
191
     */
186
    private Map _afpOptions = null;
192
    private Map _afpOptions = null;
Lines 1121-1132 Link Here
1121
        renderInlineAreaBackAndBorders(text);
1127
        renderInlineAreaBackAndBorders(text);
1122
1128
1123
        String name = getInternalFontNameForArea(text);
1129
        String name = getInternalFontNameForArea(text);
1124
        _currentFontSize = ((Integer) text.getTrait(Trait.FONT_SIZE)).intValue();
1130
        _currentFontSize = ((FontSize) text.getTrait(Trait.FONT_SIZE)).getSize();
1125
        AFPFont tf = (AFPFont) fontInfo.getFonts().get(name);
1131
        AFPFont tf = (AFPFont) fontInfo.getFonts().get(name);
1126
1132
1127
        Color col = (Color) text.getTrait(Trait.COLOR);
1133
        Color col = (Color) text.getTrait(Trait.COLOR);
1128
1134
1129
        int vsci = mpts2units(tf.getWidth(' ', _currentFontSize) / 1000
1135
        int vsci = mpts2units(tf.getWidth(' ', _currentFontSize, _currentFontStretch) / 1000
1130
                                + text.getTextWordSpaceAdjust()
1136
                                + text.getTextWordSpaceAdjust()
1131
                                + text.getTextLetterSpaceAdjust());
1137
                                + text.getTextLetterSpaceAdjust());
1132
1138
Lines 1199-1205 Link Here
1199
     */
1205
     */
1200
    public void renderWord(WordArea word) {
1206
    public void renderWord(WordArea word) {
1201
        String name = getInternalFontNameForArea(word.getParentArea());
1207
        String name = getInternalFontNameForArea(word.getParentArea());
1202
        int size = ((Integer) word.getParentArea().getTrait(Trait.FONT_SIZE)).intValue();
1208
        FontSize size = (FontSize) word.getParentArea().getTrait(Trait.FONT_SIZE);
1203
        AFPFont tf = (AFPFont) fontInfo.getFonts().get(name);
1209
        AFPFont tf = (AFPFont) fontInfo.getFonts().get(name);
1204
1210
1205
        String s = word.getWord();
1211
        String s = word.getWord();
Lines 1214-1220 Link Here
1214
     */
1220
     */
1215
    public void renderSpace(SpaceArea space) {
1221
    public void renderSpace(SpaceArea space) {
1216
        String name = getInternalFontNameForArea(space.getParentArea());
1222
        String name = getInternalFontNameForArea(space.getParentArea());
1217
        int size = ((Integer) space.getParentArea().getTrait(Trait.FONT_SIZE)).intValue();
1223
        FontSize size = (FontSize) space.getParentArea().getTrait(Trait.FONT_SIZE);
1218
        AFPFont tf = (AFPFont) fontInfo.getFonts().get(name);
1224
        AFPFont tf = (AFPFont) fontInfo.getFonts().get(name);
1219
1225
1220
        String s = space.getSpace();
1226
        String s = space.getSpace();
(-)src/java/org/apache/fop/render/afp/fonts/FopCharacterSet.java (-1 / +1 lines)
Lines 125-131 Link Here
125
     * @return the width of the character
125
     * @return the width of the character
126
     */
126
     */
127
    public int width(int character) {
127
    public int width(int character) {
128
        return _characterSet.getWidth(character, _size);
128
        return _characterSet.getWidth(character, _size, 1);
129
    }
129
    }
130
130
131
    /**
131
    /**
(-)src/java/org/apache/fop/render/afp/fonts/OutlineFont.java (-2 / +2 lines)
Lines 138-146 Link Here
138
    /**
138
    /**
139
     * Obtain the width of the character for the specified point size.
139
     * Obtain the width of the character for the specified point size.
140
     */
140
     */
141
    public int getWidth(int character, int size) {
141
    public int getWidth(int character, int size, float stretch) {
142
142
143
        return _characterSet.width(character) / 1000 * size;
143
        return (int) (_characterSet.width(character) / 1000 * size * stretch);
144
144
145
    }
145
    }
146
146
(-)src/java/org/apache/fop/render/afp/fonts/RasterFont.java (-2 / +2 lines)
Lines 192-200 Link Here
192
    /**
192
    /**
193
     * Obtain the width of the character for the specified point size.
193
     * Obtain the width of the character for the specified point size.
194
     */
194
     */
195
    public int getWidth(int character, int size) {
195
    public int getWidth(int character, int size, float stretch) {
196
196
197
        return getCharacterSet(size).width(character);
197
        return (int) (getCharacterSet(size).width(character) * stretch);
198
198
199
    }
199
    }
200
200
(-)src/java/org/apache/fop/render/java2d/FontMetricsMapper.java (-2 / +2 lines)
Lines 124-131 Link Here
124
    /**
124
    /**
125
     * @see org.apache.fop.fonts.FontMetrics#getWidth(int, int)
125
     * @see org.apache.fop.fonts.FontMetrics#getWidth(int, int)
126
     */
126
     */
127
    public int getWidth(int i, int size) {
127
    public int getWidth(int i, int size, float stretch) {
128
        return metric.width(i, family, style, size);
128
        return metric.width(i, family, style, size, stretch);
129
    }
129
    }
130
130
131
131
(-)src/java/org/apache/fop/render/java2d/Java2DFontMetrics.java (-2 / +2 lines)
Lines 218-227 Link Here
218
     * @param size font size
218
     * @param size font size
219
     * @return character width in millipoints
219
     * @return character width in millipoints
220
     */
220
     */
221
    public int width(int i, String family, int style, int size) {
221
    public int width(int i, String family, int style, int size, float stretch) {
222
        int w;
222
        int w;
223
        setFont(family, style, size);
223
        setFont(family, style, size);
224
        w = internalCharWidth(i) * 1000;
224
        w = (int)(internalCharWidth(i) * 1000 * stretch);
225
        return w;
225
        return w;
226
    }
226
    }
227
227
(-)src/java/org/apache/fop/render/java2d/Java2DRenderer.java (-2 / +3 lines)
Lines 68-73 Link Here
68
import org.apache.fop.fo.Constants;
68
import org.apache.fop.fo.Constants;
69
import org.apache.fop.fonts.Font;
69
import org.apache.fop.fonts.Font;
70
import org.apache.fop.fonts.FontInfo;
70
import org.apache.fop.fonts.FontInfo;
71
import org.apache.fop.fonts.FontSize;
71
import org.apache.fop.fonts.Typeface;
72
import org.apache.fop.fonts.Typeface;
72
import org.apache.fop.image.FopImage;
73
import org.apache.fop.image.FopImage;
73
import org.apache.fop.image.ImageFactory;
74
import org.apache.fop.image.ImageFactory;
Lines 699-705 Link Here
699
        int saveIP = currentIPPosition;
700
        int saveIP = currentIPPosition;
700
701
701
        Font font = getFontFromArea(text);
702
        Font font = getFontFromArea(text);
702
        state.updateFont(font.getFontName(), font.getFontSize());
703
        state.updateFont(font.getFontName(), font.getFontSize().getSize());
703
        saveGraphicsState();
704
        saveGraphicsState();
704
        AffineTransform at = new AffineTransform();
705
        AffineTransform at = new AffineTransform();
705
        at.translate(rx / 1000f, bl / 1000f);
706
        at.translate(rx / 1000f, bl / 1000f);
Lines 712-718 Link Here
712
713
713
        // rendering text decorations
714
        // rendering text decorations
714
        Typeface tf = (Typeface) fontInfo.getFonts().get(font.getFontName());
715
        Typeface tf = (Typeface) fontInfo.getFonts().get(font.getFontName());
715
        int fontsize = text.getTraitAsInteger(Trait.FONT_SIZE);
716
        int fontsize = ((FontSize)text.getTrait(Trait.FONT_SIZE)).getSize();
716
        renderTextDecoration(tf, fontsize, text, bl, rx);
717
        renderTextDecoration(tf, fontsize, text, bl, rx);
717
    }
718
    }
718
719
(-)src/java/org/apache/fop/render/pcl/PCLRenderer.java (-4 / +5 lines)
Lines 75-80 Link Here
75
import org.apache.fop.fonts.Font;
75
import org.apache.fop.fonts.Font;
76
import org.apache.fop.fonts.FontInfo;
76
import org.apache.fop.fonts.FontInfo;
77
import org.apache.fop.fonts.FontMetrics;
77
import org.apache.fop.fonts.FontMetrics;
78
import org.apache.fop.fonts.FontSize;
78
import org.apache.fop.image.EPSImage;
79
import org.apache.fop.image.EPSImage;
79
import org.apache.fop.image.FopImage;
80
import org.apache.fop.image.FopImage;
80
import org.apache.fop.image.ImageFactory;
81
import org.apache.fop.image.ImageFactory;
Lines 550-556 Link Here
550
        renderInlineAreaBackAndBorders(text);
551
        renderInlineAreaBackAndBorders(text);
551
        
552
        
552
        String fontname = getInternalFontNameForArea(text);
553
        String fontname = getInternalFontNameForArea(text);
553
        final int fontsize = text.getTraitAsInteger(Trait.FONT_SIZE);
554
        final int fontsize = ((FontSize)text.getTrait(Trait.FONT_SIZE)).getSize();
554
555
555
        //Determine position
556
        //Determine position
556
        int saveIP = currentIPPosition;
557
        int saveIP = currentIPPosition;
Lines 589-598 Link Here
589
                final int baseline = text.getBaselineOffset();
590
                final int baseline = text.getBaselineOffset();
590
                
591
                
591
                //for cursive fonts, so the text isn't clipped
592
                //for cursive fonts, so the text isn't clipped
592
                int extraWidth = font.getFontSize() / 3;
593
                int extraWidth = font.getFontSize().getSize() / 3;
593
                final FontMetricsMapper mapper = (FontMetricsMapper)fontInfo.getMetricsFor(
594
                final FontMetricsMapper mapper = (FontMetricsMapper)fontInfo.getMetricsFor(
594
                        font.getFontName());
595
                        font.getFontName());
595
                int maxAscent = mapper.getMaxAscent(font.getFontSize()) / 1000;
596
                int maxAscent = mapper.getMaxAscent(font.getFontSize().getSize()) / 1000;
596
                final int additionalBPD = maxAscent - baseline;
597
                final int additionalBPD = maxAscent - baseline;
597
                
598
                
598
                Graphics2DAdapter g2a = getGraphics2DAdapter();
599
                Graphics2DAdapter g2a = getGraphics2DAdapter();
Lines 609-615 Link Here
609
                Graphics2DImagePainter painter = new Graphics2DImagePainter() {
610
                Graphics2DImagePainter painter = new Graphics2DImagePainter() {
610
611
611
                    public void paint(Graphics2D g2d, Rectangle2D area) {
612
                    public void paint(Graphics2D g2d, Rectangle2D area) {
612
                        g2d.setFont(mapper.getFont(font.getFontSize()));
613
                        g2d.setFont(mapper.getFont(font.getFontSize().getSize()));
613
                        g2d.translate(0, baseline + additionalBPD);
614
                        g2d.translate(0, baseline + additionalBPD);
614
                        g2d.scale(1000, 1000);
615
                        g2d.scale(1000, 1000);
615
                        g2d.setColor(col);
616
                        g2d.setColor(col);
(-)src/java/org/apache/fop/render/pdf/PDFRenderer.java (-10 / +19 lines)
Lines 65-70 Link Here
65
import org.apache.fop.area.inline.InlineParent;
65
import org.apache.fop.area.inline.InlineParent;
66
import org.apache.fop.area.inline.WordArea;
66
import org.apache.fop.area.inline.WordArea;
67
import org.apache.fop.area.inline.SpaceArea;
67
import org.apache.fop.area.inline.SpaceArea;
68
import org.apache.fop.fonts.FontSize;
68
import org.apache.fop.fonts.Typeface;
69
import org.apache.fop.fonts.Typeface;
69
import org.apache.fop.fonts.Font;
70
import org.apache.fop.fonts.Font;
70
import org.apache.fop.image.FopImage;
71
import org.apache.fop.image.FopImage;
Lines 245-250 Link Here
245
    protected String currentFontName = "";
246
    protected String currentFontName = "";
246
    /** Size of currently selected font */
247
    /** Size of currently selected font */
247
    protected int currentFontSize = 0;
248
    protected int currentFontSize = 0;
249
    /** Stretch of currently selected font */
250
    protected float currentFontStretch = 1;
248
    /** page height */
251
    /** page height */
249
    protected int pageHeight;
252
    protected int pageHeight;
250
253
Lines 1403-1415 Link Here
1403
        StringBuffer pdf = new StringBuffer();
1406
        StringBuffer pdf = new StringBuffer();
1404
1407
1405
        String fontName = getInternalFontNameForArea(text);
1408
        String fontName = getInternalFontNameForArea(text);
1406
        int size = ((Integer) text.getTrait(Trait.FONT_SIZE)).intValue();
1409
        FontSize size = (FontSize) text.getTrait(Trait.FONT_SIZE);
1407
        
1410
        
1408
        // This assumes that *all* CIDFonts use a /ToUnicode mapping
1411
        // This assumes that *all* CIDFonts use a /ToUnicode mapping
1409
        Typeface tf = (Typeface) fontInfo.getFonts().get(fontName);
1412
        Typeface tf = (Typeface) fontInfo.getFonts().get(fontName);
1410
        boolean useMultiByte = tf.isMultiByte();
1413
        boolean useMultiByte = tf.isMultiByte();
1411
        
1414
        
1412
        updateFont(fontName, size, pdf);
1415
        updateFont(fontName, size.getSize(), size.getStretch(), pdf);
1413
        Color ct = (Color) text.getTrait(Trait.COLOR);
1416
        Color ct = (Color) text.getTrait(Trait.COLOR);
1414
        updateColor(ct, true, pdf);
1417
        updateColor(ct, true, pdf);
1415
1418
Lines 1430-1436 Link Here
1430
1433
1431
        currentStream.add("] TJ\n");
1434
        currentStream.add("] TJ\n");
1432
        
1435
        
1433
        renderTextDecoration(tf, size, text, bl, rx);
1436
        renderTextDecoration(tf, size.getSize(), text, bl, rx);
1434
    }
1437
    }
1435
    
1438
    
1436
    /**
1439
    /**
Lines 1472-1478 Link Here
1472
                         - 2 * textArea.getTextLetterSpaceAdjust();
1475
                         - 2 * textArea.getTextLetterSpaceAdjust();
1473
1476
1474
            if (tws != 0) {
1477
            if (tws != 0) {
1475
                pdf.append(format(tws / (font.getFontSize() / 1000f)));
1478
                pdf.append(format(tws / (font.getFontSize().getSize() / 1000f)));
1476
                pdf.append(" ");
1479
                pdf.append(" ");
1477
            }
1480
            }
1478
        }
1481
        }
Lines 1509-1515 Link Here
1509
1512
1510
        int l = s.length();
1513
        int l = s.length();
1511
1514
1512
        float fontSize = fs.getFontSize() / 1000f;
1515
        float fontSize = fs.getFontSize().getSize() / 1000f;
1513
        boolean startPending = true;
1516
        boolean startPending = true;
1514
        for (int i = 0; i < l; i++) {
1517
        for (int i = 0; i < l; i++) {
1515
            char orgChar = s.charAt(i);
1518
            char orgChar = s.charAt(i);
Lines 1631-1646 Link Here
1631
        updateColor(col, fill, null);
1634
        updateColor(col, fill, null);
1632
    }
1635
    }
1633
    
1636
    
1634
    private void updateFont(String name, int size, StringBuffer pdf) {
1637
    private void updateFont(String name, int size, float stretch, StringBuffer pdf) {
1635
        if ((!name.equals(this.currentFontName))
1638
    	boolean tf = (!name.equals(this.currentFontName)) || (size != this.currentFontSize);
1636
                || (size != this.currentFontSize)) {
1639
    	boolean tz = stretch != this.currentFontStretch;
1637
            closeText();
1640
        if (tf) {
1638
1641
    		closeText();
1639
            this.currentFontName = name;
1642
            this.currentFontName = name;
1640
            this.currentFontSize = size;
1643
            this.currentFontSize = size;
1641
            pdf = pdf.append("/" + name + " " + format((float) size / 1000f)
1644
            pdf = pdf.append("/" + name + " " + format((float) size / 1000f)
1642
                              + " Tf\n");
1645
                              + " Tf\n");
1646
        	this.currentFontStretch = stretch;
1647
        	pdf = pdf.append(format(stretch * 100) + " Tz\n");
1643
        }
1648
        }
1649
        else if (tz) {
1650
        	this.currentFontStretch = stretch;
1651
        	pdf = pdf.append(format(stretch * 100) + " Tz\n");
1652
        }
1644
    }
1653
    }
1645
1654
1646
    /**
1655
    /**
(-)src/java/org/apache/fop/render/PrintRenderer.java (-1 / +2 lines)
Lines 26-31 Link Here
26
import org.apache.fop.fonts.FontInfo;
26
import org.apache.fop.fonts.FontInfo;
27
import org.apache.fop.fonts.FontResolver;
27
import org.apache.fop.fonts.FontResolver;
28
import org.apache.fop.fonts.FontSetup;
28
import org.apache.fop.fonts.FontSetup;
29
import org.apache.fop.fonts.FontSize;
29
import org.apache.fop.fonts.FontTriplet;
30
import org.apache.fop.fonts.FontTriplet;
30
import org.w3c.dom.Document;
31
import org.w3c.dom.Document;
31
32
Lines 94-100 Link Here
94
     */
95
     */
95
    protected Font getFontFromArea(Area area) {
96
    protected Font getFontFromArea(Area area) {
96
        FontTriplet triplet = (FontTriplet)area.getTrait(Trait.FONT);
97
        FontTriplet triplet = (FontTriplet)area.getTrait(Trait.FONT);
97
        int size = ((Integer)area.getTrait(Trait.FONT_SIZE)).intValue();
98
        FontSize size = (FontSize)area.getTrait(Trait.FONT_SIZE);
98
        return fontInfo.getFontInstance(triplet, size);
99
        return fontInfo.getFontInstance(triplet, size);
99
    }
100
    }
100
    
101
    
(-)src/java/org/apache/fop/render/ps/NativeTextHandler.java (-3 / +3 lines)
Lines 170-181 Link Here
170
170
171
    private void establishCurrentFont() throws IOException {
171
    private void establishCurrentFont() throws IOException {
172
        if ((currentFontName != this.font.getFontName()) 
172
        if ((currentFontName != this.font.getFontName()) 
173
                || (currentFontSize != this.font.getFontSize())) {
173
                || (currentFontSize != this.font.getFontSize().getSize())) {
174
            PSGenerator gen = getPSGenerator();
174
            PSGenerator gen = getPSGenerator();
175
            gen.writeln(this.font.getFontName() + " " 
175
            gen.writeln(this.font.getFontName() + " " 
176
                    + gen.formatDouble(font.getFontSize() / 1000f) + " F");
176
                    + gen.formatDouble(font.getFontSize().getSize() / 1000f) + " F");
177
            currentFontName = this.font.getFontName();
177
            currentFontName = this.font.getFontName();
178
            currentFontSize = this.font.getFontSize();
178
            currentFontSize = this.font.getFontSize().getSize();
179
        }
179
        }
180
    }
180
    }
181
181
(-)src/java/org/apache/fop/render/ps/PSRenderer.java (-2 / +3 lines)
Lines 59-64 Link Here
59
import org.apache.fop.fo.Constants;
59
import org.apache.fop.fo.Constants;
60
import org.apache.fop.fo.extensions.ExtensionAttachment;
60
import org.apache.fop.fo.extensions.ExtensionAttachment;
61
import org.apache.fop.fonts.Font;
61
import org.apache.fop.fonts.Font;
62
import org.apache.fop.fonts.FontSize;
62
import org.apache.fop.fonts.LazyFont;
63
import org.apache.fop.fonts.LazyFont;
63
import org.apache.fop.fonts.Typeface;
64
import org.apache.fop.fonts.Typeface;
64
import org.apache.fop.image.EPSImage;
65
import org.apache.fop.image.EPSImage;
Lines 993-999 Link Here
993
    public void renderText(TextArea area) {
994
    public void renderText(TextArea area) {
994
        renderInlineAreaBackAndBorders(area);
995
        renderInlineAreaBackAndBorders(area);
995
        String fontname = getInternalFontNameForArea(area);
996
        String fontname = getInternalFontNameForArea(area);
996
        int fontsize = area.getTraitAsInteger(Trait.FONT_SIZE);
997
        int fontsize = ((FontSize) area.getTrait(Trait.FONT_SIZE)).getSize();
997
998
998
        // This assumes that *all* CIDFonts use a /ToUnicode mapping
999
        // This assumes that *all* CIDFonts use a /ToUnicode mapping
999
        Typeface tf = (Typeface) fontInfo.getFonts().get(fontname);
1000
        Typeface tf = (Typeface) fontInfo.getFonts().get(fontname);
Lines 1078-1084 Link Here
1078
                } else {
1079
                } else {
1079
                    wordSpace = 0;
1080
                    wordSpace = 0;
1080
                }
1081
                }
1081
                int cw = tf.getWidth(mapped, font.getFontSize()) / 1000;
1082
                int cw = tf.getWidth(mapped, font.getFontSize().getSize(), font.getFontSize().getStretch()) / 1000;
1082
                int ladj = (letterAdjust != null && i < textLen - 1 ? letterAdjust[i + 1] : 0);
1083
                int ladj = (letterAdjust != null && i < textLen - 1 ? letterAdjust[i + 1] : 0);
1083
                int tls = (i < textLen - 1 ? area.getTextLetterSpaceAdjust() : 0); 
1084
                int tls = (i < textLen - 1 ? area.getTextLetterSpaceAdjust() : 0); 
1084
                offsets[i] = cw + ladj + tls + wordSpace;
1085
                offsets[i] = cw + ladj + tls + wordSpace;
(-)src/java/org/apache/fop/render/ps/PSTextPainter.java (-1 / +1 lines)
Lines 418-424 Link Here
418
            fStyle |= java.awt.Font.ITALIC;
418
            fStyle |= java.awt.Font.ITALIC;
419
        }
419
        }
420
        return new java.awt.Font(font.getFontName(), fStyle,
420
        return new java.awt.Font(font.getFontName(), fStyle,
421
                             (int)(font.getFontSize() / 1000));
421
                             (int)(font.getFontSize().getSize() / 1000));
422
    }
422
    }
423
423
424
    private float getStringWidth(String str, Font font) {
424
    private float getStringWidth(String str, Font font) {
(-)src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java (+1 lines)
Lines 311-316 Link Here
311
311
312
        currentFontName = "";
312
        currentFontName = "";
313
        currentFontSize = 0;
313
        currentFontSize = 0;
314
        currentFontStretch = 1;
314
315
315
        if (currentStream == null) {
316
        if (currentStream == null) {
316
            currentStream = new StringWriter();
317
            currentStream = new StringWriter();
(-)src/java/org/apache/fop/svg/PDFGraphics2D.java (-2 / +19 lines)
Lines 168-173 Link Here
168
    protected float currentFontSize;
168
    protected float currentFontSize;
169
169
170
    /**
170
    /**
171
     * the current font stretch in %
172
     */
173
    protected float currentFontStretch;
174
175
    /**
171
     * The output stream for the pdf document.
176
     * The output stream for the pdf document.
172
     * If this is set then it can progressively output
177
     * If this is set then it can progressively output
173
     * the pdf document objects to reduce memory.
178
     * the pdf document objects to reduce memory.
Lines 1439-1446 Link Here
1439
        }
1444
        }
1440
        String name;
1445
        String name;
1441
        float size;
1446
        float size;
1447
        float stretch;
1442
        name = fontState.getFontName();
1448
        name = fontState.getFontName();
1443
        size = (float)fontState.getFontSize() / 1000f;
1449
        size = (float)fontState.getFontSize().getSize() / 1000f;
1450
        stretch = fontState.getFontSize().getStretch();
1444
1451
1445
        if ((!name.equals(this.currentFontName))
1452
        if ((!name.equals(this.currentFontName))
1446
                || (size != this.currentFontSize)) {
1453
                || (size != this.currentFontSize)) {
Lines 1449-1454 Link Here
1449
            currentStream.write("/" + name + " " + size + " Tf\n");
1456
            currentStream.write("/" + name + " " + size + " Tf\n");
1450
1457
1451
        }
1458
        }
1459
        
1460
        if (stretch != this.currentFontStretch) {
1461
        	this.currentFontStretch = stretch;
1462
        	currentStream.write("" + stretch + " Tz\n");
1463
        }
1452
1464
1453
        currentStream.write("q\n");
1465
        currentStream.write("q\n");
1454
1466
Lines 1637-1643 Link Here
1637
            //Map attr = iterator.getAttributes();
1649
            //Map attr = iterator.getAttributes();
1638
1650
1639
            String name = fontState.getFontName();
1651
            String name = fontState.getFontName();
1640
            int size = fontState.getFontSize();
1652
            int size = fontState.getFontSize().getSize();
1653
            float stretch = fontState.getFontSize().getStretch();
1641
            if ((!name.equals(this.currentFontName))
1654
            if ((!name.equals(this.currentFontName))
1642
                    || (size != this.currentFontSize)) {
1655
                    || (size != this.currentFontSize)) {
1643
                this.currentFontName = name;
1656
                this.currentFontName = name;
Lines 1646-1651 Link Here
1646
                                    + " Tf\n");
1659
                                    + " Tf\n");
1647
1660
1648
            }
1661
            }
1662
            if (stretch != this.currentFontStretch) {
1663
            	this.currentFontStretch = stretch;
1664
            	currentStream.write("" + stretch + " Tz\n");
1665
            }
1649
1666
1650
            currentStream.write(PDFNumber.doubleOut(vals[0], DEC) + " "
1667
            currentStream.write(PDFNumber.doubleOut(vals[0], DEC) + " "
1651
                                + PDFNumber.doubleOut(vals[1], DEC) + " "
1668
                                + PDFNumber.doubleOut(vals[1], DEC) + " "
(-)src/java/org/apache/fop/svg/PDFTextPainter.java (-1 / +1 lines)
Lines 210-216 Link Here
210
            }
210
            }
211
        }
211
        }
212
        java.awt.Font font = new java.awt.Font(fontFamily, fStyle,
212
        java.awt.Font font = new java.awt.Font(fontFamily, fStyle,
213
                             (int)(fontState.getFontSize() / 1000));
213
                             (int)(fontState.getFontSize().getSize() / 1000));
214
214
215
        g2d.setFont(font);
215
        g2d.setFont(font);
216
216

Return to bug 42577