Skip to content

Commit 21ad9aa

Browse files
committed
Try to detect version
1 parent 54dbafa commit 21ad9aa

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

fitz_nocgo.go

+29
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"io"
88
"os"
99
"path/filepath"
10+
"strconv"
11+
"strings"
1012
"sync"
1113
"unsafe"
1214

@@ -623,6 +625,33 @@ func init() {
623625
purego.RegisterLibFunc(&fzPrintStextPageAsHTML, libmupdf, "fz_print_stext_page_as_html")
624626
purego.RegisterLibFunc(&fzPrintStextHeaderAsHTML, libmupdf, "fz_print_stext_header_as_html")
625627
purego.RegisterLibFunc(&fzPrintStextTrailerAsHTML, libmupdf, "fz_print_stext_trailer_as_html")
628+
629+
ver := version()
630+
if ver != "" {
631+
FzVersion = ver
632+
}
633+
}
634+
635+
func version() string {
636+
if fzNewContextImp(nil, nil, uint64(MaxStore), FzVersion) != nil {
637+
return FzVersion
638+
}
639+
640+
s := strings.Split(FzVersion, ".")
641+
v := strings.Join(s[:len(s)-1], ".")
642+
643+
for x := 10; x >= 0; x-- {
644+
ver := v + "." + strconv.Itoa(x)
645+
if ver == FzVersion {
646+
continue
647+
}
648+
649+
if fzNewContextImp(nil, nil, uint64(MaxStore), ver) != nil {
650+
return ver
651+
}
652+
}
653+
654+
return ""
626655
}
627656

628657
type bundle struct {

0 commit comments

Comments
 (0)