OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
582 | 582 |
583 void RenderTextWin::DrawVisualText(Canvas* canvas) { | 583 void RenderTextWin::DrawVisualText(Canvas* canvas) { |
584 if (text().empty()) | 584 if (text().empty()) |
585 return; | 585 return; |
586 | 586 |
587 SkCanvas* canvas_skia = canvas->GetSkCanvas(); | 587 SkCanvas* canvas_skia = canvas->GetSkCanvas(); |
588 | 588 |
589 Point offset(ToViewPoint(Point())); | 589 Point offset(ToViewPoint(Point())); |
590 // TODO(msw): Establish a vertical baseline for strings of mixed font heights. | 590 // TODO(msw): Establish a vertical baseline for strings of mixed font heights. |
591 size_t height = default_style().font.GetHeight(); | 591 size_t height = default_style().font.GetHeight(); |
592 | |
593 float base_x = SkIntToScalar(offset.x()); | |
594 float base_y = SkIntToScalar(offset.y()); | |
592 // Center the text vertically in the display area. | 595 // Center the text vertically in the display area. |
593 offset.Offset(0, (display_rect().height() - height) / 2); | 596 base_y += (display_rect().height() - default_style().font.GetHeight()) / 2; |
msw
2011/10/27 18:09:29
You have an extra space after the minus symbol '-'
| |
597 // Offset by the font size to account for Skia expecting y to be the bottom. | |
598 base_y += default_style().font.GetFontSize(); | |
594 | 599 |
595 SkPaint paint; | 600 SkPaint paint; |
596 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 601 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
597 paint.setStyle(SkPaint::kFill_Style); | 602 paint.setStyle(SkPaint::kFill_Style); |
598 paint.setAntiAlias(true); | 603 paint.setAntiAlias(true); |
599 paint.setSubpixelText(true); | 604 paint.setSubpixelText(true); |
600 paint.setLCDRenderText(true); | 605 paint.setLCDRenderText(true); |
601 SkPoint point(SkPoint::Make(SkIntToScalar(offset.x()), | 606 |
602 SkIntToScalar(display_rect().height() - offset.y()))); | |
603 scoped_array<SkPoint> pos; | 607 scoped_array<SkPoint> pos; |
604 for (size_t i = 0; i < runs_.size(); ++i) { | 608 for (size_t i = 0; i < runs_.size(); ++i) { |
605 // Get the run specified by the visual-to-logical map. | 609 // Get the run specified by the visual-to-logical map. |
606 internal::TextRun* run = runs_[visual_to_logical_[i]]; | 610 internal::TextRun* run = runs_[visual_to_logical_[i]]; |
607 | 611 |
608 // TODO(msw): Font default/fallback and style integration. | 612 // TODO(msw): Font default/fallback and style integration. |
609 std::string font(UTF16ToASCII(run->font.GetFontName())); | 613 std::string font(UTF16ToASCII(run->font.GetFontName())); |
610 SkTypeface::Style style = SkTypeface::kNormal; | 614 SkTypeface::Style style = SkTypeface::kNormal; |
611 SkTypeface* typeface = SkTypeface::CreateFromName(font.c_str(), style); | 615 SkTypeface* typeface = SkTypeface::CreateFromName(font.c_str(), style); |
612 if (typeface) { | 616 if (typeface) { |
613 paint.setTypeface(typeface); | 617 paint.setTypeface(typeface); |
614 // |paint| adds its own ref. Release the ref from CreateFromName. | 618 // |paint| adds its own ref. Release the ref from CreateFromName. |
615 typeface->unref(); | 619 typeface->unref(); |
616 } | 620 } |
617 paint.setTextSize(run->font.GetFontSize()); | 621 paint.setTextSize(run->font.GetFontSize()); |
618 paint.setColor(run->foreground); | 622 paint.setColor(run->foreground); |
619 | 623 |
620 // Based on WebCore::skiaDrawText. | 624 // Based on WebCore::skiaDrawText. |
621 pos.reset(new SkPoint[run->glyph_count]); | 625 pos.reset(new SkPoint[run->glyph_count]); |
622 for (int glyph = 0; glyph < run->glyph_count; glyph++) { | 626 for (int glyph = 0; glyph < run->glyph_count; glyph++) { |
623 pos[glyph].set(point.x() + run->offsets[glyph].du, | 627 pos[glyph].set(base_x + run->offsets[glyph].du, |
624 point.y() + run->offsets[glyph].dv); | 628 base_y + run->offsets[glyph].dv); |
625 point.offset(SkIntToScalar(run->advance_widths[glyph]), 0); | 629 base_x += SkIntToScalar(run->advance_widths[glyph]); |
626 } | 630 } |
627 size_t byte_length = run->glyph_count * sizeof(WORD); | 631 size_t byte_length = run->glyph_count * sizeof(WORD); |
628 canvas_skia->drawPosText(run->glyphs.get(), byte_length, pos.get(), paint); | 632 canvas_skia->drawPosText(run->glyphs.get(), byte_length, pos.get(), paint); |
629 | 633 |
630 // Draw the strikethrough. | 634 // Draw the strikethrough. |
631 if (run->strike) { | 635 if (run->strike) { |
632 Rect bounds(offset, Size(run->width, run->font.GetHeight())); | 636 Rect bounds(offset, Size(run->width, run->font.GetHeight())); |
633 SkPaint strike; | 637 SkPaint strike; |
634 strike.setAntiAlias(true); | 638 strike.setAntiAlias(true); |
635 strike.setStyle(SkPaint::kFill_Style); | 639 strike.setStyle(SkPaint::kFill_Style); |
(...skipping 16 matching lines...) Expand all Loading... | |
652 Rect r(GetUpdatedCursorBounds()); | 656 Rect r(GetUpdatedCursorBounds()); |
653 canvas->DrawRectInt(kCursorColor, r.x(), r.y(), r.width(), r.height()); | 657 canvas->DrawRectInt(kCursorColor, r.x(), r.y(), r.width(), r.height()); |
654 } | 658 } |
655 } | 659 } |
656 | 660 |
657 RenderText* RenderText::CreateRenderText() { | 661 RenderText* RenderText::CreateRenderText() { |
658 return new RenderTextWin; | 662 return new RenderTextWin; |
659 } | 663 } |
660 | 664 |
661 } // namespace gfx | 665 } // namespace gfx |
OLD | NEW |