2000-02-10 17:53:36 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 1998-2000 The LyX Team
|
|
|
|
*
|
|
|
|
*======================================================*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_STL_MEMORY
|
|
|
|
#include <memory>
|
|
|
|
#endif
|
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
#include <cmath>
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
#include FORMS_H_LOCATION
|
|
|
|
#include "Painter.h"
|
|
|
|
#include "LString.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "lyxfont.h"
|
|
|
|
#include "support/LAssert.h"
|
|
|
|
#include "support/lstrings.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"
|
2000-02-10 17:53:36 +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
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
Painter::Painter(WorkArea & wa)
|
|
|
|
: PainterBase(wa)
|
|
|
|
{
|
2000-04-16 22:27:30 +00:00
|
|
|
display = fl_display;
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Basic drawing routines */
|
|
|
|
|
|
|
|
extern bool Lgb_bug_find_hack;
|
|
|
|
|
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
|
|
|
{
|
2000-08-14 15:31:16 +00:00
|
|
|
if (lyxerr.debugging(Debug::GUI)) {
|
2000-02-10 17:53:36 +00:00
|
|
|
if (!Lgb_bug_find_hack)
|
|
|
|
lyxerr << "point not called from "
|
|
|
|
"workarea::workhandler\n";
|
2000-04-16 22:27:30 +00:00
|
|
|
lyxerr.debug() << "Painter drawable: "
|
|
|
|
<< owner.getPixmap() << endl;
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
|
|
|
|
2000-04-16 22:27:30 +00:00
|
|
|
XDrawPoint(display, owner.getPixmap(),
|
|
|
|
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,
|
2000-02-10 17:53:36 +00:00
|
|
|
LColor::color col,
|
|
|
|
enum line_style ls,
|
|
|
|
enum line_width lw)
|
|
|
|
{
|
2000-08-14 15:31:16 +00:00
|
|
|
if (lyxerr.debugging(Debug::GUI)) {
|
2000-02-10 17:53:36 +00:00
|
|
|
if (!Lgb_bug_find_hack)
|
|
|
|
lyxerr << "line not called from "
|
|
|
|
"workarea::workhandler\n";
|
2000-04-16 22:27:30 +00:00
|
|
|
lyxerr.debug() << "Painter drawable: "
|
|
|
|
<< owner.getPixmap() << endl;
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
|
|
|
|
2000-04-16 22:27:30 +00:00
|
|
|
XDrawLine(display, owner.getPixmap(),
|
|
|
|
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
|
|
|
{
|
2000-08-14 15:31:16 +00:00
|
|
|
if (lyxerr.debugging(Debug::GUI)) {
|
2000-02-10 17:53:36 +00:00
|
|
|
if (!Lgb_bug_find_hack)
|
|
|
|
lyxerr << "lines not called from "
|
|
|
|
"workarea::workhandler\n";
|
2000-04-16 22:27:30 +00:00
|
|
|
lyxerr.debug() << "Painter drawable: "
|
|
|
|
<< owner.getPixmap() << endl;
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef HAVE_AUTO_PTR
|
|
|
|
XPoint * points = new XPoint[np];
|
|
|
|
#else
|
|
|
|
auto_ptr<XPoint> points(new Xpoint[np]);
|
|
|
|
#endif
|
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];
|
|
|
|
}
|
|
|
|
|
2000-04-16 22:27:30 +00:00
|
|
|
XDrawLines(display, owner.getPixmap(),
|
|
|
|
lyxColorHandler->getGCLinepars(ls, lw, col),
|
2000-02-10 17:53:36 +00:00
|
|
|
points, np, CoordModeOrigin);
|
|
|
|
|
|
|
|
#ifndef HAVE_AUTO_PTR
|
|
|
|
delete[] points;
|
|
|
|
#endif
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2000-08-14 15:31:16 +00:00
|
|
|
if (lyxerr.debugging(Debug::GUI)) {
|
2000-02-10 17:53:36 +00:00
|
|
|
if (!Lgb_bug_find_hack)
|
|
|
|
lyxerr << "rectangle not called from "
|
|
|
|
"workarea::workhandler\n";
|
2000-04-16 22:27:30 +00:00
|
|
|
lyxerr << "Painter drawable: "
|
|
|
|
<< owner.getPixmap() << endl;
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
|
|
|
|
2000-04-16 22:27:30 +00:00
|
|
|
XDrawRectangle(display, owner.getPixmap(),
|
|
|
|
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,
|
2000-02-10 17:53:36 +00:00
|
|
|
LColor::color col)
|
|
|
|
{
|
2000-08-14 15:31:16 +00:00
|
|
|
if (lyxerr.debugging(Debug::GUI)) {
|
2000-02-10 17:53:36 +00:00
|
|
|
if (!Lgb_bug_find_hack)
|
|
|
|
lyxerr << "fillrectangle not called from "
|
|
|
|
"workarea::workhandler\n";
|
2000-04-16 22:27:30 +00:00
|
|
|
lyxerr << "Painter drawable: "
|
|
|
|
<< owner.getPixmap() << endl;
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
|
|
|
|
2000-04-16 22:27:30 +00:00
|
|
|
XFillRectangle(display, owner.getPixmap(),
|
|
|
|
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,
|
2000-02-10 17:53:36 +00:00
|
|
|
LColor::color col)
|
|
|
|
{
|
2000-08-14 15:31:16 +00:00
|
|
|
if (lyxerr.debugging(Debug::GUI)) {
|
2000-02-10 17:53:36 +00:00
|
|
|
if (!Lgb_bug_find_hack)
|
|
|
|
lyxerr <<"fillpolygon not called from "
|
|
|
|
"workarea::workhandler\n";
|
2000-04-16 22:27:30 +00:00
|
|
|
lyxerr << "Painter drawable: " << owner.getPixmap() << endl;
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef HAVE_AUTO_PTR
|
|
|
|
XPoint * points = new XPoint[np];
|
|
|
|
#else
|
|
|
|
auto_ptr<XPoint> points(new XPoint[np]);
|
|
|
|
#endif
|
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];
|
|
|
|
}
|
|
|
|
|
2000-04-16 22:27:30 +00:00
|
|
|
XFillPolygon(display, owner.getPixmap(),
|
|
|
|
lyxColorHandler->getGCForeground(col), points, np,
|
2000-02-10 17:53:36 +00:00
|
|
|
Nonconvex, CoordModeOrigin);
|
|
|
|
#ifndef HAVE_AUTO_PTR
|
|
|
|
delete[] points;
|
|
|
|
#endif
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-11 13:52:44 +00:00
|
|
|
PainterBase & Painter::arc(int x, int y,
|
2000-02-10 17:53:36 +00:00
|
|
|
unsigned int w, unsigned int h,
|
|
|
|
int a1, int a2, LColor::color col)
|
|
|
|
{
|
2000-08-14 15:31:16 +00:00
|
|
|
if (lyxerr.debugging(Debug::GUI)) {
|
2000-02-10 17:53:36 +00:00
|
|
|
if (!Lgb_bug_find_hack)
|
|
|
|
lyxerr << "arc not called from "
|
|
|
|
"workarea::workhandler\n";
|
2000-04-16 22:27:30 +00:00
|
|
|
lyxerr << "Painter drawable: " << owner.getPixmap() << endl;
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
|
|
|
|
2000-04-16 22:27:30 +00:00
|
|
|
XDrawArc(display, owner.getPixmap(),
|
|
|
|
lyxColorHandler->getGCForeground(col),
|
2000-02-10 17:53:36 +00:00
|
|
|
x, y, w, h, a1, a2);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Draw lines from x1,y1 to x2,y2. They are arrays
|
2000-02-11 13:52:44 +00:00
|
|
|
PainterBase & Painter::segments(int const * x1, int const * y1,
|
2000-02-10 17:53:36 +00:00
|
|
|
int const * x2, int const * y2, int ns,
|
|
|
|
LColor::color col,
|
|
|
|
enum line_style ls, enum line_width lw)
|
|
|
|
{
|
2000-08-14 15:31:16 +00:00
|
|
|
if (lyxerr.debugging(Debug::GUI)) {
|
2000-02-10 17:53:36 +00:00
|
|
|
if (!Lgb_bug_find_hack)
|
|
|
|
lyxerr << "segments not called from "
|
|
|
|
"workarea::workhandler\n";
|
2000-04-16 22:27:30 +00:00
|
|
|
lyxerr << "Painter drawable: " << owner.getPixmap() << endl;
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef HAVE_AUTO_PTR
|
|
|
|
XSegment * s= new XSegment[ns];
|
|
|
|
#else
|
|
|
|
auto_ptr<XSegment> s(new XSegment[ns]);
|
|
|
|
#endif
|
|
|
|
for (int i=0; i<ns; ++i) {
|
|
|
|
s[i].x1 = x1[i];
|
|
|
|
s[i].y1 = y1[i];
|
|
|
|
s[i].x2 = x2[i];
|
|
|
|
s[i].y2 = y2[i];
|
|
|
|
}
|
2000-04-16 22:27:30 +00:00
|
|
|
XDrawSegments(display, owner.getPixmap(),
|
|
|
|
lyxColorHandler->getGCLinepars(ls, lw, col), s, ns);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
|
|
|
#ifndef HAVE_AUTO_PTR
|
|
|
|
delete [] s;
|
|
|
|
#endif
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-11 16:56:34 +00:00
|
|
|
PainterBase & Painter::pixmap(int x, int y, int w, int h, Pixmap bitmap)
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2000-08-14 15:31:16 +00:00
|
|
|
if (lyxerr.debugging(Debug::GUI)) {
|
2000-02-10 17:53:36 +00:00
|
|
|
if (!Lgb_bug_find_hack)
|
|
|
|
lyxerr << "workAreaExpose not called from "
|
|
|
|
"workarea::workhandler\n";
|
2000-04-16 22:27:30 +00:00
|
|
|
lyxerr << "Painter drawable: " << owner.getPixmap() << endl;
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
XGCValues val;
|
|
|
|
val.function = GXcopy;
|
2000-04-16 22:27:30 +00:00
|
|
|
GC gc = XCreateGC(display, owner.getPixmap(),
|
2000-02-10 17:53:36 +00:00
|
|
|
GCFunction, &val);
|
2000-04-16 22:27:30 +00:00
|
|
|
XCopyArea(display, bitmap, owner.getPixmap(), gc,
|
2000-02-10 17:53:36 +00:00
|
|
|
0, 0, w, h, x, y);
|
|
|
|
XFreeGC(display, gc);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2000-02-14 22:14:48 +00:00
|
|
|
return text(x, y, s.c_str(), s.length(), f);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
2000-02-10 17:53:36 +00:00
|
|
|
LyXFont const & f)
|
|
|
|
{
|
2000-07-04 20:32:37 +00:00
|
|
|
if (lyxrc.font_norm_type == LyXRC::ISO_10646_1) {
|
|
|
|
XChar2b * xs = new XChar2b[ls];
|
2000-07-20 10:04:27 +00:00
|
|
|
Encoding const * encoding = f.language()->encoding();
|
|
|
|
LyXFont const * font = &f;
|
|
|
|
if (f.family() == LyXFont::SYMBOL_FAMILY) {
|
|
|
|
#ifdef USE_UNICODE_FOR_SYMBOLS
|
|
|
|
LyXFont font2 = f;
|
|
|
|
font2.setFamily(LyXFont::ROMAN_FAMILY);
|
|
|
|
font2.setShape(LyXFont::UP_SHAPE);
|
|
|
|
font = &font2;
|
|
|
|
#endif
|
|
|
|
encoding = &symbol_encoding;
|
|
|
|
}
|
2000-07-04 20:32:37 +00:00
|
|
|
for (int 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
|
|
|
}
|
|
|
|
text(x , y, xs, ls, *font);
|
2000-07-04 20:32:37 +00:00
|
|
|
delete[] xs;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2000-08-14 15:31:16 +00:00
|
|
|
if (lyxerr.debugging(Debug::GUI)) {
|
2000-02-10 17:53:36 +00:00
|
|
|
if (!Lgb_bug_find_hack)
|
|
|
|
lyxerr << "text not called from "
|
|
|
|
"workarea::workhandler\n";
|
2000-04-16 22:27:30 +00:00
|
|
|
lyxerr << "Painter drawable: " << owner.getPixmap() << endl;
|
2000-02-10 17:53:36 +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) {
|
|
|
|
lyxfont::XSetFont(display, gc, f);
|
2000-04-16 22:27:30 +00:00
|
|
|
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);
|
|
|
|
char c;
|
|
|
|
int tmpx = x;
|
|
|
|
for(int i = 0; i < ls; ++i) {
|
|
|
|
c = s[i];
|
|
|
|
if (islower(static_cast<unsigned char>(c))) {
|
|
|
|
c = toupper(c);
|
|
|
|
lyxfont::XSetFont(display, gc, smallfont);
|
2000-04-16 22:27:30 +00:00
|
|
|
XDrawString(display, owner.getPixmap(),
|
2000-04-04 00:19:15 +00:00
|
|
|
gc, tmpx, y, &c, 1);
|
|
|
|
tmpx += lyxfont::XTextWidth(smallfont, &c, 1);
|
|
|
|
} else {
|
|
|
|
lyxfont::XSetFont(display, gc, f);
|
2000-04-16 22:27:30 +00:00
|
|
|
XDrawString(display, owner.getPixmap(),
|
2000-04-04 00:19:15 +00:00
|
|
|
gc, tmpx, y, &c, 1);
|
|
|
|
tmpx += lyxfont::XTextWidth(f, &c, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-07-04 20:32:37 +00:00
|
|
|
if (f.underbar() == LyXFont::ON && f.latex() != LyXFont::ON)
|
|
|
|
underline(f, x, y, lyxfont::width(s, ls, f));
|
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,
|
|
|
|
LyXFont const & f)
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2000-08-14 15:31:16 +00:00
|
|
|
if (lyxerr.debugging(Debug::GUI)) {
|
2000-07-04 20:32:37 +00:00
|
|
|
if (!Lgb_bug_find_hack)
|
|
|
|
lyxerr << "text not called from "
|
|
|
|
"workarea::workhandler\n";
|
|
|
|
lyxerr << "Painter drawable: " << owner.getPixmap() << endl;
|
|
|
|
}
|
|
|
|
GC gc = lyxColorHandler->getGCForeground(f.realColor());
|
|
|
|
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
|
|
|
|
lyxfont::XSetFont(display, gc, f);
|
|
|
|
XDrawString16(display, owner.getPixmap(), gc, x, y, s, ls);
|
|
|
|
} else {
|
|
|
|
LyXFont smallfont(f);
|
|
|
|
smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
|
|
|
|
static XChar2b c = {0, 0};
|
|
|
|
int tmpx = x;
|
|
|
|
for(int i = 0; i < ls; ++i) {
|
|
|
|
if (s[i].byte1 == 0 && islower(s[i].byte2)) {
|
|
|
|
c.byte2 = toupper(s[i].byte2);
|
|
|
|
lyxfont::XSetFont(display, gc, smallfont);
|
|
|
|
XDrawString16(display, owner.getPixmap(),
|
|
|
|
gc, tmpx, y, &c, 1);
|
|
|
|
tmpx += lyxfont::XTextWidth16(smallfont, &c, 1);
|
|
|
|
} else {
|
|
|
|
lyxfont::XSetFont(display, gc, f);
|
|
|
|
XDrawString16(display, owner.getPixmap(),
|
|
|
|
gc, tmpx, y, &s[i], 1);
|
|
|
|
tmpx += lyxfont::XTextWidth16(f, const_cast<XChar2b *>(&s[i]), 1);
|
|
|
|
}
|
|
|
|
}
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
2000-07-04 20:32:37 +00:00
|
|
|
if (f.underbar() == LyXFont::ON && f.latex() != LyXFont::ON)
|
|
|
|
underline(f, x, y, lyxfont::width(s, ls, f));
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Painter::underline(LyXFont const & f, int x, int y, int width)
|
|
|
|
{
|
|
|
|
int below = max(lyxfont::maxDescent(f) / 2, 2);
|
|
|
|
int height = max((lyxfont::maxDescent(f) / 4) - 1, 1);
|
|
|
|
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
|
|
|
}
|