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 

Scale_font@

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



Joined: 10 Mar 2008
Posts: 2813
Location: South Pole, Antarctica

PostPosted: Mon Oct 25, 2010 3:05 am    Post subject: Scale_font@ Reply with quote

I have some very old bugs in my code which i did not have time to research. Today will be beginning of the end of one of them.

Hunting the bug and isolating the strange behavior in large subroutine for last two days I got really mind killing bug/feature of scale_font@ utility...

Isn't it supposed to return your font size back if you do

scale_font@(0.7d0)
call draw_text@('text',100, 100, icolor)
scale_font@(1./0.7d0)

???? Then look at this sample code below. Use slider which just dynamically changes the FontSizeFactor (was 0.7 in above snippet) to arbitrary value (for example between 0.1 and 3.2). Each line contains 25 instances of number 10^5 which on both lines has to be the same size.

Code print radix (number 10) with some initial font size equal 2, then scales the font to smaller size and prints exponent 5. Then font size changes back to initial size 2 again and repeats all : it prints initial size radix, scales font down and prints exponent, scales font back to normal etc

Look though what we get. What all that may mean? I'd understand some small variations in font size (or scale factor) due to rounding of real*8 numbers for font dimensions to actually integer font pixel count but not that kind of magnitude ! Just found the workarounds by selecting the same font again and again before plotting each character, but they look illogical and potentially time consuming.

Code:

  use clrwin
  integer  Start
  external Start
  real*8 FontSizeFactor
  common FontSizeFactor, k_ShowWrongWay

  k_ShowWrongWay  = 1
  FontSizeFactor= 0.7
  i=winio@('%ww&')   
  i=winio@('%ac[esc]&', 'exit')
  i=winio@('%^rb[Show how things should NOT work]%ff&',  k_ShowWrongWay, Start)
  i=winio@('%^?200sl[horizontal][exponent font size] %rf%ff%ff&', &
     & FontSizeFactor, 0.1D0, 3.2D0, Start, FontSizeFactor)
  i=winio@('%gr[black,rgb_colours]&', 1700, 480)
  i=winio@('%lw', ilw) !
  j=start()
  end
!.................................................................
  integer function Start()
  use clrwin
  real*8   SizeFontRTGxaxisR, FontSizeFactor
  common FontSizeFactor, k_ShowWrongWay

  SizeFontRTGxaxisR = 2
  kol = rgb@(170,170,250)

        call clear_screen@()

!!      call SELECT_FONT@('Arial')
!!   call SELECT_FONT@('Courier New')
   call SELECT_FONT@('Times New Roman')
    call scale_font@(SizeFontRTGxaxisR )
   call BOLD_FONT@( 1 )

        iy = 220
        do i=1,25
   if(k_ShowWrongWay.eq.0) call SELECT_FONT@('Times New Roman')
   if(k_ShowWrongWay.eq.0)   call scale_font@(SizeFontRTGxaxisR )
            CALL DRAW_TEXT@('10', 66*(i-1), iy, kol)
            call scale_font@(FontSizeFactor)
            CALL DRAW_TEXT@('5', 66*(i-1)+31, iy-17, kol)
          call scale_font@(1./FontSizeFactor) !!0.59d0)
   enddo

!  same code for another line
        iy = 270
        do i=1,25
   if(k_ShowWrongWay.eq.0) call SELECT_FONT@('Times New Roman')
   if(k_ShowWrongWay.eq.0)   call scale_font@(SizeFontRTGxaxisR )
            CALL DRAW_TEXT@('10', 66*(i-1), iy, kol)
            call scale_font@(FontSizeFactor)
            CALL DRAW_TEXT@('5', 66*(i-1)+31, iy-17, kol)
          call scale_font@(1./FontSizeFactor)
   enddo

  Start=1
  end function   


Last edited by DanRRight on Mon Oct 25, 2010 11:25 pm; edited 1 time in total
Back to top
View user's profile Send private message
IanLambley



Joined: 17 Dec 2006
Posts: 490
Location: Sunderland

