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/i18n/char_iterator.h" | 10 #include "base/i18n/char_iterator.h" |
(...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
795 pos.resize(glyph_range.length() + 1); | 795 pos.resize(glyph_range.length() + 1); |
796 for (size_t k = glyph_range.start(); k < glyph_range.end(); ++k) { | 796 for (size_t k = glyph_range.start(); k < glyph_range.end(); ++k) { |
797 pos[k - glyph_range.start()].set( | 797 pos[k - glyph_range.start()].set( |
798 SkIntToScalar(text_offset.x() + run->offsets[k].du + segment_x), | 798 SkIntToScalar(text_offset.x() + run->offsets[k].du + segment_x), |
799 SkIntToScalar(text_offset.y() - run->offsets[k].dv)); | 799 SkIntToScalar(text_offset.y() - run->offsets[k].dv)); |
800 segment_x += run->advance_widths[k]; | 800 segment_x += run->advance_widths[k]; |
801 } | 801 } |
802 pos.back().set(SkIntToScalar(text_offset.x() + segment_x), | 802 pos.back().set(SkIntToScalar(text_offset.x() + segment_x), |
803 SkIntToScalar(text_offset.y())); | 803 SkIntToScalar(text_offset.y())); |
804 | 804 |
805 renderer.SetTextSize(run->font.GetFontSize()); | 805 renderer.SetTextSize(SkIntToScalar(run->font.GetFontSize())); |
806 renderer.SetFontFamilyWithStyle(run->font.GetFontName(), run->font_style); | 806 renderer.SetFontFamilyWithStyle(run->font.GetFontName(), run->font_style); |
807 | 807 |
808 for (BreakList<SkColor>::const_iterator it = | 808 for (BreakList<SkColor>::const_iterator it = |
809 colors().GetBreak(segment->char_range.start()); | 809 colors().GetBreak(segment->char_range.start()); |
810 it != colors().breaks().end() && | 810 it != colors().breaks().end() && |
811 it->first < segment->char_range.end(); | 811 it->first < segment->char_range.end(); |
812 ++it) { | 812 ++it) { |
813 const Range intersection = | 813 const Range intersection = |
814 colors().GetRange(it).Intersect(segment->char_range); | 814 colors().GetRange(it).Intersect(segment->char_range); |
815 const Range colored_glyphs = CharRangeToGlyphRange(*run, intersection); | 815 const Range colored_glyphs = CharRangeToGlyphRange(*run, intersection); |
816 // The range may be empty if a portion of a multi-character grapheme is | 816 // The range may be empty if a portion of a multi-character grapheme is |
817 // selected, yielding two colors for a single glyph. For now, this just | 817 // selected, yielding two colors for a single glyph. For now, this just |
818 // paints the glyph with a single style, but it should paint it twice, | 818 // paints the glyph with a single style, but it should paint it twice, |
819 // clipped according to selection bounds. See http://crbug.com/366786 | 819 // clipped according to selection bounds. See http://crbug.com/366786 |
820 if (colored_glyphs.is_empty()) | 820 if (colored_glyphs.is_empty()) |
821 continue; | 821 continue; |
822 DCHECK(glyph_range.Contains(colored_glyphs)); | 822 DCHECK(glyph_range.Contains(colored_glyphs)); |
823 const SkPoint& start_pos = | 823 const SkPoint& start_pos = |
824 pos[colored_glyphs.start() - glyph_range.start()]; | 824 pos[colored_glyphs.start() - glyph_range.start()]; |
825 const SkPoint& end_pos = | 825 const SkPoint& end_pos = |
826 pos[colored_glyphs.end() - glyph_range.start()]; | 826 pos[colored_glyphs.end() - glyph_range.start()]; |
827 | 827 |
828 renderer.SetForegroundColor(it->second); | 828 renderer.SetForegroundColor(it->second); |
829 renderer.DrawPosText(&start_pos, &run->glyphs[colored_glyphs.start()], | 829 renderer.DrawPosText(&start_pos, &run->glyphs[colored_glyphs.start()], |
830 colored_glyphs.length()); | 830 colored_glyphs.length()); |
831 renderer.DrawDecorations(start_pos.x(), text_offset.y(), | 831 renderer.DrawDecorations( |
832 SkScalarCeilToInt(end_pos.x() - start_pos.x()), | 832 SkScalarFloorToInt(start_pos.x()), text_offset.y(), |
msw
2014/10/17 22:13:23
Like my other DrawDecorations suggestion, perhaps
Peter Kasting
2014/10/21 01:20:46
Done.
| |
833 run->underline, run->strike, | 833 SkScalarCeilToInt(end_pos.x() - start_pos.x()), run->underline, |
834 run->diagonal_strike); | 834 run->strike, run->diagonal_strike); |
835 } | 835 } |
836 | 836 |
837 preceding_segment_widths += segment_width; | 837 preceding_segment_widths += segment_width; |
838 } | 838 } |
839 | 839 |
840 renderer.EndDiagonalStrike(); | 840 renderer.EndDiagonalStrike(); |
841 } | 841 } |
842 | 842 |
843 UndoCompositionAndSelectionStyles(); | 843 UndoCompositionAndSelectionStyles(); |
844 } | 844 } |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1096 } | 1096 } |
1097 | 1097 |
1098 // Finally, initialize |glyph_count|, |glyphs|, |visible_attributes| and | 1098 // Finally, initialize |glyph_count|, |glyphs|, |visible_attributes| and |
1099 // |logical_clusters| on the run (since they may not have been set yet). | 1099 // |logical_clusters| on the run (since they may not have been set yet). |
1100 run->glyph_count = run_length; | 1100 run->glyph_count = run_length; |
1101 memset(run->visible_attributes.get(), 0, | 1101 memset(run->visible_attributes.get(), 0, |
1102 run->glyph_count * sizeof(SCRIPT_VISATTR)); | 1102 run->glyph_count * sizeof(SCRIPT_VISATTR)); |
1103 for (int i = 0; i < run->glyph_count; ++i) | 1103 for (int i = 0; i < run->glyph_count; ++i) |
1104 run->glyphs[i] = IsWhitespace(run_text[i]) ? space_glyph : missing_glyph; | 1104 run->glyphs[i] = IsWhitespace(run_text[i]) ? space_glyph : missing_glyph; |
1105 for (size_t i = 0; i < run_length; ++i) { | 1105 for (size_t i = 0; i < run_length; ++i) { |
1106 run->logical_clusters[i] = run->script_analysis.fRTL ? | 1106 run->logical_clusters[i] = |
1107 run_length - 1 - i : i; | 1107 static_cast<WORD>(run->script_analysis.fRTL ? run_length - 1 - i : i); |
1108 } | 1108 } |
1109 | 1109 |
1110 // TODO(msw): Don't use SCRIPT_UNDEFINED. Apparently Uniscribe can | 1110 // TODO(msw): Don't use SCRIPT_UNDEFINED. Apparently Uniscribe can |
1111 // crash on certain surrogate pairs with SCRIPT_UNDEFINED. | 1111 // crash on certain surrogate pairs with SCRIPT_UNDEFINED. |
1112 // See https://bugzilla.mozilla.org/show_bug.cgi?id=341500 | 1112 // See https://bugzilla.mozilla.org/show_bug.cgi?id=341500 |
1113 // And http://maxradi.us/documents/uniscribe/ | 1113 // And http://maxradi.us/documents/uniscribe/ |
1114 run->script_analysis.eScript = SCRIPT_UNDEFINED; | 1114 run->script_analysis.eScript = SCRIPT_UNDEFINED; |
1115 } | 1115 } |
1116 | 1116 |
1117 HRESULT RenderTextWin::ShapeTextRunWithFont(internal::TextRun* run, | 1117 HRESULT RenderTextWin::ShapeTextRunWithFont(internal::TextRun* run, |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1224 size_t position = LayoutIndexToTextIndex(run->range.end()); | 1224 size_t position = LayoutIndexToTextIndex(run->range.end()); |
1225 position = IndexOfAdjacentGrapheme(position, CURSOR_BACKWARD); | 1225 position = IndexOfAdjacentGrapheme(position, CURSOR_BACKWARD); |
1226 return SelectionModel(position, CURSOR_FORWARD); | 1226 return SelectionModel(position, CURSOR_FORWARD); |
1227 } | 1227 } |
1228 | 1228 |
1229 RenderText* RenderText::CreateNativeInstance() { | 1229 RenderText* RenderText::CreateNativeInstance() { |
1230 return new RenderTextWin; | 1230 return new RenderTextWin; |
1231 } | 1231 } |
1232 | 1232 |
1233 } // namespace gfx | 1233 } // namespace gfx |
OLD | NEW |