Skip to content
Merged
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
14 changes: 1 addition & 13 deletions fontscan/fontmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package fontscan
import (
"fmt"
"log"
"os"
"path/filepath"
"runtime"
"sync"

"github.com/go-text/typesetting/font"
Expand Down Expand Up @@ -165,17 +163,7 @@ func cacheDir(userProvided string) (string, error) {
return userProvided, nil
}
// load an existing index
if runtime.GOOS == "android" {
// There is no stable way to infer the proper place to store the cache
// with access to the Java runtime for the application. Rather than
// clutter our API with that, require the caller to provide a path.
return "", fmt.Errorf("user must provide cache directory on android")
}
configDir, err := os.UserCacheDir()
if err != nil {
return "", fmt.Errorf("resolving index cache path: %s", err)
}
return configDir, nil
return platformCacheDir()
}

// initSystemFonts scan the system fonts and update `SystemFonts`.
Expand Down
8 changes: 8 additions & 0 deletions fontscan/fontmap_cache_android.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package fontscan

func platformCacheDir() (string, error) {
// There is no stable way to infer the proper place to store the cache
// with access to the Java runtime for the application. Rather than
// clutter our API with that, require the caller to provide a path.
return "", fmt.Errorf("user must provide cache directory on android")
}
16 changes: 16 additions & 0 deletions fontscan/fontmap_cache_other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//go:build !android && !tinygo

package fontscan

import (
"fmt"
"os"
)

func platformCacheDir() (string, error) {
configDir, err := os.UserCacheDir()
if err != nil {
return "", fmt.Errorf("resolving index cache path: %s", err)
}
return configDir, nil
}
18 changes: 18 additions & 0 deletions fontscan/fontmap_cache_tinygo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//go:build tinygo

package fontscan

import (
"fmt"
"os"
"path/filepath"
)

func platformCacheDir() (string, error) {
// if no path is provided we cannot get cache dir with tinygo, so just make one up.
homeDir, err := os.UserHomeDir()
if err != nil {
return "", fmt.Errorf("resolving index cache path: %s", err)
}
return filepath.Join(homeDir, ".cache"), nil
}