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"
35 using support::uppercase;
39 XPainter::XPainter(XWorkArea & xwa)
40 : Painter(), owner_(xwa)
45 int XPainter::paperWidth() const
47 return owner_.workWidth();
51 int XPainter::paperHeight() const
53 return owner_.workHeight();
57 void XPainter::point(int x, int y, LColor_color c)
59 XDrawPoint(fl_get_display(), owner_.getPixmap(),
60 lyxColorHandler->getGCForeground(c), x, y);
64 void XPainter::line(int x1, int y1,
70 XDrawLine(fl_get_display(), owner_.getPixmap(),
71 lyxColorHandler->getGCLinepars(ls, lw, col),
76 void XPainter::lines(int const * xp, int const * yp,
82 boost::scoped_array<XPoint> points(new XPoint[np]);
84 for (int i = 0; i < np; ++i) {
89 XDrawLines(fl_get_display(), owner_.getPixmap(),
90 lyxColorHandler->getGCLinepars(ls, lw, col),
91 points.get(), np, CoordModeOrigin);
95 void XPainter::rectangle(int x, int y,
101 XDrawRectangle(fl_get_display(), owner_.getPixmap(),
102 lyxColorHandler->getGCLinepars(ls, lw, col),
107 void XPainter::fillRectangle(int x, int y,
111 XFillRectangle(fl_get_display(), owner_.getPixmap(),
112 lyxColorHandler->getGCForeground(col), x, y, w, h);
116 void XPainter::fillPolygon(int const * xp, int const * yp,
117 int np, LColor_color col)
119 boost::scoped_array<XPoint> points(new XPoint[np]);
121 for (int i = 0; i < np; ++i) {
126 XFillPolygon(fl_get_display(), owner_.getPixmap(),
127 lyxColorHandler->getGCForeground(col), points.get(),
128 np, Nonconvex, CoordModeOrigin);
132 void XPainter::arc(int x, int y,
133 unsigned int w, unsigned int h,
134 int a1, int a2, LColor_color col)
136 XDrawArc(fl_get_display(), owner_.getPixmap(),
137 lyxColorHandler->getGCForeground(col),
142 void XPainter::image(int x, int y,
144 graphics::Image const & i)
146 graphics::xformsImage const & image =
147 static_cast<graphics::xformsImage const &>(i);
150 val.function = GXcopy;
151 GC gc = XCreateGC(fl_get_display(), owner_.getPixmap(),
153 XCopyArea(fl_get_display(), image.getPixmap(), owner_.getPixmap(),
154 gc, 0, 0, w, h, x, y);
155 XFreeGC(fl_get_display(), gc);
159 void XPainter::text(int x, int y,
160 string const & s, LyXFont const & f)
162 return text(x, y, s.data(), s.length(), f);
166 void XPainter::text(int x, int y,
167 char c, LyXFont const & f)
169 char s[2] = { c, '\0' };
170 return text(x, y, s, 1, f);
174 void XPainter::text(int x, int y,
175 char const * s, size_t ls,
178 if (lyxrc.font_norm_type == LyXRC::ISO_10646_1) {
179 boost::scoped_array<XChar2b> xs(new XChar2b[ls]);
180 Encoding const * encoding = f.language()->encoding();
182 if (f.isSymbolFont()) {
183 #ifdef USE_UNICODE_FOR_SYMBOLS
184 font.setFamily(LyXFont::ROMAN_FAMILY);
185 font.setShape(LyXFont::UP_SHAPE);
187 encoding = encodings.symbol_encoding();
189 for (size_t i = 0; i < ls; ++i) {
190 Uchar c = encoding->ucs(s[i]);
191 xs[i].byte1 = c >> 8;
192 xs[i].byte2 = c & 0xff;
194 text(x, y, xs.get(), ls, font);
198 GC gc = lyxColorHandler->getGCForeground(f.realColor());
199 if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
200 xfont_metrics::XSetFont(fl_get_display(), gc, f);
201 XDrawString(fl_get_display(), owner_.getPixmap(), gc, x, y, s, ls);
203 LyXFont smallfont(f);
204 smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
206 for (size_t i = 0; i < ls; ++i) {
207 char const c = uppercase(s[i]);
209 xfont_metrics::XSetFont(fl_get_display(), gc, smallfont);
210 XDrawString(fl_get_display(), owner_.getPixmap(), gc,
212 tmpx += xfont_metrics::XTextWidth(smallfont, &c, 1);
214 xfont_metrics::XSetFont(fl_get_display(), gc, f);
215 XDrawString(fl_get_display(), owner_.getPixmap(), gc,
217 tmpx += xfont_metrics::XTextWidth(f, &c, 1);
222 if (f.underbar() == LyXFont::ON) {
223 underline(f, x, y, font_metrics::width(s, ls, f));
228 void XPainter::text(int x, int y,
229 XChar2b const * s, size_t ls,
232 GC gc = lyxColorHandler->getGCForeground(f.realColor());
233 if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
234 xfont_metrics::XSetFont(fl_get_display(), gc, f);
235 XDrawString16(fl_get_display(), owner_.getPixmap(), gc, x, y, s, ls);
237 LyXFont smallfont(f);
238 smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
241 for (size_t i = 0; i < ls; ++i) {
245 c.byte1 = s[i].byte1;
246 c.byte2 = uppercase(s[i].byte2);
248 if (c.byte2 != s[i].byte2) {
249 xfont_metrics::XSetFont(fl_get_display(), gc, smallfont);
250 XDrawString16(fl_get_display(), owner_.getPixmap(), gc,
252 tmpx += xfont_metrics::XTextWidth16(smallfont, &c, 1);
254 xfont_metrics::XSetFont(fl_get_display(), gc, f);
255 XDrawString16(fl_get_display(), owner_.getPixmap(), gc,
257 tmpx += xfont_metrics::XTextWidth16(f, &c, 1);
262 if (f.underbar() == LyXFont::ON) {
263 underline(f, x, y, xfont_metrics::width(s, ls, f));
267 } // namespace frontend