Fixed warnings and removed unnecessary include files.
[AROS.git] / workbench / system / ftmanager / fontinfo_class.c
blob395aaafdec2eb26c40fc5b3a1c2a9614e03488b9
1 #include <proto/alib.h>
3 #define NO_INLINE_STDARG
5 #include <aros/debug.h>
6 #include <exec/types.h>
7 #include <diskfont/diskfonttag.h>
8 #define MUI_OBSOLETE
9 #include <libraries/mui.h>
11 #include <proto/intuition.h>
12 #include <proto/utility.h>
13 #include <proto/muimaster.h>
14 #include <proto/asl.h>
15 #include <proto/dos.h>
17 #include "fontinfo_class.h"
18 #include "fontbitmap_class.h"
19 #include "globals.h"
20 #include "locale.h"
22 struct FontInfoData
24 STRPTR Filename;
25 FT_Face Face;
26 Object *AttachedFile;
27 Object *Name;
28 Object *YSizeFactorHigh;
29 Object *YSizeFactorLow;
30 Object *StemWeight;
31 Object *SlantStyle;
32 Object *HorizStyle;
33 Object *Family;
34 Object *Fixed;
35 Object *Serif;
36 //Object *AlgoStyle;
37 Object *FaceNum;
38 Object *Metric;
39 Object *BBoxYMin;
40 Object *BBoxYMax;
41 Object *SpaceWidth;
42 Object *Preview;
43 Object *PreviewGroup;
44 Object *Gray;
45 Object *TestSize;
46 Object *TestString;
47 struct TagItem OTags[26];
48 UWORD AvailSizes[OT_MAXAVAILSIZES];
51 typedef struct FontInfoData FontInfoData;
53 struct CycleToStringP
55 Object *String;
56 int NumValues;
57 const UBYTE *Values;
60 AROS_UFH3(void, CycleToString,
61 AROS_UFHA(struct Hook *, hook, A0),
62 AROS_UFHA(Object *, cycle, A2),
63 AROS_UFHA(struct CycleToStringP *, p, A1))
65 AROS_USERFUNC_INIT
67 IPTR entry = 0;
68 Object *str = p->String;
70 get(cycle, MUIA_Cycle_Active, &entry);
71 if (entry == p->NumValues)
73 set(str, MUIA_Disabled, FALSE);
75 else
77 SetAttrs(str,
78 MUIA_Disabled, TRUE,
79 MUIA_String_Integer, p->Values[entry],
80 TAG_END);
83 AROS_USERFUNC_EXIT
87 struct Hook CycleToStringHook = { {NULL, NULL}, UFHN(CycleToString) };
90 struct IntegerBoundsP
92 LONG Min;
93 LONG Max;
96 AROS_UFH3(void, IntegerBounds,
97 AROS_UFHA(struct Hook *, hook, A0),
98 AROS_UFHA(Object *, obj, A2),
99 AROS_UFHA(struct IntegerBoundsP *, p, A1))
101 AROS_USERFUNC_INIT
103 IPTR t = 0;
105 get(obj, MUIA_String_Integer, &t);
106 if (t < p->Min)
108 set(obj, MUIA_String_Integer, p->Min);
110 else if (t > p->Max)
112 set(obj, MUIA_String_Integer, p->Max);
115 AROS_USERFUNC_EXIT
119 struct Hook IntegerBoundsHook = { {NULL, NULL}, UFHN(IntegerBounds) };
122 AROS_UFH3(void, Metric,
123 AROS_UFHA(struct Hook *, hook, A0),
124 AROS_UFHA(Object *, obj, A2),
125 AROS_UFHA(Object **, p, A1))
127 AROS_USERFUNC_INIT
129 IPTR t = 0;
130 ULONG state;
131 int k;
133 get(obj, MUIA_Cycle_Active, &t);
134 state = t != 5;
135 for (k = 0; k < 2; ++k)
137 set(p[k], MUIA_Disabled, state);
140 AROS_USERFUNC_EXIT
144 struct Hook MetricHook = { {NULL, NULL}, UFHN(Metric) };
147 IPTR fiNew(Class *cl, Object *o, struct opSet *msg)
149 struct opSet method;
150 struct TagItem tags[3];
151 STRPTR filename = (STRPTR)GetTagData(MUIA_FontInfo_Filename, (IPTR) NULL, msg->ops_AttrList);
152 FT_Face face = (FT_Face)GetTagData(MUIA_FontInfo_Face, (IPTR) NULL, msg->ops_AttrList);
153 TT_Postscript *postscript;
154 TT_OS2 *os2;
155 Object *name, *attached_file, *size_factor_low, *size_factor_high;
156 Object *stem_weight, *slant_style, *horiz_style, *stem_weight_cycle, *horiz_style_cycle;
157 Object *family, *fixed, /**algo_style,*/ *face_num, *preview, *preview_group;
158 Object *gray, *test_string, *test_size, *serif, *space_width;
159 Object *metric, *bbox_ymin, *bbox_ymax;
160 char name_buf[27];
161 int k, l;
162 const char *q, *r;
164 static CONST_STRPTR stem_weight_names[] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
165 stem_weight_names[0] =_(MSG_WEIGHT_ULTRATHIN);
166 stem_weight_names[1] =_(MSG_WEIGHT_EXTRATHIN);
167 stem_weight_names[2] =_(MSG_WEIGHT_THIN);
168 stem_weight_names[3] =_(MSG_WEIGHT_EXTRALIGHT);
169 stem_weight_names[4] =_(MSG_WEIGHT_LIGHT);
170 stem_weight_names[5] =_(MSG_WEIGHT_DEMILIGHT);
171 stem_weight_names[6] =_(MSG_WEIGHT_SEMILIGHT);
172 stem_weight_names[7] =_(MSG_WEIGHT_BOOK);
173 stem_weight_names[8] =_(MSG_WEIGHT_MEDIUM);
174 stem_weight_names[9] =_(MSG_WEIGHT_SEMIBOLD);
175 stem_weight_names[10] =_(MSG_WEIGHT_DEMIBOLD);
176 stem_weight_names[11] =_(MSG_WEIGHT_BOLD);
177 stem_weight_names[12] =_(MSG_WEIGHT_EXTRABOLD);
178 stem_weight_names[13] =_(MSG_WEIGHT_BLACK);
179 stem_weight_names[14] =_(MSG_WEIGHT_EXTRABLACK);
180 stem_weight_names[15] =_(MSG_WEIGHT_ULTRABLACK);
181 stem_weight_names[16] =_(MSG_WEIGHT_CUSTOM);
183 static const UBYTE stem_weight_values[] =
185 OTS_UltraThin,
186 OTS_ExtraThin,
187 OTS_Thin,
188 OTS_ExtraLight,
189 OTS_Light,
190 OTS_DemiLight,
191 OTS_SemiLight,
192 OTS_Book,
193 OTS_Medium,
194 OTS_SemiBold,
195 OTS_DemiBold,
196 OTS_Bold,
197 OTS_ExtraBold,
198 OTS_Black,
199 OTS_ExtraBlack,
200 OTS_UltraBlack,
203 static CONST_STRPTR slant_style_names[] = {NULL, NULL, NULL, NULL};
204 slant_style_names[0] = _(MSG_STYLE_UPRIGHT);
205 slant_style_names[1] = _(MSG_STYLE_ITALIC);
206 slant_style_names[2] = _(MSG_STYLE_LEFTITALIC);
208 static CONST_STRPTR horiz_style_names[] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
209 horiz_style_names[0] = _(MSG_HSTYLE_ULTRACOMPRESSED);
210 horiz_style_names[1] = _(MSG_HSTYLE_EXTRACOMPRESSED);
211 horiz_style_names[2] = _(MSG_HSTYLE_COMPRESSED);
212 horiz_style_names[3] = _(MSG_HSTYLE_CONDENSED);
213 horiz_style_names[4] = _(MSG_HSTYLE_NORMAL);
214 horiz_style_names[5] = _(MSG_HSTYLE_SEMIEXPANDED);
215 horiz_style_names[6] = _(MSG_HSTYLE_EXPANDED);
216 horiz_style_names[7] = _(MSG_HSTYLE_EXTRAEXPANDED);
217 horiz_style_names[8] = _(MSG_HSTYLE_CUSTOM);
219 static const UBYTE horiz_style_values[] =
221 OTH_UltraCompressed,
222 OTH_ExtraCompressed,
223 OTH_Compressed,
224 OTH_Condensed,
225 OTH_Normal,
226 OTH_SemiExpanded,
227 OTH_Expanded,
228 OTH_ExtraExpanded,
231 static CONST_STRPTR metric_names[] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL};
232 metric_names[0] = _(MSG_METRIC_GLOBALBOUNDINGBOX);
233 metric_names[1] = _(MSG_METRIC_RAWFONTMETRIC);
234 metric_names[2] = _(MSG_METRIC_ASCENDER);
235 metric_names[3] = _(MSG_METRIC_TYPOASCENDER);
236 metric_names[4] = _(MSG_METRIC_USWINASCENDER);
237 metric_names[5] = _(MSG_METRIC_CUSTOMBOUNDINGBOX);
238 //"Bitmap size"
241 if (!filename || !face)
243 DEBUG_FONTINFO(dprintf("FontInfo: filename 0x%x face 0x%x\n", filename, face));
244 return 0;
247 q = face->family_name;
248 r = face->style_name;
249 k = 0;
250 l = -1;
251 while (k < sizeof(name_buf) - 1)
253 while (*q == ' ')
254 ++q;
255 if (!*q)
257 if (r)
259 q = r;
260 r = NULL;
261 continue;
263 break;
265 if (*q == '.')
266 l = k;
267 name_buf[k] = ToLower(*q);
268 ++k;
269 ++q;
271 if (l > 0)
272 k = l;
273 name_buf[k] = '\0';
275 postscript = FT_Get_Sfnt_Table(face, ft_sfnt_post);
276 os2 = FT_Get_Sfnt_Table(face, ft_sfnt_os2);
278 tags[0].ti_Tag = MUIA_Group_Child;
279 tags[0].ti_Data = (IPTR)ColGroup(2),
280 Child, Label2(_(MSG_LABEL_EXTRAFILE)),
281 Child, attached_file = PopaslObject,
282 MUIA_Popasl_Type, ASL_FileRequest,
283 MUIA_Popstring_String, StringObject,
284 StringFrame,
285 MUIA_String_AdvanceOnCR, TRUE,
286 MUIA_CycleChain, TRUE,
287 End,
288 MUIA_Popstring_Button, PopButton(MUII_PopFile),
289 ASLFR_RejectIcons, TRUE,
290 End,
291 Child, Label2(_(MSG_LABEL_FACENUM)),
292 Child, face_num = StringObject,
293 StringFrame,
294 MUIA_String_Integer, 0,
295 MUIA_String_Accept, "0123456789",
296 MUIA_String_AdvanceOnCR, TRUE,
297 MUIA_String_MaxLen, 5,
298 MUIA_CycleChain, TRUE,
299 End,
300 Child, Label2(_(MSG_LABEL_NAME)),
301 Child, name = StringObject,
302 StringFrame,
303 MUIA_String_Contents, name_buf,
304 MUIA_String_AdvanceOnCR, TRUE,
305 MUIA_String_MaxLen, 27,
306 MUIA_CycleChain, TRUE,
307 End,
308 Child, Label2(_(MSG_LABEL_FAMILY)),
309 Child, family = StringObject,
310 StringFrame,
311 MUIA_String_Contents, face->family_name,
312 MUIA_String_AdvanceOnCR, TRUE,
313 MUIA_CycleChain, TRUE,
314 End,
315 Child, Label2(_(MSG_LABEL_METRIC)),
316 Child, metric = CycleObject,
317 MUIA_Cycle_Entries, metric_names,
318 MUIA_Cycle_Active, 1,
319 MUIA_CycleChain, TRUE,
320 End,
321 Child, Label2(_(MSG_LABEL_BOUNDINGBOX)),
322 Child, HGroup,
323 Child, Label2("yMin"),
324 Child, bbox_ymin = StringObject,
325 StringFrame,
326 MUIA_String_Accept, "-0123456789",
327 MUIA_String_AdvanceOnCR, TRUE,
328 MUIA_String_MaxLen, 6,
329 MUIA_String_Integer, face->bbox.yMin,
330 MUIA_CycleChain, TRUE,
331 End,
332 Child, Label2("yMax"),
333 Child, bbox_ymax = StringObject,
334 StringFrame,
335 MUIA_String_Accept, "-0123456789",
336 MUIA_String_AdvanceOnCR, TRUE,
337 MUIA_String_MaxLen, 6,
338 MUIA_String_Integer, face->bbox.yMax,
339 MUIA_CycleChain, TRUE,
340 End,
341 End,
342 Child, Label2(_(MSG_LABEL_SIZEFACTOR)),
343 Child, HGroup,
344 Child, size_factor_low = StringObject,
345 StringFrame,
346 MUIA_String_Accept, "0123456789",
347 MUIA_String_AdvanceOnCR, TRUE,
348 MUIA_String_MaxLen, 6,
349 MUIA_String_Integer, 1,
350 MUIA_CycleChain, TRUE,
351 End,
352 Child, TextObject,
353 MUIA_Text_Contents, "/",
354 MUIA_Text_SetMax, TRUE,
355 End,
356 Child, size_factor_high = StringObject,
357 StringFrame,
358 MUIA_String_Accept, "0123456789",
359 MUIA_String_AdvanceOnCR, TRUE,
360 MUIA_String_MaxLen, 6,
361 MUIA_String_Integer, 1,
362 MUIA_CycleChain, TRUE,
363 End,
364 End,
365 Child, Label2(_(MSG_LABEL_SPACEWIDTH)),
366 Child, space_width = StringObject,
367 StringFrame,
368 MUIA_String_Accept, "0123456789",
369 MUIA_String_AdvanceOnCR, TRUE,
370 MUIA_String_MaxLen, 6,
371 MUIA_String_Integer, (IPTR)(face->max_advance_width * 250.0 / 72.307),
372 MUIA_CycleChain, TRUE,
373 End,
374 Child, Label1(_(MSG_LABEL_FIXEDWIDTH)),
375 Child, HGroup,
376 Child, fixed = CheckMark((face->face_flags & FT_FACE_FLAG_FIXED_WIDTH) != 0),
377 Child, RectangleObject,
378 End,
379 End,
380 Child, Label1(_(MSG_LABEL_SERIF)),
381 Child, HGroup,
382 Child, serif = CheckMark(os2 && (unsigned)(((os2->sFamilyClass >> 8) &
383 0xff) - 1) < 5),
384 Child, RectangleObject,
385 End,
386 End,
387 Child, Label2(_(MSG_LABEL_STEMWEIGHT)),
388 Child, HGroup,
389 Child, stem_weight_cycle = CycleObject,
390 MUIA_Cycle_Entries, stem_weight_names,
391 MUIA_CycleChain, TRUE,
392 End,
393 Child, stem_weight = StringObject,
394 StringFrame,
395 MUIA_String_Accept, "0123456789",
396 MUIA_String_AdvanceOnCR, TRUE,
397 MUIA_String_MaxLen, 4,
398 MUIA_String_Integer, 128,
399 MUIA_CycleChain, TRUE,
400 End,
401 End,
402 Child, Label2(_(MSG_LABEL_SLANTSTYLE)),
403 Child, slant_style = CycleObject,
404 MUIA_Cycle_Entries, slant_style_names,
405 MUIA_Cycle_Active, face->style_flags & FT_STYLE_FLAG_ITALIC ?
406 (postscript && postscript->italicAngle > 0 ?
407 OTS_LeftItalic : OTS_Italic) : OTS_Upright,
408 MUIA_CycleChain, TRUE,
409 End,
410 Child, Label2(_(MSG_LABEL_HORIZSTYLE)),
411 Child, HGroup,
412 Child, horiz_style_cycle = CycleObject,
413 MUIA_Cycle_Entries, horiz_style_names,
414 MUIA_CycleChain, TRUE,
415 End,
416 Child, horiz_style = StringObject,
417 StringFrame,
418 MUIA_String_Accept, "0123456789",
419 MUIA_String_AdvanceOnCR, TRUE,
420 MUIA_String_MaxLen, 4,
421 MUIA_String_Integer, 128,
422 MUIA_CycleChain, TRUE,
423 End,
424 End,
425 /*Child, Label1("No algo style"),
426 Child, HGroup,
427 Child, algo_style = CheckMark(FALSE),
428 Child, RectangleObject,
429 End,
430 End,*/
431 End;
432 tags[1].ti_Tag = MUIA_Group_Child;
433 tags[1].ti_Data = (IPTR)VGroup,
434 GroupFrameT(_(MSG_FRAME_PREVIEW)),
435 Child, test_string = StringObject,
436 StringFrame,
437 MUIA_String_Contents, _(MSG_PREVIEW_STRING),
438 MUIA_String_AdvanceOnCR, TRUE,
439 MUIA_CycleChain, TRUE,
440 End,
441 Child, HGroup,
442 Child, Label2(_(MSG_LABEL_SIZE)),
443 Child, test_size = StringObject,
444 StringFrame,
445 MUIA_String_Accept, "0123456789",
446 MUIA_String_Integer, 30,
447 MUIA_String_AdvanceOnCR, TRUE,
448 MUIA_CycleChain, TRUE,
449 End,
450 Child, Label2(_(MSG_LABEL_ANTIALIASING)),
451 Child, gray = CheckMark(FALSE),
452 End,
453 Child, ScrollgroupObject,
454 MUIA_Scrollgroup_Contents, VirtgroupObject,
455 VirtualFrame,
456 Child, VCenter(HCenter((preview_group = VGroup,
457 Child, preview = RectangleObject,
458 End,
459 End))),
460 End,
461 End,
462 End;
463 tags[2].ti_Tag = TAG_MORE;
464 tags[2].ti_Data = (IPTR)msg->ops_AttrList;
466 method.MethodID = OM_NEW;
467 method.ops_AttrList = tags;
468 method.ops_GInfo = NULL;
470 o = (Object *)DoSuperMethodA(cl, o, (Msg)&method);
471 if (o)
473 FontInfoData *dat = INST_DATA(cl, o);
475 dat->Filename = filename;
476 dat->Face = face;
477 dat->AttachedFile = attached_file;
478 dat->Name = name;
479 dat->Family = family;
480 dat->YSizeFactorLow = size_factor_low;
481 dat->YSizeFactorHigh = size_factor_high;
482 dat->StemWeight = stem_weight;
483 dat->SlantStyle = slant_style;
484 dat->HorizStyle = horiz_style;
485 dat->SpaceWidth = space_width;
486 dat->Fixed = fixed;
487 dat->Serif = serif;
488 //dat->AlgoStyle = algo_style;
489 dat->FaceNum = face_num;
490 dat->Metric = metric;
491 dat->BBoxYMin = bbox_ymin;
492 dat->BBoxYMax = bbox_ymax;
493 dat->Preview = preview;
494 dat->PreviewGroup = preview_group;
495 dat->TestString = test_string;
496 dat->TestSize = test_size;
497 dat->Gray = gray;
499 DoMethod(size_factor_low, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
500 size_factor_low, 4, MUIM_CallHook, &IntegerBoundsHook, 1, 65535);
501 DoMethod(size_factor_high, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
502 size_factor_high, 4, MUIM_CallHook, &IntegerBoundsHook, 1, 65535);
504 DoMethod(stem_weight_cycle, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime,
505 stem_weight_cycle, 5, MUIM_CallHook, &CycleToStringHook,
506 stem_weight, sizeof(stem_weight_values), stem_weight_values);
507 DoMethod(stem_weight, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
508 stem_weight, 4, MUIM_CallHook, &IntegerBoundsHook, 0, 255);
510 DoMethod(horiz_style_cycle, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime,
511 horiz_style_cycle, 5, MUIM_CallHook, &CycleToStringHook,
512 horiz_style, sizeof(horiz_style_values), horiz_style_values);
513 DoMethod(horiz_style, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
514 horiz_style, 4, MUIM_CallHook, &IntegerBoundsHook, 0, 255);
516 set(stem_weight_cycle, MUIA_Cycle_Active,
517 face->style_flags & FT_STYLE_FLAG_BOLD ? 11 : 7);
518 set(horiz_style_cycle, MUIA_Cycle_Active, 4);
520 DoMethod(test_string, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
521 o, 1, MUIM_FontInfo_UpdatePreview);
522 DoMethod(test_size, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
523 o, 1, MUIM_FontInfo_UpdatePreview);
524 DoMethod(gray, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
525 o, 1, MUIM_FontInfo_UpdatePreview);
527 DoMethod(bbox_ymin, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
528 bbox_ymin, 4, MUIM_CallHook, &IntegerBoundsHook, -32768, 32767);
529 DoMethod(bbox_ymax, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
530 bbox_ymax, 4, MUIM_CallHook, &IntegerBoundsHook, -32768, 32767);
532 DoMethod(metric, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime,
533 metric, 6, MUIM_CallHook, &MetricHook, bbox_ymin, bbox_ymax);
535 set(metric, MUIA_Cycle_Active, 0);
537 if (//!(face->face_flags & FT_FACE_FLAG_FIXED_WIDTH) &&
538 FT_Set_Char_Size(face, 250 * 64, 250 * 64, 2540, 2540) == 0 &&
539 FT_Load_Char(face, ' ', FT_LOAD_DEFAULT) == 0)
541 set(space_width, MUIA_String_Integer, face->glyph->metrics.horiAdvance >> 6);
544 if (os2)
546 int weight = os2->usWeightClass;
547 int value;
549 value = 0; /* UltraThin */
550 if (weight < 10) weight *= 100;
551 if (weight >= 200) value = 2; /* Thin */
552 if (weight >= 300) value = 4; /* Light */
553 if (weight >= 400) value = 7; /* Book */
554 if (weight >= 500) value = 8; /* Medium */
555 if (weight >= 600) value = 10; /* DemiBold */
556 if (weight >= 700) value = 11; /* Bold */
557 if (weight >= 800) value = 13; /* Black */
558 if (weight >= 900) value = 15; /* UltraBlack */
559 set(stem_weight_cycle, MUIA_Cycle_Active, value);
561 set(horiz_style_cycle, MUIA_Cycle_Active, os2->usWidthClass - 1);
564 DoMethod(o, MUIM_FontInfo_UpdatePreview);
567 DEBUG_FONTINFO(dprintf("FontInfo: created object 0x%lx\n", o));
569 return (IPTR)o;
572 #if 0
573 IPTR fiDispose(Class *cl, Object *o)
575 FontInfoData *dat = INST_DATA(cl, o);
577 return DoSuperMethod(cl, o, OM_DISPOSE);
579 #endif
581 IPTR fiSetOTags(Class *cl, Object *o)
583 FontInfoData *dat = INST_DATA(cl, o);
584 struct TagItem *tag = dat->OTags;
585 IPTR x = 0;
586 IPTR y = 0;
588 tag->ti_Tag = OT_FileIdent;
589 ++tag;
591 tag->ti_Tag = OT_Engine;
592 tag->ti_Data = (IPTR)"freetype2";
593 ++tag;
595 tag->ti_Tag = OT_Family;
596 get(dat->Family, MUIA_String_Contents, &tag->ti_Data);
597 ++tag;
599 //tag->ti_Tag = OT_BName;
600 //tag->ti_Tag = OT_IName;
601 //tag->ti_Tag = OT_BIName;
602 //tag->ti_Tag = OT_SymbolSet; charmap index
604 get(dat->YSizeFactorLow, MUIA_String_Integer, &x);
605 get(dat->YSizeFactorHigh, MUIA_String_Integer, &y);
606 x = (UWORD)x;
607 y = (UWORD)y;
608 if (x == 0) x = 1;
609 if (y == 0) y = 1;
610 tag->ti_Tag = OT_YSizeFactor;
611 tag->ti_Data = x | (y << 16);
612 ++tag;
614 tag->ti_Tag = OT_SpaceWidth;
615 get(dat->SpaceWidth, MUIA_String_Integer, &tag->ti_Data);
616 ++tag;
618 tag->ti_Tag = OT_IsFixed;
619 get(dat->Fixed, MUIA_Selected, &tag->ti_Data);
620 ++tag;
622 tag->ti_Tag = OT_SerifFlag;
623 get(dat->Serif, MUIA_Selected, &tag->ti_Data);
624 ++tag;
626 tag->ti_Tag = OT_StemWeight;
627 get(dat->StemWeight, MUIA_String_Integer, &tag->ti_Data);
628 ++tag;
630 tag->ti_Tag = OT_SlantStyle;
631 get(dat->SlantStyle, MUIA_Cycle_Active, &tag->ti_Data);
632 ++tag;
634 tag->ti_Tag = OT_HorizStyle;
635 get(dat->HorizStyle, MUIA_String_Integer, &tag->ti_Data);
636 ++tag;
638 tag->ti_Tag = OT_SpaceFactor;
639 tag->ti_Data = 0x10000;
640 ++tag;
642 tag->ti_Tag = OT_InhibitAlgoStyle;
643 tag->ti_Data = FSF_UNDERLINED | FSF_BOLD;
644 //get(dat->AlgoStyle, MUIA_Selected, &tag->ti_Data);
645 ++tag;
647 tag->ti_Tag = OT_SpecCount;
648 tag->ti_Data = 4;
649 ++tag;
651 tag->ti_Tag = OT_Spec1_FontFile;
652 tag->ti_Data = (IPTR)dat->Filename;
653 ++tag;
655 tag->ti_Tag = OT_Spec3_AFMFile;
656 get(dat->AttachedFile, MUIA_String_Contents, &tag->ti_Data);
657 ++tag;
659 tag->ti_Tag = OT_Spec4_Metric;
660 get(dat->Metric, MUIA_Cycle_Active, &tag->ti_Data);
661 ++tag;
663 if (tag[-1].ti_Data == METRIC_CUSTOMBBOX)
665 IPTR ymin = 0;
666 IPTR ymax = 0;
668 get(dat->BBoxYMin, MUIA_String_Integer, &ymin);
669 get(dat->BBoxYMax, MUIA_String_Integer, &ymax);
670 tag->ti_Tag = OT_Spec5_BBox;
671 tag->ti_Data = (ymax << 16) | (UWORD)ymin;
672 ++tag;
675 tag->ti_Tag = OT_Spec6_FaceNum;
676 get(dat->FaceNum, MUIA_String_Integer, &tag->ti_Data);
677 ++tag;
679 if (!IsDefaultCodePage())
681 tag->ti_Tag = OT_Spec2_CodePage;
682 tag->ti_Data = (IPTR)codepage;
683 ++tag;
686 tag->ti_Tag = TAG_END;
688 dat->AvailSizes[0] = AROS_WORD2BE(2); // <- number of entries...
689 dat->AvailSizes[1] = AROS_WORD2BE(10);
690 dat->AvailSizes[2] = AROS_WORD2BE(15);
692 return tag - dat->OTags;
695 ULONG fiUpdatePreview(Class *cl, Object *o)
697 FontInfoData *dat = INST_DATA(cl, o);
698 Object *preview;
699 STRPTR str = NULL;
700 IPTR gray = 0;
701 IPTR size = 0;
703 fiSetOTags(cl, o);
705 get(dat->TestString, MUIA_String_Contents, &str);
706 get(dat->Gray, MUIA_Selected, &gray);
707 get(dat->TestSize, MUIA_String_Integer, &size);
709 preview = FontBitmapObject,
710 MUIA_FontBitmap_Filename, dat->Filename,
711 MUIA_FontBitmap_OTags, dat->OTags,
712 MUIA_FontBitmap_String, str,
713 MUIA_FontBitmap_Gray, gray,
714 MUIA_FontBitmap_Size, size,
715 End;
717 DEBUG_FONTINFO(dprintf("FontInfo::UpdatePreview: new 0x%lx\n", preview));
719 if (preview)
721 DoMethod(dat->PreviewGroup, MUIM_Group_InitChange);
722 if (dat->Preview)
724 DoMethod(dat->PreviewGroup, OM_REMMEMBER, dat->Preview);
725 DisposeObject(dat->Preview);
727 DoMethod(dat->PreviewGroup, OM_ADDMEMBER, preview);
728 DoMethod(dat->PreviewGroup, MUIM_Group_ExitChange);
729 dat->Preview = preview;
732 return preview != NULL;
735 ULONG fiWriteFiles(Class *cl, Object *o)
737 FontInfoData *dat = INST_DATA(cl, o);
738 BPTR file;
739 char name[32];
740 STRPTR base = NULL;
741 BPTR olddir;
743 get(dat->Name, MUIA_String_Contents, &base);
744 if (!base || !base[0])
745 return FALSE;
747 olddir = CurrentDir(destdir);
749 strcpy(name, base);
750 strcat(name, ".otag");
752 file = Open(name, MODE_NEWFILE);
753 if (file)
755 struct TagItem *tag;
756 ULONG size, indirect_size;
757 UBYTE *buffer;
758 int num_sizes;
761 * In the file we store 32-bit form of taglist.
762 * Each complete tag can be represented by UQUAD (two ULONGs),
763 * and we also append one ULONG for TAG_DONE terminator
765 size = sizeof(ULONG) + (fiSetOTags(cl, o) + 2) * sizeof(UQUAD);
766 indirect_size = 0;
768 for (tag = dat->OTags; tag->ti_Tag != TAG_END; ++tag)
770 if (tag->ti_Tag == OT_Spec2_CodePage)
772 indirect_size += 1;
773 indirect_size &= ~1;
774 indirect_size += sizeof(codepage);
776 else if (tag->ti_Tag & OT_Indirect && tag->ti_Data)
778 indirect_size += strlen((const char *)tag->ti_Data) + 1;
782 indirect_size += 1;
783 indirect_size &= ~1;
785 num_sizes = 1 + dat->AvailSizes[0];
786 indirect_size += num_sizes * sizeof(UWORD);
788 dat->OTags[0].ti_Data = size + indirect_size;
790 buffer = malloc(indirect_size);
791 if (buffer)
793 size_t offset = 0;
794 ULONG *write_tags;
795 ULONG *dest;
797 memset(buffer, 0, indirect_size);
799 for (tag = dat->OTags; tag->ti_Tag != TAG_END; ++tag)
801 if (tag->ti_Tag == OT_Spec2_CodePage)
803 offset += 1;
804 offset &= ~1;
805 memcpy(buffer + offset, codepage, sizeof(codepage));
806 tag->ti_Data = size + offset;
807 offset += sizeof(codepage);
809 else if (tag->ti_Tag & OT_Indirect && tag->ti_Data)
811 size_t len = strlen((const char *)tag->ti_Data) + 1;
813 memcpy(buffer + offset, (const char *)tag->ti_Data, len);
814 tag->ti_Data = size + offset;
815 offset += len;
819 offset += 1;
820 offset &= ~1;
822 tag->ti_Tag = OT_AvailSizes;
823 tag->ti_Data = size + offset;
824 ++tag;
826 tag->ti_Tag = TAG_END;
828 memcpy(buffer + offset, dat->AvailSizes, num_sizes * sizeof(UWORD));
829 offset += num_sizes * sizeof(UWORD);
831 write_tags = malloc(size);
833 dest = write_tags;
834 for (tag = dat->OTags; tag->ti_Tag != TAG_END; tag++)
836 dest[0] = AROS_LONG2BE(tag->ti_Tag);
837 dest[1] = AROS_LONG2BE(tag->ti_Data);
838 dest += 2;
840 dest[0] = AROS_LONG2BE(TAG_END);
842 Write(file, write_tags, size);
843 free(write_tags);
845 Write(file, buffer, offset);
846 free(buffer);
849 Close(file);
852 strcpy(name, base);
853 strcat(name, ".font");
855 file = Open(name, MODE_NEWFILE);
856 if (file)
858 static UBYTE data[] = {0x0f, 0x03, 0x00, 0x00 };
859 Write(file, data, sizeof(data));
860 Close(file);
863 CurrentDir(olddir);
865 return 1;
868 AROS_UFH3(ULONG, FontInfoDispatch,
869 AROS_UFHA(Class *, cl, A0),
870 AROS_UFHA(Object *, o, A2),
871 AROS_UFHA(Msg, msg, A1))
873 AROS_USERFUNC_INIT
875 ULONG ret;
877 switch (msg->MethodID)
879 case OM_NEW:
880 ret = fiNew(cl, o, (struct opSet *)msg);
881 break;
883 #if 0
884 case OM_DISPOSE:
885 ret = fiDispose(cl, o);
886 break;
887 #endif
889 case MUIM_FontInfo_UpdatePreview:
890 ret = fiUpdatePreview(cl, o);
891 break;
893 case MUIM_FontInfo_WriteFiles:
894 ret = fiWriteFiles(cl, o);
895 break;
897 default:
898 ret = DoSuperMethodA(cl, o, msg);
899 break;
902 return ret;
904 AROS_USERFUNC_EXIT
908 void CleanupFontInfoClass(void)
910 if (FontInfoClass)
912 MUI_DeleteCustomClass(FontInfoClass);
913 FontInfoClass = NULL;
917 int InitFontInfoClass(void)
919 FontInfoClass = MUI_CreateCustomClass(NULL, MUIC_Group, NULL,
920 sizeof(FontInfoData), UFHN(FontInfoDispatch));
921 return FontInfoClass != NULL;