Proportional font size according to window resolution

Proportional font size according to window resolution

Postby Adolfo » Tue May 27, 2014 9:40 pm

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
Last edited by Adolfo on Wed May 28, 2014 8:53 pm, edited 1 time in total.
;-) Ji,ji,ji... buena la cosa... "all you need is code"

http://www.xdata.cl - Desarrollo Inteligente
----------
Asus TUF F15, 32GB Ram, 1 TB NVME M.2, 1 TB SSD, GTX 1650
User avatar
Adolfo
 
Posts: 846
Joined: Tue Oct 11, 2005 11:57 am
Location: Chile

Re: Proportinal font size according to window resolution

Postby Enrico Maria Giordano » Wed May 28, 2014 9:37 am

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
User avatar
Enrico Maria Giordano
 
Posts: 8378
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Proportinal font size according to window resolution

Postby Rick Lipkin » Wed May 28, 2014 12:57 pm

Adolfo

Take a look at the .ppo of your program code.. Define Font ..
Code: Select all  Expand view

DEFINE FONT oFont NAME "Courier New" SIZE 0,-10 BOLD of oPRINT
 

Pre-processes to:
Code: Select all  Expand view

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
User avatar
Rick Lipkin
 
Posts: 2636
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Proportinal font size according to window resolution

Postby Adolfo » Wed May 28, 2014 1:05 pm

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
;-) Ji,ji,ji... buena la cosa... "all you need is code"

http://www.xdata.cl - Desarrollo Inteligente
----------
Asus TUF F15, 32GB Ram, 1 TB NVME M.2, 1 TB SSD, GTX 1650
User avatar
Adolfo
 
Posts: 846
Joined: Tue Oct 11, 2005 11:57 am
Location: Chile

Re: Proportinal font size according to window resolution

Postby Rick Lipkin » Wed May 28, 2014 1:12 pm

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  Expand view

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
User avatar
Rick Lipkin
 
Posts: 2636
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Proportinal font size according to window resolution

Postby James Bott » Wed May 28, 2014 2:40 pm

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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Proportinal font size according to window resolution

Postby Rick Lipkin » Wed May 28, 2014 5:55 pm

Opps .. sorry for my error .. James is correct .. the .ppo should have resolved to -10 .. I just pulled the wrong line :(

Rick
User avatar
Rick Lipkin
 
Posts: 2636
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Proportinal font size according to window resolution

Postby James Bott » Wed May 28, 2014 8:19 pm

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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Proportinal font size according to window resolution

Postby Adolfo » Wed May 28, 2014 8:48 pm

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.
;-) Ji,ji,ji... buena la cosa... "all you need is code"

http://www.xdata.cl - Desarrollo Inteligente
----------
Asus TUF F15, 32GB Ram, 1 TB NVME M.2, 1 TB SSD, GTX 1650
User avatar
Adolfo
 
Posts: 846
Joined: Tue Oct 11, 2005 11:57 am
Location: Chile

Re: Proportinal font size according to window resolution

Postby ukoenig » Wed May 28, 2014 8:54 pm

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 :?:
Last edited by ukoenig on Fri May 30, 2014 10:39 am, edited 3 times 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: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Proportional font size according to window resolution

Postby Adolfo » Wed May 28, 2014 9:08 pm

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
;-) Ji,ji,ji... buena la cosa... "all you need is code"

http://www.xdata.cl - Desarrollo Inteligente
----------
Asus TUF F15, 32GB Ram, 1 TB NVME M.2, 1 TB SSD, GTX 1650
User avatar
Adolfo
 
Posts: 846
Joined: Tue Oct 11, 2005 11:57 am
Location: Chile

Re: Proportional font size according to window resolution

Postby ukoenig » Wed May 28, 2014 9:14 pm

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:
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: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Proportional font size according to window resolution

Postby James Bott » Wed May 28, 2014 10:58 pm

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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Proportional font size according to window resolution

Postby Adolfo » Thu May 29, 2014 2:06 pm

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
;-) Ji,ji,ji... buena la cosa... "all you need is code"

http://www.xdata.cl - Desarrollo Inteligente
----------
Asus TUF F15, 32GB Ram, 1 TB NVME M.2, 1 TB SSD, GTX 1650
User avatar
Adolfo
 
Posts: 846
Joined: Tue Oct 11, 2005 11:57 am
Location: Chile

Re: Proportional font size according to window resolution

Postby ukoenig » Thu May 29, 2014 4:40 pm

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  Expand view

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 :?:
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: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: AdsBot [Google], Google [Bot] and 38 guests