1 // Copyright 2005-2019 The Mumble Developers. All rights reserved. 2 // Use of this source code is governed by a BSD-style license 3 // that can be found in the LICENSE file at the root of the 4 // Mumble source tree or at <https://www.mumble.info/LICENSE>. 5 6 #ifndef MUMBLE_MUMBLE_OVERLAYTEXT_H_ 7 #define MUMBLE_MUMBLE_OVERLAYTEXT_H_ 8 9 #include <QtGui/QPainterPath> 10 #include <QtGui/QPixmap> 11 #include <QtGui/QFont> 12 13 //! Annotated QPixmap supplying a basepoint. 14 class BasepointPixmap : public QPixmap { 15 public: 16 //! Local coordinates of the base point. 17 QPoint qpBasePoint; 18 //@{ 19 /** 20 * Font ascent and descent. 21 * The pixmap may exceed those font metrics, so if you need to 22 * transform rendered text properly, use these attributes. 23 */ 24 int iAscent; 25 int iDescent; 26 //@} 27 28 BasepointPixmap(); 29 //! Create from QPixmap, basepoint is bottom left. 30 BasepointPixmap(const QPixmap&); 31 //! Empty pixmap, basepoint is bottom left. 32 BasepointPixmap(int, int); 33 //! Empty pixmap with specified basepoint. 34 BasepointPixmap(int, int, const QPoint&); 35 }; 36 37 class OverlayTextLine { 38 private: 39 const float fEdgeFactor; 40 41 QString qsText; 42 QFont qfFont; 43 QPainterPath qpp; 44 float fAscent, fDescent; 45 float fXCorrection, fYCorrection; 46 int iCurWidth, iCurHeight; 47 float fEdge; 48 float fBaseliningThreshold; 49 bool bElided; 50 51 BasepointPixmap render(int, int, const QColor&, const QPoint&) const; 52 public: 53 OverlayTextLine(const QString&, const QFont&); 54 55 void setFont(const QFont&); 56 void setEdge(float); 57 58 //! Render text with current font. 59 BasepointPixmap createPixmap(QColor col); 60 //! Render text to fit a bounding box. 61 BasepointPixmap createPixmap(unsigned int maxwidth, unsigned int height, QColor col); 62 }; 63 64 #endif //_OVERLAYTEXT_H 65