Merge pull request #324 from houqp/houqp-master

add pic document type for jpeg
This commit is contained in:
Huang Xin
2013-10-17 21:00:59 -07:00
5 changed files with 36 additions and 10 deletions

View File

@@ -16,7 +16,6 @@ CreDocument = Document:new{
fallback_font = "Droid Sans Fallback",
default_css = "./data/cr3.css",
options = CreOptions,
configurable = Configurable,
}
-- NuPogodi, 20.05.12: inspect the zipfile content

View File

@@ -10,7 +10,6 @@ DjvuDocument = Document:new{
djvulibre_cache_size = nil,
dc_null = DrawContext.new(),
options = KoptOptions,
configurable = Configurable,
koptinterface = KoptInterface,
}

View File

@@ -60,24 +60,26 @@ Document = {
number_of_pages = 0,
-- if not pageable, length of the document in pixels
doc_height = 0,
-- other metadata
title = "",
author = "",
date = ""
},
GAMMA_NO_GAMMA = 1.0,
-- override bbox from orignal page's getUsedBBox
bbox = {},
-- flag to show whether the document was opened successfully
is_open = false,
error_message = nil,
-- flag to show that the document needs to be unlocked by a password
is_locked = false,
configurable = Configurable,
}
function Document:new(o)
@@ -227,7 +229,7 @@ function Document:renderPage(pageno, rect, zoom, rotation, gamma, render_mode)
size = rect
end
-- prepare cache item with contained blitbuffer
-- prepare cache item with contained blitbuffer
local tile = TileCacheItem:new{
size = size.w * size.h / 2 + 64, -- estimation
excerpt = size,
@@ -248,7 +250,7 @@ function Document:renderPage(pageno, rect, zoom, rotation, gamma, render_mode)
dc:setOffset(0, page_size.h)
end
dc:setZoom(zoom)
if gamma ~= self.GAMMA_NO_GAMMA then
--DEBUG("gamma correction: ", gamma)
dc:setGamma(gamma)
@@ -294,7 +296,7 @@ function Document:drawPage(target, x, y, rect, pageno, zoom, rotation, gamma, re
end
DEBUG("now painting", tile, rect)
target:blitFrom(tile.bb,
x, y,
x, y,
rect.x - tile.excerpt.x,
rect.y - tile.excerpt.y,
rect.w, rect.h)
@@ -313,3 +315,4 @@ end
require "document/pdfdocument"
require "document/djvudocument"
require "document/credocument"
require "document/picdocument"

View File

@@ -10,7 +10,6 @@ PdfDocument = Document:new{
mupdf_cache_size = 5 * 1024 * 1024,
dc_null = DrawContext.new(),
options = KoptOptions,
configurable = Configurable,
koptinterface = KoptInterface,
}

View File

@@ -0,0 +1,26 @@
PicDocument = Document:new{
_document = false,
dc_null = DrawContext.new(),
}
function PicDocument:init()
ok, self._document = pcall(pic.openDocument, self.file)
if not ok then
self.error_message = "failed to open jpeg image"
return
end
self.info.has_pages = true
self.info.configurable = false
self:readMetadata()
end
function PicDocument:readMetadata()
self.info.number_of_pages = 1
end
DocumentRegistry:addProvider("jpeg", "application/jpeg", PicDocument)
DocumentRegistry:addProvider("jpg", "application/jpeg", PicDocument)