@ -363,78 +363,85 @@ function BookInfoManager:extractBookInfo(filepath, cover_specs)
-- Proceed with extracting info
-- Proceed with extracting info
local document = DocumentRegistry : openDocument ( filepath )
local document = DocumentRegistry : openDocument ( filepath )
local loaded = true
if document then
if document then
local pages
if document.loadDocument then -- needed for crengine
if document.loadDocument then -- needed for crengine
-- Setting a default font before loading document
-- Setting a default font before loading document
-- actually do prevent some crashes
-- actually do prevent some crashes
document : setFontFace ( document.default_font )
document : setFontFace ( document.default_font )
document : loadDocument ( )
if not document : loadDocument ( ) then
-- Not needed for getting props:
-- failed loading, calling other methods would segfault
-- document:render()
loaded = false
-- It would be needed to get nb of pages, but the nb obtained
end
-- by simply calling here document:getPageCount() is wrong,
-- For CreDocument, we would need to call document:render()
-- often 2 to 3 times the nb of pages we see when opening
-- to get nb of pages, but the nb obtained by simply calling
-- the document (may be some other cre settings should be applied
-- here document:getPageCount() is wrong, often 2 to 3 times
-- before calling render() ?)
-- the nb of pages we see when opening the document (may be
-- some other cre settings should be applied before calling
-- render() ?)
else
else
-- for all others than crengine, we seem to get an accurate nb of pages
-- for all others than crengine, we seem to get an accurate nb of pages
local pages = document : getPageCount ( )
pages = document : getPageCount ( )
dbrow.pages = pages
end
local props = document : getProps ( )
if next ( props ) then -- there's at least one item
dbrow.has_meta = ' Y '
end
end
if props.title and props.title ~= " " then dbrow.title = props.title end
if loaded then
if props.authors and props.authors ~= " " then dbrow.authors = props.authors end
dbrow.pages = pages
if props.series and props.series ~= " " then dbrow.series = props.series end
local props = document : getProps ( )
if props.language and props.language ~= " " then dbrow.language = props.language end
if next ( props ) then -- there's at least one item
if props.keywords and props.keywords ~= " " then dbrow.keywords = props.keywords end
dbrow.has_meta = ' Y '
if props.description and props.description ~= " " then dbrow.description = props.description end
end
if cover_specs then
if props.title and props.title ~= " " then dbrow.title = props.title end
local spec_sizetag = cover_specs.sizetag
if props.authors and props.authors ~= " " then dbrow.authors = props.authors end
local spec_max_cover_w = cover_specs.max_cover_w
if props.series and props.series ~= " " then dbrow.series = props.series end
local spec_max_cover_h = cover_specs.max_cover_h
if props.language and props.language ~= " " then dbrow.language = props.language end
if props.keywords and props.keywords ~= " " then dbrow.keywords = props.keywords end
dbrow.cover_fetched = ' Y ' -- we had a try at getting a cover
if props.description and props.description ~= " " then dbrow.description = props.description end
-- XXX make picdocument return a blitbuffer of the image
if cover_specs then
local cover_bb = document : getCoverPageImage ( )
local spec_sizetag = cover_specs.sizetag
if cover_bb then
local spec_max_cover_w = cover_specs.max_cover_w
dbrow.has_cover = ' Y '
local spec_max_cover_h = cover_specs.max_cover_h
dbrow.cover_sizetag = spec_sizetag
-- we should scale down the cover to our max size
dbrow.cover_fetched = ' Y ' -- we had a try at getting a cover
local cbb_w , cbb_h = cover_bb : getWidth ( ) , cover_bb : getHeight ( )
-- XXX make picdocument return a blitbuffer of the image
local scale_factor = 1
local cover_bb = document : getCoverPageImage ( )
if cbb_w > spec_max_cover_w or cbb_h > spec_max_cover_h then
if cover_bb then
-- scale down if bigger than what we will display
dbrow.has_cover = ' Y '
scale_factor = math.min ( spec_max_cover_w / cbb_w , spec_max_cover_h / cbb_h )
dbrow.cover_sizetag = spec_sizetag
cbb_w = math.min ( math.floor ( cbb_w * scale_factor ) + 1 , spec_max_cover_w )
-- we should scale down the cover to our max size
cbb_h = math.min ( math.floor ( cbb_h * scale_factor ) + 1 , spec_max_cover_h )
local cbb_w , cbb_h = cover_bb : getWidth ( ) , cover_bb : getHeight ( )
local new_bb
local scale_factor = 1
if self.use_legacy_image_scaling then
if cbb_w > spec_max_cover_w or cbb_h > spec_max_cover_h then
new_bb = cover_bb : scale ( cbb_w , cbb_h )
-- scale down if bigger than what we will display
else
scale_factor = math.min ( spec_max_cover_w / cbb_w , spec_max_cover_h / cbb_h )
new_bb = Mupdf.scaleBlitBuffer ( cover_bb , cbb_w , cbb_h )
cbb_w = math.min ( math.floor ( cbb_w * scale_factor ) + 1 , spec_max_cover_w )
cbb_h = math.min ( math.floor ( cbb_h * scale_factor ) + 1 , spec_max_cover_h )
local new_bb
if self.use_legacy_image_scaling then
new_bb = cover_bb : scale ( cbb_w , cbb_h )
else
new_bb = Mupdf.scaleBlitBuffer ( cover_bb , cbb_w , cbb_h )
end
cover_bb : free ( )
cover_bb = new_bb
end
end
cover_bb : free ( )
dbrow.cover_w = cbb_w
cover_bb = new_bb
dbrow.cover_h = cbb_h
dbrow.cover_btype = cover_bb : getType ( )
dbrow.cover_bpitch = cover_bb.pitch
local cover_data = Blitbuffer.tostring ( cover_bb )
cover_bb : free ( ) -- free bb before compressing to save memory
dbrow.cover_datalen = cover_data : len ( )
local cover_dataz = xutil.zlib_compress ( cover_data )
-- release memory used by uncompressed data:
cover_data = nil -- luacheck: no unused
dbrow.cover_dataz = SQ3.blob ( cover_dataz ) -- cast to blob for sqlite
logger.dbg ( " cover for " , filename , " scaled by " , scale_factor , " => " , cbb_w , " x " , cbb_h , " (compressed from " , dbrow.cover_datalen , " to " , cover_dataz : len ( ) )
end
end
dbrow.cover_w = cbb_w
dbrow.cover_h = cbb_h
dbrow.cover_btype = cover_bb : getType ( )
dbrow.cover_bpitch = cover_bb.pitch
local cover_data = Blitbuffer.tostring ( cover_bb )
cover_bb : free ( ) -- free bb before compressing to save memory
dbrow.cover_datalen = cover_data : len ( )
local cover_dataz = xutil.zlib_compress ( cover_data )
-- release memory used by uncompressed data:
cover_data = nil -- luacheck: no unused
dbrow.cover_dataz = SQ3.blob ( cover_dataz ) -- cast to blob for sqlite
logger.dbg ( " cover for " , filename , " scaled by " , scale_factor , " => " , cbb_w , " x " , cbb_h , " (compressed from " , dbrow.cover_datalen , " to " , cover_dataz : len ( ) )
end
end
end
end
DocumentRegistry : closeDocument ( filepath )
DocumentRegistry : closeDocument ( filepath )
else
end
if not loaded then
dbrow.unsupported = _ ( " not readable by engine " )
dbrow.unsupported = _ ( " not readable by engine " )
dbrow.cover_fetched = ' Y ' -- so we don't try again if we're called later if cover_specs
dbrow.cover_fetched = ' Y ' -- so we don't try again if we're called later if cover_specs
end
end