Thread Tools Display Modes
07-13-10, 02:18 AM   #1
wellbeing
A Cliff Giant
Join Date: Oct 2009
Posts: 71
fontsting:SetFont

i'm having trouble setting the font for my fontstring.

how do i point to those in the wow directory.

I know that i can go another route using "normalgamefont" or whatever, but i need to scale the size of this particular fontstring up quite a bit. From what i can tell, i wasnt allowed to define the size after setting an inherent font.

for the purpose of clarity, i'm trying to recreate a "raidwarning" style message for which i can define the duration. the built in raidwarning_sendmessage won't allow definition of duration.

in summary.. how can i make my fontstring use a font that is included in wow AND quite large?
  Reply With Quote
07-13-10, 02:30 AM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,928
The way I do it is as follows :

local Path, Size, Flags = self.Cooldown.Text:GetFont()
self.Cooldown.Text:SetFont(Path,myFontSize,Flags);

This should then resize to the size you want.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
07-13-10, 02:49 AM   #3
wellbeing
A Cliff Giant
Join Date: Oct 2009
Posts: 71
Originally Posted by Xrystal View Post
The way I do it is as follows :

local Path, Size, Flags = self.Cooldown.Text:GetFont()
self.Cooldown.Text:SetFont(Path,myFontSize,Flags);

This should then resize to the size you want.

i'm not sure how to apply that to my situation..

here is my function for creating a text frame. i need it a few times with specific variables, so i just want to make it up top for use later.. i got the general format from some addon or another and modified it to my needs. i'm just unable to sort the facts on how to define the font/size.

function CreateText(name,text,x,y,parent,w,h,relto,relpt,just)

Parent = parent


local Name = name
local TextX = x
local TextY = y
local RelativeTo = relto
local RelativePoint = rept
local TextWidth = w
local TextHeight = h
local Text = text

local FrameLevel = 4

local TextFrame = CreateFrame("FRAME",Name,Parent)
TextFrame:ClearAllPoints()
TextFrame:SetWidth(TextWidth)
TextFrame:SetHeight(TextHeight)
local TextFrameFont = TextFrame:CreateFontString(nil, "BACKGROUND")





if(justify) then
TextFrameFont:SetJustifyH(justify)
end


TextFrameFont:SetAllPoints()
TextFrameFont:SetText(Text)
TextFrameFont:SetFont("Fonts\\FRIZQT__.TTF", 11) -- these are the two lines im TRYING to use.
TextFrameFont:SetSize(24, 78)
--TextFrameFont:SetTextHeight(450)
--TextFrameFont:SetWidth(50)
TextFrame:SetPoint(RelativeTo,Parent,RelativePoint,TextX,TextY)
TextFrame:SetMovable(false)
TextFrame:SetFrameLevel(FrameLevel)




end
  Reply With Quote
07-13-10, 03:10 AM   #4
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,928
Okay, this line is possibly causing the problem. There is possibly something missing here but I can't remember exactly what else you need at the moment.

TextFrameFont:SetFont("Fonts\\FRIZQT__.TTF", 11)


Try changing these specific lines ( keep the other ones in for now ).

-- Create a Font String based on GameFontNormal
local TextFrameFont = TextFrame:CreateFontString(nil, "BACKGROUND",GameFontNormal)

--Now this is where we see what the rest of the font is holding and store it
local Path, Size, Flags = TextFrameFont :GetFont()

-- Your code to set the text contents
TextFrameFont:SetText(Text)

-- Now we want to set the font with our chosen settings but keep what it is already using
TextFrameFont:SetFont("Fonts\\FRIZQT__.TTF", 11,Flags)


Try that out and see if that works.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
07-13-10, 03:29 AM   #5
wellbeing
A Cliff Giant
Join Date: Oct 2009
Posts: 71
Originally Posted by Xrystal View Post
Okay, this line is possibly causing the problem. There is possibly something missing here but I can't remember exactly what else you need at the moment.

TextFrameFont:SetFont("Fonts\\FRIZQT__.TTF", 11)


