OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "platform/text/Hyphenation.h" | 5 #include "platform/text/Hyphenation.h" |
6 | 6 |
| 7 #include "wtf/RetainPtr.h" |
| 8 #include "wtf/text/StringView.h" |
| 9 |
7 namespace blink { | 10 namespace blink { |
8 | 11 |
9 PassRefPtr<Hyphenation> Hyphenation::platformGetHyphenation(const AtomicString&) | 12 class HyphenationCF : public Hyphenation { |
| 13 public: |
| 14 HyphenationCF(RetainPtr<CFLocaleRef>& localeCF) |
| 15 : m_localeCF(localeCF) |
| 16 { |
| 17 DCHECK(m_localeCF); |
| 18 } |
| 19 |
| 20 size_t lastHyphenLocation(const StringView& text, size_t beforeIndex) const
override |
| 21 { |
| 22 CFIndex result = CFStringGetHyphenationLocationBeforeIndex( |
| 23 text.toString()->createCFString().get(), beforeIndex, |
| 24 CFRangeMake(0, text.length()), 0, m_localeCF.get(), 0); |
| 25 return result == kCFNotFound ? 0 : result; |
| 26 } |
| 27 |
| 28 private: |
| 29 RetainPtr<CFLocaleRef> m_localeCF; |
| 30 }; |
| 31 |
| 32 PassRefPtr<Hyphenation> Hyphenation::platformGetHyphenation(const AtomicString&
locale) |
10 { | 33 { |
11 return nullptr; | 34 RetainPtr<CFStringRef> localeCFString = locale.impl()->createCFString(); |
| 35 RetainPtr<CFLocaleRef> localeCF = adoptCF(CFLocaleCreate(kCFAllocatorDefault
, localeCFString.get())); |
| 36 if (!CFStringIsHyphenationAvailableForLocale(localeCF.get())) |
| 37 return nullptr; |
| 38 return adoptRef(new HyphenationCF(localeCF)); |
12 } | 39 } |
13 | 40 |
14 } // namespace blink | 41 } // namespace blink |
OLD | NEW |