Merge pull request #2106 from yurydelendik/test-layer-test
Adds text layer testing
This commit is contained in:
commit
5a7ccc92f2
@ -26,7 +26,7 @@
|
|||||||
// "firefox-bin: Fatal IO error 12 (Cannot allocate memory) on X server :1."
|
// "firefox-bin: Fatal IO error 12 (Cannot allocate memory) on X server :1."
|
||||||
// PDFJS.disableWorker = true;
|
// PDFJS.disableWorker = true;
|
||||||
|
|
||||||
var appPath, browser, canvas, currentTaskIdx, manifest, stdout;
|
var appPath, browser, canvas, dummyCanvas, currentTaskIdx, manifest, stdout;
|
||||||
var inFlightRequests = 0;
|
var inFlightRequests = 0;
|
||||||
|
|
||||||
function queryParams() {
|
function queryParams() {
|
||||||
@ -148,6 +148,46 @@ function canvasToDataURL() {
|
|||||||
return canvas.toDataURL('image/png');
|
return canvas.toDataURL('image/png');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function NullTextLayerBuilder() {
|
||||||
|
}
|
||||||
|
NullTextLayerBuilder.prototype = {
|
||||||
|
beginLayout: function NullTextLayerBuilder_BeginLayout() {},
|
||||||
|
endLayout: function NullTextLayerBuilder_EndLayout() {},
|
||||||
|
appendText: function NullTextLayerBuilder_AppendText() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
function SimpleTextLayerBuilder(ctx, viewport) {
|
||||||
|
this.ctx = ctx;
|
||||||
|
this.viewport = viewport;
|
||||||
|
}
|
||||||
|
SimpleTextLayerBuilder.prototype = {
|
||||||
|
beginLayout: function SimpleTextLayerBuilder_BeginLayout() {
|
||||||
|
this.ctx.save();
|
||||||
|
},
|
||||||
|
endLayout: function SimpleTextLayerBuilder_EndLayout() {
|
||||||
|
this.ctx.restore();
|
||||||
|
},
|
||||||
|
appendText: function SimpleTextLayerBuilder_AppendText(text, fontName,
|
||||||
|
fontSize) {
|
||||||
|
var ctx = this.ctx, viewport = this.viewport;
|
||||||
|
// vScale and hScale already contain the scaling to pixel units
|
||||||
|
var fontHeight = fontSize * text.geom.vScale;
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.strokeStyle = 'red';
|
||||||
|
ctx.fillStyle = 'yellow';
|
||||||
|
ctx.rect(text.geom.x, text.geom.y - fontHeight,
|
||||||
|
text.canvasWidth * text.geom.hScale, fontHeight);
|
||||||
|
ctx.stroke();
|
||||||
|
ctx.fill();
|
||||||
|
|
||||||
|
var textContent = bidi(text, -1);
|
||||||
|
ctx.font = fontHeight + 'px sans-serif';
|
||||||
|
ctx.fillStyle = 'black';
|
||||||
|
ctx.fillText(textContent, text.geom.x, text.geom.y);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
function nextPage(task, loadError) {
|
function nextPage(task, loadError) {
|
||||||
var failure = loadError || '';
|
var failure = loadError || '';
|
||||||
|
|
||||||
@ -196,16 +236,21 @@ function nextPage(task, loadError) {
|
|||||||
canvas.height = viewport.height;
|
canvas.height = viewport.height;
|
||||||
clear(ctx);
|
clear(ctx);
|
||||||
|
|
||||||
// using the text layer builder that does nothing to test
|
var drawContext, textLayerBuilder;
|
||||||
// text layer creation operations
|
if (task.type == 'text') {
|
||||||
var textLayerBuilder = {
|
// using dummy canvas for pdf context drawing operations
|
||||||
beginLayout: function nullTextLayerBuilderBeginLayout() {},
|
if (!dummyCanvas) {
|
||||||
endLayout: function nullTextLayerBuilderEndLayout() {},
|
dummyCanvas = document.createElement('canvas');
|
||||||
appendText: function nullTextLayerBuilderAppendText(text, fontName,
|
}
|
||||||
fontSize) {}
|
drawContext = dummyCanvas.getContext('2d');
|
||||||
};
|
// ... text builder will draw its content on the test canvas
|
||||||
|
textLayerBuilder = new SimpleTextLayerBuilder(ctx, viewport);
|
||||||
|
} else {
|
||||||
|
drawContext = ctx;
|
||||||
|
textLayerBuilder = new NullTextLayerBuilder();
|
||||||
|
}
|
||||||
var renderContext = {
|
var renderContext = {
|
||||||
canvasContext: ctx,
|
canvasContext: drawContext,
|
||||||
textLayer: textLayerBuilder,
|
textLayer: textLayerBuilder,
|
||||||
viewport: viewport
|
viewport: viewport
|
||||||
};
|
};
|
||||||
|
@ -514,7 +514,7 @@ def check(task, results, browser, masterMode):
|
|||||||
return
|
return
|
||||||
|
|
||||||
kind = task['type']
|
kind = task['type']
|
||||||
if 'eq' == kind:
|
if 'eq' == kind or 'text' == kind:
|
||||||
checkEq(task, results, browser, masterMode)
|
checkEq(task, results, browser, masterMode)
|
||||||
elif 'fbf' == kind:
|
elif 'fbf' == kind:
|
||||||
checkFBF(task, results, browser)
|
checkFBF(task, results, browser)
|
||||||
@ -528,6 +528,7 @@ def checkEq(task, results, browser, masterMode):
|
|||||||
pfx = os.path.join(REFDIR, sys.platform, browser, task['id'])
|
pfx = os.path.join(REFDIR, sys.platform, browser, task['id'])
|
||||||
results = results[0]
|
results = results[0]
|
||||||
taskId = task['id']
|
taskId = task['id']
|
||||||
|
taskType = task['type']
|
||||||
|
|
||||||
passed = True
|
passed = True
|
||||||
for page in xrange(len(results)):
|
for page in xrange(len(results)):
|
||||||
@ -547,7 +548,7 @@ def checkEq(task, results, browser, masterMode):
|
|||||||
|
|
||||||
eq = (ref == snapshot)
|
eq = (ref == snapshot)
|
||||||
if not eq:
|
if not eq:
|
||||||
print 'TEST-UNEXPECTED-FAIL | eq', taskId, '| in', browser, '| rendering of page', page + 1, '!= reference rendering'
|
print 'TEST-UNEXPECTED-FAIL | ', taskType, taskId, '| in', browser, '| rendering of page', page + 1, '!= reference rendering'
|
||||||
|
|
||||||
if not State.eqLog:
|
if not State.eqLog:
|
||||||
State.eqLog = open(EQLOG_FILE, 'w')
|
State.eqLog = open(EQLOG_FILE, 'w')
|
||||||
@ -576,7 +577,7 @@ def checkEq(task, results, browser, masterMode):
|
|||||||
of.close()
|
of.close()
|
||||||
|
|
||||||
if passed:
|
if passed:
|
||||||
print 'TEST-PASS | eq test', task['id'], '| in', browser
|
print 'TEST-PASS | ', taskType, ' test', task['id'], '| in', browser
|
||||||
|
|
||||||
def checkFBF(task, results, browser):
|
def checkFBF(task, results, browser):
|
||||||
round0, round1 = results[0], results[1]
|
round0, round1 = results[0], results[1]
|
||||||
|
@ -11,6 +11,12 @@
|
|||||||
"rounds": 2,
|
"rounds": 2,
|
||||||
"type": "fbf"
|
"type": "fbf"
|
||||||
},
|
},
|
||||||
|
{ "id": "tracemonkey-text",
|
||||||
|
"file": "pdfs/tracemonkey.pdf",
|
||||||
|
"md5": "9a192d8b1a7dc652a19835f6f08098bd",
|
||||||
|
"rounds": 1,
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
{ "id": "html5-canvas-cheat-sheet-load",
|
{ "id": "html5-canvas-cheat-sheet-load",
|
||||||
"file": "pdfs/canvas.pdf",
|
"file": "pdfs/canvas.pdf",
|
||||||
"md5": "59510028561daf62e00bf9f6f066b033",
|
"md5": "59510028561daf62e00bf9f6f066b033",
|
||||||
@ -89,6 +95,12 @@
|
|||||||
"rounds": 1,
|
"rounds": 1,
|
||||||
"type": "eq"
|
"type": "eq"
|
||||||
},
|
},
|
||||||
|
{ "id": "thuluthfont-text",
|
||||||
|
"file": "pdfs/ThuluthFeatures.pdf",
|
||||||
|
"md5": "b7e18bf7a3d6a9c82aefa12d721072fc",
|
||||||
|
"rounds": 1,
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
{ "id": "freeculture",
|
{ "id": "freeculture",
|
||||||
"file": "pdfs/freeculture.pdf",
|
"file": "pdfs/freeculture.pdf",
|
||||||
"md5": "dcdf3a8268e6a18938a42d5149efcfca",
|
"md5": "dcdf3a8268e6a18938a42d5149efcfca",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user