Loading of multiple fonts for bold and italic
This commit is contained in:
@@ -86,9 +86,51 @@ func (backend *Backend) drawRune (
|
||||
// application background color as the background. that way, we won't
|
||||
// need to redraw the characters *or* composite them.
|
||||
|
||||
face := backend.font.normal
|
||||
|
||||
highlight := runeStyle & stone.StyleHighlight > 0
|
||||
bold := runeStyle & stone.StyleBold > 0
|
||||
italic := runeStyle & stone.StyleItalic > 0
|
||||
|
||||
boldTransform := false
|
||||
italicTransform := false
|
||||
|
||||
switch {
|
||||
case bold && italic:
|
||||
if backend.font.boldItalic == nil {
|
||||
switch {
|
||||
case
|
||||
backend.font.bold == nil && backend.font.italic != nil,
|
||||
backend.font.bold != nil && backend.font.italic != nil:
|
||||
|
||||
boldTransform = true
|
||||
face = backend.font.italic
|
||||
case backend.font.italic == nil && backend.font.bold != nil:
|
||||
italicTransform = true
|
||||
face = backend.font.bold
|
||||
default:
|
||||
boldTransform = true
|
||||
italicTransform = true
|
||||
}
|
||||
} else {
|
||||
face = backend.font.boldItalic
|
||||
}
|
||||
case bold:
|
||||
if backend.font.bold == nil {
|
||||
boldTransform = true
|
||||
} else {
|
||||
face = backend.font.bold
|
||||
}
|
||||
case italic:
|
||||
if backend.font.italic == nil {
|
||||
italicTransform = true
|
||||
} else {
|
||||
face = backend.font.italic
|
||||
}
|
||||
}
|
||||
|
||||
var background xgraphics.BGRA
|
||||
var foreground xgraphics.BGRA
|
||||
highlight := runeStyle & stone.StyleHighlight > 0
|
||||
|
||||
if highlight {
|
||||
background = backend.colors[runeColor]
|
||||
@@ -108,7 +150,7 @@ func (backend *Backend) drawRune (
|
||||
origin := backend.originOfCell(x, y + 1)
|
||||
|
||||
if character >= 32 {
|
||||
destinationRectangle, mask, maskPoint, _, ok := backend.font.face.Glyph (
|
||||
destinationRectangle, mask, maskPoint, _, ok := face.Glyph (
|
||||
fixed.Point26_6 {
|
||||
X: fixed.I(origin.X),
|
||||
Y: fixed.I(origin.Y),
|
||||
@@ -139,8 +181,7 @@ func (backend *Backend) drawRune (
|
||||
backend.sprayRuneMask (
|
||||
mask, destinationRectangle,
|
||||
maskPoint, foreground, background,
|
||||
runeStyle & stone.StyleItalic > 0,
|
||||
runeStyle & stone.StyleBold > 0)
|
||||
italicTransform, boldTransform)
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
@@ -32,11 +32,20 @@ func factory (
|
||||
}
|
||||
|
||||
// load font
|
||||
backend.font.face = findAndLoadFont (
|
||||
backend.config.FontName(),
|
||||
backend.font.normal = findAndLoadFont (
|
||||
backend.config.FontNameNormal(),
|
||||
float64(backend.config.FontSize()))
|
||||
if backend.font.face == nil {
|
||||
backend.font.face = basicfont.Face7x13
|
||||
backend.font.bold = findAndLoadFont (
|
||||
backend.config.FontNameBold(),
|
||||
float64(backend.config.FontSize()))
|
||||
backend.font.italic = findAndLoadFont (
|
||||
backend.config.FontNameItalic(),
|
||||
float64(backend.config.FontSize()))
|
||||
backend.font.boldItalic = findAndLoadFont (
|
||||
backend.config.FontNameBoldItalic(),
|
||||
float64(backend.config.FontSize()))
|
||||
if backend.font.normal == nil {
|
||||
backend.font.normal = basicfont.Face7x13
|
||||
}
|
||||
|
||||
// pre-calculate colors
|
||||
@@ -56,8 +65,8 @@ func factory (
|
||||
}
|
||||
|
||||
// calculate metrics
|
||||
metrics := backend.font.face.Metrics()
|
||||
glyphAdvance, _ := backend.font.face.GlyphAdvance('M')
|
||||
metrics := backend.font.normal.Metrics()
|
||||
glyphAdvance, _ := backend.font.normal.GlyphAdvance('M')
|
||||
backend.metrics.cellWidth = glyphAdvance.Round()
|
||||
backend.metrics.cellHeight = metrics.Height.Round()
|
||||
backend.metrics.descent = metrics.Descent.Round()
|
||||
|
||||
@@ -27,7 +27,10 @@ type Backend struct {
|
||||
lock sync.Mutex
|
||||
|
||||
font struct {
|
||||
face font.Face
|
||||
normal font.Face
|
||||
bold font.Face
|
||||
italic font.Face
|
||||
boldItalic font.Face
|
||||
}
|
||||
|
||||
colors [8]xgraphics.BGRA
|
||||
|
||||
Reference in New Issue
Block a user