3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
14 // Too hard to make concept checks work with this file
15 #ifdef _GLIBCXX_CONCEPT_CHECKS
16 #undef _GLIBCXX_CONCEPT_CHECKS
18 #ifdef _GLIBCPP_CONCEPT_CHECKS
19 #undef _GLIBCPP_CONCEPT_CHECKS
24 #include "GWorkArea.h"
25 #include "LyXGdkImage.h"
30 #include "xftFontLoader.h"
31 #include "frontends/font_metrics.h"
33 #include "support/lstrings.h"
38 #include <X11/Xft/Xft.h>
40 #include <boost/scoped_array.hpp>
49 GPainter::GPainter(GWorkArea & xwa)
50 : Painter(), owner_(xwa), currentcolor_(LColor::magenta)
55 int GPainter::paperWidth() const
57 return owner_.workWidth();
61 int GPainter::paperHeight() const
63 return owner_.workHeight();
67 inline void GPainter::setForeground(LColor_color clr)
69 if (clr != currentcolor_) {
70 gc_->set_foreground(*(colorhandler_->getGdkColor(clr)));
76 void GPainter::start()
78 pixmap_ = owner_.getPixmap();
79 colorhandler_ = &(owner_.getColorHandler());
81 gc_->set_foreground(*(colorhandler_->getGdkColor(currentcolor_)));
85 inline void GPainter::setLineParam(line_style ls, line_width lw)
89 case Painter::line_thin:
92 case Painter::line_thick:
97 Gdk::LineStyle style = Gdk::LINE_SOLID;
99 case Painter::line_solid:
100 style = Gdk::LINE_SOLID;
102 case Painter::line_onoffdash:
103 style = Gdk::LINE_ON_OFF_DASH;
106 gc_->set_line_attributes(width, style,
107 Gdk::CAP_NOT_LAST, Gdk::JOIN_MITER);
111 void GPainter::point(int x, int y, LColor_color c)
114 pixmap_->draw_point(gc_, x, y);
118 void GPainter::line(int x1, int y1,
125 setLineParam(ls, lw);
126 pixmap_->draw_line(gc_, x1, y1, x2, y2);
130 void GPainter::lines(int const * xp, int const * yp, int np,
136 setLineParam(ls, lw);
137 std::vector<Gdk::Point> points(np);
139 for (int i = 0; i < np; ++i) {
140 points[i].set_x(xp[i]);
141 points[i].set_y(yp[i]);
143 pixmap_->draw_lines(gc_, points);
147 void GPainter::rectangle(int x, int y, int w, int h,
153 setLineParam(ls, lw);
154 pixmap_->draw_rectangle(gc_, false, x, y, w, h);
158 void GPainter::fillRectangle(int x, int y, int w, int h,
162 pixmap_->draw_rectangle(gc_, true, x, y, w, h);
166 void GPainter::arc(int x, int y, unsigned int w, unsigned int h,
167 int a1, int a2, LColor_color col)
170 pixmap_->draw_arc(gc_,
171 false, x, y, w, h, a1, a2);
175 void GPainter::image(int x, int y, int w, int h,
176 graphics::Image const & i)
178 graphics::LyXGdkImage const & image =
179 static_cast<graphics::LyXGdkImage const &>(i);
180 Glib::RefPtr<Gdk::Pixbuf> const & pixbuf = image.pixbuf();
181 Glib::RefPtr<Gdk::Pixmap> pixmap = pixmap_;
183 Glib::RefPtr<Gdk::GC> gc = gc_;
184 pixmap->draw_pixbuf (gc, pixbuf, 0, 0, x, y, w, h,
185 Gdk::RGB_DITHER_NONE, 0, 0);
190 inline XftFont * getXftFont(LyXFont const & f)
192 return fontLoader.load(f.family(), f.series(),
193 f.realShape(), f.size());
199 void GPainter::text(int x, int y,
200 char_type const * s, size_t ls,
203 XftFont * font = getXftFont(f);
204 XftColor * xftClr = owner_.getColorHandler().
205 getXftColor(f.realColor());
206 XftDraw * draw = owner_.getXftDraw();
207 if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
208 XftDrawString32(draw,
212 reinterpret_cast<FcChar32 const *>(s),
215 LyXFont smallfont(f);
216 smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
217 XftFont * fontS = getXftFont(smallfont);
219 for (unsigned int i = 0; i < ls; ++i) {
220 // Ok, this looks quite ugly...
221 char_type c = gdk_keyval_to_unicode(gdk_keyval_to_upper(gdk_unicode_to_keyval(s[i])));
223 XftDrawString32(draw,
227 reinterpret_cast<FcChar32 *>(&c),
229 tmpx += font_metrics::width(c, smallfont);
231 XftDrawString32(draw,
235 reinterpret_cast<FcChar32 *>(&c),
237 tmpx += font_metrics::width(c, f);
241 if (f.underbar() == LyXFont::ON)
242 underline(f, x, y, font_metrics::width(s, ls, f));
246 void GPainter::text(int x, int y, docstring const & s, LyXFont const & f)
248 text (x, y, reinterpret_cast<char_type const *>(s.data()), s.size(), f);
252 void GPainter::text(int x, int y, char_type c, LyXFont const & f)
254 text (x, y, &c, 1, f);
258 } // namespace frontend