Skip to content

Commit

Permalink
[win32] Fix TextLayout::getBounds vertical indent
Browse files Browse the repository at this point in the history
This commit fixes too high lines when vertical indent was set for one TextLayout. There was a usage of vertical indent in pixels where vertical indent in points should have been used.

Contributes to #62 and #127
  • Loading branch information
akoch-yatta authored and HeikoKlare committed Aug 6, 2024
1 parent 00cbedf commit 8296f26
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
*******************************************************************************/
package org.eclipse.swt.graphics;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

import org.eclipse.swt.internal.*;
import org.junit.jupiter.api.*;
Expand All @@ -38,7 +39,26 @@ public void testGetBoundPublicAPIshouldReturnTheSameValueRegardlessOfZoomLevel()
layout.draw(scaledGc, 10, 10);
Rectangle scaledBounds = layout.getBounds();

assertEquals("The public API for getBounds should give the same result for any zoom level", scaledBounds, unscaledBounds);
assertEquals(unscaledBounds, scaledBounds, "The public API for getBounds should give the same result for any zoom level");
}

@Test
public void testCalculateGetBoundsWithVerticalIndent() {
TextLayout layout = new TextLayout(display);
layout.setVerticalIndent(16);
layout.setText(text);
Rectangle unscaledBounds = layout.getBounds();

int scalingFactor = 2;
int newZoom = DPIUtil.getNativeDeviceZoom() * scalingFactor;
changeDPIZoom(newZoom);
TextLayout scaledLayout = new TextLayout(display);
scaledLayout.setVerticalIndent(16);
scaledLayout.setText(text);
Rectangle scaledBounds = scaledLayout.getBounds();

assertNotEquals(layout.nativeZoom, scaledLayout.nativeZoom, "The native zoom for the TextLayouts must differ");
assertEquals(unscaledBounds.height, scaledBounds.height, 1, "The public API for getBounds with vertical indent > 0 should give a similar result for any zoom level");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public void tearDownTest() {
}

protected void changeDPIZoom (int nativeZoom) {
DPIUtil.setDeviceZoom(nativeZoom);
float scalingFactor = 1f * DPIUtil.getZoomForAutoscaleProperty(nativeZoom) / DPIUtil.getZoomForAutoscaleProperty(shell.nativeZoom);
DPIZoomChangeRegistry.applyChange(shell, nativeZoom, scalingFactor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1792,7 +1792,7 @@ public Rectangle getBounds () {
width = Math.max(width, DPIUtil.scaleDown(lineWidthInPixels[line], getZoom()) + getLineIndent(line));
}
}
return new Rectangle (0, 0, width, lineY[lineY.length - 1] + getScaledVerticalIndent());
return new Rectangle (0, 0, width, lineY[lineY.length - 1] + getVerticalIndent());
}

/**
Expand Down

0 comments on commit 8296f26

Please sign in to comment.