Krita Source Code Documentation
Loading...
Searching...
No Matches
KoSvgTextProperties Class Reference

#include <KoSvgTextProperties.h>

+ Inheritance diagram for KoSvgTextProperties:

Classes

struct  Private
 

Public Types

enum  PropertyId {
  WritingModeId , DirectionId , UnicodeBidiId , TextAnchorId ,
  DominantBaselineId , AlignmentBaselineId , BaselineShiftModeId , BaselineShiftValueId ,
  KerningId , TextOrientationId , LetterSpacingId , WordSpacingId ,
  FontFamiliesId , FontStyleId , FontStretchId , FontWeightId ,
  FontSizeId , FontSizeAdjustId , FontVariantLigatureId , FontVariantPositionId ,
  FontVariantCapsId , FontVariantNumericId , FontVariantEastAsianId , FontFeatureSettingsId ,
  FontOpticalSizingId , FontVariationSettingsId , TextDecorationLineId , TextDecorationStyleId ,
  TextDecorationColorId , TextDecorationPositionId , FillId , StrokeId ,
  Opacity , PaintOrder , Visibility , TextLanguage ,
  TextCollapseId , TextWrapId , TextTrimId , LineBreakId ,
  WordBreakId , TextAlignAllId , TextAlignLastId , TextTransformId ,
  TextOverFlowId , OverflowWrapId , InlineSizeId , LineHeightId ,
  TextIndentId , HangingPunctuationId , TabSizeId , ShapePaddingId ,
  ShapeMarginId , FontSynthesisBoldId , FontSynthesisItalicId , FontSynthesisSmallCapsId ,
  FontSynthesisSuperSubId , TextRenderingId , KraTextVersionId , KraTextStyleType ,
  KraTextStyleResolution , LastPropertyId
}
 

Public Member Functions

KoSvgText::FontMetrics applyLineHeight (KoSvgText::FontMetrics metrics) const
 applyLineHeight Calculate the linegap for the current linegap property.
 
QSharedPointer< KoShapeBackgroundbackground () const
 
QMap< QString, QString > convertParagraphProperties () const
 convertParagraphProperties some properties only apply to the root shape, so we write those separately.
 
QMap< QString, QString > convertToSvgTextAttributes () const
 
KoCSSFontInfo cssFontInfo () const
 cssFontInfo
 
QStringList fontFeaturesForText (int start, int length) const
 fontFeaturesForText Returns a harfbuzz friendly list of opentype font-feature settings using the various font-variant and font-feature-settings values.
 
KoSvgText::CssLengthPercentage fontSize () const
 
QFont generateFont () const
 
bool hasNonInheritableProperties () const
 Test whether it has non-inheritable properties set.
 
bool hasProperty (PropertyId id) const
 
void inheritFrom (const KoSvgTextProperties &parentProperties, bool resolve=false)
 
bool inheritsProperty (PropertyId id, const KoSvgTextProperties &parentProperties) const
 
bool isEmpty () const
 
 KoSvgTextProperties ()
 
 KoSvgTextProperties (const KoSvgTextProperties &rhs)
 
KoSvgText::FontMetrics metrics (const bool withResolvedLineHeight=true, const bool offsetByBaseline=false) const
 metrics Return the metrics of the first available font.
 
KoSvgTextPropertiesoperator= (const KoSvgTextProperties &rhs)
 
bool operator== (const KoSvgTextProperties &rhs) const
 
KoSvgTextProperties ownProperties (const KoSvgTextProperties &parentProperties, bool keepFontSize=false) const
 
void parseSvgTextAttribute (const SvgLoadingContext &context, const QString &command, const QString &value)
 parseSvgTextAttribute add a property according to an XML attribute value.
 
QList< PropertyIdproperties () const
 
QVariant property (PropertyId id, const QVariant &defaultValue=QVariant()) const
 
bool propertyIsInheritable (KoSvgTextProperties::PropertyId id) const
 
QVariant propertyOrDefault (PropertyId id) const
 
void removeProperty (PropertyId id)
 
void resetNonInheritableToDefault ()
 
void resolveRelativeValues (const KoSvgText::FontMetrics metrics=KoSvgText::FontMetrics(12.0, true), const qreal fontSize=12.0)
 resolveRelativeValues resolve the font-relative values.
 
void scaleAbsoluteValues (const double scaleInline=1.0, const double scaleBlock=1.0)
 scaleAbsoluteValues This scales all absolute values stored in these text properties. Relative values don't need to be scaled. This can be used to scale styles in setSize as well as scale the text properties for Style Presets.
 
void setAllButNonInheritableProperties (const KoSvgTextProperties &properties)
 Used to merge child properties into parent properties.
 
void setFontSize (const KoSvgText::CssLengthPercentage length)
 
void setProperty (PropertyId id, const QVariant &value)
 
KoShapeStrokeModelSP stroke () const
 
qreal xHeight () const
 
 ~KoSvgTextProperties ()
 

Static Public Member Functions

static const KoSvgTextPropertiesdefaultProperties ()
 
static bool propertyIsBlockOnly (KoSvgTextProperties::PropertyId id)
 
static QStringList supportedXmlAttributes ()
 

Private Attributes

const QScopedPointer< Privatem_d
 

Detailed Description

KoSvgTextProperties represents the text attributes defined in SVG DOM tree

There is a limitation in flake: it doesn't support the inheritance of shape properties: every shape stores all the properties that were defined at the loading/creation stage. KoSvgTextProperties allows the user to compare the properties of the two shapes and distinguish, which properties were inherited by text shape, and which are its own. It is needed to generate a correct and clean SVG/markup code that can be edited by the user easily. Otherwise, every <tspan> block will contain the full list of 20+ attributes, which are not interesting for the user, since they are inherited or default.

To achieve the goal, KoSvgTextProperties wraps all the SVG attributes into a map of QVariants. When the user need to find a set of unique properties of the shape, it iterates through the map and compares values with standard QVariant-based comparison operator. If the property value in a child and a parent is not the same, then it is not inherited.

Definition at line 43 of file KoSvgTextProperties.h.

Member Enumeration Documentation

◆ PropertyId

Defines a set of supported properties. See SVG 1.1 for details.

Enumerator
WritingModeId 

KoSvgText::WritingMode.

DirectionId 

KoSvgText::Direction.

UnicodeBidiId 

KoSvgText::UnicodeBidi.

TextAnchorId 

KoSvgText::TextAnchor.

DominantBaselineId 

KoSvgText::Baseline.

AlignmentBaselineId 

KoSvgText::Baseline.

BaselineShiftModeId 

KoSvgText::BaselineShiftMode.

BaselineShiftValueId 

Double.

KerningId 

KoSvgText::AutoValue.

TextOrientationId 

KoSvgText::TextOrientation.

LetterSpacingId 

KoSvgText::AutoLengthPercentage.

WordSpacingId 

KoSvgText::AutoLengthPercentage.

FontFamiliesId 

QStringList.

FontStyleId 

KoSvgText::CssSlantData.

FontStretchId 

Int.

FontWeightId 

Int.

FontSizeId 

Double.

FontSizeAdjustId 

KoSvgText::AutoValue.

FontVariantLigatureId 

KoSvgText::FontVariantFeature.

FontVariantPositionId 
FontVariantCapsId 
FontVariantNumericId 
FontVariantEastAsianId 
FontFeatureSettingsId 

QStringList.

FontOpticalSizingId 

Bool.

FontVariationSettingsId 

QStringList.

TextDecorationLineId 

Flags, KoSvgText::TextDecorations.

TextDecorationStyleId 

KoSvgText::TextDecorationStyle.

TextDecorationColorId 

QColor.

TextDecorationPositionId 

KoSvgText::TextDecorationUnderlinePosition.

FillId 

KoSvgText::BackgroundProperty.

StrokeId 

KoSvgText::StrokeProperty.

Opacity 

Double, SVG shape opacity.

PaintOrder 

QVector<KoShape::PaintOrder>

Visibility 

Bool, CSS visibility.

TextLanguage 

a language string.

TextCollapseId 

KoSvgText::TextSpaceCollapse.

TextWrapId 

KoSvgText::TextWrap.

TextTrimId 

Flags, KoSvgText::TextSpaceTrims.

LineBreakId 

KoSvgText::LineBreak.

WordBreakId 

KoSvgText::WordBreak.

TextAlignAllId 

KoSvgText::TextAlign.

TextAlignLastId 

KoSvgText::TextAlign.

TextTransformId 

KoSvgText::TextTransformInfo Struct.

TextOverFlowId 

KoSvgText::WordBreak.

OverflowWrapId 
InlineSizeId 

KoSvgText::AutoValue.

LineHeightId 

KoSvgText::AutoValue.

TextIndentId 

KoSvgText::TextIndentInfo Struct.

HangingPunctuationId 

Flags, KoSvgText::HangingPunctuations.

TabSizeId 

Int.

ShapePaddingId 

Double.

ShapeMarginId 

Double.

FontSynthesisBoldId 

Bool.

FontSynthesisItalicId 

Bool.

FontSynthesisSmallCapsId 

Bool.

FontSynthesisSuperSubId 

Bool.

TextRenderingId 

Enum.

KraTextVersionId 

Int, used for handling incorrectly saved files.

KraTextStyleType 

string, used to identify the style preset type (character or paragraph).

KraTextStyleResolution 

Int, used to scale style presets to be pixel-relative.

LastPropertyId 

Last Property ID, used for iteration.

Definition at line 49 of file KoSvgTextProperties.h.

49 {
58 KerningId,
62
69
76
80
85 FillId,
86 StrokeId,
87 Opacity,
90
92
107 TabSizeId,
108
111
116
118
122
124 };
@ TextAnchorId
KoSvgText::TextAnchor.
@ InlineSizeId
KoSvgText::AutoValue.
@ UnicodeBidiId
KoSvgText::UnicodeBidi.
@ PaintOrder
QVector<KoShape::PaintOrder>
@ KraTextStyleResolution
Int, used to scale style presets to be pixel-relative.
@ KraTextVersionId
Int, used for handling incorrectly saved files.
@ DominantBaselineId
KoSvgText::Baseline.
@ Opacity
Double, SVG shape opacity.
@ TextTrimId
Flags, KoSvgText::TextSpaceTrims.
@ AlignmentBaselineId
KoSvgText::Baseline.
@ LineHeightId
KoSvgText::AutoValue.
@ KraTextStyleType
string, used to identify the style preset type (character or paragraph).
@ WordSpacingId
KoSvgText::AutoLengthPercentage.
@ LineBreakId
KoSvgText::LineBreak.
@ FontSizeAdjustId
KoSvgText::AutoValue.
@ LetterSpacingId
KoSvgText::AutoLengthPercentage.
@ TextOrientationId
KoSvgText::TextOrientation.
@ TextAlignAllId
KoSvgText::TextAlign.
@ TextCollapseId
KoSvgText::TextSpaceCollapse.
@ StrokeId
KoSvgText::StrokeProperty.
@ TextDecorationStyleId
KoSvgText::TextDecorationStyle.
@ TextOverFlowId
KoSvgText::WordBreak.
@ TextTransformId
KoSvgText::TextTransformInfo Struct.
@ FillId
KoSvgText::BackgroundProperty.
@ FontStyleId
KoSvgText::CssSlantData.
@ FontFeatureSettingsId
QStringList.
@ WritingModeId
KoSvgText::WritingMode.
@ DirectionId
KoSvgText::Direction.
@ TextWrapId
KoSvgText::TextWrap.
@ HangingPunctuationId
Flags, KoSvgText::HangingPunctuations.
@ Visibility
Bool, CSS visibility.
@ BaselineShiftModeId
KoSvgText::BaselineShiftMode.
@ TextAlignLastId
KoSvgText::TextAlign.
@ FontVariantLigatureId
KoSvgText::FontVariantFeature.
@ TextDecorationPositionId
KoSvgText::TextDecorationUnderlinePosition.
@ TextIndentId
KoSvgText::TextIndentInfo Struct.
@ FontVariationSettingsId
QStringList.
@ WordBreakId
KoSvgText::WordBreak.
@ TextLanguage
a language string.
@ TextDecorationLineId
Flags, KoSvgText::TextDecorations.
@ LastPropertyId
Last Property ID, used for iteration.
@ KerningId
KoSvgText::AutoValue.

