Welcome, Guest. Please login or register.

Author Topic: how do i get a pointer to the default system font?  (Read 1904 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline AGSzaboTopic starter

  • Jr. Member
  • **
  • Join Date: Jun 2006
  • Posts: 55
    • Show only replies by AGSzabo
    • http://www.psi5.com/~silva/afilter/
how do i get a pointer to the default system font?
« on: June 08, 2006, 07:56:18 PM »
at the moment i use
Code: [Select]
move.l intbase(pc),a0
move.l ib_FirstScreen(a0),a0
move.l sc_RastPort+rp_Font(a0),a5


but how do i get a pointer to the default system font?
mobilis in mobili
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: how do i get a pointer to the default system font?
« Reply #1 on: June 08, 2006, 08:02:31 PM »
And what if there is no screen (ib_FirstScreen == 0) or if the screen you read the rastport from closes? Or if the font in question is flushed while you use it?

Anyway, if you insist: graphics.library base gb_DefaultFont has the current default screen font. It still doesn't gurantee a lock on it, so you should copy parameters from it withint Forbid() and call OpenFont(). Only then you're guaranteed to have valid lock on it.

System Font is trickier, basically one bulletproof way to get it is to read ENV:Sys/Font.prefs using iffparse.library. The data is multiple struct FontPrefs with system font prefs having fp_Type FP_SYSFONT.
 

Offline AGSzaboTopic starter

  • Jr. Member
  • **
  • Join Date: Jun 2006
  • Posts: 55
    • Show only replies by AGSzabo
    • http://www.psi5.com/~silva/afilter/
Re: how do i get a pointer to the default system font?
« Reply #2 on: June 08, 2006, 08:09:01 PM »
yes, thats why i ask. i need to know the font that a new window will get by default but prior to opening that window.
mobilis in mobili
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: how do i get a pointer to the default system font?
« Reply #3 on: June 08, 2006, 08:32:16 PM »
The official way is to Lock the public screen you want to open on and then use GetScreenDrawInfo(). dri_Font will then have pointer to font to be used for the window. This is the font that is used for titlebar, and window RPort default font.

Or do you really mean system font (used for console text)?
 

Offline AGSzaboTopic starter

  • Jr. Member
  • **
  • Join Date: Jun 2006
  • Posts: 55
    • Show only replies by AGSzabo
    • http://www.psi5.com/~silva/afilter/
Re: how do i get a pointer to the default system font?
« Reply #4 on: June 08, 2006, 09:00:51 PM »
Quote
Or do you really mean system font (used for console text)?


no. thank you.
mobilis in mobili
 

Offline AGSzaboTopic starter

  • Jr. Member
  • **
  • Join Date: Jun 2006
  • Posts: 55
    • Show only replies by AGSzabo
    • http://www.psi5.com/~silva/afilter/
Re: how do i get a pointer to the default system font?
« Reply #5 on: June 09, 2006, 08:52:32 PM »
what if i want to know the default font prior to opening the screen for my app?
mobilis in mobili
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: how do i get a pointer to the default system font?
« Reply #6 on: June 09, 2006, 10:12:01 PM »
Quote
what if i want to know the default font prior to opening the screen for my app?

Several ways to handle that, but the easist would be to open temp screen with SA_Behind,TRUE, then get font specifics from screen rastport font (clone the name, ysize and style). CloseScreen the temp screen.

You now have the font info, which you can for example use to open the font with OpenDiskFont().
 

Offline AGSzaboTopic starter

  • Jr. Member
  • **
  • Join Date: Jun 2006
  • Posts: 55
    • Show only replies by AGSzabo
    • http://www.psi5.com/~silva/afilter/
Re: how do i get a pointer to the default system font?
« Reply #7 on: June 10, 2006, 01:10:48 PM »
ok, i am curious about "the other methods"?
mobilis in mobili
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: how do i get a pointer to the default system font?
« Reply #8 on: June 10, 2006, 04:47:46 PM »
Method 1:
- use iffparse.library to read env:sys/fonts.prefs
- The entry with fp_Type of FP_SCREENFONT is the one defining the default screen font.

Method 2:
- LockPubScreen("Workbench")
- GetScreenDrawInfo and copy info from dri_Font
- FreeScreenDrawInfo
- UnLockPubScreen
This might not return any font though, in case there is no Workbench screen.

Method 3:
- Forbid
- copy font details from GfxBase gb_DefaultFont
- Permit
This is a hack. It really should not be used.
 

Offline AGSzaboTopic starter

  • Jr. Member
  • **
  • Join Date: Jun 2006
  • Posts: 55
    • Show only replies by AGSzabo
    • http://www.psi5.com/~silva/afilter/
Re: how do i get a pointer to the default system font?
« Reply #9 on: June 10, 2006, 04:56:33 PM »
its really great that there IS response in the amiga scene! that amiga is alive! thank you for your very good answer!

i currently use LockPubScreen(NULL) and am curious if that works on systems with gfxcard, where there is no workbench but some other default screen that i will get by LockPubScreen(NULL) instead?
mobilis in mobili
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: how do i get a pointer to the default system font?
« Reply #10 on: June 10, 2006, 05:09:32 PM »
LockPubScreen(NULL) will get you the default public screen (99% of the time this is the Workbench screen). You can get some other screen aswell though, and in theory it could use some other font than the system default.
 

Offline AGSzaboTopic starter

  • Jr. Member
  • **
  • Join Date: Jun 2006
  • Posts: 55
    • Show only replies by AGSzabo
    • http://www.psi5.com/~silva/afilter/
Re: how do i get a pointer to the default system font?
« Reply #11 on: June 10, 2006, 07:35:47 PM »
btw, why should i forbid while reading gfxbase?
mobilis in mobili
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: how do i get a pointer to the default system font?
« Reply #12 on: June 10, 2006, 07:44:49 PM »
Quote
btw, why should i forbid while reading gfxbase?

Because there is no way to arbitrate the access to it. Without Forbid(), and if the default system font was changed, you could end up with stale pointer when the OS CloseFont()'s the font.

With intuitionbase you can lock = LockIBase(0), read values and then UnlockIBase(lock).
 

Offline AGSzaboTopic starter

  • Jr. Member
  • **
  • Join Date: Jun 2006
  • Posts: 55
    • Show only replies by AGSzabo
    • http://www.psi5.com/~silva/afilter/
Re: how do i get a pointer to the default system font?
« Reply #13 on: June 10, 2006, 08:40:11 PM »
i doubt that something wonderfull will happen just in the same time when i access gfxbase or an existing screen. its more likely that you win lotto.
mobilis in mobili
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: how do i get a pointer to the default system font?
« Reply #14 on: June 10, 2006, 09:03:47 PM »
@AGSzabo
Quote

i doubt that something wonderfull will happen just in the same time when i access gfxbase or an existing screen.

It can, since this is a multitasking system. Once you've fetched the pointer, a reschedule can occur. Your task might be asleep for a very long time, and during this time the font might be closed.

Quote
its more likely that you win lotto.

Could be, but if such similar race conditions pile up, the probability for failure grows aswell. If it just takes Forbid/Permit to avoid them, better use it.