Skip to content

Commit

Permalink
Add support for background colors
Browse files Browse the repository at this point in the history
Add section to draw the background color before placing text.
  • Loading branch information
HeavyWombat committed Nov 15, 2020
1 parent 70e6a2e commit 65da3c7
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions internal/img/output.go
Expand Up @@ -241,6 +241,23 @@ func (s *Scaffold) SavePNG(path string) error {
dc.SetFontFace(s.regular)
}

str := string(cr.Symbol)
w, h := dc.MeasureString(str)

// background color
switch cr.Settings & 0x02 {
case 2:
dc.SetRGB255(
int((cr.Settings>>32)&0xFF),
int((cr.Settings>>40)&0xFF),
int((cr.Settings>>48)&0xFF),
)

dc.DrawRectangle(x, y-h+12, w, h)
dc.Fill()
}

// foreground color
switch cr.Settings & 0x01 {
case 1:
dc.SetRGB255(
Expand All @@ -253,9 +270,6 @@ func (s *Scaffold) SavePNG(path string) error {
dc.SetColor(s.defaultForegroundColor)
}

str := string(cr.Symbol)
w, h := dc.MeasureString(str)

switch str {
case "\n":
x = xOffset + paddingX
Expand Down

0 comments on commit 65da3c7

Please sign in to comment.