/* Copyright (C) 2008-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 "cvundoes.h" #include "fontforgeui.h" #include "gkeysym.h" #include "glyphcomp.h" #include "splineutil.h" #include "ustring.h" enum l2l_type { l2l_copy, l2l_compare }; typedef struct l2ld { GWindow gw; SplineFont *sf; CharView *cv; FontView *fv; enum l2l_type l2l; int done; } L2LDlg; #define CID_FromLayer 1000 #define CID_ToLayer 1001 #define CID_ClearOld 1002 #define CID_ErrorBound 1003 static GTextInfo *SFLayerList(SplineFont *sf,int def_layer) { GTextInfo *ret = calloc(sf->layer_cnt+1,sizeof(GTextInfo)); int l; for ( l=0; llayer_cnt; ++l ) { ret[l].text = (unichar_t *) copy(sf->layers[l].name); ret[l].text_is_1byte = true; ret[l].userdata = (void *) (intptr_t) l; } ret[def_layer].selected = true; return( ret ); } static void _DoCVCopy(CharView *cv,int from,int to,int clear) { SCCopyLayerToLayer(cv->b.sc,from,to,clear); } static void RedoRefs(SplineFont *sf,SplineChar *sc,int layer) { RefChar *refs; sc->ticked2 = true; for ( refs=sc->layers[layer].refs; refs!=NULL; refs=refs->next ) { if ( refs->sc->ticked && !refs->sc->ticked2 ) RedoRefs(sf,refs->sc,layer); SCReinstanciateRefChar(sc,refs,layer); } } static void _DoFVCopy(FontView *fv,int from,int to,int clear) { SplineFont *sf = fv->b.sf; int gid, enc; SplineChar *sc; for ( gid=0; gidglyphcnt; ++gid ) if ( (sc = sf->glyphs[gid])!=NULL ) { sc->ticked = sc->ticked2 = false; } for ( enc=0 ; encb.map->enccount; ++enc ) { if ( fv->b.selected[enc] && (gid=fv->b.map->map[enc])!=-1 && (sc = sf->glyphs[gid])!=NULL && !sc->ticked ) { SCCopyLayerToLayer(sc,from,to,clear); sc->ticked = true; } } for ( gid=0; gidglyphcnt; ++gid ) if ( (sc = sf->glyphs[gid])!=NULL ) { if ( sc->ticked && !sc->ticked2 ) RedoRefs(sf,sc,to); } } static void _DoCVCompare(CharView *cv,int from,int to,double errbound) { if ( LayersSimilar(&cv->b.sc->layers[from],&cv->b.sc->layers[to],errbound)) ff_post_notice(_("Match"),_("No significant differences found")); else ff_post_notice(_("Differ"),_("The layers do not match")); } static void _DoFVCompare(FontView *fv,int from,int to,double errbound) { SplineFont *sf = fv->b.sf; int gid, enc; SplineChar *sc; int first=-1; memset(fv->b.selected,0,fv->b.map->enccount); for ( enc=0 ; encb.map->enccount; ++enc ) { if ( /*fv->b.selected[enc] &&*/ (gid=fv->b.map->map[enc])!=-1 && (sc = sf->glyphs[gid])!=NULL && !sc->ticked ) { if ( !LayersSimilar(&sc->layers[from],&sc->layers[to],errbound)) { fv->b.selected[enc] = true; if ( first==-1 ) first = enc; } } } GDrawRequestExpose(fv->v,NULL,true); if ( first==-1 ) ff_post_notice(_("Match"),_("No significant differences found")); else { ff_post_notice(_("Differ"),_("The layers do not match")); FVScrollToChar(fv,first); fv->end_pos = fv->pressed_pos = first; /*FVShowInfo(fv);*/ } } static int L2L_OK(GGadget *g, GEvent *e) { if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) { L2LDlg *d = GDrawGetUserData(GGadgetGetWindow(g)); int from, to, clear; int err=0; double errbound; from = GGadgetGetFirstListSelectedItem(GWidgetGetControl(d->gw,CID_FromLayer)); to = GGadgetGetFirstListSelectedItem(GWidgetGetControl(d->gw,CID_ToLayer)); if ( d->l2l==l2l_copy ) { clear = GGadgetIsChecked(GWidgetGetControl(d->gw,CID_ClearOld)); if ( d->cv ) _DoCVCopy(d->cv,from,to,clear); else _DoFVCopy(d->fv,from,to,clear); } else { errbound = GetReal8(d->gw,CID_ErrorBound,_("Error Bound"),&err); if ( err ) return( true ); if ( d->cv ) _DoCVCompare(d->cv,from,to,errbound); else _DoFVCompare(d->fv,from,to,errbound); } d->done = true; } return( true ); } static int L2L_Cancel(GGadget *g, GEvent *e) { if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) { L2LDlg *d = GDrawGetUserData(GGadgetGetWindow(g)); d->done = true; } return( true ); } static int l2l_e_h(GWindow gw, GEvent *event) { if ( event->type==et_close ) { L2LDlg *d = GDrawGetUserData(gw); d->done = true; } else if ( event->type == et_char ) { return( false ); } return( true ); } static void Layer2Layer(CharView *cv,FontView *fv,enum l2l_type l2l,int def_layer) { L2LDlg d; GRect pos; GWindow gw; GWindowAttrs wattrs; GGadgetCreateData gcd[17], *hvarray[34], *harray[5], *harray2[8], *hvarray2[7], boxes[7]; GTextInfo label[17]; int k,j; memset(&d,0,sizeof(d)); d.cv = cv; d.fv = fv; d.l2l = l2l; if ( cv!=NULL ) d.sf = cv->b.sc->parent; else d.sf = fv->b.sf; memset(&wattrs,0,sizeof(wattrs)); wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_isdlg|wam_restrict; wattrs.event_masks = ~(1<