Refactoring

This commit is contained in:
Oleg Korshul
2022-01-17 16:04:41 +03:00
parent b9d6b59991
commit 85a551fb63
14 changed files with 0 additions and 3011 deletions

View File

@ -110,12 +110,6 @@ BYTE* CDjVuFile::GetStructure()
return m_pImplementation->GetStructure(); return m_pImplementation->GetStructure();
return NULL; return NULL;
} }
BYTE* CDjVuFile::GetGlyphs(int nPageIndex)
{
if (m_pImplementation)
return m_pImplementation->GetPageGlyphs(nPageIndex);
return NULL;
}
BYTE* CDjVuFile::GetLinks (int nPageIndex) BYTE* CDjVuFile::GetLinks (int nPageIndex)
{ {
if (m_pImplementation) if (m_pImplementation)

View File

@ -75,7 +75,6 @@ public:
#ifdef BUILDING_WASM_MODULE #ifdef BUILDING_WASM_MODULE
virtual BYTE* GetStructure(); virtual BYTE* GetStructure();
virtual BYTE* GetGlyphs(int nPageIndex);
virtual BYTE* GetLinks (int nPageIndex); virtual BYTE* GetLinks (int nPageIndex);
#endif #endif
}; };

View File

@ -1,175 +0,0 @@
QT -= core gui
TARGET = djvu_common
#TEMPLATE = lib
#CONFIG += staticlib
CONFIG += console
CONFIG -= app_bundle
CONFIG -= debug_and_release debug_and_release_target
DEFINES += _LIB
DEFINES += _CRT_SECURE_NO_WARNINGS
DEFINES -= UNICODE
DEFINES -= _UNICODE
DEFINES += NOMINMAX
DEFINES += WASM_MODE
DEFINES += THREADMODEL=0
DEFINES += "UINT=unsigned int"
DEFINES += DEBUGLVL=0
DEFINES += WASM_MODE_DEBUG
CONFIG += core_windows
core_linux {
DEFINES += \
HAVE_UNISTD_H \
HAVE_MBSTATE_T \
GCONTAINER_NO_MEMBER_TEMPLATES="1" \
HAS_WCHAR \
HAVE_WCHAR_H \
UNIX \
HAVE_STDINCLUDES
}
core_mac {
DEFINES += \
HAVE_UNISTD_H \
HAVE_MBSTATE_T \
GCONTAINER_NO_MEMBER_TEMPLATES="1" \
HAS_WCHAR \
HAVE_WCHAR_H \
UNIX \
HAVE_STDINCLUDES
}
core_windows {
LIBS += -lgdi32 \
-ladvapi32 \
-luser32 \
-lshell32
}
DJVULIB_SOURCE = $$PWD/../libdjvu
DJVULIB_SOURCE_WRAPPER = $$PWD/libdjvu
#SOURCES += \
# $$DJVULIB_SOURCE/atomic.cpp
# $$DJVULIB_SOURCE/wasm/DjVuMessage.cpp \
# $$DJVULIB_SOURCE/wasm/GOS.cpp \
# $$DJVULIB_SOURCE/GURL.cpp
SOURCES += \
$$DJVULIB_SOURCE/Arrays.cpp \
$$DJVULIB_SOURCE/BSByteStream.cpp \
$$DJVULIB_SOURCE/BSEncodeByteStream.cpp \
$$DJVULIB_SOURCE/ByteStream.cpp \
$$DJVULIB_SOURCE/DataPool.cpp \
$$DJVULIB_SOURCE/debug.cpp \
$$DJVULIB_SOURCE/DjVmDir.cpp \
$$DJVULIB_SOURCE/DjVmDir0.cpp \
$$DJVULIB_SOURCE/DjVmDoc.cpp \
$$DJVULIB_SOURCE/DjVmNav.cpp \
$$DJVULIB_SOURCE/DjVuAnno.cpp \
$$DJVULIB_SOURCE/DjVuDocEditor.cpp \
$$DJVULIB_SOURCE/DjVuDocument.cpp \
$$DJVULIB_SOURCE/DjVuDumpHelper.cpp \
$$DJVULIB_SOURCE/DjVuErrorList.cpp \
$$DJVULIB_SOURCE/DjVuFile.cpp \
$$DJVULIB_SOURCE/DjVuFileCache.cpp \
$$DJVULIB_SOURCE/DjVuGlobal.cpp \
$$DJVULIB_SOURCE/DjVuGlobalMemory.cpp \
$$DJVULIB_SOURCE/DjVuImage.cpp \
$$DJVULIB_SOURCE/DjVuInfo.cpp \
$$DJVULIB_SOURCE/DjVuMessageLite.cpp \
$$DJVULIB_SOURCE/DjVuNavDir.cpp \
$$DJVULIB_SOURCE/DjVuPalette.cpp \
$$DJVULIB_SOURCE/DjVuPort.cpp \
$$DJVULIB_SOURCE/DjVuText.cpp \
$$DJVULIB_SOURCE/DjVuToPS.cpp \
$$DJVULIB_SOURCE/GBitmap.cpp \
$$DJVULIB_SOURCE/GContainer.cpp \
$$DJVULIB_SOURCE/GException.cpp \
$$DJVULIB_SOURCE/GIFFManager.cpp \
$$DJVULIB_SOURCE/GMapAreas.cpp \
$$DJVULIB_SOURCE/GPixmap.cpp \
$$DJVULIB_SOURCE/GRect.cpp \
$$DJVULIB_SOURCE/GScaler.cpp \
$$DJVULIB_SOURCE/GSmartPointer.cpp \
$$DJVULIB_SOURCE/GString.cpp \
$$DJVULIB_SOURCE/GThreads.cpp \
$$DJVULIB_SOURCE/GUnicode.cpp \
$$DJVULIB_SOURCE/IFFByteStream.cpp \
$$DJVULIB_SOURCE/IW44EncodeCodec.cpp \
$$DJVULIB_SOURCE/IW44Image.cpp \
$$DJVULIB_SOURCE/JB2EncodeCodec.cpp \
$$DJVULIB_SOURCE/JB2Image.cpp \
$$DJVULIB_SOURCE/JPEGDecoder.cpp \
$$DJVULIB_SOURCE/MMRDecoder.cpp \
$$DJVULIB_SOURCE/MMX.cpp \
$$DJVULIB_SOURCE/UnicodeByteStream.cpp \
$$DJVULIB_SOURCE/XMLParser.cpp \
$$DJVULIB_SOURCE/XMLTags.cpp \
$$DJVULIB_SOURCE/ZPCodec.cpp
SOURCES += \
$$DJVULIB_SOURCE_WRAPPER/atomic.cpp \
$$DJVULIB_SOURCE_WRAPPER/DjVuMessage.cpp \
$$DJVULIB_SOURCE_WRAPPER/GOS.cpp \
$$DJVULIB_SOURCE_WRAPPER/GURL.cpp
SOURCES += djvu_common.cpp
HEADERS += \
$$DJVULIB_SOURCE/Arrays.h \
$$DJVULIB_SOURCE/atomic.h \
$$DJVULIB_SOURCE/BSByteStream.h \
$$DJVULIB_SOURCE/ByteStream.h \
$$DJVULIB_SOURCE/DataPool.h \
$$DJVULIB_SOURCE/debug.h \
$$DJVULIB_SOURCE/DjVmDir.h \
$$DJVULIB_SOURCE/DjVmDir0.h \
$$DJVULIB_SOURCE/DjVmDoc.h \
$$DJVULIB_SOURCE/DjVmNav.h \
$$DJVULIB_SOURCE/DjVuAnno.h \
$$DJVULIB_SOURCE/DjVuDocEditor.h \
$$DJVULIB_SOURCE/DjVuDocument.h \
$$DJVULIB_SOURCE/DjVuDumpHelper.h \
$$DJVULIB_SOURCE/DjVuErrorList.h \
$$DJVULIB_SOURCE/DjVuFile.h \
$$DJVULIB_SOURCE/DjVuFileCache.h \
$$DJVULIB_SOURCE/DjVuGlobal.h \
$$DJVULIB_SOURCE/DjVuImage.h \
$$DJVULIB_SOURCE/DjVuInfo.h \
$$DJVULIB_SOURCE/DjVuMessage.h \
$$DJVULIB_SOURCE/DjVuMessageLite.h \
$$DJVULIB_SOURCE/DjVuNavDir.h \
$$DJVULIB_SOURCE/DjVuPalette.h \
$$DJVULIB_SOURCE/DjVuPort.h \
$$DJVULIB_SOURCE/DjVuText.h \
$$DJVULIB_SOURCE/DjVuToPS.h \
$$DJVULIB_SOURCE/GBitmap.h \
$$DJVULIB_SOURCE/GContainer.h \
$$DJVULIB_SOURCE/GException.h \
$$DJVULIB_SOURCE/GIFFManager.h \
$$DJVULIB_SOURCE/GMapAreas.h \
$$DJVULIB_SOURCE/GOS.h \
$$DJVULIB_SOURCE/GPixmap.h \
$$DJVULIB_SOURCE/GRect.h \
$$DJVULIB_SOURCE/GScaler.h \
$$DJVULIB_SOURCE/GSmartPointer.h \
$$DJVULIB_SOURCE/GString.h \
$$DJVULIB_SOURCE/GThreads.h \
$$DJVULIB_SOURCE/GURL.h \
$$DJVULIB_SOURCE/IFFByteStream.h \
$$DJVULIB_SOURCE/IW44Image.h \
$$DJVULIB_SOURCE/JB2Image.h \
$$DJVULIB_SOURCE/JPEGDecoder.h \
$$DJVULIB_SOURCE/MMRDecoder.h \
$$DJVULIB_SOURCE/MMX.h \
$$DJVULIB_SOURCE/UnicodeByteStream.h \
$$DJVULIB_SOURCE/XMLParser.h \
$$DJVULIB_SOURCE/XMLTags.h \
$$DJVULIB_SOURCE/ZPCodec.h

