in modules/layers/src/text-layer/utils.js [235:282]
export function transformParagraph(paragraph, lineHeight, wordBreak, maxWidth, iconMapping) {
const result = new Array(paragraph.length);
const autoWrappingEnabled =
(wordBreak === 'break-word' || wordBreak === 'break-all') && isFinite(maxWidth) && maxWidth > 0;
// maxWidth and height of the paragraph
const size = [0, 0];
let rowOffsetTop = 0;
let lineStartIndex = 0;
for (let i = 0; i <= paragraph.length; i++) {
const char = paragraph[i];
let line;
if (char === '\n' || char === undefined) {
line = paragraph.slice(lineStartIndex, i);
}
if (line) {
const rows = autoWrappingEnabled
? autoWrapping(line, wordBreak, maxWidth, iconMapping).rows
: [line];
for (const row of rows) {
const {rowWidth, rowHeight, leftOffsets} = transformRow(row, iconMapping, lineHeight);
for (const x of leftOffsets) {
result[lineStartIndex++] = {
x,
y: rowOffsetTop + rowHeight / 2,
rowWidth
};
}
rowOffsetTop = rowOffsetTop + rowHeight * lineHeight;
size[0] = autoWrappingEnabled ? maxWidth : Math.max(size[0], rowWidth);
}
}
if (char === '\n') {
// Make sure result.length matches paragraph.length
result[lineStartIndex++] = {x: 0, y: 0, rowWidth: 0};
}
}
// last row
size[1] = rowOffsetTop;
return {characters: result, size};
}