2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1998-2000 The LyX Team
9 *======================================================*/
14 #pragma implementation
23 #include FORMS_H_LOCATION
28 #include "support/LAssert.h"
29 #include "support/lstrings.h"
32 #include "ColorHandler.h"
37 Painter::Painter(WorkArea & wa)
44 Painter::~Painter() {}
47 /* Basic drawing routines */
49 extern bool Lgb_bug_find_hack;
51 PainterBase & Painter::point(int x, int y, LColor::color c)
53 if (lyxerr.debugging()) {
54 if (!Lgb_bug_find_hack)
55 lyxerr << "point not called from "
56 "workarea::workhandler\n";
57 lyxerr.debug() << "Painter drawable: "
58 << owner.getPixmap() << endl;
61 XDrawPoint(display, owner.getPixmap(),
62 lyxColorHandler->getGCForeground(c), x, y);
67 PainterBase & Painter::line(int x1, int y1, int x2, int y2,
72 if (lyxerr.debugging()) {
73 if (!Lgb_bug_find_hack)
74 lyxerr << "line not called from "
75 "workarea::workhandler\n";
76 lyxerr.debug() << "Painter drawable: "
77 << owner.getPixmap() << endl;
80 XDrawLine(display, owner.getPixmap(),
81 lyxColorHandler->getGCLinepars(ls, lw, col),
87 PainterBase & Painter::lines(int const * xp, int const * yp, int np,
92 if (lyxerr.debugging()) {
93 if (!Lgb_bug_find_hack)
94 lyxerr << "lines not called from "
95 "workarea::workhandler\n";
96 lyxerr.debug() << "Painter drawable: "
97 << owner.getPixmap() << endl;
100 #ifndef HAVE_AUTO_PTR
101 XPoint * points = new XPoint[np];
103 auto_ptr<XPoint> points(new Xpoint[np]);
105 for (int i = 0; i < np; ++i) {
110 XDrawLines(display, owner.getPixmap(),
111 lyxColorHandler->getGCLinepars(ls, lw, col),
112 points, np, CoordModeOrigin);
114 #ifndef HAVE_AUTO_PTR
121 PainterBase & Painter::rectangle(int x, int y, int w, int h,
126 if (lyxerr.debugging()) {
127 if (!Lgb_bug_find_hack)
128 lyxerr << "rectangle not called from "
129 "workarea::workhandler\n";
130 lyxerr << "Painter drawable: "
131 << owner.getPixmap() << endl;
134 XDrawRectangle(display, owner.getPixmap(),
135 lyxColorHandler->getGCLinepars(ls, lw, col),
141 PainterBase & Painter::fillRectangle(int x, int y, int w, int h,
144 if (lyxerr.debugging()) {
145 if (!Lgb_bug_find_hack)
146 lyxerr << "fillrectangle not called from "
147 "workarea::workhandler\n";
148 lyxerr << "Painter drawable: "
149 << owner.getPixmap() << endl;
152 XFillRectangle(display, owner.getPixmap(),
153 lyxColorHandler->getGCForeground(col), x, y, w, h);
158 PainterBase & Painter::fillPolygon(int const * xp, int const * yp, int np,
161 if (lyxerr.debugging()) {
162 if (!Lgb_bug_find_hack)
163 lyxerr <<"fillpolygon not called from "
164 "workarea::workhandler\n";
165 lyxerr << "Painter drawable: " << owner.getPixmap() << endl;
168 #ifndef HAVE_AUTO_PTR
169 XPoint * points = new XPoint[np];
171 auto_ptr<XPoint> points(new XPoint[np]);
173 for (int i=0; i < np; ++i) {
178 XFillPolygon(display, owner.getPixmap(),
179 lyxColorHandler->getGCForeground(col), points, np,
180 Nonconvex, CoordModeOrigin);
181 #ifndef HAVE_AUTO_PTR
188 PainterBase & Painter::arc(int x, int y,
189 unsigned int w, unsigned int h,
190 int a1, int a2, LColor::color col)
192 if (lyxerr.debugging()) {
193 if (!Lgb_bug_find_hack)
194 lyxerr << "arc not called from "
195 "workarea::workhandler\n";
196 lyxerr << "Painter drawable: " << owner.getPixmap() << endl;
199 XDrawArc(display, owner.getPixmap(),
200 lyxColorHandler->getGCForeground(col),
206 /// Draw lines from x1,y1 to x2,y2. They are arrays
207 PainterBase & Painter::segments(int const * x1, int const * y1,
208 int const * x2, int const * y2, int ns,
210 enum line_style ls, enum line_width lw)
212 if (lyxerr.debugging()) {
213 if (!Lgb_bug_find_hack)
214 lyxerr << "segments not called from "
215 "workarea::workhandler\n";
216 lyxerr << "Painter drawable: " << owner.getPixmap() << endl;
219 #ifndef HAVE_AUTO_PTR
220 XSegment * s= new XSegment[ns];
222 auto_ptr<XSegment> s(new XSegment[ns]);
224 for (int i=0; i<ns; ++i) {
230 XDrawSegments(display, owner.getPixmap(),
231 lyxColorHandler->getGCLinepars(ls, lw, col), s, ns);
233 #ifndef HAVE_AUTO_PTR
240 PainterBase & Painter::pixmap(int x, int y, int w, int h, Pixmap bitmap)
242 if (lyxerr.debugging()) {
243 if (!Lgb_bug_find_hack)
244 lyxerr << "workAreaExpose not called from "
245 "workarea::workhandler\n";
246 lyxerr << "Painter drawable: " << owner.getPixmap() << endl;
250 val.function = GXcopy;
251 GC gc = XCreateGC(display, owner.getPixmap(),
253 XCopyArea(display, bitmap, owner.getPixmap(), gc,
255 XFreeGC(display, gc);
260 PainterBase & Painter::text(int x, int y, string const & s, LyXFont const & f)
262 return text(x, y, s.c_str(), s.length(), f);
266 PainterBase & Painter::text(int x, int y, char c, LyXFont const & f)
268 char s[2] = { c, '\0' };
269 return text(x, y, s, 1, f);
273 PainterBase & Painter::text(int x, int y, char const * s, int ls,
276 if (lyxerr.debugging()) {
277 if (!Lgb_bug_find_hack)
278 lyxerr << "text not called from "
279 "workarea::workhandler\n";
280 lyxerr << "Painter drawable: " << owner.getPixmap() << endl;
282 GC gc = lyxColorHandler->getGCForeground(f.realColor());
283 if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
284 lyxfont::XSetFont(display, gc, f);
285 XDrawString(display, owner.getPixmap(), gc, x, y, s, ls);
287 LyXFont smallfont(f);
288 smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
291 for(int i = 0; i < ls; ++i) {
293 if (islower(static_cast<unsigned char>(c))) {
295 lyxfont::XSetFont(display, gc, smallfont);
296 XDrawString(display, owner.getPixmap(),
298 tmpx += lyxfont::XTextWidth(smallfont, &c, 1);
299 //tmpx += lyxfont::width(c, f);
301 lyxfont::XSetFont(display, gc, f);
302 XDrawString(display, owner.getPixmap(),
304 tmpx += lyxfont::XTextWidth(f, &c, 1);
305 //tmpx += lyxfont::width(c, f);
309 underline(f, x, y, lyxfont::width(s, ls, f));
314 void Painter::underline(LyXFont const & f, int x, int y, int width)
316 // What about underbars?
317 if (f.underbar() == LyXFont::ON && f.latex() != LyXFont::ON) {
318 int below = max(lyxfont::maxDescent(f) / 2, 2);
319 int height = max((lyxfont::maxDescent(f) / 4) - 1, 1);
321 line(x, y + below, x + width, y + below, f.color());
323 fillRectangle(x, y + below, width, below + height,