View File

@ -1,492 +0,0 @@
window.onload = function()
{
var userAgent = navigator.userAgent.toLowerCase();
// ie detect
var isIE = (userAgent.indexOf("msie") > -1 || userAgent.indexOf("trident") > -1 || userAgent.indexOf("edge") > -1);
// chrome detect
var isChrome = !isIE && (userAgent.indexOf("chrome") > -1);
// mobile detect
var isMobile = /android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od|ad)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(navigator.userAgent || navigator.vendor || window.opera);
var isOperaOld = (!!window.opera);
var holder = document.body;
holder.ondragover = function(e)
{
var isFile = false;
if (e.dataTransfer.types)
{
for (var i = 0, length = e.dataTransfer.types.length; i < length; ++i)
{
var type = e.dataTransfer.types[i].toLowerCase();
if (type == "files" && e.dataTransfer.items && e.dataTransfer.items.length == 1)
{
var item = e.dataTransfer.items[0];
if (item.kind && "file" == item.kind.toLowerCase())
{
isFile = true;
break;
}
}
}
}
e.dataTransfer.dropEffect = isFile ? "copy" : "none";
e.preventDefault();
return false;
};
holder.ondrop = function(e)
{
var file = e.dataTransfer.files ? e.dataTransfer.files[0] : null;
if (!file)
{
e.preventDefault();
return false;
}
var reader = new FileReader();
reader.onload = function(e) {
window.Viewer.open(e.target.result);
};
reader.readAsArrayBuffer(file);
return false;
};
function CCacheManager()
{
this.images = [];
this.lock = function(w, h)
{
for (let i = 0; i < this.images.length; i++)
{
if (this.images[i].locked)
continue;
let canvas = this.images[i].canvas;
let testW = canvas.width;
let testH = canvas.height;
if (w > testW || h > testH || ((4 * w * h) < (testW * testH)))
{
this.images.splice(i, 1);
continue;
}
this.images[i].locked = true;
return canvas;
}
let newImage = { canvas : document.createElement("canvas"), locked : true };
newImage.canvas.width = w + 100;
newImage.canvas.height = h + 100;
this.images.push(newImage);
return newImage.canvas;
};
this.unlock = function(canvas)
{
for (let i = 0, len = this.images.length; i < len; i++)
{
if (this.images[i].canvas === canvas)
{
this.images[i].locked = false;
return;
}
}
};
this.clear = function()
{
this.images = [];
};
};
function CHtmlPage()
{
this.width = 0;
this.height = 0;
this.retinaPixelRatio = 1;
this.zoom = 1;
this.drawingPages = [];
this.isRepaint = false;
this.canvas = document.getElementById("main");
this.scroller = document.getElementById("pos");
this.documentWidth = 0;
this.documentHeight = 0;
this.Selection = { IsSelection : false, Image : null, page : -1 };
this.file = new AscViewer.CDrawingFile();
/*
[TIMER START]
*/
this.UseRequestAnimationFrame = isChrome;
this.RequestAnimationFrame = (function()
{
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame || null;
})();
this.CancelAnimationFrame = (function()
{
return window.cancelRequestAnimationFrame ||
window.webkitCancelAnimationFrame ||
window.webkitCancelRequestAnimationFrame ||
window.mozCancelRequestAnimationFrame ||
window.oCancelRequestAnimationFrame ||
window.msCancelRequestAnimationFrame || null;
})();
if (this.UseRequestAnimationFrame)
{
if (null == this.RequestAnimationFrame)
this.UseRequestAnimationFrame = false;
}
this.RequestAnimationOldTime = -1;
this.startTimer = function()
{
if (this.UseRequestAnimationFrame)
this.timerAnimation();
else
this.timer();
};
/*
[TIMER END]
*/
this.log = function(message)
{
//console.log(message);
};
window.onscroll = function(e) { if (window.Viewer) window.Viewer.scroll(e); };
window.onmousedown = function(e) { if (window.Viewer) window.Viewer.OnMouse(e, true); };
window.onmousemove = function(e) { if (window.Viewer) window.Viewer.OnMouse(e, false); };
window.onmouseup = function(e) { if (window.Viewer) window.Viewer.OnMouseUp(e); };
this.timerAnimation = function()
{
var now = Date.now();
if (-1 == window.Viewer.RequestAnimationOldTime || (now >= (window.Viewer.RequestAnimationOldTime + 40)) || (now < window.Viewer.RequestAnimationOldTime))
{
window.Viewer.RequestAnimationOldTime = now;
window.Viewer.timer();
}
window.Viewer.RequestAnimationFrame.call(window, window.Viewer.timerAnimation);
};
this.timer = function()
{
if (window.Viewer.isRepaint)
{
window.Viewer._paint();
window.Viewer.isRepaint = false;
}
if (!window.Viewer.UseRequestAnimationFrame)
{
setTimeout(window.Viewer.timer, 40);
}
};
this.resize = function()
{
this.zoom = 1;
this.retinaPixelRatio = 1;
/*
if (isChrome && !isOperaOld && !isMobile && document && document.firstElementChild && document.body)
{
// делаем простую проверку
// считаем: 0 < window.devicePixelRatio < 2 => _devicePixelRatio = 1; zoom = window.devicePixelRatio / _devicePixelRatio;
// считаем: window.devicePixelRatio >= 2 => _devicePixelRatio = 2; zoom = window.devicePixelRatio / _devicePixelRatio;
if (window.devicePixelRatio > 0.1)
{
if (window.devicePixelRatio < 1.99)
{
var _devicePixelRatio = 1;
this.zoom = window.devicePixelRatio / _devicePixelRatio;
}
else
{
var _devicePixelRatio = 2;
this.zoom = window.devicePixelRatio / _devicePixelRatio;
this.retinaPixelRatio = 2;
}
// chrome 54.x: zoom = "reset" - clear retina zoom (windows)
//document.firstElementChild.style.zoom = "reset";
document.firstElementChild.style.zoom = 1.0 / this.zoom;
}
else
document.firstElementChild.style.zoom = "normal";
}
else
{
var isRetina = (Math.abs(2 - (window.devicePixelRatio / this.zoom)) < 0.01);
if (isRetina)
this.retinaPixelRatio = 2;
if (isMobile)
{
this.retinaPixelRatio = window.devicePixelRatio;
}
}
*/
this.width = this.canvas.clientWidth;
this.height = this.canvas.clientHeight;
this.canvas.width = (this.width * this.retinaPixelRatio) >> 0;
this.canvas.height = (this.height * this.retinaPixelRatio) >> 0;
this.recalculatePlaces();
this.log("retinaScale: " + this.retinaPixelRatio + ", zoom: " + this.zoom);
};
this.open = function(data)
{
if (this.file)
this.file.close();
this.file = window["AscViewer"].createFile(data);
this.Selection.Image = this.cacheManager ? this.cacheManager.lock(0, 0) : document.createElement("canvas");
document.scrollingElement.scrollLeft = 0;
document.scrollingElement.scrollTop = 0;
this.scroller.style.width = "0px";
this.scroller.style.height = "0px";
this.resize();
};
this.recalculatePlaces = function()
{
this.drawingPages = [];
for (let i = 0, len = this.file.pages.length; i < len; i++)
{
this.drawingPages.push({
X : 0,
Y : 0,
W : (this.file.pages[i].W * 96 * this.zoom / this.file.pages[i].Dpi) >> 0,
H : (this.file.pages[i].H * 96 * this.zoom / this.file.pages[i].Dpi) >> 0,
});
}
this.documentWidth = 0;
for (let i = 0, len = this.drawingPages.length; i < len; i++)
{
if (this.drawingPages[i].W > this.documentWidth)
this.documentWidth = this.drawingPages[i].W;
}
var curTop = 20;
for (let i = 0, len = this.drawingPages.length; i < len; i++)
{
this.drawingPages[i].X = (this.documentWidth - this.drawingPages[i].W) >> 1;
this.drawingPages[i].Y = curTop;
curTop += this.drawingPages[i].H;
curTop += 20;
}
this.documentHeight = curTop;
var oldX = document.scrollingElement.scrollLeft;
var oldY = document.scrollingElement.scrollTop;
var oldW = parseInt(this.scroller.style.width);
var oldH = parseInt(this.scroller.style.height);
this.scroller.style.width = this.documentWidth + "px";
this.scroller.style.height = this.documentHeight + "px";
var newX = (oldX * oldW / Math.max(1, this.documentWidth)) >> 0;
var newY = (oldY * oldH / Math.max(1, this.documentHeight)) >> 0;
if (newX < 0) newX = 0;
if (newY < 0) newY = 0;
var newXMax = Math.max(0, this.documentWidth - this.width);
var newYMax = Math.max(0, this.documentHeight - this.height);
if (newX > newXMax)
newX = newXMax;
if (newY > newYMax)
newY = newYMax;
document.scrollingElement.scrollLeft = newX;
document.scrollingElement.scrollTop = newY;
this.paint();
};
this.scroll = function(e)
{
this.log("scroll: [" + document.scrollingElement.scrollLeft + ", " + document.scrollingElement.scrollTop + "]");
this.paint();
};
this.OnMouse = function(e, down)
{
if (!this.file.isValid())
return;
let lCurrentPage = -1;
for (let i = 0; i < this.drawingPages.length; i++)
{
let page = this.drawingPages[i];
let pageT = page.Y;
let pageB = page.Y + page.H;
if (e.pageY > pageT && e.pageY < pageB)
{
lCurrentPage = i;
break;
}
}
if (lCurrentPage >= 0)
{
let yPos = (document.scrollingElement.scrollTop * this.zoom) >> 0;
let page = this.drawingPages[lCurrentPage];
let w = (page.W * this.retinaPixelRatio) >> 0;
let h = (page.H * this.retinaPixelRatio) >> 0;
let x = e.pageX - (Math.max(0, (this.width - this.documentWidth) >> 1) * this.retinaPixelRatio) >> 0;
let y = e.pageY - (page.Y * this.retinaPixelRatio) >> 0;
this.Selection.page = lCurrentPage;
if (down)
this.file.OnMouseDown(lCurrentPage, this.Selection, x, y, w, h);
else
this.file.OnMouseMove(lCurrentPage, this.Selection, x, y, w, h);
if (this.Selection.IsSelection)
this.paint();
}
};
this.OnMouseUp = function(e)
{
this.file.OnMouseUp();
this.paint();
};
this.paint = function()
{
this.isRepaint = true;
};
this.getStructure = function()
{
var res = this.file.getStructure();
return res;
};
this.getGlyphs = function(pageIndex, width, height)
{
this.file.getGlyphs(pageIndex, width, height);
};
this.getLinks = function(pageIndex, width, height)
{
var res = this.file.getLinks(pageIndex, width, height);
return res;
};
this._paint = function()
{
if (!this.isRepaint)
return;
if (!this.file.isValid())
return;
let ctx = this.canvas.getContext("2d");
ctx.strokeStyle = "#000000";
let lineW = this.retinaPixelRatio >> 0;
ctx.lineWidth = lineW;
let yPos = (document.scrollingElement.scrollTop * this.zoom) >> 0;
let yMax = yPos + this.height;
let xCenter = this.width >> 1;
if (this.documentWidth > this.width)
{
xCenter = (this.documentWidth >> 1) - (document.scrollingElement.scrollLeft * this.zoom) >> 0;
}
let lStartPage = -1;
let lEndPage = -1;
let lPagesCount = this.drawingPages.length;
for (let i = 0; i < lPagesCount; i++)
{
let page = this.drawingPages[i];
let pageT = page.Y;
let pageB = page.Y + page.H;
if (yPos < pageB && yMax > pageT)
{
// страница на экране
if (-1 == lStartPage)
lStartPage = i;
lEndPage = i;
}
else
{
// страница не видна - выкидываем из кэша
if (page.Image)
{
if (this.file.cacheManager)
this.file.cacheManager.unlock(page.Image);
delete page.Image;
}
}
}
for (let i = lStartPage; i <= lEndPage; i++)
{
// отрисовываем страницу
let page = this.drawingPages[i];
let w = (page.W * this.retinaPixelRatio) >> 0;
let h = (page.H * this.retinaPixelRatio) >> 0;
if (!this.file.cacheManager)
{
if (page.Image && ((page.Image.width != w) || (page.Image.height != h)))
delete page.Image;
}
else
{
if (page.Image && ((page.Image.width < w) || (page.Image.height < h)))
{
if (this.file.cacheManager)
this.file.cacheManager.unlock(page.Image);
delete page.Image;
}
}
if (!page.Image)
page.Image = this.file.getPage(i, w, h);
let x = ((xCenter * this.retinaPixelRatio) >> 0) - (w >> 1);
let y = ((page.Y - yPos) * this.retinaPixelRatio) >> 0;
ctx.drawImage(page.Image, 0, 0, w, h, x, y, w, h);
if (this.Selection.page == i && this.Selection.IsSelection)
ctx.drawImage(this.Selection.Image, 0, 0, w, h, x, y, w, h);
ctx.strokeRect(x + lineW / 2, y + lineW / 2, w - lineW, h - lineW);
}
};
}
window.Viewer = new CHtmlPage();
window.Viewer.resize();
window.Viewer.startTimer();
window.CCacheManager = CCacheManager;
};
window.onresize = function(e)
{
if (window.Viewer)
window.Viewer.resize();
};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,393 +0,0 @@
(function(window, undefined) {
function CDocMetaSelection()
{
this.Page1 = 0;
this.Line1 = 0;
this.Glyph1 = 0;
this.Page2 = 0;
this.Line2 = 0;
this.Glyph2 = 0;
this.IsSelection = false;
}
function CFile()
{
this.nativeFile = 0;
this.pages = [];
this.zoom = 1;
this.isUse3d = false;
this.cacheManager = null;
this.logging = true;
this.Selection = new CDocMetaSelection();
}
// interface
CFile.prototype.loadFromData = function(data) {};
CFile.prototype.load = function(arrayBuffer)
{
return this.loadFromData(new Uint8Array(arrayBuffer));
};
CFile.prototype.getInfo = function() {};
CFile.prototype.getPagePixmap = function(pageIndex, width, height) {};
CFile.prototype.close = function() {};
CFile.prototype.memory = function() {};
CFile.prototype.free = function(pointer) {};
CFile.prototype.getPage = function(pageIndex, width, height)
{
if (pageIndex < 0 || pageIndex >= this.pages.length)
return null;
if (!width) width = this.pages[pageIndex].W;
if (!height) height = this.pages[pageIndex].H;
var t0 = performance.now();
var pixels = this.getPagePixmap(pageIndex, width, height);
if (!pixels)
return null;
if (!this.logging)
{
var image = this._pixelsToCanvas(pixels, width, height);
}
else
{
var t1 = performance.now();
var image = this._pixelsToCanvas(pixels, width, height);
var t2 = performance.now();
}
this.free(pixels);
return image;
};
CFile.prototype.GetNearestPos = function(pageIndex, x, y)
{
var _line = -1;
var _glyph = -1;
var minDist = Number.MAX_SAFE_INTEGER;
if (!this.pages[pageIndex].Lines)
return { Line : _line, Glyph : _glyph };
for (let i = 0; i < this.pages[pageIndex].Lines.length; i++)
{
let Y = this.pages[pageIndex].Lines[i].Glyphs[0].Y;
if (Math.abs(Y - y) < minDist)
{
minDist = Math.abs(Y - y);
_line = i;
}
}
minDist = Number.MAX_SAFE_INTEGER;
for (let j = 0; j < this.pages[pageIndex].Lines[_line].Glyphs.length; j++)
{
let X = this.pages[pageIndex].Lines[_line].Glyphs[j].X;
if (Math.abs(X - x) < minDist)
{
minDist = Math.abs(X - x);
_glyph = j;
}
}
return { Line : _line, Glyph : _glyph };
}
CFile.prototype.OnUpdateSelection = function(Selection, width, height)
{
if (!this.Selection.IsSelection)
return;
var sel = this.Selection;
var page1 = sel.Page1;
var page2 = sel.Page2;
var line1 = sel.Line1;
var line2 = sel.Line2;
var glyph1 = sel.Glyph1;
var glyph2 = sel.Glyph2;
if (page1 == page2 && line1 == line2 && glyph1 == glyph2)
{
Selection.IsSelection = false;
return;
}
else if (page1 == page2 && line1 == line2)
{
glyph1 = Math.min(sel.Glyph1, sel.Glyph2);
glyph2 = Math.max(sel.Glyph1, sel.Glyph2);
}
else if (page1 == page2)
{
if (line1 > line2)
{
line1 = sel.Line2;
line2 = sel.Line1;
glyph1 = sel.Glyph2;
glyph2 = sel.Glyph1;
}
}
if (this.cacheManager)
{
this.cacheManager.unlock(Selection.Image);
Selection.Image = this.cacheManager.lock(width, height);
}
else
{
delete Selection.Image;
Selection.Image = document.createElement("canvas");
Selection.Image.width = width;
Selection.Image.height = height;
}
let ctx = Selection.Image.getContext("2d");
// TODO: После изменения размера экрана наложение областей выделения
ctx.clearRect(0, 0, Selection.Image.width, Selection.Image.height);
ctx.globalAlpha = 0.4;
ctx.fillStyle = "#7070FF";
for (let page = page1; page <= page2; page++)
{
let start = 0;
let end = this.pages[page].Lines.length;
if (page == page1)
start = line1;
if (page == page2)
end = line2;
for (let line = start; line <= end; line++)
{
let Glyphs = this.pages[page].Lines[line].Glyphs;
let x = Glyphs[0].X;
let y = Glyphs[0].Y - Glyphs[0].fontSize;
// первая строка на первой странице
if (page == page1 && line == start)
x = Glyphs[glyph1].X;
let w = Glyphs[Glyphs.length - 1].X - x;
let h = Glyphs[0].fontSize;
// последняя строка на последней странице
if (page == page2 && line == end)
w = Glyphs[glyph2].X - x;
ctx.fillRect(x, y, w, h);
}
}
ctx.globalAlpha = 1;
Selection.IsSelection = true;
}
CFile.prototype.OnMouseDown = function(pageIndex, Selection, x, y, w, h)
{
var ret = this.GetNearestPos(pageIndex, x, y);
var sel = this.Selection;
sel.Page1 = pageIndex;
sel.Line1 = ret.Line;
sel.Glyph1 = ret.Glyph;
sel.Page2 = pageIndex;
sel.Line2 = ret.Line;
sel.Glyph2 = ret.Glyph;
sel.IsSelection = true;
this.OnUpdateSelection(Selection, w, h);
}
CFile.prototype.OnMouseMove = function(pageIndex, Selection, x, y, w, h)
{
if (false === this.Selection.IsSelection)
return;
var ret = this.GetNearestPos(pageIndex, x, y);
var sel = this.Selection;
sel.Page2 = pageIndex;
sel.Line2 = ret.Line;
sel.Glyph2 = ret.Glyph;
this.OnUpdateSelection(Selection, w, h);
}
CFile.prototype.OnMouseUp = function()
{
this.Selection.IsSelection = false;
}
CFile.prototype.getPageBase64 = function(pageIndex, width, height)
{
var _canvas = this.getPage(pageIndex, width, height);
if (!_canvas)
return "";
try
{
return _canvas.toDataURL("image/png");
}
catch (err)
{
}
return "";
};
CFile.prototype.isValid = function()
{
return this.pages.length > 0;
};
// private functions
CFile.prototype._pixelsToCanvas2d = function(pixels, width, height)
{
var canvas = null;
if (this.cacheManager)
{
canvas = this.cacheManager.lock(width, height);
}
else
{
canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
}
var mappedBuffer = new Uint8ClampedArray(this.memory().buffer, pixels, 4 * width * height);
var imageData = new ImageData(mappedBuffer, width, height);
var ctx = canvas.getContext("2d");
if (ctx)
ctx.putImageData(imageData, 0, 0);
return canvas;
};
CFile.prototype._pixelsToCanvas3d = function(pixels, width, height)
{
var vs_source = "\
attribute vec2 aVertex;\n\
attribute vec2 aTex;\n\
varying vec2 vTex;\n\
void main() {\n\
gl_Position = vec4(aVertex, 0.0, 1.0);\n\
vTex = aTex;\n\
}";
var fs_source = "\
precision mediump float;\n\
uniform sampler2D uTexture;\n\
varying vec2 vTex;\n\
void main() {\n\
gl_FragColor = texture2D(uTexture, vTex);\n\
}";
var canvas = null;
if (this.cacheManager)
{
canvas = this.cacheManager.lock(width, height);
}
else
{
canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
}
var gl = canvas.getContext('webgl', { preserveDrawingBuffer : true });
if (!gl)
throw new Error('FAIL: could not create webgl canvas context');
var colorCorrect = gl.BROWSER_DEFAULT_WEBGL;
gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, colorCorrect);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
gl.viewport(0, 0, canvas.width, canvas.height);
gl.clearColor(0, 0, 0, 1);
gl.clear(gl.COLOR_BUFFER_BIT);
if (gl.getError() != gl.NONE)
throw new Error('FAIL: webgl canvas context setup failed');
function createShader(source, type) {
var shader = gl.createShader(type);
gl.shaderSource(shader, source);
gl.compileShader(shader);
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS))
throw new Error('FAIL: shader ' + id + ' compilation failed');
return shader;
}
var program = gl.createProgram();
gl.attachShader(program, createShader(vs_source, gl.VERTEX_SHADER));
gl.attachShader(program, createShader(fs_source, gl.FRAGMENT_SHADER));
gl.linkProgram(program);
if (!gl.getProgramParameter(program, gl.LINK_STATUS))
throw new Error('FAIL: webgl shader program linking failed');
gl.useProgram(program);
var texture = gl.createTexture();
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array(this.memory().buffer, pixels, 4 * width * height));
if (gl.getError() != gl.NONE)
throw new Error('FAIL: creating webgl image texture failed');
function createBuffer(data) {
var buffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);
return buffer;
}
var vertexCoords = new Float32Array([-1, 1, -1, -1, 1, -1, 1, 1]);
var vertexBuffer = createBuffer(vertexCoords);
var location = gl.getAttribLocation(program, 'aVertex');
gl.enableVertexAttribArray(location);
gl.vertexAttribPointer(location, 2, gl.FLOAT, false, 0, 0);
if (gl.getError() != gl.NONE)
throw new Error('FAIL: vertex-coord setup failed');
var texCoords = new Float32Array([0, 1, 0, 0, 1, 0, 1, 1]);
var texBuffer = createBuffer(texCoords);
var location = gl.getAttribLocation(program, 'aTex');
gl.enableVertexAttribArray(location);
gl.vertexAttribPointer(location, 2, gl.FLOAT, false, 0, 0);
if (gl.getError() != gl.NONE)
throw new Error('FAIL: tex-coord setup setup failed');
gl.drawArrays(gl.TRIANGLE_FAN, 0, 4);
return canvas;
};
CFile.prototype._pixelsToCanvas = function(pixels, width, height)
{
if (!this.isUse3d)
{
return this._pixelsToCanvas2d(pixels, width, height);
}
try
{
return this._pixelsToCanvas3d(pixels, width, height);
}
catch (err)
{
this.isUse3d = false;
if (this.cacheManager)
this.cacheManager.clear();
return this._pixelsToCanvas(pixels, width, height);
}
};
window["AscViewer"] = window["AscViewer"] || {};
window["AscViewer"].IFile = CFile;
window["AscViewer"].createFile = function(buffer)
{
var data = new Uint8Array(buffer);
var file = new window["AscViewer"].CDrawingFile();
file.loadFromData(data);
file.cacheManager = new window.CCacheManager();
return file;
};
})(window, undefined);

