20#include <QTextCharFormat>
24 set = format.hasProperty( QTextFormat::TextVerticalAlignment );
25 switch ( format.verticalAlignment() )
27 case QTextCharFormat::AlignNormal:
29 case QTextCharFormat::AlignSuperScript:
31 case QTextCharFormat::AlignSubScript:
35 case QTextCharFormat::AlignMiddle:
36 case QTextCharFormat::AlignTop:
37 case QTextCharFormat::AlignBottom:
38 case QTextCharFormat::AlignBaseline:
46 : mTextColor( format.hasProperty( QTextFormat::ForegroundBrush ) ? format.foreground().color() : QColor() )
47 , mFontWeight( format.hasProperty( QTextFormat::FontWeight ) ? format.fontWeight() : -1 )
48 , mStyleName( format.font().styleName() )
50 , mFontPointSize( format.hasProperty( QTextFormat::FontPointSize ) ? format.fontPointSize() : - 1 )
51 , mWordSpacing( format.hasProperty( QTextFormat::FontWordSpacing ) ? format.fontWordSpacing() : std::numeric_limits< double >::quiet_NaN() )
58 if ( format.hasProperty( QTextFormat::FontFamily ) )
60 mFontFamily = format.fontFamily();
62 if ( mFontFamily.isEmpty() && format.hasProperty( QTextFormat::FontFamilies ) )
64 const QStringList families = format.fontFamilies().toStringList();
65 if ( !families.isEmpty() )
66 mFontFamily = families.at( 0 );
68 if ( format.isImageFormat() )
70 const QTextImageFormat imageFormat = format.toImageFormat();
71 mImagePath = imageFormat.name();
72 mImageSize = QSizeF( imageFormat.width(), imageFormat.height() );
78 if ( !mTextColor.isValid() && other.mTextColor.isValid() )
79 mTextColor = other.mTextColor;
80 if ( mFontPointSize == -1 && other.mFontPointSize != -1 )
81 mFontPointSize = other.mFontPointSize;
82 if ( mFontPercentageSize == -1 && other.mFontPercentageSize != -1 )
83 mFontPercentageSize = other.mFontPercentageSize;
84 if ( std::isnan( mWordSpacing ) )
85 mWordSpacing = other.mWordSpacing;
86 if ( mFontFamily.isEmpty() && !other.mFontFamily.isEmpty() )
87 mFontFamily = other.mFontFamily;
89 mStrikethrough = other.mStrikethrough;
91 mUnderline = other.mUnderline;
93 mOverline = other.mOverline;
95 mItalic = other.mItalic;
96 if ( mFontWeight == -1 && other.mFontWeight != -1 )
97 mFontWeight = other.mFontWeight;
98 if ( mStyleName.isEmpty() && ! other.mStyleName.isEmpty() )
99 mStyleName = other.mStyleName;
102 mVerticalAlign = other.mVerticalAlign;
103 mHasVerticalAlignSet =
true;
119 return mFontPointSize;
124 mFontPointSize = size;
129 return mFontPercentageSize;
134 mFontPercentageSize = size;
149 return mStrikethrough;
154 mStrikethrough = strikethrough;
200 if ( !mFontFamily.isEmpty() )
203 if ( mFontPointSize != -1 )
206 if ( mFontPercentageSize != -1 )
207 font.setPixelSize( font.pixelSize() * mFontPercentageSize );
212 if ( mFontWeight != - 1 )
214#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
215 font.setWeight( mFontWeight );
217 if ( mFontWeight <= 150 )
218 font.setWeight( QFont::Thin );
219 else if ( mFontWeight <= 250 )
220 font.setWeight( QFont::ExtraLight );
221 else if ( mFontWeight <= 350 )
222 font.setWeight( QFont::Light );
223 else if ( mFontWeight <= 450 )
224 font.setWeight( QFont::Normal );
225 else if ( mFontWeight <= 550 )
226 font.setWeight( QFont::Medium );
227 else if ( mFontWeight <= 650 )
228 font.setWeight( QFont::DemiBold );
229 else if ( mFontWeight <= 750 )
230 font.setWeight( QFont::Bold );
231 else if ( mFontWeight <= 850 )
232 font.setWeight( QFont::ExtraBold );
234 font.setWeight( QFont::Black );
239 font.setStyleName( mStyleName );
249 if ( !std::isnan( mWordSpacing ) )
282 mWordSpacing = spacing;
TextCharacterVerticalAlignment
Text vertical alignment for characters.
@ Normal
Adjacent characters are positioned in the standard way for text in the writing system in use.
@ SubScript
Characters are placed below the base line for normal text.
@ SuperScript
Characters are placed above the base line for normal text.
@ Points
Points (e.g., for font sizes)
static void setFontFamily(QFont &font, const QString &family)
Sets the family for a font object.
Contains information about the context of a rendering operation.
double convertToPainterUnits(double size, Qgis::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
Stores information relating to individual character formatting.
void setFamily(const QString &family)
Sets the font family name.
void overrideWith(const QgsTextCharacterFormat &other)
Override all the default/unset properties of the current character format with the settings from anot...
void updateFontForFormat(QFont &font, const QgsRenderContext &context, double scaleFactor=1.0) const
Updates the specified font in place, applying character formatting options which are applicable on a ...
void setFontWeight(int fontWeight)
Sets the font weight.
void setImageSize(const QSizeF &size)
Sets the image size, if the format applies to a document image fragment.
QSizeF imageSize() const
Returns the image size, if the format applies to a document image fragment.
QColor textColor() const
Returns the character's text color, or an invalid color if no color override is set and the default f...
BooleanValue italic() const
Returns whether the format has italic enabled.
QString imagePath() const
Returns the path to the image to render, if the format applies to a document image fragment.
QgsTextCharacterFormat()=default
void setStrikeOut(BooleanValue enabled)
Sets whether the format has strikethrough enabled.
void setOverline(BooleanValue enabled)
Sets whether the format has overline enabled.
BooleanValue
Status values for boolean format properties.
@ SetTrue
Property is set and true.
@ NotSet
Property is not set.
void setImagePath(const QString &path)
Sets the path to the image to render, if the format applies to a document image fragment.
int fontWeight() const
Returns the font weight, or -1 if the font weight is not set and should be inherited.
bool hasVerticalAlignmentSet() const
Returns true if the format has an explicit vertical alignment set.
BooleanValue strikeOut() const
Returns whether the format has strikethrough enabled.
double wordSpacing() const
Returns the font word spacing, in points, or NaN if word spacing is not set and should be inherited.
double fontPointSize() const
Returns the font point size, or -1 if the font size is not set and should be inherited.
QString family() const
Returns the font family name, or an empty string if the family is not set and should be inherited.
BooleanValue underline() const
Returns whether the format has underline enabled.
void setWordSpacing(double spacing)
Sets the font word spacing, in points, or NaN if word spacing is not set and should be inherited.
void setTextColor(const QColor &textColor)
Sets the character's text color.
void setUnderline(BooleanValue enabled)
Sets whether the format has underline enabled.
void setItalic(BooleanValue enabled)
Sets whether the format has italic enabled.
BooleanValue overline() const
Returns whether the format has overline enabled.
void setFontPointSize(double size)
Sets the font point size.
void setFontPercentageSize(double size)
Sets the font percentage size (as fraction of inherited font size).
double fontPercentageSize() const
Returns the font percentage size (as fraction of inherited font size), or -1 if the font size percent...
#define BUILTIN_UNREACHABLE
Qgis::TextCharacterVerticalAlignment convertTextCharFormatVAlign(const QTextCharFormat &format, bool &set)