mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-08-30 12:12:40 +08:00
@@ -33,7 +33,7 @@ const WASM_CALLBACKS = [
|
||||
"ofdgoExportFormats",
|
||||
"ofdgoExportPage",
|
||||
"ofdgoExportPDF",
|
||||
"ofdgoFontCandidates",
|
||||
"ofdgoFontSystemNames",
|
||||
];
|
||||
|
||||
let wasmPromise = null;
|
||||
@@ -616,7 +616,7 @@ function externalDocumentFontNames() {
|
||||
|
||||
function fontNameKeys(names) {
|
||||
const keys = new Set();
|
||||
for (const name of fontCandidateNames(names)) {
|
||||
for (const name of fontSystemNames(names)) {
|
||||
const key = normalizeFontName(name);
|
||||
if (key) {
|
||||
keys.add(key);
|
||||
@@ -625,18 +625,18 @@ function fontNameKeys(names) {
|
||||
return keys;
|
||||
}
|
||||
|
||||
function fontCandidateNames(names) {
|
||||
function fontSystemNames(names) {
|
||||
const source = (Array.isArray(names) ? names : [])
|
||||
.map((name) => String(name || "").trim())
|
||||
.filter((name) => name !== "");
|
||||
if (!source.length) {
|
||||
return [];
|
||||
}
|
||||
if (state.ready && !state.wasmExited && typeof globalThis.ofdgoFontCandidates === "function") {
|
||||
if (state.ready && !state.wasmExited && typeof globalThis.ofdgoFontSystemNames === "function") {
|
||||
try {
|
||||
const candidates = callWASM("ofdgoFontCandidates", source);
|
||||
if (Array.isArray(candidates)) {
|
||||
return candidates;
|
||||
const names = callWASM("ofdgoFontSystemNames", source);
|
||||
if (Array.isArray(names)) {
|
||||
return names;
|
||||
}
|
||||
} catch {
|
||||
return source;
|
||||
|
||||
@@ -45,7 +45,7 @@ func RunWASM() {
|
||||
registerCallback("ofdgoExportFormats", exportFormats)
|
||||
registerCallback("ofdgoExportPage", exportPage)
|
||||
registerCallback("ofdgoExportPDF", exportPDF)
|
||||
registerCallback("ofdgoFontCandidates", fontCandidates)
|
||||
registerCallback("ofdgoFontSystemNames", fontSystemNames)
|
||||
select {}
|
||||
}
|
||||
|
||||
@@ -164,12 +164,12 @@ func exportPDF(args []js.Value) (any, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// fontCandidates 获取字体候选名称
|
||||
// fontSystemNames 获取系统字体名称
|
||||
// 入参: args 浏览器参数
|
||||
// 返回: any 字体候选名称, error 错误信息
|
||||
func fontCandidates(args []js.Value) (any, error) {
|
||||
// 返回: any 系统字体名称, error 错误信息
|
||||
func fontSystemNames(args []js.Value) (any, error) {
|
||||
names := stringsFromJS(jsArg(args, 0))
|
||||
return ofdgo.FontCandidateNames(names...), nil
|
||||
return ofdgo.FontSystemNames(names...), nil
|
||||
}
|
||||
|
||||
// bytesFromJS 从浏览器值读取二进制数据
|
||||
|
||||
@@ -158,7 +158,6 @@ func (r *Reader) Doc() (*Document, error) {
|
||||
if doc.Signatures == "" {
|
||||
doc.Signatures = docAttr.Signatures
|
||||
}
|
||||
r.OFD.DocBody[0].DocInfo.DocID = "loaded"
|
||||
if doc.CommonData.DocumentRes != "" {
|
||||
r.loadRes(doc.CommonData.DocumentRes)
|
||||
}
|
||||
@@ -278,19 +277,6 @@ func (r *Reader) ResData(resLink string) ([]byte, error) {
|
||||
return r.readFile(fullPath)
|
||||
}
|
||||
|
||||
// DocRoots 获取所有文档根路径
|
||||
// 返回: []string 路径列表
|
||||
func (r *Reader) DocRoots() []string {
|
||||
var roots []string
|
||||
if r.OFD == nil {
|
||||
return roots
|
||||
}
|
||||
for _, body := range r.OFD.DocBody {
|
||||
roots = append(roots, body.DocRoot)
|
||||
}
|
||||
return roots
|
||||
}
|
||||
|
||||
// Version 获取OFD版本号
|
||||
// 返回: string 版本号
|
||||
func (r *Reader) Version() string {
|
||||
|
||||
+18
-5
@@ -60,7 +60,13 @@ type sesSeal struct {
|
||||
// sesCertList SES印章证书列表
|
||||
type sesCertList struct {
|
||||
Certs [][]byte
|
||||
Digests [][]byte
|
||||
Digests []sesCertDigest
|
||||
}
|
||||
|
||||
// sesCertDigest SES印章证书摘要
|
||||
type sesCertDigest struct {
|
||||
Method string
|
||||
Value []byte
|
||||
}
|
||||
|
||||
// sesVerifyResult SES签章验证结果
|
||||
@@ -385,17 +391,21 @@ func parseSESCertDigestList(raw asn1.RawValue) (sesCertList, error) {
|
||||
if !ok || len(items) == 0 {
|
||||
return sesCertList{}, fmt.Errorf("invalid ses cert digest list")
|
||||
}
|
||||
list := sesCertList{Digests: make([][]byte, 0, len(items))}
|
||||
list := sesCertList{Digests: make([]sesCertDigest, 0, len(items))}
|
||||
for _, item := range items {
|
||||
fields, ok := asn1Children(item.Bytes)
|
||||
if !ok || len(fields) < 2 {
|
||||
return sesCertList{}, fmt.Errorf("invalid ses cert digest")
|
||||
}
|
||||
method, err := parseGBTAlgorithm(fields[0])
|
||||
if err != nil {
|
||||
return sesCertList{}, err
|
||||
}
|
||||
digest, err := asn1OctetString(fields[1])
|
||||
if err != nil {
|
||||
return sesCertList{}, err
|
||||
}
|
||||
list.Digests = append(list.Digests, digest)
|
||||
list.Digests = append(list.Digests, sesCertDigest{Method: method, Value: digest})
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
@@ -514,9 +524,12 @@ func sesCertInList(cert []byte, list sesCertList) bool {
|
||||
return true
|
||||
}
|
||||
}
|
||||
digest := signSM3(cert)
|
||||
for _, item := range list.Digests {
|
||||
if bytes.Equal(digest, item) {
|
||||
digest, err := signatureDigest(item.Method, cert)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if bytes.Equal(digest, item.Value) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user