2000-02-10 17:53:36 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
2000-02-10 17:53:36 +00:00
|
|
|
* LyX, The Document Processor
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
2001-05-30 13:53:44 +00:00
|
|
|
* Copyright 1998-2001 The LyX Team
|
2000-02-10 17:53:36 +00:00
|
|
|
*
|
|
|
|
*======================================================*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "Painter.h"
|
|
|
|
#include "LString.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "lyxfont.h"
|
2000-02-18 22:22:42 +00:00
|
|
|
#include "WorkArea.h"
|
2000-04-04 00:19:15 +00:00
|
|
|
#include "font.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
|
|
|
|
2001-12-10 20:06:59 +00:00
|
|
|
#include "frontends/GUIRunTime.h"
|
2002-02-27 09:59:52 +00:00
|
|
|
#include "graphics/GraphicsImage.h"
|
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>
|
|
|
|
|
2002-03-13 13:22:54 +00:00
|
|
|
|
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-03-13 13:22:54 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
inline
|
2002-03-21 17:27:08 +00:00
|
|
|
Display * display()
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2002-03-13 13:22:54 +00:00
|
|
|
return GUIRunTime::x11Display();
|
|
|
|
}
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-13 13:22:54 +00:00
|
|
|
Painter::Painter(WorkArea & wa)
|
|
|
|
: PainterBase(wa)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
2001-12-10 20:06:59 +00:00
|
|
|
// Basic drawing routines
|
2000-02-10 17:53:36 +00:00
|
|
|
|
2000-02-11 13:52:44 +00:00
|
|
|
PainterBase & Painter::point(int x, int y, LColor::color c)
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2002-03-13 13:22:54 +00:00
|
|
|
XDrawPoint(display(), owner.getPixmap(),
|
2000-04-16 22:27:30 +00:00
|
|
|
lyxColorHandler->getGCForeground(c), x, y);
|
2000-02-10 17:53:36 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-11 13:52:44 +00:00
|
|
|
PainterBase & Painter::line(int x1, int y1, int x2, int y2,
|
2002-03-13 13:22:54 +00:00
|
|
|
LColor::color col,
|
|
|
|
enum line_style ls,
|
|
|
|
enum line_width lw)
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2002-03-21 17:27:08 +00:00
|
|
|
XDrawLine(display(), owner.getPixmap(),
|
2000-04-16 22:27:30 +00:00
|
|
|
lyxColorHandler->getGCLinepars(ls, lw, col),
|
|
|
|
x1, y1, x2, y2);
|
2000-02-10 17:53:36 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-11 13:52:44 +00:00
|
|
|
PainterBase & Painter::lines(int const * xp, int const * yp, int np,
|
2000-04-04 00:19:15 +00:00
|
|
|
LColor::color col,
|
|
|
|
enum line_style ls,
|
|
|
|
enum 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
|
|
|
|
|
|
|
XDrawLines(display(), owner.getPixmap(),
|
|
|
|
lyxColorHandler->getGCLinepars(ls, lw, col),
|
2001-12-10 20:06:59 +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-03-21 17:27:08 +00:00
|
|
|
}
|
2000-02-10 17:53:36 +00:00
|
|
|
|
|
|
|
|
2000-02-11 13:52:44 +00:00
|
|
|
PainterBase & Painter::rectangle(int x, int y, int w, int h,
|
2000-04-04 00:19:15 +00:00
|
|
|
LColor::color col,
|
|
|
|
enum line_style ls,
|
|
|
|
enum line_width lw)
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2002-03-13 13:22:54 +00:00
|
|
|
XDrawRectangle(display(), owner.getPixmap(),
|
2002-03-21 17:27:08 +00:00
|
|
|
lyxColorHandler->getGCLinepars(ls, lw, col),
|
2000-02-10 17:53:36 +00:00
|
|
|
x, y, w, h);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-11 13:52:44 +00:00
|
|
|
PainterBase & Painter::fillRectangle(int x, int y, int w, int h,
|
2002-03-13 13:22:54 +00:00
|
|
|
LColor::color col)
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2002-03-13 13:22:54 +00:00
|
|
|
XFillRectangle(display(), owner.getPixmap(),
|
2000-04-16 22:27:30 +00:00
|
|
|
lyxColorHandler->getGCForeground(col), x, y, w, h);
|
2000-02-10 17:53:36 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-11 13:52:44 +00:00
|
|
|
PainterBase & Painter::fillPolygon(int const * xp, int const * yp, int np,
|
2002-03-13 13:22:54 +00:00
|
|
|
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-03-21 17:27:08 +00:00
|
|
|
|
2002-03-13 13:22:54 +00:00
|
|
|
XFillPolygon(display(), owner.getPixmap(),
|
2002-03-21 17:27:08 +00:00
|
|
|
lyxColorHandler->getGCForeground(col), points.get(), np,
|
2000-02-10 17:53:36 +00:00
|
|
|
Nonconvex, CoordModeOrigin);
|
2002-03-21 17:27:08 +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
|
|
|
|
|
|
|
|
2000-02-11 13:52:44 +00:00
|
|
|
PainterBase & Painter::arc(int x, int y,
|
2002-03-13 13:22:54 +00:00
|
|
|
unsigned int w, unsigned int h,
|
|
|
|
int a1, int a2, LColor::color col)
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2002-03-21 17:27:08 +00:00
|
|
|
XDrawArc(display(), owner.getPixmap(),
|
2000-04-16 22:27:30 +00:00
|
|
|
lyxColorHandler->getGCForeground(col),
|
2002-03-21 17:27:08 +00:00
|
|
|
x, y, w, h, a1, a2);
|
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
|
|
|
|
|
|
|
|
|
|
|
/// Draw lines from x1,y1 to x2,y2. They are arrays
|
2002-03-21 17:27:08 +00:00
|
|
|
PainterBase & Painter::segments(int const * x1, int const * y1,
|
2002-03-13 13:22:54 +00:00
|
|
|
int const * x2, int const * y2, int ns,
|
|
|
|
LColor::color col,
|
|
|
|
enum line_style ls, enum line_width lw)
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2001-12-10 20:06:59 +00:00
|
|
|
boost::scoped_array<XSegment> s(new XSegment[ns]);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2001-12-10 20:06:59 +00:00
|
|
|
for (int i = 0; i < ns; ++i) {
|
2000-02-10 17:53:36 +00:00
|
|
|
s[i].x1 = x1[i];
|
|
|
|
s[i].y1 = y1[i];
|
|
|
|
s[i].x2 = x2[i];
|
|
|
|
s[i].y2 = y2[i];
|
|
|
|
}
|
2002-03-13 13:22:54 +00:00
|
|
|
XDrawSegments(display(), owner.getPixmap(),
|
2001-12-10 20:06:59 +00:00
|
|
|
lyxColorHandler->getGCLinepars(ls, lw, col),
|
|
|
|
s.get(), ns);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2001-12-10 20:06:59 +00:00
|
|
|
|
2002-03-13 13:22:54 +00:00
|
|
|
PainterBase & Painter::image(int x, int y, int w, int h,
|
|
|
|
grfx::GImage const & image)
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
|
|
|
XGCValues val;
|
|
|
|
val.function = GXcopy;
|
2002-03-13 13:22:54 +00:00
|
|
|
GC gc = XCreateGC(display(), owner.getPixmap(),
|
2000-02-10 17:53:36 +00:00
|
|
|
GCFunction, &val);
|
2002-03-13 13:22:54 +00:00
|
|
|
XCopyArea(display(), image.getPixmap(), owner.getPixmap(), gc,
|
2000-02-10 17:53:36 +00:00
|
|
|
0, 0, w, h, x, y);
|
2002-03-13 13:22:54 +00:00
|
|
|
XFreeGC(display(), gc);
|
2000-02-10 17:53:36 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2001-12-10 20:06:59 +00:00
|
|
|
|
2000-02-11 13:52:44 +00:00
|
|
|
PainterBase & Painter::text(int x, int y, 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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PainterBase & Painter::text(int x, int y, char c, LyXFont const & f)
|
|
|
|
{
|
|
|
|
char s[2] = { c, '\0' };
|
|
|
|
return text(x, y, s, 1, f);
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-27 18:13:30 +00:00
|
|
|
PainterBase & Painter::text(int x, int y, char const * s, size_t ls,
|
2002-03-13 13:22:54 +00:00
|
|
|
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
|
|
|
}
|
2001-12-10 20:06:59 +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-03-13 13:22:54 +00:00
|
|
|
lyxfont::XSetFont(display(), gc, f);
|
|
|
|
XDrawString(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-03-13 13:22:54 +00:00
|
|
|
lyxfont::XSetFont(display(), gc, smallfont);
|
|
|
|
XDrawString(display(), owner.getPixmap(), gc,
|
2001-12-20 15:11:51 +00:00
|
|
|
tmpx, y, &c, 1);
|
2000-04-04 00:19:15 +00:00
|
|
|
tmpx += lyxfont::XTextWidth(smallfont, &c, 1);
|
|
|
|
} else {
|
2002-03-13 13:22:54 +00:00
|
|
|
lyxfont::XSetFont(display(), gc, f);
|
|
|
|
XDrawString(display(), owner.getPixmap(), gc,
|
2001-12-20 15:11:51 +00:00
|
|
|
tmpx, y, &c, 1);
|
2000-04-04 00:19:15 +00:00
|
|
|
tmpx += lyxfont::XTextWidth(f, &c, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2001-08-03 18:28:11 +00:00
|
|
|
if (f.underbar() == LyXFont::ON) {
|
2000-07-04 20:32:37 +00:00
|
|
|
underline(f, x, y, lyxfont::width(s, ls, f));
|
2001-08-03 18:28:11 +00:00
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-04 20:32:37 +00:00
|
|
|
PainterBase & Painter::text(int x, int y, XChar2b const * s, int ls,
|
2002-03-13 13:22:54 +00:00
|
|
|
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-03-13 13:22:54 +00:00
|
|
|
lyxfont::XSetFont(display(), gc, f);
|
|
|
|
XDrawString16(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;
|
2000-11-04 10:00:12 +00:00
|
|
|
for (int 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-03-13 13:22:54 +00:00
|
|
|
lyxfont::XSetFont(display(), gc, smallfont);
|
|
|
|
XDrawString16(display(), owner.getPixmap(), gc,
|
2001-12-20 15:11:51 +00:00
|
|
|
tmpx, y, &c, 1);
|
2000-07-04 20:32:37 +00:00
|
|
|
tmpx += lyxfont::XTextWidth16(smallfont, &c, 1);
|
|
|
|
} else {
|
2002-03-13 13:22:54 +00:00
|
|
|
lyxfont::XSetFont(display(), gc, f);
|
|
|
|
XDrawString16(display(), owner.getPixmap(), gc,
|
2001-12-20 15:11:51 +00:00
|
|
|
tmpx, y, &c, 1);
|
|
|
|
tmpx += lyxfont::XTextWidth16(f, &c, 1);
|
2000-07-04 20:32:37 +00:00
|
|
|
}
|
|
|
|
}
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2001-08-03 18:28:11 +00:00
|
|
|
if (f.underbar() == LyXFont::ON) {
|
2000-07-04 20:32:37 +00:00
|
|
|
underline(f, x, y, lyxfont::width(s, ls, f));
|
2001-08-03 18:28:11 +00:00
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2000-07-04 20:32:37 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Painter::underline(LyXFont const & f, int x, int y, int width)
|
|
|
|
{
|
2001-12-10 20:06:59 +00:00
|
|
|
int const below = max(lyxfont::maxDescent(f) / 2, 2);
|
|
|
|
int const height = max((lyxfont::maxDescent(f) / 4) - 1, 1);
|
2000-07-04 20:32:37 +00:00
|
|
|
if (height < 2)
|
|
|
|
line(x, y + below, x + width, y + below, f.color());
|
|
|
|
else
|
|
|
|
fillRectangle(x, y + below, width, below + height,
|
|
|
|
f.color());
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|