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

Unified Diff: ui/gfx/platform_font_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/platform_font_win.cc
===================================================================
--- ui/gfx/platform_font_win.cc (revision 134531)
+++ ui/gfx/platform_font_win.cc (working copy)
@@ -47,6 +47,13 @@
}
}
+// Sets style properties on |font_info| based on |font_style|.
+void SetLogFontStyle(int font_style, LOGFONT* font_info) {
+ font_info->lfUnderline = (font_style & gfx::Font::UNDERLINED) != 0;
+ font_info->lfItalic = (font_style & gfx::Font::ITALIC) != 0;
+ font_info->lfWeight = (font_style & gfx::Font::BOLD) ? FW_BOLD : FW_NORMAL;
+}
+
} // namespace
namespace gfx {
@@ -75,17 +82,39 @@
InitWithFontNameAndSize(font_name, font_size);
}
+Font PlatformFontWin::DeriveFontWithHeight(int height, int style) {
+ DCHECK_GE(height, 0);
+ if (GetHeight() == height && GetStyle() == style)
+ return Font(this);
+
+ // CreateFontIndirect() doesn't return the largest size for the given height
+ // when decreasing the height. Iterate to find it.
+ if (GetHeight() > height) {
msw 2012/04/30 17:40:01 Should this heed the min locale height/size like A
Alexei Svitkine (slow) 2012/04/30 17:49:14 No, since DeriveFont() goes through AdjustFontSize
msw 2012/04/30 18:55:39 So an arg |height| < min will cause an infinite wh
Alexei Svitkine (slow) 2012/04/30 19:24:00 Good catch. Fixed and added test.
+ Font font = this->DeriveFont(-1, style);
msw 2012/04/30 17:40:01 Is there a name conflict or can you nix "this->"?
Alexei Svitkine (slow) 2012/04/30 17:49:14 Done.
+ while (font.GetHeight() > height) {
+ font = font.DeriveFont(-1, style);
+ }
+ return font;
+ }
+
+ LOGFONT font_info;
+ GetObject(GetNativeFont(), sizeof(LOGFONT), &font_info);
+ font_info.lfHeight = height;
+ SetLogFontStyle(style, &font_info);
+
+ HFONT hfont = CreateFontIndirect(&font_info);
+ return Font(new PlatformFontWin(CreateHFontRef(hfont)));
+}
+
////////////////////////////////////////////////////////////////////////////////
// PlatformFontWin, PlatformFont implementation:
Font PlatformFontWin::DeriveFont(int size_delta, int style) const {
LOGFONT font_info;
GetObject(GetNativeFont(), sizeof(LOGFONT), &font_info);
- font_info.lfHeight = AdjustFontSize(font_info.lfHeight, size_delta);
- font_info.lfUnderline =
- ((style & gfx::Font::UNDERLINED) == gfx::Font::UNDERLINED);
- font_info.lfItalic = ((style & gfx::Font::ITALIC) == gfx::Font::ITALIC);
- font_info.lfWeight = (style & gfx::Font::BOLD) ? FW_BOLD : FW_NORMAL;
+ const int requested_font_size = font_ref_->requested_font_size();
+ font_info.lfHeight = AdjustFontSize(-requested_font_size, size_delta);
+ SetLogFontStyle(style, &font_info);
HFONT hfont = CreateFontIndirect(&font_info);
return Font(new PlatformFontWin(CreateHFontRef(hfont)));
@@ -191,10 +220,11 @@
GetTextMetrics(screen_dc, &font_metrics);
}
- const int height = std::max(1, static_cast<int>(font_metrics.tmHeight));
- const int baseline = std::max(1, static_cast<int>(font_metrics.tmAscent));
- const int ave_char_width =
- std::max(1, static_cast<int>(font_metrics.tmAveCharWidth));
+ const int height = std::max<int>(1, font_metrics.tmHeight);
+ const int baseline = std::max<int>(1, font_metrics.tmAscent);
+ const int ave_char_width = std::max<int>(1, font_metrics.tmAveCharWidth);
+ const int font_size =
+ std::max<int>(1, font_metrics.tmHeight - font_metrics.tmInternalLeading);
int style = 0;
if (font_metrics.tmItalic)
style |= Font::ITALIC;
@@ -203,7 +233,7 @@
if (font_metrics.tmWeight >= kTextMetricWeightBold)
style |= Font::BOLD;
- return new HFontRef(font, height, baseline, ave_char_width, style);
+ return new HFontRef(font, font_size, height, baseline, ave_char_width, style);
}
PlatformFontWin::PlatformFontWin(HFontRef* hfont_ref) : font_ref_(hfont_ref) {
@@ -213,23 +243,26 @@
// PlatformFontWin::HFontRef:
PlatformFontWin::HFontRef::HFontRef(HFONT hfont,
+ int font_size,
int height,
int baseline,
int ave_char_width,
int style)
: hfont_(hfont),
+ font_size_(font_size),
height_(height),
baseline_(baseline),
ave_char_width_(ave_char_width),
style_(style),
- dlu_base_x_(-1) {
+ dlu_base_x_(-1),
+ requested_font_size_(font_size) {
DLOG_ASSERT(hfont);
LOGFONT font_info;
GetObject(hfont_, sizeof(LOGFONT), &font_info);
font_name_ = UTF16ToUTF8(string16(font_info.lfFaceName));
- DCHECK_LT(font_info.lfHeight, 0);
- font_size_ = -font_info.lfHeight;
+ if (font_info.lfHeight < 0)
+ requested_font_size_ = -font_info.lfHeight;
}
int PlatformFontWin::HFontRef::GetDluBaseX() {

Powered by Google App Engine
This is Rietveld 408576698