]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/XPainter.C
Remove another #ifdef block.
[lyx.git] / src / frontends / xforms / XPainter.C
1 /**
2  * \file XPainter.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author unknown
7  * \author John Levon
8  *
9  * Full author contact details are available in file CREDITS
10  */
11
12 #include <config.h>
13
14 #ifdef __GNUG__
15 #pragma implementation
16 #endif
17
18 #include "XPainter.h"
19 #include "LString.h"
20 #include "debug.h"
21 #include "XWorkArea.h"
22 #include "xfont_metrics.h"
23 #include "ColorHandler.h"
24 #include "lyxrc.h"
25 #include "encoding.h"
26 #include "language.h"
27
28 #include "xformsImage.h"
29
30 #include "support/LAssert.h"
31 #include "support/lstrings.h"
32
33 #include <boost/scoped_array.hpp>
34
35 #include <cmath>
36
37 using std::endl;
38 using std::max;
39
40
41 XPainter::XPainter(XWorkArea & xwa)
42         : Painter(), owner_(xwa)
43 {
44 }
45
46
47 int XPainter::paperWidth() const
48 {
49         return owner_.workWidth();
50 }
51
52
53 int XPainter::paperHeight() const
54 {
55         return owner_.workHeight();
56 }
57
58
59 Painter & XPainter::point(int x, int y, LColor::color c)
60 {
61         XDrawPoint(fl_get_display(), owner_.getPixmap(),
62                 lyxColorHandler->getGCForeground(c), x, y);
63         return *this;
64 }
65
66
67 Painter & XPainter::line(int x1, int y1,
68         int x2, int y2,
69         LColor::color col,
70         line_style ls,
71         line_width lw)
72 {
73         XDrawLine(fl_get_display(), owner_.getPixmap(),
74                 lyxColorHandler->getGCLinepars(ls, lw, col),
75                 x1, y1, x2, y2);
76         return *this;
77 }
78
79
80 Painter & XPainter::lines(int const * xp, int const * yp,
81         int np,
82         LColor::color col,
83         line_style ls,
84         line_width lw)
85 {
86         boost::scoped_array<XPoint> points(new XPoint[np]);
87
88         for (int i = 0; i < np; ++i) {
89                 points[i].x = xp[i];
90                 points[i].y = yp[i];
91         }
92
93         XDrawLines(fl_get_display(), owner_.getPixmap(),
94                 lyxColorHandler->getGCLinepars(ls, lw, col),
95                 points.get(), np, CoordModeOrigin);
96
97         return *this;
98 }
99
100
101 Painter & XPainter::rectangle(int x, int y,
102         int w, int h,
103         LColor::color col,
104         line_style ls,
105         line_width lw)
106 {
107         XDrawRectangle(fl_get_display(), owner_.getPixmap(),
108                 lyxColorHandler->getGCLinepars(ls, lw, col),
109                 x, y, w, h);
110         return *this;
111 }
112
113
114 Painter & XPainter::fillRectangle(int x, int y,
115         int w, int h,
116         LColor::color col)
117 {
118         XFillRectangle(fl_get_display(), owner_.getPixmap(),
119                 lyxColorHandler->getGCForeground(col), x, y, w, h);
120         return *this;
121 }
122
123
124 Painter & XPainter::fillPolygon(int const * xp, int const * yp,
125         int np, LColor::color col)
126 {
127         boost::scoped_array<XPoint> points(new XPoint[np]);
128
129         for (int i = 0; i < np; ++i) {
130                 points[i].x = xp[i];
131                 points[i].y = yp[i];
132         }
133
134         XFillPolygon(fl_get_display(), owner_.getPixmap(),
135                 lyxColorHandler->getGCForeground(col), points.get(),
136                 np, Nonconvex, CoordModeOrigin);
137
138         return *this;
139 }
140
141
142 Painter & XPainter::arc(int x, int y,
143         unsigned int w, unsigned int h,
144         int a1, int a2, LColor::color col)
145 {
146         XDrawArc(fl_get_display(), owner_.getPixmap(),
147                 lyxColorHandler->getGCForeground(col),
148                 x, y, w, h, a1, a2);
149         return *this;
150 }
151
152
153 Painter & XPainter::image(int x, int y,
154         int w, int h,
155         grfx::Image const & i)
156 {
157         grfx::xformsImage const & image =
158                 static_cast<grfx::xformsImage const &>(i);
159
160         XGCValues val;
161         val.function = GXcopy;
162         GC gc = XCreateGC(fl_get_display(), owner_.getPixmap(),
163                 GCFunction, &val);
164         XCopyArea(fl_get_display(), image.getPixmap(), owner_.getPixmap(),
165                 gc, 0, 0, w, h, x, y);
166         XFreeGC(fl_get_display(), gc);
167         return *this;
168 }
169
170
171 Painter & XPainter::text(int x, int y,
172         string const & s, LyXFont const & f)
173 {
174         return text(x, y, s.data(), s.length(), f);
175 }
176
177
178 Painter & XPainter::text(int x, int y,
179         char c, LyXFont const & f)
180 {
181         char s[2] = { c, '\0' };
182         return text(x, y, s, 1, f);
183 }
184
185
186 Painter & XPainter::text(int x, int y,
187         char const * s, size_t ls,
188         LyXFont const & f)
189 {
190         if (lyxrc.font_norm_type == LyXRC::ISO_10646_1) {
191                 boost::scoped_array<XChar2b> xs(new XChar2b[ls]);
192                 Encoding const * encoding = f.language()->encoding();
193                 LyXFont font(f);
194                 if (f.isSymbolFont()) {
195 #ifdef USE_UNICODE_FOR_SYMBOLS
196                         font.setFamily(LyXFont::ROMAN_FAMILY);
197                         font.setShape(LyXFont::UP_SHAPE);
198 #endif
199                         encoding = encodings.symbol_encoding();
200                 }
201                 for (size_t i = 0; i < ls; ++i) {
202                         Uchar c = encoding->ucs(s[i]);
203                         xs[i].byte1 = c >> 8;
204                         xs[i].byte2 = c & 0xff;
205                 }
206                 text(x, y, xs.get(), ls, font);
207                 return *this;
208         }
209
210         GC gc = lyxColorHandler->getGCForeground(f.realColor());
211         if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
212                 xfont_metrics::XSetFont(fl_get_display(), gc, f);
213                 XDrawString(fl_get_display(), owner_.getPixmap(), gc, x, y, s, ls);
214         } else {
215                 LyXFont smallfont(f);
216                 smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
217                 int tmpx = x;
218                 for (size_t i = 0; i < ls; ++i) {
219                         char const c = uppercase(s[i]);
220                         if (c != s[i]) {
221                                 xfont_metrics::XSetFont(fl_get_display(), gc, smallfont);
222                                 XDrawString(fl_get_display(), owner_.getPixmap(), gc,
223                                         tmpx, y, &c, 1);
224                                 tmpx += xfont_metrics::XTextWidth(smallfont, &c, 1);
225                         } else {
226                                 xfont_metrics::XSetFont(fl_get_display(), gc, f);
227                                 XDrawString(fl_get_display(), owner_.getPixmap(), gc,
228                                         tmpx, y, &c, 1);
229                                 tmpx += xfont_metrics::XTextWidth(f, &c, 1);
230                         }
231                 }
232         }
233
234         if (f.underbar() == LyXFont::ON) {
235                 underline(f, x, y, font_metrics::width(s, ls, f));
236         }
237
238         return *this;
239 }
240
241
242 Painter & XPainter::text(int x, int y,
243         XChar2b const * s, size_t ls,
244         LyXFont const & f)
245 {
246         GC gc = lyxColorHandler->getGCForeground(f.realColor());
247         if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
248                 xfont_metrics::XSetFont(fl_get_display(), gc, f);
249                 XDrawString16(fl_get_display(), owner_.getPixmap(), gc, x, y, s, ls);
250         } else {
251                 LyXFont smallfont(f);
252                 smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
253                 static XChar2b c;
254                 int tmpx = x;
255                 for (size_t i = 0; i < ls; ++i) {
256                         if (s[i].byte1)
257                                 c = s[i];
258                         else {
259                                 c.byte1 = s[i].byte1;
260                                 c.byte2 = uppercase(s[i].byte2);
261                         }
262                         if (c.byte2 != s[i].byte2) {
263                                 xfont_metrics::XSetFont(fl_get_display(), gc, smallfont);
264                                 XDrawString16(fl_get_display(), owner_.getPixmap(), gc,
265                                         tmpx, y, &c, 1);
266                                 tmpx += xfont_metrics::XTextWidth16(smallfont, &c, 1);
267                         } else {
268                                 xfont_metrics::XSetFont(fl_get_display(), gc, f);
269                                 XDrawString16(fl_get_display(), owner_.getPixmap(), gc,
270                                         tmpx, y, &c, 1);
271                                 tmpx += xfont_metrics::XTextWidth16(f, &c, 1);
272                         }
273                 }
274         }
275
276         if (f.underbar() == LyXFont::ON) {
277                 underline(f, x, y, xfont_metrics::width(s, ls, f));
278         }
279
280         return *this;
281 }