diff --git a/tests/YGRoundingFunctionTest.cpp b/tests/YGRoundingFunctionTest.cpp index 47efcbc4f4..0c10e011f3 100644 --- a/tests/YGRoundingFunctionTest.cpp +++ b/tests/YGRoundingFunctionTest.cpp @@ -181,3 +181,27 @@ TEST(YogaTest, raw_layout_dimensions) { YGConfigFree(config); } + +TEST(YogaTest, roundLayoutResultsToPixelGrid_height_rounding_up) { + YGConfigRef config = YGConfigNew(); + YGConfigSetPointScaleFactor(config, 3); + + YGNodeRef node = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(node, YGPositionTypeAbsolute); + + // These are values extracted from a debugging session in a real iOS app + YGNodeStyleSetPosition(node, YGEdgeLeft, 38.333333969116211); + YGNodeStyleSetPosition(node, YGEdgeTop, 1970.3333333432674); + YGNodeStyleSetWidth(node, 339.66665649414063); + YGNodeStyleSetHeight(node, 96); + YGNodeSetNodeType(node, YGNodeTypeText); + + YGNodeCalculateLayout(node, YGUndefined, YGUndefined, YGDirectionLTR); + + // If this value is anything less than 96, iOS will not wrap the text to a 4th line + ASSERT_FLOAT_EQ(YGNodeLayoutGetHeight(node), 96.0f); + + YGNodeFreeRecursive(node); + + YGConfigFree(config); +} diff --git a/yoga/algorithm/PixelGrid.cpp b/yoga/algorithm/PixelGrid.cpp index 61de2be2e8..b2298c15e0 100644 --- a/yoga/algorithm/PixelGrid.cpp +++ b/yoga/algorithm/PixelGrid.cpp @@ -116,15 +116,23 @@ void roundLayoutResultsToPixelGrid( roundValueToPixelGrid( absoluteNodeLeft, pointScaleFactor, false, textRounding)); - node->getLayout().setDimension( - Dimension::Height, - roundValueToPixelGrid( - absoluteNodeBottom, - pointScaleFactor, - (textRounding && hasFractionalHeight), - (textRounding && !hasFractionalHeight)) - - roundValueToPixelGrid( - absoluteNodeTop, pointScaleFactor, false, textRounding)); + // -- Height -- + const float roundedBottom = roundValueToPixelGrid( + absoluteNodeBottom, + pointScaleFactor, + (textRounding && hasFractionalHeight), + (textRounding && !hasFractionalHeight)); + const float roundedTop = roundValueToPixelGrid( + absoluteNodeTop, pointScaleFactor, false, textRounding); + + const float roundedHeight = roundValueToPixelGrid( + roundedBottom - roundedTop, + pointScaleFactor, + false, // Don't force ceil for height calculation + false // Don't force floor for height calculation + ); + + node->getLayout().setDimension(Dimension::Height, roundedHeight); } for (yoga::Node* child : node->getChildren()) {