From 79add22e182e80f06c13358f74005fd97f21f120 Mon Sep 17 00:00:00 2001 From: Jared Wahlstrand Date: Mon, 23 Dec 2024 20:52:14 -0500 Subject: [PATCH 1/3] wrap `set_metadata` and `set_custom_metadata` --- src/Cairo.jl | 10 ++++++++++ src/constants.jl | 16 +++++++++++++++- test/runtests.jl | 2 ++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Cairo.jl b/src/Cairo.jl index 541c14b..7236a9c 100644 --- a/src/Cairo.jl +++ b/src/Cairo.jl @@ -339,6 +339,16 @@ function CairoPDFSurface(filename::AbstractString, w_pts::Real, h_pts::Real) CairoSurface(ptr, w_pts, h_pts) end +function set_metadata(surf, metadata_type, str) + ccall((:cairo_pdf_surface_set_metadata,libcairo), Cvoid, + (Ptr{Nothing}, Cint, Cstring), surf.ptr, metadata_type, str) +end + +function set_custom_metadata(surf, name, value) + ccall((:cairo_pdf_surface_set_custom_metadata,libcairo), Cvoid, + (Ptr{Nothing}, Cstring, Cstring), surf.ptr, name, value) +end + ## EPS ## function CairoEPSSurface(stream::T, w::Real, h::Real) where {T<:IO} diff --git a/src/constants.jl b/src/constants.jl index 3aac3ad..3d804a5 100644 --- a/src/constants.jl +++ b/src/constants.jl @@ -64,7 +64,14 @@ const STATUS_DEVICE_TYPE_MISMATCH = Int32(33) const STATUS_DEVICE_ERROR = Int32(34) const STATUS_INVALID_MESH_CONSTRUCTION = Int32(35) const STATUS_DEVICE_FINISHED = Int32(36) -const STATUS_LAST_STATUS = Int32(37) +const STATUS_JBIG2_GLOBAL_MISSING = Int32(37) +const STATUS_PNG_ERROR = Int32(38) +const STATUS_FREETYPE_ERROR = Int32(39) +const STATUS_WIN32_GDI_ERROR = Int32(40) +const STATUS_TAG_ERROR = Int32(41) +const STATUS_DWRITE_ERROR = Int32(42) +const STATUS_SVG_FONT_ERROR = Int32(43) +const STATUS_LAST_STATUS = Int32(44) const surface_t = Int32 const CAIRO_SURFACE_TYPE_IMAGE = Int32(0) @@ -148,6 +155,13 @@ const OPERATOR_OVERLAY = 16 const OPERATOR_DARKEN = 17 const OPERATOR_LIGHTEN = 18 +const PDF_METADATA_TITLE = 0 +const PDF_METADATA_AUTHOR = 1 +const PDF_METADATA_SUBJECT = 2 +const PDF_METADATA_KEYWORDS = 3 +const PDF_METADATA_CREATOR = 4 +const PDF_METADATA_CREATE_DATE = 5 +const PDF_METADATA_MOD_DATE = 6 ## LaTex Token Dicts ## const _common_token_dict = Dict( diff --git a/test/runtests.jl b/test/runtests.jl index a44aa6d..e8f5293 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -166,6 +166,8 @@ end output_file_name = "a.pdf" surf = CairoPDFSurface(output_file_name,512,512) hdraw(surf,64,8,4) + Cairo.set_metadata(surf, Cairo.PDF_METADATA_CREATOR, "Cairo.jl") + Cairo.set_custom_metadata(surf, "id", "42") finish(surf) @test isfile(output_file_name) From c86d10985bd1ca5c5bf4a1cf41f6d301688f27e3 Mon Sep 17 00:00:00 2001 From: Jared Wahlstrand Date: Mon, 23 Dec 2024 20:59:30 -0500 Subject: [PATCH 2/3] update constants --- src/constants.jl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/constants.jl b/src/constants.jl index 3d804a5..34a79f8 100644 --- a/src/constants.jl +++ b/src/constants.jl @@ -69,9 +69,7 @@ const STATUS_PNG_ERROR = Int32(38) const STATUS_FREETYPE_ERROR = Int32(39) const STATUS_WIN32_GDI_ERROR = Int32(40) const STATUS_TAG_ERROR = Int32(41) -const STATUS_DWRITE_ERROR = Int32(42) -const STATUS_SVG_FONT_ERROR = Int32(43) -const STATUS_LAST_STATUS = Int32(44) +const STATUS_LAST_STATUS = Int32(42) const surface_t = Int32 const CAIRO_SURFACE_TYPE_IMAGE = Int32(0) From e8519168efc34072b102520b7b8510f35fbdc4aa Mon Sep 17 00:00:00 2001 From: Jared Wahlstrand Date: Mon, 23 Dec 2024 21:04:57 -0500 Subject: [PATCH 3/3] update Cairo compat to 1.18 since `set_custom_metadata` was added then --- Project.toml | 2 +- src/constants.jl | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 9b19027..fe68154 100644 --- a/Project.toml +++ b/Project.toml @@ -11,7 +11,7 @@ Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb" Pango_jll = "36c8627f-9965-5494-a995-c6b170f724f3" [compat] -Cairo_jll = "1.16" +Cairo_jll = "1.18" Colors = "0.12, 0.13" Glib_jll = "2.59.0" Graphics = "1" diff --git a/src/constants.jl b/src/constants.jl index 34a79f8..3d804a5 100644 --- a/src/constants.jl +++ b/src/constants.jl @@ -69,7 +69,9 @@ const STATUS_PNG_ERROR = Int32(38) const STATUS_FREETYPE_ERROR = Int32(39) const STATUS_WIN32_GDI_ERROR = Int32(40) const STATUS_TAG_ERROR = Int32(41) -const STATUS_LAST_STATUS = Int32(42) +const STATUS_DWRITE_ERROR = Int32(42) +const STATUS_SVG_FONT_ERROR = Int32(43) +const STATUS_LAST_STATUS = Int32(44) const surface_t = Int32 const CAIRO_SURFACE_TYPE_IMAGE = Int32(0)