diff options
| author | Manolo Gouy <Manolo> | 2010-06-24 08:55:04 +0000 |
|---|---|---|
| committer | Manolo Gouy <Manolo> | 2010-06-24 08:55:04 +0000 |
| commit | a40166931e13962823938bc7aa60b97b82d27a82 (patch) | |
| tree | 7dc2c52509948914fd225cf62446f6fddbad2119 /src/Fl_PostScript.cxx | |
| parent | 449b99dd86c7bdc08f98dd603ee6d18ff1a025dd (diff) | |
Fl_PostScript.cxx: now outputs correctly all of the latin1 (iso-8859-1) character set
giving support for many latin alphabet-using languages.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7653 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_PostScript.cxx')
| -rw-r--r-- | src/Fl_PostScript.cxx | 53 |
1 files changed, 36 insertions, 17 deletions
diff --git a/src/Fl_PostScript.cxx b/src/Fl_PostScript.cxx index 552740977..ad3f15a8e 100644 --- a/src/Fl_PostScript.cxx +++ b/src/Fl_PostScript.cxx @@ -351,6 +351,23 @@ static const char * prolog_2 = // prolog relevant only if lang_level >1 "end\n" "IDD image GR} bind def\n" +// procedure to modify a font to use ISOLatin1 encoding (iso-8859-1) +// and to keep its name unchanged +"/ToLatin1 { dup findfont dup length dict " +"begin {def} forall /Encoding ISOLatin1Encoding def currentdict end definefont pop } def\n" +// modify all fonts to use ISOLatin1 encoding +"/Helvetica ToLatin1 " +"/Helvetica-Bold ToLatin1 " +"/Helvetica-Oblique ToLatin1 " +"/Helvetica-BoldOblique ToLatin1 \n" +"/Courier ToLatin1 " +"/Courier-Bold ToLatin1 " +"/Courier-Oblique ToLatin1 " +"/Courier-BoldOblique ToLatin1 \n" +"/Times ToLatin1 " +"/Times-Bold ToLatin1 " +"/Times-Italic ToLatin1 " +"/Times-BoldItalic ToLatin1 \n" ; static const char * prolog_2_pixmap = // prolog relevant only if lang_level == 2 for pixmaps @@ -936,24 +953,26 @@ void Fl_PostScript_Graphics_Driver::draw(int angle, const char *str, int n, int fprintf(output, "GR\n"); } -void Fl_PostScript_Graphics_Driver::transformed_draw(const char* str, int n, double x, double y){ - if (!n || !str || !*str)return; +// outputs in PostScript a UTF8 string replacing non-Latin1 characters by ? +// and using the same width in points as on display +void Fl_PostScript_Graphics_Driver::transformed_draw(const char* str, int n, double x, double y) { + int len; + if (!n || !str || !*str) return; + const char *last = str + n; + // compute display width of string fprintf(output,"%g (", fl_width(str, n)); - int i=1; - for (int j=0;j<n;j++){ - if (i>240){ - fprintf(output, "\\\n"); - i=0; - } - i++; - switch (*str) { - case '(': case ')': case '\\' : - putc('\\' , output); - /* fallthrough */ - default: - putc(*str , output); - } - str++; + while (str < last) { + // Extract each unicode character of string. + // Until 0xFF, UTF codes coincide with iso-Latin1 (iso-8859-1) + unsigned utf = fl_utf8decode(str, last, &len); + str += len; + if (utf > 0xFF) { + utf = '?'; // replace non Latin-1 unicodes by ? + } + else if (utf == '(' || utf == ')' || utf == '\\') { + putc('\\' , output); // these chars need be escaped + } + putc(utf, output); // output the latin character } fprintf(output, ") %g %g show_pos_width\n", x, y); } |
