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>
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"
28 Object
*YSizeFactorHigh
;
29 Object
*YSizeFactorLow
;
47 struct TagItem OTags
[26];
48 UWORD AvailSizes
[OT_MAXAVAILSIZES
];
51 typedef struct FontInfoData FontInfoData
;
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
))
68 Object
*str
= p
->String
;
70 get(cycle
, MUIA_Cycle_Active
, &entry
);
71 if (entry
== p
->NumValues
)
73 set(str
, MUIA_Disabled
, FALSE
);
79 MUIA_String_Integer
, p
->Values
[entry
],
87 struct Hook CycleToStringHook
= { {NULL
, NULL
}, UFHN(CycleToString
) };
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
))
105 get(obj
, MUIA_String_Integer
, &t
);
108 set(obj
, MUIA_String_Integer
, p
->Min
);
112 set(obj
, MUIA_String_Integer
, p
->Max
);
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
))
133 get(obj
, MUIA_Cycle_Active
, &t
);
135 for (k
= 0; k
< 2; ++k
)
137 set(p
[k
], MUIA_Disabled
, state
);
144 struct Hook MetricHook
= { {NULL
, NULL
}, UFHN(Metric
) };
147 IPTR
fiNew(Class
*cl
, Object
*o
, struct opSet
*msg
)
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
;
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
;
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
[] =
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
[] =
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
);
241 if (!filename
|| !face
)
243 DEBUG_FONTINFO(dprintf("FontInfo: filename 0x%x face 0x%x\n", filename
, face
));
247 q
= face
->family_name
;
248 r
= face
->style_name
;
251 while (k
< sizeof(name_buf
) - 1)
267 name_buf
[k
] = ToLower(*q
);
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
,
285 MUIA_String_AdvanceOnCR
, TRUE
,
286 MUIA_CycleChain
, TRUE
,
288 MUIA_Popstring_Button
, PopButton(MUII_PopFile
),
289 ASLFR_RejectIcons
, TRUE
,
291 Child
, Label2(_(MSG_LABEL_FACENUM
)),
292 Child
, face_num
= StringObject
,
294 MUIA_String_Integer
, 0,
295 MUIA_String_Accept
, "0123456789",
296 MUIA_String_AdvanceOnCR
, TRUE
,
297 MUIA_String_MaxLen
, 5,
298 MUIA_CycleChain
, TRUE
,
300 Child
, Label2(_(MSG_LABEL_NAME
)),
301 Child
, name
= StringObject
,
303 MUIA_String_Contents
, name_buf
,
304 MUIA_String_AdvanceOnCR
, TRUE
,
305 MUIA_String_MaxLen
, 27,
306 MUIA_CycleChain
, TRUE
,
308 Child
, Label2(_(MSG_LABEL_FAMILY
)),
309 Child
, family
= StringObject
,
311 MUIA_String_Contents
, face
->family_name
,
312 MUIA_String_AdvanceOnCR
, TRUE
,
313 MUIA_CycleChain
, TRUE
,
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
,
321 Child
, Label2(_(MSG_LABEL_BOUNDINGBOX
)),
323 Child
, Label2("yMin"),
324 Child
, bbox_ymin
= StringObject
,
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
,
332 Child
, Label2("yMax"),
333 Child
, bbox_ymax
= StringObject
,
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
,
342 Child
, Label2(_(MSG_LABEL_SIZEFACTOR
)),
344 Child
, size_factor_low
= StringObject
,
346 MUIA_String_Accept
, "0123456789",
347 MUIA_String_AdvanceOnCR
, TRUE
,
348 MUIA_String_MaxLen
, 6,
349 MUIA_String_Integer
, 1,
350 MUIA_CycleChain
, TRUE
,
353 MUIA_Text_Contents
, "/",
354 MUIA_Text_SetMax
, TRUE
,
356 Child
, size_factor_high
= StringObject
,
358 MUIA_String_Accept
, "0123456789",
359 MUIA_String_AdvanceOnCR
, TRUE
,
360 MUIA_String_MaxLen
, 6,
361 MUIA_String_Integer
, 1,
362 MUIA_CycleChain
, TRUE
,
365 Child
, Label2(_(MSG_LABEL_SPACEWIDTH
)),
366 Child
, space_width
= StringObject
,
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
,
374 Child
, Label1(_(MSG_LABEL_FIXEDWIDTH
)),
376 Child
, fixed
= CheckMark((face
->face_flags
& FT_FACE_FLAG_FIXED_WIDTH
) != 0),
377 Child
, RectangleObject
,
380 Child
, Label1(_(MSG_LABEL_SERIF
)),
382 Child
, serif
= CheckMark(os2
&& (unsigned)(((os2
->sFamilyClass
>> 8) &
384 Child
, RectangleObject
,
387 Child
, Label2(_(MSG_LABEL_STEMWEIGHT
)),
389 Child
, stem_weight_cycle
= CycleObject
,
390 MUIA_Cycle_Entries
, stem_weight_names
,
391 MUIA_CycleChain
, TRUE
,
393 Child
, stem_weight
= StringObject
,
395 MUIA_String_Accept
, "0123456789",
396 MUIA_String_AdvanceOnCR
, TRUE
,
397 MUIA_String_MaxLen
, 4,
398 MUIA_String_Integer
, 128,
399 MUIA_CycleChain
, TRUE
,
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
,
410 Child
, Label2(_(MSG_LABEL_HORIZSTYLE
)),
412 Child
, horiz_style_cycle
= CycleObject
,
413 MUIA_Cycle_Entries
, horiz_style_names
,
414 MUIA_CycleChain
, TRUE
,
416 Child
, horiz_style
= StringObject
,
418 MUIA_String_Accept
, "0123456789",
419 MUIA_String_AdvanceOnCR
, TRUE
,
420 MUIA_String_MaxLen
, 4,
421 MUIA_String_Integer
, 128,
422 MUIA_CycleChain
, TRUE
,
425 /*Child, Label1("No algo style"),
427 Child, algo_style = CheckMark(FALSE),
428 Child, RectangleObject,
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
,
437 MUIA_String_Contents
, _(MSG_PREVIEW_STRING
),
438 MUIA_String_AdvanceOnCR
, TRUE
,
439 MUIA_CycleChain
, TRUE
,
442 Child
, Label2(_(MSG_LABEL_SIZE
)),
443 Child
, test_size
= StringObject
,
445 MUIA_String_Accept
, "0123456789",
446 MUIA_String_Integer
, 30,
447 MUIA_String_AdvanceOnCR
, TRUE
,
448 MUIA_CycleChain
, TRUE
,
450 Child
, Label2(_(MSG_LABEL_ANTIALIASING
)),
451 Child
, gray
= CheckMark(FALSE
),
453 Child
, ScrollgroupObject
,
454 MUIA_Scrollgroup_Contents
, VirtgroupObject
,
456 Child
, VCenter(HCenter((preview_group
= VGroup
,
457 Child
, preview
= RectangleObject
,
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
);
473 FontInfoData
*dat
= INST_DATA(cl
, o
);
475 dat
->Filename
= filename
;
477 dat
->AttachedFile
= attached_file
;
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
;
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
;
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);
546 int weight
= os2
->usWeightClass
;
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
));
573 IPTR
fiDispose(Class
*cl
, Object
*o
)
575 FontInfoData
*dat
= INST_DATA(cl
, o
);
577 return DoSuperMethod(cl
, o
, OM_DISPOSE
);
581 IPTR
fiSetOTags(Class
*cl
, Object
*o
)
583 FontInfoData
*dat
= INST_DATA(cl
, o
);
584 struct TagItem
*tag
= dat
->OTags
;
588 tag
->ti_Tag
= OT_FileIdent
;
591 tag
->ti_Tag
= OT_Engine
;
592 tag
->ti_Data
= (IPTR
)"freetype2";
595 tag
->ti_Tag
= OT_Family
;
596 get(dat
->Family
, MUIA_String_Contents
, &tag
->ti_Data
);
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
);
610 tag
->ti_Tag
= OT_YSizeFactor
;
611 tag
->ti_Data
= x
| (y
<< 16);
614 tag
->ti_Tag
= OT_SpaceWidth
;
615 get(dat
->SpaceWidth
, MUIA_String_Integer
, &tag
->ti_Data
);
618 tag
->ti_Tag
= OT_IsFixed
;
619 get(dat
->Fixed
, MUIA_Selected
, &tag
->ti_Data
);
622 tag
->ti_Tag
= OT_SerifFlag
;
623 get(dat
->Serif
, MUIA_Selected
, &tag
->ti_Data
);
626 tag
->ti_Tag
= OT_StemWeight
;
627 get(dat
->StemWeight
, MUIA_String_Integer
, &tag
->ti_Data
);
630 tag
->ti_Tag
= OT_SlantStyle
;
631 get(dat
->SlantStyle
, MUIA_Cycle_Active
, &tag
->ti_Data
);
634 tag
->ti_Tag
= OT_HorizStyle
;
635 get(dat
->HorizStyle
, MUIA_String_Integer
, &tag
->ti_Data
);
638 tag
->ti_Tag
= OT_SpaceFactor
;
639 tag
->ti_Data
= 0x10000;
642 tag
->ti_Tag
= OT_InhibitAlgoStyle
;
643 tag
->ti_Data
= FSF_UNDERLINED
| FSF_BOLD
;
644 //get(dat->AlgoStyle, MUIA_Selected, &tag->ti_Data);
647 tag
->ti_Tag
= OT_SpecCount
;
651 tag
->ti_Tag
= OT_Spec1_FontFile
;
652 tag
->ti_Data
= (IPTR
)dat
->Filename
;
655 tag
->ti_Tag
= OT_Spec3_AFMFile
;
656 get(dat
->AttachedFile
, MUIA_String_Contents
, &tag
->ti_Data
);
659 tag
->ti_Tag
= OT_Spec4_Metric
;
660 get(dat
->Metric
, MUIA_Cycle_Active
, &tag
->ti_Data
);
663 if (tag
[-1].ti_Data
== METRIC_CUSTOMBBOX
)
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
;
675 tag
->ti_Tag
= OT_Spec6_FaceNum
;
676 get(dat
->FaceNum
, MUIA_String_Integer
, &tag
->ti_Data
);
679 if (!IsDefaultCodePage())
681 tag
->ti_Tag
= OT_Spec2_CodePage
;
682 tag
->ti_Data
= (IPTR
)codepage
;
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
);
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
,
717 DEBUG_FONTINFO(dprintf("FontInfo::UpdatePreview: new 0x%lx\n", preview
));
721 DoMethod(dat
->PreviewGroup
, MUIM_Group_InitChange
);
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
);
743 get(dat
->Name
, MUIA_String_Contents
, &base
);
744 if (!base
|| !base
[0])
747 olddir
= CurrentDir(destdir
);
750 strcat(name
, ".otag");
752 file
= Open(name
, MODE_NEWFILE
);
756 ULONG size
, indirect_size
;
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
);
768 for (tag
= dat
->OTags
; tag
->ti_Tag
!= TAG_END
; ++tag
)
770 if (tag
->ti_Tag
== OT_Spec2_CodePage
)
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;
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
);
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
)
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
;
822 tag
->ti_Tag
= OT_AvailSizes
;
823 tag
->ti_Data
= size
+ offset
;
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
);
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
);
840 dest
[0] = AROS_LONG2BE(TAG_END
);
842 Write(file
, write_tags
, size
);
845 Write(file
, buffer
, offset
);
853 strcat(name
, ".font");
855 file
= Open(name
, MODE_NEWFILE
);
858 static UBYTE data
[] = {0x0f, 0x03, 0x00, 0x00 };
859 Write(file
, data
, sizeof(data
));
868 AROS_UFH3(ULONG
, FontInfoDispatch
,
869 AROS_UFHA(Class
*, cl
, A0
),
870 AROS_UFHA(Object
*, o
, A2
),
871 AROS_UFHA(Msg
, msg
, A1
))
877 switch (msg
->MethodID
)
880 ret
= fiNew(cl
, o
, (struct opSet
*)msg
);
885 ret
= fiDispose(cl
, o
);
889 case MUIM_FontInfo_UpdatePreview
:
890 ret
= fiUpdatePreview(cl
, o
);
893 case MUIM_FontInfo_WriteFiles
:
894 ret
= fiWriteFiles(cl
, o
);
898 ret
= DoSuperMethodA(cl
, o
, msg
);
908 void CleanupFontInfoClass(void)
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
;