21 #include <QApplication> 24 #include <QFontDatabase> 26 #include <QStringList> 53 if ( style ==
"Roman" )
55 if ( style ==
"Oblique" )
57 if ( style ==
"Bold Oblique" )
58 modified =
"Bold Italic";
73 for ( ; it != fontFamilies.
constEnd(); ++it )
76 if ( it->
startsWith( family, Qt::CaseInsensitive ) )
83 *match = ( *it == family );
148 bool foundmatch =
false;
151 styledfont = fontDB.
font( f.
family(), fontstyle, defaultSize );
152 if ( appfont != styledfont || fontstyle != fontDB.
styleString( f ) )
159 if ( fallback && !foundmatch )
167 styledfont = fontDB.
font( f.
family(), style, defaultSize );
168 styledfont = styledfont.
resolve( f );
181 styledfont = fontDB.
font( f.
family(), style, defaultSize );
218 return "QGIS Vera Sans";
224 bool fontsLoaded =
false;
228 fontStyles.
insert(
"Roman",
"QGIS-Vera/QGIS-Vera.ttf" );
229 fontStyles.
insert(
"Oblique",
"QGIS-Vera/QGIS-VeraIt.ttf" );
230 fontStyles.
insert(
"Bold",
"QGIS-Vera/QGIS-VeraBd.ttf" );
231 fontStyles.
insert(
"Bold Oblique",
"QGIS-Vera/QGIS-VeraBI.ttf" );
234 for ( ; f != fontStyles.
constEnd(); ++f )
238 if ( !( loadstyles.
contains( fontstyle ) || loadstyles.
contains(
"All" ) ) )
245 fontsLoaded = ( fontsLoaded || false );
246 QgsDebugMsg(
QString(
"Test font '%1 %2' already available" ).arg( fontFamily, fontstyle ) );
259 loaded = ( fontID != -1 );
260 fontsLoaded = ( fontsLoaded || loaded );
262 .arg( fontFamily, fontstyle, loaded ?
"loaded" :
"FAILED to load", fontPath ) );
268 QFile fontResource(
":/testdata/font/" + fontpath );
269 if ( fontResource.
open( QIODevice::ReadOnly ) )
272 loaded = ( fontID != -1 );
273 fontsLoaded = ( fontsLoaded || loaded );
276 .arg( fontFamily, fontstyle, loaded ?
"loaded" :
"FAILED to load" ) );
297 if ( style ==
"Roman" )
299 else if ( style ==
"Oblique" )
301 else if ( style ==
"Bold Oblique" )
302 modified =
"Bold Italic";
367 QStringList words =
QStringList() <<
"Normal" <<
"Light" <<
"Bold" <<
"Black" <<
"Demi" <<
"Italic" <<
"Oblique";
368 Q_FOREACH (
const QString& word, words )
372 return translatedStyleMap;
378 for (
int i = 0, n = words.
length(); i < n; ++i )
382 return words.
join(
" " );
389 for (
int i = 0, n = words.
length(); i < n; ++i )
391 if ( translatedStyleMap.
contains( words[i] ) )
393 words[i] = translatedStyleMap.
value( words[i] );
400 return words.
join(
" " );
408 css +=
"font-style: ";
409 switch ( font.
style() )
411 case QFont::StyleNormal:
414 case QFont::StyleItalic:
417 case QFont::StyleOblique:
433 case QFont::DemiBold:
442 #if QT_VERSION >= 0x050500 446 case QFont::ExtraLight:
452 case QFont::ExtraBold:
457 css +=
QString(
"font-weight: %1;" ).
arg( cssWeight );
QDomNodeList elementsByTagName(const QString &tagname) const
void setPointSize(int pointSize)
int addApplicationFontFromData(const QByteArray &fontData)
bool contains(const Key &key) const
QString attribute(const QString &name, const QString &defValue) const
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
const_iterator constBegin() const
static bool setFromXmlElement(QFont &font, const QDomElement &element)
Sets the properties of a font to match the properties stored in an XML element.
bool contains(const QString &str, Qt::CaseSensitivity cs) const
void setUnderline(bool enable)
static bool fontFamilyHasStyle(const QString &family, const QString &style)
Check whether font family on system has specific style.
Capitalization capitalization() const
QString join(const QString &separator) const
static bool isRunningFromBuildDir()
Indicates whether running from build directory (not installed)
static QString translateNamedStyle(const QString &namedStyle)
Returns the localized named style of a font, if such a translation is available.
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
QStringList styles(const QString &family) const
static QString asCSS(const QFont &font, double pointToPixelMultiplier=1.0)
Returns a CSS string representing the specified font as closely as possible.
QString styleName() const
QDomElement toElement() const
void setBold(bool enable)
void setPixelSize(int pixelSize)
bool fromString(const QString &descrip)
bool hasAttribute(const QString &name) const
static bool fontFamilyOnSystem(const QString &family)
Check whether font family is on system in a quick manner, which does not compare [foundry].
qreal letterSpacing() const
void setAttribute(const QString &name, const QString &value)
QStringList applicationFontFamilies(int id)
int addApplicationFont(const QString &fileName)
static QFont getStandardTestFont(const QString &style="Roman", int pointsize=12)
Get standard test font with specific style.
const_iterator constEnd() const
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
QFont resolve(const QFont &other) const
static QMap< QString, QString > createTranslatedStyleMap()
static bool setFromXmlChildNode(QFont &font, const QDomElement &element, const QString &childNode)
Sets the properties of a font to match the properties stored in an XML child node.
static bool loadStandardTestFonts(const QStringList &loadstyles)
Loads standard test fonts from filesystem or qrc resource.
static QString standardTestFontFamily()
Get standard test font family.
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
QString styleString(const QFont &font)
void setWordSpacing(qreal spacing)
bool startsWith(const T &value) const
bool contains(QChar ch, Qt::CaseSensitivity cs) const
QFont::Style style() const
void setItalic(bool enable)
void setPointSizeF(qreal pointSize)
const Key key(const T &value) const
static QString untranslateNamedStyle(const QString &namedStyle)
Returns the english named style of a font, if possible.
static QString buildSourcePath()
Returns path to the source directory.
static bool fontFamilyMatchOnSystem(const QString &family, QString *chosen=nullptr, bool *match=nullptr)
Check whether font family is on system.
QFont::StyleHint styleHint() const
QStringList families(WritingSystem writingSystem) const
static bool updateFontViaStyle(QFont &f, const QString &fontstyle, bool fallback=false)
Updates font with named style and retain all font properties.
QString translate(const char *context, const char *sourceText, const char *disambiguation, Encoding encoding)
void setStrikeOut(bool enable)
void setCapitalization(Capitalization caps)
iterator insert(const Key &key, const T &value)
static bool fontMatchOnSystem(const QFont &f)
Check whether exact font is on system.
static QDomElement toXmlElement(const QFont &font, QDomDocument &document, const QString &elementName)
Returns a DOM element containing the properties of the font.
const_iterator constEnd() const
QDomElement createElement(const QString &tagName)
const_iterator constBegin() const
QFont font(const QString &family, const QString &style, int pointSize) const
void setLetterSpacing(SpacingType type, qreal spacing)
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QDomNode at(int index) const
qreal wordSpacing() const
const T value(const Key &key) const