src/java.desktop/macosx/classes/sun/font/CFont.java

Print this page




  60        throw new InternalError("Not implemented");
  61     }
  62 
  63     Rectangle2D.Float getGlyphOutlineBounds(long pScalerContext,
  64                                                      int glyphCode) {
  65        throw new InternalError("Not implemented");
  66     }
  67 
  68     GeneralPath getGlyphOutline(long pScalerContext, int glyphCode,
  69                                          float x, float y) {
  70        throw new InternalError("Not implemented");
  71     }
  72 
  73     GeneralPath getGlyphVectorOutline(long pScalerContext,
  74                                                int[] glyphs, int numGlyphs,
  75                                                float x, float y) {
  76        throw new InternalError("Not implemented");
  77     }
  78 
  79     private static native long createNativeFont(final String nativeFontName,
  80                                                 final int style,
  81                                                 final boolean isFakeItalic);
  82     private static native void disposeNativeFont(final long nativeFontPtr);
  83 
  84     private boolean isFakeItalic;
  85     private String nativeFontName;
  86     private long nativeFontPtr;
  87 



























































  88     // this constructor is called from CFontWrapper.m
  89     public CFont(String name) {
  90         this(name, name);
  91     }
  92 
  93     public CFont(String name, String inFamilyName) {
  94         handle = new Font2DHandle(this);
  95         fullName = name;
  96         familyName = inFamilyName;
  97         nativeFontName = inFamilyName;
  98         setStyle();
  99     }
 100 

 101     public CFont(CFont other, String logicalFamilyName) {
 102         handle = new Font2DHandle(this);
 103         fullName = logicalFamilyName;
 104         familyName = logicalFamilyName;
 105         nativeFontName = other.nativeFontName;
 106         style = other.style;
 107         isFakeItalic = other.isFakeItalic;
 108     }
 109 
 110     public CFont createItalicVariant() {
 111         CFont font = new CFont(this, familyName);

 112         font.fullName =
 113             fullName + (style == Font.BOLD ? "" : "-") + "Italic-Derived";
 114         font.style |= Font.ITALIC;
 115         font.isFakeItalic = true;
 116         return font;
 117     }
 118 
 119     protected synchronized long getNativeFontPtr() {
 120         if (nativeFontPtr == 0L) {
 121             nativeFontPtr = createNativeFont(nativeFontName, style, isFakeItalic);
 122 }
 123         return nativeFontPtr;
 124     }
 125 
 126     protected synchronized void finalize() {
 127         if (nativeFontPtr != 0) {
 128             disposeNativeFont(nativeFontPtr);
 129         }
 130         nativeFontPtr = 0;
 131     }
 132 
 133     protected CharToGlyphMapper getMapper() {
 134         if (mapper == null) {
 135             mapper = new CCharToGlyphMapper(this);
 136         }
 137         return mapper;
 138     }
 139 
 140     protected FontStrike createStrike(FontStrikeDesc desc) {
 141         if (isFakeItalic) {




  60        throw new InternalError("Not implemented");
  61     }
  62 
  63     Rectangle2D.Float getGlyphOutlineBounds(long pScalerContext,
  64                                                      int glyphCode) {
  65        throw new InternalError("Not implemented");
  66     }
  67 
  68     GeneralPath getGlyphOutline(long pScalerContext, int glyphCode,
  69                                          float x, float y) {
  70        throw new InternalError("Not implemented");
  71     }
  72 
  73     GeneralPath getGlyphVectorOutline(long pScalerContext,
  74                                                int[] glyphs, int numGlyphs,
  75                                                float x, float y) {
  76        throw new InternalError("Not implemented");
  77     }
  78 
  79     private static native long createNativeFont(final String nativeFontName,
  80                                                 final int style);

  81     private static native void disposeNativeFont(final long nativeFontPtr);
  82 
  83     private boolean isFakeItalic;
  84     private String nativeFontName;
  85     private long nativeFontPtr;
  86 
  87     private native float getWidthNative(final long nativeFontPtr);
  88     private native float getWeightNative(final long nativeFontPtr);
  89 
  90     private int fontWidth = -1;
  91     private int fontWeight = -1;
  92 
  93     @Override
  94     public int getWidth() {
  95         if (fontWidth == -1) {
  96             // Apple use a range of -1 -> +1, where 0.0 is normal
  97             // OpenType uses a % range from 50% -> 200% where 100% is normal
  98             // and maps these onto the integer values 1->9.
  99             // Since that is what Font2D.getWidth() expects, remap to that.
 100             float fw = getWidthNative(getNativeFontPtr());
 101             if (fw == 0.0) { // short cut the common case
 102                 fontWidth = Font2D.FWIDTH_NORMAL;
 103                 return fontWidth;
 104             }
 105             fw += 1.0; fw *= 100.0;
 106             if (fw <= 50.0) {
 107                 fontWidth = 1;
 108             } else if (fw <= 62.5) {
 109                 fontWidth = 2;
 110             } else if (fw <= 75.0) {
 111                 fontWidth = 3;
 112             } else if (fw <= 87.5) {
 113                 fontWidth = 4;
 114             } else if (fw <= 100.0) {
 115                 fontWidth = 5;
 116             } else if (fw <= 112.5) {
 117                 fontWidth = 6;
 118             } else if (fw <= 125.0) {
 119                 fontWidth = 7;
 120             } else if (fw <= 150.0) {
 121                 fontWidth = 8;
 122             } else {
 123                 fontWidth = 9;
 124             }
 125         }
 126         return fontWidth;
 127    }
 128 
 129     @Override
 130     public int getWeight() {
 131         if (fontWeight == -1) {
 132             // Apple use a range of -1 -> +1, where 0 is medium/regular
 133             // Map this on to the OpenType range of 100->900 where
 134             // 500 is medium/regular.
 135             // We'll actually map to 0->1000 but that's close enough.
 136             float fw = getWeightNative(getNativeFontPtr());
 137             if (fw == 0) {
 138                return Font2D.FWEIGHT_NORMAL;
 139             }
 140             fw += 1.0; fw *= 500;
 141             fontWeight = (int)fw;
 142           }
 143           return fontWeight;
 144     }
 145     
 146     // this constructor is called from CFontWrapper.m
 147     public CFont(String name) {
 148         this(name, name);
 149     }
 150 
 151     public CFont(String name, String inFamilyName) {
 152         handle = new Font2DHandle(this);
 153         fullName = name;
 154         familyName = inFamilyName;
 155         nativeFontName = fullName;
 156         setStyle();
 157     }
 158 
 159     /* Called from CFontManager too */
 160     public CFont(CFont other, String logicalFamilyName) {
 161         handle = new Font2DHandle(this);
 162         fullName = logicalFamilyName;
 163         familyName = logicalFamilyName;
 164         nativeFontName = other.nativeFontName;
 165         style = other.style;
 166         isFakeItalic = other.isFakeItalic;
 167     }
 168 
 169     public CFont createItalicVariant() {
 170         CFont font = new CFont(this, familyName);
 171         font.nativeFontName = fullName;
 172         font.fullName =
 173             fullName + (style == Font.BOLD ? "" : "-") + "Italic-Derived";
 174         font.style |= Font.ITALIC;
 175         font.isFakeItalic = true;
 176         return font;
 177     }
 178 
 179     protected synchronized long getNativeFontPtr() {
 180         if (nativeFontPtr == 0L) {
 181             nativeFontPtr = createNativeFont(nativeFontName, style);
 182 }
 183         return nativeFontPtr;
 184     }
 185 
 186     protected synchronized void finalize() {
 187         if (nativeFontPtr != 0) {
 188             disposeNativeFont(nativeFontPtr);
 189         }
 190         nativeFontPtr = 0;
 191     }
 192 
 193     protected CharToGlyphMapper getMapper() {
 194         if (mapper == null) {
 195             mapper = new CCharToGlyphMapper(this);
 196         }
 197         return mapper;
 198     }
 199 
 200     protected FontStrike createStrike(FontStrikeDesc desc) {
 201         if (isFakeItalic) {