3 * Read the file COPYING
8 * Full author contact details are available in file CREDITS
14 #pragma implementation
20 #include "XWorkArea.h"
21 #include "xfont_metrics.h"
22 #include "ColorHandler.h"
27 #ifdef USE_XFORMS_IMAGE_LOADER
28 #include "xformsImage.h"
30 #include "graphics/GraphicsImageXPM.h"
33 #include "support/LAssert.h"
34 #include "support/lstrings.h"
36 #include <boost/scoped_array.hpp>
44 XPainter::XPainter(XWorkArea & xwa)
45 : Painter(), owner_(xwa)
50 int XPainter::paperWidth() const
52 return owner_.workWidth();
56 int XPainter::paperHeight() const
58 return owner_.workHeight();
62 Painter & XPainter::point(int x, int y, LColor::color c)
64 XDrawPoint(fl_get_display(), owner_.getPixmap(),
65 lyxColorHandler->getGCForeground(c), x, y);
70 Painter & XPainter::line(int x1, int y1,
76 XDrawLine(fl_get_display(), owner_.getPixmap(),
77 lyxColorHandler->getGCLinepars(ls, lw, col),
83 Painter & XPainter::lines(int const * xp, int const * yp,
89 boost::scoped_array<XPoint> points(new XPoint[np]);
91 for (int i = 0; i < np; ++i) {
96 XDrawLines(fl_get_display(), owner_.getPixmap(),
97 lyxColorHandler->getGCLinepars(ls, lw, col),
98 points.get(), np, CoordModeOrigin);
104 Painter & XPainter::rectangle(int x, int y,
110 XDrawRectangle(fl_get_display(), owner_.getPixmap(),
111 lyxColorHandler->getGCLinepars(ls, lw, col),
117 Painter & XPainter::fillRectangle(int x, int y,
121 XFillRectangle(fl_get_display(), owner_.getPixmap(),
122 lyxColorHandler->getGCForeground(col), x, y, w, h);
127 Painter & XPainter::fillPolygon(int const * xp, int const * yp,
128 int np, LColor::color col)
130 boost::scoped_array<XPoint> points(new XPoint[np]);
132 for (int i = 0; i < np; ++i) {
137 XFillPolygon(fl_get_display(), owner_.getPixmap(),
138 lyxColorHandler->getGCForeground(col), points.get(),
139 np, Nonconvex, CoordModeOrigin);
145 Painter & XPainter::arc(int x, int y,
146 unsigned int w, unsigned int h,
147 int a1, int a2, LColor::color col)
149 XDrawArc(fl_get_display(), owner_.getPixmap(),
150 lyxColorHandler->getGCForeground(col),
156 Painter & XPainter::image(int x, int y,
158 grfx::Image const & i)
160 #ifdef USE_XFORMS_IMAGE_LOADER
161 grfx::xformsImage const & image = static_cast<grfx::xformsImage const &>(i);
163 grfx::ImageXPM const & image = static_cast<grfx::ImageXPM const &>(i);
167 val.function = GXcopy;
168 GC gc = XCreateGC(fl_get_display(), owner_.getPixmap(),
170 XCopyArea(fl_get_display(), image.getPixmap(), owner_.getPixmap(),
171 gc, 0, 0, w, h, x, y);
172 XFreeGC(fl_get_display(), gc);
177 Painter & XPainter::text(int x, int y,
178 string const & s, LyXFont const & f)
180 return text(x, y, s.data(), s.length(), f);
184 Painter & XPainter::text(int x, int y,
185 char c, LyXFont const & f)
187 char s[2] = { c, '\0' };
188 return text(x, y, s, 1, f);
192 Painter & XPainter::text(int x, int y,
193 char const * s, size_t ls,
196 if (lyxrc.font_norm_type == LyXRC::ISO_10646_1) {
197 boost::scoped_array<XChar2b> xs(new XChar2b[ls]);
198 Encoding const * encoding = f.language()->encoding();
200 if (f.isSymbolFont()) {
201 #ifdef USE_UNICODE_FOR_SYMBOLS
202 font.setFamily(LyXFont::ROMAN_FAMILY);
203 font.setShape(LyXFont::UP_SHAPE);
205 encoding = encodings.symbol_encoding();
207 for (size_t i = 0; i < ls; ++i) {
208 Uchar c = encoding->ucs(s[i]);
209 xs[i].byte1 = c >> 8;
210 xs[i].byte2 = c & 0xff;
212 text(x, y, xs.get(), ls, font);
216 GC gc = lyxColorHandler->getGCForeground(f.realColor());
217 if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
218 xfont_metrics::XSetFont(fl_get_display(), gc, f);
219 XDrawString(fl_get_display(), owner_.getPixmap(), gc, x, y, s, ls);
221 LyXFont smallfont(f);
222 smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
224 for (size_t i = 0; i < ls; ++i) {
225 char const c = uppercase(s[i]);
227 xfont_metrics::XSetFont(fl_get_display(), gc, smallfont);
228 XDrawString(fl_get_display(), owner_.getPixmap(), gc,
230 tmpx += xfont_metrics::XTextWidth(smallfont, &c, 1);
232 xfont_metrics::XSetFont(fl_get_display(), gc, f);
233 XDrawString(fl_get_display(), owner_.getPixmap(), gc,
235 tmpx += xfont_metrics::XTextWidth(f, &c, 1);
240 if (f.underbar() == LyXFont::ON) {
241 underline(f, x, y, font_metrics::width(s, ls, f));
248 Painter & XPainter::text(int x, int y,
249 XChar2b const * s, size_t ls,
252 GC gc = lyxColorHandler->getGCForeground(f.realColor());
253 if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
254 xfont_metrics::XSetFont(fl_get_display(), gc, f);
255 XDrawString16(fl_get_display(), owner_.getPixmap(), gc, x, y, s, ls);
257 LyXFont smallfont(f);
258 smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
261 for (size_t i = 0; i < ls; ++i) {
265 c.byte1 = s[i].byte1;
266 c.byte2 = uppercase(s[i].byte2);
268 if (c.byte2 != s[i].byte2) {
269 xfont_metrics::XSetFont(fl_get_display(), gc, smallfont);
270 XDrawString16(fl_get_display(), owner_.getPixmap(), gc,
272 tmpx += xfont_metrics::XTextWidth16(smallfont, &c, 1);
274 xfont_metrics::XSetFont(fl_get_display(), gc, f);
275 XDrawString16(fl_get_display(), owner_.getPixmap(), gc,
277 tmpx += xfont_metrics::XTextWidth16(f, &c, 1);
282 if (f.underbar() == LyXFont::ON) {
283 underline(f, x, y, xfont_metrics::width(s, ls, f));