mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-29 17:27:08 +08:00
This commit is contained in:
1 parent
2ea937b7be
commit
1c7f3c03e9
6 files changed
+189
-11
No files matched your search
@@ -164,6 +164,14 @@ func renderPage(args []js.Value) (any, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
text, err := currentSession.PageText(args[0].Int())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
textData, err := json.Marshal(text)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
links := make([]any, len(page.Links))
|
||||
for i, link := range page.Links {
|
||||
links[i] = map[string]any{
|
||||
@@ -182,6 +190,7 @@ func renderPage(args []js.Value) (any, error) {
|
||||
"height": page.Height,
|
||||
"svg": page.SVG,
|
||||
"links": links,
|
||||
"text": js.Global().Get("JSON").Call("parse", string(textData)),
|
||||
}), nil
|
||||
}
|
||||
|
||||
|
||||
+15
-4
@@ -270,10 +270,10 @@ func (s *Session) SetFonts(fonts []FontFile) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SearchPage 搜索指定页面,复用当前会话的文字索引
|
||||
// 入参: index 页面索引, query 搜索文字
|
||||
// 返回: []ofdgo.TextMatch 匹配结果, error 错误信息
|
||||
func (s *Session) SearchPage(index int, query string) ([]ofdgo.TextMatch, error) {
|
||||
// PageText 获取指定页面文字,复用当前会话的文字索引
|
||||
// 入参: index 页面索引
|
||||
// 返回: *ofdgo.PageText 页面文字, error 错误信息
|
||||
func (s *Session) PageText(index int) (*ofdgo.PageText, error) {
|
||||
text := s.textCache[index]
|
||||
if text == nil {
|
||||
_, page, err := s.pageContent(index)
|
||||
@@ -286,6 +286,17 @@ func (s *Session) SearchPage(index int, query string) ([]ofdgo.TextMatch, error)
|
||||
}
|
||||
s.textCache[index] = text
|
||||
}
|
||||
return text, nil
|
||||
}
|
||||
|
||||
// SearchPage 搜索指定页面,复用当前会话的文字索引
|
||||
// 入参: index 页面索引, query 搜索文字
|
||||
// 返回: []ofdgo.TextMatch 匹配结果, error 错误信息
|
||||
func (s *Session) SearchPage(index int, query string) ([]ofdgo.TextMatch, error) {
|
||||
text, err := s.PageText(index)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return text.Search(query), nil
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user