| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #ifndef FontDataRange_h | 26 #ifndef UnicodeRangeSet_h |
| 27 #define FontDataRange_h | 27 #define UnicodeRangeSet_h |
| 28 | 28 |
| 29 #include "platform/fonts/FontData.h" | 29 #include "platform/PlatformExport.h" |
| 30 #include "platform/fonts/SimpleFontData.h" | 30 #include "platform/fonts/FontDataRange.h" |
| 31 #include "wtf/Allocator.h" | 31 #include "wtf/Allocator.h" |
| 32 #include "wtf/text/CharacterNames.h" | 32 #include "wtf/text/Unicode.h" |
| 33 | 33 |
| 34 namespace blink { | 34 namespace blink { |
| 35 | 35 |
| 36 class SimpleFontData; | 36 struct PLATFORM_EXPORT UnicodeRange { |
| 37 | |
| 38 struct FontDataRange { | |
| 39 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 37 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
| 40 explicit FontDataRange(PassRefPtr<SimpleFontData> fontData) | 38 UnicodeRange(UChar32 from, UChar32 to) |
| 41 : m_from(0) | |
| 42 , m_to(kMaxCodepoint) | |
| 43 , m_fontData(fontData) | |
| 44 { | |
| 45 } | |
| 46 | |
| 47 FontDataRange() | |
| 48 : m_from(0) | |
| 49 , m_to(kMaxCodepoint) | |
| 50 , m_fontData(nullptr) | |
| 51 { | |
| 52 } | |
| 53 | |
| 54 explicit FontDataRange(UChar32 from, UChar32 to, PassRefPtr<SimpleFontData>
fontData) | |
| 55 : m_from(from) | 39 : m_from(from) |
| 56 , m_to(to) | 40 , m_to(to) |
| 57 , m_fontData(fontData) | |
| 58 { | 41 { |
| 59 } | 42 } |
| 60 | 43 |
| 61 UChar32 from() const { return m_from; } | 44 UChar32 from() const { return m_from; } |
| 62 UChar32 to() const { return m_to; } | 45 UChar32 to() const { return m_to; } |
| 63 bool contains(UChar32 testChar) { return testChar >= m_from && testChar <= m
_to; } | 46 bool contains(UChar32 c) const { return m_from <= c && c <= m_to; } |
| 64 bool isEntireRange() const { return !m_from && m_to >= kMaxCodepoint; } | 47 bool operator<(const UnicodeRange& other) const |
| 65 bool hasFontData() const { return fontData(); } | 48 { |
| 66 PassRefPtr<SimpleFontData> fontData() const { return m_fontData; } | 49 return m_from < other.m_from; |
| 50 } |
| 51 bool operator<(UChar32 c) const { return m_to < c; } |
| 52 bool operator==(const FontDataRange& fontDataRange) const |
| 53 { |
| 54 return fontDataRange.from() == m_from |
| 55 && fontDataRange.to() == m_to; |
| 56 }; |
| 67 | 57 |
| 68 private: | 58 private: |
| 69 UChar32 m_from; | 59 UChar32 m_from; |
| 70 UChar32 m_to; | 60 UChar32 m_to; |
| 71 RefPtr<SimpleFontData> m_fontData; | 61 }; |
| 62 |
| 63 class PLATFORM_EXPORT UnicodeRangeSet { |
| 64 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
| 65 |
| 66 public: |
| 67 explicit UnicodeRangeSet(const Vector<UnicodeRange>&); |
| 68 bool contains(UChar32) const; |
| 69 bool contains(const FontDataRange&) const; |
| 70 bool intersectsWith(const String&) const; |
| 71 bool isEntireRange() const { return m_ranges.isEmpty(); } |
| 72 size_t size() const { return m_ranges.size(); } |
| 73 const UnicodeRange& rangeAt(size_t i) const { return m_ranges[i]; } |
| 74 private: |
| 75 Vector<UnicodeRange> m_ranges; // If empty, represents the whole code space. |
| 72 }; | 76 }; |
| 73 | 77 |
| 74 } // namespace blink | 78 } // namespace blink |
| 75 | 79 |
| 76 #endif | 80 #endif |
| OLD | NEW |