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/alib.h>
15 #include <proto/codesets.h>
16 #include <proto/freetype2.h>
17 #include <aros/debug.h>
19 #include "fontbitmap_class.h"
20 #include "fontinfo_class.h"
21 #include "fontlist_class.h"
22 #include "fontwindow_class.h"
26 #define ARG_TEMPLATE "TTFFONT/A,OUTFONT/A,CODEPAGE"
28 #define VERSION "$VER: FTManager 1.3 (07.09.2013) ©2011-2013 The AROS Development Team"
38 /***********************************************************************/
40 /* Global variables */
43 struct Library
*CodesetsBase
;
45 /***********************************************************************/
47 static struct RDArgs
*rda
;
49 static STRPTR
*codesetentries
;
50 static STRPTR
*codesetsupported
;
52 /***********************************************************************/
54 static void Cleanup(void)
59 CleanupFontListClass();
60 CleanupFontWindowClass();
61 CleanupFontInfoClass();
62 CleanupFontBitmapClass();
64 FT_Done_Library(ftlibrary
);
67 CodesetsFreeA(codesetsupported
, NULL
);
68 FreeVec(codesetentries
);
69 CloseLibrary(CodesetsBase
);
74 static int Init(BOOL gui
)
78 CodesetsBase
= OpenLibrary("codesets.library", 0);
82 error
= FT_Init_FreeType(&ftlibrary
);
85 DEBUG_MAIN(dprintf("Init_FreeType error %d\n", error
));
91 if (!InitFontBitmapClass() ||
92 !InitFontInfoClass() ||
93 !InitFontWindowClass() ||
96 DEBUG_MAIN(dprintf("Can't create custom classes.\n"));
101 destdir
= Lock("Fonts:", ACCESS_READ
);
107 static void SetDefaultCodePage(void)
110 for (k
= 0; k
< 256; ++k
)
114 BOOL
IsDefaultCodePage(void)
117 for (k
= 0; k
< 256; ++k
)
118 if (codepage
[k
] != k
)
123 static BOOL
LoadCodePage(int entryindex
, char *codepg
)
125 struct codeset
*cs
= NULL
;
127 SetDefaultCodePage();
129 if (entryindex
== 0 && codepg
== NULL
) // keep default code page
136 cs
= CodesetsFind(codepg
, CSA_FallbackToDefault
, FALSE
, TAG_DONE
);
138 else if (entryindex
> 0)
140 cs
= CodesetsFind(codesetentries
[entryindex
],
141 CSA_FallbackToDefault
, FALSE
, TAG_DONE
);
147 for (index
= 0 ; index
< 256 ; index
++)
149 codepage
[index
] = (UWORD
)cs
->table
[index
].ucs4
;
159 #define ID_SetDestDir 2
160 #define ID_ShowFont 3
161 #define ID_SetCodePage 4
163 static int ftmanager_gui(void)
165 int ret
= RETURN_FAIL
;
166 Object
*win
, *src
, *dest
, *fontlist
, *fontlv
, *codepagecycle
, *quit
;
167 int countfrom
, countto
;
172 SetDefaultCodePage();
174 codesetsupported
= CodesetsSupportedA(NULL
); // Available codesets
176 while (codesetsupported
[countfrom
])
180 codesetentries
= AllocVec((sizeof (STRPTR
)) * (countfrom
+ 2), MEMF_CLEAR
);
186 codesetentries
[0] = "----";
189 while (codesetsupported
[countfrom
])
191 if (strncmp(codesetsupported
[countfrom
], "UTF", 3))
193 codesetentries
[countto
] = codesetsupported
[countfrom
];
198 app
= ApplicationObject
,
199 MUIA_Application_Title
, __(MSG_APP_NAME
),
200 MUIA_Application_Version
,(IPTR
) VERSION
,
201 MUIA_Application_Copyright
, "Copyright 2002-2003 by Emmanuel Lesueur",
202 MUIA_Application_Author
, "Emmanuel Lesueur",
203 MUIA_Application_Description
, __(MSG_APP_TITLE
),
204 MUIA_Application_Base
, "FTMANAGER",
205 SubWindow
, win
= WindowObject
,
206 MUIA_Window_ID
, MAKE_ID('F','T','2','M'),
207 MUIA_Window_Title
, __(MSG_WINDOW_TITLE
),
208 MUIA_Window_Width
, 400,
209 MUIA_Window_RootObject
,VGroup
,
210 Child
, fontlv
= ListviewObject
,
211 MUIA_Listview_List
, fontlist
= FontListObject
,
215 Child
, Label2(_(MSG_LABEL_SOURCE
)),
217 MUIA_Popasl_Type
, ASL_FileRequest
,
218 MUIA_Popstring_String
, src
= StringObject
,
220 MUIA_String_Contents
, __(MSG_ASL_FONTS_TRUETYPE
),
221 MUIA_String_AdvanceOnCR
, TRUE
,
222 MUIA_CycleChain
, TRUE
,
224 MUIA_Popstring_Button
, PopButton(MUII_PopDrawer
),
225 ASLFR_RejectIcons
, TRUE
,
226 ASLFR_DrawersOnly
, TRUE
,
228 Child
, Label2(_(MSG_LABEL_DESTINATION
)),
230 MUIA_Popasl_Type
, ASL_FileRequest
,
231 MUIA_Popstring_String
, dest
= StringObject
,
233 MUIA_String_Contents
, __(MSG_ASL_FONTS
),
234 MUIA_String_AdvanceOnCR
, TRUE
,
235 MUIA_CycleChain
, TRUE
,
237 MUIA_Popstring_Button
, PopButton(MUII_PopDrawer
),
238 ASLFR_DoSaveMode
, TRUE
,
239 ASLFR_DrawersOnly
, TRUE
,
240 ASLFR_RejectIcons
, TRUE
,
242 Child
, Label2(_(MSG_LABEL_CODEPAGE
)),
243 Child
, codepagecycle
= CycleObject
,
244 MUIA_Cycle_Entries
, codesetentries
,
247 Child
, quit
= SimpleButton(_(MSG_QUIT
)),
258 DoMethod(src
, MUIM_Notify
, MUIA_String_Acknowledge
, MUIV_EveryTime
,
259 fontlist
, 2, MUIM_FontList_AddDir
, MUIV_TriggerValue
);
261 DoMethod(dest
, MUIM_Notify
, MUIA_String_Acknowledge
, MUIV_EveryTime
,
262 app
, 2, MUIM_Application_ReturnID
, ID_SetDestDir
);
264 DoMethod(codepagecycle
, MUIM_Notify
, MUIA_Cycle_Active
, MUIV_EveryTime
,
265 app
, 2, MUIM_Application_ReturnID
, ID_SetCodePage
);
267 DoMethod(fontlv
, MUIM_Notify
, MUIA_Listview_DoubleClick
, TRUE
,
268 app
, 2, MUIM_Application_ReturnID
, ID_ShowFont
);
270 DoMethod(win
, MUIM_Notify
, MUIA_Window_CloseRequest
, TRUE
,
271 app
, 2, MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
);
273 DoMethod(quit
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
274 app
, 2, MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
);
276 DoMethod(fontlist
, MUIM_FontList_AddDir
, XGET(src
, MUIA_String_Contents
));
278 set(win
, MUIA_Window_Open
, TRUE
);
280 get(win
, MUIA_Window_Open
, &t
);
289 id
= DoMethod(app
, MUIM_Application_NewInput
, &sigs
);
292 case MUIV_Application_ReturnID_Quit
:
299 CONST_STRPTR name
= NULL
;
302 get(dest
, MUIA_String_Contents
, &name
);
306 newdir
= Lock(name
, ACCESS_READ
);
317 struct MUIS_FontList_Entry
*entry
;
320 DoMethod(fontlist
, MUIM_List_GetEntry
, MUIV_List_GetEntry_Active
, &entry
);
322 w
= FontWindowObject
,
323 MUIA_FontWindow_Filename
, entry
->FileName
,
329 DoMethod(w
, MUIM_Notify
, MUIA_Window_CloseRequest
, TRUE
,
330 app
, 6, MUIM_Application_PushMethod
, app
, 3,
331 MUIM_CallHook
, &CloseWinHook
, w
);
333 DoMethod(app
, OM_ADDMEMBER
, w
);
334 set(w
, MUIA_Window_Open
, TRUE
);
335 get(w
, MUIA_Window_Open
, &t
);
338 MUI_DisposeObject(w
);
348 get(codepagecycle
, MUIA_Cycle_Active
, &entry
);
349 LoadCodePage(entry
, NULL
);
356 sigs
= Wait(sigs
| SIGBREAKF_CTRL_C
);
357 if (sigs
& SIGBREAKF_CTRL_C
)
367 printf("Can't open window.\n");
370 MUI_DisposeObject(app
);
374 printf("Can't create MUI application.\n");
382 static int ftmanager_cli(void)
388 int main(int argc
, char **argv
)
390 int retval
= RETURN_FAIL
;
396 retval
= ftmanager_cli();
400 // Starting from CLI without arguments opens GUI, too
401 retval
= ftmanager_gui();
404 Locale_Deinitialize();