From 28e466cf8282a13c22ff64eb762b7adef8f68f11 Mon Sep 17 00:00:00 2001 From: "falken@chromium.org" Date: Wed, 6 Apr 2011 05:01:20 +0000 Subject: Switch fonts when Chrome OS locale changes. This patch is just a start. When locale changes through the login screen UI, the fonts in ResourceBundle and PlatformFontGtk are updated, and the password fields and username labels are redrawn with the correct font. In the future, all widgets in the login screen would be redrawn with the correct font. When the locale changes upon login, the fonts are updated, though not all widgets are redrawn correctly yet. BUG=chromium-os:13450 TEST=manually Review URL: http://codereview.chromium.org/6788004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80579 0039d316-1c4b-4281-b951-d872f2087c98 --- ui/base/resource/resource_bundle.cc | 13 +++++++++++-- ui/base/resource/resource_bundle.h | 4 ++++ ui/gfx/platform_font_gtk.cc | 8 +++++++- ui/gfx/platform_font_gtk.h | 5 +++++ 4 files changed, 27 insertions(+), 3 deletions(-) (limited to 'ui') diff --git a/ui/base/resource/resource_bundle.cc b/ui/base/resource/resource_bundle.cc index af615c0..56b3761 100644 --- a/ui/base/resource/resource_bundle.cc +++ b/ui/base/resource/resource_bundle.cc @@ -161,7 +161,10 @@ RefCountedStaticMemory* ResourceBundle::LoadDataResourceBytes( } const gfx::Font& ResourceBundle::GetFont(FontStyle style) { - LoadFontsIfNecessary(); + { + base::AutoLock lock_scope(*lock_); + LoadFontsIfNecessary(); + } switch (style) { case BoldFont: return *bold_font_; @@ -178,6 +181,12 @@ const gfx::Font& ResourceBundle::GetFont(FontStyle style) { } } +void ResourceBundle::ReloadFonts() { + base::AutoLock lock_scope(*lock_); + base_font_.reset(); + LoadFontsIfNecessary(); +} + ResourceBundle::ResourceBundle() : lock_(new base::Lock), resources_data_(NULL), @@ -191,7 +200,7 @@ void ResourceBundle::FreeImages() { } void ResourceBundle::LoadFontsIfNecessary() { - base::AutoLock lock_scope(*lock_); + lock_->AssertAcquired(); if (!base_font_.get()) { base_font_.reset(new gfx::Font()); diff --git a/ui/base/resource/resource_bundle.h b/ui/base/resource/resource_bundle.h index aa3d306..d973103 100644 --- a/ui/base/resource/resource_bundle.h +++ b/ui/base/resource/resource_bundle.h @@ -134,6 +134,10 @@ class ResourceBundle { // Returns the font for the specified style. const gfx::Font& GetFont(FontStyle style); + // Resets and reloads the cached fonts. This is useful when the fonts of the + // system have changed, for example, when the locale has changed. + void ReloadFonts(); + #if defined(OS_WIN) // Loads and returns an icon from the app module. HICON LoadThemeIcon(int icon_id); diff --git a/ui/gfx/platform_font_gtk.cc b/ui/gfx/platform_font_gtk.cc index ac0831f..5ccc7c5 100644 --- a/ui/gfx/platform_font_gtk.cc +++ b/ui/gfx/platform_font_gtk.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -200,6 +200,12 @@ double PlatformFontGtk::underline_thickness() const { //////////////////////////////////////////////////////////////////////////////// // PlatformFontGtk, PlatformFont implementation: +// static +void PlatformFontGtk::ReloadDefaultFont() { + delete default_font_; + default_font_ = NULL; +} + Font PlatformFontGtk::DeriveFont(int size_delta, int style) const { // If the delta is negative, if must not push the size below 1 if (size_delta < 0) diff --git a/ui/gfx/platform_font_gtk.h b/ui/gfx/platform_font_gtk.h index 7f7a4ec..2159752 100644 --- a/ui/gfx/platform_font_gtk.h +++ b/ui/gfx/platform_font_gtk.h @@ -27,6 +27,11 @@ class PlatformFontGtk : public PlatformFont { // pango_font_description_free(). static PangoFontDescription* PangoFontFromGfxFont(const gfx::Font& gfx_font); + // Resets and reloads the cached system font used by the default constructor. + // This function is useful when the system font has changed, for example, when + // the locale has changed. + static void ReloadDefaultFont(); + // Position as an offset from the height of the drawn text, used to draw // an underline. This is a negative number, so the underline would be // drawn at y + height + underline_position; -- cgit v1.1