draw10.c
0000/******************************************
0001 libart
0002******************************************/
0003#include <stdlib.h>
0004#include <string.h>
0005#include "draw6.h"
0006#include "draw7.h"
0007#include "draw8.h"
0008#include "draw10.h"
0009
0010#include <stdio.h>
0011#include <libart_lgpl/libart.h>
0012
0013/* externals to be declared and initialized in the function programs */
0014extern ArtVpath* vpath[20];
0015extern int vused[20];
0016extern int currpath;
0017extern ArtBpath* bpath;
0018extern int currbp,bpmax;
0019
0020double linewidth=1.;
0021int linedraw=0,linedash=0,linejoin=0,linecap=0;
0022int AFreePath(int id);
0023
0024/**
0025int arttest()
0026{
0027 AFillRect(20,20,200,100); ok
0028 AFillOval(20,20,200,100); ok
0029 ALineStyle(10,0,0,0);
0030 AFrameRect(20,20,200,100); ok
0031 AFrameOval(20,20,200,100); ok
0032 return 0;
0033}
0034**/
0035
0036/**
0037int arttest()
0038{
0039 int i;
0040 AOpenPath(10);
0041 AMoveToOpen(20,20);
0042 AMoveTo(20,20);
0043 ALineTo(40,100);
0044 ALineTo(130,120);
0045 ALineTo(100,40);
0046 ALineTo(20,20);
0047 i=AClosePath();
0048 ADrawPath(i);
0049 AFreePath(i);
0050 return 0;
0051}
0052**/
0053
0054int arttest()
0055{
0056 int i;
0057
0058 ALineStyle(1,1,0,0);
0059
0060 AOpenPath(10);
0061 AMoveToOpen(20,20);
0062 ALineTo(40,100);
0063 ALineTo(130,120);
0064 ALineTo(100,40);
0065
0066 i=AClosePath();
0067 ADrawPath(i);
0068
0069 AFreePath(i);
0070 return 0;
0071}
0072
0073/*****************************************************************************************/
0074
0075int AFreePath(int id)
0076{
0077 art_free(vpath[id]);
0078 vused[id]=0;
0079}
0080
0081int ADrawPath(int id)
0082{
0083 ArtSVP *svp = NULL;
0084 ArtVpathDash dash_style;
0085 ArtVpath *dash;
0086
0087 if(linedraw){
0088 if(linedash==0)
0089 svp=art_svp_vpath_stroke(vpath[id],linejoin,linecap,linewidth,linewidth,1);
0090 else{
0091 dash_style.offset = 5;
0092 dash_style.n_dash = 3;
0093 dash_style.dash = art_new (double, 3);
0094 dash_style.dash[0] = linewidth*2;
0095 dash_style.dash[1] = linewidth*3;
0096 dash=art_vpath_dash(vpath[id],&dash_style);
0097 svp=art_svp_vpath_stroke(dash,linejoin,linecap,linewidth,linewidth,1);
0098 art_free(dash_style.dash);
0099 art_free(dash);
0100 }
0101 }
0102 else svp = art_svp_from_vpath(vpath[id]);
0103 ADrawSvp(svp);
0104 art_free(svp);
0105}
0106
0107int ADrawSvp(ArtSVP *svp)
0108{
0109 art_u8 *buffer = NULL;
0110 int i,j;
0111 ArtDRect bbox;
0112 int left,top,right,bottom;
0113 int width,height;
0114 PixMap *p;
0115
0116 art_drect_svp (&bbox,svp);
0117 left=bbox.x0-1.;
0118 top=bbox.y0-1.;
0119 right=bbox.x1+2.;
0120 bottom=bbox.y1+2.;
0121 width=right-left;
0122 height=bottom-top;
0123 buffer=art_new(art_u8,width*height);
0124 j=width*height;
0125 for(i=0;i<j;i++) buffer[i]=0;
0126 art_gray_svp_aa (svp, left, top, right, bottom,
0127 buffer, width);
0128
0129 p=pcreate(2,width,height); /* 8-bit grayscale */
0130 for(i=0;i<j;i++)
0131 p->pixdata[i]=0;
0132 for(j=0;j<height;j++)
0133 for(i=0;i<width;i++)
0134 p->pixdata[j*width+i]=buffer[j*width+i];
0135 art_free(buffer);
0136 j=MakePixmap(2,width,height);
0137 XferPixmap(j,p);
0138 PastePixmap(j,left,top,3);
0139 DestroyPixmap(j);
0140 pdestroy(p);
0141}
0142
0143int AAffScale(double dst[6],double sx,double sy)
0144{
0145 art_affine_scale(dst,sx,sy);
0146 return 0;
0147}
0148
0149int AAffTranslate(double dst[6],double tx,double ty)
0150{
0151 art_affine_translate(dst,tx,ty);
0152 return 0;
0153}
0154
0155int AAffRotate(double dst[6],double theta)
0156{
0157 art_affine_rotate(dst,theta);
0158 return 0;
0159}
0160
0161int AAffShear(double dst[6],double theta)
0162{
0163 art_affine_shear(dst,theta);
0164 return 0;
0165}
0166
0167int AAffFlip(double dst_src[6],int horz,int vert)
0168{
0169 art_affine_flip(dst_src,dst_src,horz,vert);
0170 return 0;
0171}
0172
0173int AAffMul(double dst[6],double src1[6],double src2[6])
0174{
0175 art_affine_multiply(dst,src1,src2);
0176 return 0;
0177}
0178
0179int AAffPoint(double *dstx,double *dsty,double srcx,double srcy,double affine[6])
0180{
0181 ArtPoint dst,src;
0182 src.x=srcx;
0183 src.y=srcy;
0184 art_affine_point(&dst,&src,affine);
0185 *dstx=dst.x;
0186 *dsty=dst.y;
0187 return 0;
0188}
0189
0190int AAffPath(int src,double affine[6])
0191{
0192 int i;
0193 for(i=0;i<20;i++) if(vused[i]==0) break;
0194 if(i==20) return -1;
0195 vused[i]=1;
0196 vpath[i]=art_vpath_affine_transform(vpath[src],affine);
0197 return i;
0198}
0199
0200int AOpenPath(int maxpath)
0201{
0202 if(bpath!=NULL) return 1;
0203 bpath=art_new(ArtBpath,maxpath);
0204 currbp=0;
0205 bpmax=maxpath;
0206 linedraw=0;
0207 return 0;
0208}
0209
0210int AMoveToOpen(double x,double y)
0211{
0212 bpath[currbp].code = ART_MOVETO_OPEN;
0213 bpath[currbp].x3=x;
0214 bpath[currbp].y3=y;
0215 currbp++;
0216 linedraw=1;
0217 return 0;
0218}
0219
0220int AMoveTo(double x,double y)
0221{
0222 bpath[currbp].code = ART_MOVETO;
0223 bpath[currbp].x3=x;
0224 bpath[currbp].y3=y;
0225 currbp++;
0226 return 0;
0227}
0228
0229int ALineTo(double x,double y)
0230{
0231 bpath[currbp].code = ART_LINETO;
0232 bpath[currbp].x3=x;
0233 bpath[currbp].y3=y;
0234 currbp++;
0235 return 0;
0236}
0237
0238int ACurveTo(double x1,double y1,double x2,double y2,double x3,double y3)
0239{
0240 bpath[currbp].code = ART_CURVETO;
0241 bpath[currbp].x1=x1;
0242 bpath[currbp].y1=y1;
0243 bpath[currbp].x2=x2;
0244 bpath[currbp].y2=y2;
0245 bpath[currbp].x3=x3;
0246 bpath[currbp].y3=y3;
0247 currbp++;
0248 return 0;
0249}
0250
0251int AClosePath()
0252{
0253 int i;
0254 bpath[currbp].code = ART_END;
0255 for(i=0;i<20;i++) if(vused[i]==0) break;
0256 if(i==20) return -1;
0257 vused[i]=1;
0258 vpath[i]=art_bez_path_to_vec(bpath,0.5);
0259 art_free(bpath);
0260 bpath=NULL;
0261 return i;
0262}
0263
0264int AFillRect(double left,double top,double right,double bottom)
0265{
0266 int i;
0267 for(i=0;i<20;i++) if(vused[i]==0) break;
0268 if(i==20) return -1;
0269 vused[i]=1;
0270 vpath[i]=art_new(ArtVpath,6);
0271
0272 vpath[i][0].code=ART_MOVETO;
0273 vpath[i][0].x=left;
0274 vpath[i][0].y=top;
0275 vpath[i][1].code=ART_LINETO;
0276 vpath[i][1].x=left;
0277 vpath[i][1].y=bottom;
0278 vpath[i][2].code=ART_LINETO;
0279 vpath[i][2].x=right;
0280 vpath[i][2].y=bottom;
0281 vpath[i][3].code=ART_LINETO;
0282 vpath[i][3].x=right;
0283 vpath[i][3].y=top;
0284 vpath[i][4].code=ART_LINETO;
0285 vpath[i][4].x=left;
0286 vpath[i][4].y=top;
0287 vpath[i][5].code=ART_END;
0288 linedraw=0;
0289 ADrawPath(i);
0290 art_free(vpath[i]);
0291 vused[i]=0;
0292}
0293
0294int AFrameRect(double left,double top,double right,double bottom)
0295{
0296 int i;
0297 ArtVpath* vpath0;
0298 ArtVpath* vpath1;
0299 ArtSVP *svp0;
0300 ArtSVP *svp1;
0301 ArtSVP *svp;
0302
0303 vpath0=art_new(ArtVpath,6);
0304
0305 vpath0[0].code=ART_MOVETO;
0306 vpath0[0].x=left;
0307 vpath0[0].y=top;
0308 vpath0[1].code=ART_LINETO;
0309 vpath0[1].x=left;
0310 vpath0[1].y=bottom;
0311 vpath0[2].code=ART_LINETO;
0312 vpath0[2].x=right;
0313 vpath0[2].y=bottom;
0314 vpath0[3].code=ART_LINETO;
0315 vpath0[3].x=right;
0316 vpath0[3].y=top;
0317 vpath0[4].code=ART_LINETO;
0318 vpath0[4].x=left;
0319 vpath0[4].y=top;
0320 vpath0[5].code=ART_END;
0321 svp0=art_svp_from_vpath(vpath0);
0322 vpath1=art_new(ArtVpath,6);
0323 vpath1[0].code=ART_MOVETO;
0324 vpath1[0].x=left+linewidth;
0325 vpath1[0].y=top+linewidth;
0326 vpath1[1].code=ART_LINETO;
0327 vpath1[1].x=left+linewidth;
0328 vpath1[1].y=bottom-linewidth;
0329 vpath1[2].code=ART_LINETO;
0330 vpath1[2].x=right-linewidth;
0331 vpath1[2].y=bottom-linewidth;
0332 vpath1[3].code=ART_LINETO;
0333 vpath1[3].x=right-linewidth;
0334 vpath1[3].y=top+linewidth;
0335 vpath1[4].code=ART_LINETO;
0336 vpath1[4].x=left+linewidth;
0337 vpath1[4].y=top+linewidth;
0338 vpath1[5].code=ART_END;
0339 svp1=art_svp_from_vpath(vpath1);
0340 svp=art_svp_diff(svp0,svp1);
0341 linedraw=0;
0342 ADrawSvp(svp);
0343 art_free(vpath0);
0344 art_free(vpath1);
0345 art_free(svp0);
0346 art_free(svp1);
0347 art_free(svp);
0348}
0349
0350int AFillOval(double left,double top,double right,double bottom)
0351{
0352 ArtVpath* vpath0;
0353 ArtVpath* vpath1;
0354 ArtSVP *svp0;
0355 double x0,y0,rx,ry;
0356 double aff0[6],aff1[6],aff2[6];
0357
0358 x0=(left+right)*0.5;
0359 y0=(top+bottom)*0.5;
0360 rx=(right-left)*0.5;
0361 ry=(bottom-top)*0.5;
0362 vpath0=art_vpath_new_circle(0.,0.,rx);
0363 art_affine_scale(aff1,1,ry/rx);
0364 art_affine_translate(aff2,x0,y0);
0365 art_affine_multiply(aff0,aff1,aff2);
0366 vpath1=art_vpath_affine_transform(vpath0,aff0);
0367 svp0=art_svp_from_vpath(vpath1);
0368 linedraw=0;
0369 ADrawSvp(svp0);
0370 art_free(vpath0);
0371 art_free(vpath1);
0372 art_free(svp0);
0373}
0374
0375int AFrameOval(double left,double top,double right,double bottom)
0376{
0377 int i;
0378 ArtVpath* vpath0;
0379 ArtVpath* vpath1;
0380 ArtVpath* vpath2;
0381 ArtSVP *svp0;
0382 ArtSVP *svp1;
0383 ArtSVP *svp;
0384 double x0,y0,rx,ry;
0385 double aff0[6],aff1[6],aff2[6];
0386
0387 x0=(left+right)*0.5;
0388 y0=(top+bottom)*0.5;
0389 rx=(right-left)*0.5;
0390 ry=(bottom-top)*0.5;
0391 vpath0=art_vpath_new_circle(0.,0.,rx);
0392 art_affine_scale(aff1,1,ry/rx);
0393 art_affine_translate(aff2,x0,y0);
0394 art_affine_multiply(aff0,aff1,aff2);
0395 vpath1=art_vpath_affine_transform(vpath0,aff0);
0396 svp0=art_svp_from_vpath(vpath1);
0397
0398 rx-=linewidth;
0399 ry-=linewidth;
0400 vpath0=art_vpath_new_circle(0.,0.,rx);
0401 art_affine_scale(aff1,1,ry/rx);
0402 art_affine_multiply(aff0,aff1,aff2);
0403 vpath2=art_vpath_affine_transform(vpath0,aff0);
0404 svp1=art_svp_from_vpath(vpath2);
0405
0406 svp=art_svp_diff(svp0,svp1);
0407 linedraw=0;
0408 ADrawSvp(svp);
0409 art_free(vpath0);
0410 art_free(vpath1);
0411 art_free(vpath2);
0412 art_free(svp0);
0413 art_free(svp1);
0414 art_free(svp);
0415 return 0;
0416}
0417
0418/*********************************************************
0419 width in pixels
0420 dash 0 : solid
0421 1 : dashed
0422 2 :
0423 join 0 : ART_PATH_STROKE_JOIN_MITER
0424 1 : ART_PATH_STROKE_JOIN_ROUND,
0425 2 : ART_PATH_STROKE_JOIN_BEVEL
0426 (ArtPathStrokeJoinType)
0427 cap 0 : ART_PATH_STROKE_CAP_BUTT
0428 1 : ART_PATH_STROKE_CAP_ROUND
0429 2 : ART_PATH_STROKE_CAP_SQUARE
0430 (ArtPathStrokeCapType)
0431**********************************************************/
0432int ALineStyle(double width,int dash,int join,int cap)
0433{
0434 linewidth=width;
0435 linedash=dash;
0436 linejoin=join;
0437 linecap=cap;
0438 return 0;
0439}
0440