|
|
|
@ -393,16 +393,39 @@ func containImage(src image.Image, boxWidth, boxHeight int) image.Image { |
|
|
|
|
|
|
|
func resolveCertificateFont(explicitPath string) (string, error) { |
|
|
|
if explicitPath != "" { |
|
|
|
if _, err := os.Stat(explicitPath); err != nil { |
|
|
|
return "", err |
|
|
|
return validateCertificateFont(explicitPath) |
|
|
|
} |
|
|
|
|
|
|
|
if envPath := os.Getenv("ZXCHAIN_CERTIFICATE_FONT_PATH"); envPath != "" { |
|
|
|
return validateCertificateFont(envPath) |
|
|
|
} |
|
|
|
|
|
|
|
candidates := certificateFontCandidates() |
|
|
|
for _, candidate := range candidates { |
|
|
|
if fontPath, err := validateCertificateFont(candidate); err == nil { |
|
|
|
return fontPath, nil |
|
|
|
} |
|
|
|
} |
|
|
|
if _, err := gg.LoadFontFace(explicitPath, 25); err != nil { |
|
|
|
return "", fmt.Errorf("load certificate font %s: %w", explicitPath, err) |
|
|
|
return "", errors.New("missing certificate font, set HashCertificateRequest.FontPath or ZXCHAIN_CERTIFICATE_FONT_PATH to a Chinese TTF/TTC/OTF font") |
|
|
|
} |
|
|
|
|
|
|
|
func validateCertificateFont(fontPath string) (string, error) { |
|
|
|
if _, err := os.Stat(fontPath); err != nil { |
|
|
|
return "", err |
|
|
|
} |
|
|
|
return explicitPath, nil |
|
|
|
if _, err := gg.LoadFontFace(fontPath, 25); err != nil { |
|
|
|
return "", fmt.Errorf("load certificate font %s: %w", fontPath, err) |
|
|
|
} |
|
|
|
return fontPath, nil |
|
|
|
} |
|
|
|
|
|
|
|
func certificateFontCandidates() []string { |
|
|
|
candidates := []string{ |
|
|
|
"C:/Windows/Fonts/msyh.ttc", |
|
|
|
"C:/Windows/Fonts/msyhbd.ttc", |
|
|
|
"C:/Windows/Fonts/simhei.ttf", |
|
|
|
"C:/Windows/Fonts/simsun.ttc", |
|
|
|
"C:/Windows/Fonts/simkai.ttf", |
|
|
|
"/System/Library/Fonts/Supplemental/Arial Unicode.ttf", |
|
|
|
"/System/Library/Fonts/Supplemental/Arial.ttf", |
|
|
|
"/System/Library/Fonts/Supplemental/Microsoft Sans Serif.ttf", |
|
|
|
@ -414,15 +437,14 @@ func resolveCertificateFont(explicitPath string) (string, error) { |
|
|
|
"/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc", |
|
|
|
"/usr/share/fonts/truetype/noto/NotoSansCJK-Regular.ttc", |
|
|
|
} |
|
|
|
for _, candidate := range candidates { |
|
|
|
if _, err := os.Stat(candidate); err != nil { |
|
|
|
continue |
|
|
|
} |
|
|
|
if _, err := gg.LoadFontFace(candidate, 25); err == nil { |
|
|
|
return candidate, nil |
|
|
|
|
|
|
|
if windowsDir := firstNonEmpty(os.Getenv("WINDIR"), os.Getenv("SystemRoot")); windowsDir != "" { |
|
|
|
windowsDir = strings.TrimRight(windowsDir, `\/`) |
|
|
|
for _, name := range []string{"msyh.ttc", "msyhbd.ttc", "simhei.ttf", "simsun.ttc", "simkai.ttf"} { |
|
|
|
candidates = append(candidates, windowsDir+"/Fonts/"+name) |
|
|
|
} |
|
|
|
} |
|
|
|
return "", errors.New("missing certificate font, set HashCertificateRequest.FontPath to a Chinese TTF/TTC font") |
|
|
|
return candidates |
|
|
|
} |
|
|
|
|
|
|
|
func certificateImageObjectKey(evidenceID, certNo string) string { |
|
|
|
|