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