Monday, April 16, 2012

Help using a custom font

I can't seem to get a fontstring to display a different font using FontString:SetFont("ariel.ttf",14). And i'm not sure how to create my own font object to use SetFontObject(GameFontNormalSmall).

The ttf font is in my addon folder and i've tried "ariel.ttf", "\ariel.ttf", "\\ariel.ttf", "Interface\\AddOns\\fontchange\\ariel.ttf" but still no luck.

I use AddOn Studio for quick script creation. Any help would be greatly appriciated.|||have a look at clearfont2 over at wowace.|||Looked at it. I need to replace specific tooltips with a specific font, not all the fonts for my ui. Though that addon is where I got the idea to try "Interface\\AddOns\\fontchange\\ariel.ttf"|||Definitely include the whole path.

You mention that you want to change specific tooltips with a specific font, so are you doing something like :


Code:
GameTooltipTextLeft1:SetFont("Interface\\AddOns\\fontchange\\ariel.ttf", 14);

?

And repeating this for each line of the tooltip ?

And then resetting the font back to the original when the tooltip closes ?

I'd make sure to use :SetFont BEFORE using GameTooltip:Show() method, as it may not have a noticeable effect once the tooltip is already showing...



Apart from that, I'm not sure what the problem might be.

Maybe post your code so we can take a more detailed look at what you're trying to do|||So I'm actually trying to create a double column tooltip to go with my addon. Yes, I know that there is ingame functionality for a double column tooltip (GameTooltip:AddDoubleLine) but that method right aligns the second column, which ends up looking trashy. So I am manually left aligning the second column by making an ascii table.

I have made the code for creating the vertical lines after the items in my first column, but as expected they don't line up.

------------------

Item #1 |

Item Number 2 |

Item Three |

The problem is the font (GameFontNormal) uses different widths for the letters so that it's impossible to calculate the space padding at the end of a word. I believe the use of a font like "Courier New" would allieviate the problem in that all of its letter spacing is uniform (eg. 'i' takes up the same space as 'w').

I decided to first experiment with FontStrings by making a barebones addon (Wow Addon Studio). I suspected changing the font of a Fontstring would be easy, since it had methods like SetFont and SetFontObject, and GameTooltip had neither. (And lets face it, if i can't change the font of a fontstring, i have no hope with the Gametooltip.) I've tried many versions to try and get it working, but the font doesn't want to change.

================================

--Example 1 not working

FontString1:SetFont("Interface\AddOns\changefont\ariel.ttf", 12) --Also tried with \\

FontString1:SetText("Hello There")

================================

--Example 2 not working

--in an xml file, based on the format found in blizz's FrameXML fonts.xml

<Font name="Ariel" virtual=true inherits="Master Font" font="Interface\AddOns\changefont\ariel.ttf">

</Font>

--in the lua file

FontString1:SetFontObject(Ariel)

FontString1:SetText("Hello There")

================================

I got a little bit closer with example #2. I replaced font="Inte..." with font="Font\FRIZQT__.ttf" (blizz's in-game font) and it responded to that, so I know the code is correct.

I also read that there is a "hacky" way to change the in-game fonts. By creating a folder called Font (in world of warcraft folder) and putting your fonts in there named after blizz's official fonts, it will call yours instead of the built in ones.

These two facts, put together lead me to believe it was possible to switch out an entire font, but not to add a custom font for something like a tooltip.

But I know i've seen addons that have their own fonts. ScrollingCombatText is one that comes to mind. I looked at the code and it seems to use StubLib (probably and Ace2 library). Though I don't want to convert my whole addon to Ace just to include a font feature. I also tried SharedMedia / SharedMediaLib, but couldn't get that to function either with SetFont, or SetFontObject.

So I'm at a loss. Have any ideas?

Sorry for the wall of text.|||I had written up my response in a text document, because I lost my original response -- apparently it took too long to write in the "Quick Reply."

Even though I didn't figure out how to do what I wanted, I went ahead and used blizz's double line function, which turned out to work much better than I anticipated. I posted my response, to those who were stricken with the curiousity bug, and so that my work writing it wouldn't be wasted.

Anyway, I posed my mod "MobMarks" yesterday on the site. If you want to get an idea of how it looks with the doubleline, I posted a pic of it.

Thanks for the ideas!

~John|||Also the font is spelt "Arial", not "Ariel".|||Quote:








Also the font is spelt "Arial", not "Ariel".

No comments:

Post a Comment