/* Copyright (C) 2003-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 "edgelist.h" #include "effects.h" #include "fontforgeui.h" #include "gkeysym.h" #include "splinestroke.h" #include "splineutil2.h" #include "ustring.h" #include "utype.h" #include static void CVOutline(CharView *cv, real width) { StrokeInfo si; SplineSet *temp, *spl; int changed; InitializeStrokeInfo(&si); si.removeexternal = true; si.width = width*2; CVPreserveState((CharViewBase *) cv); temp = SplineSetStroke(cv->b.layerheads[cv->b.drawmode]->splines,&si,cv->b.layerheads[cv->b.drawmode]->order2); for ( spl=cv->b.layerheads[cv->b.drawmode]->splines; spl->next!=NULL; spl=spl->next ); spl->next = temp; SplineSetsCorrect(cv->b.layerheads[cv->b.drawmode]->splines,&changed); CVCharChangedUpdate(&cv->b); } static void MVOutline(MetricsView *mv, real width) { StrokeInfo si; SplineSet *temp, *spl; int i, changed; InitializeStrokeInfo(&si); si.removeexternal = true; si.width = width*2; for ( i=mv->glyphcnt-1; i>=0; --i ) if ( mv->perchar[i].selected ) break; if ( i!=-1 ) { SplineChar *sc = mv->glyphs[i].sc; SCPreserveLayer(sc,mv->layer,false); temp = SplineSetStroke(sc->layers[mv->layer].splines,&si,sc->layers[mv->layer].order2); for ( spl=sc->layers[mv->layer].splines; spl->next!=NULL; spl=spl->next ); spl->next = temp; SplineSetsCorrect(sc->layers[mv->layer].splines,&changed); SCCharChangedUpdate(sc,mv->layer); } } static void CVInline(CharView *cv, real width, real inset) { StrokeInfo si; SplineSet *temp, *spl, *temp2; int changed; InitializeStrokeInfo(&si); si.removeexternal = true; CVPreserveState((CharViewBase *) cv); si.width = width*2; temp = SplineSetStroke(cv->b.layerheads[cv->b.drawmode]->splines,&si,cv->b.layerheads[cv->b.drawmode]->order2); si.width = (width+inset)*2; temp2 = SplineSetStroke(cv->b.layerheads[cv->b.drawmode]->splines,&si,cv->b.layerheads[cv->b.drawmode]->order2); for ( spl=cv->b.layerheads[cv->b.drawmode]->splines; spl->next!=NULL; spl=spl->next ); spl->next = temp; for ( ; spl->next!=NULL; spl=spl->next ); spl->next = temp2; SplineSetsCorrect(cv->b.layerheads[cv->b.drawmode]->splines,&changed); CVCharChangedUpdate(&cv->b); } static void MVInline(MetricsView *mv, real width, real inset) { StrokeInfo si; SplineSet *temp, *spl, *temp2; int i, changed; InitializeStrokeInfo(&si); si.removeexternal = true; for ( i=mv->glyphcnt-1; i>=0; --i ) if ( mv->perchar[i].selected ) break; if ( i!=-1 ) { SplineChar *sc = mv->glyphs[i].sc; SCPreserveLayer(sc,mv->layer,false); si.width = width*2; temp = SplineSetStroke(sc->layers[mv->layer].splines,&si,sc->layers[mv->layer].order2); si.width = (width+inset)*2; temp2 = SplineSetStroke(sc->layers[mv->layer].splines,&si,sc->layers[mv->layer].order2); for ( spl=sc->layers[mv->layer].splines; spl->next!=NULL; spl=spl->next ); spl->next = temp; for ( ; spl->next!=NULL; spl=spl->next ); spl->next = temp2; SplineSetsCorrect(sc->layers[mv->layer].splines,&changed); SCCharChangedUpdate(sc,mv->layer); } } static double def_outline_width = 10, def_gap_width = 20; #define CID_Width 1000 #define CID_Gap 1001 typedef struct outlinedata { unsigned int done: 1; FontView *fv; CharView *cv; MetricsView *mv; int isinline; int wireframe; GWindow gw; } OutlineData; static int OD_OK(GGadget *g, GEvent *e) { if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) { OutlineData *od = GDrawGetUserData(GGadgetGetWindow(g)); real width, gap; int err = 0; width = GetReal8(od->gw,CID_Width,_("Outline Width"),&err); if ( od->isinline ) gap = GetReal8(od->gw,CID_Gap,_("_Gap:"),&err); if ( err ) return(true); def_outline_width = width; if ( od->isinline ) { def_gap_width = gap; if ( od->fv!=NULL ) FVInline((FontViewBase *) od->fv,width,gap); else if ( od->cv!=NULL ) CVInline(od->cv,width,gap); else if ( od->mv!=NULL ) MVInline(od->mv,width,gap); } else { if ( od->fv!=NULL ) FVOutline((FontViewBase *) od->fv,width); else if ( od->cv!=NULL ) CVOutline(od->cv,width); else if ( od->mv!=NULL ) MVOutline(od->mv,width); } od->done = true; } return( true ); } static int OD_Cancel(GGadget *g, GEvent *e) { if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) { OutlineData *od = GDrawGetUserData(GGadgetGetWindow(g)); od->done = true; } return( true ); } static int od_e_h(GWindow gw, GEvent *event) { if ( event->type==et_close ) { OutlineData *od = GDrawGetUserData(gw); od->done = true; } else if ( event->type == et_char ) { return( false ); } else if ( event->type == et_map ) { /* Above palettes */ GDrawRaise(gw); } return( true ); } void OutlineDlg(FontView *fv, CharView *cv,MetricsView *mv,int isinline) { GRect pos; GWindow gw; GWindowAttrs wattrs; GGadgetCreateData gcd[9], *harray[6], *butarray[7], *varray[7], boxes[4]; GTextInfo label[9]; OutlineData od; char buffer[20], buffer2[20]; int i,k; od.done = false; od.fv = fv; od.cv = cv; od.mv = mv; od.isinline = isinline; memset(&wattrs,0,sizeof(wattrs)); wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_isdlg|wam_restrict; wattrs.event_masks = ~(1<b.layerheads[cv->b.drawmode]->splines = SSShadow(cv->b.layerheads[cv->b.drawmode]->splines,angle,outline_width,shadow_length,cv->b.sc,wireframe); CVCharChangedUpdate(&cv->b); } static void MVShadow(MetricsView *mv,real angle, real outline_width, real shadow_length,int wireframe) { int i; for ( i=mv->glyphcnt-1; i>=0; --i ) if ( mv->perchar[i].selected ) break; if ( i!=-1 ) { SplineChar *sc = mv->glyphs[i].sc; SCPreserveLayer(sc,mv->layer,false); sc->layers[mv->layer].splines = SSShadow(sc->layers[mv->layer].splines,angle,outline_width,shadow_length,sc,wireframe); SCCharChangedUpdate(sc,mv->layer); } } static double def_shadow_len=100, def_sun_angle= -45; #define CID_ShadowLen 1001 #define CID_LightAngle 1002 static int SD_OK(GGadget *g, GEvent *e) { if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) { OutlineData *od = GDrawGetUserData(GGadgetGetWindow(g)); real width, angle, len; int err = 0; width = GetReal8(od->gw,CID_Width,_("Outline Width"),&err); len = GetReal8(od->gw,CID_ShadowLen,_("Shadow Length:"),&err); angle = GetReal8(od->gw,CID_LightAngle,_("Light Angle:"),&err); if ( err ) return(true); def_outline_width = width; def_shadow_len = len; def_sun_angle = angle; angle *= -FF_PI/180; angle -= FF_PI/2; if ( od->fv!=NULL ) FVShadow((FontViewBase *) od->fv,angle,width,len,od->wireframe); else if ( od->cv!=NULL ) CVShadow(od->cv,angle,width,len,od->wireframe); else if ( od->mv!=NULL ) MVShadow(od->mv,angle,width,len,od->wireframe); od->done = true; } return( true ); } void ShadowDlg(FontView *fv, CharView *cv,MetricsView *mv,int wireframe) { GRect pos; GWindow gw; GWindowAttrs wattrs; GGadgetCreateData gcd[10], *butarray[7], *hvarray[16], boxes[3]; GTextInfo label[10]; OutlineData od; char buffer[20], buffer2[20], buffer3[20]; int i, k; od.done = false; od.fv = fv; od.cv = cv; od.mv = mv; od.wireframe = wireframe; memset(&wattrs,0,sizeof(wattrs)); wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_isdlg|wam_restrict; wattrs.event_masks = ~(1<