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;
36 XPainter::XPainter(XWorkArea & xwa)
37 : Painter(), owner_(xwa)
42 int XPainter::paperWidth() const
44 return owner_.workWidth();
48 int XPainter::paperHeight() const
50 return owner_.workHeight();
54 void XPainter::point(int x, int y, LColor_color c)
56 XDrawPoint(fl_get_display(), owner_.getPixmap(),
57 lyxColorHandler->getGCForeground(c), x, y);
61 void XPainter::line(int x1, int y1,
67 XDrawLine(fl_get_display(), owner_.getPixmap(),
68 lyxColorHandler->getGCLinepars(ls, lw, col),
73 void 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);
92 void XPainter::rectangle(int x, int y,
98 XDrawRectangle(fl_get_display(), owner_.getPixmap(),
99 lyxColorHandler->getGCLinepars(ls, lw, col),
104 void XPainter::fillRectangle(int x, int y,
108 XFillRectangle(fl_get_display(), owner_.getPixmap(),
109 lyxColorHandler->getGCForeground(col), x, y, w, h);
113 void XPainter::fillPolygon(int const * xp, int const * yp,
114 int np, LColor_color col)
116 boost::scoped_array<XPoint> points(new XPoint[np]);
118 for (int i = 0; i < np; ++i) {
123 XFillPolygon(fl_get_display(), owner_.getPixmap(),
124 lyxColorHandler->getGCForeground(col), points.get(),
125 np, Nonconvex, CoordModeOrigin);
129 void XPainter::arc(int x, int y,
130 unsigned int w, unsigned int h,
131 int a1, int a2, LColor_color col)
133 XDrawArc(fl_get_display(), owner_.getPixmap(),
134 lyxColorHandler->getGCForeground(col),
139 void XPainter::image(int x, int y,
141 lyx::graphics::Image const & i)
143 lyx::graphics::xformsImage const & image =
144 static_cast<lyx::graphics::xformsImage const &>(i);
147 val.function = GXcopy;
148 GC gc = XCreateGC(fl_get_display(), owner_.getPixmap(),
150 XCopyArea(fl_get_display(), image.getPixmap(), owner_.getPixmap(),
151 gc, 0, 0, w, h, x, y);
152 XFreeGC(fl_get_display(), gc);
156 void XPainter::text(int x, int y,
157 string const & s, LyXFont const & f)
159 return text(x, y, s.data(), s.length(), f);
163 void XPainter::text(int x, int y,
164 char c, LyXFont const & f)
166 char s[2] = { c, '\0' };
167 return text(x, y, s, 1, f);
171 void XPainter::text(int x, int y,
172 char const * s, size_t ls,
175 if (lyxrc.font_norm_type == LyXRC::ISO_10646_1) {
176 boost::scoped_array<XChar2b> xs(new XChar2b[ls]);
177 Encoding const * encoding = f.language()->encoding();
179 if (f.isSymbolFont()) {
180 #ifdef USE_UNICODE_FOR_SYMBOLS
181 font.setFamily(LyXFont::ROMAN_FAMILY);
182 font.setShape(LyXFont::UP_SHAPE);
184 encoding = encodings.symbol_encoding();
186 for (size_t i = 0; i < ls; ++i) {
187 Uchar c = encoding->ucs(s[i]);
188 xs[i].byte1 = c >> 8;
189 xs[i].byte2 = c & 0xff;
191 text(x, y, xs.get(), ls, font);
195 GC gc = lyxColorHandler->getGCForeground(f.realColor());
196 if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
197 xfont_metrics::XSetFont(fl_get_display(), gc, f);
198 XDrawString(fl_get_display(), owner_.getPixmap(), gc, x, y, s, ls);
200 LyXFont smallfont(f);
201 smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
203 for (size_t i = 0; i < ls; ++i) {
204 char const c = uppercase(s[i]);
206 xfont_metrics::XSetFont(fl_get_display(), gc, smallfont);
207 XDrawString(fl_get_display(), owner_.getPixmap(), gc,
209 tmpx += xfont_metrics::XTextWidth(smallfont, &c, 1);
211 xfont_metrics::XSetFont(fl_get_display(), gc, f);
212 XDrawString(fl_get_display(), owner_.getPixmap(), gc,
214 tmpx += xfont_metrics::XTextWidth(f, &c, 1);
219 if (f.underbar() == LyXFont::ON) {
220 underline(f, x, y, font_metrics::width(s, ls, f));
225 void XPainter::text(int x, int y,
226 XChar2b const * s, size_t ls,
229 GC gc = lyxColorHandler->getGCForeground(f.realColor());
230 if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
231 xfont_metrics::XSetFont(fl_get_display(), gc, f);
232 XDrawString16(fl_get_display(), owner_.getPixmap(), gc, x, y, s, ls);
234 LyXFont smallfont(f);
235 smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
238 for (size_t i = 0; i < ls; ++i) {
242 c.byte1 = s[i].byte1;
243 c.byte2 = uppercase(s[i].byte2);
245 if (c.byte2 != s[i].byte2) {
246 xfont_metrics::XSetFont(fl_get_display(), gc, smallfont);
247 XDrawString16(fl_get_display(), owner_.getPixmap(), gc,
249 tmpx += xfont_metrics::XTextWidth16(smallfont, &c, 1);
251 xfont_metrics::XSetFont(fl_get_display(), gc, f);
252 XDrawString16(fl_get_display(), owner_.getPixmap(), gc,
254 tmpx += xfont_metrics::XTextWidth16(f, &c, 1);
259 if (f.underbar() == LyXFont::ON) {
260 underline(f, x, y, xfont_metrics::width(s, ls, f));