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/render_text_win.h" | 5 #include "ui/gfx/render_text_win.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/i18n/break_iterator.h" | 9 #include "base/i18n/break_iterator.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 internal::TextRun* run = runs_[i]; | 594 internal::TextRun* run = runs_[i]; |
595 size_t run_length = run->range.length(); | 595 size_t run_length = run->range.length(); |
596 const wchar_t* run_text = &(text()[run->range.start()]); | 596 const wchar_t* run_text = &(text()[run->range.start()]); |
597 bool tried_fallback = false; | 597 bool tried_fallback = false; |
598 size_t linked_font_index = 0; | 598 size_t linked_font_index = 0; |
599 const std::vector<Font>* linked_fonts = NULL; | 599 const std::vector<Font>* linked_fonts = NULL; |
600 | 600 |
601 // Select the font desired for glyph generation. | 601 // Select the font desired for glyph generation. |
602 SelectObject(cached_hdc_, run->font.GetNativeFont()); | 602 SelectObject(cached_hdc_, run->font.GetNativeFont()); |
603 | 603 |
604 SCRIPT_FONTPROPERTIES font_properties; | 604 SCRIPT_FONTPROPERTIES properties; |
605 memset(&font_properties, 0, sizeof(font_properties)); | 605 memset(&properties, 0, sizeof(properties)); |
606 font_properties.cBytes = sizeof(SCRIPT_FONTPROPERTIES); | 606 properties.cBytes = sizeof(properties); |
607 ScriptGetFontProperties(cached_hdc_, &run->script_cache, &font_properties); | |
608 | 607 |
609 run->logical_clusters.reset(new WORD[run_length]); | 608 run->logical_clusters.reset(new WORD[run_length]); |
610 run->glyph_count = 0; | 609 run->glyph_count = 0; |
611 // Max glyph guess: http://msdn.microsoft.com/en-us/library/dd368564.aspx | 610 // Max glyph guess: http://msdn.microsoft.com/en-us/library/dd368564.aspx |
612 size_t max_glyphs = static_cast<size_t>(1.5 * run_length + 16); | 611 size_t max_glyphs = static_cast<size_t>(1.5 * run_length + 16); |
613 while (max_glyphs < kMaxGlyphs) { | 612 while (max_glyphs < kMaxGlyphs) { |
614 bool glyphs_missing = false; | 613 bool glyphs_missing = false; |
615 run->glyphs.reset(new WORD[max_glyphs]); | 614 run->glyphs.reset(new WORD[max_glyphs]); |
616 run->visible_attributes.reset(new SCRIPT_VISATTR[max_glyphs]); | 615 run->visible_attributes.reset(new SCRIPT_VISATTR[max_glyphs]); |
617 hr = ScriptShape(cached_hdc_, | 616 hr = ScriptShape(cached_hdc_, |
618 &run->script_cache, | 617 &run->script_cache, |
619 run_text, | 618 run_text, |
620 run_length, | 619 run_length, |
621 max_glyphs, | 620 max_glyphs, |
622 &(run->script_analysis), | 621 &(run->script_analysis), |
623 run->glyphs.get(), | 622 run->glyphs.get(), |
624 run->logical_clusters.get(), | 623 run->logical_clusters.get(), |
625 run->visible_attributes.get(), | 624 run->visible_attributes.get(), |
626 &(run->glyph_count)); | 625 &(run->glyph_count)); |
627 if (hr == E_OUTOFMEMORY) { | 626 if (hr == E_OUTOFMEMORY) { |
628 max_glyphs *= 2; | 627 max_glyphs *= 2; |
629 continue; | 628 continue; |
630 } else if (hr == USP_E_SCRIPT_NOT_IN_FONT) { | 629 } else if (hr == USP_E_SCRIPT_NOT_IN_FONT) { |
631 glyphs_missing = true; | 630 glyphs_missing = true; |
632 } else if (hr == S_OK) { | 631 } else if (hr == S_OK) { |
633 // If |hr| is S_OK, there could still be missing glyphs in the output, | 632 // If |hr| is S_OK, there could still be missing glyphs in the output, |
634 // see: http://msdn.microsoft.com/en-us/library/windows/desktop/dd368564
.aspx | 633 // see: http://msdn.microsoft.com/en-us/library/windows/desktop/dd368564
.aspx |
| 634 ScriptGetFontProperties(cached_hdc_, &run->script_cache, &properties); |
635 for (int i = 0; i < run->glyph_count; ++i) { | 635 for (int i = 0; i < run->glyph_count; ++i) { |
636 if (run->glyphs[i] == font_properties.wgDefault) { | 636 if (run->glyphs[i] == properties.wgDefault) { |
637 glyphs_missing = true; | 637 glyphs_missing = true; |
638 break; | 638 break; |
639 } | 639 } |
640 } | 640 } |
641 } | 641 } |
642 | 642 |
643 // Skip font substitution if there are no missing glyphs. | 643 // Skip font substitution if there are no missing glyphs. |
644 if (!glyphs_missing) | 644 if (!glyphs_missing) |
645 break; | 645 break; |
646 | 646 |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
784 internal::TextRun* run) { | 784 internal::TextRun* run) { |
785 size_t caret = IndexOfAdjacentGrapheme(run->range.end(), CURSOR_BACKWARD); | 785 size_t caret = IndexOfAdjacentGrapheme(run->range.end(), CURSOR_BACKWARD); |
786 return SelectionModel(caret, CURSOR_FORWARD); | 786 return SelectionModel(caret, CURSOR_FORWARD); |
787 } | 787 } |
788 | 788 |
789 RenderText* RenderText::CreateRenderText() { | 789 RenderText* RenderText::CreateRenderText() { |
790 return new RenderTextWin; | 790 return new RenderTextWin; |
791 } | 791 } |
792 | 792 |
793 } // namespace gfx | 793 } // namespace gfx |
OLD | NEW |