Skip to content

Commit 771aaf6

Browse files
committed
Revert commits 264bb9a 4cba1ee baee450
1 parent 264bb9a commit 771aaf6

File tree

2 files changed

+24
-44
lines changed

2 files changed

+24
-44
lines changed

lib/recipe/text.js

+20-40
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ function _initOptions(self, x = {}, y, options = {}) {
9797
self._firstLineHeight = 0; // indicates not set yet, determined later.
9898
self._textOptions = { textBox: {} };
9999
self._previousTextObjects = [];
100-
self._incompleteTextObjects = [];
101100
self._flow = options.flow || false;
102101

103102
if (options.layout) {
@@ -114,7 +113,6 @@ function _initOptions(self, x = {}, y, options = {}) {
114113
}
115114

116115
self._previousTextObjects = self._previousTextObjects || [];
117-
self._incompleteTextObjects = self._incompleteTextObjects || [];
118116

119117
// Merge any previous options with new options
120118
const mergedOpts = self._merge(self._textOptions, options);
@@ -837,7 +835,6 @@ exports._layoutText = function _layoutText(textObjects, textBox, pathOptions) {
837835
: child.strikeOut;
838836

839837
child.lineID = textObject.lineID;
840-
child.tag = textObject.tag;
841838
writeValue(child);
842839
});
843840
}
@@ -1087,7 +1084,6 @@ function bindTextToLine(line, textObjects, wordCount, totalTextWidth) {
10871084

10881085
function makeTextObjects(self, textObject = {}, pathOptions, textBox = {}) {
10891086
const toWriteTextObjects = [...self._previousTextObjects];
1090-
const incompleteTextObjects = self._incompleteTextObjects || [];
10911087
let text =
10921088
(textObject.prependValue ? textObject.prependValue : "") +
10931089
textObject.value +
@@ -1150,11 +1146,11 @@ function makeTextObjects(self, textObject = {}, pathOptions, textBox = {}) {
11501146
// When text flow is involved, there may be lines that are
11511147
// incomplete. So need to determine previous line word count
11521148
// and remove last line marks because more text is being processed.
1153-
if (incompleteTextObjects.length > 0) {
1149+
if (toWriteTextObjects.length > 0) {
11541150
let lineWidth = 0;
11551151
let spaceSz = 0;
1156-
const end = incompleteTextObjects.length - 1;
1157-
const previousLine = incompleteTextObjects[end];
1152+
const end = toWriteTextObjects.length - 1;
1153+
const previousLine = toWriteTextObjects[end];
11581154
let lineComplete, fini;
11591155

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

11651161
for (let i = end; i >= 0; i--) {
1166-
let textObj = incompleteTextObjects[i];
1162+
let textObj = toWriteTextObjects[i];
11671163

11681164
// only collect data while lineID's match.
11691165
if (textObj.lineID !== previousLine.lineID) {
@@ -1178,10 +1174,7 @@ function makeTextObjects(self, textObject = {}, pathOptions, textBox = {}) {
11781174
} else {
11791175
fini = textObj.lineComplete;
11801176
}
1181-
1182-
if (textObj.wordsInLine.length) {
1183-
textObj.wordsInLine[textObj.wordsInLine.length - 1].lastWord(fini);
1184-
}
1177+
textObj.wordsInLine[textObj.wordsInLine.length - 1].lastWord(fini);
11851178
}
11861179

11871180
if (lineComplete) {
@@ -1192,7 +1185,6 @@ function makeTextObjects(self, textObject = {}, pathOptions, textBox = {}) {
11921185
spaceSz = 0;
11931186
}
11941187
remainderWidth = lineMaxWidth - lineWidth - spaceSz;
1195-
lineID = previousLine.lineID;
11961188
}
11971189
}
11981190

@@ -1207,16 +1199,14 @@ function makeTextObjects(self, textObject = {}, pathOptions, textBox = {}) {
12071199
} else {
12081200
// Protect against line width being too small to accept any
12091201
// word, which may also happen during text justification.
1210-
const objects = toWriteTextObjects.length ? toWriteTextObjects : incompleteTextObjects;
1211-
12121202
if (newLine.words.length === 0) {
12131203
// self.movedown(); // start at front of next line.
12141204
if (wordCount > 0) {
12151205
// no words applied to previous segment, so drop word count
12161206
// and mark last word of previous line in case justifying.
12171207
wordCount = 0;
12181208
totalTextWidth = 0;
1219-
markLineComplete(objects);
1209+
markLineComplete(toWriteTextObjects);
12201210
}
12211211
} else {
12221212
// remove any trailing space on previous word so right justification works appropriately
@@ -1226,7 +1216,7 @@ function makeTextObjects(self, textObject = {}, pathOptions, textBox = {}) {
12261216

12271217
[wordCount, totalTextWidth] = bindTextToLine(
12281218
newLine,
1229-
objects,
1219+
toWriteTextObjects,
12301220
wordCount,
12311221
totalTextWidth
12321222
);
@@ -1326,32 +1316,26 @@ function makeTextObjects(self, textObject = {}, pathOptions, textBox = {}) {
13261316
let isLastLine = alignHorizontal === "justify" && !self._flow;
13271317

13281318
if (!flushLine) {
1329-
const objects = toWriteTextObjects.length ? toWriteTextObjects : incompleteTextObjects;
1330-
13311319
[wordCount, totalTextWidth] = bindTextToLine(
13321320
newLine,
1333-
objects,
1321+
toWriteTextObjects,
13341322
wordCount,
13351323
totalTextWidth
13361324
);
13371325

1338-
const incompleteTextObject = makeTextObject(
1339-
lines,
1340-
newLine,
1341-
lineID,
1342-
textBox,
1343-
Object.assign({}, lineOpts, {
1344-
wordCount: wordCount,
1345-
totalTextWidth: totalTextWidth,
1346-
lastLine: isLastLine,
1347-
}),
1348-
);
1349-
13501326
toWriteTextObjects.push(
1351-
incompleteTextObject
1327+
makeTextObject(
1328+
lines,
1329+
newLine,
1330+
lineID,
1331+
textBox,
1332+
Object.assign({}, lineOpts, {
1333+
wordCount: wordCount,
1334+
totalTextWidth: totalTextWidth,
1335+
lastLine: isLastLine,
1336+
})
1337+
)
13521338
);
1353-
1354-
self._incompleteTextObjects.push(incompleteTextObject);
13551339
} else {
13561340
toWriteTextObjects[toWriteTextObjects.length - 1].lastLine = isLastLine;
13571341
}
@@ -1370,17 +1354,13 @@ function markLineComplete(toWriteTextObjects, lines = null) {
13701354
const textObj = toWriteTextObjects[toWriteTextObjects.length - 1];
13711355
const lastWordIdx = textObj.wordsInLine.length - 1;
13721356

1373-
if (lastWordIdx > -1) {
1374-
textObj.wordsInLine[lastWordIdx].lastWord();
1375-
}
1357+
textObj.wordsInLine[lastWordIdx].lastWord();
13761358
textObj.text = textObj.text.trim();
13771359
textObj.lineComplete = true;
13781360

13791361
if (lines) {
13801362
textObj.lineOffset = lines;
13811363
}
1382-
1383-
this._incompleteTextObjects = [];
13841364
}
13851365

13861366
/** Move text positioning down N lines in text box

tests/recipe/text.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ describe("Text", () => {
215215
.endPDF(done);
216216
});
217217

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

313-
it("Add text with italic format inside textbox", (done) => {
313+
it("Add text with italic text inside textbox", (done) => {
314314
const src = "new"; //path.join(__dirname, '../TestMaterials/recipe/test.pdf');
315315
const output = path.join(
316316
__dirname,
@@ -413,8 +413,8 @@ describe("Text", () => {
413413
);
414414
const recipe = new HummusRecipe(src, output);
415415
const textContent =
416-
`${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. ` +
417-
`${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).`;
416+
`${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. ` +
417+
`${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).`;
418418

419419
recipe
420420
.createPage("letter")

0 commit comments

Comments
 (0)