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 /* Basic drawing routines */
46 extern bool Lgb_bug_find_hack;
48 PainterBase & Painter::point(int x, int y, LColor::color c)
50 if (lyxerr.debugging()) {
51 if (!Lgb_bug_find_hack)
52 lyxerr << "point not called from "
53 "workarea::workhandler\n";
54 lyxerr.debug() << "Painter drawable: "
55 << owner.getPixmap() << endl;
58 XDrawPoint(display, owner.getPixmap(),
59 lyxColorHandler->getGCForeground(c), x, y);
64 PainterBase & Painter::line(int x1, int y1, int x2, int y2,
69 if (lyxerr.debugging()) {
70 if (!Lgb_bug_find_hack)
71 lyxerr << "line not called from "
72 "workarea::workhandler\n";
73 lyxerr.debug() << "Painter drawable: "
74 << owner.getPixmap() << endl;
77 XDrawLine(display, owner.getPixmap(),
78 lyxColorHandler->getGCLinepars(ls, lw, col),
84 PainterBase & Painter::lines(int const * xp, int const * yp, int np,
89 if (lyxerr.debugging()) {
90 if (!Lgb_bug_find_hack)
91 lyxerr << "lines not called from "
92 "workarea::workhandler\n";
93 lyxerr.debug() << "Painter drawable: "
94 << owner.getPixmap() << endl;
98 XPoint * points = new XPoint[np];
100 auto_ptr<XPoint> points(new Xpoint[np]);
102 for (int i = 0; i < np; ++i) {
107 XDrawLines(display, owner.getPixmap(),
108 lyxColorHandler->getGCLinepars(ls, lw, col),
109 points, np, CoordModeOrigin);
111 #ifndef HAVE_AUTO_PTR
118 PainterBase & Painter::rectangle(int x, int y, int w, int h,
123 if (lyxerr.debugging()) {
124 if (!Lgb_bug_find_hack)
125 lyxerr << "rectangle not called from "
126 "workarea::workhandler\n";
127 lyxerr << "Painter drawable: "
128 << owner.getPixmap() << endl;
131 XDrawRectangle(display, owner.getPixmap(),
132 lyxColorHandler->getGCLinepars(ls, lw, col),
138 PainterBase & Painter::fillRectangle(int x, int y, int w, int h,
141 if (lyxerr.debugging()) {
142 if (!Lgb_bug_find_hack)
143 lyxerr << "fillrectangle not called from "
144 "workarea::workhandler\n";
145 lyxerr << "Painter drawable: "
146 << owner.getPixmap() << endl;
149 XFillRectangle(display, owner.getPixmap(),
150 lyxColorHandler->getGCForeground(col), x, y, w, h);
155 PainterBase & Painter::fillPolygon(int const * xp, int const * yp, int np,
158 if (lyxerr.debugging()) {
159 if (!Lgb_bug_find_hack)
160 lyxerr <<"fillpolygon not called from "
161 "workarea::workhandler\n";
162 lyxerr << "Painter drawable: " << owner.getPixmap() << endl;
165 #ifndef HAVE_AUTO_PTR
166 XPoint * points = new XPoint[np];
168 auto_ptr<XPoint> points(new XPoint[np]);
170 for (int i=0; i < np; ++i) {
175 XFillPolygon(display, owner.getPixmap(),
176 lyxColorHandler->getGCForeground(col), points, np,
177 Nonconvex, CoordModeOrigin);
178 #ifndef HAVE_AUTO_PTR
185 PainterBase & Painter::arc(int x, int y,
186 unsigned int w, unsigned int h,
187 int a1, int a2, LColor::color col)
189 if (lyxerr.debugging()) {
190 if (!Lgb_bug_find_hack)
191 lyxerr << "arc not called from "
192 "workarea::workhandler\n";
193 lyxerr << "Painter drawable: " << owner.getPixmap() << endl;
196 XDrawArc(display, owner.getPixmap(),
197 lyxColorHandler->getGCForeground(col),
203 /// Draw lines from x1,y1 to x2,y2. They are arrays
204 PainterBase & Painter::segments(int const * x1, int const * y1,
205 int const * x2, int const * y2, int ns,
207 enum line_style ls, enum line_width lw)
209 if (lyxerr.debugging()) {
210 if (!Lgb_bug_find_hack)
211 lyxerr << "segments not called from "
212 "workarea::workhandler\n";
213 lyxerr << "Painter drawable: " << owner.getPixmap() << endl;
216 #ifndef HAVE_AUTO_PTR
217 XSegment * s= new XSegment[ns];
219 auto_ptr<XSegment> s(new XSegment[ns]);
221 for (int i=0; i<ns; ++i) {
227 XDrawSegments(display, owner.getPixmap(),
228 lyxColorHandler->getGCLinepars(ls, lw, col), s, ns);
230 #ifndef HAVE_AUTO_PTR
237 PainterBase & Painter::pixmap(int x, int y, int w, int h, Pixmap bitmap)
239 if (lyxerr.debugging()) {
240 if (!Lgb_bug_find_hack)
241 lyxerr << "workAreaExpose not called from "
242 "workarea::workhandler\n";
243 lyxerr << "Painter drawable: " << owner.getPixmap() << endl;
247 val.function = GXcopy;
248 GC gc = XCreateGC(display, owner.getPixmap(),
250 XCopyArea(display, bitmap, owner.getPixmap(), gc,
252 XFreeGC(display, gc);
257 PainterBase & Painter::text(int x, int y, string const & s, LyXFont const & f)
259 return text(x, y, s.c_str(), s.length(), f);
263 PainterBase & Painter::text(int x, int y, char c, LyXFont const & f)
265 char s[2] = { c, '\0' };
266 return text(x, y, s, 1, f);
270 PainterBase & Painter::text(int x, int y, char const * s, int ls,
273 if (lyxerr.debugging()) {
274 if (!Lgb_bug_find_hack)
275 lyxerr << "text not called from "
276 "workarea::workhandler\n";
277 lyxerr << "Painter drawable: " << owner.getPixmap() << endl;
279 GC gc = lyxColorHandler->getGCForeground(f.realColor());
280 if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
281 lyxfont::XSetFont(display, gc, f);
282 XDrawString(display, owner.getPixmap(), gc, x, y, s, ls);
284 LyXFont smallfont(f);
285 smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
288 for(int i = 0; i < ls; ++i) {
290 if (islower(static_cast<unsigned char>(c))) {
292 lyxfont::XSetFont(display, gc, smallfont);
293 XDrawString(display, owner.getPixmap(),
295 tmpx += lyxfont::XTextWidth(smallfont, &c, 1);
296 //tmpx += lyxfont::width(c, f);
298 lyxfont::XSetFont(display, gc, f);
299 XDrawString(display, owner.getPixmap(),
301 tmpx += lyxfont::XTextWidth(f, &c, 1);
302 //tmpx += lyxfont::width(c, f);
306 underline(f, x, y, lyxfont::width(s, ls, f));
311 void Painter::underline(LyXFont const & f, int x, int y, int width)
313 // What about underbars?
314 if (f.underbar() == LyXFont::ON && f.latex() != LyXFont::ON) {
315 int below = max(lyxfont::maxDescent(f) / 2, 2);
316 int height = max((lyxfont::maxDescent(f) / 4) - 1, 1);
318 line(x, y + below, x + width, y + below, f.color());
320 fillRectangle(x, y + below, width, below + height,