| OLD | NEW |
| 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 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 renderer->SetForegroundColor(run.foreground); | 253 renderer->SetForegroundColor(run.foreground); |
| 254 renderer->SetTextSize(CTFontGetSize(run.ct_font)); | 254 renderer->SetTextSize(CTFontGetSize(run.ct_font)); |
| 255 | 255 |
| 256 // The painter adds its own ref. So don't |release()| it from the ref ptr in | 256 // The painter adds its own ref. So don't |release()| it from the ref ptr in |
| 257 // TextRun. | 257 // TextRun. |
| 258 renderer->SetTypeface(run.typeface); | 258 renderer->SetTypeface(run.typeface); |
| 259 | 259 |
| 260 renderer->DrawPosText(&run.glyph_positions[0], &run.glyphs[0], | 260 renderer->DrawPosText(&run.glyph_positions[0], &run.glyphs[0], |
| 261 run.glyphs.size()); | 261 run.glyphs.size()); |
| 262 renderer->DrawDecorations(run.origin.x(), run.origin.y(), run.width, | 262 renderer->DrawDecorations(run.origin.x(), run.origin.y(), run.width, |
| 263 run.underline, run.strike, run.diagonal_strike); | 263 run.underline, run.strike); |
| 264 } | 264 } |
| 265 | |
| 266 renderer->EndDiagonalStrike(); | |
| 267 } | 265 } |
| 268 | 266 |
| 269 RenderTextMac::TextRun::TextRun() | 267 RenderTextMac::TextRun::TextRun() |
| 270 : ct_run(NULL), | 268 : ct_run(NULL), |
| 271 origin(SkPoint::Make(0, 0)), | 269 origin(SkPoint::Make(0, 0)), |
| 272 width(0), | 270 width(0), |
| 273 foreground(SK_ColorBLACK), | 271 foreground(SK_ColorBLACK), |
| 274 underline(false), | 272 underline(false), |
| 275 strike(false), | 273 strike(false) {} |
| 276 diagonal_strike(false) {} | |
| 277 | 274 |
| 278 RenderTextMac::TextRun::TextRun(TextRun&& other) = default; | 275 RenderTextMac::TextRun::TextRun(TextRun&& other) = default; |
| 279 | 276 |
| 280 RenderTextMac::TextRun::~TextRun() {} | 277 RenderTextMac::TextRun::~TextRun() {} |
| 281 | 278 |
| 282 float RenderTextMac::GetLayoutTextWidth() { | 279 float RenderTextMac::GetLayoutTextWidth() { |
| 283 base::ScopedCFTypeRef<CFMutableArrayRef> attributes_owner; | 280 base::ScopedCFTypeRef<CFMutableArrayRef> attributes_owner; |
| 284 base::ScopedCFTypeRef<CTLineRef> line( | 281 base::ScopedCFTypeRef<CTLineRef> line( |
| 285 EnsureLayoutInternal(layout_text(), &attributes_owner)); | 282 EnsureLayoutInternal(layout_text(), &attributes_owner)); |
| 286 SkScalar baseline; | 283 SkScalar baseline; |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 CTRunGetPositions(ct_run, empty_cf_range, &positions[0]); | 434 CTRunGetPositions(ct_run, empty_cf_range, &positions[0]); |
| 438 positions_ptr = &positions[0]; | 435 positions_ptr = &positions[0]; |
| 439 } | 436 } |
| 440 for (size_t glyph = 0; glyph < glyph_count; glyph++) { | 437 for (size_t glyph = 0; glyph < glyph_count; glyph++) { |
| 441 SkPoint* point = &run->glyph_positions[glyph]; | 438 SkPoint* point = &run->glyph_positions[glyph]; |
| 442 point->set(x + SkDoubleToScalar(positions_ptr[glyph].x), | 439 point->set(x + SkDoubleToScalar(positions_ptr[glyph].x), |
| 443 y + SkDoubleToScalar(positions_ptr[glyph].y)); | 440 y + SkDoubleToScalar(positions_ptr[glyph].y)); |
| 444 } | 441 } |
| 445 | 442 |
| 446 // TODO(asvitkine): Style boundaries are not necessarily per-run. Handle | 443 // TODO(asvitkine): Style boundaries are not necessarily per-run. Handle |
| 447 // this better. Also, support strike and diagonal_strike. | 444 // this better. Also, support strike. |
| 448 CFDictionaryRef attributes = CTRunGetAttributes(ct_run); | 445 CFDictionaryRef attributes = CTRunGetAttributes(ct_run); |
| 449 CTFontRef ct_font = base::mac::GetValueFromDictionary<CTFontRef>( | 446 CTFontRef ct_font = base::mac::GetValueFromDictionary<CTFontRef>( |
| 450 attributes, kCTFontAttributeName); | 447 attributes, kCTFontAttributeName); |
| 451 run->ct_font.reset(ct_font, base::scoped_policy::RETAIN); | 448 run->ct_font.reset(ct_font, base::scoped_policy::RETAIN); |
| 452 run->typeface.reset(SkCreateTypefaceFromCTFont(ct_font)); | 449 run->typeface.reset(SkCreateTypefaceFromCTFont(ct_font)); |
| 453 | 450 |
| 454 const CGColorRef foreground = base::mac::GetValueFromDictionary<CGColorRef>( | 451 const CGColorRef foreground = base::mac::GetValueFromDictionary<CGColorRef>( |
| 455 attributes, kCTForegroundColorAttributeName); | 452 attributes, kCTForegroundColorAttributeName); |
| 456 if (foreground) | 453 if (foreground) |
| 457 run->foreground = skia::CGColorRefToSkColor(foreground); | 454 run->foreground = skia::CGColorRefToSkColor(foreground); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 480 // TODO(karandeepb): This is not invoked on any codepath currently. Style the | 477 // TODO(karandeepb): This is not invoked on any codepath currently. Style the |
| 481 // returned text if need be. | 478 // returned text if need be. |
| 482 if (obscured()) | 479 if (obscured()) |
| 483 return false; | 480 return false; |
| 484 | 481 |
| 485 decorated_text->text = GetTextFromRange(range); | 482 decorated_text->text = GetTextFromRange(range); |
| 486 return true; | 483 return true; |
| 487 } | 484 } |
| 488 | 485 |
| 489 } // namespace gfx | 486 } // namespace gfx |
| OLD | NEW |