home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / OTL-MC7.DMS / in.adf / classsource.lha / ClassSource / Graphics / text / text.c
Encoding:
C/C++ Source or Header  |  1995-02-12  |  5.7 KB  |  296 lines

  1. #include <classes/Graphics/Text.h>
  2.  
  3. #pragma -
  4. #include <pragma/diskfont_lib.h>
  5. #include <pragma/graphics_lib.h>
  6. #pragma +
  7.  
  8. TextFontC::TextFontC()
  9.     : opened()
  10. {
  11.     textfont = NULL;
  12. }
  13.  
  14. TextFontC::TextFontC(const TextFontC &s)
  15.     : opened()
  16. {
  17.     textfont = s.textfont;
  18.     // Falls ein Font geöffnet war...
  19.     if (!s.opened.only())
  20.     {
  21.         // kopiere und referenziere diesen.
  22.         opened = s.opened;
  23.         opened.reference()
  24.     };
  25.     // Ansonsten wird der schon angelegte Referenzenzähler benutzt.
  26. }
  27.  
  28. TextFontC::~TextFontC()
  29. {
  30.     close();
  31. }
  32.  
  33. TextFontC &TextFontC::operator = (const TextFontC &s)
  34. {
  35.     if (this != &s)
  36.     {
  37.         close();
  38.         textfont = s.textfont;
  39.         // Falls kein Font geöffnet war...
  40.         if (s.opened.only())
  41.         {
  42.             // lege eine neue Instanz für den Referenzenzähler an...
  43.             opened = ShareManualC()
  44.         }
  45.         else {
  46.             // ansonsten kopiere und referenziere den alten.
  47.             opened = s.opened;
  48.             opened.reference()
  49.         };
  50.     };
  51.     return *this;
  52. }
  53.  
  54. BOOL TextFontC::open(const TextAttrC &t)
  55. {
  56.     if (opened.only())
  57.     {
  58.         if (textfont = OpenFont((struct TextAttr *) &t))
  59.         {
  60.             opened.reference();
  61.             return TRUE;
  62.         };
  63.         if (textfont = OpenDiskFont((struct TextAttr *) &t))
  64.         {
  65.             opened.reference();
  66.             return TRUE;
  67.         };
  68.     };
  69.     return FALSE;
  70. }
  71.  
  72. VOID TextFontC::close()
  73. {
  74.     if (textfont)
  75.     {
  76.         opened.dereference();
  77.         if (opened.only())
  78.         {
  79.             CloseFont(textfont);
  80.             textfont = NULL;
  81.         };
  82.     };
  83. }
  84.  
  85. // *************************************************************
  86.  
  87. TextAttrC::TextAttrC(STRPTR name, UWORD YSize,
  88.         UBYTE Style, UBYTE Flags, struct TagItem *tagitems)
  89.     : tags(tagitems),
  90.       fontname(name)
  91. {
  92.     tta_Name = (STRPTR) fontname;
  93.     tta_YSize = YSize;
  94.     tta_Style = Style;
  95.     tta_Flags = Flags|FSF_TAGGED;
  96.     tta_Tags = tags.tags();
  97. }
  98.  
  99. TextAttrC::TextAttrC(STRPTR name, UWORD YSize,
  100.         UBYTE Style, UBYTE Flags, Tag tag1type, ...)
  101.     : tags((struct TagItem *) &tag1type),
  102.       fontname(name)
  103. {
  104.     tta_Name = (STRPTR) fontname;
  105.     tta_YSize = YSize;
  106.     tta_Style = Style;
  107.     tta_Flags = Flags|FSF_TAGGED;
  108.     tta_Tags = tags.tags();
  109. }
  110.  
  111. TextAttrC::TextAttrC(const struct TextAttr &t)
  112.     : tags(NULL),
  113.       fontname(t.ta_Name)
  114. {
  115.     tta_Name = (STRPTR) fontname;
  116.     tta_YSize = t.ta_YSize;
  117.     tta_Style = t.ta_Style;
  118.     tta_Flags = t.ta_Flags|FSF_TAGGED;
  119.     tta_Tags = NULL;
  120. }
  121.  
  122. TextAttrC::TextAttrC(const TextAttrC &t)
  123.     : tags(t.tags),
  124.       fontname(t.fontname)
  125. {
  126.     tta_Name = (STRPTR) fontname;
  127.     tta_YSize = t.tta_YSize;
  128.     tta_Style = t.tta_Style;
  129.     tta_Flags = t.tta_Flags;
  130.     tta_Tags = tags.tags();
  131. }
  132.  
  133. TextAttrC &TextAttrC::operator= (const TextAttrC &s)
  134. {
  135.     if (this != &s)
  136.     {
  137.         fontname = s.fontname;
  138.         tta_Name = (STRPTR) fontname;
  139.         tta_YSize = s.tta_YSize;
  140.         tta_Style = s.tta_Style;
  141.         tta_Flags = s.tta_Flags;
  142.         tags = s.tags;
  143.         tta_Tags = tags.tags();
  144.     };
  145.     return *this;
  146. }
  147.  
  148. /*
  149. TextAttrC &TextAttrC::operator= (const struct TextAttr &t)
  150. {
  151.     fontname = t.ta_Name;
  152.     tta_Name = (STRPTR) fontname;
  153.     tta_YSize = t.ta_YSize;
  154.     tta_Style = t.ta_Style;
  155.     tta_Flags = t.ta_Flags|FSF_TAGGED;
  156.     tags = TagItemC(NULL);
  157.     tta_Tags = NULL;
  158.     return *this;
  159. }
  160. */
  161.  
  162. TextAttrC &TextAttrC::assign(const TextAttrC &s)
  163. {
  164.     return *this;
  165. }
  166.  
  167. // *************************************************************
  168.  
  169.  
  170. LTextAttrC::LTextAttrC(STRPTR name, UWORD YSize,
  171.         UBYTE Style, UBYTE Flags, struct TagItem *tagitems)
  172.     : TextAttrC(name,YSize,Style,Flags,tagitems),
  173.       fontlock()
  174. {
  175.     if (!fontlock.open(*this))
  176.         throw FontX();
  177. }
  178.  
  179. LTextAttrC::LTextAttrC(STRPTR name, UWORD YSize,
  180.         UBYTE Style, UBYTE Flags, Tag tag1type, ...)
  181.     : TextAttrC(name,YSize,Style,Flags,(struct TagItem *) &tag1type),
  182.       fontlock()
  183. {
  184.     if (!fontlock.open(*this))
  185.         throw FontX();
  186. }
  187.  
  188. LTextAttrC::LTextAttrC(const struct TextAttr &s)
  189.     : TextAttrC(s),
  190.       fontlock()
  191. {
  192.     if (!fontlock.open(*this))
  193.         throw FontX();
  194. }
  195.  
  196. LTextAttrC::LTextAttrC(const LTextAttrC &s)
  197.     : TextAttrC(s),
  198.       fontlock(s.fontlock)
  199. {
  200. }
  201.  
  202. LTextAttrC <extAttrC::operator= (const LTextAttrC &s)
  203. {
  204.     if (this != &s)
  205.     {
  206.         TextAttrC::operator= (s);
  207.         fontlock = s.fontlock;
  208.     };
  209.     return *this;
  210. }
  211.  
  212. /*
  213. LTextAttrC <extAttrC::operator= (const struct TextAttr &s)
  214. {
  215.     fontlock.close();
  216.     TextAttrC::operator= (s);
  217.     if (!fontlock.open(*this))
  218.         throw FontX();
  219.     return *this;
  220. }
  221. */
  222.  
  223. // *************************************************************
  224.  
  225. FTextAttrC::FTextAttrC(STRPTR Name, UWORD YSize,
  226.         UBYTE Style, UBYTE StyleMask,
  227.         UBYTE Flags, UBYTE FlagsMask,
  228.         struct TagItem *tagitems)
  229.     : TextAttrC(Name,YSize,Style,Flags,tagitems)
  230. {
  231.     named = Name != NULL;
  232.     sized = YSize != NULL;
  233.     styleMask = StyleMask;
  234.     flagsMask = FlagsMask;
  235. }
  236.  
  237. FTextAttrC::FTextAttrC(STRPTR Name, UWORD YSize,
  238.         UBYTE Style, UBYTE StyleMask, UBYTE Flags, UBYTE FlagsMask,
  239.         Tag tag1type, ...)
  240.     : TextAttrC(Name,YSize,Style,Flags,(struct TagItem *) &tag1type)
  241. {
  242.     named = Name != NULL;
  243.     sized = YSize != NULL;
  244.     styleMask = StyleMask;
  245.     flagsMask = FlagsMask;
  246. }
  247.  
  248. TextAttrC &FTextAttrC::assign(const TextAttrC &s)
  249. {
  250.     if ((TextAttrC *) this != &s)
  251.     {
  252.         if (!named)
  253.         {
  254.             fontname = s.tta_Name;
  255.             tta_Name = (STRPTR) fontname;
  256.         };
  257.         if (!sized)
  258.             tta_YSize = s.tta_YSize;
  259.         tta_Style = (tta_Style & styleMask) | (s.tta_Style & ~styleMask);
  260.         tta_Flags = (tta_Flags & flagsMask) | (s.tta_Flags & ~flagsMask);
  261.     };
  262.     return (TextAttrC &) *this;
  263. }
  264.  
  265. // *************************************************************
  266.  
  267. FLTextAttrC::FLTextAttrC(STRPTR Name, UWORD YSize,
  268.         UBYTE Style, UBYTE StyleMask,
  269.         UBYTE Flags, UBYTE FlagsMask,
  270.         struct TagItem *tagitems)
  271.     : FTextAttrC(Name,YSize,Style,StyleMask,Flags,FlagsMask,tagitems),
  272.       fontlock()
  273. {
  274. }
  275.  
  276. FLTextAttrC::FLTextAttrC(STRPTR Name, UWORD YSize,
  277.         UBYTE Style, UBYTE StyleMask, UBYTE Flags, UBYTE FlagsMask,
  278.         Tag tag1type, ...)
  279.     : FTextAttrC(Name,YSize,Style,StyleMask,Flags,FlagsMask,
  280.         (struct TagItem *) &tag1type),
  281.       fontlock()
  282. {
  283. }
  284.  
  285. TextAttrC &FLTextAttrC::assign(const TextAttrC &s)
  286. {
  287.     if ((TextAttrC *) this != &s)
  288.     {
  289.         fontlock.close();
  290.         FTextAttrC::assign(s);
  291.         if (!fontlock.open(*this))
  292.             throw FontX();
  293.     };
  294.     return (TextAttrC &) *this;
  295. }
  296.