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"
25 #include "support/lstrings.h"
27 using namespace lyx::support;
33 XPainter::XPainter(XWorkArea & xwa)
34 : Painter(), owner_(xwa)
39 int XPainter::paperWidth() const
41 return owner_.workWidth();
45 int XPainter::paperHeight() const
47 return owner_.workHeight();
51 Painter & XPainter::point(int x, int y, LColor::color c)
53 XDrawPoint(fl_get_display(), owner_.getPixmap(),
54 lyxColorHandler->getGCForeground(c), x, y);
59 Painter & XPainter::line(int x1, int y1,
65 XDrawLine(fl_get_display(), owner_.getPixmap(),
66 lyxColorHandler->getGCLinepars(ls, lw, col),
72 Painter & XPainter::lines(int const * xp, int const * yp,
78 boost::scoped_array<XPoint> points(new XPoint[np]);
80 for (int i = 0; i < np; ++i) {
85 XDrawLines(fl_get_display(), owner_.getPixmap(),
86 lyxColorHandler->getGCLinepars(ls, lw, col),
87 points.get(), np, CoordModeOrigin);
93 Painter & XPainter::rectangle(int x, int y,
99 XDrawRectangle(fl_get_display(), owner_.getPixmap(),
100 lyxColorHandler->getGCLinepars(ls, lw, col),
106 Painter & XPainter::fillRectangle(int x, int y,
110 XFillRectangle(fl_get_display(), owner_.getPixmap(),
111 lyxColorHandler->getGCForeground(col), x, y, w, h);
116 Painter & 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);
134 Painter & XPainter::arc(int x, int y,
135 unsigned int w, unsigned int h,
136 int a1, int a2, LColor::color col)
138 XDrawArc(fl_get_display(), owner_.getPixmap(),
139 lyxColorHandler->getGCForeground(col),
145 Painter & XPainter::image(int x, int y,
147 lyx::graphics::Image const & i)
149 lyx::graphics::xformsImage const & image =
150 static_cast<lyx::graphics::xformsImage const &>(i);
153 val.function = GXcopy;
154 GC gc = XCreateGC(fl_get_display(), owner_.getPixmap(),
156 XCopyArea(fl_get_display(), image.getPixmap(), owner_.getPixmap(),
157 gc, 0, 0, w, h, x, y);
158 XFreeGC(fl_get_display(), gc);
163 Painter & XPainter::text(int x, int y,
164 string const & s, LyXFont const & f)
166 return text(x, y, s.data(), s.length(), f);
170 Painter & XPainter::text(int x, int y,
171 char c, LyXFont const & f)
173 char s[2] = { c, '\0' };
174 return text(x, y, s, 1, f);
178 Painter & XPainter::text(int x, int y,
179 char const * s, size_t ls,
182 if (lyxrc.font_norm_type == LyXRC::ISO_10646_1) {
183 boost::scoped_array<XChar2b> xs(new XChar2b[ls]);
184 Encoding const * encoding = f.language()->encoding();
186 if (f.isSymbolFont()) {
187 #ifdef USE_UNICODE_FOR_SYMBOLS
188 font.setFamily(LyXFont::ROMAN_FAMILY);
189 font.setShape(LyXFont::UP_SHAPE);
191 encoding = encodings.symbol_encoding();
193 for (size_t i = 0; i < ls; ++i) {
194 Uchar c = encoding->ucs(s[i]);
195 xs[i].byte1 = c >> 8;
196 xs[i].byte2 = c & 0xff;
198 text(x, y, xs.get(), ls, font);
202 GC gc = lyxColorHandler->getGCForeground(f.realColor());
203 if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
204 xfont_metrics::XSetFont(fl_get_display(), gc, f);
205 XDrawString(fl_get_display(), owner_.getPixmap(), gc, x, y, s, ls);
207 LyXFont smallfont(f);
208 smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
210 for (size_t i = 0; i < ls; ++i) {
211 char const c = uppercase(s[i]);
213 xfont_metrics::XSetFont(fl_get_display(), gc, smallfont);
214 XDrawString(fl_get_display(), owner_.getPixmap(), gc,
216 tmpx += xfont_metrics::XTextWidth(smallfont, &c, 1);
218 xfont_metrics::XSetFont(fl_get_display(), gc, f);
219 XDrawString(fl_get_display(), owner_.getPixmap(), gc,
221 tmpx += xfont_metrics::XTextWidth(f, &c, 1);
226 if (f.underbar() == LyXFont::ON) {
227 underline(f, x, y, font_metrics::width(s, ls, f));
234 Painter & XPainter::text(int x, int y,
235 XChar2b const * s, size_t ls,
238 GC gc = lyxColorHandler->getGCForeground(f.realColor());
239 if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
240 xfont_metrics::XSetFont(fl_get_display(), gc, f);
241 XDrawString16(fl_get_display(), owner_.getPixmap(), gc, x, y, s, ls);
243 LyXFont smallfont(f);
244 smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
247 for (size_t i = 0; i < ls; ++i) {
251 c.byte1 = s[i].byte1;
252 c.byte2 = uppercase(s[i].byte2);
254 if (c.byte2 != s[i].byte2) {
255 xfont_metrics::XSetFont(fl_get_display(), gc, smallfont);
256 XDrawString16(fl_get_display(), owner_.getPixmap(), gc,
258 tmpx += xfont_metrics::XTextWidth16(smallfont, &c, 1);
260 xfont_metrics::XSetFont(fl_get_display(), gc, f);
261 XDrawString16(fl_get_display(), owner_.getPixmap(), gc,
263 tmpx += xfont_metrics::XTextWidth16(f, &c, 1);
268 if (f.underbar() == LyXFont::ON) {
269 underline(f, x, y, xfont_metrics::width(s, ls, f));