diff --git a/CHANGES.md b/CHANGES.md index 6d42de7..93c3e4d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -14,6 +14,8 @@ v1.6.0 - YYYY-MM-DD to a PDF file (Issue #104) - Added `pdfioFileCreateFontObjFromData` function for embedding fonts in memory (Issue #120) +- Added `pdfioFileGetLanguage` and `pdfioFileSetLanguage` functions for getting + and setting the default/primary language of a PDF file (Issue #124) - Now add default grayscale, RGB, and CMYK profile resources to pages as needed (Issue #104) diff --git a/doc/pdfio.3 b/doc/pdfio.3 index e6b6e37..a0f1b17 100644 --- a/doc/pdfio.3 +++ b/doc/pdfio.3 @@ -4260,6 +4260,21 @@ const char * pdfioFileGetKeywords ( pdfio_file_t *pdf ); .fi +.SS pdfioFileGetLanguage +Get the language metadata for a PDF file. +.PP +.nf +const char * pdfioFileGetLanguage ( + pdfio_file_t *pdf +); +.fi +.PP +This function gets the (primary/default) language metadata, if any, for a PDF +file. The returned string is an IETF BCP 47 language tag of the form +"lang-REGION". For example, the string "en-CA" specifies Canadian English +and the string "fr-CA" specifies Canadian French. + + .SS pdfioFileGetModificationDate Get the most recent modification date for a PDF file. .PP @@ -4415,6 +4430,22 @@ void pdfioFileSetKeywords ( const char *value ); .fi +.SS pdfioFileSetLanguage +Set the language metadata for a PDF file. +.PP +.nf +void pdfioFileSetLanguage ( + pdfio_file_t *pdf, + const char *value +); +.fi +.PP +This function sets the (primary/default) language metadata for a PDF file. +The "value" argument is an IETF BCP 47 language tag string of the form +"lang-REGION". For example, the string "en-CA" specifies Canadian English +and the string "fr-CA" specifies Canadian French. + + .SS pdfioFileSetModificationDate Set the modification date for a PDF file. .PP diff --git a/doc/pdfio.html b/doc/pdfio.html index 03f0b51..a586517 100644 --- a/doc/pdfio.html +++ b/doc/pdfio.html @@ -420,6 +420,7 @@ span.string {
  • pdfioFileGetCreator
  • pdfioFileGetID
  • pdfioFileGetKeywords
  • +
  • pdfioFileGetLanguage
  • pdfioFileGetModificationDate
  • pdfioFileGetName
  • pdfioFileGetNumObjs
  • @@ -436,6 +437,7 @@ span.string {
  • pdfioFileSetCreationDate
  • pdfioFileSetCreator
  • pdfioFileSetKeywords
  • +
  • pdfioFileSetLanguage
  • pdfioFileSetModificationDate
  • pdfioFileSetPermissions
  • pdfioFileSetSubject
  • @@ -4592,6 +4594,24 @@ time_t pdfioFileGetCreationDate(pdfio_file_t *pdf);<

    Return Value

    Keywords string or NULL for none

    +

     PDFio 1.6 pdfioFileGetLanguage

    +

    Get the language metadata for a PDF file.

    +

    +const char *pdfioFileGetLanguage(pdfio_file_t *pdf);

    +

    Parameters

    + + + +
    pdfPDF file
    +

    Return Value

    +

    Language or NULL for none

    +

    Discussion

    +

    This function gets the (primary/default) language metadata, if any, for a PDF +file. The returned string is an IETF BCP 47 language tag of the form +"lang-REGION". For example, the string "en-CA" specifies Canadian English +and the string "fr-CA" specifies Canadian French. + +

    pdfioFileGetModificationDate

    Get the most recent modification date for a PDF file.

    @@ -4798,6 +4818,24 @@ writes error messages to stderr.

    value Value +

     PDFio 1.6 pdfioFileSetLanguage

    +

    Set the language metadata for a PDF file.

    +

    +void pdfioFileSetLanguage(pdfio_file_t *pdf, const char *value);

    +

    Parameters

    + + + + + +
    pdfPDF file
    valueValue
    +

    Discussion

    +

    This function sets the (primary/default) language metadata for a PDF file. +The "value" argument is an IETF BCP 47 language tag string of the form +"lang-REGION". For example, the string "en-CA" specifies Canadian English +and the string "fr-CA" specifies Canadian French. + +

    pdfioFileSetModificationDate

    Set the modification date for a PDF file.

    diff --git a/pdfio-file.c b/pdfio-file.c index bae8a51..1e15ea3 100644 --- a/pdfio-file.c +++ b/pdfio-file.c @@ -838,6 +838,24 @@ pdfioFileGetKeywords(pdfio_file_t *pdf) // I - PDF file } +// +// 'pdfioFileGetLanguage()' - Get the language metadata for a PDF file. +// +// This function gets the (primary/default) language metadata, if any, for a PDF +// file. The returned string is an IETF BCP 47 language tag of the form +// "lang-REGION". For example, the string "en-CA" specifies Canadian English +// and the string "fr-CA" specifies Canadian French. +// +// @since PDFio 1.6@ +// + +const char * // O - Language or `NULL` for none +pdfioFileGetLanguage(pdfio_file_t *pdf) // I - PDF file +{ + return (pdfioDictGetString(pdfioFileGetCatalog(pdf), "Lang")); +} + + // // 'pdfioFileGetModificationDate()' - Get the most recent modification date for a PDF file. // @@ -1178,6 +1196,26 @@ pdfioFileSetKeywords( } +// +// 'pdfioFileSetLanguage()' - Set the language metadata for a PDF file. +// +// This function sets the (primary/default) language metadata for a PDF file. +// The "value" argument is an IETF BCP 47 language tag string of the form +// "lang-REGION". For example, the string "en-CA" specifies Canadian English +// and the string "fr-CA" specifies Canadian French. +// +// @since PDFio 1.6@ +// + +void +pdfioFileSetLanguage( + pdfio_file_t *pdf, // I - PDF file + const char *value) // I - Value +{ + pdfioDictSetString(pdfioFileGetCatalog(pdf), "Lang", value); +} + + // // 'pdfioFileSetModificationDate()' - Set the modification date for a PDF file. // diff --git a/pdfio.h b/pdfio.h index be266d9..4e19072 100644 --- a/pdfio.h +++ b/pdfio.h @@ -201,6 +201,7 @@ 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 *pdfioFileGetLanguage(pdfio_file_t *pdf) _PDFIO_PUBLIC; extern time_t pdfioFileGetModificationDate(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; @@ -217,6 +218,7 @@ extern void pdfioFileSetAuthor(pdfio_file_t *pdf, const char *value) _PDFIO_PUB 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 pdfioFileSetLanguage(pdfio_file_t *pdf, const char *value) _PDFIO_PUBLIC; extern void pdfioFileSetModificationDate(pdfio_file_t *pdf, time_t value) _PDFIO_PUBLIC; extern bool pdfioFileSetPermissions(pdfio_file_t *pdf, pdfio_permission_t permissions, pdfio_encryption_t encryption, const char *owner_password, const char *user_password) _PDFIO_PUBLIC; extern void pdfioFileSetSubject(pdfio_file_t *pdf, const char *value) _PDFIO_PUBLIC; diff --git a/pdfio1.def b/pdfio1.def index 722364d..c38ec32 100644 --- a/pdfio1.def +++ b/pdfio1.def @@ -212,6 +212,7 @@ pdfioFileGetCreationDate pdfioFileGetCreator pdfioFileGetID pdfioFileGetKeywords +pdfioFileGetLanguage pdfioFileGetModificationDate pdfioFileGetName pdfioFileGetNumObjs @@ -228,6 +229,7 @@ pdfioFileSetAuthor pdfioFileSetCreationDate pdfioFileSetCreator pdfioFileSetKeywords +pdfioFileSetLanguage pdfioFileSetModificationDate pdfioFileSetPermissions pdfioFileSetSubject diff --git a/testpdfio.c b/testpdfio.c index 562b65e..3c78718 100644 --- a/testpdfio.c +++ b/testpdfio.c @@ -1399,18 +1399,18 @@ read_unit_file(const char *filename, // I - File to read } fputs("pdfioDictGetString(Lang): ", stdout); - if ((s = pdfioDictGetString(catalog, "Lang")) != NULL && !strcmp(s, "en")) + if ((s = pdfioDictGetString(catalog, "Lang")) != NULL && !strcmp(s, "en-CA")) { puts("PASS"); } else if (s) { - printf("FAIL (got '%s', expected 'en')\n", s); + printf("FAIL (got '%s', expected 'en-CA')\n", s); return (1); } else { - puts("FAIL (got NULL, expected 'en')"); + puts("FAIL (got NULL, expected 'en-CA')"); return (1); } @@ -3555,7 +3555,6 @@ write_unit_file( // Set some catalog values... pdfioDictSetName(catalog, "PageLayout", "SinglePage"); pdfioDictSetName(catalog, "PageMode", "UseThumbs"); - pdfioDictSetString(catalog, "Lang", "en"); // Set info values... fputs("pdfioFileGet/SetAuthor: ", stdout); @@ -3609,6 +3608,23 @@ write_unit_file( return (1); } + fputs("pdfioFileGet/SetLanguage: ", stdout); + pdfioFileSetLanguage(outpdf, "en-CA"); + if ((s = pdfioFileGetLanguage(outpdf)) != NULL && !strcmp(s, "en-CA")) + { + puts("PASS"); + } + else if (s) + { + printf("FAIL (got '%s', expected 'en-CA')\n", s); + return (1); + } + else + { + puts("FAIL (got NULL, expected 'en-CA')"); + return (1); + } + fputs("pdfioFileGet/SetSubject: ", stdout); pdfioFileSetSubject(outpdf, "Unit test document"); if ((s = pdfioFileGetSubject(outpdf)) != NULL && !strcmp(s, "Unit test document"))