home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / sys / amiga / programm / 17856 < prev    next >
Encoding:
Internet Message Format  |  1992-12-28  |  4.2 KB

  1. Path: sparky!uunet!cbmvax!cbmehq!cbmfra!forgeas
  2. From: forgeas@swinjm.adsp.sub.org (Jean-Michel Forgeas)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: Newbie font/screen question
  5. Message-ID: <Qvlbs*2a2@swinjm.adsp.sub.org>
  6. Date: 24 Dec 92 10:54:44 GMT
  7. References: <37971@cbmvax.commodore.com> <paulk.2vmr@terapin.com>
  8. Reply-To: forgeas@swinjm.adsp.sub.org (Jean-Michel Forgeas)
  9. Organization: The Software Winery
  10. Lines: 126
  11. X-Newsreader: Arn V1.00 alpha rel2
  12.  
  13. In article <paulk.2vmr@terapin.com>, Paul Kienitz writes:
  14.  
  15. > At some time in the past I found that calling OpenDiskFont() will
  16. > always load from disk even if the font is already in memory.  So I
  17. > call OpenDiskFont() only if OpenFont() fails.
  18.  
  19. It's true, plus if OpenFonts() succeds you should compare the tf_YSize
  20. of the font opened, because it is possible that OpenFonts() get an
  21. other one (as close as possible the asked height) if one is in memory.
  22.  
  23. Here is my "OpenOnlyThisFont" routine. If not found, it will re_open
  24. the system default font and return it, so it could always be successful:
  25.  
  26. ****************************************************
  27. *   font = OpenOnlyThisFont( struct TTextAttr *tta )
  28. *   D0                                         a0
  29. *   should be always a success
  30. ****************************************************
  31.  
  32. OpenOnlyThisFont
  33.     movem.l a2/a6,-(sp)
  34.     move.l  a0,a2
  35.     bra.b   OpenFont
  36.  
  37.     move.l  _GfxBase,a6
  38.     jsr     _LVOOpenFont(a6)        Font = (struct TextFont *) OpenFont( &TextAttr )
  39.     tst.l   d0
  40.     beq.b   .diskfont
  41.  
  42.     move.l  d0,a0
  43.     move.w  tta_YSize(a2),d1
  44.     cmp.w   tf_YSize(a0),d1         Font->tf_YSize == TTextAttr.ta_YSize ?
  45.     beq   .end                      if yes, OK!
  46.     move.l  a0,a1
  47.     jsr     _LVOCloseFont(a6)
  48.     moveq   #0,d0
  49.  
  50. .diskfont
  51.     lea     DiskFontName,a1         open library
  52.     moveq   #0,d0
  53.     move.l  4.w,a6
  54.     jsr     _LVOOpenLibrary(a6)
  55.     tst.l   d0
  56.     beq.b   .error
  57.  
  58.     exg     d0,a6                   just to open the font
  59.     bset    #FPB_DISKFONT,tta_Flags(a2)
  60.     move.l  a2,a0
  61.     jsr     _LVOOpenDiskFont(a6)    Font = (struct TextFont *) OpenDiskFont( &TextAttr )
  62.     move.l  d0,-(sp)                save the font
  63.     ;
  64.     move.l  a6,a1                   and close the library
  65.     move.l  4.w,a6
  66.     jsr     _LVOCloseLibrary(a6)
  67.     ;
  68.     move.l  (sp)+,d0                restore fonte
  69.     beq.b   .error
  70. .end
  71.     movem.l (sp)+,a2/a6
  72.     tst.l   d0
  73.     rts
  74.  
  75. .error
  76.     move.l  _GfxBase,a6
  77.     move.l  gb_DefaultFont(a6),a1   if not successful, we open the system default font
  78.     bsr.b   _ReopenFont
  79.     bra.b   .end
  80.  
  81.  
  82. *************************************
  83. *   font = ReopenFont( font )
  84. *   d0                  a1
  85. *************************************
  86.  
  87. _ReopenFont
  88.     move.l  a6,-(sp)
  89.     sub.w   #tta_SIZEOF,sp          spare for TTextAttr
  90.     move.l  sp,a0
  91.  
  92.     move.l  4.w,a6
  93.     jsr     _LVOForbid(a6)          doesn't modify d0-d1/a0-a1 (documented)
  94.  
  95.     bsr.b   _Font2TTA               doesn't modify a1
  96.  
  97.     move.l  _GfxBase,a6
  98.     jsr     _LVOOpenFont(a6)        I know this breaks the forbid but it is the
  99.                                     ;safer solution I can see to prevent that the font
  100.                                     ;copied above can be unloaded before this OpenFont
  101.                                     ;succeds...
  102.     move.l  4.w,a6
  103.     jsr     _LVOPermit(a6)
  104.  
  105.     add.w   #tta_SIZEOF,sp
  106.     move.l  (sp)+,a6
  107.     tst.l   d0
  108.     rts
  109.  
  110.  
  111. *************************************
  112. *   void Font2TTA( font, tta )
  113. *   d0              a1   a0
  114. *   do not modify a1
  115. *************************************
  116.  
  117. _Font2TTA
  118.     move.l  LN_NAME(a1),tta_Name(a0)
  119.     move.l  tf_YSize(a1),tta_YSize(a0)
  120.  
  121.     move.l  tf_Extension(a1),d0         is there an extended font structure?
  122.     beq.b   .clear
  123.     exg     d0,a1
  124.     move.l  tfe_Tags(a1),tta_Tags(a0)   copy the pointer to the taglist
  125.     exg     d0,a1
  126.     beq.b   .clear                      was there a taglist?
  127.     bset    #FSB_TAGGED,tta_Style(a0)   so mark it.
  128.     rts
  129. .clear
  130.     bclr    #FSB_TAGGED,tta_Style(a0)
  131.     rts
  132.  
  133. Note that this last routine doesn't duplicate the taglist in case of a
  134. tagged font.
  135. --
  136.  Jean-Michel Forgeas      uunet!cbmvax!cbmehq!cbmfra!swinjm!forgeas
  137.  16170 Bordeville                            __
  138.  France                                      \/
  139.