PostPosted: Mon Oct 25, 2010 3:49 pm    Post subject: Reply with quote

Dan,
I've just been having the same problem. I was originally using set_text_attribute@ which seems to use an absolute scale to size the text, but that was a throwback to DOS. So I decided to change and use scale_text@. There did not seem to be a method of resetting the scale to the original other than the method you have used.

Eventually, I used size_in_pixels@ which allows control over the width and height of the text and I use this to set a default size for the text, from which I then apply the scale_font@. As a rough estimation of the number of characters allowed across and down the page, I assumed that the standard font was an 8 wide by 14 high and knowing the width & height of the screen or printer I could determine the scale factor to apply to that size. As you have chosen "Arial", a proportional font, the width of each letter varies and you are back to the old "letteraset" problem of knowing when to start each letter, based on where the previous letter finished. For number characters this is not such a problem, well, not until you rotate them anyway!
Ian
Back to top
View user's profile Send private message Send e-mail
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Mon Oct 25, 2010 6:41 pm    Post subject: Reply with quote

scale_font@ only applies the given factor to the current font width and height and the result is rounded to the nearest integer. If you take the inverse then you probably won't get back to where you were.
Back to top
View user's profile Send private message AIM Address
DanRRight



Joined: 10 Mar 2008
Posts: 2813
Location: South Pole, Antarctica

PostPosted: Mon Oct 25, 2010 10:21 pm    Post subject: Reply with quote

Things look more like a defect of scaling algorithm or a bug, since in some cases the fonts are not scaled up or down proportionally in horizontal and vertical directions, look at the amazing sequence of squeezing font to zero mostly horizontally for example! That's a hint because such dramatic changes in aspect ratio of the font definitely should not happen in any case. There exist some other hints too: scaling has to be homogeneous with scale factor but it jumps like crazy

P.S. i edited the code above, now it includes both how things should work and how they (as of currently) shouldn't. I think the right scaling algorithm in scale_font@ has to produce the same result as the ones with unchecked key without calling SELECT_FONT@ every time you print something of same font but of different scale. Anything else is antiintuitive and people will lose a lot of time to find "the bug". If that's not possible to fix then documentation has to explain why and warn to use SELECT_FONT@ every time fonts are scaled or do other things like Ian suggested. I for example tried to fix that strange behavior several times during 10 years (and just did not use this feature) until the last whole weekend's "final assault" Wink
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2554
Location: Sydney

PostPosted: Tue Oct 26, 2010 4:17 am    Post subject: Reply with quote

Paul,

What precision does "scale_font@" provide with "rounded to the nearest integer" ? It does request a real*8 "SIZE".
Like others, I have overcome the problem of re-scaling the font size, by reselecting the font each time then applying a new scale. I have appeared to achieve font scales of 1.5 in the past, but now I'm not certain what scale I achieved. I always use "get_text_size@ to find the text size I have achieved.

John
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Tue Oct 26, 2010 7:48 am    Post subject: Reply with quote

I need to correct the information I have given above. The actual code is

Code:
   lf.lfHeight = (int)(lf.lfHeight*size);
   lf.lfWidth = (int)(lf.lfWidth*size);

so the result is truncated and not rounded. "size" is the real*8 value given and int is integer*4.

I can improve the documentation and provide another routine (with rounding rather than truncation) if this helps but the new routine would not provide a perfect inverse. For that purpose I would probably have to add another routine that simply restores the previous font.
Back to top
View user's profile Send private message AIM Address
DanRRight



Joined: 10 Mar 2008
Posts: 2813
Location: South Pole, Antarctica

PostPosted: Wed Oct 27, 2010 9:13 am    Post subject: Reply with quote

Sounds good, thanks, Paul.
Back to top
View user's profile Send private message
IanLambley



Joined: 17 Dec 2006
Posts: 490
Location: Sunderland

PostPosted: Wed Oct 27, 2010 9:54 am    Post subject: Reply with quote

