Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(859)

Side by Side Diff: src/ports/SkFontHost_mac.cpp

Issue 147683003: fix more 64bit warnings (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/core/SkPictureFlat.h ('k') | src/ports/SkImageDecoder_CG.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 return rect.origin.y + rect.size.height; 142 return rect.origin.y + rect.size.height;
143 } 143 }
144 144
145 static CGFloat CGRectGetWidth_inline(const CGRect& rect) { 145 static CGFloat CGRectGetWidth_inline(const CGRect& rect) {
146 return rect.size.width; 146 return rect.size.width;
147 } 147 }
148 148
149 /////////////////////////////////////////////////////////////////////////////// 149 ///////////////////////////////////////////////////////////////////////////////
150 150
151 static void sk_memset_rect32(uint32_t* ptr, uint32_t value, 151 static void sk_memset_rect32(uint32_t* ptr, uint32_t value,
152 size_t width, size_t height, size_t rowBytes) { 152 int width, int height, size_t rowBytes) {
153 SkASSERT(width); 153 SkASSERT(width);
154 SkASSERT(width * sizeof(uint32_t) <= rowBytes); 154 SkASSERT(width * sizeof(uint32_t) <= rowBytes);
155 155
156 if (width >= 32) { 156 if (width >= 32) {
157 while (height) { 157 while (height) {
158 sk_memset32(ptr, value, width); 158 sk_memset32(ptr, value, width);
159 ptr = (uint32_t*)((char*)ptr + rowBytes); 159 ptr = (uint32_t*)((char*)ptr + rowBytes);
160 height -= 1; 160 height -= 1;
161 } 161 }
162 return; 162 return;
(...skipping 1271 matching lines...) Expand 10 before | Expand all | Expand 10 after
1434 } 1434 }
1435 CTFontRef ct = CTFontCreateWithGraphicsFont(cg, 0, NULL, NULL); 1435 CTFontRef ct = CTFontCreateWithGraphicsFont(cg, 0, NULL, NULL);
1436 return cg ? SkCreateTypefaceFromCTFont(ct) : NULL; 1436 return cg ? SkCreateTypefaceFromCTFont(ct) : NULL;
1437 } 1437 }
1438 1438
1439 // Web fonts added to the the CTFont registry do not return their character set. 1439 // Web fonts added to the the CTFont registry do not return their character set.
1440 // Iterate through the font in this case. The existing caller caches the result, 1440 // Iterate through the font in this case. The existing caller caches the result,
1441 // so the performance impact isn't too bad. 1441 // so the performance impact isn't too bad.
1442 static void populate_glyph_to_unicode_slow(CTFontRef ctFont, CFIndex glyphCount, 1442 static void populate_glyph_to_unicode_slow(CTFontRef ctFont, CFIndex glyphCount,
1443 SkTDArray<SkUnichar>* glyphToUnicode) { 1443 SkTDArray<SkUnichar>* glyphToUnicode) {
1444 glyphToUnicode->setCount(glyphCount); 1444 glyphToUnicode->setCount(SkToInt(glyphCount));
1445 SkUnichar* out = glyphToUnicode->begin(); 1445 SkUnichar* out = glyphToUnicode->begin();
1446 sk_bzero(out, glyphCount * sizeof(SkUnichar)); 1446 sk_bzero(out, glyphCount * sizeof(SkUnichar));
1447 UniChar unichar = 0; 1447 UniChar unichar = 0;
1448 while (glyphCount > 0) { 1448 while (glyphCount > 0) {
1449 CGGlyph glyph; 1449 CGGlyph glyph;
1450 if (CTFontGetGlyphsForCharacters(ctFont, &unichar, &glyph, 1)) { 1450 if (CTFontGetGlyphsForCharacters(ctFont, &unichar, &glyph, 1)) {
1451 out[glyph] = unichar; 1451 out[glyph] = unichar;
1452 --glyphCount; 1452 --glyphCount;
1453 } 1453 }
1454 if (++unichar == 0) { 1454 if (++unichar == 0) {
(...skipping 23 matching lines...) Expand all
1478 return; 1478 return;
1479 } 1479 }
1480 if (length > 8192) { 1480 if (length > 8192) {
1481 // TODO: Add support for Unicode above 0xFFFF 1481 // TODO: Add support for Unicode above 0xFFFF
1482 // Consider only the BMP portion of the Unicode character points. 1482 // Consider only the BMP portion of the Unicode character points.
1483 // The bitmap may contain other planes, up to plane 16. 1483 // The bitmap may contain other planes, up to plane 16.
1484 // See http://developer.apple.com/library/ios/#documentation/CoreFoundat ion/Reference/CFCharacterSetRef/Reference/reference.html 1484 // See http://developer.apple.com/library/ios/#documentation/CoreFoundat ion/Reference/CFCharacterSetRef/Reference/reference.html
1485 length = 8192; 1485 length = 8192;
1486 } 1486 }
1487 const UInt8* bits = CFDataGetBytePtr(bitmap); 1487 const UInt8* bits = CFDataGetBytePtr(bitmap);
1488 glyphToUnicode->setCount(glyphCount); 1488 glyphToUnicode->setCount(SkToInt(glyphCount));
1489 SkUnichar* out = glyphToUnicode->begin(); 1489 SkUnichar* out = glyphToUnicode->begin();
1490 sk_bzero(out, glyphCount * sizeof(SkUnichar)); 1490 sk_bzero(out, glyphCount * sizeof(SkUnichar));
1491 for (int i = 0; i < length; i++) { 1491 for (int i = 0; i < length; i++) {
1492 int mask = bits[i]; 1492 int mask = bits[i];
1493 if (!mask) { 1493 if (!mask) {
1494 continue; 1494 continue;
1495 } 1495 }
1496 for (int j = 0; j < 8; j++) { 1496 for (int j = 0; j < 8; j++) {
1497 CGGlyph glyph; 1497 CGGlyph glyph;
1498 UniChar unichar = static_cast<UniChar>((i << 3) + j); 1498 UniChar unichar = static_cast<UniChar>((i << 3) + j);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1618 info->fType = SkAdvancedTypefaceMetrics::kNotEmbeddable_Font; 1618 info->fType = SkAdvancedTypefaceMetrics::kNotEmbeddable_Font;
1619 } else if (perGlyphInfo & SkAdvancedTypefaceMetrics::kHAdvance_PerGlyphInfo) { 1619 } else if (perGlyphInfo & SkAdvancedTypefaceMetrics::kHAdvance_PerGlyphInfo) {
1620 if (info->fStyle & SkAdvancedTypefaceMetrics::kFixedPitch_Style) { 1620 if (info->fStyle & SkAdvancedTypefaceMetrics::kFixedPitch_Style) {
1621 skia_advanced_typeface_metrics_utils::appendRange(&info->fGlyphWidth s, 0); 1621 skia_advanced_typeface_metrics_utils::appendRange(&info->fGlyphWidth s, 0);
1622 info->fGlyphWidths->fAdvance.append(1, &min_width); 1622 info->fGlyphWidths->fAdvance.append(1, &min_width);
1623 skia_advanced_typeface_metrics_utils::finishRange(info->fGlyphWidths .get(), 0, 1623 skia_advanced_typeface_metrics_utils::finishRange(info->fGlyphWidths .get(), 0,
1624 SkAdvancedTypefaceMetrics::WidthRange::kDefault); 1624 SkAdvancedTypefaceMetrics::WidthRange::kDefault);
1625 } else { 1625 } else {
1626 info->fGlyphWidths.reset( 1626 info->fGlyphWidths.reset(
1627 skia_advanced_typeface_metrics_utils::getAdvanceData(ctFont.get( ), 1627 skia_advanced_typeface_metrics_utils::getAdvanceData(ctFont.get( ),
1628 glyphCount, 1628 SkToInt(glyphCount),
1629 glyphIDs, 1629 glyphIDs,
1630 glyphIDsCount, 1630 glyphIDsCount,
1631 &getWidthAdvance)); 1631 &getWidthAdvance));
1632 } 1632 }
1633 } 1633 }
1634 return info; 1634 return info;
1635 } 1635 }
1636 1636
1637 /////////////////////////////////////////////////////////////////////////////// 1637 ///////////////////////////////////////////////////////////////////////////////
1638 1638
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1717 1717
1718 // write tables 1718 // write tables
1719 SkSFNTHeader::TableDirectoryEntry* entry = (SkSFNTHeader::TableDirectoryEntr y*)dataPtr; 1719 SkSFNTHeader::TableDirectoryEntry* entry = (SkSFNTHeader::TableDirectoryEntr y*)dataPtr;
1720 dataPtr += sizeof(SkSFNTHeader::TableDirectoryEntry) * numTables; 1720 dataPtr += sizeof(SkSFNTHeader::TableDirectoryEntry) * numTables;
1721 for (int tableIndex = 0; tableIndex < numTables; ++tableIndex) { 1721 for (int tableIndex = 0; tableIndex < numTables; ++tableIndex) {
1722 size_t tableSize = tableSizes[tableIndex]; 1722 size_t tableSize = tableSizes[tableIndex];
1723 this->getTableData(tableTags[tableIndex], 0, tableSize, dataPtr); 1723 this->getTableData(tableTags[tableIndex], 0, tableSize, dataPtr);
1724 entry->tag = SkEndian_SwapBE32(tableTags[tableIndex]); 1724 entry->tag = SkEndian_SwapBE32(tableTags[tableIndex]);
1725 entry->checksum = SkEndian_SwapBE32(SkOTUtils::CalcTableChecksum((SK_OT_ ULONG*)dataPtr, 1725 entry->checksum = SkEndian_SwapBE32(SkOTUtils::CalcTableChecksum((SK_OT_ ULONG*)dataPtr,
1726 tableSi ze)); 1726 tableSi ze));
1727 entry->offset = SkEndian_SwapBE32(dataPtr - dataStart); 1727 entry->offset = SkEndian_SwapBE32(SkToU32(dataPtr - dataStart));
1728 entry->logicalLength = SkEndian_SwapBE32(tableSize); 1728 entry->logicalLength = SkEndian_SwapBE32(SkToU32(tableSize));
1729 1729
1730 dataPtr += (tableSize + 3) & ~3; 1730 dataPtr += (tableSize + 3) & ~3;
1731 ++entry; 1731 ++entry;
1732 } 1732 }
1733 1733
1734 return stream; 1734 return stream;
1735 } 1735 }
1736 1736
1737 /////////////////////////////////////////////////////////////////////////////// 1737 ///////////////////////////////////////////////////////////////////////////////
1738 /////////////////////////////////////////////////////////////////////////////// 1738 ///////////////////////////////////////////////////////////////////////////////
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1778 } 1778 }
1779 return data; 1779 return data;
1780 } 1780 }
1781 1781
1782 int SkTypeface_Mac::onGetTableTags(SkFontTableTag tags[]) const { 1782 int SkTypeface_Mac::onGetTableTags(SkFontTableTag tags[]) const {
1783 AutoCFRelease<CFArrayRef> cfArray(CTFontCopyAvailableTables(fFontRef, 1783 AutoCFRelease<CFArrayRef> cfArray(CTFontCopyAvailableTables(fFontRef,
1784 kCTFontTableOptionNoOptions)); 1784 kCTFontTableOptionNoOptions));
1785 if (NULL == cfArray) { 1785 if (NULL == cfArray) {
1786 return 0; 1786 return 0;
1787 } 1787 }
1788 int count = CFArrayGetCount(cfArray); 1788 int count = SkToInt(CFArrayGetCount(cfArray));
1789 if (tags) { 1789 if (tags) {
1790 for (int i = 0; i < count; ++i) { 1790 for (int i = 0; i < count; ++i) {
1791 uintptr_t fontTag = reinterpret_cast<uintptr_t>(CFArrayGetValueAtInd ex(cfArray, i)); 1791 uintptr_t fontTag = reinterpret_cast<uintptr_t>(CFArrayGetValueAtInd ex(cfArray, i));
1792 tags[i] = static_cast<SkFontTableTag>(fontTag); 1792 tags[i] = static_cast<SkFontTableTag>(fontTag);
1793 } 1793 }
1794 } 1794 }
1795 return count; 1795 return count;
1796 } 1796 }
1797 1797
1798 size_t SkTypeface_Mac::onGetTableData(SkFontTableTag tag, size_t offset, 1798 size_t SkTypeface_Mac::onGetTableData(SkFontTableTag tag, size_t offset,
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1923 int srcCount; 1923 int srcCount;
1924 switch (encoding) { 1924 switch (encoding) {
1925 case kUTF8_Encoding: { 1925 case kUTF8_Encoding: {
1926 const char* utf8 = reinterpret_cast<const char*>(chars); 1926 const char* utf8 = reinterpret_cast<const char*>(chars);
1927 UniChar* utf16 = charStorage.reset(2 * glyphCount); 1927 UniChar* utf16 = charStorage.reset(2 * glyphCount);
1928 src = utf16; 1928 src = utf16;
1929 for (int i = 0; i < glyphCount; ++i) { 1929 for (int i = 0; i < glyphCount; ++i) {
1930 SkUnichar uni = SkUTF8_NextUnichar(&utf8); 1930 SkUnichar uni = SkUTF8_NextUnichar(&utf8);
1931 utf16 += SkUTF16_FromUnichar(uni, utf16); 1931 utf16 += SkUTF16_FromUnichar(uni, utf16);
1932 } 1932 }
1933 srcCount = utf16 - src; 1933 srcCount = SkToInt(utf16 - src);
1934 break; 1934 break;
1935 } 1935 }
1936 case kUTF16_Encoding: { 1936 case kUTF16_Encoding: {
1937 src = reinterpret_cast<const UniChar*>(chars); 1937 src = reinterpret_cast<const UniChar*>(chars);
1938 int extra = 0; 1938 int extra = 0;
1939 for (int i = 0; i < glyphCount; ++i) { 1939 for (int i = 0; i < glyphCount; ++i) {
1940 if (SkUTF16_IsHighSurrogate(src[i + extra])) { 1940 if (SkUTF16_IsHighSurrogate(src[i + extra])) {
1941 ++extra; 1941 ++extra;
1942 } 1942 }
1943 } 1943 }
1944 srcCount = glyphCount + extra; 1944 srcCount = glyphCount + extra;
1945 break; 1945 break;
1946 } 1946 }
1947 case kUTF32_Encoding: { 1947 case kUTF32_Encoding: {
1948 const SkUnichar* utf32 = reinterpret_cast<const SkUnichar*>(chars); 1948 const SkUnichar* utf32 = reinterpret_cast<const SkUnichar*>(chars);
1949 UniChar* utf16 = charStorage.reset(2 * glyphCount); 1949 UniChar* utf16 = charStorage.reset(2 * glyphCount);
1950 src = utf16; 1950 src = utf16;
1951 for (int i = 0; i < glyphCount; ++i) { 1951 for (int i = 0; i < glyphCount; ++i) {
1952 utf16 += SkUTF16_FromUnichar(utf32[i], utf16); 1952 utf16 += SkUTF16_FromUnichar(utf32[i], utf16);
1953 } 1953 }
1954 srcCount = utf16 - src; 1954 srcCount = SkToInt(utf16 - src);
1955 break; 1955 break;
1956 } 1956 }
1957 } 1957 }
1958 1958
1959 // If glyphs is NULL, CT still needs glyph storage for finding the first fai lure. 1959 // If glyphs is NULL, CT still needs glyph storage for finding the first fai lure.
1960 // Also, if there are any non-bmp code points, the provided 'glyphs' storage will be inadequate. 1960 // Also, if there are any non-bmp code points, the provided 'glyphs' storage will be inadequate.
1961 SkAutoSTMalloc<1024, uint16_t> glyphStorage; 1961 SkAutoSTMalloc<1024, uint16_t> glyphStorage;
1962 uint16_t* macGlyphs = glyphs; 1962 uint16_t* macGlyphs = glyphs;
1963 if (NULL == macGlyphs || srcCount > glyphCount) { 1963 if (NULL == macGlyphs || srcCount > glyphCount) {
1964 macGlyphs = glyphStorage.reset(srcCount); 1964 macGlyphs = glyphStorage.reset(srcCount);
(...skipping 27 matching lines...) Expand all
1992 for (int i = 0; i < glyphCount; ++i) { 1992 for (int i = 0; i < glyphCount; ++i) {
1993 if (0 == compactedGlyphs[i]) { 1993 if (0 == compactedGlyphs[i]) {
1994 return i; 1994 return i;
1995 } 1995 }
1996 } 1996 }
1997 // Odd to get here, as we expected CT to have returned true up front. 1997 // Odd to get here, as we expected CT to have returned true up front.
1998 return glyphCount; 1998 return glyphCount;
1999 } 1999 }
2000 2000
2001 int SkTypeface_Mac::onCountGlyphs() const { 2001 int SkTypeface_Mac::onCountGlyphs() const {
2002 return CTFontGetGlyphCount(fFontRef); 2002 return SkToInt(CTFontGetGlyphCount(fFontRef));
2003 } 2003 }
2004 2004
2005 /////////////////////////////////////////////////////////////////////////////// 2005 ///////////////////////////////////////////////////////////////////////////////
2006 /////////////////////////////////////////////////////////////////////////////// 2006 ///////////////////////////////////////////////////////////////////////////////
2007 #if 1 2007 #if 1
2008 2008
2009 static bool find_desc_str(CTFontDescriptorRef desc, CFStringRef name, SkString* value) { 2009 static bool find_desc_str(CTFontDescriptorRef desc, CFStringRef name, SkString* value) {
2010 AutoCFRelease<CFStringRef> ref((CFStringRef)CTFontDescriptorCopyAttribute(de sc, name)); 2010 AutoCFRelease<CFStringRef> ref((CFStringRef)CTFontDescriptorCopyAttribute(de sc, name));
2011 if (NULL == ref.get()) { 2011 if (NULL == ref.get()) {
2012 return false; 2012 return false;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
2135 class SkFontStyleSet_Mac : public SkFontStyleSet { 2135 class SkFontStyleSet_Mac : public SkFontStyleSet {
2136 public: 2136 public:
2137 SkFontStyleSet_Mac(CFStringRef familyName, CTFontDescriptorRef desc) 2137 SkFontStyleSet_Mac(CFStringRef familyName, CTFontDescriptorRef desc)
2138 : fArray(CTFontDescriptorCreateMatchingFontDescriptors(desc, NULL)) 2138 : fArray(CTFontDescriptorCreateMatchingFontDescriptors(desc, NULL))
2139 , fFamilyName(familyName) 2139 , fFamilyName(familyName)
2140 , fCount(0) { 2140 , fCount(0) {
2141 CFRetain(familyName); 2141 CFRetain(familyName);
2142 if (NULL == fArray) { 2142 if (NULL == fArray) {
2143 fArray = CFArrayCreate(NULL, NULL, 0, NULL); 2143 fArray = CFArrayCreate(NULL, NULL, 0, NULL);
2144 } 2144 }
2145 fCount = CFArrayGetCount(fArray); 2145 fCount = SkToInt(CFArrayGetCount(fArray));
2146 } 2146 }
2147 2147
2148 virtual ~SkFontStyleSet_Mac() { 2148 virtual ~SkFontStyleSet_Mac() {
2149 CFRelease(fArray); 2149 CFRelease(fArray);
2150 CFRelease(fFamilyName); 2150 CFRelease(fFamilyName);
2151 } 2151 }
2152 2152
2153 virtual int count() SK_OVERRIDE { 2153 virtual int count() SK_OVERRIDE {
2154 return fCount; 2154 return fCount;
2155 } 2155 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2212 CFArrayRef fNames; 2212 CFArrayRef fNames;
2213 2213
2214 CFStringRef stringAt(int index) const { 2214 CFStringRef stringAt(int index) const {
2215 SkASSERT((unsigned)index < (unsigned)fCount); 2215 SkASSERT((unsigned)index < (unsigned)fCount);
2216 return (CFStringRef)CFArrayGetValueAtIndex(fNames, index); 2216 return (CFStringRef)CFArrayGetValueAtIndex(fNames, index);
2217 } 2217 }
2218 2218
2219 void lazyInit() { 2219 void lazyInit() {
2220 if (NULL == fNames) { 2220 if (NULL == fNames) {
2221 fNames = SkCTFontManagerCopyAvailableFontFamilyNames(); 2221 fNames = SkCTFontManagerCopyAvailableFontFamilyNames();
2222 fCount = fNames ? CFArrayGetCount(fNames) : 0; 2222 fCount = fNames ? SkToInt(CFArrayGetCount(fNames)) : 0;
2223 } 2223 }
2224 } 2224 }
2225 2225
2226 static SkFontStyleSet* CreateSet(CFStringRef cfFamilyName) { 2226 static SkFontStyleSet* CreateSet(CFStringRef cfFamilyName) {
2227 AutoCFRelease<CFMutableDictionaryRef> cfAttr( 2227 AutoCFRelease<CFMutableDictionaryRef> cfAttr(
2228 CFDictionaryCreateMutable(kCFAllocatorDefault, 0, 2228 CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
2229 &kCFTypeDictionaryKeyCallBacks, 2229 &kCFTypeDictionaryKeyCallBacks,
2230 &kCFTypeDictionaryValueCallBacks)); 2230 &kCFTypeDictionaryValueCallBacks));
2231 2231
2232 CFDictionaryAddValue(cfAttr, kCTFontFamilyNameAttribute, cfFamilyName); 2232 CFDictionaryAddValue(cfAttr, kCTFontFamilyNameAttribute, cfFamilyName);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
2313 return create_typeface(NULL, familyName, (SkTypeface::Style)styleBits); 2313 return create_typeface(NULL, familyName, (SkTypeface::Style)styleBits);
2314 } 2314 }
2315 }; 2315 };
2316 2316
2317 /////////////////////////////////////////////////////////////////////////////// 2317 ///////////////////////////////////////////////////////////////////////////////
2318 2318
2319 SkFontMgr* SkFontMgr::Factory() { 2319 SkFontMgr* SkFontMgr::Factory() {
2320 return SkNEW(SkFontMgr_Mac); 2320 return SkNEW(SkFontMgr_Mac);
2321 } 2321 }
2322 #endif 2322 #endif
OLDNEW
« no previous file with comments | « src/core/SkPictureFlat.h ('k') | src/ports/SkImageDecoder_CG.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698