reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 1 | /* |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2 | ** Copyright 2006, The Android Open Source Project |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 3 | ** |
| 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | ** you may not use this file except in compliance with the License. |
| 6 | ** You may obtain a copy of the License at |
| 7 | ** |
| 8 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | ** |
| 10 | ** Unless required by applicable law or agreed to in writing, software |
| 11 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | ** See the License for the specific language governing permissions and |
| 14 | ** limitations under the License. |
| 15 | */ |
| 16 | |
reed@android.com | f13c6e1 | 2009-01-19 19:10:24 +0000 | [diff] [blame] | 17 | #include <carbon/carbon.h> |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 18 | #include "SkFontHost.h" |
| 19 | #include "SkDescriptor.h" |
reed@android.com | f13c6e1 | 2009-01-19 19:10:24 +0000 | [diff] [blame] | 20 | #include "SkPoint.h" |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 21 | |
| 22 | // Give 1MB font cache budget |
| 23 | #define FONT_CACHE_MEMORY_BUDGET (1024 * 1024) |
| 24 | |
| 25 | const char* gDefaultfont = "Arial"; // hard code for now |
| 26 | static SkMutex gFTMutex; |
| 27 | |
reed@android.com | 03ca3d1 | 2008-12-22 15:35:46 +0000 | [diff] [blame] | 28 | static inline SkPoint F32PtToSkPoint(const Float32Point p) { |
| 29 | SkPoint sp = { SkFloatToScalar(p.x), SkFloatToScalar(p.y) }; |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 30 | return sp; |
| 31 | } |
| 32 | |
reed@android.com | 03ca3d1 | 2008-12-22 15:35:46 +0000 | [diff] [blame] | 33 | static inline uint32_t _rotl(uint32_t v, uint32_t r) { |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 34 | return (v << r | v >> (32 - r)); |
| 35 | } |
| 36 | |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 37 | class SkTypeface_Mac : public SkTypeface { |
| 38 | public: |
reed@android.com | ea446b9 | 2009-03-09 15:25:11 +0000 | [diff] [blame^] | 39 | SkTypeface_Mac(SkTypeface::Style style, uint32_t id) |
| 40 | : SkTypeface(style, id) {} |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | #pragma mark - |
| 44 | |
reed@android.com | ea446b9 | 2009-03-09 15:25:11 +0000 | [diff] [blame^] | 45 | static uint32_t find_from_name(const char name[]) { |
| 46 | CFStringRef str = CFStringCreateWithCString(NULL, name, |
| 47 | kCFStringEncodingUTF8); |
| 48 | uint32_t fontID = ::ATSFontFindFromName(str, kATSOptionFlagsDefault); |
| 49 | CFRelease(str); |
| 50 | return fontID; |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 51 | } |
| 52 | |
reed@android.com | ea446b9 | 2009-03-09 15:25:11 +0000 | [diff] [blame^] | 53 | static uint32_t find_default_fontID() { |
| 54 | static const char* gDefaultNames[] = { "Arial", "Tahoma", "Helvetica" }; |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 55 | |
reed@android.com | ea446b9 | 2009-03-09 15:25:11 +0000 | [diff] [blame^] | 56 | uint32_t fontID; |
| 57 | for (size_t i = 0; i < SK_ARRAY_COUNT(gDefaultNames); i++) { |
| 58 | fontID = find_from_name(gDefaultNames[i]); |
| 59 | if (fontID) { |
| 60 | return fontID; |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 61 | } |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 62 | } |
reed@android.com | ea446b9 | 2009-03-09 15:25:11 +0000 | [diff] [blame^] | 63 | sk_throw(); |
| 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | static SkTypeface* CreateTypeface_(const char name[], SkTypeface::Style style) { |
| 68 | uint32_t fontID = 0; |
| 69 | if (NULL != name) { |
| 70 | fontID = find_from_name(name); |
| 71 | } |
| 72 | if (0 == fontID) { |
| 73 | fontID = find_default_fontID(); |
| 74 | } |
| 75 | // we lie (for now) and report that we found the exact style bits |
| 76 | return new SkTypeface_Mac(style, fontID); |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | #pragma mark - |
| 80 | |
| 81 | class SkScalerContext_Mac : public SkScalerContext { |
| 82 | public: |
| 83 | SkScalerContext_Mac(const SkDescriptor* desc); |
| 84 | virtual ~SkScalerContext_Mac(); |
| 85 | |
| 86 | protected: |
| 87 | virtual unsigned generateGlyphCount() const; |
| 88 | virtual uint16_t generateCharToGlyph(SkUnichar uni); |
| 89 | virtual void generateAdvance(SkGlyph* glyph); |
| 90 | virtual void generateMetrics(SkGlyph* glyph); |
| 91 | virtual void generateImage(const SkGlyph& glyph); |
| 92 | virtual void generatePath(const SkGlyph& glyph, SkPath* path); |
| 93 | virtual void generateLineHeight(SkPoint* ascent, SkPoint* descent); |
| 94 | virtual void generateFontMetrics(SkPaint::FontMetrics* mX, SkPaint::FontMetrics* mY); |
| 95 | // virtual SkDeviceContext getDC() { return NULL; } // not implemented on Mac |
| 96 | |
| 97 | private: |
| 98 | ATSUTextLayout fLayout; |
| 99 | ATSUStyle fStyle; |
reed@android.com | 76aa34b | 2008-12-23 01:27:39 +0000 | [diff] [blame] | 100 | CGColorSpaceRef fGrayColorSpace; |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 101 | |
| 102 | static OSStatus MoveTo(const Float32Point *pt, void *cb); |
| 103 | static OSStatus Line(const Float32Point *pt, void *cb); |
| 104 | static OSStatus Curve(const Float32Point *pt1, const Float32Point *pt2, const Float32Point *pt3, void *cb); |
| 105 | static OSStatus Close(void *cb); |
| 106 | }; |
| 107 | |
| 108 | SkScalerContext_Mac::SkScalerContext_Mac(const SkDescriptor* desc) |
reed@android.com | ea446b9 | 2009-03-09 15:25:11 +0000 | [diff] [blame^] | 109 | : SkScalerContext(desc), fLayout(0), fStyle(0) { |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 110 | SkAutoMutexAcquire ac(gFTMutex); |
| 111 | OSStatus err; |
| 112 | |
reed@android.com | ea446b9 | 2009-03-09 15:25:11 +0000 | [diff] [blame^] | 113 | err = ::ATSUCreateStyle(&fStyle); |
| 114 | SkASSERT(0 == err); |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 115 | |
reed@android.com | ea446b9 | 2009-03-09 15:25:11 +0000 | [diff] [blame^] | 116 | Fixed fixedSize = SkScalarToFixed(fRec.fTextSize); |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 117 | static const ATSUAttributeTag sizeTag = kATSUSizeTag; |
| 118 | static const ByteCount sizeTagSize = sizeof(Fixed); |
| 119 | const ATSUAttributeValuePtr values[] = { &fixedSize }; |
| 120 | err = ::ATSUSetAttributes(fStyle,1,&sizeTag,&sizeTagSize,values); |
reed@android.com | ea446b9 | 2009-03-09 15:25:11 +0000 | [diff] [blame^] | 121 | SkASSERT(0 == err); |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 122 | |
| 123 | err = ::ATSUCreateTextLayout(&fLayout); |
reed@android.com | ea446b9 | 2009-03-09 15:25:11 +0000 | [diff] [blame^] | 124 | SkASSERT(0 == err); |
reed@android.com | 76aa34b | 2008-12-23 01:27:39 +0000 | [diff] [blame] | 125 | |
| 126 | fGrayColorSpace = ::CGColorSpaceCreateDeviceGray(); |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 127 | } |
| 128 | |
reed@android.com | ea446b9 | 2009-03-09 15:25:11 +0000 | [diff] [blame^] | 129 | SkScalerContext_Mac::~SkScalerContext_Mac() { |
reed@android.com | 76aa34b | 2008-12-23 01:27:39 +0000 | [diff] [blame] | 130 | ::CGColorSpaceRelease(fGrayColorSpace); |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 131 | ::ATSUDisposeTextLayout(fLayout); |
| 132 | ::ATSUDisposeStyle(fStyle); |
| 133 | } |
| 134 | |
reed@android.com | ea446b9 | 2009-03-09 15:25:11 +0000 | [diff] [blame^] | 135 | unsigned SkScalerContext_Mac::generateGlyphCount() const { |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 136 | return 0xFFFF; |
| 137 | } |
| 138 | |
| 139 | uint16_t SkScalerContext_Mac::generateCharToGlyph(SkUnichar uni) |
| 140 | { |
| 141 | SkAutoMutexAcquire ac(gFTMutex); |
| 142 | |
| 143 | OSStatus err; |
| 144 | UniChar achar = uni; |
| 145 | err = ::ATSUSetTextPointerLocation(fLayout,&achar,0,1,1); |
| 146 | err = ::ATSUSetRunStyle(fLayout,fStyle,kATSUFromTextBeginning,kATSUToTextEnd); |
| 147 | |
| 148 | ATSLayoutRecord *layoutPtr; |
| 149 | ItemCount count; |
| 150 | ATSGlyphRef glyph; |
| 151 | |
| 152 | err = ::ATSUDirectGetLayoutDataArrayPtrFromTextLayout(fLayout,0,kATSUDirectDataLayoutRecordATSLayoutRecordCurrent,(void**)&layoutPtr,&count); |
| 153 | glyph = layoutPtr->glyphID; |
| 154 | ::ATSUDirectReleaseLayoutDataArrayPtr(NULL,kATSUDirectDataLayoutRecordATSLayoutRecordCurrent,(void**)&layoutPtr); |
| 155 | return glyph; |
| 156 | } |
| 157 | |
reed@android.com | 76aa34b | 2008-12-23 01:27:39 +0000 | [diff] [blame] | 158 | static void set_glyph_metrics_on_error(SkGlyph* glyph) { |
| 159 | glyph->fRsbDelta = 0; |
| 160 | glyph->fLsbDelta = 0; |
| 161 | glyph->fWidth = 0; |
| 162 | glyph->fHeight = 0; |
| 163 | glyph->fTop = 0; |
| 164 | glyph->fLeft = 0; |
| 165 | glyph->fAdvanceX = 0; |
| 166 | glyph->fAdvanceY = 0; |
| 167 | } |
| 168 | |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 169 | void SkScalerContext_Mac::generateAdvance(SkGlyph* glyph) { |
| 170 | this->generateMetrics(glyph); |
| 171 | } |
| 172 | |
reed@android.com | 76aa34b | 2008-12-23 01:27:39 +0000 | [diff] [blame] | 173 | void SkScalerContext_Mac::generateMetrics(SkGlyph* glyph) { |
| 174 | GlyphID glyphID = glyph->getGlyphID(fBaseGlyphCount); |
reed@android.com | 03ca3d1 | 2008-12-22 15:35:46 +0000 | [diff] [blame] | 175 | ATSGlyphScreenMetrics metrics; |
reed@android.com | 76aa34b | 2008-12-23 01:27:39 +0000 | [diff] [blame] | 176 | |
| 177 | OSStatus err = ATSUGlyphGetScreenMetrics(fStyle, 1, &glyphID, 0, true, true, |
| 178 | &metrics); |
| 179 | if (noErr != err) { |
| 180 | set_glyph_metrics_on_error(glyph); |
| 181 | } else { |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 182 | glyph->fAdvanceX = SkFloatToFixed(metrics.deviceAdvance.x); |
reed@android.com | 03ca3d1 | 2008-12-22 15:35:46 +0000 | [diff] [blame] | 183 | glyph->fAdvanceY = -SkFloatToFixed(metrics.deviceAdvance.y); |
| 184 | glyph->fWidth = metrics.width; |
| 185 | glyph->fHeight = metrics.height; |
reed@android.com | 4df53b0 | 2008-12-22 22:12:55 +0000 | [diff] [blame] | 186 | glyph->fLeft = sk_float_round2int(metrics.topLeft.x); |
reed@android.com | 76aa34b | 2008-12-23 01:27:39 +0000 | [diff] [blame] | 187 | glyph->fTop = -sk_float_round2int(metrics.topLeft.y); |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 188 | } |
| 189 | } |
| 190 | |
reed@android.com | 76aa34b | 2008-12-23 01:27:39 +0000 | [diff] [blame] | 191 | void SkScalerContext_Mac::generateFontMetrics(SkPaint::FontMetrics* mx, |
| 192 | SkPaint::FontMetrics* my) { |
reed@android.com | 03ca3d1 | 2008-12-22 15:35:46 +0000 | [diff] [blame] | 193 | #if 0 |
| 194 | OSStatus ATSFontGetVerticalMetrics ( |
| 195 | ATSFontRef iFont, |
| 196 | ATSOptionFlags iOptions, |
| 197 | ATSFontMetrics *oMetrics |
| 198 | ); |
| 199 | #endif |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 200 | //SkASSERT(false); |
| 201 | if (mx) |
| 202 | memset(mx, 0, sizeof(SkPaint::FontMetrics)); |
| 203 | if (my) |
| 204 | memset(my, 0, sizeof(SkPaint::FontMetrics)); |
| 205 | return; |
| 206 | } |
| 207 | |
| 208 | void SkScalerContext_Mac::generateImage(const SkGlyph& glyph) |
| 209 | { |
| 210 | SkAutoMutexAcquire ac(gFTMutex); |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 211 | SkASSERT(fLayout); |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 212 | |
reed@android.com | 76aa34b | 2008-12-23 01:27:39 +0000 | [diff] [blame] | 213 | bzero(glyph.fImage, glyph.fHeight * glyph.rowBytes()); |
| 214 | CGContextRef contextRef = ::CGBitmapContextCreate(glyph.fImage, |
| 215 | glyph.fWidth, glyph.fHeight, 8, |
| 216 | glyph.rowBytes(), fGrayColorSpace, |
| 217 | kCGImageAlphaNone); |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 218 | if (!contextRef) { |
| 219 | SkASSERT(false); |
| 220 | return; |
| 221 | } |
reed@android.com | 76aa34b | 2008-12-23 01:27:39 +0000 | [diff] [blame] | 222 | |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 223 | ::CGContextSetGrayFillColor(contextRef, 1.0, 1.0); |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 224 | ::CGContextSetTextDrawingMode(contextRef, kCGTextFill); |
| 225 | |
reed@android.com | 60dfdbc | 2009-03-09 14:51:39 +0000 | [diff] [blame] | 226 | CGGlyph glyphID = glyph.getGlyphID(); |
| 227 | CGFontRef fontRef = CGFontCreateWithPlatformFont(&fRec.fFontID); |
| 228 | CGContextSetFont(contextRef, fontRef); |
| 229 | CGContextSetFontSize(contextRef, SkScalarToFloat(fRec.fTextSize)); |
| 230 | CGContextShowGlyphsAtPoint(contextRef, -glyph.fLeft, |
| 231 | glyph.fTop + glyph.fHeight, &glyphID, 1); |
reed@android.com | ea446b9 | 2009-03-09 15:25:11 +0000 | [diff] [blame^] | 232 | |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 233 | ::CGContextRelease(contextRef); |
| 234 | } |
| 235 | |
| 236 | void SkScalerContext_Mac::generatePath(const SkGlyph& glyph, SkPath* path) |
| 237 | { |
| 238 | SkAutoMutexAcquire ac(gFTMutex); |
| 239 | OSStatus err,result; |
| 240 | |
| 241 | err = ::ATSUGlyphGetCubicPaths( |
| 242 | fStyle,glyph.fID, |
| 243 | &SkScalerContext_Mac::MoveTo, |
| 244 | &SkScalerContext_Mac::Line, |
| 245 | &SkScalerContext_Mac::Curve, |
| 246 | &SkScalerContext_Mac::Close, |
| 247 | path,&result); |
| 248 | SkASSERT(err == noErr); |
| 249 | } |
| 250 | |
| 251 | void SkScalerContext_Mac::generateLineHeight(SkPoint* ascent, SkPoint* descent) |
| 252 | { |
| 253 | ATSUTextMeasurement textAscent, textDescent; |
| 254 | ByteCount actual = 0; |
| 255 | OSStatus err = ::ATSUGetAttribute(fStyle,kATSULineAscentTag,sizeof(ATSUTextMeasurement),&textAscent,&actual); |
| 256 | ascent->set(0,textAscent); |
| 257 | err = ::ATSUGetAttribute(fStyle,kATSULineDescentTag,sizeof(ATSUTextMeasurement),&textDescent,&actual); |
| 258 | descent->set(0,textDescent); |
| 259 | } |
| 260 | |
| 261 | OSStatus SkScalerContext_Mac::MoveTo(const Float32Point *pt, void *cb) |
| 262 | { |
| 263 | reinterpret_cast<SkPath*>(cb)->moveTo(F32PtToSkPoint(*pt)); |
| 264 | return noErr; |
| 265 | } |
| 266 | |
| 267 | OSStatus SkScalerContext_Mac::Line(const Float32Point *pt, void *cb) |
| 268 | { |
| 269 | reinterpret_cast<SkPath*>(cb)->lineTo(F32PtToSkPoint(*pt)); |
| 270 | return noErr; |
| 271 | } |
| 272 | |
reed@android.com | 03ca3d1 | 2008-12-22 15:35:46 +0000 | [diff] [blame] | 273 | OSStatus SkScalerContext_Mac::Curve(const Float32Point *pt1, |
| 274 | const Float32Point *pt2, |
| 275 | const Float32Point *pt3, void *cb) |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 276 | { |
reed@android.com | 03ca3d1 | 2008-12-22 15:35:46 +0000 | [diff] [blame] | 277 | reinterpret_cast<SkPath*>(cb)->cubicTo(F32PtToSkPoint(*pt1), |
| 278 | F32PtToSkPoint(*pt2), |
| 279 | F32PtToSkPoint(*pt3)); |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 280 | return noErr; |
| 281 | } |
| 282 | |
| 283 | OSStatus SkScalerContext_Mac::Close(void *cb) |
| 284 | { |
| 285 | reinterpret_cast<SkPath*>(cb)->close(); |
| 286 | return noErr; |
| 287 | } |
| 288 | |
| 289 | #pragma mark - |
| 290 | |
| 291 | void SkFontHost::Serialize(const SkTypeface* face, SkWStream* stream) { |
| 292 | SkASSERT(!"SkFontHost::Serialize unimplemented"); |
| 293 | } |
| 294 | |
| 295 | SkTypeface* SkFontHost::Deserialize(SkStream* stream) { |
| 296 | SkASSERT(!"SkFontHost::Deserialize unimplemented"); |
| 297 | return NULL; |
| 298 | } |
| 299 | |
reed@android.com | b1d9d2e | 2009-03-04 17:37:51 +0000 | [diff] [blame] | 300 | SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { |
reed@android.com | ea446b9 | 2009-03-09 15:25:11 +0000 | [diff] [blame^] | 301 | return NULL; |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 302 | } |
| 303 | |
reed@android.com | 03ca3d1 | 2008-12-22 15:35:46 +0000 | [diff] [blame] | 304 | SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) { |
reed@android.com | ea446b9 | 2009-03-09 15:25:11 +0000 | [diff] [blame^] | 305 | return NULL; |
reed@android.com | 03ca3d1 | 2008-12-22 15:35:46 +0000 | [diff] [blame] | 306 | } |
| 307 | |
reed@android.com | ea446b9 | 2009-03-09 15:25:11 +0000 | [diff] [blame^] | 308 | SkScalerContext* SkFontHost::CreateScalerContext(const SkDescriptor* desc) { |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 309 | return new SkScalerContext_Mac(desc); |
| 310 | } |
| 311 | |
| 312 | SkScalerContext* SkFontHost::CreateFallbackScalerContext(const SkScalerContext::Rec& rec) |
| 313 | { |
reed@android.com | ea446b9 | 2009-03-09 15:25:11 +0000 | [diff] [blame^] | 314 | SkAutoDescriptor ad(sizeof(rec) + SkDescriptor::ComputeOverhead(1)); |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 315 | SkDescriptor* desc = ad.getDesc(); |
reed@android.com | ea446b9 | 2009-03-09 15:25:11 +0000 | [diff] [blame^] | 316 | |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 317 | desc->init(); |
| 318 | SkScalerContext::Rec* newRec = |
reed@android.com | ea446b9 | 2009-03-09 15:25:11 +0000 | [diff] [blame^] | 319 | (SkScalerContext::Rec*)desc->addEntry(kRec_SkDescriptorTag, |
| 320 | sizeof(rec), &rec); |
| 321 | newRec->fFontID = find_default_fontID(); |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 322 | desc->computeChecksum(); |
reed@android.com | ea446b9 | 2009-03-09 15:25:11 +0000 | [diff] [blame^] | 323 | |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 324 | return SkFontHost::CreateScalerContext(desc); |
| 325 | } |
| 326 | |
reed@android.com | b1d9d2e | 2009-03-04 17:37:51 +0000 | [diff] [blame] | 327 | SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, |
| 328 | const char familyName[], SkTypeface::Style style) { |
reed@android.com | ea446b9 | 2009-03-09 15:25:11 +0000 | [diff] [blame^] | 329 | // todo: we don't know how to respect style bits |
| 330 | if (NULL == familyName && NULL != familyFace) { |
| 331 | familyFace->ref(); |
| 332 | return const_cast<SkTypeface*>(familyFace); |
| 333 | } else { |
| 334 | return CreateTypeface_(familyName, style); |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 335 | } |
reed@android.com | 0680d6c | 2008-12-19 19:46:15 +0000 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | size_t SkFontHost::ShouldPurgeFontCache(size_t sizeAllocatedSoFar) { |
| 339 | if (sizeAllocatedSoFar > FONT_CACHE_MEMORY_BUDGET) |
| 340 | return sizeAllocatedSoFar - FONT_CACHE_MEMORY_BUDGET; |
| 341 | else |
| 342 | return 0; // nothing to do |
| 343 | } |
| 344 | |
| 345 | int SkFontHost::ComputeGammaFlag(const SkPaint& paint) { |
| 346 | return 0; |
| 347 | } |
| 348 | |
| 349 | void SkFontHost::GetGammaTables(const uint8_t* tables[2]) { |
| 350 | tables[0] = NULL; // black gamma (e.g. exp=1.4) |
| 351 | tables[1] = NULL; // white gamma (e.g. exp= 1/1.4) |
| 352 | } |
| 353 | |