View File

@ -1,15 +0,0 @@
<!doctype html>
<html style="width:100%;height:100%;margin:0;padding:0;">
<head>
<title>ONLYOFFICE Documents</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=IE8">
<script src="./code.js"></script>
<script src="./file.js"></script>
<script src="./drawingfile.js"></script>
</head>
<body style="width:100%;height:100%;margin:0;padding:0;overflow-x:scroll;overflow-y:scroll;">
<div id="pos" style="position:absolute;margin:0;padding:0;left:0px;top:0px;width:0px;height:0px;"></div>
<canvas width="100%" height="100%" style="position:fixed;left:0px;top:0px;width:100%;height:100%;" id="main"></canvas>
</body>
</html>

View File

@ -1,88 +0,0 @@
SET SCRIPTPATH=%~dp0
CD /D %~dp0
call emsdk/emsdk_env.bat
call emcc -o djvu.js^
-O3^
-fno-rtti^
-s WASM=1^
-s ALLOW_MEMORY_GROWTH=1^
-s FILESYSTEM=0^
-s ENVIRONMENT='web'^
-s ERROR_ON_UNDEFINED_SYMBOLS=0^
-s EXPORTED_FUNCTIONS="['_malloc', '_free', '_DJVU_Load', '_DJVU_Close', '_DJVU_GetInfo', '_DJVU_GetPixmap', '_DJVU_Delete']"^
"../libdjvu/Arrays.cpp"^
"../libdjvu/BSByteStream.cpp"^
"../libdjvu/BSEncodeByteStream.cpp"^
"../libdjvu/ByteStream.cpp"^
"../libdjvu/DataPool.cpp"^
"../libdjvu/debug.cpp"^
"../libdjvu/DjVmDir.cpp"^
"../libdjvu/DjVmDir0.cpp"^
"../libdjvu/DjVmDoc.cpp"^
"../libdjvu/DjVmNav.cpp"^
"../libdjvu/DjVuAnno.cpp"^
"../libdjvu/DjVuDocEditor.cpp"^
"../libdjvu/DjVuDocument.cpp"^
"../libdjvu/DjVuDumpHelper.cpp"^
"../libdjvu/DjVuErrorList.cpp"^
"../libdjvu/DjVuFile.cpp"^
"../libdjvu/DjVuFileCache.cpp"^
"../libdjvu/DjVuGlobal.cpp"^
"../libdjvu/DjVuGlobalMemory.cpp"^
"../libdjvu/DjVuImage.cpp"^
"../libdjvu/DjVuInfo.cpp"^
"../libdjvu/DjVuMessageLite.cpp"^
"../libdjvu/DjVuNavDir.cpp"^
"../libdjvu/DjVuPalette.cpp"^
"../libdjvu/DjVuPort.cpp"^
"../libdjvu/DjVuText.cpp"^
"../libdjvu/DjVuToPS.cpp"^
"../libdjvu/GBitmap.cpp"^
"../libdjvu/GContainer.cpp"^
"../libdjvu/GException.cpp"^
"../libdjvu/GIFFManager.cpp"^
"../libdjvu/GMapAreas.cpp"^
"../libdjvu/GPixmap.cpp"^
"../libdjvu/GRect.cpp"^
"../libdjvu/GScaler.cpp"^
"../libdjvu/GSmartPointer.cpp"^
"../libdjvu/GString.cpp"^
"../libdjvu/GThreads.cpp"^
"../libdjvu/GUnicode.cpp"^
"../libdjvu/IFFByteStream.cpp"^
"../libdjvu/IW44EncodeCodec.cpp"^
"../libdjvu/IW44Image.cpp"^
"../libdjvu/JB2EncodeCodec.cpp"^
"../libdjvu/JB2Image.cpp"^
"../libdjvu/JPEGDecoder.cpp"^
"../libdjvu/MMRDecoder.cpp"^
"../libdjvu/MMX.cpp"^
"../libdjvu/UnicodeByteStream.cpp"^
"../libdjvu/XMLParser.cpp"^
"../libdjvu/XMLTags.cpp"^
"../libdjvu/ZPCodec.cpp"^
"libdjvu/atomic.cpp"^
"libdjvu/DjVuMessage.cpp"^
"libdjvu/GOS.cpp"^
"libdjvu/GURL.cpp"^
"djvu_common.cpp"^
-DWIN32^
-DNDEBUG^
-D_LIB^
-D_CRT_SECURE_NO_WARNINGS^
-DWASM_MODE^
-Derrno=0^
"-DUINT=unsigned int"^
-DTHREADMODEL=0^
-DDEBUGLVL=0
echo "finalize..."
call powershell -Command "(Get-Content ./djvu.js) -replace 'function getBinaryPromise\(\){', 'function getBinaryPromise2(){' | Set-Content ./djvu.js"
if not exist "./../deploy/djvu" mkdir "./../deploy/djvu"
call powershell -Command "(Get-Content ./djvu_base.js) -replace '//module', (Get-Content ./djvu.js) | Set-Content ./../deploy/djvu/djvu.js"
call echo f | xcopy /b/v/y/f "djvu.wasm" "./../deploy/djvu/djvu.wasm"

