summaryrefslogtreecommitdiffstats
path: root/app/gfx
diff options
context:
space:
mode:
authorjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-01 18:37:39 +0000
committerjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-01 18:37:39 +0000
commit680ed93e5e315143eb7e7478e21d2080689cbd07 (patch)
tree314dce7a8f82ba13446de7d30a55393835fca4b6 /app/gfx
parentef610457ca8d0d43594a765e2b1f1ea194c5a591 (diff)
downloadchromium_src-680ed93e5e315143eb7e7478e21d2080689cbd07.zip
chromium_src-680ed93e5e315143eb7e7478e21d2080689cbd07.tar.gz
chromium_src-680ed93e5e315143eb7e7478e21d2080689cbd07.tar.bz2
Porting textfield to toolkit_views Gtk.
BUG=None TEST=Run the view unit-tests. See original review: http://codereview.chromium.org/165512/show Review URL: http://codereview.chromium.org/180061 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25063 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app/gfx')
-rw-r--r--app/gfx/canvas_linux.cc28
-rw-r--r--app/gfx/font.h5
-rw-r--r--app/gfx/font_gtk.cc27
3 files changed, 33 insertions, 27 deletions
diff --git a/app/gfx/canvas_linux.cc b/app/gfx/canvas_linux.cc
index 521f54f..7ed1904 100644
--- a/app/gfx/canvas_linux.cc
+++ b/app/gfx/canvas_linux.cc
@@ -20,32 +20,6 @@ namespace {
// DrawStringInt().
static cairo_font_options_t* cairo_font_options = NULL;
-// Returns a new pango font, free with pango_font_description_free().
-PangoFontDescription* PangoFontFromGfxFont(const gfx::Font& gfx_font) {
- gfx::Font font = gfx_font; // Copy so we can call non-const methods.
- PangoFontDescription* pfd = pango_font_description_new();
- pango_font_description_set_family(pfd, WideToUTF8(font.FontName()).c_str());
- pango_font_description_set_size(pfd, font.FontSize() * PANGO_SCALE);
-
- switch (font.style()) {
- case gfx::Font::NORMAL:
- // Nothing to do, should already be PANGO_STYLE_NORMAL.
- break;
- case gfx::Font::BOLD:
- pango_font_description_set_weight(pfd, PANGO_WEIGHT_BOLD);
- break;
- case gfx::Font::ITALIC:
- pango_font_description_set_style(pfd, PANGO_STYLE_ITALIC);
- break;
- case gfx::Font::UNDERLINED:
- // TODO(deanm): How to do underlined? Where do we use it? Probably have
- // to paint it ourselves, see pango_font_metrics_get_underline_position.
- break;
- }
-
- return pfd;
-}
-
// Update |cairo_font_options| based on GtkSettings, allocating it if needed.
static void UpdateCairoFontOptions() {
if (!cairo_font_options)
@@ -156,7 +130,7 @@ static void SetupPangoLayout(PangoLayout* layout,
PANGO_WRAP_WORD_CHAR : PANGO_WRAP_WORD);
}
- PangoFontDescription* desc = PangoFontFromGfxFont(font);
+ PangoFontDescription* desc = gfx::Font::PangoFontFromGfxFont(font);
pango_layout_set_font_description(layout, desc);
pango_font_description_free(desc);
}
diff --git a/app/gfx/font.h b/app/gfx/font.h
index ef03d99..e0e075a 100644
--- a/app/gfx/font.h
+++ b/app/gfx/font.h
@@ -27,6 +27,7 @@ class NSFont;
#endif
typedef NSFont* NativeFont;
#elif defined(OS_LINUX)
+typedef struct _PangoFontDescription PangoFontDescription;
class SkTypeface;
typedef SkTypeface* NativeFont;
#else // null port.
@@ -130,6 +131,10 @@ class Font {
Font& operator=(const Font& other);
// Setup a Skia context to use the current typeface
void PaintSetup(SkPaint* paint) const;
+
+ // Converts |gfx_font| to a new pango font. Free the returned font with
+ // pango_font_description_free().
+ static PangoFontDescription* PangoFontFromGfxFont(const gfx::Font& gfx_font);
#endif
private:
diff --git a/app/gfx/font_gtk.cc b/app/gfx/font_gtk.cc
index 6c5f367..522c568 100644
--- a/app/gfx/font_gtk.cc
+++ b/app/gfx/font_gtk.cc
@@ -81,4 +81,31 @@ Font::Font() {
CopyFont(*default_font_);
}
+// static
+PangoFontDescription* Font::PangoFontFromGfxFont(
+ const gfx::Font& gfx_font) {
+ gfx::Font font = gfx_font; // Copy so we can call non-const methods.
+ PangoFontDescription* pfd = pango_font_description_new();
+ pango_font_description_set_family(pfd, WideToUTF8(font.FontName()).c_str());
+ pango_font_description_set_size(pfd, font.FontSize() * PANGO_SCALE);
+
+ switch (font.style()) {
+ case gfx::Font::NORMAL:
+ // Nothing to do, should already be PANGO_STYLE_NORMAL.
+ break;
+ case gfx::Font::BOLD:
+ pango_font_description_set_weight(pfd, PANGO_WEIGHT_BOLD);
+ break;
+ case gfx::Font::ITALIC:
+ pango_font_description_set_style(pfd, PANGO_STYLE_ITALIC);
+ break;
+ case gfx::Font::UNDERLINED:
+ // TODO(deanm): How to do underlined? Where do we use it? Probably have
+ // to paint it ourselves, see pango_font_metrics_get_underline_position.
+ break;
+ }
+
+ return pfd;
+}
+
} // namespace gfx