|
|
@ -1,5 +1,7 @@
|
|
|
|
'use strict';
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const defaultValue = require("default-value");
|
|
|
|
|
|
|
|
|
|
|
|
const parser = require("../parser");
|
|
|
|
const parser = require("../parser");
|
|
|
|
const findAlignment = require("../parser/find-alignment");
|
|
|
|
const findAlignment = require("../parser/find-alignment");
|
|
|
|
const generateStyle = require("../parser/generate-style");
|
|
|
|
const generateStyle = require("../parser/generate-style");
|
|
|
@ -52,7 +54,7 @@ module.exports = function layoutFormattedText(text, options) {
|
|
|
|
let height = max(processedItems.map(item => item.measurements.height));
|
|
|
|
let height = max(processedItems.map(item => item.measurements.height));
|
|
|
|
|
|
|
|
|
|
|
|
return Object.assign(line, {
|
|
|
|
return Object.assign(line, {
|
|
|
|
alignment: (line.items.length > 0) ? findAlignment(line.items[0]) : null,
|
|
|
|
alignment: defaultValue((line.items.length > 0) ? findAlignment(line.items[0]) : null, options.defaultStyle.alignment),
|
|
|
|
items: processedItems,
|
|
|
|
items: processedItems,
|
|
|
|
height: height,
|
|
|
|
height: height,
|
|
|
|
adjustedHeight: height * options.lineHeight * 1.13,
|
|
|
|
adjustedHeight: height * options.lineHeight * 1.13,
|
|
|
@ -72,14 +74,17 @@ module.exports = function layoutFormattedText(text, options) {
|
|
|
|
endHeightCorrection = 0;
|
|
|
|
endHeightCorrection = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let totalTextWidth = Math.ceil(max(lines.map(line => line.width)));
|
|
|
|
|
|
|
|
|
|
|
|
let {positionedItems, debugLines} = layoutItems(lines, {
|
|
|
|
let {positionedItems, debugLines} = layoutItems(lines, {
|
|
|
|
initialY: startHeightCorrection
|
|
|
|
initialY: startHeightCorrection,
|
|
|
|
|
|
|
|
totalTextWidth: totalTextWidth
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
let combinedLineHeights = sum(lines.map(line => line.adjustedHeight));
|
|
|
|
let combinedLineHeights = sum(lines.map(line => line.adjustedHeight));
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
width: Math.ceil(max(lines.map(line => line.width))),
|
|
|
|
width: totalTextWidth,
|
|
|
|
height: Math.ceil(combinedLineHeights + startHeightCorrection + endHeightCorrection + last(lines).maxDescender),
|
|
|
|
height: Math.ceil(combinedLineHeights + startHeightCorrection + endHeightCorrection + last(lines).maxDescender),
|
|
|
|
items: positionedItems,
|
|
|
|
items: positionedItems,
|
|
|
|
drawDebugLines: function drawDebugLines(context) {
|
|
|
|
drawDebugLines: function drawDebugLines(context) {
|
|
|
|