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

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

[nongnu] elpa/pdf-tools 209bea6428 1/3: epdfinfo: Extract server code fo


From: ELPA Syncer
Subject: [nongnu] elpa/pdf-tools 209bea6428 1/3: epdfinfo: Extract server code for selection_style validation
Date: Mon, 16 Jan 2023 13:59:54 -0500 (EST)

branch: elpa/pdf-tools
commit 209bea642877de83b28703c59965fb8698ff33f5
Author: lennonhill <@>
Commit: Vedang Manerikar <ved.manerikar@gmail.com>

    epdfinfo: Extract server code for selection_style validation
---
 server/epdfinfo.c | 38 ++++++++++++++++++++++----------------
 1 file changed, 22 insertions(+), 16 deletions(-)

diff --git a/server/epdfinfo.c b/server/epdfinfo.c
index 5dabe7ee47..a5c1359e00 100644
--- a/server/epdfinfo.c
+++ b/server/epdfinfo.c
@@ -760,6 +760,26 @@ xpoppler_annot_text_state_string (PopplerAnnotTextState 
state)
     }
 };
 
+/**
+ * Validate a PopplerSelectionStyle by replacing invalid styles
+ * with a default of POPPLER_SELECTION_GLYPH.
+ *
+ * @param selection_style The selection style.
+ *
+ * @return selection_style for valid styles, otherwise POPPLER_SELECTION_GLYPH.
+ */
+static PopplerSelectionStyle
+xpoppler_validate_selection_style (int selection_style)
+{
+  switch (selection_style) {
+    case POPPLER_SELECTION_GLYPH:
+    case POPPLER_SELECTION_WORD:
+    case POPPLER_SELECTION_LINE:
+      return selection_style;
+  }
+  return POPPLER_SELECTION_GLYPH;
+}
+
 static document_t*
 document_open (const epdfinfo_t *ctx, const char *filename,
                const char *passwd, GError **gerror)
@@ -2319,14 +2339,7 @@ cmd_gettext(const epdfinfo_t *ctx, const command_arg_t 
*args)
   double width, height;
   gchar *text = NULL;
 
-  switch (selection_style)
-    {
-    case POPPLER_SELECTION_GLYPH: break;
-    case POPPLER_SELECTION_LINE: break;
-    case POPPLER_SELECTION_WORD: break;
-    default: selection_style = POPPLER_SELECTION_GLYPH;
-    }
-
+  selection_style = xpoppler_validate_selection_style(selection_style);
   page = poppler_document_get_page (doc, pn - 1);
   perror_if_not (page, "No such page %d", pn);
   poppler_page_get_size (page, &width, &height);
@@ -2384,14 +2397,7 @@ cmd_getselection (const epdfinfo_t *ctx, const 
command_arg_t *args)
   PopplerPage *page = NULL;
   int i;
 
-  switch (selection_style)
-    {
-    case POPPLER_SELECTION_GLYPH: break;
-    case POPPLER_SELECTION_LINE: break;
-    case POPPLER_SELECTION_WORD: break;
-    default: selection_style = POPPLER_SELECTION_GLYPH;
-    }
-
+  selection_style = xpoppler_validate_selection_style(selection_style);
   page = poppler_document_get_page (doc, pn - 1);
   perror_if_not (page, "No such page %d", pn);
   poppler_page_get_size (page, &width, &height);



reply via email to

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