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
15 #pragma implementation
21 #include "XWorkArea.h"
22 #include "xfont_metrics.h"
23 #include "ColorHandler.h"
28 #ifdef USE_XFORMS_IMAGE_LOADER
29 #include "xformsImage.h"
31 #include "graphics/GraphicsImageXPM.h"
34 #include "support/LAssert.h"
35 #include "support/lstrings.h"
37 #include <boost/scoped_array.hpp>
45 XPainter::XPainter(XWorkArea & xwa)
46 : Painter(), owner_(xwa)
51 int XPainter::paperWidth() const
53 return owner_.workWidth();
57 int XPainter::paperHeight() const
59 return owner_.workHeight();
63 Painter & XPainter::point(int x, int y, LColor::color c)
65 XDrawPoint(fl_get_display(), owner_.getPixmap(),
66 lyxColorHandler->getGCForeground(c), x, y);
71 Painter & XPainter::line(int x1, int y1,
77 XDrawLine(fl_get_display(), owner_.getPixmap(),
78 lyxColorHandler->getGCLinepars(ls, lw, col),
84 Painter & XPainter::lines(int const * xp, int const * yp,
90 boost::scoped_array<XPoint> points(new XPoint[np]);
92 for (int i = 0; i < np; ++i) {
97 XDrawLines(fl_get_display(), owner_.getPixmap(),
98 lyxColorHandler->getGCLinepars(ls, lw, col),
99 points.get(), np, CoordModeOrigin);
105 Painter & XPainter::rectangle(int x, int y,
111 XDrawRectangle(fl_get_display(), owner_.getPixmap(),
112 lyxColorHandler->getGCLinepars(ls, lw, col),
118 Painter & XPainter::fillRectangle(int x, int y,
122 XFillRectangle(fl_get_display(), owner_.getPixmap(),
123 lyxColorHandler->getGCForeground(col), x, y, w, h);
128 Painter & XPainter::fillPolygon(int const * xp, int const * yp,
129 int np, LColor::color col)
131 boost::scoped_array<XPoint> points(new XPoint[np]);
133 for (int i = 0; i < np; ++i) {
138 XFillPolygon(fl_get_display(), owner_.getPixmap(),
139 lyxColorHandler->getGCForeground(col), points.get(),
140 np, Nonconvex, CoordModeOrigin);
146 Painter & XPainter::arc(int x, int y,
147 unsigned int w, unsigned int h,
148 int a1, int a2, LColor::color col)
150 XDrawArc(fl_get_display(), owner_.getPixmap(),
151 lyxColorHandler->getGCForeground(col),
157 Painter & XPainter::image(int x, int y,
159 grfx::Image const & i)
161 #ifdef USE_XFORMS_IMAGE_LOADER
162 grfx::xformsImage const & image = static_cast<grfx::xformsImage const &>(i);
164 grfx::ImageXPM const & image = static_cast<grfx::ImageXPM const &>(i);
168 val.function = GXcopy;
169 GC gc = XCreateGC(fl_get_display(), owner_.getPixmap(),
171 XCopyArea(fl_get_display(), image.getPixmap(), owner_.getPixmap(),
172 gc, 0, 0, w, h, x, y);
173 XFreeGC(fl_get_display(), gc);
178 Painter & XPainter::text(int x, int y,
179 string const & s, LyXFont const & f)
181 return text(x, y, s.data(), s.length(), f);
185 Painter & XPainter::text(int x, int y,
186 char c, LyXFont const & f)
188 char s[2] = { c, '\0' };
189 return text(x, y, s, 1, f);
193 Painter & XPainter::text(int x, int y,
194 char const * s, size_t ls,
197 if (lyxrc.font_norm_type == LyXRC::ISO_10646_1) {
198 boost::scoped_array<XChar2b> xs(new XChar2b[ls]);
199 Encoding const * encoding = f.language()->encoding();
201 if (f.isSymbolFont()) {
202 #ifdef USE_UNICODE_FOR_SYMBOLS
203 font.setFamily(LyXFont::ROMAN_FAMILY);
204 font.setShape(LyXFont::UP_SHAPE);
206 encoding = encodings.symbol_encoding();
208 for (size_t i = 0; i < ls; ++i) {
209 Uchar c = encoding->ucs(s[i]);
210 xs[i].byte1 = c >> 8;
211 xs[i].byte2 = c & 0xff;
213 text(x, y, xs.get(), ls, font);
217 GC gc = lyxColorHandler->getGCForeground(f.realColor());
218 if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
219 xfont_metrics::XSetFont(fl_get_display(), gc, f);
220 XDrawString(fl_get_display(), owner_.getPixmap(), gc, x, y, s, ls);
222 LyXFont smallfont(f);
223 smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
225 for (size_t i = 0; i < ls; ++i) {
226 char const c = uppercase(s[i]);
228 xfont_metrics::XSetFont(fl_get_display(), gc, smallfont);
229 XDrawString(fl_get_display(), owner_.getPixmap(), gc,
231 tmpx += xfont_metrics::XTextWidth(smallfont, &c, 1);
233 xfont_metrics::XSetFont(fl_get_display(), gc, f);
234 XDrawString(fl_get_display(), owner_.getPixmap(), gc,
236 tmpx += xfont_metrics::XTextWidth(f, &c, 1);
241 if (f.underbar() == LyXFont::ON) {
242 underline(f, x, y, font_metrics::width(s, ls, f));
249 Painter & XPainter::text(int x, int y,
250 XChar2b const * s, size_t ls,
253 GC gc = lyxColorHandler->getGCForeground(f.realColor());
254 if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
255 xfont_metrics::XSetFont(fl_get_display(), gc, f);
256 XDrawString16(fl_get_display(), owner_.getPixmap(), gc, x, y, s, ls);
258 LyXFont smallfont(f);
259 smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
262 for (size_t i = 0; i < ls; ++i) {
266 c.byte1 = s[i].byte1;
267 c.byte2 = uppercase(s[i].byte2);
269 if (c.byte2 != s[i].byte2) {
270 xfont_metrics::XSetFont(fl_get_display(), gc, smallfont);
271 XDrawString16(fl_get_display(), owner_.getPixmap(), gc,
273 tmpx += xfont_metrics::XTextWidth16(smallfont, &c, 1);
275 xfont_metrics::XSetFont(fl_get_display(), gc, f);
276 XDrawString16(fl_get_display(), owner_.getPixmap(), gc,
278 tmpx += xfont_metrics::XTextWidth16(f, &c, 1);
283 if (f.underbar() == LyXFont::ON) {
284 underline(f, x, y, xfont_metrics::width(s, ls, f));