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.
16 #include "ColorHandler.h"
17 #include "xfont_metrics.h"
18 #include "xformsImage.h"
19 #include "XWorkArea.h"
21 #include "font_metrics.h"
29 #include "support/lstrings.h"
31 using lyx::support::uppercase;
34 XPainter::XPainter(XWorkArea & xwa)
35 : Painter(), owner_(xwa)
40 int XPainter::paperWidth() const
42 return owner_.workWidth();
46 int XPainter::paperHeight() const
48 return owner_.workHeight();
52 Painter & XPainter::point(int x, int y, LColor_color c)
54 XDrawPoint(fl_get_display(), owner_.getPixmap(),
55 lyxColorHandler->getGCForeground(c), x, y);
60 Painter & XPainter::line(int x1, int y1,
66 XDrawLine(fl_get_display(), owner_.getPixmap(),
67 lyxColorHandler->getGCLinepars(ls, lw, col),
73 Painter & XPainter::lines(int const * xp, int const * yp,
79 boost::scoped_array<XPoint> points(new XPoint[np]);
81 for (int i = 0; i < np; ++i) {
86 XDrawLines(fl_get_display(), owner_.getPixmap(),
87 lyxColorHandler->getGCLinepars(ls, lw, col),
88 points.get(), np, CoordModeOrigin);
94 Painter & XPainter::rectangle(int x, int y,
100 XDrawRectangle(fl_get_display(), owner_.getPixmap(),
101 lyxColorHandler->getGCLinepars(ls, lw, col),
107 Painter & XPainter::fillRectangle(int x, int y,
111 XFillRectangle(fl_get_display(), owner_.getPixmap(),
112 lyxColorHandler->getGCForeground(col), x, y, w, h);
117 Painter & XPainter::fillPolygon(int const * xp, int const * yp,
118 int np, LColor_color col)
120 boost::scoped_array<XPoint> points(new XPoint[np]);
122 for (int i = 0; i < np; ++i) {
127 XFillPolygon(fl_get_display(), owner_.getPixmap(),
128 lyxColorHandler->getGCForeground(col), points.get(),
129 np, Nonconvex, CoordModeOrigin);
135 Painter & XPainter::arc(int x, int y,
136 unsigned int w, unsigned int h,
137 int a1, int a2, LColor_color col)
139 XDrawArc(fl_get_display(), owner_.getPixmap(),
140 lyxColorHandler->getGCForeground(col),
146 Painter & XPainter::image(int x, int y,
148 lyx::graphics::Image const & i)
150 lyx::graphics::xformsImage const & image =
151 static_cast<lyx::graphics::xformsImage const &>(i);
154 val.function = GXcopy;
155 GC gc = XCreateGC(fl_get_display(), owner_.getPixmap(),
157 XCopyArea(fl_get_display(), image.getPixmap(), owner_.getPixmap(),
158 gc, 0, 0, w, h, x, y);
159 XFreeGC(fl_get_display(), gc);
164 Painter & XPainter::text(int x, int y,
165 string const & s, LyXFont const & f)
167 return text(x, y, s.data(), s.length(), f);
171 Painter & XPainter::text(int x, int y,
172 char c, LyXFont const & f)
174 char s[2] = { c, '\0' };
175 return text(x, y, s, 1, f);
179 Painter & XPainter::text(int x, int y,
180 char const * s, size_t ls,
183 if (lyxrc.font_norm_type == LyXRC::ISO_10646_1) {
184 boost::scoped_array<XChar2b> xs(new XChar2b[ls]);
185 Encoding const * encoding = f.language()->encoding();
187 if (f.isSymbolFont()) {
188 #ifdef USE_UNICODE_FOR_SYMBOLS
189 font.setFamily(LyXFont::ROMAN_FAMILY);
190 font.setShape(LyXFont::UP_SHAPE);
192 encoding = encodings.symbol_encoding();
194 for (size_t i = 0; i < ls; ++i) {
195 Uchar c = encoding->ucs(s[i]);
196 xs[i].byte1 = c >> 8;
197 xs[i].byte2 = c & 0xff;
199 text(x, y, xs.get(), ls, font);
203 GC gc = lyxColorHandler->getGCForeground(f.realColor());
204 if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
205 xfont_metrics::XSetFont(fl_get_display(), gc, f);
206 XDrawString(fl_get_display(), owner_.getPixmap(), gc, x, y, s, ls);
208 LyXFont smallfont(f);
209 smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
211 for (size_t i = 0; i < ls; ++i) {
212 char const c = uppercase(s[i]);
214 xfont_metrics::XSetFont(fl_get_display(), gc, smallfont);
215 XDrawString(fl_get_display(), owner_.getPixmap(), gc,
217 tmpx += xfont_metrics::XTextWidth(smallfont, &c, 1);
219 xfont_metrics::XSetFont(fl_get_display(), gc, f);
220 XDrawString(fl_get_display(), owner_.getPixmap(), gc,
222 tmpx += xfont_metrics::XTextWidth(f, &c, 1);
227 if (f.underbar() == LyXFont::ON) {
228 underline(f, x, y, font_metrics::width(s, ls, f));
235 Painter & XPainter::text(int x, int y,
236 XChar2b const * s, size_t ls,
239 GC gc = lyxColorHandler->getGCForeground(f.realColor());
240 if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
241 xfont_metrics::XSetFont(fl_get_display(), gc, f);
242 XDrawString16(fl_get_display(), owner_.getPixmap(), gc, x, y, s, ls);
244 LyXFont smallfont(f);
245 smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
248 for (size_t i = 0; i < ls; ++i) {
252 c.byte1 = s[i].byte1;
253 c.byte2 = uppercase(s[i].byte2);
255 if (c.byte2 != s[i].byte2) {
256 xfont_metrics::XSetFont(fl_get_display(), gc, smallfont);
257 XDrawString16(fl_get_display(), owner_.getPixmap(), gc,
259 tmpx += xfont_metrics::XTextWidth16(smallfont, &c, 1);
261 xfont_metrics::XSetFont(fl_get_display(), gc, f);
262 XDrawString16(fl_get_display(), owner_.getPixmap(), gc,
264 tmpx += xfont_metrics::XTextWidth16(f, &c, 1);
269 if (f.underbar() == LyXFont::ON) {
270 underline(f, x, y, xfont_metrics::width(s, ls, f));