[poppler] glib/poppler-document.cc glib/poppler-document.h glib/reference

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Oct 19 21:14:22 UTC 2018


 glib/poppler-document.cc            |  252 ++++++++++++++++++++++++++++++++++++
 glib/poppler-document.h             |   87 ++++++++++++
 glib/reference/poppler-sections.txt |   13 +
 3 files changed, 352 insertions(+)

New commits:
commit 20dfaa9e0b993567055c01902527bcddb9017520
Author: Evangelos Rigas <erigas at rnd2.org>
Date:   Mon Sep 24 15:59:44 2018 +0100

    Add support for PDF subtype property (glib backend)
    
    Export PDFSubtype, PDFSubtypePart, and PDFSubtypeConformance
    to GLib as enums and add function to get the GTS string based
    on the PDF Subtype.
    
    Add PDF Subtype documentation reference in glib.

diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc
index ea319344..8567856a 100644
--- a/glib/poppler-document.cc
+++ b/glib/poppler-document.cc
@@ -62,6 +62,10 @@ enum {
 	PROP_FORMAT,
 	PROP_FORMAT_MAJOR,
 	PROP_FORMAT_MINOR,
+	PROP_SUBTYPE,
+	PROP_SUBTYPE_STRING,
+	PROP_SUBTYPE_PART,
+	PROP_SUBTYPE_CONF,
 	PROP_AUTHOR,
 	PROP_SUBJECT,
 	PROP_KEYWORDS,
@@ -813,6 +817,85 @@ convert_page_mode (Catalog::PageMode pageMode)
     }
 }
 
