]> git.lyx.org Git - lyx.git/blob - src/frontends/Painter.h
Amend 6c3447c8: FindAdv: sometimes a space is added on some math symbols
[lyx.git] / src / frontends / Painter.h
1 // -*- C++ -*-
2 /**
3  * \file Painter.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author unknown
8  * \author John Levon
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef PAINTER_H
14 #define PAINTER_H
15
16 #include "support/strfwd.h"
17 #include "support/types.h"
18
19 namespace lyx {
20
21 class Color;
22 class Font;
23 class FontInfo;
24
25 namespace graphics { class Image; }
26
27 namespace frontend {
28
29 /**
30  * Painter - A painter class to encapsulate all graphics parameters and operations
31  *
32  * Every graphics operation in LyX should be made by this class. The
33  * painter is used for drawing on the WorkArea, and is passed around
34  * during draw operations.
35  *
36  * It hides low level windows system parameters so insets and other
37  * clients don't have to worry about them and we can control graphics and
38  * GUI toolkit dependent drawing functions inside this single class.
39  *
40  * The intention for a toolkit is that it uses these methods to paint
41  * onto a backing pixmap. Only when expose events arrive via the event
42  * queue, does the copy onto the actual WorkArea widget take place.
43  *
44  * Caution: All char_type and docstring arguments of the text drawing
45  * methods of this class are no UCS4 chars or strings if the font is a
46  * symbol font. They simply denote the code points of the font instead.
47  * You have to keep this in mind when you implement the methods in a
48  * frontend. You must not pass these parameters to a unicode conversion
49  * function in particular.
50  */
51 class Painter {
52 public:
53         Painter(double pixel_ratio, bool devel_mode)
54                 : pixel_ratio_(pixel_ratio), devel_mode_(devel_mode) {}
55
56         static const int thin_line;
57
58         /// possible line styles
59         enum line_style {
60                 line_solid, //< solid line
61                 line_solid_aliased, //< solid line, no anti-aliasing (used as a
62                                     // workaround to painting issues)
63                 line_onoffdash //< dashes with spaces
64         };
65
66         /// possible fill styles
67         enum fill_style {
68                 fill_none,
69                 fill_oddeven,
70                 fill_winding
71         };
72
73         /// possible character styles of preedit string.
74         /// This is used for CJK input method support.
75         enum preedit_style {
76                 preedit_default, //< when unselecting, no cursor and dashed underline.
77                 preedit_selecting, //< when selecting.
78                 preedit_cursor //< with cursor.
79         };
80
81         virtual ~Painter() {}
82
83         /// draw a line from point to point
84         virtual void line(int x1, int y1, int x2, int y2, Color,
85                 line_style = line_solid, int line_width = thin_line) = 0;
86
87         /**
88          * lines -  draw a set of lines
89          * @param xp array of points' x co-ords
90          * @param yp array of points' y co-ords
91          * @param np size of the points array
92          */
93         virtual void lines(int const * xp, int const * yp, int np, Color,
94                 fill_style = fill_none, line_style = line_solid,
95                 int line_width = thin_line) = 0;
96
97         /**
98          * path -  draw a path with bezier curves
99          * @param xp array of points' x co-ords
100          * @param yp array of points' y co-ords
101          * @param c1x array of first control points' x co-ords
102          * @param c1y array of first control points' y co-ords
103          * @param c2x array of second control points' x co-ords
104          * @param c2y array of second control points' y co-ords
105          * @param np size of the points array
106          */
107         virtual void path(int const * xp, int const * yp,
108                 int const * c1x, int const * c1y,
109                 int const * c2x, int const * c2y,
110                 int np, Color,
111                 fill_style = fill_none, line_style = line_solid,
112                 int line_width = thin_line) = 0;
113
114         /// draw a rectangle
115         virtual void rectangle(int x, int y, int w, int h, Color,
116                 line_style = line_solid, int line_width = thin_line) = 0;
117
118         /// draw a filled rectangle
119         virtual void fillRectangle(int x, int y, int w, int h, Color) = 0;
120
121         /// draw an arc
122         virtual void arc(int x, int y, unsigned int w, unsigned int h,
123                 int a1, int a2, Color) = 0;
124
125         /// draw an ellipse
126         virtual void ellipse(double x, double y, double rx, double ry, Color,
127                 fill_style = fill_none, line_style = line_solid,
128                 int line_width = thin_line) = 0;
129
130         /// draw a pixel
131         virtual void point(int x, int y, Color) = 0;
132
133         /// draw an image from the image cache
134         virtual void image(int x, int y, int w, int h,
135                 graphics::Image const & image, bool const revert_in_darkmode = false) = 0;
136
137         // Direction for painting text
138         enum Direction { LtR, RtL, Auto };
139
140         /// draw a string at position x, y (y is the baseline).
141         virtual void text(int x, int y, docstring const & str, FontInfo const & f,
142                           Direction const dir = Auto) = 0;
143
144         /// draw a char at position x, y (y is the baseline)
145         virtual void text(int x, int y, char_type c, FontInfo const & f,
146                           Direction const dir = Auto) = 0;
147
148         /** draw a string at position x, y (y is the baseline). The
149          * text direction is enforced by the \c Font.
150          */
151         virtual void text(int x, int y, docstring const & str, Font const & f,
152                       double wordspacing, double textwidth) = 0;
153
154         /** draw a string at position x, y (y is the baseline), but
155          * make sure that the part between \c from and \c to is in
156          * \c other color. The text direction is enforced by the \c Font.
157          */
158         virtual void text(int x, int y, docstring const & str, Font const & f,
159                           Color other, size_type from, size_type to,
160                       double wordspacing, double textwidth) = 0;
161
162         // Returns true if the painter does not actually paint.
163         virtual bool isNull() const = 0;
164
165         double pixelRatio() const { return pixel_ratio_; }
166
167         bool develMode() const { return devel_mode_; }
168
169         /// draw the underbar, strikeout, xout, uuline and uwave font attributes
170         virtual void textDecoration(FontInfo const & f, int x, int y, int width) = 0;
171
172         /**
173          * Draw a string and enclose it inside a rectangle. If
174          * back color is specified, the background is cleared with
175          * the given color. If frame is specified, a thin frame is drawn
176          * around the text with the given color.
177          */
178         virtual void rectText(int x, int baseline, docstring const & str,
179                 FontInfo const & font, Color back, Color frame) = 0;
180
181         /// draw a string and enclose it inside a button frame
182         virtual void buttonText(int x, int baseline, docstring const & s,
183                 FontInfo const & font, Color back, Color frame, int offset) = 0;
184
185         /// draw a character of a preedit string for cjk support.
186         virtual int preeditText(int x, int y,
187                 char_type c, FontInfo const & f, preedit_style style) = 0;
188
189         /// start monochrome painting mode, i.e. map every color a shade of \c blend.
190         virtual void enterMonochromeMode(Color const & blend) = 0;
191         /// leave monochrome painting mode
192         virtual void leaveMonochromeMode() = 0;
193         /// draws a wavy line that can be used for underlining.
194         virtual void wavyHorizontalLine(FontInfo const & f, int x, int y, int width, ColorCode col) = 0;
195 private:
196         /// Ratio between physical pixels and device-independent pixels
197         double pixel_ratio_;
198         /// True when developer more is on at application-level.
199         bool devel_mode_;
200 };
201
202 } // namespace frontend
203 } // namespace lyx
204
205 #endif // PAINTER_H