Krita Source Code Documentation
Loading...
Searching...
No Matches
KisTextBrushesPipe Class Reference
+ Inheritance diagram for KisTextBrushesPipe:

Public Member Functions

void clear () override
 
int currentBrushIndex () override
 
KisGbrBrushSP firstBrush () const
 
 KisTextBrushesPipe ()
 
 KisTextBrushesPipe (const KisTextBrushesPipe &rhs)
 
void notifyStrokeStarted () override
 
void setText (const QString &text, const QFont &font)
 
- Public Member Functions inherited from KisBrushesPipe< KisGbrBrush >
QVector< QSharedPointer< KisGbrBrush > > brushes ()
 
QSharedPointer< KisGbrBrushcurrentBrush (const KisPaintInformation &info)
 
QSharedPointer< KisGbrBrushfirstBrush () const
 
void generateMaskAndApplyMaskOrCreateDab (KisFixedPaintDeviceSP dst, KisBrush::ColoringInformation *coloringInformation, KisDabShape const &shape, const KisPaintInformation &info, double subPixelX, double subPixelY, qreal softnessFactor, qreal lightnessStrength=DEFAULT_LIGHTNESS_STRENGTH)
 
bool hasColorAndTransparency () const
 
bool isImageType () const
 
 KisBrushesPipe ()
 
 KisBrushesPipe (const KisBrushesPipe &rhs)
 
QSharedPointer< KisGbrBrushlastBrush () const
 
qint32 maskHeight (KisDabShape const &shape, double subPixelX, double subPixelY, const KisPaintInformation &info)
 
qint32 maskWidth (KisDabShape const &shape, double subPixelX, double subPixelY, const KisPaintInformation &info)
 
void notifyBrushIsGoingToBeClonedForStroke ()
 
KisFixedPaintDeviceSP paintDevice (const KoColorSpace *colorSpace, KisDabShape const &shape, const KisPaintInformation &info, double subPixelX, double subPixelY)
 
void prepareForSeqNo (const KisPaintInformation &info, int seqNo)
 
void setAngle (qreal angle)
 
void setBrushApplication (enumBrushApplication brushApplication) const
 
void setGradient (KoAbstractGradientSP gradient) const
 
void setScale (qreal scale)
 
void setSpacing (double spacing)
 
void testingSelectNextBrush (const KisPaintInformation &info)
 
virtual ~KisBrushesPipe ()
 

Static Public Member Functions

static QImage renderChar (const QString &text, const QFont &font)
 

Protected Member Functions

int chooseNextBrush (const KisPaintInformation &info) override
 
void updateBrushIndexes (KisRandomSourceSP randomSource, int seqNo) override
 
- Protected Member Functions inherited from KisBrushesPipe< KisGbrBrush >
void addBrush (QSharedPointer< KisGbrBrush > brush)
 
int sizeBrush ()
 

Private Member Functions

void updateBrushIndexesImpl ()
 

Private Attributes

QMap< QChar, KisGbrBrushSPm_brushesMap
 
int m_charIndex
 
int m_currentBrushIndex
 
QString m_text
 

Additional Inherited Members

- Protected Attributes inherited from KisBrushesPipe< KisGbrBrush >
QVector< QSharedPointer< KisGbrBrush > > m_brushes
 

Detailed Description

Definition at line 27 of file kis_text_brush.cpp.

Constructor & Destructor Documentation

◆ KisTextBrushesPipe() [1/2]

KisTextBrushesPipe::KisTextBrushesPipe ( )
inline

Definition at line 30 of file kis_text_brush.cpp.

References m_charIndex, and m_currentBrushIndex.

◆ KisTextBrushesPipe() [2/2]

KisTextBrushesPipe::KisTextBrushesPipe ( const KisTextBrushesPipe & rhs)
inline

Definition at line 35 of file kis_text_brush.cpp.

