FontFaceRule

Since: BlackBerry 10.2.0

#include <bb/cascades/FontFaceRule>

Represents the font face rules that define the properties for custom fonts.

A FontFaceRule object can be used to add an internal font family name to an external font. The internal name is defined using a name you specify using the FontFaceRule::fontFamily property. In addition, a FontFaceRule object also requires a font file specified using the FontFaceRule::source property. Currently, FontFaceRule supports TrueType font (TTF) and OpenType font (OTF) formats, and the font file must be located in the "assets" folder of your project.

The fontFamily and source properties must be defined for a FontFaceRule object to be valid. If either the fontFamily or source properties are not defined, the rule is ignored.

After the font family name is defined, it can be applied to a text control using the TextStyleDefinition::fontFamily property.

Currently, text style rules can only be applied in QML.

The following QML example shows how to define an external font called "MyFont" that is sourced from a font file called "myfont.ttf":
 import bb.cascades 1.2

 Container {
     attachedObjects: [
         TextStyleDefinition {
             id: myStyle
             base: SystemDefaults.TextStyles.BodyText

             rules: [
                 FontFaceRule {
                     source: "myfont.ttf"
                     fontFamily: "MyFont"
                 }
             ]
             fontFamily: "MyFont, sans-serif"
         }
     ]

     Label {
         text: "Hello, world!"
         textStyle.base: myStyle.style
     }
 }
See also:

TextStyleDefinition::rules, TextStyleDefinition::fontFamily, TextStyle::fontFamily


Overview

QML properties

fontFamily: QString
source: QUrl
objectName: QStringInherited
parent: QObject [read-only]Inherited

QML signals

Properties Index

Public Functions Index

QStringfontFamily () const
Q_SLOT voidresetFontFamily ()
Q_SLOT voidresetSource ()
Q_SLOT voidsetFontFamily (const QString &fontFamily)
Q_SLOT voidsetSource (const QUrl &source)
QUrlsource () const
voidsetObjectName (const QString &name)Inherited
virtual Q_INVOKABLE QStringtoDebugString () const Inherited

Protected Functions Index

Only has inherited protected functions

BaseObject (QObject *parent=0)Inherited

Signals Index

voidfontFamilyChanged (const QString &fontFamily)
voidsourceChanged (const QUrl &source)
voidcreationCompleted ()Inherited
voidobjectNameChanged (const QString &objectName)Inherited

Properties

QString fontFamily

The font-family name.

Since:

BlackBerry 10.2.0

QUrl source

The font source URL.

The default value is an empty QUrl. If no font source URL is specified for this property, the FontFaceRule is ignored. Only assets are supported for FontFaceRule::source property.

Since:

BlackBerry 10.2.0

QString objectNameInherited

This property is overridden from QObject.

See also:

QObject::objectName().

Since:

BlackBerry 10.0.0

QObject parentInherited[read-only]

A read-only property that represents this object's parent.

The parent of an object is specified using QObject::setParent(QObject*). The purpose of the property is to expose the object's parent to QML.

This property is read-only to prevent modifications from QML, where typically the parent is declaratively set. In C++ code, the parent can be explicitly set using QObject::setParent(QObject*), or implicitly set by adding it to a visual container.

The default value of this property is 0.

Since:

BlackBerry 10.0.0

Public Functions

QString fontFamily ()

Returns the font family of the FontFaceRule.

Return:

The font family of the FontFaceRule.

Since:

BlackBerry 10.2.0

Q_SLOT void resetFontFamily ()

Resets the font family on the FontFaceRule to the default value.

The default value is QString::null.

Since:

BlackBerry 10.2.0

Q_SLOT void resetSource ()

Resets the font source on the FontFaceRule.

The default value is an empty QUrl.

Since:

BlackBerry 10.2.0

Q_SLOT void setFontFamily (

Sets the font family on the FontFaceRule.

Parameters
fontFamily

The font family of the FontFaceRule.

Since:

BlackBerry 10.2.0

Q_SLOT void setSource (

Sets the source on the FontFaceRule.

Parameters
source

The source of the FontFaceRule.

Since:

BlackBerry 10.2.0

QUrl source ()

Returns the source of the FontFaceRule.

Return:

The source of the FontFaceRule.

Since:

BlackBerry 10.2.0

void setObjectName (Inherited

Sets the objectName property.

Parameters
name

The new name for the object.

Since:

BlackBerry 10.0.0

virtual Q_INVOKABLE QString toDebugString ()Inherited

Returns a debug string representing this object.

Return:

A debug string for the object.

Since:

BlackBerry 10.0.0

Protected Functions

(Only has inherited protected functions)

BaseObject (Inherited

Constructs an instance of BaseObject's subclass.

Parameters
parent

An optional parent, defaults to 0.

Since:

BlackBerry 10.0.0

Signals

void fontFamilyChanged (

Emitted when the font family has changed.

Parameters
fontFamily

The new font family.

Since:

BlackBerry 10.2.0

void sourceChanged (

Emitted when the font source has changed.

Parameters
source

The new font source.

Since:

BlackBerry 10.2.0

void creationCompleted ()Inherited

Emitted when this object is instantiated as a result of loading a QML document and creating the root node (only after the root component that caused this instantiation has completed construction), or when the object is being constructed from its builder class.

This signal indicates that the construction and initialization of the object has been completed, the properties are initialized, and any QML binding values have been assigned to the object.

This signal is not emitted when the object is constructed from C++ using the constructor. If the object is constructed using its builder class, the signal is emitted when the the builder class returns the fully constructed object.

This signal can be used when there is an activity that needs to be performed, such as a property state integrity verification after the object is instantiated from a QML document or a builder, but before control is returned to the application.

See also:

QmlDocument

Since:

BlackBerry 10.0.0

void objectNameChanged (Inherited

This signal is emitted when the objectName property is changed.

Since:

BlackBerry 10.0.0

Last modified: 2014-09-30



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus