diff --git a/packages/react-native/Libraries/Text/__tests__/Text-itest.js b/packages/react-native/Libraries/Text/__tests__/Text-itest.js index 0d0b98090978..890e3cdc1d55 100644 --- a/packages/react-native/Libraries/Text/__tests__/Text-itest.js +++ b/packages/react-native/Libraries/Text/__tests__/Text-itest.js @@ -11,7 +11,7 @@ import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment'; import type {HostInstance} from 'react-native'; -import type {AccessibilityProps} from 'react-native'; +import type {AccessibilityProps, TextLayoutEvent} from 'react-native'; import accessibilityPropsSuite, { rolePropSuite, @@ -22,7 +22,7 @@ import * as Fantom from '@react-native/fantom'; import nullthrows from 'nullthrows'; import * as React from 'react'; import {createRef} from 'react'; -import {Text} from 'react-native'; +import {Text, View} from 'react-native'; const TEST_TEXT = 'the text'; @@ -651,6 +651,300 @@ describe('', () => { }); }); + describe('onTextLayout', () => { + it('reports each line where it is drawn', () => { + const lines: Array<{ + text: string, + x: number, + width: number, + capHeight: number, + xHeight: number, + height: number, + ascender: number, + descender: number, + }> = []; + const root = Fantom.createRoot(); + + Fantom.runTask(() => { + root.render( + { + for (const line of event.nativeEvent.lines) { + lines.push({ + text: line.text, + x: line.x, + width: line.width, + capHeight: line.capHeight, + xHeight: line.xHeight, + height: line.height, + ascender: line.ascender, + descender: line.descender, + }); + } + }} + style={{width: 200, textAlign: 'center'}}> + {TEST_TEXT} + , + ); + }); + Fantom.flushAllNativeEvents(); + + expect(lines).toHaveLength(1); + expect(lines[0].text).toBe(TEST_TEXT); + expect(lines[0].width).toBeGreaterThan(0); + expect(lines[0].width).toBeLessThan(200); + expect(lines[0].x).toBeCloseTo((200 - lines[0].width) / 2); + expect(lines[0].xHeight).toBeGreaterThan(0); + expect(lines[0].capHeight).toBeGreaterThan(lines[0].xHeight); + expect(lines[0].ascender).toBeGreaterThan(lines[0].capHeight); + expect(lines[0].ascender + lines[0].descender).toBeCloseTo( + lines[0].height, + ); + }); + + it('draws the lines it reports when only `numberOfLines` changes', () => { + const LONG_TEXT = 'the text that is long enough to wrap onto more lines'; + const renderText = ( + root: ReturnType, + numberOfLines: number, + ): ReadonlyArray => { + let reportedLines: ReadonlyArray = []; + Fantom.runTask(() => { + root.render( + { + reportedLines = event.nativeEvent.lines.map(line => line.text); + }} + style={{width: 100, height: 60}}> + {LONG_TEXT} + , + ); + }); + Fantom.flushAllNativeEvents(); + return reportedLines; + }; + + const changedRoot = Fantom.createRoot(); + expect(renderText(changedRoot, 2)).toHaveLength(2); + const twoLines = changedRoot.takeScreenshot(); + expect(renderText(changedRoot, 1)).toHaveLength(1); + const oneLineRoot = Fantom.createRoot(); + renderText(oneLineRoot, 1); + + expect(twoLines.isEqual(oneLineRoot.takeScreenshot())).toBe(false); + expect( + changedRoot.takeScreenshot().isEqual(oneLineRoot.takeScreenshot()), + ).toBe(true); + }); + + it('draws the lines it reports for a selectable text', () => { + const renderText = ( + root: ReturnType, + selectable: boolean, + ): ReadonlyArray => { + let reportedLines: ReadonlyArray = []; + Fantom.runTask(() => { + root.render( + { + reportedLines = event.nativeEvent.lines.map(line => line.text); + }} + selectable={selectable} + style={{width: 100}}> + {TEST_TEXT} + , + ); + }); + Fantom.flushAllNativeEvents(); + return reportedLines; + }; + + const selectableRoot = Fantom.createRoot(); + expect(renderText(selectableRoot, true)).toEqual([TEST_TEXT]); + const plainRoot = Fantom.createRoot(); + renderText(plainRoot, false); + const emptyRoot = Fantom.createRoot(); + Fantom.runTask(() => { + emptyRoot.render(); + }); + + expect( + selectableRoot.takeScreenshot().isEqual(plainRoot.takeScreenshot()), + ).toBe(true); + expect( + selectableRoot.takeScreenshot().isEqual(emptyRoot.takeScreenshot()), + ).toBe(false); + }); + + it('ends a cut last line with an ellipsis (plain text only)', () => { + const LONG_TEXT = + 'The quick brown fox jumps over the lazy dog again and again'; + const linesByText: {[name: string]: ReadonlyArray} = {}; + let blankLineLines: TextLayoutEvent['nativeEvent']['lines'] = []; + const reportLines = + (name: string) => + (event: TextLayoutEvent): void => { + linesByText[name] = event.nativeEvent.lines.map(line => line.text); + if (name === 'blankLine') { + blankLineLines = event.nativeEvent.lines; + } + }; + + const root = Fantom.createRoot(); + Fantom.runTask(() => { + root.render( + + + {LONG_TEXT} + + + The quick fox + + + {'The quick brown '} + + {' fox jumps over the lazy dog again and again'} + + + {'\u{1F600}\u{1F600}\u{1F600} and more text after them'} + + + {'Title\n\nMore details'} + + + {'Title\nMore'} + + + {`Title\nMore${' '.repeat(100)}\n`} + + + {'Title\n'} + + + , + ); + }); + Fantom.flushAllNativeEvents(); + + expect(linesByText.cut).toHaveLength(2); + expect(linesByText.cut[1].endsWith('\u2026')).toBe(true); + expect(linesByText.fitting).toEqual(['The quick fox']); + // With an inline view or shaped emoji on the last line, the cut stays without an ellipsis. + expect(linesByText.inlineView).toHaveLength(2); + expect(linesByText.inlineView[1].endsWith('\u2026')).toBe(false); + expect(linesByText.emoji).toHaveLength(1); + expect(linesByText.emoji[0].endsWith('\u2026')).toBe(false); + // A blank line cut by a hard break still marks the cut. + expect(linesByText.blankLine).toEqual(['Title', '\u2026']); + // The ellipsis on a blank line has the metrics of its font, like the line above. + expect(blankLineLines[1].capHeight).toBeCloseTo( + blankLineLines[0].capHeight, + ); + expect(blankLineLines[1].xHeight).toBeCloseTo(blankLineLines[0].xHeight); + expect(blankLineLines[1].xHeight).toBeGreaterThan(0); + expect(linesByText.fittingLines).toEqual(['Title', 'More']); + // Spaces wrapped before a final line break cut no text. + expect(linesByText.trailingSpaces).toEqual(['Title', 'More']); + // An inline view on a line that was cut away does not stop the ellipsis. + expect(linesByText.clippedView).toEqual(['Title\u2026']); + }); + + it('draws the ellipsis after a cut emoji in a font that has it', () => { + const renderText = ( + root: ReturnType, + text: string, + numberOfLines: number, + ): ReadonlyArray => { + let reportedLines: ReadonlyArray = []; + Fantom.runTask(() => { + root.render( + + { + reportedLines = event.nativeEvent.lines.map( + line => line.text, + ); + }}> + {text} + + , + ); + }); + Fantom.flushAllNativeEvents(); + return reportedLines; + }; + + const cutRoot = Fantom.createRoot(); + const [cutLine] = renderText( + cutRoot, + 'Nice \u{1F600}\nmore words after the line break', + 1, + ); + const typedRoot = Fantom.createRoot(); + renderText(typedRoot, 'Nice \u{1F600}\u2026', 1); + + expect(cutLine).toBe('Nice \u{1F600}\u2026'); + expect(cutRoot.takeScreenshot().isEqual(typedRoot.takeScreenshot())).toBe( + true, + ); + }); + + it('reports the same lines for a cut text that shrinks to fit', () => { + const LONG_TEXT = + 'The quick brown fox jumps over the lazy dog again and again'; + const cases = Array.from({length: 61}, (_, i) => ({ + numberOfLines: 1 + (i % 2), + width: 80 + i, + stretchedLines: [] as Array, + shrunkLines: [] as Array, + })); + const root = Fantom.createRoot(); + Fantom.runTask(() => { + root.render( + <> + {cases.map(testCase => ( + + + { + testCase.stretchedLines = event.nativeEvent.lines.map( + line => line.text, + ); + }}> + {LONG_TEXT} + + + + { + testCase.shrunkLines = event.nativeEvent.lines.map( + line => line.text, + ); + }}> + {LONG_TEXT} + + + + ))} + , + ); + }); + Fantom.flushAllNativeEvents(); + + for (const {numberOfLines, stretchedLines, shrunkLines} of cases) { + expect(stretchedLines).toHaveLength(numberOfLines); + expect(stretchedLines[numberOfLines - 1].endsWith('\u2026')).toBe(true); + expect(shrunkLines).toEqual(stretchedLines); + } + }); + }); + describe('ref', () => { it('is a element node', () => { const elementRef = createRef(); diff --git a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/cxx/react/renderer/textlayoutmanager/TextLayoutManager.cpp b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/cxx/react/renderer/textlayoutmanager/TextLayoutManager.cpp index 0444a94b25cc..cb88a07c89cf 100644 --- a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/cxx/react/renderer/textlayoutmanager/TextLayoutManager.cpp +++ b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/cxx/react/renderer/textlayoutmanager/TextLayoutManager.cpp @@ -36,4 +36,11 @@ TextMeasurement TextLayoutManager::measure( .attachments = attachments}; } +LinesMeasurements TextLayoutManager::measureLines( + const AttributedStringBox& /*attributedStringBox*/, + const ParagraphAttributes& /*paragraphAttributes*/, + const Size& /*size*/) const { + return {}; +} + } // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/cxx/react/renderer/textlayoutmanager/TextLayoutManager.h b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/cxx/react/renderer/textlayoutmanager/TextLayoutManager.h index 9cf9543b6282..6fdd865ecafa 100644 --- a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/cxx/react/renderer/textlayoutmanager/TextLayoutManager.h +++ b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/cxx/react/renderer/textlayoutmanager/TextLayoutManager.h @@ -51,6 +51,16 @@ class TextLayoutManager { const TextLayoutContext &layoutContext, const LayoutConstraints &layoutConstraints) const; + /* + * Measures the lines of `attributedStringBox` laid out at `size`. This + * implementation does not lay text out and returns no lines; a subclass that + * does, such as Fantom's `FantomTextLayoutManager`, overrides it. + */ + virtual LinesMeasurements measureLines( + const AttributedStringBox &attributedStringBox, + const ParagraphAttributes ¶graphAttributes, + const Size &size) const; + protected: std::shared_ptr contextContainer_; TextMeasureCache textMeasureCache_; diff --git a/private/react-native-fantom/__docs__/rendering.md b/private/react-native-fantom/__docs__/rendering.md index 9b61b29059fe..f77d47d80730 100644 --- a/private/react-native-fantom/__docs__/rendering.md +++ b/private/react-native-fantom/__docs__/rendering.md @@ -33,8 +33,12 @@ without custom path mappings. Keep a fixture alongside the test that uses it. Default color emoji selection follows Unicode 16.0 `Emoji_Presentation`. Explicit text and emoji variation selectors override that default. Selectors and keycap sequences stay with their bases during fallback and wrapping; HarfBuzz -shapes color emoji sequences for both measurement and painting. General script -shaping, text decorations and ellipsis are not implemented. +shapes color emoji sequences for both measurement and painting. With the default +`ellipsizeMode` (`tail`), text cut by `numberOfLines` ends with a tail ellipsis, +except when its last visible line has an inline view or shaped emoji, or when +only spaces were cut. A trailing line break adds no empty last line. General +script shaping, text decorations and head or middle ellipsis are not +implemented. ### Public native build diff --git a/private/react-native-fantom/src/__tests__/__snapshots__/FantomScreenSnapshots-itest.js.screenshots/Fantom_screen_snapshots_captures_the_feed_and_its_scrolled_viewport_1-7d02926c-40d84b27.png b/private/react-native-fantom/src/__tests__/__snapshots__/FantomScreenSnapshots-itest.js.screenshots/Fantom_screen_snapshots_captures_the_feed_and_its_scrolled_viewport_1-7d02926c-40d84b27.png index fa1ac63f5b78..fd7ad8f2c180 100644 Binary files a/private/react-native-fantom/src/__tests__/__snapshots__/FantomScreenSnapshots-itest.js.screenshots/Fantom_screen_snapshots_captures_the_feed_and_its_scrolled_viewport_1-7d02926c-40d84b27.png and b/private/react-native-fantom/src/__tests__/__snapshots__/FantomScreenSnapshots-itest.js.screenshots/Fantom_screen_snapshots_captures_the_feed_and_its_scrolled_viewport_1-7d02926c-40d84b27.png differ diff --git a/private/react-native-fantom/src/__tests__/__snapshots__/FantomScreenSnapshots-itest.js.snap b/private/react-native-fantom/src/__tests__/__snapshots__/FantomScreenSnapshots-itest.js.snap index b55f4182ac74..61c91562257c 100644 --- a/private/react-native-fantom/src/__tests__/__snapshots__/FantomScreenSnapshots-itest.js.snap +++ b/private/react-native-fantom/src/__tests__/__snapshots__/FantomScreenSnapshots-itest.js.snap @@ -9,7 +9,7 @@ Object { exports[`Fantom screen snapshots captures the feed and its scrolled viewport 1`] = ` Object { - "hash": "a71fd606e25d99e9afc33d276138ae2db1d42352ec0995d23bdaefab811eba17", + "hash": "16b6dd92373af0ffaa0b670193ed834214e9c14f21d5b3cf693138e977141112", "type": "Screenshot", } `; diff --git a/private/react-native-fantom/tester/src/render/ImageRenderer.cpp b/private/react-native-fantom/tester/src/render/ImageRenderer.cpp index 6848f06a43e3..0f8aca0d9236 100644 --- a/private/react-native-fantom/tester/src/render/ImageRenderer.cpp +++ b/private/react-native-fantom/tester/src/render/ImageRenderer.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -314,7 +315,7 @@ void paintView( } const std::string_view name(view.componentName ? view.componentName : ""); - if (name == "Paragraph" && view.state) { + if ((name == "Paragraph" || name == "SelectableParagraph") && view.state) { const auto& state = static_cast&>(*view.state) .getData(); @@ -327,7 +328,9 @@ void paintView( layoutText( &canvas, state.attributedString, - state.paragraphAttributes, + // As on iOS, from the props: the state keeps the attributes it was + // created with when only they change. + static_cast(*view.props).paragraphAttributes, frame.size.width), frame.size.width); canvas.restore(); diff --git a/private/react-native-fantom/tester/src/render/TextLayout.cpp b/private/react-native-fantom/tester/src/render/TextLayout.cpp index a065fd528ea6..89e3c13295e9 100644 --- a/private/react-native-fantom/tester/src/render/TextLayout.cpp +++ b/private/react-native-fantom/tester/src/render/TextLayout.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #ifndef FANTOM_SKIA_FACTORY_PROVIDED /* static */ sk_sp SkFontMgr::Factory() { @@ -390,6 +391,130 @@ SkFont applyFont(SkCanvas* /*canvas*/, const TextAttributes& attributes) { return font; } +// Where `text` must end, at a text unit boundary, to fit in `limit` with +// `font`, and how wide that start of it is. +static std::pair +fittingPrefix(const std::string& text, const SkFont& font, Float limit) { + Float width = 0; + size_t end = 0; + while (end < text.size()) { + const auto next = nextTextUnitEnd(text, end); + const auto unit = std::string_view(text).substr(end, next - end); + const auto advance = + font.measureText(unit.data(), unit.size(), SkTextEncoding::kUTF8); + if (width + advance > limit) { + break; + } + width += advance; + end = next; + } + return {end, width}; +} + +// Ends a cut paragraph's last line with "…", keeping the longest start of it +// that fits with the ellipsis. Runs are unshaped text (see the caller). +static void ellipsizeTail(TextLine& line, Float maximumWidth) { + if (line.runs.empty() && !line.breakAttributes.has_value()) { + return; + } + const std::string ellipsis = "\u2026"; + auto attributes = + line.runs.empty() ? *line.breakAttributes : line.runs.back().attributes; + // An emoji font has no ellipsis glyph. + if (!hasGlyphs(applyFont(nullptr, attributes), ellipsis)) { + attributes.fontFamily = fallbackFamily(ellipsis, attributes); + } + const auto ascent = line.runs.empty() ? line.ascent : line.runs.back().ascent; + const auto ellipsisFont = applyFont(nullptr, attributes); + const auto ellipsisWidth = ellipsisFont.measureText( + ellipsis.data(), ellipsis.size(), SkTextEncoding::kUTF8); + while (!line.runs.empty() && line.width + ellipsisWidth > maximumWidth) { + auto& run = line.runs.back(); + const auto [end, width] = fittingPrefix( + run.text, + applyFont(nullptr, run.attributes), + maximumWidth - ellipsisWidth - run.x); + if (end > 0) { + run.text.resize(end); + run.width = width; + line.width = run.x + width; + break; + } + line.width = run.x; + line.runs.pop_back(); + } + SkFontMetrics metrics{}; + ellipsisFont.getMetrics(&metrics); + line.capHeight = + std::max(line.capHeight, static_cast(metrics.fCapHeight)); + line.xHeight = std::max(line.xHeight, static_cast(metrics.fXHeight)); + line.runs.push_back( + {ellipsis, attributes, line.width, ellipsisWidth, ascent, nullptr}); + line.width += ellipsisWidth; +} + +// Inline views are not runs, and shaped runs (emoji) cannot be cut at a +// character, so a last line with either is cut without an ellipsis instead. +static bool canEllipsize(const TextLayout& layout) { + Float lastLineTop = 0; + for (size_t i = 0; i + 1 < layout.lines.size(); ++i) { + lastLineTop += layout.lines[i].height; + } + const auto& attachments = layout.measurement.attachments; + const bool hasInlineViewOnLastLine = std::any_of( + attachments.begin(), attachments.end(), [&](const auto& attachment) { + return !attachment.isClipped && + attachment.frame.origin.y >= lastLineTop; + }); + if (hasInlineViewOnLastLine) { + return false; + } + return std::none_of( + layout.lines.back().runs.begin(), + layout.lines.back().runs.end(), + [](const TextRun& run) { return run.blob != nullptr; }); +} + +// A line a hard break ends before any text keeps the break's height, ascent +// and style. +static void endWithHardBreak( + TextLine& line, + Float height, + Float ascent, + const TextAttributes& attributes) { + line.height = std::max(line.height, height); + if (!line.runs.empty()) { + return; + } + line.ascent = std::max(line.ascent, ascent); + line.breakAttributes = attributes; +} + +static bool hasText(const TextLine& line) { + return std::any_of(line.runs.begin(), line.runs.end(), [](const auto& run) { + return run.text.find_first_not_of(" \t") != std::string::npos; + }); +} + +// Whether the lines after the first `count` show anything: text other than +// spaces, or an inline view. Spaces wrapped before a final line break leave an +// empty line that cuts nothing. +static bool hasContentAfter(const TextLayout& layout, int count) { + const auto& attachments = layout.measurement.attachments; + if (std::any_of( + attachments.begin(), attachments.end(), [](const auto& attachment) { + return attachment.isClipped; + })) { + return true; + } + for (auto i = static_cast(count); i < layout.lines.size(); ++i) { + if (hasText(layout.lines[i])) { + return true; + } + } + return false; +} + TextLayout layoutText( SkCanvas* canvas, const AttributedString& text, @@ -438,6 +563,9 @@ TextLayout layoutText( line.width += shaped.width; line.height = std::max(line.height, height); line.ascent = std::max(line.ascent, static_cast(-font.fAscent)); + line.capHeight = + std::max(line.capHeight, static_cast(font.fCapHeight)); + line.xHeight = std::max(line.xHeight, static_cast(font.fXHeight)); }; if (fragment.isAttachment()) { @@ -459,7 +587,11 @@ TextLayout layoutText( // Break at whitespace, then at UTF-8 character boundaries for long words. for (size_t start = 0; start < fragment.string.size();) { if (fragment.string[start] == '\n') { - line.height = std::max(line.height, height); + endWithHardBreak( + line, + height, + static_cast(-font.fAscent), + fragment.textAttributes); finishLine(); ++start; continue; @@ -502,6 +634,7 @@ TextLayout layoutText( finishLine(); } if (static_cast(result.lines.size()) > maxLines) { + const bool cutsContent = hasContentAfter(result, maxLines); result.lines.resize(maxLines); result.measurement.size = {}; for (const auto& visibleLine : result.lines) { @@ -509,25 +642,46 @@ TextLayout layoutText( std::max(result.measurement.size.width, visibleLine.width); result.measurement.size.height += visibleLine.height; } + if (paragraph.ellipsizeMode == EllipsizeMode::Tail && cutsContent && + canEllipsize(result)) { + ellipsizeTail(result.lines.back(), maximumWidth); + // Wide enough for the lines before and after the ellipsis, so laying + // out again at the measured width gives the same lines. + result.measurement.size.width = + std::max(result.measurement.size.width, result.lines.back().width); + } } + return result; } +// How far below the line's top `paintText` puts its baseline. +static Float getLineBaseline(const TextLine& line) { + return (line.height - line.ascent) / 2 + line.ascent; +} + +// Where a line starts in a paragraph `width` wide, from its alignment. +static Float getLineOffset(const TextLine& line, Float width) { + if (line.runs.empty()) { + return 0; + } + const auto alignment = line.runs.front().attributes.alignment; + if (alignment == TextAlignment::Center) { + return (width - line.width) / 2; + } + if (alignment == TextAlignment::Right) { + return width - line.width; + } + return 0; +} + void paintText(SkCanvas* canvas, const TextLayout& layout, Float width) { if (canvas == nullptr) { throw std::invalid_argument("Fantom requires a canvas to paint text"); } Float y = 0; for (const auto& line : layout.lines) { - Float offset = 0; - if (!line.runs.empty()) { - const auto alignment = line.runs.front().attributes.alignment; - if (alignment == TextAlignment::Center) { - offset = (width - line.width) / 2; - } else if (alignment == TextAlignment::Right) { - offset = width - line.width; - } - } + const auto offset = getLineOffset(line, width); for (const auto& run : line.runs) { const auto font = applyFont(canvas, run.attributes); const auto opacity = @@ -551,7 +705,7 @@ void paintText(SkCanvas* canvas, const TextLayout& layout, Float width) { const auto color = run.attributes.foregroundColor ? run.attributes.foregroundColor : blackColor(); - const auto baseline = y + (line.height - line.ascent) / 2 + line.ascent; + const auto baseline = y + getLineBaseline(line); if (run.blob) { canvas->drawTextBlob( run.blob, offset + run.x, baseline, paintFor(color)); @@ -583,4 +737,43 @@ TextMeasurement FantomTextLayoutManager::measure( return result; } +LinesMeasurements FantomTextLayoutManager::measureLines( + const AttributedStringBox& text, + const ParagraphAttributes& paragraph, + const Size& size) const { + LinesMeasurements lines; + Float y = 0; + for (const auto& line : + layoutText(nullptr, text.getValue(), paragraph, size.width).lines) { + std::string lineText; + for (const auto& run : line.runs) { + lineText += run.text; + } + const auto ascender = getLineBaseline(line); + lines.emplace_back( + std::move(lineText), + Rect{ + .origin = {.x = getLineOffset(line, size.width), .y = y}, + .size = {.width = line.width, .height = line.height}}, + /* descender */ line.height - ascender, + line.capHeight, + ascender, + line.xHeight); + y += line.height; + } + // Like Android, a paragraph with no text still has one empty line. + if (lines.empty()) { + lines.emplace_back( + "", + Rect{ + .origin = {.x = 0, .y = 0}, + .size = {.width = 0, .height = size.height}}, + /* descender */ 0, + /* capHeight */ 0, + /* ascender */ 0, + /* xHeight */ 0); + } + return lines; +} + } // namespace facebook::react diff --git a/private/react-native-fantom/tester/src/render/TextLayout.h b/private/react-native-fantom/tester/src/render/TextLayout.h index 31ee898572cc..bcb110f9bdfc 100644 --- a/private/react-native-fantom/tester/src/render/TextLayout.h +++ b/private/react-native-fantom/tester/src/render/TextLayout.h @@ -14,6 +14,7 @@ #include #include #include +#include namespace facebook::react { @@ -31,6 +32,10 @@ struct TextLine { Float width{}; Float height{}; Float ascent{}; + Float capHeight{}; + Float xHeight{}; + // The style of a line ended by a hard break before any text. + std::optional breakAttributes; }; struct TextLayout { @@ -54,6 +59,8 @@ class FantomTextLayoutManager : public TextLayoutManager { const ParagraphAttributes ¶graph, const TextLayoutContext &context, const LayoutConstraints &constraints) const override; + LinesMeasurements + measureLines(const AttributedStringBox &text, const ParagraphAttributes ¶graph, const Size &size) const override; }; } // namespace facebook::react