mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
rescale image if width or height is specified in ImageWidget
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
local Widget = require("ui/widget/widget")
|
||||
local Image = require("ffi/mupdfimg")
|
||||
local Geom = require("ui/geometry")
|
||||
-- Image
|
||||
|
||||
--[[
|
||||
ImageWidget shows an image from a file
|
||||
@@ -10,6 +10,9 @@ local ImageWidget = Widget:new{
|
||||
invert = nil,
|
||||
dim = nil,
|
||||
hide = nil,
|
||||
-- if width or height is given, image will rescale to the given size
|
||||
width = nil,
|
||||
height = nil,
|
||||
_bb = nil
|
||||
}
|
||||
|
||||
@@ -20,6 +23,10 @@ function ImageWidget:_render()
|
||||
elseif itype == "png" then
|
||||
self._bb = Image:fromPNG(self.file)
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
||||
function ImageWidget:getSize()
|
||||
@@ -34,7 +41,7 @@ function ImageWidget:paintTo(bb, x, y)
|
||||
self.dimen = Geom:new{
|
||||
x = x, y = y,
|
||||
w = size.w,
|
||||
h = size.h
|
||||
h = size.h
|
||||
}
|
||||
if self.hide then return end
|
||||
bb:blitFrom(self._bb, x, y, 0, 0, size.w, size.h)
|
||||
|
||||
Reference in New Issue
Block a user