| OLD | NEW | 
|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include <stdlib.h> | 5 #include <stdlib.h> | 
| 6 | 6 | 
| 7 #include "base/logging.h" | 7 #include "base/logging.h" | 
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" | 
| 9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" | 
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" | 
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 62                                  int font_size) { | 62                                  int font_size) { | 
| 63   std::string description = JoinString(font_names, ','); | 63   std::string description = JoinString(font_names, ','); | 
| 64   description += "," + FontStyleAndSizeToString(font_style, font_size); | 64   description += "," + FontStyleAndSizeToString(font_style, font_size); | 
| 65   return description; | 65   return description; | 
| 66 } | 66 } | 
| 67 | 67 | 
| 68 }  // namespace | 68 }  // namespace | 
| 69 | 69 | 
| 70 namespace gfx { | 70 namespace gfx { | 
| 71 | 71 | 
| 72 FontList::FontList() { | 72 FontList::FontList() : common_height_(-1), common_baseline_(-1) { | 
| 73   fonts_.push_back(Font()); | 73   fonts_.push_back(Font()); | 
| 74 } | 74 } | 
| 75 | 75 | 
| 76 FontList::FontList(const std::string& font_description_string) | 76 FontList::FontList(const std::string& font_description_string) | 
| 77     : font_description_string_(font_description_string) { | 77     : font_description_string_(font_description_string), | 
|  | 78       common_height_(-1), | 
|  | 79       common_baseline_(-1) { | 
| 78   DCHECK(!font_description_string.empty()); | 80   DCHECK(!font_description_string.empty()); | 
| 79   // DCHECK description string ends with "px" for size in pixel. | 81   // DCHECK description string ends with "px" for size in pixel. | 
| 80   DCHECK(EndsWith(font_description_string, "px", true)); | 82   DCHECK(EndsWith(font_description_string, "px", true)); | 
| 81 } | 83 } | 
| 82 | 84 | 
| 83 FontList::FontList(const std::vector<Font>& fonts) | 85 FontList::FontList(const std::vector<Font>& fonts) | 
| 84     : fonts_(fonts) { | 86     : fonts_(fonts), common_height_(-1), common_baseline_(-1) { | 
| 85   DCHECK(!fonts.empty()); | 87   DCHECK(!fonts.empty()); | 
| 86   if (DCHECK_IS_ON()) { | 88   if (DCHECK_IS_ON()) { | 
| 87     int style = fonts[0].GetStyle(); | 89     int style = fonts[0].GetStyle(); | 
| 88     int size = fonts[0].GetFontSize(); | 90     int size = fonts[0].GetFontSize(); | 
| 89     for (size_t i = 1; i < fonts.size(); ++i) { | 91     for (size_t i = 1; i < fonts.size(); ++i) { | 
| 90       DCHECK_EQ(fonts[i].GetStyle(), style); | 92       DCHECK_EQ(fonts[i].GetStyle(), style); | 
| 91       DCHECK_EQ(fonts[i].GetFontSize(), size); | 93       DCHECK_EQ(fonts[i].GetFontSize(), size); | 
| 92     } | 94     } | 
| 93   } | 95   } | 
| 94 } | 96 } | 
| 95 | 97 | 
| 96 FontList::FontList(const Font& font) { | 98 FontList::FontList(const Font& font) | 
|  | 99     : common_height_(-1), common_baseline_(-1) { | 
| 97   fonts_.push_back(font); | 100   fonts_.push_back(font); | 
| 98 } | 101 } | 
| 99 | 102 | 
| 100 FontList::~FontList() { | 103 FontList::~FontList() { | 
| 101 } | 104 } | 
| 102 | 105 | 
| 103 FontList FontList::DeriveFontList(int font_style) const { | 106 FontList FontList::DeriveFontList(int font_style) const { | 
| 104   // If there is a font vector, derive from that. | 107   // If there is a font vector, derive from that. | 
| 105   if (!fonts_.empty()) { | 108   if (!fonts_.empty()) { | 
| 106     std::vector<Font> fonts = fonts_; | 109     std::vector<Font> fonts = fonts_; | 
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 139   int font_style = 0; | 142   int font_style = 0; | 
| 140   ParseFontDescriptionString(font_description_string_, &font_names, | 143   ParseFontDescriptionString(font_description_string_, &font_names, | 
| 141                              &font_style, &old_size); | 144                              &font_style, &old_size); | 
| 142 | 145 | 
| 143   if (old_size == size) | 146   if (old_size == size) | 
| 144     return FontList(font_description_string_); | 147     return FontList(font_description_string_); | 
| 145 | 148 | 
| 146   return FontList(BuildFontDescription(font_names, font_style, size)); | 149   return FontList(BuildFontDescription(font_names, font_style, size)); | 
| 147 } | 150 } | 
| 148 | 151 | 
|  | 152 int FontList::GetHeight() const { | 
|  | 153   if (common_height_ < 0) { | 
|  | 154     int ascent = 0; | 
|  | 155     int descent = 0; | 
|  | 156     const std::vector<Font>& fonts = GetFonts(); | 
|  | 157     for (std::vector<Font>::const_iterator i = fonts.begin(); | 
|  | 158          i != fonts.end(); ++i) { | 
|  | 159       ascent = std::max(ascent, i->GetBaseline()); | 
|  | 160       descent = std::max(descent, i->GetHeight() - i->GetBaseline()); | 
|  | 161     } | 
|  | 162     common_height_ = ascent + descent; | 
|  | 163   } | 
|  | 164   return common_height_; | 
|  | 165 } | 
|  | 166 | 
|  | 167 int FontList::GetBaseline() const { | 
|  | 168   if (common_baseline_ < 0) { | 
|  | 169     int baseline = 0; | 
|  | 170     const std::vector<Font>& fonts = GetFonts(); | 
|  | 171     for (std::vector<Font>::const_iterator i = fonts.begin(); | 
|  | 172          i != fonts.end(); ++i) { | 
|  | 173       baseline = std::max(baseline, i->GetBaseline()); | 
|  | 174     } | 
|  | 175     common_baseline_ = baseline; | 
|  | 176   } | 
|  | 177   return common_baseline_; | 
|  | 178 } | 
|  | 179 | 
| 149 int FontList::GetFontStyle() const { | 180 int FontList::GetFontStyle() const { | 
| 150   if (!fonts_.empty()) | 181   if (!fonts_.empty()) | 
| 151     return fonts_[0].GetStyle(); | 182     return fonts_[0].GetStyle(); | 
| 152 | 183 | 
| 153   std::vector<std::string> font_names; | 184   std::vector<std::string> font_names; | 
| 154   int font_style; | 185   int font_style; | 
| 155   int font_size; | 186   int font_size; | 
| 156   ParseFontDescriptionString(font_description_string_, &font_names, | 187   ParseFontDescriptionString(font_description_string_, &font_names, | 
| 157                              &font_style, &font_size); | 188                              &font_style, &font_size); | 
| 158   return font_style; | 189   return font_style; | 
| (...skipping 30 matching lines...) Expand all  Loading... | 
| 189       if (font_style == Font::NORMAL) | 220       if (font_style == Font::NORMAL) | 
| 190         fonts_.push_back(font); | 221         fonts_.push_back(font); | 
| 191       else | 222       else | 
| 192         fonts_.push_back(font.DeriveFont(0, font_style)); | 223         fonts_.push_back(font.DeriveFont(0, font_style)); | 
| 193     } | 224     } | 
| 194   } | 225   } | 
| 195   return fonts_; | 226   return fonts_; | 
| 196 } | 227 } | 
| 197 | 228 | 
| 198 }  // namespace gfx | 229 }  // namespace gfx | 
| OLD | NEW | 
|---|