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

Unified Diff: ui/gfx/font_list.cc

Issue 18848002: Shows Japanese and English mixed queries correctly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Disables the test on Android. Created 7 years, 5 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
« no previous file with comments | « ui/gfx/font_list.h ('k') | ui/gfx/font_list_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/font_list.cc
diff --git a/ui/gfx/font_list.cc b/ui/gfx/font_list.cc
index 93bf73e834a0bd5bbeed9c2670e64aaeb7f86add..bbf79afe6e81530d20b0d457e39663d7cda5ec4d 100644
--- a/ui/gfx/font_list.cc
+++ b/ui/gfx/font_list.cc
@@ -69,19 +69,21 @@ std::string BuildFontDescription(const std::vector<std::string>& font_names,
namespace gfx {
-FontList::FontList() {
+FontList::FontList() : common_height_(-1), common_baseline_(-1) {
fonts_.push_back(Font());
}
FontList::FontList(const std::string& font_description_string)
- : font_description_string_(font_description_string) {
+ : font_description_string_(font_description_string),
+ common_height_(-1),
+ common_baseline_(-1) {
DCHECK(!font_description_string.empty());
// DCHECK description string ends with "px" for size in pixel.
DCHECK(EndsWith(font_description_string, "px", true));
}
FontList::FontList(const std::vector<Font>& fonts)
- : fonts_(fonts) {
+ : fonts_(fonts), common_height_(-1), common_baseline_(-1) {
DCHECK(!fonts.empty());
if (DCHECK_IS_ON()) {
int style = fonts[0].GetStyle();
@@ -93,7 +95,8 @@ FontList::FontList(const std::vector<Font>& fonts)
}
}
-FontList::FontList(const Font& font) {
+FontList::FontList(const Font& font)
+ : common_height_(-1), common_baseline_(-1) {
fonts_.push_back(font);
}
@@ -146,6 +149,34 @@ FontList FontList::DeriveFontListWithSize(int size) const {
return FontList(BuildFontDescription(font_names, font_style, size));
}
+int FontList::GetHeight() const {
+ if (common_height_ < 0) {
+ int ascent = 0;
+ int descent = 0;
+ const std::vector<Font>& fonts = GetFonts();
+ for (std::vector<Font>::const_iterator i = fonts.begin();
+ i != fonts.end(); ++i) {
+ ascent = std::max(ascent, i->GetBaseline());
+ descent = std::max(descent, i->GetHeight() - i->GetBaseline());
+ }
+ common_height_ = ascent + descent;
+ }
+ return common_height_;
+}
+
+int FontList::GetBaseline() const {
+ if (common_baseline_ < 0) {
+ int baseline = 0;
+ const std::vector<Font>& fonts = GetFonts();
+ for (std::vector<Font>::const_iterator i = fonts.begin();
+ i != fonts.end(); ++i) {
+ baseline = std::max(baseline, i->GetBaseline());
+ }
+ common_baseline_ = baseline;
+ }
+ return common_baseline_;
+}
+
int FontList::GetFontStyle() const {
if (!fonts_.empty())
return fonts_[0].GetStyle();
« no previous file with comments | « ui/gfx/font_list.h ('k') | ui/gfx/font_list_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698