forked from mgroeber9110/freegeos-font-lister
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fontlist.goc
233 lines (190 loc) · 7.82 KB
/
fontlist.goc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/*
* FONTLIST.GOC - prototype of a Geos font listing application
*
* by Marcus Groeber, [email protected]
*
*/
@include <stdapp.goh>
#include <Ansi/stdio.h>
#include <timer.h>
#define MAX_SAMPLE_LEN 512
#define TEMP_FILE_NAME "Font List Buffer"
/*
* every application needs a process class that handles some of the
* most basic messages
*/
@class FontListProcessClass, GenProcessClass;
@message void MSG_FONT_LIST_PROCESS_UPDATE();
@endc
@classdecl FontListProcessClass, neverSaved;
/*
***************************************************************************
* UI Objects
***************************************************************************
*/
@start AppResource;
/* declare the main application object */
@object GenApplicationClass FontListApp = {
GI_visMoniker = list { @FontListTextMoniker }
GI_comp = @FontListPrimary; /* one main window, nothing else */
gcnList(MANUFACTURER_ID_GEOWORKS,GAGCNLT_WINDOWS) =
@FontListPrimary, @SampleDialog;
gcnList(MANUFACTURER_ID_GEOWORKS,GAGCNLT_SELF_LOAD_OPTIONS) =
@EditControl;
}
@visMoniker FontListTextMoniker = "Font Lister";
@end AppResource;
@start Interface; /* resource for misc UI objects */
@object GenPrimaryClass FontListPrimary = {
GI_comp = @EditControl,
@SampleDialog,
@FontListText; /* nothing fancy, just a window with
a text object */
}
@object GenTextClass FontListText = {
GI_attrs = @default | GA_READ_ONLY | GA_TARGETABLE;
/* can't modify text object */
GTXI_attrs = @default | GTA_INIT_SCROLLING;
/* always turn on scrollers */
GTXI_text = ""; /* empty at start */
ATTR_GEN_TEXT_SELECTABLE; /* user can select and QuickCopy */
HINT_EXPAND_HEIGHT_TO_FIT_PARENT; /* use up all space available */
}
@object GenEditControlClass EditControl = {
GI_attrs = @default | GA_KBD_SEARCH_PATH;
GII_visibility = GIV_POPUP;
ATTR_GEN_CONTROL_PROHIBIT_UI = GECF_UNDO|GECF_DELETE|GECF_CUT|GECF_PASTE;
ATTR_GEN_INTERACTION_GROUP_TYPE = (GIGT_EDIT_MENU);
}
@object GenInteractionClass SampleDialog = {
GI_visMoniker = 'L',"FontList";
GI_comp = @SampleText, @UpdateTrigger;
GII_visibility = GIV_DIALOG;
GII_type = GIT_COMMAND;
HINT_SEEK_MENU_BAR;
}
@object GenTextClass SampleText = {
GTXI_attrs = @default | GTA_INIT_SCROLLING;
/* always turn on scrollers */
GTXI_text = "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG\rthe quick brown fox jumps over the lazy dog\rAVATAR 123 +;\x23 \x8A\x80\xA7 \xDB";
GTXI_maxLength = MAX_SAMPLE_LEN;
ATTR_GEN_TEXT_SELECTABLE; /* user can select and QuickCopy */
HINT_EXPAND_HEIGHT_TO_FIT_PARENT; /* use up all space available */
HINT_MINIMUM_SIZE = {SST_AVG_CHAR_WIDTHS | 60, 0, 0};
HINT_INITIAL_SIZE = {SST_AVG_CHAR_WIDTHS | 60, 0, 0};
}
@object GenTriggerClass UpdateTrigger = {
GI_visMoniker = 'U',"Update List";
GTI_destination = process;
GTI_actionMsg = MSG_FONT_LIST_PROCESS_UPDATE;
HINT_SEEK_REPLY_BAR;
}
@end Interface;
/*
***************************************************************************
* Methods and procedures
***************************************************************************
*/
/*
* Performs a speed test of the passed font by rendering the letters
* A to Z into a bitmap and measuring the number of ticks. Because of
* font caching, this is unreliable if run more than once.
*/
dword BenchmarkFont(FontID fid, GStateHandle gstate)
{
char c;
dword t;
t = TimerGetCount();
GrSetFont(gstate, fid, MakeWWFixed(29)); /* unlikely to have bitmap */
for(c='A'; c<='Z'; c++) {
GrDrawText(gstate, 0, 0, &c, 1);
}
return (word)(TimerGetCount() - t);
}
/*
* AppendLine appends the string in str[] and sets the font to the
* passed font id and the point size to the value specified in ps.
*/
void AppendLine(char *str,FontID fid,sword ps)
{
dword p1,p2;
WWFixed pswwf;
p1=@call FontListText::MSG_VIS_TEXT_GET_TEXT_SIZE();
/* get starting position of range */
@call FontListText::MSG_VIS_TEXT_APPEND_PTR(str,0);
/* append text of line */
p2=@call FontListText::MSG_VIS_TEXT_GET_TEXT_SIZE();
/* get end of range */
@call FontListText::MSG_VIS_TEXT_APPEND_PTR("\r",0);
/* add a newline */
@call FontListText::MSG_VIS_TEXT_SET_FONT_ID(fid,p2,p1);
*(WWFixedAsDWord *)&pswwf=MakeWWFixed(ps);
@call FontListText::MSG_VIS_TEXT_SET_POINT_SIZE(pswwf,p2,p1);
/* set font and point size */
}
@method FontListProcessClass, MSG_FONT_LIST_PROCESS_UPDATE
{
word numFonts,i;
MemHandle h;
FontEnumStruct *fes;
char buf[80], sample[MAX_SAMPLE_LEN+1];
VMFileHandle vmf;
VMBlockHandle vmb;
GStateHandle gstate;
@call FontListText::MSG_VIS_TEXT_DELETE_ALL();
numFonts = GrEnumFonts(NULL,0,FEF_ALPHABETIZE|FEF_OUTLINES,0);
/* get number of matching fonts */
h = MemAlloc(sizeof(FontEnumStruct)*numFonts,HF_DYNAMIC,HAF_NO_ERR);
fes = MemLock(h); /* get pointer to memory block */
GrEnumFonts(fes,numFonts,FEF_ALPHABETIZE|FEF_OUTLINES,0);
/* get list of fonts into buffer */
/* Create temporary file holding bitmap */
FileSetStandardPath(SP_WASTE_BASKET);
vmf = VMOpen(TEMP_FILE_NAME, VMAF_FORCE_READ_WRITE,
VMO_CREATE_TRUNCATE, 0); /* create temporary file for fonts */
vmb = GrCreateBitmap(BMF_MONO, 100, 100, vmf, 0, &gstate);
@call SampleText::MSG_VIS_TEXT_GET_ALL_PTR(sample);
@call FontListText::MSG_META_SUSPEND();
/* don't update text object yet */
for(i=0; i<numFonts; i++) /* process all fonts */
{
word t = BenchmarkFont(fes[i].FES_ID, gstate);
AppendLine("",FID_DTC_URW_SANS,12);
sprintf(buf,"%s [%04X] %d ms/char",
fes[i].FES_name, fes[i].FES_ID, (t*100/6));
AppendLine(buf,FID_DTC_URW_SANS,12);
/* add font name/id to list */
AppendLine(sample, fes[i].FES_ID,20);
/* add some sample text */
}
/* Close and delete temporary file holding bitmap */
GrDestroyBitmap(gstate, BMD_KILL_DATA);
VMClose(vmf, FILE_NO_ERRORS);
FileSetStandardPath(SP_WASTE_BASKET);
FileDelete(TEMP_FILE_NAME);
MemUnlock(h);
MemFree(h); /* release memory */
@call FontListText::MSG_META_UNSUSPEND();
/* now show what we have done */
}
/*
* This method handler is called once at the start of the application.
* It loads the font samples into the text window. All other processing
* for resizing, scrolling and ending the application is performed
* by Geos internally.
*/
@method FontListProcessClass, MSG_GEN_PROCESS_OPEN_APPLICATION
{
@callsuper();
@call FontListText::MSG_VIS_TEXT_CREATE_STORAGE(
VTSF_MULTIPLE_CHAR_ATTRS,
FALSE); /* we'll have multiple text fonts */
AppendLine(
"\r"
"Please use the Update List command to generate a font listing. "
"If you experience crashes with a large number of fonts, try reducing "
"the amount of sample text that is used.",
FID_DTC_URW_SANS,14);
@call FontListText::MSG_META_GRAB_TARGET_EXCL();
/* keystrokes go to text object */
}