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