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;
170 if (removeParagraph) {
174 if (!removeParagraph) {
197 sampleText->setPropertiesAtPos(-1, modifiedProps);
201 const QSizeF sampleSize =
d->paragraphSampleSize;
205 inlineShape->
moveTo(QPointF(0, 0));
206 inlineShape->
lineTo(QPointF(sampleSize.width(), 0));
207 inlineShape->
lineTo(QPointF(sampleSize.width(), sampleSize.height()));
208 inlineShape->
lineTo(QPointF(0, sampleSize.height()));
209 inlineShape->
lineTo(QPointF(0, 0));
210 inlineShape->
close();
223 newShape->setPropertiesAtPos(-1, paraProps);
224 if (!after.isEmpty()) {
225 newShape->insertText(0, after);
227 if (!before.isEmpty()) {
228 newShape->insertText(0, before);
231 newShape->insertRichText(newShape->posForIndex(before.size()),
sampleText.data());
232 return newShape.take();
240 QMap<QString, QVariant> m =
metadata();
241 QVariant
v = m.value(
SAMPLE_ALIGN,
static_cast<Qt::Alignment::Int
>(Qt::AlignHCenter | Qt::AlignVCenter));
242 return static_cast<Qt::Alignment
>(
v.value<Qt::Alignment::Int>());
247 QMap<QString, QVariant> m =
metadata();
253 Qt::AlignmentFlag hComponent = Qt::AlignHCenter;
254 Qt::AlignmentFlag vComponent = Qt::AlignVCenter;
267 vComponent = Qt::AlignTop;
270 hComponent = Qt::AlignLeft;
272 hComponent = Qt::AlignRight;
276 hComponent = Qt::AlignRight;
278 hComponent = Qt::AlignLeft;
281 hComponent = Qt::AlignLeft;
283 hComponent = Qt::AlignRight;
289 vComponent = Qt::AlignTop;
291 vComponent = Qt::AlignBottom;
295 vComponent = Qt::AlignBottom;
297 vComponent = Qt::AlignTop;
300 vComponent = Qt::AlignTop;
302 vComponent = Qt::AlignBottom;
309 vComponent = Qt::AlignTop;
312 hComponent = Qt::AlignLeft;
314 hComponent = Qt::AlignRight;
318 hComponent = Qt::AlignRight;
320 hComponent = Qt::AlignLeft;
323 hComponent = Qt::AlignHCenter;
329 vComponent = Qt::AlignTop;
331 vComponent = Qt::AlignBottom;
335 vComponent = Qt::AlignBottom;
337 vComponent = Qt::AlignTop;
340 vComponent = Qt::AlignVCenter;
351 return d->beforeText;
356 if (
d->beforeText == text)
return;
357 d->beforeText = text;
368 if (
d->afterText == text)
return;
375 QMap<QString, QVariant> m =
metadata();
381 return d->paragraphSampleSize;
386 d->paragraphSampleSize = size;
392 QMap<QString, QVariant> m =
metadata();
409 Q_UNUSED(resourcesInterface)
410 if (!dev->isOpen()) dev->open(QIODevice::ReadOnly);
415 if (xmlDocument.isNull()) {
418 <<
" In line: " << errorLine <<
", column: " << errorColumn << Qt::endl
419 <<
" Error message: " << errorMsg << Qt::endl;
420 errorFlake <<
"Parsing error in the main document at line" << errorLine
421 <<
", column" << errorColumn << Qt::endl
422 <<
"Error message: " << errorMsg;
435 Q_FOREACH(
KoShape *shape, shapes) {
458 d->sample = textShape->
plainText().mid(pos.first, pos.second-pos.first);
459 d->beforeText = textShape->
plainText().mid(0, pos.first);
460 d->afterText = textShape->
plainText().mid(pos.second);
463 d->paragraphSampleSize = textShape->
shapesInside().first()->size();
483 if (!shape)
return false;
485 QMap<QString, QVariant> m =
metadata();
487 shape->setAdditionalAttribute(
TITLE,
name());
489 const QRectF boundingRect = shape->boundingRect();
491 return writer.
save(*dev, boundingRect.size());
503 buffer.open(QIODevice::WriteOnly);
507 return QString::fromUtf8(buffer.data());
516 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