Function: pdf-util-translate

pdf-util-translate is a natively compiled function defined in pdf-util.el.

Signature

(pdf-util-translate LIST-OF-EDGES-OR-POS OFFSET &optional OPPOSITE-DIRECTION-P)

Documentation

Translate LIST-OF-EDGES-OR-POS by OFFSET

OFFSET should be a cons (X . Y), by which to translate LIST-OF-EDGES-OR-POS. If OPPOSITE-DIRECTION-P is non-nil translate by (-X . -Y).

See pdf-util-scale for the LIST-OF-EDGES-OR-POS argument.

Source Code

;; Defined in /nix/store/63h5z2vmzn0mfavcxi2idi23g5xcgkbl-emacs-packages-deps/share/emacs/site-lisp/elpa/pdf-tools-20260102.1101/pdf-util.el
(defun pdf-util-translate (list-of-edges-or-pos
                           offset &optional opposite-direction-p)
  "Translate LIST-OF-EDGES-OR-POS by OFFSET

OFFSET should be a cons \(X . Y\), by which to translate
LIST-OF-EDGES-OR-POS.  If OPPOSITE-DIRECTION-P is non-nil
translate by \(-X . -Y\).

See `pdf-util-scale' for the LIST-OF-EDGES-OR-POS argument."

  (let ((have-list-p (listp (car list-of-edges-or-pos))))
    (unless have-list-p
      (setq list-of-edges-or-pos (list list-of-edges-or-pos)))
    (let* ((ox (if opposite-direction-p
                   (- (car offset))
                 (car offset)))
           (oy (if opposite-direction-p
                   (- (cdr offset))
                 (cdr offset)))
           (result
            (mapcar
             (lambda (edges)
               (cond
                ((consp (cdr edges))
                 (list (+ (nth 0 edges) ox)
                       (+ (nth 1 edges) oy)
                       (+ (nth 2 edges) ox)
                       (+ (nth 3 edges) oy)))
                (t
                 (cons (+ (car edges) ox)
                       (+ (cdr edges) oy)))))
             list-of-edges-or-pos)))
      (if have-list-p
          result
        (car result)))))