Krita Source Code Documentation
Loading...
Searching...
No Matches
KoSvgTextShape_p_output.cpp File Reference
#include "KoSvgTextShape.h"
#include "KoSvgTextShape_p.h"
#include "KoSvgTextProperties.h"
#include <KoClipMaskPainter.h>
#include <KoColorBackground.h>
#include <KoGradientBackground.h>
#include <KoPathShape.h>
#include <KoShapeStroke.h>
#include <KoShapeRegistry.h>
#include <KoShapeFactoryBase.h>
#include <KoProperties.h>
#include <KoClipMask.h>
#include <KoInsets.h>
#include <KoShapeGroup.h>
#include <KoShapeGroupCommand.h>
#include <kis_algebra_2d.h>
#include <QPainter>
#include <QtMath>
#include <variant>

Go to the source code of this file.

Functions

QGradient * cloneAndTransformGradient (const QGradient *grad, const QTransform &tf)
 
static void inheritPaintProperties (const KisForest< KoSvgTextContentElement >::composition_iterator it, KoShapeStrokeModelSP &stroke, QSharedPointer< KoShapeBackground > &background, QVector< KoShape::PaintOrder > &paintOrder)
 
void setRenderHints (QPainter &painter, const KoSvgText::TextRendering textRendering, const bool testAntialiasing)
 
QSharedPointer< KoShapeBackgroundtransformBackgroundToBounds (QSharedPointer< KoShapeBackground > bg, const QRectF &oldBounds, const QRectF &newBounds)
 
KoShapeStrokeModelSP transformStrokeBgToNewBounds (KoShapeStrokeModelSP stroke, const QRectF &oldBounds, const QRectF &newBounds, bool calcInsets=true)
 

Function Documentation

◆ cloneAndTransformGradient()

QGradient * cloneAndTransformGradient ( const QGradient * grad,
const QTransform & tf )

Definition at line 310 of file KoSvgTextShape_p_output.cpp.

310 {
311 QGradient *newGrad = KoFlake::cloneGradient(grad);
312
313 if (newGrad->type() == QGradient::LinearGradient) {
314 QLinearGradient *lgradient = static_cast<QLinearGradient*>(newGrad);
315 lgradient->setStart(tf.map(lgradient->start()));
316 lgradient->setFinalStop(tf.map(lgradient->finalStop()));
317 } else if (newGrad->type() == QGradient::RadialGradient) {
318 QRadialGradient *rgradient = static_cast<QRadialGradient*>(newGrad);
319 rgradient->setFocalPoint(tf.map(rgradient->focalPoint()));
320 rgradient->setCenter(tf.map(rgradient->center()));
321 }
322 return newGrad;
323}
KRITAFLAKE_EXPORT QGradient * cloneGradient(const QGradient *gradient)
clones the given gradient
Definition KoFlake.cpp:17

References KoFlake::cloneGradient().

◆ inheritPaintProperties()

static void inheritPaintProperties ( const KisForest< KoSvgTextContentElement >::composition_iterator it,
KoShapeStrokeModelSP & stroke,
QSharedPointer< KoShapeBackground > & background,
QVector< KoShape::PaintOrder > & paintOrder )
static

Definition at line 33 of file KoSvgTextShape_p_output.cpp.

36 {
37 for (auto parentIt = KisForestDetail::hierarchyBegin(siblingCurrent(it)); parentIt != KisForestDetail::hierarchyEnd(siblingCurrent(it)); parentIt++) {
38 if (parentIt->properties.hasProperty(KoSvgTextProperties::StrokeId)) {
39 stroke = parentIt->properties.stroke();
40 break;
41 }
42 }
43 for (auto parentIt = KisForestDetail::hierarchyBegin(siblingCurrent(it)); parentIt != KisForestDetail::hierarchyEnd(siblingCurrent(it)); parentIt++) {
44 if (parentIt->properties.hasProperty(KoSvgTextProperties::FillId)) {
45 background = parentIt->properties.background();
46 break;
47 }
48 }
49 for (auto parentIt = KisForestDetail::hierarchyBegin(siblingCurrent(it)); parentIt != KisForestDetail::hierarchyEnd(siblingCurrent(it)); parentIt++) {
50 if (parentIt->properties.hasProperty(KoSvgTextProperties::PaintOrder)) {
51 paintOrder = parentIt->properties.propertyOrDefault(KoSvgTextProperties::PaintOrder).value<QVector<KoShape::PaintOrder>>();
52 break;
53 }
54 }
55}
@ PaintOrder
QVector<KoShape::PaintOrder>
@ StrokeId
KoSvgText::StrokeProperty.
@ FillId
KoSvgText::BackgroundProperty.
ResultIterator hierarchyBegin(Iterator it)
Definition KisForest.h:419
ResultIterator hierarchyEnd(Iterator it)
Definition KisForest.h:427
ChildIterator< value_type, is_const > siblingCurrent(ChildIterator< value_type, is_const > it)
Definition KisForest.h:240

