From 159a1d5612b803ca1d8b1f5d7498d5e84a58c284 Mon Sep 17 00:00:00 2001 From: Martynas Bagdonas Date: Sun, 1 Oct 2023 22:09:06 +0100 Subject: [PATCH] Round char rotation to the closest standard angle --- src/core/evaluator.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 7154c4c820da6..88115370e67ab 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -2874,6 +2874,22 @@ class PartialEvaluator { } textChunk.str.push(glyphUnicode); + function closestStandardAngle(degrees) { + const standardAngles = [0, 90, 180, 270]; + let closestAngle = standardAngles[0]; + let minDifference = Math.abs(degrees - closestAngle); + + for (let i = 1; i < standardAngles.length; i++) { + const difference = Math.abs(degrees - standardAngles[i]); + if (difference < minDifference) { + minDifference = difference; + closestAngle = standardAngles[i]; + } + } + + return closestAngle; + } + function matrixToDegrees(matrix) { let radians = Math.atan2(matrix[1], matrix[0]); if (radians < 0) { @@ -2884,6 +2900,7 @@ class PartialEvaluator { if (degrees < 0) { degrees += 360; } + degrees = closestStandardAngle(degrees); return degrees; }