static Uchar *font_print(int lowvalue, Attribute *attr, RedirectFunc *func) { int attribute,value; char *v; Uchar *fb; attribute=(lowvalue&0x3e0)>>5; value=(lowvalue&0x1f); v=font_get_name(attribute,-1); UTFtoUstr(v,fontbuf); fb=fontbuf; while (*fb) fb++; *fb++=':'; v=font_get_name(attribute,value); UTFtoUstr(v,fb); return fontbuf; }
// Ask for font name void font_ask_name(font_data *data) { char file[40],path[256],*fileptr; // Copy path strcpy(path,data->font_name); // Split filename if ((fileptr=FilePart(path))) { strcpy(file,fileptr); *fileptr=0; } else file[0]=0; // Empty path? if (!path[0]) strcpy(path,"fonts:"); // Busy window SetWindowBusy(data->window); // Display requester if (AslRequestTags(((WindowData *)data->window->UserData)->request, ASLFR_Window,data->window, ASLFR_TitleText,GetString(&data->locale,MSG_FONT_SELECT), ASLFR_InitialFile,file, ASLFR_InitialDrawer,path, ASLFR_IntuiMsgFunc,&data->refresh_hook, TAG_END)) { // Get pathname strcpy(path,((WindowData *)data->window->UserData)->request->fr_Drawer); AddPart(path,((WindowData *)data->window->UserData)->request->fr_File,256); // Get font name font_get_name(data,path); // Get new font font_get_font(data); font_show_font(data,FALSE); } // Unbusy window else ClearWindowBusy(data->window); }
int main(int argc,char **argv) { font_data *data; // Need dopus library if (!(DOpusBase=OpenLibrary("dopus5.library",LIB_VERSION))) if (!(DOpusBase=OpenLibrary("dopus5:libs/dopus5.library",55))) return(10); #ifdef __amigaos4__ if (!(IDOpus = (struct DOpusIFace *)GetInterface(DOpusBase, "main", 1, NULL))) { CloseLibrary(DOpusBase); return(10); } #endif // Allocate data if (!(data=AllocVec(sizeof(font_data),MEMF_CLEAR))) { font_free(0); return(5); } // Parse arguments data->args= ReadArgs( "FONT,SIZE/N,B=BOLD/S,I=ITALIC/S,U=ULINE/S,PUBSCREEN/K", (APTR)data->arg_array, NULL); // Default to topaz 8 #ifdef __AROS__ strcpy(data->font_name,"ttcourier.font"); #else strcpy(data->font_name,"topaz.font"); #endif data->font_size=8; // Got font name? if (data->arg_array[ARG_FONT]) font_get_name(data,(char *)data->arg_array[ARG_FONT]); // Got a font size? if (data->arg_array[ARG_SIZE] && *((long *)data->arg_array[ARG_SIZE])) { data->font_size=*((long *)data->arg_array[ARG_SIZE]); data->first=TRUE; } // Initialise locale init_locale_data(&data->locale); // Got locale library? if (LocaleBase) { BPTR lock; // Change PROGDIR: to dopus5: if ((lock=Lock("dopus5:",ACCESS_READ))) #ifdef __AROS__ // the lock returned here is the initial PROGDIR: which belongs to the system, // so it's not a very good idea to just UnLock it SetProgramDir(lock); #else UnLock(SetProgramDir(lock)); #endif // Initialise data->locale.li_LocaleBase=LocaleBase; data->locale.li_Catalog=OpenCatalogA(0,"viewfont.catalog",0); data->locale.li_Locale=OpenLocale(0); } // Create message port data->appport=CreateMsgPort(); // Open window if (!(font_open(data))) { font_free(data); return(5); } // Initial gadget settings if (data->arg_array[ARG_BOLD]) SetGadgetValue(data->list,GAD_FONT_BOLD,1); if (data->arg_array[ARG_ITALIC]) SetGadgetValue(data->list,GAD_FONT_ITALIC,1); if (data->arg_array[ARG_ULINE]) SetGadgetValue(data->list,GAD_FONT_ULINE,1); // Show font font_show_font(data,FALSE); // Initialise refresh hook data->refresh_hook.h_Entry=(ULONG (*)())font_refresh; data->refresh_hook.h_Data=data; // Event loop FOREVER { struct IntuiMessage *msg; BOOL quit_flag=FALSE; // AppWindow? if (data->appwindow) { struct AppMessage *amsg; // Get messages while ((amsg=(struct AppMessage *)GetMsg(data->appport))) { // Got file? if (amsg->am_NumArgs>0) { char buf[256]; // Get name DevNameFromLockDopus(amsg->am_ArgList[0].wa_Lock,buf,256); if (amsg->am_ArgList[0].wa_Name && *amsg->am_ArgList[0].wa_Name) AddPart(buf,amsg->am_ArgList[0].wa_Name,256); // Get font name font_get_name(data,buf); // Get new font font_get_font(data); font_show_font(data,FALSE); } // Reply to message ReplyMsg((struct Message *)amsg); } } // Requester? if (data->about) { // Handle requester if (SysReqHandler(data->about,0,0)>=0) { // Close requester FreeSysRequest(data->about); data->about=NULL; } } // Intuition messages if (data->window) { while ((msg=GetWindowMsg(data->window->UserPort))) { struct IntuiMessage msg_copy; UWORD id=0; // Copy message and reply msg_copy=*msg; ReplyWindowMsg(msg); // Get gadget ID if (msg_copy.Class==IDCMP_GADGETUP) id=((struct Gadget *)msg_copy.IAddress)->GadgetID; // Look at message switch (msg_copy.Class) { // Close window case IDCMP_CLOSEWINDOW: quit_flag=TRUE; break; // New size case IDCMP_NEWSIZE: // Redraw font font_show_font(data,FALSE); // Set flag to say we resized data->resized=TRUE; break; // Menu case IDCMP_MENUPICK: { struct MenuItem *item; // Get item if (!(item=ItemAddress(data->window->MenuStrip,msg_copy.Code))) break; // Get ID id=GTMENUITEM_USERDATA(item); // Fall through } // Gadget case IDCMP_GADGETUP: switch (id) { // Show requester case GAD_FONT_FONT_POPUP: case MENU_OPEN_FONT: // Ask for name font_ask_name(data); break; // Font name typed case GAD_FONT_FONT: // Get name font_get_name(data,(char *)GetGadgetValue(data->list,GAD_FONT_FONT)); // Get new font font_get_font(data); font_show_font(data,FALSE); break; // Font size up/down case GAD_FONT_UP: case GAD_FONT_DOWN: { short size; // Get next size size=font_get_size(data,(id==GAD_FONT_UP)?1:-1); // No change? if (size==data->font_size) break; // Use this size data->font_size=size; SetGadgetValue(data->list,GAD_FONT_SIZE,size); } // Font size given case GAD_FONT_CYCLE: // Check id if (id==GAD_FONT_CYCLE) { short size; // Get size if (!(size=atoi(data->size_labels[msg_copy.Code]))) break; // Refresh gadget data->font_size=size; SetGadgetValue(data->list,GAD_FONT_SIZE,data->font_size); } // Font size case GAD_FONT_SIZE: // Entered size if (id==GAD_FONT_SIZE) { // Bounds check gadget data->font_size= BoundsCheckGadget( data->list, GAD_FONT_SIZE, 4, 255); } // Get new font font_get_font(data); font_show_font(data,FALSE); break; // Styles changed case GAD_FONT_BOLD: case GAD_FONT_ITALIC: case GAD_FONT_ULINE: // Redraw font font_show_font(data,FALSE); break; // Save settings case MENU_SAVE_SETTINGS: font_save_settings(data); break; // Quit case MENU_QUIT: quit_flag=TRUE; break; // About case MENU_ABOUT: font_show_about(data); break; } break; // Rawkey case IDCMP_RAWKEY: // Help? if (msg_copy.Code==0x5f) font_show_about(data); // Key case IDCMP_VANILLAKEY: // Escape does quit if (msg_copy.Code==0x1b) quit_flag=TRUE; break; // Refresh case IDCMP_REFRESHWINDOW: // Have we just resized? if (data->resized) { // Don't need to refresh BeginRefresh(data->window); EndRefresh(data->window,TRUE); data->resized=FALSE; break; } // Refresh font display font_show_font(data,TRUE); break; } // Check window is still valid if (!data->window) break; } } if (quit_flag) break; // Wait for signal (ctrl-c breaks) if ((Wait(SIGBREAKF_CTRL_C| ((data->window)?(1<<data->window->UserPort->mp_SigBit):0)| ((data->about)?(1<<data->about->UserPort->mp_SigBit):0)| ((data->appwindow)?(1<<data->appport->mp_SigBit):0)))&SIGBREAKF_CTRL_C) break; } // Free stuff font_free(data); return(0); }