36 : KisBrushesPipe<KisGbrBrush>(), // no copy here!
37 m_text(rhs.m_text),
40 {
41 m_brushesMap.clear();
42
43 QMapIterator<QChar, KisGbrBrushSP> iter(rhs.m_brushesMap);
44 while (iter.hasNext()) {
45 iter.next();
46 KisGbrBrushSP brush(new KisGbrBrush(*iter.value()));
47 m_brushesMap.insert(iter.key(), brush);
49 }
50 }
void addBrush(QSharedPointer< BrushType > brush)
QMap< QChar, KisGbrBrushSP > m_brushesMap

References KisBrushesPipe< BrushType >::addBrush(), and m_brushesMap.

Member Function Documentation

◆ chooseNextBrush()

int KisTextBrushesPipe::chooseNextBrush ( const KisPaintInformation & info)
inlineoverrideprotectedvirtual

Returns the index of the next brush that corresponds to the current values of info. This method is called before the dab is actually painted.

Implements KisBrushesPipe< KisGbrBrush >.

Definition at line 131 of file kis_text_brush.cpp.

131 {
132 Q_UNUSED(info);
133 return m_currentBrushIndex;
134 }

References m_currentBrushIndex.

◆ clear()

void KisTextBrushesPipe::clear ( )
inlineoverridevirtual

Reimplemented from KisBrushesPipe< KisGbrBrush >.

Definition at line 109 of file kis_text_brush.cpp.

109 {
110 m_brushesMap.clear();
112 }
virtual void clear()

References KisBrushesPipe< BrushType >::clear(), and m_brushesMap.

◆ currentBrushIndex()

int KisTextBrushesPipe::currentBrushIndex ( )
inlineoverridevirtual

Returns the current index of the brush This method is called before the dab is actually painted.

The method is const, so no internal counters of the brush should change during its execution

Implements KisBrushesPipe< KisGbrBrush >.

Definition at line 125 of file kis_text_brush.cpp.

125 {
126 return m_currentBrushIndex;
127 }

References m_currentBrushIndex.

◆ firstBrush()

KisGbrBrushSP KisTextBrushesPipe::firstBrush ( ) const
inline

Definition at line 114 of file kis_text_brush.cpp.

114 {
115 Q_ASSERT(m_text.size() > 0);
116 Q_ASSERT(m_brushesMap.size() > 0);
117 return m_brushesMap.value(m_text.at(0));
118 }

References m_brushesMap, and m_text.

◆ notifyStrokeStarted()

void KisTextBrushesPipe::notifyStrokeStarted ( )
inlineoverridevirtual

Is called by the paint op when a paintop starts a stroke. The brushes are shared among different strokes, so sometimes the brush should be reset.

Implements KisBrushesPipe< KisGbrBrush >.

Definition at line 120 of file kis_text_brush.cpp.

120 {
121 m_charIndex = 0;
123 }

References m_charIndex, and updateBrushIndexesImpl().

◆ renderChar()

static QImage KisTextBrushesPipe::renderChar ( const QString & text,
const QFont & font )
inlinestatic

Definition at line 76 of file kis_text_brush.cpp.

76 {
77#ifdef HAVE_THREADED_TEXT_RENDERING_WORKAROUND
78 QWidget *focusWidget = qApp->focusWidget();
79 if (focusWidget) {
80 QThread *guiThread = focusWidget->thread();
81 if (guiThread != QThread::currentThread()) {
82 warnKrita << "WARNING: Rendering text in non-GUI thread!"
83 << "That may lead to hangups and crashes on some"
84 << "versions of X11/Qt!";
85 }
86 }
87#endif /* HAVE_THREADED_TEXT_RENDERING_WORKAROUND */
88
89 QFontMetrics metric(font);
90 QRect rect = metric.boundingRect(text);
91
92 if (rect.isEmpty()) {
93 rect = QRect(0, 0, 1, 1); // paint at least something
94 }
95
96 QRect paintingRect = rect.translated(-rect.x(), -rect.y());
97
98 QImage renderedChar(paintingRect.size(), QImage::Format_ARGB32);
99 QPainter p;
100 p.begin(&renderedChar);
101 p.setFont(font);
102 p.fillRect(paintingRect, Qt::white);
103 p.setPen(Qt::black);
104 p.drawText(-rect.x(), -rect.y(), text);
105 p.end();
106 return renderedChar;
107 }
const Params2D p
#define warnKrita
Definition kis_debug.h:87

