QCAD
Open Source 2D CAD
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RTextRenderer.h
Go to the documentation of this file.
1 
20 #ifndef RTEXTRENDERER_H
21 #define RTEXTRENDERER_H
22 
23 #include "entity_global.h"
24 
25 #include <QTextLayout>
26 
27 #include "RDocument.h"
28 #include "REntityData.h"
29 #include "RPainterPath.h"
30 #include "RPainterPathSource.h"
31 #include "RTextBasedData.h"
32 #include "RVector.h"
33 
34 class QTextDocument;
35 
43 public:
44  enum Target {
45  PainterPaths = 0x01,
46  RichText = 0x02
47  };
48 
49 public:
50  RTextRenderer(const RTextBasedData& textData, bool draft, RTextRenderer::Target target, double fontHeightFactor = 1.0);
51 
52  void renderSimple();
53  void render();
54 
55  QList<RPainterPath> getPainterPaths() const {
56  return painterPaths;
57  }
58 
59  RBox getBoundingBox() const {
60  return boundingBox;
61  }
62 
63  double getHeight() const {
64  return height;
65  }
66 
67  double getWidth() const {
68  return width;
69  }
70 
71  QString getRichText() const {
72  return richText;
73  }
74 
75 private:
76  QList<RPainterPath> getPainterPathsForBlock(
77  const QString& blockText,
78  const QList<QTextLayout::FormatRange>& formats,
79  double& horizontalAdvance,
80  double& horizontalAdvanceNoSpacing,
81  double& ascent,
82  double& descent);
83 
84  QList<RPainterPath> getPainterPathsForBlockTtf(
85  const QString& blockText,
86  const QList<QTextLayout::FormatRange>& formats,
87  double& horizontalAdvance,
88  double& horizontalAdvanceNoSpacing,
89  double& ascent,
90  double& descent);
91 
92  QList<RPainterPath> getPainterPathsForBlockCad(
93  const QString& blockText,
94  const QList<QTextLayout::FormatRange>& formats,
95  double& horizontalAdvance,
96  double& horizontalAdvanceNoSpacing,
97  double& ascent,
98  double& descent);
99 
100  QRectF getCharacterRect(const QString& fontName, const QChar& ch) const;
101  QRectF getCharacterRect(const QFont& font, const QChar& ch) const;
102 
103  QString getRichTextForBlock(const QString& blockText,
104  const QList<QTextLayout::FormatRange>& formats);
105 
106 public:
107  static QString rxLineFeed;
108  static QString rxParagraphFeed;
109  static QString rxHeightChange;
110  //static QString rxRelativeHeightChange;
111  static QString rxStackedText;
112  static QString rxColorChangeIndex;
113  static QString rxColorChangeCustom;
114  static QString rxNonBreakingSpace;
115  static QString rxOverlineOn;
116  static QString rxOverlineOff;
117  static QString rxUnderlineOn;
118  static QString rxUnderlineOff;
119  static QString rxWidthChange;
120  static QString rxObliqueAngleChange;
121  static QString rxTrackChange;
122  static QString rxAlignmentChange;
123  static QString rxFontChangeCad;
124  static QString rxFontChangeTtf;
125  static QString rxBeginBlock;
126  static QString rxEndBlock;
127  static QString rxBackslash;
128  static QString rxCurlyOpen;
129  static QString rxCurlyClose;
130  static QString rxDegree;
131  static QString escDegree;
132  static QString rxPlusMinus;
133  static QString escPlusMinus;
134  static QString rxDiameter;
135  static QString escDiameter;
136  static QString rxUnicode;
137 
138  static QString rxAll;
139 
140  static QChar chDegree;
141  static QChar chPlusMinus;
142  static QChar chDiameter;
143 
144 private:
146 
148  QList<RPainterPath> painterPaths;
150  double height;
151  double width;
152  bool draft;
153  QString richText;
155 
156  QStack<bool> useCadFont;
157  QStack<QTextCharFormat> currentFormat;
158  QStack<double> blockHeight;
159  QStack<QString> blockFont;
160  QStack<bool> blockBold;
161  QStack<bool> blockItalic;
162  QStack<QStringList> openTags;
163 };
164 
168 
169 #endif