summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-14 19:26:49 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-14 19:26:49 +0000
commit5e70f14644629b7f9fe9126553758aed25e17128 (patch)
tree65bd07608366d1f3004535e2ca91a9089327ed92
parent1bf956b6f611bd3e116489bfdef7ac9048db0308 (diff)
downloadchromium_src-5e70f14644629b7f9fe9126553758aed25e17128.zip
chromium_src-5e70f14644629b7f9fe9126553758aed25e17128.tar.gz
chromium_src-5e70f14644629b7f9fe9126553758aed25e17128.tar.bz2
Reverts linux font change again. Slow down isn't as bad as before. But
still not ideal. BUG=none TEST=none TBR=agl Review URL: http://codereview.chromium.org/194105 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26141 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--app/app.gyp1
-rw-r--r--app/gfx/canvas_linux.cc4
-rw-r--r--app/gfx/font.h111
-rw-r--r--app/gfx/font_gtk.cc248
-rw-r--r--app/gfx/font_skia.cc160
-rw-r--r--app/gfx/font_unittest.cc7
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc31
-rw-r--r--views/controls/button/native_button_gtk.cc5
-rw-r--r--views/controls/textfield/native_textfield_gtk.cc3
9 files changed, 306 insertions, 264 deletions
diff --git a/app/app.gyp b/app/app.gyp
index b610b02..e58b762 100644
--- a/app/app.gyp
+++ b/app/app.gyp
@@ -76,6 +76,7 @@
'gfx/font.h',
'gfx/font_gtk.cc',
'gfx/font_mac.mm',
+ 'gfx/font_skia.cc',
'gfx/font_win.cc',
'gfx/color_utils.cc',
'gfx/color_utils.h',
diff --git a/app/gfx/canvas_linux.cc b/app/gfx/canvas_linux.cc
index 1614f44..7ed1904 100644
--- a/app/gfx/canvas_linux.cc
+++ b/app/gfx/canvas_linux.cc
@@ -130,7 +130,9 @@ static void SetupPangoLayout(PangoLayout* layout,
PANGO_WRAP_WORD_CHAR : PANGO_WRAP_WORD);
}
- pango_layout_set_font_description(layout, font.nativeFont());
+ PangoFontDescription* desc = gfx::Font::PangoFontFromGfxFont(font);
+ pango_layout_set_font_description(layout, desc);
+ pango_font_description_free(desc);
}
// static
diff --git a/app/gfx/font.h b/app/gfx/font.h
index 60e94d2..e53bd79 100644
--- a/app/gfx/font.h
+++ b/app/gfx/font.h
@@ -9,12 +9,12 @@
#include <string>
-#if defined(OS_LINUX)
-#include <list>
-#endif
-
#if defined(OS_WIN)
typedef struct HFONT__* HFONT;
+#elif defined(OS_LINUX)
+#include "third_party/skia/include/core/SkRefCnt.h"
+class SkPaint;
+class SkTypeface;
#endif
#if defined(OS_WIN)
@@ -28,7 +28,8 @@ class NSFont;
typedef NSFont* NativeFont;
#elif defined(OS_LINUX)
typedef struct _PangoFontDescription PangoFontDescription;
-typedef PangoFontDescription* NativeFont;
+class SkTypeface;
+typedef SkTypeface* NativeFont;
#else // null port.
#error No known OS defined
#endif
@@ -101,10 +102,6 @@ class Font {
// Font Size.
int FontSize();
- // Returns a handle to the native font.
- // NOTE: on linux this returns the PangoFontDescription* being held by this
- // object. You should not modify or free it. If you need to use it, make a
- // copy of it by way of pango_font_description_copy(nativeFont()).
NativeFont nativeFont() const;
// Creates a font with the default name and style.
@@ -129,6 +126,16 @@ class Font {
}
#elif defined(OS_LINUX)
static Font CreateFont(PangoFontDescription* desc);
+ // We need a copy constructor and assignment operator to deal with
+ // the Skia reference counting.
+ Font(const Font& other);
+ 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:
@@ -189,74 +196,32 @@ class Font {
// Indirect reference to the HFontRef, which references the underlying HFONT.
scoped_refptr<HFontRef> font_ref_;
#elif defined(OS_LINUX)
- // Used internally on Linux to cache information about the font. Each
- // Font maintains a reference to a PangoFontRef. Coping a Font ups the
- // refcount of the corresponding PangoFontRef.
- //
- // As obtaining metrics (height, ascent, average char width) is expensive,
- // the metrics are only obtained as needed. Additionally PangoFontRef
- // maintains a static cache of PangoFontRefs. When a PangoFontRef is needed
- // the cache is checked first.
- class PangoFontRef : public base::RefCounted<PangoFontRef> {
- public:
- ~PangoFontRef();
-
- // Creates or returns a cached PangoFontRef of the given family, size and
- // style.
- static PangoFontRef* Create(PangoFontDescription* pfd,
- const std::wstring& family,
- int size,
- int style);
-
- PangoFontDescription* pfd() const { return pfd_; }
- const std::wstring& family() const { return family_; }
- int size() const { return size_; }
- int style() const { return style_; }
- int GetHeight() const;
- int GetAscent() const;
- int GetAveCharWidth() const;
-
- private:
- typedef std::list<PangoFontRef*> Cache;
-
- PangoFontRef(PangoFontDescription* pfd,
- const std::wstring& family,
- int size,
- int style);
-
- void CalculateMetricsIfNecessary() const;
-
- // Returns the cache.
- static Cache* GetCache();
-
- // Adds |ref| to the cache, removing an existing PangoFontRef if there are
- // too many.
- static void AddToCache(PangoFontRef* ref);
-
- PangoFontDescription* pfd_;
- const std::wstring family_;
- const int size_;
- const int style_;
-
- // Metrics related members. As these are expensive to calculate they are
- // calculated the first time requested.
- mutable int height_;
- mutable int ascent_;
- mutable int ave_char_width_;
-
- // Have the metrics related members been determined yet (height_, ascent_
- // ave_char_width_)?
- mutable bool calculated_metrics_;
-
- DISALLOW_COPY_AND_ASSIGN(PangoFontRef);
- };
-
- explicit Font(PangoFontDescription* pfd);
+ explicit Font(SkTypeface* typeface, const std::wstring& name,
+ int size, int style);
+ // Calculate and cache the font metrics.
+ void calculateMetrics();
+ // Make |this| a copy of |other|.
+ void CopyFont(const Font& other);
// The default font, used for the default constructor.
static Font* default_font_;
- scoped_refptr<PangoFontRef> font_ref_;
+ // These two both point to the same SkTypeface. We use the SkAutoUnref to
+ // handle the reference counting, but without @typeface_ we would have to
+ // cast the SkRefCnt from @typeface_helper_ every time.
+ scoped_ptr<SkAutoUnref> typeface_helper_;
+ SkTypeface *typeface_;
+
+ // Additional information about the face
+ // Skia actually expects a family name and not a font name.
+ std::wstring font_family_;
+ int font_size_;
+ int style_;
+
+ // Cached metrics, generated at construction
+ int height_;
+ int ascent_;
+ int avg_width_;
#elif defined(OS_MACOSX)
explicit Font(const std::wstring& font_name, int font_size, int style);
diff --git a/app/gfx/font_gtk.cc b/app/gfx/font_gtk.cc
index 897e8f0..244810a 100644
--- a/app/gfx/font_gtk.cc
+++ b/app/gfx/font_gtk.cc
@@ -7,87 +7,56 @@
#include <fontconfig/fontconfig.h>
#include <gtk/gtk.h>
-#include "app/gfx/canvas.h"
#include "base/string_util.h"
namespace gfx {
-namespace {
-
-// Returns a PangoContext that is used to get metrics. The returned context
-// should never be freed.
-PangoContext* get_context() {
- static PangoContext* context = NULL;
- if (!context) {
- context = gdk_pango_context_get_for_screen(gdk_screen_get_default());
- pango_context_set_language(context, gtk_get_default_language());
- }
- return context;
-}
+Font* Font::default_font_ = NULL;
+// Find the best match font for |family_name| in the same way as Skia
+// to make sure CreateFont() successfully creates a default font. In
+// Skia, it only checks the best match font. If it failed to find
+// one, SkTypeface will be NULL for that font family. It eventually
+// causes a segfault. For example, family_name = "Sans" and system
+// may have various fonts. The first font family in FcPattern will be
+// "DejaVu Sans" but a font family returned by FcFontMatch will be "VL
+// PGothic". In this case, SkTypeface for "Sans" returns NULL even if
+// the system has a font for "Sans" font family. See FontMatch() in
+// skia/ports/SkFontHost_fontconfig.cpp for more detail.
+static std::wstring FindBestMatchFontFamilyName(const char* family_name) {
+ FcPattern* pattern = FcPatternCreate();
+ FcValue fcvalue;
+ fcvalue.type = FcTypeString;
+ char* family_name_copy = strdup(family_name);
+ fcvalue.u.s = reinterpret_cast<FcChar8*>(family_name_copy);
+ FcPatternAdd(pattern, FC_FAMILY, fcvalue, 0);
+ FcConfigSubstitute(0, pattern, FcMatchPattern);
+ FcDefaultSubstitute(pattern);
+ FcResult result;
+ FcPattern* match = FcFontMatch(0, pattern, &result);
+ DCHECK(match) << "Could not find font: " << family_name;
+ FcChar8* match_family;
+ FcPatternGetString(match, FC_FAMILY, 0, &match_family);
+
+ std::wstring font_family = UTF8ToWide(
+ reinterpret_cast<char*>(match_family));
+ FcPatternDestroy(match);
+ FcPatternDestroy(pattern);
+ free(family_name_copy);
+ return font_family;
}
-Font* Font::default_font_ = NULL;
-
// static
Font Font::CreateFont(PangoFontDescription* desc) {
- return Font(desc);
-}
+ gint size = pango_font_description_get_size(desc);
+ const char* family_name = pango_font_description_get_family(desc);
-Font Font::DeriveFont(int size_delta, int style) const {
- // If the delta is negative, if must not push the size below 1
- if (size_delta < 0)
- DCHECK_LT(-size_delta, font_ref_->size());
-
- PangoFontDescription* pfd = pango_font_description_copy(nativeFont());
- pango_font_description_set_size(
- pfd, (font_ref_->size() + size_delta) * PANGO_SCALE);
- pango_font_description_set_style(
- pfd, style & ITALIC ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL);
- pango_font_description_set_weight(
- pfd, style & BOLD ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL);
- Font font(pfd);
- pango_font_description_free(pfd);
- return font;
-}
-
-int Font::height() const {
- return font_ref_->GetHeight();
-}
+ // Find best match font for |family_name| to make sure we can get
+ // a SkTypeface for the default font.
+ // TODO(agl): remove this.
+ std::wstring font_family = FindBestMatchFontFamilyName(family_name);
-int Font::baseline() const {
- return font_ref_->GetAscent();
-}
-
-int Font::ave_char_width() const {
- return font_ref_->GetAveCharWidth();
-}
-
-int Font::GetStringWidth(const std::wstring& text) const {
- int width = 0, height = 0;
-
- Canvas::SizeStringInt(text, *this, &width, &height, 0);
- return width;
-}
-
-int Font::GetExpectedTextWidth(int length) const {
- return length * font_ref_->GetAveCharWidth();
-}
-
-int Font::style() const {
- return font_ref_->style();
-}
-
-std::wstring Font::FontName() {
- return font_ref_->family();
-}
-
-int Font::FontSize() {
- return font_ref_->size();
-}
-
-PangoFontDescription* Font::nativeFont() const {
- return font_ref_->pfd();
+ return Font(CreateFont(font_family, size / PANGO_SCALE));
}
// Get the default gtk system font (name and size).
@@ -106,130 +75,41 @@ Font::Font() {
PangoFontDescription* desc =
pango_font_description_from_string(font_name);
- default_font_ = new Font(desc);
+ default_font_ = new Font(CreateFont(desc));
pango_font_description_free(desc);
g_free(font_name);
+
+ DCHECK(default_font_);
}
- *this = *default_font_;
+ CopyFont(*default_font_);
}
// static
-Font Font::CreateFont(const std::wstring& font_family, int font_size) {
- DCHECK_GT(font_size, 0);
-
+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_family).c_str());
- pango_font_description_set_size(pfd, font_size * PANGO_SCALE);
- pango_font_description_set_style(pfd, PANGO_STYLE_NORMAL);
- pango_font_description_set_weight(pfd, PANGO_WEIGHT_NORMAL);
- Font font(pfd);
- pango_font_description_free(pfd);
- return font;
-}
-
-Font::Font(PangoFontDescription* desc) {
- PangoContext* context = get_context();
- pango_context_set_font_description(context, desc);
- int size = pango_font_description_get_size(desc) / PANGO_SCALE;
- int style = 0;
- if (pango_font_description_get_weight(desc) >= PANGO_WEIGHT_BOLD)
- style |= BOLD;
- if (pango_font_description_get_style(desc) == PANGO_STYLE_ITALIC)
- style |= ITALIC;
- std::wstring name(UTF8ToWide(pango_font_description_get_family(desc)));
- font_ref_ = PangoFontRef::Create(desc, name, size, style);
-}
-
-// PangoFontRef ---------------------------------------------------------------
-
-// Maximum number of PangoFontRefs cached.
-static const size_t kMaxCacheSize = 20;
-
-// static
-Font::PangoFontRef* Font::PangoFontRef::Create(PangoFontDescription* pfd,
- const std::wstring& family,
- int size,
- int style) {
- Cache* cache = GetCache();
- for (Cache::iterator i = cache->begin(); i != cache->end(); ++i) {
- PangoFontRef* ref = *i;
- if (ref->size() == size && ref->style() == style &&
- ref->family() == family)
- return ref;
+ 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;
}
- PangoFontRef* ref = new PangoFontRef(pfd, family, size, style);
- AddToCache(ref);
- return ref;
-}
-
-Font::PangoFontRef::~PangoFontRef() {
- pango_font_description_free(pfd_);
-}
-
-int Font::PangoFontRef::GetHeight() const {
- CalculateMetricsIfNecessary();
- return height_;
-}
-
-int Font::PangoFontRef::GetAscent() const {
- CalculateMetricsIfNecessary();
- return ascent_;
-}
-
-int Font::PangoFontRef::GetAveCharWidth() const {
- CalculateMetricsIfNecessary();
- return ave_char_width_;
-}
-
-Font::PangoFontRef::PangoFontRef(PangoFontDescription* pfd,
- const std::wstring& family,
- int size,
- int style)
- : pfd_(pango_font_description_copy(pfd)),
- family_(family),
- size_(size),
- style_(style),
- height_(0),
- ascent_(0),
- ave_char_width_(0),
- calculated_metrics_(false) {
-}
-
-void Font::PangoFontRef::CalculateMetricsIfNecessary() const {
- if (calculated_metrics_)
- return;
-
- calculated_metrics_ = true;
- PangoContext* context = get_context();
- pango_context_set_font_description(context, pfd_);
- PangoFontMetrics* metrics = pango_context_get_metrics(context, pfd_, NULL);
- ascent_ = pango_font_metrics_get_ascent(metrics) / PANGO_SCALE;
- height_ = ascent_ + pango_font_metrics_get_descent(metrics) / PANGO_SCALE;
- ave_char_width_ = pango_font_metrics_get_approximate_char_width(metrics) /
- PANGO_SCALE;
- pango_font_metrics_unref(metrics);
-}
-
-// static
-Font::PangoFontRef::Cache* Font::PangoFontRef::GetCache() {
- static Cache* cache = NULL;
- if (!cache)
- cache = new Cache();
- return cache;
-}
-
-// static
-void Font::PangoFontRef::AddToCache(PangoFontRef* ref) {
- ref->AddRef();
- Cache* cache = GetCache();
- cache->push_back(ref);
- while (cache->size() >= kMaxCacheSize) {
- PangoFontRef* ref = cache->front();
- cache->pop_front();
- ref->Release();
- }
+ return pfd;
}
} // namespace gfx
diff --git a/app/gfx/font_skia.cc b/app/gfx/font_skia.cc
new file mode 100644
index 0000000..4308bf6
--- /dev/null
+++ b/app/gfx/font_skia.cc
@@ -0,0 +1,160 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "app/gfx/font.h"
+
+#include "app/gfx/canvas.h"
+
+#include "base/logging.h"
+#include "base/sys_string_conversions.h"
+
+#include "third_party/skia/include/core/SkTypeface.h"
+#include "third_party/skia/include/core/SkPaint.h"
+
+namespace gfx {
+
+Font::Font(const Font& other) {
+ CopyFont(other);
+}
+
+Font& Font::operator=(const Font& other) {
+ CopyFont(other);
+ return *this;
+}
+
+Font::Font(SkTypeface* tf, const std::wstring& font_family, int font_size,
+ int style)
+ : typeface_helper_(new SkAutoUnref(tf)),
+ typeface_(tf),
+ font_family_(font_family),
+ font_size_(font_size),
+ style_(style) {
+ tf->ref();
+ calculateMetrics();
+}
+
+void Font::calculateMetrics() {
+ SkPaint paint;
+ SkPaint::FontMetrics metrics;
+
+ PaintSetup(&paint);
+ paint.getFontMetrics(&metrics);
+
+ ascent_ = SkScalarRound(-metrics.fAscent);
+ height_ = SkScalarRound(-metrics.fAscent + metrics.fDescent +
+ metrics.fLeading);
+
+ if (metrics.fAvgCharWidth) {
+ avg_width_ = SkScalarRound(metrics.fAvgCharWidth);
+ } else {
+ static const char x_char = 'x';
+ paint.setTextEncoding(SkPaint::kUTF8_TextEncoding);
+ SkScalar width = paint.measureText(&x_char, 1);
+
+ avg_width_ = static_cast<int>(ceilf(SkScalarToFloat(width)));
+ }
+}
+
+void Font::CopyFont(const Font& other) {
+ typeface_helper_.reset(new SkAutoUnref(other.typeface_));
+ typeface_ = other.typeface_;
+ typeface_->ref();
+ font_family_ = other.font_family_;
+ font_size_ = other.font_size_;
+ style_ = other.style_;
+ height_ = other.height_;
+ ascent_ = other.ascent_;
+ avg_width_ = other.avg_width_;
+}
+
+int Font::height() const {
+ return height_;
+}
+
+int Font::baseline() const {
+ return ascent_;
+}
+
+int Font::ave_char_width() const {
+ return avg_width_;
+}
+
+Font Font::CreateFont(const std::wstring& font_family, int font_size) {
+ DCHECK_GT(font_size, 0);
+
+ SkTypeface* tf = SkTypeface::CreateFromName(
+ base::SysWideToUTF8(font_family).c_str(), SkTypeface::kNormal);
+ // Temporary CHECK for tracking down
+ // http://code.google.com/p/chromium/issues/detail?id=12530
+ CHECK(tf) << "Could not find font: " << base::SysWideToUTF8(font_family);
+ SkAutoUnref tf_helper(tf);
+
+ return Font(tf, font_family, font_size, NORMAL);
+}
+
+Font Font::DeriveFont(int size_delta, int style) const {
+ // If the delta is negative, if must not push the size below 1
+ if (size_delta < 0) {
+ DCHECK_LT(-size_delta, font_size_);
+ }
+
+ if (style == style_) {
+ // Fast path, we just use the same typeface at a different size
+ return Font(typeface_, font_family_, font_size_ + size_delta, style_);
+ }
+
+ // If the style has changed we may need to load a new face
+ int skstyle = SkTypeface::kNormal;
+ if (BOLD & style)
+ skstyle |= SkTypeface::kBold;
+ if (ITALIC & style)
+ skstyle |= SkTypeface::kItalic;
+
+ SkTypeface* tf = SkTypeface::CreateFromName(
+ base::SysWideToUTF8(font_family_).c_str(),
+ static_cast<SkTypeface::Style>(skstyle));
+ SkAutoUnref tf_helper(tf);
+
+ return Font(tf, font_family_, font_size_ + size_delta, skstyle);
+}
+
+void Font::PaintSetup(SkPaint* paint) const {
+ paint->setAntiAlias(false);
+ paint->setSubpixelText(false);
+ paint->setTextSize(SkFloatToScalar(font_size_));
+ paint->setTypeface(typeface_);
+ paint->setFakeBoldText((BOLD & style_) && !typeface_->isBold());
+ paint->setTextSkewX((ITALIC & style_) && !typeface_->isItalic() ?
+ -SK_Scalar1/4 : 0);
+}
+
+int Font::GetStringWidth(const std::wstring& text) const {
+ int width = 0, height = 0;
+
+ Canvas::SizeStringInt(text, *this, &width, &height, 0);
+ return width;
+}
+
+int Font::GetExpectedTextWidth(int length) const {
+ return length * avg_width_;
+}
+
+
+int Font::style() const {
+ return style_;
+}
+
+std::wstring Font::FontName() {
+ return font_family_;
+}
+
+int Font::FontSize() {
+ return font_size_;
+}
+
+NativeFont Font::nativeFont() const {
+ return typeface_;
+}
+
+} // namespace gfx
diff --git a/app/gfx/font_unittest.cc b/app/gfx/font_unittest.cc
index d0f4fff..dc81ca8 100644
--- a/app/gfx/font_unittest.cc
+++ b/app/gfx/font_unittest.cc
@@ -10,7 +10,8 @@ namespace {
using gfx::Font;
-typedef testing::Test FontTest;
+class FontTest : public testing::Test {
+};
TEST_F(FontTest, LoadArial) {
Font cf(Font::CreateFont(L"Arial", 16));
@@ -30,13 +31,13 @@ TEST_F(FontTest, LoadArialBold) {
TEST_F(FontTest, Ascent) {
Font cf(Font::CreateFont(L"Arial", 16));
ASSERT_GT(cf.baseline(), 2);
- ASSERT_LT(cf.baseline(), 22);
+ ASSERT_LT(cf.baseline(), 20);
}
TEST_F(FontTest, Height) {
Font cf(Font::CreateFont(L"Arial", 16));
ASSERT_GT(cf.baseline(), 2);
- ASSERT_LT(cf.baseline(), 22);
+ ASSERT_LT(cf.baseline(), 20);
}
TEST_F(FontTest, AvgWidths) {
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
index fac4fcd..fb98795 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
+++ b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
@@ -69,6 +69,33 @@ const int kCornerSize = 3;
// UTF-8 Left-to-right embedding.
const char* kLRE = "\xe2\x80\xaa";
+// TODO(deanm): We should put this on gfx::Font so it can be shared.
+// Returns a new pango font, free with pango_font_description_free().
+PangoFontDescription* PangoFontFromGfxFont(const gfx::Font& chrome_font) {
+ gfx::Font font = chrome_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;
+}
+
// Return a Rect covering the whole area of |window|.
gfx::Rect GetWindowRect(GdkWindow* window) {
gint width, height;
@@ -246,7 +273,9 @@ AutocompletePopupViewGtk::AutocompletePopupViewGtk(
// For now, force the font size.
gfx::Font font = gfx::Font::CreateFont(
gfx::Font().FontName(), browser_defaults::kAutocompletePopupFontSize);
- pango_layout_set_font_description(layout_, font.nativeFont());
+ PangoFontDescription* pfd = PangoFontFromGfxFont(font);
+ pango_layout_set_font_description(layout_, pfd);
+ pango_font_description_free(pfd);
gtk_widget_add_events(window_, GDK_BUTTON_MOTION_MASK |
GDK_POINTER_MOTION_MASK |
diff --git a/views/controls/button/native_button_gtk.cc b/views/controls/button/native_button_gtk.cc
index 0632b21..d1fb0ef4 100644
--- a/views/controls/button/native_button_gtk.cc
+++ b/views/controls/button/native_button_gtk.cc
@@ -41,8 +41,11 @@ void NativeButtonGtk::UpdateFont() {
if (!native_view())
return;
+ NOTIMPLEMENTED();
preferred_size_ = gfx::Size();
- gtk_widget_modify_font(native_view(), native_button_->font().nativeFont());
+ // SendMessage(GetHWND(), WM_SETFONT,
+ // reinterpret_cast<WPARAM>(native_button_->font().hfont()),
+ // FALSE);
}
void NativeButtonGtk::UpdateEnabled() {
diff --git a/views/controls/textfield/native_textfield_gtk.cc b/views/controls/textfield/native_textfield_gtk.cc
index 34c4a1f..ef7a67d 100644
--- a/views/controls/textfield/native_textfield_gtk.cc
+++ b/views/controls/textfield/native_textfield_gtk.cc
@@ -105,7 +105,8 @@ void NativeTextfieldGtk::UpdateReadOnly() {
void NativeTextfieldGtk::UpdateFont() {
if (!native_view())
return;
- gtk_widget_modify_font(native_view(), textfield_->font().nativeFont());
+ gtk_widget_modify_font(native_view(),
+ gfx::Font::PangoFontFromGfxFont(textfield_->font()));
}
void NativeTextfieldGtk::UpdateEnabled() {