Page 1 of 2

Proportional font size according to window resolution

Posted: Tue May 27, 2014 9:40 pm
by Adolfo
Hi Fivewinners

I have to do something like this...

I have a text of N lines, 10 is the max
I need to show this text accordiong to the number of used lines
Ex.
5 used lines, I need a Font which Height is 20% of WndHeight
10 used lines, a font with 10% height of WndHeight

How do I define this font in terms of size
Must I create 10 different fonts according to the possible heights the may have.
Screen height in pixels is fixed, 1050 pixels, the only sure thing I know

Any help will be appreciated

From Chile
Adolfo

Re: Proportinal font size according to window resolution

Posted: Wed May 28, 2014 9:37 am
by Enrico Maria Giordano
Adolfo,
Adolfo wrote:Must I create 10 different fonts according to the possible heights the may have.
No, you can create the required font "on the fly".

EMG

Re: Proportinal font size according to window resolution

Posted: Wed May 28, 2014 12:57 pm
by Rick Lipkin
Adolfo

Take a look at the .ppo of your program code.. Define Font ..

Code: Select all

DEFINE FONT oFont NAME "Courier New" SIZE 0,-10 BOLD of oPRINT
 
Pre-processes to:

Code: Select all

oFontB    := TFont():New("Ms Sans Serif",,-6,.F.,.T. ,,,,.F. )
 
You can use the native pre-processed code to insert your variables for size, weight, etc ...

Rick Lipkin

Re: Proportinal font size according to window resolution

Posted: Wed May 28, 2014 1:05 pm
by Adolfo
Thanks Rick

I see a -10 in the "define clause"

a 6 in the call to tfont:new().

This 6, what is it, pixel, dpi, logic units ?
Why -10 translates to 6 ?

There must be a way to assign a Height in pixels to a font, and as Enrico say, maybe on the fly ?

Thanks again

From Chile
Adolfo

Re: Proportinal font size according to window resolution

Posted: Wed May 28, 2014 1:12 pm
by Rick Lipkin
Adolfo

You may have to play around with the pixel size, Here are some examples I have used for an Invoice print routine:

Code: Select all

oFont8b   := TFont():New( "Times New Roman", 0,-8, .F.,.T. , , , ,.F.,,,,,,, oPRINT, )
oFont10   := TFont():New( "Times New Roman", 0,-10,.F.,.F. , , , ,.F.,,,,,,, oPRINT, )
oFont10b  := TFont():New( "Times New Roman", 0,-10,.F.,.T. , , , ,.F.,,,,,,, oPRINT, )
oFont12ib := TFont():New( "Times New Roman", 0,-12,.F.,.T. , , , ,.T.,,,,,,, oPRINT, )
oFont12b  := TFont():New( "Times New Roman", 0,-12,.F.,.T. , , , ,.F.,,,,,,, oPRINT, )
oFont14b  := TFont():New( "Times New Roman", 0,-14,.F.,.T. , , , ,.F.,,,,,,, oPRINT, )
oFont24b  := TFont():New( "Times New Roman", 0,-24,.F.,.T. , , , ,.F.,,,,,,, oPRINT, )
 
Rick Lipkin

Re: Proportinal font size according to window resolution

Posted: Wed May 28, 2014 2:40 pm
by James Bott
Adolpho,
DEFINE FONT oFont NAME "Courier New" SIZE 0,-10 BOLD of oPRINT

Pre-processes to:
oFontB := TFont():New("Ms Sans Serif",,-6,.F.,.T. ,,,,.F. )
Why -10 translates to 6 ?
Ricks example was not accurate. It actually translates to:

oFont := TFont():New( "Courier New", 0, -10,, .T.,,,,,,,,,,, oPRINT, )

So there is no change in the font spec in points by the preprocessor.

Regards,
James

Re: Proportinal font size according to window resolution

