Skip to content

Commit

Permalink
issue #293: fix text color, both color idx and hex code that not in c…
Browse files Browse the repository at this point in the history
…olor dictionary
  • Loading branch information
modesty committed Feb 18, 2023
1 parent 95d2c8e commit 60b51b0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
11 changes: 4 additions & 7 deletions lib/pdffont.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export default class PDFFont {

// public instance methods
processText(p, str, maxWidth, color, fontSize, targetData, matrix2D) {
let text = this.#processSymbolicFont(str);
const text = this.#processSymbolicFont(str);
if (!text) {
return;
}
Expand All @@ -266,7 +266,7 @@ export default class PDFFont {
const TS = [this.faceIdx, this.fontSize, this.bold?1:0, this.italic?1:0];

const clrId = PDFUnit.findColorIndex(color);
const colorObj = (clrId > 0 && clrId < PDFUnit.colorCount()) ? {clr: clrId} : {oc: this.color};
const colorObj = (clrId >= 0 && clrId < PDFUnit.colorCount()) ? {clr: clrId} : {oc: color};

let textRun = {
T: this.flash_encode(text),
Expand All @@ -279,18 +279,15 @@ export default class PDFFont {
textRun = {...textRun, RA: rAngle};
}

let oneText = {x: PDFUnit.toFormX(p.x) - 0.25,
const oneText = {x: PDFUnit.toFormX(p.x) - 0.25,
y: PDFUnit.toFormY(p.y) - 0.75,
w: PDFUnit.toFixedFloat(maxWidth),
...colorObj, //MQZ.07/29/2013: when color is not in color dictionary, set the original color (oc)
sw: this.spaceWidth, //font space width, use to merge adjacent text blocks
A: "left",
R: [textRun]
};

//MQZ.07/29/2013: when color is not in color dictionary, set the original color (oc)
oneText = {...oneText, ...colorObj};


targetData.Texts.push(oneText);
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"parse-r": "node --trace-deprecation --trace-warnings pdf2json.js -f ./test/pdf/fd/form/F1040.pdf -o ./test/target/fd/form -t -c -m -r",
"parse-fd": "node --trace-deprecation --trace-warnings pdf2json.js -f ./test/pdf/fd/form/ -o ./test/target/fd/form -t -c -m -r",
"parse-tb": "node --trace-deprecation --trace-warnings pdf2json.js -f ./test/pdf/misc/i242_testingWithTable.pdf -o ./test/target/misc",
"parse-tc": "node --trace-deprecation --trace-warnings pdf2json.js -f ./test/pdf/misc/i293_pdfpac.pdf -o ./test/target/misc",
"parse-e": "node --trace-deprecation --trace-warnings pdf2json.js -f ./test/pdf/misc/i43_encrypted.pdf -o ./test/target/misc",
"parse-e2": "node --trace-deprecation --trace-warnings pdf2json.js -f ./test/pdf/misc/i243_problem_file_anon.pdf -o ./test/target/misc",
"parse-e3": "node --trace-deprecation --trace-warnings pdf2json.js -f ./test/pdf/misc/i200_test.pdf -o ./test/target/misc"
Expand Down
Binary file added test/pdf/misc/i293_pdfpac.pdf
Binary file not shown.

0 comments on commit 60b51b0

Please sign in to comment.