PSP3D Left Header
PSP3D Header Right
PSP3D Logo CraveOnline Logo
Help the PSP 3D community grow!
Vote for us below:


Vote on the PSP Top 200
PSP Top 200 - Games, Videos, Wallpapers, Files, Hacks, Homebrew

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!

Go Back PSP3D.com - Sony PlayStation Portable News, Homebrew, Hacks, Reviews, Videos, Mods, Forums > PSP Forums > Getting Started/Help/Tutorials
Tags: fontfonts [X]lua [X]programming [X]


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-25-2007, 02:09 AM
Merick's Avatar
Merick Merick is offline
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
Reply With Quote
  #2 (permalink)  
Old 02-25-2007, 04:17 AM
pj1115's Avatar
pj1115 pj1115 is offline
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
Send a message via MSN to pj1115
Nice, but I don't code in Lua.

Would be nice to see one for C.
Reply With Quote
  #3 (permalink)  
Old 02-25-2007, 04:18 AM
FreeJ's Avatar
FreeJ FreeJ is offline
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"
Reply With Quote
  #4 (permalink)  
Old 02-25-2007, 04:58 AM
sikheadtom's Avatar
sikheadtom sikheadtom is offline
Is Da Best PSP3D Member
My Mood:
 
Join Date: Dec 2005
Location: England
Posts: 651
Points: 1.06
Donate
Send a message via AIM to sikheadtom Send a message via MSN to sikheadtom
Great work!
__________________
SNES, PS1, PS2, PSP and PS3
Number of times reached 1000 posts: 3
Reply With Quote
  #5 (permalink)  
Old 02-25-2007, 06:05 PM
Merick's Avatar
Merick Merick is offline
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
Reply With Quote
  #6 (permalink)  
Old 02-25-2007, 06:17 PM
wilhel1812's Avatar
wilhel1812 wilhel1812 is offline
Designer
My Mood:
 
Join Date: Jan 2006
Location: Oslo, Norway
Age: 17
Posts: 2,342
Points: 23.16
Donate
Send a message via ICQ to wilhel1812 Send a message via AIM to wilhel1812 Send a message via MSN to wilhel1812 Send a message via Yahoo to wilhel1812
will it become anti aliased?
__________________
Reply With Quote
  #7 (permalink)  
Old 02-25-2007, 07:36 PM
Merick's Avatar
Merick Merick is offline
Member
My Mood:
 
Join Date: Feb 2007
Posts: 45
Points: 73.56
Donate
Quote:
Originally Posted by wilhel1812 View Post
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
Reply With Quote
  #8 (permalink)  
Old 02-25-2007, 08:50 PM
jcoolkatzerg's Avatar
jcoolkatzerg jcoolkatzerg is offline
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.
Reply With Quote
  #9 (permalink)  
Old 02-25-2007, 09:24 PM
Merick's Avatar
Merick Merick is offline
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.
Reply With Quote
  #10 (permalink)  
Old 02-26-2007, 12:52 AM
wilhel1812's Avatar
wilhel1812 wilhel1812 is offline
Designer
My Mood:
 
Join Date: Jan 2006
Location: Oslo, Norway
Age: 17
Posts: 2,342
Points: 23.16
Donate
Send a message via ICQ to wilhel1812 Send a message via AIM to wilhel1812 Send a message via MSN to wilhel1812 Send a message via Yahoo to wilhel1812
Quote:
Originally Posted by Merick View Post
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
__________________
Reply With Quote
Reply

« 3.10 OE-A to 3.03 OE-C | 3.03 oe »



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Points Per Thread View: 0.00
Points Per Thread: 15.00
Points Per Reply: 0.50

Similar Threads
Thread Thread Starter Forum Replies Last Post
The Ultimat Guide To Dark_AleX's Custom Firmwares The Ex Getting Started/Help/Tutorials 35 01-31-2008 01:27 AM
The n00b-proof D-Viant Flash 2.80 guide A.d.i.d.a.Z Getting Started/Help/Tutorials 6 01-01-2007 08:33 PM
[TUTORIAL] LUA: The Begginer Lesson rikardo_92 Getting Started/Help/Tutorials 16 09-17-2006 09:22 AM
LUA Player v0.20 Released! Robert A. Homepage News 5 06-05-2006 07:52 PM
Interesting bug found in Lua Player Demo V0.16 badg0r General PSP Discussion 2 03-11-2006 03:48 PM





Crave Partner Sites: CraveOnline.com | DVDFile.com | PSP3D.com | ComingSoon.net | SuperHeroHype.com | RedBalcony.com | ActionTrip.com | CraveLyrics.com
Soundtrack.net | CraveFix.com | SpikedHumor.com | RPGamer.com | TattooNow.com | ImpactWrestling.com | SeekLyrics.com | PedalBMX.com | WildKO.com
vidKing.com | StrategyInformer.com | HHdb.com | RapLeagues.com | HipHop-Lyrics.com | Cravecocktails.com | ThePhatPhree.com | RideJudge.com | HottieSpots.com

PSP3D Footer Left Powered by Custom vB Version 5.1.0 for Crave Online Media, LLC.
Copyright © 2000 - 2007, Jelsoft Enterprises Ltd. and PSP3D.com.
LinkBacks Enabled by vBSEO 3.0.0 RC8

All times are GMT -4. The time now is 04:37 PM.
PSP3D Footer Right