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 #include <ApplicationServices/ApplicationServices.h> | 7 #include <ApplicationServices/ApplicationServices.h> |
8 | 8 |
9 #include <cmath> | 9 #include <cmath> |
10 #include <utility> | 10 #include <utility> |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 } // namespace | 80 } // namespace |
81 | 81 |
82 namespace gfx { | 82 namespace gfx { |
83 | 83 |
84 RenderTextMac::RenderTextMac() : common_baseline_(0), runs_valid_(false) { | 84 RenderTextMac::RenderTextMac() : common_baseline_(0), runs_valid_(false) { |
85 } | 85 } |
86 | 86 |
87 RenderTextMac::~RenderTextMac() { | 87 RenderTextMac::~RenderTextMac() { |
88 } | 88 } |
89 | 89 |
90 base::i18n::TextDirection RenderTextMac::GetTextDirection() { | |
91 return base::i18n::LEFT_TO_RIGHT; | |
92 } | |
93 | |
94 Size RenderTextMac::GetStringSize() { | 90 Size RenderTextMac::GetStringSize() { |
95 EnsureLayout(); | 91 EnsureLayout(); |
96 return string_size_; | 92 return string_size_; |
97 } | 93 } |
98 | 94 |
99 int RenderTextMac::GetBaseline() { | 95 int RenderTextMac::GetBaseline() { |
100 EnsureLayout(); | 96 EnsureLayout(); |
101 return common_baseline_; | 97 return common_baseline_; |
102 } | 98 } |
103 | 99 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 CFDictionaryCreate(NULL, keys, values, arraysize(keys), NULL, | 172 CFDictionaryCreate(NULL, keys, values, arraysize(keys), NULL, |
177 &kCFTypeDictionaryValueCallBacks)); | 173 &kCFTypeDictionaryValueCallBacks)); |
178 | 174 |
179 base::mac::ScopedCFTypeRef<CFStringRef> cf_text( | 175 base::mac::ScopedCFTypeRef<CFStringRef> cf_text( |
180 base::SysUTF16ToCFStringRef(text())); | 176 base::SysUTF16ToCFStringRef(text())); |
181 base::mac::ScopedCFTypeRef<CFAttributedStringRef> attr_text( | 177 base::mac::ScopedCFTypeRef<CFAttributedStringRef> attr_text( |
182 CFAttributedStringCreate(NULL, cf_text, attributes)); | 178 CFAttributedStringCreate(NULL, cf_text, attributes)); |
183 base::mac::ScopedCFTypeRef<CFMutableAttributedStringRef> attr_text_mutable( | 179 base::mac::ScopedCFTypeRef<CFMutableAttributedStringRef> attr_text_mutable( |
184 CFAttributedStringCreateMutableCopy(NULL, 0, attr_text)); | 180 CFAttributedStringCreateMutableCopy(NULL, 0, attr_text)); |
185 | 181 |
| 182 // TODO(asvitkine|msw): Respect GetTextDirection(), which may not match the |
| 183 // natural text direction. See kCTTypesetterOptionForcedEmbeddingLevel, etc. |
| 184 |
186 ApplyStyles(attr_text_mutable, ct_font); | 185 ApplyStyles(attr_text_mutable, ct_font); |
187 line_.reset(CTLineCreateWithAttributedString(attr_text_mutable)); | 186 line_.reset(CTLineCreateWithAttributedString(attr_text_mutable)); |
188 | 187 |
189 CGFloat ascent = 0; | 188 CGFloat ascent = 0; |
190 CGFloat descent = 0; | 189 CGFloat descent = 0; |
191 CGFloat leading = 0; | 190 CGFloat leading = 0; |
192 // TODO(asvitkine): Consider using CTLineGetBoundsWithOptions() on 10.8+. | 191 // TODO(asvitkine): Consider using CTLineGetBoundsWithOptions() on 10.8+. |
193 double width = CTLineGetTypographicBounds(line_, &ascent, &descent, &leading); | 192 double width = CTLineGetTypographicBounds(line_, &ascent, &descent, &leading); |
194 string_size_ = Size(width, ascent + descent + leading); | 193 string_size_ = Size(width, ascent + descent + leading); |
195 common_baseline_ = ascent; | 194 common_baseline_ = ascent; |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 run_origin.offset(run_width, 0); | 368 run_origin.offset(run_width, 0); |
370 } | 369 } |
371 runs_valid_ = true; | 370 runs_valid_ = true; |
372 } | 371 } |
373 | 372 |
374 RenderText* RenderText::CreateInstance() { | 373 RenderText* RenderText::CreateInstance() { |
375 return new RenderTextMac; | 374 return new RenderTextMac; |
376 } | 375 } |
377 | 376 |
378 } // namespace gfx | 377 } // namespace gfx |
OLD | NEW |