Try changing these specific lines ( keep the other ones in for now ).

-- Create a Font String based on GameFontNormal
local TextFrameFont = TextFrame:CreateFontString(nil, "BACKGROUND",GameFontNormal)

--Now this is where we see what the rest of the font is holding and store it
local Path, Size, Flags = TextFrameFont :GetFont()

-- Your code to set the text contents
TextFrameFont:SetText(Text)

-- Now we want to set the font with our chosen settings but keep what it is already using
TextFrameFont:SetFont("Fonts\\FRIZQT__.TTF", 11,Flags)


Try that out and see if that works.


TextFrameFont:SetFont(Path, Size,Flags)

did you mean to have that as the last line or am i missing the point?
  Reply With Quote
07-13-10, 03:36 AM   #6
wellbeing
A Cliff Giant
Join Date: Oct 2009
Posts: 71
Originally Posted by wellbeing View Post
TextFrameFont:SetFont(Path, Size,Flags)

did you mean to have that as the last line or am i missing the point?

function CreateText(name,text,x,y,parent,w,h,relativeto,relativepoint,justify)

Parent = parent


local Name = name
local TextX = x
local TextY = y
local RelativeTo = relativeto
local RelativePoint = relativepoint
local TextWidth = w
local TextHeight = h
local Text = text

local FrameLevel = 4

local TextFrame = CreateFrame("FRAME",Name,Parent)
TextFrame:ClearAllPoints()
TextFrame:SetWidth(TextWidth)
TextFrame:SetHeight(TextHeight)

TextFrameFont = TextFrame:CreateFontString(nil, "BACKGROUND",GameFontNormal)
local Path, Size, Flags = TextFrameFont:GetFont()
TextFrameFont:SetText(Text)
TextFrameFont:SetFont(Path, Size,Flags)


if(justify) then
TextFrameFont:SetJustifyH(justify)
end

end

this isnt working. hmmm.
  Reply With Quote
07-13-10, 03:50 AM   #7
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,928
Hmm, I can't see why it doesn't work unless you have to have a name passed to the FontString. I think I read somewhere that you can only override the object if it has a unique identity.

Try changing this line ...

TextFrameFont = TextFrame:CreateFontString(nil, "BACKGROUND",GameFontNormal)

To this ...

TextFrameFont = TextFrame:CreateFontString("MyTextFrameFont", "BACKGROUND",GameFontNormal)

And see if that works.

If it still doesn't work and no-one else can see anything by the time I get back in game later on I'll see what's happening.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
07-13-10, 09:27 AM   #8
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
Code:
local function CreateText(name, text, x, y, parent, width, height, relTo, relPoint, justifyH)
	local frame = CreateFrame('Frame', name, parent)
	frame:SetPoint(relTo, parent, relPoint, x, y)
	frame:SetFrameStrata('HIGH')
	frame:SetFrameLevel(4)
	frame:SetHeight(height)
	frame:SetWidth(width)

	local fontString = frame:CreateFontString(nil, 'ARTWORK')
	fontString:SetAllPoints()
	fontString:SetFont("Fonts\\FRIZQT__.TTF", 20)
	fontString:SetShadowOffset(1, -1)
	fontString:SetText(text)

	if justifyH then
		fontString:SetJustifyH(justifyH)
	end

	frame.fontString = fontString
	return frame
end
As you should have figured out by now, the second argument to SetFont is the size you want to use. If your function isn't working it would be nice if you posted the values you are passing since they could be a contributing factor.

For future reference, "this isnt working" doesn't tell us anything. What isn't working? Was there an error message? You get the point (I hope).
  Reply With Quote
07-13-10, 09:48 AM   #9
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
Also:

Creating variables to hold arguments instead of using the arguments directly is o.O...
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote
07-13-10, 11:50 AM   #10
wellbeing
A Cliff Giant
Join Date: Oct 2009
Posts: 71
Originally Posted by Vrul View Post
[code]


