11

Is there anyway to use unicode strings (most probably in UTF-8, but could be any encoding) in PostScript?

So far, i've been using this function to transforms fonts to Latin1 encoding:

/latinize {
  findfont
  dup length dict begin
  { 1 index /FID ne {def}{pop pop} ifelse }forall
  /Encoding ISOLatin1Encoding def
  currentdict
  end
  definefont pop
}bind def

/HelveLat /Helvetica latinize
/HelveLatbold /Helvetica-Bold latinize

but i really don't like it.

Javier
  • 60,510
  • 8
  • 78
  • 126

2 Answers2

6

Not really or in any simple "out of the box" way. See this FAQ entry for details.

jwd
  • 10,837
  • 3
  • 43
  • 67
Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
  • tks, it's really awkward, and something plaftorm-dependent (on top of font-dependent); but so far it's the only step in the right direction i've seen – Javier May 28 '09 at 14:29
2

This may or may not fit your bill, but the interpreter that I wrote (xpost) uses Cairo for all its graphics and font functions, including show. So whatever support Cairo has to offer, xpost doesn't get in the way. But before you get too excited, it's a one-man project, and doesn't quite offer full Level-1 Postscript yet.

Edit: The newest version does not support this. Here is the last version that did (listing).


Here's my C code for the show operator itself.

OPFN_ void show(state *st, object s) {
    char str[s.u.c.n+1];
    memcpy(str, STR(s), s.u.c.n); str[s.u.c.n] = '\0';
    //printf("showing (%s)\n", str);
    if (st->cr) {
        cairo_show_text(st->cr, str);
        cairo_surface_flush(st->surface);
        XFlush(st->dis);
    }
}

And from the Cairo docs:

cairo_show_text ()

void cairo_show_text (cairo_t *cr,
const char *utf8);

A drawing operator that generates the shape from a string of UTF-8 characters, rendered according to the current font_face, font_size (font_matrix), and font_options.

This function first computes a set of glyphs for the string of text. The first glyph is placed so that its origin is at the current point. The origin of each subsequent glyph is offset from that of the previous glyph by the advance values of the previous glyph.

After this call the current point is moved to the origin of where the next glyph would be placed in this same progression. That is, the current point will be at the origin of the final glyph offset by its advance values. This allows for easy display of a single logical string with multiple calls to cairo_show_text().

Note: The cairo_show_text() function call is part of what the cairo designers call the "toy" text API. It is convenient for short demos and simple programs, but it is not expected to be adequate for serious text-using applications. See cairo_show_glyphs() for the "real" text display API in cairo.

http://www.cairographics.org/manual/cairo-text.html#cairo-show-text

So it's UTF-8 in Postscript, near as I can figure! :)

luser droog
  • 18,988
  • 3
  • 53
  • 105
  • well, that's nice; but only means that xpost assumes text is UTF-8 (a good choice!). It doesn't help me to use Unicode text in PS documents that would go to printer (or get distilled into PDF) – Javier Sep 21 '12 at 22:11