gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis-gtk] branch master updated: printing skeleton logic (#7


From: gnunet
Subject: [taler-anastasis-gtk] branch master updated: printing skeleton logic (#7090)
Date: Thu, 30 Dec 2021 19:40:44 +0100

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository anastasis-gtk.

The following commit(s) were added to refs/heads/master by this push:
     new 697b929  printing skeleton logic (#7090)
697b929 is described below

commit 697b9292283b1db460e84eeec12e7e121f378a50
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Thu Dec 30 19:40:34 2021 +0100

    printing skeleton logic (#7090)
---
 src/anastasis/.gitignore                           |   1 +
 src/anastasis/Makefile.am                          |  19 ++-
 src/anastasis/anastasis-gtk.h                      |   4 +-
 .../anastasis-gtk_handle-challenge-code.c          |   2 -
 ...stasis-gtk_handle-main-window-forward-clicked.c |   5 +-
 src/anastasis/anastasis-gtk_handle-print.c         |  29 +++-
 src/anastasis/print.c                              | 158 +++++++++++++++++++++
 .../{anastasis-gtk_handle-print.c => print.h}      |  34 +++--
 .../{anastasis-gtk_handle-print.c => test-print.c} |  38 +++--
 9 files changed, 245 insertions(+), 45 deletions(-)

diff --git a/src/anastasis/.gitignore b/src/anastasis/.gitignore
index e4b8b25..18dd486 100644
--- a/src/anastasis/.gitignore
+++ b/src/anastasis/.gitignore
@@ -1 +1,2 @@
 anastasis-gtk
+test-print
diff --git a/src/anastasis/Makefile.am b/src/anastasis/Makefile.am
index 110682c..cf0bbcf 100644
--- a/src/anastasis/Makefile.am
+++ b/src/anastasis/Makefile.am
@@ -62,7 +62,8 @@ anastasis_gtk_SOURCES = \
 
 if HPDF_ENABLED
 anastasis_gtk_SOURCES += \
-  anastasis-gtk_handle-print.c
+  anastasis-gtk_handle-print.c \
+  print.c
 else
 anastasis_gtk_SOURCES += \
   anastasis-gtk_handle-noprint.c
@@ -97,3 +98,19 @@ anastasis_gtk_LDADD += \
 anastasis_gtk_CFLAGS += \
   $(HPDF_CFLAGS)
 endif
+
+
+if HPDF_ENABLED
+noinst_PROGRAMS = \
+  test-print
+
+test_print_SOURCES = \
+  test-print.c \
+  print.c
+test_print_LDADD = \
+  $(HPDF_LIBS) \
+  -lgnunetutil \
+  -ljansson
+test_print_CFLAGS = \
+  $(HPDF_CFLAGS)
+endif
diff --git a/src/anastasis/anastasis-gtk.h b/src/anastasis/anastasis-gtk.h
index 27d23f3..5151383 100644
--- a/src/anastasis/anastasis-gtk.h
+++ b/src/anastasis/anastasis-gtk.h
@@ -19,8 +19,8 @@
 */
 
 /**
- * @file src/include/anastasis-gtk_helper.h
- * @brief Definition of helpers.
+ * @file src/anastasis/anastasis-gtk.h
+ * @brief Definitions of the main Gtk GUI.
  * @author Christian Grothoff
  * @author Dennis Neufeld
  */
diff --git a/src/anastasis/anastasis-gtk_handle-challenge-code.c 
b/src/anastasis/anastasis-gtk_handle-challenge-code.c
index 4f42023..6aeeb6f 100644
--- a/src/anastasis/anastasis-gtk_handle-challenge-code.c
+++ b/src/anastasis/anastasis-gtk_handle-challenge-code.c
@@ -48,8 +48,6 @@ anastasis_gtk_c_code_dialog_response_cb (GtkDialog *dialog,
   const char *qs;
   json_t *args;
   unsigned long long pin;
-  char dummy;
-  char s[16];
 
   if (GTK_RESPONSE_OK != response_id)
   {
diff --git a/src/anastasis/anastasis-gtk_handle-main-window-forward-clicked.c 
b/src/anastasis/anastasis-gtk_handle-main-window-forward-clicked.c
index 0e3c238..8ce8e3b 100644
--- a/src/anastasis/anastasis-gtk_handle-main-window-forward-clicked.c
+++ b/src/anastasis/anastasis-gtk_handle-main-window-forward-clicked.c
@@ -23,6 +23,9 @@
  * @author Christian Grothoff
  * @author Dennis Neufeld
  */
+#include "anastasis_gtk_config.h"
+#define HAVE_USED_CONFIG_H 1
+
 #include <gnunet/platform.h>
 #include <gnunet/gnunet_util_lib.h>
 #include "anastasis-gtk_action.h"
@@ -200,7 +203,7 @@ question_certainty (void)
     GtkWidget *toplevel;
     GtkWidget *widget;
 
-#if ! HPDF_ENABLED
+#if ! HAVE_HPDF_H
     gtk_widget_hide (
       GTK_WIDGET (
         gtk_builder_get_object (
diff --git a/src/anastasis/anastasis-gtk_handle-print.c 
b/src/anastasis/anastasis-gtk_handle-print.c
index 5b72c39..e4961d3 100644
--- a/src/anastasis/anastasis-gtk_handle-print.c
+++ b/src/anastasis/anastasis-gtk_handle-print.c
@@ -25,10 +25,11 @@
  */
 #include <gnunet/platform.h>
 #include <gnunet/gnunet_util_lib.h>
+#include "anastasis-gtk_attributes.h"
 #include "anastasis-gtk_helper.h"
 #include <jansson.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
-
+#include "print.h"
 
 /**
  * The user clicked the 'print' button to print their personal
@@ -41,7 +42,33 @@ void
 anastasis_gtk_print_details_button_clicked_cb (GtkButton *button,
                                                gpointer user_data)
 {
+  json_t *attr;
+  json_t *attrs;
+  int ret;
+
   (void) button;
   (void) user_data;
   GNUNET_break (0);
+  attr = AG_collect_attributes (false);
+  attrs = json_object_get (attr,
+                           "identity_attributes");
+  /*
+     Example for ATTRS is now:
+     "full_name": "Max",
+     "birthdate": "1980-09-22",
+     "sq_number": "4"
+  */
+
+  json_dumpf (attrs,
+              stderr,
+              JSON_INDENT (2));
+  /* FIXME: convert keys in 'attrs' to
+     more nice, human-readable keys! */
+  ret = AG_print (attrs,
+                  "test.pdf"); // FIXME: let user specify the filename!
+  json_decref (attr);
+  if (0 != ret)
+  {
+    /* FIXME: report failure... */
+  }
 }
diff --git a/src/anastasis/print.c b/src/anastasis/print.c
new file mode 100644
index 0000000..6b4a4c5
--- /dev/null
+++ b/src/anastasis/print.c
@@ -0,0 +1,158 @@
+/*
+     This file is part of anastasis-gtk.
+     Copyright (C) 2021 Anastasis SARL
+
+     Anastasis is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 3, or (at your
+     option) any later version.
+
+     Anastasis is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with Anastasis; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
+*/
+
+/**
+ * @file src/anastasis/print.c
+ * @brief Printing helper.
+ * @author Christian Grothoff
+ */
+
+#include <gnunet/platform.h>
+#include <setjmp.h>
+#include <hpdf.h>
+#include <gnunet/gnunet_util_lib.h>
+#include "print.h"
+
+static jmp_buf env;
+
+
+static void
+error_handler  (HPDF_STATUS error_no,
+                HPDF_STATUS detail_no,
+                void         *user_data)
+{
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+              "error_no=%04X, detail_no=%u\n",
+              (HPDF_UINT) error_no,
+              (HPDF_UINT) detail_no);
+  longjmp (env,
+           1);
+}
+
+
+int
+AG_print (json_t *user,
+          const char *fname)
+{
+  const char *page_title = "GNU Anastasis Identity Sheet";
+  const char *type;
+  json_t *jvalue;
+  HPDF_Doc pdf;
+  HPDF_Font font;
+  HPDF_Page page;
+  float tw;
+  float fsize;
+
+  pdf = HPDF_New (error_handler, NULL);
+  if (! pdf)
+  {
+    printf ("error: cannot create PdfDoc object\n");
+    return 1;
+  }
+
+  if (setjmp (env))
+  {
+    HPDF_Free (pdf);
+    return 1;
+  }
+
+  /* set compression mode */
+  HPDF_SetCompressionMode (pdf,
+                           HPDF_COMP_ALL);
+  /* create default-font */
+  font = HPDF_GetFont (pdf,
+                       "Helvetica",
+                       NULL);
+  /* add a new page object. */
+  page = HPDF_AddPage (pdf);
+
+  /* print the lines of the page. */
+  HPDF_Page_SetLineWidth (page, 1);
+  HPDF_Page_Rectangle (page,
+                       50, 50,
+                       HPDF_Page_GetWidth (page) - 100,
+                       HPDF_Page_GetHeight (page) - 110);
+  HPDF_Page_Stroke (page);
+
+  /* print the title of the page (with positioning center). */
+  HPDF_Page_SetFontAndSize (page,
+                            font,
+                            24);
+  tw = HPDF_Page_TextWidth (page,
+                            page_title);
+  HPDF_Page_BeginText (page);
+  HPDF_Page_TextOut (page,
+                     (HPDF_Page_GetWidth (page) - tw) / 2,
+                     HPDF_Page_GetHeight (page) - 50,
+                     page_title);
+  HPDF_Page_EndText (page);
+
+  HPDF_Page_BeginText (page);
+  HPDF_Page_MoveTextPos (page, 60, HPDF_Page_GetHeight (page) - 60);
+
+  /*
+   * font size
+   */
+  fsize = 18;
+  json_object_foreach (user, type, jvalue)
+  {
+    char *val;
+    int len;
+
+    /* print the description. */
+    HPDF_Page_MoveTextPos (page, 0, -12);
+    HPDF_Page_SetFontAndSize (page, font, 10);
+    HPDF_Page_ShowText (page, type);
+
+    /* set the position of the text. */
+    HPDF_Page_MoveTextPos (page, 10, -5 - fsize);
+    val = GNUNET_strdup (json_string_value (jvalue));
+    do {
+      /* set style and size of font. */
+      HPDF_Page_SetFontAndSize (page, font, fsize);
+      /* measure the number of characters which included in the page. */
+      len = HPDF_Page_MeasureText (page,
+                                   val,
+                                   HPDF_Page_GetWidth (page) - 130,
+                                   HPDF_FALSE,
+                                   NULL);
+      if ( (len < strlen (val)) &&
+           (fsize > 10) )
+        fsize--;
+      else
+        break;
+    } while (1);
+    /* truncate the text. */
+    val[len] = 0x00;
+    HPDF_Page_ShowText (page, val);
+    GNUNET_free (val);
+    HPDF_Page_MoveTextPos (page, -10, -25 - fsize);
+  }
+
+  HPDF_Page_EndText (page);
+
+  /* save the document to a file */
+  HPDF_SaveToFile (pdf, fname);
+
+  /* clean up */
+  HPDF_Free (pdf);
+
+  return 0;
+}
diff --git a/src/anastasis/anastasis-gtk_handle-print.c b/src/anastasis/print.h
similarity index 60%
copy from src/anastasis/anastasis-gtk_handle-print.c
copy to src/anastasis/print.h
index 5b72c39..142f9f5 100644
--- a/src/anastasis/anastasis-gtk_handle-print.c
+++ b/src/anastasis/print.h
@@ -19,29 +19,27 @@
 */
 
 /**
- * @file src/anastasis/anastasis-gtk_print.c
- * @brief Implementation of the "print" button
+ * @file src/anastasis/print.h
+ * @brief Definition of printing helper.
  * @author Christian Grothoff
  */
-#include <gnunet/platform.h>
-#include <gnunet/gnunet_util_lib.h>
-#include "anastasis-gtk_helper.h"
+
+#ifndef PRINT_H
+#define PRINT_H
+
 #include <jansson.h>
-#include <gdk-pixbuf/gdk-pixbuf.h>
 
 
 /**
- * The user clicked the 'print' button to print their personal
- * details. Try to print them.
+ * Generate a PDF file with the key-value strings
+ * from @a user and write it to @a fname.
  *
- * @param button the print button
- * @param user_data the builder for the dialog
+ * @param user user attribute data to output
+ * @param fname filename to write the PDF to (will overwrite)
+ * @return 0 on success
  */
-void
-anastasis_gtk_print_details_button_clicked_cb (GtkButton *button,
-                                               gpointer user_data)
-{
-  (void) button;
-  (void) user_data;
-  GNUNET_break (0);
-}
+int
+AG_print (json_t *user,
+          const char *fname);
+
+#endif
diff --git a/src/anastasis/anastasis-gtk_handle-print.c 
b/src/anastasis/test-print.c
similarity index 58%
copy from src/anastasis/anastasis-gtk_handle-print.c
copy to src/anastasis/test-print.c
index 5b72c39..c27c5ce 100644
--- a/src/anastasis/anastasis-gtk_handle-print.c
+++ b/src/anastasis/test-print.c
@@ -19,29 +19,27 @@
 */
 
 /**
- * @file src/anastasis/anastasis-gtk_print.c
- * @brief Implementation of the "print" button
+ * @file src/anastasis/test-print.c
+ * @brief Program to test printing helper.
  * @author Christian Grothoff
  */
-#include <gnunet/platform.h>
-#include <gnunet/gnunet_util_lib.h>
-#include "anastasis-gtk_helper.h"
-#include <jansson.h>
-#include <gdk-pixbuf/gdk-pixbuf.h>
+#include "print.h"
 
 
-/**
- * The user clicked the 'print' button to print their personal
- * details. Try to print them.
- *
- * @param button the print button
- * @param user_data the builder for the dialog
- */
-void
-anastasis_gtk_print_details_button_clicked_cb (GtkButton *button,
-                                               gpointer user_data)
+int
+main (int argc,
+      char **argv)
 {
-  (void) button;
-  (void) user_data;
-  GNUNET_break (0);
+  json_t *user;
+  int ret;
+
+  user = json_pack ("{s:s,s:s,s:s}",
+                    "key1", "value1",
+                    "key2",
+                    
"superloooooooooooooooooooooooooooooooooooooooooooooooooongvaaaaluevalue2",
+                    "key3", "value3");
+  ret = AG_print (user,
+                  "test-print.pdf");
+  json_decref (user);
+  return ret;
 }

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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