|
Contents
IntroductionThe font node lets you specify the characteristics of a desired font. It then loads the closest matching font available in the system and presents a handle to that font on its handle attribute. This in turn can be used by other nodes, such as Gooroos Software's annotation node, as the font in which they display their text. Because font handling varies considerably between different operating systems, the font node makes available different attributes on Windows than on Linux. The functionality of the listFonts command is also different between the two operating systems. For this reason, this documentation provides separate User's Guides and Attribute References for Linux and Windows. The differences between the two platforms also means that you must take extra care if you are writing MEL scripts which must run on both. For tips on doing that, refer to the section on Making Portable MEL Scripts.
User's Guide (Linux)A font node is created like any other node in Maya, using the createNode command. For example:
createNode font;
// Result: font1
When initially created, the font node is set to provide the system's "fixed" font. Specifically, it uses the following X Logical Font Descriptor (XLFD):
-*-fixed-*-r-*-*-*-120-*-*-*-*-*-*
The font's characteristics can be defined by setting the node's various
attributes. For example, you could switch to the "times" font family, make
the font bold, italicize it and double its size as follows:
setAttr -type "string" font1.family "times";
setAttr -type "string" font1.weight "bold";
setAttr -type "string" font1.slant "i";
setAttr font1.pointSize 240;
This would then generate the following XLFD:
-*-times-bold-i-*-*-*-240-*-*-*-*-*-*
We can connect this to a Gooroos Software annotation node
bearing the text "Italicized Times Font" to see the results of the font
settings:
annotation -fontNode font1 "Italicized Times Font";
When setting string values, "any" is an alias for "*", and "none" is an alias for an empty string. Thus, the following two blocks of MEL script will both generate the same XLFD:
// These two statements...
setAttr -type "string" font1.slant "any";
setAttr -type "string" font1.additionalStyle "none";
// Are the same as these two...
setAttr -type "string" font1.slant "*";
setAttr -type "string" font1.additionalStyle "";
// They both generate the following XLFD:
-*-times-bold-*-*--*-240-*-*-*-*-*-*
When setting integer values, -1 is an alias for "*" and -2 is an alias for
an empty specification. In this case you must use the aliases since an
integer field will not accept "*" or an empty string as input.
Each attribute will take any value you give it, regardless of whether that produces a meaningful font descriptor. The reason for this is that the list of valid values is dependent upon the set of fonts currently installed in your system. To help narrow down the range of choices, the Attribute Editor provides a 'Browse' button for each attribute which lists the valid values for the fonts currently installed on your system. However, it should be noted that the various size attributes -- pixelSize, pointSize, xResolution, yResolution and width -- only pertain to non-scalable fonts: for scalable fonts, such as TrueType fonts, you can specify any positive integer value for these sizing attributes. You can also use the listFonts command to view all the valid values for any XFLD attribute, from all of the fonts installed on your system. Alternatively, the X Windowing System provides a standard utility called xfontsel which you can run from the Linux shell to interactively select different font characteristics to see how they work together. If the X Windowing System cannot provide a font exactly matching the characteristics which you have specified then it will supply the closest matching font. If no font at all can be found, then the font node will fall back to using the system's "fixed" font. In addition to the individual attributes used to define the XFLD, the font node has an another string attribute called predefinedFont. If this attribute is set to anything other than "none" or empty, the font node will ignore all of its other attributes and just use whatever font name you supply. This provides a method for using predefined font aliases which are not in XFLD form. For example:
setAttr -type "string" font1.predefinedFont "8x16";
User's Guide (Windows)A font node is created like any other node in Maya, using the createNode command. For example:
createNode font;
// Result: font1
When initially created, the font node is set to select Windows' "GUI Default" font. This is one of the seven predefined fonts which are available on all Windows systems. The diagram below shows what these predefined fonts look like:
A font node can be made to select any one of these predefined fonts by setting its stockFont attribute to the appropriate value, from 1 to 7. For example, the following MEL command would set a font node to use Windows' predefined ANSI Fixed-pitch font:
setAttr font1.stockFont 2;
Instead of using a predefined font, you can set the font node's stockFont attribute to zero, then use its remaining attributes to specify the precise characteristics of the font you would like. The node will then search for the available font which most closely matches those characteristics.
setAttr font1.stockFont 0;
setAttr -type "string" font1.typeface
"Times New Roman";
setAttr font1.width 10;
setAttr font1.height 20;
setAttr font1.italic yes;
createNode -name "sample" annotation;
setAttr -type "string" sample.text
"Italicized Times New Roman font";
connectAttr font1.handle sample.font;
Attribute Reference (Linux)A font node's special attributes are found in the Attribute Editor under the Font heading. Beneath this is a sub-section entitled Explicit Font Attributes. The explicit attributes are only enabled when you set the Predefined Font field to None or empty. Beside each input attribute the Attribue Editor will display a 'Browse' button. If you click on the button a list of valid values for that attribute will be displayed. Double-clicking on a value, or selecting one and clicking the "OK" button, will copy that value into the attribute.
Attribute Reference (Windows)A font node's special attributes are found in the Attribute Editor under the Font heading. Beneath this is a sub-section entitled Explicit Font Attributes. The explicit attributes are only enabled when you set the Predefined Font field to None (which is equivalent to setting the node's stockFont attribute to zero).
The listFonts CommandThe font node plugin also contains the listFonts MEL command. When executed with no arguments, this returns an array of strings where each element is the name of an installed font family (which are referred to as "typefaces" on Windows). For example:
string $fonts[] = listFonts();
print("The result is " + $fonts[5] + "\n");
The result is Courier New
On Linux, the listFonts command also supports a number of flags which can be used to list the valid values for each component of an X Logical Font Descriptor. The flag names match the names of the corresponding attributes on the font node. Thus, if you wanted to list the pixelSizes available across all currently installed fonts, you would use the -px or -pixelSize flag. For example:
int $pixelSizes[] = `listFonts -px`;
Only one flag may be specified per command invocation. If you specify more than one then the command will pick just one of them and return the values for it.
Making Portable MEL ScriptsAt the MEL scripting level, the syntax for connecting a font node to an annotation node is consistent. Thus, all of the following will work on both Linux and Windows:
// Create a font node and annotation
// node and connect them by hand.
createNode -n f font;
createNode -n a annotation;
connectAttr f.handle a.font;
or
// Have the annotation command create and
// connect the font node for us.
annotation -createFontNode yes "Some text";
or
createNode -n myFont font;
// Have the annotation command connect
// to the existing font node.
annotation -fontNode myFont "Some more text";
Furthermore, the listFonts command, with no arguments, will behave similarly on both operating systems, returning an array of font family names on Linux and an array of typeface names on Windows. However, pretty much anything else that you do with the font node or the listFonts command will require that you provide different MEL commands for Linux and Windows. To do this, you can use the MEL command about to determine which operating system the script is being run under. For example:
//
// Change the font size.
//
if (`about -windows`)
{
// Windows-specific code
setAttr f.width 20;
setAttr f.height 40;
}
else
{
// Linux-specific code
setAttr f.pointSize 200;
}
Support & Copyright InformationThe font node and its associated materials, which are collectively referred to as "this product", are copyright Gooroos Software, 1999-2004. Gooroos Software provides this product as-is and assumes no liability for its use. You may freely redistribute it, but only in complete and unmodified form. If you have any questions or problems with this product, please send email to support@gooroos.com. Because this product is made freely available, we cannot guarantee you a response, but we will try to get back to you as time permits. For more information on Gooroos Software and our other products, please visit our web-site at www.gooroos.com.
Downloads
|