/* Qxw is a program to help construct and publish crosswords. Copyright 2011-2020 Mark Owen; Windows port by Peter Flippant http://www.quinapalus.com E-mail: qxw@quinapalus.com This file is part of Qxw. Qxw is free software: you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. Qxw is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Qxw. If not, see or write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include #include #include #include #include #include #include #include #include #include #include "common.h" #include "qxw.h" #include "draw.h" #include "gui.h" #include "dicts.h" int bawdpx,hbawdpx; static int sfcxoff=0,sfcyoff=0; static double sdirdx[NGTYPE][MAXNDIR]={{1,0},{ 1.2,1.2,0 },{1.4,0.7,-0.7},{1,0},{1,0},{1,0},{1,0},{1,0},{1,0},{1,0},{1,0},{1,0},{1,0}}; static double sdirdy[NGTYPE][MAXNDIR]={{0,1},{-0.7,0.7,1.4},{0 ,1.2, 1.2},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1}}; char*dname[NGTYPE][MAXNDIR]={{"Across","Down"},{"Northeast","Southeast","South"},{"East","Southeast","Southwest"},{"Ring","Radial"},{"Ring","Radial"}, {"Across","Down"},{"Across","Down"},{"Across","Down"},{"Across","Down"},{"Across","Down"}, {"Across","Down"},{"Across","Down"},{"Across","Down"} }; double gscale=1; // global scaling for cairo operations // GERNERAL DRAWING void moveto(cairo_t*cc,double x,double y) {cairo_move_to(cc,x*gscale,y*gscale);} void lineto(cairo_t*cc,double x,double y) {cairo_line_to(cc,x*gscale,y*gscale);} void rmoveto(cairo_t*cc,double x,double y) {cairo_rel_move_to(cc,x*gscale,y*gscale);} void rlineto(cairo_t*cc,double x,double y) {cairo_rel_line_to(cc,x*gscale,y*gscale);} void setlinewidth(cairo_t*cc,double w) {cairo_set_line_width(cc,w*gscale);} void setlinecap(cairo_t*cc,int c) {cairo_set_line_cap(cc,c);} void closepath(cairo_t*cc) {cairo_close_path(cc);} void fill(cairo_t*cc) {cairo_fill(cc);} void stroke(cairo_t*cc) {cairo_stroke(cc);} void strokepreserve(cairo_t*cc) {cairo_stroke_preserve(cc);} void clip(cairo_t*cc) {cairo_clip(cc);} void gsave(cairo_t*cc) {cairo_save(cc);} void grestore(cairo_t*cc) {cairo_restore(cc);} void setrgbcolor(cairo_t*cc,double r,double g, double b) {cairo_set_source_rgb(cc,r,g,b);} void setrgbacolor(cairo_t*cc,double r,double g, double b,double a) {cairo_set_source_rgba(cc,r,g,b,a);} static PangoLayout*playout; static PangoFontDescription*fdesc; static double bheight; void settext(cairo_t*cc,char*s,double h,int fs) { static cairo_t*occ=0; static int ofs=-1; static double oh=-1; h*=gscale; if(cc!=occ) { if(playout) g_object_unref(playout); playout=pango_cairo_create_layout(cc); occ=cc; ofs=-1; oh=-1; } DEB_RF printf("settext(%s,%g,%d)\n",s,h,fs); if(!fdesc) fdesc=pango_font_description_from_string("Sans"); if(h!=oh) { pango_font_description_set_absolute_size(fdesc,(int)(h*PANGO_SCALE+.5)); pango_layout_set_font_description(playout,fdesc); oh=h; } if(fs!=ofs) { pango_font_description_set_weight(fdesc,(fs&1)?PANGO_WEIGHT_BOLD :PANGO_WEIGHT_NORMAL); pango_font_description_set_style (fdesc,(fs&2)?PANGO_STYLE_ITALIC:PANGO_STYLE_NORMAL); pango_layout_set_font_description(playout,fdesc); ofs=fs; } pango_layout_set_text(playout,s,-1); pango_cairo_update_layout(cc,playout); bheight=(double)pango_layout_get_baseline(playout)/PANGO_SCALE/gscale; } void showtext(cairo_t*cc) { rmoveto(cc,0,-bheight); pango_cairo_show_layout(cc,playout); } double textwidth(cairo_t*cc) { int x,y; // PangoRectangle ir,lr; pango_layout_get_size(playout,&x,&y); // seems that this doesn't work rounds to multiples of 1024=PANGO_SCALE in some versions of Pango; hence need for gscale everywhere DEB_RF printf(" (x=%d y=%d)\n",x,y); // pango_layout_get_extents(playout,&ir,&lr); //DEB_RF printf(" (PANGO_SCALE=%d ir=[%d %d %d %d] lr=[%d %d %d %d])\n",PANGO_SCALE, ir.x,ir.y,ir.width,ir.height, lr.x,lr.y,lr.width,lr.height ); return (double)x/PANGO_SCALE/gscale; // return (double)ir.width/PANGO_SCALE/gscale; } void ltext(cairo_t*cc,char*s,double h,int fs) { moveto(cc,0,0); settext(cc,s,h,fs); showtext(cc); } // Centered text. If ocm==0, print normally spaced; if ocm==1, print one character at a time, regularly spaced void ctext(cairo_t*cc,char*s,double x,double y,double h,int fs,int ocm) { int i,l,m; char*p,t[SLEN+1]; double u; DEB_RF printf("ctext(..,<%s>,x=%f,y=%f,h=%f,fs=%d,ocm=%d)\n",s,x,y,h,fs,ocm); if(!ocm) { settext(cc,s,h,fs); u=x-textwidth(cc)/2.0; DEB_RF printf(" tw=%f,u=%f\n",textwidth(cc),u); moveto(cc,u,y); showtext(cc); return; } for(l=0,p=s;*p;l++) { m=q_mblen(p); if(m<1) break; p+=m; } for(i=0,p=s;*p;i++) { m=q_mblen(p); if(m<1) return; strncpy(t,p,m); t[m]=0; settext(cc,t,h,fs); u=x-textwidth(cc)/2.0+(i+i+1-l)*h*.4; moveto(cc,u,y); showtext(cc); p+=m; } } // Cairo's arc drawing does not seem to work well as part of a path, so we do our own void arc(cairo_t*cc,double x,double y,double r,double t0,double t1) {double u; if(t11.0/pxsq) { // error of approx 1/4 px? u=(t0+t1)/2; arc(cc,x,y,r,t0,u); arc(cc,x,y,r, u,t1); } else lineto(cc,x+r*cos(t1),y+r*sin(t1)); } void arcn(cairo_t*cc,double x,double y,double r,double t0,double t1) {double u; if(t01.0/pxsq) { // error of approx 1/4 px? u=(t0+t1)/2; arcn(cc,x,y,r,t0,u); arcn(cc,x,y,r, u,t1); } else lineto(cc,x+r*cos(t1),y+r*sin(t1)); } static void setrgbcolor24(cairo_t*cc,int c) {setrgbcolor(cc,((c>>16)&255)/255.0,((c>>8)&255)/255.0,(c&255)/255.0);} static void setrgbcolor24a(cairo_t*cc,int c,double a) {setrgbacolor(cc,((c>>16)&255)/255.0,((c>>8)&255)/255.0,(c&255)/255.0,a);} // GRID GEOMETRY static void vxcoords(double*x0,double*y0,double x,double y,int d) {double t; switch(gshape[gtype]) { case 0: *x0=x; *y0=y; switch(d) { case 3: break; case 0:*x0+=1.0; break; case 1:*x0+=1.0;*y0+=1.0;break; case 2: *y0+=1.0;break; default:assert(0);break; } break; case 1: *x0=x*1.2+.4; *y0=y*1.4+((int)floor(x)&1)*.7; switch(d) { case 5: break; case 0:*x0+=0.8; break; case 1:*x0+=1.2;*y0+=0.7;break; case 2:*x0+=0.8;*y0+=1.4;break; case 3: *y0+=1.4;break; case 4:*x0-=0.4;*y0+=0.7;break; default:assert(0);break; } break; case 2: *y0=y*1.2+.4; *x0=x*1.4+((int)floor(y)&1)*.7; switch(d) { case 4: break; case 3:*y0+=0.8; break; case 2:*y0+=1.2;*x0+=0.7;break; case 1:*y0+=0.8;*x0+=1.4;break; case 0: *x0+=1.4;break; case 5:*y0-=0.4;*x0+=0.7;break; default:assert(0);break; } break; case 3:case 4: switch(d) { case 3: break; case 0:x+=1.0; break; case 1:x+=1.0;y+=1.0;break; case 2: y+=1.0;break; } t=2*PI*((gshape[gtype]==4)?x-0.5:x)/width; *x0= (height-y)*sin(t)+height; *y0=-(height-y)*cos(t)+height; break; } } void edgecoords(double*x0,double*y0,double*x1,double*y1,int x,int y,int d) { vxcoords(x0,y0,(double)x,(double)y,d); vxcoords(x1,y1,(double)x,(double)y,(d+1)%(ndir[gtype]*2)); } // find centre coordinates for merge group containing x,y void mgcentre(double*u,double*v,int x,int y,int d,int l) { double x0=0,y0=0,x1=0,y1=0; if(gshape[gtype]==3||gshape[gtype]==4) { if(EVEN(d)) vxcoords(u,v,x+l/2.0,y+0.5,3); else vxcoords(u,v,x+0.5,y+l/2.0,3); return; } if(gtype>4) { // we are on a square-format grid but there is potential for wrap-around while(l>2) stepforw(&x,&y,d),l-=2; if((d==0&&x==width -1)||(d==1&&y==height-1)) l=1; } vxcoords(&x0,&y0,(double)x,(double)y,0); vxcoords(&x1,&y1,(double)x,(double)y,ndir[gtype]); *u=(x0+x1)/2+sdirdx[gtype][d]*(l-1)/2.0; *v=(y0+y1)/2+sdirdy[gtype][d]*(l-1)/2.0; } static void addvxcoordsbbox(double*x0,double*y0,double*x1,double*y1,double x,double y,int d) {double vx=0,vy=0; vxcoords(&vx,&vy,x,y,d); if(vx<*x0) *x0=vx; if(vx>*x1) *x1=vx; if(vy<*y0) *y0=vy; if(vy>*y1) *y1=vy; } static void addsqbbox(double*x0,double*y0,double*x1,double*y1,int x,int y) {int d; double vx=0,vy=0; mgcentre(&vx,&vy,x,y,0,1); if(vx-0.5<*x0) *x0=vx-0.5; // include a 1x1 square centred in the middle of the merge group for the letter if(vx+0.5>*x1) *x1=vx+0.5; if(vy-0.5<*y0) *y0=vy-0.5; if(vy+0.5>*y1) *y1=vy+0.5; for(d=0;d1) s=1; return s; } static void movetoorig(cairo_t*cc,int x,int y) {double x0=0,y0=0; switch(gshape[gtype]) { case 0: vxcoords(&x0,&y0,(double)x,(double)y,3);break; case 1: vxcoords(&x0,&y0,(double)x,(double)y,5);break; case 2: vxcoords(&x0,&y0,(double)x,(double)y,4);break; case 3:case 4: vxcoords(&x0,&y0,(double)x,(double)y,1); break; } moveto(cc,x0,y0); } static void movetomgcentre(cairo_t*cc,int x,int y,int d,int l) {double u=0,v=0; mgcentre(&u,&v,x,y,d,l); moveto(cc,u,v); } // draw path for edges with bits set in mask b static void edges(cairo_t*cc,int x,int y,int b) {int f,g,i,j,n,o;double x0=0,y0=0,x1=0,y1=0,t; n=ndir[gtype]*2; b&=(1<>o)&1)==0) break; // find a place to start drawing f=0;g=0; for(i=0;i>j)&1) { edgecoords(&x0,&y0,&x1,&y1,x,y,j); if(f==0) moveto(cc,x0,y0); if((gshape[gtype]==3||gshape[gtype]==4)) { if(j&1) { t=2*PI*((gshape[gtype]==4)?x-0.5:x)/width-PI/2; if(j==1) arcn(cc,(double)height,(double)height,height-y-.999, t+2*PI/width,t); else arc (cc,(double)height,(double)height,height-y ,t,t+2*PI/width); } else lineto(cc,x1,y1); } else { // the following is to defeat this bug: // https://bugs.freedesktop.org/show_bug.cgi?id=39551 lineto(cc,(x0+x1)/2,(y0+y1)/2); moveto(cc,(x0+x1)/2,(y0+y1)/2); lineto(cc,x1,y1); } f=1; } else f=0,g=1; } if(g==0) closepath(cc); } // draw path for outline of a `square' static void sqpath(cairo_t*cc,int x,int y) {int i;double x0=0,y0=0,t; vxcoords(&x0,&y0,(double)x,(double)y,0); moveto(cc,x0,y0); switch(gshape[gtype]) { case 0: case 1: case 2: for(i=1;igx1) gx1=sx1; if(sy1>gy1) gy1=sy1; sfq[x][y]=cairo_image_surface_create(CAIRO_FORMAT_ARGB32,sx1-sx0,sy1-sy0); } DEB_RF printf("Overall bbox = (%d,%d)-(%d,%d)\n",gx0,gy0,gx1,gy1); sfb=cairo_image_surface_create(CAIRO_FORMAT_ARGB32,gx1,gy1); // take top left as (0,0) sfc=cairo_image_surface_create(CAIRO_FORMAT_ARGB32,pxsq,pxsq); sfs=cairo_image_surface_create(CAIRO_FORMAT_ARGB32,gx1+hbawdpx-1,gy1+hbawdpx-1); sfh=cairo_image_surface_create(CAIRO_FORMAT_ARGB32,gx1,gy1); sfn=cairo_image_surface_create(CAIRO_FORMAT_ARGB32,gx1,gy1); } // Refresh drawing area: called here with clip already set on cr, so we can // just repaint everything. void repaint(cairo_t*cc) {int i,j; assert(sfb); cairo_set_source_surface(cc,sfb,bawdpx,bawdpx); // paint background cairo_paint(cc); cairo_set_source_surface(cc,sfc,sfcxoff,sfcyoff); // paint cursor cairo_paint(cc); cairo_set_source_surface(cc,sfh,bawdpx,bawdpx); // paint hints cairo_paint(cc); for(j=0;jctlen[i]>l) l=sq->ctlen[i]; // find longest contents string h=0.7/nd; if(h>1.0/l) h=1.0/l; for(i=0;ictbm[i],sq->ctlen[i]); if(dots) for(j=0;s[j];j++) if(s[j]==' ') s[j]='.'; ctext(cc,s,u,v+((i-(nd-1.0)/2.0)*h+0.42*h)*sc,h*sc,getfstyle(xr,yr),ocm); } } else { s[0]=0; l=0; for(i=0;ictlen[i]; // total content length for(i=0;ictbm[i],sq->ctlen[i]); // printf("drawct: %016llx >%s< l=%d\n",sq->ctbm[0][0],s,l); if(dots&&l>1) for(i=0;s[i];i++) if(s[i]==' ') s[i]='.'; h=0.7; if(l>1) h=1.0/l; ctext(cc,s,u,v+0.42*h*sc,h*sc,getfstyle(xr,yr),ocm); } } // draw bars and edges // lf=1 draw entered letter also // ocm flag passed on to ctext static void drawsqfg(cairo_t*cc,int x,int y,int sq,int ba,int lf,int ocm,double textscale) { int b,d,f,m,xr,yr; // edges and bars b=0; for(d=0;d=2); tl=getmergegroupd(0,0,lx[0],ly[0],d); movetomgcentre(cc,lx[0],ly[0],d,tl); mgcentre(&u,&v,lx[0],ly[0],d,tl); for(k=1;k=5) { // potential for wrap-around? if(d==0&&(lx[k]=100 int i,j,l,md,nc,pd[MXSZ][MXSZ],vis[MXSZ][MXSZ],x,y,x0,y0; double sc[MXCL],u,v,xc[MXCL],yc[MXCL]; setlinecap(cc,1); memset(vis,0,sizeof(vis)); for(i=0;i=ndir[gtype]) refreshsel2(cc); cairo_destroy(cc); invaldaall(); gscale=1; } void refreshcur() { double sc,c=0,s=0,u,v; int m,x,y; char t[20]; static int ocx=0,ocy=0; cairo_t*cc; cc=cairo_create(sfc); setrgbacolor(cc,0.0,0.0,0.0,0.0); cairo_set_operator(cc,CAIRO_OPERATOR_SOURCE); cairo_paint(cc); cairo_set_operator(cc,CAIRO_OPERATOR_OVER); sc=getscale(curx,cury,0,1)*pxsq; gscale=1; setrgbacolor(cc,0.6,0.6,0.6,0.8); setlinewidth(cc,2); if(curdir1) { curmux=curmux%m; sprintf(t,"%d",curmux+1); setrgbacolor(cc,0.0,1.0,0.0,1.0); ctext(cc,t,pxsq*0.5,pxsq*0.3,pxsq*0.35,0,0); setrgbacolor(cc,0.6,0.6,0.6,0.8); } } } else { // moveto(cc,pxsq/2+sc/4,pxsq/2); // circle in VL mode // arc(cc,pxsq/2,pxsq/2,sc/4,0,2*PI); // closepath(cc); // fill(cc); } mgcentre(&u,&v,curx,cury,0,1); x=(int)floor(u*pxsq+0.5); y=(int)floor(v*pxsq+0.5); sfcxoff=x-pxsq/2+bawdpx; sfcyoff=y-pxsq/2+bawdpx; invaldarect(sfcxoff,sfcyoff,sfcxoff+pxsq,sfcyoff+pxsq); mgcentre(&u,&v,ocx,ocy,0,1); x=(int)floor(u*pxsq+0.5); y=(int)floor(v*pxsq+0.5); invaldarect(x-pxsq/2+bawdpx,y-pxsq/2+bawdpx,x+pxsq/2+bawdpx,y+pxsq/2+bawdpx); ocx=curx;ocy=cury; cairo_destroy(cc); gscale=1; } static int ismkcirc(int x,int y,int c) {char s[MXMK+1]; getmk(s,x,y,c); return !STRCASECMP(s,"\\o"); } static int isanymkcirc(int x,int y) {int c; for(c=0;c=MAXICC) strcpy(s,"-"); else sprintf(s,"%d",cwperm[i]); } else if(!STRCASECMP(s,"\\#")) { if(f==0) return ""; n=getnumber(x,y); if(n<=0) return ""; sprintf(s,"%d",n); } else if(!STRCASECMP(s,"\\i")) { if(nvl<1) return ""; for(i0=-1,i=0;iflbm; // not already entered? show hints } setrgbcolor(cc,0.75,0.75,0.75); drawct(cc,x,y,&sq,1,1,1.0); } else if(c<0) { // normally checked one-character cell with none/more than one bit set in bitmap if(gsq[x][y].ents[0][0]!=0) m=gsq[x][y].ents[0][0]->flbm; else m=0; k=cbits(m); // any info from filler? if(k==0) strcpy(s,"?"); // no feasible letters else if(k==1) strcpy(s,icctoutf8[abmtoicc(m)]); // unique feasible letter else strcpy(s," "); setrgbcolor(cc,0.75,0.75,0.75); mgcentre(&u,&v,x,y,md,l); ctext(cc,s,u,v+0.3*sc,.7*sc,getfstyle(x,y),1); if(k>1&&k"); if(fs&2) fprintf(fp,""); xmlesc(fp,s); if(fs&2) fprintf(fp,""); if(fs&1) fprintf(fp,""); } // convert light/answer to string form for display void ansform(char*t0,int t0l,int ln,int wlen,unsigned int dmask) { struct answer*a; int em,f,i; em=lts[ln].em; t0[0]=0; if(em>0&&em<4) { // special entry method (but not jumble)? give grid form too for(i=0;lts[ln].s[i];i++) strcat(t0,icctoutf8[(int)lts[ln].s[i]]); strcat(t0,": "); } DEB_EX printf("ansform: t0=<%s> ln=%d dmask=0x%08x\n",t0,ln,dmask); if(lts[ln].ans<0) return; // negative ans values should not occur here a=ansp[lts[ln].ans]; f=0; for(;a;a=a->acf) { DEB_EX printf(" a=%p cfdmask=%08x cf=<%s> acf=%p t0=<%s>\n",(void*)a,a->cfdmask,a->cf,(void*)a->acf,t0); if(a->cfdmask&dmask) { if((int)strlen(t0)+(int)strlen(a->cf)+2>t0l-LEMDESCLEN-10) {strcat(t0,"...");break;} if(f) strcat(t0,", "); strcat(t0,a->cf); f++; DEB_EX printf(" t0=<%s>\n",t0); } } if(em>0) strcat(t0,lemdesc[lts[ln].em]); DEB_EX printf(" done: acf=%p t0=<%s>\n",(void*)a->acf,t0); } // Output answers in direction dir; if dir==-1 do VL:s // html=0: plain text // html=1: block HTML with enumeration // html=2: block HTML // html=3: table HTML // html=4: CCW XML words // html=5: CCW XML clues // cf=1: word lists are valid, can be used for citation forms // wordid: pointer to wordid counter, used for CCW XML output static void panswers(FILE*fp,int dir,int html,int cf,int*wordid) { int d,f,i,j,k,ll,m,m0,m1,n,vlf; char s[SLEN]; char t[MXLE*16+1]; char t0[MXFL*10+100]; struct word*w; vlf=(dir==-1); // doing virtual lights? for(j=0;j<(vlf?1:height);j++) for(i=0;i<(vlf?1:width);i++) for(d=vlf?100:dir;d<(vlf?100+nvl:(dir+1));d++) { // loop over all possible answers if(!vlf&&!isstartoflight(i,j,d)) continue; if(ismux(i,j,d)) {m0=0;m1=getmaxmux(i,j,d);} else {m0=-1;m1=0;} for(m=m0;m0) sprintf(s,"%d",n); else strcpy(s,"-"); // unnumbered light if (html==0) fprintf(fp,"%s ",s); else if(html==1) fprintf(fp,"%s ",s); else if(html==2) fprintf(fp,"%s ",s); else if(html==3) fprintf(fp,"%s\n",s); else if(html==4) { if(dir==0) fprintf(fp,"\n",*wordid,i+1,i+ll,j+1); if(dir==1) fprintf(fp,"\n",*wordid,i+1,j+1,j+ll); } else if(html==5) fprintf(fp,"",*wordid,s,ll); if(html!=4) { if(f) { if(vlf) w=vls[d-100].w; else w=gsq[i][j].w[d][(m<0)?0:m]; } else w=0; if(w&&w->flistlen>0) { for(k=0;kflistlen;k++) { if(k>0) fprintf(fp,"; "); ansform(t0,sizeof(t0),w->flist[k],w->wlen,w->lp->dmask); if(html==0) fprintf(fp,"%s",t0); else xmlesc(fp,t0); } } else xmlesc(fp,t); } if (html==0) fprintf(fp," (%d)\n",ll); else if(html==1) fprintf(fp," (%d)
\n",ll); else if(html==2) fprintf(fp,"\n"); else if(html==3) fprintf(fp," (%d)\n",ll); // answer and length else if(html==5) fprintf(fp,"
\n"); if(wordid) (*wordid)++; } } } // HTML export // f b0: include grid // f b1: include answers in grid // f b2: include numbers in grid // f b3: include answers in table (to be edited into clues) // f b4: include answers in compact format // f b5: include link to grid image (given URL) // Thanks to Paul Boorer for CSS suggestions void a_exportgh(int f,char*url) { int c,cf,d,fl,i,j,i0,j0,k,l,md,u,v,x,y,bg,fg,mk,fs,fh; int de,nd; int hbawd; double textscale; FILE*fp; textscale=((f&6)==6)?0.8:1; // smaller text if we are doing numbers and entries hbawd=hpxsq/8; // a suitable bar width if(hbawd<3) hbawd=3; hbawd|=1; // ensure it is odd DEB_EX printf("export HTML %s\n",filename); fp=q_fopen(filename,"w"); if(!fp) {fserror();return;} cf=!preexport(); // emit header and CSS fprintf(fp, "\n" "\n" "\n" "\n" "",RELEASE); xmlesc(fp,titlebyauthor()); fprintf(fp,"\n"); fprintf(fp,"\n"); if(f&1) { // need the styles for the grid fprintf(fp,"\n"); } fprintf(fp,"\n\n\n"); if(f&1) { fprintf(fp,"
\n"); fprintf(fp,"
\n",width*hpxsq+1,height*hpxsq+1); fprintf(fp,"
\n",width*hpxsq+1,height*hpxsq+1); for(j=0;j
\n",i*hpxsq+1,j*hpxsq+1);continue;} fprintf(fp,"
\n",i*hpxsq+1,j*hpxsq+1,bg,hpxsq); } for(j=0;j
\n",(i+1)*hpxsq-hbawd/2,j*hpxsq); else fprintf(fp,"
\n",(i+1)*hpxsq-hbawd/2,j*hpxsq); } if(isbar(i,j,1)) { if(isbar(i,j,2)) fprintf(fp,"
\n",i*hpxsq-hbawd/2,(j+1)*hpxsq-hbawd/2); else fprintf(fp,"
\n",i*hpxsq,(j+1)*hpxsq-hbawd/2); } if(isbar(i,j,2)) { if(isbar(i,j,3)) fprintf(fp,"
\n",i*hpxsq-hbawd/2,j*hpxsq-hbawd/2); else fprintf(fp,"
\n",i*hpxsq-hbawd/2,j*hpxsq); } if(isbar(i,j,3)) { if(isbar(i,j,0)) fprintf(fp,"
\n",i*hpxsq,j*hpxsq-hbawd/2); else fprintf(fp,"
\n",i*hpxsq,j*hpxsq-hbawd/2); } for(c=0;c<4;c++) { char*p; p=getmktext(i,j,c,!!(f&4)); // pass number-enable flag if(!strcmp(p,"")) continue; mk=getmkcol(i,j); switch(c) { case 0: fprintf(fp,"
",i*hpxsq+4,j*hpxsq+1 ,mk); xmlesc(fp,p); fprintf(fp,"
\n"); break; case 1: fprintf(fp,"
",i*hpxsq+1,j*hpxsq+1 ,mk); xmlesc(fp,p); fprintf(fp,"
\n"); break; case 2: fprintf(fp,"
",i*hpxsq+1,j*hpxsq+hpxsq*2/3-4,mk); xmlesc(fp,p); fprintf(fp,"
\n"); break; case 3: fprintf(fp,"
",i*hpxsq+4,j*hpxsq+hpxsq*2/3-4,mk); xmlesc(fp,p); fprintf(fp,"
\n"); break; } } } for(j=0;j2) stepforw(&i0,&j0,md),l-=2; if((md==0&&i0==width-1)||(md==1&&j0==height-1)) l=1; x=((i0*2+(md==0)*(l-1))*hpxsq)/2+1; y=((j0*2+(md==1)*(l-1))*hpxsq)/2+hpxsq/2; de=getdech(i,j); nd=ndir[gtype]; if(de==0) nd=1,de=1; if(de==2) { l=3; for(k=0;kl) l=gsq[i][j].ctlen[k]; // find longest fh=(int)floor(hpxsq*textscale/l+.5); abmstodispstr(s,gsq[i][j].ctbm[0],gsq[i][j].ctlen[0]); fprintf(fp,"
",x,y-fh,fg,fh); xmlescfs(fp,s,fs); fprintf(fp,"
\n"); abmstodispstr(s,gsq[i][j].ctbm[1],gsq[i][j].ctlen[1]); fprintf(fp,"
",x,y,fg,fh); xmlescfs(fp,s,fs); fprintf(fp,"
\n"); } else { s[0]=0; for(k=0,l=0;k",x,y-fh/2,fg,fh); xmlescfs(fp,s,fs); fprintf(fp,"\n"); } } } for(j=0;j<=height;j++) for(i=0,v=0;i<=width;i++) { if(j==0) u=!ismerge(i,j ,3); else u=!ismerge(i,j-1,1); u&=sqexists(i,j)|sqexists(i,j-1); if(u==0&&v>0) fprintf(fp,"
\n",(i-v)*hpxsq,j*hpxsq,v*hpxsq+1); if(u==0) v=0; else v++; } for(i=0;i<=width;i++) for(j=0,v=0;j<=height;j++) { if(i==0) u=!ismerge(i ,j,2); else u=!ismerge(i-1,j,0); u&=sqexists(i,j)|sqexists(i-1,j); if(u==0&&v>0) fprintf(fp,"
\n",i*hpxsq,(j-v)*hpxsq,v*hpxsq+1); if(u==0) v=0; else v++; } fprintf(fp,"
\n"); } if(f&0x20) { fprintf(fp,"
\n"); fprintf(fp,"\"grid\n",url); fprintf(fp,"
\n"); } if(f&8) { // print table of `clues' fprintf(fp,"
\n"); for(d=0;d%s\n",96/ndir[gtype],dname[gtype][d]); if(d \n"); } fprintf(fp,"\n"); for(d=0;d
\n"); panswers(fp,d,3,cf,0); fprintf(fp,"
\n"); if(d \n"); } fprintf(fp,"\n"); if(nvl>0) { fprintf(fp,"Other\n",ndir[gtype]*2-1); fprintf(fp,"\n",ndir[gtype]*2-1); panswers(fp,-1,2,cf,0); fprintf(fp,"
\n"); } fprintf(fp,"
\n"); } if(f&16) { // print answers in condensed form for(d=0;d%s:\n",dname[gtype][d]); panswers(fp,d,2,cf,0); fprintf(fp,"
\n"); } if(nvl>0) { fprintf(fp,"Other:\n"); panswers(fp,-1,2,cf,0); fprintf(fp,"
\n"); } } fprintf(fp,"\n"); if(ferror(fp)) fserror(); if(fclose(fp)) fserror(); postexport(); } // GRID AS EPS OR PNG static cairo_status_t filewrite(FILE*fp,unsigned char*p,unsigned int n) { return (fwrite(p,1,n,fp)==n)?CAIRO_STATUS_SUCCESS:CAIRO_STATUS_WRITE_ERROR; } // f0 b1: include answers in grid // f0 b2: include numbers and marks in grid // f1: 0=EPS 1=SVG 2=PNG void a_exportg(char*fn,int f0,int f1) { cairo_surface_t*sf=0; cairo_t*cc; int i,j,sq=0,ba,px,py; char s[1000]; double textscale; FILE*fp=0; DEB_EX printf("a_exportg(\"%s\",%d,%d)\n",fn,f0,f1); switch(f1) { case 0: sq=eptsq; break; case 1: sq=eptsq; break; case 2: sq=hpxsq; break; } textscale=((f0&6)==6)?0.8:1; // smaller text if we are doing numbers and entries ba=sq/8; // a suitable bar width if(ba<2) ba=2; px=gwidth(sq,ba); py=gheight(sq,ba); switch(f1) { case 0: fp=q_fopen(fn,"w"); if(!fp) {fserror();return;} sf=cairo_ps_surface_create_for_stream((cairo_write_func_t)filewrite,fp,px,py); cairo_ps_surface_restrict_to_level(sf,CAIRO_PS_LEVEL_2); cairo_ps_surface_set_eps(sf,1); sprintf(s,"%%%%Title: %s generated by Qxw",fn); cairo_ps_surface_dsc_comment(sf,s); break; case 1: fp=q_fopen(fn,"w"); if(!fp) {fserror();return;} sf=cairo_svg_surface_create_for_stream((cairo_write_func_t)filewrite,fp,px,py); cairo_svg_surface_restrict_to_version(sf,CAIRO_SVG_VERSION_1_1); break; case 2: sf=cairo_image_surface_create(CAIRO_FORMAT_ARGB32,px,py); break; } cc=cairo_create(sf); if(f1==2) { cairo_set_source_rgb(cc,1,1,1); // flood PNG to white to avoid nasty transparency effect in merged cells cairo_paint(cc); } cairo_translate(cc,ba-.5,ba-.5); gscale=sq; for(j=0;j\n"); fprintf(fp,"\n"); fprintf(fp,"\n\n\n\n",RELEASE); } for(d=0;d%s
\n\n",dname[gtype][d]); else fprintf(fp,"\n%s\n\n",dname[gtype][d]); panswers(fp,d,f,cf,0); } if(nvl>0) { if(f) fprintf(fp,"\nOther
\n\n"); else fprintf(fp,"\nOther\n\n"); panswers(fp,-1,f,cf,0); } if(f) fprintf(fp,"\n"); if(ferror(fp)) fserror(); if(fclose(fp)) fserror(); postexport(); } // COMBINED HTML AND PNG // f: 0=puzzle, 1=solution // f0: f0 flags for exportg // f1: 1=SVG, 2=PNG void a_exporthp(int f,int f0,int f1) { char url[SLEN+200]; char*base; strcpy(url,filename); strcat(url,"_files"); g_mkdir(url,0777); base=g_path_get_basename(url); strcat(url,f?"/solution":"/grid"); strcat(url,f1==1?".svg":".png"); a_exportg(url,f0,f1); // write out the image strcpy(url,base); strcat(url,f?"/solution":"/grid"); strcat(url,f1==1?".svg":".png"); a_exportgh(f?0x30:0x28,url); // write out the HTML with a link to the image g_free(base); } // Crossword Compiler XML // only the most basic of Qxw's features are represented in this export format void a_exportccwxml(char*fn) { FILE*fp; int cf,d,fl,i,j,n,wordid; if(gshape[gtype]!=0) { // check for basic limitations reperr("Cannot export non-rectangular grids\nto Crossword Compiler XML"); return; } for(j=0;j\n"); fprintf(fp,"\n"); fprintf(fp,"\n\n"); fprintf(fp,"\n"); fprintf(fp,""); xmlesc(fp,gtitle); fprintf(fp,"\n"); fprintf(fp,""); xmlesc(fp,gauthor); fprintf(fp,"\n"); fprintf(fp,"Qxw %s http://www.quinapalus.com\n",RELEASE); fprintf(fp,"\n"); fprintf(fp,"\n"); fprintf(fp,"\n\n"); fprintf(fp,"\n\n"); fprintf(fp,"\n",width,height); fprintf(fp,"\n",hpxsq); for(j=0;j>1)&0x7f7f7f)|0x808080)); else fprintf(fp," background-color=\"#%06X\"", getbgcol(i,j)); if(gsq[i][j].ctlen[0]==1&&onebit(gsq[i][j].ctbm[0][0])) { // only one character allowed fprintf(fp," solution=\""); xmlesc(fp,icctoutf8[abmtoicc(gsq[i][j].ctbm[0][0])]); fprintf(fp,"\""); } n=getnumber(i,j); if(n>0) fprintf(fp," number=\"%d\"",n); if(isbar(i,j,2)) fprintf(fp," left-bar=\"true\""); if(isbar(i,j,3)) fprintf(fp," top-bar=\"true\""); ew0: fprintf(fp,">\n"); } fprintf(fp,"\n\n"); wordid=1; panswers(fp,0,4,cf,&wordid); panswers(fp,1,4,cf,&wordid); wordid=1; for(d=0;d<2;d++) { fprintf(fp,"<b>%s</b>\n",dname[gtype][d]); panswers(fp,d,5,cf,&wordid); fprintf(fp,"\n"); } fprintf(fp,"\n\n"); fprintf(fp,"\n"); fprintf(fp,"\n"); if(ferror(fp)) fserror(); if(fclose(fp)) fserror(); postexport(); }