~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/ikvm/openjdk/sun/font/Font2D.java

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (C) 2009 Volker Berlin (i-net software)
 
3
 
 
4
  This software is provided 'as-is', without any express or implied
 
5
  warranty.  In no event will the authors be held liable for any damages
 
6
  arising from the use of this software.
 
7
 
 
8
  Permission is granted to anyone to use this software for any purpose,
 
9
  including commercial applications, and to alter it and redistribute it
 
10
  freely, subject to the following restrictions:
 
11
 
 
12
  1. The origin of this software must not be misrepresented; you must not
 
13
     claim that you wrote the original software. If you use this software
 
14
     in a product, an acknowledgment in the product documentation would be
 
15
     appreciated but is not required.
 
16
  2. Altered source versions must be plainly marked as such, and must not be
 
17
     misrepresented as being the original software.
 
18
  3. This notice may not be removed or altered from any source distribution.
 
19
 
 
20
  Jeroen Frijters
 
21
  jeroen@frijters.net
 
22
  
 
23
 */
 
24
package sun.font;
 
25
 
 
26
import java.awt.Font;
 
27
import java.awt.font.FontRenderContext;
 
28
import java.awt.geom.AffineTransform;
 
29
import java.util.Locale;
 
30
 
 
31
import sun.awt.SunHints;
 
32
 
 
33
 
 
34
 
 
35
/**
 
36
 * 
 
37
 */
 
