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,16 +162,27 @@ 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 ++ {
var previousAlpha uint32
offset := 0
if italic {
offset = (maxY - y) / 4
}
for x := 0; x < maxX; x ++ { for x := 0; x < maxX; x ++ {
_, _, _, _, _, _,
alpha := mask.At(x + maskPoint.X, y + maskPoint.Y).RGBA() alpha := mask.At(x + maskPoint.X, y + maskPoint.Y).RGBA()
currentAlpha := alpha
if bold && previousAlpha > alpha {
alpha = previousAlpha
}
backend.canvas.SetBGRA ( backend.canvas.SetBGRA (
x + bounds.Min.X, x + bounds.Min.X + offset,
y + bounds.Min.Y - backend.metrics.descent, y + bounds.Min.Y - backend.metrics.descent,
xgraphics.BlendBGRA ( xgraphics.BlendBGRA (
background, background,
@ -180,24 +192,12 @@ func (backend *Backend) sprayRuneMask (
B: fill.B, B: fill.B,
A: uint8(alpha >> 8), A: uint8(alpha >> 8),
})) }))
}} previousAlpha = currentAlpha
} }
func (backend *Backend) sprayRuneMaskAlpha ( if bold {
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 ( backend.canvas.SetBGRA (
x + bounds.Min.X, bounds.Max.X + offset,
y + bounds.Min.Y - backend.metrics.descent, y + bounds.Min.Y - backend.metrics.descent,
xgraphics.BlendBGRA ( xgraphics.BlendBGRA (
background, background,
@ -205,10 +205,38 @@ func (backend *Backend) sprayRuneMaskAlpha (
R: fill.R, R: fill.R,
G: fill.G, G: fill.G,
B: fill.B, 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 ( func fillRectangle (
source image.Image, source image.Image,