Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 278923
Collapse All | Expand All

(-)src/org/eclipse/gmf/runtime/draw2d/ui/text/TextUtilitiesEx.java (-13 / +9 lines)
Lines 1-5 Link Here
1
/******************************************************************************
1
/******************************************************************************
2
 * Copyright (c) 2007, 2008 IBM Corporation and others.
2
 * Copyright (c) 2007, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 14-20 Link Here
14
import org.eclipse.draw2d.TextUtilities;
14
import org.eclipse.draw2d.TextUtilities;
15
import org.eclipse.draw2d.geometry.Dimension;
15
import org.eclipse.draw2d.geometry.Dimension;
16
import org.eclipse.gmf.runtime.draw2d.ui.mapmode.IMapMode;
16
import org.eclipse.gmf.runtime.draw2d.ui.mapmode.IMapMode;
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.graphics.Font;
17
import org.eclipse.swt.graphics.Font;
19
import org.eclipse.swt.graphics.GC;
18
import org.eclipse.swt.graphics.GC;
20
import org.eclipse.swt.widgets.Shell;
19
import org.eclipse.swt.widgets.Shell;
Lines 64-70 Link Here
64
     */
63
     */
65
    public Dimension getStringExtents(String s, Font f) {
64
    public Dimension getStringExtents(String s, Font f) {
66
    	Dimension extents = new Dimension(getStringDimension(s, f, true));
65
    	Dimension extents = new Dimension(getStringDimension(s, f, true));
67
        applyItalicBugHack(s, f, extents);
66
        applyMarginAddition(s, f, extents);
68
        applyMapModeConversion(extents);
67
        applyMapModeConversion(extents);
69
        return extents;
68
        return extents;
70
    }
69
    }
Lines 74-80 Link Here
74
     */
73
     */
75
    public Dimension getTextExtents(String s, Font f) {
74
    public Dimension getTextExtents(String s, Font f) {
76
        Dimension extents = new Dimension(getTextDimension(s, f, true));
75
        Dimension extents = new Dimension(getTextDimension(s, f, true));
77
        applyItalicBugHack(s, f, extents);
76
        applyMarginAddition(s, f, extents);
78
        applyMapModeConversion(extents);
77
        applyMapModeConversion(extents);
79
        return extents;
78
        return extents;
80
    }
79
    }
Lines 115-136 Link Here
115
    }
114
    }
116
    
115
    
117
    /**
116
    /**
118
     * If the font is in italics, this does not always return the correct
117
     *  {GC#textExtents(String s)} and {GC#stringExtent(String s)} do not always return the correct
119
     * size and the text can get clipped. See
118
     * size and the text can get clipped. See
120
     * https://bugs.eclipse.org/bugs/show_bug.cgi?id=5190. Compensate for
119
     * https://bugs.eclipse.org/bugs/show_bug.cgi?id=5190. Compensate for
121
     * this here until the bugzilla is fixed in SWT by adding an extra half
120
     *  by adding an extra character space here.
122
     * a character space here.
121
     * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=278923
123
     * 
124
     * @deprecated
125
     * @param s the string
122
     * @param s the string
126
     * @param f the font
123
     * @param f the font
127
     * @param dimension the extents to be corrected
124
     * @param dimension the extents to be corrected
128
     */
125
     */
129
    private static void applyItalicBugHack(String s, Font f, Dimension extents)
126
    private static void applyMarginAddition(String s, Font f, Dimension extents)
130
    {
127
    {
131
        if ((f.getFontData()[0].getStyle() & SWT.ITALIC) != 0 &&
128
        if (s.length() > 0) {
132
        		s.length() > 0) {
129
        	extents.width += extents.width / s.length();
133
        	extents.width += (extents.width / s.length()) / 2;
134
        }
130
        }
135
    }
131
    }
136
    
132
    

Return to bug 278923