Constructor & Destructor Documentation

◆ KoSvgTextProperties() [1/2]

KoSvgTextProperties::KoSvgTextProperties ( )

Definition at line 32 of file KoSvgTextProperties.cpp.

33 : m_d(new Private)
34{
35}
const QScopedPointer< Private > m_d

◆ ~KoSvgTextProperties()

KoSvgTextProperties::~KoSvgTextProperties ( )

Definition at line 37 of file KoSvgTextProperties.cpp.

38{
39}

◆ KoSvgTextProperties() [2/2]

KoSvgTextProperties::KoSvgTextProperties ( const KoSvgTextProperties & rhs)

Definition at line 41 of file KoSvgTextProperties.cpp.

42 : m_d(new Private)
43{
44 m_d->properties = rhs.m_d->properties;
45}

References m_d.

Member Function Documentation

◆ applyLineHeight()

KoSvgText::FontMetrics KoSvgTextProperties::applyLineHeight ( KoSvgText::FontMetrics metrics) const

applyLineHeight Calculate the linegap for the current linegap property.

Parameters
metricsthe metrics to apply this to.
Returns
metrics with the linegap adjusted for the lineheight.

Definition at line 1112 of file KoSvgTextProperties.cpp.

1113{
1114 const qreal res = metrics.fontSize / this->fontSize().value;
1115
1117 if (!lineHeight.isNormal) {
1118 if (lineHeight.isNumber) {
1119 metrics.lineGap = (metrics.fontSize)*lineHeight.value;
1120 } else {
1121 metrics.lineGap = lineHeight.length.value * res;
1122 }
1124 }
1125 return metrics;
1126}
KoSvgText::FontMetrics metrics(const bool withResolvedLineHeight=true, const bool offsetByBaseline=false) const
metrics Return the metrics of the first available font.
QVariant propertyOrDefault(PropertyId id) const
KoSvgText::CssLengthPercentage fontSize() const
qint32 lineGap
additional linegap between consecutive lines.
Definition KoSvgText.h:341
qint32 fontSize
Currently set size, CSS unit 'em'.
Definition KoSvgText.h:329
qint32 descender
distance for origin to bottom.
Definition KoSvgText.h:340
qint32 ascender
distance from origin to top.
Definition KoSvgText.h:339
bool isNumber
Length or number.
Definition KoSvgText.h:695
CssLengthPercentage length
Definition KoSvgText.h:693
bool isNormal
It's a number indicating the lineHeight;.
Definition KoSvgText.h:696

References KoSvgText::FontMetrics::ascender, KoSvgText::FontMetrics::descender, KoSvgText::FontMetrics::fontSize, fontSize(), KoSvgText::LineHeightInfo::isNormal, KoSvgText::LineHeightInfo::isNumber, KoSvgText::LineHeightInfo::length, KoSvgText::FontMetrics::lineGap, LineHeightId, metrics(), propertyOrDefault(), KoSvgText::CssLengthPercentage::value, and KoSvgText::LineHeightInfo::value.

◆ background()

QSharedPointer< KoShapeBackground > KoSvgTextProperties::background ( ) const

Definition at line 1193 of file KoSvgTextProperties.cpp.

1194{
1196}
QVariant property(PropertyId id, const QVariant &defaultValue=QVariant()) const
BackgroundProperty is a special wrapper around KoShapeBackground for managing it in KoSvgTextProperti...
Definition KoSvgText.h:714

References FillId, and property().

◆ convertParagraphProperties()

QMap< QString, QString > KoSvgTextProperties::convertParagraphProperties ( ) const

convertParagraphProperties some properties only apply to the root shape, so we write those separately.

Returns

Definition at line 995 of file KoSvgTextProperties.cpp.

996{
997 using namespace KoSvgText;
998 QMap<QString, QString> result;
1000 result.insert("inline-size", writeAutoValue(property(InlineSizeId).value<AutoValue>(), "auto"));
1001 }
1003 result.insert("text-indent", writeTextIndent(propertyOrDefault(TextIndentId).value<TextIndentInfo>()));
1004 }
1007 result.insert("text-align", writeTextAlign(all));
1009 if (last != all || last != AlignLastAuto) {
1010 result.insert("text-align-last", writeTextAlign(last));
1011 }
1012 }
1014 result.insert("shape-padding", writeLengthPercentage(property(ShapePaddingId).value<CssLengthPercentage>()));
1015 }
1017 result.insert("shape-margin", writeLengthPercentage(property(ShapeMarginId).value<CssLengthPercentage>()));
1018 }
1019 return result;
1020}
bool hasProperty(PropertyId id) const
int toInt(const QString &str, bool *ok=nullptr)
QString writeLengthPercentage(const CssLengthPercentage &length, bool percentageAsEm)
QString writeTextAlign(TextAlign value)
QString writeAutoValue(const AutoValue &value, const QString &autoKeyword)
QString writeTextIndent(const TextIndentInfo textIndent)

References hasProperty(), InlineSizeId, property(), propertyOrDefault(), ShapeMarginId, ShapePaddingId, TextAlignAllId, TextAlignLastId, and TextIndentId.

◆ convertToSvgTextAttributes()

QMap< QString, QString > KoSvgTextProperties::convertToSvgTextAttributes ( ) const

Convert all the properties of the set into a map of XML attribute/value pairs.

Definition at line 640 of file KoSvgTextProperties.cpp.

