Quantcast
Channel: SCN : All Content - PowerBuilder Developer Center
Viewing all articles
Browse latest Browse all 2935

has anyone done automatic font sizing based on field content?

$
0
0

Our client has seen a competing product that automatically sizes text into a fixed text area on a report (not auto-height field), shorter text appears larger, longer text appears smaller (wraps if needed).

 

Has anyone done anything similar in PB? (Or any other language)

 

I know I can do something like this:

Create a Device Context (or get a handle to screen context)

Create a font handle based on font used for the field I'm adjusting

Use GetTextExtentPoint32 to find out how big the text will be (length/height, no CR/LF/TAB allowed)

Find out what percentage of space the string takes up based on size of the text box it's destined for

Adjust the font point size by the percentage difference (point size can be changed in 1/10th increments)

 

Example:

Text box is 185x13 pixels, 10pt font

Target text is 200x12

% to reduce is 92.5

12 * .925 = 11.1

So the new text should fit into the 185 long text box if it's 11.1point

 

The numbers here will probably need adjusting since I think PB always has some padding in a text box

 

We want to be able to do this for the client, but are afraid that it's going to slow down the reports by a huge amount. The reports will have hundreds of rows with auto-sized text (and possibly more than one field per row).

 

It will also mean adjusting all the affected reports to be measured in pixels so we can do apples 2 apples compare of textextent and destination box. (PITA, but necessary)

 

Any ideas welcome. I'm not looking forward to this much Windows API coding, especially when it may turn out to be extremely slow, or not even work properly.

 

Thanks


Viewing all articles
Browse latest Browse all 2935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>