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

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: Add a lost comment and modify a render text unittest to not test black because of test env font con… Created 4 years, 7 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
« no previous file with comments | « ui/gfx/render_text_harfbuzz.cc ('k') | ui/gfx/render_text_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/render_text_mac.mm
diff --git a/ui/gfx/render_text_mac.mm b/ui/gfx/render_text_mac.mm
index 584f08d49ea2e2ef6fba1ec6cd999b19c74a3f31..a6e28c25cd8c67a2f304a31c3848d267dd68723a 100644
--- a/ui/gfx/render_text_mac.mm
+++ b/ui/gfx/render_text_mac.mm
@@ -67,8 +67,11 @@ namespace gfx {
namespace internal {
// Note: this is only used by RenderTextHarfbuzz.
-sk_sp<SkTypeface> CreateSkiaTypeface(const gfx::Font& font, int style) {
- gfx::Font font_with_style = font.Derive(0, style);
+sk_sp<SkTypeface> CreateSkiaTypeface(const Font& font,
+ bool italic,
+ Font::Weight weight) {
+ const Font::FontStyle style = italic ? Font::ITALIC : Font::NORMAL;
+ Font font_with_style = font.Derive(0, style, weight);
if (!font_with_style.GetNativeFont())
return nullptr;
@@ -119,7 +122,7 @@ std::vector<RenderText::FontSpan> RenderTextMac::GetFontSpansForTesting() {
const CFRange cf_range = CTRunGetStringRange(runs_[i].ct_run);
const Range range(cf_range.location, cf_range.location + cf_range.length);
spans.push_back(RenderText::FontSpan(
- gfx::Font(base::mac::CFToNSCast(runs_[i].ct_font.get())), range));
+ Font(base::mac::CFToNSCast(runs_[i].ct_font.get())), range));
}
return spans;
@@ -250,7 +253,7 @@ float RenderTextMac::GetLayoutTextWidth() {
return GetCTLineSize(line.get(), &baseline).width();
}
-gfx::SizeF RenderTextMac::GetCTLineSize(CTLineRef line, SkScalar* baseline) {
+SizeF RenderTextMac::GetCTLineSize(CTLineRef line, SkScalar* baseline) {
CGFloat ascent = 0;
CGFloat descent = 0;
CGFloat leading = 0;
@@ -311,7 +314,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());
@@ -331,8 +334,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);
« no previous file with comments | « ui/gfx/render_text_harfbuzz.cc ('k') | ui/gfx/render_text_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698