641{
642 using namespace KoSvgText;
643
644 QMap<QString, QString> result;
645
646 bool svg1_1 = false;
647
649 result.insert("writing-mode", writeWritingMode(WritingMode(property(WritingModeId).toInt()), svg1_1));
650 }
651
653 if (svg1_1) {
655 QString value = "auto";
656 if (orientation == OrientationUpright) {
657 value = "0";
658 } else if (orientation == OrientationSideWays) {
659 value = "90";
660 }
661 result.insert("glyph-orientation-vertical", value);
662 } else {
663 result.insert("text-orientation", writeTextOrientation(TextOrientation(property(TextOrientationId).toInt())));
664 }
665 }
666
668 result.insert("direction", writeDirection(Direction(property(DirectionId).toInt())));
669 }
670
672 result.insert("unicode-bidi", writeUnicodeBidi(UnicodeBidi(property(UnicodeBidiId).toInt())));
673 }
674
676 result.insert("text-anchor", writeTextAnchor(TextAnchor(property(TextAnchorId).toInt())));
677 }
678
680 result.insert("dominant-baseline", writeDominantBaseline(Baseline(property(DominantBaselineId).toInt())));
681 }
682
683 bool writeSeparate = true;
684 if (hasProperty(BaselineShiftModeId) && !svg1_1) {
686 if (mode == ShiftLineTop || mode == ShiftLineBottom) {
687 writeSeparate = false;
688 }
689 }
690
691 if (writeSeparate) {
693 result.insert("alignment-baseline", writeAlignmentBaseline(Baseline(property(AlignmentBaselineId).toInt())));
694 }
695
698 result.insert("baseline-shift",
700 }
701 } else {
702 QStringList verticalAlign;
705 }
706
710 }
711 if (!verticalAlign.isEmpty()) {
712 result.insert("vertical-align", verticalAlign.join(" "));
713 }
714 }
715
716 if (hasProperty(KerningId)) {
717 if (svg1_1) {
718 result.insert("kerning", writeAutoValue(property(KerningId).value<AutoValue>()));
719 } else {
720 AutoValue kerning = property(KerningId).value<AutoValue>();
721 if (kerning.isAuto) {
722 result.insert("font-kerning", "auto");
723 } else if (kerning.customValue == 0) {
724 result.insert("font-kerning", "none");
725 } else {
726 result.insert("font-kerning", "normal");
727 }
728 }
729 }
730
731 // Word-spacing and letter-spacing don't support % until css-text-4, and in svg 1.1, % were viewport, so save % as em for now.
733 result.insert("letter-spacing", writeAutoLengthPercentage(property(LetterSpacingId).value<AutoLengthPercentage>(), "normal", true));
734 }
735
737 result.insert("word-spacing", writeAutoLengthPercentage(property(WordSpacingId).value<AutoLengthPercentage>(), "normal", true));
738 }
739
741 result.insert("font-family", property(FontFamiliesId).toStringList().join(','));
742 }
743
746 result.insert("font-style", KoSvgText::writeFontStyle(style));
747 }
748
751 result.insert("font-variant-ligatures", writeFontFeatureLigatures(feat));
752 }
755 result.insert("font-variant-position", writeFontFeaturePosition(feat));
756 }
759 result.insert("font-variant-caps", writeFontFeatureCaps(feat));
760 }
763 result.insert("font-variant-numeric", writeFontFeatureNumeric(feat));
764 }
767 result.insert("font-variant-east-asian", writeFontFeatureEastAsian(feat));
768 }
770 QStringList settings;
771 QVariantMap vals = property(FontFeatureSettingsId).toMap();
772 for(auto it = vals.begin(); it != vals.end(); it++) {
773 settings.append(QString("'%1' %2").arg(it.key()).arg(it.value().toDouble()));
774 }
775 result.insert("font-feature-settings", settings.join(", "));
776 }
777
779 if (!property(FontOpticalSizingId).toBool()) {
780 result.insert("font-optical-sizing", "none");
781 }
782 }
784 QStringList settings;
785 QVariantMap vals = property(FontVariationSettingsId).toMap();
786 for(auto it = vals.begin(); it != vals.end(); it++) {
787 settings.append(QString("'%1' %2").arg(it.key()).arg(it.value().toDouble()));
788 }
789 result.insert("font-variation-settings", settings.join(", "));
790 }
791
793 const int stretch = property(FontStretchId).toInt();
794 static constexpr std::array<int, 9> fontStretches = {50, 62, 75, 87, 100, 112, 125, 150, 200};
795 if (svg1_1 || std::find(fontStretches.begin(), fontStretches.end(), stretch) != fontStretches.end()) {
796 const auto it = std::lower_bound(fontStretches.begin(), fontStretches.end(), stretch);
797 if (it != fontStretches.end()) {
798 const auto index = std::distance(fontStretches.begin(), it);
799 KIS_ASSERT(index >= 0);
800 result.insert("font-stretch", KoSvgText::fontStretchNames.at(static_cast<size_t>(index)));
801 }
802 } else {
803 result.insert("font-stretch", KisDomUtils::toString(stretch));
804 }
805 }
806
808 result.insert("font-weight", KisDomUtils::toString(property(FontWeightId).toInt()));
809 }
810
811 if (hasProperty(FontSizeId)) {
812 result.insert("font-size", writeLengthPercentage(fontSize()));
813 }
814
816 result.insert("font-size-adjust", writeAutoValue(property(FontSizeAdjustId).value<AutoValue>(), "none"));
817 }
818
819 QStringList decoStrings;
821 TextDecorations deco = property(TextDecorationLineId).value<TextDecorations>();
822
823 if (deco.testFlag(DecorationUnderline)) {
824 decoStrings.append("underline");
825 }
826
827 if (deco.testFlag(DecorationOverline)) {
828 decoStrings.append("overline");
829 }
830
831 if (deco.testFlag(DecorationLineThrough)) {
832 decoStrings.append("line-through");
833 }
834
835 if (deco != DecorationNone) {
838
839 if (style == Solid) {
840 decoStrings.append("solid");
841 } else if (style == Double) {
842 decoStrings.append("double");
843 } else if (style == Dotted) {
844 decoStrings.append("dotted");
845 } else if (style == Dashed) {
846 decoStrings.append("dashed");
847 } else if (style == Wavy) {
848 decoStrings.append("wavy");
849 }
850 }
852 QColor color = property(TextDecorationColorId).value<QColor>();
853 if (color.isValid()) {
854 decoStrings.append(color.name());
855 }
856 }
857 }
858 if (!decoStrings.isEmpty()) {
859 result.insert("text-decoration", decoStrings.join(' '));
860 }
861 }
862
864 QStringList decoPositionStrings;
866 if (pos.horizontalPosition == UnderlineUnder) {
867 decoPositionStrings.append("under");
868 } else {
869 decoPositionStrings.append("auto");
870 }
871 if (pos.verticalPosition == UnderlineRight) {
872 decoPositionStrings.append("right");
873 } else {
874 decoPositionStrings.append("left");
875 }
876 if (!decoPositionStrings.isEmpty()) {
877 result.insert("text-decoration-position", decoPositionStrings.join(' '));
878 }
879 }
880
882 result.insert("xml:lang", property(TextLanguage).toString());
883 }
884
886 result.insert("text-transform", writeTextTransform(property(TextTransformId).value<TextTransformInfo>()));
887 }
889 result.insert("word-break", writeWordBreak(WordBreak(property(WordBreakId).toInt())));
890 }
892 result.insert("line-break", writeLineBreak(LineBreak(property(LineBreakId).toInt())));
893 }
895 KoSvgText::TextSpaceTrims trims = propertyOrDefault(TextTrimId).value<KoSvgText::TextSpaceTrims>();
898 if (collapse == KoSvgText::PreserveSpaces || svg1_1) {
899 result.insert("xml:space", writeXmlSpace(collapse));
900 } else {
901 result.insert("white-space", writeWhiteSpaceValue(collapse, wrap, trims));
902 }
903 }
906 result.insert("line-height", KoSvgText::writeLineHeight(lineHeight));
907 }
908 if (hasProperty(TabSizeId)) {
909 result.insert("tab-size", writeTabSize(propertyOrDefault(TabSizeId).value<TabSizeInfo>()));
910 }
912 HangingPunctuations hang = property(HangingPunctuationId).value<HangingPunctuations>();
914
915 if (hang.testFlag(HangFirst)) {
916 value.append("first");
917 }
918 if (hang.testFlag(HangLast)) {
919 value.append("last");
920 }
921 if (hang.testFlag(HangEnd)) {
922 if (hang.testFlag(HangForce)) {
923 value.append("force-end");
924 } else {
925 value.append("allow-end");
926 }
927 }
928
929 if (!value.isEmpty()) {
930 result.insert("hanging-punctuation", value.join(" "));
931 }
932 }
933
936 if (overflow == OverflowWrapAnywhere) {
937 result.insert("overflow-wrap", "anywhere");
938 } else if (overflow == OverflowWrapBreakWord) {
939 result.insert("overflow-wrap", "break-word");
940 }
941 }
944 if (overflow == OverFlowClip) {
945 result.insert("overflow", "clip");
946 result.insert("text-overflow", "clip");
947 } else if (overflow == OverFlowEllipse) {
948 result.insert("overflow", "visible");
949 result.insert("text-overflow", "ellipse");
950 } else {
951 result.insert("overflow", "visible");
952 result.insert("text-overflow", "clip");
953 }
954 }
955
958 bool weight = property(FontSynthesisBoldId).toBool();
959 bool italic = property(FontSynthesisItalicId).toBool();
960 bool caps = property(FontSynthesisSmallCapsId).toBool();
961 bool super = property(FontSynthesisSuperSubId).toBool();
962
963 if (!weight && !italic && !caps && !super) {
964 result.insert("font-synthesis", "none");
965 } else {
966 QStringList params;
967 if (weight) params.append("weight");
968 if (italic) params.append("style");
969 if (caps) params.append("small-caps");
970 if (super) params.append("position");
971 result.insert("font-synthesis", params.join(" "));
972 }
973 } else {
975 result.insert("font-synthesis-weight", property(FontSynthesisBoldId).toBool()? "auto": "none");
976 }
978 result.insert("font-synthesis-style", property(FontSynthesisItalicId).toBool()? "auto": "none");
979 }
981 result.insert("font-synthesis-small-caps", property(FontSynthesisSmallCapsId).toBool()? "auto": "none");
982 }
984 result.insert("font-synthesis-position", property(FontSynthesisSuperSubId).toBool()? "auto": "none");
985 }
986 }
987
989 result.insert("text-rendering", KoSvgText::writeTextRendering(TextRendering(property(TextRenderingId).toInt())));
990 }
991
992 return result;
993}
float value(const T *src, size_t ch)
#define KIS_ASSERT(cond)
Definition kis_assert.h:33
QString toString(const QString &value)
BaselineShiftMode
Mode of the baseline shift.
Definition KoSvgText.h:240
FontFeatureCaps
Represents font-feature-caps.
Definition KoSvgText.h:897
TextAnchor
Where the text is anchored for SVG 1.1 text and 'inline-size'.
Definition KoSvgText.h:79
QString writeWordBreak(WordBreak value)
FontFeaturePosition
The FontFeatureLigatures class This enum represents css font-variant-position.
Definition KoSvgText.h:886
TextDecorationStyle
Style of the text-decoration.
Definition KoSvgText.h:265
OverflowWrap
What to do with words that cannot be broken, but still overflow.
Definition KoSvgText.h:151
WordBreak
Whether to break words.
Definition KoSvgText.h:132
QString writeBaselineShiftMode(BaselineShiftMode value, CssLengthPercentage shift)
QString writeTabSize(const TabSizeInfo tabSize)
TextWrap
Part of "white-space", in practice we only support wrap and nowrap.
Definition KoSvgText.h:109
QString writeLineHeight(LineHeightInfo lineHeight)
Baseline
Baseline values used by dominant-baseline and baseline-align.
Definition KoSvgText.h:213
QString writeFontFeatureLigatures(const FontFeatureLigatures &feature)
QString writeUnicodeBidi(UnicodeBidi value)
TextOverflow
How to handle overflow.
Definition KoSvgText.h:193
QString writeTextRendering(TextRendering value)
QString writeLineBreak(LineBreak value)
QString writeAutoLengthPercentage(const AutoLengthPercentage &value, const QString &autoKeyword, bool percentageToEm)
QString writeFontFeatureCaps(const FontFeatureCaps &value)
QString writeFontFeatureEastAsian(const FontFeatureEastAsian &feature)
QString writeFontStyle(CssFontStyleData value)
QString writeFontFeatureNumeric(const FontFeatureNumeric &feature)
QString writeAlignmentBaseline(Baseline value)
QString writeFontFeaturePosition(const FontFeaturePosition &value)
static const std::array< const char *, 9 > fontStretchNames
Definition KoSvgText.h:543
QString writeTextOrientation(TextOrientation orientation)
QString writeXmlSpace(TextSpaceCollapse collapseMethod)
TextOrientation
Orientation of the glyphs, used for vertical writing modes.
Definition KoSvgText.h:70
QString writeTextAnchor(TextAnchor value)
QString writeWritingMode(WritingMode value, bool svg1_1)
QString writeDominantBaseline(Baseline value)
TextSpaceCollapse
Definition KoSvgText.h:96
@ PreserveSpaces
required for 'xml:space="preserve"' emulation.
Definition KoSvgText.h:102
QString writeTextTransform(const TextTransformInfo textTransform)
QString writeDirection(Direction value)
QString writeWhiteSpaceValue(TextSpaceCollapse collapseMethod, TextWrap wrapMethod, TextSpaceTrims trimMethod)
wrap(obj, force=False)
Definition mikro.py:126
When style is oblique, a custom slant value can be specified for variable fonts.
Definition KoSvgText.h:475
The FontFeatureLigatures class This struct represents css font-variant-ligatures.
Definition KoSvgText.h:847
The FontFeatureLigatures class This struct represents css font-variant-numeric.
Definition KoSvgText.h:935
TextDecorationUnderlinePosition verticalPosition
Definition KoSvgText.h:1070
TextDecorationUnderlinePosition horizontalPosition
Definition KoSvgText.h:1069

References AlignmentBaselineId, BaselineShiftModeId, BaselineShiftValueId, KoSvgText::AutoValue::customValue, Direction, DirectionId, DominantBaselineId, FontFamiliesId, FontFeatureSettingsId, FontOpticalSizingId, fontSize(), FontSizeAdjustId, FontSizeId, FontStretchId, KoSvgText::fontStretchNames, FontStyleId, FontSynthesisBoldId, FontSynthesisItalicId, FontSynthesisSmallCapsId, FontSynthesisSuperSubId, FontVariantCapsId, FontVariantEastAsianId, FontVariantLigatureId, FontVariantNumericId, FontVariantPositionId, FontVariationSettingsId, FontWeightId, HangingPunctuationId, hasProperty(), KoSvgText::TextUnderlinePosition::horizontalPosition, KoSvgText::AutoValue::isAuto, KerningId, KIS_ASSERT, LetterSpacingId, LineBreakId, LineHeightId, OverflowWrapId, KoSvgText::PreserveSpaces, property(), propertyOrDefault(), TabSizeId, TextAnchorId, TextCollapseId, TextDecorationColorId, TextDecorationLineId, TextDecorationPositionId, TextDecorationStyleId, TextLanguage, TextOrientationId, TextOverFlowId, TextRenderingId, TextTransformId, TextTrimId, TextWrapId, KisDomUtils::toString(), UnicodeBidiId, value(), KoSvgText::TextUnderlinePosition::verticalPosition, WordBreakId, WordSpacingId, KoSvgText::writeFontStyle(), KoSvgText::writeLineHeight(), KoSvgText::writeTextRendering(), and WritingModeId.

