OLD | NEW |
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 <dwrite.h> | 8 #include <dwrite.h> |
9 #include <limits.h> | 9 #include <limits.h> |
10 #include <math.h> | 10 #include <math.h> |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 return lf_height < 0 ? -min_font_size : min_font_size; | 60 return lf_height < 0 ? -min_font_size : min_font_size; |
61 } else { | 61 } else { |
62 return lf_height; | 62 return lf_height; |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
66 // Sets style properties on |font_info| based on |font_style|. | 66 // Sets style properties on |font_info| based on |font_style|. |
67 void SetLogFontStyle(int font_style, LOGFONT* font_info) { | 67 void SetLogFontStyle(int font_style, LOGFONT* font_info) { |
68 font_info->lfUnderline = (font_style & gfx::Font::UNDERLINE) != 0; | 68 font_info->lfUnderline = (font_style & gfx::Font::UNDERLINE) != 0; |
69 font_info->lfItalic = (font_style & gfx::Font::ITALIC) != 0; | 69 font_info->lfItalic = (font_style & gfx::Font::ITALIC) != 0; |
70 font_info->lfWeight = (font_style & gfx::Font::BOLD) ? FW_BOLD : FW_NORMAL; | 70 } |
| 71 |
| 72 gfx::Font::Weight ToGfxFontWeight(int weight) { |
| 73 return static_cast<gfx::Font::Weight>(weight); |
71 } | 74 } |
72 | 75 |
73 // Returns the family name for the |IDWriteFont| interface passed in. | 76 // Returns the family name for the |IDWriteFont| interface passed in. |
74 // The family name is returned in the |family_name_ret| parameter. | 77 // The family name is returned in the |family_name_ret| parameter. |
75 // Returns S_OK on success. | 78 // Returns S_OK on success. |
76 // TODO(ananta) | 79 // TODO(ananta) |
77 // Remove the CHECKs in this function once this stabilizes on the field. | 80 // Remove the CHECKs in this function once this stabilizes on the field. |
78 HRESULT GetFamilyNameFromDirectWriteFont(IDWriteFont* dwrite_font, | 81 HRESULT GetFamilyNameFromDirectWriteFont(IDWriteFont* dwrite_font, |
79 base::string16* family_name_ret) { | 82 base::string16* family_name_ret) { |
80 base::win::ScopedComPtr<IDWriteFontFamily> font_family; | 83 base::win::ScopedComPtr<IDWriteFontFamily> font_family; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 return hr; | 154 return hr; |
152 } | 155 } |
153 | 156 |
154 // Returns a matching IDWriteFont for the |font_info| passed in. If we fail | 157 // Returns a matching IDWriteFont for the |font_info| passed in. If we fail |
155 // to find a matching font, then we return the IDWriteFont corresponding to | 158 // to find a matching font, then we return the IDWriteFont corresponding to |
156 // the default font on the system. | 159 // the default font on the system. |
157 // Returns S_OK on success. | 160 // Returns S_OK on success. |
158 // The contents of the LOGFONT pointer |font_info| may be modified on | 161 // The contents of the LOGFONT pointer |font_info| may be modified on |
159 // return. | 162 // return. |
160 HRESULT GetMatchingDirectWriteFont(LOGFONT* font_info, | 163 HRESULT GetMatchingDirectWriteFont(LOGFONT* font_info, |
161 int font_style, | 164 bool italic, |
162 IDWriteFactory* factory, | 165 IDWriteFactory* factory, |
163 IDWriteFont** dwrite_font) { | 166 IDWriteFont** dwrite_font) { |
164 // First try the GDI compat route to get a matching DirectWrite font. | 167 // First try the GDI compat route to get a matching DirectWrite font. |
165 // If that succeeds then we are good. If that fails then try and find a | 168 // If that succeeds then we are good. If that fails then try and find a |
166 // match from the DirectWrite font collection. | 169 // match from the DirectWrite font collection. |
167 HRESULT hr = FindDirectWriteFontForLOGFONT(factory, font_info, dwrite_font); | 170 HRESULT hr = FindDirectWriteFontForLOGFONT(factory, font_info, dwrite_font); |
168 if (SUCCEEDED(hr)) | 171 if (SUCCEEDED(hr)) |
169 return hr; | 172 return hr; |
170 | 173 |
171 // Get a matching font from the system font collection exposed by | 174 // Get a matching font from the system font collection exposed by |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 // If we fail to find a matching font, then fallback to the first font in | 233 // If we fail to find a matching font, then fallback to the first font in |
231 // the list. This is what skia does as well. | 234 // the list. This is what skia does as well. |
232 hr = font_collection->GetFontFamily(0, font_family.Receive()); | 235 hr = font_collection->GetFontFamily(0, font_family.Receive()); |
233 } | 236 } |
234 | 237 |
235 if (FAILED(hr)) { | 238 if (FAILED(hr)) { |
236 CHECK(false); | 239 CHECK(false); |
237 return hr; | 240 return hr; |
238 } | 241 } |
239 | 242 |
240 DWRITE_FONT_WEIGHT weight = (font_style & SkTypeface::kBold) | 243 DWRITE_FONT_WEIGHT weight = |
241 ? DWRITE_FONT_WEIGHT_BOLD | 244 static_cast<DWRITE_FONT_WEIGHT>(font_info->lfWeight); |
242 : DWRITE_FONT_WEIGHT_NORMAL; | |
243 DWRITE_FONT_STRETCH stretch = DWRITE_FONT_STRETCH_NORMAL; | 245 DWRITE_FONT_STRETCH stretch = DWRITE_FONT_STRETCH_NORMAL; |
244 DWRITE_FONT_STYLE italic = (font_style & SkTypeface::kItalic) | 246 DWRITE_FONT_STYLE style = |
245 ? DWRITE_FONT_STYLE_ITALIC | 247 (italic) ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL; |
246 : DWRITE_FONT_STYLE_NORMAL; | |
247 | 248 |
248 // The IDWriteFontFamily::GetFirstMatchingFont call fails on certain machines | 249 // The IDWriteFontFamily::GetFirstMatchingFont call fails on certain machines |
249 // for fonts like MS UI Gothic, Segoe UI, etc. It is not clear why these | 250 // for fonts like MS UI Gothic, Segoe UI, etc. It is not clear why these |
250 // fonts could be accessible to GDI and not to DirectWrite. | 251 // fonts could be accessible to GDI and not to DirectWrite. |
251 // The code below adds some debug fields to help track down these failures. | 252 // The code below adds some debug fields to help track down these failures. |
252 // 1. We get the matching font list for the font attributes passed in. | 253 // 1. We get the matching font list for the font attributes passed in. |
253 // 2. We get the font count in the family with a debug alias variable. | 254 // 2. We get the font count in the family with a debug alias variable. |
254 // 3. If GetFirstMatchingFont fails then we CHECK as before. | 255 // 3. If GetFirstMatchingFont fails then we CHECK as before. |
255 // Next step would be to remove the CHECKs in this function and fallback to | 256 // Next step would be to remove the CHECKs in this function and fallback to |
256 // GDI. | 257 // GDI. |
257 // http://crbug.com/434425 | 258 // http://crbug.com/434425 |
258 // TODO(ananta) | 259 // TODO(ananta) |
259 // Remove the GetMatchingFonts and related code here once we get to a stable | 260 // Remove the GetMatchingFonts and related code here once we get to a stable |
260 // state in canary. | 261 // state in canary. |
261 base::win::ScopedComPtr<IDWriteFontList> matching_font_list; | 262 base::win::ScopedComPtr<IDWriteFontList> matching_font_list; |
262 hr = font_family->GetMatchingFonts(weight, stretch, italic, | 263 hr = font_family->GetMatchingFonts(weight, stretch, style, |
263 matching_font_list.Receive()); | 264 matching_font_list.Receive()); |
264 uint32_t matching_font_count = 0; | 265 uint32_t matching_font_count = 0; |
265 if (SUCCEEDED(hr)) | 266 if (SUCCEEDED(hr)) |
266 matching_font_count = matching_font_list->GetFontCount(); | 267 matching_font_count = matching_font_list->GetFontCount(); |
267 | 268 |
268 hr = font_family->GetFirstMatchingFont(weight, stretch, italic, | 269 hr = font_family->GetFirstMatchingFont(weight, stretch, style, dwrite_font); |
269 dwrite_font); | |
270 if (FAILED(hr)) { | 270 if (FAILED(hr)) { |
271 base::debug::Alias(&matching_font_count); | 271 base::debug::Alias(&matching_font_count); |
272 CHECK(false); | 272 CHECK(false); |
273 } | 273 } |
274 | 274 |
275 base::string16 font_name; | 275 base::string16 font_name; |
276 GetFamilyNameFromDirectWriteFont(*dwrite_font, &font_name); | 276 GetFamilyNameFromDirectWriteFont(*dwrite_font, &font_name); |
277 wcscpy_s(font_info->lfFaceName, arraysize(font_info->lfFaceName), | 277 wcscpy_s(font_info->lfFaceName, arraysize(font_info->lfFaceName), |
278 font_name.c_str()); | 278 font_name.c_str()); |
279 return hr; | 279 return hr; |
(...skipping 22 matching lines...) Expand all Loading... |
302 | 302 |
303 PlatformFontWin::PlatformFontWin(NativeFont native_font) { | 303 PlatformFontWin::PlatformFontWin(NativeFont native_font) { |
304 InitWithCopyOfHFONT(native_font); | 304 InitWithCopyOfHFONT(native_font); |
305 } | 305 } |
306 | 306 |
307 PlatformFontWin::PlatformFontWin(const std::string& font_name, | 307 PlatformFontWin::PlatformFontWin(const std::string& font_name, |
308 int font_size) { | 308 int font_size) { |
309 InitWithFontNameAndSize(font_name, font_size); | 309 InitWithFontNameAndSize(font_name, font_size); |
310 } | 310 } |
311 | 311 |
312 Font PlatformFontWin::DeriveFontWithHeight(int height, int style) { | |
313 DCHECK_GE(height, 0); | |
314 | |
315 // Create a font with a height near that of the target height. | |
316 LOGFONT font_info; | |
317 GetObject(GetNativeFont(), sizeof(LOGFONT), &font_info); | |
318 font_info.lfHeight = height; | |
319 SetLogFontStyle(style, &font_info); | |
320 | |
321 HFONT hfont = CreateFontIndirect(&font_info); | |
322 Font font(new PlatformFontWin(CreateHFontRef(hfont))); | |
323 | |
324 // Respect the minimum font size constraint. | |
325 const int min_font_size = GetMinimumFontSize(); | |
326 | |
327 // Used to avoid shrinking the font and expanding it. | |
328 bool ran_shrink_loop = false; | |
329 | |
330 // Iterate to find the largest font with a height <= |height|. | |
331 while ((font.GetHeight() > height) && | |
332 (font.GetFontSize() >= min_font_size)) { | |
333 ran_shrink_loop = true; | |
334 Font derived_font = font.Derive(-1, style); | |
335 // Break the loop if the derived font is too small or hasn't shrunk at all. | |
336 if ((derived_font.GetFontSize() < min_font_size) || | |
337 ((derived_font.GetFontSize() == font.GetFontSize()) && | |
338 (derived_font.GetHeight() == font.GetHeight()))) | |
339 break; | |
340 font = derived_font; | |
341 } | |
342 | |
343 while ((!ran_shrink_loop && font.GetHeight() <= height) || | |
344 (font.GetFontSize() < min_font_size)) { | |
345 Font derived_font = font.Derive(1, style); | |
346 // Break the loop if the derived font is too large or hasn't grown at all. | |
347 if (((derived_font.GetHeight() > height) && | |
348 (font.GetFontSize() >= min_font_size)) || | |
349 ((derived_font.GetFontSize() == font.GetFontSize()) && | |
350 (derived_font.GetHeight() == font.GetHeight()))) | |
351 break; | |
352 font = derived_font; | |
353 } | |
354 return font; | |
355 } | |
356 | |
357 //////////////////////////////////////////////////////////////////////////////// | 312 //////////////////////////////////////////////////////////////////////////////// |
358 // PlatformFontWin, PlatformFont implementation: | 313 // PlatformFontWin, PlatformFont implementation: |
359 | 314 |
360 Font PlatformFontWin::DeriveFont(int size_delta, int style) const { | 315 Font PlatformFontWin::DeriveFont(int size_delta, |
| 316 int style, |
| 317 gfx::Font::Weight weight) const { |
361 LOGFONT font_info; | 318 LOGFONT font_info; |
362 GetObject(GetNativeFont(), sizeof(LOGFONT), &font_info); | 319 GetObject(GetNativeFont(), sizeof(LOGFONT), &font_info); |
363 const int requested_font_size = font_ref_->requested_font_size(); | 320 const int requested_font_size = font_ref_->requested_font_size(); |
364 font_info.lfHeight = AdjustFontSize(-requested_font_size, size_delta); | 321 font_info.lfHeight = AdjustFontSize(-requested_font_size, size_delta); |
| 322 font_info.lfWeight = static_cast<LONG>(weight); |
365 SetLogFontStyle(style, &font_info); | 323 SetLogFontStyle(style, &font_info); |
366 | 324 |
367 HFONT hfont = CreateFontIndirect(&font_info); | 325 HFONT hfont = CreateFontIndirect(&font_info); |
368 return Font(new PlatformFontWin(CreateHFontRef(hfont))); | 326 return Font(new PlatformFontWin(CreateHFontRef(hfont))); |
369 } | 327 } |
370 | 328 |
371 int PlatformFontWin::GetHeight() { | 329 int PlatformFontWin::GetHeight() { |
372 return font_ref_->height(); | 330 return font_ref_->height(); |
373 } | 331 } |
374 | 332 |
| 333 gfx::Font::Weight PlatformFontWin::GetWeight() const { |
| 334 return font_ref_->weight(); |
| 335 } |
| 336 |
375 int PlatformFontWin::GetBaseline() { | 337 int PlatformFontWin::GetBaseline() { |
376 return font_ref_->baseline(); | 338 return font_ref_->baseline(); |
377 } | 339 } |
378 | 340 |
379 int PlatformFontWin::GetCapHeight() { | 341 int PlatformFontWin::GetCapHeight() { |
380 return font_ref_->cap_height(); | 342 return font_ref_->cap_height(); |
381 } | 343 } |
382 | 344 |
383 int PlatformFontWin::GetExpectedTextWidth(int length) { | 345 int PlatformFontWin::GetExpectedTextWidth(int length) { |
384 return length * std::min(font_ref_->GetDluBaseX(), | 346 return length * std::min(font_ref_->GetDluBaseX(), |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 const int cap_height = | 485 const int cap_height = |
524 std::max<int>(1, font_metrics.tmAscent - font_metrics.tmInternalLeading); | 486 std::max<int>(1, font_metrics.tmAscent - font_metrics.tmInternalLeading); |
525 const int ave_char_width = std::max<int>(1, font_metrics.tmAveCharWidth); | 487 const int ave_char_width = std::max<int>(1, font_metrics.tmAveCharWidth); |
526 const int font_size = | 488 const int font_size = |
527 std::max<int>(1, font_metrics.tmHeight - font_metrics.tmInternalLeading); | 489 std::max<int>(1, font_metrics.tmHeight - font_metrics.tmInternalLeading); |
528 int style = 0; | 490 int style = 0; |
529 if (font_metrics.tmItalic) | 491 if (font_metrics.tmItalic) |
530 style |= Font::ITALIC; | 492 style |= Font::ITALIC; |
531 if (font_metrics.tmUnderlined) | 493 if (font_metrics.tmUnderlined) |
532 style |= Font::UNDERLINE; | 494 style |= Font::UNDERLINE; |
533 if (font_metrics.tmWeight >= kTextMetricWeightBold) | |
534 style |= Font::BOLD; | |
535 | 495 |
536 return new HFontRef(font, font_size, height, baseline, cap_height, | 496 return new HFontRef(font, font_size, height, baseline, cap_height, |
537 ave_char_width, style); | 497 ave_char_width, ToGfxFontWeight(font_metrics.tmWeight), |
| 498 style); |
538 } | 499 } |
539 | 500 |
540 // static | 501 // static |
541 PlatformFontWin::HFontRef* PlatformFontWin::CreateHFontRefFromSkia( | 502 PlatformFontWin::HFontRef* PlatformFontWin::CreateHFontRefFromSkia( |
542 HFONT gdi_font, | 503 HFONT gdi_font, |
543 const TEXTMETRIC& font_metrics) { | 504 const TEXTMETRIC& font_metrics) { |
544 LOGFONT font_info = {0}; | 505 LOGFONT font_info = {0}; |
545 GetObject(gdi_font, sizeof(LOGFONT), &font_info); | 506 GetObject(gdi_font, sizeof(LOGFONT), &font_info); |
546 | 507 |
547 // If the font height is passed in as 0, assume the height to be -1 to ensure | 508 // If the font height is passed in as 0, assume the height to be -1 to ensure |
548 // that we return the metrics for a 1 point font. | 509 // that we return the metrics for a 1 point font. |
549 // If the font height is positive it represents the rasterized font's cell | 510 // If the font height is positive it represents the rasterized font's cell |
550 // height. Calculate the actual height accordingly. | 511 // height. Calculate the actual height accordingly. |
551 if (font_info.lfHeight > 0) { | 512 if (font_info.lfHeight > 0) { |
552 font_info.lfHeight = | 513 font_info.lfHeight = |
553 font_metrics.tmInternalLeading - font_metrics.tmHeight; | 514 font_metrics.tmInternalLeading - font_metrics.tmHeight; |
554 } else if (font_info.lfHeight == 0) { | 515 } else if (font_info.lfHeight == 0) { |
555 font_info.lfHeight = -1; | 516 font_info.lfHeight = -1; |
556 } | 517 } |
557 | 518 |
558 int skia_style = SkTypeface::kNormal; | 519 const bool italic = font_info.lfItalic != 0; |
559 if (font_info.lfWeight >= FW_SEMIBOLD && | |
560 font_info.lfWeight <= FW_ULTRABOLD) { | |
561 skia_style |= SkTypeface::kBold; | |
562 } | |
563 if (font_info.lfItalic) | |
564 skia_style |= SkTypeface::kItalic; | |
565 | 520 |
566 // Skia does not return all values we need for font metrics. For e.g. | 521 // Skia does not return all values we need for font metrics. For e.g. |
567 // the cap height which indicates the height of capital letters is not | 522 // the cap height which indicates the height of capital letters is not |
568 // returned even though it is returned by DirectWrite. | 523 // returned even though it is returned by DirectWrite. |
569 // TODO(ananta) | 524 // TODO(ananta) |
570 // Fix SkScalerContext_win_dw.cpp to return all metrics we need from | 525 // Fix SkScalerContext_win_dw.cpp to return all metrics we need from |
571 // DirectWrite and remove the code here which retrieves metrics from | 526 // DirectWrite and remove the code here which retrieves metrics from |
572 // DirectWrite to calculate the cap height. | 527 // DirectWrite to calculate the cap height. |
573 base::win::ScopedComPtr<IDWriteFont> dwrite_font; | 528 base::win::ScopedComPtr<IDWriteFont> dwrite_font; |
574 HRESULT hr = GetMatchingDirectWriteFont(&font_info, | 529 HRESULT hr = GetMatchingDirectWriteFont( |
575 skia_style, | 530 &font_info, italic, direct_write_factory_, dwrite_font.Receive()); |
576 direct_write_factory_, | |
577 dwrite_font.Receive()); | |
578 if (FAILED(hr)) { | 531 if (FAILED(hr)) { |
579 CHECK(false); | 532 CHECK(false); |
580 return nullptr; | 533 return nullptr; |
581 } | 534 } |
582 | 535 |
583 DWRITE_FONT_METRICS dwrite_font_metrics = {0}; | 536 DWRITE_FONT_METRICS dwrite_font_metrics = {0}; |
584 dwrite_font->GetMetrics(&dwrite_font_metrics); | 537 dwrite_font->GetMetrics(&dwrite_font_metrics); |
585 | 538 |
586 skia::RefPtr<SkTypeface> skia_face = skia::AdoptRef( | 539 SkFontStyle skia_font_style(font_info.lfWeight, SkFontStyle::kNormal_Width, |
587 SkTypeface::CreateFromName( | 540 font_info.lfItalic ? SkFontStyle::kItalic_Slant |
588 base::SysWideToUTF8(font_info.lfFaceName).c_str(), | 541 : SkFontStyle::kUpright_Slant); |
589 static_cast<SkTypeface::Style>(skia_style))); | 542 |
| 543 skia::RefPtr<SkTypeface> skia_face = |
| 544 skia::AdoptRef(SkTypeface::CreateFromName( |
| 545 base::SysWideToUTF8(font_info.lfFaceName).c_str(), skia_font_style)); |
590 | 546 |
591 gfx::FontRenderParams font_params = | 547 gfx::FontRenderParams font_params = |
592 gfx::GetFontRenderParams(gfx::FontRenderParamsQuery(), nullptr); | 548 gfx::GetFontRenderParams(gfx::FontRenderParamsQuery(), nullptr); |
593 SkFontHost::SetSubpixelOrder( | 549 SkFontHost::SetSubpixelOrder( |
594 gfx::FontRenderParams::SubpixelRenderingToSkiaLCDOrder( | 550 gfx::FontRenderParams::SubpixelRenderingToSkiaLCDOrder( |
595 font_params.subpixel_rendering)); | 551 font_params.subpixel_rendering)); |
596 SkFontHost::SetSubpixelOrientation( | 552 SkFontHost::SetSubpixelOrientation( |
597 gfx::FontRenderParams::SubpixelRenderingToSkiaLCDOrientation( | 553 gfx::FontRenderParams::SubpixelRenderingToSkiaLCDOrientation( |
598 font_params.subpixel_rendering)); | 554 font_params.subpixel_rendering)); |
599 | 555 |
(...skipping 16 matching lines...) Expand all Loading... |
616 // The metrics retrieved from skia don't have the average character width. In | 572 // The metrics retrieved from skia don't have the average character width. In |
617 // any case if we get the average character width from skia then use that or | 573 // any case if we get the average character width from skia then use that or |
618 // the average character width in the TEXTMETRIC structure. | 574 // the average character width in the TEXTMETRIC structure. |
619 // TODO(ananta): Investigate whether it is possible to retrieve this value | 575 // TODO(ananta): Investigate whether it is possible to retrieve this value |
620 // from DirectWrite. | 576 // from DirectWrite. |
621 const int ave_char_width = | 577 const int ave_char_width = |
622 skia_metrics.fAvgCharWidth == 0 ? font_metrics.tmAveCharWidth | 578 skia_metrics.fAvgCharWidth == 0 ? font_metrics.tmAveCharWidth |
623 : skia_metrics.fAvgCharWidth; | 579 : skia_metrics.fAvgCharWidth; |
624 | 580 |
625 int style = 0; | 581 int style = 0; |
626 if (skia_style & SkTypeface::kItalic) | 582 if (italic) |
627 style |= Font::ITALIC; | 583 style |= Font::ITALIC; |
628 if (font_info.lfUnderline) | 584 if (font_info.lfUnderline) |
629 style |= Font::UNDERLINE; | 585 style |= Font::UNDERLINE; |
630 if (font_info.lfWeight >= kTextMetricWeightBold) | |
631 style |= Font::BOLD; | |
632 | 586 |
633 // DirectWrite may have substituted the GDI font name with a fallback | 587 // DirectWrite may have substituted the GDI font name with a fallback |
634 // font. Ensure that it is updated here. | 588 // font. Ensure that it is updated here. |
635 DeleteObject(gdi_font); | 589 DeleteObject(gdi_font); |
636 gdi_font = ::CreateFontIndirect(&font_info); | 590 gdi_font = ::CreateFontIndirect(&font_info); |
637 return new HFontRef(gdi_font, -font_info.lfHeight, height, baseline, | 591 return new HFontRef(gdi_font, -font_info.lfHeight, height, baseline, |
638 cap_height, ave_char_width, style); | 592 cap_height, ave_char_width, |
| 593 ToGfxFontWeight(font_metrics.tmWeight), style); |
639 } | 594 } |
640 | 595 |
641 PlatformFontWin::PlatformFontWin(HFontRef* hfont_ref) : font_ref_(hfont_ref) { | 596 PlatformFontWin::PlatformFontWin(HFontRef* hfont_ref) : font_ref_(hfont_ref) { |
642 } | 597 } |
643 | 598 |
644 PlatformFontWin::~PlatformFontWin() { | 599 PlatformFontWin::~PlatformFontWin() { |
645 } | 600 } |
646 | 601 |
647 //////////////////////////////////////////////////////////////////////////////// | 602 //////////////////////////////////////////////////////////////////////////////// |
648 // PlatformFontWin::HFontRef: | 603 // PlatformFontWin::HFontRef: |
649 | 604 |
650 PlatformFontWin::HFontRef::HFontRef(HFONT hfont, | 605 PlatformFontWin::HFontRef::HFontRef(HFONT hfont, |
651 int font_size, | 606 int font_size, |
652 int height, | 607 int height, |
653 int baseline, | 608 int baseline, |
654 int cap_height, | 609 int cap_height, |
655 int ave_char_width, | 610 int ave_char_width, |
| 611 gfx::Font::Weight weight, |
656 int style) | 612 int style) |
657 : hfont_(hfont), | 613 : hfont_(hfont), |
658 font_size_(font_size), | 614 font_size_(font_size), |
659 height_(height), | 615 height_(height), |
660 baseline_(baseline), | 616 baseline_(baseline), |
661 cap_height_(cap_height), | 617 cap_height_(cap_height), |
662 ave_char_width_(ave_char_width), | 618 ave_char_width_(ave_char_width), |
| 619 weight_(weight), |
663 style_(style), | 620 style_(style), |
664 dlu_base_x_(-1), | 621 dlu_base_x_(-1), |
665 requested_font_size_(font_size) { | 622 requested_font_size_(font_size) { |
666 DLOG_ASSERT(hfont); | 623 DLOG_ASSERT(hfont); |
667 | 624 |
668 LOGFONT font_info; | 625 LOGFONT font_info; |
669 GetObject(hfont_, sizeof(LOGFONT), &font_info); | 626 GetObject(hfont_, sizeof(LOGFONT), &font_info); |
670 font_name_ = base::UTF16ToUTF8(base::string16(font_info.lfFaceName)); | 627 font_name_ = base::UTF16ToUTF8(base::string16(font_info.lfFaceName)); |
671 | 628 |
672 // Retrieve the font size from the GetTextMetrics API instead of referencing | 629 // Retrieve the font size from the GetTextMetrics API instead of referencing |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 return new PlatformFontWin(native_font); | 681 return new PlatformFontWin(native_font); |
725 } | 682 } |
726 | 683 |
727 // static | 684 // static |
728 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, | 685 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, |
729 int font_size) { | 686 int font_size) { |
730 return new PlatformFontWin(font_name, font_size); | 687 return new PlatformFontWin(font_name, font_size); |
731 } | 688 } |
732 | 689 |
733 } // namespace gfx | 690 } // namespace gfx |
OLD | NEW |