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

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

Issue 12941006: override SkTypeface::onOpenStream() (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 9 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 | « no previous file | no next file » | 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 "SkAdvancedTypefaceMetrics.h" 9 #include "SkAdvancedTypefaceMetrics.h"
10 #include "SkBase64.h" 10 #include "SkBase64.h"
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 SkTypeface::Style style = get_style(lf); 203 SkTypeface::Style style = get_style(lf);
204 SkFontID fontID = SkTypefaceCache::NewFontID(); 204 SkFontID fontID = SkTypefaceCache::NewFontID();
205 return new LogFontTypeface(style, fontID, lf); 205 return new LogFontTypeface(style, fontID, lf);
206 } 206 }
207 207
208 static void EnsureAccessible(const SkTypeface* face) { 208 static void EnsureAccessible(const SkTypeface* face) {
209 call_ensure_accessible(static_cast<const LogFontTypeface*>(face)->fLogFo nt); 209 call_ensure_accessible(static_cast<const LogFontTypeface*>(face)->fLogFo nt);
210 } 210 }
211 211
212 protected: 212 protected:
213 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE;
213 virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK _OVERRIDE; 214 virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK _OVERRIDE;
214 virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE; 215 virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE;
215 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( 216 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
216 SkAdvancedTypefaceMetrics::PerGlyphInfo, 217 SkAdvancedTypefaceMetrics::PerGlyphInfo,
217 const uint32_t*, uint32_t) const SK_OVERRIDE; 218 const uint32_t*, uint32_t) const SK_OVERRIDE;
218 }; 219 };
219 220
220 class FontMemResourceTypeface : public LogFontTypeface { 221 class FontMemResourceTypeface : public LogFontTypeface {
221 public: 222 public:
222 /** 223 /**
(...skipping 1091 matching lines...) Expand 10 before | Expand all | Expand 10 after
1314 1315
1315 SkString familyName; 1316 SkString familyName;
1316 tchar_to_skstring(fontName.get(), &familyName); 1317 tchar_to_skstring(fontName.get(), &familyName);
1317 descriptor.setFamilyName(familyName.c_str()); 1318 descriptor.setFamilyName(familyName.c_str());
1318 //TODO: FileName and PostScriptName currently unsupported. 1319 //TODO: FileName and PostScriptName currently unsupported.
1319 1320
1320 descriptor.serialize(stream); 1321 descriptor.serialize(stream);
1321 1322
1322 if (face->fSerializeAsStream) { 1323 if (face->fSerializeAsStream) {
1323 // store the entire font in the fontData 1324 // store the entire font in the fontData
1324 SkAutoTUnref<SkStream> fontStream(SkFontHost::OpenStream(face->uniqueID( ))); 1325 SkAutoTUnref<SkStream> fontStream(face->openStream(NULL));
1325 const uint32_t length = fontStream->getLength(); 1326 if (fontStream.get()) {
1326 1327 const uint32_t length = fontStream->getLength();
1327 stream->writePackedUInt(length); 1328 stream->writePackedUInt(length);
1328 stream->writeStream(fontStream, length); 1329 stream->writeStream(fontStream, length);
1330 } else {
1331 stream->writePackedUInt(0);
1332 }
1329 } else { 1333 } else {
1330 stream->writePackedUInt(0); 1334 stream->writePackedUInt(0);
1331 } 1335 }
1332 } 1336 }
1333 1337
1334 SkTypeface* SkFontHost::Deserialize(SkStream* stream) { 1338 SkTypeface* SkFontHost::Deserialize(SkStream* stream) {
1335 SkFontDescriptor descriptor(stream); 1339 SkFontDescriptor descriptor(stream);
1336 1340
1337 const uint32_t customFontDataLength = stream->readPackedUInt(); 1341 const uint32_t customFontDataLength = stream->readPackedUInt();
1338 if (customFontDataLength > 0) { 1342 if (customFontDataLength > 0) {
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
1581 return NULL; 1585 return NULL;
1582 } 1586 }
1583 1587
1584 // Create the typeface. 1588 // Create the typeface.
1585 LOGFONT lf; 1589 LOGFONT lf;
1586 logfont_for_name(familyName, lf); 1590 logfont_for_name(familyName, lf);
1587 1591
1588 return SkCreateFontMemResourceTypefaceFromLOGFONT(lf, fontReference); 1592 return SkCreateFontMemResourceTypefaceFromLOGFONT(lf, fontReference);
1589 } 1593 }
1590 1594
1591 SkStream* SkFontHost::OpenStream(SkFontID uniqueID) { 1595 SkStream* LogFontTypeface::onOpenStream(int* ttcIndex) const {
1596 *ttcIndex = 0;
1597
1592 const DWORD kTTCTag = 1598 const DWORD kTTCTag =
1593 SkEndian_SwapBE32(SkSetFourByteTag('t', 't', 'c', 'f')); 1599 SkEndian_SwapBE32(SkSetFourByteTag('t', 't', 'c', 'f'));
1594 LOGFONT lf; 1600 LOGFONT lf = fLogFont;
1595 GetLogFontByID(uniqueID, &lf);
1596 1601
1597 HDC hdc = ::CreateCompatibleDC(NULL); 1602 HDC hdc = ::CreateCompatibleDC(NULL);
1598 HFONT font = CreateFontIndirect(&lf); 1603 HFONT font = CreateFontIndirect(&lf);
1599 HFONT savefont = (HFONT)SelectObject(hdc, font); 1604 HFONT savefont = (HFONT)SelectObject(hdc, font);
1600 1605
1601 SkMemoryStream* stream = NULL; 1606 SkMemoryStream* stream = NULL;
1602 DWORD tables[2] = {kTTCTag, 0}; 1607 DWORD tables[2] = {kTTCTag, 0};
1603 for (int i = 0; i < SK_ARRAY_COUNT(tables); i++) { 1608 for (int i = 0; i < SK_ARRAY_COUNT(tables); i++) {
1604 size_t bufferSize = GetFontData(hdc, tables[i], 0, NULL, 0); 1609 size_t bufferSize = GetFontData(hdc, tables[i], 0, NULL, 0);
1605 if (bufferSize == GDI_ERROR) { 1610 if (bufferSize == GDI_ERROR) {
(...skipping 12 matching lines...) Expand all
1618 } 1623 }
1619 } 1624 }
1620 1625
1621 SelectObject(hdc, savefont); 1626 SelectObject(hdc, savefont);
1622 DeleteObject(font); 1627 DeleteObject(font);
1623 DeleteDC(hdc); 1628 DeleteDC(hdc);
1624 1629
1625 return stream; 1630 return stream;
1626 } 1631 }
1627 1632
1633 SkStream* SkFontHost::OpenStream(SkFontID uniqueID) {
1634 SkTypeface* typeface = SkTypefaceCache::FindByID(uniqueID);
1635 return typeface ? typeface->openStream(NULL) : NULL;
1636 }
1637
1628 size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length, int3 2_t* index) { 1638 size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length, int3 2_t* index) {
1639 SkASSERT(!"SkFontHost::GetFileName is DEPRECATED\n");
1629 return 0; 1640 return 0;
1630 } 1641 }
1631 1642
1632 SkScalerContext* LogFontTypeface::onCreateScalerContext(const SkDescriptor* desc ) const { 1643 SkScalerContext* LogFontTypeface::onCreateScalerContext(const SkDescriptor* desc ) const {
1633 return SkNEW_ARGS(SkScalerContext_Windows, (const_cast<LogFontTypeface*>(thi s), desc)); 1644 return SkNEW_ARGS(SkScalerContext_Windows, (const_cast<LogFontTypeface*>(thi s), desc));
1634 } 1645 }
1635 1646
1636 /** Return the closest matching typeface given either an existing family 1647 /** Return the closest matching typeface given either an existing family
1637 (specified by a typeface in that family) or by a familyName, and a 1648 (specified by a typeface in that family) or by a familyName, and a
1638 requested style. 1649 requested style.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1701 if (isLCD(*rec) && !isAxisAligned(*rec)) { 1712 if (isLCD(*rec) && !isAxisAligned(*rec)) {
1702 rec->fMaskFormat = SkMask::kA8_Format; 1713 rec->fMaskFormat = SkMask::kA8_Format;
1703 } 1714 }
1704 #endif 1715 #endif
1705 1716
1706 if (!fCanBeLCD && isLCD(*rec)) { 1717 if (!fCanBeLCD && isLCD(*rec)) {
1707 rec->fMaskFormat = SkMask::kA8_Format; 1718 rec->fMaskFormat = SkMask::kA8_Format;
1708 rec->fFlags &= ~SkScalerContext::kGenA8FromLCD_Flag; 1719 rec->fFlags &= ~SkScalerContext::kGenA8FromLCD_Flag;
1709 } 1720 }
1710 } 1721 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698