4 * Copyright 2001 the LyX Team
5 * Read the file COPYING
7 * \author Alejandro Aguilar Sierra
14 #include XPM_H_LOCATION
17 #pragma implementation
20 #include "support/LAssert.h"
23 #include "MathsSymbols.h"
24 #include "FormMathsPanel.h"
30 #ifndef CXX_GLOBAL_CSTD
35 /* Latex code for those bitmaps */
44 #include "mathed/math_parser.h"
53 #include "equation.xpm"
55 char const * function_names[] = {
56 "arccos", "arcsin", "arctan", "arg", "bmod",
57 "cos", "cosh", "cot", "coth", "csc", "deg",
58 "det", "dim", "exp", "gcd", "hom", "inf", "ker",
59 "lg", "lim", "liminf", "limsup", "ln", "log",
60 "max", "min", "sec", "sin", "sinh", "sup",
64 int const nr_function_names = sizeof(function_names) /
67 char const * latex_arrow[] = {
68 "downarrow", "leftarrow", "Downarrow", "Leftarrow",
69 "hookleftarrow", "rightarrow", "uparrow", "Rightarrow", "Uparrow",
70 "hookrightarrow", "updownarrow", "Leftrightarrow", "leftharpoonup",
71 "rightharpoonup", "rightleftharpoons", "leftrightarrow", "Updownarrow",
72 "leftharpoondown", "rightharpoondown", "mapsto",
73 "Longleftarrow", "Longrightarrow", "Longleftrightarrow",
74 "longleftrightarrow", "longleftarrow", "longrightarrow", "longmapsto",
75 "nwarrow", "nearrow", "swarrow", "searrow", "",
78 int const nr_latex_arrow = sizeof(latex_arrow) / sizeof(char const *);
80 char const * latex_bop[] = {
81 "pm", "cap", "diamond", "oplus",
82 "mp", "cup", "bigtriangleup", "ominus",
83 "times", "uplus", "bigtriangledown", "otimes",
84 "div", "sqcap", "triangleright", "oslash",
85 "cdot", "sqcup", "triangleleft", "odot",
86 "star", "vee", "amalg", "bigcirc",
87 "setminus", "wedge", "dagger", "circ",
88 "bullet", "wr", "ddagger", ""
91 int const nr_latex_bop = sizeof(latex_bop) / sizeof(char const *);
93 char const * latex_brel[] = {
94 "leq", "geq", "equiv", "models",
95 "prec", "succ", "sim", "perp",
96 "preceq", "succeq", "simeq", "mid",
97 "ll", "gg", "asymp", "parallel",
98 "subset", "supset", "approx", "smile",
99 "subseteq", "supseteq", "cong", "frown",
100 "sqsubseteq", "sqsupseteq", "doteq", "neq",
101 "in", "ni", "propto", "notin",
102 "vdash", "dashv", "bowtie", ""
105 int const nr_latex_brel = sizeof(latex_brel) / sizeof(char const *);
107 char const * latex_dots[] = {
108 "ldots", "cdots", "vdots", "ddots"
111 int const nr_latex_dots = sizeof(latex_dots) / sizeof(char const *);
113 char const * latex_greek[] = {
114 "Gamma", "Delta", "Theta", "Lambda", "Xi", "Pi",
115 "Sigma", "Upsilon", "Phi", "Psi", "Omega",
116 "alpha", "beta", "gamma", "delta", "epsilon", "varepsilon", "zeta",
117 "eta", "theta", "vartheta", "iota", "kappa", "lambda", "mu",
118 "nu", "xi", "pi", "varpi", "rho", "sigma", "varsigma",
119 "tau", "upsilon", "phi", "varphi", "chi", "psi", "omega", ""
122 int const nr_latex_greek = sizeof(latex_greek) / sizeof(char const *);
124 char const * latex_misc[] = {
125 "nabla", "partial", "infty", "prime", "ell",
126 "emptyset", "exists", "forall", "imath", "jmath",
127 "Re", "Im", "aleph", "wp", "hbar",
128 "angle", "top", "bot", "Vert", "neg",
129 "flat", "natural", "sharp", "surd", "triangle",
130 "diamondsuit", "heartsuit", "clubsuit", "spadesuit", ""
133 int const nr_latex_misc = sizeof(latex_misc) / sizeof(char const *);
135 char const * latex_varsz[] = {
136 "sum", "int", "oint",
137 "prod", "coprod", "bigsqcup",
138 "bigotimes", "bigodot", "bigoplus",
139 "bigcap", "bigcup", "biguplus",
140 "bigvee", "bigwedge", ""
143 int const nr_latex_varsz = sizeof(latex_varsz) / sizeof(char const *);
145 static char const ** mathed_get_pixmap_from_icon(int d)
148 case MM_FRAC: return frac;
149 case MM_SQRT: return sqrt_xpm;
150 case MM_DELIM: return delim;
151 case MM_MATRIX: return matrix;
152 case MM_EQU: return equation;
153 case MM_DECO: return deco;
154 case MM_SPACE: return space_xpm;
159 static char const ** pixmapFromBitmapData(char const * s, int wx, int hx)
161 char const ** data = 0;
167 char const ** latex_str = 0;
169 case 0: latex_str = latex_greek; break;
170 case 1: latex_str = latex_bop; break;
171 case 2: latex_str = latex_brel; break;
172 case 3: latex_str = latex_arrow; break;
173 case 4: latex_str = latex_varsz; break;
174 case 5: latex_str = latex_misc; break;
177 for (int k = 0; latex_str[k][0] > ' '; ++k) {
178 if (compare(latex_str[k], s) == 0) {
185 if (i < 6 && id >= 0) {
186 unsigned char const * bdata = 0;
192 lyxerr[Debug::MATHED] << "Imando " << i << ", " << id << endl;
231 } else if (id > 28) {
265 XImage * xima = XCreateImage(fl_get_display(), 0, 1, XYBitmap, 0,
266 const_cast<char*>(reinterpret_cast<char const *>(bdata)), w, h, 8, 0);
267 xima->byte_order = LSBFirst;
268 xima->bitmap_bit_order = LSBFirst;
269 int x = (id % dw) * ww;
270 int y = (id/dw) * hh;
271 if (ww > wx) ww = wx;
272 if (hh > hx) hh = hx;
273 XImage * sbima = XSubImage(xima, x, y, ww, hh);
274 XpmCreateDataFromImage(fl_get_display(), const_cast<char***>(&data), sbima, sbima, 0);
276 // Dirty hack to get blue symbols quickly
277 char * sx = const_cast<char*>(strstr(data[2], "FFFFFFFF"));
279 for (int k = 0; k < 8; ++k) sx[k] = '0';
282 // XDestroyImage(xima);
289 char const ** get_pixmap_from_symbol(char const * arg, int wx, int hx)
293 char const ** data = 0;
294 latexkeys const * l = in_word_set(arg);
300 data = mathed_get_pixmap_from_icon(MM_FRAC);
303 data = mathed_get_pixmap_from_icon(MM_SQRT);
307 // I have to use directly the bitmap data since the
308 // bitmap tables are not yet created when this
309 // function is called.
310 data = pixmapFromBitmapData(arg, wx, hx);