3 * Copyright 1998-2002 the LyX Team
4 * Read the file COPYING
7 * \author John Levon <moz@compsoc.man.ac.uk>
13 #pragma implementation
19 #include "XWorkArea.h"
20 #include "xfont_metrics.h"
21 #include "ColorHandler.h"
26 #ifdef USE_XFORMS_IMAGE_LOADER
27 #include "xformsImage.h"
29 #include "graphics/GraphicsImageXPM.h"
32 #include "support/LAssert.h"
33 #include "support/lstrings.h"
35 #include <boost/scoped_array.hpp>
43 XPainter::XPainter(XWorkArea & xwa)
44 : Painter(), owner_(xwa)
49 int XPainter::paperWidth() const
51 return owner_.workWidth();
55 int XPainter::paperHeight() const
57 return owner_.workHeight();
61 Painter & XPainter::point(int x, int y, LColor::color c)
63 XDrawPoint(fl_get_display(), owner_.getPixmap(),
64 lyxColorHandler->getGCForeground(c), x, y);
69 Painter & XPainter::line(int x1, int y1,
75 XDrawLine(fl_get_display(), owner_.getPixmap(),
76 lyxColorHandler->getGCLinepars(ls, lw, col),
82 Painter & XPainter::lines(int const * xp, int const * yp,
88 boost::scoped_array<XPoint> points(new XPoint[np]);
90 for (int i = 0; i < np; ++i) {
95 XDrawLines(fl_get_display(), owner_.getPixmap(),
96 lyxColorHandler->getGCLinepars(ls, lw, col),
97 points.get(), np, CoordModeOrigin);
103 Painter & XPainter::rectangle(int x, int y,
109 XDrawRectangle(fl_get_display(), owner_.getPixmap(),
110 lyxColorHandler->getGCLinepars(ls, lw, col),
116 Painter & XPainter::fillRectangle(int x, int y,
120 XFillRectangle(fl_get_display(), owner_.getPixmap(),
121 lyxColorHandler->getGCForeground(col), x, y, w, h);
126 Painter & XPainter::fillPolygon(int const * xp, int const * yp,
127 int np, LColor::color col)
129 boost::scoped_array<XPoint> points(new XPoint[np]);
131 for (int i = 0; i < np; ++i) {
136 XFillPolygon(fl_get_display(), owner_.getPixmap(),
137 lyxColorHandler->getGCForeground(col), points.get(),
138 np, Nonconvex, CoordModeOrigin);
144 Painter & XPainter::arc(int x, int y,
145 unsigned int w, unsigned int h,
146 int a1, int a2, LColor::color col)
148 XDrawArc(fl_get_display(), owner_.getPixmap(),
149 lyxColorHandler->getGCForeground(col),
155 Painter & XPainter::image(int x, int y,
157 grfx::Image const & i)
159 #ifdef USE_XFORMS_IMAGE_LOADER
160 grfx::xformsImage const & image = static_cast<grfx::xformsImage const &>(i);
162 grfx::ImageXPM const & image = static_cast<grfx::ImageXPM const &>(i);
166 val.function = GXcopy;
167 GC gc = XCreateGC(fl_get_display(), owner_.getPixmap(),
169 XCopyArea(fl_get_display(), image.getPixmap(), owner_.getPixmap(),
170 gc, 0, 0, w, h, x, y);
171 XFreeGC(fl_get_display(), gc);
176 Painter & XPainter::text(int x, int y,
177 string const & s, LyXFont const & f)
179 return text(x, y, s.data(), s.length(), f);
183 Painter & XPainter::text(int x, int y,
184 char c, LyXFont const & f)
186 char s[2] = { c, '\0' };
187 return text(x, y, s, 1, f);
191 Painter & XPainter::text(int x, int y,
192 char const * s, size_t ls,
195 if (lyxrc.font_norm_type == LyXRC::ISO_10646_1) {
196 boost::scoped_array<XChar2b> xs(new XChar2b[ls]);
197 Encoding const * encoding = f.language()->encoding();
199 if (f.isSymbolFont()) {
200 #ifdef USE_UNICODE_FOR_SYMBOLS
201 font.setFamily(LyXFont::ROMAN_FAMILY);
202 font.setShape(LyXFont::UP_SHAPE);
204 encoding = encodings.symbol_encoding();
206 for (size_t i = 0; i < ls; ++i) {
207 Uchar c = encoding->ucs(s[i]);
208 xs[i].byte1 = c >> 8;
209 xs[i].byte2 = c & 0xff;
211 text(x , y, xs.get(), ls, font);
215 GC gc = lyxColorHandler->getGCForeground(f.realColor());
216 if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
217 xfont_metrics::XSetFont(fl_get_display(), gc, f);
218 XDrawString(fl_get_display(), owner_.getPixmap(), gc, x, y, s, ls);
220 LyXFont smallfont(f);
221 smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
223 for (size_t i = 0; i < ls; ++i) {
224 char const c = uppercase(s[i]);
226 xfont_metrics::XSetFont(fl_get_display(), gc, smallfont);
227 XDrawString(fl_get_display(), owner_.getPixmap(), gc,
229 tmpx += xfont_metrics::XTextWidth(smallfont, &c, 1);
231 xfont_metrics::XSetFont(fl_get_display(), gc, f);
232 XDrawString(fl_get_display(), owner_.getPixmap(), gc,
234 tmpx += xfont_metrics::XTextWidth(f, &c, 1);
239 if (f.underbar() == LyXFont::ON) {
240 underline(f, x, y, font_metrics::width(s, ls, f));
247 Painter & XPainter::text(int x, int y,
248 XChar2b const * s, size_t ls,
251 GC gc = lyxColorHandler->getGCForeground(f.realColor());
252 if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
253 xfont_metrics::XSetFont(fl_get_display(), gc, f);
254 XDrawString16(fl_get_display(), owner_.getPixmap(), gc, x, y, s, ls);
256 LyXFont smallfont(f);
257 smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
260 for (size_t i = 0; i < ls; ++i) {
264 c.byte1 = s[i].byte1;
265 c.byte2 = uppercase(s[i].byte2);
267 if (c.byte2 != s[i].byte2) {
268 xfont_metrics::XSetFont(fl_get_display(), gc, smallfont);
269 XDrawString16(fl_get_display(), owner_.getPixmap(), gc,
271 tmpx += xfont_metrics::XTextWidth16(smallfont, &c, 1);
273 xfont_metrics::XSetFont(fl_get_display(), gc, f);
274 XDrawString16(fl_get_display(), owner_.getPixmap(), gc,
276 tmpx += xfont_metrics::XTextWidth16(f, &c, 1);
281 if (f.underbar() == LyXFont::ON) {
282 underline(f, x, y, xfont_metrics::width(s, ls, f));