Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SVG marker support #242

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading