mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2025-09-12 17:52:13 +02:00
minor fix: fixed rotation to be exactly 0 when user chooses: set roation to none, in advanced: rotate 0 and variance 0
This commit is contained in:
parent
e2d01f0fea
commit
283fec6ea3
@ -168,13 +168,22 @@ public class FakeScanController {
|
||||
if (baseRotation != 0 || rotateVariance != 0) {
|
||||
pageRotation += (RANDOM.nextDouble() * 2 - 1) * rotateVariance;
|
||||
}
|
||||
|
||||
BufferedImage rotated;
|
||||
int w = composed.getWidth();
|
||||
int h = composed.getHeight();
|
||||
int rotW = w;
|
||||
int rotH = h;
|
||||
|
||||
// Skip rotation entirely if no rotation is needed
|
||||
if (pageRotation == 0) {
|
||||
rotated = composed;
|
||||
} else {
|
||||
double radians = Math.toRadians(pageRotation);
|
||||
double sin = Math.abs(Math.sin(radians));
|
||||
double cos = Math.abs(Math.cos(radians));
|
||||
int w = composed.getWidth();
|
||||
int h = composed.getHeight();
|
||||
int rotW = (int) Math.floor(w * cos + h * sin);
|
||||
int rotH = (int) Math.floor(h * cos + w * sin);
|
||||
rotW = (int) Math.floor(w * cos + h * sin);
|
||||
rotH = (int) Math.floor(h * cos + w * sin);
|
||||
BufferedImage rotatedBg = new BufferedImage(rotW, rotH, composed.getType());
|
||||
Graphics2D gBgRot = rotatedBg.createGraphics();
|
||||
for (int y = 0; y < rotH; y++) {
|
||||
@ -183,7 +192,8 @@ public class FakeScanController {
|
||||
int r =
|
||||
Math.round(
|
||||
startColor.getRed()
|
||||
+ (endColor.getRed() - startColor.getRed()) * frac);
|
||||
+ (endColor.getRed() - startColor.getRed())
|
||||
* frac);
|
||||
int g =
|
||||
Math.round(
|
||||
startColor.getGreen()
|
||||
@ -198,7 +208,7 @@ public class FakeScanController {
|
||||
}
|
||||
}
|
||||
gBgRot.dispose();
|
||||
BufferedImage rotated = new BufferedImage(rotW, rotH, composed.getType());
|
||||
rotated = new BufferedImage(rotW, rotH, composed.getType());
|
||||
Graphics2D g2d = rotated.createGraphics();
|
||||
g2d.drawImage(rotatedBg, 0, 0, null);
|
||||
AffineTransform at = new AffineTransform();
|
||||
@ -213,6 +223,7 @@ public class FakeScanController {
|
||||
RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g2d.drawImage(composed, at, null);
|
||||
g2d.dispose();
|
||||
}
|
||||
|
||||
// 4. Scale and center the rotated image to cover the original page size
|
||||
PDRectangle origPageSize = document.getPage(i).getMediaBox();
|
||||
|
@ -85,6 +85,7 @@ public class FakeScanRequest {
|
||||
|
||||
public int getRotationValue() {
|
||||
return switch (rotation.toLowerCase()) {
|
||||
case "none" -> 0;
|
||||
case "slight" -> 2;
|
||||
case "moderate" -> 5;
|
||||
case "severe" -> 8;
|
||||
|
Loading…
Reference in New Issue
Block a user