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

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: Add StaticCast variants 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
« no previous file with comments | « base/mac/foundation_util.h ('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 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 // Skia will draw glyphs with respect to the baseline. 365 // Skia will draw glyphs with respect to the baseline.
366 text_offset += Vector2d(0, common_baseline_); 366 text_offset += Vector2d(0, common_baseline_);
367 367
368 const SkScalar x = SkIntToScalar(text_offset.x()); 368 const SkScalar x = SkIntToScalar(text_offset.x());
369 const SkScalar y = SkIntToScalar(text_offset.y()); 369 const SkScalar y = SkIntToScalar(text_offset.y());
370 SkPoint run_origin = SkPoint::Make(x, y); 370 SkPoint run_origin = SkPoint::Make(x, y);
371 371
372 const CFRange empty_cf_range = CFRangeMake(0, 0); 372 const CFRange empty_cf_range = CFRangeMake(0, 0);
373 for (CFIndex i = 0; i < ct_runs_count; ++i) { 373 for (CFIndex i = 0; i < ct_runs_count; ++i) {
374 CTRunRef ct_run = 374 CTRunRef ct_run =
375 base::mac::CFCast<CTRunRef>(CFArrayGetValueAtIndex(ct_runs, i)); 375 base::mac::CFStaticCast<CTRunRef>(CFArrayGetValueAtIndex(ct_runs, i));
376 const size_t glyph_count = CTRunGetGlyphCount(ct_run); 376 const size_t glyph_count = CTRunGetGlyphCount(ct_run);
377 const double run_width = 377 const double run_width =
378 CTRunGetTypographicBounds(ct_run, empty_cf_range, NULL, NULL, NULL); 378 CTRunGetTypographicBounds(ct_run, empty_cf_range, NULL, NULL, NULL);
379 if (glyph_count == 0) { 379 if (glyph_count == 0) {
380 run_origin.offset(run_width, 0); 380 run_origin.offset(run_width, 0);
381 continue; 381 continue;
382 } 382 }
383 383
384 runs_.emplace_back(); 384 runs_.emplace_back();
385 TextRun* run = &runs_.back(); 385 TextRun* run = &runs_.back();
(...skipping 21 matching lines...) Expand all
407 } 407 }
408 for (size_t glyph = 0; glyph < glyph_count; glyph++) { 408 for (size_t glyph = 0; glyph < glyph_count; glyph++) {
409 SkPoint* point = &run->glyph_positions[glyph]; 409 SkPoint* point = &run->glyph_positions[glyph];
410 point->set(x + SkDoubleToScalar(positions_ptr[glyph].x), 410 point->set(x + SkDoubleToScalar(positions_ptr[glyph].x),
411 y + SkDoubleToScalar(positions_ptr[glyph].y)); 411 y + SkDoubleToScalar(positions_ptr[glyph].y));
412 } 412 }
413 413
414 // TODO(asvitkine): Style boundaries are not necessarily per-run. Handle 414 // TODO(asvitkine): Style boundaries are not necessarily per-run. Handle
415 // this better. Also, support strike and diagonal_strike. 415 // this better. Also, support strike and diagonal_strike.
416 CFDictionaryRef attributes = CTRunGetAttributes(ct_run); 416 CFDictionaryRef attributes = CTRunGetAttributes(ct_run);
417 CTFontRef ct_font = base::mac::GetValueFromDictionary<CTFontRef>( 417 CTFontRef ct_font = base::mac::CFStaticCast<CTFontRef>(
418 attributes, kCTFontAttributeName); 418 CFDictionaryGetValue(attributes, kCTFontAttributeName));
419 run->ct_font.reset(ct_font, base::scoped_policy::RETAIN); 419 run->ct_font.reset(ct_font, base::scoped_policy::RETAIN);
420 run->typeface.reset(SkCreateTypefaceFromCTFont(ct_font)); 420 run->typeface.reset(SkCreateTypefaceFromCTFont(ct_font));
421 421
422 const CGColorRef foreground = base::mac::GetValueFromDictionary<CGColorRef>( 422 const CGColorRef foreground = base::mac::CFStaticCast<CGColorRef>(
423 attributes, kCTForegroundColorAttributeName); 423 CFDictionaryGetValue(attributes, kCTForegroundColorAttributeName));
424 if (foreground) 424 if (foreground)
425 run->foreground = skia::CGColorRefToSkColor(foreground); 425 run->foreground = skia::CGColorRefToSkColor(foreground);
426 426
427 const CFNumberRef underline = 427 const CFNumberRef underline = base::mac::CFStaticCast<CFNumberRef>(
428 base::mac::GetValueFromDictionary<CFNumberRef>( 428 CFDictionaryGetValue(attributes, kCTUnderlineStyleAttributeName));
429 attributes, kCTUnderlineStyleAttributeName);
430 CTUnderlineStyle value = kCTUnderlineStyleNone; 429 CTUnderlineStyle value = kCTUnderlineStyleNone;
431 if (underline && CFNumberGetValue(underline, kCFNumberSInt32Type, &value)) 430 if (underline && CFNumberGetValue(underline, kCFNumberSInt32Type, &value))
432 run->underline = (value == kCTUnderlineStyleSingle); 431 run->underline = (value == kCTUnderlineStyleSingle);
433 432
434 run_origin.offset(run_width, 0); 433 run_origin.offset(run_width, 0);
435 } 434 }
436 runs_valid_ = true; 435 runs_valid_ = true;
437 } 436 }
438 437
439 void RenderTextMac::InvalidateStyle() { 438 void RenderTextMac::InvalidateStyle() {
440 line_.reset(); 439 line_.reset();
441 attributes_.reset(); 440 attributes_.reset();
442 runs_.clear(); 441 runs_.clear();
443 runs_valid_ = false; 442 runs_valid_ = false;
444 } 443 }
445 444
446 } // namespace gfx 445 } // namespace gfx
OLDNEW
« no previous file with comments | « base/mac/foundation_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698