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" | |
9 // SkTypes will include Windows.h, which will pull in all of the GDI defines. | |
10 // GDI #defines GetGlyphIndices to GetGlyphIndicesA or GetGlyphIndicesW, but | |
11 // IDWriteFontFace has a method called GetGlyphIndices. Since this file does | |
12 // not use GDI, undefing GetGlyphIndices makes things less confusing. | |
13 #undef GetGlyphIndices | |
14 | |
8 #include "SkDWriteFontFileStream.h" | 15 #include "SkDWriteFontFileStream.h" |
9 #include "SkFontDescriptor.h" | 16 #include "SkFontDescriptor.h" |
10 #include "SkFontStream.h" | 17 #include "SkFontStream.h" |
11 #include "SkOTTable_head.h" | 18 #include "SkOTTable_head.h" |
12 #include "SkOTTable_hhea.h" | 19 #include "SkOTTable_hhea.h" |
13 #include "SkOTTable_OS_2.h" | 20 #include "SkOTTable_OS_2.h" |
14 #include "SkOTTable_post.h" | 21 #include "SkOTTable_post.h" |
15 #include "SkScalerContext.h" | 22 #include "SkScalerContext.h" |
16 #include "SkScalerContext_win_dw.h" | 23 #include "SkScalerContext_win_dw.h" |
17 #include "SkTypeface_win_dw.h" | 24 #include "SkTypeface_win_dw.h" |
18 #include "SkTypes.h" | |
19 #include "SkUtils.h" | 25 #include "SkUtils.h" |
20 | 26 |
21 void DWriteFontTypeface::onGetFontDescriptor(SkFontDescriptor* desc, | 27 void DWriteFontTypeface::onGetFontDescriptor(SkFontDescriptor* desc, |
22 bool* isLocalStream) const { | 28 bool* isLocalStream) const { |
23 // Get the family name. | 29 // Get the family name. |
24 SkTScopedComPtr<IDWriteLocalizedStrings> dwFamilyNames; | 30 SkTScopedComPtr<IDWriteLocalizedStrings> dwFamilyNames; |
25 HRV(fDWriteFontFamily->GetFamilyNames(&dwFamilyNames)); | 31 HRV(fDWriteFontFamily->GetFamilyNames(&dwFamilyNames)); |
26 | 32 |
27 UINT32 dwFamilyNamesLength; | 33 UINT32 dwFamilyNamesLength; |
28 HRV(dwFamilyNames->GetStringLength(0, &dwFamilyNamesLength)); | 34 HRV(dwFamilyNames->GetStringLength(0, &dwFamilyNamesLength)); |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
271 } | 277 } |
272 | 278 |
273 /////////////////////////////////////////////////////////////////////////////// | 279 /////////////////////////////////////////////////////////////////////////////// |
274 //PDF Support | 280 //PDF Support |
275 | 281 |
276 using namespace skia_advanced_typeface_metrics_utils; | 282 using namespace skia_advanced_typeface_metrics_utils; |
277 | 283 |
278 // Construct Glyph to Unicode table. | 284 // Construct Glyph to Unicode table. |
279 // Unicode code points that require conjugate pairs in utf16 are not | 285 // Unicode code points that require conjugate pairs in utf16 are not |
280 // supported. | 286 // supported. |
281 // TODO(arthurhsu): Add support for conjugate pairs. It looks like that may | |
282 // require parsing the TTF cmap table (platform 4, encoding 12) directly instead | |
283 // of calling GetFontUnicodeRange(). | |
284 // TODO(bungeman): This never does what anyone wants. | 287 // TODO(bungeman): This never does what anyone wants. |
285 // What is really wanted is the text to glyphs mapping | 288 // What is really wanted is the text to glyphs mapping |
286 static void populate_glyph_to_unicode(IDWriteFontFace* fontFace, | 289 static void populate_glyph_to_unicode(IDWriteFontFace* fontFace, |
287 const unsigned glyphCount, | 290 const unsigned glyphCount, |
288 SkTDArray<SkUnichar>* glyphToUnicode) { | 291 SkTDArray<SkUnichar>* glyphToUnicode) { |
289 HRESULT hr = S_OK; | 292 HRESULT hr = S_OK; |
290 | 293 |
291 //Do this like free type instead | 294 //Do this like free type instead |
292 UINT32 count = 0; | 295 SkAutoTMalloc<SkUnichar> glyphToUni(glyphCount); |
296 int maxGlyph = -1; | |
293 for (UINT32 c = 0; c < 0x10FFFF; ++c) { | 297 for (UINT32 c = 0; c < 0x10FFFF; ++c) { |
294 UINT16 glyph; | 298 UINT16 glyph; |
295 hr = fontFace->GetGlyphIndices(&c, 1, &glyph); | 299 hr = fontFace->GetGlyphIndices(&c, 1, &glyph); |
296 if (glyph > 0) { | 300 SkASSERT(glyph < glyphCount); |
297 ++count; | 301 if (0 < glyph) { |
302 maxGlyph = SkTMax(static_cast<int>(glyph), maxGlyph); | |
303 glyphToUni[glyph] = c; | |
298 } | 304 } |
299 } | 305 } |
300 | 306 |
301 SkAutoTArray<UINT32> chars(count); | 307 glyphToUnicode->swap(SkTDArray<SkUnichar>(glyphToUni, maxGlyph + 1)); |
Nico
2014/08/25 03:18:59
Our clang/win fyi bot doesn't like this:
..\..\th
bungeman-skia
2014/08/25 14:01:49
Hmmmm, yes, C++ specifically forbids all of this t
| |
302 count = 0; | |
303 for (UINT32 c = 0; c < 0x10FFFF; ++c) { | |
304 UINT16 glyph; | |
305 hr = fontFace->GetGlyphIndices(&c, 1, &glyph); | |
306 if (glyph > 0) { | |
307 chars[count] = c; | |
308 ++count; | |
309 } | |
310 } | |
311 | |
312 SkAutoTArray<UINT16> glyph(count); | |
313 fontFace->GetGlyphIndices(chars.get(), count, glyph.get()); | |
314 | |
315 USHORT maxGlyph = 0; | |
316 for (USHORT j = 0; j < count; ++j) { | |
317 if (glyph[j] > maxGlyph) maxGlyph = glyph[j]; | |
318 } | |
319 | |
320 glyphToUnicode->setCount(maxGlyph+1); | |
321 for (USHORT j = 0; j < maxGlyph+1u; ++j) { | |
322 (*glyphToUnicode)[j] = 0; | |
323 } | |
324 | |
325 //'invert' | |
326 for (USHORT j = 0; j < count; ++j) { | |
327 if (glyph[j] < glyphCount && (*glyphToUnicode)[glyph[j]] == 0) { | |
328 (*glyphToUnicode)[glyph[j]] = chars[j]; | |
329 } | |
330 } | |
331 } | 308 } |
332 | 309 |
333 static bool getWidthAdvance(IDWriteFontFace* fontFace, int gId, int16_t* advance ) { | 310 static bool getWidthAdvance(IDWriteFontFace* fontFace, int gId, int16_t* advance ) { |
334 SkASSERT(advance); | 311 SkASSERT(advance); |
335 | 312 |
336 UINT16 glyphId = gId; | 313 UINT16 glyphId = gId; |
337 DWRITE_GLYPH_METRICS gm; | 314 DWRITE_GLYPH_METRICS gm; |
338 HRESULT hr = fontFace->GetDesignGlyphMetrics(&glyphId, 1, &gm); | 315 HRESULT hr = fontFace->GetDesignGlyphMetrics(&glyphId, 1, &gm); |
339 | 316 |
340 if (FAILED(hr)) { | 317 if (FAILED(hr)) { |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
481 getAdvanceData(fDWriteFontFace.get(), | 458 getAdvanceData(fDWriteFontFace.get(), |
482 glyphCount, | 459 glyphCount, |
483 glyphIDs, | 460 glyphIDs, |
484 glyphIDsCount, | 461 glyphIDsCount, |
485 getWidthAdvance)); | 462 getWidthAdvance)); |
486 } | 463 } |
487 } | 464 } |
488 | 465 |
489 return info; | 466 return info; |
490 } | 467 } |
OLD | NEW |