Uwe...
Thanks a lot. Works like a charm.
From Chile
Adolfo
Proportional font size according to window resolution
Re: Proportional font size according to window resolution
Ji,ji,ji... buena la cosa... "all you need is code"
http://www.xdata.cl - Desarrollo Inteligente
----------
Lenovo Legion Y520, 16GB Ram, 1 TB NVME M.2, 1 TB SSD, GTX 1050
http://www.xdata.cl - Desarrollo Inteligente
----------
Lenovo Legion Y520, 16GB Ram, 1 TB NVME M.2, 1 TB SSD, GTX 1050
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Re: Proportional font size according to window resolution
Adolfo,
Here is my test code. I was planning to add the automatic calculation of the font width based on the longest line and the screen resolution, but I know you are anxious for a working model.
The font width calculation is complicated since the relationship between font width and line length is not linear so finding a formula is tedious.
James
Here is my test code. I was planning to add the automatic calculation of the font width based on the longest line and the screen resolution, but I know you are anxious for a working model.
The font width calculation is complicated since the relationship between font width and line length is not linear so finding a formula is tedious.
James
Code: Select all
// Purpose : To display x Lines of text at maximum size
// Author : James Bott, jbott at compuserve dot com
// Date : 5/28/2014
// Language: FiveWin/xHarbour
#include "fivewin.ch"
Function Main()
local oWnd
local aItems:={}
local nLines:=6 // just for testing
//local nHorizRes := GetSysMetrics( 0 )
//local nVertRes := GetSysMetrics(1)
//msgInfo( GetSysMetrics(1))
for i=1 to nLines
aadd(aItems,"Line "+ltrim(str(i)) )
//aadd(aItems,"Line "+ltrim(str(i)) + " KKKKK<")
next
//aItems[2]:=replicate("K",14)+"<"
aItems[3]:="856.5 max tons bruto"
aItems[4]:="250.3 tons tercer turno"
aItems[5]:="153 operarios"
aItems[6]:="Recepcion abierta"
define window oWnd
activate window oWnd maximized on init displayItems(aItems)
return nil
Function DisplayItems(aItems)
local nWidth:=45 //64 //50 // font width
local nHeight:=0
local oWnd:= wndMain()
local nMax:=0
// Size of longest line
for i= 1 to len(aItems)
nMax:= max(nMax,len(aItems[i]))
next
// Need to figure how to calculate the font width
// based on the length of the longest line so that it takes up the entire
// width of the screen. Will need to use screen resolution also.
// nWidth :=
//msgInfo( nMax, "X = nMax line length")
//msgInfo( len(aItems[2]), "Line length")
//msgInfo( nWidth, "Y = Font Width")
// Calculate font height based on number of lines
// The -30 is to compensate for the space between the lines
nHeight:= ( oWnd:nHeight -30)/ len(aItems)
//msgInfo( nHeight, "Font height")
// msgInfo( oWnd:nHeight / len(aItems) )
define font oFont name "arial" size nWidth, nHeight
n:=1
for i=1 to len(aItems)
@ n, 10 say aItems[i] font oFont pixels of oWnd
n:= i*nHeight
next
return nil
// eof
Re: Proportional font size according to window resolution
I added some more options
( maybe some more can be added like :
predefined window-size like 800 x 600, 1024 x 768 .... )
1. Top / Left textposition ( bottom / right the same )
2. a checkbox for optional window-width adjusted to the longest textline
( a defined Top and Left, will center the text vertical and horizontal inside the window )
Best regards
Uwe
( maybe some more can be added like :
predefined window-size like 800 x 600, 1024 x 768 .... )
1. Top / Left textposition ( bottom / right the same )
2. a checkbox for optional window-width adjusted to the longest textline
( a defined Top and Left, will center the text vertical and horizontal inside the window )
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.
i work with FW.
If you have any questions about special functions, maybe i can help.