Skip to content

Commit 30fd8ef

Browse files
committed
WIP
1 parent 3d93396 commit 30fd8ef

File tree

7 files changed

+93
-11
lines changed

7 files changed

+93
-11
lines changed

bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3886,6 +3886,31 @@ public int getLinePixel(int lineIndex) {
38863886
}
38873887
return height + topMargin;
38883888
}
3889+
3890+
public float getLinePixelFloat(int lineIndex) {
3891+
checkWidget();
3892+
int zoom = DPIUtil.getZoomForAutoscaleProperty(nativeZoom);
3893+
int lineCount = content.getLineCount();
3894+
lineIndex = Math.max(0, Math.min(lineCount, lineIndex));
3895+
if (isFixedLineHeight()) {
3896+
int lineHeight = renderer.getLineHeight();
3897+
float lh = DPIUtil.scaleDown((float) DPIUtil.scaleUp(lineHeight, zoom), zoom);
3898+
return lineIndex * lh - getVerticalScrollOffset() + topMargin;
3899+
}
3900+
if (lineIndex == topIndex)
3901+
return topIndexY + topMargin;
3902+
int height = topIndexY;
3903+
if (lineIndex > topIndex) {
3904+
for (int i = topIndex; i < lineIndex; i++) {
3905+
height += DPIUtil.scaleDown((float) DPIUtil.scaleUp(renderer.getLineHeight(i), zoom), zoom);
3906+
}
3907+
} else {
3908+
for (int i = topIndex - 1; i >= lineIndex; i--) {
3909+
height -= DPIUtil.scaleDown((float) DPIUtil.scaleUp(renderer.getLineHeight(i), zoom), zoom);
3910+
}
3911+
}
3912+
return height + topMargin;
3913+
}
38893914
/**
38903915
* Returns the line index for a y, relative to the client area.
38913916
* The line index returned is always in the range 0..lineCount - 1.

bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextRenderer.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public LineInfo(LineInfo info) {
184184
}
185185
}
186186

187-
private record LineDrawInfo(int index, TextLayout layout, String text, int offset, int height) {
187+
private record LineDrawInfo(int index, TextLayout layout, String text, int offset, float height) {
188188

189189
}
190190

@@ -466,7 +466,7 @@ private LineDrawInfo makeLineDrawInfo(int lineIndex) {
466466
TextLayout layout = getTextLayout(lineIndex);
467467
String text = content.getLine(lineIndex);
468468
int offset = content.getOffsetAtLine(lineIndex);
469-
int height = layout.getBounds().height;
469+
float height = layout.getBounds().getHeight();
470470
return new LineDrawInfo(lineIndex, layout, text, offset, height);
471471
}
472472

@@ -483,6 +483,11 @@ int drawLines(int startLine, int endLine, int begX, int begY, int endY, GC gc, C
483483
// still, I'd rather stay safe.
484484
final boolean drawBackBeforeFore = (fixedLineMetrics != null);
485485

486+
487+
// Rectangle bounds = styledText.getClientArea();
488+
// gc.setBackground(widgetBackground);
489+
// styledText.drawBackground(gc, bounds.x, bounds.y, bounds.width, bounds.height);
490+
486491
if (drawBackBeforeFore) {
487492
// Cache drawing information
488493
final List<LineDrawInfo> drawInfos = new ArrayList<>();
@@ -515,18 +520,18 @@ int drawLines(int startLine, int endLine, int begX, int begY, int endY, GC gc, C
515520
return y - begY;
516521
}
517522

518-
int y = begY;
523+
float y = begY;
519524
for (int iLine = startLine; y < endY && iLine < endLine; iLine++) {
520525
LineDrawInfo lineInfo = makeLineDrawInfo(iLine);
521526
drawLineBackground(lineInfo, y, gc, widgetBackground);
522-
drawLineForeground(lineInfo, begX, y, gc, widgetForeground);
527+
drawLineForeground(lineInfo, begX, (int) y, gc, widgetForeground);
523528
disposeTextLayout(lineInfo.layout);
524-
y += lineInfo.height;
529+
y += lineInfo.height; // Culprit
525530
}
526-
return y - begY;
531+
return (int) y - begY;
527532
}
528533

529-
private void drawLineBackground(LineDrawInfo lineInfo, int paintY, GC gc, Color widgetBackground) {
534+
private void drawLineBackground(LineDrawInfo lineInfo, float paintY, GC gc, Color widgetBackground) {
530535
Rectangle client = styledText.getClientArea();
531536
Color lineBackground = getLineBackground(lineInfo.index, null);
532537
StyledTextEvent event = styledText.getLineBackgroundData(lineInfo.offset, lineInfo.text);
@@ -536,13 +541,13 @@ private void drawLineBackground(LineDrawInfo lineInfo, int paintY, GC gc, Color
536541
if (lineBackground != null) {
537542
if (verticalIndent > 0) {
538543
gc.setBackground(widgetBackground);
539-
gc.fillRectangle(client.x, paintY, client.width, verticalIndent);
544+
gc.fillRectangle(new Rectangle.OfFloat(client.x, paintY, client.width, verticalIndent));
540545
}
541546
gc.setBackground(lineBackground);
542-
gc.fillRectangle(client.x, paintY + verticalIndent, client.width, lineInfo.height - verticalIndent);
547+
gc.fillRectangle(new Rectangle.OfFloat(client.x, paintY + verticalIndent, client.width, lineInfo.height - verticalIndent));
543548
} else {
544549
gc.setBackground(widgetBackground);
545-
styledText.drawBackground(gc, client.x, paintY, client.width, lineInfo.height);
550+
styledText.drawBackground(gc, new Rectangle.OfFloat(client.x, paintY, client.width, lineInfo.height));
546551
}
547552
}
548553

bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Point.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ public Point (int x, int y) {
6969
this.y = y;
7070
}
7171

72+
public float getX() {
73+
return x;
74+
}
75+
76+
public float getY() {
77+
return y;
78+
}
79+
80+
81+
7282
/**
7383
* Compares the argument to the receiver, and returns true
7484
* if they represent the <em>same</em> object using a class
@@ -142,10 +152,12 @@ public OfFloat(float x, float y) {
142152
this.residualY = y - this.y;
143153
}
144154

155+
@Override
145156
public float getX() {
146157
return x + residualX;
147158
}
148159

160+
@Override
149161
public float getY() {
150162
return y + residualY;
151163
}

bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Rectangle.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,28 @@ public Rectangle (int x, int y, int width, int height) {
8787
this.height = height;
8888
}
8989

90+
91+
92+
public float getX() {
93+
return x;
94+
}
95+
96+
97+
public float getY() {
98+
return y;
99+
}
100+
101+
102+
public float getWidth() {
103+
return width;
104+
}
105+
106+
107+
public float getHeight() {
108+
return height;
109+
}
110+
111+
90112
/**
91113
* Destructively replaces the x, y, width and height values
92114
* in the receiver with ones which represent the union of the
@@ -424,18 +446,22 @@ public OfFloat(float x, float y, float width, float height) {
424446
this.residualHeight = height - this.height;
425447
}
426448

449+
@Override
427450
public float getX() {
428451
return x + residualX;
429452
}
430453

454+
@Override
431455
public float getY() {
432456
return y + residualY;
433457
}
434458

459+
@Override
435460
public float getWidth() {
436461
return width + residualWidth;
437462
}
438463

464+
@Override
439465
public float getHeight() {
440466
return height + residualHeight;
441467
}

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2405,6 +2405,13 @@ public void drawString (String string, int x, int y, boolean isTransparent) {
24052405
storeAndApplyOperationForExistingHandle(new DrawStringOperation(string, new Point(x, y), isTransparent));
24062406
}
24072407

2408+
public void drawString (String string, Point.OfFloat point, boolean isTransparent) {
2409+
checkNonDisposed();
2410+
if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
2411+
if (string.isEmpty()) return;
2412+
storeAndApplyOperationForExistingHandle(new DrawStringOperation(string, point, isTransparent));
2413+
}
2414+
24082415
private class DrawStringOperation extends Operation {
24092416
private final String string;
24102417
private final Point location;

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/TextLayout.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1799,7 +1799,8 @@ public Rectangle getBounds () {
17991799
width = Math.max(width, DPIUtil.scaleDown(lineWidthInPixels[line], getZoom()) + getLineIndent(line));
18001800
}
18011801
}
1802-
return new Rectangle (0, 0, width, lineY[lineY.length - 1] + getVerticalIndent());
1802+
float height = DPIUtil.scaleDown((float) Math.round(DPIUtil.scaleUp(lineY[lineY.length - 1] + getVerticalIndent(), getZoom())), getZoom());
1803+
return new Rectangle.OfFloat (0, 0, width, height);
18031804
}
18041805

18051806
/**

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Canvas.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ public void drawBackground (GC gc, int x, int y, int width, int height) {
108108
drawBackgroundInPixels(gc, rectangle.x, rectangle.y, rectangle.width, rectangle.height, 0, 0);
109109
}
110110

111+
public void drawBackground (GC gc, Rectangle rectangle) {
112+
int zoom = getZoom();
113+
Rectangle scaledRectangle = DPIUtil.scaleUp(rectangle, zoom);
114+
drawBackgroundInPixels(gc, scaledRectangle.x, scaledRectangle.y, scaledRectangle.width, scaledRectangle.height, 0, 0);
115+
}
116+
111117
/**
112118
* Returns the caret.
113119
* <p>

0 commit comments

Comments
 (0)