3 * Copyright 1998-2002 the LyX Team
4 * Read the file COPYING
6 * \author John Levon <moz@compsoc.man.ac.uk>
12 #pragma implementation
17 //#include "graphics/GraphicsImage.h"
18 #include "font_metrics.h"
19 #include "support/lstrings.h"
24 #include "QWorkArea.h"
25 #include "qfont_loader.h"
26 #include "QLPainter.h"
32 QLPainter::QLPainter(QWorkArea & qwa)
33 : Painter(), owner_(qwa), paint_check_(0)
35 qp_.reset(new QPainter());
39 void QLPainter::start()
41 if (++paint_check_ == 1)
42 qp_->begin(owner_.getPixmap());
48 if (paint_check_ == 0) {
49 lyxerr << "ended painting whilst not painting ??" << endl;
50 } else if (--paint_check_ == 0) {
56 int QLPainter::paperWidth() const
58 return owner_.workWidth();
62 int QLPainter::paperHeight() const
64 return owner_.workHeight();
68 QPainter & QLPainter::setPen(LColor::color c,
69 Painter::line_style ls, Painter::line_width lw)
71 QPen pen = qp_->pen();
73 pen.setColor(lcolor.getX11Name(c).c_str());
76 case line_solid: pen.setStyle(QPen::SolidLine); break;
77 case line_onoffdash: pen.setStyle(QPen::DashLine); break;
81 case line_thin: pen.setWidth(0); break;
82 case line_thick: pen.setWidth(3); break;
90 Painter & QLPainter::point(int x, int y, LColor::color c)
92 setPen(c).drawPoint(x, y);
97 Painter & QLPainter::line(int x1, int y1,
103 setPen(col, ls, lw).drawLine(x1, y1, x2, y2);
108 Painter & QLPainter::lines(int const * xp, int const * yp,
116 QCOORD points[np * 2];
120 for (int i = 0; i < np; ++i) {
125 setPen(col, ls, lw).drawPolyline(QPointArray(np, points));
130 Painter & QLPainter::rectangle(int x, int y,
136 setPen(col, ls, lw).drawRect(x, y, w, h);
141 Painter & QLPainter::fillRectangle(int x, int y,
145 qp_->fillRect(x, y, w, h, QColor(lcolor.getX11Name(col).c_str()));
150 Painter & QLPainter::fillPolygon(int const * xp, int const * yp,
151 int np, LColor::color col)
155 QCOORD points[np * 2];
159 for (int i = 0; i < np; ++i) {
164 setPen(col).drawPolygon(QPointArray(np, points));
169 Painter & QLPainter::arc(int x, int y,
170 unsigned int w, unsigned int h,
171 int a1, int a2, LColor::color col)
174 setPen(col).drawArc(x, y, w, h, a1, a2);
179 Painter & QLPainter::image(int , int ,
181 grfx::GImage const & )
185 val.function = GXcopy;
186 GC gc = XCreateGC(display(), owner_.getPixmap(),
188 XCopyArea(display(), image.getPixmap(), owner_.getPixmap(),
189 gc, 0, 0, w, h, x, y);
190 XFreeGC(display(), gc);
196 Painter & QLPainter::text(int x, int y,
197 string const & s, LyXFont const & f)
199 return text(x, y, s.data(), s.length(), f);
203 Painter & QLPainter::text(int x, int y,
204 char c, LyXFont const & f)
206 char s[2] = { c, '\0' };
207 return text(x, y, s, 1, f);
211 void QLPainter::smallCapsText(int x, int y,
212 char const * s, size_t ls,
215 LyXFont smallfont(f);
216 smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
218 QFont const & qfont = fontloader.get(f);
219 QFont const & qsmallfont = fontloader.get(smallfont);
220 QFontMetrics const & qfontm = QFontMetrics(qfont);
221 QFontMetrics const & qsmallfontm = QFontMetrics(qsmallfont);
224 for (size_t i = 0; i < ls; ++i) {
225 char const c = uppercase(s[i]);
227 qp_->setFont(qsmallfont);
228 qp_->drawText(tmpx, y, &c, 1);
229 tmpx += qsmallfontm.width(&c, 1);
232 qp_->drawText(tmpx, y, &c, 1);
233 tmpx += qfontm.width(&c, 1);
239 Painter & QLPainter::text(int x, int y,
240 char const * s, size_t ls,
245 if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
246 qp_->setFont(fontloader.get(f));
247 qp_->drawText(x, y, s, ls);
249 smallCapsText(x, y, s, ls, f);
252 if (f.underbar() == LyXFont::ON) {
253 underline(f, x, y, font_metrics::width(s, ls, f));