michaelrsweet / pdfio

PDFio is a simple C library for reading and writing PDF files.
https://www.msweet.org/pdfio
Apache License 2.0
199 stars 44 forks source link

Implement pdf text quote operators (' and ") #24

Closed zacii7 closed 11 months ago

zacii7 commented 3 years ago

Single- and double quote operators are currently missing in pdfio

as per pdf specs,

(sometext)' is equivalent to T* (sometext)Tj

and

2 1 (sometext)" is equivalent to 2 Tw 1 Tc (sometext)'

michaelrsweet commented 3 years ago

Hmm, will consider this for a future feature release after 1.0. There is still a lot of work to do with text support...

zacii7 commented 3 years ago

Fair enough

I figured the implementation should be fairly straight forward given the routines you already have in place, so it shouldn't add too much maintenance burden. And they can't really be added externally, because they rely on the internal write_string function.

  bool pdfioContentTextNewLineShow(pdfio_stream_t *st,bool unicode,char *s) {
    bool newline = false;
    if (!write_string(st, unicode, s, &newline))
      return (false);
    return(pdfioStreamPuts(st, "'\n"));
  }
  bool pdfioContentTextNewLineShowSpaced(pdfio_stream_t *st,double ws,double cs,bool unicode,char *s) {
    bool newline = false;

    if (!pdfioStreamPrintf(st, "%g %g", ws,cs)) {
      return (false);
    }

    if (!write_string(st, unicode, s, &newline))
      return (false);
    return(pdfioStreamPuts(st, "\"\n"));
  }
michaelrsweet commented 11 months ago

Opted to add a single set of APIs to cover both operators:

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);

[master 7ff051f] Add pdfioContentTextNewLineShow/f functions (Issue #24)