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

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 133692)
+++ ui/gfx/platform_font_win.cc (working copy)
@@ -47,6 +47,14 @@
}
}
+// 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) == gfx::Font::UNDERLINED);
msw 2012/04/26 21:04:42 Just set the bool to the bit-wise & value (kinda l
Alexei Svitkine (slow) 2012/04/26 21:45:56 Done. I used != 0 since I don't know if passing va
+ font_info->lfItalic = ((font_style & gfx::Font::ITALIC) == gfx::Font::ITALIC);
+ font_info->lfWeight = (font_style & gfx::Font::BOLD) ? FW_BOLD : FW_NORMAL;
+}
+
} // namespace
namespace gfx {
@@ -75,6 +83,20 @@
InitWithFontNameAndSize(font_name, font_size);
}
+Font PlatformFontWin::DeriveFontWithHeight(int height, int style) {
+ DCHECK_GE(height, 0);
+ if (GetHeight() == height && GetStyle() == style)
+ return Font(this);
+
+ 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:
@@ -82,10 +104,7 @@
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;
+ SetLogFontStyle(style, &font_info);
HFONT hfont = CreateFontIndirect(&font_info);
return Font(new PlatformFontWin(CreateHFontRef(hfont)));
@@ -191,10 +210,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);
msw 2012/04/26 21:04:42 nice :)
+ 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 +223,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);
msw 2012/04/26 21:04:42 Seems like HFontRef's ctor should just take (HFONT
Alexei Svitkine (slow) 2012/04/26 21:45:56 I agree, but let's leave it for another CL.
msw 2012/04/26 22:14:13 SGTM.
}
PlatformFontWin::PlatformFontWin(HFontRef* hfont_ref) : font_ref_(hfont_ref) {
@@ -213,11 +233,13 @@
// 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),
@@ -228,8 +250,6 @@
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;
}
int PlatformFontWin::HFontRef::GetDluBaseX() {

Powered by Google App Engine
This is Rietveld 408576698