From 4e89137689087afc45ff2505b289d1cf4be389ef Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Tue, 11 Feb 2025 20:22:36 -0500 Subject: [PATCH] Use pkg-config for compiler options. Fix some issues with the image2pdf example code. --- examples/Makefile | 4 ++-- examples/image2pdf.c | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/examples/Makefile b/examples/Makefile index 72f299b..7b20129 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -14,8 +14,8 @@ # Common options CFLAGS = -g $(CPPFLAGS) #CFLAGS = -g -fsanitize=address $(CPPFLAGS) -CPPFLAGS = -I.. -I/usr/local/include -LIBS = -L.. -L/usr/local/lib -lpdfio -lz -lm +CPPFLAGS = -I.. $(shell PKG_CONFIG_PATH="..:$(PKG_CONFIG_PATH)" pkg-config pdfio --cflags) +LIBS = -L.. $(shell PKG_CONFIG_PATH="..:$(PKG_CONFIG_PATH)" pkg-config pdfio --libs) # Targets diff --git a/examples/image2pdf.c b/examples/image2pdf.c index 7697e91..bf81b95 100644 --- a/examples/image2pdf.c +++ b/examples/image2pdf.c @@ -1,7 +1,7 @@ // // Image example for PDFio. // -// Copyright © 2023-2024 by Michael R Sweet. +// Copyright © 2023-2025 by Michael R Sweet. // // Licensed under Apache License v2.0. See the file "LICENSE" for more // information. @@ -22,8 +22,8 @@ bool // O - True on success, false on failure create_pdf_image_file( - const char *pdfname, // I - PDF filename const char *imagename, // I - Image filename + const char *pdfname, // I - PDF filename const char *caption) // I - Caption filename { pdfio_file_t *pdf; // PDF file @@ -36,6 +36,15 @@ create_pdf_image_file( double tx, ty; // Position on page + // Default the caption... + if (!caption) + { + if ((caption = strrchr(imagename, '/')) != NULL) + caption ++; + else + caption = imagename; + } + // Create the PDF file... pdf = pdfioFileCreate(pdfname, /*version*/NULL, /*media_box*/NULL, /*crop_box*/NULL, /*error_cb*/NULL,