@@ -52,28 +52,45 @@ bool ElementImage::GetIntrinsicDimensions(Vector2f& _dimensions, float& _ratio)
52
52
{
53
53
EnsureSourceLoaded ();
54
54
55
- // Calculate the x dimension.
56
- if (HasAttribute (" width" ))
57
- dimensions.x = GetAttribute<float >(" width" , -1 );
58
- else if (rect_source == RectSource::None)
55
+ if (rect_source == RectSource::None)
56
+ {
59
57
dimensions.x = (float )texture.GetDimensions ().x ;
60
- else
61
- dimensions.x = rect.Width ();
62
-
63
- // Calculate the y dimension.
64
- if (HasAttribute (" height" ))
65
- dimensions.y = GetAttribute<float >(" height" , -1 );
66
- else if (rect_source == RectSource::None)
67
58
dimensions.y = (float )texture.GetDimensions ().y ;
68
- else
59
+ } else
60
+ {
61
+ dimensions.x = rect.Width ();
69
62
dimensions.y = rect.Height ();
63
+ }
64
+
65
+ // Calculate the source ratio
66
+ _ratio = dimensions.x / dimensions.y ;
67
+
68
+ // Scale based on attributes (this only appears to be done by LayoutDetails for CSS set height/width)
69
+ auto requested_width = GetAttribute<float >(" width" , -1 );
70
+ auto requested_height = GetAttribute<float >(" height" , -1 );
71
+ if (requested_height>0 && requested_width>0 )
72
+ {
73
+ // If both a height and width are set update the ratio to match
74
+ _ratio = requested_width / requested_height;
75
+ dimensions.x = requested_width;
76
+ dimensions.y = requested_height;
77
+ }
78
+ else if (requested_height>0 )
79
+ {
80
+ dimensions.x = requested_height * _ratio;
81
+ dimensions.y = requested_height;
82
+ }
83
+ else if (requested_width>0 )
84
+ {
85
+ dimensions.x = requested_width;
86
+ dimensions.y = requested_width / _ratio;
87
+ }
70
88
71
89
dimensions *= dimensions_scale;
72
90
73
91
// Return the calculated dimensions. If this changes the size of the element, it will result in
74
92
// a call to 'onresize' below which will regenerate the geometry.
75
93
_dimensions = dimensions;
76
- _ratio = dimensions.x / dimensions.y ;
77
94
78
95
return true ;
79
96
}
0 commit comments