3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
9 * Full author contact details are available in file CREDITS
17 #include "XWorkArea.h"
18 #include "xfont_metrics.h"
19 #include "ColorHandler.h"
24 #include "xformsImage.h"
26 #include "support/LAssert.h"
27 #include "support/lstrings.h"
29 #include <boost/scoped_array.hpp>
33 using namespace lyx::support;
38 namespace grfx = lyx::graphics;
40 XPainter::XPainter(XWorkArea & xwa)
41 : Painter(), owner_(xwa)
46 int XPainter::paperWidth() const
48 return owner_.workWidth();
52 int XPainter::paperHeight() const
54 return owner_.workHeight();
58 Painter & XPainter::point(int x, int y, LColor::color c)
60 XDrawPoint(fl_get_display(), owner_.getPixmap(),
61 lyxColorHandler->getGCForeground(c), x, y);
66 Painter & XPainter::line(int x1, int y1,
72 XDrawLine(fl_get_display(), owner_.getPixmap(),
73 lyxColorHandler->getGCLinepars(ls, lw, col),
79 Painter & XPainter::lines(int const * xp, int const * yp,
85 boost::scoped_array<XPoint> points(new XPoint[np]);
87 for (int i = 0; i < np; ++i) {
92 XDrawLines(fl_get_display(), owner_.getPixmap(),
93 lyxColorHandler->getGCLinepars(ls, lw, col),
94 points.get(), np, CoordModeOrigin);
100 Painter & XPainter::rectangle(int x, int y,
106 XDrawRectangle(fl_get_display(), owner_.getPixmap(),
107 lyxColorHandler->getGCLinepars(ls, lw, col),
113 Painter & XPainter::fillRectangle(int x, int y,
117 XFillRectangle(fl_get_display(), owner_.getPixmap(),
118 lyxColorHandler->getGCForeground(col), x, y, w, h);
123 Painter & XPainter::fillPolygon(int const * xp, int const * yp,
124 int np, LColor::color col)
126 boost::scoped_array<XPoint> points(new XPoint[np]);
128 for (int i = 0; i < np; ++i) {
133 XFillPolygon(fl_get_display(), owner_.getPixmap(),
134 lyxColorHandler->getGCForeground(col), points.get(),
135 np, Nonconvex, CoordModeOrigin);
141 Painter & XPainter::arc(int x, int y,
142 unsigned int w, unsigned int h,
143 int a1, int a2, LColor::color col)
145 XDrawArc(fl_get_display(), owner_.getPixmap(),
146 lyxColorHandler->getGCForeground(col),
152 Painter & XPainter::image(int x, int y,
154 grfx::Image const & i)
156 grfx::xformsImage const & image =
157 static_cast<grfx::xformsImage const &>(i);
160 val.function = GXcopy;
161 GC gc = XCreateGC(fl_get_display(), owner_.getPixmap(),
163 XCopyArea(fl_get_display(), image.getPixmap(), owner_.getPixmap(),
164 gc, 0, 0, w, h, x, y);
165 XFreeGC(fl_get_display(), gc);
170 Painter & XPainter::text(int x, int y,
171 string const & s, LyXFont const & f)
173 return text(x, y, s.data(), s.length(), f);
177 Painter & XPainter::text(int x, int y,
178 char c, LyXFont const & f)
180 char s[2] = { c, '\0' };
181 return text(x, y, s, 1, f);
185 Painter & XPainter::text(int x, int y,
186 char const * s, size_t ls,
189 if (lyxrc.font_norm_type == LyXRC::ISO_10646_1) {
190 boost::scoped_array<XChar2b> xs(new XChar2b[ls]);
191 Encoding const * encoding = f.language()->encoding();
193 if (f.isSymbolFont()) {
194 #ifdef USE_UNICODE_FOR_SYMBOLS
195 font.setFamily(LyXFont::ROMAN_FAMILY);
196 font.setShape(LyXFont::UP_SHAPE);
198 encoding = encodings.symbol_encoding();
200 for (size_t i = 0; i < ls; ++i) {
201 Uchar c = encoding->ucs(s[i]);
202 xs[i].byte1 = c >> 8;
203 xs[i].byte2 = c & 0xff;
205 text(x, y, xs.get(), ls, font);
209 GC gc = lyxColorHandler->getGCForeground(f.realColor());
210 if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
211 xfont_metrics::XSetFont(fl_get_display(), gc, f);
212 XDrawString(fl_get_display(), owner_.getPixmap(), gc, x, y, s, ls);
214 LyXFont smallfont(f);
215 smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
217 for (size_t i = 0; i < ls; ++i) {
218 char const c = uppercase(s[i]);
220 xfont_metrics::XSetFont(fl_get_display(), gc, smallfont);
221 XDrawString(fl_get_display(), owner_.getPixmap(), gc,
223 tmpx += xfont_metrics::XTextWidth(smallfont, &c, 1);
225 xfont_metrics::XSetFont(fl_get_display(), gc, f);
226 XDrawString(fl_get_display(), owner_.getPixmap(), gc,
228 tmpx += xfont_metrics::XTextWidth(f, &c, 1);
233 if (f.underbar() == LyXFont::ON) {
234 underline(f, x, y, font_metrics::width(s, ls, f));
241 Painter & XPainter::text(int x, int y,
242 XChar2b const * s, size_t ls,
245 GC gc = lyxColorHandler->getGCForeground(f.realColor());
246 if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
247 xfont_metrics::XSetFont(fl_get_display(), gc, f);
248 XDrawString16(fl_get_display(), owner_.getPixmap(), gc, x, y, s, ls);
250 LyXFont smallfont(f);
251 smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
254 for (size_t i = 0; i < ls; ++i) {
258 c.byte1 = s[i].byte1;
259 c.byte2 = uppercase(s[i].byte2);
261 if (c.byte2 != s[i].byte2) {
262 xfont_metrics::XSetFont(fl_get_display(), gc, smallfont);
263 XDrawString16(fl_get_display(), owner_.getPixmap(), gc,
265 tmpx += xfont_metrics::XTextWidth16(smallfont, &c, 1);
267 xfont_metrics::XSetFont(fl_get_display(), gc, f);
268 XDrawString16(fl_get_display(), owner_.getPixmap(), gc,
270 tmpx += xfont_metrics::XTextWidth16(f, &c, 1);
275 if (f.underbar() == LyXFont::ON) {
276 underline(f, x, y, xfont_metrics::width(s, ls, f));