bdf: make it possible to set the drawing colour
Intended for red and black tapes.
This commit is contained in:
parent
8215b59834
commit
9734cdd16e
2
LICENSE
2
LICENSE
|
@ -1,4 +1,4 @@
|
|||
Copyright (c) 2019, Přemysl Eric Janouch <p@janouch.name>
|
||||
Copyright (c) 2019 - 2021, Přemysl Eric Janouch <p@janouch.name>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted.
|
||||
|
|
|
@ -66,11 +66,13 @@ func (f *Font) FindGlyph(r rune) (glyph, bool) {
|
|||
|
||||
// DrawString draws the specified text string onto dst horizontally along
|
||||
// the baseline starting at dp, using black color.
|
||||
func (f *Font) DrawString(dst draw.Image, dp image.Point, s string) {
|
||||
func (f *Font) DrawString(dst draw.Image, dp image.Point,
|
||||
color color.Color, s string) {
|
||||
src := image.NewUniform(color)
|
||||
for _, r := range s {
|
||||
g, _ := f.FindGlyph(r)
|
||||
draw.DrawMask(dst, g.bounds.Add(dp),
|
||||
image.Black, image.ZP, &g, g.bounds.Min, draw.Over)
|
||||
src, image.ZP, &g, g.bounds.Min, draw.Over)
|
||||
dp.X += g.advance
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"html/template"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/draw"
|
||||
"image/png"
|
||||
"log"
|
||||
|
@ -82,7 +83,7 @@ func main() {
|
|||
|
||||
img := image.NewRGBA(super)
|
||||
draw.Draw(img, super, image.White, image.ZP, draw.Src)
|
||||
font.DrawString(img, image.ZP, font.Name)
|
||||
font.DrawString(img, image.ZP, color.Black, font.Name)
|
||||
|
||||
fonts[filename] = fontItem{Font: font, Preview: img}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"image"
|
||||
"image/color"
|
||||
"image/draw"
|
||||
"image/png"
|
||||
"log"
|
||||
|
@ -26,7 +27,7 @@ func main() {
|
|||
|
||||
img := image.NewRGBA(super)
|
||||
draw.Draw(img, super, image.White, image.ZP, draw.Src)
|
||||
font.DrawString(img, image.ZP, font.Name)
|
||||
font.DrawString(img, image.ZP, color.Black, font.Name)
|
||||
|
||||
fo, err := os.Create("out.png")
|
||||
if err != nil {
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"errors"
|
||||
"html/template"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/draw"
|
||||
"image/png"
|
||||
"log"
|
||||
|
@ -260,7 +261,7 @@ func main() {
|
|||
|
||||
img := image.NewRGBA(super)
|
||||
draw.Draw(img, super, image.White, image.ZP, draw.Src)
|
||||
font.DrawString(img, image.ZP, font.Name)
|
||||
font.DrawString(img, image.ZP, color.Black, font.Name)
|
||||
|
||||
fonts = append(fonts, &fontItem{Path: path, Font: font, Preview: img})
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package label
|
|||
|
||||
import (
|
||||
"image"
|
||||
"image/color"
|
||||
"image/draw"
|
||||
"strings"
|
||||
|
||||
|
@ -19,7 +20,7 @@ func GenLabelForHeight(font *bdf.Font,
|
|||
textRect, _ := font.BoundString(text)
|
||||
textImg := image.NewRGBA(textRect)
|
||||
draw.Draw(textImg, textRect, image.White, image.ZP, draw.Src)
|
||||
font.DrawString(textImg, image.ZP, text)
|
||||
font.DrawString(textImg, image.ZP, color.Black, text)
|
||||
|
||||
scaledTextImg := imgutil.Scale{Image: textImg, Scale: scale}
|
||||
scaledTextRect := scaledTextImg.Bounds()
|
||||
|
@ -93,7 +94,7 @@ func GenLabelForWidth(font *bdf.Font,
|
|||
for i, line := range lines {
|
||||
textImg := image.NewRGBA(rects[i])
|
||||
draw.Draw(textImg, rects[i], image.White, image.ZP, draw.Src)
|
||||
font.DrawString(textImg, image.ZP, line)
|
||||
font.DrawString(textImg, image.ZP, color.Black, line)
|
||||
|
||||
scaledImg := imgutil.Scale{Image: textImg, Scale: scale}
|
||||
scaledRect := scaledImg.Bounds()
|
||||
|
|
Loading…
Reference in New Issue