From ab249fd24b355ead23ab23f481bd219e0d95faaa Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 4 Mar 2023 01:46:07 +0200 Subject: [PATCH] [justify] Fix shrink/expand conditions --- src/justify.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/justify.py b/src/justify.py index 0677bd7e0..61b71ed2f 100644 --- a/src/justify.py +++ b/src/justify.py @@ -168,9 +168,10 @@ class Line: def justify(self): buf, text = makebuffer(str(self)) + wiggle = 5 advance = self.advance - shrink = self._target_advance > advance - expand = not shrink + shrink = self._target_advance - wiggle < advance + expand = self._target_advance + wiggle > advance ret, advance, tag, value = hb.shape_justify( self._font, @@ -184,15 +185,17 @@ class Line: if not ret: return False - if shrink and advance > self._target_advance: - return False - if expand and advance < self._target_advance: - return False self._variation = hb.variation_t() self._variation.tag = tag self._variation.value = value self._words = makewords(buf, self._font, text) + + if shrink and advance > self._target_advance + wiggle: + return False + if expand and advance < self._target_advance - wiggle: + return False + return True def draw(self, context):