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

Unified Diff: ui/gfx/render_text.cc

Issue 8725002: Draw text via Skia in RenderTextLinux. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years 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 side-by-side diff with in-line comments
Download patch
Index: ui/gfx/render_text.cc
===================================================================
--- ui/gfx/render_text.cc (revision 112983)
+++ ui/gfx/render_text.cc (working copy)
@@ -9,6 +9,7 @@
#include "base/i18n/break_iterator.h"
#include "base/logging.h"
#include "base/stl_util.h"
+#include "third_party/skia/include/core/SkTypeface.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/canvas_skia.h"
#include "unicode/uchar.h"
@@ -79,6 +80,83 @@
namespace gfx {
+namespace internal {
+
+SkiaTextRenderer::SkiaTextRenderer(Canvas* canvas)
+ : canvas_skia_(canvas->GetSkCanvas()) {
+ DCHECK(canvas_skia_);
+}
+
+SkiaTextRenderer::~SkiaTextRenderer() {
+}
+
+void SkiaTextRenderer::Init() {
+ paint_.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
msw 2011/12/06 18:40:56 Why not roll this into the ctor?
Alexei Svitkine (slow) 2011/12/06 19:10:12 I guess I followed our style that we shouldn't do
+ paint_.setStyle(SkPaint::kFill_Style);
+ paint_.setAntiAlias(true);
+ paint_.setSubpixelText(true);
+ paint_.setLCDRenderText(true);
+}
+
+void SkiaTextRenderer::SetFont(const gfx::Font& font) {
+ SkTypeface* typeface =
+ SkTypeface::CreateFromName(font.GetFontName().c_str(),
+ SkTypeface::kNormal);
+ if (typeface) {
+ paint_.setTypeface(typeface);
+ // |paint_| adds its own ref. Release the ref from |CreateFromName()|.
msw 2011/12/06 18:40:56 Then shouldn't |typeface| be a scoped refptr or so
Alexei Svitkine (slow) 2011/12/06 19:10:12 The Chromium scoped_refptr won't work, since its a
msw 2011/12/07 01:08:45 Thanks for enlightening me!
+ typeface->unref();
+ }
+ paint_.setTextSize(font.GetFontSize());
+}
+
+void SkiaTextRenderer::SetForegroundColor(SkColor foreground) {
+ paint_.setColor(foreground);
+}
+
+void SkiaTextRenderer::DrawPosText(const SkPoint* pos,
+ const uint16* glyphs,
msw 2011/12/06 18:40:56 Indent these args.
Alexei Svitkine (slow) 2011/12/06 19:10:12 Done.
+ size_t glyph_count) {
+ size_t byte_length = glyph_count * sizeof(glyphs[0]);
xji 2011/12/05 23:47:09 Will uint16 cause problem? PangoGlyph is a guint32
Alexei Svitkine (slow) 2011/12/06 19:10:12 It's a good question. |drawPosText()| seems to onl
+ canvas_skia_->drawPosText(&glyphs[0], byte_length, &pos[0], paint_);
+}
+
+// Draw underline and strike through text decorations.
+// Based on |SkCanvas::DrawTextDecorations()| and constants from:
+// third_party/skia/src/core/SkTextFormatParams.h
+void SkiaTextRenderer::DrawDecorations(int x, int y, int width,
+ bool underline, bool strike) {
+ // Fraction of the text size to lower a strike through below the baseline.
+ const SkScalar kStrikeThroughOffset = (-SK_Scalar1 * 6 / 21);
+ // Fraction of the text size to lower an underline below the baseline.
+ const SkScalar kUnderlineOffset = (SK_Scalar1 / 9);
+ // Fraction of the text size to use for a strike through or under-line.
+ const SkScalar kLineThickness = (SK_Scalar1 / 18);
+
+ SkScalar text_size = paint_.getTextSize();
+ SkScalar height = SkScalarMul(text_size, kLineThickness);
+ SkRect r;
+
+ r.fLeft = x;
+ r.fRight = x + width;
+
+ if (underline) {
+ SkScalar offset = SkScalarMulAdd(text_size, kUnderlineOffset, y);
+ r.fTop = offset;
+ r.fBottom = offset + height;
+ canvas_skia_->drawRect(r, paint_);
+ }
+ if (strike) {
+ SkScalar offset = SkScalarMulAdd(text_size, kStrikeThroughOffset, y);
+ r.fTop = offset;
+ r.fBottom = offset + height;
+ canvas_skia_->drawRect(r, paint_);
+ }
+}
+
+} // namespace internal
+
+
StyleRange::StyleRange()
: font(),
foreground(SK_ColorBLACK),

Powered by Google App Engine
This is Rietveld 408576698