/* Copyright (C) 2000-2012 by George Williams */ /* * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include "bvedit.h" #include "fontforgeui.h" #include "fvmetrics.h" #include "splineutil.h" #include "ustring.h" #include typedef struct createwidthdlg { CreateWidthData wd; GWindow gw; } CreateWidthDlg; #define CID_Set 1001 #define CID_Incr 1002 #define CID_Scale 1003 #define CID_SetVal 1011 #define CID_IncrVal 1012 #define CID_ScaleVal 1013 static char *rb1[] = { N_("Set Width To:"), N_("Set LBearing To:"), N_("Set RBearing To:"), N_("Set Bearings To:"), N_("Set Vert. Advance To:") }; static char *rb2[] = { N_("Increment Width By:"), N_("Increment LBearing By:"), N_("Increment RBearing By:"), N_("Increment Bearings By:"), N_("Increment V. Adv. By:") }; static char *rb3[] = { N_("Scale Width By:"), N_("Scale LBearing By:"), N_("Scale RBearing By:"), N_("Scale Bearings By:"), N_("Scale VAdvance By:") }; static char *info[] = { N_("Left Side Bearing does not change."), N_("Advance Width does not change."), N_("Left Side Bearing does not change."), N_("ThisSpaceIntentionallyLeftBlank-PleaseDoNotTranslate-LeaveThisOut|"), N_("Top Bearing does not change.") }; static int CW_OK(GGadget *g, GEvent *e) { if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) { int err = false; CreateWidthDlg *wd = GDrawGetUserData(GGadgetGetWindow(g)); if ( GGadgetIsChecked(GWidgetGetControl(wd->gw,CID_Set)) ) { wd->wd.type = st_set; wd->wd.setto = GetReal8(wd->gw,CID_SetVal,rb1[wd->wd.wtype],&err); if ( wd->wd.setto<0 && wd->wd.wtype==wt_width ) { char *yesno[3]; yesno[0] = _("_Yes"); yesno[1] = _("_No"); yesno[2] = NULL; if ( gwwv_ask(_("Negative Width"), (const char **) yesno, 0, 1, _("Negative glyph widths are not allowed in TrueType\nDo you really want a negative width?") )==1 ) return( true ); } } else if ( GGadgetIsChecked(GWidgetGetControl(wd->gw,CID_Incr)) ) { wd->wd.type = st_incr; wd->wd.increment = GetReal8(wd->gw,CID_IncrVal,rb2[wd->wd.wtype],&err); } else { wd->wd.type = st_scale; wd->wd.scale = GetReal8(wd->gw,CID_ScaleVal,rb2[wd->wd.wtype],&err); } if ( err ) return(true); (wd->wd.doit)((CreateWidthData *) wd); } return( true ); } static int CW_Cancel(GGadget *g, GEvent *e) { if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) { CreateWidthDlg *wd = GDrawGetUserData(GGadgetGetWindow(g)); wd->wd.done = true; } return( true ); } static int CW_FocusChange(GGadget *g, GEvent *e) { if ( e->type==et_controlevent && e->u.control.subtype == et_textfocuschanged ) { CreateWidthDlg *wd = GDrawGetUserData(GGadgetGetWindow(g)); int cid = (intptr_t) GGadgetGetUserData(g); GGadgetSetChecked(GWidgetGetControl(wd->gw,cid),true); } return( true ); } static int CW_RadioChange(GGadget *g, GEvent *e) { if ( e->type==et_controlevent && e->u.control.subtype == et_radiochanged ) { CreateWidthDlg *wd = GDrawGetUserData(GGadgetGetWindow(g)); int cid = (intptr_t) GGadgetGetUserData(g); GWidgetIndicateFocusGadget(GWidgetGetControl(wd->gw,cid)); GTextFieldSelect(GWidgetGetControl(wd->gw,cid),0,-1); } return( true ); } static int cwd_e_h(GWindow gw, GEvent *event) { if ( event->type==et_close ) { CreateWidthDlg *wd = GDrawGetUserData(gw); wd->wd.done = true; } else if ( event->type == et_char ) { return( false ); } else if ( event->type == et_map ) { /* Above palettes */ GDrawRaise(gw); } return( true ); } static void FVCreateWidth( void *_fv,SplineChar* _sc,void (*doit)(CreateWidthData *), enum widthtype wtype, char *def) { GRect pos; GWindowAttrs wattrs; GGadgetCreateData gcd[11], boxes[2], topbox[2], *hvs[17], *varray[8], *buttons[6]; GTextInfo label[11]; static CreateWidthDlg cwd; static GWindow winds[5] = {NULL, NULL, NULL, NULL, NULL}; static char *title[] = { N_("Set Width..."), N_("Set LBearing..."), N_("Set RBearing..."), N_("Set Both Side Bearings..."), N_("Set Vertical Advance...") }; cwd.wd.done = false; cwd.wd._fv = _fv; cwd.wd._sc = _sc; cwd.wd.wtype = wtype; cwd.wd.doit = doit; cwd.gw = winds[wtype]; if ( cwd.gw==NULL ) { memset(&wattrs,0,sizeof(wattrs)); wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_isdlg|wam_restrict; wattrs.event_masks = ~(1<width ); else if ( wtype==wt_vwidth ) sprintf( buf, "%d", fv->show->pixelsize ); else { BDFCharFindBounds(bc,&bb); if ( wtype==wt_lbearing ) sprintf( buf, "%d", bb.minx ); else if ( wtype==wt_rbearing ) sprintf( buf, "%d", bc->width-bb.maxx-1 ); else sprintf( buf, "%d", (int) rint( (bc->width-bb.maxx-1 + bb.minx)/2 )); } } static void SCDefWidthVal(char buf[12],SplineChar *sc, enum widthtype wtype) { DBounds bb; if ( wtype==wt_width ) sprintf( buf, "%d", sc->width ); else if ( wtype==wt_vwidth ) sprintf( buf, "%d", sc->vwidth ); else { SplineCharFindBounds(sc,&bb); if ( wtype==wt_lbearing ) sprintf( buf, "%.4g", (double) bb.minx ); else if ( wtype==wt_rbearing ) sprintf( buf, "%.4g", sc->width-(double) bb.maxx ); else sprintf( buf, "%.4g", rint( (sc->width-(double) bb.maxx + (double) bb.minx)/2 ) ); } } void FVSetWidth(FontView *fv,enum widthtype wtype) { char buffer[12]; int em = fv->b.sf->ascent + fv->b.sf->descent; int i, gid; if ( !fv->b.sf->onlybitmaps || fv->b.sf->bitmaps==NULL ) { sprintf(buffer,"%d",wtype==wt_width?6*em/10:wtype==wt_vwidth?em: em/10 ); for ( i=0; ib.map->enccount; ++i ) if ( fv->b.selected[i] && (gid=fv->b.map->map[i])!=-1 && fv->b.sf->glyphs[gid]!=NULL ) { SCDefWidthVal(buffer,fv->b.sf->glyphs[gid],wtype); break; } } else { int size = fv->show->pixelsize; sprintf(buffer,"%d",wtype==wt_width?6*size/10:wtype==wt_vwidth?size: size/10 ); for ( i=0; ib.map->enccount; ++i ) if ( fv->b.selected[i] && (gid=fv->b.map->map[i])!=-1 && fv->show->glyphs[gid]!=NULL ) { BCDefWidthVal(buffer,fv->show->glyphs[gid],fv,wtype); break; } } FVCreateWidth(fv,0,FVDoit,wtype,buffer); } static void CVDoit(CreateWidthData *wd) { CharView *cv = (CharView *) (wd->_fv); DoChar(cv->b.sc,wd,(FontViewBase *) (cv->b.fv),NULL); wd->done = true; } void CVSetWidth(CharView *cv,enum widthtype wtype) { char buf[12]; SCDefWidthVal(buf,cv->b.sc,wtype); FVCreateWidth(cv,cv->b.sc,CVDoit,wtype,buf); } void GenericVSetWidth(FontView *fv,SplineChar* sc,enum widthtype wtype) { char buf[12]; SCDefWidthVal(buf,sc,wtype); FVCreateWidth(fv,sc,GenericVDoit,wtype,buf); }