mirror of
https://github.com/michaelrsweet/pdfio.git
synced 2025-02-13 15:32:51 +01:00
Info catalog accessors (Issue #9)
This commit is contained in:
parent
4f6a7ab03f
commit
30343cdb00
6
Makefile
6
Makefile
@ -17,15 +17,15 @@ CC = cc
|
||||
CFLAGS =
|
||||
CODESIGN_IDENTITY = Developer ID
|
||||
COMMONFLAGS = -Os -g
|
||||
CPPFLAGS =
|
||||
CPPFLAGS = '-DPDFIO_VERSION="$(VERSION)"'
|
||||
DESTDIR = $(DSTROOT)
|
||||
DSO = cc
|
||||
DSOFLAGS =
|
||||
DSOFLAGS =
|
||||
DSONAME =
|
||||
LDFLAGS =
|
||||
LIBS = -lm -lz
|
||||
RANLIB = ranlib
|
||||
VERSION = 0.1
|
||||
VERSION = 0.2
|
||||
prefix = /usr/local
|
||||
|
||||
|
||||
|
@ -1491,7 +1491,8 @@ pdfioFileCreateFontObjFromFile(
|
||||
pdfioDictSetName(dict, "Subtype", "Type0");
|
||||
pdfioDictSetName(dict, "BaseFont", basefont);
|
||||
pdfioDictSetArray(dict, "DescendantFonts", descendants);
|
||||
pdfioDictSetName(dict, "Encoding", "Identity-H");
|
||||
// pdfioDictSetName(dict, "Encoding", "Identity-H");
|
||||
pdfioDictSetName(dict, "Encoding", "UniCNS-UCS2-H");
|
||||
|
||||
if ((obj = pdfioFileCreateObj(pdf, dict)) == NULL)
|
||||
return (NULL);
|
||||
|
192
pdfio-file.c
192
pdfio-file.c
@ -123,10 +123,11 @@ pdfioFileClose(pdfio_file_t *pdf) // I - PDF file
|
||||
{
|
||||
ret = false;
|
||||
|
||||
if (write_pages(pdf))
|
||||
if (write_catalog(pdf))
|
||||
if (write_trailer(pdf))
|
||||
ret = _pdfioFileFlush(pdf);
|
||||
if (pdfioObjClose(pdf->info))
|
||||
if (write_pages(pdf))
|
||||
if (write_catalog(pdf))
|
||||
if (write_trailer(pdf))
|
||||
ret = _pdfioFileFlush(pdf);
|
||||
}
|
||||
|
||||
if (close(pdf->fd) < 0)
|
||||
@ -177,6 +178,7 @@ pdfioFileCreate(
|
||||
{
|
||||
pdfio_file_t *pdf; // PDF file
|
||||
pdfio_dict_t *dict; // Dictionary for pages object
|
||||
pdfio_dict_t *info_dict; // Dictionary for information object
|
||||
|
||||
|
||||
// Range check input...
|
||||
@ -269,6 +271,24 @@ pdfioFileCreate(
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
// Create the info object...
|
||||
if ((info_dict = pdfioDictCreate(pdf)) == NULL)
|
||||
{
|
||||
pdfioFileClose(pdf);
|
||||
unlink(filename);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
// pdfioDictSetDate(info_dict, "CreationDate", time(NULL));
|
||||
pdfioDictSetString(info_dict, "Producer", "pdfio/" PDFIO_VERSION);
|
||||
|
||||
if ((pdf->info = pdfioFileCreateObj(pdf, info_dict)) == NULL)
|
||||
{
|
||||
pdfioFileClose(pdf);
|
||||
unlink(filename);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
return (pdf);
|
||||
}
|
||||
|
||||
@ -511,6 +531,42 @@ pdfioFileFindObj(
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// 'pdfioFileGetAuthor()' - Get the author for a PDF file.
|
||||
//
|
||||
|
||||
const char * // O - Author or `NULL` for none
|
||||
pdfioFileGetAuthor(pdfio_file_t *pdf) // I - PDF file
|
||||
{
|
||||
return (pdf && pdf->info ? pdfioDictGetString(pdf->info->value.value.dict, "Author") : NULL);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// 'pdfioFileGetCreationDate()' - Get the creation date for a PDF file.
|
||||
//
|
||||
|
||||
time_t // O - Creation date or `0` for none
|
||||
pdfioFileGetCreationDate(
|
||||
pdfio_file_t *pdf) // I - PDF file
|
||||
{
|
||||
(void)pdf;
|
||||
return (0);
|
||||
// return (pdf && pdf->info ? pdfioDictGetDate(pdf->info->value.value.dict, "CreationDate") : 0);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// 'pdfioFileGetCreator()' - Get the creator string for a PDF file.
|
||||
//
|
||||
|
||||
const char * // O - Creator string or `NULL` for none
|
||||
pdfioFileGetCreator(pdfio_file_t *pdf) // I - PDF file
|
||||
{
|
||||
return (pdf && pdf->info ? pdfioDictGetString(pdf->info->value.value.dict, "Creator") : NULL);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// 'pdfioFileGetID()' - Get the PDF file's ID strings.
|
||||
//
|
||||
@ -518,7 +574,18 @@ pdfioFileFindObj(
|
||||
pdfio_array_t * // O - Array with binary strings
|
||||
pdfioFileGetID(pdfio_file_t *pdf) // I - PDF file
|
||||
{
|
||||
return (pdf ? pdfioDictGetArray(pdf->trailer, "ID") : NULL);
|
||||
return (pdf && pdf->info ? pdfioDictGetArray(pdf->trailer, "ID") : NULL);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// 'pdfioFileGetKeywords()' - Get the keywords for a PDF file.
|
||||
//
|
||||
|
||||
const char * // O - Keywords string or `NULL` for none
|
||||
pdfioFileGetKeywords(pdfio_file_t *pdf) // I - PDF file
|
||||
{
|
||||
return (pdf && pdf->info ? pdfioDictGetString(pdf->info->value.value.dict, "Keywords") : NULL);
|
||||
}
|
||||
|
||||
|
||||
@ -586,6 +653,39 @@ pdfioFileGetPage(pdfio_file_t *pdf, // I - PDF file
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// 'pdfioFileGetProducer()' - Get the producer string for a PDF file.
|
||||
//
|
||||
|
||||
const char * // O - Producer string or `NULL` for none
|
||||
pdfioFileGetProducer(pdfio_file_t *pdf) // I - PDF file
|
||||
{
|
||||
return (pdf && pdf->info ? pdfioDictGetString(pdf->info->value.value.dict, "Producer") : NULL);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// 'pdfioFileGetSubject()' - Get the subject for a PDF file.
|
||||
//
|
||||
|
||||
const char * // O - Subject or `NULL` for none
|
||||
pdfioFileGetSubject(pdfio_file_t *pdf) // I - PDF file
|
||||
{
|
||||
return (pdf && pdf->info ? pdfioDictGetString(pdf->info->value.value.dict, "Subject") : NULL);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// 'pdfioFileGetTitle()' - Get the title for a PDF file.
|
||||
//
|
||||
|
||||
const char * // O - Title or `NULL` for none
|
||||
pdfioFileGetTitle(pdfio_file_t *pdf) // I - PDF file
|
||||
{
|
||||
return (pdf && pdf->info ? pdfioDictGetString(pdf->info->value.value.dict, "Title") : NULL);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// 'pdfioFileGetVersion()' - Get the PDF version number for a PDF file.
|
||||
//
|
||||
@ -701,6 +801,88 @@ pdfioFileOpen(
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// 'pdfioFileSetAuthor()' - Set the author for a PDF file.
|
||||
//
|
||||
|
||||
void
|
||||
pdfioFileSetAuthor(pdfio_file_t *pdf, // I - PDF file
|
||||
const char *value) // I - Value
|
||||
{
|
||||
if (pdf && pdf->info)
|
||||
pdfioDictSetString(pdf->info->value.value.dict, "Author", pdfioStringCreate(pdf, value));
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// 'pdfioFileSetCreationDate()' - Set the creation date for a PDF file.
|
||||
//
|
||||
|
||||
void
|
||||
pdfioFileSetCreationDate(
|
||||
pdfio_file_t *pdf, // I - PDF file
|
||||
time_t value) // I - Value
|
||||
{
|
||||
(void)pdf;
|
||||
(void)value;
|
||||
// if (pdf && pdf->info)
|
||||
// pdfioDictSetDate(pdf->info->value.value.dict, "CreationDate", value);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// 'pdfioFileSetCreator()' - Set the creator string for a PDF file.
|
||||
//
|
||||
|
||||
void
|
||||
pdfioFileSetCreator(pdfio_file_t *pdf, // I - PDF file
|
||||
const char *value)// I - Value
|
||||
{
|
||||
if (pdf && pdf->info)
|
||||
pdfioDictSetString(pdf->info->value.value.dict, "Creator", pdfioStringCreate(pdf, value));
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// 'pdfioFileSetKeywords()' - Set the keywords string for a PDF file.
|
||||
//
|
||||
|
||||
void
|
||||
pdfioFileSetKeywords(
|
||||
pdfio_file_t *pdf, // I - PDF file
|
||||
const char *value) // I - Value
|
||||
{
|
||||
if (pdf && pdf->info)
|
||||
pdfioDictSetString(pdf->info->value.value.dict, "Keywords", pdfioStringCreate(pdf, value));
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// 'pdfioFileSetSubject()' - Set the subject for a PDF file.
|
||||
//
|
||||
|
||||
void
|
||||
pdfioFileSetSubject(pdfio_file_t *pdf, // I - PDF file
|
||||
const char *value)// I - Value
|
||||
{
|
||||
if (pdf && pdf->info)
|
||||
pdfioDictSetString(pdf->info->value.value.dict, "Subject", pdfioStringCreate(pdf, value));
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// 'pdfioFileSetTitle()' - Set the title for a PDF file.
|
||||
//
|
||||
|
||||
void
|
||||
pdfioFileSetTitle(pdfio_file_t *pdf, // I - PDF file
|
||||
const char *value) // I - Value
|
||||
{
|
||||
if (pdf && pdf->info)
|
||||
pdfioDictSetString(pdf->info->value.value.dict, "Title", pdfioStringCreate(pdf, value));
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// '_pdfioObjAdd()' - Add an object to a file.
|
||||
//
|
||||
|
@ -221,7 +221,7 @@ struct _pdfio_file_s // PDF file structure
|
||||
off_t bufpos; // Position in file for start of buffer
|
||||
pdfio_dict_t *trailer; // Trailer dictionary
|
||||
pdfio_obj_t *root; // Root object/dictionary
|
||||
pdfio_obj_t *info; // Information object/dictionary
|
||||
pdfio_obj_t *info; // Information object
|
||||
pdfio_obj_t *pages_root; // Root pages object
|
||||
pdfio_obj_t *encrypt; // Encryption object/dictionary
|
||||
pdfio_obj_t *cp1252_obj, // CP1252 font encoding object
|
||||
|
13
pdfio.h
13
pdfio.h
@ -155,14 +155,27 @@ extern pdfio_obj_t *pdfioFileCreateObj(pdfio_file_t *pdf, pdfio_dict_t *dict) PD
|
||||
// TODO: Add number, array, string, etc. versions of pdfioFileCreateObject?
|
||||
extern pdfio_stream_t *pdfioFileCreatePage(pdfio_file_t *pdf, pdfio_dict_t *dict) PDFIO_PUBLIC;
|
||||
extern pdfio_obj_t *pdfioFileFindObj(pdfio_file_t *pdf, size_t number) PDFIO_PUBLIC;
|
||||
extern const char *pdfioFileGetAuthor(pdfio_file_t *pdf) PDFIO_PUBLIC;
|
||||
extern time_t pdfioFileGetCreationDate(pdfio_file_t *pdf) PDFIO_PUBLIC;
|
||||
extern const char *pdfioFileGetCreator(pdfio_file_t *pdf) PDFIO_PUBLIC;
|
||||
extern pdfio_array_t *pdfioFileGetID(pdfio_file_t *pdf) PDFIO_PUBLIC;
|
||||
extern const char *pdfioFileGetKeywords(pdfio_file_t *pdf) PDFIO_PUBLIC;
|
||||
extern const char *pdfioFileGetName(pdfio_file_t *pdf) PDFIO_PUBLIC;
|
||||
extern size_t pdfioFileGetNumObjs(pdfio_file_t *pdf) PDFIO_PUBLIC;
|
||||
extern size_t pdfioFileGetNumPages(pdfio_file_t *pdf) PDFIO_PUBLIC;
|
||||
extern pdfio_obj_t *pdfioFileGetObj(pdfio_file_t *pdf, size_t n) PDFIO_PUBLIC;
|
||||
extern pdfio_obj_t *pdfioFileGetPage(pdfio_file_t *pdf, size_t n) PDFIO_PUBLIC;
|
||||
extern const char *pdfioFileGetProducer(pdfio_file_t *pdf) PDFIO_PUBLIC;
|
||||
extern const char *pdfioFileGetSubject(pdfio_file_t *pdf) PDFIO_PUBLIC;
|
||||
extern const char *pdfioFileGetTitle(pdfio_file_t *pdf) PDFIO_PUBLIC;
|
||||
extern const char *pdfioFileGetVersion(pdfio_file_t *pdf) PDFIO_PUBLIC;
|
||||
extern pdfio_file_t *pdfioFileOpen(const char *filename, pdfio_error_cb_t error_cb, void *error_data) PDFIO_PUBLIC;
|
||||
extern void pdfioFileSetAuthor(pdfio_file_t *pdf, const char *value) PDFIO_PUBLIC;
|
||||
extern void pdfioFileSetCreationDate(pdfio_file_t *pdf, time_t value) PDFIO_PUBLIC;
|
||||
extern void pdfioFileSetCreator(pdfio_file_t *pdf, const char *value) PDFIO_PUBLIC;
|
||||
extern void pdfioFileSetKeywords(pdfio_file_t *pdf, const char *value) PDFIO_PUBLIC;
|
||||
extern void pdfioFileSetSubject(pdfio_file_t *pdf, const char *value) PDFIO_PUBLIC;
|
||||
extern void pdfioFileSetTitle(pdfio_file_t *pdf, const char *value) PDFIO_PUBLIC;
|
||||
|
||||
extern bool pdfioObjClose(pdfio_obj_t *obj) PDFIO_PUBLIC;
|
||||
extern pdfio_obj_t *pdfioObjCopy(pdfio_file_t *pdf, pdfio_obj_t *srcobj) PDFIO_PUBLIC;
|
||||
|
@ -352,15 +352,16 @@
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
CODE_SIGN_IDENTITY = "Developer ID Application";
|
||||
COPY_PHASE_STRIP = NO;
|
||||
CURRENT_PROJECT_VERSION = 1.0;
|
||||
CURRENT_PROJECT_VERSION = 0.2;
|
||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
ENABLE_TESTABILITY = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu11;
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
GCC_PREPROCESSOR_DEFINITIONS = (
|
||||
"DEBUG=1",
|
||||
"$(inherited)",
|
||||
"DEBUG=1",
|
||||
"'PDFIO_VERSION=\"$(CURRENT_PROJECT_VERSION)\"'",
|
||||
);
|
||||
GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES;
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
@ -429,13 +430,17 @@
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
CODE_SIGN_IDENTITY = "Developer ID Application";
|
||||
COPY_PHASE_STRIP = NO;
|
||||
CURRENT_PROJECT_VERSION = 1.0;
|
||||
CURRENT_PROJECT_VERSION = 0.2;
|
||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||
ENABLE_HARDENED_RUNTIME = YES;
|
||||
ENABLE_NS_ASSERTIONS = NO;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu11;
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
GCC_PREPROCESSOR_DEFINITIONS = (
|
||||
"$(inherited)",
|
||||
"'PDFIO_VERSION=\"$(CURRENT_PROJECT_VERSION)\"'",
|
||||
);
|
||||
GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES;
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES;
|
||||
|
Loading…
x
Reference in New Issue
Block a user