+static PopplerPDFSubtype
+convert_pdf_subtype (PDFSubtype pdfSubtype)
+{
+  switch (pdfSubtype)
+    {
+    case subtypePDFA:
+      return POPPLER_PDF_SUBTYPE_PDF_A;
+    case subtypePDFE:
+      return POPPLER_PDF_SUBTYPE_PDF_E;
+    case subtypePDFUA:
+      return POPPLER_PDF_SUBTYPE_PDF_UA;
+    case subtypePDFVT:
+      return POPPLER_PDF_SUBTYPE_PDF_VT;
+    case subtypePDFX:
+      return POPPLER_PDF_SUBTYPE_PDF_X;
+    case subtypeNone:
+      return POPPLER_PDF_SUBTYPE_NONE;
+    case subtypeNull:
+    default:
+      return POPPLER_PDF_SUBTYPE_UNSET;
+    }
+}
+
+static PopplerPDFPart
+convert_pdf_subtype_part (PDFSubtypePart pdfSubtypePart)
+{
+  switch (pdfSubtypePart)
+    {
+    case subtypePart1:
+      return POPPLER_PDF_SUBTYPE_PART_1;
+    case subtypePart2:
+      return POPPLER_PDF_SUBTYPE_PART_2;
+    case subtypePart3:
+      return POPPLER_PDF_SUBTYPE_PART_3;
+    case subtypePart4:
+      return POPPLER_PDF_SUBTYPE_PART_4;
+    case subtypePart5:
+      return POPPLER_PDF_SUBTYPE_PART_5;
+    case subtypePart6:
+      return POPPLER_PDF_SUBTYPE_PART_6;
+    case subtypePart7:
+      return POPPLER_PDF_SUBTYPE_PART_7;
+    case subtypePart8:
+      return POPPLER_PDF_SUBTYPE_PART_8;
+    case subtypePartNone:
+      return POPPLER_PDF_SUBTYPE_PART_NONE;
+    case subtypePartNull:
+    default:
+      return POPPLER_PDF_SUBTYPE_PART_UNSET;
+    }
+}
+
+static PopplerPDFConformance
+convert_pdf_subtype_conformance (PDFSubtypeConformance pdfSubtypeConf)
+{
+  switch (pdfSubtypeConf)
+    {
+    case subtypeConfA:
+      return POPPLER_PDF_SUBTYPE_CONF_A;
+    case subtypeConfB:
+      return POPPLER_PDF_SUBTYPE_CONF_B;
+    case subtypeConfG:
+      return POPPLER_PDF_SUBTYPE_CONF_G;
+    case subtypeConfN:
+      return POPPLER_PDF_SUBTYPE_CONF_N;
+    case subtypeConfP:
+      return POPPLER_PDF_SUBTYPE_CONF_P;
+    case subtypeConfPG:
+      return POPPLER_PDF_SUBTYPE_CONF_PG;
+    case subtypeConfU:
+      return POPPLER_PDF_SUBTYPE_CONF_U;
+    case subtypeConfNone:
+      return POPPLER_PDF_SUBTYPE_CONF_NONE;
+    case subtypeConfNull:
+    default:
+      return POPPLER_PDF_SUBTYPE_CONF_UNSET;
+    }
+}
+
 /**
  * poppler_document_get_pdf_version_string:
  * @document: A #PopplerDocument
@@ -1358,6 +1441,108 @@ poppler_document_get_permissions (PopplerDocument *document)
 }
 
 /**
+ * poppler_document_get_pdf_subtype_string:
+ * @document: A #PopplerDocument
+ *
+ * Returns the PDF subtype version of @document as a string.
+ *
+ * Returns: (transfer full) (nullable): a newly allocated string containing
+ * the PDF subtype version of @document, or %NULL
+ *
+ * Since: 0.70
+ **/
+gchar *
+poppler_document_get_pdf_subtype_string (PopplerDocument *document)
+{
+  g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), NULL);
+
+  GooString *infostring;
+
+  switch (document->doc->getPDFSubtype ())
+    {
+    case subtypePDFA:
+      infostring = document->doc->getDocInfoStringEntry ("GTS_PDFA1Version");
+      break;
+    case subtypePDFE:
+      infostring = document->doc->getDocInfoStringEntry ("GTS_PDFEVersion");
+      break;
+    case subtypePDFUA:
+      infostring = document->doc->getDocInfoStringEntry ("GTS_PDFUAVersion");
+      break;
+    case subtypePDFVT:
+      infostring = document->doc->getDocInfoStringEntry ("GTS_PDFVTVersion");
+      break;
+    case subtypePDFX:
+      infostring = document->doc->getDocInfoStringEntry ("GTS_PDFXVersion");
+      break;
+    case subtypeNone:
+    case subtypeNull:
+    default:
+      infostring = nullptr;
+    }
+
+  gchar *utf8 = _poppler_goo_string_to_utf8 (infostring);
+  delete infostring;
+
+  return utf8;
+}
+
+/**
+ * poppler_document_get_pdf_subtype:
+ * @document: A #PopplerDocument
+ *
+ * Returns the subtype of @document as a #PopplerPDFSubtype.
+ *
+ * Returns: the document's subtype
+ *
+ * Since: 0.70
+ **/
+PopplerPDFSubtype
+poppler_document_get_pdf_subtype (PopplerDocument *document)
+{
+  g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), POPPLER_PDF_SUBTYPE_NONE);
+
+  return convert_pdf_subtype (document->doc->getPDFSubtype ());
+}
+
+/**
+ * poppler_document_get_pdf_part:
+ * @document: A #PopplerDocument
+ *
+ * Returns the part of the conforming standard that the @document adheres to
+ * as a #PopplerPDFSubtype.
+ *
+ * Returns: the document's subtype part
+ *
+ * Since: 0.70
+ **/
+PopplerPDFPart
+poppler_document_get_pdf_part (PopplerDocument *document)
+{
+  g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), POPPLER_PDF_SUBTYPE_PART_NONE);
+
+  return convert_pdf_subtype_part (document->doc->getPDFSubtypePart ());
+}
+
+/**
+ * poppler_document_get_pdf_conformance:
+ * @document: A #PopplerDocument
+ *
+ * Returns the conformance level of the @document as #PopplerPDFConformance.
+ *
+ * Returns: the document's subtype conformance level
+ *
+ * Since: 0.70
+ **/
+PopplerPDFConformance
+poppler_document_get_pdf_conformance (PopplerDocument *document)
+{
+  g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), POPPLER_PDF_SUBTYPE_CONF_NONE);
+
+  return convert_pdf_subtype_conformance (document->doc->getPDFSubtypeConformance ());
+}
+
+/**
  * poppler_document_get_metadata:
  * @document: A #PopplerDocument
  *
@@ -1451,6 +1636,18 @@ poppler_document_get_property (GObject    *object,
     case PROP_PERMISSIONS:
       g_value_set_flags (value, poppler_document_get_permissions (document));
       break;
+    case PROP_SUBTYPE:
+      g_value_set_enum (value, poppler_document_get_pdf_subtype (document));
+      break;
+    case PROP_SUBTYPE_STRING:
+      g_value_take_string (value, poppler_document_get_pdf_subtype_string (document));
+      break;
+    case PROP_SUBTYPE_PART:
+      g_value_set_enum (value, poppler_document_get_pdf_part (document));
+      break;
+    case PROP_SUBTYPE_CONF:
+      g_value_set_enum (value, poppler_document_get_pdf_conformance (document));
+      break;
     case PROP_METADATA:
       g_value_take_string (value, poppler_document_get_metadata (document));
       break;
@@ -1718,6 +1915,61 @@ poppler_document_class_init (PopplerDocumentClass *klass)
 						       G_PARAM_READABLE));
 
   /**
+   * PopplerDocument:subtype:
+   *
+   *  Document PDF subtype type
+   */
+  g_object_class_install_property (G_OBJECT_CLASS (klass),
+				   PROP_SUBTYPE,
+				   g_param_spec_enum ("subtype",
+						       "PDF Format Subtype Type",
+						       "The PDF subtype of the document",
+						       POPPLER_TYPE_PDF_SUBTYPE,
+						       POPPLER_PDF_SUBTYPE_UNSET,
+						       G_PARAM_READABLE));
+
+  /**
+   * PopplerDocument:subtype-string:
+   *
+   *  Document PDF subtype. See also poppler_document_get_pdf_subtype_string()
+   */
+  g_object_class_install_property (G_OBJECT_CLASS (klass),
+				   PROP_SUBTYPE_STRING,
+				   g_param_spec_string ("subtype-string",
+						       "PDF Format Subtype",
+						       "The PDF subtype of the document",
+						       nullptr,
+						       G_PARAM_READABLE));
+
+  /**
+   * PopplerDocument:subtype-part:
+   *
+   *  Document PDF subtype part
+   */
+  g_object_class_install_property (G_OBJECT_CLASS (klass),
+				   PROP_SUBTYPE_PART,
+						       g_param_spec_enum ("subtype-part",
+						       "PDF Format Subtype Part",
+						       "The part of PDF conformance",
+						       POPPLER_TYPE_PDF_PART,
+						       POPPLER_PDF_SUBTYPE_PART_UNSET,
+						       G_PARAM_READABLE));
+
+  /**
+   * PopplerDocument:subtype-conformance:
+   *
+   *  Document PDF subtype conformance
+   */
+  g_object_class_install_property (G_OBJECT_CLASS (klass),
+				   PROP_SUBTYPE_CONF,
+				   g_param_spec_enum ("subtype-conformance",
+						       "PDF Format Subtype Conformance",
+						       "The conformance level of PDF subtype",
+						       POPPLER_TYPE_PDF_CONFORMANCE,
+						       POPPLER_PDF_SUBTYPE_CONF_UNSET,
+						       G_PARAM_READABLE));
+
+  /**
    * PopplerDocument:metadata:
    *
    * Document metadata in XML format, or %NULL
diff --git a/glib/poppler-document.h b/glib/poppler-document.h
index a7fcea1d..e943cd84 100644
--- a/glib/poppler-document.h
+++ b/glib/poppler-document.h
@@ -165,7 +165,90 @@ typedef enum /*< flags >*/
 
 } PopplerPermissions;
 
+/**
+ * PopplerPDFSubtype:
+ * @POPPLER_PDF_SUBTYPE_UNSET: Null
+ * @POPPLER_PDF_SUBTYPE_PDF_A: ISO 19005 - Document management -- Electronic document file format for long-term preservation (PDF/A)
+ * @POPPLER_PDF_SUBTYPE_PDF_E: ISO 24517 - Document management -- Engineering document format using PDF (PDF/E)
+ * @POPPLER_PDF_SUBTYPE_PDF_UA: ISO 14289 - Document management applications -- Electronic document file format enhancement for accessibility (PDF/UA)
+ * @POPPLER_PDF_SUBTYPE_PDF_VT: ISO 16612 - Graphic technology -- Variable data exchange (PDF/VT)
+ * @POPPLER_PDF_SUBTYPE_PDF_X: ISO 15930 - Graphic technology -- Prepress digital data exchange (PDF/X)
+ * @POPPLER_PDF_SUBTYPE_NONE: Not compliant with the above standards
+ *
+ * PDF Subtype
+ *
+ * Since: 0.70
+ */
+typedef enum
+{
+  POPPLER_PDF_SUBTYPE_UNSET,
+  POPPLER_PDF_SUBTYPE_PDF_A,
+  POPPLER_PDF_SUBTYPE_PDF_E,
+  POPPLER_PDF_SUBTYPE_PDF_UA,
+  POPPLER_PDF_SUBTYPE_PDF_VT,
+  POPPLER_PDF_SUBTYPE_PDF_X,
+  POPPLER_PDF_SUBTYPE_NONE
+} PopplerPDFSubtype;
 
+/**
+ * PopplerPDFPart:
+ * @POPPLER_PDF_SUBTYPE_PART_UNSET: Null
+ * @POPPLER_PDF_SUBTYPE_PART_1: 1
+ * @POPPLER_PDF_SUBTYPE_PART_2: 2
+ * @POPPLER_PDF_SUBTYPE_PART_3: 3
+ * @POPPLER_PDF_SUBTYPE_PART_4: 4
+ * @POPPLER_PDF_SUBTYPE_PART_5: 5
+ * @POPPLER_PDF_SUBTYPE_PART_6: 6
+ * @POPPLER_PDF_SUBTYPE_PART_7: 7
+ * @POPPLER_PDF_SUBTYPE_PART_8: 8
+ * @POPPLER_PDF_SUBTYPE_PART_NONE: No part available
+ *
+ * PDF Subtype Part
+ *
+ * Since: 0.70
+ */
+typedef enum
+{
+  POPPLER_PDF_SUBTYPE_PART_UNSET,
+  POPPLER_PDF_SUBTYPE_PART_1,
+  POPPLER_PDF_SUBTYPE_PART_2,
+  POPPLER_PDF_SUBTYPE_PART_3,
+  POPPLER_PDF_SUBTYPE_PART_4,
+  POPPLER_PDF_SUBTYPE_PART_5,
+  POPPLER_PDF_SUBTYPE_PART_6,
+  POPPLER_PDF_SUBTYPE_PART_7,
+  POPPLER_PDF_SUBTYPE_PART_8,
+  POPPLER_PDF_SUBTYPE_PART_NONE
+} PopplerPDFPart;
+
+/**
+ * PopplerPDFConformance:
+ * @POPPLER_PDF_SUBTYPE_CONF_UNSET: Null
+ * @POPPLER_PDF_SUBTYPE_CONF_A: Level A (accessible) conformance (PDF/A)
+ * @POPPLER_PDF_SUBTYPE_CONF_B: Level B (basic) conformance (PDF/A)
+ * @POPPLER_PDF_SUBTYPE_CONF_G: Level G (external graphical content) (PDF/X)
+ * @POPPLER_PDF_SUBTYPE_CONF_N: Level N (external ICC Profile) (PDF/X)
+ * @POPPLER_PDF_SUBTYPE_CONF_P: Level P (ICC Profile) (PDF/X)
+ * @POPPLER_PDF_SUBTYPE_CONF_PG: Level PG (conjuction of P and G) (PDF/X)
+ * @POPPLER_PDF_SUBTYPE_CONF_U: Level U (Unicode) conformance (PDF/A)
+ * @POPPLER_PDF_SUBTYPE_CONF_NONE: No conformance level available
+ *
+ * PDF Subtype Conformance
+ *
+ * Since: 0.70
+ */
+typedef enum
+{
+  POPPLER_PDF_SUBTYPE_CONF_UNSET,
+  POPPLER_PDF_SUBTYPE_CONF_A,
+  POPPLER_PDF_SUBTYPE_CONF_B,
+  POPPLER_PDF_SUBTYPE_CONF_G,
+  POPPLER_PDF_SUBTYPE_CONF_N,
+  POPPLER_PDF_SUBTYPE_CONF_P,
+  POPPLER_PDF_SUBTYPE_CONF_PG,
+  POPPLER_PDF_SUBTYPE_CONF_U,
+  POPPLER_PDF_SUBTYPE_CONF_NONE
+} PopplerPDFConformance;
 
 GType              poppler_document_get_type               (void) G_GNUC_CONST;
 PopplerDocument   *poppler_document_new_from_file          (const char      *uri,
@@ -230,6 +313,10 @@ gboolean           poppler_document_is_linearized          (PopplerDocument *doc
 PopplerPageLayout  poppler_document_get_page_layout        (PopplerDocument *document);
 PopplerPageMode    poppler_document_get_page_mode          (PopplerDocument *document);
 PopplerPermissions poppler_document_get_permissions        (PopplerDocument *document);
+gchar             *poppler_document_get_pdf_subtype_string (PopplerDocument *document);
+PopplerPDFSubtype  poppler_document_get_pdf_subtype        (PopplerDocument *document);
+PopplerPDFPart     poppler_document_get_pdf_part           (PopplerDocument *document);
+PopplerPDFConformance poppler_document_get_pdf_conformance (PopplerDocument *document);
 gchar             *poppler_document_get_metadata           (PopplerDocument *document);
 
 /* Attachments */
diff --git a/glib/reference/poppler-sections.txt b/glib/reference/poppler-sections.txt
index af1bbba9..1cefc79c 100644
--- a/glib/reference/poppler-sections.txt
+++ b/glib/reference/poppler-sections.txt
@@ -124,6 +124,9 @@ PopplerFontType
 PopplerPSFile
 PopplerViewerPreferences
 PopplerPermissions
+PopplerPDFSubtype
+PopplerPDFPart
+PopplerPDFConformance
 poppler_document_new_from_file
 poppler_document_new_from_data
 poppler_document_new_from_stream
@@ -152,6 +155,10 @@ poppler_document_set_modification_date
 poppler_document_get_page_layout
 poppler_document_get_page_mode
 poppler_document_get_permissions
+poppler_document_get_pdf_subtype_string
+poppler_document_get_pdf_subtype
+poppler_document_get_pdf_part
+poppler_document_get_pdf_conformance
 poppler_document_get_metadata
 poppler_document_is_linearized
 poppler_document_get_n_pages
@@ -213,6 +220,9 @@ POPPLER_TYPE_FONT_TYPE
 POPPLER_TYPE_PAGE_LAYOUT
 POPPLER_TYPE_PAGE_MODE
 POPPLER_TYPE_PERMISSIONS
+POPPLER_TYPE_PDF_SUBTYPE
+POPPLER_TYPE_PDF_PART
+POPPLER_TYPE_PDF_CONFORMANCE
 POPPLER_TYPE_VIEWER_PREFERENCES
 
 <SUBSECTION Private>
@@ -226,6 +236,9 @@ poppler_font_type_get_type
 poppler_page_layout_get_type
 poppler_page_mode_get_type
 poppler_permissions_get_type
+poppler_pdf_subtype_get_type
+poppler_pdf_part_get_type
+poppler_pdf_conformance_get_type
 poppler_viewer_preferences_get_type
 </SECTION>
 


More information about the poppler mailing list