mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
build wasm module
This commit is contained in:
@ -114,7 +114,7 @@ window.onload = function()
|
||||
this.documentHeight = 0;
|
||||
this.Selection = { IsSelection : false, Image : null, page : -1 };
|
||||
|
||||
this.file = new AscViewer.DjVuFile();
|
||||
this.file = new AscViewer.CDrawingFile();
|
||||
|
||||
/*
|
||||
[TIMER START]
|
||||
@ -373,7 +373,7 @@ window.onload = function()
|
||||
|
||||
this.getStructure = function()
|
||||
{
|
||||
var res = this.file.structure();
|
||||
var res = this.file.getStructure();
|
||||
return res;
|
||||
};
|
||||
|
||||
@ -469,7 +469,7 @@ window.onload = function()
|
||||
if (!page.Image)
|
||||
{
|
||||
page.Image = this.file.getPage(i, w, h);
|
||||
this.getGlyphs(i, w, h);
|
||||
//this.getGlyphs(i, w, h);
|
||||
this.links = this.getLinks(i, w, h);
|
||||
this.links.Page = i;
|
||||
}
|
||||
@ -487,7 +487,7 @@ window.onload = function()
|
||||
for (let j = 0; j < this.links.length; j++)
|
||||
{
|
||||
let Link = this.links[j];
|
||||
ctx.fillRect(x + Link.X, y + Link.Y, Link.W, Link.H);
|
||||
ctx.fillRect(x + Link.x, y + Link.y, Link.w, Link.h);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
610
DjVuFile/wasm/all_files_test/drawingfile.js
Normal file
610
DjVuFile/wasm/all_files_test/drawingfile.js
Normal file
File diff suppressed because one or more lines are too long
BIN
DjVuFile/wasm/all_files_test/drawingfile.wasm
Normal file
BIN
DjVuFile/wasm/all_files_test/drawingfile.wasm
Normal file
Binary file not shown.
@ -242,156 +242,6 @@
|
||||
|
||||
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;
|
||||
@ -399,53 +249,7 @@ void main() {\n\
|
||||
window["AscViewer"].createFile = function(buffer)
|
||||
{
|
||||
var data = new Uint8Array(buffer);
|
||||
var file = null;
|
||||
|
||||
var maxCheck = Math.min(100, data.length - 5);
|
||||
var pdfCheck = [
|
||||
"%".charCodeAt(0),
|
||||
"P".charCodeAt(0),
|
||||
"D".charCodeAt(0),
|
||||
"F".charCodeAt(0),
|
||||
"-".charCodeAt(0)
|
||||
];
|
||||
var isPdf = false;
|
||||
for (var i = 0; i < maxCheck; i++)
|
||||
{
|
||||
if (data[i + 0] == pdfCheck[0] &&
|
||||
data[i + 1] == pdfCheck[1] &&
|
||||
data[i + 2] == pdfCheck[2] &&
|
||||
data[i + 3] == pdfCheck[3] &&
|
||||
data[i + 4] == pdfCheck[4])
|
||||
{
|
||||
isPdf = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isPdf)
|
||||
{
|
||||
file = new window["AscViewer"].PdfFile();
|
||||
file.type = 0;
|
||||
}
|
||||
|
||||
if (data.length > 7 && !file &&
|
||||
0x41 == data[0] && 0x54 == data[1] && 0x26 == data[2] && 0x54 == data[3] &&
|
||||
0x46 == data[4] && 0x4f == data[5] && 0x52 == data[6] && 0x4d == data[7])
|
||||
{
|
||||
file = new window["AscViewer"].DjVuFile();
|
||||
}
|
||||
|
||||
if (!file)
|
||||
{
|
||||
file = new window["AscViewer"].XpsFile();
|
||||
}
|
||||
|
||||
if (!file)
|
||||
{
|
||||
file = new window["AscViewer"].PdfFile();
|
||||
file.type = 1;
|
||||
}
|
||||
var file = new window["AscViewer"].CDrawingFile();
|
||||
|
||||
file.loadFromData(data);
|
||||
file.cacheManager = new window.CCacheManager();
|
||||
|
||||
@ -6,9 +6,7 @@
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=IE8">
|
||||
<script src="./code.js"></script>
|
||||
<script src="./file.js"></script>
|
||||
<script src="./djvu.js"></script>
|
||||
<script src="./pdf.js"></script>
|
||||
<script src="./xps.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>
|
||||
|
||||
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Binary file not shown.
@ -15,9 +15,7 @@ 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/xps.js", "./deploy/xps.js")
|
||||
base.copy_file("./../../DesktopEditor/graphics/pro/js/deploy/djvu.js", "./deploy/djvu.js")
|
||||
base.copy_file("./../../DesktopEditor/graphics/pro/js/deploy/pdf.js", "./deploy/pdf.js")
|
||||
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")
|
||||
else:
|
||||
print("make.py error")
|
||||
@ -28,4 +26,3 @@ else:
|
||||
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")
|
||||
base.copy_dir("./all_files_test/pdf", "./deploy/pdf")
|
||||
|
||||
Reference in New Issue
Block a user