◆ cssFontInfo()

KoCSSFontInfo KoSvgTextProperties::cssFontInfo ( ) const

cssFontInfo

Returns
this collects all the CSS Font properties into a KoCSSFontInfo struct for usage with the KoFontRegistry.

Definition at line 1167 of file KoSvgTextProperties.cpp.

1168{
1169 KoCSSFontInfo info;
1170 info.weight = propertyOrDefault(FontWeightId).toInt();
1171 info.width = propertyOrDefault(FontStretchId).toInt();
1174 info.families = propertyOrDefault(FontFamiliesId).toStringList();
1176 if (property(KraTextVersionId).toInt() >= 3) {
1177 info.fontSizeAdjust = fontSizeAdjust.isAuto? 0.0: fontSizeAdjust.customValue;
1178 }
1179
1181 info.slantMode = style.style;
1182 info.autoSlant = style.slantValue.isAuto;
1183 info.slantValue = style.slantValue.customValue;
1184
1185 QVariantMap features = property(FontVariationSettingsId).toMap();
1186 for (auto it = features.begin(); it != features.end(); it++) {
1187 info.axisSettings.insert(it.key(), it.value().toDouble());
1188 }
1189
1190 return info;
1191}
The KoCSSFontInfo class Convenience struct to make it easier to use KoFontRegistry....
QStringList families
double fontSizeAdjust
bool automaticOpticalSizing
< Size in Pt.
QMap< QString, double > axisSettings
QFont::Style slantMode
KoSvgText::AutoValue slantValue
Definition KoSvgText.h:479

References KoCSSFontInfo::automaticOpticalSizing, KoCSSFontInfo::autoSlant, KoCSSFontInfo::axisSettings, KoSvgText::AutoValue::customValue, KoCSSFontInfo::families, FontFamiliesId, FontOpticalSizingId, KoCSSFontInfo::fontSizeAdjust, FontSizeAdjustId, FontSizeId, FontStretchId, FontStyleId, FontVariationSettingsId, FontWeightId, KoSvgText::AutoValue::isAuto, KraTextVersionId, property(), propertyOrDefault(), KoCSSFontInfo::size, KoCSSFontInfo::slantMode, KoCSSFontInfo::slantValue, KoSvgText::CssFontStyleData::slantValue, KoSvgText::CssFontStyleData::style, value(), KoCSSFontInfo::weight, and KoCSSFontInfo::width.

◆ defaultProperties()

const KoSvgTextProperties & KoSvgTextProperties::defaultProperties ( )
static

Return a static object that defines default values for all the supported properties according to SVG

Definition at line 1238 of file KoSvgTextProperties.cpp.

1239{
1240 if (!s_defaultProperties.exists()) {
1241 using namespace KoSvgText;
1242
1243 s_defaultProperties->setProperty(WritingModeId, HorizontalTB);
1244 s_defaultProperties->setProperty(DirectionId, DirectionLeftToRight);
1245 s_defaultProperties->setProperty(UnicodeBidiId, BidiNormal);
1246 s_defaultProperties->setProperty(TextAnchorId, AnchorStart);
1247 s_defaultProperties->setProperty(DominantBaselineId, BaselineAuto);
1248 s_defaultProperties->setProperty(AlignmentBaselineId, BaselineDominant);
1249 s_defaultProperties->setProperty(BaselineShiftModeId, ShiftNone);
1250 s_defaultProperties->setProperty(BaselineShiftValueId, QVariant::fromValue(KoSvgText::CssLengthPercentage()));
1251 s_defaultProperties->setProperty(KerningId, fromAutoValue(AutoValue()));
1252 s_defaultProperties->setProperty(TextOrientationId, OrientationMixed);
1253 s_defaultProperties->setProperty(LetterSpacingId, QVariant::fromValue(AutoLengthPercentage()));
1254 s_defaultProperties->setProperty(WordSpacingId, QVariant::fromValue(AutoLengthPercentage()));
1255
1256 s_defaultProperties->setProperty(FontFamiliesId, QStringLiteral("sans-serif"));
1257 s_defaultProperties->setProperty(FontStyleId, QVariant::fromValue(KoSvgText::CssFontStyleData()));
1258 s_defaultProperties->setProperty(FontStretchId, 100);
1259 s_defaultProperties->setProperty(FontWeightId, 400);
1260 s_defaultProperties->setProperty(FontSizeId, QVariant::fromValue(KoSvgText::CssLengthPercentage(12.0)));
1261 s_defaultProperties->setProperty(FontSizeAdjustId, fromAutoValue(AutoValue()));
1262
1263 s_defaultProperties->setProperty(FontSynthesisBoldId, true);
1264 s_defaultProperties->setProperty(FontSynthesisItalicId, true);
1265 s_defaultProperties->setProperty(FontSynthesisSmallCapsId, true);
1266 s_defaultProperties->setProperty(FontSynthesisSuperSubId, true);
1267
1268 s_defaultProperties->setProperty(FontOpticalSizingId, true);
1269 s_defaultProperties->setProperty(TextRenderingId, RenderingAuto);
1270 {
1271 using namespace KoSvgText;
1272 TextDecorations deco = DecorationNone;
1273
1274 s_defaultProperties->setProperty(TextDecorationLineId, QVariant::fromValue(deco));
1275 s_defaultProperties->setProperty(TextDecorationPositionId, QVariant::fromValue(KoSvgText::TextUnderlinePosition()));
1276 s_defaultProperties->setProperty(TextDecorationColorId, QVariant::fromValue(Qt::transparent));
1277 s_defaultProperties->setProperty(TextDecorationStyleId, Solid);
1278
1279 s_defaultProperties->setProperty(TextCollapseId, Collapse);
1280 s_defaultProperties->setProperty(TextWrapId, Wrap);
1281 TextSpaceTrims trim = TrimNone;
1282 s_defaultProperties->setProperty(TextTrimId, QVariant::fromValue(trim));
1283 s_defaultProperties->setProperty(LineBreakId, LineBreakAuto);
1284 s_defaultProperties->setProperty(WordBreakId, WordBreakNormal);
1285 s_defaultProperties->setProperty(TextAlignAllId, AlignStart);
1286 s_defaultProperties->setProperty(TextAlignLastId, AlignLastAuto);
1287 s_defaultProperties->setProperty(TextTransformId, TextTransformNone);
1288 s_defaultProperties->setProperty(LineHeightId, QVariant::fromValue(KoSvgText::LineHeightInfo()));
1289 s_defaultProperties->setProperty(TabSizeId, QVariant::fromValue(KoSvgText::TabSizeInfo()));
1290 HangingPunctuations hang = HangNone;
1291 s_defaultProperties->setProperty(HangingPunctuationId, QVariant::fromValue(hang));
1292 }
1293 }
1294 return *s_defaultProperties;
1295}
@ Collapse
Collapse if first or last in line.
@ DecorationNone
Definition KoSvgText.h:258
QVariant fromAutoValue(const KoSvgText::AutoValue &value)
Definition KoSvgText.h:493
@ TrimNone
No trimming.
Definition KoSvgText.h:124
@ HangNone
Hang nothing.
Definition KoSvgText.h:205

References AlignmentBaselineId, BaselineShiftModeId, BaselineShiftValueId, Collapse, DirectionId, DominantBaselineId, FontFamiliesId, FontOpticalSizingId, FontSizeAdjustId, FontSizeId, FontStretchId, FontStyleId, FontSynthesisBoldId, FontSynthesisItalicId, FontSynthesisSmallCapsId, FontSynthesisSuperSubId, FontWeightId, HangingPunctuationId, KerningId, LetterSpacingId, LineBreakId, LineHeightId, TabSizeId, TextAlignAllId, TextAlignLastId, TextAnchorId, TextCollapseId, TextDecorationColorId, TextDecorationLineId, TextDecorationPositionId, TextDecorationStyleId, TextOrientationId, TextRenderingId, TextTransformId, TextTrimId, TextWrapId, UnicodeBidiId, WordBreakId, WordSpacingId, and WritingModeId.

◆ fontFeaturesForText()

QStringList KoSvgTextProperties::fontFeaturesForText ( int start,
int length ) const

fontFeaturesForText Returns a harfbuzz friendly list of opentype font-feature settings using the various font-variant and font-feature-settings values.

Parameters
startthe start pos of the text.
lengththe length of the text.
Returns
a list of strings for font-features and their ranges that can be understood by harfbuzz.

Definition at line 1128 of file KoSvgTextProperties.cpp.

1129{
1130 using namespace KoSvgText;
1131 QStringList fontFeatures;
1132
1134 fontFeatures.append(liga.fontFeatures(start, start+length));
1136 fontFeatures.append(KoSvgText::fontFeaturesPosition(pos, start, start+length));
1138 fontFeatures.append(KoSvgText::fontFeaturesCaps(caps, start, start+length));
1140 fontFeatures.append(numeric.fontFeatures(start, start+length));
1142 fontFeatures.append(eastasian.fontFeatures(start, start+length));
1143
1144 if (!property(KerningId).value<AutoValue>().isAuto && property(KerningId).value<AutoValue>().customValue == 0) {
1145 QString openTypeTag = "kern";
1146 openTypeTag += QString("[%1:%2]").arg(start).arg(start + length);
1147 openTypeTag += "=0";
1148 fontFeatures.append(openTypeTag);
1149 openTypeTag = "vkrn";
1150 openTypeTag += QString("[%1:%2]").arg(start).arg(start + length);
1151 openTypeTag += "=0";
1152 fontFeatures.append(openTypeTag);
1153 }
1154
1156 QVariantMap features = property(FontFeatureSettingsId).toMap();
1157 for (int i = 0; i < features.keys().size(); i++) {
1158 const QString key = features.keys().at(i);
1159 QString openTypeTag = QString("%1[%2:%3]=%4").arg(key).arg(start).arg(start + length).arg(features.value(key).toInt());
1160 fontFeatures.append(openTypeTag);
1161 }
1162 }
1163
1164 return fontFeatures;
1165}
qreal length(const QPointF &vec)
Definition Ellipse.cc:82
int size(const Forest< T > &forest)
Definition KisForest.h:1232
QStringList fontFeaturesPosition(const FontFeaturePosition &feature, const int start, const int end)
QStringList fontFeaturesCaps(const FontFeatureCaps &feature, const int start, const int end)
QStringList fontFeatures(const int start, const int end)
Definition KoSvgText.h:1023
QStringList fontFeatures(const int start, const int end)
Definition KoSvgText.h:860
QStringList fontFeatures(const int start, const int end)
Definition KoSvgText.h:951

