Qt 4.8
Public Functions | Public Variables | List of all members
QSvgFont Class Reference

#include <qsvgfont_p.h>

Inheritance diagram for QSvgFont:
QSvgRefCounted

Public Functions

void addGlyph (QChar unicode, const QPainterPath &path, qreal horizAdvX=-1)
 
void draw (QPainter *p, const QPointF &point, const QString &str, qreal pixelSize, Qt::Alignment alignment) const
 
QString familyName () const
 
 QSvgFont (qreal horizAdvX)
 
void setFamilyName (const QString &name)
 
void setUnitsPerEm (qreal upem)
 
- Public Functions inherited from QSvgRefCounted
void deref ()
 
 QSvgRefCounted ()
 
void ref ()
 
virtual ~QSvgRefCounted ()
 

Public Variables

qreal m_ascent
 
qreal m_descent
 
QString m_familyName
 
QHash< QChar, QSvgGlyphm_glyphs
 
qreal m_horizAdvX
 
qreal m_unitsPerEm
 

Detailed Description

Definition at line 78 of file qsvgfont_p.h.

Constructors and Destructors

◆ QSvgFont()

QSvgFont::QSvgFont ( qreal  horizAdvX)

Definition at line 60 of file qsvgfont.cpp.

61  : m_horizAdvX(horizAdvX)
62 {
63 }
qreal m_horizAdvX
Definition: qsvgfont_p.h:96

Functions

◆ addGlyph()

void QSvgFont::addGlyph ( QChar  unicode,
const QPainterPath path,
qreal  horizAdvX = -1 
)

Definition at line 72 of file qsvgfont.cpp.

Referenced by createSvgGlyph().

73 {
74  m_glyphs.insert(unicode, QSvgGlyph(unicode, path,
75  (horizAdvX==-1)?m_horizAdvX:horizAdvX));
76 }
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
qreal m_horizAdvX
Definition: qsvgfont_p.h:96
QHash< QChar, QSvgGlyph > m_glyphs
Definition: qsvgfont_p.h:97

◆ draw()

void QSvgFont::draw ( QPainter p,
const QPointF point,
const QString str,
qreal  pixelSize,
Qt::Alignment  alignment 
) const

Definition at line 79 of file qsvgfont.cpp.

Referenced by QSvgText::draw().

80 {
81  p->save();
82  p->translate(point);
84 
85  // Calculate the text width to be used for alignment
86  int textWidth = 0;
88  for ( ; itr != str.constEnd(); ++itr) {
89  QChar unicode = *itr;
90  if (!m_glyphs.contains(*itr)) {
91  unicode = 0;
92  if (!m_glyphs.contains(unicode))
93  continue;
94  }
95  textWidth += static_cast<int>(m_glyphs[unicode].m_horizAdvX);
96  }
97 
98  QPoint alignmentOffset(0, 0);
99  if (alignment == Qt::AlignHCenter) {
100  alignmentOffset.setX(-textWidth / 2);
101  } else if (alignment == Qt::AlignRight) {
102  alignmentOffset.setX(-textWidth);
103  }
104 
105  p->translate(alignmentOffset);
106 
107  // since in SVG the embedded font ain't really a path
108  // the outline has got to stay untransformed...
109  qreal penWidth = p->pen().widthF();
110  penWidth /= (pixelSize/m_unitsPerEm);
111  QPen pen = p->pen();
112  pen.setWidthF(penWidth);
113  p->setPen(pen);
114 
115  itr = str.constBegin();
116  for ( ; itr != str.constEnd(); ++itr) {
117  QChar unicode = *itr;
118  if (!m_glyphs.contains(*itr)) {
119  unicode = 0;
120  if (!m_glyphs.contains(unicode))
121  continue;
122  }
123  p->drawPath(m_glyphs[unicode].m_path);
124  p->translate(m_glyphs[unicode].m_horizAdvX, 0);
125  }
126 
127  p->restore();
128 }
void drawPath(const QPainterPath &path)
Draws the given painter path using the current pen for outline and the current brush for filling...
Definition: qpainter.cpp:3502
double qreal
Definition: qglobal.h:1193
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
Definition: qhash.h:872
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first character in the string. ...
Definition: qstring.h:892
const QPen & pen() const
Returns the painter&#39;s current pen.
Definition: qpainter.cpp:4152
static float pixelSize(const QFontDef &request, int dpi)
Definition: qfont_win.cpp:80
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qstring.h:898
qreal m_unitsPerEm
Definition: qsvgfont_p.h:93
qreal m_horizAdvX
Definition: qsvgfont_p.h:96
void setWidthF(qreal width)
Sets the pen width to the given width in pixels with floating point precision.
Definition: qpen.cpp:690
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
qreal widthF() const
Returns the pen width with floating point precision.
Definition: qpen.cpp:645
QHash< QChar, QSvgGlyph > m_glyphs
Definition: qsvgfont_p.h:97
void scale(qreal sx, qreal sy)
Scales the coordinate system by ({sx}, {sy}).
Definition: qpainter.cpp:3234
void translate(const QPointF &offset)
Translates the coordinate system by the given offset; i.e.
Definition: qpainter.cpp:3311

◆ familyName()

QString QSvgFont::familyName ( ) const

Definition at line 66 of file qsvgfont.cpp.

Referenced by QSvgTinyDocument::addSvgFont(), createFontNode(), parseFontFaceNameNode(), and parseFontFaceNode().

67 {
68  return m_familyName;
69 }
QString m_familyName
Definition: qsvgfont_p.h:92

◆ setFamilyName()

void QSvgFont::setFamilyName ( const QString name)

Definition at line 130 of file qsvgfont.cpp.

Referenced by createFontNode(), parseFontFaceNameNode(), and parseFontFaceNode().

131 {
132  m_familyName = name;
133 }
QString m_familyName
Definition: qsvgfont_p.h:92
const char * name

◆ setUnitsPerEm()

void QSvgFont::setUnitsPerEm ( qreal  upem)

Definition at line 135 of file qsvgfont.cpp.

Referenced by parseFontFaceNode().

136 {
137  m_unitsPerEm = upem;
138 }
qreal m_unitsPerEm
Definition: qsvgfont_p.h:93

Properties

◆ m_ascent

qreal QSvgFont::m_ascent

Definition at line 94 of file qsvgfont_p.h.

◆ m_descent

qreal QSvgFont::m_descent

Definition at line 95 of file qsvgfont_p.h.

◆ m_familyName

QString QSvgFont::m_familyName

Definition at line 92 of file qsvgfont_p.h.

Referenced by familyName(), and setFamilyName().

◆ m_glyphs

QHash<QChar, QSvgGlyph> QSvgFont::m_glyphs

Definition at line 97 of file qsvgfont_p.h.

Referenced by addGlyph(), and draw().

◆ m_horizAdvX

qreal QSvgFont::m_horizAdvX

Definition at line 96 of file qsvgfont_p.h.

Referenced by addGlyph(), and draw().

◆ m_unitsPerEm

qreal QSvgFont::m_unitsPerEm

Definition at line 93 of file qsvgfont_p.h.

Referenced by draw(), and setUnitsPerEm().


The documentation for this class was generated from the following files: