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

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

Issue 19734003: Fixes vertical alignment of RenderTextWin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 renderer.DrawPosText(&pos[0], run->glyphs.get(), run->glyph_count); 481 renderer.DrawPosText(&pos[0], run->glyphs.get(), run->glyph_count);
482 renderer.DrawDecorations(x, y, run->width, run->underline, run->strike, 482 renderer.DrawDecorations(x, y, run->width, run->underline, run->strike,
483 run->diagonal_strike); 483 run->diagonal_strike);
484 484
485 x = glyph_x; 485 x = glyph_x;
486 } 486 }
487 } 487 }
488 488
489 void RenderTextWin::ItemizeLogicalText() { 489 void RenderTextWin::ItemizeLogicalText() {
490 runs_.clear(); 490 runs_.clear();
491 string_size_ = Size(0, GetFont().GetHeight()); 491 string_size_ = Size(0, font_list().GetHeight());
492 common_baseline_ = 0; 492 common_baseline_ = font_list().GetBaseline();
Alexei Svitkine (slow) 2013/07/24 15:29:48 This value will be clobbered unless the text is em
Yuki 2013/07/25 14:32:41 Done.
493 493
494 // Set Uniscribe's base text direction. 494 // Set Uniscribe's base text direction.
495 script_state_.uBidiLevel = 495 script_state_.uBidiLevel =
496 (GetTextDirection() == base::i18n::RIGHT_TO_LEFT) ? 1 : 0; 496 (GetTextDirection() == base::i18n::RIGHT_TO_LEFT) ? 1 : 0;
497 497
498 if (text().empty()) 498 if (text().empty())
499 return; 499 return;
500 500
501 HRESULT hr = E_OUTOFMEMORY; 501 HRESULT hr = E_OUTOFMEMORY;
502 int script_items_count = 0; 502 int script_items_count = 0;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 UndoCompositionAndSelectionStyles(); 557 UndoCompositionAndSelectionStyles();
558 } 558 }
559 559
560 void RenderTextWin::LayoutVisualText() { 560 void RenderTextWin::LayoutVisualText() {
561 DCHECK(!runs_.empty()); 561 DCHECK(!runs_.empty());
562 562
563 if (!cached_hdc_) 563 if (!cached_hdc_)
564 cached_hdc_ = CreateCompatibleDC(NULL); 564 cached_hdc_ = CreateCompatibleDC(NULL);
565 565
566 HRESULT hr = E_FAIL; 566 HRESULT hr = E_FAIL;
567 string_size_.set_height(0); 567 int ascent = font_list().GetBaseline();
568 int descent = font_list().GetHeight() - font_list().GetBaseline();
Alexei Svitkine (slow) 2013/07/24 15:29:48 I'm not sure it makes sense to start with the metr
msw 2013/07/24 18:02:36 Using just the fonts of the runs and not including
Alexei Svitkine (slow) 2013/07/24 18:12:28 Ah, I understand now. Thanks for the explanation -
Yuki 2013/07/25 14:32:41 Done.
568 for (size_t i = 0; i < runs_.size(); ++i) { 569 for (size_t i = 0; i < runs_.size(); ++i) {
569 internal::TextRun* run = runs_[i]; 570 internal::TextRun* run = runs_[i];
570 LayoutTextRun(run); 571 LayoutTextRun(run);
571 572
572 string_size_.set_height(std::max(string_size_.height(), 573 ascent = std::max(ascent, run->font.GetBaseline());
573 run->font.GetHeight())); 574 descent = std::max(descent,
574 common_baseline_ = std::max(common_baseline_, run->font.GetBaseline()); 575 run->font.GetHeight() - run->font.GetBaseline());
575 576
576 if (run->glyph_count > 0) { 577 if (run->glyph_count > 0) {
577 run->advance_widths.reset(new int[run->glyph_count]); 578 run->advance_widths.reset(new int[run->glyph_count]);
578 run->offsets.reset(new GOFFSET[run->glyph_count]); 579 run->offsets.reset(new GOFFSET[run->glyph_count]);
579 hr = ScriptPlace(cached_hdc_, 580 hr = ScriptPlace(cached_hdc_,
580 &run->script_cache, 581 &run->script_cache,
581 run->glyphs.get(), 582 run->glyphs.get(),
582 run->glyph_count, 583 run->glyph_count,
583 run->visible_attributes.get(), 584 run->visible_attributes.get(),
584 &(run->script_analysis), 585 &(run->script_analysis),
585 run->advance_widths.get(), 586 run->advance_widths.get(),
586 run->offsets.get(), 587 run->offsets.get(),
587 &(run->abc_widths)); 588 &(run->abc_widths));
588 DCHECK(SUCCEEDED(hr)); 589 DCHECK(SUCCEEDED(hr));
589 } 590 }
590 } 591 }
592 string_size_.set_height(ascent + descent);
593 common_baseline_ = ascent;
591 594
592 // Build the array of bidirectional embedding levels. 595 // Build the array of bidirectional embedding levels.
593 scoped_ptr<BYTE[]> levels(new BYTE[runs_.size()]); 596 scoped_ptr<BYTE[]> levels(new BYTE[runs_.size()]);
594 for (size_t i = 0; i < runs_.size(); ++i) 597 for (size_t i = 0; i < runs_.size(); ++i)
595 levels[i] = runs_[i]->script_analysis.s.uBidiLevel; 598 levels[i] = runs_[i]->script_analysis.s.uBidiLevel;
596 599
597 // Get the maps between visual and logical run indices. 600 // Get the maps between visual and logical run indices.
598 visual_to_logical_.reset(new int[runs_.size()]); 601 visual_to_logical_.reset(new int[runs_.size()]);
599 logical_to_visual_.reset(new int[runs_.size()]); 602 logical_to_visual_.reset(new int[runs_.size()]);
600 hr = ScriptLayout(runs_.size(), 603 hr = ScriptLayout(runs_.size(),
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 size_t position = LayoutIndexToTextIndex(run->range.end()); 832 size_t position = LayoutIndexToTextIndex(run->range.end());
830 position = IndexOfAdjacentGrapheme(position, CURSOR_BACKWARD); 833 position = IndexOfAdjacentGrapheme(position, CURSOR_BACKWARD);
831 return SelectionModel(position, CURSOR_FORWARD); 834 return SelectionModel(position, CURSOR_FORWARD);
832 } 835 }
833 836
834 RenderText* RenderText::CreateInstance() { 837 RenderText* RenderText::CreateInstance() {
835 return new RenderTextWin; 838 return new RenderTextWin;
836 } 839 }
837 840
838 } // namespace gfx 841 } // namespace gfx
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698