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 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 | 383 |
382 SkScalar x = SkIntToScalar(offset.x()); | 384 SkScalar x = SkIntToScalar(offset.x()); |
383 SkScalar y = SkIntToScalar(offset.y()); | 385 SkScalar y = SkIntToScalar(offset.y()); |
384 | 386 |
385 std::vector<SkPoint> pos; | 387 std::vector<SkPoint> pos; |
386 std::vector<uint16> glyphs; | 388 std::vector<uint16> glyphs; |
387 | 389 |
388 internal::SkiaTextRenderer renderer(canvas); | 390 internal::SkiaTextRenderer renderer(canvas); |
389 ApplyFadeEffects(&renderer); | 391 ApplyFadeEffects(&renderer); |
390 ApplyTextShadows(&renderer); | 392 ApplyTextShadows(&renderer); |
391 | 393 renderer.SetFontRenderParams( |
392 // TODO(derat): Use font-specific params: http://crbug.com/125235 | 394 font_list().GetPrimaryFont().GetFontRenderParams(), |
393 renderer.SetFontRenderParams(GetDefaultFontRenderParams(), | 395 background_is_transparent()); |
394 background_is_transparent()); | |
395 | 396 |
396 // Temporarily apply composition underlines and selection colors. | 397 // Temporarily apply composition underlines and selection colors. |
397 ApplyCompositionAndSelectionStyles(); | 398 ApplyCompositionAndSelectionStyles(); |
398 | 399 |
399 internal::StyleIterator style(colors(), styles()); | 400 internal::StyleIterator style(colors(), styles()); |
400 for (GSList* it = current_line_->runs; it; it = it->next) { | 401 for (GSList* it = current_line_->runs; it; it = it->next) { |
401 PangoLayoutRun* run = reinterpret_cast<PangoLayoutRun*>(it->data); | 402 PangoLayoutRun* run = reinterpret_cast<PangoLayoutRun*>(it->data); |
402 int glyph_count = run->glyphs->num_glyphs; | 403 int glyph_count = run->glyphs->num_glyphs; |
403 // TODO(msw): Skip painting runs outside the display rect area, like Win. | 404 // TODO(msw): Skip painting runs outside the display rect area, like Win. |
404 if (glyph_count == 0) | 405 if (glyph_count == 0) |
405 continue; | 406 continue; |
406 | 407 |
407 ScopedPangoFontDescription desc( | 408 ScopedPangoFontDescription desc( |
408 pango_font_describe(run->item->analysis.font)); | 409 pango_font_describe(run->item->analysis.font)); |
409 | |
410 const std::string family_name = | 410 const std::string family_name = |
411 pango_font_description_get_family(desc.get()); | 411 pango_font_description_get_family(desc.get()); |
412 renderer.SetTextSize(GetPangoFontSizeInPixels(desc.get())); | 412 renderer.SetTextSize(GetPangoFontSizeInPixels(desc.get())); |
413 | 413 |
414 glyphs.resize(glyph_count); | 414 glyphs.resize(glyph_count); |
415 pos.resize(glyph_count); | 415 pos.resize(glyph_count); |
416 | 416 |
417 // Track the current glyph and the glyph at the start of its styled range. | 417 // Track the current glyph and the glyph at the start of its styled range. |
418 int glyph_index = 0; | 418 int glyph_index = 0; |
419 int style_start_glyph_index = glyph_index; | 419 int style_start_glyph_index = glyph_index; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 int glyph_index) const { | 501 int glyph_index) const { |
502 return LayoutIndexToTextIndex(run->item->offset + | 502 return LayoutIndexToTextIndex(run->item->offset + |
503 run->glyphs->log_clusters[glyph_index]); | 503 run->glyphs->log_clusters[glyph_index]); |
504 } | 504 } |
505 | 505 |
506 RenderText* RenderText::CreateNativeInstance() { | 506 RenderText* RenderText::CreateNativeInstance() { |
507 return new RenderTextPango; | 507 return new RenderTextPango; |
508 } | 508 } |
509 | 509 |
510 } // namespace gfx | 510 } // namespace gfx |
OLD | NEW |