home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cbmvax!cbmehq!cbmfra!forgeas
- From: forgeas@swinjm.adsp.sub.org (Jean-Michel Forgeas)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: Newbie font/screen question
- Message-ID: <Qvlbs*2a2@swinjm.adsp.sub.org>
- Date: 24 Dec 92 10:54:44 GMT
- References: <37971@cbmvax.commodore.com> <paulk.2vmr@terapin.com>
- Reply-To: forgeas@swinjm.adsp.sub.org (Jean-Michel Forgeas)
- Organization: The Software Winery
- Lines: 126
- X-Newsreader: Arn V1.00 alpha rel2
-
- In article <paulk.2vmr@terapin.com>, Paul Kienitz writes:
-
- > At some time in the past I found that calling OpenDiskFont() will
- > always load from disk even if the font is already in memory. So I
- > call OpenDiskFont() only if OpenFont() fails.
-
- It's true, plus if OpenFonts() succeds you should compare the tf_YSize
- of the font opened, because it is possible that OpenFonts() get an
- other one (as close as possible the asked height) if one is in memory.
-
- Here is my "OpenOnlyThisFont" routine. If not found, it will re_open
- the system default font and return it, so it could always be successful:
-
- ****************************************************
- * font = OpenOnlyThisFont( struct TTextAttr *tta )
- * D0 a0
- * should be always a success
- ****************************************************
-
- OpenOnlyThisFont
- movem.l a2/a6,-(sp)
- move.l a0,a2
- bra.b OpenFont
-
- move.l _GfxBase,a6
- jsr _LVOOpenFont(a6) Font = (struct TextFont *) OpenFont( &TextAttr )
- tst.l d0
- beq.b .diskfont
-
- move.l d0,a0
- move.w tta_YSize(a2),d1
- cmp.w tf_YSize(a0),d1 Font->tf_YSize == TTextAttr.ta_YSize ?
- beq .end if yes, OK!
- move.l a0,a1
- jsr _LVOCloseFont(a6)
- moveq #0,d0
-
- .diskfont
- lea DiskFontName,a1 open library
- moveq #0,d0
- move.l 4.w,a6
- jsr _LVOOpenLibrary(a6)
- tst.l d0
- beq.b .error
-
- exg d0,a6 just to open the font
- bset #FPB_DISKFONT,tta_Flags(a2)
- move.l a2,a0
- jsr _LVOOpenDiskFont(a6) Font = (struct TextFont *) OpenDiskFont( &TextAttr )
- move.l d0,-(sp) save the font
- ;
- move.l a6,a1 and close the library
- move.l 4.w,a6
- jsr _LVOCloseLibrary(a6)
- ;
- move.l (sp)+,d0 restore fonte
- beq.b .error
- .end
- movem.l (sp)+,a2/a6
- tst.l d0
- rts
-
- .error
- move.l _GfxBase,a6
- move.l gb_DefaultFont(a6),a1 if not successful, we open the system default font
- bsr.b _ReopenFont
- bra.b .end
-
-
- *************************************
- * font = ReopenFont( font )
- * d0 a1
- *************************************
-
- _ReopenFont
- move.l a6,-(sp)
- sub.w #tta_SIZEOF,sp spare for TTextAttr
- move.l sp,a0
-
- move.l 4.w,a6
- jsr _LVOForbid(a6) doesn't modify d0-d1/a0-a1 (documented)
-
- bsr.b _Font2TTA doesn't modify a1
-
- move.l _GfxBase,a6
- jsr _LVOOpenFont(a6) I know this breaks the forbid but it is the
- ;safer solution I can see to prevent that the font
- ;copied above can be unloaded before this OpenFont
- ;succeds...
- move.l 4.w,a6
- jsr _LVOPermit(a6)
-
- add.w #tta_SIZEOF,sp
- move.l (sp)+,a6
- tst.l d0
- rts
-
-
- *************************************
- * void Font2TTA( font, tta )
- * d0 a1 a0
- * do not modify a1
- *************************************
-
- _Font2TTA
- move.l LN_NAME(a1),tta_Name(a0)
- move.l tf_YSize(a1),tta_YSize(a0)
-
- move.l tf_Extension(a1),d0 is there an extended font structure?
- beq.b .clear
- exg d0,a1
- move.l tfe_Tags(a1),tta_Tags(a0) copy the pointer to the taglist
- exg d0,a1
- beq.b .clear was there a taglist?
- bset #FSB_TAGGED,tta_Style(a0) so mark it.
- rts
- .clear
- bclr #FSB_TAGGED,tta_Style(a0)
- rts
-
- Note that this last routine doesn't duplicate the taglist in case of a
- tagged font.
- --
- Jean-Michel Forgeas uunet!cbmvax!cbmehq!cbmfra!swinjm!forgeas
- 16170 Bordeville __
- France \/
-