1 /* 2 For general Scribus (>=1.3.2) copyright and licensing information please refer 3 to the COPYING file provided with the program. Following this notice may exist 4 a copyright and/or license notice that predates the release of Scribus 1.3.2 5 for which a new license (GPL+exception) is in place. 6 */ 7 8 #ifndef TEXTLAYOUTPAINTER_H 9 #define TEXTLAYOUTPAINTER_H 10 11 #include <stack> 12 13 #include "scribusapi.h" 14 #include "sctextstruct.h" 15 #include "glyphcluster.h" 16 17 18 struct TextLayoutColor 19 { 20 QString color; 21 double shade; 22 TextLayoutColorTextLayoutColor23 TextLayoutColor() 24 : color("Black") 25 , shade(100) 26 { } 27 28 TextLayoutColor(QString c, double s=100) colorTextLayoutColor29 : color(c) 30 , shade(s) 31 { } 32 33 bool operator ==(const TextLayoutColor &other) const 34 { 35 return other.color == color && other.shade == shade; 36 } 37 38 bool operator !=(const TextLayoutColor &other) const 39 { 40 return !(*this == other); 41 } 42 }; 43 44 /** 45 * @brief The TextLayoutPainter class 46 * 47 * This class provides the API for drawing primitives used to render boxes, 48 * each subclass of it will provide the actual implementation for drawing 49 * glyphs, lines and rectangle specific for the target format. 50 */ 51 class SCRIBUS_API TextLayoutPainter 52 { 53 public: 54 TextLayoutPainter(); 55 virtual ~TextLayoutPainter(); 56 57 /// Sets the current font that will be used for all subsequent glyph 58 /// drawings. 59 virtual void setFont(const ScFace& font); 60 /// The current font. 61 virtual const ScFace& font() const; 62 63 /// Sets the current font size that will be used for all subsequent 64 /// glyph drawings. 65 virtual void setFontSize(double size); 66 /// The current font size. 67 virtual double fontSize() const; 68 69 /// Sets the current color for line strokes. 70 virtual void setStrokeColor(const TextLayoutColor& c); 71 /// The current color for line strokes. 72 virtual const TextLayoutColor& strokeColor() const; 73 74 /// Sets the current foreground color. 75 virtual void setFillColor(const TextLayoutColor& c); 76 /// The current foreground color. 77 virtual const TextLayoutColor& fillColor() const; 78 79 /// Sets the current width for line strokes. 80 virtual void setStrokeWidth(double w); 81 /// The current width for line strokes. 82 virtual double strokeWidth() const; 83 84 /// Moves the current x and y positions by the specified amount. 85 virtual void translate(double x, double y); 86 /// The current x positions. 87 virtual double x() const; 88 /// The current y positions. 89 virtual double y() const; 90 91 /// Sets the current horizontal and vertical scales. 92 virtual void setScale(double h, double v); 93 /// The current horizontal scale. 94 virtual double scaleV() const; 95 /// The current vertical scale. 96 virtual double scaleH() const; 97 98 /// Sets the selection state of subsequent drawing operations, used for 99 /// selecting proper foreground and background colors when drawing text 100 /// selection. 101 virtual void setSelected(bool s); 102 /// The current selection sate. 103 virtual bool selected() const; 104 105 /// Sets the transformation matrix to be applied to subsequent drawing 106 /// operations. 107 virtual void setMatrix(const QTransform&); 108 /// The current transformation matrix. 109 virtual const QTransform& matrix() const; 110 111 /// Draws a regular (filled) glyph using the current font, fill color 112 /// etc. at the current x and y positions. 113 virtual void drawGlyph(const GlyphCluster& gc) = 0; 114 /// Same as drawGlyphs() but draws an outlined glyph with current 115 /// stroke color, if @fill is true then the glyphs is also filled by 116 /// the current fill color. 117 virtual void drawGlyphOutline(const GlyphCluster& gc, bool fill) = 0; 118 /// Draws a line from @start to @end relative current x and y 119 /// positions, with current stroke color and width. 120 virtual void drawLine(QPointF start, QPointF end) = 0; 121 /// Draws a rectangle at current x and y positions, using current stoke 122 /// color and width for its border, and filled with the current fill 123 /// color. 124 virtual void drawRect(QRectF rect) = 0; 125 /// Draws and embedded page item at the current x and y positions. 126 virtual void drawObject(PageItem* item) = 0; 127 128 /// Save the current painter state. 129 virtual void save(); 130 /// Restore the last saved painter state. 131 virtual void restore(); 132 133 private: 134 struct State 135 { 136 ScFace font; 137 double fontSize; 138 TextLayoutColor strokeColor; 139 TextLayoutColor fillColor; 140 QTransform matrix; 141 double strokeWidth; 142 double x; 143 double y; 144 double scaleH; 145 double scaleV; 146 bool selected; 147 StateState148 State() 149 : fontSize(0) 150 , strokeWidth(0) 151 , x(0) 152 , y(0) 153 , scaleH(1) 154 , scaleV(1) 155 , selected(false) 156 {} 157 }; 158 159 std::stack<State> m_stack; 160 }; 161 162 #endif // TEXTLAYOUTPAINTER_H 163