static void unicode_subst (int src, int dest, int nr, string fn) { for (int i=0; i<nr; i++) { string csrc = upcase_all ("<#" * as_hexadecimal (src + i) * ">"); string cdest= upcase_all ("<#" * as_hexadecimal (dest + i) * ">"); if (dest + i < 128) cdest= string ((char) (dest + i)); substitution_char (csrc)= cdest; substitution_font (csrc)= fn; csrc= locase_all (csrc); substitution_char (csrc)= cdest; substitution_font (csrc)= fn; csrc= rewrite_math (csrc); substitution_char (csrc)= cdest; substitution_font (csrc)= fn; } }
string uni_upcase_char (string s) { if (N(s) == 1) { unsigned char c= s[0]; if ((c >= 'a' && c <= 'z') || (c >= ((unsigned char) 0xA0) && (c <= ((unsigned char) 0xBF))) || (c >= ((unsigned char) 0xE0))) return string ((char) (c - 0x20)); return s; } else if (starts (s, "<#") && ends (s, ">")) { int code= from_hexadecimal (s (2, N(s) - 1)); if (code >= 0x3AC && code <= 0x3CE) { if (code >= 0x3B1 && code <= 0x3CB) code -= 0x20; else if (code >= 0x3AC && code <= 0x3AC) code -= 0x26; else if (code >= 0x3AD && code <= 0x3AF) code -= 0x25; else if (code >= 0x3CC && code <= 0x3CC) code -= 0x40; else if (code >= 0x3CD && code <= 0x3CE) code -= 0x3f; } else if (code >= 0x450 && code <= 0x45F) code -= 0x50; else if (code >= 0x430 && code <= 0x44F) code -= 0x20; else if (code >= 0x460 && code <= 0x4FF) { if ((code & 1) == 1) code -= 1; } return "<#" * as_hexadecimal (code) * ">"; } else { init_case_tables (); if (upcase_tab->contains (s)) return upcase_tab[s]; return s; } }
string uni_locase_char (string s) { if (N(s) == 1) { unsigned char c= s[0]; if ((c >= 'A' && c <= 'Z') || (c >= ((unsigned char) 0x80) && (c <= ((unsigned char) 0x9F))) || (c >= ((unsigned char) 0xC0) && (c <= ((unsigned char) 0xDF)))) return string ((char) (c + 0x20)); return s; } else if (starts (s, "<#") && ends (s, ">")) { int code= from_hexadecimal (s (2, N(s) - 1)); if (code >= 0x386 && code <= 0x3AB) { if (code >= 0x391 && code <= 0x3AB) code += 0x20; else if (code >= 0x386 && code <= 0x386) code += 0x26; else if (code >= 0x388 && code <= 0x38A) code += 0x25; else if (code >= 0x38C && code <= 0x38C) code += 0x40; else if (code >= 0x38E && code <= 0x38F) code += 0x3f; } else if (code >= 0x400 && code <= 0x40F) code += 0x50; else if (code >= 0x410 && code <= 0x42F) code += 0x20; else if (code >= 0x460 && code <= 0x4FF) { if ((code & 1) == 0) code += 1; } return "<#" * as_hexadecimal (code) * ">"; } else { init_case_tables (); if (locase_tab->contains (s)) return locase_tab[s]; return s; } }
static bool is_greek (string c) { static hashmap<string,bool> t (false); if (N(t) == 0) { array<int> a; //for (int i= 0x391; i<0x3a9; i++) if (i != 0x3a2) a << i; for (int i= 0x3b1; i<0x3c9; i++) a << i; for (int i= 0; i<N(a); i++) { string s= upcase_all ("<#" * as_hexadecimal (a[i]) * ">"); t (s)= true; t (locase_all (s))= true; t (rewrite_math (s))= true; } } return t[c]; }
string substitute_math_letter (string c, int math_kind) { if (math_kind == 0) return ""; int code= get_utf8_code (c); if ((code >= 0x1d400 && code <= 0x1d7ff) || (code >= 0x2100 && code <= 0x213f)) { init_unicode_substitution (); string nc= "<#" * as_hexadecimal (code) * ">"; string sc= substitution_char [nc]; string sf= substitution_font [nc]; //cout << c << " (" << nc << ") -> " << sc << ", " << sf << "\n"; if (sc != "" && sc != c) { bool flag= ends (sf, "cal") || ends (sf, "frak") || ends (sf, "bbb"); if (!flag || math_kind == 2) return sf; } } return ""; }
string picture_as_eps (picture pic, int dpi) { (void) dpi; if (DEBUG_CONVERT) debug_convert<< "in picture_as_eps " <<LF; static const char* d= "0123456789ABCDEF"; int w_pt= pic->get_width (), h_pt= pic->get_height (); int ox= pic->get_origin_x (), oy= pic->get_origin_y (); string r; string sw= as_string (w_pt); string sh= as_string (h_pt); r << "%!PS-Adobe-3.0 EPSF-3.0\n%%Creator: TeXmacs\n%%BoundingBox: 0 0 " << sw << " " << sh << "\n\n% Created by picture_as_eps ()\n\n%%BeginProlog\nsave\n" << "countdictstack\nmark\nnewpath\n/showpage {} def\n/setpagedevice " << "{pop} def\n%%EndProlog\n%%Page 1 1\n" << "/max { 2 copy lt { exch } if pop } bind def\n" << "/ImageWidth " << sw << " def\n/ImageHeight " << sh << " def\nImageWidth ImageHeight max " << "ImageWidth ImageHeight max scale\n\n/ImageDatas\n\tcurrentfile\n\t" << "<< /Filter /ASCIIHexDecode >>\n\t/ReusableStreamDecode\n\tfilter\n"; int v, i= 0, j= 0, k= 0, l= 0; bool alpha= false; for (j=0; j < h_pt; j++) for (i=0; i < w_pt; i++) { color col= pic->get_pixel (i - ox, h_pt - 1 - j - oy); int rr, gg, bb, aa; get_rgb_color (col, rr, gg, bb, aa); if (aa != 255) alpha= true; } string mask; for (j= 0; j < h_pt; j++) { for (i=0; i < w_pt; i++) { l++; color col= pic->get_pixel (i - ox, h_pt - 1 - j - oy); int rr, gg, bb, aa; get_rgb_color (col, rr, gg, bb, aa); rr= (rr * aa + 255 * (255 - aa)) / 255; gg= (gg * aa + 255 * (255 - aa)) / 255; bb= (bb * aa + 255 * (255 - aa)) / 255; r << as_hexadecimal (rr, 2); r << as_hexadecimal (gg, 2); r << as_hexadecimal (bb, 2); if (l > 12) { r << "\n"; l= 0; } } if (alpha) { v = 0; for (i=0; i < w_pt; i++) { color col= pic->get_pixel (i - ox, h_pt - 1 - j - oy); int rr, gg, bb, aa; get_rgb_color (col, rr, gg, bb, aa); v += (aa <= 32) << (3 - i % 4); if (i % 4 == 3 || i + 1 == w_pt) { mask << d[v]; v= 0; k++; // Padding of the image data mask if (i + 1 == w_pt && k % 2 == 1) { mask << d[0]; k++; } // Code layout if (k >= 78) { mask << "\n"; k= 0; } } } } } r << ">\ndef\n\n"; if (alpha) { r << "/MaskDatas\n\tcurrentfile\n\t<< /Filter /ASCIIHexDecode >>\n" << "\t/ReusableStreamDecode\n\tfilter\n" << mask << ">\ndef\n\n" << "/TheMask\n<<\n\t/ImageType\t1\n\t/Width\t\tImageWidth\n\t/Height\t" << "\tImageHeight\n\t/BitsPerComponent 1\n\t/Decode [ 0 1 ]\n\t" << "/ImageMatrix [ ImageWidth 0 0 ImageWidth neg 0 ImageHeight ]\n\t" << "/DataSource MaskDatas\n>> def\n\n"; } r << "/TheImage\n<<\n\t/ImageType\t1\n\t/Width\t\tImageWidth\n\t/Height\t" << "\tImageHeight\n\t/BitsPerComponent 8\n\t/Decode [ 0 1 0 1 0 1 ]\n\t" << "/ImageMatrix [ ImageWidth 0 0 ImageWidth neg 0 ImageHeight ]\n\t" << "/DataSource ImageDatas\n>> def\n\n" << "/DeviceRGB setcolorspace\n"; if (alpha) { r << "<<\n\t/ImageType 3\n\t/InterleaveType 3\n\t/DataDict TheImage\n" << "\t/MaskDict TheMask\n>>"; } else { r << "\tTheImage"; } r << "\nimage\nshowpage\n%%Trailer\ncleartomark\ncountdictstack\n" << "exch sub { end } repeat\nrestore\n%%EOF\n"; return r; }
static void translit_set (int i, string s) { string h= as_hexadecimal (i); translit_table ("<#" * locase_all (h) * ">")= s; translit_table ("<#" * upcase_all (h) * ">")= s; }