diff --git a/CHANGES.md b/CHANGES.md index 679fbe4..6e058a6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,9 @@ v1.2.0 (Month DD, YYYY) ----------------------- - Added `pdfioContentTextMeasure` function (Issue #17) +- Added `pdfioContentTextNewLineShow` and `pdfioContentTextNewLineShowf` + functions (Issue #24) +- Renamed `pdfioContentTextNextLine` to `pdfioContentTextNewLine`. - Now use autoconf to configure the PDFio sources (Issue #54) diff --git a/doc/pdfio.3 b/doc/pdfio.3 index e8d913e..872877a 100644 --- a/doc/pdfio.3 +++ b/doc/pdfio.3 @@ -1,4 +1,4 @@ -.TH pdfio 3 "pdf read/write library" "2023-12-04" "pdf read/write library" +.TH pdfio 3 "pdf read/write library" "2023-12-05" "pdf read/write library" .SH NAME pdfio \- pdf read/write library .SH Introduction @@ -1808,14 +1808,49 @@ bool pdfioContentTextMoveTo ( double ty ); .fi -.SS pdfioContentTextNextLine +.SS pdfioContentTextNewLine Move to the next line. .PP .nf -bool pdfioContentTextNextLine ( +bool pdfioContentTextNewLine ( pdfio_stream_t *st ); .fi +.SS pdfioContentTextNewLineShow +Move to the next line and show text. +.PP +.nf +bool pdfioContentTextNewLineShow ( + pdfio_stream_t *st, + double ws, + double cs, + bool unicode, + const char *s +); +.fi +.PP +This function moves to the next line and then shows some text with optional +word and character spacing in a PDF content stream. The "unicode" argument +specifies that the current font maps to full Unicode. The "s" argument +specifies a UTF-8 encoded string. +.SS pdfioContentTextNewLineShowf +Show formatted text. +.PP +.nf +bool pdfioContentTextNewLineShowf ( + pdfio_stream_t *st, + double ws, + double cs, + bool unicode, + const char *format, + ... +); +.fi +.PP +This function moves to the next line and shows some formatted text with +optional word and character spacing in a PDF content stream. The "unicode" +argument specifies that the current font maps to full Unicode. The "format" +argument specifies a UTF-8 encoded \fBprintf\fR-style format string. .SS pdfioContentTextShow Show text. .PP diff --git a/doc/pdfio.html b/doc/pdfio.html index 7d4a8eb..92a93cb 100644 --- a/doc/pdfio.html +++ b/doc/pdfio.html @@ -345,7 +345,9 @@ span.string {
  • pdfioContentTextMeasure
  • pdfioContentTextMoveLine
  • pdfioContentTextMoveTo
  • -
  • pdfioContentTextNextLine
  • +
  • pdfioContentTextNewLine
  • +
  • pdfioContentTextNewLineShow
  • +
  • pdfioContentTextNewLineShowf
  • pdfioContentTextShow
  • pdfioContentTextShowJustified
  • pdfioContentTextShowf
  • @@ -2055,10 +2057,10 @@ bool pdfioContentTextMoveTo(pdfio_stream_t *st, do

    Return Value

    true on success, false on failure

    -

    pdfioContentTextNextLine

    +

    pdfioContentTextNewLine

    Move to the next line.

    -bool pdfioContentTextNextLine(pdfio_stream_t *st);

    +bool pdfioContentTextNewLine(pdfio_stream_t *st);

    Parameters

    @@ -2066,6 +2068,56 @@ bool pdfioContentTextNextLine(pdfio_stream_t *st);
    st

    Return Value

    true on success, false on failure

    +

    pdfioContentTextNewLineShow

    +

    Move to the next line and show text.

    +

    +bool pdfioContentTextNewLineShow(pdfio_stream_t *st, double ws, double cs, bool unicode, const char *s);

    +

    Parameters

    + + + + + + + + + + + +
    stStream
    wsWord spacing or 0.0 for none
    csCharacter spacing or 0.0 for none
    unicodeUnicode text?
    sString to show
    +

    Return Value

    +

    true on success, false on failure

    +

    Discussion

    +

    This function moves to the next line and then shows some text with optional +word and character spacing in a PDF content stream. The "unicode" argument +specifies that the current font maps to full Unicode. The "s" argument +specifies a UTF-8 encoded string.

    +

    pdfioContentTextNewLineShowf

    +

    Show formatted text.

    +

    +bool pdfioContentTextNewLineShowf(pdfio_stream_t *st, double ws, double cs, bool unicode, const char *format, ...);

    +

    Parameters

    + + + + + + + + + + + + + +
    stStream
    wsWord spacing or 0.0 for none
    csCharacter spacing or 0.0 for none
    unicodeUnicode text?
    formatprintf-style format string
    ...Additional arguments as needed
    +

    Return Value

    +

    true on success, false on failure

    +

    Discussion

    +

    This function moves to the next line and shows some formatted text with +optional word and character spacing in a PDF content stream. The "unicode" +argument specifies that the current font maps to full Unicode. The "format" +argument specifies a UTF-8 encoded printf-style format string.

    pdfioContentTextShow

    Show text.

    @@ -2125,9 +2177,9 @@ bool pdfioContentTextShowf(pdfio_stream_t *st, boo

    Return Value

    Show formatted text.

    -

    This function shows some text in a PDF content stream. The "unicode" argument -specifies that the current font maps to full Unicode. The "format" argument -specifies a UTF-8 encoded printf-style format string.

    +

    This function shows some formatted text in a PDF content stream. The +"unicode" argument specifies that the current font maps to full Unicode. +The "format" argument specifies a UTF-8 encoded printf-style format string.

    pdfioDictCopy

    Copy a dictionary to a PDF file.

    diff --git a/pdfio-content.c b/pdfio-content.c index 8517166..7346487 100644 --- a/pdfio-content.c +++ b/pdfio-content.c @@ -1187,17 +1187,97 @@ pdfioContentTextMoveTo( // -// 'pdfioContentTextNextLine()' - Move to the next line. +// 'pdfioContentTextNewLine()' - Move to the next line. // bool // O - `true` on success, `false` on failure -pdfioContentTextNextLine( +pdfioContentTextNewLine( pdfio_stream_t *st) // I - Stream { return (pdfioStreamPuts(st, "T*\n")); } +// +// 'pdfioContentTextNewLineShow()' - Move to the next line and show text. +// +// This function moves to the next line and then shows some text with optional +// word and character spacing in a PDF content stream. The "unicode" argument +// specifies that the current font maps to full Unicode. The "s" argument +// specifies a UTF-8 encoded string. +// + +bool // O - `true` on success, `false` on failure +pdfioContentTextNewLineShow( + pdfio_stream_t *st, // I - Stream + double ws, // I - Word spacing or `0.0` for none + double cs, // I - Character spacing or `0.0` for none + bool unicode, // I - Unicode text? + const char *s) // I - String to show +{ + bool newline = false; // New line? + char op; // Text operator + + + // Write word and/or character spacing as needed... + if (ws > 0.0 || cs > 0.0) + { + // Use " operator to show text with word and character spacing... + if (!pdfioStreamPrintf(st, "%g %g", ws, cs)) + return (false); + + op = '\"'; + } + else + { + // Use ' operator to show text with the defaults... + op = '\''; + } + + // Write the string... + if (!write_string(st, unicode, s, &newline)) + return (false); + + // Draw it... + if (newline) + return (pdfioStreamPrintf(st, "%c T*\n", op)); + else + return (pdfioStreamPrintf(st, "%c\n", op)); +} + + +// +// 'pdfioContentTextNewLineShowf()' - Show formatted text. +// +// This function moves to the next line and shows some formatted text with +// optional word and character spacing in a PDF content stream. The "unicode" +// argument specifies that the current font maps to full Unicode. The "format" +// argument specifies a UTF-8 encoded `printf`-style format string. +// + +bool // O - `true` on success, `false` on failure +pdfioContentTextNewLineShowf( + pdfio_stream_t *st, // I - Stream + double ws, // I - Word spacing or `0.0` for none + double cs, // I - Character spacing or `0.0` for none + bool unicode, // I - Unicode text? + const char *format, // I - `printf`-style format string + ...) // I - Additional arguments as needed +{ + char buffer[8192]; // Text buffer + va_list ap; // Argument pointer + + + // Format the string... + va_start(ap, format); + vsnprintf(buffer, sizeof(buffer), format, ap); + va_end(ap); + + // Show it... + return (pdfioContentTextNewLineShow(st, ws, cs, unicode, buffer)); +} + + // // 'pdfioContentTextShow()' - Show text. // @@ -1230,9 +1310,9 @@ pdfioContentTextShow( // // 'pdfioContentTextShowf()' - Show formatted text. // -// This function shows some text in a PDF content stream. The "unicode" argument -// specifies that the current font maps to full Unicode. The "format" argument -// specifies a UTF-8 encoded `printf`-style format string. +// This function shows some formatted text in a PDF content stream. The +// "unicode" argument specifies that the current font maps to full Unicode. +// The "format" argument specifies a UTF-8 encoded `printf`-style format string. // bool diff --git a/pdfio-content.h b/pdfio-content.h index 24403d2..301811d 100644 --- a/pdfio-content.h +++ b/pdfio-content.h @@ -118,7 +118,9 @@ extern bool pdfioContentTextEnd(pdfio_stream_t *st) _PDFIO_PUBLIC; extern double pdfioContentTextMeasure(pdfio_obj_t *font, const char *s, double size) _PDFIO_PUBLIC; extern bool pdfioContentTextMoveLine(pdfio_stream_t *st, double tx, double ty) _PDFIO_PUBLIC; extern bool pdfioContentTextMoveTo(pdfio_stream_t *st, double tx, double ty) _PDFIO_PUBLIC; -extern bool pdfioContentTextNextLine(pdfio_stream_t *st) _PDFIO_PUBLIC; +extern bool pdfioContentTextNewLine(pdfio_stream_t *st) _PDFIO_PUBLIC; +extern bool pdfioContentTextNewLineShow(pdfio_stream_t *st, double ws, double cs, bool unicode, const char *s) _PDFIO_PUBLIC; +extern bool pdfioContentTextNewLineShowf(pdfio_stream_t *st, double ws, double cs, bool unicode, const char *format, ...) _PDFIO_PUBLIC _PDFIO_FORMAT(5,6); extern bool pdfioContentTextShow(pdfio_stream_t *st, bool unicode, const char *s) _PDFIO_PUBLIC; extern bool pdfioContentTextShowf(pdfio_stream_t *st, bool unicode, const char *format, ...) _PDFIO_PUBLIC _PDFIO_FORMAT(3,4); extern bool pdfioContentTextShowJustified(pdfio_stream_t *st, bool unicode, size_t num_fragments, const double *offsets, const char * const *fragments) _PDFIO_PUBLIC; diff --git a/pdfio1.def b/pdfio1.def index c487d01..82a69f6 100644 --- a/pdfio1.def +++ b/pdfio1.def @@ -141,7 +141,9 @@ pdfioContentTextEnd pdfioContentTextMeasure pdfioContentTextMoveLine pdfioContentTextMoveTo -pdfioContentTextNextLine +pdfioContentTextNewLine +pdfioContentTextNewLineShow +pdfioContentTextNewLineShowf pdfioContentTextShow pdfioContentTextShowJustified pdfioContentTextShowf