Dan & Paul,
As I have been having a little trouble with the scale_font@ routine, here is a small program that uses two methods of setting the text size.
1. Select the font and apply "scale_font@" to determine the main character size and again to set the subscript size.
2. Use size_in_pixels@ to set the main character size followed by scale_font@ to set the subscript size.

The intent of the code is to produce a string of text followed by a second string of text which is drawn as a superscript to the first and the routine returns the coordinates of the bottom right end of the overall string in case you wish to follow on with some more text.

All is well for method 1 for all angles, but method 2 fails to produce a sensible result when the rotate_font@ is called for angles which are different from 0, 90, 180, 270, i.e. for 45degrees where each character is rotated less than the overall string.
Regards
Ian

Code:

winapp
program scale_text_test
implicit real*8 (a-h,o-z)
include <windows.ins>
character*1 test_chr
ihandl = 2
itest = open_printer@(ihandl)
if(itest .ne. 0)then
  call SELECT_FONT@('Courier New')
  call scale_font@(8d0)
  call text_with_superscript('text','super',1700,1000,45d0,0,0,0.66d0,rgb@(255,0,0),ixend,iyend)
  PRINT *,IXEND,IYEND
  call SELECT_FONT@('Courier New')
  call scale_font@(8d0)
  call text_with_superscript('text','super',1500,1200,0d0,0,0,0.66d0,rgb@(255,0,0),ixend,iyend)
  PRINT *,IXEND,IYEND
  call SELECT_FONT@('Courier New')
  call scale_font@(8d0)
  call text_with_superscript('text','super',1500,1200,90d0,0,0,0.66d0,rgb@(255,0,0),ixend,iyend)
  PRINT *,IXEND,IYEND
  call SELECT_FONT@('Courier New')
  call scale_font@(8d0)
  call text_with_superscript('text','super',1500,1200,180d0,0,0,0.66d0,rgb@(255,0,0),ixend,iyend)
  PRINT *,IXEND,IYEND
  call SELECT_FONT@('Courier New')
  call scale_font@(8d0)
  call text_with_superscript('text','super',1500,1200,270d0,0,0,0.66d0,rgb@(255,0,0),ixend,iyend)
  PRINT *,IXEND,IYEND

  call text_with_superscript('text','super',1700,2500,45d0,96,112,0.66d0,rgb@(255,0,0),ixend,iyend)
  PRINT *,IXEND,IYEND
  call text_with_superscript('text','super',1500,2700,0d0,96,112,0.66d0,rgb@(255,0,0),ixend,iyend)
  PRINT *,IXEND,IYEND
  call text_with_superscript('text','super',1500,2700,90d0,96,112,0.66d0,rgb@(255,0,0),ixend,iyend)
  PRINT *,IXEND,IYEND
  call text_with_superscript('text','super',1500,2700,180d0,96,112,0.66d0,rgb@(255,0,0),ixend,iyend)
  PRINT *,IXEND,IYEND
  call text_with_superscript('text','super',1500,2700,270d0,96,112,0.66d0,rgb@(255,0,0),ixend,iyend)
  PRINT *,IXEND,IYEND

  call SELECT_FONT@('Arial')
  call text_with_superscript('text','super',1700,4000,45d0,96,112,0.66d0,rgb@(255,0,0),ixend,iyend)
  PRINT *,IXEND,IYEND
  call text_with_superscript('text','super',1500,4200,0d0,96,112,0.66d0,rgb@(255,0,0),ixend,iyend)
  PRINT *,IXEND,IYEND
  call text_with_superscript('text','super',1500,4200,90d0,96,112,0.66d0,rgb@(255,0,0),ixend,iyend)
  PRINT *,IXEND,IYEND
  call text_with_superscript('text','super',1500,4200,180d0,96,112,0.66d0,rgb@(255,0,0),ixend,iyend)
  PRINT *,IXEND,IYEND
  call text_with_superscript('text','super',1500,4200,270d0,96,112,0.66d0,rgb@(255,0,0),ixend,iyend)
  PRINT *,IXEND,IYEND
  itest = close_printer@(ihandl)
endif
end

Continued...


