Add emojis to bound calculation
This commit is contained in:
parent
e3566f7fc4
commit
9941d77460
1 changed files with 22 additions and 5 deletions
|
@ -179,12 +179,25 @@ func (gc *GraphicContext) StrokeStringAt(text string, x, y float64) (width float
|
||||||
startx := x
|
startx := x
|
||||||
prev, hasPrev := truetype.Index(0), false
|
prev, hasPrev := truetype.Index(0), false
|
||||||
fontName := gc.GetFontName()
|
fontName := gc.GetFontName()
|
||||||
for _, r := range text {
|
for fragment := range gc.Emojis.Iterate(text) {
|
||||||
index := f.Index(r)
|
if fragment.IsEmoji {
|
||||||
|
img, err := LoadFromPngFile(fragment.Emoji.Path)
|
||||||
|
if err == nil {
|
||||||
|
gc.Save()
|
||||||
|
scale := gc.GetFontSize() / 100
|
||||||
|
gc.Translate(x+scale*emojiSpacing, y-scale*emojiScale)
|
||||||
|
gc.Scale(scale, scale)
|
||||||
|
gc.DrawImage(img)
|
||||||
|
gc.Restore()
|
||||||
|
x += scale*float64(img.Bounds().Size().X) + scale*emojiSpacing*2
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
index := f.Index(fragment.Rune)
|
||||||
if hasPrev {
|
if hasPrev {
|
||||||
x += fUnitsToFloat64(f.Kern(fixed.Int26_6(gc.Current.Scale), prev, index))
|
x += fUnitsToFloat64(f.Kern(fixed.Int26_6(gc.Current.Scale), prev, index))
|
||||||
}
|
}
|
||||||
glyph := gc.glyphCache.Fetch(gc, fontName, r)
|
glyph := gc.glyphCache.Fetch(gc, fontName, fragment.Rune)
|
||||||
x += glyph.Stroke(gc, x, y)
|
x += glyph.Stroke(gc, x, y)
|
||||||
prev, hasPrev = index, true
|
prev, hasPrev = index, true
|
||||||
}
|
}
|
||||||
|
@ -262,8 +275,12 @@ func (gc *GraphicContext) GetStringBounds(s string) (left, top, right, bottom fl
|
||||||
top, left, bottom, right = 10e6, 10e6, -10e6, -10e6
|
top, left, bottom, right = 10e6, 10e6, -10e6, -10e6
|
||||||
cursor := 0.0
|
cursor := 0.0
|
||||||
prev, hasPrev := truetype.Index(0), false
|
prev, hasPrev := truetype.Index(0), false
|
||||||
for _, rune := range s {
|
for fragment := range gc.Emojis.Iterate(s) {
|
||||||
index := f.Index(rune)
|
if fragment.IsEmoji {
|
||||||
|
cursor += gc.Current.Scale*emojiScale + gc.Current.Scale*emojiSpacing*2
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
index := f.Index(fragment.Rune)
|
||||||
if hasPrev {
|
if hasPrev {
|
||||||
cursor += fUnitsToFloat64(f.Kern(fixed.Int26_6(gc.Current.Scale), prev, index))
|
cursor += fUnitsToFloat64(f.Kern(fixed.Int26_6(gc.Current.Scale), prev, index))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue