DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.

[STR New]

Link: http://www.fltk.org/str.php?L2378
Version: 1.3.0





Link: http://www.fltk.org/str.php?L2378
Version: 1.3.0
Index: src/Fl_PostScript.cxx
===================================================================
--- src/Fl_PostScript.cxx       (revision 7684)
+++ src/Fl_PostScript.cxx       (working copy)
@@ -330,8 +330,6 @@
 "IDD image GR} bind def\n"
 
 // gray image dict 
-
-
 "/GII {GS /inter exch def /py exch def /px exch def /sy exch def /sx exch def 
\n"
 "translate \n"
 "sx sy scale\n"
@@ -351,23 +349,104 @@
 "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"
+// Create a custom PostScript font that combines characters from PostScript 
standard text and Symbol fonts
+// The encoding of this custom font is as follows:
+// 0-007F     coincides with Unicode, that is to ASCII + Latin-1
+// 0100-017F  coincides with Unicode, that is to Latin Extended-A
+// 0180-01A6  encodes miscellaneous characters present in PostScript standard 
text fonts
+// 01A7-      encodes characters from the Symbol font in a custom order
+
+// use ISOLatin1Encoding for all text fonts
+"/ToISO { dup findfont dup length dict copy begin /Encoding ISOLatin1Encoding 
def currentdict end definefont pop } def\n"
+"/Helvetica ToISO /Helvetica-Bold ToISO /Helvetica-Oblique ToISO 
/Helvetica-BoldOblique ToISO \n"
+"/Courier ToISO /Courier-Bold ToISO /Courier-Oblique ToISO 
/Courier-BoldOblique ToISO \n"
+"/Times-Roman ToISO /Times-Bold ToISO /Times-Italic ToISO /Times-BoldItalic 
ToISO \n"
+
+// define LatinExtA, the encoding of Latin-extended-A + some additional 
characters
+// see http://www.adobe.com/devnet/opentype/archives/glyphlist.txt for their 
names
+"/LatinExtA \n"
+"[ "
+" /Amacron /amacron /Abreve /abreve /Aogonek /aogonek\n" // begin of Latin 
Extended-A code page
+" /Cacute  /cacute  /Ccircumflex  /ccircumflex  /Cdotaccent  /cdotaccent  
/Ccaron  /ccaron \n"
+" /Dcaron  /dcaron   /Dcroat  /dcroat\n"
+" /Emacron  /emacron  /Ebreve  /ebreve  /Edotaccent  /edotaccent  /Eogonek  
/eogonek  /Ecaron  /ecaron\n"
+" /Gcircumflex  /gcircumflex  /Gbreve  /gbreve  /Gdotaccent  /gdotaccent  
/Gcommaaccent  /gcommaaccent \n"
+" /Hcircumflex /hcircumflex  /Hbar  /hbar  \n"
+" /Itilde  /itilde  /Imacron  /imacron  /Ibreve  /ibreve  /Iogonek  /iogonek 
/Idotaccent  /dotlessi  \n"
+" /IJ  /ij  /Jcircumflex  /jcircumflex\n"
+" /Kcommaaccent  /kcommaaccent  /kgreenlandic  \n"
+" /Lacute  /lacute  /Lcommaaccent  /lcommaaccent   /Lcaron  /lcaron  
/Ldotaccent /ldotaccent   /Lslash  /lslash \n"
+" /Nacute  /nacute  /Ncommaaccent  /ncommaaccent  /Ncaron  /ncaron  
/napostrophe  /Eng  /eng  \n"
+" /Omacron  /omacron /Obreve  /obreve  /Ohungarumlaut  /ohungarumlaut  /OE  
/oe \n"
+" /Racute  /racute  /Rcommaaccent  /rcommaaccent  /Rcaron  /rcaron \n"
+" /Sacute /sacute  /Scircumflex  /scircumflex  /Scedilla /scedilla /Scaron  
/scaron \n"
+" /Tcommaaccent  /tcommaaccent  /Tcaron  /tcaron  /Tbar  /tbar \n"
+" /Utilde  /utilde /Umacron /umacron  /Ubreve  /ubreve  /Uring  /uring  
/Uhungarumlaut  /uhungarumlaut  /Uogonek /uogonek \n"
+" /Wcircumflex  /wcircumflex  /Ycircumflex  /ycircumflex  /Ydieresis \n"
+" /Zacute /zacute /Zdotaccent /zdotaccent /Zcaron /zcaron \n"
+" /longs \n" // end of Latin Extended-A code page
+" /florin  /circumflex  /caron  /breve  /dotaccent  /ring \n" // remaining 
characters from PostScript standard text fonts
+" /ogonek  /tilde  /hungarumlaut  /endash /emdash \n"
+" /quoteleft  /quoteright  /quotesinglbase  /quotedblleft  /quotedblright \n"
+" /quotedblbase  /dagger  /daggerdbl  /bullet  /ellipsis \n"
+" /perthousand  /guilsinglleft  /guilsinglright  /fraction  /Euro \n"
+" /trademark /partialdiff  /Delta /summation  /radical \n"
+" /infinity /notequal /lessequal /greaterequal /lozenge \n"
+" /fi /fl /apple \n"
+" ] def \n"
+// deal with alternative PostScript names of some characters
+" /mycharstrings /Helvetica findfont /CharStrings get def\n"
+" /PSname2 { dup mycharstrings exch known {LatinExtA 3 -1 roll 3 -1 roll 
put}{pop pop} ifelse } def \n"
+" 16#20 /Gdot PSname2 16#21 /gdot PSname2 16#30 /Idot PSname2 16#3F /Ldot 
PSname2 16#40 /ldot PSname2 16#7F /slong PSname2 \n"
+
+// proc that gives LatinExtA encoding to a font
+"/ToLatinExtA { findfont dup length dict copy begin /Encoding LatinExtA def 
currentdict end definefont pop } def\n"
+// create Ext-versions of standard fonts that use LatinExtA encoding \n"
+"/HelveticaExt /Helvetica ToLatinExtA \n"
+"/Helvetica-BoldExt /Helvetica-Bold ToLatinExtA /Helvetica-ObliqueExt 
/Helvetica-Oblique ToLatinExtA  \n"
+"/Helvetica-BoldObliqueExt /Helvetica-BoldOblique ToLatinExtA  \n"
+"/CourierExt /Courier ToLatinExtA /Courier-BoldExt /Courier-Bold ToLatinExtA  
\n"
+"/Courier-ObliqueExt /Courier-Oblique ToLatinExtA /Courier-BoldObliqueExt 
/Courier-BoldOblique ToLatinExtA \n"
+"/Times-RomanExt /Times-Roman ToLatinExtA /Times-BoldExt /Times-Bold 
ToLatinExtA  \n"
+"/Times-ItalicExt /Times-Italic ToLatinExtA /Times-BoldItalicExt 
/Times-BoldItalic ToLatinExtA \n"
+
+//define GreekEnc encoding
+"/GreekEnc [ "
+" /Alpha /Beta /Gamma /Delta /Epsilon /Zeta /Eta /Theta /Iota /Kappa /Lambda 
/Mu /Nu /Xi /Omicron \n"
+" /Pi /Rho /Sigma /Tau /Upsilon /Phi /Chi /Psi /Omega  \n"
+" /alpha /beta /gamma /delta /epsilon /zeta /eta /theta /iota /kappa /lambda 
/mu /nu /xi /omicron \n"
+" /pi /rho /sigma1 /sigma /tau /upsilon /phi1 /chi /psi  /omega /theta1 
/Upsilon1 /phi /omega1 \n"
+" /universal /existential /emptyset /gradient /element /notelement /suchthat 
/product "
+" /proportional /angle /logicaland /logicalor /intersection /union /integral 
/therefore /approxequal "
+" /equivalence /propersubset /propersuperset /notsubset /reflexsubset 
/reflexsuperset "
+" /circleplus /circlemultiply /perpendicular /Ifraktur /Rfraktur /aleph "
+" /arrowboth /arrowdblboth /arrowdbldown /arrowdblleft /arrowdblright 
/arrowdblup /arrowdown /arrowleft /arrowright /arrowup "
+" /carriagereturn /club /diamond /heart /spade /weierstrass /angleleft 
/angleright /minute /second \n"
+" ] def \n"
+// set Symbol font encoding to GreekEnc
+"/Symbol dup findfont dup length dict copy begin /Encoding GreekEnc def 
currentdict end definefont pop \n"
+
+// proc to create a Type 0 font with 2-byte encoding 
+// that merges a text font with ISO encoding + same font with LatinExtA 
encoding + the Symbol font with GreekEnc encoding
+"/To2byte { 6 dict begin /FontType 0 def \n"
+"/FDepVector 3 1 roll findfont exch findfont /Symbol findfont 3 array astore 
def \n"
+"/FontMatrix [1  0  0  1  0  0] def /FMapType 6 def /Encoding [ 0 1 2 0 ] 
def\n"
+// 100: Hexa count of ISO array; A7: hexa count of LatinExtA array; 66: hexa 
count of GreekEnc array
+"/SubsVector < 01 0100 00A7 0066 > def\n" 
+"currentdict end definefont pop } def\n"
+// create Type 0 versions of standard fonts
+"/Helvetica2B /HelveticaExt /Helvetica To2byte \n"
+"/Helvetica-Bold2B /Helvetica-BoldExt /Helvetica-Bold To2byte \n"
+"/Helvetica-Oblique2B /Helvetica-ObliqueExt /Helvetica-Oblique To2byte \n"
+"/Helvetica-BoldOblique2B /Helvetica-BoldObliqueExt /Helvetica-BoldOblique 
To2byte \n"
+"/Courier2B /CourierExt /Courier To2byte \n"
+"/Courier-Bold2B /Courier-BoldExt /Courier-Bold To2byte \n"
+"/Courier-Oblique2B /Courier-ObliqueExt /Courier-Oblique To2byte \n"
+"/Courier-BoldOblique2B /Courier-BoldObliqueExt /Courier-BoldOblique To2byte 
\n"
+"/Times-Roman2B /Times-RomanExt /Times-Roman To2byte \n"
+"/Times-Bold2B /Times-BoldExt /Times-Bold To2byte \n"
+"/Times-Italic2B /Times-ItalicExt /Times-Italic To2byte \n"
+"/Times-BoldItalic2B /Times-BoldItalicExt /Times-BoldItalic To2byte \n"
 ;
 
 static const char * prolog_2_pixmap =  // prolog relevant only if lang_level 
