@@ -257,6 +257,17 @@ public static Rectangle scaleDown(Rectangle rect, int zoom) {
257
257
scaledRect .y = scaledTopLeft .y ;
258
258
scaledRect .width = scaledBottomRight .x - scaledTopLeft .x ;
259
259
scaledRect .height = scaledBottomRight .y - scaledTopLeft .y ;
260
+
261
+ int scaledDownWidth = DPIUtil .scaleDown (rect .width , zoom );
262
+ int scaledDownHeight = DPIUtil .scaleDown (rect .height , zoom );
263
+
264
+ // It must be ensured, that a scaled down width or height
265
+ // based on Rectangle x or y is not bigger than directly
266
+ // scaling down the width or height. Therefore the min
267
+ // value is used
268
+ scaledRect .width = Math .min (scaledRect .width , scaledDownWidth );
269
+ scaledRect .height = Math .min (scaledRect .height , scaledDownHeight );
270
+
260
271
return scaledRect ;
261
272
}
262
273
/**
@@ -464,6 +475,16 @@ public static Rectangle scaleUp(Rectangle rect, int zoom) {
464
475
scaledRect .y = scaledTopLeft .y ;
465
476
scaledRect .width = scaledBottomRight .x - scaledTopLeft .x ;
466
477
scaledRect .height = scaledBottomRight .y - scaledTopLeft .y ;
478
+
479
+ int scaledUpWidth = DPIUtil .scaleUp (rect .width , zoom );
480
+ int scaledUpHeight = DPIUtil .scaleUp (rect .height , zoom );
481
+
482
+ // It must be ensured, that a scaled up width or height
483
+ // based on Rectangle x or y is not smaller that directly
484
+ // scaling up the width or height. Therefore the max
485
+ // value is used
486
+ scaledRect .width = Math .max (scaledRect .width , scaledUpWidth );
487
+ scaledRect .height = Math .max (scaledRect .height , scaledUpHeight );
467
488
return scaledRect ;
468
489
}
469
490
0 commit comments