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

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

Issue 2333423002: Simulated fonts aren't TrueType fonts. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Also FontConfig. Created 4 years, 3 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
« no previous file with comments | « src/ports/SkFontMgr_fontconfig.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 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 #if defined(SK_BUILD_FOR_WIN32) 9 #if defined(SK_BUILD_FOR_WIN32)
10 10
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 324
325 const unsigned glyphCount = fDWriteFontFace->GetGlyphCount(); 325 const unsigned glyphCount = fDWriteFontFace->GetGlyphCount();
326 326
327 DWRITE_FONT_METRICS dwfm; 327 DWRITE_FONT_METRICS dwfm;
328 fDWriteFontFace->GetMetrics(&dwfm); 328 fDWriteFontFace->GetMetrics(&dwfm);
329 329
330 info = new SkAdvancedTypefaceMetrics; 330 info = new SkAdvancedTypefaceMetrics;
331 info->fEmSize = dwfm.designUnitsPerEm; 331 info->fEmSize = dwfm.designUnitsPerEm;
332 info->fLastGlyphID = SkToU16(glyphCount - 1); 332 info->fLastGlyphID = SkToU16(glyphCount - 1);
333 333
334 info->fAscent = SkToS16(dwfm.ascent);
335 info->fDescent = SkToS16(dwfm.descent);
336 info->fCapHeight = SkToS16(dwfm.capHeight);
337
334 // SkAdvancedTypefaceMetrics::fFontName is in theory supposed to be 338 // SkAdvancedTypefaceMetrics::fFontName is in theory supposed to be
335 // the PostScript name of the font. However, due to the way it is currently 339 // the PostScript name of the font. However, due to the way it is currently
336 // used, it must actually be a family name. 340 // used, it must actually be a family name.
337 SkTScopedComPtr<IDWriteLocalizedStrings> familyNames; 341 SkTScopedComPtr<IDWriteLocalizedStrings> familyNames;
338 hr = fDWriteFontFamily->GetFamilyNames(&familyNames); 342 hr = fDWriteFontFamily->GetFamilyNames(&familyNames);
339 343
340 UINT32 familyNameLen; 344 UINT32 familyNameLen;
341 hr = familyNames->GetStringLength(0, &familyNameLen); 345 hr = familyNames->GetStringLength(0, &familyNameLen);
342 346
343 SkSMallocWCHAR familyName(familyNameLen+1); 347 SkSMallocWCHAR familyName(familyNameLen+1);
344 hr = familyNames->GetString(0, familyName.get(), familyNameLen+1); 348 hr = familyNames->GetString(0, familyName.get(), familyNameLen+1);
345 349
346 hr = sk_wchar_to_skstring(familyName.get(), familyNameLen, &info->fFontName) ; 350 hr = sk_wchar_to_skstring(familyName.get(), familyNameLen, &info->fFontName) ;
347 351
348 if (perGlyphInfo & kToUnicode_PerGlyphInfo) { 352 if (perGlyphInfo & kToUnicode_PerGlyphInfo) {
349 populate_glyph_to_unicode(fDWriteFontFace.get(), glyphCount, &(info->fGl yphToUnicode)); 353 populate_glyph_to_unicode(fDWriteFontFace.get(), glyphCount, &(info->fGl yphToUnicode));
350 } 354 }
351 355
352 DWRITE_FONT_FACE_TYPE fontType = fDWriteFontFace->GetType(); 356 DWRITE_FONT_FACE_TYPE fontType = fDWriteFontFace->GetType();
353 if (fontType == DWRITE_FONT_FACE_TYPE_TRUETYPE || 357 if (fontType != DWRITE_FONT_FACE_TYPE_TRUETYPE &&
354 fontType == DWRITE_FONT_FACE_TYPE_TRUETYPE_COLLECTION) { 358 fontType != DWRITE_FONT_FACE_TYPE_TRUETYPE_COLLECTION)
359 {
360 return info;
361 }
362
363 // Simulated fonts aren't really TrueType fonts.
364 if (fDWriteFontFace->GetSimulations() == DWRITE_FONT_SIMULATIONS_NONE) {
355 info->fType = SkAdvancedTypefaceMetrics::kTrueType_Font; 365 info->fType = SkAdvancedTypefaceMetrics::kTrueType_Font;
356 } else {
357 info->fAscent = dwfm.ascent;
358 info->fDescent = dwfm.descent;
359 info->fCapHeight = dwfm.capHeight;
360 return info;
361 } 366 }
362 367
363 AutoTDWriteTable<SkOTTableHead> headTable(fDWriteFontFace.get()); 368 AutoTDWriteTable<SkOTTableHead> headTable(fDWriteFontFace.get());
364 AutoTDWriteTable<SkOTTablePostScript> postTable(fDWriteFontFace.get()); 369 AutoTDWriteTable<SkOTTablePostScript> postTable(fDWriteFontFace.get());
365 AutoTDWriteTable<SkOTTableHorizontalHeader> hheaTable(fDWriteFontFace.get()) ; 370 AutoTDWriteTable<SkOTTableHorizontalHeader> hheaTable(fDWriteFontFace.get()) ;
366 AutoTDWriteTable<SkOTTableOS2> os2Table(fDWriteFontFace.get()); 371 AutoTDWriteTable<SkOTTableOS2> os2Table(fDWriteFontFace.get());
367 if (!headTable.fExists || !postTable.fExists || !hheaTable.fExists || !os2Ta ble.fExists) { 372 if (!headTable.fExists || !postTable.fExists || !hheaTable.fExists || !os2Ta ble.fExists) {
368 info->fAscent = dwfm.ascent;
369 info->fDescent = dwfm.descent;
370 info->fCapHeight = dwfm.capHeight;
371 return info; 373 return info;
372 } 374 }
373 375
374 //There exist CJK fonts which set the IsFixedPitch and Monospace bits, 376 //There exist CJK fonts which set the IsFixedPitch and Monospace bits,
375 //but have full width, latin half-width, and half-width kana. 377 //but have full width, latin half-width, and half-width kana.
376 bool fixedWidth = (postTable->isFixedPitch && 378 bool fixedWidth = (postTable->isFixedPitch &&
377 (1 == SkEndian_SwapBE16(hheaTable->numberOfHMetrics))); 379 (1 == SkEndian_SwapBE16(hheaTable->numberOfHMetrics)));
378 //Monospace 380 //Monospace
379 if (fixedWidth) { 381 if (fixedWidth) {
380 info->fStyle |= SkAdvancedTypefaceMetrics::kFixedPitch_Style; 382 info->fStyle |= SkAdvancedTypefaceMetrics::kFixedPitch_Style;
(...skipping 18 matching lines...) Expand all
399 { 401 {
400 info->fStyle |= SkAdvancedTypefaceMetrics::kSerif_Style; 402 info->fStyle |= SkAdvancedTypefaceMetrics::kSerif_Style;
401 } 403 }
402 //Script 404 //Script
403 } else if (SkPanose::FamilyType::Script == os2Table->version.v0.panose.bFami lyType) { 405 } else if (SkPanose::FamilyType::Script == os2Table->version.v0.panose.bFami lyType) {
404 info->fStyle |= SkAdvancedTypefaceMetrics::kScript_Style; 406 info->fStyle |= SkAdvancedTypefaceMetrics::kScript_Style;
405 } 407 }
406 408
407 info->fItalicAngle = SkEndian_SwapBE32(postTable->italicAngle) >> 16; 409 info->fItalicAngle = SkEndian_SwapBE32(postTable->italicAngle) >> 16;
408 410
409 info->fAscent = SkToS16(dwfm.ascent);
410 info->fDescent = SkToS16(dwfm.descent);
411 info->fCapHeight = SkToS16(dwfm.capHeight);
412
413 info->fBBox = SkIRect::MakeLTRB((int32_t)SkEndian_SwapBE16((uint16_t)headTab le->xMin), 411 info->fBBox = SkIRect::MakeLTRB((int32_t)SkEndian_SwapBE16((uint16_t)headTab le->xMin),
414 (int32_t)SkEndian_SwapBE16((uint16_t)headTab le->yMax), 412 (int32_t)SkEndian_SwapBE16((uint16_t)headTab le->yMax),
415 (int32_t)SkEndian_SwapBE16((uint16_t)headTab le->xMax), 413 (int32_t)SkEndian_SwapBE16((uint16_t)headTab le->xMax),
416 (int32_t)SkEndian_SwapBE16((uint16_t)headTab le->yMin)); 414 (int32_t)SkEndian_SwapBE16((uint16_t)headTab le->yMin));
417 return info; 415 return info;
418 } 416 }
419 #endif//defined(SK_BUILD_FOR_WIN32) 417 #endif//defined(SK_BUILD_FOR_WIN32)
OLDNEW
« no previous file with comments | « src/ports/SkFontMgr_fontconfig.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698