2 * Based on source from ftmanager from MorphOS for their ft2.library
4 #define NO_INLINE_STDARG
6 #include <libraries/mui.h>
7 #include <libraries/asl.h>
9 #include <proto/exec.h>
10 #include <proto/dos.h>
11 #include <proto/intuition.h>
12 #include <proto/muimaster.h>
13 #undef NO_INLINE_STDARG
14 #include <proto/codesets.h>
15 #include <proto/freetype2.h>
16 #include <aros/debug.h>
18 #include "fontbitmap_class.h"
19 #include "fontinfo_class.h"
20 #include "fontlist_class.h"
21 #include "fontwindow_class.h"
24 #define ARG_TEMPLATE "TTFFONT/A,OUTFONT/A,CODEPAGE"
34 /***********************************************************************/
36 /* Global variables */
39 struct Library
*CodesetsBase
;
41 /***********************************************************************/
43 static struct RDArgs
*rda
;
45 static STRPTR
*codesetentries
;
46 static STRPTR
*codesetsupported
;
48 /***********************************************************************/
50 static void Cleanup(void)
55 CleanupFontListClass();
56 CleanupFontWindowClass();
57 CleanupFontInfoClass();
58 CleanupFontBitmapClass();
60 FT_Done_Library(ftlibrary
);
63 CodesetsFreeA(codesetsupported
, NULL
);
64 FreeVec(codesetentries
);
65 CloseLibrary(CodesetsBase
);
70 static int Init(BOOL gui
)
74 CodesetsBase
= OpenLibrary("codesets.library", 0);
78 error
= FT_Init_FreeType(&ftlibrary
);
81 DEBUG_MAIN(dprintf("Init_FreeType error %d\n", error
));
87 if (!InitFontBitmapClass() ||
88 !InitFontInfoClass() ||
89 !InitFontWindowClass() ||
92 DEBUG_MAIN(dprintf("Can't create custom classes.\n"));
97 destdir
= Lock("Fonts:", ACCESS_READ
);
103 static void SetDefaultCodePage(void)
106 for (k
= 0; k
< 256; ++k
)
110 BOOL
IsDefaultCodePage(void)
113 for (k
= 0; k
< 256; ++k
)
114 if (codepage
[k
] != k
)
119 static BOOL
LoadCodePage(int entryindex
, char *codepg
)
121 struct codeset
*cs
= NULL
;
123 SetDefaultCodePage();
125 if (entryindex
== 0 && codepg
== NULL
) // keep default code page
132 cs
= CodesetsFind(codepg
, CSA_FallbackToDefault
, FALSE
, TAG_DONE
);
134 else if (entryindex
> 0)
136 cs
= CodesetsFind(codesetentries
[entryindex
],
137 CSA_FallbackToDefault
, FALSE
, TAG_DONE
);
143 for (index
= 0 ; index
< 256 ; index
++)
145 codepage
[index
] = (UWORD
)cs
->table
[index
].ucs4
;
155 #define ID_SetDestDir 2
156 #define ID_ShowFont 3
157 #define ID_SetCodePage 4
159 static int ftmanager_gui(void)
161 int ret
= RETURN_FAIL
;
162 Object
*win
, *src
, *dest
, *fontlist
, *fontlv
, *codepagecycle
, *quit
;
163 int countfrom
, countto
;
168 SetDefaultCodePage();
170 codesetsupported
= CodesetsSupportedA(NULL
); // Available codesets
172 while (codesetsupported
[countfrom
])
176 codesetentries
= AllocVec((sizeof (STRPTR
)) * (countfrom
+ 2), MEMF_CLEAR
);
182 codesetentries
[0] = "----";
185 while (codesetsupported
[countfrom
])
187 if (strncmp(codesetsupported
[countfrom
], "UTF", 3))
189 codesetentries
[countto
] = codesetsupported
[countfrom
];
194 app
= ApplicationObject
,
195 MUIA_Application_Title
, "FTManager",
196 MUIA_Application_Version
, "$VER: FTManager 1.2 (4.12.2007)",
197 MUIA_Application_Copyright
, "Copyright 2002-2003 by Emmanuel Lesueur",
198 MUIA_Application_Author
, "Emmanuel Lesueur",
199 MUIA_Application_Description
, "FreeType font manager",
200 MUIA_Application_Base
, "FTMANAGER",
201 SubWindow
, win
= WindowObject
,
202 MUIA_Window_ID
, MAKE_ID('F','T','2','M'),
203 MUIA_Window_Title
, "FreeType Font Manager",
204 MUIA_Window_Width
, 400,
205 MUIA_Window_RootObject
,VGroup
,
206 Child
, fontlv
= ListviewObject
,
207 MUIA_Listview_List
, fontlist
= FontListObject
,
211 Child
, Label2("Source"),
213 MUIA_Popasl_Type
, ASL_FileRequest
,
214 MUIA_Popstring_String
, src
= StringObject
,
216 MUIA_String_Contents
, "Fonts:TrueType",
217 MUIA_String_AdvanceOnCR
, TRUE
,
218 MUIA_CycleChain
, TRUE
,
220 MUIA_Popstring_Button
, PopButton(MUII_PopDrawer
),
221 ASLFR_RejectIcons
, TRUE
,
222 ASLFR_DrawersOnly
, TRUE
,
224 Child
, Label2("Destination"),
226 MUIA_Popasl_Type
, ASL_FileRequest
,
227 MUIA_Popstring_String
, dest
= StringObject
,
229 MUIA_String_Contents
, "Fonts:",
230 MUIA_String_AdvanceOnCR
, TRUE
,
231 MUIA_CycleChain
, TRUE
,
233 MUIA_Popstring_Button
, PopButton(MUII_PopDrawer
),
234 ASLFR_DoSaveMode
, TRUE
,
235 ASLFR_DrawersOnly
, TRUE
,
236 ASLFR_RejectIcons
, TRUE
,
238 Child
, Label2("Codepage"),
239 Child
, codepagecycle
= CycleObject
,
240 MUIA_Cycle_Entries
, codesetentries
,
243 Child
, quit
= SimpleButton("_Quit"),
254 DoMethod(src
, MUIM_Notify
, MUIA_String_Acknowledge
, MUIV_EveryTime
,
255 fontlist
, 2, MUIM_FontList_AddDir
, MUIV_TriggerValue
);
257 DoMethod(dest
, MUIM_Notify
, MUIA_String_Acknowledge
, MUIV_EveryTime
,
258 app
, 2, MUIM_Application_ReturnID
, ID_SetDestDir
);
260 DoMethod(codepagecycle
, MUIM_Notify
, MUIA_Cycle_Active
, MUIV_EveryTime
,
261 app
, 2, MUIM_Application_ReturnID
, ID_SetCodePage
);
263 DoMethod(fontlv
, MUIM_Notify
, MUIA_Listview_DoubleClick
, TRUE
,
264 app
, 2, MUIM_Application_ReturnID
, ID_ShowFont
);
266 DoMethod(win
, MUIM_Notify
, MUIA_Window_CloseRequest
, TRUE
,
267 app
, 2, MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
);
269 DoMethod(quit
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
270 app
, 2, MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
);
272 DoMethod(fontlist
, MUIM_FontList_AddDir
, XGET(src
, MUIA_String_Contents
));
274 set(win
, MUIA_Window_Open
, TRUE
);
275 get(win
, MUIA_Window_Open
, &t
);
284 id
= DoMethod(app
, MUIM_Application_NewInput
, &sigs
);
287 case MUIV_Application_ReturnID_Quit
:
297 get(dest
, MUIA_String_Contents
, &name
);
298 newdir
= Lock(name
, ACCESS_READ
);
309 struct MUIS_FontList_Entry
*entry
;
312 DoMethod(fontlist
, MUIM_List_GetEntry
, MUIV_List_GetEntry_Active
, &entry
);
314 w
= FontWindowObject
,
315 MUIA_FontWindow_Filename
, entry
->FileName
,
321 DoMethod(w
, MUIM_Notify
, MUIA_Window_CloseRequest
, TRUE
,
322 app
, 6, MUIM_Application_PushMethod
, app
, 3,
323 MUIM_CallHook
, &CloseWinHook
, w
);
325 DoMethod(app
, OM_ADDMEMBER
, w
);
326 set(w
, MUIA_Window_Open
, TRUE
);
327 get(w
, MUIA_Window_Open
, &t
);
330 MUI_DisposeObject(w
);
340 get(codepagecycle
, MUIA_Cycle_Active
, &entry
);
341 LoadCodePage(entry
, NULL
);
348 sigs
= Wait(sigs
| SIGBREAKF_CTRL_C
);
349 if (sigs
& SIGBREAKF_CTRL_C
)
359 printf("Can't open window.\n");
362 MUI_DisposeObject(app
);
366 printf("Can't create MUI application.\n");
374 static int ftmanager_cli(void)
380 int main(int argc
, char **argv
)
382 int retval
= RETURN_FAIL
;
385 retval
= ftmanager_cli();
389 // Starting from CLI without arguments opens GUI, too
390 retval
= ftmanager_gui();