References KoSvgTextProperties::FillId, KisForestDetail::hierarchyBegin(), KisForestDetail::hierarchyEnd(), KoSvgTextProperties::PaintOrder, and KoSvgTextProperties::StrokeId.

◆ setRenderHints()

void setRenderHints ( QPainter & painter,
const KoSvgText::TextRendering textRendering,
const bool testAntialiasing )

Definition at line 57 of file KoSvgTextShape_p_output.cpp.

57 {
58 if (textRendering != KoSvgText::RenderingOptimizeSpeed && testAntialiasing) {
59 // also apply antialiasing only if antialiasing is active on provided target QPainter
60 painter.setRenderHint(QPainter::Antialiasing, true);
61 painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
62 } else {
63 painter.setRenderHint(QPainter::Antialiasing, false);
64 painter.setRenderHint(QPainter::SmoothPixmapTransform, false);
65 }
66}
@ RenderingOptimizeSpeed
Definition KoSvgText.h:316

References KoSvgText::RenderingOptimizeSpeed.

◆ transformBackgroundToBounds()

QSharedPointer< KoShapeBackground > transformBackgroundToBounds ( QSharedPointer< KoShapeBackground > bg,
const QRectF & oldBounds,
const QRectF & newBounds )

Definition at line 325 of file KoSvgTextShape_p_output.cpp.

325 {
326 KoGradientBackground *g = dynamic_cast<KoGradientBackground *>(bg.data());
327
328 if (g) {
329 QRectF relative = KisAlgebra2D::absoluteToRelative(oldBounds, newBounds);
330 QTransform newTf = QTransform::fromTranslate(relative.x(), relative.y());
331 newTf.scale(relative.width(), relative.height());
332
334 }
335
336 // assume bg is KoColorBackground.
337 return bg;
338}
QGradient * cloneAndTransformGradient(const QGradient *grad, const QTransform &tf)
A gradient shape background.
const QGradient * gradient() const
Returns the gradient.
QTransform transform() const
Returns the transform matrix.
QPointF absoluteToRelative(const QPointF &pt, const QRectF &rc)

References KisAlgebra2D::absoluteToRelative(), cloneAndTransformGradient(), KoGradientBackground::gradient(), and KoGradientBackground::transform().

◆ transformStrokeBgToNewBounds()

KoShapeStrokeModelSP transformStrokeBgToNewBounds ( KoShapeStrokeModelSP stroke,
const QRectF & oldBounds,
const QRectF & newBounds,
bool calcInsets = true )

Definition at line 340 of file KoSvgTextShape_p_output.cpp.

340 {
341 KoShapeStrokeSP s = qSharedPointerDynamicCast<KoShapeStroke>(stroke);
342 if (s) {
343 QBrush b = s->lineBrush();
344 if (b.gradient()) {
345 QRectF nb = newBounds;
346 if (calcInsets) {
347 KoInsets insets;
348 s->strokeInsets(nullptr, insets);
349 nb.adjust(-insets.left, -insets.top, insets.right, insets.bottom);
350 }
351
352 QRectF relative = KisAlgebra2D::absoluteToRelative(oldBounds, nb);
353 KoShapeStrokeSP newStroke(new KoShapeStroke(*s.data()));
354 QTransform newTf = QTransform::fromTranslate(relative.x(), relative.y());
355 newTf.scale(relative.width(), relative.height());
356 QBrush newBrush = *cloneAndTransformGradient(b.gradient(), newTf);
357 newStroke->setLineBrush(newBrush);
358 return newStroke;
359 }
360 }
361 return stroke;
362}
qreal bottom
Bottom inset.
Definition KoInsets.h:50
qreal right
Right inset.
Definition KoInsets.h:52
qreal top
Top inset.
Definition KoInsets.h:49
qreal left
Left inset.
Definition KoInsets.h:51

References KisAlgebra2D::absoluteToRelative(), KoInsets::bottom, cloneAndTransformGradient(), KoInsets::left, KoInsets::right, KoShape::s, KoShape::stroke(), and KoInsets::top.