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