References KoSvgText::FontFeatureLigatures::fontFeatures(), KoSvgText::FontFeatureNumeric::fontFeatures(), KoSvgText::FontFeatureEastAsian::fontFeatures(), KoSvgText::fontFeaturesCaps(), FontFeatureSettingsId, KoSvgText::fontFeaturesPosition(), FontVariantCapsId, FontVariantEastAsianId, FontVariantLigatureId, FontVariantNumericId, FontVariantPositionId, hasProperty(), KerningId, length(), and property().

◆ fontSize()

KoSvgText::CssLengthPercentage KoSvgTextProperties::fontSize ( ) const

◆ generateFont()

QFont KoSvgTextProperties::generateFont ( ) const

The constructor of QFont cannot accept fractional font size, so we pass a rounded one to it and set the correct one later on

Definition at line 1022 of file KoSvgTextProperties.cpp.

1023{
1024 QString fontFamily;
1025
1026 QStringList familiesList =
1028 if (!familiesList.isEmpty()) {
1029 fontFamily = familiesList.first();
1030 }
1031 const QFont::Style style =
1033
1035
1036 // for rounding see a comment below!
1037 QFont font(fontFamily
1038 , qMax(qRound(fontSize.value), 1)
1040 , style != QFont::StyleNormal);
1041 font.setStyle(style);
1042
1047 font.setPointSizeF(fontSize.value);
1048
1050
1051 using namespace KoSvgText;
1052
1053 TextDecorations deco = propertyOrDefault(KoSvgTextProperties::TextDecorationLineId).value<KoSvgText::TextDecorations>();
1054
1055 font.setStrikeOut(deco & DecorationLineThrough);
1056 font.setUnderline(deco & DecorationUnderline);
1057 font.setOverline(deco & DecorationOverline);
1058
1059 struct FakePaintDevice : public QPaintDevice
1060 {
1061 QPaintEngine *paintEngine() const override {
1062 return nullptr;
1063 }
1064
1065 int metric(QPaintDevice::PaintDeviceMetric metric) const override {
1066
1067 if (metric == QPaintDevice::PdmDpiX || metric == QPaintDevice::PdmDpiY) {
1068 return 72;
1069 }
1070
1071
1072 return QPaintDevice::metric(metric);
1073 }
1074 };
1075
1076 // paint device is used only to initialize DPI, so
1077 // we can delete it right after creation of the font
1078 FakePaintDevice fake72DpiPaintDevice;
1079 return QFont(font, &fake72DpiPaintDevice);
1080}

References FontFamiliesId, fontSize(), FontStretchId, FontStyleId, FontWeightId, propertyOrDefault(), TextDecorationLineId, and KoSvgText::CssLengthPercentage::value.

◆ hasNonInheritableProperties()

bool KoSvgTextProperties::hasNonInheritableProperties ( ) const

Test whether it has non-inheritable properties set.

Definition at line 186 of file KoSvgTextProperties.cpp.

187{
188 for (auto it = m_d->properties.constBegin(); it != m_d->properties.constEnd(); ++it) {
189 if (!m_d->isInheritable(it.key())) {
190 return true;
191 }
192 }
193 return false;
194}

References m_d.

◆ hasProperty()

bool KoSvgTextProperties::hasProperty ( KoSvgTextProperties::PropertyId id) const

Check if property id is present in this properties set

Definition at line 64 of file KoSvgTextProperties.cpp.

65{
66 return m_d->properties.contains(id);
67}

References m_d.

◆ inheritFrom()

void KoSvgTextProperties::inheritFrom ( const KoSvgTextProperties & parentProperties,
bool resolve = false )

Apply properties from the parent shape. The property is set iff the property is inheritable according to SVG and this set does not define it.

Definition at line 114 of file KoSvgTextProperties.cpp.

115{
116 auto it = parentProperties.m_d->properties.constBegin();
117 for (; it != parentProperties.m_d->properties.constEnd(); ++it) {
118 if (!hasProperty(it.key()) && m_d->isInheritable(it.key())) {
119 setProperty(it.key(), it.value());
120 }
121 }
122
123 if (resolve) {
124 resolveRelativeValues(parentProperties.metrics(), parentProperties.fontSize().value);
125 }
126}
void resolveRelativeValues(const KoSvgText::FontMetrics metrics=KoSvgText::FontMetrics(12.0, true), const qreal fontSize=12.0)
resolveRelativeValues resolve the font-relative values.
void setProperty(PropertyId id, const QVariant &value)

References fontSize(), hasProperty(), m_d, metrics(), resolveRelativeValues(), setProperty(), and KoSvgText::CssLengthPercentage::value.

◆ inheritsProperty()

bool KoSvgTextProperties::inheritsProperty ( KoSvgTextProperties::PropertyId id,
const KoSvgTextProperties & parentProperties ) const

Return true if the property id is inherited from parentProperties. The property is considered "inherited" **iff* it is inheritable according to SVG and the parent defined the same property with the same value.

Definition at line 181 of file KoSvgTextProperties.cpp.

182{
183 return !hasProperty(id) || parentProperties.property(id) == property(id);
184}

References hasProperty(), and property().

◆ isEmpty()

bool KoSvgTextProperties::isEmpty ( ) const

Return true if the set contains no properties

Definition at line 93 of file KoSvgTextProperties.cpp.

94{
95 return m_d->properties.isEmpty();
96}

References m_d.

◆ metrics()

KoSvgText::FontMetrics KoSvgTextProperties::metrics ( const bool withResolvedLineHeight = true,
const bool offsetByBaseline = false ) const

metrics Return the metrics of the first available font.

Parameters
withResolvedLineHeight– apply the lineheight into the linegap property.
offsetByBaseline– ensure the metrics are offset by the dominant baseline.
Returns
metrics for the current font.

Definition at line 1093 of file KoSvgTextProperties.cpp.

1094{
1095 const KoCSSFontInfo info = cssFontInfo();
1096
1097 const bool isHorizontal = propertyOrDefault(WritingModeId).toInt() == KoSvgText::HorizontalTB;
1100
1101 if (offsetByBaseline) {
1103 if (baseline == KoSvgText::BaselineAuto || baseline == KoSvgText::BaselineNoChange || baseline == KoSvgText::BaselineResetSize || baseline == KoSvgText::BaselineUseScript) {
1105 }
1107 }
1108
1109 return withResolvedLineHeight? applyLineHeight(metrics): metrics;
1110}
KoSvgText::FontMetrics fontMetricsForCSSValues(KoCSSFontInfo info=KoCSSFontInfo(), const bool isHorizontal=true, const KoSvgText::TextRendering rendering=KoSvgText::RenderingAuto, const QString &text="", quint32 xRes=72, quint32 yRes=72, bool disableFontMatching=false, const QString &language=QString())
static KoFontRegistry * instance()
KoCSSFontInfo cssFontInfo() const
cssFontInfo
KoSvgText::FontMetrics applyLineHeight(KoSvgText::FontMetrics metrics) const
applyLineHeight Calculate the linegap for the current linegap property.
@ BaselineAlphabetic
Use 'romn' or the baseline for LCG scripts.
Definition KoSvgText.h:225
@ BaselineUseScript
Definition KoSvgText.h:216
@ BaselineResetSize
Definition KoSvgText.h:221
@ BaselineNoChange
Use parent baseline table.
Definition KoSvgText.h:220
@ BaselineCentral
Use the center between the ideographic over and under.
Definition KoSvgText.h:231
@ HorizontalTB
Definition KoSvgText.h:38
The FontMetrics class A class to keep track of a variety of font metrics. Note that values are in Fre...
Definition KoSvgText.h:327
void offsetMetricsToNewOrigin(const Baseline baseline)

References applyLineHeight(), KoSvgText::BaselineAlphabetic, KoSvgText::BaselineAuto, KoSvgText::BaselineCentral, KoSvgText::BaselineNoChange, KoSvgText::BaselineResetSize, KoSvgText::BaselineUseScript, cssFontInfo(), DominantBaselineId, KoFontRegistry::fontMetricsForCSSValues(), KoSvgText::HorizontalTB, KoFontRegistry::instance(), metrics(), KoSvgText::FontMetrics::offsetMetricsToNewOrigin(), propertyOrDefault(), TextRenderingId, and WritingModeId.

◆ operator=()

KoSvgTextProperties & KoSvgTextProperties::operator= ( const KoSvgTextProperties & rhs)

Definition at line 47 of file KoSvgTextProperties.cpp.

48{
49 if (&rhs != this) {
50 m_d->properties = rhs.m_d->properties;
51 }
52 return *this;
53}

References m_d, and properties().

◆ operator==()

bool KoSvgTextProperties::operator== ( const KoSvgTextProperties & rhs) const

Definition at line 55 of file KoSvgTextProperties.cpp.

55 {
56 return m_d->properties == rhs.m_d->properties;
57}

References m_d.

◆ ownProperties()

KoSvgTextProperties KoSvgTextProperties::ownProperties ( const KoSvgTextProperties & parentProperties,
bool keepFontSize = false ) const

Return a set of properties that ar not inherited from parentProperties. The property is considered "inherited" **iff* it is inheritable according to SVG and the parent defined the same property with the same value.

Parameters
keepFontSizewhether to keep the font size, use for root nodes so that it won't be omitted and inheriting from the "default", which may not be deterministic.

Definition at line 246 of file KoSvgTextProperties.cpp.

247{
248 KoSvgTextProperties result;
249
250 auto it = m_d->properties.constBegin();
251 for (; it != m_d->properties.constEnd(); ++it) {
252 if ((keepFontSize && it.key() == FontSizeId) || !parentProperties.hasProperty(it.key())
253 || parentProperties.property(it.key()) != it.value()) {
254 result.setProperty(it.key(), it.value());
255 }
256 }
257
258 return result;
259}
QList< PropertyId > properties() const

References FontSizeId, hasProperty(), m_d, properties(), property(), and setProperty().

◆ parseSvgTextAttribute()

void KoSvgTextProperties::parseSvgTextAttribute ( const SvgLoadingContext & context,
const QString & command,
const QString & value )

parseSvgTextAttribute add a property according to an XML attribute value.

Parameters
contextshared loading context
commandXML attribute name
valueattribute value
See also
supportedXmlAttributes for a list of supported attributes

Definition at line 321 of file KoSvgTextProperties.cpp.

