@react-pdf/textkit
Advanced tools
Comparing version 2.0.5 to 2.0.6
@@ -16,3 +16,20 @@ "use strict"; | ||
var ELLIPSIS_UNICODE = 8230; | ||
var ELLIPSIS_STRING = String.fromCharCode(ELLIPSIS_UNICODE); | ||
/** | ||
* Get ellipsis codepoint. This may be different in standard and embedded fonts | ||
* | ||
* @param {number} font | ||
* @return {Object} ellipsis codepoint | ||
*/ | ||
var getEllipsisCodePoint = function getEllipsisCodePoint(font) { | ||
if (!font.encode) return ELLIPSIS_UNICODE; | ||
var _font$encode = font.encode(ELLIPSIS_STRING), | ||
codePoints = _font$encode[0]; | ||
return parseInt(codePoints[0], 16); | ||
}; | ||
/** | ||
* Trucante block with ellipsis | ||
@@ -24,2 +41,4 @@ * | ||
*/ | ||
var truncate = function truncate(block) { | ||
@@ -30,3 +49,5 @@ var runs = R.propOr([], 'runs', R.last(block)); | ||
if (font) { | ||
return R.adjust(-1, R.compose((0, _append.default)(font.glyphForCodePoint(8230)), _trim.default))(block); | ||
var codePoint = getEllipsisCodePoint(font); | ||
var glyph = font.glyphForCodePoint(codePoint); | ||
return R.adjust(-1, R.compose((0, _append.default)(glyph), _trim.default))(block); | ||
} | ||
@@ -33,0 +54,0 @@ |
@@ -21,6 +21,4 @@ "use strict"; | ||
var ALIGNMENT_FACTORS = { | ||
left: 0, | ||
center: 0.5, | ||
right: 1, | ||
justify: 0 | ||
right: 1 | ||
}; | ||
@@ -67,8 +65,9 @@ /** | ||
return function (line) { | ||
var lineAdvanceWidth = (0, _advanceWidth.default)(line); | ||
var remainingWidth = Math.max(0, line.box.width - lineAdvanceWidth); | ||
var shouldJustify = align === 'justify' || lineAdvanceWidth > line.box.width; | ||
var lineWidth = (0, _advanceWidth.default)(line); | ||
var alignFactor = ALIGNMENT_FACTORS[align] || 0; | ||
var remainingWidth = Math.max(0, line.box.width - lineWidth); | ||
var shouldJustify = align === 'justify' || lineWidth > line.box.width; | ||
return R.compose(R.when(R.always(shouldJustify), engines.justification(options)), R.evolve({ | ||
box: R.evolve({ | ||
x: R.add(remainingWidth * ALIGNMENT_FACTORS[align]) | ||
x: R.add(remainingWidth * alignFactor) | ||
}) | ||
@@ -115,3 +114,6 @@ }))(line); | ||
var finalizeFragments = function finalizeFragments(engines, options, blocks) { | ||
return R.map(R.addIndex(R.map)(finalizeBlock(engines, options)), blocks); | ||
var blockFinalizer = finalizeBlock(engines, options); | ||
return blocks.map(function (block) { | ||
return block.map(blockFinalizer); | ||
}); | ||
}; | ||
@@ -118,0 +120,0 @@ |
@@ -39,2 +39,3 @@ "use strict"; | ||
var paragraphs = [].concat(attributedStrings); | ||
var layoutBlock = (0, _layoutParagraph.default)(engines, options); | ||
var maxLines = R.propOr(Infinity, 'maxLines', container); | ||
@@ -47,3 +48,3 @@ var truncateEllipsis = container.truncateMode === 'ellipsis'; | ||
while (linesCount > 0 && nextParagraph) { | ||
var block = (0, _layoutParagraph.default)(engines, options)(paragraphRect, nextParagraph); | ||
var block = layoutBlock(paragraphRect, nextParagraph); | ||
var slicedBlock = (0, _slice.default)(linesCount, block); | ||
@@ -50,0 +51,0 @@ var linesHeight = (0, _height.default)(slicedBlock); |
{ | ||
"name": "@react-pdf/textkit", | ||
"license": "MIT", | ||
"version": "2.0.5", | ||
"version": "2.0.6", | ||
"description": "An advanced text layout framework", | ||
@@ -25,3 +25,3 @@ "main": "./lib/index.js", | ||
}, | ||
"gitHead": "e15b90e39aefde8635663b58ef2e3ffa6494cecd" | ||
"gitHead": "eeb19949e0eb13b25ea790ffe387bc2da6b2f298" | ||
} |
150306
3952