As you should have figured out by now, the second argument to SetFont is the size you want to use. If your function isn't working it would be nice if you posted the values you are passing since they could be a contributing factor.

For future reference, "this isnt working" doesn't tell us anything. What isn't working? Was there an error message? You get the point (I hope).

Ok, if there had been an error, i wouldve included it.

perhaps I shouldve been more clear.

if i DON'T try to change the font of the inherent font named, then it shows up in the proper place at the proper time. that is.. the function is completely operational (albeit messy) aside from the fact that i cannot enlarge the fontsize.

servers are still down, I'll try what you posted when they are back up.

THANKS!!
  Reply With Quote
07-13-10, 12:05 PM   #11
wellbeing
A Cliff Giant
Join Date: Oct 2009
Posts: 71
also, let me ask this, while i have your begrudging attn.

Is the only way to include custom sound/font/texture files to use SharedMedia or Ace libraries?

im trying to keep guild from having to download any dependencies for this, but would like to add a few sound files.
  Reply With Quote
07-13-10, 12:34 PM   #12
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
No. You can just put them in your addon folder and reference their location in your code (or reference the location of an in-game sound/texture). SharedMedia is for just that - SHARED media which any addon that supports it has access to.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
07-13-10, 01:08 PM   #13
wellbeing
A Cliff Giant
Join Date: Oct 2009
Posts: 71
Originally Posted by Seerah View Post
No. You can just put them in your addon folder and reference their location in your code (or reference the location of an in-game sound/texture). SharedMedia is for just that - SHARED media which any addon that supports it has access to.
Heard. Thx. I guess i was confused due to the fact that im currently unable to point to a font in my addon directory as part of the problem OP'd in this thread. i used "\Interface\AddOns\myaddonname\fonts\fontname.ttf" to attempt to do it with the fontstring:setfont. the error i get when trying to run is "err in line 65, setfont(), font not set."

this was done both before and after removing the inherent reference to gamefontnormal in my fontstring creation.

sigh.
  Reply With Quote
07-13-10, 01:19 PM   #14
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
When you did that, did you use double slashes? \\
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
07-13-10, 02:00 PM   #15
wellbeing
A Cliff Giant
Join Date: Oct 2009
Posts: 71
Originally Posted by Seerah View Post
When you did that, did you use double slashes? \\
good point, i tried both.
here is my code now:

when i call the function:
Code:
CreateText("test","TEST!!",25,-25,f,512,64,"TOP","TOP")
the function:

Code:
function CreateText(name,text,x,y,parent,w,h,relativeto,relativepoint)
  
    Parent = parent
  

  local Name = name
  local TextX = x
  local TextY = y
  local RelativeTo = relativeto
  local RelativePoint = relativepoint
  local TextWidth = w
  local TextHeight = h
  local Text = text

  local FrameLevel = 4

  local TextFrame = CreateFrame("FRAME",Name,Parent)
  TextFrame:ClearAllPoints()
  TextFrame:SetWidth(TextWidth)
  TextFrame:SetHeight(TextHeight)
  --local TextFrameFont = TextFrame:CreateFontString(nil, "BACKGROUND")
  --TextFrameFonttemp = TextFrame:CreateFontString(nil, "BACKGROUND",GameFontNormal)
  --local Path, Size, Flags = TextFrameFonttemp:GetFont()
  TextFrameFont = TextFrame:CreateFontString(nil, "BACKGROUND")
  TextFrameFont:SetText(Text)
  TextFrameFont:SetFont("\\Interface\AddOns\myaddonname\fonts\fontname.ttf", 20)

   
end
frustrashun.
  Reply With Quote
07-13-10, 02:03 PM   #16
Ailae
A Rage Talon Dragon Guard
 
Ailae's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 318
Code:
TextFrameFont:SetFont("Interface\\AddOns\\myaddonname\\fonts\\fontname.ttf", 20)
..is what Seerah meant.
__________________
Oh, the simulated horror!
  Reply With Quote
