From f2cf10a015864b807d854c22eab420088e0f01e8 Mon Sep 17 00:00:00 2001 From: chrox Date: Sat, 14 Sep 2013 12:56:10 +0800 Subject: [PATCH] refactoring koptcontext creation function --- frontend/document/koptinterface.lua | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/frontend/document/koptinterface.lua b/frontend/document/koptinterface.lua index 50422d185..1fa2f01a1 100644 --- a/frontend/document/koptinterface.lua +++ b/frontend/document/koptinterface.lua @@ -46,6 +46,12 @@ function KoptInterface:createContext(doc, pageno, bbox) -- So there is no need to check background context when creating new context. local kc = KOPTContext.new() local screen_size = Screen:getSize() + local lang = doc.configurable.doc_language + if lang == "chi_sim" or lang == "chi_tra" or + lang == "jpn" or lang == "kor" then + kc:setCJKChar() + end + kc:setLanguage(lang) kc:setTrim(doc.configurable.trim_page) kc:setWrap(doc.configurable.text_wrap) kc:setIndent(doc.configurable.detect_indent) @@ -62,8 +68,7 @@ function KoptInterface:createContext(doc, pageno, bbox) kc:setDefectSize(doc.configurable.defect_size) kc:setLineSpacing(doc.configurable.line_spacing) kc:setWordSpacing(doc.configurable.word_spacing) - kc:setLanguage(doc.configurable.doc_language) - kc:setBBox(bbox.x0, bbox.y0, bbox.x1, bbox.y1) + if bbox then kc:setBBox(bbox.x0, bbox.y0, bbox.x1, bbox.y1) end if Dbg.is_on then kc:setDebug() end return kc end @@ -133,12 +138,6 @@ function KoptInterface:getReflewTextBoxes(doc, pageno) if cached then local kc = self:waitForContext(cached.kctx) --kc:setDebug() - local lang = doc.configurable.doc_language - if lang == "chi_sim" or lang == "chi_tra" or - lang == "jpn" or lang == "kor" then - kc:setCJKChar() - end - kc:setLanguage(lang) local fullwidth, fullheight = kc:getPageDim() local boxes = kc:getWordBoxes(0, 0, fullwidth, fullheight) Cache:insert(hash, CacheItem:new{ rfpgboxes = boxes }) @@ -154,14 +153,8 @@ function KoptInterface:getTextBoxes(doc, pageno) local cached = Cache:check(hash) if not cached then local kc_hash = "kctx|"..doc.file.."|"..pageno - local kc = KOPTContext.new() + local kc = self:createContext(doc, pageno) kc:setDebug() - local lang = doc.configurable.doc_language - if lang == "chi_sim" or lang == "chi_tra" or - lang == "jpn" or lang == "kor" then - kc:setCJKChar() - end - kc:setLanguage(lang) local page = doc._document:openPage(pageno) page:getPagePix(kc) local fullwidth, fullheight = kc:getPageDim()