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

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

Issue 23769011: Move a bunch of windows stuff from ui/base/win to ui/gfx/win (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moar bustage. Created 7 years, 3 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/font_smoothing_win.cc ('k') | ui/gfx/render_text.cc » ('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_win.h" 5 #include "ui/gfx/platform_font_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <math.h> 8 #include <math.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 #include <string> 11 #include <string>
12 12
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/strings/sys_string_conversions.h" 15 #include "base/strings/sys_string_conversions.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "base/win/scoped_hdc.h" 17 #include "base/win/scoped_hdc.h"
18 #include "base/win/scoped_select_object.h" 18 #include "base/win/scoped_select_object.h"
19 #include "base/win/win_util.h" 19 #include "base/win/win_util.h"
20 #include "ui/base/win/scoped_set_map_mode.h"
21 #include "ui/gfx/canvas.h" 20 #include "ui/gfx/canvas.h"
22 #include "ui/gfx/font.h" 21 #include "ui/gfx/font.h"
22 #include "ui/gfx/win/scoped_set_map_mode.h"
23 23
24 namespace { 24 namespace {
25 25
26 // If the tmWeight field of a TEXTMETRIC structure has a value >= this, the 26 // If the tmWeight field of a TEXTMETRIC structure has a value >= this, the
27 // font is bold. 27 // font is bold.
28 const int kTextMetricWeightBold = 700; 28 const int kTextMetricWeightBold = 700;
29 29
30 // Returns the minimum font size, using the minimum size callback, if set. 30 // Returns the minimum font size, using the minimum size callback, if set.
31 int GetMinimumFontSize() { 31 int GetMinimumFontSize() {
32 int min_font_size = 0; 32 int min_font_size = 0;
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 } 222 }
223 return base_font_ref_; 223 return base_font_ref_;
224 } 224 }
225 225
226 PlatformFontWin::HFontRef* PlatformFontWin::CreateHFontRef(HFONT font) { 226 PlatformFontWin::HFontRef* PlatformFontWin::CreateHFontRef(HFONT font) {
227 TEXTMETRIC font_metrics; 227 TEXTMETRIC font_metrics;
228 228
229 { 229 {
230 base::win::ScopedGetDC screen_dc(NULL); 230 base::win::ScopedGetDC screen_dc(NULL);
231 base::win::ScopedSelectObject scoped_font(screen_dc, font); 231 base::win::ScopedSelectObject scoped_font(screen_dc, font);
232 ui::ScopedSetMapMode mode(screen_dc, MM_TEXT); 232 gfx::ScopedSetMapMode mode(screen_dc, MM_TEXT);
233 GetTextMetrics(screen_dc, &font_metrics); 233 GetTextMetrics(screen_dc, &font_metrics);
234 } 234 }
235 235
236 const int height = std::max<int>(1, font_metrics.tmHeight); 236 const int height = std::max<int>(1, font_metrics.tmHeight);
237 const int baseline = std::max<int>(1, font_metrics.tmAscent); 237 const int baseline = std::max<int>(1, font_metrics.tmAscent);
238 const int ave_char_width = std::max<int>(1, font_metrics.tmAveCharWidth); 238 const int ave_char_width = std::max<int>(1, font_metrics.tmAveCharWidth);
239 const int font_size = 239 const int font_size =
240 std::max<int>(1, font_metrics.tmHeight - font_metrics.tmInternalLeading); 240 std::max<int>(1, font_metrics.tmHeight - font_metrics.tmInternalLeading);
241 int style = 0; 241 int style = 0;
242 if (font_metrics.tmItalic) 242 if (font_metrics.tmItalic)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 if (font_info.lfHeight < 0) 277 if (font_info.lfHeight < 0)
278 requested_font_size_ = -font_info.lfHeight; 278 requested_font_size_ = -font_info.lfHeight;
279 } 279 }
280 280
281 int PlatformFontWin::HFontRef::GetDluBaseX() { 281 int PlatformFontWin::HFontRef::GetDluBaseX() {
282 if (dlu_base_x_ != -1) 282 if (dlu_base_x_ != -1)
283 return dlu_base_x_; 283 return dlu_base_x_;
284 284
285 base::win::ScopedGetDC screen_dc(NULL); 285 base::win::ScopedGetDC screen_dc(NULL);
286 base::win::ScopedSelectObject font(screen_dc, hfont_); 286 base::win::ScopedSelectObject font(screen_dc, hfont_);
287 ui::ScopedSetMapMode mode(screen_dc, MM_TEXT); 287 gfx::ScopedSetMapMode mode(screen_dc, MM_TEXT);
288 288
289 // Yes, this is how Microsoft recommends calculating the dialog unit 289 // Yes, this is how Microsoft recommends calculating the dialog unit
290 // conversions. See: http://support.microsoft.com/kb/125681 290 // conversions. See: http://support.microsoft.com/kb/125681
291 SIZE ave_text_size; 291 SIZE ave_text_size;
292 GetTextExtentPoint32(screen_dc, 292 GetTextExtentPoint32(screen_dc,
293 L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 293 L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
294 52, &ave_text_size); 294 52, &ave_text_size);
295 dlu_base_x_ = (ave_text_size.cx / 26 + 1) / 2; 295 dlu_base_x_ = (ave_text_size.cx / 26 + 1) / 2;
296 296
297 DCHECK_NE(dlu_base_x_, -1); 297 DCHECK_NE(dlu_base_x_, -1);
(...skipping 17 matching lines...) Expand all
315 return new PlatformFontWin(native_font); 315 return new PlatformFontWin(native_font);
316 } 316 }
317 317
318 // static 318 // static
319 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, 319 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name,
320 int font_size) { 320 int font_size) {
321 return new PlatformFontWin(font_name, font_size); 321 return new PlatformFontWin(font_name, font_size);
322 } 322 }
323 323
324 } // namespace gfx 324 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/font_smoothing_win.cc ('k') | ui/gfx/render_text.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698