== 2 for pixmaps
@@ -887,21 +966,21 @@
 };
 
 static const char *_fontNames[] = {
-"Helvetica",
-"Helvetica-Bold",
-"Helvetica-Oblique",
-"Helvetica-BoldOblique",
-"Courier",
-"Courier-Bold",
-"Courier-Oblique",
-"Courier-BoldOblique",
-"Times",
-"Times-Bold",
-"Times-Italic",
-"Times-BoldItalic",
+"Helvetica2B", 
+"Helvetica-Bold2B",
+"Helvetica-Oblique2B",
+"Helvetica-BoldOblique2B",
+"Courier2B",
+"Courier-Bold2B",
+"Courier-Oblique2B",
+"Courier-BoldOblique2B",
+"Times-Roman2B",
+"Times-Bold2B",
+"Times-Italic2B",
+"Times-BoldItalic2B",
 "Symbol",
-"Courier",
-"Courier-Bold",
+"Courier2B",
+"Courier-Bold2B",
 "ZapfDingbats"
 };
 
@@ -941,28 +1020,88 @@
   fprintf(output, "GR\n");
 }
 
-// outputs in PostScript a UTF8 string replacing non-Latin1 characters by ?
+
+static int is_in_table(unsigned utf) {
+  int i;
+  static int extra_table_roman[] = { // unicodes/*names*/ of other characters 
from PostScript standard fonts
+    0x192/*florin*/, 0x2C6/*circumflex*/, 0x2C7/*caron*/, 
+    0x2D8/*breve*/, 0x2D9/*dotaccent*/, 0x2DA/*ring*/, 0x2DB/*ogonek*/, 
0x2DC/*tilde*/, 0x2DD/*hungarumlaut*/,
+    0x2013/*endash*/, 0x2014/*emdash*/, 0x2018/*quoteleft*/, 
0x2019/*quoteright*/, 
+    0x201A/*quotesinglbase*/, 0x201C/*quotedblleft*/, 0x201D/*quotedblright*/, 
0x201E/*quotedblbase*/, 
+    0x2020/*dagger*/, 0x2021/*daggerdbl*/, 0x2022/*bullet*/,
+    0x2026/*ellipsis*/, 0x2030/*perthousand*/, 0x2039/*guilsinglleft*/, 
0x203A/*guilsinglright*/, 
+    0x2044/*fraction*/, 0x20AC/*Euro*/, 0x2122/*trademark*/, 
+    0x2202/*partialdiff*/, 0x2206/*Delta*/, 0x2211/*summation*/, 
0x221A/*radical*/,
+    0x221E/*infinity*/, 0x2260/*notequal*/, 0x2264/*lessequal*/, 
+    0x2265/*greaterequal*/, 
+    0x25CA/*lozenge*/, 0xFB01/*fi*/, 0xFB02/*fl*/,
+    0xF8FF/*apple*/
+  };
+  static int extra_table_symbol[] = { // unicodes/*names*/ of all characters 
of the Symbol PostScript character set
+    0x391/*Alpha*/, 0x392/*Beta*/, 0x393/*Gamma*/, 0x394/*Delta*/, 
0x395/*Epsilon*/ ,
+    0x396/*Zeta*/, 0x397/*Eta*/, 0x398/*Theta*/, 0x399/*Iota*/, 0x39A/*Kappa*/ 
,
+    0x39B/*Lambda*/, 0x39C/*Mu*/, 0x39D/*Nu*/, 0x39E/*Xi*/, 0x39F/*Omicron*/,
+    0x3A0/*Pi*/, 0x3A1/*Rho*/,  0x3A3/*Sigma*/, 0x3A4/*Tau*/, 0x3A5/*Upsilon*/ 
,
+    0x3A6/*Phi*/, 0x3A7/*Chi*/, 0x3A8/*Psi*/, 0x3A9/*Omega*/,
+    0x3B1/*alpha*/, 0x3B2/*beta*/, 0x3B3/*gamma*/, 0x3B4/*delta*/ ,
+    0x3B5/*epsilon*/, 0x3B6/*zeta*/, 0x3B7/*eta*/, 0x3B8/*theta*/, 
0x3B9/*iota*/, 
+    0x3BA/*kappa*/, 0x3BB/*lambda*/, 0x3BC/*mu*/, 0x3BD/*nu*/, 0x3BE/*xi*/, 
0x3BF/*omicron*/,
+    0x3C0/*pi*/, 0x3C1/*rho*/, 0x3C2/*sigma1*/, 0x3C3/*sigma*/, 0x3C4/*tau*/ ,
+    0x3C5/*upsilon*/, 0x3C6/*phi1*/, 0x3C7/*chi*/, 0x3C8/*psi*/, 
0x3C9/*omega*/,
+    0x3D1/*theta1*/, 0x3D2/*Upsilon1*/, 0x3D5/*phi*/, 0x3D6/*omega1*/,
+    0x2200/*universal*/, 0x2203/*existential*/, 0x2205/*emptyset*/, 
0X2207/*gradient*/, 0x2208/*element*/, 
+    0x2209/*notelement*/, 0x220D/*suchthat*/, 0x220F/*product*/, 
0x221D/*proportional*/, 0x2220/*angle*/,
+    0x2227/*logicaland*/, 0x2228/*logicalor*/, 0x2229/*intersection*/, 
0x222A/*union*/, 0x222B/*integral*/, 
+    0x2234/*therefore*/, 0x2248/*approxequal*/,0x2261/*equivalence*/, 
0x2282/*propersubset*/, 0x2283/*propersuperset*/, 
+    
0x2284/*notsubset*/,0x2286/*reflexsubset*/,0x2287/*reflexsuperset*/,0x2295/*circleplus*/,
 0x2297/*circlemultiply*/,
+    0x22A5/*perpendicular*/,0x2111/*Ifraktur*/, 0x211C/*Rfraktur*/, 
0x2135/*aleph*/,0x2194/*arrowboth*/, 
+    
0x21D4/*arrowdblboth*/,0x21D3/*arrowdbldown*/,0x21D0/*arrowdblleft*/,0x21D2/*arrowdblright*/,0x21D1/*arrowdblup*/,
 
+    0x2193/*arrowdown*/, 0X2190/*arrowleft*/, 0x2192/*arrowright*/, 
0x2191/*arrowup*/, 0x21B5/*carriagereturn*/, 
+    0x2663/*club*/, 0x2666/*diamond*/, 0x2665/*heart*/, 0x2660/*spade*/, 
0x2118/*weierstrass*/, 
+    0x27E8/*angleleft*/, 0x27E9/*angleright*/, 0x2032/*minute*/, 
0x2033/*second*/
+  };
+  for ( i = 0; i < sizeof(extra_table_roman)/sizeof(int); i++) {
+    if (extra_table_roman[i] == utf) return i + 0x180;
+    }
+  for ( i = 0; i < sizeof(extra_table_symbol)/sizeof(int); i++) {
+    if (extra_table_symbol[i] == utf) return i + 0x1A7;
+  }
+  return 0;
+}
+
+// outputs in PostScript a UTF8 string replacing unknown characters by 
questiondown
 // 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;
