From AddOn Studio
Jump to navigation Jump to search

XML UI ← XML elements < FontString

FontString is an element that allows drawing text in the WoW UI. Like Texture, 'FontString' is a LayoutFrame and is placed in a Layer in a Frame. Also Font is a special type for FontString that allows properties to be more easily defined for inheriting or association, rather than using a full FontString in a XML/Ui element for virtual 'non-directly visible' instances.


Inherited by: none, Inherits: LayoutFrame, Widget API: FontString
Defined in: Layer, Button, ...


  • FontHeight (Value) - screen height of the font, 'font' attribute must also be set
  • Color
  • Shadow


  • name (string) - name of this layout frame
  • inherits (string) - a virtual Font, FontFamily or FontString to inherit properties from.
  • virtual (bool) - Default is 'false'.
  • font (string) - resource path to an actual wow font file. not a reference to Font, FontFamily or FontString.
  • spacing (float) - alters the natural text character spacing. Default is '0'.
  • outline (OUTLINE) - Default is 'NONE'.
  • monochrome (bool) - Default is 'false'.
  • justifyV (JUSTIFYV) - Default is 'MIDDLE'.
  • justifyH (JUSTIFYH) - Default is 'CENTER'.
  • bytes - storage bytes to set asside as an optimization to hold text internally. Default is '255'.
  • text - actual text to be displayed, or predefined WoW constant that gets replaced with localized text.
  • nonspacewrap - if enabled, will break on characters instead of words. effective only when wordwrap is enabled.
  • wordwrap - enables traditional word wrap, where text will wrap around to a new line if it exceeds the frontstring frame width, breaking at the end of the last character or word that fits the width on any particular line.
  • maxLines - the maximum number of lines to render, independant of the size of the fontstring box. text will be constrained by either the heigth of the fontstring frame or the maxLines setting, whichever is smaller.
  • indented - indents all but the first line of text. effective only when wordwrap is enbled. Default is 'false'.


The Fontstring element is used to display a text in the user interface. The text displayed by the Fontstring element can be changed with the LUA function fontStringObject:SetText() or read with the function fontStringObject:GetText().


<Ui xmlns=""
  <Font name="MyFont" font="myfont.ttf" virtual="true">
       <AbsValue val="12"/>
   <Frame name="MyFrame">
     <Size x="200" y="200"/>
         <FontString text="Bob" inherits="MyFont">
           <Size x="100" y="100"/>
             <Anchor point="TOP"/>

This example creates a Font that is used by a FontString.


Specific Options[edit]

  • outline = NORMAL, THICK
  • monochrome = true, false
  • justifyV = TOP, MIDDLE, BOTTOM
  • justifyH = LEFT, CENTER, RIGHT


FontString 'Inherits', in addition to being able to be set to another FontString, can also be set to an existing Font or FontFamily. If set, the current FontString will take on all of that Font's settings, unless overridden in the current FontString.


In addition to setting a 'text' value to a localized string programmatically via WoW Lua run after the XML is loaded, text can also be replaced with a localized string automatically via one of the WoW pre-defined localization constants. For example text="GENERAL_MACROS" would get replaced with text="General Macros" for English text settings, or the Spanish version for Spanish text settings. The value must be one of the pre-defined localization constants or the FontString will simply display the literal text you gave it for the 'text' attribute.

Another Example[edit]

<FontString name="$parentFontString" font="Fonts\FRIZQT__.TTF"
      text="Example Text" justifyH="LEFT" justifyV="TOP">
  <Color r="1" g="0.8" b="1" a="1"/>
  <FontHeight val="12"/>
    <Anchor point="TOPLEFT" relativeTo="$parent" x="20" y="-20" />
    <Offset x="1" y="1" />
    <Color r="0" g="0" b="0"/>


  • <FontString> must be within a <Layer>
  • attribute 'font' needs to be set in order for element 'FontHeight' to work

See also[edit]