38
public abstract class Font2D{
 
39
 
 
40
    public Font2DHandle handle = new Font2DHandle(this);
 
41
 
 
42
    /* SunGraphics2D has font, tx, aa and fm. From this info
 
43
     * can get a Strike object from the cache, creating it if necessary.
 
44
     * This code is designed for multi-threaded access.
 
45
     * For that reason it creates a local FontStrikeDesc rather than filling
 
46
     * in a shared one. Up to two AffineTransforms and one FontStrikeDesc will
 
47
     * be created by every lookup. This appears to perform more than
 
48
     * adequately. But it may make sense to expose FontStrikeDesc
 
49
     * as a parameter so a caller can use its own.
 
50
     * In such a case if a FontStrikeDesc is stored as a key then
 
51
     * we would need to use a private copy.
 
52
     *
 
53
     * Note that this code doesn't prevent two threads from creating
 
54
     * two different FontStrike instances and having one of the threads
 
55
     * overwrite the other in the map. This is likely to be a rare
 
56
     * occurrence and the only consequence is that these callers will have
 
57
     * different instances of the strike, and there'd be some duplication of
 
58
     * population of the strikes. However since users of these strikes are
 
59
     * transient, then the one that was overwritten would soon be freed.
 
60
     * If there is any problem then a small synchronized block would be
 
61
     * required with its attendant consequences for MP scalability.
 
62
     */
 
63
    public FontStrike getStrike(Font font, AffineTransform devTx, int aa, int fm){
 
64
        return getStrike(font, new FontRenderContext(devTx, aa == SunHints.INTVAL_TEXT_ANTIALIAS_ON,
 
65
                fm == SunHints.INTVAL_FRACTIONALMETRICS_ON));
 
66
    }
 
67
    
 
68
    public FontStrike getStrike(Font font, FontRenderContext frc) {
 
69
        // TODO Auto-generated method stub
 
70
        return null;
 
71
    }
 
72
 
 
73
    public void removeFromCache(FontStrikeDesc desc){
 
74
        // TODO Auto-generated method stub
 
75
 
 
76
    }
 
77
 
 
78
    /**
 
79
     * The length of the metrics array must be >= 8.  This method will
 
80
     * store the following elements in that array before returning:
 
81
     *    metrics[0]: ascent
 
82
     *    metrics[1]: descent
 
83
     *    metrics[2]: leading
 
84
     *    metrics[3]: max advance
 
85
     *    metrics[4]: strikethrough offset
 
86
     *    metrics[5]: strikethrough thickness
 
87
     *    metrics[6]: underline offset
 
88
     *    metrics[7]: underline thickness
 
89
     */
 
90
    public void getFontMetrics(Font font, AffineTransform identityTx, Object antiAliasingHint,
 
91
            Object fractionalMetricsHint, float[] metrics){
 
92
        FontRenderContext frc = new FontRenderContext(identityTx, antiAliasingHint, fractionalMetricsHint);
 
93
        StrikeMetrics strikeMetrics = getStrike(font, frc).getFontMetrics();
 
94
        metrics[0] = strikeMetrics.getAscent();
 
95
        metrics[1] = strikeMetrics.getDescent();
 
96
        metrics[2] = strikeMetrics.getLeading();
 
97
        metrics[3] = strikeMetrics.getMaxAdvance();    
 
98
        
 
99
        getStyleMetrics(font.getSize2D(), metrics, 4);
 
100
    }
 
101
 
 
102
    /**
 
103
     * The length of the metrics array must be >= offset+4, and offset must be
 
104
     * >= 0.  Typically offset is 4.  This method will
 
105
     * store the following elements in that array before returning:
 
106
     *    metrics[off+0]: strikethrough offset
 
107
     *    metrics[off+1]: strikethrough thickness
 
108
     *    metrics[off+2]: underline offset
 
109
     *    metrics[off+3]: underline thickness
 
110
     *
 
111
     * Note that this implementation simply returns default values;
 
112
     * subclasses can override this method to provide more accurate values.
 
113
     */
 
114
    public void getStyleMetrics(float pointSize, float[] metrics, int offset) {
 
115
        metrics[offset] = -metrics[0] / 2.5f;
 
116
        metrics[offset+1] = pointSize / 12;
 
117
        metrics[offset+2] = metrics[offset+1] / 1.5f;
 
118
        metrics[offset+3] = metrics[offset+1];
 
119
    }
 
120
    
 
121
    /**
 
122
     * The length of the metrics array must be >= 4.  This method will
 
123
     * store the following elements in that array before returning:
 
124
     *    metrics[0]: ascent
 
125
     *    metrics[1]: descent
 
126
     *    metrics[2]: leading
 
127
     *    metrics[3]: max advance
 
128
     */
 
129
    public void getFontMetrics(Font font, FontRenderContext frc,
 
130
                               float metrics[]) {
 
131
        StrikeMetrics strikeMetrics = getStrike(font, frc).getFontMetrics();
 
132
        metrics[0] = strikeMetrics.getAscent();
 
133
        metrics[1] = strikeMetrics.getDescent();
 
134
        metrics[2] = strikeMetrics.getLeading();
 
135
        metrics[3] = strikeMetrics.getMaxAdvance();    
 
136
    }
 
137
 
 
138
    /*
 
139
     * All the important subclasses override this which is principally for
 
140
     * the TrueType 'gasp' table.
 
141
     */
 
142
    public boolean useAAForPtSize(int ptsize) {
 
143
        return true;
 
144
    }
 
145
 
 
146
    public boolean hasSupplementaryChars() {
 
147
        return false;
 
148
    }
 
149
 
 
150
    /* The following methods implement public methods on java.awt.Font */
 
151
    public String getPostscriptName(){
 
152
        // TODO Auto-generated method stub
 
153
        return null;
 
154
    }
 
155
 
 
156
    public String getFontName(Locale l){
 
157
        // TODO Auto-generated method stub
 
158
        return null;
 
159
    }
 
160
 
 
161
    public String getFamilyName(Locale l){
 
162
        // TODO Auto-generated method stub
 
163
        return null;
 
164
    }
 
165
 
 
166
    public int getNumGlyphs(){
 
167
        // TODO Auto-generated method stub
 
168
        return 0;
 
169
    }
 
170
 
 
171
    public int charToGlyph(int wchar) {
 
172
        return wchar;
 
173
    }
 
174
 
 
175
    public int getMissingGlyphCode(){
 
176
        // TODO Auto-generated method stub
 
177
        return 0;
 
178
    }
 
179
 
 
180
    public boolean canDisplay(char c){
 
181
        //HACK There is no equivalent in C# http://msdn2.microsoft.com/en-us/library/sf4dhbw8(VS.80).aspx
 
182
        return true;
 
183
    }
 
184
 
 
185
    public boolean canDisplay(int cp){
 
186
        //HACK There is no equivalent in C# http://msdn2.microsoft.com/en-us/library/sf4dhbw8(VS.80).aspx
 
187
        return true;
 
188
    }
 
189
 
 
190
    public byte getBaselineFor(char c) {
 
191
        return Font.ROMAN_BASELINE;
 
192
    }
 
193
 
 
194
    public float getItalicAngle(Font font, AffineTransform at,
 
195
                                Object aaHint, Object fmHint) {
 
196
        /* hardwire psz=12 as that's typical and AA vs non-AA for 'gasp' mode
 
197
         * isn't important for the caret slope of this rarely used API.
 
198
         */
 
199
        int aa = FontStrikeDesc.getAAHintIntVal(aaHint, this, 12);
 
200
        int fm = FontStrikeDesc.getFMHintIntVal(fmHint);
 
201
        FontStrike strike = getStrike(font, at, aa, fm);
 
202
        StrikeMetrics metrics = strike.getFontMetrics();
 
203
        if (metrics.ascentY == 0 || metrics.ascentX == 0) {
 
204
            return 0f;
 
205
        } else {
 
206
            /* ascent is "up" from the baseline so its typically
 
207
             * a negative value, so we need to compensate
 
208
             */
 
209
            return metrics.ascentX/-metrics.ascentY;
 
210
        }
 
211
    }
 
212
 
 
213
    /** Returns the "real" style of this Font2D. Eg the font face
 
214
     * Lucida Sans Bold" has a real style of Font.BOLD, even though
 
215
     * it may be able to used to simulate bold italic
 
216
     */
 
217
    public abstract int getStyle();
 
218
 
 
219
    public abstract cli.System.Drawing.Font createNetFont(Font font);
 
220
 
 
221
}