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

Unified Diff: app/gfx/font_gtk.cc

Issue 1095004: Clamp the max size of fonts used by skia/chrome canvas. (Closed)
Patch Set: Created 10 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « app/gfx/font.h ('k') | app/gfx/font_skia.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: app/gfx/font_gtk.cc
diff --git a/app/gfx/font_gtk.cc b/app/gfx/font_gtk.cc
index 85640b0801021754b304e575f13fbc4624df5b0a..dbd4228c19937384cf76d49457a6bcfedbe9faf8 100644
--- a/app/gfx/font_gtk.cc
+++ b/app/gfx/font_gtk.cc
@@ -4,6 +4,7 @@
#include "app/gfx/font.h"
+#include <algorithm>
#include <fontconfig/fontconfig.h>
#include <gtk/gtk.h>
@@ -48,6 +49,30 @@ static std::wstring FindBestMatchFontFamilyName(const char* family_name) {
return font_family;
}
+// Pango scales font sizes. This returns the scale factor. See
+// pango_cairo_context_set_resolution for details.
+// NOTE: this isn't entirely accurate, in that Pango also consults the
+// FC_PIXEL_SIZE first (see get_font_size in pangocairo-fcfont), but this
+// seems to give us the same sizes as used by Pango for all our fonts in both
+// English and Thai.
+float Font::GetPangoScaleFactor() {
+ static float scale_factor = 0;
+ static bool determined_scale = false;
+ if (!determined_scale) {
+ PangoContext* context = gdk_pango_context_get();
+ scale_factor = pango_cairo_context_get_resolution(context);
+ // Until we switch to vector graphics, force the max DPI to 96.0.
+ scale_factor = std::min(scale_factor, 96.f);
Evan Martin 2010/03/19 04:56:56 This is the new code, right?
tony 2010/03/19 04:59:36 Yes.
+ g_object_unref(context);
+ if (scale_factor <= 0)
+ scale_factor = 1;
+ else
+ scale_factor /= 72.0;
+ determined_scale = true;
+ }
+ return scale_factor;
+}
+
// static
Font Font::CreateFont(PangoFontDescription* desc) {
gint size = pango_font_description_get_size(desc);
@@ -105,7 +130,9 @@ PangoFontDescription* Font::PangoFontFromGfxFont(
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);
+ // Set the absolute size to avoid overflowing UI elements.
+ pango_font_description_set_absolute_size(pfd,
+ font.FontSize() * PANGO_SCALE * Font::GetPangoScaleFactor());
sky 2010/03/23 20:33:32 You also need to change Canvas::SetupPangoLayout o
switch (font.style()) {
case gfx::Font::NORMAL:
« no previous file with comments | « app/gfx/font.h ('k') | app/gfx/font_skia.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698