Skip to content

Commit

Permalink
Add SVG marker support
Browse files Browse the repository at this point in the history
Include qualified selector styles when performing styling

Fix problem with unsupported font is used from fc-match in
FindLocalFont.

Unescape XML encoded strings for text.

Default font-size medium absolute size to the default font
size.
  • Loading branch information
SuperTXT Team committed Aug 26, 2023
1 parent 8bc6ac4 commit 1598b61
Show file tree
Hide file tree
Showing 2 changed files with 231 additions and 113 deletions.
18 changes: 15 additions & 3 deletions font.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"io/ioutil"
"math"
"os/exec"
"path/filepath"
"reflect"
"strings"
"sync"

"github.com/adrg/sysfont"
Expand Down Expand Up @@ -118,17 +120,27 @@ var sysfontFinder = struct {
func FindLocalFont(name string, style FontStyle) string {
// TODO: use style to match font
// try with fc-match first
filename, err := exec.Command("fc-match", "--format=%{file}", name).Output()
extensions := []string{".ttf", ".otf", ".ttc", ".woff", ".woff2", ".eot"}

fns, err := exec.Command("fc-match", "-s", "--format=%{file}\\n", name).Output()
if err == nil {
return string(filename)
filenames := strings.Split(string(fns), "\n")
for _, filename := range filenames {
ext := filepath.Ext(filename)
for _, extension := range extensions {
if ext == extension {
return filename
}
}
}
}

// then use known font directories
sysfontFinder.m.Lock()
finder := sysfontFinder.f
if finder == nil {
finder = sysfont.NewFinder(&sysfont.FinderOpts{ // TODO: very slow (takes 1s)
Extensions: []string{".ttf", ".otf", ".ttc", ".woff", ".woff2", ".eot"},
Extensions: extensions,
})
sysfontFinder.f = finder
}
Expand Down
Loading

0 comments on commit 1598b61

Please sign in to comment.