コード例 #1
0
ファイル: render.c プロジェクト: JiajiaGuo/libk2pdfopt
void render_partial_circle_pts(double xc,double yc,double radius,
                               double theta0,double theta1,int nsteps)

    {
    int i;

    if (theta0==0. && theta1==0.)
        theta1=2.*PI;
    if (nsteps<1)
        {
        int n1,n2;

        n1=lbmp->width*1.33*radius/width_pts;
        n2=lbmp->height*1.33*radius/height_pts;
        nsteps = n1<n2 ? n2 : n1;
        if (nsteps<8)
            nsteps=8;
        nsteps *= fabs(theta1-theta0)/(2.*PI);
        if (nsteps<1)
            nsteps=1;
        }
    for (i=0;i<nsteps;i++)
        {
        double th1,th2;

        th1=theta0+i*(theta1-theta0)/nsteps;
        th2=(i==nsteps-1)?theta1:theta0+(i+1)*(theta1-theta0)/nsteps;
        render_tri_pts(xc,yc,xc+radius*cos(th1),yc+radius*sin(th1),
                             xc+radius*cos(th2),yc+radius*sin(th2));
        }
    }
コード例 #2
0
ファイル: render.c プロジェクト: FauxFaux/k2pdfopt
/*
** x0,y0,x1,y1 in points
*/
static void render_solid_line_pts(double x0,double y0,double x1,double y1)

    {
    double theta;
    double dx,dy,r;


    dx=x1-x0;
    dy=y1-y0;
    r=linewidth/2.;
    if (fabs(dx)>1e-8 || fabs(dy)>1e-8)
        theta=atan2(dy,dx);
    else
        theta=0.;
    switch (linecap)
        {
        case 0: /* butt */
        case 1: /* round */
            {
            double xa,ya,xb,yb,xc,yc,xd,yd;
            xa=x0+r*cos(theta-PI/2.);
            ya=y0+r*sin(theta-PI/2.);
            xb=x0+r*cos(theta+PI/2.);
            yb=y0+r*sin(theta+PI/2.);
            xc=x1+r*cos(theta+PI/2.);
            yc=y1+r*sin(theta+PI/2.);
            xd=x1+r*cos(theta-PI/2.);
            yd=y1+r*sin(theta-PI/2.);
            render_rect_pts(xa,ya,xb,yb,xc,yc,xd,yd);
            if (linecap==0)
                break;
            render_partial_circle_pts(x0,y0,r,theta+PI/2.,theta+3.*PI/2.,-1);
            render_partial_circle_pts(x1,y1,r,theta-PI/2.,theta+PI/2.,-1);
            break;
            }
        case 2: /* project */
            {
            double xa,ya,xb,yb,xc,yc,xd,yd;
            double r2;
            r2=r*SQRT2;
            xa=x0+r2*cos(theta-1.5*PI/2.);
            ya=y0+r2*sin(theta-1.5*PI/2.);
            xb=x0+r2*cos(theta+1.5*PI/2.);
            yb=y0+r2*sin(theta+1.5*PI/2.);
            xc=x1+r2*cos(theta+PI/4.);
            yc=y1+r2*sin(theta+PI/4.);
            xd=x1+r2*cos(theta-PI/4.);
            yd=y1+r2*sin(theta-PI/4.);
            render_rect_pts(xa,ya,xb,yb,xc,yc,xd,yd);
            break;
            }
        case 3: /* arrow */
            {
            double xa,ya,xb,yb,xc,yc,xd,yd;
            double xe,ye,xf,yf,xg,yg,xh,yh;

            /* Back up (x1,y1) along line to give room for arrow head */
            xg=x1-r*7.00*cos(theta);
            yg=y1-r*7.00*sin(theta);
            xa=x0+r*cos(theta-PI/2.);
            ya=y0+r*sin(theta-PI/2.);
            xb=x0+r*cos(theta+PI/2.);
            yb=y0+r*sin(theta+PI/2.);
            xc=xg+r*cos(theta+PI/2.);
            yc=yg+r*sin(theta+PI/2.);
            xd=xg+r*cos(theta-PI/2.);
            yd=yg+r*sin(theta-PI/2.);
            /* Draw butt-ended line */
            render_rect_pts(xa,ya,xb,yb,xc,yc,xd,yd);
            /* Arrowhead points */
            xe=x1-r*6.25*cos(theta);
            ye=y1-r*6.25*sin(theta);
            xf=x1-r*10.0*cos(theta);
            yf=y1-r*10.0*sin(theta);
            xg=xf+5*r*cos(theta+PI/2.);
            yg=yf+5*r*sin(theta+PI/2.);
            xh=xf+5*r*cos(theta-PI/2.);
            yh=yf+5*r*sin(theta-PI/2.);
            render_tri_pts(xc,yc,xe,ye,xd,yd);
            render_tri_pts(xe,ye,xg,yg,x1,y1);
            render_tri_pts(xe,ye,x1,y1,xh,yh);
            break;
            }
        }
    }