3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS
15 #pragma implementation
21 #include "XWorkArea.h"
22 #include "xfont_metrics.h"
23 #include "ColorHandler.h"
28 #include "xformsImage.h"
30 #include "support/LAssert.h"
31 #include "support/lstrings.h"
33 #include <boost/scoped_array.hpp>
41 XPainter::XPainter(XWorkArea & xwa)
42 : Painter(), owner_(xwa)
47 int XPainter::paperWidth() const
49 return owner_.workWidth();
53 int XPainter::paperHeight() const
55 return owner_.workHeight();
59 Painter & XPainter::point(int x, int y, LColor::color c)
61 XDrawPoint(fl_get_display(), owner_.getPixmap(),
62 lyxColorHandler->getGCForeground(c), x, y);
67 Painter & XPainter::line(int x1, int y1,
73 XDrawLine(fl_get_display(), owner_.getPixmap(),
74 lyxColorHandler->getGCLinepars(ls, lw, col),
80 Painter & XPainter::lines(int const * xp, int const * yp,
86 boost::scoped_array<XPoint> points(new XPoint[np]);
88 for (int i = 0; i < np; ++i) {
93 XDrawLines(fl_get_display(), owner_.getPixmap(),
94 lyxColorHandler->getGCLinepars(ls, lw, col),
95 points.get(), np, CoordModeOrigin);
101 Painter & XPainter::rectangle(int x, int y,
107 XDrawRectangle(fl_get_display(), owner_.getPixmap(),
108 lyxColorHandler->getGCLinepars(ls, lw, col),
114 Painter & XPainter::fillRectangle(int x, int y,
118 XFillRectangle(fl_get_display(), owner_.getPixmap(),
119 lyxColorHandler->getGCForeground(col), x, y, w, h);
124 Painter & XPainter::fillPolygon(int const * xp, int const * yp,
125 int np, LColor::color col)
127 boost::scoped_array<XPoint> points(new XPoint[np]);
129 for (int i = 0; i < np; ++i) {
134 XFillPolygon(fl_get_display(), owner_.getPixmap(),
135 lyxColorHandler->getGCForeground(col), points.get(),
136 np, Nonconvex, CoordModeOrigin);
142 Painter & XPainter::arc(int x, int y,
143 unsigned int w, unsigned int h,
144 int a1, int a2, LColor::color col)
146 XDrawArc(fl_get_display(), owner_.getPixmap(),
147 lyxColorHandler->getGCForeground(col),
153 Painter & XPainter::image(int x, int y,
155 grfx::Image const & i)
157 grfx::xformsImage const & image =
158 static_cast<grfx::xformsImage const &>(i);
161 val.function = GXcopy;
162 GC gc = XCreateGC(fl_get_display(), owner_.getPixmap(),
164 XCopyArea(fl_get_display(), image.getPixmap(), owner_.getPixmap(),
165 gc, 0, 0, w, h, x, y);
166 XFreeGC(fl_get_display(), gc);
171 Painter & XPainter::text(int x, int y,
172 string const & s, LyXFont const & f)
174 return text(x, y, s.data(), s.length(), f);
178 Painter & XPainter::text(int x, int y,
179 char c, LyXFont const & f)
181 char s[2] = { c, '\0' };
182 return text(x, y, s, 1, f);
186 Painter & XPainter::text(int x, int y,
187 char const * s, size_t ls,
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();
194 if (f.isSymbolFont()) {
195 #ifdef USE_UNICODE_FOR_SYMBOLS
196 font.setFamily(LyXFont::ROMAN_FAMILY);
197 font.setShape(LyXFont::UP_SHAPE);
199 encoding = encodings.symbol_encoding();
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;
206 text(x, y, xs.get(), ls, font);
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);
215 LyXFont smallfont(f);
216 smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
218 for (size_t i = 0; i < ls; ++i) {
219 char const c = uppercase(s[i]);
221 xfont_metrics::XSetFont(fl_get_display(), gc, smallfont);
222 XDrawString(fl_get_display(), owner_.getPixmap(), gc,
224 tmpx += xfont_metrics::XTextWidth(smallfont, &c, 1);
226 xfont_metrics::XSetFont(fl_get_display(), gc, f);
227 XDrawString(fl_get_display(), owner_.getPixmap(), gc,
229 tmpx += xfont_metrics::XTextWidth(f, &c, 1);
234 if (f.underbar() == LyXFont::ON) {
235 underline(f, x, y, font_metrics::width(s, ls, f));
242 Painter & XPainter::text(int x, int y,
243 XChar2b const * s, size_t ls,
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);
251 LyXFont smallfont(f);
252 smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
255 for (size_t i = 0; i < ls; ++i) {
259 c.byte1 = s[i].byte1;
260 c.byte2 = uppercase(s[i].byte2);
262 if (c.byte2 != s[i].byte2) {
263 xfont_metrics::XSetFont(fl_get_display(), gc, smallfont);
264 XDrawString16(fl_get_display(), owner_.getPixmap(), gc,
266 tmpx += xfont_metrics::XTextWidth16(smallfont, &c, 1);
268 xfont_metrics::XSetFont(fl_get_display(), gc, f);
269 XDrawString16(fl_get_display(), owner_.getPixmap(), gc,
271 tmpx += xfont_metrics::XTextWidth16(f, &c, 1);
276 if (f.underbar() == LyXFont::ON) {
277 underline(f, x, y, xfont_metrics::width(s, ls, f));