| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "app/gfx/font.h" | 5 #include "app/gfx/font.h" |
| 6 | 6 |
| 7 #include <gdk/gdk.h> | 7 #include <gdk/gdk.h> |
| 8 #include <pango/pango.h> | 8 #include <pango/pango.h> |
| 9 | 9 |
| 10 #include "app/gfx/canvas.h" | 10 #include "app/gfx/canvas.h" |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 pango_language_get_default()); | 180 pango_language_get_default()); |
| 181 double pango_width = | 181 double pango_width = |
| 182 pango_font_metrics_get_approximate_char_width(pango_metrics); | 182 pango_font_metrics_get_approximate_char_width(pango_metrics); |
| 183 pango_width /= PANGO_SCALE; | 183 pango_width /= PANGO_SCALE; |
| 184 | 184 |
| 185 // Yes, this is how Microsoft recommends calculating the dialog unit | 185 // Yes, this is how Microsoft recommends calculating the dialog unit |
| 186 // conversions. | 186 // conversions. |
| 187 int text_width = GetStringWidth( | 187 int text_width = GetStringWidth( |
| 188 L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"); | 188 L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"); |
| 189 double dialog_units = (text_width / 26 + 1) / 2; | 189 double dialog_units = (text_width / 26 + 1) / 2; |
| 190 | |
| 191 avg_width_ = std::min(pango_width, dialog_units); | 190 avg_width_ = std::min(pango_width, dialog_units); |
| 192 pango_font_metrics_unref(pango_metrics); | 191 pango_font_metrics_unref(pango_metrics); |
| 193 pango_font_description_free(pango_desc); | 192 pango_font_description_free(pango_desc); |
| 194 } | 193 } |
| 195 return avg_width_; | 194 return avg_width_; |
| 196 } | 195 } |
| 197 | 196 |
| 198 int Font::GetExpectedTextWidth(int length) const { | 197 int Font::GetExpectedTextWidth(int length) const { |
| 199 double char_width = const_cast<Font*>(this)->avg_width(); | 198 double char_width = const_cast<Font*>(this)->avg_width(); |
| 200 return round(static_cast<float>(length) * char_width); | 199 return round(static_cast<float>(length) * char_width); |
| 201 } | 200 } |
| 202 | 201 |
| 203 int Font::style() const { | 202 int Font::style() const { |
| 204 return style_; | 203 return style_; |
| 205 } | 204 } |
| 206 | 205 |
| 207 std::wstring Font::FontName() { | 206 std::wstring Font::FontName() { |
| 208 return font_family_; | 207 return font_family_; |
| 209 } | 208 } |
| 210 | 209 |
| 211 int Font::FontSize() { | 210 int Font::FontSize() { |
| 212 return font_size_; | 211 return font_size_; |
| 213 } | 212 } |
| 214 | 213 |
| 215 NativeFont Font::nativeFont() const { | 214 NativeFont Font::nativeFont() const { |
| 216 return typeface_; | 215 return typeface_; |
| 217 } | 216 } |
| 218 | 217 |
| 219 } // namespace gfx | 218 } // namespace gfx |
| OLD | NEW |