View File

@ -1,276 +0,0 @@
/*
* (c) Copyright Ascensio System SIA 2010-2019
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
(function(window, undefined) {
var printErr = undefined;
var FS = undefined;
var print = undefined;
var getBinaryPromise = null;
if (window["AscDesktopEditor"] && document.currentScript && 0 == document.currentScript.src.indexOf("file:///"))
{
// fetch not support file:/// scheme
window.fetch = undefined;
getBinaryPromise = function() {
var wasmPath = "ascdesktop://fonts/" + wasmBinaryFile.substr(8);
return new Promise(function (resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open('GET', wasmPath, true);
xhr.responseType = 'arraybuffer';
if (xhr.overrideMimeType)
xhr.overrideMimeType('text/plain; charset=x-user-defined');
else
xhr.setRequestHeader('Accept-Charset', 'x-user-defined');
xhr.onload = function () {
if (this.status == 200) {
resolve(new Uint8Array(this.response));
}
};
xhr.send(null);
});
}
}
else
{
getBinaryPromise = function() {
return getBinaryPromise2();
}
}
//string_utf8
//module
/**
*
* @param config
* @constructor
* @extends {AscViewer.IFile}
*/
function CFile()
{
AscViewer.IFile.call(this);
}
CFile.prototype = Object.create(AscViewer.IFile.prototype);
CFile.prototype.constructor = CFile;
CFile.prototype.loadFromData = function(arrayBuffer)
{
var data = new Uint8Array(arrayBuffer);
var _stream = Module["_malloc"](data.length);
Module["HEAP8"].set(data, _stream);
this.nativeFile = Module["_Open"](_stream, data.length);
Module["_free"](_stream);
return this.getInfo();
};
CFile.prototype.getInfo = function()
{
if (!this.nativeFile)
return false;
var _info = Module["_GetInfo"](this.nativeFile);
if (!_info)
return false;
var _pages = Module["HEAP32"][_info >> 2];
var _buffer = new Int32Array(Module["HEAP8"].buffer, _info, 1 + 3 * _pages);
var _cur = 1;
for (var i = 0; i < _pages; i++)
{
this.pages.push({ W : _buffer[_cur++], H : _buffer[_cur++], Dpi : _buffer[_cur++] });
}
this.free(_info);
return this.pages.length > 0;
};
CFile.prototype.getPagePixmap = function(pageIndex, width, height)
{
return Module["_GetPixmap"](this.nativeFile, pageIndex, width, height);
};
CFile.prototype.getGlyphs = function(pageIndex, width, height)
{
var glyphs = Module["_GetGlyphs"](this.nativeFile, pageIndex, width, height);
if (glyphs == null)
return;
var lenArray = new Int32Array(Module["HEAP8"].buffer, glyphs, 4);
var len = lenArray[0];
len -= 4;
if (len <= 0)
return;
this.pages[pageIndex].Lines = [];
var buffer = new Uint8Array(Module["HEAP8"].buffer, glyphs + 4, len);
var index = 0;
var Line = -1;
while (index < len)
{
var lenRec = buffer[index] | buffer[index + 1] << 8 | buffer[index + 2] << 16 | buffer[index + 3] << 24;
index += 4;
var _Word = "".fromUtf8(buffer, index, lenRec);
index += lenRec;
lenRec = buffer[index] | buffer[index + 1] << 8 | buffer[index + 2] << 16 | buffer[index + 3] << 24;
index += 4;
var _X = parseFloat("".fromUtf8(buffer, index, lenRec));
index += lenRec;
lenRec = buffer[index] | buffer[index + 1] << 8 | buffer[index + 2] << 16 | buffer[index + 3] << 24;
index += 4;
var _Y = parseFloat("".fromUtf8(buffer, index, lenRec));
index += lenRec;
lenRec = buffer[index] | buffer[index + 1] << 8 | buffer[index + 2] << 16 | buffer[index + 3] << 24;
index += 4;
var _W = parseFloat("".fromUtf8(buffer, index, lenRec));
index += lenRec;
lenRec = buffer[index] | buffer[index + 1] << 8 | buffer[index + 2] << 16 | buffer[index + 3] << 24;
index += 4;
var _H = parseFloat("".fromUtf8(buffer, index, lenRec));
index += lenRec;
Line++;
this.pages[pageIndex].Lines.push({ Glyphs : [] });
for (let i = 0; i < _Word.length; i++)
{
this.pages[pageIndex].Lines[Line].Glyphs.push({
X : _X + _W / (_Word.length - 1) * i,
UChar : _Word[i]
});
}
this.pages[pageIndex].Lines[Line].Glyphs[0].Y = _Y + _H;
this.pages[pageIndex].Lines[Line].Glyphs[0].fontSize = _H;
}
Module["_free"](glyphs);
};
CFile.prototype.getLinks = function(pageIndex, width, height)
{
var res = [];
var ext = Module["_GetLinks"](this.nativeFile, pageIndex, width, height);
var lenArray = new Int32Array(Module["HEAP8"].buffer, ext, 4);
if (lenArray == null)
return res;
var len = lenArray[0];
len -= 4;
if (len <= 0)
return res;
var index = 0;
var buffer = new Uint8Array(Module["HEAP8"].buffer, ext + 4, len);
while (index < len)
{
var lenRec = buffer[index] | buffer[index + 1] << 8 | buffer[index + 2] << 16 | buffer[index + 3] << 24;
index += 4;
var _Link = "".fromUtf8(buffer, index, lenRec);
index += lenRec;
lenRec = buffer[index] | buffer[index + 1] << 8 | buffer[index + 2] << 16 | buffer[index + 3] << 24;
index += 4;
var _X = parseFloat("".fromUtf8(buffer, index, lenRec));
index += lenRec;
lenRec = buffer[index] | buffer[index + 1] << 8 | buffer[index + 2] << 16 | buffer[index + 3] << 24;
index += 4;
var _Y = parseFloat("".fromUtf8(buffer, index, lenRec));
index += lenRec;
lenRec = buffer[index] | buffer[index + 1] << 8 | buffer[index + 2] << 16 | buffer[index + 3] << 24;
index += 4;
var _W = parseFloat("".fromUtf8(buffer, index, lenRec));
index += lenRec;
lenRec = buffer[index] | buffer[index + 1] << 8 | buffer[index + 2] << 16 | buffer[index + 3] << 24;
index += 4;
var _H = parseFloat("".fromUtf8(buffer, index, lenRec));
index += lenRec;
res.push({ X : _X, Y : _Y, W : _W, H : _H, Link : _Link});
}
Module["_free"](ext);
return res;
};
CFile.prototype.structure = function()
{
var res = [];
var str = Module["_GetStructure"](this.nativeFile);
var lenArray = new Int32Array(Module["HEAP8"].buffer, str, 4);
if (lenArray == null)
return res;
var len = lenArray[0];
len -= 4;
if (len <= 0)
return res;
var buffer = new Uint8Array(Module["HEAP8"].buffer, str + 4, len);
var index = 0;
var Line = -1;
var prevY = -1;
while (index < len)
{
var lenRec = buffer[index] | buffer[index + 1] << 8 | buffer[index + 2] << 16 | buffer[index + 3] << 24;
index += 4;
var _Page = lenRec;
lenRec = buffer[index] | buffer[index + 1] << 8 | buffer[index + 2] << 16 | buffer[index + 3] << 24;
index += 4;
var _Level = lenRec;
lenRec = buffer[index] | buffer[index + 1] << 8 | buffer[index + 2] << 16 | buffer[index + 3] << 24;
index += 4;
var _Description = "".fromUtf8(buffer, index, lenRec);
index += lenRec;
res.push({ page : _Page, level : _Level, Y : 0, description : _Description});
}
Module["_free"](str);
return res;
};
CFile.prototype.close = function()
{
Module["_Close"](this.nativeFile);
this.nativeFile = 0;
this.pages = [];
};
CFile.prototype.memory = function()
{
return Module["HEAP8"];
};
CFile.prototype.free = function(pointer)
{
Module["_free"](pointer);
};
window["AscViewer"].DjVuFile = CFile;
})(window, undefined);

