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

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

Issue 1927003004: Mac: Introduce "StaticCast" variants of base::mac::FooCastStrict, which do not typecheck in Release (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase 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 unified diff | Download patch
« base/mac/foundation_util.mm ('K') | « base/mac/foundation_util.mm ('k') | no next file » | 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 #import <AppKit/AppKit.h> 7 #import <AppKit/AppKit.h>
8 #include <ApplicationServices/ApplicationServices.h> 8 #include <ApplicationServices/ApplicationServices.h>
9 #include <CoreText/CoreText.h> 9 #include <CoreText/CoreText.h>
10 10
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 // Skia will draw glyphs with respect to the baseline. 362 // Skia will draw glyphs with respect to the baseline.
363 text_offset += Vector2d(0, common_baseline_); 363 text_offset += Vector2d(0, common_baseline_);
364 364
365 const SkScalar x = SkIntToScalar(text_offset.x()); 365 const SkScalar x = SkIntToScalar(text_offset.x());
366 const SkScalar y = SkIntToScalar(text_offset.y()); 366 const SkScalar y = SkIntToScalar(text_offset.y());
367 SkPoint run_origin = SkPoint::Make(x, y); 367 SkPoint run_origin = SkPoint::Make(x, y);
368 368
369 const CFRange empty_cf_range = CFRangeMake(0, 0); 369 const CFRange empty_cf_range = CFRangeMake(0, 0);
370 for (CFIndex i = 0; i < ct_runs_count; ++i) { 370 for (CFIndex i = 0; i < ct_runs_count; ++i) {
371 CTRunRef ct_run = 371 CTRunRef ct_run =
372 base::mac::CFCast<CTRunRef>(CFArrayGetValueAtIndex(ct_runs, i)); 372 base::mac::CFCastStrict<CTRunRef>(CFArrayGetValueAtIndex(ct_runs, i));
373 const size_t glyph_count = CTRunGetGlyphCount(ct_run); 373 const size_t glyph_count = CTRunGetGlyphCount(ct_run);
374 const double run_width = 374 const double run_width =
375 CTRunGetTypographicBounds(ct_run, empty_cf_range, NULL, NULL, NULL); 375 CTRunGetTypographicBounds(ct_run, empty_cf_range, NULL, NULL, NULL);
376 if (glyph_count == 0) { 376 if (glyph_count == 0) {
377 run_origin.offset(run_width, 0); 377 run_origin.offset(run_width, 0);
378 continue; 378 continue;
379 } 379 }
380 380
381 runs_.emplace_back(); 381 runs_.emplace_back();
382 TextRun* run = &runs_.back(); 382 TextRun* run = &runs_.back();
(...skipping 21 matching lines...) Expand all
404 } 404 }
405 for (size_t glyph = 0; glyph < glyph_count; glyph++) { 405 for (size_t glyph = 0; glyph < glyph_count; glyph++) {
406 SkPoint* point = &run->glyph_positions[glyph]; 406 SkPoint* point = &run->glyph_positions[glyph];
407 point->set(x + SkDoubleToScalar(positions_ptr[glyph].x), 407 point->set(x + SkDoubleToScalar(positions_ptr[glyph].x),
408 y + SkDoubleToScalar(positions_ptr[glyph].y)); 408 y + SkDoubleToScalar(positions_ptr[glyph].y));
409 } 409 }
410 410
411 // TODO(asvitkine): Style boundaries are not necessarily per-run. Handle 411 // TODO(asvitkine): Style boundaries are not necessarily per-run. Handle
412 // this better. Also, support strike and diagonal_strike. 412 // this better. Also, support strike and diagonal_strike.
413 CFDictionaryRef attributes = CTRunGetAttributes(ct_run); 413 CFDictionaryRef attributes = CTRunGetAttributes(ct_run);
414 CTFontRef ct_font = base::mac::GetValueFromDictionary<CTFontRef>( 414 CTFontRef ct_font = base::mac::CFCastStrict<CTFontRef>(
415 attributes, kCTFontAttributeName); 415 CFDictionaryGetValue(attributes, kCTFontAttributeName));
416 run->ct_font.reset(ct_font, base::scoped_policy::RETAIN); 416 run->ct_font.reset(ct_font, base::scoped_policy::RETAIN);
417 run->typeface.reset(SkCreateTypefaceFromCTFont(ct_font)); 417 run->typeface.reset(SkCreateTypefaceFromCTFont(ct_font));
418 418
419 const CGColorRef foreground = base::mac::GetValueFromDictionary<CGColorRef>( 419 const CGColorRef foreground = base::mac::CFCastStrict<CGColorRef>(
420 attributes, kCTForegroundColorAttributeName); 420 CFDictionaryGetValue(attributes, kCTForegroundColorAttributeName));
421 if (foreground) 421 if (foreground)
422 run->foreground = skia::CGColorRefToSkColor(foreground); 422 run->foreground = skia::CGColorRefToSkColor(foreground);
423 423
424 const CFNumberRef underline = 424 const CFNumberRef underline = base::mac::CFCastStrict<CFNumberRef>(
425 base::mac::GetValueFromDictionary<CFNumberRef>( 425 CFDictionaryGetValue(attributes, kCTUnderlineStyleAttributeName));
426 attributes, kCTUnderlineStyleAttributeName);
427 CTUnderlineStyle value = kCTUnderlineStyleNone; 426 CTUnderlineStyle value = kCTUnderlineStyleNone;
428 if (underline && CFNumberGetValue(underline, kCFNumberSInt32Type, &value)) 427 if (underline && CFNumberGetValue(underline, kCFNumberSInt32Type, &value))
429 run->underline = (value == kCTUnderlineStyleSingle); 428 run->underline = (value == kCTUnderlineStyleSingle);
430 429
431 run_origin.offset(run_width, 0); 430 run_origin.offset(run_width, 0);
432 } 431 }
433 runs_valid_ = true; 432 runs_valid_ = true;
434 } 433 }
435 434
436 void RenderTextMac::InvalidateStyle() { 435 void RenderTextMac::InvalidateStyle() {
437 line_.reset(); 436 line_.reset();
438 attributes_.reset(); 437 attributes_.reset();
439 runs_.clear(); 438 runs_.clear();
440 runs_valid_ = false; 439 runs_valid_ = false;
441 } 440 }
442 441
443 } // namespace gfx 442 } // namespace gfx
OLDNEW
« base/mac/foundation_util.mm ('K') | « base/mac/foundation_util.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698