Skip to content

Commit

Permalink
Revert commits 264bb9a 4cba1ee baee450
Browse files Browse the repository at this point in the history
  • Loading branch information
joemoongit committed Aug 26, 2024
1 parent 264bb9a commit 771aaf6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 44 deletions.
60 changes: 20 additions & 40 deletions lib/recipe/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ function _initOptions(self, x = {}, y, options = {}) {
self._firstLineHeight = 0; // indicates not set yet, determined later.
self._textOptions = { textBox: {} };
self._previousTextObjects = [];
self._incompleteTextObjects = [];
self._flow = options.flow || false;

if (options.layout) {
Expand All @@ -114,7 +113,6 @@ 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 @@ -837,7 +835,6 @@ exports._layoutText = function _layoutText(textObjects, textBox, pathOptions) {
: child.strikeOut;

child.lineID = textObject.lineID;
child.tag = textObject.tag;
writeValue(child);
});
}
Expand Down Expand Up @@ -1087,7 +1084,6 @@ function bindTextToLine(line, textObjects, wordCount, totalTextWidth) {

function makeTextObjects(self, textObject = {}, pathOptions, textBox = {}) {
const toWriteTextObjects = [...self._previousTextObjects];
const incompleteTextObjects = self._incompleteTextObjects || [];
let text =
(textObject.prependValue ? textObject.prependValue : "") +
textObject.value +
Expand Down Expand Up @@ -1150,11 +1146,11 @@ function makeTextObjects(self, textObject = {}, pathOptions, textBox = {}) {
// When text flow is involved, there may be lines that are
// incomplete. So need to determine previous line word count
// and remove last line marks because more text is being processed.
if (incompleteTextObjects.length > 0) {
if (toWriteTextObjects.length > 0) {
let lineWidth = 0;
let spaceSz = 0;
const end = incompleteTextObjects.length - 1;
const previousLine = incompleteTextObjects[end];
const end = toWriteTextObjects.length - 1;
const previousLine = toWriteTextObjects[end];
let lineComplete, fini;

if (text === "" && !self._flow) {
Expand All @@ -1163,7 +1159,7 @@ function makeTextObjects(self, textObject = {}, pathOptions, textBox = {}) {
}

for (let i = end; i >= 0; i--) {
let textObj = incompleteTextObjects[i];
let textObj = toWriteTextObjects[i];

// only collect data while lineID's match.
if (textObj.lineID !== previousLine.lineID) {
Expand All @@ -1178,10 +1174,7 @@ function makeTextObjects(self, textObject = {}, pathOptions, textBox = {}) {
} else {
fini = textObj.lineComplete;
}

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

if (lineComplete) {
Expand All @@ -1192,7 +1185,6 @@ function makeTextObjects(self, textObject = {}, pathOptions, textBox = {}) {
spaceSz = 0;
}
remainderWidth = lineMaxWidth - lineWidth - spaceSz;
lineID = previousLine.lineID;
}
}

Expand All @@ -1207,16 +1199,14 @@ function makeTextObjects(self, textObject = {}, pathOptions, textBox = {}) {
} else {
// Protect against line width being too small to accept any
// word, which may also happen during text justification.
const objects = toWriteTextObjects.length ? toWriteTextObjects : incompleteTextObjects;

if (newLine.words.length === 0) {
// self.movedown(); // start at front of next line.
if (wordCount > 0) {
// no words applied to previous segment, so drop word count
// and mark last word of previous line in case justifying.
wordCount = 0;
totalTextWidth = 0;
markLineComplete(objects);
markLineComplete(toWriteTextObjects);
}
} else {
// remove any trailing space on previous word so right justification works appropriately
Expand All @@ -1226,7 +1216,7 @@ function makeTextObjects(self, textObject = {}, pathOptions, textBox = {}) {

[wordCount, totalTextWidth] = bindTextToLine(
newLine,
objects,
toWriteTextObjects,
wordCount,
totalTextWidth
);
Expand Down Expand Up @@ -1326,32 +1316,26 @@ function makeTextObjects(self, textObject = {}, pathOptions, textBox = {}) {
let isLastLine = alignHorizontal === "justify" && !self._flow;

if (!flushLine) {
const objects = toWriteTextObjects.length ? toWriteTextObjects : incompleteTextObjects;

[wordCount, totalTextWidth] = bindTextToLine(
newLine,
objects,
toWriteTextObjects,
wordCount,
totalTextWidth
);

const incompleteTextObject = makeTextObject(
lines,
newLine,
lineID,
textBox,
Object.assign({}, lineOpts, {
wordCount: wordCount,
totalTextWidth: totalTextWidth,
lastLine: isLastLine,
}),
);

toWriteTextObjects.push(
incompleteTextObject
makeTextObject(
lines,
newLine,
lineID,
textBox,
Object.assign({}, lineOpts, {
wordCount: wordCount,
totalTextWidth: totalTextWidth,
lastLine: isLastLine,
})
)
);

self._incompleteTextObjects.push(incompleteTextObject);
} else {
toWriteTextObjects[toWriteTextObjects.length - 1].lastLine = isLastLine;
}
Expand All @@ -1370,17 +1354,13 @@ function markLineComplete(toWriteTextObjects, lines = null) {
const textObj = toWriteTextObjects[toWriteTextObjects.length - 1];
const lastWordIdx = textObj.wordsInLine.length - 1;

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

if (lines) {
textObj.lineOffset = lines;
}

this._incompleteTextObjects = [];
}

/** Move text positioning down N lines in text box
Expand Down
8 changes: 4 additions & 4 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 format inside textbox", (done) => {
it("Add text with bolded text 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 format inside textbox", (done) => {
it("Add text with italic text inside textbox", (done) => {
const src = "new"; //path.join(__dirname, '../TestMaterials/recipe/test.pdf');
const output = path.join(
__dirname,
Expand Down Expand Up @@ -413,8 +413,8 @@ describe("Text", () => {
);
const recipe = new HummusRecipe(src, output);
const textContent =
`${Date.now()} Lorem Ipsum is simply dummy text of the printing and typesetting industry. This <u>word</u> should be underlined. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. <u>This entire sentence should be underlined.</u> <u>It was popularised in the 1960s with the release </u>of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. ` +
`${Date.now()} It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. <u>The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.</u> Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).`;
`${Date.now()} Lorem Ipsum is simply dummy text of the printing and typesetting industry. This <u>word</u> should be underlined. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. <u>This entire sentence should be underlined.</u> It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. ` +
`${Date.now()} It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).`;

recipe
.createPage("letter")
Expand Down

0 comments on commit 771aaf6

Please sign in to comment.