View File

@ -1,440 +0,0 @@
// djvu wrapper
#include "../libdjvu/DjVuDocument.h"
#include "../libdjvu/DjVuImage.h"
#include "../libdjvu/GBitmap.h"
#include "../libdjvu/GScaler.h"
#include "../libdjvu/IFFByteStream.h"
#include "../libdjvu/BSByteStream.h"
#include "../libdjvu/DataPool.h"
#include "../libdjvu/DjVuText.h"
#include "../libdjvu/DjVmNav.h"
#include "../libdjvu/IW44Image.h"
class CDjvuFile
{
public:
GP<DjVuDocument> m_doc;
};
class CData
{
protected:
unsigned char* m_pData;
size_t m_lSize;
unsigned char* m_pDataCur;
size_t m_lSizeCur;
public:
CData()
{
m_pData = NULL;
m_lSize = 0;
m_pDataCur = m_pData;
m_lSizeCur = m_lSize;
}
virtual ~CData()
{
Clear();
}
inline void AddSize(size_t nSize)
{
if (NULL == m_pData)
{
m_lSize = 1000;
if (nSize > m_lSize)
m_lSize = nSize;
m_pData = (unsigned char*)malloc(m_lSize * sizeof(unsigned char));
m_lSizeCur = 0;
m_pDataCur = m_pData;
return;
}
if ((m_lSizeCur + nSize) > m_lSize)
{
while ((m_lSizeCur + nSize) > m_lSize)
m_lSize *= 2;
unsigned char* pRealloc = (unsigned char*)realloc(m_pData, m_lSize * sizeof(unsigned char));
if (NULL != pRealloc)
{
m_pData = pRealloc;
m_pDataCur = m_pData + m_lSizeCur;
}
else
{
unsigned char* pMalloc = (unsigned char*)malloc(m_lSize * sizeof(unsigned char));
memcpy(pMalloc, m_pData, m_lSizeCur * sizeof(unsigned char));
free(m_pData);
m_pData = pMalloc;
m_pDataCur = m_pData + m_lSizeCur;
}
}
}
public:
void AddInt(unsigned int value)
{
AddSize(4);
memcpy(m_pDataCur, &value, sizeof(unsigned int));
m_pDataCur += 4;
m_lSizeCur += 4;
}
void WriteString(unsigned char* value, unsigned int len)
{
AddSize(len + 4);
memcpy(m_pDataCur, &len, sizeof(unsigned int));
m_pDataCur += 4;
m_lSizeCur += 4;
memcpy(m_pDataCur, value, len);
m_pDataCur += len;
m_lSizeCur += len;
}
unsigned char* GetBuffer()
{
return m_pData;
}
void Clear()
{
if (m_pData) free(m_pData);
m_pData = NULL;
m_lSize = 0;
m_pDataCur = m_pData;
m_lSizeCur = 0;
}
void ClearWithoutAttack()
{
m_pData = NULL;
m_lSize = 0;
m_pDataCur = m_pData;
m_lSizeCur = 0;
}
void ClearNoAttack()
{
m_pDataCur = m_pData;
m_lSizeCur = 0;
}
unsigned int GetSize()
{
return (unsigned int)m_lSizeCur;
}
void SkipLen()
{
AddInt(0);
}
void WriteLen()
{
unsigned int len = (unsigned int)m_lSizeCur;
memcpy(m_pData, &len, sizeof(unsigned int));
}
};
extern "C"
{
CDjvuFile* DJVU_Load(unsigned char* pData, unsigned int len);
void DJVU_Close(CDjvuFile* file);
int* DJVU_GetInfo(CDjvuFile* file);
unsigned char* DJVU_GetPixmap(CDjvuFile* file, int page_index, int w, int h);
unsigned char* DJVU_GetGlyphs(CDjvuFile* file);
unsigned char* DJVU_GetStructure(CDjvuFile* file);
void DJVU_Delete(unsigned char* pData);
}
CDjvuFile* DJVU_Load(unsigned char* pData, unsigned int len)
{
GP<ByteStream> stream = ByteStream::create(pData, (size_t)len);
CDjvuFile* file = new CDjvuFile();
file->m_doc = DjVuDocument::create(stream);
file->m_doc->wait_get_pages_num();
int pages_count = file->m_doc->get_pages_num();
if (0 == pages_count)
{
delete file;
return NULL;
}
return file;
}
void DJVU_Close(CDjvuFile* file)
{
delete file;
}
int* DJVU_GetInfo(CDjvuFile* file)
{
int pages_count = file->m_doc->get_pages_num();
int* buffer = new int[pages_count * 3 + 1];
int buffer_index = 0;
buffer[buffer_index++] = pages_count;
for (int page = 0; page < pages_count; ++page)
{
int nW = 0;
int nH = 0;
int nDpi = 0;
file->m_doc->ReadPageInfo(page, nW, nH, nDpi);
buffer[buffer_index++] = nW;
buffer[buffer_index++] = nH;
buffer[buffer_index++] = nDpi;
}
return buffer;
}
unsigned char* DJVU_GetPixmap(CDjvuFile* file, int page_index, int w, int h)
{
GP<DjVuImage> page = file->m_doc->get_page(page_index);
int w_real = page->get_real_width();
int h_real = page->get_real_height();
unsigned char* pixmap = new unsigned char[4 * w * h];
if (!pixmap)
return NULL;
if (page->is_legal_photo() || page->is_legal_compound())
{
GRect oRectAll(0, 0, w, h);
GP<GPixmap> pImage = page->get_pixmap(oRectAll, oRectAll);
unsigned char* pixmap_cur = pixmap;
for (int j = h - 1; j >= 0; --j)
{
GPixel* pLine = pImage->operator [](j);
for (int i = 0; i < w; ++i, pixmap_cur += 4, ++pLine)
{
pixmap_cur[0] = pLine->r;
pixmap_cur[1] = pLine->g;
pixmap_cur[2] = pLine->b;
pixmap_cur[3] = 255;
}
}
}
else if (page->is_legal_bilevel())
{
GRect oRectAll(0, 0, w, h);
GP<GBitmap> pBitmap = page->get_bitmap(oRectAll, oRectAll, 4);
int nPaletteEntries = pBitmap->get_grays();
unsigned int* palette = new unsigned int[nPaletteEntries];
// Create palette for the bitmap
int color = 0xff0000;
int decrement = color / (nPaletteEntries - 1);
for (int i = 0; i < nPaletteEntries; ++i)
{
unsigned char level = (unsigned char)(color >> 16);
palette[i] = (0xFF000000 | level << 16 | level << 8 | level);
color -= decrement;
}
unsigned int* pixmap_cur = (unsigned int*)pixmap;
for (int j = h - 1; j >= 0; --j)
{
unsigned char* pLine = pBitmap->operator [](j);
for (int i = 0; i < w; ++i, ++pixmap_cur, ++pLine)
{
if (*pLine < nPaletteEntries)
{
*pixmap_cur = palette[*pLine];
}
else
{
*pixmap_cur = palette[0];
}
}
}
delete [] palette;
}
else
{
GRect oRectAll(0, 0, w, h);
GP<GPixmap> pImage = page->get_pixmap(oRectAll, oRectAll);
if (NULL != pImage)
{
unsigned char* pixmap_cur = pixmap;
for (int j = h - 1; j >= 0; --j)
{
GPixel* pLine = pImage->operator [](j);
for (int i = 0; i < w; ++i, pixmap_cur += 4, ++pLine)
{
pixmap_cur[0] = pLine->r;
pixmap_cur[1] = pLine->g;
pixmap_cur[2] = pLine->b;
pixmap_cur[3] = 255;
}
}
}
else
{
GP<GBitmap> pBitmap = page->get_bitmap(oRectAll, oRectAll, 4);
if (NULL != pBitmap)
{
int nPaletteEntries = pBitmap->get_grays();
unsigned int* palette = new unsigned int[nPaletteEntries];
// Create palette for the bitmap
int color = 0xff0000;
int decrement = color / (nPaletteEntries - 1);
for (int i = 0; i < nPaletteEntries; ++i)
{
unsigned char level = (unsigned char)(color >> 16);
palette[i] = (0xFF000000 | level << 16 | level << 8 | level);
color -= decrement;
}
unsigned int* pixmap_cur = (unsigned int*)pixmap;
for (int j = h - 1; j >= 0; --j)
{
unsigned char* pLine = pBitmap->operator [](j);
for (int i = 0; i < w; ++i, ++pixmap_cur, ++pLine)
{
if (*pLine < nPaletteEntries)
{
*pixmap_cur = palette[*pLine];
}
else
{
*pixmap_cur = palette[0];
}
}
}
delete [] palette;
}
}
}
return pixmap;
}
unsigned char* DJVU_GetGlyphs(CDjvuFile* file, int page_index)
{
GP<DjVuImage> pPage = file->m_doc->get_page(page_index);
GP<DjVuText> text(DjVuText::create());
GP<ByteStream> text_str(pPage->get_text());
if (text_str)
{
text->decode(text_str);
GUTF8String pageText = text->get_xmlText(pPage->get_height());
}
return NULL;
}
void getBookmars(const GP<DjVmNav>& nav, int& pos, int count, CData& out, int level)
{
while (count > 0 && pos < nav->getBookMarkCount())
{
GP<DjVmNav::DjVuBookMark> gpBookMark;
nav->getBookMark(gpBookMark, pos++);
GUTF8String str = gpBookMark->url;
int endpos;
unsigned long nPage = str.toULong(1, endpos);
if (endpos == (int)str.length())
{
out.AddInt(nPage);
out.AddInt(level);
GUTF8String description = gpBookMark->displayname;
out.WriteString((unsigned char*)description.getbuf(), description.length());
}
getBookmars(nav, pos, gpBookMark->count, out, level + 1);
count--;
}
}
unsigned char* DJVU_GetStructure(CDjvuFile* file)
{
GP<DjVmNav> nav = file->m_doc->get_djvm_nav();
if (!nav)
return NULL;
int pos = 0;
int count = nav->getBookMarkCount();
if (count <= 0)
return NULL;
CData oRes;
oRes.SkipLen();
getBookmars(nav, pos, count, oRes, 1);
oRes.WriteLen();
unsigned char* bRes = oRes.GetBuffer();
oRes.ClearWithoutAttack();
return bRes;
}
void DJVU_Delete(unsigned char* pData)
{
delete [] pData;
}
#ifdef WASM_MODE_DEBUG
#include <stdio.h>
#include <string>
#include <iostream>
int main(int argc, char *argv[])
{
FILE* f = fopen("D:\\1.djvu", "rb");
fseek(f, 0, SEEK_END);
int file_size = (int)ftell(f);
fseek(f, 0, SEEK_SET);
unsigned char* file_data = new unsigned char[file_size];
fread((void*)file_data, 1, file_size, f);
fclose(f);
CDjvuFile* file = DJVU_Load(file_data, file_size);
delete [] file_data;
if (file)
{
int* info = DJVU_GetInfo(file);
int pages_count = *info;
if (pages_count > 0)
{
unsigned char* pixmap = DJVU_GetPixmap(file, 0, info[1] * 96 / info[3], info[2] * 96 / info[3]);
delete [] pixmap;
}
delete [] info;
unsigned char* pStructure = DJVU_GetStructure(file);
unsigned nLength = pStructure[0] | pStructure[1] << 8 | pStructure[2] << 16 | pStructure[3] << 24;
unsigned i = 4;
nLength -= 4;
while (i < nLength)
{
unsigned nPathLength = (pStructure + i)[0] | (pStructure + i)[1] << 8 | (pStructure + i)[2] << 16 | (pStructure + i)[3] << 24;
i += 4;
std::cout << "Page " << nPathLength << ", ";
nPathLength = (pStructure + i)[0] | (pStructure + i)[1] << 8 | (pStructure + i)[2] << 16 | (pStructure + i)[3] << 24;
i += 4;
std::cout << "Level " << nPathLength << ", ";
nPathLength = (pStructure + i)[0] | (pStructure + i)[1] << 8 | (pStructure + i)[2] << 16 | (pStructure + i)[3] << 24;
i += 4;
std::string oDs = std::string((char*)(pStructure + i), nPathLength);
std::cout << "Description " << oDs << std::endl;
i += nPathLength;
}
delete [] pStructure;
}
return 0;
}
#endif

