@@ -125,13 +125,36 @@ fun buildOutline(
125125 size : Size ,
126126 layoutDirection : LayoutDirection ,
127127 density : Density
128- ): Triple <Float , Float , Outline > {
128+ ): Pair <Offset , Outline > {
129+
130+ val (shapeSize, offset) = calculateSizeAndOffsetFromAspectRatio(aspectRatio, coefficient, size)
131+
132+ val outline = shape.createOutline(
133+ size = shapeSize,
134+ layoutDirection = layoutDirection,
135+ density = density
136+ )
137+ return Pair (offset, outline)
138+ }
139+
140+
141+ /* *
142+ * Calculate new size and offset based on [size], [coefficient] and [aspectRatio]
143+ *
144+ * For 4/3f aspect ratio with 1000px width, 1000px height with coefficient 1f
145+ * it returns Size(1000f, 750f), Offset(0f, 125f).
146+ */
147+ fun calculateSizeAndOffsetFromAspectRatio (
148+ aspectRatio : AspectRatio ,
149+ coefficient : Float ,
150+ size : Size ,
151+ ): Pair <Size , Offset > {
129152 val width = size.width
130153 val height = size.height
131154
132155 val value = aspectRatio.value
133156
134- val shapeSize = if (aspectRatio == AspectRatio .Unspecified ) {
157+ val newSize = if (aspectRatio == AspectRatio .Unspecified ) {
135158 Size (width * coefficient, height * coefficient)
136159 } else if (value > 1 ) {
137160 Size (
@@ -142,13 +165,8 @@ fun buildOutline(
142165 Size (width = coefficient * height * value, height = coefficient * height)
143166 }
144167
145- val left = (width - shapeSize .width) / 2
146- val top = (height - shapeSize .height) / 2
168+ val left = (width - newSize .width) / 2
169+ val top = (height - newSize .height) / 2
147170
148- val outline = shape.createOutline(
149- size = shapeSize,
150- layoutDirection = layoutDirection,
151- density = density
152- )
153- return Triple (left, top, outline)
154- }
171+ return Pair (newSize, Offset (left, top))
172+ }
0 commit comments