Adds text layer testing
This commit is contained in:
parent
40eb44eae4
commit
3fed93d808
@ -26,7 +26,7 @@
|
||||
// "firefox-bin: Fatal IO error 12 (Cannot allocate memory) on X server :1."
|
||||
// PDFJS.disableWorker = true;
|
||||
|
||||
var appPath, browser, canvas, currentTaskIdx, manifest, stdout;
|
||||
var appPath, browser, canvas, dummyCanvas, currentTaskIdx, manifest, stdout;
|
||||
var inFlightRequests = 0;
|
||||
|
||||
function queryParams() {
|
||||
@ -148,6 +148,46 @@ function canvasToDataURL() {
|
||||
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) {
|
||||
var failure = loadError || '';
|
||||
|
||||
@ -196,16 +236,21 @@ function nextPage(task, loadError) {
|
||||
canvas.height = viewport.height;
|
||||
clear(ctx);
|
||||
|
||||
// using the text layer builder that does nothing to test
|
||||
// text layer creation operations
|
||||
var textLayerBuilder = {
|
||||
beginLayout: function nullTextLayerBuilderBeginLayout() {},
|
||||
endLayout: function nullTextLayerBuilderEndLayout() {},
|
||||
appendText: function nullTextLayerBuilderAppendText(text, fontName,
|
||||
fontSize) {}
|
||||
};
|
||||
var drawContext, textLayerBuilder;
|
||||
if (task.type == 'text') {
|
||||
// using dummy canvas for pdf context drawing operations
|
||||
if (!dummyCanvas) {
|
||||
dummyCanvas = document.createElement('canvas');
|
||||
}
|
||||
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 = {
|
||||
canvasContext: ctx,
|
||||
canvasContext: drawContext,
|
||||
textLayer: textLayerBuilder,
|
||||
viewport: viewport
|
||||
};
|
||||
|
@ -514,7 +514,7 @@ def check(task, results, browser, masterMode):
|
||||
return
|
||||
|
||||
kind = task['type']
|
||||
if 'eq' == kind:
|
||||
if 'eq' == kind or 'text' == kind:
|
||||
checkEq(task, results, browser, masterMode)
|
||||
elif 'fbf' == kind:
|
||||
checkFBF(task, results, browser)
|
||||
@ -528,6 +528,7 @@ def checkEq(task, results, browser, masterMode):
|
||||
pfx = os.path.join(REFDIR, sys.platform, browser, task['id'])
|
||||
results = results[0]
|
||||
taskId = task['id']
|
||||
taskType = task['type']
|
||||
|
||||
passed = True
|
||||
for page in xrange(len(results)):
|
||||
@ -547,7 +548,7 @@ def checkEq(task, results, browser, masterMode):
|
||||
|
||||
eq = (ref == snapshot)
|
||||
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:
|
||||
State.eqLog = open(EQLOG_FILE, 'w')
|
||||
@ -576,7 +577,7 @@ def checkEq(task, results, browser, masterMode):
|
||||
of.close()
|
||||
|
||||
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):
|
||||
round0, round1 = results[0], results[1]
|
||||
|
@ -11,6 +11,12 @@
|
||||
"rounds": 2,
|
||||
"type": "fbf"
|
||||
},
|
||||
{ "id": "tracemonkey-text",
|
||||
"file": "pdfs/tracemonkey.pdf",
|
||||
"md5": "9a192d8b1a7dc652a19835f6f08098bd",
|
||||
"rounds": 1,
|
||||
"type": "text"
|
||||
},
|
||||
{ "id": "html5-canvas-cheat-sheet-load",
|
||||
"file": "pdfs/canvas.pdf",
|
||||
"md5": "59510028561daf62e00bf9f6f066b033",
|
||||
@ -89,6 +95,12 @@
|
||||
"rounds": 1,
|
||||
"type": "eq"
|
||||
},
|
||||
{ "id": "thuluthfont-text",
|
||||
"file": "pdfs/ThuluthFeatures.pdf",
|
||||
"md5": "b7e18bf7a3d6a9c82aefa12d721072fc",
|
||||
"rounds": 1,
|
||||
"type": "text"
|
||||
},
|
||||
{ "id": "freeculture",
|
||||
"file": "pdfs/freeculture.pdf",
|
||||
"md5": "dcdf3a8268e6a18938a42d5149efcfca",
|
||||
|
Loading…
Reference in New Issue
Block a user