View File

@ -1,30 +0,0 @@
import sys
sys.path.append("../../../build_tools/scripts")
import base
import os
base.configure_common_apps()
# remove previous version
if base.is_dir("./deploy"):
base.delete_dir("./deploy")
base.create_dir("./deploy")
# command
base.cmd_in_dir("./../../DesktopEditor/graphics/pro/js", "python", ["make.py"])
# finalize
if base.is_exist("./../../DesktopEditor/graphics/pro/js/deploy/drawingfile.wasm"):
base.copy_file("./../../DesktopEditor/graphics/pro/js/deploy/drawingfile.js", "./deploy/drawingfile.js")
base.copy_file("./../../DesktopEditor/graphics/pro/js/deploy/drawingfile.wasm", "./deploy/drawingfile.wasm")
base.copy_file("./../../DesktopEditor/graphics/pro/js/deploy/drawingfile_ie.js", "./deploy/drawingfile_ie.js")
base.copy_file("./../../DesktopEditor/graphics/pro/js/deploy/drawingfile.js.mem", "./deploy/drawingfile.js.mem")
else:
print("make.py error")
base.copy_dir("./all_files_test/xps_djvu", "./deploy")
base.copy_dir("./all_files_test/pdf", "./deploy")
# write new version
base.copy_file("./all_files_test/index.html", "./deploy/index.html")
base.copy_file("./all_files_test/code.js", "./deploy/code.js")
base.copy_file("./all_files_test/file.js", "./deploy/file.js")