References p, and warnKrita.

◆ setText()

void KisTextBrushesPipe::setText ( const QString & text,
const QFont & font )
inline

Definition at line 52 of file kis_text_brush.cpp.

52 {
53 m_text = text;
54
55 m_charIndex = 0;
56
57 clear();
58
59 for (int i = 0; i < m_text.length(); i++) {
60
61 const QChar letter = m_text.at(i);
62
63 // skip letters that are already present in the brushes pipe
64 if (m_brushesMap.contains(letter)) continue;
65
66 QImage image = renderChar(letter, font);
67 KisGbrBrushSP brush(new KisGbrBrush(image, letter));
68 brush->setSpacing(0.1); // support for letter spacing?
69 brush->makeMaskImage(false);
70
71 m_brushesMap.insert(letter, brush);
73 }
74 }
static QImage renderChar(const QString &text, const QFont &font)
void clear() override

References KisBrushesPipe< BrushType >::addBrush(), clear(), m_brushesMap, m_charIndex, m_text, and renderChar().

◆ updateBrushIndexes()

void KisTextBrushesPipe::updateBrushIndexes ( KisRandomSourceSP randomSource,
int seqNo )
inlineoverrideprotectedvirtual

Updates internal counters of the brush after a dab has been painted on the canvas. Some incremental switching of the brushes may me implemented in this method.

If seqNo is equal or greater than zero, then incremental iteration is overridden by this seqNo value

Implements KisBrushesPipe< KisGbrBrush >.

Definition at line 136 of file kis_text_brush.cpp.

136 {
137 Q_UNUSED(randomSource);
138
139 if (m_text.size()) {
140 m_charIndex = (seqNo >= 0 ? seqNo : (m_charIndex + 1)) % m_text.size();
141 } else {
142 m_charIndex = 0;
143 }
144
146 }

References m_charIndex, m_text, and updateBrushIndexesImpl().

◆ updateBrushIndexesImpl()

void KisTextBrushesPipe::updateBrushIndexesImpl ( )
inlineprivate

Definition at line 149 of file kis_text_brush.cpp.

149 {
150 if (m_text.isEmpty()) return;
151
152 if (m_charIndex >= m_text.size()) {
153 m_charIndex = 0;
154 }
155
156 QChar letter = m_text.at(m_charIndex);
157 Q_ASSERT(m_brushesMap.contains(letter));
158
159 m_currentBrushIndex = m_brushes.indexOf(m_brushesMap.value(letter));
160 }
QVector< QSharedPointer< KisGbrBrush > > m_brushes

References KisBrushesPipe< KisGbrBrush >::m_brushes, m_brushesMap, m_charIndex, m_currentBrushIndex, and m_text.

Member Data Documentation

◆ m_brushesMap

QMap<QChar, KisGbrBrushSP> KisTextBrushesPipe::m_brushesMap
private

Definition at line 163 of file kis_text_brush.cpp.

◆ m_charIndex

int KisTextBrushesPipe::m_charIndex
private

Definition at line 165 of file kis_text_brush.cpp.

◆ m_currentBrushIndex

int KisTextBrushesPipe::m_currentBrushIndex
private

Definition at line 166 of file kis_text_brush.cpp.

◆ m_text

QString KisTextBrushesPipe::m_text
private

Definition at line 164 of file kis_text_brush.cpp.


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