Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unicode in postscript

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.

like image 822
Javier Avatar asked Nov 06 '08 22:11

Javier


2 Answers

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

like image 106
Aaron Digulla Avatar answered Oct 19 '22 18:10

Aaron Digulla


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! :)

like image 38
luser droog Avatar answered Oct 19 '22 16:10

luser droog