Page 2 of 2

Re: Proportional font size according to window resolution

PostPosted: Thu May 29, 2014 8:49 pm
by Adolfo
Uwe...

Thanks a lot. Works like a charm.

From Chile
Adolfo

Re: Proportional font size according to window resolution

PostPosted: Thu May 29, 2014 10:14 pm
by James Bott
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

Code: Select all  Expand view
// 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

PostPosted: Fri May 30, 2014 10:43 am
by ukoenig
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 )

Image

Best regards
Uwe :lol: