FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Possible to calculate Text-Width and Hight in Pixel ?
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Possible to calculate Text-Width and Hight in Pixel ?
Posted: Sat Apr 05, 2008 01:56 PM
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 :

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 :-) [/code]
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.
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Possible to calculate Text-Widht and Hight in Pixel ?
Posted: Sat Apr 05, 2008 03:08 PM

If it is HTML then you have to use tables.

EMG

Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Pixel of Text Widht and Hight
Posted: Sat Apr 05, 2008 03:27 PM

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.
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Possible to calculate Text-Width and Hight in Pixel ?
Posted: Sat Apr 05, 2008 05:52 PM

Uwe,

Try getTextWidth( hDC, cText )

James

(edited by Antonio to change hWnd into hDC)

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Centered Text on Bitmap
Posted: Sat Apr 05, 2008 06:52 PM
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 ...



// 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 :-)
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.

Continue the discussion