Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
View this page
Toggle table of contents sidebar

# `Text`

A `Text` object contains text.

new Text()

  Constructor method.

  Create a new empty text object.

  Returns:

    `Text`.

  EXAMPLE

      var text = new mupdf.Text();

Instance methods

showGlyph(font, transform, glyph, unicode, wmode)

  Add a glyph to the text object.

  Transform is the text matrix, specifying font size and glyph location. For example: `[size,0,0,-size,x,y]`.

  Glyph and unicode may be `-1` for n-to-m cluster mappings. For example, the “fi” ligature would be added in two steps: first the glyph for the ‘fi’ ligature and the unicode value for ‘f’; then glyph `-1` and the unicode value for ‘i’.

  Arguments:

    - font – `Font` object.

    - transform – `[a,b,c,d,e,f]`. The transform matrix.

    - glyph – `Integer`.

    - unicode – `Integer`.

    - wmode – `0` for horizontal writing, and `1` for vertical writing.

  EXAMPLE

      text.showGlyph(new mupdf.Font("Times-Roman"), mupdf.Matrix.identity, 21, 0x66, 0);
      text.showGlyph(new mupdf.Font("Times-Roman"), mupdf.Matrix.identity, -1, 0x69, 0);

showString(font, transform, string)

  Add a simple string to the `Text` object. Will do font substitution if the font does not have all the unicode characters required.

  Arguments:

    - font – `Font` object.

    - transform – `[a,b,c,d,e,f]`. The transform matrix.

    - string – String content for `Text` object.

  EXAMPLE

      text.showString(new mupdf.Font("Times-Roman"), mupdf.Matrix.identity, "Hello");

walk(textWalker)

  Call the `showGlyph` method on the `textWalker` object for each glyph in the text object.

  Arguments:

    - textWalker – The text walker object. A user definable JavaScript object which can be used to trigger your own functions on the text methods.

  EXAMPLE

      text.walk({
          beginSpan: function (font, transform, wmode, bidilevel, markupdirection, language) {
              // ... do whatever ...
          },
          showGlyph: function (font, transform, glyph, unicode, wmode, bidilevel) {
              // ... do whatever ...
          },
          endSpan: function () {
              // ... do whatever ...
          },
      });