Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(417)

Side by Side Diff: ui/gfx/render_text_win.cc

Issue 16867016: Windows implementation of multiline RenderText (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Mike's comments Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/rtl.h" 10 #include "base/i18n/rtl.h"
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 } else { 147 } else {
148 result = ui::Range(run.logical_clusters[run_range.start()], 148 result = ui::Range(run.logical_clusters[run_range.start()],
149 run_range.end() < run.range.length() ? 149 run_range.end() < run.range.length() ?
150 run.logical_clusters[run_range.end()] : run.glyph_count); 150 run.logical_clusters[run_range.end()] : run.glyph_count);
151 } 151 }
152 DCHECK(!result.is_reversed()); 152 DCHECK(!result.is_reversed());
153 DCHECK(ui::Range(0, run.glyph_count).Contains(result)); 153 DCHECK(ui::Range(0, run.glyph_count).Contains(result));
154 return result; 154 return result;
155 } 155 }
156 156
157 // Starting from |start_char|, finds a suitable line break position at or before
158 // |available_width| using word break info from |breaks|. If |empty_line| is
159 // true, this function will not roll back to |start_char| and |*pos| will be
160 // greater than |start_char|.
161 // TODO(ckocagil): Do not break ligatures and diacritics.
162 // TextRun::logical_clusters might help.
163 // TODO(ckocagil): We might have to reshape after breaking at ligatures.
164 // See whether resolving the TODO above resolves this too.
165 // TODO(ckocagil): Do not reserve space for whitespace at the end of lines.
166 bool BreakRunAtWidth(const internal::TextRun& run,
167 const BreakList<size_t>& breaks,
168 size_t start_char,
169 int available_width,
170 bool empty_line,
171 int* width,
172 size_t* pos) {
173 DCHECK(run.range.Contains(ui::Range(start_char)));
174 BreakList<size_t>::const_iterator word = breaks.GetBreak(start_char);
175 BreakList<size_t>::const_iterator next_word = word + 1;
176 // Width from |std::max(word->first, start_char)|.
177 int word_width = 0;
178 *width = 0;
179
180 for (size_t i = start_char; i < run.range.end(); ++i) {
181 if (next_word != breaks.breaks().end() && i >= next_word->first) {
182 word = next_word++;
183 word_width = 0;
184 }
185
186 ui::Range glyphs = CharRangeToGlyphRange(run, ui::Range(i, i + 1));
187 int char_width = 0;
188 for (size_t j = glyphs.start(); j < glyphs.end(); ++j)
189 char_width += run.advance_widths[j];
190
191 *width += char_width;
192 word_width += char_width;
193
194 if (*width > available_width) {
195 if (!empty_line || word_width < *width) {
196 *width -= word_width;
197 *pos = std::max(word->first, start_char);
198 } else if (char_width < *width) {
199 *width -= char_width;
200 *pos = i;
201 } else {
202 *pos = i + 1;
203 }
204
205 return true;
206 }
207 }
208
209 *pos = run.range.end();
210 return false;
211 }
212
157 } // namespace 213 } // namespace
158 214
159 namespace internal { 215 namespace internal {
160 216
161 TextRun::TextRun() 217 TextRun::TextRun()
162 : font_style(0), 218 : font_style(0),
163 strike(false), 219 strike(false),
164 diagonal_strike(false), 220 diagonal_strike(false),
165 underline(false), 221 underline(false),
166 width(0), 222 width(0),
(...skipping 23 matching lines...) Expand all
190 run->glyph_count, 246 run->glyph_count,
191 run->logical_clusters.get(), 247 run->logical_clusters.get(),
192 run->visible_attributes.get(), 248 run->visible_attributes.get(),
193 run->advance_widths.get(), 249 run->advance_widths.get(),
194 &run->script_analysis, 250 &run->script_analysis,
195 &x); 251 &x);
196 DCHECK(SUCCEEDED(hr)); 252 DCHECK(SUCCEEDED(hr));
197 return run->preceding_run_widths + x; 253 return run->preceding_run_widths + x;
198 } 254 }
199 255
256 // Internal class to generate Line structures. If |multiline| is true, the text
257 // is broken into lines at |words| boundaries such that each line is no longer
258 // than |max_width|. If |multiline| is false, only outputs a single Line from
259 // the given runs.
260 class LineBreaker {
261 public:
262 LineBreaker(int max_width,
263 bool multiline,
264 const BreakList<size_t>* words,
265 const ScopedVector<TextRun>& runs)
266 : max_width_(max_width),
267 multiline_(multiline),
268 words_(words),
269 runs_(runs),
270 segment_start_(0),
271 text_x_(0),
272 line_x_(0),
273 total_height_(0),
274 common_width_(0),
275 line_ascent_(0),
276 line_descent_(0) {
277 AdvanceLine();
278 }
279
280 // Breaks the run at given |run_index| into Line structs.
281 void AddRun(int run_index) {
282 TextRun* run = runs_[run_index];
283 segment_start_ = run->range.start();
284 int width = run->width;
285 if (multiline_ && line_x_ + width > max_width_)
286 width = BreakRun(run_index);
287 // Remaining part of the run fits the line, add it as well.
288 AddSegment(run_index, run->range.end(), width);
289 }
290
291 // Finishes line breaking and outputs the results. Can be called at most once.
292 void Finalize(std::vector<Line>* lines, Size* size) {
293 DCHECK(!lines_.empty());
294 // Add an empty line to finish the line size calculation and remove it.
295 AdvanceLine();
296 lines_.pop_back();
297 *size = Size(common_width_,
298 lines_.back().preceding_heights + lines_.back().size.height());
299 lines->swap(lines_);
300 }
301
302 private:
303 // Breaks a run into segments of at most |max_width_| width, adds all but the
304 // final segment to |lines_.back()|, returns the width of that final segment.
305 int BreakRun(int run_index) {
306 DCHECK(words_);
307 int width = 0;
308 size_t next_pos = 0;
309
310 // Break the run until it fits the current line.
311 while (BreakRunAtWidth(*runs_[run_index], *words_, segment_start_,
312 max_width_ - line_x_, line_x_ == 0, &width,
313 &next_pos)) {
314 DCHECK_LT(segment_start_, runs_[run_index]->range.end());
315 AddSegment(run_index, next_pos, width);
316 AdvanceLine();
317 }
318
319 return width;
320 }
321
322 // RTL runs are broken in logical order but displayed in visual order. To find
323 // the text-space coordinate (where it would fall in a single-line text)
324 // |x_range| of RTL segments, segment widths are applied in reverse order.
325 // e.g. {[5, 10], [10, 40]} will become {[35, 40], [5, 35]}.
326 void PopRtl() {
327 if (rtl_segments_.empty())
328 return;
329 int x = rtl_segments_[0]->x_range.start();
330 for (size_t i = rtl_segments_.size(); i > 0; --i) {
331 LineSegment* segment = rtl_segments_[i - 1];
332 segment->x_range = ui::Range(x, x + segment->x_range.length());
333 x += segment->x_range.length();
334 }
335 rtl_segments_.clear();
336 }
337
338 void AdvanceLine() {
339 if (!lines_.empty()) {
340 Line* line = &lines_.back();
341 line->baseline = line_ascent_;
342 line->size.set_height(line_ascent_ + line_descent_);
343 line->preceding_heights = total_height_;
344 total_height_ += line->size.height();
345 common_width_ = std::max(common_width_, line->size.width());
346 }
347 line_x_ = 0;
348 line_ascent_ = 0;
349 line_descent_ = 0;
350 lines_.push_back(Line());
351 }
352
353 void AddSegment(int run_index, size_t segment_end, int width) {
354 if (segment_start_ == segment_end) {
msw 2013/08/21 16:46:23 Does this actually happen? Should it DCHECK_NE ins
ckocagil 2013/08/23 21:45:34 I checked it, it happens. I can move this to the c
355 DCHECK_EQ(width, 0);
356 return;
357 }
358 const TextRun* run = runs_[run_index];
359 line_ascent_ = std::max(line_ascent_, run->font.GetBaseline());
360 line_descent_ = std::max(line_descent_,
361 run->font.GetHeight() - run->font.GetBaseline());
362 LineSegment segment;
363 segment.run = run_index;
364 segment.char_range = ui::Range(segment_start_, segment_end);
365 segment.x_range = ui::Range(text_x_, text_x_ + width);
366 Line* line = &lines_.back();
367 line->segments.push_back(segment);
368 line->size.set_width(line->size.width() + segment.x_range.length());
369 if (run->script_analysis.fRTL) {
370 rtl_segments_.push_back(&line->segments.back());
371 if (segment_end == run->range.end())
372 PopRtl();
373 }
374 segment_start_ = segment_end;
375 text_x_ += width;
376 line_x_ += width;
377 }
378
379 const int max_width_;
380 const bool multiline_;
381 const BreakList<size_t>* const words_;
382 const ScopedVector<TextRun>& runs_;
383
384 // Stores the resulting lines.
385 std::vector<Line> lines_;
386
387 // Position information of the next segment to be added. |segment_start_| is
388 // the segment's start character position. |text_x_| and |line_x_| are
389 // text-space and line-space x coordinates of |segment_start_|.
390 size_t segment_start_;
391 int text_x_;
392 int line_x_;
393 int total_height_;
msw 2013/08/21 16:46:23 nit: combine total_height_ and common_width_ as a
ckocagil 2013/08/23 21:45:34 Done.
394
395 int common_width_;
396
397 // Ascent and descent values of the current line, |lines_.back()|.
398 int line_ascent_;
399 int line_descent_;
400
401 // Segments to be applied by |PopRtl()|.
402 std::vector<LineSegment*> rtl_segments_;
403
404 DISALLOW_COPY_AND_ASSIGN(LineBreaker);
405 };
406
200 } // namespace internal 407 } // namespace internal
201 408
202 // static 409 // static
203 HDC RenderTextWin::cached_hdc_ = NULL; 410 HDC RenderTextWin::cached_hdc_ = NULL;
204 411
205 // static 412 // static
206 std::map<std::string, Font> RenderTextWin::successful_substitute_fonts_; 413 std::map<std::string, Font> RenderTextWin::successful_substitute_fonts_;
207 414
208 RenderTextWin::RenderTextWin() 415 RenderTextWin::RenderTextWin()
209 : RenderText(), 416 : RenderText(),
210 common_baseline_(0), 417 common_baseline_(0),
211 needs_layout_(false) { 418 needs_layout_(false) {
212 set_truncate_length(kMaxUniscribeTextLength); 419 set_truncate_length(kMaxUniscribeTextLength);
213 420
214 memset(&script_control_, 0, sizeof(script_control_)); 421 memset(&script_control_, 0, sizeof(script_control_));
215 memset(&script_state_, 0, sizeof(script_state_)); 422 memset(&script_state_, 0, sizeof(script_state_));
216 423
217 MoveCursorTo(EdgeSelectionModel(CURSOR_LEFT)); 424 MoveCursorTo(EdgeSelectionModel(CURSOR_LEFT));
218 } 425 }
219 426
220 RenderTextWin::~RenderTextWin() { 427 RenderTextWin::~RenderTextWin() {
221 } 428 }
222 429
223 Size RenderTextWin::GetStringSize() { 430 Size RenderTextWin::GetStringSize() {
224 EnsureLayout(); 431 EnsureLayout();
225 return string_size_; 432 return string_size_;
226 } 433 }
227 434
435 Size RenderTextWin::GetMultilineTextSize() {
436 if (!multiline())
437 return GetStringSize();
438 EnsureLayout();
439 return multiline_string_size_;
440 }
441
228 int RenderTextWin::GetBaseline() { 442 int RenderTextWin::GetBaseline() {
229 EnsureLayout(); 443 EnsureLayout();
230 return common_baseline_; 444 return common_baseline_;
231 } 445 }
232 446
233 SelectionModel RenderTextWin::FindCursorPosition(const Point& point) { 447 SelectionModel RenderTextWin::FindCursorPosition(const Point& point) {
234 if (text().empty()) 448 if (text().empty())
235 return SelectionModel(); 449 return SelectionModel();
236 450
237 EnsureLayout(); 451 EnsureLayout();
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 GetGlyphXBoundary(run, layout_index, true)); 590 GetGlyphXBoundary(run, layout_index, true));
377 } 591 }
378 592
379 std::vector<Rect> RenderTextWin::GetSubstringBounds(const ui::Range& range) { 593 std::vector<Rect> RenderTextWin::GetSubstringBounds(const ui::Range& range) {
380 DCHECK(!needs_layout_); 594 DCHECK(!needs_layout_);
381 DCHECK(ui::Range(0, text().length()).Contains(range)); 595 DCHECK(ui::Range(0, text().length()).Contains(range));
382 ui::Range layout_range(TextIndexToLayoutIndex(range.start()), 596 ui::Range layout_range(TextIndexToLayoutIndex(range.start()),
383 TextIndexToLayoutIndex(range.end())); 597 TextIndexToLayoutIndex(range.end()));
384 DCHECK(ui::Range(0, GetLayoutText().length()).Contains(layout_range)); 598 DCHECK(ui::Range(0, GetLayoutText().length()).Contains(layout_range));
385 599
386 std::vector<Rect> bounds; 600 std::vector<Rect> rects;
387 if (layout_range.is_empty()) 601 if (layout_range.is_empty())
388 return bounds; 602 return rects;
603 std::vector<ui::Range> bounds;
389 604
390 // Add a Rect for each run/selection intersection. 605 // Add a Range for each run/selection intersection.
391 // TODO(msw): The bounds should probably not always be leading the range ends. 606 // TODO(msw): The bounds should probably not always be leading the range ends.
392 for (size_t i = 0; i < runs_.size(); ++i) { 607 for (size_t i = 0; i < runs_.size(); ++i) {
393 const internal::TextRun* run = runs_[visual_to_logical_[i]]; 608 const internal::TextRun* run = runs_[visual_to_logical_[i]];
394 ui::Range intersection = run->range.Intersect(layout_range); 609 ui::Range intersection = run->range.Intersect(layout_range);
395 if (intersection.IsValid()) { 610 if (intersection.IsValid()) {
396 DCHECK(!intersection.is_reversed()); 611 DCHECK(!intersection.is_reversed());
397 ui::Range range_x(GetGlyphXBoundary(run, intersection.start(), false), 612 ui::Range range_x(GetGlyphXBoundary(run, intersection.start(), false),
398 GetGlyphXBoundary(run, intersection.end(), false)); 613 GetGlyphXBoundary(run, intersection.end(), false));
399 Rect rect(range_x.GetMin(), 0, range_x.length(), run->font.GetHeight()); 614 if (range_x.is_empty())
400 rect.set_origin(ToViewPoint(rect.origin())); 615 continue;
401 // Union this with the last rect if they're adjacent. 616 range_x = ui::Range(range_x.GetMin(), range_x.GetMax());
402 if (!bounds.empty() && rect.SharesEdgeWith(bounds.back())) { 617 // Union this with the last range if they're adjacent.
403 rect.Union(bounds.back()); 618 DCHECK(bounds.empty() || bounds.back().GetMin() != range_x.GetMax());
619 if (!bounds.empty() && bounds.back().GetMax() == range_x.GetMin()) {
620 range_x = ui::Range(bounds.back().GetMin(), range_x.GetMax());
404 bounds.pop_back(); 621 bounds.pop_back();
405 } 622 }
406 bounds.push_back(rect); 623 bounds.push_back(range_x);
407 } 624 }
408 } 625 }
409 return bounds; 626 for (size_t i = 0; i < bounds.size(); ++i) {
627 std::vector<Rect> current_rects = TextBoundsToViewBounds(bounds[i]);
628 rects.insert(rects.end(), current_rects.begin(), current_rects.end());
629 }
630 return rects;
410 } 631 }
411 632
412 size_t RenderTextWin::TextIndexToLayoutIndex(size_t index) const { 633 size_t RenderTextWin::TextIndexToLayoutIndex(size_t index) const {
413 DCHECK_LE(index, text().length()); 634 DCHECK_LE(index, text().length());
414 ptrdiff_t i = obscured() ? ui::UTF16IndexToOffset(text(), 0, index) : index; 635 ptrdiff_t i = obscured() ? ui::UTF16IndexToOffset(text(), 0, index) : index;
415 CHECK_GE(i, 0); 636 CHECK_GE(i, 0);
416 // Clamp layout indices to the length of the text actually used for layout. 637 // Clamp layout indices to the length of the text actually used for layout.
417 return std::min<size_t>(GetLayoutText().length(), i); 638 return std::min<size_t>(GetLayoutText().length(), i);
418 } 639 }
419 640
(...skipping 21 matching lines...) Expand all
441 position < LayoutIndexToTextIndex(GetLayoutText().length()) && 662 position < LayoutIndexToTextIndex(GetLayoutText().length()) &&
442 GetGlyphBounds(position) != GetGlyphBounds(position - 1); 663 GetGlyphBounds(position) != GetGlyphBounds(position - 1);
443 } 664 }
444 665
445 void RenderTextWin::ResetLayout() { 666 void RenderTextWin::ResetLayout() {
446 // Layout is performed lazily as needed for drawing/metrics. 667 // Layout is performed lazily as needed for drawing/metrics.
447 needs_layout_ = true; 668 needs_layout_ = true;
448 } 669 }
449 670
450 void RenderTextWin::EnsureLayout() { 671 void RenderTextWin::EnsureLayout() {
451 if (!needs_layout_) 672 if (needs_layout_) {
452 return; 673 // TODO(msw): Skip complex processing if ScriptIsComplex returns false.
453 // TODO(msw): Skip complex processing if ScriptIsComplex returns false. 674 ItemizeLogicalText();
454 ItemizeLogicalText(); 675 if (!runs_.empty())
455 if (!runs_.empty()) 676 LayoutVisualText();
456 LayoutVisualText(); 677 needs_layout_ = false;
457 needs_layout_ = false; 678 std::vector<internal::Line> lines;
679 set_lines(&lines);
680 }
681 // Compute lines if they're not valid. This is separate from the layout steps
682 // above to avoid text layout and shaping when we resize |display_rect_|.
683 if (lines().empty()) {
684 DCHECK(!needs_layout_);
685 std::vector<internal::Line> lines;
686 internal::LineBreaker line_breaker(display_rect().width() - 1, multiline(),
687 multiline() ? &GetLineBreaks() : NULL,
688 runs_);
689 for (size_t i = 0; i < runs_.size(); ++i)
690 line_breaker.AddRun(visual_to_logical_[i]);
691 line_breaker.Finalize(&lines, &multiline_string_size_);
692 DCHECK(!lines.empty());
693 set_lines(&lines);
694 }
458 } 695 }
459 696
460 void RenderTextWin::DrawVisualText(Canvas* canvas) { 697 void RenderTextWin::DrawVisualText(Canvas* canvas) {
461 DCHECK(!needs_layout_); 698 DCHECK(!needs_layout_);
462 699 DCHECK(!multiline() || !lines().empty());
463 // Skia will draw glyphs with respect to the baseline.
464 Vector2d offset(GetTextOffset() + Vector2d(0, common_baseline_));
465
466 SkScalar x = SkIntToScalar(offset.x());
467 SkScalar y = SkIntToScalar(offset.y());
468 700
469 std::vector<SkPoint> pos; 701 std::vector<SkPoint> pos;
470 702
471 internal::SkiaTextRenderer renderer(canvas); 703 internal::SkiaTextRenderer renderer(canvas);
472 ApplyFadeEffects(&renderer); 704 ApplyFadeEffects(&renderer);
473 ApplyTextShadows(&renderer); 705 ApplyTextShadows(&renderer);
474 706
475 bool smoothing_enabled; 707 bool smoothing_enabled;
476 bool cleartype_enabled; 708 bool cleartype_enabled;
477 GetCachedFontSmoothingSettings(&smoothing_enabled, &cleartype_enabled); 709 GetCachedFontSmoothingSettings(&smoothing_enabled, &cleartype_enabled);
478 // Note that |cleartype_enabled| corresponds to Skia's |enable_lcd_text|. 710 // Note that |cleartype_enabled| corresponds to Skia's |enable_lcd_text|.
479 renderer.SetFontSmoothingSettings( 711 renderer.SetFontSmoothingSettings(
480 smoothing_enabled, cleartype_enabled && !background_is_transparent()); 712 smoothing_enabled, cleartype_enabled && !background_is_transparent());
481 713
482 ApplyCompositionAndSelectionStyles(); 714 ApplyCompositionAndSelectionStyles();
483 715
484 for (size_t i = 0; i < runs_.size(); ++i) { 716 for (size_t i = 0; i < lines().size(); ++i) {
485 // Get the run specified by the visual-to-logical map. 717 const internal::Line& line = lines()[i];
486 internal::TextRun* run = runs_[visual_to_logical_[i]]; 718 Vector2d line_offset = GetLineOffset(i);
719 Vector2d text_offset = line_offset + Vector2d(0, line.baseline);
720 int preceding_segment_widths = 0;
487 721
488 // Skip painting empty runs and runs outside the display rect area. 722 // Skip painting empty lines or lines outside the display rect area.
489 if ((run->glyph_count == 0) || (x >= display_rect().right()) || 723 if (!display_rect().Intersects(Rect(PointAtOffsetFromOrigin(line_offset),
490 (x + run->width <= display_rect().x())) { 724 line.size)))
491 x += run->width;
492 continue; 725 continue;
726
727 for (size_t j = 0; j < line.segments.size(); ++j) {
728 const internal::LineSegment* segment = &line.segments[j];
729 const int segment_width = segment->x_range.length();
730 const internal::TextRun* run = runs_[segment->run];
731 DCHECK(!segment->char_range.is_empty());
732 DCHECK(run->range.Contains(segment->char_range));
733 ui::Range glyphs = CharRangeToGlyphRange(*run, segment->char_range);
734 if (glyphs.is_empty()) {
735 DCHECK(segment_width == 0);
736 continue;
737 }
738 // Skip painting segments outside the display rect area.
739 if (!multiline()) {
740 const Rect segment_bounds(PointAtOffsetFromOrigin(line_offset) +
741 Vector2d(preceding_segment_widths, 0),
742 Size(segment_width, line.size.height()));
743 if (!display_rect().Intersects(segment_bounds)) {
744 preceding_segment_widths += segment_width;
745 continue;
746 }
747 }
748
749 // |pos| contains the positions of glyphs. An extra terminal |pos| entry
750 // is added to simplify width calculations.
751 int segment_x = 0;
msw 2013/08/21 16:46:23 Init this to |preceding_segment_widths|.
ckocagil 2013/08/23 21:45:34 Done.
752 pos.resize(glyphs.length() + 1);
753 for (size_t g = glyphs.start(); g < glyphs.end(); ++g) {
754 pos[g - glyphs.start()].set(
755 SkIntToScalar(text_offset.x() + preceding_segment_widths +
756 segment_x + run->offsets[g].du),
757 SkIntToScalar(text_offset.y() + run->offsets[g].dv));
758 segment_x += run->advance_widths[g];
759 }
760 pos.back().set(
761 SkIntToScalar(text_offset.x() + preceding_segment_widths + segment_x),
762 SkIntToScalar(text_offset.y()));
763
764 renderer.SetTextSize(run->font.GetFontSize());
765 renderer.SetFontFamilyWithStyle(run->font.GetFontName(), run->font_style);
766
767 for (BreakList<SkColor>::const_iterator it =
768 colors().GetBreak(run->range.start());
769 it != colors().breaks().end() && it->first < run->range.end();
770 ++it) {
771 const ui::Range intersection =
772 colors().GetRange(it).Intersect(segment->char_range);
773 const ui::Range colored_glyphs =
774 CharRangeToGlyphRange(*run, intersection);
775 DCHECK(glyphs.Contains(colored_glyphs));
776 if (colored_glyphs.is_empty())
777 continue;
778 renderer.SetForegroundColor(it->second);
779 renderer.DrawPosText(&pos[colored_glyphs.start() - glyphs.start()],
780 &run->glyphs[colored_glyphs.start()],
781 colored_glyphs.length());
782 const SkScalar width = pos[colored_glyphs.end() - glyphs.start()].x() -
783 pos[colored_glyphs.start() - glyphs.start()].x();
784 renderer.DrawDecorations(
785 pos[colored_glyphs.start() - glyphs.start()].x(), text_offset.y(),
786 SkScalarCeilToInt(width), run->underline, run->strike,
787 run->diagonal_strike);
788 }
789
790 preceding_segment_widths += segment_width;
493 } 791 }
494
495 // Based on WebCore::skiaDrawText. |pos| contains the positions of glyphs.
496 // An extra terminal |pos| entry is added to simplify width calculations.
497 pos.resize(run->glyph_count + 1);
498 SkScalar glyph_x = x;
499 for (int glyph = 0; glyph < run->glyph_count; glyph++) {
500 pos[glyph].set(glyph_x + run->offsets[glyph].du,
501 y + run->offsets[glyph].dv);
502 glyph_x += SkIntToScalar(run->advance_widths[glyph]);
503 }
504 pos.back().set(glyph_x, y);
505
506 renderer.SetTextSize(run->font.GetFontSize());
507 renderer.SetFontFamilyWithStyle(run->font.GetFontName(), run->font_style);
508
509 for (BreakList<SkColor>::const_iterator it =
510 colors().GetBreak(run->range.start());
511 it != colors().breaks().end() && it->first < run->range.end();
512 ++it) {
513 const ui::Range glyph_range = CharRangeToGlyphRange(*run,
514 colors().GetRange(it).Intersect(run->range));
515 if (glyph_range.is_empty())
516 continue;
517 renderer.SetForegroundColor(it->second);
518 renderer.DrawPosText(&pos[glyph_range.start()],
519 &run->glyphs[glyph_range.start()],
520 glyph_range.length());
521 const SkScalar width = pos[glyph_range.end()].x() -
522 pos[glyph_range.start()].x();
523 renderer.DrawDecorations(pos[glyph_range.start()].x(), y,
524 SkScalarCeilToInt(width), run->underline,
525 run->strike, run->diagonal_strike);
526 }
527
528 DCHECK_EQ(glyph_x - x, run->width);
529 x = glyph_x;
530 } 792 }
531 793
532 UndoCompositionAndSelectionStyles(); 794 UndoCompositionAndSelectionStyles();
533 } 795 }
534 796
535 void RenderTextWin::ItemizeLogicalText() { 797 void RenderTextWin::ItemizeLogicalText() {
536 runs_.clear(); 798 runs_.clear();
537 // Make |string_size_|'s height and |common_baseline_| tall enough to draw 799 // Make |string_size_|'s height and |common_baseline_| tall enough to draw
538 // often-used characters which are rendered with fonts in the font list. 800 // often-used characters which are rendered with fonts in the font list.
539 string_size_ = Size(0, font_list().GetHeight()); 801 string_size_ = Size(0, font_list().GetHeight());
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 size_t position = LayoutIndexToTextIndex(run->range.end()); 1159 size_t position = LayoutIndexToTextIndex(run->range.end());
898 position = IndexOfAdjacentGrapheme(position, CURSOR_BACKWARD); 1160 position = IndexOfAdjacentGrapheme(position, CURSOR_BACKWARD);
899 return SelectionModel(position, CURSOR_FORWARD); 1161 return SelectionModel(position, CURSOR_FORWARD);
900 } 1162 }
901 1163
902 RenderText* RenderText::CreateInstance() { 1164 RenderText* RenderText::CreateInstance() {
903 return new RenderTextWin; 1165 return new RenderTextWin;
904 } 1166 }
905 1167
906 } // namespace gfx 1168 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698