emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/pdf-tools 2037c52f12 2/2: Add a dedicated rotation command


From: ELPA Syncer
Subject: [nongnu] elpa/pdf-tools 2037c52f12 2/2: Add a dedicated rotation command and keybinding
Date: Mon, 16 Jan 2023 22:59:47 -0500 (EST)

branch: elpa/pdf-tools
commit 2037c52f127f3971e8f8bcd1a8874bcaa4c8f5ba
Author: Visuwesh <visuweshm@gmail.com>
Commit: Vedang Manerikar <ved.manerikar@gmail.com>

    Add a dedicated rotation command and keybinding
    
    We need a dedicated command for rotation since when `pdf-tools`
    redisplays the image, the `:rotation` image-property is lost.
    Pdf-tools redisplays the images when changing pages, zooming in/out,
    setting the slice, etc. so this is essential to have.
    
    A variable is used simply because `pdf-tools` already uses a variable to
    keep track of the current scaling.
    
    * lisp/pdf-view.el (pdf-view--current-rotation): Add new variable to
    keep track of angle.
    (pdf-view-create-page): Account for above.
    (pdf-view-mode-map): Add the new command under "R".
    (pdf-view-rotate): Add new command.
    
    Fixes: #152
    Closes: #165
---
 NEWS             |  3 +++
 README.org       |  2 ++
 lisp/pdf-view.el | 21 +++++++++++++++++++++
 3 files changed, 26 insertions(+)

diff --git a/NEWS b/NEWS
index a4bec6d4d8..5abb81569b 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,9 @@
   + This feature enabled us to change the default ~selection-style~ used in 
~pdf-tools~ from =GLYPH= to =WORD=.
   + The change makes highlighting / selecting text *much* snappier. If you 
want to go back to the old behaviour of selecting by glyph instead of word, or 
if you want to select a whole line instead, customize ~pdf-view-selection-style~
 
+- Track rotation of pages and add a command to make rotation of pages easy 
@vizs #165
+  + The new command is bound to =R= in `pdf-view-mode-map`.
+
 ** Functionality fixes and improvements
 - Fix: Saving a PDF when ~buffer-file-name~ is missing will now prompt for a 
filename (eg: in EWW) @akater #178
 
diff --git a/README.org b/README.org
index c4306b9bd8..961a75a45c 100644
--- a/README.org
+++ b/README.org
@@ -288,6 +288,8 @@ Note that ~pdf-tools~ renders the PDF as images inside 
Emacs. This means that al
 | Trim Margins (set slice to bounding box) | ~s b~           |
 | Reset Margins                            | ~s r~           |
 | Reset Zoom                               | ~0~             |
+| Rotate Page                              | ~R~             |
+|------------------------------------------+-----------------|
 
 ** Annotations
 :PROPERTIES:
diff --git a/lisp/pdf-view.el b/lisp/pdf-view.el
index 454effa283..afca46f54e 100644
--- a/lisp/pdf-view.el
+++ b/lisp/pdf-view.el
@@ -226,6 +226,9 @@ regarding display of the region in the later function.")
 (defvar-local pdf-view--hotspot-functions nil
   "Alist of hotspot functions.")
 
+(defvar-local pdf-view--current-rotation nil
+  "Current rotation of the page.")
+
 (defvar-local pdf-view-register-alist nil
   "Local, dedicated register for PDF positions.")
 
@@ -290,6 +293,8 @@ regarding display of the region in the later function.")
     (define-key map (kbd "s m")       'pdf-view-set-slice-using-mouse)
     (define-key map (kbd "s b")       'pdf-view-set-slice-from-bounding-box)
     (define-key map (kbd "s r")       'pdf-view-reset-slice)
+    ;; Rotation.
+    (define-key map (kbd "R")              #'pdf-view-rotate)
     ;; Reconvert
     (define-key map (kbd "C-c C-c")   'doc-view-mode)
     (define-key map (kbd "g")         'revert-buffer)
@@ -586,6 +591,21 @@ For example, (pdf-view-shrink 1.25) decreases size by 20%."
   (setq pdf-view-display-size 1.0)
   (pdf-view-redisplay t))
 
+
+;; * ================================================================== *
+;; * Rotation
+;; * ================================================================== *
+(defun pdf-view-rotate (angle)
+  "Rotate the current page by ANGLE degrees clockwise.
+When called interactively, angle defaults to 90.  Moreover, if
+called interactively with a prefix argument, then rotate
+anti-clockwise."
+  (interactive (list (if current-prefix-arg -90 90)))
+  (setq-local pdf-view--current-rotation
+              (mod (+ (or pdf-view--current-rotation 0)
+                      angle)
+                   360))
+  (pdf-view-redisplay t))
 
 
 ;; * ================================================================== *
@@ -974,6 +994,7 @@ See also `pdf-view-use-imagemagick'."
                     window page size)))
     (pdf-view-create-image data
       :width (car size)
+      :rotation (or pdf-view--current-rotation 0)
       :map hotspots
       :pointer 'arrow)))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]