322{
323 if (command == "writing-mode") {
325 } else if (command == "glyph-orientation-vertical") {
327 // glyph-orientation-vertical should only be converted for the 'auto', '0' and '90' cases,
328 // and treated as invalid otherwise.
329 QStringList acceptedOrientations;
330 acceptedOrientations << "auto"
331 << "0"
332 << "0deg"
333 << "90"
334 << "90deg";
335 if (acceptedOrientations.contains(value.toLower())) {
336 if (!autoValue.isAuto) {
338 }
340 setProperty(TextOrientationId, orientation);
341 }
342 } else if (command == "text-orientation") {
344 } else if (command == "direction") {
346 } else if (command == "unicode-bidi") {
348 } else if (command == "text-anchor") {
350 } else if (command == "dominant-baseline") {
352 } else if (command == "alignment-baseline") {
354 } else if (command == "baseline-shift") {
359 setProperty(BaselineShiftValueId, QVariant::fromValue(shift));
360 }
361 } else if (command == "vertical-align") {
362 QRegExp digits = QRegExp("\\d");
363 Q_FOREACH (const QString &param, value.split(' ', Qt::SkipEmptyParts)) {
364#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
365 bool paramContains = param.contains(digits);
366#else
367 bool paramContains = (digits.indexIn(param) > 0);
368#endif
369
370
371 if (param == "sub" || param == "super" || param == "top" || param == "bottom" || paramContains) {
372 parseSvgTextAttribute(context, "baseline-shift", param);
373 } else {
374 parseSvgTextAttribute(context, "alignment-baseline", param);
375 }
376 }
377 } else if (command == "kerning" || command == "font-kerning") {
378 KoSvgText::AutoValue kerning;
379 if (value == "none") {
380 kerning.isAuto = false;
381 kerning.customValue = 0;
382 } else if (value == "normal") {
383 kerning.isAuto = false;
384 kerning.customValue = 1;
385 } else {
386 kerning = KoSvgText::parseAutoValueXY(value, context);
387 }
389 } else if (command == "letter-spacing") {
390 setProperty(LetterSpacingId, QVariant::fromValue(KoSvgText::parseAutoLengthPercentageXY(value, context, "normal", context.currentGC()->currentBoundingBox, true)));
391 } else if (command == "word-spacing") {
392 setProperty(WordSpacingId, QVariant::fromValue(KoSvgText::parseAutoLengthPercentageXY(value, context, "normal", context.currentGC()->currentBoundingBox, true)));
393 } else if (command == "font-family") {
394 QStringList familiesList;
395 Q_FOREACH (const QString &fam, value.split(',', Qt::SkipEmptyParts)) {
396 QString family = fam.trimmed();
397 if ((family.startsWith('\"') && family.endsWith('\"')) ||
398 (family.startsWith('\'') && family.endsWith('\''))) {
399
400 family = family.mid(1, family.size() - 2);
401 }
402 familiesList.append(family);
403 }
404 setProperty(FontFamiliesId, familiesList);
405
406 } else if (command == "font-style") {
408 } else if (command == "font-variant" || command == "font-variant-ligatures" || command == "font-variant-position" || command == "font-variant-caps"
409 || command == "font-variant-numeric" || command == "font-variant-east-asian" || command == "font-variant-alternates") {
410 const QStringList features = value.split(" ");
411 Q_FOREACH (const QString f, features) {
412 bool commandFontVariant = (command == "font-variant");
413 if (commandFontVariant || command == "font-variant-ligatures") {
416 setProperty(FontVariantLigatureId, QVariant::fromValue(liga));
417 }
418 if (commandFontVariant || command == "font-variant-position") {
421 setProperty(FontVariantPositionId, QVariant::fromValue(pos));
422 }
423 if (commandFontVariant || command == "font-variant-caps") {
425 caps = KoSvgText::parseFontFeatureCaps(f, caps);
426 setProperty(FontVariantCapsId, QVariant::fromValue(caps));
427 }
428 if (commandFontVariant || command == "font-variant-numeric") {
431 setProperty(FontVariantNumericId, QVariant::fromValue(num));
432 }
433 if (commandFontVariant || command == "font-variant-east-asian") {
436 setProperty(FontVariantEastAsianId, QVariant::fromValue(ea));
437 }
438 }
439
440 } else if (command == "font-feature-settings") {
442 } else if (command == "font-stretch") {
443 int newStretch = 100;
444
446
447 setProperty(FontStretchId, newStretch);
448
449 } else if (command == "font-weight") {
451
452 setProperty(FontWeightId, weight);
453
454 } else if (command == "font-size") {
456 if (pointSize.value > 0.0) {
457 setProperty(FontSizeId, QVariant::fromValue(pointSize));
458 }
459 } else if (command == "font-size-adjust") {
461
462 } else if (command == "font-optical-sizing") {
464 } else if (command == "font-variation-settings") {
466 } else if (command == "text-decoration" || command == "text-decoration-line" || command == "text-decoration-style" || command == "text-decoration-color"
467 || command == "text-decoration-position") {
468 using namespace KoSvgText;
469
470 TextDecorations deco = propertyOrDefault(TextDecorationLineId).value<KoSvgText::TextDecorations>();
471 if (command == "text-decoration" || command == "text-decoration-line") {
472 // reset deco when those values are being set..
474 }
475
478 QColor textDecorationColor = propertyOrDefault(TextDecorationStyleId).value<QColor>();
479 bool setPosition = false;
480
481 Q_FOREACH (const QString &param, value.split(' ', Qt::SkipEmptyParts)) {
482 if (param == "line-through") {
483 deco |= DecorationLineThrough;
484 } else if (param == "underline") {
485 deco |= DecorationUnderline;
486 } else if (param == "overline") {
487 deco |= DecorationOverline;
488 } else if (param == "solid") {
489 style = Solid;
490 } else if (param == "double") {
491 style = Double;
492 } else if (param == "dotted") {
493 style = Dotted;
494 } else if (param == "dashed") {
495 style = Dashed;
496 } else if (param == "wavy") {
497 style = Wavy;
498 } else if (param == "auto") {
499 underlinePos.horizontalPosition = UnderlineAuto;
500 setPosition = true;
501 } else if (param == "under") {
502 underlinePos.horizontalPosition = UnderlineUnder;
503 setPosition = true;
504 } else if (param == "left") {
505 underlinePos.verticalPosition = UnderlineLeft;
506 setPosition = true;
507 } else if (param == "right") {
508 underlinePos.verticalPosition = UnderlineRight;
509 setPosition = true;
510 } else if (QColor::isValidColor(param)) {
511 // TODO: Convert to KoColor::fromSvg11.
512 textDecorationColor = QColor(param);
513 }
514 }
515
516 if (command == "text-decoration" || command == "text-decoration-line") {
517 setProperty(TextDecorationLineId, QVariant::fromValue(deco));
518 }
519 if (command == "text-decoration" || command == "text-decoration-style") {
521 }
522 if (command == "text-decoration" || command == "text-decoration-color") {
523 setProperty(TextDecorationColorId, QVariant::fromValue(textDecorationColor));
524 }
525 if ((command == "text-decoration" || command == "text-decoration-position") && setPosition) {
526 setProperty(TextDecorationPositionId, QVariant::fromValue(underlinePos));
527 }
528
529 } else if (command == "xml:lang") {
531 } else if (command == "text-transform") {
533 } else if (command == "white-space") {
534 KoSvgText::TextSpaceTrims trims = propertyOrDefault(TextTrimId).value<KoSvgText::TextSpaceTrims>();
537
538 KoSvgText::whiteSpaceValueToLongHands(value, collapse, wrap, trims);
539
540 setProperty(TextTrimId, QVariant::fromValue(trims));
541 setProperty(TextWrapId, wrap);
542 setProperty(TextCollapseId, collapse);
543
544 } else if (command == "xml:space") {
547 setProperty(TextCollapseId, collapse);
548 } else if (command == "word-break") {
550 } else if (command == "line-break") {
552 } else if (command == "text-align" || command == "text-align-all" || command == "text-align-last") {
553 QStringList params = value.split(' ', Qt::SkipEmptyParts);
554 if (command == "text-align" || command == "text-align-all") {
556 if (value == "justify-all") {
558 }
559 }
560 if (command == "text-align" && params.size() > 1) {
562 }
563 if (command == "text-align-last") {
565 }
566 } else if (command == "line-height") {
567 setProperty(LineHeightId, QVariant::fromValue(KoSvgText::parseLineHeight(value, context)));
568 } else if (command == "text-indent") {
569 setProperty(TextIndentId, QVariant::fromValue(KoSvgText::parseTextIndent(value, context)));
570 } else if (command == "hanging-punctuation") {
571 KoSvgText::HangingPunctuations hang;
572 Q_FOREACH (const QString &param, value.split(' ', Qt::SkipEmptyParts)) {
573 if (param == "first") {
574 hang.setFlag(KoSvgText::HangFirst, true);
575 } else if (param == "last") {
576 hang.setFlag(KoSvgText::HangLast, true);
577 } else if (param == "allow-end") {
578 hang.setFlag(KoSvgText::HangEnd, true);
579 hang.setFlag(KoSvgText::HangForce, false);
580 } else if (param == "force-end") {
581 hang.setFlag(KoSvgText::HangEnd, true);
582 hang.setFlag(KoSvgText::HangForce, true);
583 }
584 }
585 setProperty(HangingPunctuationId, QVariant::fromValue(hang));
586 } else if (command == "inline-size") {
588 } else if (command == "overflow") {
590 } else if (command == "text-overflow") {
592 } else if (command == "overflow-wrap" || command == "word-wrap") {
595 : value == "anywhere" ? KoSvgText::OverflowWrapAnywhere
597 } else if (command == "tab-size") {
598 setProperty(TabSizeId, QVariant::fromValue(KoSvgText::parseTabSize(value, context)));
599 } else if (command == "shape-padding") {
601 setProperty(ShapePaddingId, QVariant::fromValue(size));
602 } else if (command == "shape-margin") {
604 setProperty(ShapeMarginId, QVariant::fromValue(size));
605 } else if (command == "font-synthesis") {
610 if (value != "none") {
611 QStringList params = value.split(" ");
612 if (params.contains("position")) {
614 }
615 if (params.contains("weight")) {
617 }
618 if (params.contains("style")) {
620 }
621 if (params.contains("small-caps")) {
623 }
624 }
625 } else if (command == "font-synthesis-weight") {
627 } else if (command == "font-synthesis-style") {
629 } else if (command == "font-synthesis-small-caps") {
631 } else if (command == "font-synthesis-position") {
633 } else if (command == "text-rendering") {
635 } else {
636 qFatal("FATAL: Unknown SVG property: %s = %s", command.toUtf8().data(), value.toUtf8().data());
637 }
638}
qreal roundToStraightAngle(qreal value)
QVariantMap parseFeatureSettingsStringList(const QStringList features)
QVariantMap parseVariantStringList(const QStringList features)
void parseSvgTextAttribute(const SvgLoadingContext &context, const QString &command, const QString &value)
parseSvgTextAttribute add a property according to an XML attribute value.
QRectF currentBoundingBox
the current bound box used for bounding box units
SvgGraphicsContext * currentGC() const
Returns the current graphics context.
KoSvgTextProperties resolvedProperties() const
These are the text properties, completely resolved, ensuring that everything is inherited and the siz...
static KoSvgText::CssLengthPercentage parseTextUnitStruct(SvgGraphicsContext *gc, QStringView unit)
Unit structs for text do not need the percentage to be resolved to viewport in most cases.
Definition SvgUtil.cpp:239
T kisRadiansToDegrees(T radians)
Definition kis_global.h:181
@ Solid
Definition KoFlake.h:35
BaselineShiftMode parseBaselineShiftMode(const QString &value)
@ ShiftLengthPercentage
Css Length Percentage, percentage is lh.
Definition KoSvgText.h:244
bool xmlSpaceToLongHands(const QString &value, TextSpaceCollapse &collapseMethod)
xmlSpaceToLongHands This takes xml:space values and converts them to CSS-Text-4 properties.
AutoValue parseAutoValueY(const QString &value, const SvgLoadingContext &context, const QString &autoKeyword)
TabSizeInfo parseTabSize(const QString &value, const SvgLoadingContext &context)
Baseline parseBaseline(const QString &value)
@ Dashed
Draw a dashed line. Ex: - - - - -.
Definition KoSvgText.h:269
@ Double
Draw two lines. Ex: =====.
Definition KoSvgText.h:267
@ Wavy
Draw a wavy line. We currently make a zigzag, ex: ^^^^^.
Definition KoSvgText.h:270
@ Dotted
Draw a dotted line. Ex: .....
Definition KoSvgText.h:268
FontFeatureEastAsian parseFontFeatureEastAsian(const QString &value, FontFeatureEastAsian features)
TextAnchor parseTextAnchor(const QString &value)
@ OverflowWrapBreakWord
Definition KoSvgText.h:155
@ OverflowWrapNormal
Definition KoSvgText.h:152
@ OverflowWrapAnywhere
Break anywhere as soon as overflow happens.
Definition KoSvgText.h:154
TextOrientation parseTextOrientation(const QString &value)
@ UnderlineLeft
Definition KoSvgText.h:278
@ UnderlineRight
Definition KoSvgText.h:280
@ UnderlineUnder
Use the bottom of the text decoration bounding box.
Definition KoSvgText.h:277
@ UnderlineAuto
Use Font metrics.
Definition KoSvgText.h:276
UnicodeBidi parseUnicodeBidi(const QString &value)
WritingMode parseWritingMode(const QString &value)
@ DecorationOverline
Definition KoSvgText.h:260
@ DecorationLineThrough
Definition KoSvgText.h:261
@ DecorationUnderline
Definition KoSvgText.h:259
bool whiteSpaceValueToLongHands(const QString &value, TextSpaceCollapse &collapseMethod, TextWrap &wrapMethod, TextSpaceTrims &trimMethod)
whiteSpaceValueToLongHands CSS-Text-4 takes CSS-Text-3 whitespace values and treats them as a shortha...
CssFontStyleData parseFontStyle(const QString &value)
TextRendering parseTextRendering(const QString &value)
AutoValue parseAutoValueAngular(const QString &value, const SvgLoadingContext &context, const QString &autoKeyword)
@ OverFlowVisible
Definition KoSvgText.h:194
@ OverFlowEllipse
Replace the last characters with "U+2026".
Definition KoSvgText.h:198
@ OverFlowClip
Clip the rendered content.
Definition KoSvgText.h:197
TextIndentInfo parseTextIndent(const QString &value, const SvgLoadingContext &context)
TextAlign parseTextAlign(const QString &value)
Direction parseDirection(const QString &value)
LineHeightInfo parseLineHeight(const QString &value, const SvgLoadingContext &context)
AutoValue parseAutoValueXY(const QString &value, const SvgLoadingContext &context, const QString &autoKeyword)
FontFeaturePosition parseFontFeaturePosition(const QString &value, FontFeaturePosition feature)
LineBreak parseLineBreak(const QString &value)
int parseCSSFontWeight(const QString &value, int currentWeight)
TextOrientation parseTextOrientationFromGlyphOrientation(AutoValue value)
AutoLengthPercentage parseAutoLengthPercentageXY(const QString &value, const SvgLoadingContext &context, const QString &autoKeyword, QRectF bbox, bool percentageIsViewPort)
FontFeatureCaps parseFontFeatureCaps(const QString &value, FontFeatureCaps feature)
FontFeatureLigatures parseFontFeatureLigatures(const QString &value, FontFeatureLigatures features)
int parseCSSFontStretch(const QString &value, int currentStretch)
parseCSSFontStretch For CSS3, the font-stretches were only given as keywords. In Css 4 and above,...
TextTransformInfo parseTextTransform(const QString &value)
@ HangForce
Whether to force hanging stops or commas.
Definition KoSvgText.h:209
@ HangLast
Hang closing brackets and quotes.
Definition KoSvgText.h:207
@ HangFirst
Hang opening brackets and quotes.
Definition KoSvgText.h:206
@ HangEnd
Hang stops and commas. Force/Allow is a separate boolean.
Definition KoSvgText.h:208
WordBreak parseWordBreak(const QString &value)
FontFeatureNumeric parseFontFeatureNumeric(const QString &value, FontFeatureNumeric features)

