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

Side by Side Diff: ui/gfx/platform_font_pango.cc

Issue 9117009: Move |PlatformFont::GetStringWidth()| implementation up into font.cc directly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gfx/platform_font_pango.h ('k') | ui/gfx/platform_font_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ui/gfx/platform_font_pango.h" 5 #include "ui/gfx/platform_font_pango.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <fontconfig/fontconfig.h> 8 #include <fontconfig/fontconfig.h>
9 #include <map> 9 #include <map>
10 #include <pango/pango.h> 10 #include <pango/pango.h>
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 232
233 int PlatformFontPango::GetBaseline() const { 233 int PlatformFontPango::GetBaseline() const {
234 return ascent_pixels_; 234 return ascent_pixels_;
235 } 235 }
236 236
237 int PlatformFontPango::GetAverageCharacterWidth() const { 237 int PlatformFontPango::GetAverageCharacterWidth() const {
238 const_cast<PlatformFontPango*>(this)->InitPangoMetrics(); 238 const_cast<PlatformFontPango*>(this)->InitPangoMetrics();
239 return SkScalarRound(average_width_pixels_); 239 return SkScalarRound(average_width_pixels_);
240 } 240 }
241 241
242 int PlatformFontPango::GetStringWidth(const string16& text) const {
243 int width = 0, height = 0;
244 CanvasSkia::SizeStringInt(text, Font(const_cast<PlatformFontPango*>(this)),
245 &width, &height, gfx::Canvas::NO_ELLIPSIS);
246 return width;
247 }
248
249 int PlatformFontPango::GetExpectedTextWidth(int length) const { 242 int PlatformFontPango::GetExpectedTextWidth(int length) const {
250 double char_width = const_cast<PlatformFontPango*>(this)->GetAverageWidth(); 243 double char_width = const_cast<PlatformFontPango*>(this)->GetAverageWidth();
251 return round(static_cast<float>(length) * char_width); 244 return round(static_cast<float>(length) * char_width);
252 } 245 }
253 246
254 int PlatformFontPango::GetStyle() const { 247 int PlatformFontPango::GetStyle() const {
255 return style_; 248 return style_;
256 } 249 }
257 250
258 std::string PlatformFontPango::GetFontName() const { 251 std::string PlatformFontPango::GetFontName() const {
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 // TODO(davemoore): Come up with a better solution. 385 // TODO(davemoore): Come up with a better solution.
393 // This is a hack, but without doing this the underlines 386 // This is a hack, but without doing this the underlines
394 // we get end up fuzzy. So we align to the midpoint of a pixel. 387 // we get end up fuzzy. So we align to the midpoint of a pixel.
395 underline_position_pixels_ /= 2; 388 underline_position_pixels_ /= 2;
396 389
397 underline_thickness_pixels_ = 390 underline_thickness_pixels_ =
398 pango_font_metrics_get_underline_thickness(pango_metrics) / 391 pango_font_metrics_get_underline_thickness(pango_metrics) /
399 PANGO_SCALE; 392 PANGO_SCALE;
400 393
401 // First get the Pango-based width (converting from Pango units to pixels). 394 // First get the Pango-based width (converting from Pango units to pixels).
402 double pango_width_pixels = 395 const double pango_width_pixels =
403 pango_font_metrics_get_approximate_char_width(pango_metrics) / 396 pango_font_metrics_get_approximate_char_width(pango_metrics) /
404 PANGO_SCALE; 397 PANGO_SCALE;
405 398
406 // Yes, this is how Microsoft recommends calculating the dialog unit 399 // Yes, this is how Microsoft recommends calculating the dialog unit
407 // conversions. 400 // conversions.
408 int text_width_pixels = GetStringWidth( 401 const int text_width_pixels = CanvasSkia::GetStringWidth(
409 ASCIIToUTF16("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); 402 ASCIIToUTF16("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"),
410 double dialog_units_pixels = (text_width_pixels / 26 + 1) / 2; 403 Font(this));
404 const double dialog_units_pixels = (text_width_pixels / 26 + 1) / 2;
411 average_width_pixels_ = std::min(pango_width_pixels, dialog_units_pixels); 405 average_width_pixels_ = std::min(pango_width_pixels, dialog_units_pixels);
412 pango_font_description_free(pango_desc); 406 pango_font_description_free(pango_desc);
413 } 407 }
414 } 408 }
415 409
416 410
417 double PlatformFontPango::GetAverageWidth() const { 411 double PlatformFontPango::GetAverageWidth() const {
418 const_cast<PlatformFontPango*>(this)->InitPangoMetrics(); 412 const_cast<PlatformFontPango*>(this)->InitPangoMetrics();
419 return average_width_pixels_; 413 return average_width_pixels_;
420 } 414 }
(...skipping 16 matching lines...) Expand all
437 return new PlatformFontPango(native_font); 431 return new PlatformFontPango(native_font);
438 } 432 }
439 433
440 // static 434 // static
441 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, 435 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name,
442 int font_size) { 436 int font_size) {
443 return new PlatformFontPango(font_name, font_size); 437 return new PlatformFontPango(font_name, font_size);
444 } 438 }
445 439
446 } // namespace gfx 440 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/platform_font_pango.h ('k') | ui/gfx/platform_font_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698