Help the PSP 3D community grow! Vote for us below:


| | Getting Started/Help/Tutorials - Just bought your PSP and need some basic help using it or loading homebrew? |
Welcome to PSP3D.com - Sony PlayStation Portable News, Homebrew, Hacks, Reviews, Videos, Mods, Forums!
You are currently viewing our website as a guest, which gives you limited access to reply and interact to discussions and other members. By joining our free community, you will be able to post topics in the forums, communicate privately with other members, vote in polls, and access many other special features.
Registration is fast, simple, and absolutely free so join our community today!
|  | | 
02-25-2007, 02:09 AM
| | Member
My Mood: | | Join Date: Feb 2007
Posts: 45
Points: 73.56 Donate | | | LUA Guide: True Type Fonts Now this may be old news to some of you, but since I just spent some time doing google searches and couldn't find any guides specifically about this I decided to write one.
Step one: find a ttf font to use (I got several nice ones from Download Free Fonts @ 1001 Fonts .com)
load the font into your program with this: Code: myfont = Font.load("fontname.ttf") you can replace "myfont" with whatever name you want
then, you need to use either one of these to set the font size(if you don't, you won't be able to see anyting printed with the font): Code: myfont:setCharSize(width, height, Dx, Dy)
myfont:setPixelSizes(width, height) *edit* I didn't realize this before because I was using the variable name "font" for the fonts in my test program, but when setting the font size you need to use the variable name that you used to load the font - I.E., if you load a font into the variable verdana you set the size with verdana:setCharSize or verdana:setPixelSizes
the first goes by "point size", the second goes by actual pixels. Dx and Dy are the display resolution, not sure exactly how that part works
the following will print text using the font, then wait for input before ending the program: Code: green = Color.new(0,255,0)
screen:clear()
screen:fontPrint(myfont, 50, 100, "Font Test", green)
screen.flip()
while true do
pad = Controls.read()
if pad:start() then break
end
end
Last edited by Merick : 02-25-2007 at 03:09 PM.
Reason: to fix an error in the guide
| 
02-25-2007, 04:17 AM
| | Camouflage Condoms: They won't see you coming
My Mood: | | Join Date: Nov 2005 Location: Surrey, UK Age: 22
Posts: 1,310
Points: 212.38 Donate | | | Nice, but I don't code in Lua.
Would be nice to see one for C. | 
02-25-2007, 04:18 AM
| | Senior Member
My Mood: | | Join Date: Jun 2006 Location: Australia Age: 15
Posts: 263
Points: 1.33 Donate | | | lol ur mood is currently "freej"
loving it
__________________ "PLEASE INSERT POINTS PLEASE" | 
02-25-2007, 04:58 AM
| | Is Da Best PSP3D Member
My Mood: | | Join Date: Dec 2005 Location: England
Posts: 651
Points: 1.06 Donate | | | Great work! | 
02-25-2007, 06:05 PM
| | Member
My Mood: | | Join Date: Feb 2007
Posts: 45
Points: 73.56 Donate | | | Some more info:
when setting the font size, if you use zero for the width, then the width will be calculated proportionally to the height.
Also, when using screen:fontPrint you need to remember that the x/y coordinates are used for the bottom left corner of the first letter, not the top as with other screen drawing commands | 
02-25-2007, 06:17 PM
| | Designer
My Mood: | | Join Date: Jan 2006 Location: Oslo, Norway Age: 17
Posts: 2,342
Points: 23.16 Donate | | | will it become anti aliased? | 
02-25-2007, 07:36 PM
| | Member
My Mood: | | Join Date: Feb 2007
Posts: 45
Points: 73.56 Donate | | Quote:
Originally Posted by wilhel1812 will it become anti aliased? |
LOL, I'm just figuring this stuff out as I go along, and I have no idea what you mean by that
Another function I just figured out is getTextSize, used as: Code: myfont:getTextSize("text")["width"] --returns what the width of the text would be if
printed with the named font
or
myfont:getTextSize(text)["height"] --returns the height as an example of its use, here is a bit of code that will use a ttf and print text centered on the screen Code: myfont = Font.load("fontname.ttf")
myfont:setPixelSizes(0, 20)
function printCentered(font, y, text, color)
screen:fontPrint(font, 240 - ((font:getTextSize(text)["width"])/2), y, text, color)
end
screen:clear()
printCentered(myfont, 100, "Centered Text", blue)
screen.flip()
while true do
pad = Controls.read()
if pad:start() then break
end
end Doubleposted Message Below:
hmm..
setCharSize(width, height, Dx, Dy) makes the font size smaller than setPixelSizes(width, height) even if you use the same numbers for width and height. Anyone know why is works out that way?
Last edited by Merick : 02-25-2007 at 07:36 PM.
Reason: PSP3D.com Doublepost Preventer
| 
02-25-2007, 08:50 PM
| | Creator and Editor of PSP3D Radio
My Mood: | | Join Date: Nov 2005 Location: Dream Land, CA
Posts: 950
Points: 13.86 Donate | | | Dx and Dy are the number of pixels per [unit of mesurment]. The question is, which one? Is it pixels per point size or pixels per cm or inch?
__________________ My mayor is a Teflon coated slime bag
Hopefully he'll learn not to try and push quite possibly unconstitutional bills though the state assembly and then waste tax money fighting it in court. Plus, he has failed the bar exam 4 times  . Disclaimer: These are my opinions, and I am wholy responsible for them. | 
02-25-2007, 09:24 PM
| | Member
My Mood: | | Join Date: Feb 2007
Posts: 45
Points: 73.56 Donate | | well, the page that I found the functions on only has this basic info about them:
Font Font:setCharSize(number width, number height, number dpiX, number dpiY)
Changes the size of the current font to the specified point size height and width (if width is 0, it will be calculated proportional to the height for every character). dpiX and dpiY is the resolution of the display (see the Freetype documentation for details).
Font Font:setPixelSizes(number width, number height)
Changes the size of the current font to the specified pixel size height and width (if width is 0, it will be calculated proportional to the height for every character). (see the Freetype documentation for details).
that page has no detailed instructions on how to actually use them, I've only been able to learn this much by looking through a number of different pieces of code from various sites
the page where I found them: psp:lua_player:functions [psDevWiki]
I did do a short search for the freetype docs they mentioned, but I got tired of that and wanted to get back to my game engine
Last edited by Merick : 02-25-2007 at 09:26 PM.
| 
02-26-2007, 12:52 AM
| | Designer
My Mood: | | Join Date: Jan 2006 Location: Oslo, Norway Age: 17
Posts: 2,342
Points: 23.16 Donate | | Quote:
Originally Posted by Merick LOL, I'm just figuring this stuff out as I go along, and I have no idea what you mean by that | http://www.cambridgeincolour.com/tut...#anti-aliasing | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | | | Thread Tools | | | | Display Modes | Linear Mode |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off Points Per Thread View: 0.00 Points Per Thread: 15.00 Points Per Reply: 0.50 | | | | |