Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f18100c1 authored by Fynn Godau's avatar Fynn Godau
Browse files

Unskew circle stroke pattern in lite mode

Increase dot width by dpi factor. Also increase bitmap height by dpi
factor.
parent e895d25a
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -289,9 +289,9 @@ class LiteGoogleMapImpl(context: Context, var options: GoogleMapOptions) : Abstr
                PropertyFactory.lineCap(Property.LINE_CAP_ROUND),
            ).apply {
                circle.strokePattern?.let {
                    val name = it.getName(circle.strokeColor, circle.strokeWidth)
                    val name = it.getName(circle.strokeColor, circle.strokeWidth, dpi)
                    withProperties(PropertyFactory.linePattern(name))
                    styleBuilder.withImage(name, it.makeBitmap(circle.strokeColor, circle.strokeWidth))
                    styleBuilder.withImage(name, it.makeBitmap(circle.strokeColor, circle.strokeWidth, dpi))
                }
            }).withSource(GeoJsonSource("${circle.id}s", circle.line.annotationOptions.geometry))
        }
+15 −15
Original line number Diff line number Diff line
@@ -18,18 +18,18 @@ fun PatternItem.getName(): String = when (this) {
/**
 * Name of pattern, to identify it after it is added to map
 */
fun List<PatternItem>.getName(color: Int, strokeWidth: Float) = joinToString("-") {
fun List<PatternItem>.getName(color: Int, strokeWidth: Float, skew: Float = 1f) = joinToString("-") {
    it.getName()
} + "-${color}-width${strokeWidth}"
} + "-${color}-width${strokeWidth}-skew${skew}"

/**
 * Gets width that a bitmap for this pattern item would have if the pattern's bitmap
 * were to be drawn with respect to aspect ratio onto a canvas with height 1.
 */
fun PatternItem.getWidth(strokeWidth: Float): Float = when (this) {
fun PatternItem.getWidth(strokeWidth: Float, skew: Float): Float = when (this) {
    is Dash -> this.length
    is Gap -> this.length
    is Dot -> strokeWidth
    is Dot -> strokeWidth * skew
    else -> 1f
}

@@ -37,19 +37,19 @@ fun PatternItem.getWidth(strokeWidth: Float): Float = when (this) {
 * Gets width that a bitmap for this pattern would have if it were to be drawn
 * with respect to aspect ratio onto a canvas with height 1.
 */
fun List<PatternItem>.getWidth(strokeWidth: Float) = map { it.getWidth(strokeWidth) }.sum()
fun List<PatternItem>.getWidth(strokeWidth: Float, skew: Float) = map { it.getWidth(strokeWidth, skew) }.sum()

fun List<PatternItem>.makeBitmap(color: Int, strokeWidth: Float): Bitmap = makeBitmap(Paint().apply {
fun List<PatternItem>.makeBitmap(color: Int, strokeWidth: Float, skew: Float = 1f): Bitmap = makeBitmap(Paint().apply {
    setColor(color)
    style = Paint.Style.FILL
}, strokeWidth)
}, strokeWidth, skew)


fun List<PatternItem>.makeBitmap(paint: Paint, strokeWidth: Float): Bitmap {
fun List<PatternItem>.makeBitmap(paint: Paint, strokeWidth: Float, skew: Float): Bitmap {

    // Pattern aspect ratio is not respected by renderer
    val width = getWidth(strokeWidth).toInt()
    val height = strokeWidth.toInt() // avoids squished image bugs
    val width = getWidth(strokeWidth, skew).toInt()
    val height = (strokeWidth * skew).toInt() // avoids squished image bugs

    val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
    val canvas = Canvas(bitmap)
@@ -60,8 +60,8 @@ fun List<PatternItem>.makeBitmap(paint: Paint, strokeWidth: Float): Bitmap {
            is Dash -> canvas.drawRect(
                drawCursor,
                0f,
                drawCursor + item.length,
                strokeWidth,
                drawCursor + item.getWidth(strokeWidth, skew),
                strokeWidth * skew,
                paint
            )

@@ -70,13 +70,13 @@ fun List<PatternItem>.makeBitmap(paint: Paint, strokeWidth: Float): Bitmap {
            is Dot -> canvas.drawOval(
                drawCursor,
                0f,
                drawCursor + item.getWidth(strokeWidth),
                strokeWidth,
                drawCursor + item.getWidth(strokeWidth, skew),
                strokeWidth * skew,
                paint
            )
        }

        drawCursor += item.getWidth(strokeWidth)
        drawCursor += item.getWidth(strokeWidth, skew)
    }

    return bitmap
+1 −1
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ public class PatternItem extends AutoSafeParcelable {
    @Field(2)
    private int type;
    @Field(3)
    private float length;
    private Float length;

    private PatternItem() {
    }