From fd5392494fc547e049c933203953aeedd437175d Mon Sep 17 00:00:00 2001 From: generatedunixname499836121 Date: Mon, 19 Oct 2026 06:39:46 -0700 Subject: [PATCH] Keep the measured pixel size of text nodes when rounding to the pixel grid (#2040) Summary: When a text node's scaled size is a whole number of pixels, use that pixel count as its rounded size instead of the difference of its two rounded edges. The 0.0001 snap tolerance could snap one edge to a pixel and floor the other, which made the node one pixel smaller than its measured size and truncated its text. Reviewed By: cortinico Differential Revision: D125427541 fbshipit-source-id: 4fdd9223120938b35c38fc75df1602cbbc01820a --- .../yoga/yoga/algorithm/PixelGrid.cpp | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/packages/react-native/ReactCommon/yoga/yoga/algorithm/PixelGrid.cpp b/packages/react-native/ReactCommon/yoga/yoga/algorithm/PixelGrid.cpp index 476b316d3c5..529dedf4ddb 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/algorithm/PixelGrid.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/algorithm/PixelGrid.cpp @@ -112,9 +112,9 @@ void roundLayoutResultsToPixelGrid( // whole number, we don't have any fraction To verify if the result is close // to whole number we want to check both floor and ceil numbers - const double scaledNodeWith = nodeWidth * pointScaleFactor; + const double scaledNodeWidth = nodeWidth * pointScaleFactor; const bool hasFractionalWidth = - !yoga::inexactEquals(round(scaledNodeWith), scaledNodeWith); + !yoga::inexactEquals(round(scaledNodeWidth), scaledNodeWidth); const double scaledNodeHeight = nodeHeight * pointScaleFactor; const bool hasFractionalHeight = @@ -122,25 +122,32 @@ void roundLayoutResultsToPixelGrid( node->getLayout().setDimension( Dimension::Width, - static_cast( - roundValueToPixelGridDouble( - absoluteNodeRight, - pointScaleFactor, - (textRounding && hasFractionalWidth), - (textRounding && !hasFractionalWidth)) - - roundValueToPixelGridDouble( - absoluteNodeLeft, pointScaleFactor, false, textRounding))); + textRounding && !hasFractionalWidth + ? static_cast(round(scaledNodeWidth) / pointScaleFactor) + : static_cast( + roundValueToPixelGridDouble( + absoluteNodeRight, + pointScaleFactor, + textRounding, + false) - + roundValueToPixelGridDouble( + absoluteNodeLeft, + pointScaleFactor, + false, + textRounding))); node->getLayout().setDimension( Dimension::Height, - static_cast( - roundValueToPixelGridDouble( - absoluteNodeBottom, - pointScaleFactor, - (textRounding && hasFractionalHeight), - (textRounding && !hasFractionalHeight)) - - roundValueToPixelGridDouble( - absoluteNodeTop, pointScaleFactor, false, textRounding))); + textRounding && !hasFractionalHeight + ? static_cast(round(scaledNodeHeight) / pointScaleFactor) + : static_cast( + roundValueToPixelGridDouble( + absoluteNodeBottom, + pointScaleFactor, + textRounding, + false) - + roundValueToPixelGridDouble( + absoluteNodeTop, pointScaleFactor, false, textRounding))); } for (yoga::Node* child : node->getChildren()) {