Merge pull request #10508 from Snuffleupagus/issue-8276

Do the final text scaling correctly in `flushTextContentItem` (issue 8276)
This commit is contained in:
Tim van der Meij 2019-01-29 22:46:36 +01:00 committed by GitHub
commit 291e62b41e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 116 additions and 8 deletions

View File

@ -1332,7 +1332,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
fontFamily: font.fallbackName,
ascent: font.ascent,
descent: font.descent,
vertical: font.vertical,
vertical: !!font.vertical,
};
}
textContentItem.fontName = font.loadedName;
@ -1508,9 +1508,12 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
return;
}
// Do final text scaling
textContentItem.width *= textContentItem.textAdvanceScale;
textContentItem.height *= textContentItem.textAdvanceScale;
// Do final text scaling.
if (!textContentItem.vertical) {
textContentItem.width *= textContentItem.textAdvanceScale;
} else {
textContentItem.height *= textContentItem.textAdvanceScale;
}
textContent.items.push(runBidiTransform(textContentItem));
textContentItem.initialized = false;

View File

@ -54,6 +54,7 @@
!issue8088.pdf
!issue8125.pdf
!issue8229.pdf
!issue8276_reduced.pdf
!issue8372.pdf
!issue8424.pdf
!issue8480.pdf

View File

@ -0,0 +1,70 @@
%PDF-1.7
%âãÏÓ
1 0 obj
<<
/Pages 2 0 R
/Type /Catalog
>>
endobj
2 0 obj
<<
/Kids [3 0 R]
/Count 1
/Type /Pages
>>
endobj
3 0 obj
<<
/Parent 2 0 R
/MediaBox [0 0 594.000000 840.239990]
/Resources
<<
/Font
<<
/F1 4 0 R
>>
>>
/Contents 5 0 R
/Type /Page
>>
endobj
4 0 obj
<<
/BaseFont /Times-Roman
/Subtype /Type1
/Encoding /WinAnsiEncoding
/Type /Font
>>
endobj
5 0 obj
<<
/Length 76
>>
stream
q
0.03 0 0 0.03 0 0 cm
BT
/F1 600.00 Tf
14727 23615 TD
(Issue 8276) Tj
ET
Q
endstream
endobj xref
0 6
0000000000 65535 f
0000000015 00000 n
0000000066 00000 n
0000000125 00000 n
0000000269 00000 n
0000000370 00000 n
trailer
<<
/Root 1 0 R
/Size 6
>>
startxref
498
%%EOF

View File

@ -1174,6 +1174,39 @@ describe('api', function() {
done();
}).catch(done.fail);
});
it('gets text content, with correct properties (issue 8276)',
function(done) {
const loadingTask = getDocument(
buildGetDocumentParams('issue8276_reduced.pdf'));
loadingTask.promise.then((pdfDoc) => {
pdfDoc.getPage(1).then((pdfPage) => {
pdfPage.getTextContent().then(({ items, styles, }) => {
expect(items.length).toEqual(1);
expect(Object.keys(styles)).toEqual(['Times']);
expect(items[0]).toEqual({
dir: 'ltr',
fontName: 'Times',
height: 18,
str: 'Issue 8276',
transform: [18, 0, 0, 18, 441.81, 708.4499999999999],
width: 77.49,
});
expect(styles.Times).toEqual({
fontFamily: 'serif',
ascent: NaN,
descent: NaN,
vertical: false,
});
loadingTask.destroy().then(done);
});
});
}).catch(done.fail);
});
it('gets operator list', function(done) {
var promise = page.getOperatorList();
promise.then(function (oplist) {
@ -1191,11 +1224,12 @@ describe('api', function() {
pdfPage.getOperatorList().then((opList) => {
let imgIndex = opList.fnArray.indexOf(OPS.paintImageXObject);
let imgArgs = opList.argsArray[imgIndex];
let { data: imgData, } = pdfPage.objs.get(imgArgs[0]);
let { data, } = pdfPage.objs.get(imgArgs[0]);
expect(imgData instanceof Uint8ClampedArray).toEqual(true);
expect(imgData.length).toEqual(90000);
done();
expect(data instanceof Uint8ClampedArray).toEqual(true);
expect(data.length).toEqual(90000);
loadingTask.destroy().then(done);
});
});
}).catch(done.fail);