+  int len, code;
   if (!n || !str || !*str) return;
   const char *last = str + n;
   // compute display width of string
-  fprintf(output,"%g (", fl_width(str, n));
+  fprintf(output,"%g <", fl_width(str, n));
+  // transforms UTF8 encoding to our custom PostScript encoding as follows:
+  // extract each unicode character
+  // if unicode <= 0x17F, unicode and PostScript codes are identical
+  // if unicode is one of the values listed in extra_table_roman above
+  //    its PostScript code is 0x180 + the character's rank in 
extra_table_roman
+  // if unicode is one of the values listed in extra_table_symbol above
+  //    its PostScript code is 0x1A7 + the character's rank in 
extra_table_roman
+  // if unicode is something else, replace by reverse question mark
+
   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 ?
+    if (utf <= 0x17F) { // until Latin Extended-A
+      ;
       }
-    else if (utf == '(' || utf == ')' || utf == '\\') {
-      putc('\\' , output); // these chars need be escaped
-     }
-    putc(utf, output); // output the latin character
+    else if ( (code = is_in_table(utf)) != 0) { // other handled characters
+      utf = code;
+      }
+    else {
+      utf = 0xBF; // replace other unicodes by questiondown
+    }
+    fprintf(output, "%4.4X", utf);
   }
-  fprintf(output, ") %g %g show_pos_width\n", x, y);
+  fprintf(output, "> %g %g show_pos_width\n", x, y);
 }
 
 struct matrix {double a, b, c, d, x, y;};
_______________________________________________
fltk-bugs mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-bugs

Reply via email to