SkTypeface_win_dw.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. /*
  2. * Copyright 2014 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #include "src/utils/win/SkDWriteNTDDI_VERSION.h"
  8. #include "include/core/SkTypes.h"
  9. #if defined(SK_BUILD_FOR_WIN)
  10. // SkTypes will include Windows.h, which will pull in all of the GDI defines.
  11. // GDI #defines GetGlyphIndices to GetGlyphIndicesA or GetGlyphIndicesW, but
  12. // IDWriteFontFace has a method called GetGlyphIndices. Since this file does
  13. // not use GDI, undefing GetGlyphIndices makes things less confusing.
  14. #undef GetGlyphIndices
  15. #include "include/private/SkTo.h"
  16. #include "include/core/SkData.h"
  17. #include "src/core/SkFontDescriptor.h"
  18. #include "src/core/SkFontStream.h"
  19. #include "src/core/SkScalerContext.h"
  20. #include "src/core/SkUtils.h"
  21. #include "src/ports/SkScalerContext_win_dw.h"
  22. #include "src/ports/SkTypeface_win_dw.h"
  23. #include "src/sfnt/SkOTTable_OS_2.h"
  24. #include "src/sfnt/SkOTTable_fvar.h"
  25. #include "src/sfnt/SkOTTable_head.h"
  26. #include "src/sfnt/SkOTTable_hhea.h"
  27. #include "src/sfnt/SkOTTable_post.h"
  28. #include "src/sfnt/SkOTUtils.h"
  29. #include "src/utils/win/SkDWrite.h"
  30. #include "src/utils/win/SkDWriteFontFileStream.h"
  31. void DWriteFontTypeface::onGetFamilyName(SkString* familyName) const {
  32. SkTScopedComPtr<IDWriteLocalizedStrings> familyNames;
  33. HRV(fDWriteFontFamily->GetFamilyNames(&familyNames));
  34. sk_get_locale_string(familyNames.get(), nullptr/*fMgr->fLocaleName.get()*/, familyName);
  35. }
  36. void DWriteFontTypeface::onGetFontDescriptor(SkFontDescriptor* desc,
  37. bool* isLocalStream) const {
  38. // Get the family name.
  39. SkTScopedComPtr<IDWriteLocalizedStrings> familyNames;
  40. HRV(fDWriteFontFamily->GetFamilyNames(&familyNames));
  41. SkString utf8FamilyName;
  42. sk_get_locale_string(familyNames.get(), nullptr/*fMgr->fLocaleName.get()*/, &utf8FamilyName);
  43. desc->setFamilyName(utf8FamilyName.c_str());
  44. desc->setStyle(this->fontStyle());
  45. *isLocalStream = SkToBool(fDWriteFontFileLoader.get());
  46. }
  47. void DWriteFontTypeface::onCharsToGlyphs(const SkUnichar uni[], int count,
  48. SkGlyphID glyphs[]) const {
  49. fDWriteFontFace->GetGlyphIndices((const UINT32*)uni, count, glyphs);
  50. }
  51. int DWriteFontTypeface::onCountGlyphs() const {
  52. return fDWriteFontFace->GetGlyphCount();
  53. }
  54. void DWriteFontTypeface::getPostScriptGlyphNames(SkString*) const {}
  55. int DWriteFontTypeface::onGetUPEM() const {
  56. DWRITE_FONT_METRICS metrics;
  57. fDWriteFontFace->GetMetrics(&metrics);
  58. return metrics.designUnitsPerEm;
  59. }
  60. class LocalizedStrings_IDWriteLocalizedStrings : public SkTypeface::LocalizedStrings {
  61. public:
  62. /** Takes ownership of the IDWriteLocalizedStrings. */
  63. explicit LocalizedStrings_IDWriteLocalizedStrings(IDWriteLocalizedStrings* strings)
  64. : fIndex(0), fStrings(strings)
  65. { }
  66. bool next(SkTypeface::LocalizedString* localizedString) override {
  67. if (fIndex >= fStrings->GetCount()) {
  68. return false;
  69. }
  70. // String
  71. UINT32 stringLen;
  72. HRBM(fStrings->GetStringLength(fIndex, &stringLen), "Could not get string length.");
  73. SkSMallocWCHAR wString(stringLen+1);
  74. HRBM(fStrings->GetString(fIndex, wString.get(), stringLen+1), "Could not get string.");
  75. HRB(sk_wchar_to_skstring(wString.get(), stringLen, &localizedString->fString));
  76. // Locale
  77. UINT32 localeLen;
  78. HRBM(fStrings->GetLocaleNameLength(fIndex, &localeLen), "Could not get locale length.");
  79. SkSMallocWCHAR wLocale(localeLen+1);
  80. HRBM(fStrings->GetLocaleName(fIndex, wLocale.get(), localeLen+1), "Could not get locale.");
  81. HRB(sk_wchar_to_skstring(wLocale.get(), localeLen, &localizedString->fLanguage));
  82. ++fIndex;
  83. return true;
  84. }
  85. private:
  86. UINT32 fIndex;
  87. SkTScopedComPtr<IDWriteLocalizedStrings> fStrings;
  88. };
  89. SkTypeface::LocalizedStrings* DWriteFontTypeface::onCreateFamilyNameIterator() const {
  90. sk_sp<SkTypeface::LocalizedStrings> nameIter =
  91. SkOTUtils::LocalizedStrings_NameTable::MakeForFamilyNames(*this);
  92. if (!nameIter) {
  93. SkTScopedComPtr<IDWriteLocalizedStrings> familyNames;
  94. HRNM(fDWriteFontFamily->GetFamilyNames(&familyNames), "Could not obtain family names.");
  95. nameIter = sk_make_sp<LocalizedStrings_IDWriteLocalizedStrings>(familyNames.release());
  96. }
  97. return nameIter.release();
  98. }
  99. int DWriteFontTypeface::onGetVariationDesignPosition(
  100. SkFontArguments::VariationPosition::Coordinate coordinates[], int coordinateCount) const
  101. {
  102. #if defined(NTDDI_WIN10_RS3) && NTDDI_VERSION >= NTDDI_WIN10_RS3
  103. SkTScopedComPtr<IDWriteFontFace5> fontFace5;
  104. if (FAILED(fDWriteFontFace->QueryInterface(&fontFace5))) {
  105. return -1;
  106. }
  107. // Return 0 if the font is not variable font.
  108. if (!fontFace5->HasVariations()) {
  109. return 0;
  110. }
  111. UINT32 fontAxisCount = fontFace5->GetFontAxisValueCount();
  112. SkTScopedComPtr<IDWriteFontResource> fontResource;
  113. HR_GENERAL(fontFace5->GetFontResource(&fontResource), nullptr, -1);
  114. int variableAxisCount = 0;
  115. for (UINT32 i = 0; i < fontAxisCount; ++i) {
  116. if (fontResource->GetFontAxisAttributes(i) & DWRITE_FONT_AXIS_ATTRIBUTES_VARIABLE) {
  117. variableAxisCount++;
  118. }
  119. }
  120. if (!coordinates || coordinateCount < variableAxisCount) {
  121. return variableAxisCount;
  122. }
  123. SkAutoSTMalloc<8, DWRITE_FONT_AXIS_VALUE> fontAxisValue(fontAxisCount);
  124. HR_GENERAL(fontFace5->GetFontAxisValues(fontAxisValue.get(), fontAxisCount), nullptr, -1);
  125. UINT32 coordIndex = 0;
  126. for (UINT32 axisIndex = 0; axisIndex < fontAxisCount; ++axisIndex) {
  127. if (fontResource->GetFontAxisAttributes(axisIndex) & DWRITE_FONT_AXIS_ATTRIBUTES_VARIABLE) {
  128. coordinates[coordIndex].axis = SkEndian_SwapBE32(fontAxisValue[axisIndex].axisTag);
  129. coordinates[coordIndex].value = fontAxisValue[axisIndex].value;
  130. }
  131. }
  132. return variableAxisCount;
  133. #endif
  134. return -1;
  135. }
  136. int DWriteFontTypeface::onGetVariationDesignParameters(
  137. SkFontParameters::Variation::Axis parameters[], int parameterCount) const
  138. {
  139. #if defined(NTDDI_WIN10_RS3) && NTDDI_VERSION >= NTDDI_WIN10_RS3
  140. SkTScopedComPtr<IDWriteFontFace5> fontFace5;
  141. if (FAILED(fDWriteFontFace->QueryInterface(&fontFace5))) {
  142. return -1;
  143. }
  144. // Return 0 if the font is not variable font.
  145. if (!fontFace5->HasVariations()) {
  146. return 0;
  147. }
  148. UINT32 fontAxisCount = fontFace5->GetFontAxisValueCount();
  149. SkTScopedComPtr<IDWriteFontResource> fontResource;
  150. HR_GENERAL(fontFace5->GetFontResource(&fontResource), nullptr, -1);
  151. int variableAxisCount = 0;
  152. for (UINT32 i = 0; i < fontAxisCount; ++i) {
  153. if (fontResource->GetFontAxisAttributes(i) & DWRITE_FONT_AXIS_ATTRIBUTES_VARIABLE) {
  154. variableAxisCount++;
  155. }
  156. }
  157. if (!parameters || parameterCount < variableAxisCount) {
  158. return variableAxisCount;
  159. }
  160. SkAutoSTMalloc<8, DWRITE_FONT_AXIS_RANGE> fontAxisRange(fontAxisCount);
  161. HR_GENERAL(fontResource->GetFontAxisRanges(fontAxisRange.get(), fontAxisCount), nullptr, -1);
  162. SkAutoSTMalloc<8, DWRITE_FONT_AXIS_VALUE> fontAxisDefaultValue(fontAxisCount);
  163. HR_GENERAL(fontResource->GetDefaultFontAxisValues(fontAxisDefaultValue.get(), fontAxisCount),
  164. nullptr, -1);
  165. UINT32 coordIndex = 0;
  166. for (UINT32 axisIndex = 0; axisIndex < fontAxisCount; ++axisIndex) {
  167. if (fontResource->GetFontAxisAttributes(axisIndex) & DWRITE_FONT_AXIS_ATTRIBUTES_VARIABLE) {
  168. parameters[coordIndex].tag = SkEndian_SwapBE32(fontAxisDefaultValue[axisIndex].axisTag);
  169. parameters[coordIndex].min = fontAxisRange[axisIndex].minValue;
  170. parameters[coordIndex].def = fontAxisDefaultValue[axisIndex].value;
  171. parameters[coordIndex].max = fontAxisRange[axisIndex].maxValue;
  172. parameters[coordIndex].setHidden(fontResource->GetFontAxisAttributes(axisIndex) &
  173. DWRITE_FONT_AXIS_ATTRIBUTES_HIDDEN);
  174. }
  175. }
  176. return variableAxisCount;
  177. #endif
  178. return -1;
  179. }
  180. int DWriteFontTypeface::onGetTableTags(SkFontTableTag tags[]) const {
  181. DWRITE_FONT_FACE_TYPE type = fDWriteFontFace->GetType();
  182. if (type != DWRITE_FONT_FACE_TYPE_CFF &&
  183. type != DWRITE_FONT_FACE_TYPE_TRUETYPE &&
  184. type != DWRITE_FONT_FACE_TYPE_TRUETYPE_COLLECTION)
  185. {
  186. return 0;
  187. }
  188. int ttcIndex;
  189. std::unique_ptr<SkStreamAsset> stream = this->openStream(&ttcIndex);
  190. return stream.get() ? SkFontStream::GetTableTags(stream.get(), ttcIndex, tags) : 0;
  191. }
  192. size_t DWriteFontTypeface::onGetTableData(SkFontTableTag tag, size_t offset,
  193. size_t length, void* data) const
  194. {
  195. AutoDWriteTable table(fDWriteFontFace.get(), SkEndian_SwapBE32(tag));
  196. if (!table.fExists) {
  197. return 0;
  198. }
  199. if (offset > table.fSize) {
  200. return 0;
  201. }
  202. size_t size = SkTMin(length, table.fSize - offset);
  203. if (data) {
  204. memcpy(data, table.fData + offset, size);
  205. }
  206. return size;
  207. }
  208. sk_sp<SkData> DWriteFontTypeface::onCopyTableData(SkFontTableTag tag) const {
  209. AutoDWriteTable table(fDWriteFontFace.get(), SkEndian_SwapBE32(tag));
  210. if (!table.fExists) {
  211. return nullptr;
  212. }
  213. return SkData::MakeWithCopy(table.fData, table.fSize);
  214. }
  215. sk_sp<SkTypeface> DWriteFontTypeface::onMakeClone(const SkFontArguments& args) const {
  216. // Skip if the current face index does not match the ttcIndex
  217. if (fDWriteFontFace->GetIndex() != SkTo<UINT32>(args.getCollectionIndex())) {
  218. return sk_ref_sp(this);
  219. }
  220. #if defined(NTDDI_WIN10_RS3) && NTDDI_VERSION >= NTDDI_WIN10_RS3
  221. SkTScopedComPtr<IDWriteFontFace5> fontFace5;
  222. if (SUCCEEDED(fDWriteFontFace->QueryInterface(&fontFace5)) && fontFace5->HasVariations()) {
  223. UINT32 fontAxisCount = fontFace5->GetFontAxisValueCount();
  224. UINT32 argsCoordCount = args.getVariationDesignPosition().coordinateCount;
  225. SkAutoSTMalloc<8, DWRITE_FONT_AXIS_VALUE> fontAxisValue(fontAxisCount);
  226. HRN(fontFace5->GetFontAxisValues(fontAxisValue.get(), fontAxisCount));
  227. for (UINT32 fontIndex = 0; fontIndex < fontAxisCount; ++fontIndex) {
  228. for (UINT32 argsIndex = 0; argsIndex < argsCoordCount; ++argsIndex) {
  229. if (SkEndian_SwapBE32(fontAxisValue[fontIndex].axisTag) ==
  230. args.getVariationDesignPosition().coordinates[argsIndex].axis) {
  231. fontAxisValue[fontIndex].value =
  232. args.getVariationDesignPosition().coordinates[argsIndex].value;
  233. }
  234. }
  235. }
  236. SkTScopedComPtr<IDWriteFontResource> fontResource;
  237. HRN(fontFace5->GetFontResource(&fontResource));
  238. SkTScopedComPtr<IDWriteFontFace5> newFontFace5;
  239. HRN(fontResource->CreateFontFace(fDWriteFont->GetSimulations(),
  240. fontAxisValue.get(),
  241. fontAxisCount,
  242. &newFontFace5));
  243. SkTScopedComPtr<IDWriteFontFace> newFontFace;
  244. HRN(newFontFace5->QueryInterface(&newFontFace));
  245. return DWriteFontTypeface::Make(fFactory.get(),
  246. newFontFace.get(),
  247. fDWriteFont.get(),
  248. fDWriteFontFamily.get(),
  249. fDWriteFontFileLoader.get(),
  250. fDWriteFontCollectionLoader.get());
  251. }
  252. #endif
  253. return sk_ref_sp(this);
  254. }
  255. std::unique_ptr<SkStreamAsset> DWriteFontTypeface::onOpenStream(int* ttcIndex) const {
  256. *ttcIndex = fDWriteFontFace->GetIndex();
  257. UINT32 numFiles;
  258. HRNM(fDWriteFontFace->GetFiles(&numFiles, nullptr),
  259. "Could not get number of font files.");
  260. if (numFiles != 1) {
  261. return nullptr;
  262. }
  263. SkTScopedComPtr<IDWriteFontFile> fontFile;
  264. HRNM(fDWriteFontFace->GetFiles(&numFiles, &fontFile), "Could not get font files.");
  265. const void* fontFileKey;
  266. UINT32 fontFileKeySize;
  267. HRNM(fontFile->GetReferenceKey(&fontFileKey, &fontFileKeySize),
  268. "Could not get font file reference key.");
  269. SkTScopedComPtr<IDWriteFontFileLoader> fontFileLoader;
  270. HRNM(fontFile->GetLoader(&fontFileLoader), "Could not get font file loader.");
  271. SkTScopedComPtr<IDWriteFontFileStream> fontFileStream;
  272. HRNM(fontFileLoader->CreateStreamFromKey(fontFileKey, fontFileKeySize,
  273. &fontFileStream),
  274. "Could not create font file stream.");
  275. return std::unique_ptr<SkStreamAsset>(new SkDWriteFontFileStream(fontFileStream.get()));
  276. }
  277. SkScalerContext* DWriteFontTypeface::onCreateScalerContext(const SkScalerContextEffects& effects,
  278. const SkDescriptor* desc) const {
  279. return new SkScalerContext_DW(sk_ref_sp(const_cast<DWriteFontTypeface*>(this)), effects, desc);
  280. }
  281. void DWriteFontTypeface::onFilterRec(SkScalerContextRec* rec) const {
  282. if (rec->fFlags & SkScalerContext::kLCD_Vertical_Flag) {
  283. rec->fMaskFormat = SkMask::kA8_Format;
  284. rec->fFlags |= SkScalerContext::kGenA8FromLCD_Flag;
  285. }
  286. unsigned flagsWeDontSupport = SkScalerContext::kForceAutohinting_Flag |
  287. SkScalerContext::kEmbolden_Flag |
  288. SkScalerContext::kLCD_Vertical_Flag;
  289. rec->fFlags &= ~flagsWeDontSupport;
  290. SkFontHinting h = rec->getHinting();
  291. // DirectWrite2 allows for hinting to be turned off. Force everything else to normal.
  292. if (h != SkFontHinting::kNone || !fFactory2 || !fDWriteFontFace2) {
  293. h = SkFontHinting::kNormal;
  294. }
  295. rec->setHinting(h);
  296. #if defined(SK_FONT_HOST_USE_SYSTEM_SETTINGS)
  297. IDWriteFactory* factory = sk_get_dwrite_factory();
  298. if (factory != nullptr) {
  299. SkTScopedComPtr<IDWriteRenderingParams> defaultRenderingParams;
  300. if (SUCCEEDED(factory->CreateRenderingParams(&defaultRenderingParams))) {
  301. float gamma = defaultRenderingParams->GetGamma();
  302. rec->setDeviceGamma(gamma);
  303. rec->setPaintGamma(gamma);
  304. rec->setContrast(defaultRenderingParams->GetEnhancedContrast());
  305. }
  306. }
  307. #endif
  308. }
  309. ///////////////////////////////////////////////////////////////////////////////
  310. //PDF Support
  311. void DWriteFontTypeface::getGlyphToUnicodeMap(SkUnichar* glyphToUnicode) const {
  312. unsigned glyphCount = fDWriteFontFace->GetGlyphCount();
  313. sk_bzero(glyphToUnicode, sizeof(SkUnichar) * glyphCount);
  314. IDWriteFontFace* fontFace = fDWriteFontFace.get();
  315. int maxGlyph = -1;
  316. unsigned remainingGlyphCount = glyphCount;
  317. for (UINT32 c = 0; c < 0x10FFFF && remainingGlyphCount != 0; ++c) {
  318. UINT16 glyph = 0;
  319. HRVM(fontFace->GetGlyphIndices(&c, 1, &glyph), "Failed to get glyph index.");
  320. // Intermittent DW bug on Windows 10. See crbug.com/470146.
  321. if (glyph >= glyphCount) {
  322. return;
  323. }
  324. if (0 < glyph && glyphToUnicode[glyph] == 0) {
  325. maxGlyph = SkTMax(static_cast<int>(glyph), maxGlyph);
  326. glyphToUnicode[glyph] = c; // Always use lowest-index unichar.
  327. --remainingGlyphCount;
  328. }
  329. }
  330. }
  331. std::unique_ptr<SkAdvancedTypefaceMetrics> DWriteFontTypeface::onGetAdvancedMetrics() const {
  332. std::unique_ptr<SkAdvancedTypefaceMetrics> info(nullptr);
  333. DWRITE_FONT_METRICS dwfm;
  334. fDWriteFontFace->GetMetrics(&dwfm);
  335. info.reset(new SkAdvancedTypefaceMetrics);
  336. info->fAscent = SkToS16(dwfm.ascent);
  337. info->fDescent = SkToS16(dwfm.descent);
  338. info->fCapHeight = SkToS16(dwfm.capHeight);
  339. {
  340. SkTScopedComPtr<IDWriteLocalizedStrings> postScriptNames;
  341. BOOL exists = FALSE;
  342. if (FAILED(fDWriteFont->GetInformationalStrings(
  343. DWRITE_INFORMATIONAL_STRING_POSTSCRIPT_NAME,
  344. &postScriptNames,
  345. &exists)) ||
  346. !exists ||
  347. FAILED(sk_get_locale_string(postScriptNames.get(), nullptr, &info->fPostScriptName)))
  348. {
  349. SkDEBUGF("Unable to get postscript name for typeface %p\n", this);
  350. }
  351. }
  352. // SkAdvancedTypefaceMetrics::fFontName must actually be a family name.
  353. SkTScopedComPtr<IDWriteLocalizedStrings> familyNames;
  354. if (FAILED(fDWriteFontFamily->GetFamilyNames(&familyNames)) ||
  355. FAILED(sk_get_locale_string(familyNames.get(), nullptr, &info->fFontName)))
  356. {
  357. SkDEBUGF("Unable to get family name for typeface 0x%p\n", this);
  358. }
  359. if (info->fPostScriptName.isEmpty()) {
  360. info->fPostScriptName = info->fFontName;
  361. }
  362. DWRITE_FONT_FACE_TYPE fontType = fDWriteFontFace->GetType();
  363. if (fontType != DWRITE_FONT_FACE_TYPE_TRUETYPE &&
  364. fontType != DWRITE_FONT_FACE_TYPE_TRUETYPE_COLLECTION)
  365. {
  366. return info;
  367. }
  368. // Simulated fonts aren't really TrueType fonts.
  369. if (fDWriteFontFace->GetSimulations() == DWRITE_FONT_SIMULATIONS_NONE) {
  370. info->fType = SkAdvancedTypefaceMetrics::kTrueType_Font;
  371. }
  372. AutoTDWriteTable<SkOTTableHead> headTable(fDWriteFontFace.get());
  373. AutoTDWriteTable<SkOTTablePostScript> postTable(fDWriteFontFace.get());
  374. AutoTDWriteTable<SkOTTableHorizontalHeader> hheaTable(fDWriteFontFace.get());
  375. AutoTDWriteTable<SkOTTableOS2> os2Table(fDWriteFontFace.get());
  376. if (!headTable.fExists || !postTable.fExists || !hheaTable.fExists || !os2Table.fExists) {
  377. return info;
  378. }
  379. SkOTUtils::SetAdvancedTypefaceFlags(os2Table->version.v4.fsType, info.get());
  380. // There are versions of DirectWrite which support named instances for system variation fonts,
  381. // but no means to indicate that such a typeface is a variation.
  382. AutoTDWriteTable<SkOTTableFontVariations> fvarTable(fDWriteFontFace.get());
  383. if (fvarTable.fExists) {
  384. info->fFlags |= SkAdvancedTypefaceMetrics::kMultiMaster_FontFlag;
  385. }
  386. //There exist CJK fonts which set the IsFixedPitch and Monospace bits,
  387. //but have full width, latin half-width, and half-width kana.
  388. bool fixedWidth = (postTable->isFixedPitch &&
  389. (1 == SkEndian_SwapBE16(hheaTable->numberOfHMetrics)));
  390. //Monospace
  391. if (fixedWidth) {
  392. info->fStyle |= SkAdvancedTypefaceMetrics::kFixedPitch_Style;
  393. }
  394. //Italic
  395. if (os2Table->version.v0.fsSelection.field.Italic) {
  396. info->fStyle |= SkAdvancedTypefaceMetrics::kItalic_Style;
  397. }
  398. //Serif
  399. using SerifStyle = SkPanose::Data::TextAndDisplay::SerifStyle;
  400. SerifStyle serifStyle = os2Table->version.v0.panose.data.textAndDisplay.bSerifStyle;
  401. if (SkPanose::FamilyType::TextAndDisplay == os2Table->version.v0.panose.bFamilyType) {
  402. if (SerifStyle::Cove == serifStyle ||
  403. SerifStyle::ObtuseCove == serifStyle ||
  404. SerifStyle::SquareCove == serifStyle ||
  405. SerifStyle::ObtuseSquareCove == serifStyle ||
  406. SerifStyle::Square == serifStyle ||
  407. SerifStyle::Thin == serifStyle ||
  408. SerifStyle::Bone == serifStyle ||
  409. SerifStyle::Exaggerated == serifStyle ||
  410. SerifStyle::Triangle == serifStyle)
  411. {
  412. info->fStyle |= SkAdvancedTypefaceMetrics::kSerif_Style;
  413. }
  414. //Script
  415. } else if (SkPanose::FamilyType::Script == os2Table->version.v0.panose.bFamilyType) {
  416. info->fStyle |= SkAdvancedTypefaceMetrics::kScript_Style;
  417. }
  418. info->fItalicAngle = SkEndian_SwapBE32(postTable->italicAngle) >> 16;
  419. info->fBBox = SkIRect::MakeLTRB((int32_t)SkEndian_SwapBE16((uint16_t)headTable->xMin),
  420. (int32_t)SkEndian_SwapBE16((uint16_t)headTable->yMax),
  421. (int32_t)SkEndian_SwapBE16((uint16_t)headTable->xMax),
  422. (int32_t)SkEndian_SwapBE16((uint16_t)headTable->yMin));
  423. return info;
  424. }
  425. #endif//defined(SK_BUILD_FOR_WIN)