From 696ea8953089c3872bca22ec24ca28139ef46cd3 Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Fri, 26 Apr 2019 11:40:43 +0200 Subject: label-tool: respect font ascent and descent Also try to load the values from the BDF font file. --- bdf/bdf.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'bdf') diff --git a/bdf/bdf.go b/bdf/bdf.go index c02e31e..5ff8f30 100644 --- a/bdf/bdf.go +++ b/bdf/bdf.go @@ -49,6 +49,8 @@ func (g *glyph) At(x, y int) color.Color { // Font represents a particular bitmap font. type Font struct { Name string + Ascent int // needn't be present in the font + Descent int // needn't be present in the font glyphs map[rune]glyph fallback glyph } @@ -192,17 +194,23 @@ func (p *bdfParser) readLine() bool { return true } -func (p *bdfParser) readCharEncoding() int { +func (p *bdfParser) readIntegerArgument() int { if len(p.tokens) < 2 { panic("insufficient arguments") } if i, err := strconv.Atoi(p.tokens[1]); err != nil { panic(err) } else { - return i // Some fonts even use -1 for things outside the encoding. + return i } } +// Some fonts even use -1 for things outside the encoding. +func (p *bdfParser) readCharEncoding() int { return p.readIntegerArgument() } + +// XXX: Ignoring vertical advance since we only expect purely horizontal fonts. +func (p *bdfParser) readDwidth() int { return p.readIntegerArgument() } + func (p *bdfParser) parseProperties() { // The wording in the specification suggests that the argument // with the number of properties to follow isn't reliable. @@ -210,22 +218,14 @@ func (p *bdfParser) parseProperties() { switch p.tokens[0] { case "DEFAULT_CHAR": p.defaultChar = p.readCharEncoding() + case "FONT_ASCENT": + p.font.Ascent = p.readIntegerArgument() + case "FONT_DESCENT": + p.font.Descent = p.readIntegerArgument() } } } -// XXX: Ignoring vertical advance since we only expect purely horizontal fonts. -func (p *bdfParser) readDwidth() int { - if len(p.tokens) < 2 { - panic("insufficient arguments") - } - if i, err := strconv.Atoi(p.tokens[1]); err != nil { - panic(err) - } else { - return i - } -} - func (p *bdfParser) readBBX() image.Rectangle { if len(p.tokens) < 5 { panic("insufficient arguments") -- cgit v1.2.3-70-g09d2