Home| base |src.lib|graphic|ps| PostScriptPolygon Index

PostScriptPolygon

Syntax
int PostScriptPolygon(struct PostScript *ptr, struct PostScriptMatrix *matrix, float x,float y, int num,float *px,float *py,int *t,int fill, unsigned int color,float width, struct PostScriptDash *dash,struct PostScriptClip *clip);
Header
base/rps.h
Library
rps
Description

The PosctScriptPolygon function plots a polygon.

The argument ptr is a pointer to the PostScript control structure . The argument matrix is an optional transformation matrix that can be applied to the polygon. If this is set to a NULL pointer then no transformation is applied. The position at which the polygon is plotted is given by the arguments x, and y.

The number of vertices of the polygon is given by the argument num. The arrays containing the X and Y coordinates of each vertex are pointed to by the arguments x and y.

A polygon can be constructed from straight line segments or bezier curves. The array pointed to by the argument t determines what kind of line segment is used to join to a vertex. If the corresponding entry in the array equals zero, then the segment between the current point and the next point is a straight line; if the entry is (1) then the connecting segment is a bezier curve and the next two vertices are the control points, the curve connects to the third point.

If the argument fill is set to a non-zero value then the polygon will be plotted as solid shape, not an outline.

The color used to plot the polygon is given by the color which is a 24-bit number that represents the red,green and blue components of the color as 8-bit number. The alpha red occupies the most significant bits and the blue channel occupies the least significant bits.

The width of the line used to plot the polygon is controlled using the argument width, a value of zero will plot a hairline. The dot-dash pattern used to plot the polygon is given by dash. If this is set to a NULL pointer, a solid line is plotted.

The clipping polygon is given by the argument clip. If this is set to a NULL pointer, no clipping is performed.

Returns
Returns zero on success. On error, (-1) is returned.
Errors
Returns zero on success. On error, (-1) is returned.
Example
PostScriptPolygon
Source Code: PostScriptPolygon.c

/* PostScriptPolygon
   =================
   Author: R.J.Barnes
 Copyright (c) 2012 The Johns Hopkins University/Applied Physics Laboratory

This file is part of the Radar Software Toolkit (RST).

RST is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program 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 this program. If not, see <https://www.gnu.org/licenses/>.

Modifications:




#include <stdio.h>
#include <stdlib.h>
#include "rfbuffer.h"
#include "rps.h"

int stream(char *buf,int sze,void *data) {
  FILE *fp;
  fp=(FILE *) data;
  fwrite(buf,sze,1,stdout);
  return 0;
} 


int main(int argc,char *argv[]) {

  struct PostScript *ps=NULL;

  float wdt=400,hgt=400;
  float xoff=50,yoff=50;

  float x[4],y[4];
  int t[4]={0,0,0,0};


  unsigned int fgcol=0xff000000;

  ps=PostScriptMake();
  PostScriptSetText(ps,stream,stdout);   
  PostScriptMakeDocument(ps,xoff,yoff,wdt,hgt,0);
  PostScriptMakePlot(ps);

  x[0]=50;
  x[1]=300;
  x[2]=350;
  x[3]=100;

  y[0]=100;
  y[1]=100;
  y[2]=300;
  y[3]=300;

  PostScriptPolygon(ps,NULL,0,0,4,x,y,t,
                  1,fgcol,0,NULL,NULL);

  PostScriptEndPlot(ps);
  PostScriptEndDocument(ps);
  return 0;
}