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/utility.h>
12 #include <proto/intuition.h>
13 #include <proto/muimaster.h>
14 #undef NO_INLINE_STDARG
15 #include <proto/alib.h>
16 #include <proto/codesets.h>
17 #include <proto/freetype2.h>
18 #include <aros/debug.h>
20 #include "fontbitmap_class.h"
21 #include "fontinfo_class.h"
22 #include "fontlist_class.h"
23 #include "fontwindow_class.h"
27 #define VERSION "$VER: FTManager 1.5 (23.1.2018) (C) 2011-2018 The AROS Development Team"
29 /***********************************************************************/
31 /* Global variables */
34 struct Library
*CodesetsBase
;
36 /***********************************************************************/
38 static struct RDArgs
*rda
;
40 static STRPTR
*codesetentries
;
41 static STRPTR
*codesetsupported
;
43 /***********************************************************************/
45 int ftmanager_cli(void);
47 /***********************************************************************/
49 static void Cleanup(void)
54 CleanupFontListClass();
55 CleanupFontWindowClass();
56 CleanupFontInfoClass();
57 CleanupFontBitmapClass();
59 FT_Done_Library(ftlibrary
);
62 CodesetsFreeA(codesetsupported
, NULL
);
63 FreeVec(codesetentries
);
64 CloseLibrary(CodesetsBase
);
69 static int Init(BOOL gui
)
73 CodesetsBase
= OpenLibrary("codesets.library", 0);
77 error
= FT_Init_FreeType(&ftlibrary
);
80 DEBUG_MAIN(dprintf("Init_FreeType error %d\n", error
));
86 if (!InitFontBitmapClass() ||
87 !InitFontInfoClass() ||
88 !InitFontWindowClass() ||
91 DEBUG_MAIN(dprintf("Can't create custom classes.\n"));
96 destdir
= Lock("Fonts:", ACCESS_READ
);
102 static void SetDefaultCodePage(void)
105 for (k
= 0; k
< 256; ++k
)
109 BOOL
IsDefaultCodePage(void)
112 for (k
= 0; k
< 256; ++k
)
113 if (codepage
[k
] != k
)
118 static BOOL
LoadCodePage(int entryindex
, char *codepg
)
120 struct codeset
*cs
= NULL
;
122 SetDefaultCodePage();
124 if (entryindex
== 0 && codepg
== NULL
) // keep default code page
131 cs
= CodesetsFind(codepg
, CSA_FallbackToDefault
, FALSE
, TAG_DONE
);
133 else if (entryindex
> 0)
135 cs
= CodesetsFind(codesetentries
[entryindex
],
136 CSA_FallbackToDefault
, FALSE
, TAG_DONE
);
142 for (index
= 0 ; index
< 256 ; index
++)
144 codepage
[index
] = (UWORD
)cs
->table
[index
].ucs4
;
154 #define ID_SetDestDir 2
155 #define ID_ShowFont 3
156 #define ID_SetCodePage 4
158 static int ftmanager_gui(void)
160 int ret
= RETURN_FAIL
;
161 Object
*win
, *src
, *dest
, *fontlist
, *fontlv
, *codepagecycle
, *quit
;
162 int countfrom
, countto
;
168 codesetsupported
= CodesetsSupportedA(NULL
); // Available codesets
170 while (codesetsupported
[countfrom
])
174 codesetentries
= AllocVec((sizeof (STRPTR
)) * (countfrom
+ 2), MEMF_CLEAR
);
180 codesetentries
[0] = "----";
183 while (codesetsupported
[countfrom
])
185 if (strncmp(codesetsupported
[countfrom
], "UTF", 3))
187 codesetentries
[countto
] = codesetsupported
[countfrom
];
192 app
= ApplicationObject
,
193 MUIA_Application_Title
, __(MSG_APP_NAME
),
194 MUIA_Application_Version
,(IPTR
) VERSION
,
195 MUIA_Application_Copyright
, "Copyright 2002-2003 by Emmanuel Lesueur",
196 MUIA_Application_Author
, "Emmanuel Lesueur",
197 MUIA_Application_Description
, __(MSG_APP_TITLE
),
198 MUIA_Application_Base
, "FTMANAGER",
199 SubWindow
, win
= WindowObject
,
200 MUIA_Window_ID
, MAKE_ID('F','T','2','M'),
201 MUIA_Window_Title
, __(MSG_WINDOW_TITLE
),
202 MUIA_Window_Width
, 400,
203 MUIA_Window_RootObject
,VGroup
,
204 Child
, fontlv
= ListviewObject
,
205 MUIA_Listview_List
, fontlist
= FontListObject
,
209 Child
, Label2(_(MSG_LABEL_SOURCE
)),
211 MUIA_Popasl_Type
, ASL_FileRequest
,
212 MUIA_Popstring_String
, src
= StringObject
,
214 MUIA_String_Contents
, __(MSG_ASL_FONTS_TRUETYPE
),
215 MUIA_String_AdvanceOnCR
, TRUE
,
216 MUIA_CycleChain
, TRUE
,
218 MUIA_Popstring_Button
, PopButton(MUII_PopDrawer
),
219 ASLFR_RejectIcons
, TRUE
,
220 ASLFR_DrawersOnly
, TRUE
,
222 Child
, Label2(_(MSG_LABEL_DESTINATION
)),
224 MUIA_Popasl_Type
, ASL_FileRequest
,
225 MUIA_Popstring_String
, dest
= StringObject
,
227 MUIA_String_Contents
, __(MSG_ASL_FONTS
),
228 MUIA_String_AdvanceOnCR
, TRUE
,
229 MUIA_CycleChain
, TRUE
,
231 MUIA_Popstring_Button
, PopButton(MUII_PopDrawer
),
232 ASLFR_DoSaveMode
, TRUE
,
233 ASLFR_DrawersOnly
, TRUE
,
234 ASLFR_RejectIcons
, TRUE
,
236 Child
, Label2(_(MSG_LABEL_CODEPAGE
)),
237 Child
, codepagecycle
= CycleObject
,
238 MUIA_Cycle_Entries
, codesetentries
,
241 Child
, quit
= SimpleButton(_(MSG_QUIT
)),
252 DoMethod(src
, MUIM_Notify
, MUIA_String_Acknowledge
, MUIV_EveryTime
,
253 fontlist
, 2, MUIM_FontList_AddDir
, MUIV_TriggerValue
);
255 DoMethod(dest
, MUIM_Notify
, MUIA_String_Acknowledge
, MUIV_EveryTime
,
256 app
, 2, MUIM_Application_ReturnID
, ID_SetDestDir
);
258 DoMethod(codepagecycle
, MUIM_Notify
, MUIA_Cycle_Active
, MUIV_EveryTime
,
259 app
, 2, MUIM_Application_ReturnID
, ID_SetCodePage
);
261 DoMethod(fontlv
, MUIM_Notify
, MUIA_Listview_DoubleClick
, TRUE
,
262 app
, 2, MUIM_Application_ReturnID
, ID_ShowFont
);
264 DoMethod(win
, MUIM_Notify
, MUIA_Window_CloseRequest
, TRUE
,
265 app
, 2, MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
);
267 DoMethod(quit
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
268 app
, 2, MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
);
270 DoMethod(fontlist
, MUIM_FontList_AddDir
, XGET(src
, MUIA_String_Contents
));
272 set(win
, MUIA_Window_Open
, TRUE
);
274 get(win
, MUIA_Window_Open
, &t
);
283 id
= DoMethod(app
, MUIM_Application_NewInput
, &sigs
);
286 case MUIV_Application_ReturnID_Quit
:
293 CONST_STRPTR name
= NULL
;
296 get(dest
, MUIA_String_Contents
, &name
);
300 newdir
= Lock(name
, ACCESS_READ
);
311 struct MUIS_FontList_Entry
*entry
;
314 DoMethod(fontlist
, MUIM_List_GetEntry
, MUIV_List_GetEntry_Active
, &entry
);
316 w
= FontWindowObject
,
317 MUIA_FontWindow_Filename
, entry
->FileName
,
323 DoMethod(w
, MUIM_Notify
, MUIA_Window_CloseRequest
, TRUE
,
324 app
, 6, MUIM_Application_PushMethod
, app
, 3,
325 MUIM_CallHook
, &CloseWinHook
, w
);
327 DoMethod(app
, OM_ADDMEMBER
, w
);
328 set(w
, MUIA_Window_Open
, TRUE
);
329 get(w
, MUIA_Window_Open
, &t
);
332 MUI_DisposeObject(w
);
342 get(codepagecycle
, MUIA_Cycle_Active
, &entry
);
343 LoadCodePage(entry
, NULL
);
350 sigs
= Wait(sigs
| SIGBREAKF_CTRL_C
);
351 if (sigs
& SIGBREAKF_CTRL_C
)
361 printf("Can't open window.\n");
364 MUI_DisposeObject(app
);
368 printf("Can't create MUI application.\n");
377 int main(int argc
, char **argv
)
379 int retval
= RETURN_FAIL
;
383 SetDefaultCodePage();
387 retval
= ftmanager_cli();
391 // Starting from CLI without arguments opens GUI, too
392 retval
= ftmanager_gui();
395 Locale_Deinitialize();