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 "SkAdvancedTypefaceMetrics.h" | 9 #include "SkAdvancedTypefaceMetrics.h" |
10 #include "SkBase64.h" | 10 #include "SkBase64.h" |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE; |
214 virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK
_OVERRIDE; | 214 virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK
_OVERRIDE; |
215 virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE; | 215 virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE; |
216 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( | 216 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( |
217 SkAdvancedTypefaceMetrics::PerGlyphInfo, | 217 SkAdvancedTypefaceMetrics::PerGlyphInfo, |
218 const uint32_t*, uint32_t) const SK_OVERRIDE; | 218 const uint32_t*, uint32_t) const SK_OVERRIDE; |
| 219 virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE
; |
219 }; | 220 }; |
220 | 221 |
221 class FontMemResourceTypeface : public LogFontTypeface { | 222 class FontMemResourceTypeface : public LogFontTypeface { |
222 public: | 223 public: |
223 /** | 224 /** |
224 * Takes ownership of fontMemResource. | 225 * Takes ownership of fontMemResource. |
225 */ | 226 */ |
226 FontMemResourceTypeface(SkTypeface::Style style, SkFontID fontID, const LOGF
ONT& lf, HANDLE fontMemResource) : | 227 FontMemResourceTypeface(SkTypeface::Style style, SkFontID fontID, const LOGF
ONT& lf, HANDLE fontMemResource) : |
227 LogFontTypeface(style, fontID, lf, true), fFontMemResource(fontMemResour
ce) { | 228 LogFontTypeface(style, fontID, lf, true), fFontMemResource(fontMemResour
ce) { |
228 } | 229 } |
(...skipping 1043 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1272 static void tchar_to_skstring(const TCHAR* t, SkString* s) { | 1273 static void tchar_to_skstring(const TCHAR* t, SkString* s) { |
1273 #ifdef UNICODE | 1274 #ifdef UNICODE |
1274 size_t sSize = WideCharToMultiByte(CP_UTF8, 0, t, -1, NULL, 0, NULL, NULL); | 1275 size_t sSize = WideCharToMultiByte(CP_UTF8, 0, t, -1, NULL, 0, NULL, NULL); |
1275 s->resize(sSize); | 1276 s->resize(sSize); |
1276 WideCharToMultiByte(CP_UTF8, 0, t, -1, s->writable_str(), sSize, NULL, NULL)
; | 1277 WideCharToMultiByte(CP_UTF8, 0, t, -1, s->writable_str(), sSize, NULL, NULL)
; |
1277 #else | 1278 #else |
1278 s->set(t); | 1279 s->set(t); |
1279 #endif | 1280 #endif |
1280 } | 1281 } |
1281 | 1282 |
1282 void SkFontHost::Serialize(const SkTypeface* rawFace, SkWStream* stream) { | 1283 void LogFontTypeface::onGetFontDescriptor(SkFontDescriptor* desc, |
1283 const LogFontTypeface* face = static_cast<const LogFontTypeface*>(rawFace); | 1284 bool* isLocalStream) const { |
1284 SkFontDescriptor descriptor(face->style()); | |
1285 | |
1286 // Get the actual name of the typeface. The logfont may not know this. | 1285 // Get the actual name of the typeface. The logfont may not know this. |
1287 HFONT font = CreateFontIndirect(&face->fLogFont); | 1286 HFONT font = CreateFontIndirect(&fLogFont); |
1288 | 1287 |
1289 HDC deviceContext = ::CreateCompatibleDC(NULL); | 1288 HDC deviceContext = ::CreateCompatibleDC(NULL); |
1290 HFONT savefont = (HFONT)SelectObject(deviceContext, font); | 1289 HFONT savefont = (HFONT)SelectObject(deviceContext, font); |
1291 | 1290 |
1292 int fontNameLen; //length of fontName in TCHARS. | 1291 int fontNameLen; //length of fontName in TCHARS. |
1293 if (0 == (fontNameLen = GetTextFace(deviceContext, 0, NULL))) { | 1292 if (0 == (fontNameLen = GetTextFace(deviceContext, 0, NULL))) { |
1294 LogFontTypeface::EnsureAccessible(rawFace); | 1293 call_ensure_accessible(fLogFont); |
1295 if (0 == (fontNameLen = GetTextFace(deviceContext, 0, NULL))) { | 1294 if (0 == (fontNameLen = GetTextFace(deviceContext, 0, NULL))) { |
1296 fontNameLen = 0; | 1295 fontNameLen = 0; |
1297 } | 1296 } |
1298 } | 1297 } |
1299 | 1298 |
1300 SkAutoSTArray<LF_FULLFACESIZE, TCHAR> fontName(fontNameLen+1); | 1299 SkAutoSTArray<LF_FULLFACESIZE, TCHAR> fontName(fontNameLen+1); |
1301 if (0 == GetTextFace(deviceContext, fontNameLen, fontName.get())) { | 1300 if (0 == GetTextFace(deviceContext, fontNameLen, fontName.get())) { |
1302 LogFontTypeface::EnsureAccessible(rawFace); | 1301 call_ensure_accessible(fLogFont); |
1303 if (0 == GetTextFace(deviceContext, fontNameLen, fontName.get())) { | 1302 if (0 == GetTextFace(deviceContext, fontNameLen, fontName.get())) { |
1304 fontName[0] = 0; | 1303 fontName[0] = 0; |
1305 } | 1304 } |
1306 } | 1305 } |
1307 | 1306 |
1308 if (deviceContext) { | 1307 if (deviceContext) { |
1309 ::SelectObject(deviceContext, savefont); | 1308 ::SelectObject(deviceContext, savefont); |
1310 ::DeleteDC(deviceContext); | 1309 ::DeleteDC(deviceContext); |
1311 } | 1310 } |
1312 if (font) { | 1311 if (font) { |
1313 ::DeleteObject(font); | 1312 ::DeleteObject(font); |
1314 } | 1313 } |
1315 | 1314 |
1316 SkString familyName; | 1315 SkString familyName; |
1317 tchar_to_skstring(fontName.get(), &familyName); | 1316 tchar_to_skstring(fontName.get(), &familyName); |
1318 descriptor.setFamilyName(familyName.c_str()); | |
1319 //TODO: FileName and PostScriptName currently unsupported. | |
1320 | 1317 |
1321 descriptor.serialize(stream); | 1318 desc->setFamilyName(familyName.c_str()); |
1322 | 1319 *isLocalStream = this->fSerializeAsStream; |
1323 if (face->fSerializeAsStream) { | |
1324 // store the entire font in the fontData | |
1325 SkAutoTUnref<SkStream> fontStream(face->openStream(NULL)); | |
1326 if (fontStream.get()) { | |
1327 const uint32_t length = fontStream->getLength(); | |
1328 stream->writePackedUInt(length); | |
1329 stream->writeStream(fontStream, length); | |
1330 } else { | |
1331 stream->writePackedUInt(0); | |
1332 } | |
1333 } else { | |
1334 stream->writePackedUInt(0); | |
1335 } | |
1336 } | |
1337 | |
1338 SkTypeface* SkFontHost::Deserialize(SkStream* stream) { | |
1339 SkFontDescriptor descriptor(stream); | |
1340 | |
1341 const uint32_t customFontDataLength = stream->readPackedUInt(); | |
1342 if (customFontDataLength > 0) { | |
1343 // generate a new stream to store the custom typeface | |
1344 SkAutoTUnref<SkMemoryStream> fontStream(SkNEW_ARGS(SkMemoryStream, (cust
omFontDataLength - 1))); | |
1345 stream->read((void*)fontStream->getMemoryBase(), customFontDataLength -
1); | |
1346 | |
1347 return CreateTypefaceFromStream(fontStream.get()); | |
1348 } | |
1349 | |
1350 return SkFontHost::CreateTypeface(NULL, descriptor.getFamilyName(), descript
or.getStyle()); | |
1351 } | 1320 } |
1352 | 1321 |
1353 static bool getWidthAdvance(HDC hdc, int gId, int16_t* advance) { | 1322 static bool getWidthAdvance(HDC hdc, int gId, int16_t* advance) { |
1354 // Initialize the MAT2 structure to the identify transformation matrix. | 1323 // Initialize the MAT2 structure to the identify transformation matrix. |
1355 static const MAT2 mat2 = {SkScalarToFIXED(1), SkScalarToFIXED(0), | 1324 static const MAT2 mat2 = {SkScalarToFIXED(1), SkScalarToFIXED(0), |
1356 SkScalarToFIXED(0), SkScalarToFIXED(1)}; | 1325 SkScalarToFIXED(0), SkScalarToFIXED(1)}; |
1357 int flags = GGO_METRICS | GGO_GLYPH_INDEX; | 1326 int flags = GGO_METRICS | GGO_GLYPH_INDEX; |
1358 GLYPHMETRICS gm; | 1327 GLYPHMETRICS gm; |
1359 if (GDI_ERROR == GetGlyphOutline(hdc, gId, flags, &gm, 0, NULL, &mat2)) { | 1328 if (GDI_ERROR == GetGlyphOutline(hdc, gId, flags, &gm, 0, NULL, &mat2)) { |
1360 return false; | 1329 return false; |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1702 if (isLCD(*rec) && !isAxisAligned(*rec)) { | 1671 if (isLCD(*rec) && !isAxisAligned(*rec)) { |
1703 rec->fMaskFormat = SkMask::kA8_Format; | 1672 rec->fMaskFormat = SkMask::kA8_Format; |
1704 } | 1673 } |
1705 #endif | 1674 #endif |
1706 | 1675 |
1707 if (!fCanBeLCD && isLCD(*rec)) { | 1676 if (!fCanBeLCD && isLCD(*rec)) { |
1708 rec->fMaskFormat = SkMask::kA8_Format; | 1677 rec->fMaskFormat = SkMask::kA8_Format; |
1709 rec->fFlags &= ~SkScalerContext::kGenA8FromLCD_Flag; | 1678 rec->fFlags &= ~SkScalerContext::kGenA8FromLCD_Flag; |
1710 } | 1679 } |
1711 } | 1680 } |
OLD | NEW |