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

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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/render_text_win.cc
===================================================================
--- ui/gfx/render_text_win.cc (revision 133692)
+++ ui/gfx/render_text_win.cc (working copy)
@@ -13,6 +13,7 @@
#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"
@@ -116,14 +117,41 @@
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) {
+// Chooses the largest font size for |font| such that its height does not exceed
msw 2012/04/25 22:07:31 Add a DCHECK at the bottom of the function to ensu
+// |font_height|. |font_style| is used for the style when deriving the font.
+void DeriveFontWithHeight(int font_height, int font_style, gfx::Font* font) {
msw 2012/04/25 22:07:31 This probably needs test coverage.
Alexei Svitkine (slow) 2012/04/25 23:19:31 Do you mean the function itself, or the whole Rend
msw 2012/04/25 23:35:41 I meant the CJK rendertext codepath, very sad that
+ if (font->GetHeight() > font_height) {
+ do {
+ *font = font->DeriveFont(-1, font_style);
+ } while (font->GetHeight() > font_height);
msw 2012/04/25 22:07:31 Only code trying to emulate MS APIs could be this
Alexei Svitkine (slow) 2012/04/25 23:19:31 DeriveFont() is not very expensive anymore (but no
msw 2012/04/25 23:35:41 Yeah, I'm dubious that it's worth your time/effort
+ } else if (font->GetHeight() < font_height) {
+ gfx::Font larger_font = font->DeriveFont(1, font_style);
+ while (larger_font.GetHeight() < font_height) {
msw 2012/04/25 22:07:31 Shouldn't this be '<=' ? Otherwiset we'll miss whe
Alexei Svitkine (slow) 2012/04/25 23:19:31 You're absolutely right! I had this correct before
+ *font = larger_font;
+ larger_font = larger_font.DeriveFont(1, font_style);
+ }
+ }
+}
+
+// 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,
+ int font_height,
+ int font_style,
+ gfx::Font* font) {
+ // On Windows XP, the font must be resized using |font_height| instead of
+ // |font_size| to match the GDI behavior.
msw 2012/04/25 22:07:31 grammar nit: nix 'the' -> "match GDI behavior"
+ if (base::win::GetVersion() < base::win::VERSION_VISTA) {
+ DeriveFontWithHeight(font_height, font_style, font);
+ font_size = font->GetFontSize();
+ }
+
const int kStyleMask = (gfx::Font::BOLD | gfx::Font::ITALIC);
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);
}
@@ -562,7 +590,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 +775,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());
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698