Skip to content

Commit ac14cee

Browse files
committed
Add getLongestLine
1 parent 32f990b commit ac14cee

File tree

6 files changed

+17
-2
lines changed

6 files changed

+17
-2
lines changed

package/cpp/api/JsiSkParagraph.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ class JsiSkParagraph : public JsiSkHostObject {
6363
return static_cast<double>(_paragraph->getMinIntrinsicWidth());
6464
}
6565

66+
JSI_HOST_FUNCTION(getLongestLine) {
67+
return static_cast<double>(_paragraph->getLongestLine());
68+
}
69+
6670
JSI_HOST_FUNCTION(getGlyphPositionAtCoordinate) {
6771
auto dx = getArgumentAsNumber(runtime, arguments, count, 0);
6872
auto dy = getArgumentAsNumber(runtime, arguments, count, 1);
@@ -123,6 +127,7 @@ class JsiSkParagraph : public JsiSkHostObject {
123127
JSI_EXPORT_FUNC(JsiSkParagraph, getMaxWidth),
124128
JSI_EXPORT_FUNC(JsiSkParagraph, getMinIntrinsicWidth),
125129
JSI_EXPORT_FUNC(JsiSkParagraph, getMaxIntrinsicWidth),
130+
JSI_EXPORT_FUNC(JsiSkParagraph, getLongestLine),
126131
JSI_EXPORT_FUNC(JsiSkParagraph, getHeight),
127132
JSI_EXPORT_FUNC(JsiSkParagraph, getRectsForPlaceholders),
128133
JSI_EXPORT_FUNC(JsiSkParagraph,
Binary file not shown.
89 Bytes
Loading

package/src/renderer/__tests__/e2e/Paragraphs.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,9 +518,9 @@ describe("Paragraphs", () => {
518518
paint.setColor(Skia.Color("cyan"));
519519
const maxWidth = para.getMaxWidth();
520520
const height = para.getHeight();
521-
const maxIntrinsicWidth = para.getMaxIntrinsicWidth();
521+
const longestLine = para.getLongestLine();
522522
// The width of the bounding box is the smaller of the maximum width or the maximum intrinsic width
523-
const width = Math.min(maxWidth, maxIntrinsicWidth);
523+
const width = Math.min(maxWidth, longestLine);
524524
canvas.drawRect(Skia.XYWHRect(0, 0, width, height), paint);
525525
para.paint(canvas, 0, 0);
526526
},

package/src/skia/types/Paragraph/Paragraph.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ export interface SkParagraph extends SkJSIInstance<"Paragraph"> {
5151
*/
5252
getMaxIntrinsicWidth(): number;
5353

54+
/**
55+
* Returns the width of the longest line in the paragraph.
56+
* This method requires the layout method to have been called first.
57+
*/
58+
getLongestLine(): number;
59+
5460
/**
5561
* Returns the index of the glyph at the given position. This method requires
5662
* the layout method to have been called first.

package/src/skia/web/JsiSkParagraph.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ export class JsiSkParagraph
2020
return this.ref.getMaxIntrinsicWidth();
2121
}
2222

23+
getLongestLine(): number {
24+
return this.ref.getLongestLine();
25+
}
26+
2327
layout(width: number): void {
2428
this.ref.layout(width);
2529
}

0 commit comments

Comments
 (0)