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;
39 XPainter::XPainter(XWorkArea & xwa)
40 : Painter(), owner_(xwa)
45 int XPainter::paperWidth() const
47 return owner_.workWidth();
51 int XPainter::paperHeight() const
53 return owner_.workHeight();
57 Painter & XPainter::point(int x, int y, LColor::color c)
59 XDrawPoint(fl_get_display(), owner_.getPixmap(),
60 lyxColorHandler->getGCForeground(c), x, y);
65 Painter & XPainter::line(int x1, int y1,
71 XDrawLine(fl_get_display(), owner_.getPixmap(),
72 lyxColorHandler->getGCLinepars(ls, lw, col),
78 Painter & XPainter::lines(int const * xp, int const * yp,
84 boost::scoped_array<XPoint> points(new XPoint[np]);
86 for (int i = 0; i < np; ++i) {
91 XDrawLines(fl_get_display(), owner_.getPixmap(),
92 lyxColorHandler->getGCLinepars(ls, lw, col),
93 points.get(), np, CoordModeOrigin);
99 Painter & XPainter::rectangle(int x, int y,
105 XDrawRectangle(fl_get_display(), owner_.getPixmap(),
106 lyxColorHandler->getGCLinepars(ls, lw, col),
112 Painter & XPainter::fillRectangle(int x, int y,
116 XFillRectangle(fl_get_display(), owner_.getPixmap(),
117 lyxColorHandler->getGCForeground(col), x, y, w, h);
122 Painter & XPainter::fillPolygon(int const * xp, int const * yp,
123 int np, LColor::color col)
125 boost::scoped_array<XPoint> points(new XPoint[np]);
127 for (int i = 0; i < np; ++i) {
132 XFillPolygon(fl_get_display(), owner_.getPixmap(),
133 lyxColorHandler->getGCForeground(col), points.get(),
134 np, Nonconvex, CoordModeOrigin);
140 Painter & XPainter::arc(int x, int y,
141 unsigned int w, unsigned int h,
142 int a1, int a2, LColor::color col)
144 XDrawArc(fl_get_display(), owner_.getPixmap(),
145 lyxColorHandler->getGCForeground(col),
151 Painter & XPainter::image(int x, int y,
153 grfx::Image const & i)
155 grfx::xformsImage const & image =
156 static_cast<grfx::xformsImage const &>(i);
159 val.function = GXcopy;
160 GC gc = XCreateGC(fl_get_display(), owner_.getPixmap(),
162 XCopyArea(fl_get_display(), image.getPixmap(), owner_.getPixmap(),
163 gc, 0, 0, w, h, x, y);
164 XFreeGC(fl_get_display(), gc);
169 Painter & XPainter::text(int x, int y,
170 string const & s, LyXFont const & f)
172 return text(x, y, s.data(), s.length(), f);
176 Painter & XPainter::text(int x, int y,
177 char c, LyXFont const & f)
179 char s[2] = { c, '\0' };
180 return text(x, y, s, 1, f);
184 Painter & XPainter::text(int x, int y,
185 char const * s, size_t ls,
188 if (lyxrc.font_norm_type == LyXRC::ISO_10646_1) {
189 boost::scoped_array<XChar2b> xs(new XChar2b[ls]);
190 Encoding const * encoding = f.language()->encoding();
192 if (f.isSymbolFont()) {
193 #ifdef USE_UNICODE_FOR_SYMBOLS
194 font.setFamily(LyXFont::ROMAN_FAMILY);
195 font.setShape(LyXFont::UP_SHAPE);
197 encoding = encodings.symbol_encoding();
199 for (size_t i = 0; i < ls; ++i) {
200 Uchar c = encoding->ucs(s[i]);
201 xs[i].byte1 = c >> 8;
202 xs[i].byte2 = c & 0xff;
204 text(x, y, xs.get(), ls, font);
208 GC gc = lyxColorHandler->getGCForeground(f.realColor());
209 if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
210 xfont_metrics::XSetFont(fl_get_display(), gc, f);
211 XDrawString(fl_get_display(), owner_.getPixmap(), gc, x, y, s, ls);
213 LyXFont smallfont(f);
214 smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
216 for (size_t i = 0; i < ls; ++i) {
217 char const c = uppercase(s[i]);
219 xfont_metrics::XSetFont(fl_get_display(), gc, smallfont);
220 XDrawString(fl_get_display(), owner_.getPixmap(), gc,
222 tmpx += xfont_metrics::XTextWidth(smallfont, &c, 1);
224 xfont_metrics::XSetFont(fl_get_display(), gc, f);
225 XDrawString(fl_get_display(), owner_.getPixmap(), gc,
227 tmpx += xfont_metrics::XTextWidth(f, &c, 1);
232 if (f.underbar() == LyXFont::ON) {
233 underline(f, x, y, font_metrics::width(s, ls, f));
240 Painter & XPainter::text(int x, int y,
241 XChar2b const * s, size_t ls,
244 GC gc = lyxColorHandler->getGCForeground(f.realColor());
245 if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
246 xfont_metrics::XSetFont(fl_get_display(), gc, f);
247 XDrawString16(fl_get_display(), owner_.getPixmap(), gc, x, y, s, ls);
249 LyXFont smallfont(f);
250 smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
253 for (size_t i = 0; i < ls; ++i) {
257 c.byte1 = s[i].byte1;
258 c.byte2 = uppercase(s[i].byte2);
260 if (c.byte2 != s[i].byte2) {
261 xfont_metrics::XSetFont(fl_get_display(), gc, smallfont);
262 XDrawString16(fl_get_display(), owner_.getPixmap(), gc,
264 tmpx += xfont_metrics::XTextWidth16(smallfont, &c, 1);
266 xfont_metrics::XSetFont(fl_get_display(), gc, f);
267 XDrawString16(fl_get_display(), owner_.getPixmap(), gc,
269 tmpx += xfont_metrics::XTextWidth16(f, &c, 1);
274 if (f.underbar() == LyXFont::ON) {
275 underline(f, x, y, xfont_metrics::width(s, ls, f));