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_pango.h" | 5 #include "ui/gfx/render_text_pango.h" |
6 | 6 |
7 #include <pango/pangocairo.h> | 7 #include <pango/pangocairo.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/i18n/break_iterator.h" | 12 #include "base/i18n/break_iterator.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "third_party/skia/include/core/SkTypeface.h" | 14 #include "third_party/skia/include/core/SkTypeface.h" |
15 #include "ui/gfx/canvas.h" | 15 #include "ui/gfx/canvas.h" |
16 #include "ui/gfx/font.h" | 16 #include "ui/gfx/font.h" |
| 17 #include "ui/gfx/font_list.h" |
17 #include "ui/gfx/font_render_params.h" | 18 #include "ui/gfx/font_render_params.h" |
18 #include "ui/gfx/pango_util.h" | 19 #include "ui/gfx/pango_util.h" |
| 20 #include "ui/gfx/platform_font_pango.h" |
19 #include "ui/gfx/utf16_indexing.h" | 21 #include "ui/gfx/utf16_indexing.h" |
20 | 22 |
21 namespace gfx { | 23 namespace gfx { |
22 | 24 |
23 namespace { | 25 namespace { |
24 | 26 |
25 // Returns the preceding element in a GSList (O(n)). | 27 // Returns the preceding element in a GSList (O(n)). |
26 GSList* GSListPrevious(GSList* head, GSList* item) { | 28 GSList* GSListPrevious(GSList* head, GSList* item) { |
27 GSList* prev = NULL; | 29 GSList* prev = NULL; |
28 for (GSList* cur = head; cur != item; cur = cur->next) { | 30 for (GSList* cur = head; cur != item; cur = cur->next) { |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 | 374 |
373 SkScalar x = SkIntToScalar(offset.x()); | 375 SkScalar x = SkIntToScalar(offset.x()); |
374 SkScalar y = SkIntToScalar(offset.y()); | 376 SkScalar y = SkIntToScalar(offset.y()); |
375 | 377 |
376 std::vector<SkPoint> pos; | 378 std::vector<SkPoint> pos; |
377 std::vector<uint16> glyphs; | 379 std::vector<uint16> glyphs; |
378 | 380 |
379 internal::SkiaTextRenderer renderer(canvas); | 381 internal::SkiaTextRenderer renderer(canvas); |
380 ApplyFadeEffects(&renderer); | 382 ApplyFadeEffects(&renderer); |
381 ApplyTextShadows(&renderer); | 383 ApplyTextShadows(&renderer); |
382 | 384 renderer.SetFontRenderParams(font_list().GetFontRenderParams(), |
383 // TODO(derat): Use font-specific params: http://crbug.com/125235 | |
384 renderer.SetFontRenderParams(GetDefaultFontRenderParams(), | |
385 background_is_transparent()); | 385 background_is_transparent()); |
386 | 386 |
387 // Temporarily apply composition underlines and selection colors. | 387 // Temporarily apply composition underlines and selection colors. |
388 ApplyCompositionAndSelectionStyles(); | 388 ApplyCompositionAndSelectionStyles(); |
389 | 389 |
390 internal::StyleIterator style(colors(), styles()); | 390 internal::StyleIterator style(colors(), styles()); |
391 for (GSList* it = current_line_->runs; it; it = it->next) { | 391 for (GSList* it = current_line_->runs; it; it = it->next) { |
392 PangoLayoutRun* run = reinterpret_cast<PangoLayoutRun*>(it->data); | 392 PangoLayoutRun* run = reinterpret_cast<PangoLayoutRun*>(it->data); |
393 int glyph_count = run->glyphs->num_glyphs; | 393 int glyph_count = run->glyphs->num_glyphs; |
394 // TODO(msw): Skip painting runs outside the display rect area, like Win. | 394 // TODO(msw): Skip painting runs outside the display rect area, like Win. |
395 if (glyph_count == 0) | 395 if (glyph_count == 0) |
396 continue; | 396 continue; |
397 | 397 |
398 ScopedPangoFontDescription desc( | 398 ScopedPangoFontDescription desc( |
399 pango_font_describe(run->item->analysis.font)); | 399 pango_font_describe(run->item->analysis.font)); |
400 | |
401 const std::string family_name = | 400 const std::string family_name = |
402 pango_font_description_get_family(desc.get()); | 401 pango_font_description_get_family(desc.get()); |
403 renderer.SetTextSize(GetPangoFontSizeInPixels(desc.get())); | 402 renderer.SetTextSize(GetPangoFontSizeInPixels(desc.get())); |
404 | 403 |
405 glyphs.resize(glyph_count); | 404 glyphs.resize(glyph_count); |
406 pos.resize(glyph_count); | 405 pos.resize(glyph_count); |
407 | 406 |
408 // Track the current glyph and the glyph at the start of its styled range. | 407 // Track the current glyph and the glyph at the start of its styled range. |
409 int glyph_index = 0; | 408 int glyph_index = 0; |
410 int style_start_glyph_index = glyph_index; | 409 int style_start_glyph_index = glyph_index; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 int glyph_index) const { | 491 int glyph_index) const { |
493 return LayoutIndexToTextIndex(run->item->offset + | 492 return LayoutIndexToTextIndex(run->item->offset + |
494 run->glyphs->log_clusters[glyph_index]); | 493 run->glyphs->log_clusters[glyph_index]); |
495 } | 494 } |
496 | 495 |
497 RenderText* RenderText::CreateNativeInstance() { | 496 RenderText* RenderText::CreateNativeInstance() { |
498 return new RenderTextPango; | 497 return new RenderTextPango; |
499 } | 498 } |
500 | 499 |
501 } // namespace gfx | 500 } // namespace gfx |
OLD | NEW |