MCPcopy Index your code
hub / github.com/OpenSignLabs/OpenSign / compensateRotation

Function compensateRotation

apps/OpenSign/src/constant/Utils.js:3213–3281  ·  view source on GitHub ↗
(
  pageRotation,
  x,
  y,
  scale,
  dimensions,
  fontSize,
  updateColorInRgb,
  font,
  page
)

Source from the content-addressed store, hash-verified

3211}
3212// `compensateRotation` is used to calculate x and y position of widget on portait, landscape pdf for pdf-lib
3213function compensateRotation(
3214 pageRotation,
3215 x,
3216 y,
3217 scale,
3218 dimensions,
3219 fontSize,
3220 updateColorInRgb,
3221 font,
3222 page
3223) {
3224 // Ensure pageRotation is between 0 and 360 degrees
3225 pageRotation = ((pageRotation % 360) + 360) % 360;
3226 let rotationRads = (pageRotation * Math.PI) / 180;
3227
3228 // Coordinates are from bottom-left
3229 let coordsFromBottomLeft = { x: x / scale };
3230 if (pageRotation === 90 || pageRotation === 270) {
3231 coordsFromBottomLeft.y = dimensions.width - (y + fontSize) / scale;
3232 } else {
3233 coordsFromBottomLeft.y = dimensions.height - (y + fontSize) / scale;
3234 }
3235
3236 let drawX = null;
3237 let drawY = null;
3238
3239 if (pageRotation === 90) {
3240 drawX =
3241 coordsFromBottomLeft.x * Math.cos(rotationRads) -
3242 coordsFromBottomLeft.y * Math.sin(rotationRads) +
3243 dimensions.width;
3244 drawY =
3245 coordsFromBottomLeft.x * Math.sin(rotationRads) +
3246 coordsFromBottomLeft.y * Math.cos(rotationRads);
3247 } else if (pageRotation === 180) {
3248 drawX =
3249 coordsFromBottomLeft.x * Math.cos(rotationRads) -
3250 coordsFromBottomLeft.y * Math.sin(rotationRads) +
3251 dimensions.width;
3252 drawY =
3253 coordsFromBottomLeft.x * Math.sin(rotationRads) +
3254 coordsFromBottomLeft.y * Math.cos(rotationRads) +
3255 dimensions.height;
3256 } else if (pageRotation === 270) {
3257 drawX =
3258 coordsFromBottomLeft.x * Math.cos(rotationRads) -
3259 coordsFromBottomLeft.y * Math.sin(rotationRads);
3260 drawY =
3261 coordsFromBottomLeft.x * Math.sin(rotationRads) +
3262 coordsFromBottomLeft.y * Math.cos(rotationRads) +
3263 dimensions.height;
3264 } else if (pageRotation === 0 || pageRotation === 360) {
3265 // No rotation or full rotation
3266 drawX = coordsFromBottomLeft.x;
3267 drawY = coordsFromBottomLeft.y;
3268 }
3269 if (font) {
3270 return {

Callers 3

embedDocIdFunction · 0.85
embedWidgetsToDocFunction · 0.85
getWidgetPositionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected