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,17 +179,26 @@ class MovableType(
if (box.isNotGlue()) { if (box.isNotGlue()) {
// deal with the hangables // deal with the hangables
val slugWidthForOverflowCalc = if (box.penultimateCharOrNull == null) val slugWidthForOverflowCalc = when (strategy) {
slugWidth TypesettingStrategy.JUSTIFIED -> if (box.penultimateCharOrNull == null)
else if (hangable.contains(box.penultimateCharOrNull)) slugWidth
slugWidth - hangWidth else if (hangable.contains(box.penultimateCharOrNull))
else if (hangableFW.contains(box.penultimateCharOrNull)) slugWidth - hangWidth
slugWidth - hangWidthFW else if (hangableFW.contains(box.penultimateCharOrNull))
else slugWidth - hangWidthFW
slugWidth 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 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 adding the box would cause overflow (justified)
if (strategy == TypesettingStrategy.JUSTIFIED) { if (strategy == TypesettingStrategy.JUSTIFIED) {
// text overflow occured; set the width to the max value // text overflow occured; set the width to the max value