References AlignmentBaselineId, BaselineShiftModeId, BaselineShiftValueId, SvgGraphicsContext::currentBoundingBox, SvgLoadingContext::currentGC(), KoSvgText::AutoValue::customValue, KoSvgText::DecorationNone, DirectionId, DominantBaselineId, FontFamiliesId, FontFeatureSettingsId, FontOpticalSizingId, FontSizeAdjustId, FontSizeId, FontStretchId, FontStyleId, FontSynthesisBoldId, FontSynthesisItalicId, FontSynthesisSmallCapsId, FontSynthesisSuperSubId, FontVariantCapsId, FontVariantEastAsianId, FontVariantLigatureId, FontVariantNumericId, FontVariantPositionId, FontVariationSettingsId, FontWeightId, KoSvgText::fromAutoValue(), KoSvgText::HangEnd, KoSvgText::HangFirst, KoSvgText::HangForce, HangingPunctuationId, KoSvgText::HangLast, KoSvgText::TextUnderlinePosition::horizontalPosition, InlineSizeId, KoSvgText::AutoValue::isAuto, KerningId, kisRadiansToDegrees(), LetterSpacingId, LineBreakId, LineHeightId, KoSvgText::OverFlowClip, KoSvgText::OverFlowEllipse, KoSvgText::OverFlowVisible, KoSvgText::OverflowWrapAnywhere, KoSvgText::OverflowWrapBreakWord, OverflowWrapId, KoSvgText::OverflowWrapNormal, KoSvgText::parseAutoLengthPercentageXY(), KoSvgText::parseAutoValueAngular(), KoSvgText::parseAutoValueXY(), KoSvgText::parseAutoValueY(), KoSvgText::parseBaseline(), KoSvgText::parseBaselineShiftMode(), KoSvgText::parseCSSFontStretch(), KoSvgText::parseCSSFontWeight(), KoSvgText::parseDirection(), parseFeatureSettingsStringList(), KoSvgText::parseFontFeatureCaps(), KoSvgText::parseFontFeatureEastAsian(), KoSvgText::parseFontFeatureLigatures(), KoSvgText::parseFontFeatureNumeric(), KoSvgText::parseFontFeaturePosition(), KoSvgText::parseFontStyle(), KoSvgText::parseLineBreak(), KoSvgText::parseLineHeight(), parseSvgTextAttribute(), KoSvgText::parseTabSize(), KoSvgText::parseTextAlign(), KoSvgText::parseTextAnchor(), KoSvgText::parseTextIndent(), KoSvgText::parseTextOrientation(), KoSvgText::parseTextOrientationFromGlyphOrientation(), KoSvgText::parseTextRendering(), KoSvgText::parseTextTransform(), SvgUtil::parseTextUnitStruct(), KoSvgText::parseUnicodeBidi(), parseVariantStringList(), KoSvgText::parseWordBreak(), KoSvgText::parseWritingMode(), property(), propertyOrDefault(), SvgLoadingContext::resolvedProperties(), roundToStraightAngle(), setProperty(), ShapeMarginId, ShapePaddingId, KoSvgText::ShiftLengthPercentage, TabSizeId, TextAlignAllId, TextAlignLastId, TextAnchorId, TextCollapseId, TextDecorationColorId, TextDecorationLineId, TextDecorationPositionId, TextDecorationStyleId, TextIndentId, TextLanguage, TextOrientationId, TextOverFlowId, TextRenderingId, TextTransformId, TextTrimId, TextWrapId, UnicodeBidiId, KoSvgText::CssLengthPercentage::value, value(), KoSvgText::TextUnderlinePosition::verticalPosition, KoSvgText::whiteSpaceValueToLongHands(), WordBreakId, WordSpacingId, WritingModeId, and KoSvgText::xmlSpaceToLongHands().

◆ properties()

QList< KoSvgTextProperties::PropertyId > KoSvgTextProperties::properties ( ) const

Return a list of properties contained in this set

Definition at line 88 of file KoSvgTextProperties.cpp.

89{
90 return m_d->properties.keys();
91}

References m_d.

◆ property()

QVariant KoSvgTextProperties::property ( KoSvgTextProperties::PropertyId id,
const QVariant & defaultValue = QVariant() ) const

Return the value of property id. If the property doesn't exist in the shape, return defaultValue instead.

Definition at line 69 of file KoSvgTextProperties.cpp.

70{
71 return m_d->properties.value(id, defaultValue);
72}

References m_d.

◆ propertyIsBlockOnly()

bool KoSvgTextProperties::propertyIsBlockOnly ( KoSvgTextProperties::PropertyId id)
static

Returns whether the property only applies to paragraphs (what CSS calls blocks). Within SVG, all paragraphs are blocks and all text inside is inline. There are some potential caveats to this (text-combine-upright, ruby), but those are also unique in other ways.

Definition at line 1297 of file KoSvgTextProperties.cpp.

1298{
1299 return id == WritingModeId ||
1300 id == TextAlignAllId ||
1301 id == TextAlignLastId ||
1302 id == TextIndentId ||
1303 id == HangingPunctuationId ||
1304 id == TextRenderingId;
1305}

References HangingPunctuationId, TextAlignAllId, TextAlignLastId, TextIndentId, TextRenderingId, and WritingModeId.

◆ propertyIsInheritable()

bool KoSvgTextProperties::propertyIsInheritable ( KoSvgTextProperties::PropertyId id) const

returns whether a property can be inherited.

Definition at line 1307 of file KoSvgTextProperties.cpp.

1308{
1309 return m_d->isInheritable(id);
1310}

References m_d.

◆ propertyOrDefault()

QVariant KoSvgTextProperties::propertyOrDefault ( KoSvgTextProperties::PropertyId id) const

Return the value of property id. If the property doesn't exist in the shape, return the default value define in SVG 1.1.

Definition at line 79 of file KoSvgTextProperties.cpp.

80{
81 QVariant value = m_d->properties.value(id);
82 if (value.isNull()) {
84 }
85 return value;
86}
static const KoSvgTextProperties & defaultProperties()

References defaultProperties(), m_d, property(), and value().

