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

Side by Side Diff: app/gfx/chrome_canvas_linux.cc

Issue 113441: ChromeFont->gfx::Font... (Closed) Base URL: svn://chrome-svn.corp.google.com/chrome/trunk/src/
Patch Set: Created 11 years, 7 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
« no previous file with comments | « app/gfx/chrome_canvas.cc ('k') | app/gfx/chrome_canvas_win.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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "app/gfx/chrome_canvas.h" 5 #include "app/gfx/chrome_canvas.h"
6 6
7 #include <pango/pango.h> 7 #include <pango/pango.h>
8 8
9 #include "app/gfx/chrome_font.h" 9 #include "app/gfx/chrome_font.h"
10 #include "base/gfx/rect.h" 10 #include "base/gfx/rect.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 13
14 namespace { 14 namespace {
15 15
16 // Returns a new pango font, free with pango_font_description_free(). 16 // Returns a new pango font, free with pango_font_description_free().
17 PangoFontDescription* PangoFontFromChromeFont(const ChromeFont& chrome_font) { 17 PangoFontDescription* PangoFontFromGfxFont(const gfx::Font& gfx_font) {
18 ChromeFont font = chrome_font; // Copy so we can call non-const methods. 18 gfx::Font font = gfx_font; // Copy so we can call non-const methods.
19 PangoFontDescription* pfd = pango_font_description_new(); 19 PangoFontDescription* pfd = pango_font_description_new();
20 pango_font_description_set_family(pfd, WideToUTF8(font.FontName()).c_str()); 20 pango_font_description_set_family(pfd, WideToUTF8(font.FontName()).c_str());
21 pango_font_description_set_size(pfd, font.FontSize() * PANGO_SCALE); 21 pango_font_description_set_size(pfd, font.FontSize() * PANGO_SCALE);
22 22
23 switch (font.style()) { 23 switch (font.style()) {
24 case ChromeFont::NORMAL: 24 case gfx::Font::NORMAL:
25 // Nothing to do, should already be PANGO_STYLE_NORMAL. 25 // Nothing to do, should already be PANGO_STYLE_NORMAL.
26 break; 26 break;
27 case ChromeFont::BOLD: 27 case gfx::Font::BOLD:
28 pango_font_description_set_weight(pfd, PANGO_WEIGHT_BOLD); 28 pango_font_description_set_weight(pfd, PANGO_WEIGHT_BOLD);
29 break; 29 break;
30 case ChromeFont::ITALIC: 30 case gfx::Font::ITALIC:
31 pango_font_description_set_style(pfd, PANGO_STYLE_ITALIC); 31 pango_font_description_set_style(pfd, PANGO_STYLE_ITALIC);
32 break; 32 break;
33 case ChromeFont::UNDERLINED: 33 case gfx::Font::UNDERLINED:
34 // TODO(deanm): How to do underlined? Where do we use it? Probably have 34 // TODO(deanm): How to do underlined? Where do we use it? Probably have
35 // to paint it ourselves, see pango_font_metrics_get_underline_position. 35 // to paint it ourselves, see pango_font_metrics_get_underline_position.
36 break; 36 break;
37 } 37 }
38 38
39 return pfd; 39 return pfd;
40 } 40 }
41 41
42 } // namespace 42 } // namespace
43 43
44 ChromeCanvas::ChromeCanvas(int width, int height, bool is_opaque) 44 ChromeCanvas::ChromeCanvas(int width, int height, bool is_opaque)
45 : skia::PlatformCanvasLinux(width, height, is_opaque) { 45 : skia::PlatformCanvasLinux(width, height, is_opaque) {
46 } 46 }
47 47
48 ChromeCanvas::ChromeCanvas() : skia::PlatformCanvasLinux() { 48 ChromeCanvas::ChromeCanvas() : skia::PlatformCanvasLinux() {
49 } 49 }
50 50
51 ChromeCanvas::~ChromeCanvas() { 51 ChromeCanvas::~ChromeCanvas() {
52 } 52 }
53 53
54 // static 54 // static
55 void ChromeCanvas::SizeStringInt(const std::wstring& text, 55 void ChromeCanvas::SizeStringInt(const std::wstring& text,
56 const ChromeFont& font, 56 const gfx::Font& font,
57 int* width, int* height, int flags) { 57 int* width, int* height, int flags) {
58 NOTIMPLEMENTED(); 58 NOTIMPLEMENTED();
59 } 59 }
60 60
61 void ChromeCanvas::ApplySkiaMatrixToCairoContext(cairo_t* cr) { 61 void ChromeCanvas::ApplySkiaMatrixToCairoContext(cairo_t* cr) {
62 const SkMatrix& skia_matrix = getTotalMatrix(); 62 const SkMatrix& skia_matrix = getTotalMatrix();
63 cairo_matrix_t cairo_matrix; 63 cairo_matrix_t cairo_matrix;
64 cairo_matrix_init(&cairo_matrix, 64 cairo_matrix_init(&cairo_matrix,
65 SkScalarToFloat(skia_matrix.getScaleX()), 65 SkScalarToFloat(skia_matrix.getScaleX()),
66 SkScalarToFloat(skia_matrix.getSkewY()), 66 SkScalarToFloat(skia_matrix.getSkewY()),
67 SkScalarToFloat(skia_matrix.getSkewX()), 67 SkScalarToFloat(skia_matrix.getSkewX()),
68 SkScalarToFloat(skia_matrix.getScaleY()), 68 SkScalarToFloat(skia_matrix.getScaleY()),
69 SkScalarToFloat(skia_matrix.getTranslateX()), 69 SkScalarToFloat(skia_matrix.getTranslateX()),
70 SkScalarToFloat(skia_matrix.getTranslateY())); 70 SkScalarToFloat(skia_matrix.getTranslateY()));
71 cairo_set_matrix(cr, &cairo_matrix); 71 cairo_set_matrix(cr, &cairo_matrix);
72 } 72 }
73 73
74 void ChromeCanvas::DrawStringInt(const std::wstring& text, 74 void ChromeCanvas::DrawStringInt(const std::wstring& text,
75 const ChromeFont& font, 75 const gfx::Font& font,
76 const SkColor& color, int x, int y, int w, 76 const SkColor& color, int x, int y, int w,
77 int h, int flags) { 77 int h, int flags) {
78 cairo_surface_t* surface = beginPlatformPaint(); 78 cairo_surface_t* surface = beginPlatformPaint();
79 cairo_t* cr = cairo_create(surface); 79 cairo_t* cr = cairo_create(surface);
80 // We're going to draw onto the surface directly. This circumvents the matrix 80 // We're going to draw onto the surface directly. This circumvents the matrix
81 // installed by Skia. Apply the matrix from skia to cairo so they align and 81 // installed by Skia. Apply the matrix from skia to cairo so they align and
82 // we draw at the right place. 82 // we draw at the right place.
83 ApplySkiaMatrixToCairoContext(cr); 83 ApplySkiaMatrixToCairoContext(cr);
84 PangoLayout* layout = pango_cairo_create_layout(cr); 84 PangoLayout* layout = pango_cairo_create_layout(cr);
85 85
(...skipping 19 matching lines...) Expand all
105 pango_layout_set_wrap(layout, 105 pango_layout_set_wrap(layout,
106 (flags & CHARACTER_BREAK) ? PANGO_WRAP_WORD_CHAR : PANGO_WRAP_WORD); 106 (flags & CHARACTER_BREAK) ? PANGO_WRAP_WORD_CHAR : PANGO_WRAP_WORD);
107 } 107 }
108 108
109 if (flags & NO_ELLIPSIS) 109 if (flags & NO_ELLIPSIS)
110 pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE); 110 pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
111 111
112 std::string utf8 = WideToUTF8(text); 112 std::string utf8 = WideToUTF8(text);
113 pango_layout_set_text(layout, utf8.data(), utf8.size()); 113 pango_layout_set_text(layout, utf8.data(), utf8.size());
114 114
115 PangoFontDescription* desc = PangoFontFromChromeFont(font); 115 PangoFontDescription* desc = PangoFontFromGfxFont(font);
116 pango_layout_set_font_description(layout, desc); 116 pango_layout_set_font_description(layout, desc);
117 pango_font_description_free(desc); 117 pango_font_description_free(desc);
118 118
119 int width, height; 119 int width, height;
120 pango_layout_get_size(layout, &width, &height); 120 pango_layout_get_size(layout, &width, &height);
121 121
122 if (flags & ChromeCanvas::TEXT_VALIGN_TOP) { 122 if (flags & ChromeCanvas::TEXT_VALIGN_TOP) {
123 // Cairo should draw from the top left corner already. 123 // Cairo should draw from the top left corner already.
124 } else if (flags & ChromeCanvas::TEXT_VALIGN_BOTTOM) { 124 } else if (flags & ChromeCanvas::TEXT_VALIGN_BOTTOM) {
125 y = y + (h - (height / PANGO_SCALE)); 125 y = y + (h - (height / PANGO_SCALE));
126 } else { 126 } else {
127 // Vertically centered. 127 // Vertically centered.
128 y = y + ((h - (height / PANGO_SCALE)) / 2); 128 y = y + ((h - (height / PANGO_SCALE)) / 2);
129 } 129 }
130 130
131 cairo_move_to(cr, x, y); 131 cairo_move_to(cr, x, y);
132 pango_cairo_show_layout(cr, layout); 132 pango_cairo_show_layout(cr, layout);
133 133
134 g_object_unref(layout); 134 g_object_unref(layout);
135 cairo_destroy(cr); 135 cairo_destroy(cr);
136 // NOTE: beginPlatformPaint returned its surface, we shouldn't destroy it. 136 // NOTE: beginPlatformPaint returned its surface, we shouldn't destroy it.
137 } 137 }
OLDNEW
« no previous file with comments | « app/gfx/chrome_canvas.cc ('k') | app/gfx/chrome_canvas_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698