Possible to calculate Text-Width and Hight in Pixel ?

Post Reply
User avatar
ukoenig
Posts: 3981
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

Possible to calculate Text-Width and Hight in Pixel ?

Post by ukoenig »

Hello,

is it possible to calculate the overall Widht and Hight
of a written Text for a special font ?

In my Internet jobs i used :

Code: Select all


Approximate Conversion from Points to Pixels
(and Ems and %)
Here's a chart that converts points to pixels (and ems and %). 
It's an approximation, which will depend on font, browser and OS, 
but it's a good starting point.

Points     Pixels    Ems      Percent
---------------------------------------
 6          8         0.5         50
 7          9         0.55       55
 7.5      10          0.625      62.5
 8         11         0.7         70
 9         12         0.75       75
10        13          0.8         80
10.5      14         0.875      87.5
11        15          0.95       95
12        16          1          100
13        17          1.05      105
13.5     18          1.125    112.5
14        19         1.2        120
14.5     20         1.25       125
15        21         1.3        130
16        22         1.4        140
17        23         1.45      145
18        24         1.5        150
20        26         1.6        160
22        29         1.8        180
24        32         2           200
26        35         2.2        220
27        36         2.25      225
28        37         2.3        230
29        38         2.35      235
30        40         2.45      245
32        42         2.55      255
34        45         2.75      275
36        48         3          300
           
Can somebody tell me,
how i can format text in this part ( in the moment i use spaces ) ?
Tabs don't work.

Regards
Uwe :lol: [/code]
Last edited by ukoenig on Sat Apr 05, 2008 5:49 pm, edited 1 time in total.
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
Posts: 3981
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

Pixel of Text Widht and Hight

Post by ukoenig »

Hello Enrico,

I want to use it inside FW
as a sample :

I have a Bitmap Pixel Hight = 20 and Width = 400 in Pixel.

Now i want to center a text as a sample > This is a Test <.
That means : Start-pos from left = (400 - Text-length) / 2
Top-Pos = ( 20 - Font-height ) / 2
In Fivewin, there is the Function < TextOut > to draw text on a bitmap.
This function works only with given values.

Now, i want the position calculated.

Regards

Uwe
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

Uwe,

Try getTextWidth( hDC, cText )

James

(edited by Antonio to change hWnd into hDC)
User avatar
ukoenig
Posts: 3981
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

Centered Text on Bitmap

Post by ukoenig »

Hello James,

That works fine.

I try to explain, what i do :
1. I created a long bitmap-resource in a dialog ( container ).
2. A small bitmap just 30 x 15 i expand to the resource.
3. I fill the expanded bitmap with a desired color, brush ...

Image

Code: Select all


// because the bitmap is expanded, i must look for the new size

FUNCTION ONPAINT(hDC,oBmp,nVColor,nBColor,nTColor,cText)

......
......

nTXTLG := GetTextWidth( hDC, cText )     // New
nBMPLONG  := oBmp:Super:nWidth() 
nBMPHIGHT := oBmp:Super:nHeight() 
nFONTHIGHT := oBFont:nInpHeight * -1 
nLEFT := (nBMPLONG - nTXTLG) / 2          // it centers the text

// still i have to calculate the top of the text
// There is no function GetTextHight( hDC, cText )
// A dialog-title will have allways a small bitmap-hight
// I can do this ( not a clean way ) :
// The Height 12, 14, 16 and so on are not pixel
// so i have to adjust the Font-Hight with the table from above.

nNEWHEIGHT := 10

IF nFONTHEIGHT = 10 
    nNEWHEIGHT := 13
ENDIF
IF nFONTHEIGHT = 12 
    nNEWHEIGHT := 16
ENDIF
....
.....

// Top of Text inside of a Bitmap
// ----------------------------------- 
nTOP := ( nBMPHEIGHT - nNEWHEIGHT ) / 2

.....
.....
.....

Thanks

Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
Post Reply