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

Unified Diff: ui/base/resource/resource_bundle.cc

Issue 1819753003: Allow various font weights in gfx. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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/base/resource/resource_bundle.cc
diff --git a/ui/base/resource/resource_bundle.cc b/ui/base/resource/resource_bundle.cc
index 8afa15b608988d97be8981edc0f61467667a3c13..29f09bb951e55f2aa4cd59decaf991b57b354179 100644
--- a/ui/base/resource/resource_bundle.cc
+++ b/ui/base/resource/resource_bundle.cc
@@ -158,6 +158,29 @@ class ResourceBundle::ResourceBundleImageSource : public gfx::ImageSkiaSource {
DISALLOW_COPY_AND_ASSIGN(ResourceBundleImageSource);
};
+struct ResourceBundle::FontKey {
+ FontKey(int in_size_delta,
+ gfx::Font::FontStyle in_style,
+ gfx::Font::FontWeight in_weight)
+ : size_delta(in_size_delta), style(in_style), weight(in_weight) {}
+
+ ~FontKey() {}
+
+ bool operator==(const FontKey& rhs) const {
+ return size_delta == rhs.size_delta && style == rhs.style &&
+ weight == rhs.weight;
+ }
+
+ bool operator<(const FontKey& rhs) const {
+ return size_delta < rhs.size_delta || style < rhs.style ||
msw 2016/03/22 01:53:43 This key comparator may be problematic, the conver
tapted 2016/03/22 04:04:17 yeah - comparators need to obey "strict weak order
Mikus 2016/03/22 14:19:50 Done.
Mikus 2016/03/22 14:19:50 Done.
+ weight < rhs.weight;
+ }
+
+ int size_delta;
+ gfx::Font::FontStyle style;
+ gfx::Font::FontWeight weight;
+};
+
// static
std::string ResourceBundle::InitSharedInstanceWithLocale(
const std::string& pref_locale,
@@ -533,36 +556,38 @@ base::string16 ResourceBundle::GetLocalizedString(int message_id) {
const gfx::FontList& ResourceBundle::GetFontListWithDelta(
int size_delta,
- gfx::Font::FontStyle style) {
+ gfx::Font::FontStyle style,
+ gfx::Font::FontWeight weight) {
base::AutoLock lock_scope(*images_and_fonts_lock_);
- typedef std::pair<int, gfx::Font::FontStyle> Key;
- const Key styled_key(size_delta, style);
+ const FontKey key = {size_delta, style, weight};
tapted 2016/03/22 04:04:17 These will call the constructor using C++11 "Unifo
Mikus 2016/03/22 14:19:50 But this is a POD object, we can use this for stru
tapted 2016/03/22 23:31:32 You can't use aggregate initialization if there's
- auto found = font_cache_.find(styled_key);
+ auto found = font_cache_.find(key);
if (found != font_cache_.end())
return found->second;
- const Key base_key(0, gfx::Font::NORMAL);
+ const FontKey base_key = {0, gfx::Font::NORMAL, gfx::Font::WEIGHT_NORMAL};
gfx::FontList& base = font_cache_[base_key];
- if (styled_key == base_key)
+ if (key == base_key)
return base;
// Fonts of a given style are derived from the unstyled font of the same size.
// Cache the unstyled font by first inserting a default-constructed font list.
// Then, derive it for the initial insertion, or use the iterator that points
// to the existing entry that the insertion collided with.
- const Key sized_key(size_delta, gfx::Font::NORMAL);
+ const FontKey sized_key = {size_delta, gfx::Font::NORMAL, weight};
tapted 2016/03/22 04:04:17 This needs to pass gfx::Font::WEIGHT_NORMAL, not |
Mikus 2016/03/22 14:19:50 Done.
auto sized = font_cache_.insert(std::make_pair(sized_key, gfx::FontList()));
if (sized.second)
sized.first->second = base.DeriveWithSizeDelta(size_delta);
- if (styled_key == sized_key)
+ if (key == sized_key)
tapted 2016/03/22 04:04:17 Unless I've missed something, this should go back
Mikus 2016/03/22 14:19:50 Done.
return sized.first->second;
- auto styled = font_cache_.insert(std::make_pair(styled_key, gfx::FontList()));
+ auto styled = font_cache_.insert(std::make_pair(sized_key, gfx::FontList()));
tapted 2016/03/22 04:04:17 sized_key -> styled_key
DCHECK(styled.second); // Otherwise font_cache_.find(..) would have found it.
styled.first->second = sized.first->second.DeriveWithStyle(
sized.first->second.GetFontStyle() | style);
+ styled.first->second = sized.first->second.DeriveWithWeight(weight);
msw 2016/03/22 01:53:43 Can/should we avoid the second derive call and jus
Mikus 2016/03/22 14:19:50 Done.
+
return styled.first->second;
}
@@ -572,10 +597,10 @@ const gfx::Font& ResourceBundle::GetFontWithDelta(int size_delta,
}
const gfx::FontList& ResourceBundle::GetFontList(FontStyle legacy_style) {
- gfx::Font::FontStyle font_style = gfx::Font::NORMAL;
+ gfx::Font::FontWeight font_weight = gfx::Font::WEIGHT_NORMAL;
if (legacy_style == BoldFont || legacy_style == SmallBoldFont ||
legacy_style == MediumBoldFont || legacy_style == LargeBoldFont)
- font_style = gfx::Font::BOLD;
+ font_weight = gfx::Font::WEIGHT_BOLD;
int size_delta = 0;
switch (legacy_style) {
@@ -596,7 +621,7 @@ const gfx::FontList& ResourceBundle::GetFontList(FontStyle legacy_style) {
break;
}
- return GetFontListWithDelta(size_delta, font_style);
+ return GetFontListWithDelta(size_delta, gfx::Font::NORMAL, font_weight);
}
const gfx::Font& ResourceBundle::GetFont(FontStyle style) {

Powered by Google App Engine
This is Rietveld 408576698