◆ removeProperty()

void KoSvgTextProperties::removeProperty ( KoSvgTextProperties::PropertyId id)

Remove property id from the set

Definition at line 74 of file KoSvgTextProperties.cpp.

75{
76 m_d->properties.remove(id);
77}

References m_d.

◆ resetNonInheritableToDefault()

void KoSvgTextProperties::resetNonInheritableToDefault ( )

Reset all non-inheritable properties to default values. The set of non-inheritable properties is define by SVG 1.1. Used by the loading code for resetting state automata's properties on entering a <tspan>.

Definition at line 104 of file KoSvgTextProperties.cpp.

105{
106 auto it = m_d->properties.begin();
107 for (; it != m_d->properties.end(); ++it) {
108 if (!m_d->isInheritable(it.key())) {
109 it.value() = defaultProperties().property(it.key());
110 }
111 }
112}

References defaultProperties(), m_d, and property().

◆ resolveRelativeValues()

void KoSvgTextProperties::resolveRelativeValues ( const KoSvgText::FontMetrics metrics = KoSvgText::FontMetrics(12.0, true),
const qreal fontSize = 12.0 )

resolveRelativeValues resolve the font-relative values.

Parameters
fontSize– fontsize to resolve 'em' to.
xHeight– xHeight to resolve 'ex' to.

Definition at line 128 of file KoSvgTextProperties.cpp.

129{
130 // First resolve 'font-*' properties.
131 // See https://www.w3.org/TR/css-values-4/#font-relative-lengths
134 this->setFontSize(size);
135 const qreal usedSize = size.value;
137 if (!lineHeight.isNormal && !lineHeight.isNumber) {
140 } else {
141 lineHeight.length.convertToAbsolute(this->metrics(false), usedSize);
142 }
143 setProperty(LineHeightId, QVariant::fromValue(lineHeight));
144 }
145
146 const KoSvgText::FontMetrics usedMetrics = this->metrics();
147
148 for (auto it = this->m_d->properties.begin(); it != this->m_d->properties.end(); it++) {
149
152
153 if (it.key() == LineHeightId) continue;
154 if (it.value().canConvert<KoSvgText::CssLengthPercentage>() && it.key() != KoSvgTextProperties::FontSizeId) {
156 length.convertToAbsolute(usedMetrics, usedSize, percentageUnit);
157 it.value() = QVariant::fromValue(length);
158 } else if (it.value().canConvert<KoSvgText::AutoLengthPercentage>()) {
160
161 if (!val.isAuto) {
162 val.length.convertToAbsolute(usedMetrics, usedSize, percentageUnit);
163 it.value() = QVariant::fromValue(val);
164 }
165 } else if (it.key() == KoSvgTextProperties::TabSizeId) {
167 if (!tabSize.isNumber) {
168 tabSize.length.convertToAbsolute(usedMetrics, usedSize);
169 it.value() = QVariant::fromValue(tabSize);
170 }
171 } else if (it.key() == KoSvgTextProperties::TextIndentId) {
172 KoSvgText::TextIndentInfo indent = it.value().value<KoSvgText::TextIndentInfo>();
174 indent.length.convertToAbsolute(usedMetrics, usedSize);
175 }
176 it.value() = QVariant::fromValue(indent);
177 }
178 }
179}
void setFontSize(const KoSvgText::CssLengthPercentage length)
CssLengthPercentage length
Definition KoSvgText.h:466
@ Lh
multiply by width of "U+6C34", represents average full width script advance.
Definition KoSvgText.h:415
void convertToAbsolute(const KoSvgText::FontMetrics metrics, const qreal fontSize, const UnitType percentageUnit=Em)
qreal value
A length or a number. Length is currently marked 'at-risk'.
Definition KoSvgText.h:675
CssLengthPercentage length
Definition KoSvgText.h:678
CssLengthPercentage length
Definition KoSvgText.h:658

References BaselineShiftValueId, KoSvgText::CssLengthPercentage::convertToAbsolute(), KoSvgText::CssLengthPercentage::Em, fontSize(), FontSizeId, KoSvgText::AutoLengthPercentage::isAuto, KoSvgText::LineHeightInfo::isNormal, KoSvgText::TabSizeInfo::isNumber, KoSvgText::LineHeightInfo::isNumber, KoSvgText::AutoLengthPercentage::length, KoSvgText::TextIndentInfo::length, KoSvgText::TabSizeInfo::length, KoSvgText::LineHeightInfo::length, length(), KoSvgText::CssLengthPercentage::Lh, LineHeightId, m_d, metrics(), KoSvgText::CssLengthPercentage::Percentage, propertyOrDefault(), setFontSize(), setProperty(), TabSizeId, TextIndentId, KoSvgText::CssLengthPercentage::unit, KoSvgText::CssLengthPercentage::value, and KoSvgText::TabSizeInfo::value.

◆ scaleAbsoluteValues()

void KoSvgTextProperties::scaleAbsoluteValues ( const double scaleInline = 1.0,
const double scaleBlock = 1.0 )

scaleAbsoluteValues This scales all absolute values stored in these text properties. Relative values don't need to be scaled. This can be used to scale styles in setSize as well as scale the text properties for Style Presets.

Parameters
scaleInline– affects inline-direction values, like letter-spacing, inline-size, tab-size, text-indent, etc.
scaleBlock– affects block-direction values, like font-size, line-height, and baseline-shift.

Definition at line 206 of file KoSvgTextProperties.cpp.

207{
209
210 for (auto it = this->m_d->properties.begin(); it != this->m_d->properties.end(); ++it) {
211 if (it.value().canConvert<KoSvgText::CssLengthPercentage>()) {
213 if (length.unit != absoluteUnit) continue;
214 if (it.key() == FontSizeId || it.key() == BaselineShiftValueId) {
215 length.value *= scaleBlock;
216 } else {
217 length.value *= scaleInline;
218 }
219 it.value() = QVariant::fromValue(length);
220 } else if (it.value().canConvert<KoSvgText::LineHeightInfo>()) {
222 if (info.length.unit != absoluteUnit) continue;
223 info.length.value *= scaleBlock;
224 it.value() = QVariant::fromValue(info);
225 } else if (it.value().canConvert<KoSvgText::TabSizeInfo>()) {
227 if (info.length.unit != absoluteUnit) continue;
228 info.length.value *= scaleInline;
229 it.value() = QVariant::fromValue(info);
230 } else if (it.value().canConvert<KoSvgText::TextIndentInfo>()) {
232 if (info.length.unit != absoluteUnit) continue;
233 info.length.value *= scaleInline;
234 it.value() = QVariant::fromValue(info);
235 } else if (it.value().canConvert<KoSvgText::AutoValue>()) {
236 KoSvgText::AutoValue info = it.value().value<KoSvgText::AutoValue>();
237 if (info.isAuto) continue;
238 if (it.key() != InlineSizeId) continue;
239 info.customValue *= scaleInline;
240 it.value() = QVariant::fromValue(info);
241 }
242 // TODO: Check shape padding and margin when they become editable.
243 }
244}
@ Absolute
Pt, everything needs to be converted to pt for this to work.
Definition KoSvgText.h:408

References KoSvgText::CssLengthPercentage::Absolute, BaselineShiftValueId, KoSvgText::AutoValue::customValue, FontSizeId, InlineSizeId, KoSvgText::AutoValue::isAuto, KoSvgText::TextIndentInfo::length, KoSvgText::TabSizeInfo::length, KoSvgText::LineHeightInfo::length, length(), m_d, KoSvgText::CssLengthPercentage::unit, KoSvgText::CssLengthPercentage::value, KoSvgText::TabSizeInfo::value, and KoSvgText::LineHeightInfo::value.

◆ setAllButNonInheritableProperties()

void KoSvgTextProperties::setAllButNonInheritableProperties ( const KoSvgTextProperties & properties)

Used to merge child properties into parent properties.

Definition at line 196 of file KoSvgTextProperties.cpp.

197{
198 auto it = properties.m_d->properties.constBegin();
199 for (; it != properties.m_d->properties.constEnd(); ++it) {
200 if (m_d->isInheritable(it.key())) {
201 setProperty(it.key(), it.value());
202 }
203 }
204}

References m_d, properties(), and setProperty().

◆ setFontSize()

void KoSvgTextProperties::setFontSize ( const KoSvgText::CssLengthPercentage length)

Definition at line 1208 of file KoSvgTextProperties.cpp.

1209{
1210 setProperty(KoSvgTextProperties::FontSizeId, QVariant::fromValue(length));
1211}

References FontSizeId, length(), and setProperty().

◆ setProperty()

void KoSvgTextProperties::setProperty ( KoSvgTextProperties::PropertyId id,
const QVariant & value )

Set the property id to value

Definition at line 59 of file KoSvgTextProperties.cpp.

60{
61 m_d->properties.insert(id, value);
62}

References m_d, and value().

◆ stroke()

KoShapeStrokeModelSP KoSvgTextProperties::stroke ( ) const

Definition at line 1198 of file KoSvgTextProperties.cpp.

1199{
1201}
StrokeProperty is a special wrapper around KoShapeStrokeModel for managing it in KoSvgTextProperties.
Definition KoSvgText.h:733

References property(), and StrokeId.

◆ supportedXmlAttributes()

QStringList KoSvgTextProperties::supportedXmlAttributes ( )
static

Return a list of supported XML attribute names (defined in SVG)

Definition at line 1213 of file KoSvgTextProperties.cpp.

1214{
1215 QStringList attributes;
1216 attributes << "writing-mode"
1217 << "glyph-orientation-vertical"
1218 << "glyph-orientation-horizontal"
1219 << "direction"
1220 << "unicode-bidi"
1221 << "text-anchor"
1222 << "dominant-baseline"
1223 << "alignment-baseline"
1224 << "baseline-shift"
1225 << "kerning"
1226 << "letter-spacing"
1227 << "word-spacing"
1228 << "xml:space"
1229 << "xml:lang"
1230 << "text-rendering";
1231 return attributes;
1232}

◆ xHeight()

qreal KoSvgTextProperties::xHeight ( ) const

Definition at line 1082 of file KoSvgTextProperties.cpp.

1083{
1084 const KoSvgText::FontMetrics metrics = this->metrics(false);
1085
1086 const qreal fontSizeVal = fontSize().value;
1087 if (metrics.xHeight > 0 && metrics.fontSize > 0) {
1088 return metrics.xHeight * fontSizeVal / metrics.fontSize;
1089 }
1090 return fontSizeVal * 0.5;
1091}
qint32 xHeight
height of X, defaults to 0.5 fontsize.
Definition KoSvgText.h:334

References KoSvgText::FontMetrics::fontSize, fontSize(), metrics(), KoSvgText::CssLengthPercentage::value, and KoSvgText::FontMetrics::xHeight.

Member Data Documentation

◆ m_d

const QScopedPointer<Private> KoSvgTextProperties::m_d
private

Definition at line 324 of file KoSvgTextProperties.h.


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