mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
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
This commit is contained in:
1 parent
4de5b675b0
commit
fd5392494f
1 file changed
+25
-18
@@ -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<float>(
|
||||
roundValueToPixelGridDouble(
|
||||
absoluteNodeRight,
|
||||
pointScaleFactor,
|
||||
(textRounding && hasFractionalWidth),
|
||||
(textRounding && !hasFractionalWidth)) -
|
||||
roundValueToPixelGridDouble(
|
||||
absoluteNodeLeft, pointScaleFactor, false, textRounding)));
|
||||
textRounding && !hasFractionalWidth
|
||||
? static_cast<float>(round(scaledNodeWidth) / pointScaleFactor)
|
||||
: static_cast<float>(
|
||||
roundValueToPixelGridDouble(
|
||||
absoluteNodeRight,
|
||||
pointScaleFactor,
|
||||
textRounding,
|
||||
false) -
|
||||
roundValueToPixelGridDouble(
|
||||
absoluteNodeLeft,
|
||||
pointScaleFactor,
|
||||
false,
|
||||
textRounding)));
|
||||
|
||||
node->getLayout().setDimension(
|
||||
Dimension::Height,
|
||||
static_cast<float>(
|
||||
roundValueToPixelGridDouble(
|
||||
absoluteNodeBottom,
|
||||
pointScaleFactor,
|
||||
(textRounding && hasFractionalHeight),
|
||||
(textRounding && !hasFractionalHeight)) -
|
||||
roundValueToPixelGridDouble(
|
||||
absoluteNodeTop, pointScaleFactor, false, textRounding)));
|
||||
textRounding && !hasFractionalHeight
|
||||
? static_cast<float>(round(scaledNodeHeight) / pointScaleFactor)
|
||||
: static_cast<float>(
|
||||
roundValueToPixelGridDouble(
|
||||
absoluteNodeBottom,
|
||||
pointScaleFactor,
|
||||
textRounding,
|
||||
false) -
|
||||
roundValueToPixelGridDouble(
|
||||
absoluteNodeTop, pointScaleFactor, false, textRounding)));
|
||||
}
|
||||
|
||||
for (yoga::Node* child : node->getChildren()) {
|
||||
|
||||
Reference in new issue
Block a user