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
18 #include "XWorkArea.h"
19 #include "xfont_metrics.h"
20 #include "ColorHandler.h"
25 #include "xformsImage.h"
27 #include "support/LAssert.h"
28 #include "support/lstrings.h"
30 #include <boost/scoped_array.hpp>
38 XPainter::XPainter(XWorkArea & xwa)
39 : Painter(), owner_(xwa)
44 int XPainter::paperWidth() const
46 return owner_.workWidth();
50 int XPainter::paperHeight() const
52 return owner_.workHeight();
56 Painter & XPainter::point(int x, int y, LColor::color c)
58 XDrawPoint(fl_get_display(), owner_.getPixmap(),
59 lyxColorHandler->getGCForeground(c), x, y);
64 Painter & XPainter::line(int x1, int y1,
70 XDrawLine(fl_get_display(), owner_.getPixmap(),
71 lyxColorHandler->getGCLinepars(ls, lw, col),
77 Painter & XPainter::lines(int const * xp, int const * yp,
83 boost::scoped_array<XPoint> points(new XPoint[np]);
85 for (int i = 0; i < np; ++i) {
90 XDrawLines(fl_get_display(), owner_.getPixmap(),
91 lyxColorHandler->getGCLinepars(ls, lw, col),
92 points.get(), np, CoordModeOrigin);
98 Painter & XPainter::rectangle(int x, int y,
104 XDrawRectangle(fl_get_display(), owner_.getPixmap(),
105 lyxColorHandler->getGCLinepars(ls, lw, col),
111 Painter & XPainter::fillRectangle(int x, int y,
115 XFillRectangle(fl_get_display(), owner_.getPixmap(),
116 lyxColorHandler->getGCForeground(col), x, y, w, h);
121 Painter & XPainter::fillPolygon(int const * xp, int const * yp,
122 int np, LColor::color col)
124 boost::scoped_array<XPoint> points(new XPoint[np]);
126 for (int i = 0; i < np; ++i) {
131 XFillPolygon(fl_get_display(), owner_.getPixmap(),
132 lyxColorHandler->getGCForeground(col), points.get(),
133 np, Nonconvex, CoordModeOrigin);
139 Painter & XPainter::arc(int x, int y,
140 unsigned int w, unsigned int h,
141 int a1, int a2, LColor::color col)
143 XDrawArc(fl_get_display(), owner_.getPixmap(),
144 lyxColorHandler->getGCForeground(col),
150 Painter & XPainter::image(int x, int y,
152 grfx::Image const & i)
154 grfx::xformsImage const & image =
155 static_cast<grfx::xformsImage const &>(i);
158 val.function = GXcopy;
159 GC gc = XCreateGC(fl_get_display(), owner_.getPixmap(),
161 XCopyArea(fl_get_display(), image.getPixmap(), owner_.getPixmap(),
162 gc, 0, 0, w, h, x, y);
163 XFreeGC(fl_get_display(), gc);
168 Painter & XPainter::text(int x, int y,
169 string const & s, LyXFont const & f)
171 return text(x, y, s.data(), s.length(), f);
175 Painter & XPainter::text(int x, int y,
176 char c, LyXFont const & f)
178 char s[2] = { c, '\0' };
179 return text(x, y, s, 1, f);
183 Painter & XPainter::text(int x, int y,
184 char const * s, size_t ls,
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();
191 if (f.isSymbolFont()) {
192 #ifdef USE_UNICODE_FOR_SYMBOLS
193 font.setFamily(LyXFont::ROMAN_FAMILY);
194 font.setShape(LyXFont::UP_SHAPE);
196 encoding = encodings.symbol_encoding();
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;
203 text(x, y, xs.get(), ls, font);
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);
212 LyXFont smallfont(f);
213 smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
215 for (size_t i = 0; i < ls; ++i) {
216 char const c = uppercase(s[i]);
218 xfont_metrics::XSetFont(fl_get_display(), gc, smallfont);
219 XDrawString(fl_get_display(), owner_.getPixmap(), gc,
221 tmpx += xfont_metrics::XTextWidth(smallfont, &c, 1);
223 xfont_metrics::XSetFont(fl_get_display(), gc, f);
224 XDrawString(fl_get_display(), owner_.getPixmap(), gc,
226 tmpx += xfont_metrics::XTextWidth(f, &c, 1);
231 if (f.underbar() == LyXFont::ON) {
232 underline(f, x, y, font_metrics::width(s, ls, f));
239 Painter & XPainter::text(int x, int y,
240 XChar2b const * s, size_t ls,
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);
248 LyXFont smallfont(f);
249 smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
252 for (size_t i = 0; i < ls; ++i) {
256 c.byte1 = s[i].byte1;
257 c.byte2 = uppercase(s[i].byte2);
259 if (c.byte2 != s[i].byte2) {
260 xfont_metrics::XSetFont(fl_get_display(), gc, smallfont);
261 XDrawString16(fl_get_display(), owner_.getPixmap(), gc,
263 tmpx += xfont_metrics::XTextWidth16(smallfont, &c, 1);
265 xfont_metrics::XSetFont(fl_get_display(), gc, f);
266 XDrawString16(fl_get_display(), owner_.getPixmap(), gc,
268 tmpx += xfont_metrics::XTextWidth16(f, &c, 1);
273 if (f.underbar() == LyXFont::ON) {
274 underline(f, x, y, xfont_metrics::width(s, ls, f));