11#include <KLocalizedString>
16#include <QDomDocument>
24const QString
DESC =
"desc";
56 const QFileInfo f(
name());
65 d->properties = rhs.
d->properties;
66 d->sample = rhs.
d->sample;
67 d->afterText = rhs.
d->afterText;
68 d->beforeText = rhs.
d->beforeText;
83 if (storedPPI > 0 && ppi > 0) {
84 const double scale = double(storedPPI)/double(ppi);
116 QMap<QString, QVariant> m =
metadata();
122 QMap<QString, QVariant> m =
metadata();
130 QMap<QString, QVariant> m =
metadata();
136 QMap<QString, QVariant> m =
metadata();
149 if (
d->sample == text)
return;
157 const QString sample =
d->sample;
158 const QString after =
d->afterText;
159 const QString before =
d->beforeText;
190 sampleText->setPropertiesAtPos(-1, modifiedProps);
194 const QSizeF sampleSize =
d->paragraphSampleSize;
198 inlineShape->
moveTo(QPointF(0, 0));
199 inlineShape->
lineTo(QPointF(sampleSize.width(), 0));
200 inlineShape->
lineTo(QPointF(sampleSize.width(), sampleSize.height()));
201 inlineShape->
lineTo(QPointF(0, sampleSize.height()));
202 inlineShape->
lineTo(QPointF(0, 0));
203 inlineShape->
close();
216 newShape->setPropertiesAtPos(-1, paraProps);
217 if (!after.isEmpty()) {
218 newShape->insertText(0, after);
220 if (!before.isEmpty()) {
221 newShape->insertText(0, before);
224 newShape->insertRichText(newShape->posForIndex(before.size()),
sampleText.data());
225 return newShape.take();
233 QMap<QString, QVariant> m =
metadata();
234 QVariant
v = m.value(
SAMPLE_ALIGN,
static_cast<Qt::Alignment::Int
>(Qt::AlignHCenter | Qt::AlignVCenter));
235 return static_cast<Qt::Alignment
>(
v.value<Qt::Alignment::Int>());
240 QMap<QString, QVariant> m =
metadata();
246 Qt::AlignmentFlag hComponent = Qt::AlignHCenter;
247 Qt::AlignmentFlag vComponent = Qt::AlignVCenter;
260 vComponent = Qt::AlignTop;
263 hComponent = Qt::AlignLeft;
265 hComponent = Qt::AlignRight;
269 hComponent = Qt::AlignRight;
271 hComponent = Qt::AlignLeft;
274 hComponent = Qt::AlignLeft;
276 hComponent = Qt::AlignRight;
282 vComponent = Qt::AlignTop;
284 vComponent = Qt::AlignBottom;
288 vComponent = Qt::AlignBottom;
290 vComponent = Qt::AlignTop;
293 vComponent = Qt::AlignTop;
295 vComponent = Qt::AlignBottom;
302 vComponent = Qt::AlignTop;
305 hComponent = Qt::AlignLeft;
307 hComponent = Qt::AlignRight;
311 hComponent = Qt::AlignRight;
313 hComponent = Qt::AlignLeft;
316 hComponent = Qt::AlignHCenter;
322 vComponent = Qt::AlignTop;
324 vComponent = Qt::AlignBottom;
328 vComponent = Qt::AlignBottom;
330 vComponent = Qt::AlignTop;
333 vComponent = Qt::AlignVCenter;
344 return d->beforeText;
349 if (
d->beforeText == text)
return;
350 d->beforeText = text;
361 if (
d->afterText == text)
return;
368 QMap<QString, QVariant> m =
metadata();
374 return d->paragraphSampleSize;
379 d->paragraphSampleSize = size;
385 QMap<QString, QVariant> m =
metadata();
402 Q_UNUSED(resourcesInterface)
403 if (!dev->isOpen()) dev->open(QIODevice::ReadOnly);
408 if (xmlDocument.isNull()) {
411 <<
" In line: " << errorLine <<
", column: " << errorColumn << Qt::endl
412 <<
" Error message: " << errorMsg << Qt::endl;
413 errorFlake <<
"Parsing error in the main document at line" << errorLine
414 <<
", column" << errorColumn << Qt::endl
415 <<
"Error message: " << errorMsg;
428 Q_FOREACH(
KoShape *shape, shapes) {
451 d->sample = textShape->
plainText().mid(pos.first, pos.second-pos.first);
452 d->beforeText = textShape->
plainText().mid(0, pos.first);
453 d->afterText = textShape->
plainText().mid(pos.second);
456 d->paragraphSampleSize = textShape->
shapesInside().first()->size();
476 if (!shape)
return false;
478 QMap<QString, QVariant> m =
metadata();
480 shape->setAdditionalAttribute(
TITLE,
name());
482 const QRectF boundingRect = shape->boundingRect();
484 return writer.
save(*dev, boundingRect.size());
496 buffer.open(QIODevice::WriteOnly);
500 return QString::fromUtf8(buffer.data());
509 QImage::Format_ARGB32);
const QString STYLE_TYPE_PARAGRAPH
QString generateSVG(const KoSvgTextShape *shape)
const QString DESCRIPTION
const QString PRIMARY_FONT_FAMILY
const QString SAMPLE_ALIGN
const QString STYLE_TYPE_CHARACTER
const KLocalizedString SAMPLE_PLACEHOLDER
The KoCssStylePreset class.
KoCssStylePreset(const QString &filename)
void setStyleType(const QString &type)
QSizeF paragraphSampleSize() const
Returns the size of the shape which the paragraph is set as.
void setBeforeText(const QString &text)
set the before text. Call updateThumbnail to update the sample.
bool loadFromDevice(QIODevice *dev, KisResourcesInterfaceSP resourcesInterface) override
QString defaultFileExtension() const override
QString beforeText() const
The text displayed before the sample. Only relevant when in Character mode.
void setProperties(const KoSvgTextProperties &properties)
set the properties. Call updateThumbnail to update the sample.
KoShape * generateSampleShape() const
generateSampleShape This generates the sample textshape from the properties and sample text(s).
QString sampleText() const
The sample text that is being styled by this preset.
int storedPPIResolution() const
void setParagraphSampleSize(const QSizeF size)
Set the size of the shape the paragraph is set in.
void setAfterText(const QString &text)
set the after text. Call updateThumbnail to update the sample.
void setSampleText(const QString &text)
set the sample. Call updateThumbnail to update the sample.
void setDescription(const QString &desc)
QString afterText() const
The text displayed after the sample, only relevant when in character mode.
void setStoredPPIResolution(const int ppi)
void updateThumbnail() override
updateThumbnail updates the thumbnail for this resource. Reimplement if your thumbnail is something e...
Qt::Alignment alignSample() const
QScopedPointer< Private > d
KoSvgTextProperties properties(int ppi=72, bool removeKraProps=false) const
The actual text properties.
QString sampleSvg() const
Returns the sample svg metadata. Use updateThumbnail to update it.
bool saveToDevice(QIODevice *dev) const override
QString description() const
The description associated with this style.
KoResourceSP clone() const override
QPair< QString, QString > resourceType() const override
QString primaryFontFamily() const
primaryFontFamily If a style uses a FontFamily, it may not look as expected when that font family is ...
QString styleType() const
Set the style type, type is either "paragraph" or "character".
The position of a path point within a path shape.
KoPathPoint * lineTo(const QPointF &p)
Adds a new line segment.
void close()
Closes the current subpath.
KoPathPoint * moveTo(const QPointF &p)
Starts a new Subpath.
void setShapes(const QList< KoShape * > &shapes)
void paint(QPainter &painter)
QString additionalAttribute(const QString &name) const
The KoSvgTextNodeIndex class.
KoSvgTextProperties * properties()
properties The properties for this node as a pointer.
@ TextAnchorId
KoSvgText::TextAnchor.
@ InlineSizeId
KoSvgText::AutoValue.
@ PaintOrder
QVector<KoShape::PaintOrder>
@ KraTextStyleResolution
Int, used to scale style presets to be pixel-relative.
@ KraTextVersionId
Int, used for handling incorrectly saved files.
@ FontFamiliesId
QStringList.
@ Opacity
Double, SVG shape opacity.
@ KraTextStyleType
string, used to identify the style preset type (character or paragraph).
@ TextOrientationId
KoSvgText::TextOrientation.
@ TextAlignAllId
KoSvgText::TextAlign.
@ TextCollapseId
KoSvgText::TextSpaceCollapse.
@ StrokeId
KoSvgText::StrokeProperty.
@ FillId
KoSvgText::BackgroundProperty.
@ WritingModeId
KoSvgText::WritingMode.
@ DirectionId
KoSvgText::Direction.
@ TextWrapId
KoSvgText::TextWrap.
@ Visibility
Bool, CSS visibility.
@ TextAlignLastId
KoSvgText::TextAlign.
void removeProperty(PropertyId id)
QList< PropertyId > properties() const
static bool propertyIsBlockOnly(KoSvgTextProperties::PropertyId id)
QVariant property(PropertyId id, const QVariant &defaultValue=QVariant()) const
static const KoSvgTextProperties & defaultProperties()
void scaleAbsoluteValues(const double scaleInline=1.0, const double scaleBlock=1.0)
scaleAbsoluteValues This scales all absolute values stored in these text properties....
bool hasProperty(PropertyId id) const
void setProperty(PropertyId id, const QVariant &value)
QVariant propertyOrDefault(PropertyId id) const
QPair< int, int > findRangeForNodeIndex(const KoSvgTextNodeIndex &node) const
findRangeForNodeIndex Find the start and end cursor position for a given nodeIndex.
QRectF boundingRect() const override
Get the bounding box of the shape.
KoSvgTextNodeIndex findNodeIndexForPropertyId(KoSvgTextProperties::PropertyId propertyId)
findNodeIndexForPropertyId
int indexForPos(int pos) const
indexForPos get the string index for a given cursor position.
KoShape * textOutline() const
textOutline This turns the text object into non-text KoShape(s) to the best of its abilities.
QList< KoShape * > shapesInside
static QDomDocument createDocumentFromSvg(QIODevice *device, QString *errorMsg=0, int *errorLine=0, int *errorColumn=0)
void setResolveTextPropertiesForTopLevel(const bool enable)
QList< KoShape * > parseSvg(const QDomElement &e, QSizeF *fragmentSize=0)
Parses a svg fragment, returning the list of top level child shapes.
void setResolution(const QRectF boundsInPixels, qreal pixelsPerInch)
Implements exporting shapes to SVG.
bool save(QIODevice &outputDevice, const QSizeF &pageSize)
Writes svg to specified output device.
QSharedPointer< KoResource > KoResourceSP
TextAnchor
Where the text is anchored for SVG 1.1 text and 'inline-size'.
@ AnchorEnd
Anchor right for LTR, left for RTL.
@ AnchorStart
Anchor left for LTR, right for RTL.
Direction
Base direction used by Bidi algorithm.
@ Preserve
Do not collapse any space.
QSizeF paragraphSampleSize
KoSvgTextProperties properties
void setValid(bool valid)
void setName(const QString &name)
void addMetaData(QString key, QVariant value)
store the given key, value pair in the resource
void setDirty(bool value)
Mark the preset as modified but not saved.
void setImage(const QImage &image)
QMap< QString, QVariant > metadata