| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 #ifdef SK_BUILD_FOR_MAC | 10 #ifdef SK_BUILD_FOR_MAC |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 #include "SkOTUtils.h" | 35 #include "SkOTUtils.h" |
| 36 #include "SkPaint.h" | 36 #include "SkPaint.h" |
| 37 #include "SkPath.h" | 37 #include "SkPath.h" |
| 38 #include "SkString.h" | 38 #include "SkString.h" |
| 39 #include "SkStream.h" | 39 #include "SkStream.h" |
| 40 #include "SkThread.h" | 40 #include "SkThread.h" |
| 41 #include "SkTypeface_mac.h" | 41 #include "SkTypeface_mac.h" |
| 42 #include "SkUtils.h" | 42 #include "SkUtils.h" |
| 43 #include "SkTypefaceCache.h" | 43 #include "SkTypefaceCache.h" |
| 44 #include "SkFontMgr.h" | 44 #include "SkFontMgr.h" |
| 45 #include "SkUtils.h" |
| 45 | 46 |
| 46 //#define HACK_COLORGLYPHS | 47 //#define HACK_COLORGLYPHS |
| 47 | 48 |
| 48 class SkScalerContext_Mac; | 49 class SkScalerContext_Mac; |
| 49 | 50 |
| 50 // CTFontManagerCopyAvailableFontFamilyNames() is not always available, so we | 51 // CTFontManagerCopyAvailableFontFamilyNames() is not always available, so we |
| 51 // provide a wrapper here that will return an empty array if need be. | 52 // provide a wrapper here that will return an empty array if need be. |
| 52 static CFArrayRef SkCTFontManagerCopyAvailableFontFamilyNames() { | 53 static CFArrayRef SkCTFontManagerCopyAvailableFontFamilyNames() { |
| 53 #ifdef SK_BUILD_FOR_IOS | 54 #ifdef SK_BUILD_FOR_IOS |
| 54 return CFArrayCreate(NULL, NULL, 0, NULL); | 55 return CFArrayCreate(NULL, NULL, 0, NULL); |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE; | 455 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE; |
| 455 virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE; | 456 virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE; |
| 456 virtual size_t onGetTableData(SkFontTableTag, size_t offset, | 457 virtual size_t onGetTableData(SkFontTableTag, size_t offset, |
| 457 size_t length, void* data) const SK_OVERRIDE; | 458 size_t length, void* data) const SK_OVERRIDE; |
| 458 virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK
_OVERRIDE; | 459 virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK
_OVERRIDE; |
| 459 virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE; | 460 virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE; |
| 460 virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE
; | 461 virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE
; |
| 461 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( | 462 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( |
| 462 SkAdvancedTypefaceMetrics::PerGlyphInfo, | 463 SkAdvancedTypefaceMetrics::PerGlyphInfo, |
| 463 const uint32_t*, uint32_t) const SK_OVERRIDE; | 464 const uint32_t*, uint32_t) const SK_OVERRIDE; |
| 465 virtual int onCharsToGlyphs(const void* chars, Encoding, uint16_t glyphs[], |
| 466 int glyphCount) const SK_OVERRIDE; |
| 467 virtual int onCountGlyphs() const SK_OVERRIDE; |
| 464 | 468 |
| 465 private: | 469 private: |
| 466 | 470 |
| 467 typedef SkTypeface INHERITED; | 471 typedef SkTypeface INHERITED; |
| 468 }; | 472 }; |
| 469 | 473 |
| 470 static SkTypeface* NewFromFontRef(CTFontRef fontRef, const char name[]) { | 474 static SkTypeface* NewFromFontRef(CTFontRef fontRef, const char name[]) { |
| 471 SkASSERT(fontRef); | 475 SkASSERT(fontRef); |
| 472 bool isFixedPitch; | 476 bool isFixedPitch; |
| 473 SkTypeface::Style style = computeStyleBits(fontRef, &isFixedPitch); | 477 SkTypeface::Style style = computeStyleBits(fontRef, &isFixedPitch); |
| (...skipping 1419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1893 bool* isLocalStream) const { | 1897 bool* isLocalStream) const { |
| 1894 SkString tmpStr; | 1898 SkString tmpStr; |
| 1895 | 1899 |
| 1896 desc->setFamilyName(get_str(CTFontCopyFamilyName(fFontRef), &tmpStr)); | 1900 desc->setFamilyName(get_str(CTFontCopyFamilyName(fFontRef), &tmpStr)); |
| 1897 desc->setFullName(get_str(CTFontCopyFullName(fFontRef), &tmpStr)); | 1901 desc->setFullName(get_str(CTFontCopyFullName(fFontRef), &tmpStr)); |
| 1898 desc->setPostscriptName(get_str(CTFontCopyPostScriptName(fFontRef), &tmpStr)
); | 1902 desc->setPostscriptName(get_str(CTFontCopyPostScriptName(fFontRef), &tmpStr)
); |
| 1899 // TODO: need to add support for local-streams (here and openStream) | 1903 // TODO: need to add support for local-streams (here and openStream) |
| 1900 *isLocalStream = false; | 1904 *isLocalStream = false; |
| 1901 } | 1905 } |
| 1902 | 1906 |
| 1907 int SkTypeface_Mac::onCharsToGlyphs(const void* chars, Encoding encoding, |
| 1908 uint16_t glyphs[], int glyphCount) const { |
| 1909 // UniChar is utf16 |
| 1910 SkAutoSTMalloc<1024, UniChar> charStorage; |
| 1911 const UniChar* src; |
| 1912 switch (encoding) { |
| 1913 case kUTF8_Encoding: { |
| 1914 const char* u8 = (const char*)chars; |
| 1915 const UniChar* u16 = src = charStorage.reset(2 * glyphCount); |
| 1916 for (int i = 0; i < glyphCount; ++i) { |
| 1917 SkUnichar uni = SkUTF8_NextUnichar(&u8); |
| 1918 int n = SkUTF16_FromUnichar(uni, (uint16_t*)u16); |
| 1919 u16 += n; |
| 1920 } |
| 1921 break; |
| 1922 } |
| 1923 case kUTF16_Encoding: |
| 1924 src = (const UniChar*)chars; |
| 1925 break; |
| 1926 case kUTF32_Encoding: { |
| 1927 const SkUnichar* u32 = (const SkUnichar*)chars; |
| 1928 const UniChar* u16 = src = charStorage.reset(2 * glyphCount); |
| 1929 for (int i = 0; i < glyphCount; ++i) { |
| 1930 int n = SkUTF16_FromUnichar(u32[i], (uint16_t*)u16); |
| 1931 u16 += n; |
| 1932 } |
| 1933 break; |
| 1934 } |
| 1935 } |
| 1936 |
| 1937 // Our caller may not want glyphs for output, but we need to give that |
| 1938 // storage to CT, so we can walk it looking for the first non-zero. |
| 1939 SkAutoSTMalloc<1024, uint16_t> glyphStorage; |
| 1940 uint16_t* macGlyphs = glyphs; |
| 1941 if (NULL == macGlyphs) { |
| 1942 macGlyphs = glyphStorage.reset(glyphCount); |
| 1943 } |
| 1944 |
| 1945 if (CTFontGetGlyphsForCharacters(fFontRef, src, macGlyphs, glyphCount)) { |
| 1946 return glyphCount; |
| 1947 } |
| 1948 // If we got false, then we need to manually look for first failure |
| 1949 for (int i = 0; i < glyphCount; ++i) { |
| 1950 if (0 == macGlyphs[i]) { |
| 1951 return i; |
| 1952 } |
| 1953 } |
| 1954 // odd to get here, as we expected CT to have returned true up front. |
| 1955 return glyphCount; |
| 1956 } |
| 1957 |
| 1958 int SkTypeface_Mac::onCountGlyphs() const { |
| 1959 return CTFontGetGlyphCount(fFontRef); |
| 1960 } |
| 1961 |
| 1903 /////////////////////////////////////////////////////////////////////////////// | 1962 /////////////////////////////////////////////////////////////////////////////// |
| 1904 /////////////////////////////////////////////////////////////////////////////// | 1963 /////////////////////////////////////////////////////////////////////////////// |
| 1905 #if 1 | 1964 #if 1 |
| 1906 | 1965 |
| 1907 static bool find_desc_str(CTFontDescriptorRef desc, CFStringRef name, SkString*
value) { | 1966 static bool find_desc_str(CTFontDescriptorRef desc, CFStringRef name, SkString*
value) { |
| 1908 AutoCFRelease<CFStringRef> ref((CFStringRef)CTFontDescriptorCopyAttribute(de
sc, name)); | 1967 AutoCFRelease<CFStringRef> ref((CFStringRef)CTFontDescriptorCopyAttribute(de
sc, name)); |
| 1909 if (NULL == ref.get()) { | 1968 if (NULL == ref.get()) { |
| 1910 return false; | 1969 return false; |
| 1911 } | 1970 } |
| 1912 CFStringToSkString(ref, value); | 1971 CFStringToSkString(ref, value); |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2198 return NULL; | 2257 return NULL; |
| 2199 } | 2258 } |
| 2200 return create_from_dataProvider(pr); | 2259 return create_from_dataProvider(pr); |
| 2201 } | 2260 } |
| 2202 }; | 2261 }; |
| 2203 | 2262 |
| 2204 SkFontMgr* SkFontMgr::Factory() { | 2263 SkFontMgr* SkFontMgr::Factory() { |
| 2205 return SkNEW(SkFontMgr_Mac); | 2264 return SkNEW(SkFontMgr_Mac); |
| 2206 } | 2265 } |
| 2207 #endif | 2266 #endif |
| OLD | NEW |