mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
40328523ad
1 changed files with 34 additions and 23 deletions
|
|
@ -121,15 +121,23 @@ func parseTTCFontFamily(fontPath string) (ret []string) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
family, _ := font.Name(nil, ttc.NameIDFamily)
|
family, _ := font.Name(nil, ttc.NameIDFull)
|
||||||
if "" == family {
|
|
||||||
family, _ = font.Name(nil, ttc.NameIDTypographicFamily)
|
|
||||||
}
|
|
||||||
family = strings.TrimSpace(family)
|
family = strings.TrimSpace(family)
|
||||||
if "" == family || strings.HasPrefix(family, ".") {
|
if "" != family && !strings.HasPrefix(family, ".") {
|
||||||
continue
|
ret = append(ret, family)
|
||||||
|
}
|
||||||
|
|
||||||
|
family, _ = font.Name(nil, ttc.NameIDFamily)
|
||||||
|
family = strings.TrimSpace(family)
|
||||||
|
if "" != family && !strings.HasPrefix(family, ".") {
|
||||||
|
ret = append(ret, family)
|
||||||
|
}
|
||||||
|
|
||||||
|
family, _ = font.Name(nil, ttc.NameIDTypographicFamily)
|
||||||
|
family = strings.TrimSpace(family)
|
||||||
|
if "" != family && !strings.HasPrefix(family, ".") {
|
||||||
|
ret = append(ret, family)
|
||||||
}
|
}
|
||||||
ret = append(ret, family)
|
|
||||||
}
|
}
|
||||||
ret = gulu.Str.RemoveDuplicatedElem(ret)
|
ret = gulu.Str.RemoveDuplicatedElem(ret)
|
||||||
return
|
return
|
||||||
|
|
@ -150,35 +158,38 @@ func parseTTFFontFamily(fontPath string) (ret string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if strings.Contains(fontPath, "04") {
|
||||||
|
logging.LogInfo(fontPath)
|
||||||
|
}
|
||||||
|
|
||||||
t, err := font.NameTable()
|
t, err := font.NameTable()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.LogErrorf("get font [%s] name table failed: %s", fontPath, err)
|
logging.LogErrorf("get font [%s] name table failed: %s", fontPath, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var family, subfamily string
|
||||||
for _, e := range t.List() {
|
for _, e := range t.List() {
|
||||||
if sfnt.NameFontFamily != e.NameID && sfnt.NamePreferredFamily != e.NameID {
|
if sfnt.NameFontFamily == e.NameID && (sfnt.PlatformLanguageID(1033) == e.LanguageID || sfnt.PlatformLanguageID(2052) == e.LanguageID) {
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if sfnt.PlatformLanguageID(1033) == e.LanguageID || sfnt.PlatformLanguageID(2052) == e.LanguageID {
|
|
||||||
v, _, err := transform.Bytes(textUnicode.UTF16(textUnicode.BigEndian, textUnicode.IgnoreBOM).NewDecoder(), e.Value)
|
v, _, err := transform.Bytes(textUnicode.UTF16(textUnicode.BigEndian, textUnicode.IgnoreBOM).NewDecoder(), e.Value)
|
||||||
if err != nil {
|
if err == nil {
|
||||||
return ""
|
family = strings.TrimSpace(string(v))
|
||||||
}
|
}
|
||||||
val := string(v)
|
}
|
||||||
if sfnt.NameFontFamily == e.NameID && "" != val {
|
if sfnt.NameFontSubfamily == e.NameID && (sfnt.PlatformLanguageID(1033) == e.LanguageID || sfnt.PlatformLanguageID(2052) == e.LanguageID) {
|
||||||
ret = val
|
v, _, err := transform.Bytes(textUnicode.UTF16(textUnicode.BigEndian, textUnicode.IgnoreBOM).NewDecoder(), e.Value)
|
||||||
}
|
if err == nil {
|
||||||
if sfnt.NamePreferredFamily == e.NameID && "" != val {
|
subfamily = strings.TrimSpace(string(v))
|
||||||
ret = val
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = strings.TrimSpace(ret)
|
if family != "" && !strings.HasPrefix(family, ".") {
|
||||||
if strings.HasPrefix(ret, ".") {
|
if subfamily != "" && !strings.Contains(subfamily, "<") && !strings.EqualFold(subfamily, "Regular") {
|
||||||
return ""
|
ret = family + " " + subfamily // 例如 "PingFang SC Bold"
|
||||||
|
} else {
|
||||||
|
ret = family
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue