Perl-cairo patch to add bindings for PDF outline support.

This patch is technically incomplete since I don't know how the following defined constants should be handled. Constructive suggestion welcome.

        CAIRO_PDF_OUTLINE_ROOT  # 0
        CAIRO_TAG_DEST          # 'cairo.dest'
        CAIRO_TAG_LINK          # 'Link'


Raymond S Brand

>From 44477de54b3a7e4d52136d49dead48a28bef83d1 Mon Sep 17 00:00:00 2001
From: Raymond S Brand <r...@acm.org>
Date: Wed, 4 Nov 2020 19:54:59 -0500
Subject: [PATCH 2/2] Add bindings for PDF outline support

---
 CairoSurface.xs  |  6 ++++++
 Makefile.PL      | 13 +++++++++++++
 lib/Cairo.pm     | 32 ++++++++++++++++++++++++++++++++
 t/CairoSurface.t | 22 ++++++++++++++++++++--
 4 files changed, 71 insertions(+), 2 deletions(-)

diff --git a/CairoSurface.xs b/CairoSurface.xs
index d14caf2..26dd27a 100644
--- a/CairoSurface.xs
+++ b/CairoSurface.xs
@@ -625,8 +625,14 @@ cairo_pdf_surface_version_to_string (...)
 
 #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 16, 0)
 
+int cairo_pdf_surface_add_outline (cairo_surface_t *surface, int parent_id, const char *utf8, const char *link_attribs, cairo_pdf_outline_flags_t flags);
+
 void cairo_pdf_surface_set_metadata (cairo_surface_t *surface, cairo_pdf_metadata_t metadata, const char_utf8 * utf8);
 
+void cairo_pdf_surface_set_page_label (cairo_surface_t *surface, const char *utf8);
+
+void cairo_pdf_surface_set_thumbnail_size (cairo_surface_t *surface, int width, int height);
+
 #endif
 
 #endif
diff --git a/Makefile.PL b/Makefile.PL
index 2b5b5ca..a5a6d49 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -539,8 +539,21 @@ if ($have_cairo_1_16) {
 		CAIRO_PDF_METADATA_CREATE_DATE
 		CAIRO_PDF_METADATA_MOD_DATE
 	/];
+
+	$flags{cairo_pdf_outline_flags_t} = [qw/
+		CAIRO_PDF_OUTLINE_FLAG_
+		CAIRO_PDF_OUTLINE_FLAG_OPEN
+		CAIRO_PDF_OUTLINE_FLAG_BOLD
+		CAIRO_PDF_OUTLINE_FLAG_ITALIC
+	/];
+
+	 push @exports, qw/newSVCairoPdfOutline
+			SvCairoPdfOutline
+			cairo_pdf_outline_flags_from_sv
+			cairo_pdf_outline_flags_to_sv/;
 } else {
 	$enums{cairo_pdf_metadata_t} = [];
+	$flags{cairo_pdf_outline_flags_t} = [];
 }
 
 # --------------------------------------------------------------------------- #
diff --git a/lib/Cairo.pm b/lib/Cairo.pm
index 32ec0ce..556538b 100644
--- a/lib/Cairo.pm
+++ b/lib/Cairo.pm
@@ -1523,6 +1523,20 @@ For hysterical reasons, you can also use the following syntax:
 
 =back
 
+=item $id = $surface->add_outline($parent_id, $name, $attributes, $flags) [1.16]
+
+=over
+
+=item $id: int, item ID
+
+=item $name: string, item display
+
+=item $attributes: string, item attributes
+
+=item $flags: list reference, item flags
+
+=back
+
 =item $surface->set_metadata($name, $value) [1.16]
 
 =over
@@ -1533,6 +1547,24 @@ For hysterical reasons, you can also use the following syntax:
 
 =back
 
+=item $surface->set_page_label($label) [1.16]
+
+=over
+
+=item $label: string, page label
+
+=back
+
+=item $surface->set_thumbnail_size($width, $height) [1.16]
+
+=over
+
+=item $width: int, thumbnail width
+
+=item $height: int, thumbnail height
+
+=back
+
 =back
 
 =cut
diff --git a/t/CairoSurface.t b/t/CairoSurface.t
index 4fb8b34..f3c43b3 100644
--- a/t/CairoSurface.t
+++ b/t/CairoSurface.t
@@ -12,7 +12,7 @@ use warnings;
 
 use Config; # for byteorder
 
-use Test::More tests => 96;
+use Test::More tests => 99;
 
 use constant IMG_WIDTH => 256;
 use constant IMG_HEIGHT => 256;
@@ -216,7 +216,7 @@ SKIP: {
 }
 
 SKIP: {
-	skip 'pdf surface', 14
+	skip 'pdf surface', 17
 		unless Cairo::HAS_PDF_SURFACE;
 
 	my $surf = Cairo::PdfSurface->create ('tmp.pdf', IMG_WIDTH, IMG_HEIGHT);
@@ -301,6 +301,24 @@ SKIP: {
 		ok(1);	# No get_metadata, so assume OK if we're still alive
 	}
 
+	SKIP: {
+		skip 'new stuff', 3
+			unless Cairo::VERSION >= Cairo::VERSION_ENCODE (1, 16, 0);
+
+		$surf->set_page_label('Page label');
+		is ($surf->status(), 'success');
+
+		$surf->set_thumbnail_size(20, 20);
+		is ($surf->status(), 'success');
+
+		my $parent = $surf->add_outline(0, 'Cover', "dest='page=1'", ['bold']);
+		$parent = $surf->add_outline($parent, 'Chapter 1', 'page=2', ['bold', 'open']);
+		$parent = $surf->add_outline($parent, 'Section 1', 'page=2', ['open']);
+		$parent = $surf->add_outline($parent, 'Section 1.1', 'page=2', ['italic']);
+		$parent = $surf->add_outline($parent, 'Review', 'page=2', []);
+		is ($surf->status(), 'success');
+	}
+
 	unlink 'tmp.pdf';
 }
 
-- 
2.20.1

_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-perl-list

Reply via email to