Skip to content

Commit 1a01ec0

Browse files
committed
Delegate direction chars to bitmap builder
1 parent 787181f commit 1a01ec0

File tree

5 files changed

+46
-14
lines changed

5 files changed

+46
-14
lines changed

libs/monobitmap-manager/src/main/kotlin/mono/bitmap/manager/factory/LineBitmapFactory.kt

+12-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
package mono.bitmap.manager.factory
66

7+
import mono.common.Characters
78
import mono.graphics.bitmap.MonoBitmap
89
import mono.graphics.geo.Point
910
import mono.shape.extra.LineExtra
@@ -26,8 +27,8 @@ object LineBitmapFactory {
2627
val strokeStyle = lineExtra.strokeStyle ?: PredefinedStraightStrokeStyle.NO_STROKE
2728
createCharPoints(jointPoints, strokeStyle)
2829
.forEachIndexed { index, pointChar ->
29-
val char = if (dashPattern.isGap(index)) ' ' else pointChar.char
30-
bitmapBuilder.put(pointChar.top, pointChar.left, char)
30+
val visualChar = if (dashPattern.isGap(index)) ' ' else pointChar.char
31+
bitmapBuilder.put(pointChar.top, pointChar.left, visualChar, pointChar.char)
3132
}
3233

3334
val startAnchor = lineExtra.startAnchor
@@ -124,7 +125,13 @@ object LineBitmapFactory {
124125
} else {
125126
if (anchor.top < previousPoint.top) anchorChar.top else anchorChar.bottom
126127
}
127-
put(anchor.row, anchor.column, char)
128+
// Anchor point won't override the direction char.
129+
put(
130+
row = anchor.row,
131+
column = anchor.column,
132+
visualChar = char,
133+
directionChar = Characters.TRANSPARENT_CHAR
134+
)
128135
}
129136

130137
private fun isHorizontal(point1: Point, point2: Point): Boolean = point1.top == point2.top
@@ -137,8 +144,8 @@ object LineBitmapFactory {
137144
) {
138145
private val builder = MonoBitmap.Builder(width, height)
139146

140-
fun put(row: Int, column: Int, char: Char) =
141-
builder.put(row - row0, column - column0, char)
147+
fun put(row: Int, column: Int, visualChar: Char, directionChar: Char) =
148+
builder.put(row - row0, column - column0, visualChar, directionChar)
142149

143150
fun toBitmap(): MonoBitmap = builder.toBitmap()
144151

libs/monobitmap-manager/src/main/kotlin/mono/bitmap/manager/factory/RectangleBitmapFactory.kt

+13-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ object RectangleBitmapFactory {
4848
dashPattern: StraightStrokeDashPattern
4949
) {
5050
if (size.width == 1 && size.height == 1) {
51-
put(0, 0, '')
51+
put(
52+
row = 0,
53+
column = 0,
54+
visualChar = '',
55+
directionChar = '',
56+
)
5257
return
5358
}
5459

@@ -83,8 +88,13 @@ object RectangleBitmapFactory {
8388
pointChars
8489
.flatMap { it }
8590
.forEachIndexed { index, pointChar ->
86-
val char = if (dashPattern.isGap(index)) ' ' else pointChar.char
87-
put(pointChar.top, pointChar.left, char)
91+
val visualChar = if (dashPattern.isGap(index)) ' ' else pointChar.char
92+
put(
93+
row = pointChar.top,
94+
column = pointChar.left,
95+
visualChar = visualChar,
96+
directionChar = pointChar.char
97+
)
8898
}
8999
}
90100
}

libs/monobitmap-manager/src/main/kotlin/mono/bitmap/manager/factory/TextBitmapFactory.kt

+7-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ object TextBitmapFactory {
4848
} else {
4949
(maxTextHeight - renderableText.size) / 2 + rowOffset
5050
}
51+
5152
TextAlign.VerticalAlign.BOTTOM ->
5253
if (maxTextHeight < renderableText.size) {
5354
rowOffset
@@ -67,7 +68,12 @@ object TextBitmapFactory {
6768
for (colIndex in row.indices) {
6869
val char = row[colIndex]
6970
if (char != ' ') {
70-
put(row0 + rowIndex, col0 + colIndex, char)
71+
put(
72+
row = row0 + rowIndex,
73+
column = col0 + colIndex,
74+
visualChar = char,
75+
directionChar = char
76+
)
7177
}
7278
}
7379
}

libs/monobitmap/src/main/kotlin/mono/graphics/bitmap/MonoBitmap.kt

+7-4
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,14 @@ class MonoBitmap private constructor(val matrix: List<Row>) {
5252
MutableList(width) { TRANSPARENT_CHAR }
5353
}
5454

55-
fun put(row: Int, column: Int, char: Char) {
55+
fun put(row: Int, column: Int, visualChar: Char, directionChar: Char) {
5656
if (row in 0 until height && column in 0 until width) {
57-
visualMatrix[row][column] = char
58-
// TODO: Delegate direction char
59-
directionMatrix[row][column] = char
57+
visualMatrix[row][column] = visualChar
58+
59+
// The direction char is only override with non-transparent chars.
60+
if (directionChar != TRANSPARENT_CHAR) {
61+
directionMatrix[row][column] = directionChar
62+
}
6063
}
6164
}
6265

libs/monobitmap/src/main/kotlin/mono/graphics/bitmap/drawable/NinePatchDrawable.kt

+7-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ class NinePatchDrawable(
2626
val colIndexes = horizontalRepeatableRange.toIndexes(width, pattern.width)
2727
for (row in 0 until height) {
2828
for (col in 0 until width) {
29-
builder.put(row, col, pattern.getChar(rowIndexes[row], colIndexes[col]))
29+
builder.put(
30+
row = row,
31+
column = col,
32+
visualChar = pattern.getChar(rowIndexes[row], colIndexes[col]),
33+
// TODO: Think about a way to support direction chars to 9-patch drawable
34+
directionChar = pattern.getChar(rowIndexes[row], colIndexes[col]),
35+
)
3036
}
3137
}
3238
return builder.toBitmap()

0 commit comments

Comments
 (0)