Attempt to fix creation of boot floppy with new nightly scripts.
[tangerine.git] / test / fontinfo.c
blob45ad864acbf6ee142b2d4d404b0c76d28aee0c24
1 #include <exec/initializers.h>
2 #include <dos/dos.h>
3 #include <diskfont/diskfont.h>
4 #include <graphics/text.h>
5 #include <graphics/gfxbase.h>
6 #include <intuition/intuition.h>
7 #include <proto/diskfont.h>
8 #include <proto/exec.h>
9 #include <proto/dos.h>
10 #include <proto/graphics.h>
11 #include <proto/utility.h>
12 #include <proto/intuition.h>
14 #include <stdio.h>
15 #include <string.h>
16 #include <stdlib.h>
18 #define ARG_TEMPLATE "FONTNAME/A,FONTSIZE/N/A,XDPI/N,YDPI/N,BOLD/S,ITALIC/S,SHOW/S"
19 #define ARG_NAME 0
20 #define ARG_SIZE 1
21 #define ARG_XDPI 2
22 #define ARG_YDPI 3
23 #define ARG_BOLD 4
24 #define ARG_ITALIC 5
25 #define ARG_SHOW 6
26 #define NUM_ARGS 7
28 struct Library *DiskfontBase;
29 struct UtilityBase *UtilityBase;
30 struct GfxBase *GfxBase;
31 struct IntuitionBase *IntuitionBase;
33 struct TextFont *font;
34 STRPTR fontname;
35 ULONG fontsize, xdpi, ydpi;
36 struct RDArgs *myargs;
37 ULONG args[NUM_ARGS];
38 char s[256];
40 static void cleanup(char *msg)
42 if (msg) printf("fontinfo: %s\n", msg);
44 if (font) CloseFont(font);
46 if (UtilityBase) CloseLibrary((struct Library *)UtilityBase);
47 if (GfxBase) CloseLibrary((struct Library *)GfxBase);
48 if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
49 if (DiskfontBase) CloseLibrary(DiskfontBase);
51 if (myargs) FreeArgs(myargs);
53 exit(0);
56 static void getarguments(void)
58 myargs = ReadArgs(ARG_TEMPLATE, args, NULL);
59 if (!myargs)
61 Fault(IoErr(), 0, s, 255);
62 cleanup(s);
65 fontname = (STRPTR)args[ARG_NAME];
66 fontsize = *(LONG *)args[ARG_SIZE];
68 xdpi = args[ARG_XDPI] ? *(LONG *)args[ARG_XDPI] : 72;
69 ydpi = args[ARG_YDPI] ? *(LONG *)args[ARG_YDPI] : 72;
73 static void openlibs(void)
75 DiskfontBase = OpenLibrary("diskfont.library", 38);
76 if (!DiskfontBase) cleanup("Can't open diskfont.library!");
78 GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 38);
79 if (!GfxBase) cleanup("Can't open graphics.library!");
81 IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 38);
82 if (!IntuitionBase) cleanup("Can't open intuition.library!");
84 UtilityBase = (struct UtilityBase *)OpenLibrary("utility.library", 38);
85 if (!UtilityBase) cleanup("Can't open utility.library!");
88 static void openfont(void)
90 struct TTextAttr ta;
91 struct TagItem tags[] =
93 {TA_DeviceDPI, (xdpi << 16) | ydpi },
94 {TAG_DONE }
97 ta.tta_Name = fontname;
98 ta.tta_YSize = fontsize;
99 ta.tta_Style = FSF_TAGGED;
100 if (args[ARG_BOLD]) ta.tta_Style |= FSF_BOLD;
101 if (args[ARG_ITALIC]) ta.tta_Style |= FSF_ITALIC;
103 ta.tta_Flags = FPF_DESIGNED;
104 ta.tta_Tags = tags;
106 printf("fontname = \"%s\" fontsize = %ld\n", fontname, fontsize);
108 font = OpenDiskFont((struct TextAttr *)&ta);
109 if (!font) cleanup("Could not open font!");
111 printf("Opened font addr = %p\n", font);
112 printf("Opened font has xsize = %d ysize = %d baseline = %d flags = 0x%x style = 0x%x\n",
113 font->tf_XSize,
114 font->tf_YSize,
115 font->tf_Baseline,
116 font->tf_Flags,
117 font->tf_Style);
118 printf("boldsmear = %d\n", font->tf_BoldSmear);
119 printf("tf_CharData = %p\n", font->tf_CharData);
121 if (font->tf_Flags & FPF_DISKFONT)
123 struct DiskFontHeader *dfh = (struct DiskFontHeader *)(((UBYTE *)font) - (UBYTE *)OFFSET(DiskFontHeader, dfh_TF));
125 printf("DiskFontHeader:\n");
126 printf(" succ %p\n", dfh->dfh_DF.ln_Succ);
127 printf(" pred %p\n", dfh->dfh_DF.ln_Pred);
128 printf(" type %x\n", dfh->dfh_DF.ln_Type);
129 printf(" pri %x\n", dfh->dfh_DF.ln_Pri);
130 printf(" name %p (%s)\n", dfh->dfh_DF.ln_Name, dfh->dfh_DF.ln_Name);
131 printf(" FileID %x\n", dfh->dfh_FileID);
132 printf(" Revision %x\n", dfh->dfh_Revision);
133 printf(" Segment %p\n", dfh->dfh_Segment);
134 printf(" Name %p (%s)\n", dfh->dfh_Name, dfh->dfh_Name);
137 printf("tf_Message:\n");
138 printf(" succ %p\n", font->tf_Message.mn_Node.ln_Succ);
139 printf(" pred %p\n", font->tf_Message.mn_Node.ln_Pred);
140 printf(" type %x\n", font->tf_Message.mn_Node.ln_Type);
141 printf(" pri %x\n", font->tf_Message.mn_Node.ln_Pri);
142 printf(" name %p (%s)\n", font->tf_Message.mn_Node.ln_Name, font->tf_Message.mn_Node.ln_Name);
143 printf(" replyport %p\n", font->tf_Message.mn_ReplyPort);
144 printf(" length %x\n", font->tf_Message.mn_Length);
146 printf("textfontextension:\n");
147 if (ExtendFont(font, 0))
149 struct TextFontExtension *tfe = ((struct TextFontExtension *)font->tf_Extension);
150 struct TagItem *extension = tfe->tfe_Tags;
151 struct TagItem *tag, *tstate = extension;
152 LONG dpivalue;
154 printf(" taglist:\n");
155 while((tag = NextTagItem((const struct TagItem **)&tstate)))
157 printf(" {0x%08lx,0x%08lx}\n", tag->ti_Tag, tag->ti_Data);
160 dpivalue = GetTagData(TA_DeviceDPI, 0, extension);
162 printf(" ta_devicedpi of opened font is: xdpi %ld ydpi: %ld\n",
163 dpivalue >> 16, dpivalue & 0xFFFF);
165 printf(" tfe_MatchWord %x\n", tfe->tfe_MatchWord);
166 printf(" tfe_Flags0 %x\n", tfe->tfe_Flags0);
167 printf(" tfe_Flags1 %x\n", tfe->tfe_Flags1);
168 printf(" tfe_OrigReplyPort %p\n", tfe->tfe_OrigReplyPort);
169 printf(" tfe_OFontPatchS %p\n", tfe->tfe_OFontPatchS);
170 printf(" tfe_OFontPatchK %p\n", tfe->tfe_OFontPatchK);
173 if (font->tf_Style & FSF_COLORFONT)
175 struct ColorTextFont *ctf = (struct ColorTextFont *)font;
176 WORD i;
178 printf(" ctf_Flags %x\n", ctf->ctf_Flags);
179 printf(" ctf_Depth %x\n", ctf->ctf_Depth);
180 printf(" ctf_FgColor %x\n", ctf->ctf_FgColor);
181 printf(" ctf_Low %x\n", ctf->ctf_Low);
182 printf(" ctf_High %x\n", ctf->ctf_High);
183 printf(" ctf_PlanePick %x\n", ctf->ctf_PlanePick);
184 printf(" ctf_PlaneOnOff %x\n", ctf->ctf_PlaneOnOff);
185 printf(" ctf_colorFontColors %p\n", ctf->ctf_ColorFontColors);
187 for(i = 0; i <8; i++)
189 printf(" ctf_CharData[%d] %p\n", i, ctf->ctf_CharData[i]);
194 struct TextFont *tf = (struct TextFont *)GfxBase->TextFonts.lh_Head;
196 printf("SYSFONTLIST:\n");
197 while(tf->tf_Message.mn_Node.ln_Succ)
199 printf(" addr %p name %s size %d\n", tf, tf->tf_Message.mn_Node.ln_Name, tf->tf_YSize);
200 tf = (struct TextFont *)tf->tf_Message.mn_Node.ln_Succ;
205 static void action(void)
207 WORD i;
208 LONG totcharsize = 0;
209 LONG totcharkern = 0;
210 LONG totcharspace = 0;
211 LONG totsomething = 0;
212 LONG numsomething = 0;
213 LONG numcharspace = 0;
215 printf("lowchar = %d\n", font->tf_LoChar);
216 printf("hichar = %d\n", font->tf_HiChar);
217 printf("isprop = %s\n", (font->tf_Flags & FPF_PROPORTIONAL) ? "yes" : "no");
218 printf("haskern = %s\n", font->tf_CharKern ? "yes" : "no");
219 printf("hasspace = %s\n", font->tf_CharSpace ? "yes" : "no");
220 puts("");
222 for(i = font->tf_LoChar; i <= font->tf_HiChar + 1; i++)
224 printf("#%03d kerning = %s%4d%s blackwidth = %4ld spacing = %s%4d%s\n",
226 font->tf_CharKern ? "" : "[",
227 (font->tf_CharKern ? ((WORD *)font->tf_CharKern)[i - font->tf_LoChar] : 0),
228 font->tf_CharKern ? "" : "]",
229 ((LONG *)font->tf_CharLoc)[i - font->tf_LoChar] & 0xFFFF,
230 font->tf_CharSpace ? "" : "[",
231 (font->tf_CharSpace ? ((WORD *)font->tf_CharSpace)[i - font->tf_LoChar] : 0),
232 font->tf_CharSpace ? "" : "]");
234 if (font->tf_CharKern) totcharkern += ((WORD *)font->tf_CharKern)[i - font->tf_LoChar];
235 if (font->tf_CharSpace)
237 ULONG old_totcharspace = totcharspace;
238 totcharspace += ((WORD *)font->tf_CharSpace)[i - font->tf_LoChar];
239 if (totcharspace != old_totcharspace) numcharspace++;
242 totcharsize += ((LONG *)font->tf_CharLoc)[i - font->tf_LoChar] & 0xFFFF;
244 if ((i >= 110) && (font->tf_CharKern && font->tf_CharSpace))
246 ULONG old_totsomething = totsomething;
247 totsomething += ((WORD *)font->tf_CharSpace)[i - font->tf_LoChar] +
248 ((WORD *)font->tf_CharKern)[i - font->tf_LoChar];
250 if (totsomething != old_totsomething)
251 numsomething++;
256 if (numsomething) printf("average something = %ld\n", totsomething / numsomething);
257 if (numcharspace) printf("average charspace = %ld\n", totcharspace / numcharspace);
260 static void showfont(void)
262 static char *text = "ABCDEFGHabcdefgh1234567890";
263 static struct RastPort temprp;
264 struct TextExtent te;
265 struct Screen *scr;
266 struct Window *win;
268 InitRastPort(&temprp);
269 SetFont(&temprp, font);
271 TextExtent(&temprp, text, strlen(text), &te);
273 if ((scr = LockPubScreen(NULL)))
275 win = OpenWindowTags(NULL, WA_PubScreen, (ULONG)scr,
276 WA_InnerWidth, te.te_Width + 6,
277 WA_InnerHeight, te.te_Height + 6,
278 WA_CloseGadget, TRUE,
279 WA_DragBar, TRUE,
280 WA_DepthGadget, TRUE,
281 WA_Activate, TRUE,
282 WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_VANILLAKEY,
283 WA_Title, (ULONG)"FontInfo",
284 TAG_DONE);
286 if (win)
288 SetFont(win->RPort, font);
289 SetAPen(win->RPort, 1);
290 Move(win->RPort, win->BorderLeft + 3 - te.te_Extent.MinX,
291 win->BorderTop + 3 - te.te_Extent.MinY);
292 Text(win->RPort, text, strlen(text));
293 WaitPort(win->UserPort);
294 CloseWindow(win);
296 UnlockPubScreen(NULL, scr);
300 int main(void)
302 getarguments();
303 openlibs();
304 openfont();
305 action();
306 if (args[ARG_SHOW]) showfont();
307 cleanup(0);
309 return 0;