unichar_t *FVOpenFont(char *title, const char *defaultfile, int mult) { GRect pos; int i, filter, renamei; GWindow gw; GWindowAttrs wattrs; GGadgetCreateData gcd[11], boxes[5], *varray[9], *harray1[7], *harray2[4], *harray3[9]; GTextInfo label[10]; struct gfc_data d; int bs = GIntGetResource(_NUM_Buttonsize), bsbigger, totwid, spacing; GGadget *tf; unichar_t *temp; char **nlnames; GTextInfo *namelistnames, **filts; int cnt; memset(&d,'\0',sizeof(d)); memset(&wattrs,0,sizeof(wattrs)); wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_isdlg|wam_restrict; wattrs.event_masks = ~(1<<et_charup); wattrs.restrict_input_to_me = 1; wattrs.is_dlg = true; wattrs.undercursor = 1; wattrs.cursor = ct_pointer; wattrs.utf8_window_title = title; pos.x = pos.y = 0; totwid = GGadgetScale(295); bsbigger = 4*bs+4*14>totwid; totwid = bsbigger?4*bs+4*12:totwid; spacing = (totwid-4*bs-2*12)/3; pos.width = GDrawPointsToPixels(NULL,totwid); pos.height = GDrawPointsToPixels(NULL,247); gw = GDrawCreateTopWindow(NULL,&pos,e_h,&d,&wattrs); memset(&label,0,sizeof(label)); memset(&gcd,0,sizeof(gcd)); memset(&boxes,0,sizeof(boxes)); i=0; gcd[i].gd.pos.x = 12; gcd[i].gd.pos.y = 6; gcd[i].gd.pos.width = totwid*100/GIntGetResource(_NUM_ScaleFactor)-24; gcd[i].gd.pos.height = 180; gcd[i].gd.flags = gg_visible | gg_enabled; if ( RecentFiles[0]!=NULL ) gcd[i].gd.flags = gg_visible | gg_enabled | gg_file_pulldown; if ( mult ) gcd[i].gd.flags |= gg_file_multiple; varray[0] = &gcd[i]; varray[1] = NULL; gcd[i++].creator = GFileChooserCreate; label[i].text = (unichar_t *) _("Filter:"); label[i].text_is_1byte = true; gcd[i].gd.label = &label[i]; gcd[i].gd.pos.x = 8; gcd[i].gd.pos.y = 188+6; gcd[i].gd.flags = gg_visible | gg_enabled | gg_utf8_popup; gcd[i].gd.popup_msg = (unichar_t *) _("Display files of this type" ); harray1[0] = GCD_Glue; harray1[1] = &gcd[i]; gcd[i++].creator = GLabelCreate; gcd[i].gd.pos.x = 0; gcd[i].gd.pos.y = gcd[i-1].gd.pos.y-6; gcd[i].gd.flags = gg_visible | gg_enabled | gg_utf8_popup; gcd[i].gd.popup_msg = (unichar_t *) _("Display files of this type"); gcd[i].gd.handle_controlevent = GFD_FilterSelected; harray1[2] = &gcd[i]; harray1[3] = GCD_Glue; harray1[4] = GCD_Glue; harray1[5] = GCD_Glue; harray1[6] = NULL; gcd[i++].creator = GListButtonCreate; boxes[2].gd.flags = gg_visible | gg_enabled; boxes[2].gd.u.boxelements = harray1; boxes[2].creator = GHBoxCreate; varray[2] = &boxes[2]; varray[3] = NULL; label[i].text = (unichar_t *) _("Force glyph names to:"); label[i].text_is_1byte = true; gcd[i].gd.label = &label[i]; gcd[i].gd.pos.x = 8; gcd[i].gd.pos.y = 188+6; gcd[i].gd.flags = gg_visible | gg_enabled | gg_utf8_popup; gcd[i].gd.popup_msg = (unichar_t *) _("In the saved font, force all glyph names to match those in the specified namelist"); harray2[0] = &gcd[i]; gcd[i++].creator = GLabelCreate; renamei = i; gcd[i].gd.pos.x = 0; gcd[i].gd.pos.y = gcd[i-1].gd.pos.y-6; gcd[i].gd.flags = gg_visible | gg_enabled | gg_utf8_popup; gcd[i].gd.popup_msg = (unichar_t *) _("In the saved font, force all glyph names to match those in the specified namelist"); gcd[i].creator = GListButtonCreate; nlnames = AllNamelistNames(); for ( cnt=0; nlnames[cnt]!=NULL; ++cnt); namelistnames = gcalloc(cnt+3,sizeof(GTextInfo)); namelistnames[0].text = (unichar_t *) _("No Rename"); namelistnames[0].text_is_1byte = true; if ( force_names_when_opening==NULL ) { namelistnames[0].selected = true; gcd[i].gd.label = &namelistnames[0]; } namelistnames[1].line = true; for ( cnt=0; nlnames[cnt]!=NULL; ++cnt) { namelistnames[cnt+2].text = (unichar_t *) nlnames[cnt]; namelistnames[cnt+2].text_is_1byte = true; if ( force_names_when_opening!=NULL && strcmp(_(force_names_when_opening->title),nlnames[cnt])==0 ) { namelistnames[cnt+2].selected = true; gcd[i].gd.label = &namelistnames[cnt+2]; } } harray2[1] = &gcd[i]; harray2[2] = GCD_Glue; harray2[3] = NULL; gcd[i++].gd.u.list = namelistnames; free(nlnames); boxes[3].gd.flags = gg_visible | gg_enabled; boxes[3].gd.u.boxelements = harray2; boxes[3].creator = GHBoxCreate; varray[4] = &boxes[3]; varray[5] = NULL; gcd[i].gd.pos.x = 12; gcd[i].gd.pos.y = 216-3; gcd[i].gd.pos.width = -1; gcd[i].gd.flags = gg_visible | gg_enabled | gg_but_default; label[i].text = (unichar_t *) _("_OK"); label[i].text_is_1byte = true; label[i].text_in_resource = true; gcd[i].gd.mnemonic = 'O'; gcd[i].gd.label = &label[i]; gcd[i].gd.handle_controlevent = GFD_Ok; harray3[0] = GCD_Glue; harray3[1] = &gcd[i]; gcd[i++].creator = GButtonCreate; gcd[i].gd.pos.x = -(spacing+bs)*100/GIntGetResource(_NUM_ScaleFactor)-12; gcd[i].gd.pos.y = gcd[i-1].gd.pos.y+3; gcd[i].gd.pos.width = -1; gcd[i].gd.flags = gg_visible | gg_enabled; label[i].text = (unichar_t *) S_("Font|_New"); label[i].text_is_1byte = true; label[i].text_in_resource = true; gcd[i].gd.mnemonic = 'N'; gcd[i].gd.label = &label[i]; gcd[i].gd.handle_controlevent = GFD_New; harray3[2] = GCD_Glue; harray3[3] = &gcd[i]; gcd[i++].creator = GButtonCreate; filter = i; gcd[i].gd.pos.x = (spacing+bs)*100/GIntGetResource(_NUM_ScaleFactor)+12; gcd[i].gd.pos.y = gcd[i-1].gd.pos.y; gcd[i].gd.pos.width = -1; gcd[i].gd.flags = /* gg_visible |*/ gg_enabled; label[i].text = (unichar_t *) _("_Filter"); label[i].text_is_1byte = true; label[i].text_in_resource = true; gcd[i].gd.mnemonic = 'F'; gcd[i].gd.label = &label[i]; gcd[i].gd.handle_controlevent = GFileChooserFilterEh; harray3[4] = &gcd[i]; gcd[i++].creator = GButtonCreate; gcd[i].gd.pos.x = -12; gcd[i].gd.pos.y = gcd[i-1].gd.pos.y; gcd[i].gd.pos.width = -1; gcd[i].gd.flags = gg_visible | gg_enabled | gg_but_cancel; label[i].text = (unichar_t *) _("_Cancel"); label[i].text_is_1byte = true; label[i].text_in_resource = true; gcd[i].gd.label = &label[i]; gcd[i].gd.mnemonic = 'C'; gcd[i].gd.handle_controlevent = GFD_Cancel; harray3[5] = GCD_Glue; harray3[6] = &gcd[i]; harray3[7] = GCD_Glue; harray3[8] = NULL; gcd[i++].creator = GButtonCreate; boxes[4].gd.flags = gg_visible | gg_enabled; boxes[4].gd.u.boxelements = harray3; boxes[4].creator = GHBoxCreate; varray[6] = &boxes[4]; varray[7] = NULL; varray[8] = NULL; boxes[0].gd.pos.x = boxes[0].gd.pos.y = 2; boxes[0].gd.flags = gg_visible | gg_enabled; boxes[0].gd.u.boxelements = varray; boxes[0].creator = GHVGroupCreate; gcd[i].gd.pos.x = 2; gcd[i].gd.pos.y = 2; gcd[i].gd.pos.width = pos.width-4; gcd[i].gd.pos.height = pos.height-4; gcd[i].gd.flags = gg_enabled | gg_visible | gg_pos_in_pixels; gcd[i++].creator = GGroupCreate; GGadgetsCreate(gw,boxes); d.gfc = gcd[0].ret; d.rename = gcd[renamei].ret; GGadgetSetList(harray1[2]->ret,(filts = StandardFilters()),true); GHVBoxSetExpandableRow(boxes[0].ret,0); GHVBoxSetExpandableCol(boxes[2].ret,gb_expandglue); GHVBoxSetExpandableCol(boxes[3].ret,gb_expandglue); GHVBoxSetExpandableCol(boxes[4].ret,gb_expandgluesame); GHVBoxFitWindow(boxes[0].ret); free(namelistnames); GGadgetSetUserData(gcd[filter].ret,gcd[0].ret); GFileChooserConnectButtons(gcd[0].ret,harray3[1]->ret,gcd[filter].ret); temp = utf82u_copy(filts[default_font_filter_index]->userdata); GFileChooserSetFilterText(gcd[0].ret,temp); free(temp); GFileChooserGetChildren(gcd[0].ret,NULL, NULL, &tf); if ( RecentFiles[0]!=NULL ) { GGadgetSetList(tf,GTextInfoFromChars(RecentFiles,RECENT_MAX),false); } GGadgetSetTitle8(gcd[0].ret,defaultfile); GWidgetHidePalettes(); GDrawSetVisible(gw,true); while ( !d.done ) GDrawProcessOneEvent(NULL); GDrawDestroyWindow(gw); GDrawProcessPendingEvents(NULL); /* Give the window a chance to vanish... */ GDrawSync(NULL); GDrawProcessPendingEvents(NULL); /* Give the window a chance to vanish... */ free( d.lastpopupfontname ); return(d.ret); }
unichar_t* WordlistEscapedInputStringToRealString( SplineFont* sf, const unichar_t* input_const, GArray** selected_out, WordlistEscapedInputStringToRealString_getFakeUnicodeOfScFunc getUnicodeFunc, void* udata ) { char* input = u2utf8_copy(input_const); // truncate insanely long lines rather than crash if( strlen(input) > PATH_MAX ) input[PATH_MAX] = '\0'; // printf("MVEscapedInputStringToRealString(top) input:%s\n", input ); int buffer_sz = PATH_MAX; char buffer[PATH_MAX+1]; memset( buffer, '\0', buffer_sz ); char *out = buffer; char* in = input; char* in_end = input + strlen(input); // trim comment and beyond from input { char* p = input; while( p && p < in_end ) { p = strchr( p, '#' ); if( p > input && *(p-1) == '/' ) { p++; continue; } if( p ) *p = '\0'; break; } } in_end = input + strlen(input); // printf("MVEscapedInputStringToRealString() in:%p in_end:%p\n", in, in_end ); GArray* selected = g_array_new( 1, 1, sizeof(int)); *selected_out = selected; int addingGlyphsToSelected = 0; int currentGlyphIndex = -1; for ( ; in != in_end; in++ ) { char ch = *in; // printf("got ch:%c buf:%s\n", ch, buffer ); if( ch == '[' ) { addingGlyphsToSelected = 1; continue; } if( ch == ']' ) { addingGlyphsToSelected = 0; continue; } currentGlyphIndex++; if( addingGlyphsToSelected ) { int selectGlyph = currentGlyphIndex; g_array_append_val( selected, selectGlyph ); } if( ch == '/' || ch == '\\' ) { // start of a glyph name char glyphname[ PATH_MAX+1 ]; char* updated_in = 0; SplineChar* sc = WordlistEscapedInputStringToRealString_readGlyphName( sf, in, in_end, &updated_in, glyphname ); if( sc ) { TRACE("ToRealString have an sc!... in:%p updated_in:%p\n", in, updated_in ); in = updated_in; int n = getUnicodeFunc( sc, udata ); TRACE("ToRealString orig_pos:%d\n", sc->orig_pos ); if( n == -1 ) { printf("ToRealString NO UNICODE, orig_pos:%d\n", sc->orig_pos ); printf("ToRealString NO UNICODE, name:%s\n", sc->name ); } // printf("ToRealString have an sc!... n:%d\n", n ); // printf("sc->unic:%d\n",sc->unicodeenc); TRACE("calling utf8_idpb buffer:%s out:%s ch:%d\n", buffer, out, n ); out = utf8_idpb( out, n, 0); if( !out ) printf("ToRealString error on out\n"); continue; } } *out++ = ch; } unichar_t* ret = (unichar_t *) utf82u_copy( buffer ); free(input); return(ret); }
static void InsertSubMenus(PyObject *args,GMenuItem2 **mn, int is_cv) { int i, j, cnt; PyObject *func, *check, *data; char *shortcut_str; GMenuItem2 *mmn; /* I've done type checking already */ cnt = PyTuple_Size(args); func = PyTuple_GetItem(args,0); if ( (check = PyTuple_GetItem(args,1))==Py_None ) check = NULL; data = PyTuple_GetItem(args,2); if ( PyTuple_GetItem(args,4)==Py_None ) shortcut_str = NULL; else { #if PY_MAJOR_VERSION >= 3 PyObject *obj = PyUnicode_AsUTF8String(PyTuple_GetItem(args,4)); shortcut_str = PyBytes_AsString(obj); #else /* PY_MAJOR_VERSION >= 3 */ shortcut_str = PyBytes_AsString(PyTuple_GetItem(args,4)); #endif /* PY_MAJOR_VERSION >= 3 */ } for ( i=5; i<cnt; ++i ) { PyObject *submenu_utf8 = PYBYTES_UTF8(PyTuple_GetItem(args,i)); unichar_t *submenuu = utf82u_copy( PyBytes_AsString(submenu_utf8) ); Py_DECREF(submenu_utf8); j = 0; if ( *mn != NULL ) { for ( j=0; (*mn)[j].ti.text!=NULL || (*mn)[j].ti.line; ++j ) { if ( (*mn)[j].ti.text==NULL ) continue; if ( u_strcmp((*mn)[j].ti.text,submenuu)==0 ) break; } } if ( *mn==NULL || (*mn)[j].ti.text==NULL ) { *mn = grealloc(*mn,(j+2)*sizeof(GMenuItem2)); memset(*mn+j,0,2*sizeof(GMenuItem2)); } mmn = *mn; if ( mmn[j].ti.text==NULL ) { mmn[j].ti.text = submenuu; mmn[j].ti.fg = mmn[j].ti.bg = COLOR_DEFAULT; if ( i!=cnt-1 ) { mmn[j].mid = -1; mmn[j].moveto = is_cv ? cvpy_tllistcheck : fvpy_tllistcheck; mn = &mmn[j].sub; } else { mmn[j].shortcut = shortcut_str; mmn[j].invoke = is_cv ? cvpy_menuactivate : fvpy_menuactivate; mmn[j].mid = MenuDataAdd(func,check,data,is_cv); } } else { if ( i!=cnt-1 ) mn = &mmn[j].sub; else { mmn[j].shortcut = shortcut_str; mmn[j].invoke = is_cv ? cvpy_menuactivate : fvpy_menuactivate; mmn[j].mid = MenuDataAdd(func,check,data,is_cv); fprintf( stderr, "Redefining menu item %s\n", u2utf8_copy(submenuu) ); free(submenuu); } } } }
/* Builds up a menu containing the titles of all the major windows */ void WindowMenuBuild(GWindow basew,struct gmenuitem *mi,GEvent *e) { int i, cnt, precnt; FontViewBase *fv; CharViewBase *cv; MetricsView *mv; BitmapView *bv; GMenuItem *sub; BDFFont *bdf; precnt = 6; cnt = precnt; for ( fv = (FontViewBase *) fv_list; fv!=NULL; fv = fv->next ) { ++cnt; /* for the font */ for ( i=0; i<fv->sf->glyphcnt; ++i ) if ( fv->sf->glyphs[i]!=NULL ) { for ( cv = fv->sf->glyphs[i]->views; cv!=NULL; cv=cv->next ) ++cnt; /* for each char view in the font */ } for ( bdf= fv->sf->bitmaps; bdf!=NULL; bdf = bdf->next ) { for ( i=0; i<bdf->glyphcnt; ++i ) if ( bdf->glyphs[i]!=NULL ) { for ( bv = bdf->glyphs[i]->views; bv!=NULL; bv=bv->next ) ++cnt; } } for ( mv=fv->sf->metrics; mv!=NULL; mv=mv->next ) ++cnt; } if ( cnt==0 ) { /* This can't happen */ return; } sub = calloc(cnt+1,sizeof(GMenuItem)); memcpy(sub,mi->sub,precnt*sizeof(struct gmenuitem)); for ( i=0; i<precnt; ++i ) mi->sub[i].ti.text = NULL; mi->sub = sub; for ( i=0; sub[i].ti.text!=NULL || sub[i].ti.line; ++i ) { if ( sub[i].ti.text_is_1byte && sub[i].ti.text_in_resource) { sub[i].ti.text = utf82u_mncopy((char *) sub[i].ti.text,&sub[i].ti.mnemonic); sub[i].ti.text_is_1byte = sub[i].ti.text_in_resource = false; } else if ( sub[i].ti.text_is_1byte ) { sub[i].ti.text = utf82u_copy((char *) sub[i].ti.text); sub[i].ti.text_is_1byte = false; } else if ( sub[i].ti.text_in_resource ) { sub[i].ti.text = u_copy(GStringGetResource((intpt) sub[i].ti.text,NULL)); sub[i].ti.text_in_resource = false; } else sub[i].ti.text = u_copy(sub[i].ti.text); } cnt = precnt; for ( fv = (FontViewBase *) fv_list; fv!=NULL; fv = fv->next ) { AddMI(&sub[cnt++],((FontView *) fv)->gw,fv->sf->changed,true); for ( i=0; i<fv->sf->glyphcnt; ++i ) if ( fv->sf->glyphs[i]!=NULL ) { for ( cv = fv->sf->glyphs[i]->views; cv!=NULL; cv=cv->next ) AddMI(&sub[cnt++],((CharView *) cv)->gw,cv->sc->changed,false); } for ( bdf= fv->sf->bitmaps; bdf!=NULL; bdf = bdf->next ) { for ( i=0; i<bdf->glyphcnt; ++i ) if ( bdf->glyphs[i]!=NULL ) { for ( bv = bdf->glyphs[i]->views; bv!=NULL; bv=bv->next ) AddMI(&sub[cnt++],bv->gw,bv->bc->changed,false); } } for ( mv=fv->sf->metrics; mv!=NULL; mv=mv->next ) AddMI(&sub[cnt++],mv->gw,false,false); } }