refactoring: use Document API getCoverPageImage to get cover image

This commit is contained in:
chrox
2014-08-27 11:07:25 +08:00
parent 40bddf0735
commit 0bc3eadcae
8 changed files with 130 additions and 170 deletions

View File

@@ -27,6 +27,7 @@ ImageWidget shows an image from a file
--]]
local ImageWidget = Widget:new{
file = nil,
image = nil,
invert = nil,
dim = nil,
hide = nil,
@@ -36,7 +37,11 @@ local ImageWidget = Widget:new{
_bb = nil
}
function ImageWidget:_render()
function ImageWidget:_loadimage()
self._bb = self.image
end
function ImageWidget:_loadfile()
local itype = string.lower(string.match(self.file, ".+%.([^.]+)") or "")
if itype == "png" or itype == "jpg" or itype == "jpeg"
or itype == "tiff" then
@@ -58,6 +63,16 @@ function ImageWidget:_render()
else
error("Image file type not supported.")
end
end
function ImageWidget:_render()
if self.image then
self:_loadimage()
elseif self.file then
self:_loadfile()
else
error("cannot render image")
end
local w, h = self._bb:getWidth(), self._bb:getHeight()
if (self.width and self.width ~= w) or (self.height and self.height ~= h) then
self._bb = self._bb:scale(self.width or w, self.height or h)
@@ -92,4 +107,11 @@ function ImageWidget:paintTo(bb, x, y)
end
end
function ImageWidget:free()
if self.image then
self.image:free()
self.image = nil
end
end
return ImageWidget