OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 // SkTypes will include Windows.h, which will pull in all of the GDI defines. | 9 // SkTypes will include Windows.h, which will pull in all of the GDI defines. |
10 // GDI #defines GetGlyphIndices to GetGlyphIndicesA or GetGlyphIndicesW, but | 10 // GDI #defines GetGlyphIndices to GetGlyphIndicesA or GetGlyphIndicesW, but |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 HRESULT hr = S_OK; | 332 HRESULT hr = S_OK; |
333 | 333 |
334 const unsigned glyphCount = fDWriteFontFace->GetGlyphCount(); | 334 const unsigned glyphCount = fDWriteFontFace->GetGlyphCount(); |
335 | 335 |
336 DWRITE_FONT_METRICS dwfm; | 336 DWRITE_FONT_METRICS dwfm; |
337 fDWriteFontFace->GetMetrics(&dwfm); | 337 fDWriteFontFace->GetMetrics(&dwfm); |
338 | 338 |
339 info = new SkAdvancedTypefaceMetrics; | 339 info = new SkAdvancedTypefaceMetrics; |
340 info->fEmSize = dwfm.designUnitsPerEm; | 340 info->fEmSize = dwfm.designUnitsPerEm; |
341 info->fLastGlyphID = SkToU16(glyphCount - 1); | 341 info->fLastGlyphID = SkToU16(glyphCount - 1); |
342 info->fStyle = 0; | |
343 info->fFlags = SkAdvancedTypefaceMetrics::kEmpty_FontFlag; | |
344 | 342 |
345 // SkAdvancedTypefaceMetrics::fFontName is in theory supposed to be | 343 // SkAdvancedTypefaceMetrics::fFontName is in theory supposed to be |
346 // the PostScript name of the font. However, due to the way it is currently | 344 // the PostScript name of the font. However, due to the way it is currently |
347 // used, it must actually be a family name. | 345 // used, it must actually be a family name. |
348 SkTScopedComPtr<IDWriteLocalizedStrings> familyNames; | 346 SkTScopedComPtr<IDWriteLocalizedStrings> familyNames; |
349 hr = fDWriteFontFamily->GetFamilyNames(&familyNames); | 347 hr = fDWriteFontFamily->GetFamilyNames(&familyNames); |
350 | 348 |
351 UINT32 familyNameLen; | 349 UINT32 familyNameLen; |
352 hr = familyNames->GetStringLength(0, &familyNameLen); | 350 hr = familyNames->GetStringLength(0, &familyNameLen); |
353 | 351 |
354 SkSMallocWCHAR familyName(familyNameLen+1); | 352 SkSMallocWCHAR familyName(familyNameLen+1); |
355 hr = familyNames->GetString(0, familyName.get(), familyNameLen+1); | 353 hr = familyNames->GetString(0, familyName.get(), familyNameLen+1); |
356 | 354 |
357 hr = sk_wchar_to_skstring(familyName.get(), familyNameLen, &info->fFontName)
; | 355 hr = sk_wchar_to_skstring(familyName.get(), familyNameLen, &info->fFontName)
; |
358 | 356 |
359 if (perGlyphInfo & kToUnicode_PerGlyphInfo) { | 357 if (perGlyphInfo & kToUnicode_PerGlyphInfo) { |
360 populate_glyph_to_unicode(fDWriteFontFace.get(), glyphCount, &(info->fGl
yphToUnicode)); | 358 populate_glyph_to_unicode(fDWriteFontFace.get(), glyphCount, &(info->fGl
yphToUnicode)); |
361 } | 359 } |
362 | 360 |
363 DWRITE_FONT_FACE_TYPE fontType = fDWriteFontFace->GetType(); | 361 DWRITE_FONT_FACE_TYPE fontType = fDWriteFontFace->GetType(); |
364 if (fontType == DWRITE_FONT_FACE_TYPE_TRUETYPE || | 362 if (fontType == DWRITE_FONT_FACE_TYPE_TRUETYPE || |
365 fontType == DWRITE_FONT_FACE_TYPE_TRUETYPE_COLLECTION) { | 363 fontType == DWRITE_FONT_FACE_TYPE_TRUETYPE_COLLECTION) { |
366 info->fType = SkAdvancedTypefaceMetrics::kTrueType_Font; | 364 info->fType = SkAdvancedTypefaceMetrics::kTrueType_Font; |
367 } else { | 365 } else { |
368 info->fType = SkAdvancedTypefaceMetrics::kOther_Font; | |
369 info->fItalicAngle = 0; | |
370 info->fAscent = dwfm.ascent; | 366 info->fAscent = dwfm.ascent; |
371 info->fDescent = dwfm.descent; | 367 info->fDescent = dwfm.descent; |
372 info->fStemV = 0; | |
373 info->fCapHeight = dwfm.capHeight; | 368 info->fCapHeight = dwfm.capHeight; |
374 info->fBBox = SkIRect::MakeEmpty(); | |
375 return info; | 369 return info; |
376 } | 370 } |
377 | 371 |
378 AutoTDWriteTable<SkOTTableHead> headTable(fDWriteFontFace.get()); | 372 AutoTDWriteTable<SkOTTableHead> headTable(fDWriteFontFace.get()); |
379 AutoTDWriteTable<SkOTTablePostScript> postTable(fDWriteFontFace.get()); | 373 AutoTDWriteTable<SkOTTablePostScript> postTable(fDWriteFontFace.get()); |
380 AutoTDWriteTable<SkOTTableHorizontalHeader> hheaTable(fDWriteFontFace.get())
; | 374 AutoTDWriteTable<SkOTTableHorizontalHeader> hheaTable(fDWriteFontFace.get())
; |
381 AutoTDWriteTable<SkOTTableOS2> os2Table(fDWriteFontFace.get()); | 375 AutoTDWriteTable<SkOTTableOS2> os2Table(fDWriteFontFace.get()); |
382 if (!headTable.fExists || !postTable.fExists || !hheaTable.fExists || !os2Ta
ble.fExists) { | 376 if (!headTable.fExists || !postTable.fExists || !hheaTable.fExists || !os2Ta
ble.fExists) { |
383 info->fItalicAngle = 0; | |
384 info->fAscent = dwfm.ascent; | 377 info->fAscent = dwfm.ascent; |
385 info->fDescent = dwfm.descent; | 378 info->fDescent = dwfm.descent; |
386 info->fStemV = 0; | |
387 info->fCapHeight = dwfm.capHeight; | 379 info->fCapHeight = dwfm.capHeight; |
388 info->fBBox = SkIRect::MakeEmpty(); | |
389 return info; | 380 return info; |
390 } | 381 } |
391 | 382 |
392 //There exist CJK fonts which set the IsFixedPitch and Monospace bits, | 383 //There exist CJK fonts which set the IsFixedPitch and Monospace bits, |
393 //but have full width, latin half-width, and half-width kana. | 384 //but have full width, latin half-width, and half-width kana. |
394 bool fixedWidth = (postTable->isFixedPitch && | 385 bool fixedWidth = (postTable->isFixedPitch && |
395 (1 == SkEndian_SwapBE16(hheaTable->numberOfHMetrics))); | 386 (1 == SkEndian_SwapBE16(hheaTable->numberOfHMetrics))); |
396 //Monospace | 387 //Monospace |
397 if (fixedWidth) { | 388 if (fixedWidth) { |
398 info->fStyle |= SkAdvancedTypefaceMetrics::kFixedPitch_Style; | 389 info->fStyle |= SkAdvancedTypefaceMetrics::kFixedPitch_Style; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 getAdvanceData(fDWriteFontFace.get(), | 447 getAdvanceData(fDWriteFontFace.get(), |
457 glyphCount, | 448 glyphCount, |
458 glyphIDs, | 449 glyphIDs, |
459 glyphIDsCount, | 450 glyphIDsCount, |
460 getWidthAdvance)); | 451 getWidthAdvance)); |
461 } | 452 } |
462 } | 453 } |
463 | 454 |
464 return info; | 455 return info; |
465 } | 456 } |
OLD | NEW |