package font
import (
"fmt"
"github.com/go-text/typesetting/font/opentype/tables"
)
type svg []svgDocument
func newSvg(table tables .SVG ) (svg , error ) {
rawData := table .SVGDocumentList .SVGRawData
out := make (svg , len (table .SVGDocumentList .DocumentRecords ))
for i , rec := range table .SVGDocumentList .DocumentRecords {
start , end := rec .SvgDocOffset , rec .SvgDocOffset +tables .Offset32 (rec .SvgDocLength )
if len (rawData ) < int (end ) {
return nil , fmt .Errorf ("invalid svg table (EOF: expected %d, got %d)" , end , len (rawData ))
}
out [i ] = svgDocument {
first : rec .StartGlyphID ,
last : rec .EndGlyphID ,
svg : rawData [start :end ],
}
}
return out , nil
}
type svgDocument struct {
svg []byte
first gID
last gID
}
func (s svg ) rawGlyphData (gid gID ) ([]byte , bool ) {
for i , j := 0 , len (s ); i < j ; {
h := i + (j -i )/2
entry := s [h ]
if gid < entry .first {
j = h
} else if entry .last < gid {
i = h + 1
} else {
return entry .svg , true
}
}
return nil , false
}
The pages are generated with Golds v0.8.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .