Skip to content

Commit

Permalink
specify bmp source when calling getNativeWordBoxes and getReflowedWor…
Browse files Browse the repository at this point in the history
…dBoxes
  • Loading branch information
chrox committed Apr 6, 2014
1 parent 5bb5eaa commit c087744
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
15 changes: 10 additions & 5 deletions ffi/koptcontext.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function KOPTContext_mt.__index:dstToBlitBuffer()
end
end

function KOPTContext_mt.__index:getWordBoxes(x, y, w, h, box_type)
function KOPTContext_mt.__index:getWordBoxes(bmp, x, y, w, h, box_type)
local box = ffi.new("BOX[1]")
local boxa = ffi.new("BOXA[1]")
local nai = ffi.new("NUMA[1]")
Expand All @@ -74,12 +74,12 @@ function KOPTContext_mt.__index:getWordBoxes(x, y, w, h, box_type)
local l_x0, l_y0, l_x1, l_y1

if box_type == 0 then
k2pdfopt.k2pdfopt_get_reflowed_word_boxes(self, self.dst,
k2pdfopt.k2pdfopt_get_reflowed_word_boxes(self, bmp == "src" and self.src or self.dst,
ffi.new("int", x), ffi.new("int", y), ffi.new("int", w), ffi.new("int", h))
boxa = self.rboxa
nai = self.rnai
elseif box_type == 1 then
k2pdfopt.k2pdfopt_get_native_word_boxes(self, self.dst,
k2pdfopt.k2pdfopt_get_native_word_boxes(self, bmp == "src" and self.src or self.dst,
ffi.new("int", x), ffi.new("int", y), ffi.new("int", w), ffi.new("int", h))
boxa = self.nboxa
nai = self.nnai
Expand Down Expand Up @@ -130,8 +130,13 @@ function KOPTContext_mt.__index:getWordBoxes(x, y, w, h, box_type)
return boxes
end

function KOPTContext_mt.__index:getReflowedWordBoxes(x, y, w, h) return self:getWordBoxes(x, y, w, h, 0) end
function KOPTContext_mt.__index:getNativeWordBoxes(x, y, w, h) return self:getWordBoxes(x, y, w, h, 1) end
function KOPTContext_mt.__index:getReflowedWordBoxes(bmp, x, y, w, h)
return self:getWordBoxes(bmp, x, y, w, h, 0)
end

function KOPTContext_mt.__index:getNativeWordBoxes(bmp, x, y, w, h)
return self:getWordBoxes(bmp, x, y, w, h, 1)
end

function KOPTContext_mt.__index:reflowToNativePosTransform(xc, yc, wr, hr)
local function wrectmap_reflow_distance(wrmap, x, y)
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/koptcontext_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe("KOPTContext module", function()
local kc = KOPTContext.new()
k2pdfopt.bmpmupdf_pdffile_to_bmp(kc.src, ffi.cast("char*", sample_pdf), 3, 300, 8)
k2pdfopt.k2pdfopt_reflow_bmp(kc)
local boxes = kc:getReflowedWordBoxes(0, 0, kc.dst.width, kc.dst.height)
local boxes = kc:getReflowedWordBoxes("dst", 0, 0, kc.dst.width, kc.dst.height)
for i = 1, #boxes do
for j = 1, #boxes[i] do
local box = boxes[i][j]
Expand All @@ -86,7 +86,7 @@ describe("KOPTContext module", function()
local kc = KOPTContext.new()
k2pdfopt.bmpmupdf_pdffile_to_bmp(kc.src, ffi.cast("char*", sample_pdf), 4, 300, 8)
k2pdfopt.k2pdfopt_reflow_bmp(kc)
local boxes = kc:getNativeWordBoxes(0, 0, kc.dst.width, kc.dst.height)
local boxes = kc:getNativeWordBoxes("dst", 0, 0, kc.dst.width, kc.dst.height)
for i = 1, #boxes do
for j = 1, #boxes[i] do
local box = boxes[i][j]
Expand Down

0 comments on commit c087744

Please sign in to comment.