Skip Menu |

This queue is for tickets about the Cairo CPAN distribution.

Report information
The Basics
Id: 130308
Status: resolved
Priority: 0/
Queue: Cairo

People
Owner: XAOC [...] cpan.org
Requestors: jv [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: PDF metadata
Does the PDF surface support the set/get metadata calls? https://cairographics.org/manual/cairo-PDF-Surfaces.html#cairo-pdf-surface-set-metadata
On Fri Aug 16 02:37:08 2019, JV wrote: Show quoted text
> Does the PDF surface support the set/get metadata calls? > https://cairographics.org/manual/cairo-PDF-Surfaces.html#cairo-pdf- > surface-set-metadata
$ cd perl-Cairo.git $ grep -rns cairo_pdf_surface_set_metadata * | wc -l 0 No, the Cairo Perl module does not currently support the cairo_pdf_surface_set_metadata Cairo C library function. Patches with test cases are always welcome. You can grep through the Perl module source to see what C lib functions currently are supported. For example: grep -rns cairo_pdf_version_to_string * | wc -l 3 For what it's worth, I'm not seeing a "cairo-pdf-surface-get-metadata" function in the Cairo documentation that you linked, so with the Cairo C library, you can only *set* PDF metadata, you can't retrieve (get) it. Do you need anything else for this ticket?
Subject: Re: [rt.cpan.org #130308] PDF metadata
Date: Sat, 17 Aug 2019 22:47:31 +0200
To: bug-Cairo [...] rt.cpan.org
From: Johan Vromans <jvromans [...] squirrel.nl>
Show quoted text
> For what it's worth, I'm not seeing a "cairo-pdf-surface-get-metadata" > function in the Cairo documentation that you linked, so with the Cairo C > library, you can only *set* PDF metadata, you can't retrieve (get) it.
Yes. Despite this it would be nice if this function was added to perl-Cairo. It looks easy but it is beyond my capabilities -- I'm not familiar with XS programming. Thanks.
The attached patch against 1.106 adds set_metadata to the pdf surface. It includes test and documentation. Note that line numbers are based on 1.106 plus the 'tag' patch. Thanks.
Subject: perl-Cairo-1.106-metadata.patch
*** Cairo-1.106/CairoSurface.xs~ 2013-09-29 06:49:21.000000000 +0200 --- Cairo-1.106/CairoSurface.xs 2019-08-18 22:08:54.565352385 +0200 *************** *** 580,585 **** --- 580,591 ---- #endif + #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 16, 0) + + void cairo_pdf_surface_set_metadata (cairo_surface_t *surface, cairo_pdf_metadata_t metadata, const char_utf8 * utf8); + + #endif + #endif # --------------------------------------------------------------------------- # *** Cairo-1.106/Makefile.PL~ 2015-09-26 19:10:29.000000000 +0200 --- Cairo-1.106/Makefile.PL 2019-08-18 22:32:53.033563091 +0200 *************** *** 482,487 **** --- 482,498 ---- CAIRO_PDF_VERSION_1_5 /]; + $enums{cairo_pdf_metadata_t} = [qw/ + CAIRO_PDF_METADATA_ + CAIRO_PDF_METADATA_TITLE + CAIRO_PDF_METADATA_AUTHOR + CAIRO_PDF_METADATA_SUBJECT + CAIRO_PDF_METADATA_KEYWORDS + CAIRO_PDF_METADATA_CREATOR + CAIRO_PDF_METADATA_CREATE_DATE + CAIRO_PDF_METADATA_MOD_DATE + /]; + $enums{cairo_region_overlap_t} = [qw/ CAIRO_REGION_OVERLAP_ CAIRO_REGION_OVERLAP_IN *** Cairo-1.106/t/CairoSurface.t~ 2011-11-27 08:56:45.000000000 +0100 --- Cairo-1.106/t/CairoSurface.t 2019-08-19 08:48:20.157001297 +0200 *************** *** 12,18 **** use Config; # for byteorder ! use Test::More tests => 88; use constant IMG_WIDTH => 256; use constant IMG_HEIGHT => 256; --- 12,18 ---- use Config; # for byteorder ! use Test::More tests => 89; use constant IMG_WIDTH => 256; use constant IMG_HEIGHT => 256; *************** *** 268,273 **** --- 268,283 ---- like (Cairo::PdfSurface->version_to_string('1-4'), qr/1\.4/); } + SKIP: { + skip 'new stuff', 3 + unless Cairo::VERSION >= Cairo::VERSION_ENCODE (1, 16, 0); + + $surf->set_metadata("title","Testing metadata"); + $surf->set_metadata("author","Johan Vromans"); + $surf->set_metadata("subject","cairo_pdf_set_metadata"); + ok(1); # No get_metadata, so assume OK if we're still alive + } + unlink 'tmp.pdf'; } *** Cairo-1.106/lib/Cairo.pm~ 2015-09-29 07:05:09.000000000 +0200 --- Cairo-1.106/lib/Cairo.pm 2019-08-19 08:50:47.637235873 +0200 *************** *** 1491,1496 **** --- 1509,1524 ---- =back + =item $surface->set_metadata($name, $value) [1.16] + + =over + + =item $name: string + + =item $value: string + + =back + =back =cut
On Mon Aug 19 03:31:56 2019, JV wrote: Show quoted text
> The attached patch against 1.106 adds set_metadata to the pdf surface. > It includes test and documentation.
Thanks a lot for your contribution. The enum handling in Makefile.PL should be version-protected for 1.16, not 1.10 as it is now. And in the corresponding else branch, an empty hash entry needs to be added. See the else branch for 'if ($have_cairo_1_2)' for an explanation. Apart from that, the patch looks fine to me.
Revised patch.
Subject: perl-Cairo-1.106-metadata.patch
*** Cairo-1.106/CairoSurface.xs~ 2013-09-29 06:49:21.000000000 +0200 --- Cairo-1.106/CairoSurface.xs 2019-08-18 22:08:54.565352385 +0200 *************** *** 580,585 **** --- 580,591 ---- #endif + #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 16, 0) + + void cairo_pdf_surface_set_metadata (cairo_surface_t *surface, cairo_pdf_metadata_t metadata, const char_utf8 * utf8); + + #endif + #endif # --------------------------------------------------------------------------- # *** Cairo-1.106/Makefile.PL~ 2015-09-26 19:10:29.000000000 +0200 --- Cairo-1.106/Makefile.PL 2019-08-18 22:32:53.033563091 +0200 *************** *** 325,330 **** --- 325,331 ---- my $have_cairo_1_6 = ExtUtils::PkgConfig->atleast_version("cairo", "1.6.0"); my $have_cairo_1_8 = ExtUtils::PkgConfig->atleast_version("cairo", "1.8.0"); my $have_cairo_1_10 = ExtUtils::PkgConfig->atleast_version("cairo", "1.10.0"); + my $have_cairo_1_16 = ExtUtils::PkgConfig->atleast_version("cairo", "1.16.0"); if ($have_cairo_1_2) { add_new_enum_values( *************** *** 500,505 **** --- 501,522 ---- $enums{cairo_region_overlap_t} = []; } + if ($have_cairo_1_16) { + $enums{cairo_pdf_metadata_t} = [qw/ + CAIRO_PDF_METADATA_ + CAIRO_PDF_METADATA_TITLE + CAIRO_PDF_METADATA_AUTHOR + CAIRO_PDF_METADATA_SUBJECT + CAIRO_PDF_METADATA_KEYWORDS + CAIRO_PDF_METADATA_CREATOR + CAIRO_PDF_METADATA_CREATE_DATE + CAIRO_PDF_METADATA_MOD_DATE + /]; + + } else { + $enums{cairo_pdf_metadata_t} = []; + } + # --------------------------------------------------------------------------- # my %object_guards = ( *** Cairo-1.106/t/CairoSurface.t~ 2011-11-27 08:56:45.000000000 +0100 --- Cairo-1.106/t/CairoSurface.t 2019-08-19 08:48:20.157001297 +0200 *************** *** 12,18 **** use Config; # for byteorder ! use Test::More tests => 88; use constant IMG_WIDTH => 256; use constant IMG_HEIGHT => 256; --- 12,18 ---- use Config; # for byteorder ! use Test::More tests => 89; use constant IMG_WIDTH => 256; use constant IMG_HEIGHT => 256; *************** *** 268,273 **** --- 268,283 ---- like (Cairo::PdfSurface->version_to_string('1-4'), qr/1\.4/); } + SKIP: { + skip 'new stuff', 3 + unless Cairo::VERSION >= Cairo::VERSION_ENCODE (1, 16, 0); + + $surf->set_metadata("title","Testing metadata"); + $surf->set_metadata("author","Johan Vromans"); + $surf->set_metadata("subject","cairo_pdf_set_metadata"); + ok(1); # No get_metadata, so assume OK if we're still alive + } + unlink 'tmp.pdf'; } *** Cairo-1.106/lib/Cairo.pm~ 2015-09-29 07:05:09.000000000 +0200 --- Cairo-1.106/lib/Cairo.pm 2019-08-19 08:50:47.637235873 +0200 *************** *** 1491,1496 **** --- 1509,1524 ---- =back + =item $surface->set_metadata($name, $value) [1.16] + + =over + + =item $name: string + + =item $value: string + + =back + =back =cut