Changeset 287866 in webkit
- Timestamp:
- Jan 10, 2022, 6:17:09 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 10 edited
-
LayoutTests/ChangeLog (modified) (1 diff)
-
LayoutTests/fast/images/text-recognition/image-overlay-line-wrapping.html (modified) (1 diff)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/dom/ImageOverlay.cpp (modified) (2 diffs)
-
Source/WebCore/platform/TextRecognitionResult.h (modified) (4 diffs)
-
Source/WebCore/testing/Internals.cpp (modified) (1 diff)
-
Source/WebCore/testing/Internals.h (modified) (1 diff)
-
Source/WebCore/testing/Internals.idl (modified) (1 diff)
-
Source/WebKit/ChangeLog (modified) (1 diff)
-
Source/WebKit/Platform/cocoa/TextRecognitionUtilities.mm (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r287863 r287866 1 2022-01-10 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 Followup to r287863 - adjust line wrapping behavior in image overlays 4 https://bugs.webkit.org/show_bug.cgi?id=235035 5 rdar://85139146 6 7 Reviewed by Tim Horton. 8 9 Make a slight adjustment to an existing layout test (i.e. rename `shouldWrap` to `hasTrailingNewline`). See 10 WebCore/ChangeLog for more details. 11 12 * fast/images/text-recognition/image-overlay-line-wrapping.html: 13 1 14 2022-01-10 Wenson Hsieh <wenson_hsieh@apple.com> 2 15 -
trunk/LayoutTests/fast/images/text-recognition/image-overlay-line-wrapping.html
r287863 r287866 26 26 bottomRight : new DOMPointReadOnly(1, 0.3), 27 27 bottomLeft : new DOMPointReadOnly(0, 0.3), 28 shouldWrap: true,28 hasTrailingNewline: false, 29 29 children: [ 30 30 { -
trunk/Source/WebCore/ChangeLog
r287863 r287866 1 2022-01-10 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 Followup to r287863 - adjust line wrapping behavior in image overlays 4 https://bugs.webkit.org/show_bug.cgi?id=235035 5 rdar://85139146 6 7 Reviewed by Tim Horton. 8 9 The previous change I landed in r287863 was written under the assumption that `-shouldWrap` describes whether or 10 not a recognized line of text should wrap to the next line. However, after trying it out, it seems to indicate 11 whether or not the previous line of text should wrap to the current line. As a result, the current adoption of 12 this property is wrong, since the line wrapping is off-by-one. 13 14 Fix this by renaming the `shouldWrap` boolean flag in TextRecognitionLineData to the much less ambiguous name 15 `hasTrailingNewline`, and set `hasTrailingNewline` based on the `shouldWrap` property of the *next* 16 VKWKLineInfo. 17 18 * dom/ImageOverlay.cpp: 19 (WebCore::ImageOverlay::updateSubtree): 20 21 Avoid a potentially even-more-confusing `!= !!` here by using `static_cast<>` to check the nullity of the 22 `RefPtr`. 23 24 * platform/TextRecognitionResult.h: 25 (WebCore::TextRecognitionLineData::TextRecognitionLineData): 26 (WebCore::TextRecognitionLineData::encode const): 27 (WebCore::TextRecognitionLineData::decode): 28 29 Make sure we also flip the default from `false` to `true`, since `hasTrailingNewline` is intended to have the 30 opposite effect as the extant `shouldWrap`. 31 32 * testing/Internals.cpp: 33 (WebCore::makeDataForLine): 34 * testing/Internals.h: 35 * testing/Internals.idl: 36 1 37 2022-01-10 Wenson Hsieh <wenson_hsieh@apple.com> 2 38 -
trunk/Source/WebCore/dom/ImageOverlay.cpp
r287863 r287866 277 277 auto& lineElements = elements.lines[lineIndex]; 278 278 auto& childTextElements = lineElements.children; 279 if (lineResult. shouldWrap != !lineElements.lineBreak)279 if (lineResult.hasTrailingNewline != static_cast<bool>(lineElements.lineBreak)) 280 280 return false; 281 281 … … 336 336 } 337 337 338 if ( !line.shouldWrap) {338 if (line.hasTrailingNewline) { 339 339 lineElements.lineBreak = HTMLBRElement::create(document.get()); 340 340 lineContainer->appendChild(*lineElements.lineBreak); -
trunk/Source/WebCore/platform/TextRecognitionResult.h
r287863 r287866 82 82 83 83 struct TextRecognitionLineData { 84 TextRecognitionLineData(FloatQuad&& quad, Vector<TextRecognitionWordData>&& theChildren, bool wrap)84 TextRecognitionLineData(FloatQuad&& quad, Vector<TextRecognitionWordData>&& theChildren, bool newline) 85 85 : normalizedQuad(WTFMove(quad)) 86 86 , children(WTFMove(theChildren)) 87 , shouldWrap(wrap)87 , hasTrailingNewline(newline) 88 88 { 89 89 } … … 91 91 FloatQuad normalizedQuad; 92 92 Vector<TextRecognitionWordData> children; 93 bool shouldWrap { false };93 bool hasTrailingNewline { true }; 94 94 95 95 template<class Encoder> void encode(Encoder&) const; … … 117 117 encoder << normalizedQuad; 118 118 encoder << children; 119 encoder << shouldWrap;119 encoder << hasTrailingNewline; 120 120 } 121 121 … … 132 132 return std::nullopt; 133 133 134 std::optional<bool> shouldWrap;135 decoder >> shouldWrap;136 if (! shouldWrap)137 return std::nullopt; 138 139 return { { WTFMove(*normalizedQuad), WTFMove(*children), * shouldWrap} };134 std::optional<bool> hasTrailingNewline; 135 decoder >> hasTrailingNewline; 136 if (!hasTrailingNewline) 137 return std::nullopt; 138 139 return { { WTFMove(*normalizedQuad), WTFMove(*children), *hasTrailingNewline } }; 140 140 } 141 141 -
trunk/Source/WebCore/testing/Internals.cpp
r287863 r287866 5771 5771 return { textChild.text, getQuad<Internals::ImageOverlayText>(textChild), textChild.hasLeadingWhitespace }; 5772 5772 }), 5773 line. shouldWrap5773 line.hasTrailingNewline 5774 5774 }; 5775 5775 } -
trunk/Source/WebCore/testing/Internals.h
r287863 r287866 923 923 RefPtr<DOMPointReadOnly> bottomLeft; 924 924 Vector<ImageOverlayText> children; 925 bool shouldWrap { false };925 bool hasTrailingNewline { true }; 926 926 927 927 ~ImageOverlayLine(); -
trunk/Source/WebCore/testing/Internals.idl
r287863 r287866 293 293 required DOMPointReadOnly bottomLeft; 294 294 sequence<ImageOverlayText> children; 295 boolean shouldWrap = false;295 boolean hasTrailingNewline = true; 296 296 }; 297 297 -
trunk/Source/WebKit/ChangeLog
r287863 r287866 1 2022-01-10 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 Followup to r287863 - adjust line wrapping behavior in image overlays 4 https://bugs.webkit.org/show_bug.cgi?id=235035 5 rdar://85139146 6 7 Reviewed by Tim Horton. 8 9 Use the `-shouldWrap` property to compute `hasTrailingNewline`. See WebCore/ChangeLog for more details. 10 11 * Platform/cocoa/TextRecognitionUtilities.mm: 12 (WebKit::makeTextRecognitionResult): 13 1 14 2022-01-10 Wenson Hsieh <wenson_hsieh@apple.com> 2 15 -
trunk/Source/WebKit/Platform/cocoa/TextRecognitionUtilities.mm
r287863 r287866 79 79 TextRecognitionResult makeTextRecognitionResult(VKImageAnalysis *analysis) 80 80 { 81 NSArray<VKWK TextInfo *> *allLines = analysis.allLines;81 NSArray<VKWKLineInfo *> *allLines = analysis.allLines; 82 82 TextRecognitionResult result; 83 83 result.lines.reserveInitialCapacity(allLines.count); 84 84 85 85 bool isFirstLine = true; 86 size_t nextLineIndex = 1; 86 87 for (VKWKLineInfo *line in allLines) { 87 88 Vector<TextRecognitionWordData> children; … … 115 116 children.uncheckedAppend({ WTFMove(childText), floatQuad(child.quad), hasLeadingWhitespace }); 116 117 } 117 result.lines.uncheckedAppend({ 118 floatQuad(line.quad), 119 WTFMove(children), 120 [line respondsToSelector:@selector(shouldWrap)] && [line shouldWrap] 121 }); 118 VKWKLineInfo *nextLine = nextLineIndex < allLines.count ? allLines[nextLineIndex] : nil; 119 // The `shouldWrap` property indicates whether or not a line should wrap, relative to the previous line. 120 bool hasTrailingNewline = nextLine && (![nextLine respondsToSelector:@selector(shouldWrap)] || ![nextLine shouldWrap]); 121 result.lines.uncheckedAppend({ floatQuad(line.quad), WTFMove(children), hasTrailingNewline }); 122 122 isFirstLine = false; 123 nextLineIndex++; 123 124 } 124 125
Note:
See TracChangeset
for help on using the changeset viewer.