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 ); }
static int FtPpem_PtYChanged(GGadget *g, GEvent *e) { if ( e->type==et_controlevent && e->u.control.subtype == et_textchanged ) { FtSizeData *fsd = GDrawGetUserData(GGadgetGetWindow(g)); if ( GGadgetIsChecked(GWidgetGetControl(fsd->gw,CID_SameAs))) { const unichar_t *y = _GGadgetGetTitle(g); GGadgetSetTitle(GWidgetGetControl(fsd->gw,CID_PointSizeX),y); } } return( true ); }
static real GetQuietReal(GWindow gw,int cid,int *err) { const unichar_t *txt; unichar_t *end; real val; txt = _GGadgetGetTitle(GWidgetGetControl(gw,cid)); val = u_strtod(txt,&end); if ( *end!='\0' ) *err = true; return( val ); }
static int FtPpem_SameAsChanged(GGadget *g, GEvent *e) { if ( e->type==et_controlevent && e->u.control.subtype == et_radiochanged ) { FtSizeData *fsd = GDrawGetUserData(GGadgetGetWindow(g)); if ( GGadgetIsChecked(g)) { const uint32_t *y = _GGadgetGetTitle(GWidgetGetControl(fsd->gw,CID_PointSize)); GGadgetSetTitle(GWidgetGetControl(fsd->gw,CID_PointSizeX),y); GGadgetSetEnabled(GWidgetGetControl(fsd->gw,CID_PointSizeX),false); } else { GGadgetSetEnabled(GWidgetGetControl(fsd->gw,CID_PointSizeX),true); } } return( true ); }
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') { d->done = true; d->ret = GGadgetGetTitle (d->gfc); } } return (true); }
static void ExecNative(GGadget *g, GEvent *e) { struct sd_data *sd = GDrawGetUserData(GGadgetGetWindow(g)); Context c; Val args[1]; Array *dontfree[1]; jmp_buf env; memset( &c,0,sizeof(c)); memset( args,0,sizeof(args)); memset( dontfree,0,sizeof(dontfree)); running_script = true; c.a.argc = 1; c.a.vals = args; c.dontfree = dontfree; c.filename = args[0].u.sval = "ScriptDlg"; args[0].type = v_str; c.return_val.type = v_void; c.err_env = &env; c.curfv = (FontViewBase *) sd->fv; if ( setjmp(env)!=0 ) { running_script = false; return; /* Error return */ } c.script = GFileTmpfile(); if ( c.script==NULL ) ScriptError(&c, "Can't create temporary file"); else { const unichar_t *ret = _GGadgetGetTitle(GWidgetGetControl(sd->gw,CID_Script)); while ( *ret ) { /* There's a bug here. Filenames need to be converted to the local charset !!!! */ putc(*ret,c.script); ++ret; } rewind(c.script); ff_VerboseCheck(); c.lineno = 1; while ( !c.returned && !c.broken && ff_NextToken(&c)!=tt_eof ) { ff_backuptok(&c); ff_statement(&c); } fclose(c.script); sd->done = true; } running_script = false; }
static int AnchorD_CorrectionChanged(GGadget *g, GEvent *e) { AnchorDlg *a = GDrawGetUserData(GGadgetGetWindow(g)); if ( e->type==et_controlevent && e->u.control.subtype == et_textchanged ) { const unichar_t *ret = _GGadgetGetTitle(g); int is_y = GGadgetGetCid(g)==CID_YCor; unichar_t *end; int correction = u_strtol(ret,&end,10); while ( *end==' ' ) ++end; if ( *end!='\0' ) return( true ); if ( correction<-128 || correction>127 ) { ff_post_error( _("Out of Range"), _("Corrections must be between -128 and 127 (and should be smaller)") ); return( true ); } DeviceTableSet(is_y?&a->yadjust:&a->xadjust,a->pixelsize,correction); GDrawRequestExpose(a->gw,NULL,false); } return( true ); }
static int AnchorD_PositionChanged(GGadget *g, GEvent *e) { AnchorDlg *a = GDrawGetUserData(GGadgetGetWindow(g)); if ( e->type==et_controlevent && e->u.control.subtype == et_textchanged ) { const unichar_t *ret = _GGadgetGetTitle(g); int is_y = GGadgetGetCid(g)==CID_Y; unichar_t *end; int val = u_strtol(ret,&end,10); while ( *end==' ' ) ++end; if ( *end!='\0' ) return( true ); if ( (is_y && a->apos.y==val) || (!is_y && a->apos.x==val)) return( true ); if ( is_y ) a->apos.y = val; else a->apos.x = val; AnchorD_ClearCorrections(a); GDrawRequestExpose(a->gw,NULL,false); } 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 ); }
static int AnchorD_DisplaySizeChanged(GGadget *g, GEvent *e) { AnchorDlg *a = GDrawGetUserData(GGadgetGetWindow(g)); if ( e->type==et_controlevent && e->u.control.subtype == et_textchanged ) { const unichar_t *ret = _GGadgetGetTitle(GWidgetGetControl(a->gw,CID_DisplaySize)); unichar_t *end; int pixelsize = u_strtol(ret,&end,10); while ( *end==' ' ) ++end; if ( pixelsize>4 && pixelsize<400 && *end=='\0' ) { unichar_t ubuf[20]; char buffer[20]; ubuf[0] = '0'; ubuf[1] = '\0'; if ( a->xadjust.corrections!=NULL && pixelsize>=a->xadjust.first_pixel_size && pixelsize<=a->xadjust.last_pixel_size ) { sprintf( buffer, "%d", a->xadjust.corrections[ pixelsize-a->xadjust.first_pixel_size]); uc_strcpy(ubuf,buffer); } GGadgetSetTitle(GWidgetGetControl(a->gw,CID_XCor),ubuf); ubuf[0] = '0'; ubuf[1] = '\0'; if ( a->yadjust.corrections!=NULL && pixelsize>=a->yadjust.first_pixel_size && pixelsize<=a->yadjust.last_pixel_size ) { sprintf( buffer, "%d", a->yadjust.corrections[ pixelsize-a->yadjust.first_pixel_size]); uc_strcpy(ubuf,buffer); } GGadgetSetTitle(GWidgetGetControl(a->gw,CID_YCor),ubuf); a->xoff = pixelsize*a->xoff/a->pixelsize; a->pixelsize = aa_pixelsize = pixelsize; AnchorD_ChangeSize(a); GDrawRequestExpose(a->gw,NULL,false); } } return( true ); }
void NonLinearDlg(FontView *fv,CharView *cv) { static unichar_t *lastx, *lasty; struct nldlg d; GRect pos; GWindowAttrs wattrs; GGadgetCreateData gcd[8], boxes[4], *hvarray[3][3], *barray[9], *varray[3][2]; GTextInfo label[8]; struct context c; char *expstr; memset(&d,'\0',sizeof(d)); memset(&c,'\0',sizeof(c)); memset(&wattrs,0,sizeof(wattrs)); wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_restrict|wam_isdlg; wattrs.event_masks = ~(1<<et_charup); wattrs.restrict_input_to_me = 1; wattrs.is_dlg = 1; wattrs.undercursor = 1; wattrs.cursor = ct_pointer; wattrs.utf8_window_title = _("Non Linear Transform"); pos.x = pos.y = 0; pos.width = GGadgetScale(GDrawPointsToPixels(NULL,200)); pos.height = GDrawPointsToPixels(NULL,97); d.gw = GDrawCreateTopWindow(NULL,&pos,nld_e_h,&d,&wattrs); memset(gcd,0,sizeof(gcd)); memset(boxes,0,sizeof(boxes)); memset(label,0,sizeof(label)); /* GT: an expression describing the transformation applied to the X coordinate */ label[0].text = (unichar_t *) _("X Expr:"); label[0].text_is_1byte = true; gcd[0].gd.label = &label[0]; gcd[0].gd.pos.x = 10; gcd[0].gd.pos.y = 8; gcd[0].gd.flags = gg_visible | gg_enabled | gg_utf8_popup; gcd[0].gd.popup_msg = (unichar_t *) _("These expressions may contain the operators +,-,*,/,%,^ (which means raise to the power of here), and ?: It may also contain a few standard functions. Basic terms are real numbers, x and y.\nExamples:\n x^3+2.5*x^2+5\n (x-300)*(y-200)/100\n y+sin(100*x)"); gcd[0].creator = GLabelCreate; hvarray[0][0] = &gcd[0]; if ( lastx!=NULL ) label[1].text = lastx; else { label[1].text = (unichar_t *) "x"; label[1].text_is_1byte = true; } gcd[1].gd.label = &label[1]; gcd[1].gd.pos.x = 55; gcd[1].gd.pos.y = 5; gcd[1].gd.pos.width = 135; gcd[1].gd.flags = gg_visible | gg_enabled | gg_utf8_popup; gcd[1].gd.popup_msg = (unichar_t *) _("These expressions may contain the operators +,-,*,/,%,^ (which means raise to the power of here), and ?: It may also contain a few standard functions. Basic terms are real numbers, x and y.\nExamples:\n x^3+2.5*x^2+5\n (x-300)*(y-200)/100\n y+sin(100*x)"); gcd[1].creator = GTextFieldCreate; hvarray[0][1] = &gcd[1]; hvarray[0][2] = NULL; /* GT: an expression describing the transformation applied to the Y coordinate */ label[2].text = (unichar_t *) _("Y Expr:"); label[2].text_is_1byte = true; gcd[2].gd.label = &label[2]; gcd[2].gd.pos.x = 10; gcd[2].gd.pos.y = gcd[0].gd.pos.y+26; gcd[2].gd.flags = gg_visible | gg_enabled | gg_utf8_popup; gcd[2].gd.popup_msg = (unichar_t *) _("These expressions may contain the operators +,-,*,/,%,^ (which means raise to the power of here), and ?: It may also contain a few standard functions. Basic terms are real numbers, x and y.\nExamples:\n x^3+2.5*x^2+5\n (x-300)*(y-200)/100\n y+sin(100*x)"); gcd[2].creator = GLabelCreate; hvarray[1][0] = &gcd[2]; if ( lasty!=NULL ) label[3].text = lasty; else { label[3].text = (unichar_t *) "y"; label[3].text_is_1byte = true; } gcd[3].gd.label = &label[3]; gcd[3].gd.pos.x = gcd[1].gd.pos.x; gcd[3].gd.pos.y = gcd[1].gd.pos.y+26; gcd[3].gd.pos.width = gcd[1].gd.pos.width; gcd[3].gd.flags = gg_visible | gg_enabled | gg_utf8_popup; gcd[3].gd.popup_msg = (unichar_t *) _("These expressions may contain the operators +,-,*,/,%,^ (which means raise to the power of here), and ?: It may also contain a few standard functions. Basic terms are real numbers, x and y.\nExamples:\n x^3+2.5*x^2+5\n (x-300)*(y-200)/100\n y+sin(100*x)"); gcd[3].creator = GTextFieldCreate; hvarray[1][1] = &gcd[3]; hvarray[1][2] = NULL; hvarray[2][0] = NULL; boxes[2].gd.flags = gg_enabled|gg_visible; boxes[2].gd.u.boxelements = hvarray[0]; boxes[2].creator = GHVBoxCreate; varray[0][0] = &boxes[2]; varray[0][1] = NULL; gcd[4].gd.pos.x = 30-3; gcd[4].gd.pos.y = gcd[3].gd.pos.y+30; gcd[4].gd.pos.width = -1; gcd[4].gd.pos.height = 0; gcd[4].gd.flags = gg_visible | gg_enabled | gg_but_default; label[4].text = (unichar_t *) _("_OK"); label[4].text_is_1byte = true; label[4].text_in_resource = true; gcd[4].gd.label = &label[4]; gcd[4].gd.cid = true; gcd[4].creator = GButtonCreate; barray[0] = GCD_Glue; barray[1] = &gcd[4]; barray[2] = GCD_Glue; gcd[5].gd.pos.x = -30; gcd[5].gd.pos.y = gcd[4].gd.pos.y+3; gcd[5].gd.pos.width = -1; gcd[5].gd.pos.height = 0; gcd[5].gd.flags = gg_visible | gg_enabled | gg_but_cancel; label[5].text = (unichar_t *) _("_Cancel"); label[5].text_is_1byte = true; label[5].text_in_resource = true; gcd[5].gd.label = &label[5]; gcd[5].gd.cid = false; gcd[5].creator = GButtonCreate; barray[3] = GCD_Glue; barray[4] = &gcd[5]; barray[5] = GCD_Glue; barray[6] = NULL; boxes[3].gd.flags = gg_enabled|gg_visible; boxes[3].gd.u.boxelements = barray; boxes[3].creator = GHBoxCreate; varray[1][0] = &boxes[3]; varray[1][1] = NULL; varray[2][0] = NULL; boxes[0].gd.pos.x = boxes[0].gd.pos.y = 2; boxes[0].gd.flags = gg_enabled|gg_visible; boxes[0].gd.u.boxelements = varray[0]; boxes[0].creator = GHVGroupCreate; GGadgetsCreate(d.gw,boxes); GHVBoxSetExpandableCol(boxes[2].ret,1); GHVBoxSetExpandableCol(boxes[3].ret,gb_expandgluesame); GHVBoxFitWindow(boxes[0].ret); GDrawSetVisible(d.gw,true); while ( !d.done ) { GDrawProcessOneEvent(NULL); if ( d.done && d.ok ) { expstr = cu_copy(_GGadgetGetTitle(gcd[1].ret)); c.had_error = false; if ( (c.x_expr = nlt_parseexpr(&c,expstr))==NULL ) d.done = d.ok = false; else { free(expstr); c.had_error = false; expstr = cu_copy(_GGadgetGetTitle(gcd[3].ret)); if ( (c.y_expr = nlt_parseexpr(&c,expstr))==NULL ) { d.done = d.ok = false; nlt_exprfree(c.x_expr); } else { free(expstr); free(lasty); free(lastx); lastx = GGadgetGetTitle(gcd[1].ret); lasty = GGadgetGetTitle(gcd[3].ret); } } } } if ( d.ok ) { if ( fv!=NULL ) _SFNLTrans((FontViewBase *) fv,&c); else CVNLTrans((CharViewBase *) cv,&c); nlt_exprfree(c.x_expr); nlt_exprfree(c.y_expr); } GDrawDestroyWindow(d.gw); }
#define CID_Win 1008 #define CID_Mac 1009 #define CID_FreeType 1010 #define CID_RasterizedStrikes 1011 static int GetSystem(GWindow gw) { if ( GGadgetIsChecked(GWidgetGetControl(gw,CID_X)) ) return( CID_X ); if ( GGadgetIsChecked(GWidgetGetControl(gw,CID_Win)) ) return( CID_Win ); return( CID_Mac ); } static int32 *ParseList(GWindow gw, int cid,int *err, int final) { const unichar_t *val = _GGadgetGetTitle(GWidgetGetControl(gw,cid)), *pt; unichar_t *end, *end2; int i; real *sizes; int32 *ret; int system = GetSystem(gw); int scale; *err = false; end2 = NULL; for ( i=1, pt = val; (end = u_strchr(pt,',')) || (end2=u_strchr(pt,' ')); ++i ) { if ( end!=NULL && end2!=NULL ) { if ( end2<end ) end = end2; } else if ( end2!=NULL ) end = end2; pt = end+1;
static void AnchorD_Expose(AnchorDlg *a,GWindow pixmap,GEvent *event) { GRect *area = &event->u.expose.rect; GRect clip, old1, old2; int expose_end = area->x+area->width; int factor = a->magfactor; int i,x,y; if ( expose_end<a->ctl_len ) return; GDrawPushClip(pixmap,area,&old1); if ( area->x<a->ctl_len+a->char_size*factor ) { GDrawDrawLine(pixmap,a->ctl_len,0,a->ctl_len,a->full_height,0x000000); KCD_DrawGlyph(pixmap,a->char_off*factor+a->ctl_len,a->baseline,a->bdfc,factor); DrawAnchorPoint(pixmap, a->char_off*factor+a->ctl_len + ((int) rint(a->apos.x*a->scale))*factor, a->baseline - ((int) rint(a->apos.y*a->scale))*factor, false); GDrawDrawLine(pixmap,a->ctl_len+a->char_size*factor,0,a->ctl_len+a->char_size*factor,a->full_height,0x000000); } if ( expose_end>a->ctl_len+a->char_size && area->y<a->sb_base ) { int xcor=0, ycor=0; unichar_t *end; const unichar_t *ret; ret = _GGadgetGetTitle(GWidgetGetControl(a->gw,CID_XCor)); xcor = u_strtol(ret,&end,10); while ( *end==' ' ) ++end; if ( *end!='\0' || xcor<-128 || xcor>127 ) xcor = 0; ret = _GGadgetGetTitle(GWidgetGetControl(a->gw,CID_YCor)); ycor = u_strtol(ret,&end,10); while ( *end==' ' ) ++end; if ( *end!='\0' || ycor<-128 || ycor>127 ) ycor = 0; clip = *area; if ( area->x<=a->ctl_len+a->char_size ) { clip.width -= a->ctl_len+a->char_size+1 - area->x; clip.x = a->ctl_len+a->char_size+1; } if ( area->y+area->height > a->sb_base ) clip.height = a->sb_base-area->y; GDrawPushClip(pixmap,&clip,&old2); for ( i=0; i<a->cnt; ++i ) { if ( a->apmatch[i].xstart - a->xoff > clip.x+clip.width ) break; if ( a->apmatch[i].xstart+a->apmatch[i].size*factor - a->xoff < clip.x ) continue; y = a->baseline; if ( i!=0 ) GDrawDrawLine(pixmap,a->apmatch[i].xstart-a->xoff,0, a->apmatch[i].xstart-a->xoff,a->sb_base,0x808080); if ( a->ap->type==at_cexit || a->ap->type==at_basechar || a->ap->type==at_baselig || a->ap->type==at_basemark ) { x = a->apmatch[i].xstart+a->char_off*factor - a->xoff; KCD_DrawGlyph(pixmap,x,y,a->bdfc,factor); x += ((int) rint((-a->apmatch[i].ap->me.x + a->apos.x)*a->scale) + xcor - DevTabFind(&a->apmatch[i].ap->xadjust,a->pixelsize))*factor; y += ((int) rint((a->apmatch[i].ap->me.y - a->apos.y)*a->scale) + -ycor + DevTabFind(&a->apmatch[i].ap->yadjust,a->pixelsize))*factor; KCD_DrawGlyph(pixmap,x,y,a->apmatch[i].bdfc,factor); } else { x = a->apmatch[i].xstart+a->apmatch[i].off*factor - a->xoff; KCD_DrawGlyph(pixmap,x,y,a->apmatch[i].bdfc,factor); x += ((int) rint((a->apmatch[i].ap->me.x - a->apos.x)*a->scale) + DevTabFind(&a->apmatch[i].ap->xadjust,a->pixelsize)-xcor)*factor; y += ((int) rint((-a->apmatch[i].ap->me.y + a->apos.y)*a->scale) + -DevTabFind(&a->apmatch[i].ap->yadjust,a->pixelsize)+ycor)*factor; KCD_DrawGlyph(pixmap,x,y,a->bdfc,factor); } } if ( i>0 ) GDrawDrawLine(pixmap,a->apmatch[i-1].xstart+a->apmatch[i-1].size*factor-a->xoff,0, a->apmatch[i-1].xstart+a->apmatch[i-1].size*factor-a->xoff,a->sb_base,0x808080); GDrawPopClip(pixmap,&old2); } GDrawPopClip(pixmap,&old1); }