diff options
Diffstat (limited to 'WebCore/platform/text')
-rw-r--r-- | WebCore/platform/text/BidiResolver.h | 78 | ||||
-rw-r--r-- | WebCore/platform/text/TextCodecUTF16.cpp | 12 | ||||
-rw-r--r-- | WebCore/platform/text/TextStream.cpp | 6 | ||||
-rw-r--r-- | WebCore/platform/text/cf/HyphenationCF.cpp | 34 | ||||
-rw-r--r-- | WebCore/platform/text/mac/TextBreakIteratorInternalICUMac.mm | 14 |
5 files changed, 85 insertions, 59 deletions
diff --git a/WebCore/platform/text/BidiResolver.h b/WebCore/platform/text/BidiResolver.h index a99fd01..1f87115 100644 --- a/WebCore/platform/text/BidiResolver.h +++ b/WebCore/platform/text/BidiResolver.h @@ -201,6 +201,7 @@ protected: private: void raiseExplicitEmbeddingLevel(WTF::Unicode::Direction from, WTF::Unicode::Direction to); void lowerExplicitEmbeddingLevel(WTF::Unicode::Direction from); + void checkDirectionInLowerRaiseEmbeddingLevel(); Vector<WTF::Unicode::Direction, 8> m_currentExplicitEmbeddingSequence; }; @@ -308,23 +309,39 @@ void BidiResolver<Iterator, Run>::embed(WTF::Unicode::Direction d) } template <class Iterator, class Run> +void BidiResolver<Iterator, Run>::checkDirectionInLowerRaiseEmbeddingLevel() +{ + using namespace WTF::Unicode; + + ASSERT(m_status.eor != OtherNeutral || eor.atEnd()); + // bidi.sor ... bidi.eor ... bidi.last eor; need to append the bidi.sor-bidi.eor run or extend it through bidi.last + // Bidi control characters are included into BidiRun, so last direction + // could be one of the bidi embeddings when there are nested embeddings. + // For example: "‪‫....." + ASSERT(m_status.last == EuropeanNumberSeparator + || m_status.last == EuropeanNumberTerminator + || m_status.last == CommonNumberSeparator + || m_status.last == BoundaryNeutral + || m_status.last == BlockSeparator + || m_status.last == SegmentSeparator + || m_status.last == WhiteSpaceNeutral + || m_status.last == OtherNeutral + || m_status.last == RightToLeftEmbedding + || m_status.last == LeftToRightEmbedding + || m_status.last == RightToLeftOverride + || m_status.last == LeftToRightOverride + || m_status.last == PopDirectionalFormat); + if (m_direction == OtherNeutral) + m_direction = m_status.lastStrong == LeftToRight ? LeftToRight : RightToLeft; +} + +template <class Iterator, class Run> void BidiResolver<Iterator, Run>::lowerExplicitEmbeddingLevel(WTF::Unicode::Direction from) { using namespace WTF::Unicode; if (!emptyRun && eor != last) { - ASSERT(m_status.eor != OtherNeutral || eor.atEnd()); - // bidi.sor ... bidi.eor ... bidi.last eor; need to append the bidi.sor-bidi.eor run or extend it through bidi.last - ASSERT(m_status.last == EuropeanNumberSeparator - || m_status.last == EuropeanNumberTerminator - || m_status.last == CommonNumberSeparator - || m_status.last == BoundaryNeutral - || m_status.last == BlockSeparator - || m_status.last == SegmentSeparator - || m_status.last == WhiteSpaceNeutral - || m_status.last == OtherNeutral); - if (m_direction == OtherNeutral) - m_direction = m_status.lastStrong == LeftToRight ? LeftToRight : RightToLeft; + checkDirectionInLowerRaiseEmbeddingLevel(); if (from == LeftToRight) { // bidi.sor ... bidi.eor ... bidi.last L if (m_status.eor == EuropeanNumber) { @@ -359,18 +376,7 @@ void BidiResolver<Iterator, Run>::raiseExplicitEmbeddingLevel(WTF::Unicode::Dire using namespace WTF::Unicode; if (!emptyRun && eor != last) { - ASSERT(m_status.eor != OtherNeutral || eor.atEnd()); - // bidi.sor ... bidi.eor ... bidi.last eor; need to append the bidi.sor-bidi.eor run or extend it through bidi.last - ASSERT(m_status.last == EuropeanNumberSeparator - || m_status.last == EuropeanNumberTerminator - || m_status.last == CommonNumberSeparator - || m_status.last == BoundaryNeutral - || m_status.last == BlockSeparator - || m_status.last == SegmentSeparator - || m_status.last == WhiteSpaceNeutral - || m_status.last == OtherNeutral); - if (m_direction == OtherNeutral) - m_direction = m_status.lastStrong == LeftToRight ? LeftToRight : RightToLeft; + checkDirectionInLowerRaiseEmbeddingLevel(); if (to == LeftToRight) { // bidi.sor ... bidi.eor ... bidi.last L if (m_status.eor == EuropeanNumber) { @@ -568,7 +574,7 @@ void BidiResolver<Iterator, Run>::createBidiRunsForLine(const Iterator& end, boo commitExplicitEmbedding(); break; - // strong types + // strong types case LeftToRight: switch(m_status.last) { case RightToLeft: @@ -860,11 +866,6 @@ void BidiResolver<Iterator, Run>::createBidiRunsForLine(const Iterator& end, boo break; case NonSpacingMark: case BoundaryNeutral: - case RightToLeftEmbedding: - case LeftToRightEmbedding: - case RightToLeftOverride: - case LeftToRightOverride: - case PopDirectionalFormat: // ignore these break; case EuropeanNumber: @@ -875,11 +876,7 @@ void BidiResolver<Iterator, Run>::createBidiRunsForLine(const Iterator& end, boo last = current; - if (emptyRun && !(dirCurrent == RightToLeftEmbedding - || dirCurrent == LeftToRightEmbedding - || dirCurrent == RightToLeftOverride - || dirCurrent == LeftToRightOverride - || dirCurrent == PopDirectionalFormat)) { + if (emptyRun) { sor = current; emptyRun = false; } @@ -901,17 +898,6 @@ void BidiResolver<Iterator, Run>::createBidiRunsForLine(const Iterator& end, boo } } - if (emptyRun && (dirCurrent == RightToLeftEmbedding - || dirCurrent == LeftToRightEmbedding - || dirCurrent == RightToLeftOverride - || dirCurrent == LeftToRightOverride - || dirCurrent == PopDirectionalFormat)) { - // exclude the embedding char itself from the new run so that ATSUI will never see it - eor = Iterator(); - last = current; - sor = current; - } - if (!pastEnd && (current == end || current.atEnd())) { if (emptyRun) break; diff --git a/WebCore/platform/text/TextCodecUTF16.cpp b/WebCore/platform/text/TextCodecUTF16.cpp index 5c23732..95f4dc4 100644 --- a/WebCore/platform/text/TextCodecUTF16.cpp +++ b/WebCore/platform/text/TextCodecUTF16.cpp @@ -31,6 +31,8 @@ #include <wtf/text/StringBuffer.h> #include <wtf/PassOwnPtr.h> +using namespace std; + namespace WebCore { void TextCodecUTF16::registerEncodingNames(EncodingNameRegistrar registrar) @@ -115,23 +117,27 @@ String TextCodecUTF16::decode(const char* bytes, size_t length, bool, bool, bool CString TextCodecUTF16::encode(const UChar* characters, size_t length, UnencodableHandling) { + if (length > numeric_limits<size_t>::max() / 2) + CRASH(); + char* bytes; CString string = CString::newUninitialized(length * 2, bytes); // FIXME: CString is not a reasonable data structure for encoded UTF-16, which will have - // null characters inside it. Perhaps the result of encode should not be a CString? - if (m_littleEndian) + // null characters inside it. Perhaps the result of encode should not be a CString. + if (m_littleEndian) { for (size_t i = 0; i < length; ++i) { UChar c = characters[i]; bytes[i * 2] = c; bytes[i * 2 + 1] = c >> 8; } - else + } else { for (size_t i = 0; i < length; ++i) { UChar c = characters[i]; bytes[i * 2] = c >> 8; bytes[i * 2 + 1] = c; } + } return string; } diff --git a/WebCore/platform/text/TextStream.cpp b/WebCore/platform/text/TextStream.cpp index 646de3f..1094fa4 100644 --- a/WebCore/platform/text/TextStream.cpp +++ b/WebCore/platform/text/TextStream.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2004, 2008, 2010 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -29,6 +29,8 @@ #include "PlatformString.h" #include <wtf/StringExtras.h> +using namespace std; + namespace WebCore { static const size_t printBufferSize = 100; // large enough for any integer or floating point value in string format, including trailing null character @@ -84,6 +86,8 @@ TextStream& TextStream::operator<<(const char* string) { size_t stringLength = strlen(string); size_t textLength = m_text.size(); + if (stringLength > numeric_limits<size_t>::max() - textLength) + CRASH(); m_text.grow(textLength + stringLength); for (size_t i = 0; i < stringLength; ++i) m_text[textLength + i] = string[i]; diff --git a/WebCore/platform/text/cf/HyphenationCF.cpp b/WebCore/platform/text/cf/HyphenationCF.cpp index b265c56..dbc11ae 100644 --- a/WebCore/platform/text/cf/HyphenationCF.cpp +++ b/WebCore/platform/text/cf/HyphenationCF.cpp @@ -33,6 +33,38 @@ #include <wtf/ListHashSet.h> #include <wtf/RetainPtr.h> +#if PLATFORM(WIN) + +#include "SoftLinking.h" + +#ifdef DEBUG_ALL +SOFT_LINK_DEBUG_LIBRARY(CoreFoundation) +#else +SOFT_LINK_LIBRARY(CoreFoundation) +#endif + +SOFT_LINK_OPTIONAL(CoreFoundation, CFStringGetHyphenationLocationBeforeIndex, CFIndex, , (CFStringRef string, CFIndex location, CFRange limitRange, CFOptionFlags options, CFLocaleRef locale, UTF32Char *character)) +SOFT_LINK_OPTIONAL(CoreFoundation, CFStringIsHyphenationAvailableForLocale, Boolean, , (CFLocaleRef locale)) + +static CFIndex wkCFStringGetHyphenationLocationBeforeIndex(CFStringRef string, CFIndex location, CFRange limitRange, CFOptionFlags options, CFLocaleRef locale, UTF32Char *character) +{ + static CFStringGetHyphenationLocationBeforeIndexPtrType cfStringGetHyphenationLocationBeforeIndex = CFStringGetHyphenationLocationBeforeIndexPtr(); + if (!cfStringGetHyphenationLocationBeforeIndex) + return kCFNotFound; + return cfStringGetHyphenationLocationBeforeIndex(string, location, limitRange, options, locale, character); +} + +static Boolean wkCFStringIsHyphenationAvailableForLocale(CFLocaleRef locale) +{ + static CFStringIsHyphenationAvailableForLocalePtrType cfStringIsHyphenationAvailableForLocale = CFStringIsHyphenationAvailableForLocalePtr(); + return cfStringIsHyphenationAvailableForLocale && cfStringIsHyphenationAvailableForLocale(locale); +} + +#define CFStringGetHyphenationLocationBeforeIndex wkCFStringGetHyphenationLocationBeforeIndex +#define CFStringIsHyphenationAvailableForLocale wkCFStringIsHyphenationAvailableForLocale + +#endif // PLATFORM(WIN) + namespace WebCore { template<> @@ -65,7 +97,7 @@ bool canHyphenate(const AtomicString& localeIdentifier) size_t lastHyphenLocation(const UChar* characters, size_t length, size_t beforeIndex, const AtomicString& localeIdentifier) { - RetainPtr<CFStringRef> string(AdoptCF, CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, characters, length, kCFAllocatorNull)); + RetainPtr<CFStringRef> string(AdoptCF, CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, reinterpret_cast<const UniChar*>(characters), length, kCFAllocatorNull)); RetainPtr<CFLocaleRef> locale = cfLocaleCache().get(localeIdentifier); ASSERT(locale); diff --git a/WebCore/platform/text/mac/TextBreakIteratorInternalICUMac.mm b/WebCore/platform/text/mac/TextBreakIteratorInternalICUMac.mm index 5da10e0..6af5616 100644 --- a/WebCore/platform/text/mac/TextBreakIteratorInternalICUMac.mm +++ b/WebCore/platform/text/mac/TextBreakIteratorInternalICUMac.mm @@ -38,17 +38,15 @@ static inline RetainPtr<CFStringRef> textBreakLocalePreference() static RetainPtr<CFStringRef> topLanguagePreference() { - RetainPtr<CFPropertyListRef> languages(AdoptCF, CFPreferencesCopyValue(CFSTR("AppleLanguages"), - kCFPreferencesAnyApplication, kCFPreferencesCurrentUser, kCFPreferencesAnyHost)); - if (!languages || CFGetTypeID(languages.get()) != CFArrayGetTypeID()) + NSArray *languagesArray = [[NSUserDefaults standardUserDefaults] arrayForKey:@"AppleLanguages"]; + if (!languagesArray) return 0; - CFArrayRef languagesArray = static_cast<CFArrayRef>(languages.get()); - if (CFArrayGetCount(languagesArray) < 1) + if ([languagesArray count] < 1) return 0; - const void* value = CFArrayGetValueAtIndex(languagesArray, 0); - if (!value || CFGetTypeID(value) != CFStringGetTypeID()) + NSString *value = [languagesArray objectAtIndex:0]; + if (![value isKindOfClass:[NSString class]]) return 0; - return static_cast<CFStringRef>(value); + return reinterpret_cast<CFStringRef>(value); } static RetainPtr<CFStringRef> canonicalLanguageIdentifier(CFStringRef locale) |