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

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

Issue 387743002: Apply hinting in SkiaTextRenderer::SetFontRenderParams(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add fallback return Created 6 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 | Annotate | Revision Log
« no previous file with comments | « ui/gfx/render_text.h ('k') | ui/gfx/render_text_pango.cc » ('j') | 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.h" 5 #include "ui/gfx/render_text.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <climits> 8 #include <climits>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 149
150 SkPoint points[2]; 150 SkPoint points[2];
151 points[0].iset(text_rect.x(), text_rect.y()); 151 points[0].iset(text_rect.x(), text_rect.y());
152 points[1].iset(text_rect.right(), text_rect.y()); 152 points[1].iset(text_rect.right(), text_rect.y());
153 153
154 return skia::AdoptRef( 154 return skia::AdoptRef(
155 SkGradientShader::CreateLinear(&points[0], &colors[0], &positions[0], 155 SkGradientShader::CreateLinear(&points[0], &colors[0], &positions[0],
156 colors.size(), SkShader::kClamp_TileMode)); 156 colors.size(), SkShader::kClamp_TileMode));
157 } 157 }
158 158
159 // Converts a FontRenderParams::Hinting value to the corresponding
160 // SkPaint::Hinting value.
161 SkPaint::Hinting FontRenderParamsHintingToSkPaintHinting(
162 FontRenderParams::Hinting params_hinting) {
163 switch (params_hinting) {
164 case FontRenderParams::HINTING_NONE: return SkPaint::kNo_Hinting;
165 case FontRenderParams::HINTING_SLIGHT: return SkPaint::kSlight_Hinting;
166 case FontRenderParams::HINTING_MEDIUM: return SkPaint::kNormal_Hinting;
167 case FontRenderParams::HINTING_FULL: return SkPaint::kFull_Hinting;
168 }
169 return SkPaint::kNo_Hinting;
170 }
171
159 } // namespace 172 } // namespace
160 173
161 namespace internal { 174 namespace internal {
162 175
163 // Value of |underline_thickness_| that indicates that underline metrics have 176 // Value of |underline_thickness_| that indicates that underline metrics have
164 // not been set explicitly. 177 // not been set explicitly.
165 const SkScalar kUnderlineMetricsNotSet = -1.0f; 178 const SkScalar kUnderlineMetricsNotSet = -1.0f;
166 179
167 SkiaTextRenderer::SkiaTextRenderer(Canvas* canvas) 180 SkiaTextRenderer::SkiaTextRenderer(Canvas* canvas)
168 : canvas_(canvas), 181 : canvas_(canvas),
(...skipping 29 matching lines...) Expand all
198 void SkiaTextRenderer::SetDrawLooper(SkDrawLooper* draw_looper) { 211 void SkiaTextRenderer::SetDrawLooper(SkDrawLooper* draw_looper) {
199 paint_.setLooper(draw_looper); 212 paint_.setLooper(draw_looper);
200 } 213 }
201 214
202 void SkiaTextRenderer::SetFontRenderParams(const FontRenderParams& params, 215 void SkiaTextRenderer::SetFontRenderParams(const FontRenderParams& params,
203 bool background_is_transparent) { 216 bool background_is_transparent) {
204 paint_.setAntiAlias(params.antialiasing); 217 paint_.setAntiAlias(params.antialiasing);
205 paint_.setLCDRenderText(!background_is_transparent && 218 paint_.setLCDRenderText(!background_is_transparent &&
206 params.subpixel_rendering != FontRenderParams::SUBPIXEL_RENDERING_NONE); 219 params.subpixel_rendering != FontRenderParams::SUBPIXEL_RENDERING_NONE);
207 paint_.setSubpixelText(params.subpixel_positioning); 220 paint_.setSubpixelText(params.subpixel_positioning);
208 } 221 paint_.setAutohinted(params.autohinter);
209 222 paint_.setHinting(FontRenderParamsHintingToSkPaintHinting(params.hinting));
210 void SkiaTextRenderer::SetFontHinting(SkPaint::Hinting hinting) {
211 paint_.setHinting(hinting);
212 } 223 }
213 224
214 void SkiaTextRenderer::SetTypeface(SkTypeface* typeface) { 225 void SkiaTextRenderer::SetTypeface(SkTypeface* typeface) {
215 paint_.setTypeface(typeface); 226 paint_.setTypeface(typeface);
216 } 227 }
217 228
218 void SkiaTextRenderer::SetTextSize(SkScalar size) { 229 void SkiaTextRenderer::SetTextSize(SkScalar size) {
219 paint_.setTextSize(size); 230 paint_.setTextSize(size);
220 } 231 }
221 232
(...skipping 1131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1353 cursor_bounds_ += delta_offset; 1364 cursor_bounds_ += delta_offset;
1354 } 1365 }
1355 1366
1356 void RenderText::DrawSelection(Canvas* canvas) { 1367 void RenderText::DrawSelection(Canvas* canvas) {
1357 const std::vector<Rect> sel = GetSubstringBounds(selection()); 1368 const std::vector<Rect> sel = GetSubstringBounds(selection());
1358 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) 1369 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i)
1359 canvas->FillRect(*i, selection_background_focused_color_); 1370 canvas->FillRect(*i, selection_background_focused_color_);
1360 } 1371 }
1361 1372
1362 } // namespace gfx 1373 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/render_text.h ('k') | ui/gfx/render_text_pango.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698