OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkTypes.h" // Keep this before any #ifdef ... | 8 #include "SkTypes.h" // Keep this before any #ifdef ... |
9 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) | 9 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) |
10 | 10 |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 if (!find_dict_float(dict, kCTFontWidthTrait, &width)) { | 410 if (!find_dict_float(dict, kCTFontWidthTrait, &width)) { |
411 width = 0; | 411 width = 0; |
412 } | 412 } |
413 if (!find_dict_float(dict, kCTFontSlantTrait, &slant)) { | 413 if (!find_dict_float(dict, kCTFontSlantTrait, &slant)) { |
414 slant = 0; | 414 slant = 0; |
415 } | 415 } |
416 | 416 |
417 return SkFontStyle(unit_weight_to_fontstyle(weight), | 417 return SkFontStyle(unit_weight_to_fontstyle(weight), |
418 unit_width_to_fontstyle(width), | 418 unit_width_to_fontstyle(width), |
419 slant ? SkFontStyle::kItalic_Slant | 419 slant ? SkFontStyle::kItalic_Slant |
420 : SkFontStyle::kUpright_Slant); | 420 : SkFontStyle::kUpright_Slant); |
421 } | 421 } |
422 | 422 |
423 #define WEIGHT_THRESHOLD ((SkFontStyle::kNormal_Weight + SkFontStyle::kBold_W
eight)/2) | 423 #define WEIGHT_THRESHOLD ((SkFontStyle::kNormal_Weight + SkFontStyle::kBold_W
eight)/2) |
424 | 424 |
425 // kCTFontColorGlyphsTrait was added in the Mac 10.7 and iPhone 4.3 SDKs. | 425 // kCTFontColorGlyphsTrait was added in the Mac 10.7 and iPhone 4.3 SDKs. |
426 // Being an enum value it is not guarded by version macros, but old SDKs must st
ill be supported. | 426 // Being an enum value it is not guarded by version macros, but old SDKs must st
ill be supported. |
427 #if defined(__MAC_10_7) || defined(__IPHONE_4_3) | 427 #if defined(__MAC_10_7) || defined(__IPHONE_4_3) |
428 static const uint32_t SkCTFontColorGlyphsTrait = kCTFontColorGlyphsTrait; | 428 static const uint32_t SkCTFontColorGlyphsTrait = kCTFontColorGlyphsTrait; |
429 #else | 429 #else |
430 static const uint32_t SkCTFontColorGlyphsTrait = (1 << 13); | 430 static const uint32_t SkCTFontColorGlyphsTrait = (1 << 13); |
(...skipping 1713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2144 | 2144 |
2145 static inline int sqr(int value) { | 2145 static inline int sqr(int value) { |
2146 SkASSERT(SkAbs32(value) < 0x7FFF); // check for overflow | 2146 SkASSERT(SkAbs32(value) < 0x7FFF); // check for overflow |
2147 return value * value; | 2147 return value * value; |
2148 } | 2148 } |
2149 | 2149 |
2150 // We normalize each axis (weight, width, italic) to be base-900 | 2150 // We normalize each axis (weight, width, italic) to be base-900 |
2151 static int compute_metric(const SkFontStyle& a, const SkFontStyle& b) { | 2151 static int compute_metric(const SkFontStyle& a, const SkFontStyle& b) { |
2152 return sqr(a.weight() - b.weight()) + | 2152 return sqr(a.weight() - b.weight()) + |
2153 sqr((a.width() - b.width()) * 100) + | 2153 sqr((a.width() - b.width()) * 100) + |
2154 sqr((a.isItalic() != b.isItalic()) * 900); | 2154 sqr((a.slant() != b.slant()) * 900); |
2155 } | 2155 } |
2156 | 2156 |
2157 static SkTypeface* createFromDesc(CTFontDescriptorRef desc) { | 2157 static SkTypeface* createFromDesc(CTFontDescriptorRef desc) { |
2158 AutoCFRelease<CTFontRef> ctFont(CTFontCreateWithFontDescriptor(desc, 0, null
ptr)); | 2158 AutoCFRelease<CTFontRef> ctFont(CTFontCreateWithFontDescriptor(desc, 0, null
ptr)); |
2159 if (!ctFont) { | 2159 if (!ctFont) { |
2160 return nullptr; | 2160 return nullptr; |
2161 } | 2161 } |
2162 | 2162 |
2163 SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_CTFontRef, (voi
d*)ctFont.get()); | 2163 SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_CTFontRef, (voi
d*)ctFont.get()); |
2164 if (face) { | 2164 if (face) { |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2575 | 2575 |
2576 return SkSafeRef(GetDefaultFace()); | 2576 return SkSafeRef(GetDefaultFace()); |
2577 } | 2577 } |
2578 }; | 2578 }; |
2579 | 2579 |
2580 /////////////////////////////////////////////////////////////////////////////// | 2580 /////////////////////////////////////////////////////////////////////////////// |
2581 | 2581 |
2582 SkFontMgr* SkFontMgr::Factory() { return new SkFontMgr_Mac; } | 2582 SkFontMgr* SkFontMgr::Factory() { return new SkFontMgr_Mac; } |
2583 | 2583 |
2584 #endif//defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) | 2584 #endif//defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) |
OLD | NEW |