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

Unified Diff: ui/gfx/render_text_win.cc

Issue 10228009: Fix CJK font linking size on Windows XP. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 8 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
Index: ui/gfx/render_text_win.cc
===================================================================
--- ui/gfx/render_text_win.cc (revision 133692)
+++ ui/gfx/render_text_win.cc (working copy)
@@ -13,9 +13,10 @@
#include "base/threading/thread_restrictions.h"
#include "base/utf_string_conversions.h"
#include "base/win/registry.h"
+#include "base/win/windows_version.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/font_smoothing_win.h"
-#include "ui/gfx/platform_font.h"
+#include "ui/gfx/platform_font_win.h"
namespace {
@@ -116,16 +117,29 @@
key.Close();
}
-// Changes |font| to have the specified |font_size| and |font_style| if it does
-// not already. Only considers bold and italic styles, since the underlined
-// style has no effect on glyph shaping.
-void DeriveFontIfNecessary(int font_size, int font_style, gfx::Font* font) {
+// Changes |font| to have the specified |font_size| (or |font_height| on Windows
+// XP) and |font_style| if it is not the case already. Only considers bold and
+// italic styles, since the underlined style has no effect on glyph shaping.
+void DeriveFontIfNecessary(int font_size,
msw 2012/04/26 21:04:42 It would be nice to have this function take a cons
Alexei Svitkine (slow) 2012/04/26 21:45:56 That won't work for the call site that applies the
msw 2012/04/26 22:14:13 Fair enough, I agree :), the function comment suff
+ int font_height,
+ int font_style,
+ gfx::Font* font) {
const int kStyleMask = (gfx::Font::BOLD | gfx::Font::ITALIC);
+ const int target_style = (font_style & kStyleMask);
+
+ // On Windows XP, the font must be resized using |font_height| instead of
+ // |font_size| to match GDI behavior.
+ if (base::win::GetVersion() < base::win::VERSION_VISTA) {
+ gfx::PlatformFontWin* platform_font =
+ static_cast<gfx::PlatformFontWin*>(font->platform_font());
+ *font = platform_font->DeriveFontWithHeight(font_height, target_style);
+ return;
+ }
+
const int current_style = (font->GetStyle() & kStyleMask);
- const int target_style = (font_style & kStyleMask);
const int current_size = font->GetFontSize();
- if (current_style != target_style || current_size != font_size)
- *font = font->DeriveFont(font_size - current_size, font_style);
+ if (current_style != target_style || current_size != font->GetFontSize())
+ *font = font->DeriveFont(font_size - font->GetFontSize(), font_style);
}
} // namespace
@@ -562,7 +576,8 @@
run->range.set_start(run_break);
run->font = GetFont();
run->font_style = style->font_style;
- DeriveFontIfNecessary(run->font.GetFontSize(), run->font_style, &run->font);
+ DeriveFontIfNecessary(run->font.GetFontSize(), run->font.GetHeight(),
+ run->font_style, &run->font);
run->foreground = style->foreground;
run->strike = style->strike;
run->diagonal_strike = style->diagonal_strike;
@@ -746,8 +761,9 @@
void RenderTextWin::ApplySubstituteFont(internal::TextRun* run,
const Font& font) {
const int font_size = run->font.GetFontSize();
+ const int font_height = run->font.GetHeight();
run->font = font;
- DeriveFontIfNecessary(font_size, run->font_style, &run->font);
+ DeriveFontIfNecessary(font_size, font_height, run->font_style, &run->font);
ScriptFreeCache(&run->script_cache);
SelectObject(cached_hdc_, run->font.GetNativeFont());
}

Powered by Google App Engine
This is Rietveld 408576698