Welcome, Guest. Please login or register.

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

Description:

0 Members and 1 Guest are viewing this topic.

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: how do i get a pointer to the default system font?
« 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 Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: how do i get a pointer to the default system font?
« Reply #1 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 Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: how do i get a pointer to the default system font?
« Reply #2 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 Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: how do i get a pointer to the default system font?
« Reply #3 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 Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: how do i get a pointer to the default system font?
« Reply #4 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 Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: how do i get a pointer to the default system font?
« Reply #5 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 Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: how do i get a pointer to the default system font?
« Reply #6 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.