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"
32 #include "frontends/Application.h"
33 #include "frontends/FontMetrics.h"
35 #include "support/lstrings.h"
40 #include <X11/Xft/Xft.h>
42 #include <boost/scoped_array.hpp>
51 GPainter::GPainter(GWorkArea & xwa)
52 : Painter(), owner_(xwa), currentcolor_(LColor::magenta)
57 int GPainter::paperWidth() const
59 return owner_.workWidth();
63 int GPainter::paperHeight() const
65 return owner_.workHeight();
69 inline void GPainter::setForeground(LColor_color clr)
71 if (clr != currentcolor_) {
72 gc_->set_foreground(*(colorhandler_->getGdkColor(clr)));
78 void GPainter::start()
80 pixmap_ = owner_.getPixmap();
81 colorhandler_ = &(owner_.getColorHandler());
83 gc_->set_foreground(*(colorhandler_->getGdkColor(currentcolor_)));
87 inline void GPainter::setLineParam(line_style ls, line_width lw)
91 case Painter::line_thin:
94 case Painter::line_thick:
99 Gdk::LineStyle style = Gdk::LINE_SOLID;
101 case Painter::line_solid:
102 style = Gdk::LINE_SOLID;
104 case Painter::line_onoffdash:
105 style = Gdk::LINE_ON_OFF_DASH;
108 gc_->set_line_attributes(width, style,
109 Gdk::CAP_NOT_LAST, Gdk::JOIN_MITER);
113 void GPainter::point(int x, int y, LColor_color c)
116 pixmap_->draw_point(gc_, x, y);
120 void GPainter::line(int x1, int y1,
127 setLineParam(ls, lw);
128 pixmap_->draw_line(gc_, x1, y1, x2, y2);
132 void GPainter::lines(int const * xp, int const * yp, int np,
138 setLineParam(ls, lw);
139 std::vector<Gdk::Point> points(np);
141 for (int i = 0; i < np; ++i) {
142 points[i].set_x(xp[i]);
143 points[i].set_y(yp[i]);
145 pixmap_->draw_lines(gc_, points);
149 void GPainter::rectangle(int x, int y, int w, int h,
155 setLineParam(ls, lw);
156 pixmap_->draw_rectangle(gc_, false, x, y, w, h);
160 void GPainter::fillRectangle(int x, int y, int w, int h,
164 pixmap_->draw_rectangle(gc_, true, x, y, w, h);
168 void GPainter::arc(int x, int y, unsigned int w, unsigned int h,
169 int a1, int a2, LColor_color col)
172 pixmap_->draw_arc(gc_,
173 false, x, y, w, h, a1, a2);
177 void GPainter::image(int x, int y, int w, int h,
178 graphics::Image const & i)
180 graphics::LyXGdkImage const & image =
181 static_cast<graphics::LyXGdkImage const &>(i);
182 Glib::RefPtr<Gdk::Pixbuf> const & pixbuf = image.pixbuf();
183 Glib::RefPtr<Gdk::Pixmap> pixmap = pixmap_;
185 Glib::RefPtr<Gdk::GC> gc = gc_;
186 pixmap->draw_pixbuf (gc, pixbuf, 0, 0, x, y, w, h,
187 Gdk::RGB_DITHER_NONE, 0, 0);
192 inline XftFont * getXftFont(LyXFont const & f)
194 return fontLoader.load(f.family(), f.series(),
195 f.realShape(), f.size());
201 int GPainter::text(int x, int y,
202 char_type const * s, size_t ls,
205 XftFont * font = getXftFont(f);
206 XftColor * xftClr = owner_.getColorHandler().
207 getXftColor(f.realColor());
208 XftDraw * draw = owner_.getXftDraw();
211 if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
212 XftDrawString32(draw,
216 reinterpret_cast<FcChar32 const *>(s),
218 textwidth = theApp->fontLoader().metrics(f).width(s, ls);
220 LyXFont smallfont(f);
221 smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
222 XftFont * fontS = getXftFont(smallfont);
223 for (unsigned int i = 0; i < ls; ++i) {
224 // Ok, this looks quite ugly...
225 char_type c = gdk_keyval_to_unicode(gdk_keyval_to_upper(gdk_unicode_to_keyval(s[i])));
227 XftDrawString32(draw,
231 reinterpret_cast<FcChar32 *>(&c),
233 textwidth += theApp->fontLoader().metrics(smallfont).width(c);
235 XftDrawString32(draw,
239 reinterpret_cast<FcChar32 *>(&c),
241 textwidth += theApp->fontLoader().metrics(f).width(c);
245 if (f.underbar() == LyXFont::ON)
246 underline(f, x, y, textwidth);
252 int GPainter::text(int x, int y, docstring const & s, LyXFont const & f)
254 return text (x, y, reinterpret_cast<char_type const *>(s.data()), s.size(), f);
258 int GPainter::text(int x, int y, char_type c, LyXFont const & f)
260 return text (x, y, &c, 1, f);
264 } // namespace frontend