Proportional font size according to window resolution

Re: Proportional font size according to window resolution

Postby Adolfo » Thu May 29, 2014 8:49 pm

Uwe...

Thanks a lot. Works like a charm.

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

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

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:
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

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 53 guests