Fix typo causing incorrect desktop sorting
[AROS.git] / workbench / system / ftmanager / fontinfo_class.c
blob6262a97145a3cd1696a8fbff4d6bef515dab2fbf
1 #define NO_INLINE_STDARG
3 #include <aros/debug.h>
4 #include <exec/types.h>
5 #include <diskfont/diskfonttag.h>
6 #define MUI_OBSOLETE
7 #include <libraries/mui.h>
9 #include <proto/intuition.h>
10 #include <proto/utility.h>
11 #include <proto/muimaster.h>
12 #include <proto/asl.h>
13 #include <proto/dos.h>
15 #include "fontinfo_class.h"
16 #include "fontbitmap_class.h"
17 #include "globals.h"
19 struct FontInfoData
21 STRPTR Filename;
22 FT_Face Face;
23 Object *AttachedFile;
24 Object *Name;
25 Object *YSizeFactorHigh;
26 Object *YSizeFactorLow;
27 Object *StemWeight;
28 Object *SlantStyle;
29 Object *HorizStyle;
30 Object *Family;
31 Object *Fixed;
32 Object *Serif;
33 //Object *AlgoStyle;
34 Object *FaceNum;
35 Object *Metric;
36 Object *BBoxYMin;
37 Object *BBoxYMax;
38 Object *SpaceWidth;
39 Object *Preview;
40 Object *PreviewGroup;
41 Object *Gray;
42 Object *TestSize;
43 Object *TestString;
44 struct TagItem OTags[26];
45 UWORD AvailSizes[OT_MAXAVAILSIZES];
48 typedef struct FontInfoData FontInfoData;
50 struct CycleToStringP
52 Object *String;
53 int NumValues;
54 const UBYTE *Values;
57 AROS_UFH3(void, CycleToString,
58 AROS_UFHA(struct Hook *, hook, A0),
59 AROS_UFHA(Object *, cycle, A2),
60 AROS_UFHA(struct CycleToStringP *, p, A1))
62 AROS_USERFUNC_INIT
64 ULONG entry;
65 Object *str = p->String;
66 get(cycle, MUIA_Cycle_Active, &entry);
67 if (entry == p->NumValues)
69 set(str, MUIA_Disabled, FALSE);
71 else
73 SetAttrs(str,
74 MUIA_Disabled, TRUE,
75 MUIA_String_Integer, p->Values[entry],
76 TAG_END);
79 AROS_USERFUNC_EXIT
83 struct Hook CycleToStringHook = { {NULL, NULL}, UFHN(CycleToString) };
86 struct IntegerBoundsP
88 LONG Min;
89 LONG Max;
92 AROS_UFH3(void, IntegerBounds,
93 AROS_UFHA(struct Hook *, hook, A0),
94 AROS_UFHA(Object *, obj, A2),
95 AROS_UFHA(struct IntegerBoundsP *, p, A1))
97 AROS_USERFUNC_INIT
99 LONG t;
100 get(obj, MUIA_String_Integer, &t);
101 if (t < p->Min)
103 set(obj, MUIA_String_Integer, p->Min);
105 else if (t > p->Max)
107 set(obj, MUIA_String_Integer, p->Max);
110 AROS_USERFUNC_EXIT
114 struct Hook IntegerBoundsHook = { {NULL, NULL}, UFHN(IntegerBounds) };
117 AROS_UFH3(void, Metric,
118 AROS_UFHA(struct Hook *, hook, A0),
119 AROS_UFHA(Object *, obj, A2),
120 AROS_UFHA(Object **, p, A1))
122 AROS_USERFUNC_INIT
124 ULONG t;
125 ULONG state;
126 int k;
128 get(obj, MUIA_Cycle_Active, &t);
129 state = t != 5;
130 for (k = 0; k < 2; ++k)
132 set(p[k], MUIA_Disabled, state);
135 AROS_USERFUNC_EXIT
139 struct Hook MetricHook = { {NULL, NULL}, UFHN(Metric) };
142 ULONG fiNew(Class *cl, Object *o, struct opSet *msg)
144 struct opSet method;
145 struct TagItem tags[3];
146 STRPTR filename = (STRPTR)GetTagData(MUIA_FontInfo_Filename, (IPTR) NULL, msg->ops_AttrList);
147 FT_Face face = (FT_Face)GetTagData(MUIA_FontInfo_Face, (IPTR) NULL, msg->ops_AttrList);
148 TT_Postscript *postscript;
149 TT_OS2 *os2;
150 Object *name, *attached_file, *size_factor_low, *size_factor_high;
151 Object *stem_weight, *slant_style, *horiz_style, *stem_weight_cycle, *horiz_style_cycle;
152 Object *family, *fixed, /**algo_style,*/ *face_num, *preview, *preview_group;
153 Object *gray, *test_string, *test_size, *serif, *space_width;
154 Object *metric, *bbox_ymin, *bbox_ymax;
155 char name_buf[27];
156 int k, l;
157 const char *q, *r;
159 static const char * const stem_weight_names[] =
161 "UltraThin",
162 "ExtraThin",
163 "Thin",
164 "ExtraLight",
165 "Light",
166 "DemiLight",
167 "SemiLight",
168 "Book",
169 "Medium",
170 "SemiBold",
171 "DemiBold",
172 "Bold",
173 "ExtraBold",
174 "Black",
175 "ExtraBlack",
176 "UltraBlack",
177 "Custom",
178 NULL
180 static const UBYTE stem_weight_values[] =
182 OTS_UltraThin,
183 OTS_ExtraThin,
184 OTS_Thin,
185 OTS_ExtraLight,
186 OTS_Light,
187 OTS_DemiLight,
188 OTS_SemiLight,
189 OTS_Book,
190 OTS_Medium,
191 OTS_SemiBold,
192 OTS_DemiBold,
193 OTS_Bold,
194 OTS_ExtraBold,
195 OTS_Black,
196 OTS_ExtraBlack,
197 OTS_UltraBlack,
200 static const char * const slant_style_names[] =
202 "Upright",
203 "Italic",
204 "LeftItalic",
205 NULL
208 static const char * const horiz_style_names[] =
210 "UltraCompressed",
211 "ExtraCompressed",
212 "Compressed",
213 "Condensed",
214 "Normal",
215 "SemiExpanded",
216 "Expanded",
217 "ExtraExpanded",
218 "Custom",
219 NULL
221 static const UBYTE horiz_style_values[] =
223 OTH_UltraCompressed,
224 OTH_ExtraCompressed,
225 OTH_Compressed,
226 OTH_Condensed,
227 OTH_Normal,
228 OTH_SemiExpanded,
229 OTH_Expanded,
230 OTH_ExtraExpanded,
233 static const char *metric_names[] =
235 "Global bounding box",
236 "Raw font metric",
237 "Ascender",
238 "Typo ascender",
239 "USWin ascender",
240 "Custom bounding box",
241 //"Bitmap size",
242 NULL,
245 if (!filename || !face)
247 DEBUG_FONTINFO(dprintf("FontInfo: filename 0x%x face 0x%x\n", filename, face));
248 return 0;
251 q = face->family_name;
252 r = face->style_name;
253 k = 0;
254 l = -1;
255 while (k < sizeof(name_buf) - 1)
257 while (*q == ' ')
258 ++q;
259 if (!*q)
261 if (r)
263 q = r;
264 r = NULL;
265 continue;
267 break;
269 if (*q == '.')
270 l = k;
271 name_buf[k] = ToLower(*q);
272 ++k;
273 ++q;
275 if (l > 0)
276 k = l;
277 name_buf[k] = '\0';
279 postscript = FT_Get_Sfnt_Table(face, ft_sfnt_post);
280 os2 = FT_Get_Sfnt_Table(face, ft_sfnt_os2);
282 tags[0].ti_Tag = MUIA_Group_Child;
283 tags[0].ti_Data = (ULONG)ColGroup(2),
284 Child, Label2("Extra file"),
285 Child, attached_file = PopaslObject,
286 MUIA_Popasl_Type, ASL_FileRequest,
287 MUIA_Popstring_String, StringObject,
288 StringFrame,
289 MUIA_String_AdvanceOnCR, TRUE,
290 MUIA_CycleChain, TRUE,
291 End,
292 MUIA_Popstring_Button, PopButton(MUII_PopFile),
293 ASLFR_RejectIcons, TRUE,
294 End,
295 Child, Label2("Face num"),
296 Child, face_num = StringObject,
297 StringFrame,
298 MUIA_String_Integer, 0,
299 MUIA_String_Accept, "0123456789",
300 MUIA_String_AdvanceOnCR, TRUE,
301 MUIA_String_MaxLen, 5,
302 MUIA_CycleChain, TRUE,
303 End,
304 Child, Label2("Name"),
305 Child, name = StringObject,
306 StringFrame,
307 MUIA_String_Contents, name_buf,
308 MUIA_String_AdvanceOnCR, TRUE,
309 MUIA_String_MaxLen, 27,
310 MUIA_CycleChain, TRUE,
311 End,
312 Child, Label2("Family"),
313 Child, family = StringObject,
314 StringFrame,
315 MUIA_String_Contents, face->family_name,
316 MUIA_String_AdvanceOnCR, TRUE,
317 MUIA_CycleChain, TRUE,
318 End,
319 Child, Label2("Metric"),
320 Child, metric = CycleObject,
321 MUIA_Cycle_Entries, metric_names,
322 MUIA_Cycle_Active, 1,
323 MUIA_CycleChain, TRUE,
324 End,
325 Child, Label2("Bounding box"),
326 Child, HGroup,
327 Child, Label2("yMin"),
328 Child, bbox_ymin = StringObject,
329 StringFrame,
330 MUIA_String_Accept, "-0123456789",
331 MUIA_String_AdvanceOnCR, TRUE,
332 MUIA_String_MaxLen, 6,
333 MUIA_String_Integer, face->bbox.yMin,
334 MUIA_CycleChain, TRUE,
335 End,
336 Child, Label2("yMax"),
337 Child, bbox_ymax = StringObject,
338 StringFrame,
339 MUIA_String_Accept, "-0123456789",
340 MUIA_String_AdvanceOnCR, TRUE,
341 MUIA_String_MaxLen, 6,
342 MUIA_String_Integer, face->bbox.yMax,
343 MUIA_CycleChain, TRUE,
344 End,
345 End,
346 Child, Label2("Size factor"),
347 Child, HGroup,
348 Child, size_factor_low = StringObject,
349 StringFrame,
350 MUIA_String_Accept, "0123456789",
351 MUIA_String_AdvanceOnCR, TRUE,
352 MUIA_String_MaxLen, 6,
353 MUIA_String_Integer, 1,
354 MUIA_CycleChain, TRUE,
355 End,
356 Child, TextObject,
357 MUIA_Text_Contents, "/",
358 MUIA_Text_SetMax, TRUE,
359 End,
360 Child, size_factor_high = StringObject,
361 StringFrame,
362 MUIA_String_Accept, "0123456789",
363 MUIA_String_AdvanceOnCR, TRUE,
364 MUIA_String_MaxLen, 6,
365 MUIA_String_Integer, 1,
366 MUIA_CycleChain, TRUE,
367 End,
368 End,
369 Child, Label2("Space width"),
370 Child, space_width = StringObject,
371 StringFrame,
372 MUIA_String_Accept, "0123456789",
373 MUIA_String_AdvanceOnCR, TRUE,
374 MUIA_String_MaxLen, 6,
375 MUIA_String_Integer, (ULONG)(face->max_advance_width * 250.0 / 72.307),
376 MUIA_CycleChain, TRUE,
377 End,
378 Child, Label1("Fixed width"),
379 Child, HGroup,
380 Child, fixed = CheckMark((face->face_flags & FT_FACE_FLAG_FIXED_WIDTH) != 0),
381 Child, RectangleObject,
382 End,
383 End,
384 Child, Label1("Serif"),
385 Child, HGroup,
386 Child, serif = CheckMark(os2 && (unsigned)(((os2->sFamilyClass >> 8) &
387 0xff) - 1) < 5),
388 Child, RectangleObject,
389 End,
390 End,
391 Child, Label2("Stem weight"),
392 Child, HGroup,
393 Child, stem_weight_cycle = CycleObject,
394 MUIA_Cycle_Entries, stem_weight_names,
395 MUIA_CycleChain, TRUE,
396 End,
397 Child, stem_weight = StringObject,
398 StringFrame,
399 MUIA_String_Accept, "0123456789",
400 MUIA_String_AdvanceOnCR, TRUE,
401 MUIA_String_MaxLen, 4,
402 MUIA_String_Integer, 128,
403 MUIA_CycleChain, TRUE,
404 End,
405 End,
406 Child, Label2("Slant style"),
407 Child, slant_style = CycleObject,
408 MUIA_Cycle_Entries, slant_style_names,
409 MUIA_Cycle_Active, face->style_flags & FT_STYLE_FLAG_ITALIC ?
410 (postscript && postscript->italicAngle > 0 ?
411 OTS_LeftItalic : OTS_Italic) : OTS_Upright,
412 MUIA_CycleChain, TRUE,
413 End,
414 Child, Label2("Horiz style"),
415 Child, HGroup,
416 Child, horiz_style_cycle = CycleObject,
417 MUIA_Cycle_Entries, horiz_style_names,
418 MUIA_CycleChain, TRUE,
419 End,
420 Child, horiz_style = StringObject,
421 StringFrame,
422 MUIA_String_Accept, "0123456789",
423 MUIA_String_AdvanceOnCR, TRUE,
424 MUIA_String_MaxLen, 4,
425 MUIA_String_Integer, 128,
426 MUIA_CycleChain, TRUE,
427 End,
428 End,
429 /*Child, Label1("No algo style"),
430 Child, HGroup,
431 Child, algo_style = CheckMark(FALSE),
432 Child, RectangleObject,
433 End,
434 End,*/
435 End;
436 tags[1].ti_Tag = MUIA_Group_Child;
437 tags[1].ti_Data = (ULONG)VGroup,
438 GroupFrameT("Preview"),
439 Child, test_string = StringObject,
440 StringFrame,
441 MUIA_String_Contents, "The quick brown fox jumped over the lazy dog.",
442 MUIA_String_AdvanceOnCR, TRUE,
443 MUIA_CycleChain, TRUE,
444 End,
445 Child, HGroup,
446 Child, Label2("Size"),
447 Child, test_size = StringObject,
448 StringFrame,
449 MUIA_String_Accept, "0123456789",
450 MUIA_String_Integer, 30,
451 MUIA_String_AdvanceOnCR, TRUE,
452 MUIA_CycleChain, TRUE,
453 End,
454 Child, Label2("Anti-aliasing"),
455 Child, gray = CheckMark(FALSE),
456 End,
457 Child, ScrollgroupObject,
458 MUIA_Scrollgroup_Contents, VirtgroupObject,
459 VirtualFrame,
460 Child, VCenter(HCenter((preview_group = VGroup,
461 Child, preview = RectangleObject,
462 End,
463 End))),
464 End,
465 End,
466 End;
467 tags[2].ti_Tag = TAG_MORE;
468 tags[2].ti_Data = (ULONG)msg->ops_AttrList;
470 method.MethodID = OM_NEW;
471 method.ops_AttrList = tags;
472 method.ops_GInfo = NULL;
474 o = (Object *)DoSuperMethodA(cl, o, (Msg)&method);
475 if (o)
477 FontInfoData *dat = INST_DATA(cl, o);
479 dat->Filename = filename;
480 dat->Face = face;
481 dat->AttachedFile = attached_file;
482 dat->Name = name;
483 dat->Family = family;
484 dat->YSizeFactorLow = size_factor_low;
485 dat->YSizeFactorHigh = size_factor_high;
486 dat->StemWeight = stem_weight;
487 dat->SlantStyle = slant_style;
488 dat->HorizStyle = horiz_style;
489 dat->SpaceWidth = space_width;
490 dat->Fixed = fixed;
491 dat->Serif = serif;
492 //dat->AlgoStyle = algo_style;
493 dat->FaceNum = face_num;
494 dat->Metric = metric;
495 dat->BBoxYMin = bbox_ymin;
496 dat->BBoxYMax = bbox_ymax;
497 dat->Preview = preview;
498 dat->PreviewGroup = preview_group;
499 dat->TestString = test_string;
500 dat->TestSize = test_size;
501 dat->Gray = gray;
503 DoMethod(size_factor_low, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
504 size_factor_low, 4, MUIM_CallHook, &IntegerBoundsHook, 1, 65535);
505 DoMethod(size_factor_high, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
506 size_factor_high, 4, MUIM_CallHook, &IntegerBoundsHook, 1, 65535);
508 DoMethod(stem_weight_cycle, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime,
509 stem_weight_cycle, 5, MUIM_CallHook, &CycleToStringHook,
510 stem_weight, sizeof(stem_weight_values), stem_weight_values);
511 DoMethod(stem_weight, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
512 stem_weight, 4, MUIM_CallHook, &IntegerBoundsHook, 0, 255);
514 DoMethod(horiz_style_cycle, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime,
515 horiz_style_cycle, 5, MUIM_CallHook, &CycleToStringHook,
516 horiz_style, sizeof(horiz_style_values), horiz_style_values);
517 DoMethod(horiz_style, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
518 horiz_style, 4, MUIM_CallHook, &IntegerBoundsHook, 0, 255);
520 set(stem_weight_cycle, MUIA_Cycle_Active,
521 face->style_flags & FT_STYLE_FLAG_BOLD ? 11 : 7);
522 set(horiz_style_cycle, MUIA_Cycle_Active, 4);
524 DoMethod(test_string, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
525 o, 1, MUIM_FontInfo_UpdatePreview);
526 DoMethod(test_size, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
527 o, 1, MUIM_FontInfo_UpdatePreview);
528 DoMethod(gray, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
529 o, 1, MUIM_FontInfo_UpdatePreview);
531 DoMethod(bbox_ymin, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
532 bbox_ymin, 4, MUIM_CallHook, &IntegerBoundsHook, -32768, 32767);
533 DoMethod(bbox_ymax, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
534 bbox_ymax, 4, MUIM_CallHook, &IntegerBoundsHook, -32768, 32767);
536 DoMethod(metric, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime,
537 metric, 6, MUIM_CallHook, &MetricHook, bbox_ymin, bbox_ymax);
539 set(metric, MUIA_Cycle_Active, 0);
541 if (//!(face->face_flags & FT_FACE_FLAG_FIXED_WIDTH) &&
542 FT_Set_Char_Size(face, 250 * 64, 250 * 64, 2540, 2540) == 0 &&
543 FT_Load_Char(face, ' ', FT_LOAD_DEFAULT) == 0)
545 set(space_width, MUIA_String_Integer, face->glyph->metrics.horiAdvance >> 6);
548 if (os2)
550 int weight = os2->usWeightClass;
551 int value;
553 value = 0; /* UltraThin */
554 if (weight < 10) weight *= 100;
555 if (weight >= 200) value = 2; /* Thin */
556 if (weight >= 300) value = 4; /* Light */
557 if (weight >= 400) value = 7; /* Book */
558 if (weight >= 500) value = 8; /* Medium */
559 if (weight >= 600) value = 10; /* DemiBold */
560 if (weight >= 700) value = 11; /* Bold */
561 if (weight >= 800) value = 13; /* Black */
562 if (weight >= 900) value = 15; /* UltraBlack */
563 set(stem_weight_cycle, MUIA_Cycle_Active, value);
565 set(horiz_style_cycle, MUIA_Cycle_Active, os2->usWidthClass - 1);
568 DoMethod(o, MUIM_FontInfo_UpdatePreview);
571 DEBUG_FONTINFO(dprintf("FontInfo: created object 0x%lx\n", o));
573 return (ULONG)o;
576 #if 0
577 ULONG fiDispose(Class *cl, Object *o)
579 FontInfoData *dat = INST_DATA(cl, o);
581 return DoSuperMethod(cl, o, OM_DISPOSE);
583 #endif
585 ULONG fiSetOTags(Class *cl, Object *o)
587 FontInfoData *dat = INST_DATA(cl, o);
588 struct TagItem *tag = dat->OTags;
589 ULONG x, y;
591 tag->ti_Tag = OT_FileIdent;
592 ++tag;
594 tag->ti_Tag = OT_Engine;
595 tag->ti_Data = (ULONG)"freetype2";
596 ++tag;
598 tag->ti_Tag = OT_Family;
599 get(dat->Family, MUIA_String_Contents, &tag->ti_Data);
600 ++tag;
602 //tag->ti_Tag = OT_BName;
603 //tag->ti_Tag = OT_IName;
604 //tag->ti_Tag = OT_BIName;
605 //tag->ti_Tag = OT_SymbolSet; charmap index
607 get(dat->YSizeFactorLow, MUIA_String_Integer, &x);
608 get(dat->YSizeFactorHigh, MUIA_String_Integer, &y);
609 x = (UWORD)x;
610 y = (UWORD)y;
611 if (x == 0) x = 1;
612 if (y == 0) y = 1;
613 tag->ti_Tag = OT_YSizeFactor;
614 tag->ti_Data = x | (y << 16);
615 ++tag;
617 tag->ti_Tag = OT_SpaceWidth;
618 get(dat->SpaceWidth, MUIA_String_Integer, &tag->ti_Data);
619 ++tag;
621 tag->ti_Tag = OT_IsFixed;
622 get(dat->Fixed, MUIA_Selected, &tag->ti_Data);
623 ++tag;
625 tag->ti_Tag = OT_SerifFlag;
626 get(dat->Serif, MUIA_Selected, &tag->ti_Data);
627 ++tag;
629 tag->ti_Tag = OT_StemWeight;
630 get(dat->StemWeight, MUIA_String_Integer, &tag->ti_Data);
631 ++tag;
633 tag->ti_Tag = OT_SlantStyle;
634 get(dat->SlantStyle, MUIA_Cycle_Active, &tag->ti_Data);
635 ++tag;
637 tag->ti_Tag = OT_HorizStyle;
638 get(dat->HorizStyle, MUIA_String_Integer, &tag->ti_Data);
639 ++tag;
641 tag->ti_Tag = OT_SpaceFactor;
642 tag->ti_Data = 0x10000;
643 ++tag;
645 tag->ti_Tag = OT_InhibitAlgoStyle;
646 tag->ti_Data = FSF_UNDERLINED | FSF_BOLD;
647 //get(dat->AlgoStyle, MUIA_Selected, &tag->ti_Data);
648 ++tag;
650 tag->ti_Tag = OT_SpecCount;
651 tag->ti_Data = 4;
652 ++tag;
654 tag->ti_Tag = OT_Spec1_FontFile;
655 tag->ti_Data = (ULONG)dat->Filename;
656 ++tag;
658 tag->ti_Tag = OT_Spec3_AFMFile;
659 get(dat->AttachedFile, MUIA_String_Contents, &tag->ti_Data);
660 ++tag;
662 tag->ti_Tag = OT_Spec4_Metric;
663 get(dat->Metric, MUIA_Cycle_Active, &tag->ti_Data);
664 ++tag;
666 if (tag[-1].ti_Data == METRIC_CUSTOMBBOX)
668 ULONG ymin, ymax;
669 get(dat->BBoxYMin, MUIA_String_Integer, &ymin);
670 get(dat->BBoxYMax, MUIA_String_Integer, &ymax);
671 tag->ti_Tag = OT_Spec5_BBox;
672 tag->ti_Data = (ymax << 16) | (UWORD)ymin;
673 ++tag;
676 tag->ti_Tag = OT_Spec6_FaceNum;
677 get(dat->FaceNum, MUIA_String_Integer, &tag->ti_Data);
678 ++tag;
680 if (!IsDefaultCodePage())
682 tag->ti_Tag = OT_Spec2_CodePage;
683 tag->ti_Data = (ULONG)codepage;
684 ++tag;
687 tag->ti_Tag = TAG_END;
689 dat->AvailSizes[0] = AROS_WORD2BE(2); // <- number of entries...
690 dat->AvailSizes[1] = AROS_WORD2BE(10);
691 dat->AvailSizes[2] = AROS_WORD2BE(15);
693 return tag - dat->OTags;
696 ULONG fiUpdatePreview(Class *cl, Object *o)
698 FontInfoData *dat = INST_DATA(cl, o);
699 Object *preview;
700 STRPTR str;
701 ULONG gray;
702 ULONG size;
704 fiSetOTags(cl, o);
706 get(dat->TestString, MUIA_String_Contents, &str);
707 get(dat->Gray, MUIA_Selected, &gray);
708 get(dat->TestSize, MUIA_String_Integer, &size);
710 preview = FontBitmapObject,
711 MUIA_FontBitmap_Filename, dat->Filename,
712 MUIA_FontBitmap_OTags, dat->OTags,
713 MUIA_FontBitmap_String, str,
714 MUIA_FontBitmap_Gray, gray,
715 MUIA_FontBitmap_Size, size,
716 End;
718 DEBUG_FONTINFO(dprintf("FontInfo::UpdatePreview: new 0x%lx\n", preview));
720 if (preview)
722 DoMethod(dat->PreviewGroup, MUIM_Group_InitChange);
723 if (dat->Preview)
725 DoMethod(dat->PreviewGroup, OM_REMMEMBER, dat->Preview);
726 DisposeObject(dat->Preview);
728 DoMethod(dat->PreviewGroup, OM_ADDMEMBER, preview);
729 DoMethod(dat->PreviewGroup, MUIM_Group_ExitChange);
730 dat->Preview = preview;
733 return preview != NULL;
736 ULONG fiWriteFiles(Class *cl, Object *o)
738 FontInfoData *dat = INST_DATA(cl, o);
739 BPTR file;
740 char name[32];
741 STRPTR base;
742 BPTR olddir;
744 get(dat->Name, MUIA_String_Contents, &base);
745 if (!base || !base[0])
746 return FALSE;
748 olddir = CurrentDir(destdir);
750 strcpy(name, base);
751 strcat(name, ".otag");
753 file = Open(name, MODE_NEWFILE);
754 if (file)
756 struct TagItem *tag;
757 ULONG size, indirect_size;
758 UBYTE *buffer;
759 int num_sizes;
761 size = sizeof(tag->ti_Tag) + (fiSetOTags(cl, o) + 2) * sizeof(*tag);
762 indirect_size = 0;
764 for (tag = dat->OTags; tag->ti_Tag != TAG_END; ++tag)
766 if (tag->ti_Tag == OT_Spec2_CodePage)
768 indirect_size += 1;
769 indirect_size &= ~1;
770 indirect_size += sizeof(codepage);
772 else if (tag->ti_Tag & OT_Indirect && tag->ti_Data)
774 indirect_size += strlen((const char *)tag->ti_Data) + 1;
778 indirect_size += 1;
779 indirect_size &= ~1;
781 num_sizes = 1 + dat->AvailSizes[0];
782 indirect_size += num_sizes * sizeof(UWORD);
784 dat->OTags[0].ti_Data = size + indirect_size;
786 buffer = malloc(indirect_size);
787 if (buffer)
789 size_t offset = 0;
790 struct TagItem *write_tags;
792 memset(buffer, 0, indirect_size);
794 for (tag = dat->OTags; tag->ti_Tag != TAG_END; ++tag)
796 if (tag->ti_Tag == OT_Spec2_CodePage)
798 offset += 1;
799 offset &= ~1;
800 memcpy(buffer + offset, codepage, sizeof(codepage));
801 tag->ti_Data = size + offset;
802 offset += sizeof(codepage);
804 else if (tag->ti_Tag & OT_Indirect && tag->ti_Data)
806 size_t len = strlen((const char *)tag->ti_Data) + 1;
807 memcpy(buffer + offset, (const char *)tag->ti_Data, len);
808 tag->ti_Data = size + offset;
809 offset += len;
813 offset += 1;
814 offset &= ~1;
816 tag->ti_Tag = OT_AvailSizes;
817 tag->ti_Data = size + offset;
818 ++tag;
820 tag->ti_Tag = TAG_END;
822 memcpy(buffer + offset, dat->AvailSizes, num_sizes * sizeof(UWORD));
823 offset += num_sizes * sizeof(UWORD);
825 write_tags = malloc(size);
826 memcpy(write_tags, dat->OTags, size);
827 for (tag = write_tags; tag->ti_Tag != TAG_END; tag++)
829 tag->ti_Tag = AROS_LONG2BE(tag->ti_Tag);
830 tag->ti_Data = AROS_LONG2BE(tag->ti_Data);
832 tag->ti_Tag = AROS_LONG2BE(TAG_END);
834 Write(file, write_tags, size);
835 free(write_tags);
836 Write(file, buffer, offset);
838 free(buffer);
841 Close(file);
844 strcpy(name, base);
845 strcat(name, ".font");
847 file = Open(name, MODE_NEWFILE);
848 if (file)
850 static UBYTE data[] = {0x0f, 0x03, 0x00, 0x00 };
851 Write(file, data, sizeof(data));
852 Close(file);
855 CurrentDir(olddir);
857 return 1;
860 AROS_UFH3(ULONG, FontInfoDispatch,
861 AROS_UFHA(Class *, cl, A0),
862 AROS_UFHA(Object *, o, A2),
863 AROS_UFHA(Msg, msg, A1))
865 AROS_USERFUNC_INIT
867 ULONG ret;
869 switch (msg->MethodID)
871 case OM_NEW:
872 ret = fiNew(cl, o, (struct opSet *)msg);
873 break;
875 #if 0
876 case OM_DISPOSE:
877 ret = fiDispose(cl, o);
878 break;
879 #endif
881 case MUIM_FontInfo_UpdatePreview:
882 ret = fiUpdatePreview(cl, o);
883 break;
885 case MUIM_FontInfo_WriteFiles:
886 ret = fiWriteFiles(cl, o);
887 break;
889 default:
890 ret = DoSuperMethodA(cl, o, msg);
891 break;
894 return ret;
896 AROS_USERFUNC_EXIT
900 void CleanupFontInfoClass(void)
902 if (FontInfoClass)
904 MUI_DeleteCustomClass(FontInfoClass);
905 FontInfoClass = NULL;
909 int InitFontInfoClass(void)
911 FontInfoClass = MUI_CreateCustomClass(NULL, MUIC_Group, NULL,
912 sizeof(FontInfoData), UFHN(FontInfoDispatch));
913 return FontInfoClass != NULL;