Example #1
0
static int GFD_Ok(GGadget *g, GEvent *e) {
    if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
	struct gfc_data *d = GDrawGetUserData(GGadgetGetWindow(g));
	GGadget *tf;
	GFileChooserGetChildren(d->gfc,NULL,NULL,&tf);
	if ( *_GGadgetGetTitle(tf)!='\0' ) {
	    extern int allow_utf8_glyphnames;
	    GTextInfo *ti = GGadgetGetListItemSelected(d->rename);
	    char *nlname = u2utf8_copy(ti->text);
	    force_names_when_opening = NameListByName(nlname);
	    free(nlname);
	    if ( force_names_when_opening!=NULL && force_names_when_opening->uses_unicode &&
		    !allow_utf8_glyphnames) {
		ff_post_error(_("Namelist contains non-ASCII names"),_("Glyph names should be limited to characters in the ASCII character set, but there are names in this namelist which use characters outside that range."));
return(true);
	    }
	    d->done = true;
	    d->ret = GGadgetGetTitle(d->gfc);

	    // Trim trailing '/' if its there and put that string back as
	    // the d->gfc string.
	    int tmplen = u_strlen( d->ret );
	    if( tmplen > 0 ) {
		if( d->ret[ tmplen-1 ] == '/' ) {
		    unichar_t* tmp = u_copy( d->ret );
		    tmp[ tmplen-1 ] = '\0';
		    GGadgetSetTitle(d->gfc, tmp);
		    free(tmp);
		    d->ret = GGadgetGetTitle(d->gfc);
		}
	    }
	}
    }
return( true );
}
Example #2
0
static void py_tllistcheck(struct gmenuitem *mi,PyObject *owner,
                           struct python_menu_info *menu_data, int menu_cnt) {
    PyObject *arglist, *result;

    if ( menu_data==NULL )
        return;

    for ( mi = mi->sub; mi->ti.text!=NULL || mi->ti.line ; ++mi ) {
        if ( mi->mid==-1 )		/* Submenu */
            continue;
        if ( mi->mid<0 || mi->mid>=menu_cnt ) {
            fprintf( stderr, "Bad Menu ID in python menu %d\n", mi->mid );
            mi->ti.disabled = true;
            continue;
        }
        if ( menu_data[mi->mid].check_enabled==NULL ) {
            mi->ti.disabled = false;
            continue;
        }
        arglist = PyTuple_New(2);
        Py_XINCREF(menu_data[mi->mid].data);
        Py_XINCREF(owner);
        PyTuple_SetItem(arglist,0,menu_data[mi->mid].data);
        PyTuple_SetItem(arglist,1,owner);
        result = PyEval_CallObject(menu_data[mi->mid].check_enabled, arglist);
        Py_DECREF(arglist);
        if ( result==NULL )
            /* Oh. An error. How fun. See below */;
        else if ( !PyInt_Check(result)) {
            char *menu_item_name = u2utf8_copy(mi->ti.text);
            LogError( "Return from enabling function for menu item %s must be boolean", menu_item_name );
            free( menu_item_name );
            mi->ti.disabled = true;
        } else
            mi->ti.disabled = PyInt_AsLong(result)==0;
        Py_XDECREF(result);
        if ( PyErr_Occurred()!=NULL )
            PyErr_Print();
    }
}
Example #3
0
static int AnchorD_GlyphChanged(GGadget *g, GEvent *e) {
    AnchorDlg *a = GDrawGetUserData(GGadgetGetWindow(g));
    if ( e->type==et_controlevent && e->u.control.subtype == et_listselected ) {
	GTextInfo *sel = GGadgetGetListItemSelected(g);

	if ( sel!=NULL ) {
	    AnchorPoint *ap = sel->userdata;
	    if ( ap==Add_Mark )
		AddAnchor(a,a->sc->parent,a->ap->anchor,true);
	    else if ( ap==Add_Base )
		AddAnchor(a,a->sc->parent,a->ap->anchor,false);
	    else {
		char *name = u2utf8_copy(sel->text);
		SplineChar *sc = SFGetChar(a->sc->parent,-1,name);

		free(name);
		AnchorD_ChangeGlyph(a,sc,ap);
	    }
	}
    }
return( true );
}
Encoding *ParseEncodingNameFromList(GGadget *listfield) {
    const unichar_t *name = _GGadgetGetTitle(listfield);
    int32 len;
    GTextInfo **ti = GGadgetGetList(listfield,&len);
    int i;
    Encoding *enc = NULL;

    for ( i=0; i<len; ++i ) if ( ti[i]->text!=NULL ) {
            if ( u_strcmp(name,ti[i]->text)==0 ) {
                enc = FindOrMakeEncoding(ti[i]->userdata);
                break;
            }
        }

    if ( enc == NULL ) {
        char *temp = u2utf8_copy(name);
        enc = FindOrMakeEncoding(temp);
        free(temp);
    }
    if ( enc==NULL )
        ff_post_error(_("Bad Encoding"),_("Bad Encoding"));
    return( enc );
}
Example #5
0
static void AnchorD_NextPrev(AnchorDlg *a,int incr) {
    GGadget *g = GWidgetGetControl(a->gw,CID_Glyph);
    int len;
    GTextInfo **ti = GGadgetGetList(g,&len);
    int sel = GGadgetGetFirstListSelectedItem(g);

    for ( sel += incr; sel>0 && sel<len; sel+=incr ) {
	if ( !( ti[sel]->userdata == Add_Mark ||
		ti[sel]->userdata == Add_Base ||
		ti[sel]->line ||
		ti[sel]->disabled ))
    break;
    }
    if ( sel==0 || sel>=len )
	GDrawBeep(NULL);
    else {
	char *name = u2utf8_copy(ti[sel]->text);
	SplineChar *sc = SFGetChar(a->sc->parent,-1,name);

	free(name);
	GGadgetSelectOneListItem(g,sel);
	AnchorD_ChangeGlyph(a,sc,ti[sel]->userdata);
    }
}
Example #6
0
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);
            }
        }
    }
}
Example #7
0
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);
}