Implemented awful fallback bold and italic

This commit is contained in:
Sasha Koshka 2022-11-29 02:12:30 -05:00
parent e4c7dcb2e1
commit e753fc11ca

View File

@ -130,17 +130,18 @@ func (backend *Backend) drawRune (
backend.boundsOfCell(x, y))
}
// cue a series of pointless optimizations
alphaMask, isAlpha := mask.(*image.Alpha)
if isAlpha {
backend.sprayRuneMaskAlpha (
alphaMask, destinationRectangle,
maskPoint, foreground, background)
} else {
// alphaMask, isAlpha := mask.(*image.Alpha)
// if isAlpha {
// backend.sprayRuneMaskAlpha (
// alphaMask, destinationRectangle,
// maskPoint, foreground, background)
// } else {
backend.sprayRuneMask (
mask, destinationRectangle,
maskPoint, foreground, background)
}
maskPoint, foreground, background,
runeStyle & stone.StyleItalic > 0,
runeStyle & stone.StyleBold > 0)
// }
}
// underline
@ -161,16 +162,27 @@ func (backend *Backend) sprayRuneMask (
maskPoint image.Point,
fill xgraphics.BGRA,
background xgraphics.BGRA,
italic bool,
bold bool,
) {
maxX := bounds.Max.X - bounds.Min.X
maxY := bounds.Max.Y - bounds.Min.Y
for y := 0; y < maxY; y ++ {
var previousAlpha uint32
offset := 0
if italic {
offset = (maxY - y) / 4
}
for x := 0; x < maxX; x ++ {
_, _, _,
alpha := mask.At(x + maskPoint.X, y + maskPoint.Y).RGBA()
currentAlpha := alpha
if bold && previousAlpha > alpha {
alpha = previousAlpha
}
backend.canvas.SetBGRA (
x + bounds.Min.X,
x + bounds.Min.X + offset,
y + bounds.Min.Y - backend.metrics.descent,
xgraphics.BlendBGRA (
background,
@ -180,24 +192,12 @@ func (backend *Backend) sprayRuneMask (
B: fill.B,
A: uint8(alpha >> 8),
}))
}}
previousAlpha = currentAlpha
}
func (backend *Backend) sprayRuneMaskAlpha (
mask *image.Alpha,
bounds image.Rectangle,
maskPoint image.Point,
fill xgraphics.BGRA,
background xgraphics.BGRA,
) {
maxX := bounds.Max.X - bounds.Min.X
maxY := bounds.Max.Y - bounds.Min.Y
for y := 0; y < maxY; y ++ {
for x := 0; x < maxX; x ++ {
alpha := mask.AlphaAt(x + maskPoint.X, y + maskPoint.Y).A
if bold {
backend.canvas.SetBGRA (
x + bounds.Min.X,
bounds.Max.X + offset,
y + bounds.Min.Y - backend.metrics.descent,
xgraphics.BlendBGRA (
background,
@ -205,10 +205,38 @@ func (backend *Backend) sprayRuneMaskAlpha (
R: fill.R,
G: fill.G,
B: fill.B,
A: alpha,
A: uint8(previousAlpha >> 8),
}))
}}
}
}
}
// func (backend *Backend) sprayRuneMaskAlpha (
// mask *image.Alpha,
// bounds image.Rectangle,
// maskPoint image.Point,
// fill xgraphics.BGRA,
// background xgraphics.BGRA,
// ) {
// maxX := bounds.Max.X - bounds.Min.X
// maxY := bounds.Max.Y - bounds.Min.Y
//
// for y := 0; y < maxY; y ++ {
// for x := 0; x < maxX; x ++ {
// alpha := mask.AlphaAt(x + maskPoint.X, y + maskPoint.Y).A
// backend.canvas.SetBGRA (
// x + bounds.Min.X,
// y + bounds.Min.Y - backend.metrics.descent,
// xgraphics.BlendBGRA (
// background,
// xgraphics.BGRA {
// R: fill.R,
// G: fill.G,
// B: fill.B,
// A: alpha,
// }))
// }}
// }
func fillRectangle (
source image.Image,