| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "gfx/font.h" | 5 #include "gfx/font.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 | 11 |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/win_util.h" | 14 #include "base/win_util.h" |
| 15 #include "gfx/canvas.h" | 15 #include "gfx/canvas_skia.h" |
| 16 | 16 |
| 17 namespace gfx { | 17 namespace gfx { |
| 18 | 18 |
| 19 // static | 19 // static |
| 20 Font::HFontRef* Font::base_font_ref_; | 20 Font::HFontRef* Font::base_font_ref_; |
| 21 | 21 |
| 22 // static | 22 // static |
| 23 Font::AdjustFontCallback Font::adjust_font_callback = NULL; | 23 Font::AdjustFontCallback Font::adjust_font_callback = NULL; |
| 24 Font::GetMinimumFontSizeCallback Font::get_minimum_font_size_callback = NULL; | 24 Font::GetMinimumFontSizeCallback Font::get_minimum_font_size_callback = NULL; |
| 25 | 25 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 font_info.lfUnderline = ((style & UNDERLINED) == UNDERLINED); | 164 font_info.lfUnderline = ((style & UNDERLINED) == UNDERLINED); |
| 165 font_info.lfItalic = ((style & ITALIC) == ITALIC); | 165 font_info.lfItalic = ((style & ITALIC) == ITALIC); |
| 166 font_info.lfWeight = (style & BOLD) ? FW_BOLD : FW_NORMAL; | 166 font_info.lfWeight = (style & BOLD) ? FW_BOLD : FW_NORMAL; |
| 167 | 167 |
| 168 HFONT hfont = CreateFontIndirect(&font_info); | 168 HFONT hfont = CreateFontIndirect(&font_info); |
| 169 return Font(CreateHFontRef(hfont)); | 169 return Font(CreateHFontRef(hfont)); |
| 170 } | 170 } |
| 171 | 171 |
| 172 int Font::GetStringWidth(const std::wstring& text) const { | 172 int Font::GetStringWidth(const std::wstring& text) const { |
| 173 int width = 0, height = 0; | 173 int width = 0, height = 0; |
| 174 Canvas::SizeStringInt(text, *this, &width, &height, gfx::Canvas::NO_ELLIPSIS); | 174 CanvasSkia::SizeStringInt(text, *this, &width, &height, |
| 175 gfx::Canvas::NO_ELLIPSIS); |
| 175 return width; | 176 return width; |
| 176 } | 177 } |
| 177 | 178 |
| 178 Font::HFontRef* Font::CreateHFontRef(HFONT font) { | 179 Font::HFontRef* Font::CreateHFontRef(HFONT font) { |
| 179 TEXTMETRIC font_metrics; | 180 TEXTMETRIC font_metrics; |
| 180 HDC screen_dc = GetDC(NULL); | 181 HDC screen_dc = GetDC(NULL); |
| 181 HFONT previous_font = static_cast<HFONT>(SelectObject(screen_dc, font)); | 182 HFONT previous_font = static_cast<HFONT>(SelectObject(screen_dc, font)); |
| 182 int last_map_mode = SetMapMode(screen_dc, MM_TEXT); | 183 int last_map_mode = SetMapMode(screen_dc, MM_TEXT); |
| 183 GetTextMetrics(screen_dc, &font_metrics); | 184 GetTextMetrics(screen_dc, &font_metrics); |
| 184 // Yes, this is how Microsoft recommends calculating the dialog unit | 185 // Yes, this is how Microsoft recommends calculating the dialog unit |
| (...skipping 21 matching lines...) Expand all Loading... |
| 206 } | 207 } |
| 207 if (font_metrics.tmWeight >= kTextMetricWeightBold) { | 208 if (font_metrics.tmWeight >= kTextMetricWeightBold) { |
| 208 style |= Font::BOLD; | 209 style |= Font::BOLD; |
| 209 } | 210 } |
| 210 | 211 |
| 211 return new HFontRef(font, height, baseline, ave_char_width, style, | 212 return new HFontRef(font, height, baseline, ave_char_width, style, |
| 212 dlu_base_x); | 213 dlu_base_x); |
| 213 } | 214 } |
| 214 | 215 |
| 215 } // namespace gfx | 216 } // namespace gfx |
| OLD | NEW |