forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Font size in a graphics window

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+
View previous topic :: View next topic  
Author Message
aebolzan



Joined: 06 Jul 2007
Posts: 229
Location: La Plata, Argentina

PostPosted: Fri Mar 26, 2010 5:47 pm    Post subject: Font size in a graphics window Reply with quote

I am using a graphics window (%gr) and, after plotting some data using either call draw_point@ or draw_polyline@, I want to add some text on the window. For this purpose I call each time I plot some data, the following subroutine:

subroutine draw_textos
use datos_celulas
use mswin
implicit none
character*10 ::longitud,cnum
call select_font@('Arial')
CALL SIZE_IN_PIXELS@(44,27)
longitud=cnum(pixels_contorno)
call draw_characters@('longitud con overhang: '//longitud//' pixels',100,400,black)
call select_font@('Times New Roman')
CALL SIZE_IN_PIXELS@(44,27)
longitud=cnum(pixels_contorno_sin_overhang)
call draw_characters@('longitud sin overhang: '//longitud//' pixels',100,500,red)
end subroutine draw_textos

The problem is that the size of the fonts change every time I change the content of the window with new data!!! It is not fixed at all!. Any explanation about how to write some text with a fixed size under Clearwin? Does the size of fonts depend on some parameters that one should take care about?

Thanks a lot

Agustin

P.D. By the way. I create a graphics region using
call create_graphics_region@(3,hres,vres) and copy it to the screen using call copy_graphics_region@(1,0,0,800,600,3,0,0,hres,vres,srccopy)
Depending on the maximum and minimum values of the data set to be plotted, hres and vres can change. Could this be the reason of the change of the font size?
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Sat Mar 27, 2010 1:34 pm    Post subject: Reply with quote

If it is any consolation, I gave up on changing font sizes on the screen - I just looked at my code to see what I do, and all of it was commented out in my code. ("it" being the code I wrote to change font sizes on the screen). I just use the default font and the default size. It mostly works OK. However, when generating hard copy I see that I used the "size in points" subroutine as that makes it resolution independent - and that works. Perhaps someone will tell us both the answer!

Eddie
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2554
Location: Sydney

PostPosted: Sun Mar 28, 2010 11:55 pm    Post subject: Reply with quote

Agustin,

You could/would have problems with text scale, depending on the values of "hres,vres", as the image can be ‘stretched’ . (800x600 is a small window these days, and few screens are still 4:3 !)
I have had success to the limited extent I have tried to change text size, by using "scale_font@". I use the following routines to select a scaled font and also return the length of a string in my screen units, to account for variable width characters. I typically use a font scale between 0.8 and 2.0 and also automatically scale the font when the screen width exceeds 1152 pixels so I don't get small text on a higher resolution screen and so that running the program on different screens will not produce dramatically different layouts.

Code:
      SUBROUTINE CRTFONT (FONT, FONT_SIZE, KCHX_TEK, KCHY_TEK)
!
!    Selects the font and character size and returns the typical test size
!
      INCLUDE 'crtcom.ins'
      include <clearwin.ins>
!
      CHARACTER FONT*(*)
      REAL*4    FONT_SIZE
      INTEGER*4 KCHX_TEK, KCHY_TEK
!
      integer*4 c_len, c_high
      real*8    font_scale
!
!---  set the text mode
!
      call select_font@ (font)
!
      if (x_max_win > 1152 .OR. abs (font_size-1.0) > 0.01) then
         font_scale = x_max_win / 1152. * font_size
         call scale_font@ (font_scale)
      end if
!
      call get_text_size@ ('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', c_len, c_high)
      CHRX     = c_len/36             ! character size in screen pixels
      CHRY     = c_high
!
      NCHCOL   = NXPIX/CHRX           ! characters across screen
      NCHLIN   = NYPIX/CHRY           ! lines available
!
      KCHX_TEK = X_MAX_TEK/NCHCOL     ! character width (tek units)
      KCHY_TEK = Y_MAX_TEK/NCHLIN     ! character height (tek units)
      RETURN
      END

      subroutine crtstr_size (string, t_len, t_high)
!
!    return the string size in TEK units
!
      INCLUDE 'crtcom.ins'
      include <clearwin.ins>
      character string*(*)
      integer*4 t_len, t_high, c_len, c_high
      INTRINSIC trim
!
      call get_text_size@ (trim(string), c_len, c_high)
!
      t_len  = NINT (REAL(c_len)*X_MAX_TEK/X_MAX_WIN)
      t_high = NINT (REAL(c_high)*Y_MAX_TEK/Y_MAX_WIN)
!
      return
      end

Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Mon Mar 29, 2010 10:56 am    Post subject: Reply with quote

John,

There's a lot more in your code than you explained in your text!

What is in "crtcom.ins"?

The code from the line that begins "call get_text_size@" is the way that we work out the pixel size of an "average character", which is used to position controls in Clearwin - applicable to a heck of a lot of other things, not just font scaling in a %gr area.

When I run my programs on a hi-res screen, whether or not the characters are readable depends on the physical size of the screen as well as the pixel count. Some laptop screens (I have one) have zillions of pixels, but aren't all that big. Some physically imposing screens aren't all that well-endowed with pixels. Further, there is the "large fonts" setting that truly messes things up.

I would have agreed with you about the lower resolution screens disappearing - until the advent of netbooks. Some of them are quite capable of running number-crunching code (up to a point!) and come with sometimes very low res screens.

Have you tried running anything on a dual monitor setup? Now that can be interesting.

Eddie
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2554
Location: Sydney

PostPosted: Tue Mar 30, 2010 2:08 am    Post subject: Reply with quote

Eddie,

crtcom.ins is the include file that defines all my variables for managing the screen display. I must admit that the text scaling has worked adequately for the limited range of screens I have used, mainly Large low res screens, notebook high res, projectors and dual screen. Projectors can be an annoyance when they reset the screen resolution. I avoid screens less than 1152 pixels wide.

My startup graphics typically takes the whole primary screen, and does not allow re-sizing, so with a dual screen I put clearwin on the primary screen and other things are draged to the secondary screen, including the OUTPUT text window. My startup %gr code is:
Code:
     i = winio@ ('%`^gr[grey, rgb_colours, full_mouse_input]&',  &
                w_width, w_depth, w_handle, mouse_back_func)
!
     i = winio@ ('%ww[no_frame,maximise]&')      ! select full screen
!
     i = winio@  ('%sc&', plot_setup_func)       ! call setup function
!
     i = winio@  ('%mn[&File[]]&' )              ! begin menu definition
...

The functionality of two screens is very good. I haven't yet tried dragging the clearwin window to the other screen and resizing. Is there an easy way to allow for this ?

John
Back to top
View user's profile Send private message
aebolzan



Joined: 06 Jul 2007
Posts: 229
Location: La Plata, Argentina

PostPosted: Tue Mar 30, 2010 4:07 am    Post subject: Reply with quote

Sorry John, but I cannot follow your idea. You say that you use scale_font@ and I also see that you use get_text_size@ subroutine as well, but I do not see how do you write you text on the "%gr" window. Do you use draw_characters@ in another subroutine that was not included in your post?. I presume x_max_win is the width of your screen in pixels, which in my case is below 1152, so the conditional IF for scale_font does no apply. My screen is 1024x768 but I use part of it for menu buttons, so that the graphics window actually takes the resolution of 800x600 (17" CRT monitor).
Best regards,

Agustin

P.D. the reason of using get_text_size is still obscure for me.....I will check the FTN95 manual
P.D.2: By the way, I have just discovered that scale_font@ hangs my program! I can use draw_characters but without scaling it! Very strange indeed.....
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2554
Location: Sydney

PostPosted: Tue Mar 30, 2010 5:58 am    Post subject: Reply with quote

Yes I do use:
CALL DRAW_CHARACTERS@ (STRING(1:N), IX, IY, COLOUR) ! to draw the characters.
I recommend you call "get_text_size@" before this to check the pixel length of the text string you are drawing, so it does not overflow off the edge of the screen. Most fonts, except courier, have variable width characters. You can also use this for centering or right justifying the text drawn.

I use "scale_font@" when selecting the font. Did you declare "real*8 font_scale" when using as a argument to scale_font@.

John
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Tue Mar 30, 2010 10:34 am    Post subject: Reply with quote

Agustin,

When John uses the get_text_size@ routine and what follows, he is working out the average character width and its height according to Windows' own special way of doing things. The height is given immediately, but the width is the average of all those characters in his string.

Clearwin - and Windows too - use this average sized character cell to position things such as controls. They definitely don't use pixels. The idea of this is to get resolution independence. It worked magnificently when there were 3 or 4 standard screen resolutions, but now that there are some really odd ones, it sometimes results in strange spacings. (Especially if large fonts have been selected by the user.)

John says he also uses it to check his text strings don't go off the edge of the graphics window. If you don't mind if they do, you don't need to check - but if you want the whole text to be visible, then you must check it fits, and reposition it if it doesn't.

I started out not allowing the graphics area to be resizable (same as John), but it is pretty easy, and now I wouldn't do it without resizing - it makes your program look more "standard". It only takes a few lines of code in the %gr call back, to find the call back reason, and if it is resize, get the new size, recalculate scales and then replot the contents. Make sure you never use the height or width = 0 when you recalculate scales!

Eddie
Back to top
View user's profile Send private message
aebolzan



Joined: 06 Jul 2007
Posts: 229
Location: La Plata, Argentina

PostPosted: Tue Mar 30, 2010 2:33 pm    Post subject: Reply with quote

Well John, I am starting to understand your lines....but...is "x_max_win" the monitor screen resolution or is the graphics screen resolution? and "x_max_tek" is......?. I presume that in my case "x_max_win" is the value of the horizontal resolution (hres) of my graphics_region, isn't it?.

And....the font_size should be a variable declared by me, which by default should take a value of ca....?. and the meaning of the misterious "36" in CHRX = c_len/36? (72 points/2 ? )

...and...no, I did not declared "real*8 font_scale". I have corrected this error in my code.

Once again, thanks a lot for your help,

Agustin
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Tue Mar 30, 2010 6:10 pm    Post subject: Reply with quote

36 is the number of characters in the string.

Eddie
Back to top
View user's profile Send private message
aebolzan



Joined: 06 Jul 2007
Posts: 229
Location: La Plata, Argentina

PostPosted: Tue Mar 30, 2010 10:58 pm    Post subject: Re: Reply with quote

LitusSaxonicum wrote:
36 is the number of characters in the string.

Eddie


Uhmm....seems I did not sleep very well last night......... thanks Eddie!

Agustin
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+ All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group