o s/PainterBase/Painter/ as discussed before o s/Painter/XPainter/ in xforms/ o remove some unused stuff in Painter o add begin()/end() for the benefit of Qt (not used yet)
Look OK ? (Asger, should I put you as original author ? You and Lars ??) thanks john Index: Painter.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/Painter.C,v retrieving revision 1.2 diff -u -r1.2 Painter.C --- Painter.C 24 May 2002 14:34:32 -0000 1.2 +++ Painter.C 11 Jun 2002 20:57:52 -0000 @@ -1,11 +1,11 @@ -/* This file is part of - * ====================================================== +/** + * \file Painter.C + * Copyright 1998-2002 the LyX Team + * Read the file COPYING * - * LyX, The Document Processor - * - * Copyright 1998-2001 The LyX Team - * - *======================================================*/ + * \author unknown + * \author John Levon <[EMAIL PROTECTED]> + */ #include <config.h> @@ -16,43 +16,11 @@ #include "Painter.h" #include "lyxfont.h" #include "WorkArea.h" -#include "font_metrics.h" - - -int PainterBase::paperMargin() const -{ - return 20; -} - - -int PainterBase::paperWidth() const -{ - return owner.workWidth(); -} - - -int PainterBase::paperHeight() const -{ - return owner.height(); -} - - -PainterBase & PainterBase::circle(int x, int y, unsigned int d, - LColor::color col) -{ - return ellipse(x, y, d, d, col); -} - - -PainterBase & PainterBase::ellipse(int x, int y, - unsigned int w, unsigned int h, - LColor::color col) -{ - return arc(x, y, w, h, 0, 0, col); -} - - -PainterBase & PainterBase::button(int x, int y, int w, int h) +#include "frontends/font_metrics.h" + +using std::max; + +Painter & Painter::button(int x, int y, int w, int h) { fillRectangle(x, y, w, h, LColor::buttonbg); buttonFrame(x, y, w, h); @@ -60,17 +28,17 @@ } -PainterBase & PainterBase::buttonFrame(int x, int y, int w, int h) +Painter & Painter::buttonFrame(int x, int y, int w, int h) { // Width of a side of the button - int d = 2; + int const d = 2; fillRectangle(x, y, w, d, LColor::top); - fillRectangle(x, (y+h-d), w, d, LColor::bottom); - + fillRectangle(x, (y + h - d), w, d, LColor::bottom); + // Now a couple of trapezoids int x1[4], y1[4]; - + x1[0] = x + d; y1[0] = y + d; x1[1] = x + d; y1[1] = (y + h - d); x1[2] = x; y1[2] = y + h; @@ -87,35 +55,51 @@ } -PainterBase & PainterBase::rectText(int x, int baseline, - string const & str, - LyXFont const & font, - LColor::color back, - LColor::color frame) +Painter & Painter::rectText(int x, int baseline, + string const & str, + LyXFont const & font, + LColor::color back, + LColor::color frame) { int width; int ascent; int descent; font_metrics::rectText(str, font, width, ascent, descent); + rectangle(x, baseline - ascent, width, ascent + descent, frame); - fillRectangle(x + 1, baseline - ascent + 1, width - 1, + fillRectangle(x + 1, baseline - ascent + 1, width - 1, ascent + descent - 1, back); text(x + 3, baseline, str, font); return *this; } -PainterBase & PainterBase::buttonText(int x, int baseline, - string const & str, - LyXFont const & font) +Painter & Painter::buttonText(int x, int baseline, + string const & str, + LyXFont const & font) { int width; int ascent; int descent; font_metrics::buttonText(str, font, width, ascent, descent); + button(x, baseline - ascent, width, descent + ascent); text(x + 4, baseline, str, font); return *this; +} + + +void Painter::underline(LyXFont const & f, int x, int y, int width) +{ + int const below = max(font_metrics::maxDescent(f) / 2, 2); + int const height = max((font_metrics::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()); + } } Index: Painter.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/Painter.h,v retrieving revision 1.2 diff -u -r1.2 Painter.h --- Painter.h 29 May 2002 16:21:00 -0000 1.2 +++ Painter.h 11 Jun 2002 20:57:52 -0000 @@ -1,15 +1,15 @@ // -*- C++ -*- -/* This file is part of - * ====================================================== +/** + * \file Painter.h + * Copyright 1998-2002 the LyX Team + * Read the file COPYING * - * LyX, The Document Processor - * - * Copyright 1998-2001 The LyX Team - * - *======================================================*/ + * \author unknown + * \author John Levon <[EMAIL PROTECTED]> + */ -#ifndef PAINTERBASE_H -#define PAINTERBASE_H +#ifndef PAINTER_H +#define PAINTER_H #ifdef __GNUG__ #pragma interface @@ -18,161 +18,158 @@ #include "LString.h" #include "LColor.h" -class WorkArea; class LyXFont; + namespace grfx { class GImage; } -/** A painter class to encapsulate all graphics parameters and operations - - Every graphics operation in LyX should be made by this class. It will - be initialized and managed by the Screen class, and will be passed - as a parameter to inset. - - It hides low level windows system parameters so insets and other - clients don't have to worry about them and we can control graphics and - GUI toolkit dependent drawing functions inside this single class. - +/** + * Painter - A painter class to encapsulate all graphics parameters and operations + * + * Every graphics operation in LyX should be made by this class. The + * painter is used for drawing on the WorkArea, and is passed around + * during draw operations. + * + * It hides low level windows system parameters so insets and other + * clients don't have to worry about them and we can control graphics and + * GUI toolkit dependent drawing functions inside this single class. + * + * The intention for a toolkit is that it uses these methods to paint + * onto a backing pixmap. Only when expose events arrive via the event + * queue (perhaps generated via Screen::expose), does the copy onto + * the actual WorkArea widget take place. Paints are wrapped in (possibly + * recursive) calls to start() and end() to facilitate the backing pixmap + * management. + * + * Note that the methods return *this for convenience. */ -class PainterBase { +class Painter { public: - /// + /// possible line widths enum line_width { - /// - line_thin, - /// - line_thick + line_thin, //< thin line + line_thick //< thick line }; - /// + /// possible line styles enum line_style { - /// - line_solid, - /// - line_doubledash, - /// - line_onoffdash + line_solid, //< solid line + line_onoffdash //< dashes with spaces }; - /// - explicit PainterBase(WorkArea & wa) : owner(wa) {} + virtual ~Painter() {} - /// - virtual ~PainterBase() {} - - /* Screen geometry */ - /// - int paperMargin() const; - /// - int paperWidth() const; - /// - int paperHeight() const; - - /// Draw a line from point to point - virtual PainterBase & line( - int x1, int y1, int x2, int y2, + /// begin painting + virtual void start() {} + + /// end painting + virtual void end() {} + + /// return the width of the work area in pixels + virtual int paperWidth() const = 0; + /// return the height of the work area in pixels + virtual int paperHeight() const = 0; + + /// draw a line from point to point + virtual Painter & line( + int x1, int y1, + int x2, int y2, LColor::color = LColor::foreground, - enum line_style = line_solid, - enum line_width = line_thin) = 0; + line_style = line_solid, + line_width = line_thin) = 0; - /** Draw the lines between the lines in xp and yp. - xp and yp are arrays of points, and np is the - number of them. */ - virtual PainterBase & lines( - int const * xp, int const * yp, int np, - LColor::color = LColor::foreground, - enum line_style = line_solid, - enum line_width = line_thin) = 0; - - /// Here xp and yp are arrays of points - virtual PainterBase & fillPolygon( - int const * xp, int const * yp, + /** + * lines - draw a set of lines + * @param xp array of points' x co-ords + * @param yp array of points' y co-ords + * @param np size of the points array + */ + virtual Painter & lines( + int const * xp, + int const * yp, int np, - LColor::color = LColor::foreground) = 0; - - /// Draw lines from x1,y1 to x2,y2. They are arrays - virtual PainterBase & segments( - int const * x1, int const * y1, - int const * x2, int const * y2, int ns, LColor::color = LColor::foreground, - enum line_style = line_solid, - enum line_width = line_thin) = 0; + line_style = line_solid, + line_width = line_thin) = 0; - /// Draw a rectangle - virtual PainterBase & rectangle( - int x, int y, int w, int h, + /// draw a rectangle + virtual Painter & rectangle( + int x, int y, + int w, int h, LColor::color = LColor::foreground, - enum line_style = line_solid, - enum line_width = line_thin) = 0; - - /// Draw a circle, d is the diameter, not the radious - virtual PainterBase & circle( - int x, int y, unsigned int d, - LColor::color = LColor::foreground); - - /// Draw an ellipse - virtual PainterBase & ellipse( + line_style = line_solid, + line_width = line_thin) = 0; + + /// draw a filled rectangle + virtual Painter & fillRectangle( int x, int y, - unsigned int w, unsigned int h, - LColor::color = LColor::foreground); + int w, int h, + LColor::color) = 0; + + /// draw a filled (irregular) polygon + virtual Painter & fillPolygon( + int const * xp, + int const * yp, + int np, + LColor::color = LColor::foreground) = 0; - /// Draw an arc - virtual PainterBase & arc( + /// draw an arc + virtual Painter & arc( int x, int y, unsigned int w, unsigned int h, int a1, int a2, LColor::color = LColor::foreground) = 0; - /// Draw a pixel - virtual PainterBase & point( + /// draw a pixel + virtual Painter & point( int x, int y, LColor::color = LColor::foreground) = 0; + + /// draw a filled rectangle with the shape of a 3D button + virtual Painter & button(int x, int y, + int w, int h); + + /// draw an image from the image cache + virtual Painter & image(int x, int y, + int w, int h, + grfx::GImage const & image) = 0; + + /// draw a string at position x, y (y is the baseline) + virtual Painter & text(int x, int y, + string const & str, LyXFont const & f) = 0; + + /** + * Draw a string at position x, y (y is the baseline) + * This is just for fast drawing + */ + virtual Painter & text(int x, int y, + char const * str, size_t l, + LyXFont const & f) = 0; + + /// draw a char at position x, y (y is the baseline) + virtual Painter & text(int x, int y, + char c, LyXFont const & f) = 0; + + /// draw a string and enclose it inside a rectangle + Painter & rectText(int x, int baseline, + string const & string, + LyXFont const & font, + LColor::color back, + LColor::color frame); + + /// draw a string and enclose it inside a button frame + Painter & buttonText(int x, + int baseline, string const & s, + LyXFont const & font); - /// Fill a rectangle - virtual PainterBase & fillRectangle( - int x, int y, int w, int h, - LColor::color) = 0; - - /// A filled rectangle with the shape of a 3D button - virtual PainterBase & button(int x, int y, int w, int h); - - /// - virtual PainterBase & buttonFrame(int x, int y, int w, int h); - - - // For the figure inset - virtual PainterBase & image(int x, int y, int w, int h, - grfx::GImage const & image) = 0; - - /// Draw a string at position x, y (y is the baseline) - virtual PainterBase & text(int x, int y, - string const & str, LyXFont const & f) = 0; - - /** Draw a string at position x, y (y is the baseline) - This is just for fast drawing */ - virtual PainterBase & text(int x, int y, char const * str, size_t l, - LyXFont const & f) = 0; - - /// Draw a char at position x, y (y is the baseline) - virtual PainterBase & text(int x, int y, char c, LyXFont const & f)=0; - - /** Draws a string and encloses it inside a rectangle. */ - PainterBase & rectText(int x, int baseline, - string const & string, - LyXFont const & font, - LColor::color back, - LColor::color frame); - - /** Draw a string and encloses it inside a button frame. */ - PainterBase & buttonText(int x, int baseline, string const & s, - LyXFont const & font); protected: - /// - WorkArea & owner; + /// check the font, and if set, draw an underline + void underline(LyXFont const & f, + int x, int y, int width); + + /// draw a bevelled button border + Painter & buttonFrame(int x, int y, int w, int h); }; -// VERY temporary -#include "xforms/XPainter.h" - -#endif +#endif // PAINTER_H diff -u -r1.2 ColorHandler.C --- xforms/ColorHandler.C 10 Jun 2002 07:57:37 -0000 1.2 +++ xforms/ColorHandler.C 11 Jun 2002 20:57:57 -0000 @@ -168,8 +168,8 @@ // Gets GC for line -GC LyXColorHandler::getGCLinepars(PainterBase::line_style ls, - PainterBase::line_width lw, LColor::color c) +GC LyXColorHandler::getGCLinepars(Painter::line_style ls, + Painter::line_width lw, LColor::color c) { //if (lyxerr.debugging()) { // lyxerr << "Painter drawable: " << drawable() << endl; @@ -185,24 +185,21 @@ XGetGCValues(display, getGCForeground(c), GCForeground, &val); switch (lw) { - case PainterBase::line_thin: + case Painter::line_thin: val.line_width = 0; break; - case PainterBase::line_thick: + case Painter::line_thick: val.line_width = 2; break; } switch (ls) { - case PainterBase::line_solid: + case Painter::line_solid: val.line_style = LineSolid; break; - case PainterBase::line_onoffdash: + case Painter::line_onoffdash: val.line_style = LineOnOffDash; break; - case PainterBase::line_doubledash: - val.line_style = LineDoubleDash; - break; } @@ -238,8 +235,8 @@ gc = it->second; XFreeGC(display, gc); lineGCcache.erase(it); - getGCLinepars(PainterBase::line_style(ls), - PainterBase::line_width(lw), c); + getGCLinepars(Painter::line_style(ls), + Painter::line_width(lw), c); } } Index: xforms/ColorHandler.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/ColorHandler.h,v retrieving revision 1.1 diff -u -r1.1 ColorHandler.h --- xforms/ColorHandler.h 24 May 2002 18:24:14 -0000 1.1 +++ xforms/ColorHandler.h 11 Jun 2002 20:57:57 -0000 @@ -39,8 +39,8 @@ /// GC getGCForeground(LColor::color c); /// - GC getGCLinepars(PainterBase::line_style, - PainterBase::line_width, LColor::color c); + GC getGCLinepars(Painter::line_style, + Painter::line_width, LColor::color c); /// update the cache after a color definition change void updateColor(LColor::color c); Index: xforms/XPainter.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/XPainter.C,v retrieving revision 1.3 diff -u -r1.3 XPainter.C --- xforms/XPainter.C 29 May 2002 16:21:02 -0000 1.3 +++ xforms/XPainter.C 11 Jun 2002 20:57:57 -0000 @@ -1,11 +1,11 @@ -/* This file is part of - * ====================================================== +/** + * \file XPainter.C + * Copyright 1998-2002 the LyX Team + * Read the file COPYING * - * LyX, The Document Processor - * - * Copyright 1998-2001 The LyX Team - * - *======================================================*/ + * \author unknown + * \author John Levon <[EMAIL PROTECTED]> + */ #include <config.h> @@ -13,18 +13,16 @@ #pragma implementation #endif -#include "frontends/Painter.h" +#include "XPainter.h" #include "LString.h" #include "debug.h" -#include "lyxfont.h" -#include "frontends/xforms/XWorkArea.h" +#include "XWorkArea.h" #include "xfont_metrics.h" #include "ColorHandler.h" #include "lyxrc.h" #include "encoding.h" #include "language.h" -#include "frontends/GUIRunTime.h" #include "graphics/GraphicsImage.h" #include "support/LAssert.h" @@ -34,52 +32,54 @@ #include <cmath> - using std::endl; using std::max; -namespace { - -inline -Display * display() + +XPainter::XPainter(WorkArea & xwa) + : Painter(), owner_(xwa) { - return GUIRunTime::x11Display(); } -} - -Painter::Painter(WorkArea & wa) - : PainterBase(wa) -{} +int XPainter::paperWidth() const +{ + return owner_.workWidth(); +} -// Basic drawing routines +int XPainter::paperHeight() const +{ + return owner_.height(); +} -PainterBase & Painter::point(int x, int y, LColor::color c) + +Painter & XPainter::point(int x, int y, LColor::color c) { - XDrawPoint(display(), owner.getPixmap(), - lyxColorHandler->getGCForeground(c), x, y); + XDrawPoint(fl_get_display(), owner_.getPixmap(), + lyxColorHandler->getGCForeground(c), x, y); return *this; } -PainterBase & Painter::line(int x1, int y1, int x2, int y2, - LColor::color col, - enum line_style ls, - enum line_width lw) -{ - XDrawLine(display(), owner.getPixmap(), - lyxColorHandler->getGCLinepars(ls, lw, col), - x1, y1, x2, y2); +Painter & XPainter::line(int x1, int y1, + int x2, int y2, + LColor::color col, + line_style ls, + line_width lw) +{ + XDrawLine(fl_get_display(), owner_.getPixmap(), + lyxColorHandler->getGCLinepars(ls, lw, col), + x1, y1, x2, y2); return *this; } -PainterBase & Painter::lines(int const * xp, int const * yp, int np, - LColor::color col, - enum line_style ls, - enum line_width lw) +Painter & XPainter::lines(int const * xp, int const * yp, + int np, + LColor::color col, + line_style ls, + line_width lw) { boost::scoped_array<XPoint> points(new XPoint[np]); @@ -88,37 +88,39 @@ points[i].y = yp[i]; } - XDrawLines(display(), owner.getPixmap(), - lyxColorHandler->getGCLinepars(ls, lw, col), - points.get(), np, CoordModeOrigin); + XDrawLines(fl_get_display(), owner_.getPixmap(), + lyxColorHandler->getGCLinepars(ls, lw, col), + points.get(), np, CoordModeOrigin); return *this; -} +} -PainterBase & Painter::rectangle(int x, int y, int w, int h, - LColor::color col, - enum line_style ls, - enum line_width lw) -{ - XDrawRectangle(display(), owner.getPixmap(), - lyxColorHandler->getGCLinepars(ls, lw, col), - x, y, w, h); +Painter & XPainter::rectangle(int x, int y, + int w, int h, + LColor::color col, + line_style ls, + line_width lw) +{ + XDrawRectangle(fl_get_display(), owner_.getPixmap(), + lyxColorHandler->getGCLinepars(ls, lw, col), + x, y, w, h); return *this; } -PainterBase & Painter::fillRectangle(int x, int y, int w, int h, - LColor::color col) +Painter & XPainter::fillRectangle(int x, int y, + int w, int h, + LColor::color col) { - XFillRectangle(display(), owner.getPixmap(), - lyxColorHandler->getGCForeground(col), x, y, w, h); + XFillRectangle(fl_get_display(), owner_.getPixmap(), + lyxColorHandler->getGCForeground(col), x, y, w, h); return *this; } -PainterBase & Painter::fillPolygon(int const * xp, int const * yp, int np, - LColor::color col) +Painter & XPainter::fillPolygon(int const * xp, int const * yp, + int np, LColor::color col) { boost::scoped_array<XPoint> points(new XPoint[np]); @@ -126,77 +128,59 @@ points[i].x = xp[i]; points[i].y = yp[i]; } - - XFillPolygon(display(), owner.getPixmap(), - lyxColorHandler->getGCForeground(col), points.get(), np, - Nonconvex, CoordModeOrigin); - - return *this; -} - - -PainterBase & Painter::arc(int x, int y, - unsigned int w, unsigned int h, - int a1, int a2, LColor::color col) -{ - XDrawArc(display(), owner.getPixmap(), - lyxColorHandler->getGCForeground(col), - x, y, w, h, a1, a2); + + XFillPolygon(fl_get_display(), owner_.getPixmap(), + lyxColorHandler->getGCForeground(col), points.get(), + np, Nonconvex, CoordModeOrigin); + return *this; } - -/// Draw lines from x1,y1 to x2,y2. They are arrays -PainterBase & Painter::segments(int const * x1, int const * y1, - int const * x2, int const * y2, int ns, - LColor::color col, - enum line_style ls, enum line_width lw) -{ - boost::scoped_array<XSegment> s(new XSegment[ns]); - - 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]; - } - XDrawSegments(display(), owner.getPixmap(), - lyxColorHandler->getGCLinepars(ls, lw, col), - s.get(), ns); - - return *this; + +Painter & XPainter::arc(int x, int y, + unsigned int w, unsigned int h, + int a1, int a2, LColor::color col) +{ + XDrawArc(fl_get_display(), owner_.getPixmap(), + lyxColorHandler->getGCForeground(col), + x, y, w, h, a1, a2); + return *this; } - -PainterBase & Painter::image(int x, int y, int w, int h, - grfx::GImage const & image) + +Painter & XPainter::image(int x, int y, + int w, int h, + grfx::GImage const & image) { XGCValues val; val.function = GXcopy; - GC gc = XCreateGC(display(), owner.getPixmap(), - GCFunction, &val); - XCopyArea(display(), image.getPixmap(), owner.getPixmap(), gc, - 0, 0, w, h, x, y); - XFreeGC(display(), gc); + GC gc = XCreateGC(fl_get_display(), owner_.getPixmap(), + GCFunction, &val); + XCopyArea(fl_get_display(), image.getPixmap(), owner_.getPixmap(), + gc, 0, 0, w, h, x, y); + XFreeGC(fl_get_display(), gc); return *this; } -PainterBase & Painter::text(int x, int y, string const & s, LyXFont const & f) +Painter & XPainter::text(int x, int y, + string const & s, LyXFont const & f) { return text(x, y, s.data(), s.length(), f); } -PainterBase & Painter::text(int x, int y, char c, LyXFont const & f) +Painter & XPainter::text(int x, int y, + char c, LyXFont const & f) { char s[2] = { c, '\0' }; return text(x, y, s, 1, f); } -PainterBase & Painter::text(int x, int y, char const * s, size_t ls, - LyXFont const & f) +Painter & XPainter::text(int x, int y, + char const * s, size_t ls, + LyXFont const & f) { if (lyxrc.font_norm_type == LyXRC::ISO_10646_1) { boost::scoped_array<XChar2b> xs(new XChar2b[ls]); @@ -220,8 +204,8 @@ GC gc = lyxColorHandler->getGCForeground(f.realColor()); if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) { - font_metrics::XSetFont(display(), gc, f); - XDrawString(display(), owner.getPixmap(), gc, x, y, s, ls); + xfont_metrics::XSetFont(fl_get_display(), gc, f); + XDrawString(fl_get_display(), owner_.getPixmap(), gc, x, y, s, ls); } else { LyXFont smallfont(f); smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE); @@ -229,15 +213,15 @@ for (size_t i = 0; i < ls; ++i) { char const c = uppercase(s[i]); if (c != s[i]) { - font_metrics::XSetFont(display(), gc, smallfont); - XDrawString(display(), owner.getPixmap(), gc, - tmpx, y, &c, 1); - tmpx += font_metrics::XTextWidth(smallfont, &c, 1); + xfont_metrics::XSetFont(fl_get_display(), gc, +smallfont); + XDrawString(fl_get_display(), owner_.getPixmap(), gc, + tmpx, y, &c, 1); + tmpx += xfont_metrics::XTextWidth(smallfont, &c, 1); } else { - font_metrics::XSetFont(display(), gc, f); - XDrawString(display(), owner.getPixmap(), gc, - tmpx, y, &c, 1); - tmpx += font_metrics::XTextWidth(f, &c, 1); + xfont_metrics::XSetFont(fl_get_display(), gc, f); + XDrawString(fl_get_display(), owner_.getPixmap(), gc, + tmpx, y, &c, 1); + tmpx += xfont_metrics::XTextWidth(f, &c, 1); } } } @@ -245,24 +229,25 @@ if (f.underbar() == LyXFont::ON) { underline(f, x, y, font_metrics::width(s, ls, f)); } - + return *this; } -PainterBase & Painter::text(int x, int y, XChar2b const * s, int ls, - LyXFont const & f) +Painter & XPainter::text(int x, int y, + XChar2b const * s, size_t ls, + LyXFont const & f) { GC gc = lyxColorHandler->getGCForeground(f.realColor()); if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) { - font_metrics::XSetFont(display(), gc, f); - XDrawString16(display(), owner.getPixmap(), gc, x, y, s, ls); + xfont_metrics::XSetFont(fl_get_display(), gc, f); + XDrawString16(fl_get_display(), owner_.getPixmap(), gc, x, y, s, ls); } else { LyXFont smallfont(f); smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE); static XChar2b c; int tmpx = x; - for (int i = 0; i < ls; ++i) { + for (size_t i = 0; i < ls; ++i) { if (s[i].byte1) c = s[i]; else { @@ -270,34 +255,22 @@ c.byte2 = uppercase(s[i].byte2); } if (c.byte2 != s[i].byte2) { - font_metrics::XSetFont(display(), gc, smallfont); - XDrawString16(display(), owner.getPixmap(), gc, - tmpx, y, &c, 1); - tmpx += font_metrics::XTextWidth16(smallfont, &c, 1); + xfont_metrics::XSetFont(fl_get_display(), gc, +smallfont); + XDrawString16(fl_get_display(), owner_.getPixmap(), gc, + tmpx, y, &c, 1); + tmpx += xfont_metrics::XTextWidth16(smallfont, &c, 1); } else { - font_metrics::XSetFont(display(), gc, f); - XDrawString16(display(), owner.getPixmap(), gc, - tmpx, y, &c, 1); - tmpx += font_metrics::XTextWidth16(f, &c, 1); + xfont_metrics::XSetFont(fl_get_display(), gc, f); + XDrawString16(fl_get_display(), owner_.getPixmap(), gc, + tmpx, y, &c, 1); + tmpx += xfont_metrics::XTextWidth16(f, &c, 1); } } } - + if (f.underbar() == LyXFont::ON) { - underline(f, x, y, font_metrics::width(s, ls, f)); + underline(f, x, y, xfont_metrics::width(s, ls, f)); } - + return *this; -} - - -void Painter::underline(LyXFont const & f, int x, int y, int width) -{ - int const below = max(font_metrics::maxDescent(f) / 2, 2); - int const height = max((font_metrics::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()); } Index: xforms/XPainter.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/XPainter.h,v retrieving revision 1.1 diff -u -r1.1 XPainter.h --- xforms/XPainter.h 23 May 2002 09:21:27 -0000 1.1 +++ xforms/XPainter.h 11 Jun 2002 20:57:58 -0000 @@ -1,101 +1,126 @@ // -*- C++ -*- -/* This file is part of - * ====================================================== +/** + * \file XPainter.h + * Copyright 1995-2002 the LyX Team + * Read the file COPYING * - * LyX, The Document Processor - * - * Copyright 1995-2001 The LyX Team - * - * ======================================================*/ + * \author unknown + * \author John Levon <[EMAIL PROTECTED]> + */ -#ifndef PAINTER_H -#define PAINTER_H +#ifndef XPAINTER_H +#define XPAINTER_H #ifdef __GNUG__ #pragma interface #endif +#include <config.h> + +#include "Painter.h" #include "LString.h" -// This is only included to provide stuff for the non-public sections #include <X11/Xlib.h> -#include "frontends/Painter.h" class LyXFont; class WorkArea; -/** An inplementation for the X Window System. Xlib. - Classes similar to this one can be made for gtk+, Qt, etc. -*/ -class Painter : public PainterBase { +/** + * XPainter - a painter implementation for Xlib + */ +class XPainter : public Painter { public: - /// Constructor - explicit Painter(WorkArea &); - - /// Draw a line from point to point - PainterBase & line(int x1, int y1, int x2, int y2, - LColor::color = LColor::foreground, - enum line_style = line_solid, - enum line_width = line_thin); - - /// Here xp and yp are arrays of points - PainterBase & lines(int const * xp, int const * yp, int np, - LColor::color = LColor::foreground, - enum line_style = line_solid, - enum line_width = line_thin); - - /// Here xp and yp are arrays of points - PainterBase & fillPolygon(int const * xp, int const * yp, int np, - LColor::color = LColor::foreground); - - /// Draw lines from x1,y1 to x2,y2. They are arrays - PainterBase & segments(int const * x1, int const * y1, - int const * x2, int const * y2, int ns, - LColor::color = LColor::foreground, - enum line_style = line_solid, - enum line_width = line_thin); - - /// Draw a rectangle - PainterBase & rectangle(int x, int y, int w, int h, - LColor::color = LColor::foreground, - enum line_style = line_solid, - enum line_width = line_thin); - - /// Draw an arc - PainterBase & arc(int x, int y, unsigned int w, unsigned int h, - int a1, int a2, - LColor::color = LColor::foreground); - - /// Draw a pixel - PainterBase & point(int x, int y, LColor::color = LColor::foreground); - - /// Fill a rectangle - PainterBase & fillRectangle(int x, int y, int w, int h, - LColor::color); - - /// For the graphics inset. - PainterBase & image(int x, int y, int w, int h, - grfx::GImage const & image); - - /// Draw a string at position x, y (y is the baseline) - PainterBase & text(int x, int y, - string const & str, LyXFont const & f); + XPainter(WorkArea &); + + /// return the width of the work area in pixels + virtual int paperWidth() const; + /// return the height of the work area in pixels + virtual int paperHeight() const; + + /// draw a line from point to point + virtual Painter & line( + int x1, int y1, + int x2, int y2, + LColor::color = LColor::foreground, + line_style = line_solid, + line_width = line_thin); + + /** + * lines - draw a set of lines + * @param xp array of points' x co-ords + * @param yp array of points' y co-ords + * @param np size of the points array + */ + virtual Painter & lines( + int const * xp, + int const * yp, + int np, + LColor::color = LColor::foreground, + line_style = line_solid, + line_width = line_thin); + + /// draw a rectangle + virtual Painter & rectangle( + int x, int y, + int w, int h, + LColor::color = LColor::foreground, + line_style = line_solid, + line_width = line_thin); + + /// draw a filled rectangle + virtual Painter & fillRectangle( + int x, int y, + int w, int h, + LColor::color); + + /// draw a filled (irregular) polygon + virtual Painter & fillPolygon( + int const * xp, + int const * yp, + int np, + LColor::color = LColor::foreground); + + /// draw an arc + virtual Painter & arc( + int x, int y, + unsigned int w, unsigned int h, + int a1, int a2, + LColor::color = LColor::foreground); + + /// draw a pixel + virtual Painter & point( + int x, int y, + LColor::color = LColor::foreground); + + /// draw an image from the image cache + virtual Painter & image(int x, int y, + int w, int h, + grfx::GImage const & image); + + /// draw a string at position x, y (y is the baseline) + virtual Painter & text(int x, int y, + string const & str, LyXFont const & f); /** Draw a string at position x, y (y is the baseline) - This is just for fast drawing */ - PainterBase & text(int x, int y, char const * str, size_t l, - LyXFont const & f); - - /// Draw a char at position x, y (y is the baseline) - PainterBase & text(int x, int y, char c, LyXFont const & f); - - /// Draw a wide string at position x, y - PainterBase & text(int x, int y, XChar2b const * str, int l, - LyXFont const & f); + * This is just for fast drawing + */ + virtual Painter & text(int x, int y, + char const * str, size_t l, + LyXFont const & f); + + /// draw a char at position x, y (y is the baseline) + virtual Painter & text(int x, int y, + char c, LyXFont const & f); + + /// draw a wide string at position x, y + Painter & text(int x, int y, + XChar2b const * str, size_t l, + LyXFont const & f); + private: - /// Check the font, and if set, draw an underline - void underline(LyXFont const & f, int x, int y, int width); + /// our owner who we paint upon + WorkArea & owner_; }; -#endif +#endif // XPAINTER_H