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

Unified Diff: ui/gfx/render_text_mac.mm

Issue 1819753003: Allow various font weights in gfx. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Alexei's issues Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: ui/gfx/render_text_mac.mm
diff --git a/ui/gfx/render_text_mac.mm b/ui/gfx/render_text_mac.mm
index 3a6d01b9f3ad84bf581e59276e0670b11e6124be..3b4b2383432e6de1f77dde5aa1e44534c57418be 100644
--- a/ui/gfx/render_text_mac.mm
+++ b/ui/gfx/render_text_mac.mm
@@ -65,8 +65,11 @@ namespace gfx {
namespace internal {
-skia::RefPtr<SkTypeface> CreateSkiaTypeface(const gfx::Font& font, int style) {
- gfx::Font font_with_style = font.Derive(0, style);
+skia::RefPtr<SkTypeface> CreateSkiaTypeface(const gfx::Font& font,
Alexei Svitkine (slow) 2016/04/05 16:38:53 Remove gfx::
+ bool italic,
+ gfx::Font::Weight weight) {
Alexei Svitkine (slow) 2016/04/05 16:38:53 Remove gfx::
+ const Font::FontStyle style = italic ? Font::ITALIC : Font::NORMAL;
+ gfx::Font font_with_style = font.Derive(0, style, weight);
if (!font_with_style.GetNativeFont())
return nullptr;
return skia::AdoptRef(SkCreateTypefaceFromCTFont(
@@ -211,13 +214,12 @@ void RenderTextMac::DrawVisualText(internal::SkiaTextRenderer* renderer) {
CTFontRef ct_font = static_cast<CTFontRef>(run.font.GetNativeFont());
renderer->SetTextSize(CTFontGetSize(ct_font));
- int font_style = Font::NORMAL;
+ // TODO(mboc): Apply font weights.
+ Font::Weight font_weight = Font::Weight::NORMAL;
CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(ct_font);
if (traits & kCTFontBoldTrait)
- font_style |= Font::BOLD;
- if (traits & kCTFontItalicTrait)
- font_style |= Font::ITALIC;
- renderer->SetFontWithStyle(run.font, font_style);
+ font_weight = Font::Weight::BOLD;
+ renderer->SetFont(run.font, traits & kCTFontItalicTrait, font_weight);
renderer->DrawPosText(&run.glyph_positions[0], &run.glyphs[0],
run.glyphs.size());
@@ -308,7 +310,7 @@ base::ScopedCFTypeRef<CFMutableArrayRef> RenderTextMac::ApplyStyles(
CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks));
// https://developer.apple.com/library/mac/#documentation/Carbon/Reference/CoreText_StringAttributes_Ref/Reference/reference.html
- internal::StyleIterator style(colors(), baselines(), styles());
+ internal::StyleIterator style(colors(), baselines(), weights(), styles());
const size_t layout_text_length = CFAttributedStringGetLength(attr_string);
for (size_t i = 0, end = 0; i < layout_text_length; i = end) {
end = TextIndexToGivenTextIndex(text, style.GetRange().end());
@@ -328,8 +330,10 @@ base::ScopedCFTypeRef<CFMutableArrayRef> RenderTextMac::ApplyStyles(
CFArrayAppendValue(attributes, underline_value);
}
- const int traits = (style.style(BOLD) ? kCTFontBoldTrait : 0) |
- (style.style(ITALIC) ? kCTFontItalicTrait : 0);
+ // TODO(mboc): Apply font weights other than bold below.
+ const int traits =
+ (style.style(ITALIC) ? kCTFontItalicTrait : 0) |
+ (style.weight() >= Font::Weight::BOLD ? kCTFontBoldTrait : 0);
if (traits != 0) {
base::ScopedCFTypeRef<CTFontRef> styled_font =
CopyFontWithSymbolicTraits(font, traits);

Powered by Google App Engine
This is Rietveld 408576698