grub2: bring back build of aros-side grub2 tools
[AROS.git] / test / diskfont / fontinfo.c
blob673c5fbbe05aaf03d9e134520105d7e43909b39d
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <exec/initializers.h>
7 #include <dos/dos.h>
8 #include <diskfont/diskfont.h>
9 #include <graphics/text.h>
10 #include <graphics/gfxbase.h>
11 #include <intuition/intuition.h>
12 #include <proto/diskfont.h>
13 #include <proto/exec.h>
14 #include <proto/dos.h>
15 #include <proto/graphics.h>
16 #include <proto/utility.h>
17 #include <proto/intuition.h>
19 #include <stdio.h>
20 #include <string.h>
21 #include <stdlib.h>
23 #define ARG_TEMPLATE "FONTNAME/A,FONTSIZE/N/A,XDPI/N,YDPI/N,BOLD/S,ITALIC/S,SHOW/S"
24 #define ARG_NAME 0
25 #define ARG_SIZE 1
26 #define ARG_XDPI 2
27 #define ARG_YDPI 3
28 #define ARG_BOLD 4
29 #define ARG_ITALIC 5
30 #define ARG_SHOW 6
31 #define NUM_ARGS 7
33 struct Library *DiskfontBase;
34 struct UtilityBase *UtilityBase;
35 struct GfxBase *GfxBase;
36 struct IntuitionBase *IntuitionBase;
38 struct TextFont *font;
39 STRPTR fontname;
40 ULONG fontsize, xdpi, ydpi;
41 struct RDArgs *myargs;
42 IPTR args[NUM_ARGS];
43 char s[256];
45 static void cleanup(char *msg)
47 if (msg) printf("fontinfo: %s\n", msg);
49 if (font) CloseFont(font);
51 if (UtilityBase) CloseLibrary((struct Library *)UtilityBase);
52 if (GfxBase) CloseLibrary((struct Library *)GfxBase);
53 if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
54 if (DiskfontBase) CloseLibrary(DiskfontBase);
56 if (myargs) FreeArgs(myargs);
58 exit(msg == NULL ? RETURN_OK : RETURN_FAIL);
61 static void getarguments(void)
63 myargs = ReadArgs(ARG_TEMPLATE, args, NULL);
64 if (!myargs)
66 Fault(IoErr(), 0, s, 255);
67 cleanup(s);
70 fontname = (STRPTR)args[ARG_NAME];
71 fontsize = *(LONG *)args[ARG_SIZE];
73 xdpi = args[ARG_XDPI] ? *(LONG *)args[ARG_XDPI] : 72;
74 ydpi = args[ARG_YDPI] ? *(LONG *)args[ARG_YDPI] : 72;
78 static void openlibs(void)
80 DiskfontBase = OpenLibrary("diskfont.library", 38);
81 if (!DiskfontBase) cleanup("Can't open diskfont.library!");
83 GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 38);
84 if (!GfxBase) cleanup("Can't open graphics.library!");
86 IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 38);
87 if (!IntuitionBase) cleanup("Can't open intuition.library!");
89 UtilityBase = (struct UtilityBase *)OpenLibrary("utility.library", 38);
90 if (!UtilityBase) cleanup("Can't open utility.library!");
93 static void openfont(void)
95 struct TTextAttr ta;
96 struct TagItem tags[] =
98 {TA_DeviceDPI, (xdpi << 16) | ydpi },
99 {TAG_DONE }
102 ta.tta_Name = fontname;
103 ta.tta_YSize = fontsize;
104 ta.tta_Style = FSF_TAGGED;
105 if (args[ARG_BOLD]) ta.tta_Style |= FSF_BOLD;
106 if (args[ARG_ITALIC]) ta.tta_Style |= FSF_ITALIC;
108 ta.tta_Flags = FPF_DESIGNED;
109 ta.tta_Tags = tags;
111 printf("fontname = \"%s\" fontsize = %ld\n", fontname, (long)fontsize);
113 font = OpenDiskFont((struct TextAttr *)&ta);
114 if (!font) cleanup("Could not open font!");
116 printf("Opened font addr = %p\n", font);
117 printf("Opened font has xsize = %d ysize = %d baseline = %d flags = 0x%x style = 0x%x\n",
118 font->tf_XSize,
119 font->tf_YSize,
120 font->tf_Baseline,
121 font->tf_Flags,
122 font->tf_Style);
123 printf("boldsmear = %d\n", font->tf_BoldSmear);
124 printf("tf_CharData = %p\n", font->tf_CharData);
126 if (font->tf_Flags & FPF_DISKFONT)
128 struct DiskFontHeader *dfh = (struct DiskFontHeader *)(((UBYTE *)font) - (UBYTE *)OFFSET(DiskFontHeader, dfh_TF));
130 printf("DiskFontHeader:\n");
131 printf(" succ %p\n", dfh->dfh_DF.ln_Succ);
132 printf(" pred %p\n", dfh->dfh_DF.ln_Pred);
133 printf(" type %x\n", dfh->dfh_DF.ln_Type);
134 printf(" pri %x\n", dfh->dfh_DF.ln_Pri);
135 printf(" name %p (%s)\n", dfh->dfh_DF.ln_Name, dfh->dfh_DF.ln_Name);
136 printf(" FileID %x\n", dfh->dfh_FileID);
137 printf(" Revision %x\n", dfh->dfh_Revision);
138 printf(" Segment %p\n", BADDR(dfh->dfh_Segment));
139 printf(" Name %p (%s)\n", dfh->dfh_Name, dfh->dfh_Name);
142 printf("tf_Message:\n");
143 printf(" succ %p\n", font->tf_Message.mn_Node.ln_Succ);
144 printf(" pred %p\n", font->tf_Message.mn_Node.ln_Pred);
145 printf(" type %x\n", font->tf_Message.mn_Node.ln_Type);
146 printf(" pri %x\n", font->tf_Message.mn_Node.ln_Pri);
147 printf(" name %p (%s)\n", font->tf_Message.mn_Node.ln_Name, font->tf_Message.mn_Node.ln_Name);
148 printf(" replyport %p\n", font->tf_Message.mn_ReplyPort);
149 printf(" length %x\n", font->tf_Message.mn_Length);
151 printf("textfontextension:\n");
152 if (ExtendFont(font, 0))
154 struct TextFontExtension *tfe = ((struct TextFontExtension *)font->tf_Extension);
155 struct TagItem *extension = tfe->tfe_Tags;
156 struct TagItem *tag, *tstate = extension;
157 LONG dpivalue;
159 printf(" taglist:\n");
160 while((tag = NextTagItem(&tstate)))
162 printf(" {%08x,%p}\n", (unsigned)tag->ti_Tag, (void *)tag->ti_Data);
165 dpivalue = GetTagData(TA_DeviceDPI, 0, extension);
167 printf(" ta_devicedpi of opened font is: xdpi %ld ydpi: %ld\n",
168 (long)(dpivalue >> 16), (long)(dpivalue & 0xFFFF));
170 printf(" tfe_MatchWord %x\n", tfe->tfe_MatchWord);
171 printf(" tfe_Flags0 %x\n", tfe->tfe_Flags0);
172 printf(" tfe_Flags1 %x\n", tfe->tfe_Flags1);
173 printf(" tfe_OrigReplyPort %p\n", tfe->tfe_OrigReplyPort);
174 printf(" tfe_OFontPatchS %p\n", tfe->tfe_OFontPatchS);
175 printf(" tfe_OFontPatchK %p\n", tfe->tfe_OFontPatchK);
178 if (font->tf_Style & FSF_COLORFONT)
180 struct ColorTextFont *ctf = (struct ColorTextFont *)font;
181 WORD i;
183 printf(" ctf_Flags %x\n", ctf->ctf_Flags);
184 printf(" ctf_Depth %x\n", ctf->ctf_Depth);
185 printf(" ctf_FgColor %x\n", ctf->ctf_FgColor);
186 printf(" ctf_Low %x\n", ctf->ctf_Low);
187 printf(" ctf_High %x\n", ctf->ctf_High);
188 printf(" ctf_PlanePick %x\n", ctf->ctf_PlanePick);
189 printf(" ctf_PlaneOnOff %x\n", ctf->ctf_PlaneOnOff);
190 printf(" ctf_colorFontColors %p\n", ctf->ctf_ColorFontColors);
192 for(i = 0; i <8; i++)
194 printf(" ctf_CharData[%d] %p\n", i, ctf->ctf_CharData[i]);
199 struct TextFont *tf = (struct TextFont *)GfxBase->TextFonts.lh_Head;
201 printf("SYSFONTLIST:\n");
202 while(tf->tf_Message.mn_Node.ln_Succ)
204 printf(" addr %p name %s size %d\n", tf, tf->tf_Message.mn_Node.ln_Name, tf->tf_YSize);
205 tf = (struct TextFont *)tf->tf_Message.mn_Node.ln_Succ;
210 static void action(void)
212 WORD i;
213 LONG totcharsize = 0;
214 LONG totcharkern = 0;
215 LONG totcharspace = 0;
216 LONG totsomething = 0;
217 LONG numsomething = 0;
218 LONG numcharspace = 0;
220 printf("lowchar = %d\n", font->tf_LoChar);
221 printf("hichar = %d\n", font->tf_HiChar);
222 printf("isprop = %s\n", (font->tf_Flags & FPF_PROPORTIONAL) ? "yes" : "no");
223 printf("haskern = %s\n", font->tf_CharKern ? "yes" : "no");
224 printf("hasspace = %s\n", font->tf_CharSpace ? "yes" : "no");
225 puts("");
227 for(i = font->tf_LoChar; i <= font->tf_HiChar + 1; i++)
229 printf("#%03d kerning = %s%4d%s blackwidth = %4ld spacing = %s%4d%s\n",
231 font->tf_CharKern ? "" : "[",
232 (font->tf_CharKern ? ((WORD *)font->tf_CharKern)[i - font->tf_LoChar] : 0),
233 font->tf_CharKern ? "" : "]",
234 (long)((LONG *)font->tf_CharLoc)[i - font->tf_LoChar] & 0xFFFF,
235 font->tf_CharSpace ? "" : "[",
236 (font->tf_CharSpace ? ((WORD *)font->tf_CharSpace)[i - font->tf_LoChar] : 0),
237 font->tf_CharSpace ? "" : "]");
239 if (font->tf_CharKern) totcharkern += ((WORD *)font->tf_CharKern)[i - font->tf_LoChar];
240 if (font->tf_CharSpace)
242 ULONG old_totcharspace = totcharspace;
243 totcharspace += ((WORD *)font->tf_CharSpace)[i - font->tf_LoChar];
244 if (totcharspace != old_totcharspace) numcharspace++;
247 totcharsize += ((LONG *)font->tf_CharLoc)[i - font->tf_LoChar] & 0xFFFF;
249 if ((i >= 110) && (font->tf_CharKern && font->tf_CharSpace))
251 ULONG old_totsomething = totsomething;
252 totsomething += ((WORD *)font->tf_CharSpace)[i - font->tf_LoChar] +
253 ((WORD *)font->tf_CharKern)[i - font->tf_LoChar];
255 if (totsomething != old_totsomething)
256 numsomething++;
261 if (numsomething) printf("average something = %ld\n", (long)(totsomething / numsomething));
262 if (numcharspace) printf("average charspace = %ld\n", (long)(totcharspace / numcharspace));
265 static void showfont(void)
267 static char *text = "ABCDEFGHabcdefgh1234567890";
268 static struct RastPort temprp;
269 struct TextExtent te;
270 struct Screen *scr;
271 struct Window *win;
273 InitRastPort(&temprp);
274 SetFont(&temprp, font);
276 TextExtent(&temprp, text, strlen(text), &te);
278 if ((scr = LockPubScreen(NULL)))
280 win = OpenWindowTags(NULL, WA_PubScreen, scr,
281 WA_InnerWidth, te.te_Width + 6,
282 WA_InnerHeight, te.te_Height + 6,
283 WA_CloseGadget, TRUE,
284 WA_DragBar, TRUE,
285 WA_DepthGadget, TRUE,
286 WA_Activate, TRUE,
287 WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_VANILLAKEY,
288 WA_Title, "FontInfo",
289 TAG_DONE);
291 if (win)
293 SetFont(win->RPort, font);
294 SetAPen(win->RPort, 1);
295 Move(win->RPort, win->BorderLeft + 3 - te.te_Extent.MinX,
296 win->BorderTop + 3 - te.te_Extent.MinY);
297 Text(win->RPort, text, strlen(text));
298 WaitPort(win->UserPort);
299 CloseWindow(win);
301 UnlockPubScreen(NULL, scr);
305 int main(void)
307 getarguments();
308 openlibs();
309 openfont();
310 action();
311 if (args[ARG_SHOW]) showfont();
312 cleanup(NULL);
314 return 0;