Project members: Font resource variant
With a font resource variant member you can override another font resource member existing in your project. Once overridden, the variant member can retrospectively modify the attributes of the original font resource member. Font resource variant members are represented in Composer by following bricks. Please note the additional small overlay in the icon of the brick:
The derivation of variants provides the fundamental technique to manage several product and design versions within one and the same GUI application. The selection of the appropriate variant occurs automatically depending on the condition specified in the VariantCond attribute of the variant member. Depending on this condition, Embedded Wizard distinguishes between following two types of a variant:
Type |
Short description |
---|---|
Static |
The condition for the selection of the respective variant results in a value well known at the code compilation time and immutable at the runtime. If this condition is true, the affected variant overrides the original font resource member permanently. If the condition is false, the variant has no effect. |
Dynamic |
The condition for the variant selection depends on styles. Since styles can be activated and deactivated individually at the runtime, the overriding changes dynamically. |
A font resource member, which has been overridden by a variant member is considered as being multi-variant. You can derive as many variants of an original member as you want. Moreover, one font resource variant can override another font resource variant resulting in a hierarchy of variants. With the Browser window you can inspect this hierarchy. Please note, a member overridden by a variant is signed in the Browser with an additional small icon. You can thus recognize multi-variant members easily. Additionally, the corresponding variant condition is shown between a pair of [...] (squared brackets):
The original font resource member is overridden by a variant, which, in turn, is overridden by another variant. Both variants specify as condition true and are thus static.
Create new font resource variant
You create a new font resource variant by simply deriving it from an existing font resource or another font resource variant. In the simplest case, if both, the original member and the variant are defined within the same unit, do following:
★First ensure, that the original font resource member is selected.
★Then drag and drop the selected member while holding the keys CtrlShiftAlt pressed.
Deriving a new variant from a font resource member existing within the same unit.
If the original member is not defined within the same unit, you can use the Browser window:
★First switch to the Composer page for the respective unit member, where you want to add the new variant member.
★Then ensure that the Browser window is visible.
★Within the Browser locate the desired font resource member. This can be done easily with Browser's own filter function.
★Select the found font resource member in the Browser window.
★Drag and drop the selected member into the Composer area while holding the keys CtrlShiftAlt pressed.
Deriving a new variant by using the Browser window.
Alternatively, you can derive a new variant by using the clipboard functions Copy & Paste:
★First ensure, that the original font resource member is selected (e.g. in Composer, Inspector or Browser).
★Press the keys CtrlC or use the menu item to copy the selected font resource into the clipboard.
★Eventually switch to the Composer page for the respective unit member, where you want to add the new variant.
★Press the keys CtrlShiftAltV or use the menu item to add a new variant by deriving it from the font resource stored in the clipboard.
Name the font resource variant
★First ensure, that the font resource variant member is selected.
★Press the key F2 or select the menu item .
★Enter the new name in the Inspector window.
Variant members have a global character - they can be accessed from everywhere within your project. To address a variant member, you must always use its full name, which is composed of the unit name, the member is defined inside, and the name of the member itself, both separated by :: (double colon) signs. For example Examples::LabelFontHiResVariant.
Specify the variant condition
The effect of an overriding depends on the condition you specify in the attribute VariantCond of the respective variant member. Per default newly derived variants are configured with the condition true. They overrides thus statically and permanently the original member. You should therefore always review this attribute after deriving a new variant.
Please note, if two variants override the same original member and both variants are configured with the same condition, Embedded Wizard will report a compilation error because of the ambiguity.
Override inherited attributes
The variant exposes all attributes of the original font resource member. The attributes can be inspected or modified with new initialization expressions. As long as not modified, the font resource variant uses the expression inherited from its original member. When you modify an attribute, its original value is overridden.
If your project is localized for several languages, you can override the expressions for every language individually. If neither the variant nor the original font resource specify a particular language specific value for an attribute, the value from the fallback language Default is used automatically.
Once overridden values can be removed easily by pressing the keys CtrlR when the affected value is selected in Inspector. Thereupon, the value inherited from the original member is restored again.
Duplicate an existing font resource variant
You can create any number of copies of an already existing font resource variant member.
★First ensure, that the variant member is selected.
★Press the keys CtrlC and CtrlV in succession ...
★... or hold the key Ctrl pressed while you drag and drop the selected variant member.
★Finally rename the just duplicated font resource variant member ...
★... and review its variant condition.
You can also Drag & Drop a font resource variant member from the Browser into the Composer window and create so a duplicate of the affected member:
★First switch to the Composer page for the respective unit member, where you want to add the duplicate of the font resource variant.
★Then ensure that the Browser window is visible.
★Within the Browser window locate the desired font resource variant member. This can be done easily with Browser's own filter function.
★Select this font resource variant member in the Browser window.
★Drag and drop the selected font resource variant member into the Composer:
Duplicating a font resource variant by simply Drag & Drop it between the Browser and Composer windows
★Finally rename the just duplicated font resource variant member ...
★... and review its variant condition.
Please note, when you have two font resource variant members configured identically with one and the same TrueType font, then Embedded Wizard will treat both individually. In other words, the TrueType fonts are converted twice and they are stored twice in the generated code.
Use the font resource variant
Embedded Wizard selects the appropriate variant automatically either at the code generation time or just at the moment when the corresponding original font resource is evaluated within an expression. Accessing the font resource variants individually is not possible. The selection is controlled by the attribute VariantCond.
Control the code generation
With the attribute Storage you can selectively specify the location where data belonging to the resource should be stored. The data can be stored directly in the generated code or in a separate so-called Blob file. Unlike the first option, the Blob file can be replaced and so the contents of the resource can be exchanged retrospectively without needing to rebuild the binary.
Delete a font resource variant
★First ensure, that the variant member is selected.
★Press the key DEL or select the menu item .
Attributes of a font resource variant
The following table shows the complete list of attributes provided by the font resource variant member:
Attribute name |
Short description |
---|---|
Configures the appearance of the font represented by a font resource variant member. If not modified, contains the value inherited from the original member. |
|
Configures the appearance of the font represented by a font resource variant member. If not modified, contains the value inherited from the original member. |
|
Determines the position and the size of a variant member brick within the Composer window. |
|
Contains the description for the variant member. |
|
Specifies the name of the TrueType font to include by a font resource variant member. If not modified, contains the value inherited from the original member. |
|
Configures the size of the font represented by a font resource variant member. If not modified, contains the value inherited from the original member. |
|
Controls the height calculation mode of the font represented by a font resource member. If not modified, contains the value inherited from the original member. |
|
Configures the appearance of the font represented by a font resource variant member. If not modified, contains the value inherited from the original member. |
|
Controls the kerning metrics of the font represented by a font resource member. If not modified, contains the value inherited from the original member. |
|
Controls the conversion of the font represented by a font resource variant member. If not modified, contains the value inherited from the original member. |
|
Determines the font glyphs to incorporate when converting a particular font resource variant member. If not modified, contains the value inherited from the original member. |
|
Determines the class of a resource member. Please note, this attribute can't be modified in derived variants. |
|
Controls the distance between text rows in the font represented by a font resource member. If not modified, contains the value inherited from the original member. |
|
Determines the condition to activate a particular variant member. |
|
Determines the original font resource member to override by the variant member. |
|
Controls the storage location for data belonging to the resource when generating code. |
Chora syntax of a font resource variant
This section describes the Chora syntax of how font resource variants are stored inside Embedded Wizard project files. The knowledge about the syntax can be helpful when you plan to process the project contents by third party tools. In particular, the general purpose Export and Import functionality introduced in version 14 requires a good understanding of how project members are represented in Chora syntax to correctly interpret the exported members and synthesize the Chora code for members to import. Please note, Embedded Wizard project files (and thus Chora code) are encoded as text in UTF-8 format.
In Chora syntax, font resource variant definition is always introduced with the keyword vresource, followed by the name of the variant, the fully qualified name of the original font resource to override by the variant and a list of attributes to configure the font resource variant. The variant name and the name of the original resource are separated by : colon sign. The attributes are enclosed between a pair of curly braces {..}, whereby each attribute starts with the keyword attr, followed by the attribute name and optionally the value (or values) for the attribute separated from the name by = an assignment operator. Each attribute terminates with ; semicolon sign. Wherever necessary, the tokens are separated by whitespace signs. For the list of attributes supported by the font resource please see the section Attributes of a font resource.
A font resource variant may be localized for multiple languages. It this case the attributes contain multiple values, each composed of a language name and the corresponding value. Each language name and the corresponding value are separated by an assignment operator = and terminated with ; semicolon sign. All language specific values belonging to an attribute are enclosed between a pair of parenthesis (..).
The definition of a resource variant can be initiated by a comment block providing optional description for the variant. The content of this comment corresponds to the value of the variant's attribute Description. Furthermore the directives $rect, $variant and $storage can be specified providing values for the corresponding attributes Brick, VariantCond and Storage. The following examples demonstrate the described syntax:
// This is a font resource variant overriding the resource 'Example::Font'. \ // This variant specifies a different size of the font to use when the variant \ // is active. All other attributes are inherited from the original resource. // // $rect determines the position of the brick inside Composer window. // $variant determines the condition when the variant is used. Here, let \ // assume, the variant depends on the profile named 'SmallTarget'. $rect <10,10,210,50> $variant SmallTarget vresource SmallFont : Example::Font { attr Height = 20; } // This font resource variant overrides the original font resource \ // Example::Font and defines a smaller character code ranges for the \ // languages 'Default' and 'Chinese'. // // $rect determines the position of the brick inside Composer window. // $variant determines the condition when the variant is used. Here, let \ // assume, the variant depends on the profile named 'SmallTarget'. // $storage indicates the content of the variant to be stored in a Blob file. $rect <10,10,210,50> $variant SmallTarget $storage Blob resource Resources::Font Font { attr Ranges = ( Default = 0x20-0x7F; Chinese = Ranges_Chinese.txt; ); }
Each Chora file (or text exchanged with an external Export and/or Import tool) can be (or even should be) prefixed with $version directive. This directive determines the version number of the included Chora code. For details concerning the syntax of the version please see the chapter $version macro. Furthermore, the code can include a $scope directive followed by a path to a project member acting as the original owner of the corresponding code. That means the members described by the Chora code existed inside the member specified in $scope. In case of a font resource variant, $scope would specify the name of the unit the variant belongs to.