Skip to content

Commit

Permalink
Create new array to store incomplete text objects
Browse files Browse the repository at this point in the history
  • Loading branch information
joemoongit committed Jan 26, 2024
1 parent 4cba1ee commit 264bb9a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions lib/recipe/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ function _initOptions(self, x = {}, y, options = {}) {
}

self._previousTextObjects = self._previousTextObjects || [];
self._incompleteTextObjects = self._incompleteTextObjects || [];

// Merge any previous options with new options
const mergedOpts = self._merge(self._textOptions, options);
Expand Down Expand Up @@ -1177,7 +1178,10 @@ function makeTextObjects(self, textObject = {}, pathOptions, textBox = {}) {
} else {
fini = textObj.lineComplete;
}
textObj.wordsInLine[textObj.wordsInLine.length - 1].lastWord(fini);

if (textObj.wordsInLine.length) {
textObj.wordsInLine[textObj.wordsInLine.length - 1].lastWord(fini);
}
}

if (lineComplete) {
Expand Down Expand Up @@ -1366,7 +1370,9 @@ function markLineComplete(toWriteTextObjects, lines = null) {
const textObj = toWriteTextObjects[toWriteTextObjects.length - 1];
const lastWordIdx = textObj.wordsInLine.length - 1;

textObj.wordsInLine[lastWordIdx].lastWord();
if (lastWordIdx > -1) {
textObj.wordsInLine[lastWordIdx].lastWord();
}
textObj.text = textObj.text.trim();
textObj.lineComplete = true;

Expand Down
4 changes: 2 additions & 2 deletions tests/recipe/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ describe("Text", () => {
.endPDF(done);
});

it("Add text with bolded text inside textbox", (done) => {
it("Add text with bolded format inside textbox", (done) => {
const src = "new"; //path.join(__dirname, '../TestMaterials/recipe/test.pdf');
const output = path.join(
__dirname,
Expand Down Expand Up @@ -310,7 +310,7 @@ describe("Text", () => {
.endPDF(done);
});

it("Add text with italic text inside textbox", (done) => {
it("Add text with italic format inside textbox", (done) => {
const src = "new"; //path.join(__dirname, '../TestMaterials/recipe/test.pdf');
const output = path.join(
__dirname,
Expand Down

0 comments on commit 264bb9a

Please sign in to comment.