diff options
author | jshin@chromium.org <jshin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-16 23:10:29 +0000 |
---|---|---|
committer | jshin@chromium.org <jshin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-16 23:10:29 +0000 |
commit | f80821f8daed7afa20cec3685a9897460242ba3a (patch) | |
tree | a604a9a82c33932375cffebe2337df66afa3abc6 /app | |
parent | 4c8a86f8e37d96d6e0836215665698ad42577de4 (diff) | |
download | chromium_src-f80821f8daed7afa20cec3685a9897460242ba3a.zip chromium_src-f80821f8daed7afa20cec3685a9897460242ba3a.tar.gz chromium_src-f80821f8daed7afa20cec3685a9897460242ba3a.tar.bz2 |
Forcing font size to be >= IDS_MINIMUM_UI_FONT_SIZE (usually 5, but for some
locales more than that).Fixed spelling in font.h.Added windows only unittest for
it.
BUG=2919 (http://crbug.com/2919)
TEST=Pass font_unittest on Windows
Patch by cira
Original Review: http://codereview.chromium.org/125159
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18552 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r-- | app/gfx/font.h | 2 | ||||
-rw-r--r-- | app/gfx/font_unittest.cc | 19 | ||||
-rw-r--r-- | app/gfx/font_win.cc | 43 | ||||
-rw-r--r-- | app/resources/app_locale_settings.grd | 6 |
4 files changed, 51 insertions, 19 deletions
diff --git a/app/gfx/font.h b/app/gfx/font.h index bf759f75..ef03d99 100644 --- a/app/gfx/font.h +++ b/app/gfx/font.h @@ -65,7 +65,7 @@ class Font { } // Returns a new Font derived from the existing font. - // size_deta is the size to add to the current font. See the single + // size_delta is the size to add to the current font. See the single // argument version of this method for an example. // The style parameter specifies the new style for the font, and is a // bitmask of the values: BOLD, ITALIC and UNDERLINED. diff --git a/app/gfx/font_unittest.cc b/app/gfx/font_unittest.cc index 3a13e2f6..dc81ca8 100644 --- a/app/gfx/font_unittest.cc +++ b/app/gfx/font_unittest.cc @@ -56,4 +56,23 @@ TEST_F(FontTest, Widths) { ASSERT_GT(cf.GetStringWidth(L"abc"), cf.GetStringWidth(L"ab")); } +#if defined(OS_WIN) +TEST_F(FontTest, DeriveFontResizesIfSizeTooSmall) { + // This creates font of height -8. + Font cf(Font::CreateFont(L"Arial", 6)); + Font derived_font = cf.DeriveFont(-4); + LOGFONT font_info; + GetObject(derived_font.hfont(), sizeof(LOGFONT), &font_info); + EXPECT_EQ(-5, font_info.lfHeight); +} + +TEST_F(FontTest, DeriveFontKeepsOriginalSizeIfHeightOk) { + // This creates font of height -8. + Font cf(Font::CreateFont(L"Arial", 6)); + Font derived_font = cf.DeriveFont(-2); + LOGFONT font_info; + GetObject(derived_font.hfont(), sizeof(LOGFONT), &font_info); + EXPECT_EQ(-6, font_info.lfHeight); +} +#endif } // anonymous namespace diff --git a/app/gfx/font_win.cc b/app/gfx/font_win.cc index c1b9d24..5e22efe 100644 --- a/app/gfx/font_win.cc +++ b/app/gfx/font_win.cc @@ -9,9 +9,12 @@ #include <algorithm> +#include "app/l10n_util.h" #include "app/l10n_util_win.h" #include "base/logging.h" +#include "base/string_util.h" #include "base/win_util.h" +#include "grit/app_locale_settings.h" namespace gfx { @@ -22,6 +25,25 @@ Font::HFontRef* Font::base_font_ref_; // font is bold. static const int kTextMetricWeightBold = 700; +// Returns either minimum font allowed for a current locale or +// lf_height + size_delta value. +static int AdjustFontSize(int lf_height, int size_delta) { + if (lf_height < 0) { + lf_height -= size_delta; + } else { + lf_height += size_delta; + } + int min_font_size = + StringToInt(l10n_util::GetString(IDS_MINIMUM_UI_FONT_SIZE).c_str()); + // Make sure lf_height is not smaller than allowed min font size for current + // locale. + if (abs(lf_height) < min_font_size) { + return lf_height < 0 ? -min_font_size : min_font_size; + } else { + return lf_height; + } +} + // // Font // @@ -78,12 +100,8 @@ Font::HFontRef* Font::GetBaseFontRef() { win_util::GetNonClientMetrics(&metrics); l10n_util::AdjustUIFont(&metrics.lfMessageFont); - - // See comment in Font::DeriveFont() about font size. - // TODO(jungshik): Add a per-locale resource entry for the minimum - // font size and actually enforce the lower-bound. 5 is way too small - // for CJK, Thai, and Indian locales. - DCHECK_GE(abs(metrics.lfMessageFont.lfHeight), 5); + metrics.lfMessageFont.lfHeight = + AdjustFontSize(metrics.lfMessageFont.lfHeight, 0); HFONT font = CreateFontIndirect(&metrics.lfMessageFont); DLOG_ASSERT(font); base_font_ref_ = Font::CreateHFontRef(font); @@ -133,21 +151,10 @@ Font::HFontRef::~HFontRef() { DeleteObject(hfont_); } - Font Font::DeriveFont(int size_delta, int style) const { LOGFONT font_info; GetObject(hfont(), sizeof(LOGFONT), &font_info); - // LOGFONT returns two types of font heights, negative is measured slightly - // differently (character height, vs cell height). - if (font_info.lfHeight < 0) { - font_info.lfHeight -= size_delta; - } else { - font_info.lfHeight += size_delta; - } - // Even with "Small Fonts", the smallest readable font size is 5. It is easy - // to create a non-drawing font and forget about the fact that text should be - // drawn in the UI. This test ensures that the font will be readable. - DCHECK_GE(abs(font_info.lfHeight), 5); + font_info.lfHeight = AdjustFontSize(font_info.lfHeight, size_delta); font_info.lfUnderline = ((style & UNDERLINED) == UNDERLINED); font_info.lfItalic = ((style & ITALIC) == ITALIC); font_info.lfWeight = (style & BOLD) ? FW_BOLD : FW_NORMAL; diff --git a/app/resources/app_locale_settings.grd b/app/resources/app_locale_settings.grd index c86e4dc..e004736 100644 --- a/app/resources/app_locale_settings.grd +++ b/app/resources/app_locale_settings.grd @@ -193,6 +193,12 @@ <message name="IDS_UI_FONT_SIZE_SCALER_XP" use_name_for_id="true"> 100 </message> + + <!-- Limit minimum UI font size to 5 for all locales. + TODO(cira): add exceptions once we create xtb files. --> + <message name="IDS_MINIMUM_UI_FONT_SIZE" use_name_for_id="true"> + 5 + </message> </messages> </release> </grit> |