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

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

[nongnu] elpa/pdf-tools 97cffdd1b2 6/8: Allow creation of markup annotat


From: ELPA Syncer
Subject: [nongnu] elpa/pdf-tools 97cffdd1b2 6/8: Allow creation of markup annotations without a text selection
Date: Sat, 10 Jun 2023 16:02:07 -0400 (EDT)

branch: elpa/pdf-tools
commit 97cffdd1b214d0c6e904630468550802d20f4601
Author: Augusto Stoffel <arstoffel@gmail.com>
Commit: Vedang Manerikar <ved.manerikar@gmail.com>

    Allow creation of markup annotations without a text selection
    
    This allows calling `pdf-info-addannot` from Lisp with a nil
    `markup-edges` argument, which was previously disallowed.
    
    In this case, the annotation covers exactly the selected region of the
    page, without attempting to match it to a certain text region.
    
    This means that you can now highlight an exact region! Just select the
    region by holding down the Meta key and dragging the mouse. Then
    invoke `pdf-annot-add-highlight-markup-annotation` (with `C-c C-a h`)
    and voila!
    
    Closes: #191
---
 lisp/pdf-annot.el |  7 +++++--
 server/epdfinfo.c | 15 +++++++++++++++
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/lisp/pdf-annot.el b/lisp/pdf-annot.el
index e0f2ae9ae3..078f132cad 100644
--- a/lisp/pdf-annot.el
+++ b/lisp/pdf-annot.el
@@ -1053,9 +1053,12 @@ Return the new annotation."
              (> (length edges) 1))
     (error "Edges argument should be a single edge-list for text annotations"))
   (let* ((selection-style pdf-view-selection-style)
+         (non-markup (pcase type
+                       ('text t)
+                       ('highlight pdf-view--have-rectangle-region)))
          (a (apply #'pdf-info-addannot
                    page
-                   (if (eq type 'text)
+                   (if non-markup
                        (car edges)
                      (apply #'pdf-util-edges-union
                             (apply #'append
@@ -1066,7 +1069,7 @@ Return the new annotation."
                    type
                    selection-style
                    nil
-                   (if (not (eq type 'text)) edges)))
+                   (unless non-markup edges)))
          (id (pdf-annot-get-id a)))
     (when property-alist
       (condition-case err
diff --git a/server/epdfinfo.c b/server/epdfinfo.c
index 6d3e14efd5..b3925d0ef7 100644
--- a/server/epdfinfo.c
+++ b/server/epdfinfo.c
@@ -1635,6 +1635,21 @@ annotation_new (const epdfinfo_t *ctx, document_t *doc, 
PopplerPage *page,
 #ifdef HAVE_POPPLER_ANNOT_MARKUP
   garray = g_array_new (FALSE, FALSE, sizeof (PopplerQuadrilateral));
   poppler_page_get_size (page, &width, &height);
+  if (nargs == 0)
+    {
+      PopplerQuadrilateral q;
+
+      q.p1.x = r->x1;
+      q.p1.y = r->y1;
+      q.p2.x = r->x2;
+      q.p2.y = r->y1;
+      q.p4.x = r->x2;
+      q.p4.y = r->y2;
+      q.p3.x = r->x1;
+      q.p3.y = r->y2;
+
+      g_array_append_val (garray, q);
+    }
   for (i = 0; i < nargs; ++i)
     {
       PopplerRectangle *rr = &carg.value.rectangle;



reply via email to

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