Last edited by IanLambley on Wed Oct 27, 2010 3:29 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
IanLambley



Joined: 17 Dec 2006
Posts: 490
Location: Sunderland

PostPosted: Wed Oct 27, 2010 2:20 pm    Post subject: Reply with quote

Last bit
Code:

subroutine text_with_superscript(text,super,ix,iy,angle,iwidth,iheight,factor,icolour,ixend,iyend)
implicit real*8 (a-h,o-z)
character*(*) text,super
include <windows.ins>
if(iwidth*iheight .gt. 0)then
  call size_in_pixels@(iwidth,iheight)
endif
call rotate_font@(angle)
call get_text_size@(text,itextw,itexth)
theta=angle*asin(1d0)/90d0
ixsuper = ix + dble(itextw)*cos(theta) - dble(itexth)*(1d0-factor)*sin(theta)
iysuper = iy - dble(itextw)*sin(theta) - dble(itexth)*(1d0-factor)*cos(theta)
call draw_characters@(text,ix,iy,icolour)
call scale_font@(factor)
call draw_characters@(super,ixsuper,iysuper,icolour)

call get_text_size@(super,isuperw,isuperh)
ixend = ix + dble(itextw+isuperw)*cos(theta)
iyend = iy - dble(itextw+isuperw)*sin(theta)

end
Back to top
View user's profile Send private message Send e-mail
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Thu Oct 28, 2010 8:15 am    Post subject: Reply with quote

I have added scale_font1@ to the library. It is the same as scale_font@ but uses rounding instead of truncation. I have also added unscale_font@() which takes no arguments and undoes to previous scale_font@ or scale_font1@. This routine can only be used once in succession.

I am not sure if these changes will get into the next release that is currently under construction.
Back to top
View user's profile Send private message AIM Address
DanRRight



Joined: 10 Mar 2008
Posts: 2813
Location: South Pole, Antarctica

PostPosted: Thu Oct 28, 2010 8:54 am    Post subject: Reply with quote

So size_in_pixels@ is not scalable to arb angles. Is this defect of the size_in_pixels@ method, Ian? Or it has to work this way in any case with arbitrary scaling of the font because not proportional in vertical and horizontal direction scaling distorts the font ? Elliptic scaling might solve that i think, it does not look as unsolvable problem, but this could be a bit of a headache to change the scaling routines. Or might be not. May be Paul will shed the light, the scaled this way fonts really look ugly

Paul, does rounding generally fixes the example i've posted above? Or the sequence slowly uncontrollably falls into one or the other black hole (too small or too large or too narrow)? And of course we'd like to see it in this release, but...it does not depend on us. If depends will be glad to betatest.


Last edited by DanRRight on Thu Oct 28, 2010 11:29 am; edited 1 time in total
Back to top
View user's profile Send private message
IanLambley



Joined: 17 Dec 2006
Posts: 490
Location: Sunderland

PostPosted: Thu Oct 28, 2010 11:28 am    Post subject: Reply with quote

Paul,
Those two routines sound good, is there a way to find the current font size, so we can manually save and restore sizes. For example "get_size_in_pixels@(width,height)"

Might the error in the rotation be due to the wrong aspect ratio in the call to size_in_pixels@?

Ian
Back to top
View user's profile Send private message Send e-mail
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Thu Oct 28, 2010 12:52 pm    Post subject: Reply with quote

There is a routine that you can use which I assume is undocumented...

Code:

  integer finfo(12)
  character*80 fname
  ....
  call current_font_info@(finfo, fname)


The first two entries in the array are the height and width in pixels.

I don't have time at the moment to research the rotation problem.
Back to top
View user's profile Send private message AIM Address
IanLambley



Joined: 17 Dec 2006
Posts: 490
Location: Sunderland

PostPosted: Thu Oct 28, 2010 11:05 pm    Post subject: Reply with quote

Paul,
I've just tried the font rotation on my home printer instead of work's printer, and the printing works fine. It may just be a bad print driver at work.
Ian
Back to top
View user's profile Send private message Send e-mail
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