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

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

Issue 16917011: mac: Replace base::mac::ScopedCFTypeRef with base::ScopedCFTypeRef. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: with fixed off-by-1 in git-clang-format Created 7 years, 6 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/render_text_mac.h ('k') | ui/shell_dialogs/select_file_dialog_mac.mm » ('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/render_text_mac.h" 5 #include "ui/gfx/render_text_mac.h"
6 6
7 #include <ApplicationServices/ApplicationServices.h> 7 #include <ApplicationServices/ApplicationServices.h>
8 8
9 #include <cmath> 9 #include <cmath>
10 #include <utility> 10 #include <utility>
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 runs_valid_ = false; 100 runs_valid_ = false;
101 } 101 }
102 102
103 void RenderTextMac::EnsureLayout() { 103 void RenderTextMac::EnsureLayout() {
104 if (line_.get()) 104 if (line_.get())
105 return; 105 return;
106 runs_.clear(); 106 runs_.clear();
107 runs_valid_ = false; 107 runs_valid_ = false;
108 108
109 const Font& font = GetFont(); 109 const Font& font = GetFont();
110 base::mac::ScopedCFTypeRef<CFStringRef> font_name_cf_string( 110 base::ScopedCFTypeRef<CFStringRef> font_name_cf_string(
111 base::SysUTF8ToCFStringRef(font.GetFontName())); 111 base::SysUTF8ToCFStringRef(font.GetFontName()));
112 base::mac::ScopedCFTypeRef<CTFontRef> ct_font( 112 base::ScopedCFTypeRef<CTFontRef> ct_font(
113 CTFontCreateWithName(font_name_cf_string, font.GetFontSize(), NULL)); 113 CTFontCreateWithName(font_name_cf_string, font.GetFontSize(), NULL));
114 114
115 const void* keys[] = { kCTFontAttributeName }; 115 const void* keys[] = { kCTFontAttributeName };
116 const void* values[] = { ct_font }; 116 const void* values[] = { ct_font };
117 base::mac::ScopedCFTypeRef<CFDictionaryRef> attributes( 117 base::ScopedCFTypeRef<CFDictionaryRef> attributes(
118 CFDictionaryCreate(NULL, keys, values, arraysize(keys), NULL, 118 CFDictionaryCreate(NULL,
119 keys,
120 values,
121 arraysize(keys),
122 NULL,
119 &kCFTypeDictionaryValueCallBacks)); 123 &kCFTypeDictionaryValueCallBacks));
120 124
121 base::mac::ScopedCFTypeRef<CFStringRef> cf_text( 125 base::ScopedCFTypeRef<CFStringRef> cf_text(
122 base::SysUTF16ToCFStringRef(text())); 126 base::SysUTF16ToCFStringRef(text()));
123 base::mac::ScopedCFTypeRef<CFAttributedStringRef> attr_text( 127 base::ScopedCFTypeRef<CFAttributedStringRef> attr_text(
124 CFAttributedStringCreate(NULL, cf_text, attributes)); 128 CFAttributedStringCreate(NULL, cf_text, attributes));
125 base::mac::ScopedCFTypeRef<CFMutableAttributedStringRef> attr_text_mutable( 129 base::ScopedCFTypeRef<CFMutableAttributedStringRef> attr_text_mutable(
126 CFAttributedStringCreateMutableCopy(NULL, 0, attr_text)); 130 CFAttributedStringCreateMutableCopy(NULL, 0, attr_text));
127 131
128 // TODO(asvitkine|msw): Respect GetTextDirection(), which may not match the 132 // TODO(asvitkine|msw): Respect GetTextDirection(), which may not match the
129 // natural text direction. See kCTTypesetterOptionForcedEmbeddingLevel, etc. 133 // natural text direction. See kCTTypesetterOptionForcedEmbeddingLevel, etc.
130 134
131 ApplyStyles(attr_text_mutable, ct_font); 135 ApplyStyles(attr_text_mutable, ct_font);
132 line_.reset(CTLineCreateWithAttributedString(attr_text_mutable)); 136 line_.reset(CTLineCreateWithAttributedString(attr_text_mutable));
133 137
134 CGFloat ascent = 0; 138 CGFloat ascent = 0;
135 CGFloat descent = 0; 139 CGFloat descent = 0;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 // attribute objects do not leak, they are saved to |attributes_|. 190 // attribute objects do not leak, they are saved to |attributes_|.
187 // Clear the attributes storage. 191 // Clear the attributes storage.
188 attributes_.reset(CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks)); 192 attributes_.reset(CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks));
189 193
190 // https://developer.apple.com/library/mac/#documentation/Carbon/Reference/Cor eText_StringAttributes_Ref/Reference/reference.html 194 // https://developer.apple.com/library/mac/#documentation/Carbon/Reference/Cor eText_StringAttributes_Ref/Reference/reference.html
191 internal::StyleIterator style(colors(), styles()); 195 internal::StyleIterator style(colors(), styles());
192 const size_t layout_text_length = GetLayoutText().length(); 196 const size_t layout_text_length = GetLayoutText().length();
193 for (size_t i = 0, end = 0; i < layout_text_length; i = end) { 197 for (size_t i = 0, end = 0; i < layout_text_length; i = end) {
194 end = TextIndexToLayoutIndex(style.GetRange().end()); 198 end = TextIndexToLayoutIndex(style.GetRange().end());
195 const CFRange range = CFRangeMake(i, end - i); 199 const CFRange range = CFRangeMake(i, end - i);
196 base::mac::ScopedCFTypeRef<CGColorRef> foreground( 200 base::ScopedCFTypeRef<CGColorRef> foreground(
197 gfx::CGColorCreateFromSkColor(style.color())); 201 gfx::CGColorCreateFromSkColor(style.color()));
198 CFAttributedStringSetAttribute(attr_string, range, 202 CFAttributedStringSetAttribute(attr_string, range,
199 kCTForegroundColorAttributeName, foreground); 203 kCTForegroundColorAttributeName, foreground);
200 CFArrayAppendValue(attributes_, foreground); 204 CFArrayAppendValue(attributes_, foreground);
201 205
202 if (style.style(UNDERLINE)) { 206 if (style.style(UNDERLINE)) {
203 CTUnderlineStyle value = kCTUnderlineStyleSingle; 207 CTUnderlineStyle value = kCTUnderlineStyleSingle;
204 base::mac::ScopedCFTypeRef<CFNumberRef> underline_value( 208 base::ScopedCFTypeRef<CFNumberRef> underline_value(
205 CFNumberCreate(NULL, kCFNumberSInt32Type, &value)); 209 CFNumberCreate(NULL, kCFNumberSInt32Type, &value));
206 CFAttributedStringSetAttribute(attr_string, range, 210 CFAttributedStringSetAttribute(attr_string, range,
207 kCTUnderlineStyleAttributeName, 211 kCTUnderlineStyleAttributeName,
208 underline_value); 212 underline_value);
209 CFArrayAppendValue(attributes_, underline_value); 213 CFArrayAppendValue(attributes_, underline_value);
210 } 214 }
211 215
212 const int traits = (style.style(BOLD) ? kCTFontBoldTrait : 0) | 216 const int traits = (style.style(BOLD) ? kCTFontBoldTrait : 0) |
213 (style.style(ITALIC) ? kCTFontItalicTrait : 0); 217 (style.style(ITALIC) ? kCTFontItalicTrait : 0);
214 if (traits != 0) { 218 if (traits != 0) {
215 base::mac::ScopedCFTypeRef<CTFontRef> styled_font( 219 base::ScopedCFTypeRef<CTFontRef> styled_font(
216 CTFontCreateCopyWithSymbolicTraits(font, 0.0, NULL, traits, traits)); 220 CTFontCreateCopyWithSymbolicTraits(font, 0.0, NULL, traits, traits));
217 // TODO(asvitkine): Handle |styled_font| == NULL case better. 221 // TODO(asvitkine): Handle |styled_font| == NULL case better.
218 if (styled_font) { 222 if (styled_font) {
219 CFAttributedStringSetAttribute(attr_string, range, kCTFontAttributeName, 223 CFAttributedStringSetAttribute(attr_string, range, kCTFontAttributeName,
220 styled_font); 224 styled_font);
221 CFArrayAppendValue(attributes_, styled_font); 225 CFArrayAppendValue(attributes_, styled_font);
222 } 226 }
223 } 227 }
224 228
225 style.UpdatePosition(LayoutIndexToTextIndex(end)); 229 style.UpdatePosition(LayoutIndexToTextIndex(end));
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 point->set(x + SkDoubleToScalar(positions_ptr[glyph].x), 290 point->set(x + SkDoubleToScalar(positions_ptr[glyph].x),
287 y + SkDoubleToScalar(positions_ptr[glyph].y)); 291 y + SkDoubleToScalar(positions_ptr[glyph].y));
288 } 292 }
289 293
290 // TODO(asvitkine): Style boundaries are not necessarily per-run. Handle 294 // TODO(asvitkine): Style boundaries are not necessarily per-run. Handle
291 // this better. Also, support strike and diagonal_strike. 295 // this better. Also, support strike and diagonal_strike.
292 CFDictionaryRef attributes = CTRunGetAttributes(ct_run); 296 CFDictionaryRef attributes = CTRunGetAttributes(ct_run);
293 CTFontRef ct_font = 297 CTFontRef ct_font =
294 base::mac::GetValueFromDictionary<CTFontRef>(attributes, 298 base::mac::GetValueFromDictionary<CTFontRef>(attributes,
295 kCTFontAttributeName); 299 kCTFontAttributeName);
296 base::mac::ScopedCFTypeRef<CFStringRef> font_name_ref( 300 base::ScopedCFTypeRef<CFStringRef> font_name_ref(
297 CTFontCopyFamilyName(ct_font)); 301 CTFontCopyFamilyName(ct_font));
298 run->font_name = base::SysCFStringRefToUTF8(font_name_ref); 302 run->font_name = base::SysCFStringRefToUTF8(font_name_ref);
299 run->text_size = CTFontGetSize(ct_font); 303 run->text_size = CTFontGetSize(ct_font);
300 304
301 CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(ct_font); 305 CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(ct_font);
302 if (traits & kCTFontBoldTrait) 306 if (traits & kCTFontBoldTrait)
303 run->font_style |= Font::BOLD; 307 run->font_style |= Font::BOLD;
304 if (traits & kCTFontItalicTrait) 308 if (traits & kCTFontItalicTrait)
305 run->font_style |= Font::ITALIC; 309 run->font_style |= Font::ITALIC;
306 310
(...skipping 13 matching lines...) Expand all
320 run_origin.offset(run_width, 0); 324 run_origin.offset(run_width, 0);
321 } 325 }
322 runs_valid_ = true; 326 runs_valid_ = true;
323 } 327 }
324 328
325 RenderText* RenderText::CreateInstance() { 329 RenderText* RenderText::CreateInstance() {
326 return new RenderTextMac; 330 return new RenderTextMac;
327 } 331 }
328 332
329 } // namespace gfx 333 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/render_text_mac.h ('k') | ui/shell_dialogs/select_file_dialog_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698