fix: bad width calculation on raggedright

This commit is contained in:
minjaesong
2024-05-09 15:59:30 +09:00
parent 48339b0599
commit e2d6d3724c

View File

@@ -179,7 +179,8 @@ class MovableType(
if (box.isNotGlue()) {
// deal with the hangables
val slugWidthForOverflowCalc = if (box.penultimateCharOrNull == null)
val slugWidthForOverflowCalc = when (strategy) {
TypesettingStrategy.JUSTIFIED -> if (box.penultimateCharOrNull == null)
slugWidth
else if (hangable.contains(box.penultimateCharOrNull))
slugWidth - hangWidth
@@ -188,8 +189,16 @@ class MovableType(
else
slugWidth
TypesettingStrategy.RAGGED_RIGHT -> slugWidth
}
val truePaperWidth = when (strategy) {
TypesettingStrategy.JUSTIFIED -> paperWidth
TypesettingStrategy.RAGGED_RIGHT -> paperWidth + 2
}
// if adding the box would cause overflow
if (slugWidthForOverflowCalc + box.width > paperWidth) {
if (slugWidthForOverflowCalc + box.width > truePaperWidth) {
// if adding the box would cause overflow (justified)
if (strategy == TypesettingStrategy.JUSTIFIED) {
// text overflow occured; set the width to the max value