@@ -17,26 +17,25 @@ ShadowNodeTraits PdfViewShadowNode::BaseTraits()
1717Size PdfViewShadowNode::measureContent (
1818 const LayoutContext& layoutContext,
1919 const LayoutConstraints& layoutConstraints) const {
20- int pageWidth = getStateData ().getPageWidth ();
21- int pageHeight = getStateData ().getPageHeight ();
22- Float aspectRatio = static_cast <Float>(pageWidth) / pageHeight;
23- Float targetWidth = layoutConstraints.maximumSize .height * aspectRatio;
24- if (std::isinf (layoutConstraints.maximumSize .width ) || layoutConstraints.maximumSize .width < 1 ) {
25- if (std::isinf (layoutConstraints.maximumSize .height ) || layoutConstraints.maximumSize .height < 1 ) {
26- // No restrictions on dimensions? Use pdf dimensions.
27- return {static_cast <Float>(pageWidth), static_cast <Float>(pageHeight)};
28- }
29- // No width requirements? Scale page to match requested height.
30- return {targetWidth, layoutConstraints.maximumSize .height };
20+ Float pageWidth = getStateData ().getPageWidth ();
21+ Float pageHeight = getStateData ().getPageHeight ();
22+ Float aspectRatio = pageWidth / pageHeight;
23+ if (std::isfinite (layoutConstraints.maximumSize .width )) {
24+ // Scale page to match requested width.
25+ pageWidth = layoutConstraints.maximumSize .width ;
26+ pageHeight = pageWidth / aspectRatio;
3127 }
32-
33- if (targetWidth <= layoutConstraints.maximumSize .width ) {
34- // When scaled to match requested height, page scaled width is
35- // within width bounds. Scale page to match requested height.
36- return {targetWidth, layoutConstraints.maximumSize .height };
28+ if (std::isfinite (layoutConstraints.maximumSize .height )) {
29+ // Scale page to match requested height.
30+ pageHeight = std::isfinite (layoutConstraints.maximumSize .width )
31+ ? std::min (pageHeight, layoutConstraints.maximumSize .height )
32+ : layoutConstraints.maximumSize .height ;
33+ pageWidth = pageHeight * aspectRatio;
3734 }
38- // Scale page to match requested width.
39- return {layoutConstraints.maximumSize .width , layoutConstraints.maximumSize .width / aspectRatio};
35+ return {
36+ std::max (pageWidth, layoutConstraints.minimumSize .width ),
37+ std::max (pageHeight, layoutConstraints.minimumSize .height )
38+ };
4039}
4140
4241} // namespace facebook::react
0 commit comments