]> git.kianting.info Git - clo/blob - src/libclo/index.js
update readme
[clo] / src / libclo / index.js
1 "use strict";
2 var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3 if (k2 === undefined) k2 = k;
4 var desc = Object.getOwnPropertyDescriptor(m, k);
5 if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6 desc = { enumerable: true, get: function() { return m[k]; } };
7 }
8 Object.defineProperty(o, k2, desc);
9 }) : (function(o, m, k, k2) {
10 if (k2 === undefined) k2 = k;
11 o[k2] = m[k];
12 }));
13 var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14 Object.defineProperty(o, "default", { enumerable: true, value: v });
15 }) : function(o, v) {
16 o["default"] = v;
17 });
18 var __importStar = (this && this.__importStar) || function (mod) {
19 if (mod && mod.__esModule) return mod;
20 var result = {};
21 if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22 __setModuleDefault(result, mod);
23 return result;
24 };
25 var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27 return new (P || (P = Promise))(function (resolve, reject) {
28 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31 step((generator = generator.apply(thisArg, _arguments || [])).next());
32 });
33 };
34 Object.defineProperty(exports, "__esModule", { value: true });
35 exports.Clo = exports.applyVOffset = exports.putInVBox = exports.calculateTextWidthHeightAux = exports.calculateTextWidthHeight = exports.hyphenTkTree = exports.filterEmptyString = exports.spacesToBreakpoint = exports.hyphenForClo = exports.splitCJKV = exports.twoReturnsToNewline = exports.ptToPx = exports.cjkvRegexPattern = exports.cjkvBlocksInRegex = exports.defaultFrameStyle = exports.defaultTextStyle = exports.A4_IN_PX = exports.Direction = void 0;
36 const canva_1 = require("../canva");
37 const fontkit = __importStar(require("fontkit"));
38 const breakLines = __importStar(require("./breakLines"));
39 const PDFDocument = require('pdfkit');
40 const memfs_1 = require("memfs");
41 /**
42 * TYPES
43 */
44 /**
45 * text direction
46 * LTR - left to right
47 * TTB - top to bottom
48 * etc.
49 */
50 var Direction;
51 (function (Direction) {
52 Direction[Direction["LTR"] = 0] = "LTR";
53 Direction[Direction["RTL"] = 1] = "RTL";
54 Direction[Direction["TTB"] = 2] = "TTB";
55 Direction[Direction["BTT"] = 3] = "BTT";
56 })(Direction || (exports.Direction = Direction = {}));
57 /**
58 * DEFAULT CONST PART
59 */
60 exports.A4_IN_PX = { "width": 793.7,
61 "height": 1122.5 };
62 exports.defaultTextStyle = {
63 family: "Noto Sans CJK TC",
64 size: ptToPx(12),
65 textWeight: canva_1.TextWeight.REGULAR,
66 fontStyle: canva_1.FontStyle.ITALIC,
67 };
68 exports.defaultFrameStyle = {
69 directionInsideLine: Direction.LTR,
70 direction: Direction.TTB,
71 baseLineskip: ptToPx(15),
72 textStyle: exports.defaultTextStyle,
73 x: exports.A4_IN_PX.width * 0.10,
74 y: exports.A4_IN_PX.height * 0.10,
75 width: exports.A4_IN_PX.width * 0.80,
76 height: exports.A4_IN_PX.height * 0.80,
77 content: null,
78 };
79 /**
80 * definition for cjk scripts
81 * - Hani : Han Character
82 * - Hang : Hangul
83 * - Bopo : Bopomofo
84 * - Kana : Katakana
85 * - Hira : Hiragana
86 */
87 exports.cjkvBlocksInRegex = ["Hani", "Hang", "Bopo", "Kana", "Hira"];
88 exports.cjkvRegexPattern = new RegExp("((?:" +
89 exports.cjkvBlocksInRegex.map((x) => "\\p{Script_Extensions=" + x + "}").join("|") + ")+)", "gu");
90 /**
91 * FUNCTION PART
92 */
93 /**
94 * convert from ptToPx
95 * @param pt pt size value
96 * @returns the corresponding px value
97 */
98 function ptToPx(pt) {
99 return pt * 4.0 / 3.0;
100 }
101 exports.ptToPx = ptToPx;
102 /**
103 * REGISTER PART
104 */
105 /**
106 * convert '\n\n' to new paragraph command ["br"]
107 * @param arr the input `tkTree`
108 * @param clo the `Clo` object
109 * @returns the input tktree
110 */
111 function twoReturnsToNewline(arr, clo) {
112 var middle = [];
113 for (let i = 0; i < arr.length; i++) {
114 var item = arr[i];
115 if (!Array.isArray(item)) {
116 middle = middle.concat(item.split(/(\n\n)/g));
117 }
118 else {
119 middle.push(item);
120 }
121 }
122 var result = [];
123 for (let j = 0; j < middle.length; j++) {
124 var item = middle[j];
125 if (!Array.isArray(item) && item == "\n\n") {
126 result.push(["br"]); // push a newline command to the result `tkTree`
127 }
128 else {
129 result.push(middle[j]);
130 }
131 }
132 return result;
133 }
134 exports.twoReturnsToNewline = twoReturnsToNewline;
135 /**
136 * split CJKV and non-CJKV
137 *
138 * @param arr : input tkTree
139 * @returns a splitted tkTree (by CJK and NonCJK)
140 * - Examples:
141 * ```
142 * [`many臺中daylight`] => [`many`, `臺中`, `dahylight`]
143 * ```
144 */
145 function splitCJKV(arr, clo) {
146 var result = [];
147 for (let i = 0; i < arr.length; i++) {
148 var item = arr[i];
149 if (!Array.isArray(item)) {
150 result = result.concat(item.split(exports.cjkvRegexPattern));
151 }
152 else {
153 result.push(item);
154 }
155 }
156 return result;
157 }
158 exports.splitCJKV = splitCJKV;
159 /**
160 * hyphenation for a clo document
161 * @param arr the array for a `tkTree`
162 * @param clo the Clo object
163 */
164 function hyphenForClo(arr, clo) {
165 let hyphenLanguage = clo.attrs["hyphenLanguage"];
166 let res = hyphenTkTree(arr, hyphenLanguage);
167 return res;
168 }
169 exports.hyphenForClo = hyphenForClo;
170 /**
171 * convert spaces to Breakpoint
172 * \s+ => ["bp" [\s+] ""]
173 * @param arr the tkTree input text stream
174 * @param clo the Clo object
175 * @returns the converted object
176 */
177 function spacesToBreakpoint(arr, clo) {
178 let spacePattern = /^([ \t]+)$/g;
179 var result = [];
180 for (let i = 0; i < arr.length; i++) {
181 var item = arr[i];
182 if (!Array.isArray(item) && item.match(spacePattern)) {
183 // push a breakpoint command to the result `tkTree`
184 result.push(['bp', [["hglue", "0.1"], item], ""]);
185 }
186 else {
187 result.push(item);
188 }
189 }
190 return result;
191 }
192 exports.spacesToBreakpoint = spacesToBreakpoint;
193 /**
194 * remove all the `` (empty string) in the arr
195 * @param arr the tkTree to be filtered
196 * @param clo the Clo file
197 */
198 function filterEmptyString(arr, clo) {
199 if (Array.isArray(arr)) {
200 arr.filter((x) => { return x != ``; });
201 }
202 return arr;
203 }
204 exports.filterEmptyString = filterEmptyString;
205 /**
206 * OTHER FUNCTIONS
207 */
208 /**
209 * hyphenate for a tkTree
210 * - hyphenation => ["bp", "", "-"]
211 * @param arr the tkTree array
212 * @param lang ISO 639 code for the language
213 */
214 function hyphenTkTree(arr, lang) {
215 // import corresponding hyphen language data and function
216 let hyphen = require("hyphen/" + lang);
217 let result = [];
218 for (let i = 0; i < arr.length; i++) {
219 let element = arr[i];
220 let splitter = "分"; // a CJKV
221 if (!Array.isArray(element)) {
222 let hyphenatedElement = hyphen.hyphenateSync(element, { hyphenChar: splitter });
223 let hyphenatedSplitted = hyphenatedElement.split(splitter);
224 var newSplitted = [];
225 for (var j = 0; j < hyphenatedSplitted.length - 1; j++) {
226 newSplitted.push(hyphenatedSplitted[j]);
227 // "bp" for breakpoint
228 newSplitted.push(["bp", "", "-"]); //insert a breakable point (bp) mark
229 }
230 newSplitted.push(hyphenatedSplitted[hyphenatedSplitted.length - 1]);
231 result = result.concat(newSplitted);
232 }
233 else {
234 result.push(element);
235 }
236 }
237 return result;
238 }
239 exports.hyphenTkTree = hyphenTkTree;
240 /**
241 * calculate the text width and Height with a given `TextStyle`
242 * @param preprocessed
243 * @param defaultFontStyle
244 */
245 function calculateTextWidthHeight(element, style) {
246 return __awaiter(this, void 0, void 0, function* () {
247 var res = [];
248 var styleCache = {};
249 var fontCache = {};
250 for (var i = 0; i < element.length; i++) {
251 let item = yield calculateTextWidthHeightAux(element[i], style, styleCache, fontCache);
252 styleCache = item[1];
253 fontCache = item[2];
254 res.push(item[0]);
255 }
256 res = res.flat();
257 return res;
258 });
259 }
260 exports.calculateTextWidthHeight = calculateTextWidthHeight;
261 /**
262 * calculate the text width and Height with a given `TextStyle`
263 * @param preprocessed
264 * @param defaultFontStyle
265 */
266 function calculateTextWidthHeightAux(element, style, styleCache, fontCache) {
267 return __awaiter(this, void 0, void 0, function* () {
268 var result = [];
269 var font;
270 if (style === styleCache) {
271 font = fontCache;
272 }
273 else {
274 let fontPair = (0, canva_1.fontStyleTofont)(style);
275 if (fontPair.path.match(/\.ttc$/)) {
276 font = yield fontkit.openSync(fontPair.path, fontPair.psName);
277 styleCache = style;
278 fontCache = font;
279 }
280 else {
281 font = yield fontkit.openSync(fontPair.path);
282 styleCache = style;
283 fontCache = font;
284 }
285 }
286 if (!Array.isArray(element)) {
287 var run = font.layout(element, undefined, undefined, undefined, "ltr");
288 for (var j = 0; j < run.glyphs.length; j++) {
289 let runGlyphsItem = run.glyphs[j];
290 let item = {
291 x: null,
292 y: null,
293 textStyle: style,
294 direction: Direction.LTR,
295 width: (runGlyphsItem.advanceWidth) * (style.size) / 1000 * 0.75,
296 height: (runGlyphsItem.bbox.maxY - runGlyphsItem.bbox.minY) * (style.size) / 1000 * 0.75,
297 content: element[j],
298 minX: runGlyphsItem.bbox.minX,
299 maxX: runGlyphsItem.bbox.maxX,
300 minY: runGlyphsItem.bbox.minY,
301 maxY: runGlyphsItem.bbox.maxY
302 };
303 result.push(item);
304 }
305 return [result, styleCache, fontCache];
306 // break point of a line
307 }
308 else if (element[0] == "bp") {
309 var beforeNewLine = (yield calculateTextWidthHeightAux(element[1], style, styleCache, fontCache))[0];
310 if (Array.isArray(beforeNewLine)) {
311 beforeNewLine = beforeNewLine.flat();
312 }
313 let afterNewLine = (yield calculateTextWidthHeightAux(element[2], style, styleCache, fontCache))[0];
314 if (Array.isArray(afterNewLine)) {
315 afterNewLine = afterNewLine.flat();
316 }
317 let breakPointNode = {
318 original: beforeNewLine,
319 newLined: afterNewLine,
320 };
321 return [breakPointNode, styleCache, fontCache];
322 // hglue
323 }
324 else if (element[0] == "hglue" && !Array.isArray(element[1])) {
325 let hGlue = {
326 isHorizonalGlue: true,
327 stretchFactor: parseFloat(element[1])
328 };
329 return [hGlue, styleCache, fontCache];
330 }
331 // new line <br/>
332 else if (element[0] == "br") {
333 let brBoxItem = yield calculateTextWidthHeightAux(["hglue", "10000"], style, styleCache, fontCache);
334 // <br/>
335 let BR = {
336 isBR: true,
337 original: brBoxItem[0],
338 newLined: brBoxItem[0]
339 };
340 return [BR, styleCache, fontCache];
341 }
342 else {
343 return [yield calculateTextWidthHeight(element, style), styleCache, fontCache];
344 }
345 });
346 }
347 exports.calculateTextWidthHeightAux = calculateTextWidthHeightAux;
348 /**
349 * put childrenBox inside VBox
350 */
351 function putInVBox(childrenBox, parentBox) {
352 var voffset = Array(childrenBox.length).fill(0);
353 for (var i = 0; i < childrenBox.length - 1; i++) {
354 voffset[i + 1] = voffset[i] + childrenBox[i].height;
355 }
356 console.log("~", voffset);
357 for (var i = 0; i < childrenBox.length; i++) {
358 childrenBox[i] = applyVOffset(childrenBox[i], voffset[i]);
359 childrenBox[i].y += voffset[i];
360 }
361 parentBox.content = childrenBox;
362 return parentBox;
363 }
364 exports.putInVBox = putInVBox;
365 /**
366 * apply vertical offset to a box
367 * @param box the box to be applied
368 * @param voffset the vertical offset
369 * @returns applied box
370 */
371 function applyVOffset(box, voffset) {
372 if (box.y !== null) {
373 box.y += voffset;
374 }
375 if (Array.isArray(box.content)) {
376 box.content = box.content.map((x) => applyVOffset(x, voffset));
377 }
378 return box;
379 }
380 exports.applyVOffset = applyVOffset;
381 /**
382 * whole document-representing class
383 */
384 class Clo {
385 constructor() {
386 this.preprocessors = [];
387 this.mainStream = [];
388 this.attrs = {
389 "page": exports.A4_IN_PX,
390 "defaultFrameStyle": exports.defaultFrameStyle,
391 "hyphenLanguage": 'en' // hyphenated in the language (in ISO 639)
392 };
393 // register the precessor functions
394 this.preprocessorRegister(splitCJKV);
395 this.preprocessorRegister(hyphenForClo);
396 this.preprocessorRegister(twoReturnsToNewline);
397 this.preprocessorRegister(spacesToBreakpoint);
398 this.preprocessorRegister(filterEmptyString);
399 }
400 setAttr(attr, val) {
401 Object.assign(this.attrs, attr, val);
402 }
403 getAttr(attr) {
404 if (Object.keys(this.attrs).length === 0) {
405 return this.attrs[attr];
406 }
407 else {
408 return undefined;
409 }
410 }
411 /**
412 * register a function of preprocessor
413 * @param f a function
414 */
415 preprocessorRegister(f) {
416 this.preprocessors.push(f);
417 }
418 generatePdf() {
419 return __awaiter(this, void 0, void 0, function* () {
420 // preprocessed
421 var preprocessed = this.mainStream;
422 for (var i = 0; i < this.preprocessors.length; i++) {
423 preprocessed = this.preprocessors[i](preprocessed, this);
424 }
425 // generate the width and height of the stream
426 let defaultFontStyle = this.attrs.defaultFrameStyle.textStyle;
427 // calculate the width and height of each chars
428 let calculated = yield calculateTextWidthHeight(preprocessed, defaultFontStyle);
429 //
430 let paragraphized = this.paragraphize(calculated);
431 let breakLineAlgorithms = new breakLines.BreakLineAlgorithm();
432 let segmentedNodes = paragraphized.map((x) => breakLineAlgorithms.segmentedNodes(x, this.attrs.defaultFrameStyle.width));
433 let segmentedNodesToBox = segmentedNodes.map((x) => this.segmentedNodesToFrameBoxAux(x, this.attrs.defaultFrameStyle));
434 let boxWithParagraph = putInVBox(segmentedNodesToBox, this.attrs.defaultFrameStyle);
435 console.log(boxWithParagraph);
436 // fix the bug of main Frame x & y
437 if (boxWithParagraph.x !== null) {
438 boxWithParagraph.x *= 0.75;
439 }
440 if (boxWithParagraph.y !== null) {
441 boxWithParagraph.y *= 0.75;
442 }
443 let boxesFixed = this.fixenBoxesPosition(boxWithParagraph);
444 boxesFixed.content.map((e) => { console.log(e.y); });
445 // generate pdf
446 const doc = new PDFDocument({ size: 'A4' });
447 // let fsMemory = memfs();
448 doc.pipe(memfs_1.vol.createWriteStream('output.pdf'));
449 this.grid(doc);
450 let styleCache = {};
451 let fontPairCache = { path: "", psName: "" };
452 yield this.putText(doc, boxesFixed, styleCache, fontPairCache);
453 // putChar
454 doc.end();
455 });
456 }
457 paragraphize(calculated) {
458 var res = [[]];
459 for (var i = 0; i < calculated.length; i++) {
460 if ("isBR" in (calculated[i])) {
461 res[res.length - 1] = res[res.length - 1].concat(calculated[i]);
462 res.push([]);
463 }
464 else {
465 res[res.length - 1] = res[res.length - 1].concat(calculated[i]);
466 }
467 }
468 res = res.filter((x) => x.length !== 0);
469 return res;
470 }
471 putText(doc, box, styleCache, fontPairCache) {
472 return __awaiter(this, void 0, void 0, function* () {
473 var fontPair;
474 if (box.textStyle !== null) {
475 if (box.textStyle == styleCache) {
476 fontPair = fontPairCache;
477 }
478 else {
479 fontPair = (0, canva_1.fontStyleTofont)(box.textStyle);
480 styleCache = box.textStyle;
481 fontPairCache = fontPair;
482 let textColor = box.textStyle.color;
483 if (fontPair.path.match(/\.ttc$/g)) {
484 doc
485 .fillColor(textColor !== undefined ? textColor : "#000000")
486 .font(fontPair.path, fontPair.psName)
487 .fontSize(box.textStyle.size * 0.75);
488 }
489 else {
490 doc
491 .fillColor(textColor !== undefined ? textColor : "#000000")
492 .font(fontPair.path)
493 .fontSize(box.textStyle.size * 0.75); // 0.75 must added!
494 }
495 }
496 if (box.textStyle.color !== undefined) {
497 doc.fill(box.textStyle.color);
498 }
499 if (Array.isArray(box.content)) {
500 for (var k = 0; k < box.content.length; k++) {
501 let tmp = yield this.putText(doc, box.content[k], styleCache, fontPairCache);
502 doc = tmp[0];
503 styleCache = tmp[1];
504 fontPairCache = tmp[2];
505 }
506 }
507 else if (box.content !== null) {
508 yield doc.text(box.content, (box.x !== null ? box.x : undefined), (box.y !== null ? box.y : undefined));
509 }
510 }
511 return [doc, styleCache, fontPairCache];
512 });
513 }
514 ;
515 grid(doc) {
516 for (var j = 0; j < exports.A4_IN_PX.width; j += 5) {
517 if (j % 50 == 0) {
518 doc.save().fill('#000000')
519 .fontSize(8).text(j.toString(), j * 0.75, 50);
520 doc
521 .save()
522 .lineWidth(0.4)
523 .strokeColor("#dddddd")
524 .moveTo(j * 0.75, 0)
525 .lineTo(j * 0.75, 1000)
526 .stroke();
527 }
528 doc
529 .save()
530 .lineWidth(0.2)
531 .strokeColor("#dddddd")
532 .moveTo(j * 0.75, 0)
533 .lineTo(j * 0.75, 1000)
534 .stroke();
535 }
536 for (var i = 0; i < 1050; i += 5) {
537 if (i % 50 == 0) {
538 doc.save()
539 .fontSize(8).text(i.toString(), 50, i * 0.75);
540 doc
541 .save()
542 .lineWidth(0.4)
543 .strokeColor("#bbbbbb")
544 .moveTo(0, i * 0.75)
545 .lineTo(1000, i * 0.75)
546 .stroke();
547 }
548 doc
549 .save()
550 .lineWidth(0.2)
551 .strokeColor("#bbbbbb")
552 .moveTo(0, i * 0.75)
553 .lineTo(1000, i * 0.75)
554 .stroke();
555 }
556 doc
557 .save()
558 .moveTo(0, 200)
559 .lineTo(1000, 200)
560 .fill('#FF3300');
561 }
562 /**
563 * make all the nest boxes's position fixed
564 * @param box the main boxes
565 * @returns the fixed boxes
566 */
567 fixenBoxesPosition(box) {
568 var currX = (box.x !== null ? box.x : 0); // current x
569 var currY = (box.y !== null ? box.y : 0); // current y
570 if (Array.isArray(box.content)) {
571 for (var i = 0; i < box.content.length; i++) {
572 if (box.direction == Direction.LTR) {
573 box.content[i].x = currX;
574 box.content[i].y = currY;
575 let elementWidth = box.content[i].width;
576 if (elementWidth !== null) {
577 currX += elementWidth;
578 }
579 }
580 if (box.direction == Direction.TTB) {
581 box.content[i].x = currX;
582 box.content[i].y = currY;
583 let elementHeight = box.content[i].height;
584 if (elementHeight !== null) {
585 currY += elementHeight;
586 }
587 }
588 box.content[i] = this.fixenBoxesPosition(box.content[i]);
589 }
590 }
591 return box;
592 }
593 /**
594 * input a `segmentedNodes` and a layed `frame`, return a big `Box` that nodes is put in.
595 * @param segmentedNodes the segmentnodes to be input
596 * @param frame the frame to be layed out.
597 * @returns the big `Box`.
598 */
599 segmentedNodesToFrameBoxAux(segmentedNodes, frame) {
600 let baseLineskip = frame.baseLineskip;
601 let boxArrayEmpty = [];
602 let bigBox = {
603 x: (frame.x !== null ? frame.x * 0.75 : null),
604 y: (frame.y !== null ? frame.y * 0.75 : null),
605 textStyle: frame.textStyle,
606 direction: frame.direction,
607 width: frame.width,
608 height: frame.height,
609 content: boxArrayEmpty,
610 };
611 var bigBoxContent = boxArrayEmpty;
612 let segmentedNodesFixed = segmentedNodes.map((x) => this.removeBreakPoints(x).flat());
613 let segmentedNodeUnglue = segmentedNodesFixed.map((x) => this.removeGlue(x, frame).flat());
614 for (var i = 0; i < segmentedNodeUnglue.length; i++) {
615 var currentLineSkip = baseLineskip;
616 var glyphMaxHeight = this.getGlyphMaxHeight(segmentedNodesFixed[i]);
617 if (currentLineSkip === null || glyphMaxHeight > currentLineSkip) {
618 currentLineSkip = glyphMaxHeight;
619 }
620 var currentLineBox = {
621 x: null,
622 y: null,
623 textStyle: exports.defaultTextStyle,
624 direction: frame.directionInsideLine,
625 width: frame.width,
626 height: currentLineSkip,
627 content: segmentedNodeUnglue[i],
628 };
629 bigBoxContent.push(currentLineBox);
630 }
631 bigBox.content = bigBoxContent;
632 let bigBoxHeight = bigBoxContent.map((x) => x.height).reduce((x, y) => x + y, 0);
633 bigBox.height = bigBoxHeight;
634 return bigBox;
635 }
636 /**
637 * get the max height of the glyph`[a, b, c]`
638 * @param nodeLine the node line [a, b, c, ...]
639 * @returns
640 */
641 getGlyphMaxHeight(nodeLine) {
642 let segmentedNodeLineHeight = nodeLine.map((x) => { if ("height" in x && x.height > 0.0) {
643 return x.height;
644 }
645 else {
646 return 0.0;
647 } });
648 let maxHeight = Math.max(...segmentedNodeLineHeight);
649 return maxHeight;
650 }
651 removeGlue(nodeLine, frame) {
652 let breakLineAlgorithms = new breakLines.BreakLineAlgorithm();
653 let glueRemoved = nodeLine.filter((x) => !breakLineAlgorithms.isHGlue(x));
654 let onlyGlue = nodeLine.filter((x) => breakLineAlgorithms.isHGlue(x));
655 let sumStretchFactor = onlyGlue.map((x) => { if ("stretchFactor" in x) {
656 return x.stretchFactor;
657 }
658 else {
659 return 0;
660 } })
661 .reduce((acc, cur) => acc + cur, 0);
662 let glueRemovedWidth = glueRemoved.map((x) => { if ("width" in x) {
663 return x.width;
664 }
665 else {
666 return 0;
667 } })
668 .reduce((acc, cur) => acc + cur, 0);
669 let offset = frame.width * 0.75 - glueRemovedWidth;
670 var res = [];
671 for (var i = 0; i < nodeLine.length; i++) {
672 var ele = nodeLine[i];
673 if (breakLineAlgorithms.isHGlue(ele)) {
674 let tmp = {
675 x: null,
676 y: null,
677 textStyle: null,
678 direction: frame.directionInsideLine,
679 //width : 0, // ragged
680 width: ele.stretchFactor / sumStretchFactor * offset,
681 height: 0,
682 content: "",
683 };
684 res.push(tmp);
685 }
686 else {
687 res.push(ele);
688 }
689 }
690 return res;
691 }
692 /**
693 * remove breakpoints
694 * @param boxitemline boxitem in a line with a breakpoint
695 * @returns boxitemline with break points removed
696 */
697 removeBreakPoints(boxitemline) {
698 var res = [];
699 let breakLineAlgorithms = new breakLines.BreakLineAlgorithm();
700 for (var i = 0; i < boxitemline.length; i++) {
701 let ele = boxitemline[i];
702 if (breakLineAlgorithms.isBreakPoint(ele)) {
703 if (i == boxitemline.length - 1) {
704 res.push(ele.newLined);
705 }
706 else {
707 res.push(ele.original);
708 }
709 }
710 else {
711 res.push(ele);
712 }
713 }
714 return res;
715 }
716 }
717 exports.Clo = Clo;
718 /*
719 export let a = new Clo();
720 export default a; */