OLD | NEW |
---|---|
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 | 8 |
9 #include "base/i18n/break_iterator.h" | 9 #include "base/i18n/break_iterator.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 return SkGradientShader::CreateLinear(&points[0], &colors[0], &positions[0], | 172 return SkGradientShader::CreateLinear(&points[0], &colors[0], &positions[0], |
173 colors.size(), SkShader::kClamp_TileMode); | 173 colors.size(), SkShader::kClamp_TileMode); |
174 } | 174 } |
175 | 175 |
176 } // namespace | 176 } // namespace |
177 | 177 |
178 namespace gfx { | 178 namespace gfx { |
179 | 179 |
180 namespace internal { | 180 namespace internal { |
181 | 181 |
182 // Indicates that an underline metric has not been set explicitly. | |
183 const SkScalar kUnderlineMetricNotSet = SK_ScalarNaN; | |
msw
2012/06/06 18:35:25
optional nit: just using SK_ScalarNaN directly it
Alexei Svitkine (slow)
2012/06/06 18:46:23
Done.
| |
184 | |
182 SkiaTextRenderer::SkiaTextRenderer(Canvas* canvas) | 185 SkiaTextRenderer::SkiaTextRenderer(Canvas* canvas) |
183 : canvas_skia_(canvas->sk_canvas()), | 186 : canvas_skia_(canvas->sk_canvas()), |
184 started_drawing_(false) { | 187 started_drawing_(false), |
188 underline_thickness_(kUnderlineMetricNotSet), | |
189 underline_position_(kUnderlineMetricNotSet) { | |
185 DCHECK(canvas_skia_); | 190 DCHECK(canvas_skia_); |
186 paint_.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 191 paint_.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
187 paint_.setStyle(SkPaint::kFill_Style); | 192 paint_.setStyle(SkPaint::kFill_Style); |
188 paint_.setAntiAlias(true); | 193 paint_.setAntiAlias(true); |
189 paint_.setSubpixelText(true); | 194 paint_.setSubpixelText(true); |
190 paint_.setLCDRenderText(true); | 195 paint_.setLCDRenderText(true); |
191 bounds_.setEmpty(); | 196 bounds_.setEmpty(); |
192 } | 197 } |
193 | 198 |
194 SkiaTextRenderer::~SkiaTextRenderer() { | 199 SkiaTextRenderer::~SkiaTextRenderer() { |
(...skipping 19 matching lines...) Expand all Loading... | |
214 bool enable_lcd_text) { | 219 bool enable_lcd_text) { |
215 paint_.setAntiAlias(enable_smoothing); | 220 paint_.setAntiAlias(enable_smoothing); |
216 paint_.setSubpixelText(enable_smoothing); | 221 paint_.setSubpixelText(enable_smoothing); |
217 paint_.setLCDRenderText(enable_lcd_text); | 222 paint_.setLCDRenderText(enable_lcd_text); |
218 } | 223 } |
219 | 224 |
220 void SkiaTextRenderer::SetTypeface(SkTypeface* typeface) { | 225 void SkiaTextRenderer::SetTypeface(SkTypeface* typeface) { |
221 paint_.setTypeface(typeface); | 226 paint_.setTypeface(typeface); |
222 } | 227 } |
223 | 228 |
224 void SkiaTextRenderer::SetTextSize(int size) { | 229 void SkiaTextRenderer::SetTextSize(SkScalar size) { |
225 paint_.setTextSize(size); | 230 paint_.setTextSize(size); |
226 } | 231 } |
227 | 232 |
228 void SkiaTextRenderer::SetFontFamilyWithStyle(const std::string& family, | 233 void SkiaTextRenderer::SetFontFamilyWithStyle(const std::string& family, |
229 int style) { | 234 int style) { |
230 DCHECK(!family.empty()); | 235 DCHECK(!family.empty()); |
231 | 236 |
232 SkTypeface::Style skia_style = ConvertFontStyleToSkiaTypefaceStyle(style); | 237 SkTypeface::Style skia_style = ConvertFontStyleToSkiaTypefaceStyle(style); |
233 SkTypeface* typeface = SkTypeface::CreateFromName(family.c_str(), skia_style); | 238 SkTypeface* typeface = SkTypeface::CreateFromName(family.c_str(), skia_style); |
234 SkAutoUnref auto_unref(typeface); | 239 SkAutoUnref auto_unref(typeface); |
(...skipping 10 matching lines...) Expand all Loading... | |
245 | 250 |
246 void SkiaTextRenderer::SetForegroundColor(SkColor foreground) { | 251 void SkiaTextRenderer::SetForegroundColor(SkColor foreground) { |
247 paint_.setColor(foreground); | 252 paint_.setColor(foreground); |
248 } | 253 } |
249 | 254 |
250 void SkiaTextRenderer::SetShader(SkShader* shader, const Rect& bounds) { | 255 void SkiaTextRenderer::SetShader(SkShader* shader, const Rect& bounds) { |
251 bounds_ = RectToSkRect(bounds); | 256 bounds_ = RectToSkRect(bounds); |
252 paint_.setShader(shader); | 257 paint_.setShader(shader); |
253 } | 258 } |
254 | 259 |
260 void SkiaTextRenderer::SetUnderlineMetrics(SkScalar thickness, | |
261 SkScalar position) { | |
262 underline_thickness_ = thickness; | |
263 underline_position_ = position; | |
264 printf("Set to %f %f\n", underline_thickness_, underline_position_); | |
msw
2012/06/06 18:35:25
oops :) please remove
Alexei Svitkine (slow)
2012/06/06 18:46:23
Done.
| |
265 } | |
266 | |
255 void SkiaTextRenderer::DrawPosText(const SkPoint* pos, | 267 void SkiaTextRenderer::DrawPosText(const SkPoint* pos, |
256 const uint16* glyphs, | 268 const uint16* glyphs, |
257 size_t glyph_count) { | 269 size_t glyph_count) { |
258 if (!started_drawing_) { | 270 if (!started_drawing_) { |
259 started_drawing_ = true; | 271 started_drawing_ = true; |
260 // Work-around for http://crbug.com/122743, where non-ClearType text is | 272 // Work-around for http://crbug.com/122743, where non-ClearType text is |
261 // rendered with incorrect gamma when using the fade shader. Draw the text | 273 // rendered with incorrect gamma when using the fade shader. Draw the text |
262 // to a layer and restore it faded by drawing a rect in kDstIn_Mode mode. | 274 // to a layer and restore it faded by drawing a rect in kDstIn_Mode mode. |
263 // | 275 // |
264 // Skip this when there is a looper which seems not working well with | 276 // Skip this when there is a looper which seems not working well with |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
297 const SkScalar kDiagonalStrikeThroughMarginOffset = (SK_Scalar1 / 4); | 309 const SkScalar kDiagonalStrikeThroughMarginOffset = (SK_Scalar1 / 4); |
298 | 310 |
299 SkScalar text_size = paint_.getTextSize(); | 311 SkScalar text_size = paint_.getTextSize(); |
300 SkScalar height = SkScalarMul(text_size, kLineThickness); | 312 SkScalar height = SkScalarMul(text_size, kLineThickness); |
301 SkRect r; | 313 SkRect r; |
302 | 314 |
303 r.fLeft = x; | 315 r.fLeft = x; |
304 r.fRight = x + width; | 316 r.fRight = x + width; |
305 | 317 |
306 if (style.underline) { | 318 if (style.underline) { |
307 SkScalar offset = SkScalarMulAdd(text_size, kUnderlineOffset, y); | 319 if (underline_position_ == kUnderlineMetricNotSet) |
308 r.fTop = offset; | 320 r.fTop = SkScalarMulAdd(text_size, kUnderlineOffset, y); |
309 r.fBottom = offset + height; | 321 else |
322 r.fTop = y + underline_position_; | |
323 if (underline_thickness_ == kUnderlineMetricNotSet) | |
324 r.fBottom = r.fTop + height; | |
325 else | |
326 r.fBottom = r.fTop + underline_thickness_; | |
310 canvas_skia_->drawRect(r, paint_); | 327 canvas_skia_->drawRect(r, paint_); |
311 } | 328 } |
312 if (style.strike) { | 329 if (style.strike) { |
313 SkScalar offset = SkScalarMulAdd(text_size, kStrikeThroughOffset, y); | 330 SkScalar offset = SkScalarMulAdd(text_size, kStrikeThroughOffset, y); |
314 r.fTop = offset; | 331 r.fTop = offset; |
315 r.fBottom = offset + height; | 332 r.fBottom = offset + height; |
316 canvas_skia_->drawRect(r, paint_); | 333 canvas_skia_->drawRect(r, paint_); |
317 } | 334 } |
318 if (style.diagonal_strike) { | 335 if (style.diagonal_strike) { |
319 SkScalar offset = | 336 SkScalar offset = |
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
945 if (cursor_enabled() && cursor_visible() && focused()) { | 962 if (cursor_enabled() && cursor_visible() && focused()) { |
946 const Rect& bounds = GetUpdatedCursorBounds(); | 963 const Rect& bounds = GetUpdatedCursorBounds(); |
947 if (bounds.width() != 0) | 964 if (bounds.width() != 0) |
948 canvas->FillRect(bounds, cursor_color_); | 965 canvas->FillRect(bounds, cursor_color_); |
949 else | 966 else |
950 canvas->DrawRect(bounds, cursor_color_); | 967 canvas->DrawRect(bounds, cursor_color_); |
951 } | 968 } |
952 } | 969 } |
953 | 970 |
954 } // namespace gfx | 971 } // namespace gfx |
OLD | NEW |