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) {
|
if (baseRotation != 0 || rotateVariance != 0) {
|
||||||
pageRotation += (RANDOM.nextDouble() * 2 - 1) * rotateVariance;
|
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 radians = Math.toRadians(pageRotation);
|
||||||
double sin = Math.abs(Math.sin(radians));
|
double sin = Math.abs(Math.sin(radians));
|
||||||
double cos = Math.abs(Math.cos(radians));
|
double cos = Math.abs(Math.cos(radians));
|
||||||
int w = composed.getWidth();
|
rotW = (int) Math.floor(w * cos + h * sin);
|
||||||
int h = composed.getHeight();
|
rotH = (int) Math.floor(h * cos + w * sin);
|
||||||
int rotW = (int) Math.floor(w * cos + h * sin);
|
|
||||||
int rotH = (int) Math.floor(h * cos + w * sin);
|
|
||||||
BufferedImage rotatedBg = new BufferedImage(rotW, rotH, composed.getType());
|
BufferedImage rotatedBg = new BufferedImage(rotW, rotH, composed.getType());
|
||||||
Graphics2D gBgRot = rotatedBg.createGraphics();
|
Graphics2D gBgRot = rotatedBg.createGraphics();
|
||||||
for (int y = 0; y < rotH; y++) {
|
for (int y = 0; y < rotH; y++) {
|
||||||
@ -183,7 +192,8 @@ public class FakeScanController {
|
|||||||
int r =
|
int r =
|
||||||
Math.round(
|
Math.round(
|
||||||
startColor.getRed()
|
startColor.getRed()
|
||||||
+ (endColor.getRed() - startColor.getRed()) * frac);
|
+ (endColor.getRed() - startColor.getRed())
|
||||||
|
* frac);
|
||||||
int g =
|
int g =
|
||||||
Math.round(
|
Math.round(
|
||||||
startColor.getGreen()
|
startColor.getGreen()
|
||||||
@ -198,7 +208,7 @@ public class FakeScanController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
gBgRot.dispose();
|
gBgRot.dispose();
|
||||||
BufferedImage rotated = new BufferedImage(rotW, rotH, composed.getType());
|
rotated = new BufferedImage(rotW, rotH, composed.getType());
|
||||||
Graphics2D g2d = rotated.createGraphics();
|
Graphics2D g2d = rotated.createGraphics();
|
||||||
g2d.drawImage(rotatedBg, 0, 0, null);
|
g2d.drawImage(rotatedBg, 0, 0, null);
|
||||||
AffineTransform at = new AffineTransform();
|
AffineTransform at = new AffineTransform();
|
||||||
@ -213,6 +223,7 @@ public class FakeScanController {
|
|||||||
RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
g2d.drawImage(composed, at, null);
|
g2d.drawImage(composed, at, null);
|
||||||
g2d.dispose();
|
g2d.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
// 4. Scale and center the rotated image to cover the original page size
|
// 4. Scale and center the rotated image to cover the original page size
|
||||||
PDRectangle origPageSize = document.getPage(i).getMediaBox();
|
PDRectangle origPageSize = document.getPage(i).getMediaBox();
|
||||||
|
@ -85,6 +85,7 @@ public class FakeScanRequest {
|
|||||||
|
|
||||||
public int getRotationValue() {
|
public int getRotationValue() {
|
||||||
return switch (rotation.toLowerCase()) {
|
return switch (rotation.toLowerCase()) {
|
||||||
|
case "none" -> 0;
|
||||||
case "slight" -> 2;
|
case "slight" -> 2;
|
||||||
case "moderate" -> 5;
|
case "moderate" -> 5;
|
||||||
case "severe" -> 8;
|
case "severe" -> 8;
|
||||||
|
Loading…
Reference in New Issue
Block a user