| 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,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,6 +82,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 +103,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 +209,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 +222,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,11 +232,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 +249,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() {
|
|
|