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

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

Issue 12807004: move impl of AdvancedTypefaceMetrics into typeface (3) (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
« include/core/SkTypeface.h ('K') | « src/ports/SkFontHost_win.cpp ('k') | 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 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
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" 8 #include "SkTypes.h"
9 #undef GetGlyphIndices 9 #undef GetGlyphIndices
10 10
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 474
475 IDWriteFactory* factory; 475 IDWriteFactory* factory;
476 HRVM(get_dwrite_factory(&factory), "Could not get factory."); 476 HRVM(get_dwrite_factory(&factory), "Could not get factory.");
477 HRV(factory->UnregisterFontCollectionLoader(fDWriteFontCollectionLoader. get())); 477 HRV(factory->UnregisterFontCollectionLoader(fDWriteFontCollectionLoader. get()));
478 HRV(factory->UnregisterFontFileLoader(fDWriteFontFileLoader.get())); 478 HRV(factory->UnregisterFontFileLoader(fDWriteFontFileLoader.get()));
479 } 479 }
480 480
481 protected: 481 protected:
482 virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK _OVERRIDE; 482 virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK _OVERRIDE;
483 virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE; 483 virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE;
484 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
485 SkAdvancedTypefaceMetrics::PerGlyphInfo,
486 const uint32_t*, uint32_t) const SK_OVERRIDE;
484 }; 487 };
485 488
486 class SkScalerContext_Windows : public SkScalerContext { 489 class SkScalerContext_Windows : public SkScalerContext {
487 public: 490 public:
488 SkScalerContext_Windows(DWriteFontTypeface*, const SkDescriptor* desc); 491 SkScalerContext_Windows(DWriteFontTypeface*, const SkDescriptor* desc);
489 virtual ~SkScalerContext_Windows(); 492 virtual ~SkScalerContext_Windows();
490 493
491 protected: 494 protected:
492 virtual unsigned generateGlyphCount() SK_OVERRIDE; 495 virtual unsigned generateGlyphCount() SK_OVERRIDE;
493 virtual uint16_t generateCharToGlyph(SkUnichar uni) SK_OVERRIDE; 496 virtual uint16_t generateCharToGlyph(SkUnichar uni) SK_OVERRIDE;
(...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after
1390 1393
1391 const T* fData; 1394 const T* fData;
1392 UINT32 fSize; 1395 UINT32 fSize;
1393 BOOL fExists; 1396 BOOL fExists;
1394 private: 1397 private:
1395 //SkTScopedComPtr<IDWriteFontFace> fFontFace; 1398 //SkTScopedComPtr<IDWriteFontFace> fFontFace;
1396 IDWriteFontFace* fFontFace; 1399 IDWriteFontFace* fFontFace;
1397 void* fLock; 1400 void* fLock;
1398 }; 1401 };
1399 1402
1400 // static 1403 SkAdvancedTypefaceMetrics* DWriteFontTypeface::onGetAdvancedTypefaceMetrics(
1401 SkAdvancedTypefaceMetrics* SkFontHost::GetAdvancedTypefaceMetrics(
1402 uint32_t fontID,
1403 SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo, 1404 SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo,
1404 const uint32_t* glyphIDs, 1405 const uint32_t* glyphIDs,
1405 uint32_t glyphIDsCount) { 1406 uint32_t glyphIDsCount) const {
1406 1407
1407 SkAdvancedTypefaceMetrics* info = NULL; 1408 SkAdvancedTypefaceMetrics* info = NULL;
1408 1409
1409 HRESULT hr = S_OK; 1410 HRESULT hr = S_OK;
1410 1411
1411 DWriteFontTypeface* typeface = GetDWriteFontByID(fontID); 1412 const unsigned glyphCount = fDWriteFontFace->GetGlyphCount();
1412
1413 const unsigned glyphCount = typeface->fDWriteFontFace->GetGlyphCount();
1414 1413
1415 DWRITE_FONT_METRICS dwfm; 1414 DWRITE_FONT_METRICS dwfm;
1416 typeface->fDWriteFontFace->GetMetrics(&dwfm); 1415 fDWriteFontFace->GetMetrics(&dwfm);
1417 1416
1418 info = new SkAdvancedTypefaceMetrics; 1417 info = new SkAdvancedTypefaceMetrics;
1419 info->fEmSize = dwfm.designUnitsPerEm; 1418 info->fEmSize = dwfm.designUnitsPerEm;
1420 info->fMultiMaster = false; 1419 info->fMultiMaster = false;
1421 info->fLastGlyphID = SkToU16(glyphCount - 1); 1420 info->fLastGlyphID = SkToU16(glyphCount - 1);
1422 info->fStyle = 0; 1421 info->fStyle = 0;
1423 1422
1424 1423
1425 SkTScopedComPtr<IDWriteLocalizedStrings> familyNames; 1424 SkTScopedComPtr<IDWriteLocalizedStrings> familyNames;
1426 SkTScopedComPtr<IDWriteLocalizedStrings> faceNames; 1425 SkTScopedComPtr<IDWriteLocalizedStrings> faceNames;
1427 hr = typeface->fDWriteFontFamily->GetFamilyNames(&familyNames); 1426 hr = fDWriteFontFamily->GetFamilyNames(&familyNames);
1428 hr = typeface->fDWriteFont->GetFaceNames(&faceNames); 1427 hr = fDWriteFont->GetFaceNames(&faceNames);
1429 1428
1430 UINT32 familyNameLength; 1429 UINT32 familyNameLength;
1431 hr = familyNames->GetStringLength(0, &familyNameLength); 1430 hr = familyNames->GetStringLength(0, &familyNameLength);
1432 1431
1433 UINT32 faceNameLength; 1432 UINT32 faceNameLength;
1434 hr = faceNames->GetStringLength(0, &faceNameLength); 1433 hr = faceNames->GetStringLength(0, &faceNameLength);
1435 1434
1436 size_t size = familyNameLength+1+faceNameLength+1; 1435 size_t size = familyNameLength+1+faceNameLength+1;
1437 SkTDArray<wchar_t> wFamilyName(new wchar_t[size], size); 1436 SkTDArray<wchar_t> wFamilyName(new wchar_t[size], size);
1438 hr = familyNames->GetString(0, wFamilyName.begin(), size); 1437 hr = familyNames->GetString(0, wFamilyName.begin(), size);
1439 wFamilyName[familyNameLength] = L' '; 1438 wFamilyName[familyNameLength] = L' ';
1440 hr = faceNames->GetString(0, &wFamilyName[familyNameLength+1], size - faceNa meLength + 1); 1439 hr = faceNames->GetString(0, &wFamilyName[familyNameLength+1], size - faceNa meLength + 1);
1441 1440
1442 size_t str_len = WideCharToMultiByte(CP_UTF8, 0, wFamilyName.begin(), -1, NU LL, 0, NULL, NULL); 1441 size_t str_len = WideCharToMultiByte(CP_UTF8, 0, wFamilyName.begin(), -1, NU LL, 0, NULL, NULL);
1443 if (0 == str_len) { 1442 if (0 == str_len) {
1444 //TODO: error 1443 //TODO: error
1445 } 1444 }
1446 SkTDArray<char> familyName(new char[str_len], str_len); 1445 SkTDArray<char> familyName(new char[str_len], str_len);
1447 str_len = WideCharToMultiByte(CP_UTF8, 0, wFamilyName.begin(), -1, familyNam e.begin(), str_len, NULL, NULL); 1446 str_len = WideCharToMultiByte(CP_UTF8, 0, wFamilyName.begin(), -1, familyNam e.begin(), str_len, NULL, NULL);
1448 if (0 == str_len) { 1447 if (0 == str_len) {
1449 //TODO: error 1448 //TODO: error
1450 } 1449 }
1451 info->fFontName.set(familyName.begin(), str_len); 1450 info->fFontName.set(familyName.begin(), str_len);
1452 1451
1453 if (perGlyphInfo & SkAdvancedTypefaceMetrics::kToUnicode_PerGlyphInfo) { 1452 if (perGlyphInfo & SkAdvancedTypefaceMetrics::kToUnicode_PerGlyphInfo) {
1454 populate_glyph_to_unicode(typeface->fDWriteFontFace.get(), glyphCount, & (info->fGlyphToUnicode)); 1453 populate_glyph_to_unicode(fDWriteFontFace.get(), glyphCount, &(info->fGl yphToUnicode));
1455 } 1454 }
1456 1455
1457 DWRITE_FONT_FACE_TYPE fontType = typeface->fDWriteFontFace->GetType(); 1456 DWRITE_FONT_FACE_TYPE fontType = fDWriteFontFace->GetType();
1458 if (fontType == DWRITE_FONT_FACE_TYPE_TRUETYPE || 1457 if (fontType == DWRITE_FONT_FACE_TYPE_TRUETYPE ||
1459 fontType == DWRITE_FONT_FACE_TYPE_TRUETYPE_COLLECTION) { 1458 fontType == DWRITE_FONT_FACE_TYPE_TRUETYPE_COLLECTION) {
1460 info->fType = SkAdvancedTypefaceMetrics::kTrueType_Font; 1459 info->fType = SkAdvancedTypefaceMetrics::kTrueType_Font;
1461 } else { 1460 } else {
1462 info->fType = SkAdvancedTypefaceMetrics::kOther_Font; 1461 info->fType = SkAdvancedTypefaceMetrics::kOther_Font;
1463 info->fItalicAngle = 0; 1462 info->fItalicAngle = 0;
1464 info->fAscent = dwfm.ascent;; 1463 info->fAscent = dwfm.ascent;;
1465 info->fDescent = dwfm.descent; 1464 info->fDescent = dwfm.descent;
1466 info->fStemV = 0; 1465 info->fStemV = 0;
1467 info->fCapHeight = dwfm.capHeight; 1466 info->fCapHeight = dwfm.capHeight;
1468 info->fBBox = SkIRect::MakeEmpty(); 1467 info->fBBox = SkIRect::MakeEmpty();
1469 return info; 1468 return info;
1470 } 1469 }
1471 1470
1472 AutoDWriteTable<SkOTTableHead> headTable(typeface->fDWriteFontFace.get()); 1471 AutoDWriteTable<SkOTTableHead> headTable(fDWriteFontFace.get());
1473 AutoDWriteTable<SkOTTablePostScript> postTable(typeface->fDWriteFontFace.get ()); 1472 AutoDWriteTable<SkOTTablePostScript> postTable(fDWriteFontFace.get());
1474 AutoDWriteTable<SkOTTableHorizontalHeader> hheaTable(typeface->fDWriteFontFa ce.get()); 1473 AutoDWriteTable<SkOTTableHorizontalHeader> hheaTable(fDWriteFontFace.get());
1475 AutoDWriteTable<SkOTTableOS2> os2Table(typeface->fDWriteFontFace.get()); 1474 AutoDWriteTable<SkOTTableOS2> os2Table(fDWriteFontFace.get());
1476 if (!headTable.fExists || !postTable.fExists || !hheaTable.fExists || !os2Ta ble.fExists) { 1475 if (!headTable.fExists || !postTable.fExists || !hheaTable.fExists || !os2Ta ble.fExists) {
1477 info->fItalicAngle = 0; 1476 info->fItalicAngle = 0;
1478 info->fAscent = dwfm.ascent;; 1477 info->fAscent = dwfm.ascent;;
1479 info->fDescent = dwfm.descent; 1478 info->fDescent = dwfm.descent;
1480 info->fStemV = 0; 1479 info->fStemV = 0;
1481 info->fCapHeight = dwfm.capHeight; 1480 info->fCapHeight = dwfm.capHeight;
1482 info->fBBox = SkIRect::MakeEmpty(); 1481 info->fBBox = SkIRect::MakeEmpty();
1483 return info; 1482 return info;
1484 } 1483 }
1485 1484
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1539 1538
1540 // If Restricted, the font may not be embedded in a document. 1539 // If Restricted, the font may not be embedded in a document.
1541 // If not Restricted, the font can be embedded. 1540 // If not Restricted, the font can be embedded.
1542 // If PreviewPrint, the embedding is read-only. 1541 // If PreviewPrint, the embedding is read-only.
1543 if (os2Table->version.v0.fsType.field.Restricted) { 1542 if (os2Table->version.v0.fsType.field.Restricted) {
1544 info->fType = SkAdvancedTypefaceMetrics::kNotEmbeddable_Font; 1543 info->fType = SkAdvancedTypefaceMetrics::kNotEmbeddable_Font;
1545 } else if (perGlyphInfo & SkAdvancedTypefaceMetrics::kHAdvance_PerGlyphInfo) { 1544 } else if (perGlyphInfo & SkAdvancedTypefaceMetrics::kHAdvance_PerGlyphInfo) {
1546 if (fixedWidth) { 1545 if (fixedWidth) {
1547 appendRange(&info->fGlyphWidths, 0); 1546 appendRange(&info->fGlyphWidths, 0);
1548 int16_t advance; 1547 int16_t advance;
1549 getWidthAdvance(typeface->fDWriteFontFace.get(), 1, &advance); 1548 getWidthAdvance(fDWriteFontFace.get(), 1, &advance);
1550 info->fGlyphWidths->fAdvance.append(1, &advance); 1549 info->fGlyphWidths->fAdvance.append(1, &advance);
1551 finishRange(info->fGlyphWidths.get(), 0, 1550 finishRange(info->fGlyphWidths.get(), 0,
1552 SkAdvancedTypefaceMetrics::WidthRange::kDefault); 1551 SkAdvancedTypefaceMetrics::WidthRange::kDefault);
1553 } else { 1552 } else {
1554 info->fGlyphWidths.reset( 1553 info->fGlyphWidths.reset(
1555 getAdvanceData(typeface->fDWriteFontFace.get(), 1554 getAdvanceData(fDWriteFontFace.get(),
1556 glyphCount, 1555 glyphCount,
1557 glyphIDs, 1556 glyphIDs,
1558 glyphIDsCount, 1557 glyphIDsCount,
1559 getWidthAdvance)); 1558 getWidthAdvance));
1560 } 1559 }
1561 } 1560 }
1562 1561
1563 return info; 1562 return info;
1564 } 1563 }
OLDNEW
« include/core/SkTypeface.h ('K') | « src/ports/SkFontHost_win.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698