Fix cut-off descenders in non-whitespace-trimming mode

master
Sven Slootweg 7 years ago
parent 8f51e98b92
commit bbc2574e51

@ -79,7 +79,7 @@ module.exports = function layoutFormattedText(text, options) {
if (options.trimVerticalWhitespace) { if (options.trimVerticalWhitespace) {
startHeightCorrection = -(adjustedLineHeights[0] / 2) - (lines[0].minAscender / 2); startHeightCorrection = -(adjustedLineHeights[0] / 2) - (lines[0].minAscender / 2);
endHeightCorrection = -(last(adjustedLineHeights) / 2) - (last(lines).minAscender / 2) + (last(lines).maxDescender); endHeightCorrection = -(last(adjustedLineHeights) / 2) - (last(lines).minAscender / 2);
} else { } else {
startHeightCorrection = 0; startHeightCorrection = 0;
endHeightCorrection = 0; endHeightCorrection = 0;
@ -117,7 +117,7 @@ module.exports = function layoutFormattedText(text, options) {
return { return {
width: Math.ceil(max(lines.map(line => line.width))), width: Math.ceil(max(lines.map(line => line.width))),
height: Math.ceil(sum(adjustedLineHeights) + startHeightCorrection + endHeightCorrection), height: Math.ceil(sum(adjustedLineHeights) + startHeightCorrection + endHeightCorrection + (last(lines).maxDescender)),
items: positionedItems, items: positionedItems,
drawDebugLines: function drawDebugLines(context) { drawDebugLines: function drawDebugLines(context) {
debugLines.forEach((debugLine) => { debugLines.forEach((debugLine) => {
@ -154,7 +154,7 @@ module.exports = function layoutFormattedText(text, options) {
if (options.trimVerticalWhitespace) { if (options.trimVerticalWhitespace) {
startHeightCorrection = -(adjustedLineHeights[0] / 2) - (lines[0].measurements.ascender / 2); startHeightCorrection = -(adjustedLineHeights[0] / 2) - (lines[0].measurements.ascender / 2);
endHeightCorrection = -(last(adjustedLineHeights) / 2) - (last(lines).measurements.ascender / 2) + (last(lines).measurements.descender); endHeightCorrection = -(last(adjustedLineHeights) / 2) - (last(lines).measurements.ascender / 2);
} else { } else {
startHeightCorrection = 0; startHeightCorrection = 0;
endHeightCorrection = 0; endHeightCorrection = 0;
@ -186,7 +186,7 @@ module.exports = function layoutFormattedText(text, options) {
return { return {
width: Math.ceil(max(lines.map(line => line.measurements.width))), width: Math.ceil(max(lines.map(line => line.measurements.width))),
height: Math.ceil(sum(adjustedLineHeights) + startHeightCorrection + endHeightCorrection), height: Math.ceil(sum(adjustedLineHeights) + startHeightCorrection + endHeightCorrection + (last(lines).measurements.descender)),
items: positionedItems, items: positionedItems,
drawDebugLines: function drawDebugLines(context) { drawDebugLines: function drawDebugLines(context) {
debugLines.forEach((debugLine) => { debugLines.forEach((debugLine) => {

Loading…
Cancel
Save