Changeset 204830 in webkit
- Timestamp:
- Aug 23, 2016 6:36:26 AM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r204809 r204830 1 2016-08-03 Frederic Wang <fwang@igalia.com> 2 3 Share and improve extraction of character for operator and token elements 4 https://bugs.webkit.org/show_bug.cgi?id=160462 5 6 Reviewed by Darin Adler. 7 8 No new tests, already covered by existing tests. 9 10 * mathml/MathMLElement.cpp: 11 (WebCore::MathMLElement::stripLeadingAndTrailingWhitespace): Make this a protected member of 12 MathMLElement so that it can be used in MathMLTokenElement. 13 (WebCore::skipLeadingAndTrailingWhitespace): Deleted. 14 * mathml/MathMLElement.h: Declare stripLeadingAndTrailingWhitespace. 15 * mathml/MathMLOperatorElement.cpp: 16 (WebCore::MathMLOperatorElement::parseOperatorChar): Use convertToSingleCodePoint to extract 17 a code point more efficiently. For now, we continue to only handle BMP characters. 18 * mathml/MathMLTokenElement.cpp: 19 (WebCore::MathMLTokenElement::convertToSingleCodePoint): Helper function to try and convert a 20 string to a single code point after having removed leading and trailing space. 21 * mathml/MathMLTokenElement.h: Declare convertToSingleCodePoint. 22 * rendering/mathml/RenderMathMLToken.cpp: 23 (WebCore::RenderMathMLToken::updateMathVariantGlyph): Use convertToSingleCodePoint to extract 24 a code point more efficiently. 25 1 26 2016-08-23 Frederic Wang <fwang@igalia.com> 2 27 -
trunk/Source/WebCore/mathml/MathMLElement.cpp
r204692 r204830 366 366 } 367 367 368 static inline StringView skipLeadingAndTrailingWhitespace(const StringView& stringView)368 StringView MathMLElement::stripLeadingAndTrailingWhitespace(const StringView& stringView) 369 369 { 370 370 unsigned start = 0, stringLength = stringView.length(); … … 471 471 472 472 // We first skip whitespace from both ends of the string. 473 StringView stringView = s kipLeadingAndTrailingWhitespace(string);473 StringView stringView = stripLeadingAndTrailingWhitespace(string); 474 474 475 475 if (stringView.isEmpty()) -
trunk/Source/WebCore/mathml/MathMLElement.h
r204692 r204830 94 94 MathMLElement(const QualifiedName& tagName, Document&); 95 95 96 static StringView stripLeadingAndTrailingWhitespace(const StringView&); 97 96 98 void parseAttribute(const QualifiedName&, const AtomicString&) override; 97 99 bool childShouldCreateRenderer(const Node&) const override; -
trunk/Source/WebCore/mathml/MathMLOperatorElement.cpp
r204715 r204830 51 51 { 52 52 OperatorChar operatorChar; 53 54 // We collapse the whitespace and replace the hyphens by minus signs. 55 AtomicString textContent = string.stripWhiteSpace().simplifyWhiteSpace().replace(hyphenMinus, minusSign).impl(); 56 57 // We verify whether the operator text can be represented by a single UChar. 58 // FIXME: This is a really inefficient way to extract a character from a string (https://webkit.org/b/160241#c7). 59 // FIXME: This does not handle surrogate pairs (https://webkit.org/b/122296). 60 // FIXME: This does not handle <mo> operators with multiple characters (https://webkit.org/b/124828). 61 operatorChar.character = textContent.length() == 1 ? textContent[0] : 0; 62 operatorChar.isVertical = MathMLOperatorDictionary::isVertical(operatorChar.character); 53 // FIXME: This operator dictionary does not accept multiple characters (https://webkit.org/b/124828). 54 if (auto codePoint = convertToSingleCodePoint(string)) { 55 // FIXME: MathMLOperatorDictionary/RenderMathMLOperator/MathOperator do not support non-BMP characters (https://webkit.org/b/122296). 56 if (U_IS_BMP(codePoint.value())) { 57 UChar character = codePoint.value(); 58 // The minus sign renders better than the hyphen sign used in some MathML formulas. 59 if (character == hyphenMinus) 60 character = minusSign; 61 operatorChar.character = character; 62 operatorChar.isVertical = MathMLOperatorDictionary::isVertical(operatorChar.character); 63 } 64 } 63 65 return operatorChar; 64 66 } -
trunk/Source/WebCore/mathml/MathMLTokenElement.cpp
r204715 r204830 89 89 } 90 90 91 Optional<UChar32> MathMLTokenElement::convertToSingleCodePoint(StringView string) 92 { 93 auto codePoints = stripLeadingAndTrailingWhitespace(string).codePoints(); 94 auto iterator = codePoints.begin(); 95 if (iterator == codePoints.end()) 96 return Nullopt; 97 Optional<UChar32> character = *iterator; 98 ++iterator; 99 return iterator == codePoints.end() ? character : Nullopt; 100 } 101 91 102 } 92 103 -
trunk/Source/WebCore/mathml/MathMLTokenElement.h
r204715 r204830 38 38 static Ref<MathMLTokenElement> create(const QualifiedName& tagName, Document&); 39 39 40 static Optional<UChar32> convertToSingleCodePoint(StringView); 41 40 42 protected: 41 43 MathMLTokenElement(const QualifiedName& tagName, Document&); -
trunk/Source/WebCore/rendering/mathml/RenderMathMLToken.cpp
r204715 r204830 528 528 529 529 const auto& tokenElement = element(); 530 AtomicString textContent = element().textContent().stripWhiteSpace().simplifyWhiteSpace(); 531 if (textContent.length() == 1) { 532 UChar32 codePoint = textContent[0]; 530 if (auto codePoint = MathMLTokenElement::convertToSingleCodePoint(element().textContent())) { 533 531 MathMLElement::MathVariant mathvariant = mathMLStyle()->mathVariant(); 534 532 if (mathvariant == MathMLElement::MathVariant::None) 535 533 mathvariant = tokenElement.hasTagName(MathMLNames::miTag) ? MathMLElement::MathVariant::Italic : MathMLElement::MathVariant::Normal; 536 UChar32 transformedCodePoint = mathVariant(codePoint , mathvariant);537 if (transformedCodePoint != codePoint )534 UChar32 transformedCodePoint = mathVariant(codePoint.value(), mathvariant); 535 if (transformedCodePoint != codePoint.value()) 538 536 m_mathVariantGlyph = style().fontCascade().glyphDataForCharacter(transformedCodePoint, !style().isLeftToRightDirection()); 539 537 }
Note: See TracChangeset
for help on using the changeset viewer.