11#include <KLocalizedString>
16#include <QDomDocument>
24const QString
DESC =
"desc";
54 const QFileInfo f(
name());
63 d->properties = rhs.
d->properties;
64 d->sample = rhs.
d->sample;
65 d->afterText = rhs.
d->afterText;
66 d->beforeText = rhs.
d->beforeText;
81 if (storedPPI > 0 && ppi > 0) {
82 const double scale = double(storedPPI)/double(ppi);
114 QMap<QString, QVariant> m =
metadata();
120 QMap<QString, QVariant> m =
metadata();
128 QMap<QString, QVariant> m =
metadata();
134 QMap<QString, QVariant> m =
metadata();
147 if (
d->sample == text)
return;
155 const QString sample =
d->sample;
156 const QString after =
d->afterText;
157 const QString before =
d->beforeText;
168 if (removeParagraph) {
172 if (!removeParagraph) {
195 sampleText->setPropertiesAtPos(-1, modifiedProps);
201 inlineShape->
moveTo(QPointF(0, 0));
202 inlineShape->
lineTo(QPointF(120, 0));
203 inlineShape->
lineTo(QPointF(120, 120));
204 inlineShape->
lineTo(QPointF(0, 120));
205 inlineShape->
lineTo(QPointF(0, 0));
206 inlineShape->
close();
219 newShape->setPropertiesAtPos(-1, paraProps);
220 if (!after.isEmpty()) {
221 newShape->insertText(0, after);
223 if (!before.isEmpty()) {
224 newShape->insertText(0, before);
227 newShape->insertRichText(newShape->posForIndex(before.size()),
sampleText.data());
228 return newShape.take();
236 QMap<QString, QVariant> m =
metadata();
237 QVariant
v = m.value(
SAMPLE_ALIGN,
static_cast<Qt::Alignment::Int
>(Qt::AlignHCenter | Qt::AlignVCenter));
238 return static_cast<Qt::Alignment
>(
v.value<Qt::Alignment::Int>());
243 QMap<QString, QVariant> m =
metadata();
249 Qt::AlignmentFlag hComponent = Qt::AlignHCenter;
250 Qt::AlignmentFlag vComponent = Qt::AlignVCenter;
263 vComponent = Qt::AlignTop;
266 hComponent = Qt::AlignLeft;
268 hComponent = Qt::AlignRight;
272 hComponent = Qt::AlignRight;
274 hComponent = Qt::AlignLeft;
277 hComponent = Qt::AlignLeft;
279 hComponent = Qt::AlignRight;
285 vComponent = Qt::AlignTop;
287 vComponent = Qt::AlignBottom;
291 vComponent = Qt::AlignBottom;
293 vComponent = Qt::AlignTop;
296 vComponent = Qt::AlignTop;
298 vComponent = Qt::AlignBottom;
305 vComponent = Qt::AlignTop;
308 hComponent = Qt::AlignLeft;
310 hComponent = Qt::AlignRight;
314 hComponent = Qt::AlignRight;
316 hComponent = Qt::AlignLeft;
319 hComponent = Qt::AlignHCenter;
325 vComponent = Qt::AlignTop;
327 vComponent = Qt::AlignBottom;
331 vComponent = Qt::AlignBottom;
333 vComponent = Qt::AlignTop;
336 vComponent = Qt::AlignVCenter;
347 return d->beforeText;
352 if (
d->beforeText == text)
return;
353 d->beforeText = text;
364 if (
d->afterText == text)
return;
371 QMap<QString, QVariant> m =
metadata();
377 QMap<QString, QVariant> m =
metadata();
394 Q_UNUSED(resourcesInterface)
395 if (!dev->isOpen()) dev->open(QIODevice::ReadOnly);
400 if (xmlDocument.isNull()) {
403 <<
" In line: " << errorLine <<
", column: " << errorColumn << Qt::endl
404 <<
" Error message: " << errorMsg << Qt::endl;
405 errorFlake <<
"Parsing error in the main document at line" << errorLine
406 <<
", column" << errorColumn << Qt::endl
407 <<
"Error message: " << errorMsg;
420 Q_FOREACH(
KoShape *shape, shapes) {
443 d->sample = textShape->
plainText().mid(pos.first, pos.second-pos.first);
444 d->beforeText = textShape->
plainText().mid(0, pos.first);
445 d->afterText = textShape->
plainText().mid(pos.second);
463 if (!shape)
return false;
465 QMap<QString, QVariant> m =
metadata();
467 shape->setAdditionalAttribute(
TITLE,
name());
469 const QRectF boundingRect = shape->boundingRect();
471 return writer.
save(*dev, boundingRect.size());
483 buffer.open(QIODevice::WriteOnly);
487 return QString::fromUtf8(buffer.data());
496 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)
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 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.
@ Visiblity
Bool, CSS visibility.
@ 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.
@ 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.
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.
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