07-13-10, 02:42 PM   #17
wellbeing
A Cliff Giant
Join Date: Oct 2009
Posts: 71
Originally Posted by Ailae View Post
Code:
TextFrameFont:SetFont("Interface\\AddOns\\myaddonname\\fonts\\fontname.ttf", 20)
..is what Seerah meant.
hmm, ok.. i tried 3 several different ways, among them:

Code:
TextFrameFont:SetFont("\\Interface\\AddOns\\myaddonname\\fonts\\fontname.ttf", 20)
TextFrameFont:SetFont("Interface\\AddOns\\myaddonname\\fonts\\fontname.ttf", 20)
TextFrameFont:SetFont("\\Interface\AddOns\myaddonname\fonts\fontname.ttf", 20)
both generate this error:
Interface\AddOns\skillzreceive\skillzreceive5.lua:67: <unnamed>:SetText(): Font not set

line 67 is the line after the setfont:
TextFrameFont:SetText(Text)

i moved that line below the setfont() because the error I was receiving was referring to the settext line, leading me to believe that it needs a font in the fontstring to be able to assign text. im still unsure on whether that is actually the case or not, seeing as the current err still refers to the settext() line.


im certain that all the characters in the path are correct.
should i be registering the fonts elsewhere in the lua?
  Reply With Quote
07-13-10, 02:45 PM   #18
morkesh
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jun 2010
Posts: 15
did you close wow completely and open it again after moving your fonts to the folder? wow wont loads such things on the fly to the best of my knowledge.

also, i'm not sure but by the sound of what you'r trying to do (make a raidwarning style frame), wouldn't it be easier to use a messageframe?

Code:
local msgFrame = msgFrame or CreateFrame("Messageframe", "MyMsgFrame", UIParent)
msgFrame:SetWidth(500)
msgFrame:SetHeight(200)
msgFrame:SetPoint("TOP", UIParent)
msgFrame:SetTimeVisible(1.5) --how long it will stay visible
msgFrame:SetFadeDuration(1) --how long it will spend fading out
msgFrame:Show()
msgFrame:SetFont("Fonts\\MORPHEUS.ttf", 30, "OUTLINE")
then to add a message you'd use

Code:
msgFrame:AddMessage("This is a message!", r, g, b)
(r, g & b being 0-1 values representing the rgb ammount)

Last edited by morkesh : 07-13-10 at 02:53 PM.
  Reply With Quote
07-13-10, 10:09 PM   #19
wellbeing
A Cliff Giant
Join Date: Oct 2009
Posts: 71
Originally Posted by morkesh View Post
did you close wow completely and open it again after moving your fonts to the folder? wow wont loads such things on the fly to the best of my knowledge.

also, i'm not sure but by the sound of what you'r trying to do (make a raidwarning style frame), wouldn't it be easier to use a messageframe?

Code:
local msgFrame = msgFrame or CreateFrame("Messageframe", "MyMsgFrame", UIParent)
msgFrame:SetWidth(500)
msgFrame:SetHeight(200)
msgFrame:SetPoint("TOP", UIParent)
msgFrame:SetTimeVisible(1.5) --how long it will stay visible
msgFrame:SetFadeDuration(1) --how long it will spend fading out
msgFrame:Show()
msgFrame:SetFont("Fonts\\MORPHEUS.ttf", 30, "OUTLINE")
then to add a message you'd use

Code:
msgFrame:AddMessage("This is a message!", r, g, b)
(r, g & b being 0-1 values representing the rgb ammount)


mork, i could make sweet love to you. thank you.
  Reply With Quote
07-13-10, 11:30 PM   #20
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
You are also needlessly complicating your code:

Code:
function CreateText(name,text,x,y,parent,w,h,relativeto,relativepoint)
  
    Parent = parent
  

  local Name = name
  local TextX = x
  local TextY = y
  local RelativeTo = relativeto
  local RelativePoint = relativepoint
  local TextWidth = w
  local TextHeight = h
  local Text = text
Why are you making variables to store variables? Just use the function arguments directly.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » fontsting:SetFont


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off