fix emojiMask not working correctly.

its index was being reset for each wrapped line thus not corresponding to the actual position in the full paragraph content anymore.

basically if the emojiMask was [false, false, false, true, false] for "abc🔛d" but that text was split in two lines like:
"abc
🔛d"
then the emojiMask would be read at 0, 1, 2, then 0, 1.

now that is fixed.
This commit is contained in:
fiatjaf
2023-12-28 06:48:13 -03:00
parent a500e7bb79
commit e17b3e2b45
2 changed files with 20 additions and 6 deletions

View File

@@ -518,10 +518,11 @@ func drawShapedRunAt(
clr color.Color,
out shaping.Output,
emojiMask []bool,
maskBaseIndex int,
img draw.Image,
startX,
startY int,
) int {
) (charsWritten int, endingX int) {
scale := float32(fontSize) / float32(out.Face.Upem())
b := img.Bounds()
@@ -536,7 +537,7 @@ func drawShapedRunAt(
face := out.Face
currentScale := scale
if emojiMask[i] {
if emojiMask[maskBaseIndex+i] {
face = emojiFace
currentScale = float32(fontSize) / float32(face.Upem())
}
@@ -551,10 +552,12 @@ func drawShapedRunAt(
panic("format not supported for glyph")
}
charsWritten++
x += fixed266ToFloat(g.XAdvance)
}
f.Draw()
return int(math.Ceil(float64(x)))
return charsWritten, int(math.Ceil(float64(x)))
}
// this draws a font glyph (i.e. a letter) according to instructions and scale and whatever