Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Measuring a letter.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
TokenHerbz




PostPosted: Mon Aug 28, 2006 10:12 am   Post subject: Measuring a letter.

Hi, i want to know how i can measure how many pixles, both Vertically, and Horrizontally a letter takes.

Example would be, like "X" takes more then "i"

"X" --X is wider
"i"

Ta -- T is taller

As you see, i there is a difference, and i want to beable to get precise measurements for the letters.


Any suggestions?
Sponsor
Sponsor
Sponsor
sponsor
Ultrahex




PostPosted: Mon Aug 28, 2006 11:26 am   Post subject: (No subject)

Ok this is not so much TURING, but anyhow

basically it depends on which font you are using, or are you talking about the default font in Turing Console ?

Im just curious why you are doing this also.. is there a particular reason?

Maybe theres an easier solution that is why i am saying.
Clayton




PostPosted: Mon Aug 28, 2006 1:47 pm   Post subject: (No subject)

Font.Height and Font.Width, however, whenever a letter is printed (i believe) each letter takes up the same amount of space on the screen, eg, a and A each take up the same amount of space on the screen, "a" just has more white space
neufelni




PostPosted: Mon Aug 28, 2006 2:50 pm   Post subject: (No subject)

Here is a screensaver-like program that I made a while ago. It determines the length in pixels of different strings so that they all correctly bounce off the edge of the screen. You can use a similar method for determining the length and height of individual letters.
code:
View.Set ("graphics: max; max, nobuttonbar, nocursor, offscreenonly")
colorback (7)
cls

var font : int := Font.New ("Arial:20")
var words : array 1 .. 3 of string := init ("short phrase", "a bit longer prase", "this is the longest phrase")
var x : int := floor (maxx / 2)
var y : int := floor (maxy / 2)
var x2 : int := 1
var y2 : int := 1
var col : int := Rand.Int (40, 100)
var oldnum : int
var xcheck : int := x
var check : int := 0
var len : int := 0

var i : int := 0
var num : int := Rand.Int (1, 3)
loop
    xcheck := x
    check := 0
    if i = 1000 or i = 0 then
        oldnum := num
        loop
            num := Rand.Int (1, 3)
            exit when num not= oldnum
        end loop
        col := Rand.Int (40, 100)
        i := 0
        Font.Draw (words (num), x, y, font, col)
        loop
        if xcheck >= maxx then
            exit
            end if
            if whatdotcolor (xcheck, y) = 7 then
                check += 1
            elsif whatdotcolor (xcheck, y) not= 7 then
                check := 0
            end if
            xcheck += 1
            exit when check = 20
        end loop
        loop
            xcheck -= 1
            exit when whatdotcolor (xcheck, y) not= 7
            len := xcheck - x
        end loop
    end if
    Font.Draw (words (num), x, y, font, col)
    x += x2
    y += y2
    if x + len = maxx or x = 0 then
        x2 *= -1
    elsif y + 20 = maxy or y = 0 then
        y2 *= -1
    end if
    i += 1
    delay (10)
    View.Update
    cls
end loop
TokenHerbz




PostPosted: Mon Aug 28, 2006 3:50 pm   Post subject: (No subject)

Basically i want any words i enter, to be perfectly centerd in a box of any size..
Clayton




PostPosted: Mon Aug 28, 2006 5:29 pm   Post subject: (No subject)

then all you need/want is Font.Height and Font.Width, F9 them to figure out how to use them (they are both fcns if memory serves...) and you should be good to go Very Happy
Clayton




PostPosted: Mon Aug 28, 2006 5:37 pm   Post subject: (No subject)

i looked into it a bit deeper and found that Font.Height does not exist (although im sure ive seen it used somewhere before, hmmm...), the next best thing that i can see is Font.Sizes, which returns all of the specs of a font (height, ascent descent, internal leading, and exernal leading). Font.Sizes is regrettably a procedure, so it mercilessly changes all of your size variables' values within the proc, but its the next best thing you could use for the height of a font (note: font not letter
Cervantes




PostPosted: Wed Aug 30, 2006 9:42 pm   Post subject: (No subject)

As has been mentioned, Font.Width.

For height, you can just manage that yourself if there's nothing to do it for you. You know how you say, "I want Times New Roman size 12"? 12 is the height of the font, in pixels. Of course, not every character reaches up that high. It's the height of the tallest of the characters.
Sponsor
Sponsor
Sponsor
sponsor
TheOneTrueGod




PostPosted: Fri Sep 01, 2006 2:56 pm   Post subject: (No subject)

Research Font.Sizes... Check the sample program.

Font.Sizes(font,a,b,c,d : int)

a-c I believe will get you the standard height, though some letters may go above this...

if the font size is set to 12, I don't think its allways going to be 12.

Also, the letters are only equally spaced if you choose that type of font (For example: lucida consol)
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: