mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 10:08:06 +02:00
Improve text-selection for Type3 fonts with bogus /FontBBox-entries (issue 14999)
This extends PR 13461, by also building a fallback bounding box for Type3 fonts that contain a much too small /FontBBox-entry. *Please note:* While this patch improves things overall, copy-and-pasting still doesn't work perfectly for this document. In particular the lowercase letter "c" cannot be selected/copied, however this can be reproduced in both Adobe Reader and PDFium (in Google Chrome) too, which is caused by a lack of proper /ToUnicode-data in the PDF document.
This commit is contained in:
parent
a1ac1a61b7
commit
79cfc548fc
4 changed files with 21 additions and 5 deletions
|
@ -4404,8 +4404,10 @@ class TranslatedFont {
|
|||
const fontResources = this.dict.get("Resources") || resources;
|
||||
const charProcOperatorList = Object.create(null);
|
||||
|
||||
const isEmptyBBox =
|
||||
!translatedFont.bbox || isArrayEqual(translatedFont.bbox, [0, 0, 0, 0]);
|
||||
const fontBBox = Util.normalizeRect(translatedFont.bbox || [0, 0, 0, 0]),
|
||||
width = fontBBox[2] - fontBBox[0],
|
||||
height = fontBBox[3] - fontBBox[1];
|
||||
const fontBBoxSize = Math.hypot(width, height);
|
||||
|
||||
for (const key of charProcs.getKeys()) {
|
||||
loadCharProcsPromise = loadCharProcsPromise.then(() => {
|
||||
|
@ -4426,7 +4428,7 @@ class TranslatedFont {
|
|||
// colour-related parameters) in the graphics state;
|
||||
// any use of such operators shall be ignored."
|
||||
if (operatorList.fnArray[0] === OPS.setCharWidthAndBounds) {
|
||||
this._removeType3ColorOperators(operatorList, isEmptyBBox);
|
||||
this._removeType3ColorOperators(operatorList, fontBBoxSize);
|
||||
}
|
||||
charProcOperatorList[key] = operatorList.getIR();
|
||||
|
||||
|
@ -4454,7 +4456,7 @@ class TranslatedFont {
|
|||
/**
|
||||
* @private
|
||||
*/
|
||||
_removeType3ColorOperators(operatorList, isEmptyBBox = false) {
|
||||
_removeType3ColorOperators(operatorList, fontBBoxSize = NaN) {
|
||||
if (
|
||||
typeof PDFJSDev === "undefined" ||
|
||||
PDFJSDev.test("!PRODUCTION || TESTING")
|
||||
|
@ -4467,12 +4469,19 @@ class TranslatedFont {
|
|||
const charBBox = Util.normalizeRect(operatorList.argsArray[0].slice(2)),
|
||||
width = charBBox[2] - charBBox[0],
|
||||
height = charBBox[3] - charBBox[1];
|
||||
const charBBoxSize = Math.hypot(width, height);
|
||||
|
||||
if (width === 0 || height === 0) {
|
||||
// Skip the d1 operator when its bounds are bogus (fixes issue14953.pdf).
|
||||
operatorList.fnArray.splice(0, 1);
|
||||
operatorList.argsArray.splice(0, 1);
|
||||
} else if (isEmptyBBox) {
|
||||
} else if (
|
||||
fontBBoxSize === 0 ||
|
||||
Math.round(charBBoxSize / fontBBoxSize) >= 10
|
||||
) {
|
||||
// Override the fontBBox when it's undefined/empty, or when it's at least
|
||||
// (approximately) one order of magnitude smaller than the charBBox
|
||||
// (fixes issue14999_reduced.pdf).
|
||||
if (!this._bbox) {
|
||||
this._bbox = [Infinity, Infinity, -Infinity, -Infinity];
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue