cancel
Showing results for 
Search instead for 
Did you mean: 

PowerBuilder 12.5 How to get the Text Size

Former Member
0 Kudos

Hello guys,

I searched a lot to find a way to get the size of a text (both width and height) of a text. Found some posts, mostly pointing to the of_getTextSize on PFC, or the GetTextExtentPoint32A (which is used by of_getTextSize).

The difficulty I'm having is that the Height is always returning 16, independent of the font size I use. Seems like 16, converted to PBUnits gives me the correct height to a size 8 Arial or so. Can you help me figure it out? I'm on a Windows 7 SP1 32bit machine.

Also I'm trying to get a list of fonts from Windows. I tried using the ChooseFont from comdlg32.dll, but the font list is different from the one PB shows. The same is true if I use "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts".

I found what seems to be the correct list at "HKCU\Software\Microsoft\Shared Tools\Panose", this seems to be the same font list PB uses (for the dropDown on static text and so), but what the heck is this Panose thing? Do you know if this is right way to go?

So that you know, I'm creating a dynamic DW where the user can format the font face, size, etc.

I've attached a piece of my test case.

Thanks a lot

Daniel

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Daniel;

  I do a similar thing in my STD Integrated Framework. Since PB is now Unicode - here is the SDK mapping that I use ...

   Function boolean    GetTextExtentPoint32   (ulong hDC, string tex, long len, REF struct_size size)                         LIBRARY "GDI32.dll" alias for "GetTextExtentPoint32W"

The struct_size structure declaration is:

    long        sl_width

    long        sl_height

My PowerScript code is ...

Constant Integer wmGetFont = 49  // hex 0x0031

Integer li_Len

uLong   lul_Hdc

ulong   lul_Handle

ulong   lul_hFont

struct_size   lo_str_size

li_Len   = len ( text )         // Get text length

lul_Handle = Handle ( this )    // Get objects handle

lul_Hdc  = GetDC( lul_Handle )  // create a Device Context

lul_hFont = Send ( lul_Handle, wmGetFont, 0, 0 ) // Get the font in use

SelectObject ( lul_Hdc, lul_hFont )  // Copy "text" into the DC

// Get the size of the text.

IF GetTextExtentPoint32 ( lul_Hdc, Text, li_Len, lo_str_size ) = FALSE Then   // Point size OK to use?

   ii_rc = -1 // NO=>Set "bad" RC

else

   THIS.width = PixelsToUnits (lo_str_size.sl_Width + 6, xPixelsToUnits!) // YES=>Compute actual Width

   THIS.height = PixelsToUnits (lo_str_size.sl_Height + 2, yPixelsToUnits!) // Compute actual Height

   ii_rc = 0  // Set "good" RC

END IF

HTH
Regards ... Chris

PS: No idea at the moment of how to find the active / current fonts.

Former Member
0 Kudos

Chris, Thanks for the quick response, but I got the same result.

For your "this" at lul_Handle = Handle ( this ) I used the static text on my window, not sure if that's correct.


Still, I only get 16 for the lo_str_size.sl_Height, even if if my st has font size 8 or 16 or 28....

(i change it dynamically before calling the text size, so I could afterwards ajust the width and height)

The original st has font Arial, size 8

My test button:

st_example.FaceName = 'Arial' // 'Courier New'

st_exemplo.TextSize = -16 // -8 // -28

// yield()

wf_newTextSize(st_example)

Former Member
0 Kudos

Chris, so that you know, I used a different approach, not very happy with it, but it worked. I create a auxiliary DW, with a dummy column that I created dynamically. I guess I could've just used the 1 column on the DW.

It's in this page: http://codeverge.com/sybase.powerbuilder.datawindow/how-to-get-size-of-a-autosize/834310

This works on a single row single column (with autosize height on):

string ls_text

integer li_height

ls_text = "my text"

dw_test.Modify ("create column( id="...band=Detail....height.autosize=yes...font.face='Arial'.....font.height='-20'....etc)

dw_test.Insertrow (0)

dw_test.Object.Data [1, 1] = ls_text

dw_test.deleterow(dw_test.insertrow(0))

li_height = Integer(dw_test.describe("evaluate('rowheight()',1)"))

As I said, not happy, but it worked.

Thanks a lot.

Former Member
0 Kudos

"Kool" tip .. thanks!  

Answers (0)