2002-06-12 15:01:32 +00:00
|
|
|
/**
|
|
|
|
* \file XPainter.C
|
2002-09-05 15:14:23 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
2002-06-12 15:01:32 +00:00
|
|
|
* \author unknown
|
2002-12-01 22:59:25 +00:00
|
|
|
* \author John Levon
|
2002-09-05 14:10:50 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS
|
2002-06-12 15:01:32 +00:00
|
|
|
*/
|
2000-02-10 17:53:36 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2002-06-12 15:01:32 +00:00
|
|
|
#include "XPainter.h"
|
2000-02-10 17:53:36 +00:00
|
|
|
#include "LString.h"
|
|
|
|
#include "debug.h"
|
2002-06-12 15:01:32 +00:00
|
|
|
#include "XWorkArea.h"
|
2002-05-24 14:34:32 +00:00
|
|
|
#include "xfont_metrics.h"
|
2000-04-16 22:27:30 +00:00
|
|
|
#include "ColorHandler.h"
|
2000-07-04 20:32:37 +00:00
|
|
|
#include "lyxrc.h"
|
|
|
|
#include "encoding.h"
|
2001-04-05 12:26:41 +00:00
|
|
|
#include "language.h"
|
2000-02-10 17:53:36 +00:00
|
|
|
|
2002-07-16 18:20:12 +00:00
|
|
|
#ifdef USE_XFORMS_IMAGE_LOADER
|
2002-07-15 17:17:57 +00:00
|
|
|
#include "xformsImage.h"
|
2002-07-16 18:20:12 +00:00
|
|
|
#else
|
|
|
|
#include "graphics/GraphicsImageXPM.h"
|
|
|
|
#endif
|
2000-10-12 10:46:06 +00:00
|
|
|
|
2001-12-10 20:06:59 +00:00
|
|
|
#include "support/LAssert.h"
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
2002-05-22 01:16:37 +00:00
|
|
|
#include <boost/scoped_array.hpp>
|
2001-12-10 20:06:59 +00:00
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
using std::endl;
|
2000-04-04 00:19:15 +00:00
|
|
|
using std::max;
|
2000-03-28 02:18:55 +00:00
|
|
|
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
XPainter::XPainter(XWorkArea & xwa)
|
2002-06-12 15:01:32 +00:00
|
|
|
: Painter(), owner_(xwa)
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-06-12 15:01:32 +00:00
|
|
|
int XPainter::paperWidth() const
|
|
|
|
{
|
|
|
|
return owner_.workWidth();
|
|
|
|
}
|
2002-03-13 13:22:54 +00:00
|
|
|
|
|
|
|
|
2002-06-12 15:01:32 +00:00
|
|
|
int XPainter::paperHeight() const
|
|
|
|
{
|
|
|
|
return owner_.workHeight();
|
|
|
|
}
|
2000-02-10 17:53:36 +00:00
|
|
|
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2002-06-12 15:01:32 +00:00
|
|
|
Painter & XPainter::point(int x, int y, LColor::color c)
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2002-06-12 15:01:32 +00:00
|
|
|
XDrawPoint(fl_get_display(), owner_.getPixmap(),
|
|
|
|
lyxColorHandler->getGCForeground(c), x, y);
|
2000-02-10 17:53:36 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-01 22:59:25 +00:00
|
|
|
Painter & XPainter::line(int x1, int y1,
|
2002-06-12 15:01:32 +00:00
|
|
|
int x2, int y2,
|
|
|
|
LColor::color col,
|
|
|
|
line_style ls,
|
|
|
|
line_width lw)
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2002-12-01 22:59:25 +00:00
|
|
|
XDrawLine(fl_get_display(), owner_.getPixmap(),
|
2002-06-12 15:01:32 +00:00
|
|
|
lyxColorHandler->getGCLinepars(ls, lw, col),
|
|
|
|
x1, y1, x2, y2);
|
2000-02-10 17:53:36 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-01 22:59:25 +00:00
|
|
|
Painter & XPainter::lines(int const * xp, int const * yp,
|
2002-06-12 15:01:32 +00:00
|
|
|
int np,
|
|
|
|
LColor::color col,
|
|
|
|
line_style ls,
|
|
|
|
line_width lw)
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2001-12-10 20:06:59 +00:00
|
|
|
boost::scoped_array<XPoint> points(new XPoint[np]);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
for (int i = 0; i < np; ++i) {
|
2000-02-10 17:53:36 +00:00
|
|
|
points[i].x = xp[i];
|
|
|
|
points[i].y = yp[i];
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-12-01 22:59:25 +00:00
|
|
|
XDrawLines(fl_get_display(), owner_.getPixmap(),
|
|
|
|
lyxColorHandler->getGCLinepars(ls, lw, col),
|
2002-06-12 15:01:32 +00:00
|
|
|
points.get(), np, CoordModeOrigin);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
return *this;
|
2002-12-01 22:59:25 +00:00
|
|
|
}
|
2000-02-10 17:53:36 +00:00
|
|
|
|
|
|
|
|
2002-12-01 22:59:25 +00:00
|
|
|
Painter & XPainter::rectangle(int x, int y,
|
2002-06-12 15:01:32 +00:00
|
|
|
int w, int h,
|
|
|
|
LColor::color col,
|
|
|
|
line_style ls,
|
|
|
|
line_width lw)
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2002-06-12 15:01:32 +00:00
|
|
|
XDrawRectangle(fl_get_display(), owner_.getPixmap(),
|
2002-12-01 22:59:25 +00:00
|
|
|
lyxColorHandler->getGCLinepars(ls, lw, col),
|
2002-06-12 15:01:32 +00:00
|
|
|
x, y, w, h);
|
2000-02-10 17:53:36 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-01 22:59:25 +00:00
|
|
|
Painter & XPainter::fillRectangle(int x, int y,
|
2002-06-12 15:01:32 +00:00
|
|
|
int w, int h,
|
|
|
|
LColor::color col)
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2002-06-12 15:01:32 +00:00
|
|
|
XFillRectangle(fl_get_display(), owner_.getPixmap(),
|
|
|
|
lyxColorHandler->getGCForeground(col), x, y, w, h);
|
2000-02-10 17:53:36 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-01 22:59:25 +00:00
|
|
|
Painter & XPainter::fillPolygon(int const * xp, int const * yp,
|
2002-06-12 15:01:32 +00:00
|
|
|
int np, LColor::color col)
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2001-12-10 20:06:59 +00:00
|
|
|
boost::scoped_array<XPoint> points(new XPoint[np]);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2001-12-10 20:06:59 +00:00
|
|
|
for (int i = 0; i < np; ++i) {
|
2000-02-10 17:53:36 +00:00
|
|
|
points[i].x = xp[i];
|
|
|
|
points[i].y = yp[i];
|
|
|
|
}
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2002-06-12 15:01:32 +00:00
|
|
|
XFillPolygon(fl_get_display(), owner_.getPixmap(),
|
2002-12-01 22:59:25 +00:00
|
|
|
lyxColorHandler->getGCForeground(col), points.get(),
|
2002-06-12 15:01:32 +00:00
|
|
|
np, Nonconvex, CoordModeOrigin);
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
return *this;
|
2002-03-21 17:27:08 +00:00
|
|
|
}
|
2000-02-10 17:53:36 +00:00
|
|
|
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2002-06-12 15:01:32 +00:00
|
|
|
Painter & XPainter::arc(int x, int y,
|
|
|
|
unsigned int w, unsigned int h,
|
|
|
|
int a1, int a2, LColor::color col)
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2002-12-01 22:59:25 +00:00
|
|
|
XDrawArc(fl_get_display(), owner_.getPixmap(),
|
2002-06-12 15:01:32 +00:00
|
|
|
lyxColorHandler->getGCForeground(col),
|
|
|
|
x, y, w, h, a1, a2);
|
2002-12-01 22:59:25 +00:00
|
|
|
return *this;
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
|
|
|
|
2002-12-01 22:59:25 +00:00
|
|
|
|
|
|
|
Painter & XPainter::image(int x, int y,
|
2002-06-12 15:01:32 +00:00
|
|
|
int w, int h,
|
2002-07-15 17:17:57 +00:00
|
|
|
grfx::Image const & i)
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2002-07-16 18:20:12 +00:00
|
|
|
#ifdef USE_XFORMS_IMAGE_LOADER
|
2002-07-15 17:17:57 +00:00
|
|
|
grfx::xformsImage const & image = static_cast<grfx::xformsImage const &>(i);
|
2002-07-16 18:20:12 +00:00
|
|
|
#else
|
|
|
|
grfx::ImageXPM const & image = static_cast<grfx::ImageXPM const &>(i);
|
|
|
|
#endif
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
XGCValues val;
|
|
|
|
val.function = GXcopy;
|
2002-06-12 15:01:32 +00:00
|
|
|
GC gc = XCreateGC(fl_get_display(), owner_.getPixmap(),
|
|
|
|
GCFunction, &val);
|
2002-12-01 22:59:25 +00:00
|
|
|
XCopyArea(fl_get_display(), image.getPixmap(), owner_.getPixmap(),
|
2002-06-12 15:01:32 +00:00
|
|
|
gc, 0, 0, w, h, x, y);
|
|
|
|
XFreeGC(fl_get_display(), gc);
|
2000-02-10 17:53:36 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2001-12-10 20:06:59 +00:00
|
|
|
|
2002-12-01 22:59:25 +00:00
|
|
|
Painter & XPainter::text(int x, int y,
|
2002-06-12 15:01:32 +00:00
|
|
|
string const & s, LyXFont const & f)
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2001-07-12 11:11:10 +00:00
|
|
|
return text(x, y, s.data(), s.length(), f);
|
2000-02-14 22:14:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-01 22:59:25 +00:00
|
|
|
Painter & XPainter::text(int x, int y,
|
2002-06-12 15:01:32 +00:00
|
|
|
char c, LyXFont const & f)
|
2000-02-14 22:14:48 +00:00
|
|
|
{
|
|
|
|
char s[2] = { c, '\0' };
|
|
|
|
return text(x, y, s, 1, f);
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-01 22:59:25 +00:00
|
|
|
Painter & XPainter::text(int x, int y,
|
2002-06-12 15:01:32 +00:00
|
|
|
char const * s, size_t ls,
|
|
|
|
LyXFont const & f)
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2000-07-04 20:32:37 +00:00
|
|
|
if (lyxrc.font_norm_type == LyXRC::ISO_10646_1) {
|
2001-12-10 20:06:59 +00:00
|
|
|
boost::scoped_array<XChar2b> xs(new XChar2b[ls]);
|
2000-07-20 10:04:27 +00:00
|
|
|
Encoding const * encoding = f.language()->encoding();
|
2000-10-11 21:06:43 +00:00
|
|
|
LyXFont font(f);
|
2001-08-30 22:42:26 +00:00
|
|
|
if (f.isSymbolFont()) {
|
2000-07-20 10:04:27 +00:00
|
|
|
#ifdef USE_UNICODE_FOR_SYMBOLS
|
2000-10-11 21:06:43 +00:00
|
|
|
font.setFamily(LyXFont::ROMAN_FAMILY);
|
|
|
|
font.setShape(LyXFont::UP_SHAPE);
|
2000-07-20 10:04:27 +00:00
|
|
|
#endif
|
2000-10-10 12:36:36 +00:00
|
|
|
encoding = encodings.symbol_encoding();
|
2000-07-20 10:04:27 +00:00
|
|
|
}
|
2000-10-10 12:36:36 +00:00
|
|
|
for (size_t i = 0; i < ls; ++i) {
|
2000-07-20 10:04:27 +00:00
|
|
|
Uchar c = encoding->ucs(s[i]);
|
2000-07-04 20:32:37 +00:00
|
|
|
xs[i].byte1 = c >> 8;
|
|
|
|
xs[i].byte2 = c & 0xff;
|
2000-07-20 10:04:27 +00:00
|
|
|
}
|
2002-08-15 16:02:22 +00:00
|
|
|
text(x, y, xs.get(), ls, font);
|
2000-07-04 20:32:37 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2000-04-16 22:27:30 +00:00
|
|
|
GC gc = lyxColorHandler->getGCForeground(f.realColor());
|
2000-04-04 00:19:15 +00:00
|
|
|
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
|
2002-06-12 15:01:32 +00:00
|
|
|
xfont_metrics::XSetFont(fl_get_display(), gc, f);
|
|
|
|
XDrawString(fl_get_display(), owner_.getPixmap(), gc, x, y, s, ls);
|
2000-04-04 00:19:15 +00:00
|
|
|
} else {
|
|
|
|
LyXFont smallfont(f);
|
|
|
|
smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
|
|
|
|
int tmpx = x;
|
2000-11-04 10:00:12 +00:00
|
|
|
for (size_t i = 0; i < ls; ++i) {
|
2001-12-20 15:11:51 +00:00
|
|
|
char const c = uppercase(s[i]);
|
|
|
|
if (c != s[i]) {
|
2002-06-12 15:01:32 +00:00
|
|
|
xfont_metrics::XSetFont(fl_get_display(), gc, smallfont);
|
|
|
|
XDrawString(fl_get_display(), owner_.getPixmap(), gc,
|
|
|
|
tmpx, y, &c, 1);
|
2002-06-11 21:44:00 +00:00
|
|
|
tmpx += xfont_metrics::XTextWidth(smallfont, &c, 1);
|
2000-04-04 00:19:15 +00:00
|
|
|
} else {
|
2002-06-12 15:01:32 +00:00
|
|
|
xfont_metrics::XSetFont(fl_get_display(), gc, f);
|
|
|
|
XDrawString(fl_get_display(), owner_.getPixmap(), gc,
|
|
|
|
tmpx, y, &c, 1);
|
2002-06-11 21:44:00 +00:00
|
|
|
tmpx += xfont_metrics::XTextWidth(f, &c, 1);
|
2000-04-04 00:19:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2001-08-03 18:28:11 +00:00
|
|
|
if (f.underbar() == LyXFont::ON) {
|
2002-05-24 14:34:32 +00:00
|
|
|
underline(f, x, y, font_metrics::width(s, ls, f));
|
2001-08-03 18:28:11 +00:00
|
|
|
}
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-01 22:59:25 +00:00
|
|
|
Painter & XPainter::text(int x, int y,
|
2002-06-12 15:01:32 +00:00
|
|
|
XChar2b const * s, size_t ls,
|
|
|
|
LyXFont const & f)
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2000-07-04 20:32:37 +00:00
|
|
|
GC gc = lyxColorHandler->getGCForeground(f.realColor());
|
|
|
|
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
|
2002-06-12 15:01:32 +00:00
|
|
|
xfont_metrics::XSetFont(fl_get_display(), gc, f);
|
|
|
|
XDrawString16(fl_get_display(), owner_.getPixmap(), gc, x, y, s, ls);
|
2000-07-04 20:32:37 +00:00
|
|
|
} else {
|
|
|
|
LyXFont smallfont(f);
|
|
|
|
smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
|
2001-06-04 23:57:32 +00:00
|
|
|
static XChar2b c;
|
2000-07-04 20:32:37 +00:00
|
|
|
int tmpx = x;
|
2002-06-12 15:01:32 +00:00
|
|
|
for (size_t i = 0; i < ls; ++i) {
|
2001-12-20 15:11:51 +00:00
|
|
|
if (s[i].byte1)
|
|
|
|
c = s[i];
|
|
|
|
else {
|
|
|
|
c.byte1 = s[i].byte1;
|
|
|
|
c.byte2 = uppercase(s[i].byte2);
|
|
|
|
}
|
|
|
|
if (c.byte2 != s[i].byte2) {
|
2002-06-12 15:01:32 +00:00
|
|
|
xfont_metrics::XSetFont(fl_get_display(), gc, smallfont);
|
|
|
|
XDrawString16(fl_get_display(), owner_.getPixmap(), gc,
|
|
|
|
tmpx, y, &c, 1);
|
2002-06-11 21:44:00 +00:00
|
|
|
tmpx += xfont_metrics::XTextWidth16(smallfont, &c, 1);
|
2000-07-04 20:32:37 +00:00
|
|
|
} else {
|
2002-06-12 15:01:32 +00:00
|
|
|
xfont_metrics::XSetFont(fl_get_display(), gc, f);
|
|
|
|
XDrawString16(fl_get_display(), owner_.getPixmap(), gc,
|
|
|
|
tmpx, y, &c, 1);
|
2002-06-11 21:44:00 +00:00
|
|
|
tmpx += xfont_metrics::XTextWidth16(f, &c, 1);
|
2000-07-04 20:32:37 +00:00
|
|
|
}
|
|
|
|
}
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2001-08-03 18:28:11 +00:00
|
|
|
if (f.underbar() == LyXFont::ON) {
|
2002-06-11 21:44:00 +00:00
|
|
|
underline(f, x, y, xfont_metrics::width(s, ls, f));
|
2001-08-03 18:28:11 +00:00
|
|
|
}
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2000-07-04 20:32:37 +00:00
|
|
|
return *this;
|
|
|
|
}
|