Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fuzziness to softwrapping label manager. #218

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,6 @@ public Boolean caseElkLabel(final ElkLabel layoutLabel) {
private void shapeLayoutToLayoutGraph(
final KShapeLayout sourceShapeLayout, final ElkShape targetShape) {

// Attention: Layout options are transfered by the {@link KGraphPropertyLayoutConfig}
targetShape.setLocation(sourceShapeLayout.getXpos(), sourceShapeLayout.getYpos());
targetShape.setDimensions(sourceShapeLayout.getWidth(), sourceShapeLayout.getHeight());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package de.cau.cs.kieler.klighd.labels.management;

import org.eclipse.elk.core.options.CoreOptions;
import org.eclipse.elk.graph.ElkLabel;
import org.eclipse.swt.graphics.FontData;

Expand All @@ -36,6 +37,15 @@
*/
public class SoftWrappingLabelManager extends AbstractKlighdLabelManager {

/**
* 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 getFuzziness(final ElkLabel label) {
return label.getProperty(CoreOptions.SOFTWRAPPING_FUZZINESS);
}

@Override
public Result doResizeLabel(final ElkLabel label, final double targetWidth) {
final FontData font = LabelManagementUtil.fontDataFor(label);
Expand Down Expand Up @@ -69,6 +79,31 @@ public Result doResizeLabel(final ElkLabel label, final double targetWidth) {
lineWidth = PlacementUtil.estimateTextSize(font, testText).getWidth();
} while (lineWidth < effectiveTargetWidth && currWordIndex < words.length);

// Check whether next line would be below the fuzzy threshold
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);
lineWidth = PlacementUtil.estimateTextSize(font, previewLineText).getWidth();
if (lineWidth < effectiveTargetWidth * getFuzziness(label)) {
// next line would contain too much whitespace so append it to this line
currWordIndex = previewWordIndex;
currentLineText += " " + previewLineText;
}
}
}

// No more words fit so the line is added to the result
if (currWordIndex < words.length) {
resultText.append(currentLineText).append("\n");
Expand Down
Loading