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" ) ) )
246 fontsLoaded = ( fontsLoaded || false );
260 loaded = ( fontID != -1 );
261 fontsLoaded = ( fontsLoaded || loaded );
263 .arg( familyStyle, loaded ?
"loaded" :
"FAILED to load", fontPath ) );
269 QFile fontResource(
":/testdata/font/" + fontpath );
270 if ( fontResource.
open( QIODevice::ReadOnly ) )
273 loaded = ( fontID != -1 );
274 fontsLoaded = ( fontsLoaded || loaded );
277 .arg( familyStyle, loaded ?
"loaded" :
"FAILED to load" ) );
298 if ( style ==
"Roman" )
300 else if ( style ==
"Oblique" )
302 else if ( style ==
"Bold Oblique" )
303 modified =
"Bold Italic";
354 if ( nodeList.
size() > 0 )
368 QStringList words =
QStringList() <<
"Normal" <<
"Light" <<
"Bold" <<
"Black" <<
"Demi" <<
"Italic" <<
"Oblique";
369 Q_FOREACH (
const QString& word, words )
373 return translatedStyleMap;
379 for (
int i = 0, n = words.
length(); i < n; ++i )
383 return words.
join(
" " );
390 for (
int i = 0, n = words.
length(); i < n; ++i )
392 if ( translatedStyleMap.
contains( words[i] ) )
394 words[i] = translatedStyleMap.
value( words[i] );
401 return words.
join(
" " );
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.
QStringList styles(const QString &family) const
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.
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
static bool fontFamilyMatchOnSystem(const QString &family, QString *chosen=0, bool *match=0)
Check whether font family is on system.
QDomNode at(int index) const
qreal wordSpacing() const
const T value(const Key &key) const