From c2158a221353468c83cf6c596077adeafdde3247 Mon Sep 17 00:00:00 2001 From: "mmaxfield@apple.com" Date: Fri, 3 Oct 2014 22:07:42 +0000 Subject: [PATCH] Clean up interface to Font::expansionOpportunityCount() https://bugs.webkit.org/show_bug.cgi?id=137355 Reviewed by Dean Jackson. There are two overloads of Font::expansionOpportunityCount() which perform the same operation. One overload takes a UChar*, the other takes an LChar*, and they both take a length. This is the abstraction that StringView was designed to be. Instead of forcing each caller to take a different overload based on if their data is 8 bit or not, allow the caller to construct a StringView and pass that into Font::expansionOpportunityCount() instead of a raw pointer/length. No new tests because there is no behavior change. * platform/graphics/Font.cpp: (WebCore::Font::expansionOpportunityCountInternal): Original two functions, renamed. (WebCore::Font::expansionOpportunityCount): Takes a StringView, calls expansionOpportunityCountInternal(). * platform/graphics/Font.h: Update signatures. * platform/graphics/WidthIterator.cpp: (WebCore::WidthIterator::WidthIterator): Use new signature to Font::expansionOpportunityCount(). * platform/graphics/mac/ComplexTextController.cpp: (WebCore::ComplexTextController::ComplexTextController): Ditto. * rendering/RenderBlockLineLayout.cpp: (WebCore::RenderBlockFlow::computeInlineDirectionPositionsForSegment): Ditto. * rendering/RenderText.cpp: (WebCore::RenderText::stringView): Accessor to encapsulate character pointer and length. * rendering/RenderText.h: Signature of new accessor. git-svn-id: https://svn.webkit.org/repository/webkit/trunk@174297 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- Source/WebCore/ChangeLog | 34 +++++++++++++++++++ Source/WebCore/platform/graphics/Font.cpp | 11 ++++-- Source/WebCore/platform/graphics/Font.h | 6 ++-- .../platform/graphics/WidthIterator.cpp | 2 +- .../graphics/mac/ComplexTextController.cpp | 6 +--- .../rendering/RenderBlockLineLayout.cpp | 6 +--- Source/WebCore/rendering/RenderText.cpp | 7 ++++ Source/WebCore/rendering/RenderText.h | 2 ++ 8 files changed, 59 insertions(+), 15 deletions(-) diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index fea6cd171a1c..b52867455d6f 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,37 @@ +2014-10-03 Myles C. Maxfield + + Clean up interface to Font::expansionOpportunityCount() + https://bugs.webkit.org/show_bug.cgi?id=137355 + + Reviewed by Dean Jackson. + + There are two overloads of Font::expansionOpportunityCount() which perform the same + operation. One overload takes a UChar*, the other takes an LChar*, and they both + take a length. This is the abstraction that StringView was designed to be. Instead + of forcing each caller to take a different overload based on if their data is + 8 bit or not, allow the caller to construct a StringView and pass that into + Font::expansionOpportunityCount() instead of a raw pointer/length. + + No new tests because there is no behavior change. + + * platform/graphics/Font.cpp: + (WebCore::Font::expansionOpportunityCountInternal): Original two functions, + renamed. + (WebCore::Font::expansionOpportunityCount): Takes a StringView, calls + expansionOpportunityCountInternal(). + * platform/graphics/Font.h: Update signatures. + * platform/graphics/WidthIterator.cpp: + (WebCore::WidthIterator::WidthIterator): Use new signature to + Font::expansionOpportunityCount(). + * platform/graphics/mac/ComplexTextController.cpp: + (WebCore::ComplexTextController::ComplexTextController): Ditto. + * rendering/RenderBlockLineLayout.cpp: + (WebCore::RenderBlockFlow::computeInlineDirectionPositionsForSegment): Ditto. + * rendering/RenderText.cpp: + (WebCore::RenderText::stringView): Accessor to encapsulate character pointer + and length. + * rendering/RenderText.h: Signature of new accessor. + 2014-10-03 Brent Fulgham [Win] Unreviewed build fix for MSVC 2013 SP 3. diff --git a/Source/WebCore/platform/graphics/Font.cpp b/Source/WebCore/platform/graphics/Font.cpp index 5ec424ac6b4c..a5b4d12c3b81 100644 --- a/Source/WebCore/platform/graphics/Font.cpp +++ b/Source/WebCore/platform/graphics/Font.cpp @@ -968,7 +968,7 @@ bool Font::isCJKIdeographOrSymbol(UChar32 c) return isCJKIdeograph(c); } -unsigned Font::expansionOpportunityCount(const LChar* characters, size_t length, TextDirection direction, bool& isAfterExpansion) +unsigned Font::expansionOpportunityCountInternal(const LChar* characters, size_t length, TextDirection direction, bool& isAfterExpansion) { unsigned count = 0; if (direction == LTR) { @@ -991,7 +991,7 @@ unsigned Font::expansionOpportunityCount(const LChar* characters, size_t length, return count; } -unsigned Font::expansionOpportunityCount(const UChar* characters, size_t length, TextDirection direction, bool& isAfterExpansion) +unsigned Font::expansionOpportunityCountInternal(const UChar* characters, size_t length, TextDirection direction, bool& isAfterExpansion) { static bool expandAroundIdeographs = canExpandAroundIdeographsInComplexText(); unsigned count = 0; @@ -1041,6 +1041,13 @@ unsigned Font::expansionOpportunityCount(const UChar* characters, size_t length, return count; } +unsigned Font::expansionOpportunityCount(const StringView& stringView, TextDirection direction, bool& isAfterExpansion) +{ + if (stringView.is8Bit()) + return expansionOpportunityCountInternal(stringView.characters8(), stringView.length(), direction, isAfterExpansion); + return expansionOpportunityCountInternal(stringView.characters16(), stringView.length(), direction, isAfterExpansion); +} + bool Font::canReceiveTextEmphasis(UChar32 c) { if (U_GET_GC_MASK(c) & (U_GC_Z_MASK | U_GC_CN_MASK | U_GC_CC_MASK | U_GC_CF_MASK)) diff --git a/Source/WebCore/platform/graphics/Font.h b/Source/WebCore/platform/graphics/Font.h index 58c40ab6f115..d4559a7e8bc5 100644 --- a/Source/WebCore/platform/graphics/Font.h +++ b/Source/WebCore/platform/graphics/Font.h @@ -201,8 +201,7 @@ public: static bool isCJKIdeograph(UChar32); static bool isCJKIdeographOrSymbol(UChar32); - static unsigned expansionOpportunityCount(const LChar*, size_t length, TextDirection, bool& isAfterExpansion); - static unsigned expansionOpportunityCount(const UChar*, size_t length, TextDirection, bool& isAfterExpansion); + static unsigned expansionOpportunityCount(const StringView&, TextDirection, bool& isAfterExpansion); WEBCORE_EXPORT static void setShouldUseSmoothing(bool); WEBCORE_EXPORT static bool shouldUseSmoothing(); @@ -240,6 +239,9 @@ private: int offsetForPositionForComplexText(const TextRun&, float position, bool includePartialGlyphs) const; void adjustSelectionRectForComplexText(const TextRun&, LayoutRect& selectionRect, int from, int to) const; + static unsigned expansionOpportunityCountInternal(const LChar*, size_t length, TextDirection, bool& isAfterExpansion); + static unsigned expansionOpportunityCountInternal(const UChar*, size_t length, TextDirection, bool& isAfterExpansion); + friend struct WidthIterator; friend class SVGTextRunRenderingContext; diff --git a/Source/WebCore/platform/graphics/WidthIterator.cpp b/Source/WebCore/platform/graphics/WidthIterator.cpp index 4136d1e3da7e..f2c7c05e7d32 100644 --- a/Source/WebCore/platform/graphics/WidthIterator.cpp +++ b/Source/WebCore/platform/graphics/WidthIterator.cpp @@ -57,7 +57,7 @@ WidthIterator::WidthIterator(const Font* font, const TextRun& run, HashSetbox())->setCanHaveLeadingExpansion(true); - unsigned opportunitiesInRun; - if (rt.is8Bit()) - opportunitiesInRun = Font::expansionOpportunityCount(rt.characters8() + r->m_start, r->m_stop - r->m_start, r->box()->direction(), isAfterExpansion); - else - opportunitiesInRun = Font::expansionOpportunityCount(rt.characters16() + r->m_start, r->m_stop - r->m_start, r->box()->direction(), isAfterExpansion); + unsigned opportunitiesInRun = Font::expansionOpportunityCount(rt.stringView(r->m_start, r->m_stop), r->box()->direction(), isAfterExpansion); expansionOpportunities.append(opportunitiesInRun); expansionOpportunityCount += opportunitiesInRun; } diff --git a/Source/WebCore/rendering/RenderText.cpp b/Source/WebCore/rendering/RenderText.cpp index 39012f2d3bf2..fc75302ba842 100644 --- a/Source/WebCore/rendering/RenderText.cpp +++ b/Source/WebCore/rendering/RenderText.cpp @@ -1525,4 +1525,11 @@ void RenderText::momentarilyRevealLastTypedCharacter(unsigned lastTypedCharacter secureTextTimer->restartWithNewText(lastTypedCharacterOffset); } +StringView RenderText::stringView(int start, int stop) const +{ + if (is8Bit()) + return StringView(characters8() + start, stop - start); + return StringView(characters16() + start, stop - start); +} + } // namespace WebCore diff --git a/Source/WebCore/rendering/RenderText.h b/Source/WebCore/rendering/RenderText.h index f024aa6e288a..84115a33e2a1 100644 --- a/Source/WebCore/rendering/RenderText.h +++ b/Source/WebCore/rendering/RenderText.h @@ -156,6 +156,8 @@ public: void deleteLineBoxesBeforeSimpleLineLayout(); const SimpleLineLayout::Layout* simpleLineLayout() const; + StringView stringView(int start, int stop) const; + protected: virtual void computePreferredLogicalWidths(float leadWidth); virtual void willBeDestroyed() override; -- 2.36.0