From 547112077506d299b3cae91525ba194bb57ae2c7 Mon Sep 17 00:00:00 2001 From: Max Kasperowski Date: Tue, 22 Oct 2024 09:56:33 +0200 Subject: [PATCH] Address PR comments Correct spelling of fuzziness Remove superfluous comment Add check to only execute fuzzy code when it would have an effect --- .../management/SoftWrappingLabelManager.java | 50 +++++++++---------- .../kieler/klighd/util/KlighdProperties.java | 4 +- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/labels/management/SoftWrappingLabelManager.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/labels/management/SoftWrappingLabelManager.java index 7a4e091d2..d737e0439 100644 --- a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/labels/management/SoftWrappingLabelManager.java +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/labels/management/SoftWrappingLabelManager.java @@ -37,17 +37,13 @@ */ public class SoftWrappingLabelManager extends AbstractKlighdLabelManager { - /** Amount of line overhang that is permitted in percent of the effevtiveTargetWidth - * - * */ - /** - * Returns the amount of line overhang that is permitted in percent of the effevtiveTargetWidth. - * @param label The ElkLabel for which the fuzzyness is requested. - * @return The fuzzyness + * Returns the amount of line overhang that is permitted in percent of the effectiveTargetWidth. + * @param label The ElkLabel for which the fuzziness is requested. + * @return The fuzziness */ - public double getFuzzyness(final ElkLabel label) { - return label.getProperty(KlighdProperties.SOFTWRAPPING_FUZZYNESS); + public double getFuzziness(final ElkLabel label) { + return label.getProperty(KlighdProperties.SOFTWRAPPING_FUZZINESS); } @Override @@ -84,24 +80,26 @@ public Result doResizeLabel(final ElkLabel label, final double targetWidth) { } while (lineWidth < effectiveTargetWidth && currWordIndex < words.length); // Check whether next line would be below the fuzzy threshold - int previewWordIndex = currWordIndex; - if (previewWordIndex < words.length) { - String previewLineText = words[previewWordIndex]; - testText = previewLineText; - do { - previewLineText = testText; - if (previewWordIndex < words.length - 1) { - testText = previewLineText + " " + words[++previewWordIndex]; - } else { - testText = " "; - previewWordIndex++; + if (getFuzziness(label) > 0) { + int previewWordIndex = currWordIndex; + if (previewWordIndex < words.length) { + String previewLineText = words[previewWordIndex]; + testText = previewLineText; + do { + previewLineText = testText; + if (previewWordIndex < words.length - 1) { + testText = previewLineText + " " + words[++previewWordIndex]; + } else { + testText = " "; + previewWordIndex++; + } + lineWidth = PlacementUtil.estimateTextSize(font, testText).getWidth(); + } while (lineWidth < effectiveTargetWidth && previewWordIndex < words.length); + if (lineWidth < effectiveTargetWidth * getFuzziness(label)) { + // next line would contain too much whitespace so append it to this line + currWordIndex = previewWordIndex; + currentLineText += " " + previewLineText; } - lineWidth = PlacementUtil.estimateTextSize(font, testText).getWidth(); - } while (lineWidth < effectiveTargetWidth && previewWordIndex < words.length); - if (lineWidth < effectiveTargetWidth * getFuzzyness(label)) { - // next line would contain too much whitespace so append it to this line - currWordIndex = previewWordIndex; - currentLineText += " " + previewLineText; } } diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/util/KlighdProperties.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/util/KlighdProperties.java index c239105dd..8b5509506 100644 --- a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/util/KlighdProperties.java +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/util/KlighdProperties.java @@ -429,11 +429,11 @@ public static boolean isSelectable(final EObject viewElement) { new Property("klighd.roundedRectangle.autopadding", null); /** - * Determines the amount of fuzzyness to be used when performing softwrapping on labels. + * Determines the amount of fuzziness to be used when performing softwrapping on labels. * The value expresses the percent of overhang that is permitted for each line. * If the next line would take up less space than this threshold, it is appended to the * current line instead of being placed in a new line. */ - public static final IProperty SOFTWRAPPING_FUZZYNESS = + public static final IProperty SOFTWRAPPING_FUZZINESS = new Property("klighd.softwrapping.fuzzyness",0.0); }