appletfont.c

Go to the documentation of this file.
00001 
00002 /*  $Id: appletfont.c 355 2005-01-11 22:48:55Z andreradke $    */
00003 
00004 /* copyright 1991-96 UserLand Software, Inc. All Rights Reserved.*/
00005 
00006 
00007 #include "appletdefs.h"
00008 #include "appletstrings.h"
00009 #include "appletfont.h"
00010 
00011 
00012 #define styleseparator "\p+"
00013 
00014 FontInfo globalfontinfo;
00015 
00016 #define ctstyles 7 
00017 
00018 short stylesarray [ctstyles] = 
00019     
00020     {0, bold, italic, underline, 
00021     
00022     bold + italic, bold + underline, 
00023     
00024     italic + underline};
00025 
00026 
00027 
00028 
00029 short sumcharwidths (void *pstring) {
00030     
00031     char *bs = (char *) pstring;
00032     short sum = 0;
00033     short i;
00034     
00035     for (i = 1; i <= stringlength (bs); i++)
00036         sum += CharWidth (bs [i]);
00037         
00038     return (sum);
00039     } /*sumcharwidths*/
00040     
00041 
00042 void setfontsizestyle (short fontnum, short fontsize, short fontstyle) {
00043 
00044     TextFont (fontnum);
00045     
00046     TextSize (fontsize);
00047     
00048     TextFace (fontstyle);
00049     } /*setfontsizestyle*/
00050     
00051     
00052 void setglobalfontsizestyle (short fontnum, short fontsize, short fontstyle) {
00053 
00054     setfontsizestyle (fontnum, fontsize, fontstyle);
00055     
00056     GetFontInfo (&globalfontinfo);
00057     } /*setglobalfontsizestyle*/
00058     
00059     
00060 short setnamedfont (bigstring bs, short fsize, short fstyle, short defaultfont) {
00061 
00062     /*
00063     give me the name of a font you like.  I'll try to set to that font,
00064     but if its not available, you get the default font.  be sure to select
00065     a default font that is mandatory -- like geneva or newYork.
00066     */
00067     
00068     short fontnum;
00069     
00070     GetFNum (bs, &fontnum);
00071     
00072     if (fontnum == 0) 
00073         fontnum = defaultfont; /*use caller's second choice*/
00074         
00075     setglobalfontsizestyle (fontnum, fsize, fstyle);
00076     
00077     return (fontnum); /*return the font that we are actually using*/
00078     } /*setnamedfont*/
00079         
00080 
00081 void getfontsizestyle (short *fontnum, short *fontsize, short *fontstyle) {
00082 
00083     *fontnum = (*quickdrawglobal (thePort)).txFont;
00084     
00085     *fontsize = (*quickdrawglobal (thePort)).txSize;
00086     
00087     *fontstyle = (*quickdrawglobal (thePort)).txFace;
00088     } /*getfontsizestyle*/
00089     
00090     
00091 void getstyle (short style, short *flplain, short *flbold, short *flitalic, short *flunderline, short *floutline, short *flshadow) {
00092 
00093     /*
00094     give me a style bit array, and I'll extract the booleans which are 
00095     slightly easier to deal with.
00096     
00097     if none of the others are true, we set flplain to true.  otherwise 
00098     flplain is false.
00099     */
00100 
00101     *flplain = true;  /*default values*/
00102     
00103     *flbold = false;
00104     
00105     *flitalic = false;
00106     
00107     *flunderline = false;
00108     
00109     *floutline = false;
00110     
00111     *flshadow = false;
00112     
00113     if (style >= shadow) {
00114         
00115         style -= shadow;
00116         
00117         *flshadow = true;
00118         
00119         *flplain = false;
00120         }
00121         
00122     if (style >= outline) {
00123         
00124         style -= outline;
00125         
00126         *floutline = true;
00127         
00128         *flplain = false;
00129         }
00130         
00131     if (style >= underline) {
00132         
00133         style -= underline;
00134         
00135         *flunderline = true;
00136         
00137         *flplain = false;
00138         }
00139         
00140     if (style >= italic) {
00141         
00142         style -= italic;
00143         
00144         *flitalic = true;
00145         
00146         *flplain = false;
00147         }
00148         
00149     if (style >= bold) {
00150         
00151         style -= bold;
00152         
00153         *flbold = true;
00154         
00155         *flplain = false;
00156         }
00157     } /*getstyle*/
00158     
00159 
00160 void checkstyle (boolean fl, bigstring bsin, bigstring bsout) {
00161 
00162     if (fl) {
00163         if (bsout [0]) { /*already something on the output string*/
00164         
00165             pushstring (styleseparator, bsout);
00166             
00167             pushstring (bsin, bsout);
00168             }
00169         else
00170             copystring (bsin, bsout);
00171         }
00172     } /*checkstyle*/
00173         
00174 
00175 short getfontheight (void) {
00176     
00177     FontInfo info;
00178     
00179     GetFontInfo (&info);
00180     
00181     return (info.ascent + info.descent);
00182     } /*getfontheight*/
00183     
00184     
00185 void fontgetname (short fontnum, bigstring fontname) {
00186     
00187     GetFontName (fontnum, fontname);
00188     } /*fontgetname*/
00189 
00190 
00191 void fontgetnumber (bigstring fontname, short *fontnum) {
00192     
00193     if (stringlength (fontname) == 0)
00194         *fontnum = geneva;
00195     else
00196         GetFNum ((ptrstring) fontname, fontnum);
00197     } /*fontgetnumber*/
00198     
00199 
00200 void diskgetfontname (short fontnum, diskfontstring fontname) {
00201     
00202     /*
00203     Apple recommends that fonts be stored on disk as strings.  we return the
00204     fontname, limited in length to 32, based on the indicated font number.
00205     */
00206     
00207     bigstring bs;
00208     
00209     GetFontName (fontnum, bs);
00210     
00211     if (stringlength (bs) > diskfontnamelength)
00212         setstringlength (bs, diskfontnamelength);
00213     
00214     copystring (bs, (ptrstring) fontname);
00215     } /*diskgetfontname*/
00216 
00217 
00218 void diskgetfontnum (diskfontstring fontname, short *fontnum) {
00219     
00220     if (stringlength (fontname) == 0)
00221         *fontnum = geneva;
00222     else
00223         GetFNum ((ptrstring) fontname, fontnum);
00224     } /*diskgetfontnum*/
00225     
00226 
00227 void getnextfont (short *fontnum) {
00228     
00229     /*
00230     MenuHandle hmenu = hdlfontmenu;
00231     short i, ctitems;
00232     bigstring fontname, bs;
00233     
00234     GetFontName (*fontnum, fontname);
00235     
00236     ctitems = CountMItems (hmenu);
00237     
00238     for (i = 1; i <= ctitems; i++) {
00239         
00240         GetItem (hmenu, i, bs);
00241         
00242         if (unicaseequalstrings (bs, fontname)) {
00243             
00244             if (i == ctitems)
00245                 GetItem (hmenu, 1, fontname);
00246             else
00247                 GetItem (hmenu, i + 1, fontname);
00248                 
00249             GetFNum (fontname, fontnum);
00250                 
00251             return;
00252             }
00253         } /%for%/
00254         
00255     *fontnum = applFont; /%the input font isn't on this system%/
00256     */
00257     } /*getnextfont*/
00258     
00259     
00260 void getprevfont (short *fontnum) {
00261     
00262     /*
00263     MenuHandle hmenu = hdlfontmenu;
00264     short i, ctitems;
00265     bigstring fontname, bs;
00266     
00267     GetFontName (*fontnum, fontname);
00268     
00269     ctitems = CountMItems (hmenu);
00270     
00271     for (i = 1; i <= ctitems; i++) {
00272         
00273         GetItem (hmenu, i, bs);
00274         
00275         if (unicaseequalstrings (bs, fontname)) {
00276             
00277             if (i == 1)
00278                 GetItem (hmenu, ctitems, fontname);
00279             else
00280                 GetItem (hmenu, i - 1, fontname);
00281                 
00282             GetFNum (fontname, fontnum);
00283                 
00284             return;
00285             }
00286         } /%for%/
00287         
00288     *fontnum = applFont; /%the input font isn't on this system%/
00289     */
00290     } /*getprevfont*/
00291     
00292     
00293 void getnextstyle (short *style) { 
00294     
00295     short i;
00296     
00297     for (i = 0; i < ctstyles; i++) {
00298         
00299         if (*style == stylesarray [i]) {
00300             
00301             if (i == (ctstyles - 1)) 
00302                 *style = stylesarray [0];
00303             else
00304                 *style = stylesarray [i + 1];
00305                 
00306             return;
00307             }
00308         } /*for*/
00309         
00310     *style = stylesarray [0];
00311     } /*getnextstyle*/
00312     
00313     
00314 void getprevstyle (short *style) { 
00315     
00316     short i;
00317     
00318     for (i = 0; i < ctstyles; i++) {
00319         
00320         if (*style == stylesarray [i]) {
00321             
00322             if (i == 0) 
00323                 *style = stylesarray [ctstyles - 1];
00324             else
00325                 *style = stylesarray [i - 1];
00326             
00327             return;
00328             }
00329         } /*for*/
00330         
00331     *style = stylesarray [0];
00332     } /*getprevstyle*/
00333     
00334     

Generated on Wed May 31 18:19:42 2006 for frontierkernel 10.1.10a by  doxygen 1.4.6