OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gfx/font_fallback_win.h" | 5 #include "ui/gfx/font_fallback_win.h" |
6 | 6 |
7 #include <dwrite_2.h> | 7 #include <dwrite_2.h> |
8 #include <usp10.h> | 8 #include <usp10.h> |
9 #include <wrl.h> | 9 #include <wrl.h> |
10 | 10 |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 // renderer should instead use the font proxy. | 350 // renderer should instead use the font proxy. |
351 DCHECK(base::MessageLoopForUI::IsCurrent()); | 351 DCHECK(base::MessageLoopForUI::IsCurrent()); |
352 | 352 |
353 // Check that we have at least as much text as was claimed. If we have less | 353 // Check that we have at least as much text as was claimed. If we have less |
354 // text than expected then DirectWrite will become confused and crash. This | 354 // text than expected then DirectWrite will become confused and crash. This |
355 // shouldn't happen, but crbug.com/624905 shows that it happens sometimes. | 355 // shouldn't happen, but crbug.com/624905 shows that it happens sometimes. |
356 DCHECK_GE(wcslen(text), static_cast<size_t>(text_length)); | 356 DCHECK_GE(wcslen(text), static_cast<size_t>(text_length)); |
357 text_length = std::min(wcslen(text), static_cast<size_t>(text_length)); | 357 text_length = std::min(wcslen(text), static_cast<size_t>(text_length)); |
358 | 358 |
359 base::win::ScopedComPtr<IDWriteFactory> factory; | 359 base::win::ScopedComPtr<IDWriteFactory> factory; |
360 gfx::win::CreateDWriteFactory(factory.Receive()); | 360 gfx::win::CreateDWriteFactory(factory.GetAddressOf()); |
361 base::win::ScopedComPtr<IDWriteFactory2> factory2; | 361 base::win::ScopedComPtr<IDWriteFactory2> factory2; |
362 factory.CopyTo(factory2.Receive()); | 362 factory.CopyTo(factory2.GetAddressOf()); |
363 if (!factory2) { | 363 if (!factory2) { |
364 // IDWriteFactory2 is not available before Win8.1 | 364 // IDWriteFactory2 is not available before Win8.1 |
365 return GetUniscribeFallbackFont(font, text, text_length, result); | 365 return GetUniscribeFallbackFont(font, text, text_length, result); |
366 } | 366 } |
367 | 367 |
368 base::win::ScopedComPtr<IDWriteFontFallback> fallback; | 368 base::win::ScopedComPtr<IDWriteFontFallback> fallback; |
369 if (FAILED(factory2->GetSystemFontFallback(fallback.Receive()))) | 369 if (FAILED(factory2->GetSystemFontFallback(fallback.GetAddressOf()))) |
370 return false; | 370 return false; |
371 | 371 |
372 base::string16 locale = base::UTF8ToUTF16(base::i18n::GetConfiguredLocale()); | 372 base::string16 locale = base::UTF8ToUTF16(base::i18n::GetConfiguredLocale()); |
373 | 373 |
374 base::win::ScopedComPtr<IDWriteNumberSubstitution> number_substitution; | 374 base::win::ScopedComPtr<IDWriteNumberSubstitution> number_substitution; |
375 if (FAILED(factory2->CreateNumberSubstitution( | 375 if (FAILED(factory2->CreateNumberSubstitution( |
376 DWRITE_NUMBER_SUBSTITUTION_METHOD_NONE, locale.c_str(), | 376 DWRITE_NUMBER_SUBSTITUTION_METHOD_NONE, locale.c_str(), |
377 true /* ignoreUserOverride */, number_substitution.Receive()))) { | 377 true /* ignoreUserOverride */, number_substitution.GetAddressOf()))) { |
378 return false; | 378 return false; |
379 } | 379 } |
380 | 380 |
381 uint32_t mapped_length = 0; | 381 uint32_t mapped_length = 0; |
382 base::win::ScopedComPtr<IDWriteFont> mapped_font; | 382 base::win::ScopedComPtr<IDWriteFont> mapped_font; |
383 float scale = 0; | 383 float scale = 0; |
384 base::win::ScopedComPtr<IDWriteTextAnalysisSource> text_analysis; | 384 base::win::ScopedComPtr<IDWriteTextAnalysisSource> text_analysis; |
385 DWRITE_READING_DIRECTION reading_direction = | 385 DWRITE_READING_DIRECTION reading_direction = |
386 base::i18n::IsRTL() ? DWRITE_READING_DIRECTION_RIGHT_TO_LEFT | 386 base::i18n::IsRTL() ? DWRITE_READING_DIRECTION_RIGHT_TO_LEFT |
387 : DWRITE_READING_DIRECTION_LEFT_TO_RIGHT; | 387 : DWRITE_READING_DIRECTION_LEFT_TO_RIGHT; |
388 if (FAILED(Microsoft::WRL::MakeAndInitialize<gfx::win::TextAnalysisSource>( | 388 if (FAILED(Microsoft::WRL::MakeAndInitialize<gfx::win::TextAnalysisSource>( |
389 text_analysis.Receive(), text, locale.c_str(), | 389 text_analysis.GetAddressOf(), text, locale.c_str(), |
390 number_substitution.Get(), reading_direction))) { | 390 number_substitution.Get(), reading_direction))) { |
391 return false; | 391 return false; |
392 } | 392 } |
393 base::string16 original_name = base::UTF8ToUTF16(font.GetFontName()); | 393 base::string16 original_name = base::UTF8ToUTF16(font.GetFontName()); |
394 DWRITE_FONT_STYLE font_style = DWRITE_FONT_STYLE_NORMAL; | 394 DWRITE_FONT_STYLE font_style = DWRITE_FONT_STYLE_NORMAL; |
395 if (font.GetStyle() & Font::ITALIC) | 395 if (font.GetStyle() & Font::ITALIC) |
396 font_style = DWRITE_FONT_STYLE_ITALIC; | 396 font_style = DWRITE_FONT_STYLE_ITALIC; |
397 if (FAILED(fallback->MapCharacters( | 397 if (FAILED(fallback->MapCharacters( |
398 text_analysis.Get(), 0, text_length, nullptr, original_name.c_str(), | 398 text_analysis.Get(), 0, text_length, nullptr, original_name.c_str(), |
399 static_cast<DWRITE_FONT_WEIGHT>(font.GetWeight()), font_style, | 399 static_cast<DWRITE_FONT_WEIGHT>(font.GetWeight()), font_style, |
400 DWRITE_FONT_STRETCH_NORMAL, &mapped_length, mapped_font.Receive(), | 400 DWRITE_FONT_STRETCH_NORMAL, &mapped_length, |
401 &scale))) { | 401 mapped_font.GetAddressOf(), &scale))) { |
402 return false; | 402 return false; |
403 } | 403 } |
404 | 404 |
405 if (mapped_font) { | 405 if (mapped_font) { |
406 base::string16 name; | 406 base::string16 name; |
407 if (FAILED(GetFamilyNameFromDirectWriteFont(mapped_font.Get(), &name))) | 407 if (FAILED(GetFamilyNameFromDirectWriteFont(mapped_font.Get(), &name))) |
408 return false; | 408 return false; |
409 *result = Font(base::UTF16ToUTF8(name), font.GetFontSize() * scale); | 409 *result = Font(base::UTF16ToUTF8(name), font.GetFontSize() * scale); |
410 return true; | 410 return true; |
411 } | 411 } |
412 return false; | 412 return false; |
413 } | 413 } |
414 | 414 |
415 } // namespace gfx | 415 } // namespace gfx |
OLD | NEW |