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

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

Issue 377413002: linux: Round font sizes when going from points to pixels. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gfx/pango_util.h ('k') | no next file » | 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/pango_util.h" 5 #include "ui/gfx/pango_util.h"
6 6
7 #include <cairo/cairo.h> 7 #include <cairo/cairo.h>
8 #include <pango/pango.h> 8 #include <pango/pango.h>
9 #include <pango/pangocairo.h> 9 #include <pango/pangocairo.h>
10 #include <string> 10 #include <string>
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 } 223 }
224 224
225 pango_layout_set_text(layout, utf8.data(), utf8.size()); 225 pango_layout_set_text(layout, utf8.data(), utf8.size());
226 } 226 }
227 227
228 ScopedPangoFontDescription desc(pango_font_description_from_string( 228 ScopedPangoFontDescription desc(pango_font_description_from_string(
229 font_list.GetFontDescriptionString().c_str())); 229 font_list.GetFontDescriptionString().c_str()));
230 pango_layout_set_font_description(layout, desc.get()); 230 pango_layout_set_font_description(layout, desc.get());
231 } 231 }
232 232
233 size_t GetPangoFontSizeInPixels(PangoFontDescription* pango_font) { 233 int GetPangoFontSizeInPixels(PangoFontDescription* pango_font) {
234 size_t size_in_pixels = pango_font_description_get_size(pango_font); 234 // If the size is absolute, then it's in Pango units rather than points. There
235 if (pango_font_description_get_size_is_absolute(pango_font)) { 235 // are PANGO_SCALE Pango units in a device unit (pixel).
236 // If the size is absolute, then it's in Pango units rather than points. 236 if (pango_font_description_get_size_is_absolute(pango_font))
237 // There are PANGO_SCALE Pango units in a device unit (pixel). 237 return pango_font_description_get_size(pango_font) / PANGO_SCALE;
238 size_in_pixels /= PANGO_SCALE; 238
239 } else { 239 // Otherwise, we need to convert from points.
240 // Otherwise, we need to convert from points. 240 return static_cast<int>(GetPixelsInPoint() *
241 size_in_pixels = size_in_pixels * GetPixelsInPoint() / PANGO_SCALE; 241 pango_font_description_get_size(pango_font) / PANGO_SCALE + 0.5);
242 }
243 return size_in_pixels;
244 } 242 }
245 243
246 PangoFontMetrics* GetPangoFontMetrics(PangoFontDescription* desc) { 244 PangoFontMetrics* GetPangoFontMetrics(PangoFontDescription* desc) {
247 static std::map<int, PangoFontMetrics*>* desc_to_metrics = NULL; 245 static std::map<int, PangoFontMetrics*>* desc_to_metrics = NULL;
248 static PangoContext* context = NULL; 246 static PangoContext* context = NULL;
249 247
250 if (!context) { 248 if (!context) {
251 context = GetPangoContext(); 249 context = GetPangoContext();
252 pango_context_set_language(context, pango_language_get_default()); 250 pango_context_set_language(context, pango_language_get_default());
253 } 251 }
254 252
255 if (!desc_to_metrics) 253 if (!desc_to_metrics)
256 desc_to_metrics = new std::map<int, PangoFontMetrics*>(); 254 desc_to_metrics = new std::map<int, PangoFontMetrics*>();
257 255
258 const int desc_hash = pango_font_description_hash(desc); 256 const int desc_hash = pango_font_description_hash(desc);
259 std::map<int, PangoFontMetrics*>::iterator i = 257 std::map<int, PangoFontMetrics*>::iterator i =
260 desc_to_metrics->find(desc_hash); 258 desc_to_metrics->find(desc_hash);
261 259
262 if (i == desc_to_metrics->end()) { 260 if (i == desc_to_metrics->end()) {
263 PangoFontMetrics* metrics = pango_context_get_metrics(context, desc, NULL); 261 PangoFontMetrics* metrics = pango_context_get_metrics(context, desc, NULL);
264 desc_to_metrics->insert(std::make_pair(desc_hash, metrics)); 262 desc_to_metrics->insert(std::make_pair(desc_hash, metrics));
265 return metrics; 263 return metrics;
266 } 264 }
267 return i->second; 265 return i->second;
268 } 266 }
269 267
270 } // namespace gfx 268 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/pango_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698