1 /*---------------------------------------------------------------------------*
2 Project: Dolphin OS Overview - OSLoadFont(), OSGetFontTexel()
3 File: fontdemo2.c
4
5 Copyright 2002 Nintendo. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Log: fontdemo2.c,v $
14 Revision 1.2 02/20/2006 04:13:11 mitu
15 changed include path from dolphin/ to revolution/.
16
17 Revision 1.1 01/13/2006 11:24:13 hiratsu
18 Initial check in.
19
20
21 2 3/07/02 18:37 Shiki
22 Fixed to use correct size of fontData.
23
24 1 1/09/02 15:26 Shiki
25 Initial check-in.
26 $NoKeywords: $
27 *---------------------------------------------------------------------------*/
28
29 #include <stdlib.h>
30 #include <string.h>
31 #include <revolution.h>
32
main(int argc,char * argv[])33 void main(int argc, char* argv[])
34 {
35 s32 code;
36 OSFontHeader* fontData;
37 u32 image[24 / 8 * 24]; // 24 x 24
38 char buffer[3];
39 char* string;
40 int i, j;
41 s32 width;
42
43 if (argc != 2)
44 {
45 OSHalt("usage: fontdemo2 char_code\n");
46 }
47
48 code = strtol(argv[1], NULL, 0);
49 if (code < 256)
50 {
51 buffer[0] = (char) code;
52 buffer[1] = '\0';
53 }
54 else
55 {
56 buffer[0] = (char) ((code >> 8) & 0xff);
57 buffer[1] = (char) (code & 0xff);
58 buffer[2] = '\0';
59 }
60 string = buffer;
61
62 if (OSGetFontEncode() == OS_FONT_ENCODE_SJIS)
63 {
64 fontData = OSAllocFromArenaLo(OS_FONT_DATA_SIZE_SJIS, 32);
65 }
66 else
67 {
68 fontData = OSAllocFromArenaLo(OS_FONT_DATA_SIZE_ANSI, 32);
69 }
70 OSLoadFont(fontData, OSGetArenaLo());
71
72 // Clear image buffer by zero since OSGetFontTexel() copies out
73 // font texels using logical OR.
74 memset(image, 0x00, sizeof(image));
75
76 OSReport("code %x\n\n", code);
77
78 // OSGetFontTexel() only works with the compressed font data
79 // read by OSLoadFont().
80 string = OSGetFontTexel(string, image, 0, 24 / 4, &width);
81 for (i = 0; i < 24; i++)
82 {
83 j = 24 * (i / 8) + (i % 8);
84 OSReport("%08x%08x%08x\n",
85 image[j],
86 image[j + 32 / sizeof(u32)],
87 image[j + 64 / sizeof(u32)]);
88 }
89
90 OSReport("\nwidth %d\n", width);
91 }
92