- Revision
- 287954
- Author
- wenson_hs...@apple.com
- Date
- 2022-01-12 15:13:39 -0800 (Wed, 12 Jan 2022)
Log Message
Live Text is sometimes horizontally clipped when injecting TextRecognitionBlockData
https://bugs.webkit.org/show_bug.cgi?id=235122
Reviewed by Devin Rousso.
Source/WebCore:
The current heuristic for sizing Live Text paragraphs avoids vertical overflow, but does not avoid horizontal
overflow. Line breaking inside the fixed-width container prevents the latter in most cases, but not in the
scenario where the recognized text block is a single word with no opportunity for line break.
Address this by adjusting the sizing heuristic to shrink both the width and height to fit within the target size
(rather than just fitting the height).
Test: fast/images/text-recognition/image-overlay-block-horizontal-overflow.html
* dom/ImageOverlay.cpp:
(WebCore::ImageOverlay::updateWithTextRecognitionResult):
LayoutTests:
Add a test to verify that a single, very long word in injected text recognition block data does not trigger
horizontal overflow.
* fast/images/text-recognition/image-overlay-block-horizontal-overflow-expected.html: Added.
* fast/images/text-recognition/image-overlay-block-horizontal-overflow.html: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (287953 => 287954)
--- trunk/LayoutTests/ChangeLog 2022-01-12 22:59:04 UTC (rev 287953)
+++ trunk/LayoutTests/ChangeLog 2022-01-12 23:13:39 UTC (rev 287954)
@@ -1,3 +1,16 @@
+2022-01-12 Wenson Hsieh <wenson_hs...@apple.com>
+
+ Live Text is sometimes horizontally clipped when injecting TextRecognitionBlockData
+ https://bugs.webkit.org/show_bug.cgi?id=235122
+
+ Reviewed by Devin Rousso.
+
+ Add a test to verify that a single, very long word in injected text recognition block data does not trigger
+ horizontal overflow.
+
+ * fast/images/text-recognition/image-overlay-block-horizontal-overflow-expected.html: Added.
+ * fast/images/text-recognition/image-overlay-block-horizontal-overflow.html: Added.
+
2022-01-12 Robert Jenner <jen...@apple.com>
[ iOS EWS ] imported/w3c/web-platform-tests/dom/events/focus-event-document-move.html is a constant text failure
Added: trunk/LayoutTests/fast/images/text-recognition/image-overlay-block-horizontal-overflow-expected.html (0 => 287954)
--- trunk/LayoutTests/fast/images/text-recognition/image-overlay-block-horizontal-overflow-expected.html (rev 0)
+++ trunk/LayoutTests/fast/images/text-recognition/image-overlay-block-horizontal-overflow-expected.html 2022-01-12 23:13:39 UTC (rev 287954)
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+body, html {
+ margin: 0;
+}
+
+.cover-block-container {
+ position: absolute;
+ top: 0;
+ left: 0;
+ width: 200px;
+ height: 200px;
+ background-color: black;
+}
+</style>
+</head>
+<body>
+<img src=""
+<div class="cover-block-container"></div>
+</body>
+</html>
\ No newline at end of file
Added: trunk/LayoutTests/fast/images/text-recognition/image-overlay-block-horizontal-overflow.html (0 => 287954)
--- trunk/LayoutTests/fast/images/text-recognition/image-overlay-block-horizontal-overflow.html (rev 0)
+++ trunk/LayoutTests/fast/images/text-recognition/image-overlay-block-horizontal-overflow.html 2022-01-12 23:13:39 UTC (rev 287954)
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+body, html {
+ margin: 0;
+}
+
+.cover-block-container {
+ position: absolute;
+ top: 0;
+ left: 0;
+ width: 200px;
+ height: 200px;
+ background-color: black;
+}
+</style>
+</head>
+<body>
+<img src=""
+<div class="cover-block-container"></div>
+<script>
+addEventListener("load", () => {
+ let image = document.querySelector("img");
+ internals.installImageOverlay(image, [], [
+ {
+ topLeft : new DOMPointReadOnly(0.1, 0.1),
+ topRight : new DOMPointReadOnly(0.4, 0.1),
+ bottomRight : new DOMPointReadOnly(0.4, 0.4),
+ bottomLeft : new DOMPointReadOnly(0.1, 0.4),
+ text : "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
+ }
+ ]);
+ const block = internals.shadowRoot(image).querySelector("div.image-overlay-block");
+ block.style.overflow = "visible";
+});
+</script>
+</body>
+</html>
\ No newline at end of file
Modified: trunk/Source/WebCore/ChangeLog (287953 => 287954)
--- trunk/Source/WebCore/ChangeLog 2022-01-12 22:59:04 UTC (rev 287953)
+++ trunk/Source/WebCore/ChangeLog 2022-01-12 23:13:39 UTC (rev 287954)
@@ -1,5 +1,24 @@
2022-01-12 Wenson Hsieh <wenson_hs...@apple.com>
+ Live Text is sometimes horizontally clipped when injecting TextRecognitionBlockData
+ https://bugs.webkit.org/show_bug.cgi?id=235122
+
+ Reviewed by Devin Rousso.
+
+ The current heuristic for sizing Live Text paragraphs avoids vertical overflow, but does not avoid horizontal
+ overflow. Line breaking inside the fixed-width container prevents the latter in most cases, but not in the
+ scenario where the recognized text block is a single word with no opportunity for line break.
+
+ Address this by adjusting the sizing heuristic to shrink both the width and height to fit within the target size
+ (rather than just fitting the height).
+
+ Test: fast/images/text-recognition/image-overlay-block-horizontal-overflow.html
+
+ * dom/ImageOverlay.cpp:
+ (WebCore::ImageOverlay::updateWithTextRecognitionResult):
+
+2022-01-12 Wenson Hsieh <wenson_hs...@apple.com>
+
[macOS] [WK2] NSFontPanel UI (font color, text decorations, font shadow) doesn't update on selection change
https://bugs.webkit.org/show_bug.cgi?id=190120
rdar://44897405
Modified: trunk/Source/WebCore/dom/ImageOverlay.cpp (287953 => 287954)
--- trunk/Source/WebCore/dom/ImageOverlay.cpp 2022-01-12 22:59:04 UTC (rev 287953)
+++ trunk/Source/WebCore/dom/ImageOverlay.cpp 2022-01-12 23:13:39 UTC (rev 287954)
@@ -522,7 +522,7 @@
struct FontSizeAdjustmentState {
Ref<HTMLElement> container;
- float targetHeight;
+ FloatSize targetSize;
float scale { initialScaleForFontSize };
float minScale { minScaleForFontSize };
float maxScale { maxScaleForFontSize };
@@ -541,7 +541,7 @@
auto blockContainer = elements.blocks[index];
auto bounds = fitElementToQuad(blockContainer.get(), convertToContainerCoordinates(block.normalizedQuad));
blockContainer->setInlineStyleProperty(CSSPropertyFontSize, initialScaleForFontSize * bounds.size.height(), CSSUnitType::CSS_PX);
- elementsToAdjust.uncheckedAppend({ WTFMove(blockContainer), bounds.size.height() });
+ elementsToAdjust.uncheckedAppend({ WTFMove(blockContainer), bounds.size });
}
unsigned currentIteration = 0;
@@ -563,7 +563,7 @@
continue;
}
- auto currentScore = textRenderer->linesBoundingBox().height() / state.targetHeight;
+ auto currentScore = (textRenderer->linesBoundingBox().size() / state.targetSize).maxDimension();
if (currentScore < minTargetScore)
state.minScale = state.scale;
else if (currentScore > maxTargetScore)
@@ -574,7 +574,7 @@
}
state.scale = (state.minScale + state.maxScale) / 2;
- state.container->setInlineStyleProperty(CSSPropertyFontSize, state.targetHeight * state.scale, CSSUnitType::CSS_PX);
+ state.container->setInlineStyleProperty(CSSPropertyFontSize, state.targetSize.height() * state.scale, CSSUnitType::CSS_PX);
}
elementsToAdjust.removeAllMatching([](auto& state) {
@@ -584,7 +584,7 @@
if (++currentIteration > iterationLimit) {
// Fall back to the largest font size that still vertically fits within the container.
for (auto& state : elementsToAdjust)
- state.container->setInlineStyleProperty(CSSPropertyFontSize, state.targetHeight * state.minScale, CSSUnitType::CSS_PX);
+ state.container->setInlineStyleProperty(CSSPropertyFontSize, state.targetSize.height() * state.minScale, CSSUnitType::CSS_PX);
break;
}
}