Posted: Wed May 28, 2014 5:55 pm
by Rick Lipkin
Opps .. sorry for my error .. James is correct .. the .ppo should have resolved to -10 .. I just pulled the wrong line :(

Rick

Re: Proportinal font size according to window resolution

Posted: Wed May 28, 2014 8:19 pm
by James Bott
Adopho,

Here are some other things to consider.

Is the window resizable? If so, are the font sizes going to need to be resized so the same number of lines still fits in the window?

Does the window have toolbars and/or a status bar? If so, then the client height of the window must be used instead of the window height.

Are the lines going to be wrapped if they don't fit in the window width?

At what point is the font too small to read (and this varies with the user), and what will be done with the font height at that point?

You also need to account for the "leading" (spacing) between the lines.

Why do you want do this as windows is designed to line-wrap and scroll to handle text that may not fit already?

Regards,
James

Re: Proportinal font size according to window resolution

Posted: Wed May 28, 2014 8:48 pm
by Adolfo
James

This module is part of a production software.
I need to show an information screen on 2 ofices. The values shown are numbers, production variables, like tons of a product, number of items, etc etc.

The window is not resizable. No Menu, No toolbar, No status bar, in fact there's no human interaction (mouse or keyboard) with the module that shows the information. The app starts with windows and keeps on until they turn the pc off
I have it working with a fixed numer of lines and fixed font size.

The problem is that the number of lines will change.
From 1 to 3, I use the same font size, then I'll have to change it to make them all appear on the screen.
When sensible info is to be shown, a user will delete all the lines, and use only 1 to 3 lines. If not, the system creates them according to some function result.

We are going to locate the screens on the wall, with a micro Pc attached to them, they are 42 inches monitors, one in a very large office, which can be seen from the outside thru big windows, the other on a production manager office, but he insisted on having a 42 monitor too, placed on the wall.
I can change the background, place a picture fullfilling the whole screen, show 4 lines of text with fixed sizes.. but my problem begins with more than 5 lines (up to 10), where I have to give each line the same heigth.

Thats why I'm trying to calculate the size according to a percentage of the heigth of the window.

PD: I know others managers in the factory will ask for the app once it's installed on the poduction center, there I'll have multiple resolutions screens...
Now, that's my problem.

Re: Proportinal font size according to window resolution

Posted: Wed May 28, 2014 8:54 pm
by ukoenig
Adolfo,

I created a a test, to do the needed calculation related to window-height and selected rows.
The basic / selected fontstyle- and size is saved inside a DBF
You can modify the fontsize with 2 factors : window-height and line-numbers.

10 lines are defined with a multiline-get
I can select, how many lines I want to display
Next I can change the window-height and the font-size changes related to the window-height.
Fontstyle and color can be changed at runtime.
Maybe the logic / basic and info, You are looking for ?

selected window min-height with 5 lines of 10

Image

selected window max-height with 5 lines of 10

Image

Best regards
Uwe :?:

Re: Proportional font size according to window resolution

Posted: Wed May 28, 2014 9:08 pm
by Adolfo
UWE

Thanks for your help.
The problem is that the calculation must be automatic.

Would you mind sending me the routine to calculate the sizes, please. Maybe I can "create" a solution that fits me.

Somewhere I found that 1pt is 1.3333 pixels, didn't try it, but this afternoon I must find something to solve the problem.

Thansk to you all.

From Chile
Adolfo

Re: Proportional font size according to window resolution

Posted: Wed May 28, 2014 9:14 pm
by ukoenig
Adolfo,

The download link.
The test is not 100 % ready, but maybe You find the needed infos.
I used a FACTOR for the different window-sizes ( height ).
Select a WINDOW-size from the combo and You will get different fontsizes.
Window-sizes used for the test : 800 x ( 500, 550, 600, 650, 700 )
Defined font-resize-factors : 1, 1.5, 2.0, 2.5, 3.0

Download :
http://www.pflegeplus.com/DOWNLOADS/Testfont1.zip

best regards
Uwe :lol:

Re: Proportional font size according to window resolution

Posted: Wed May 28, 2014 10:58 pm
by James Bott
Adolfo,

OK, I have a crude working example, but there may be a problem with line length. Is the length fixed? Or, better, what is the maximum length.

The length matters since the font has to be reduced to a size that the entire line will fit on the screen. Yes, the width could just be reduced, but if the height is too high it might be hard to read.

Could you provide some sample text lines?

James

Re: Proportional font size according to window resolution

Posted: Thu May 29, 2014 2:06 pm
by Adolfo
Sure James...

This is the longets text they would enter.

"856.5 max tons bruto"
"250.3 tons tercer turno"

Maybe 30 characters max. All the others are like.

"153 operarios"
"Recepcion abierta"

Thanks.
From Chile
Adolfo

Re: Proportional font size according to window resolution

Posted: Thu May 29, 2014 4:40 pm
by ukoenig
The final solution CALCULATES the fontsize, related to the number of lines and selected window-height.
The button < Windows > opens a second window and calculates the fontsize to fill the window-height.
I can adjust the window-width to the longest textline if needed.
Any window-size can be defined, to display the textlines.

Image

I can calculate / adjust the window-width related to the longest text.

Font-size calculated using 2 lines :

Image

Function to calculate the NEW font-size for the destination-window

Code: Select all

FUNCTION FONT_ADJ()
LOCAL nPoints := 10 // start-size
LOCAL nLines := VAL( SUBSTR( cDrawStyle, 1, 2 ) ) // lines from combo

// 1pt = 1.3333 pixels
DO WHILE .T.
     IF nPoints * 1.333 * nLines > nFWinH // defined window-height
          EXIT
     ENDIF
     nPoints++
ENDDO
aFTYPE[3] := nPoints // new fontsize

// create NEW fontsize related to window-height and lines
DeleteObject(oFont3) 
oFont3 := TFont():New( ALLTRIM( aFTYPE[1] ), + ;
             aFTYPE[2], aFTYPE[3], .F., aFTYPE[4], aFTYPE[5],0,0, aFTYPE[6], aFTYPE[7] ) 

RETURN( NIL )
 
best regards
Uwe :?: