1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
# include "appFrameConfig.h"
# include <stddef.h>
# include <stdlib.h>
# include <appMetafile.h>
# include <utilPs.h>
# include <sioEndian.h>
# include <appDebugon.h>
void appMetafilePolygonPathPs( SimpleOutputStream * sos,
const APP_POINT * points,
int count )
{
int done;
char * command;
int x0;
int y0;
command= "bp"; x0= 0; y0= 0;
for ( done= 0; done < count; done++ )
{
sioOutPrintf( sos, "%d %d %s",
points[done].x- x0,
points[done].y- y0,
command );
if ( done % 8 == 7 )
{ sioOutPutCharacter( '\n', sos ); }
else{ sioOutPutCharacter( ' ', sos ); }
command= "rl"; x0= points[done].x; y0= points[done].y;
}
return;
}
void appMetafileRoundRectPathPs( SimpleOutputStream * sos,
int x0,
int y0,
int x1,
int y1,
int w,
int h )
{
int top;
int bottom;
int radius;
int swap;
if ( x1 < x0 )
{ swap= x0; x0= x1; x1= swap; }
if ( y1 < y0 )
{ swap= y0; y0= y1; y1= swap; }
if ( h < 0 )
{ h= -h; }
if ( w < 0 )
{ w= -w; }
top= w* ( y1- y0 )/ ( 2* h );
bottom= w* ( y0- y1 )/ ( 2* h );
radius= w/ 2;
sioOutPrintf( sos, "%d %d bp\n", x0, bottom+ radius );
sioOutPrintf( sos, "%d %d %d %d %d arct\n",
x0, top, x0+ radius, top, radius );
sioOutPrintf( sos, "%d %d %d %d %d arct\n",
x1, top, x1, top- radius, radius );
sioOutPrintf( sos, "%d %d %d %d %d arct\n",
x1, bottom, x1- radius, bottom, radius );
sioOutPrintf( sos, "%d %d %d %d %d arct\n",
x0, bottom, x0, bottom+ radius, radius );
return;
}
void appMetafileRectPathPs( SimpleOutputStream * sos,
int x0,
int y0,
int x1,
int y1 )
{
int dx= x1- x0;
int dy= y1- y0;
sioOutPrintf( sos, "%d %d bp ", x0, y0 );
sioOutPrintf( sos, "%d %d rl ", dx, 0 );
sioOutPrintf( sos, "%d %d rl ", 0, dy );
sioOutPrintf( sos, "%d %d rl ", -dx, 0 );
sioOutPrintf( sos, "closepath\n" );
return;
}
/************************************************************************/
/* */
/* Start a pattern fill. */
/* */
/************************************************************************/
int appMetafileStartPatternFillPs( SimpleOutputStream * sos,
const AppBitmapImage * abi )
{
int bytesPerRow;
const int useFilters= 0;
const int indexedImages= 0;
BitmapPrinter bp;
bytesPerRow= bmPsRowStringSize( &(abi->abiBitmap),
abi->abiBitmap.bdPixelsWide,
indexedImages );
if ( bytesPerRow < 1 )
{ LDEB(bytesPerRow); return -1; }
sioOutPrintf( sos, "currentfile %d string readhexstring\n",
abi->abiBitmap.bdPixelsHigh* bytesPerRow );
bmPsOpenBitmapPrinter( &bp, sos, &(abi->abiBitmap),
useFilters, indexedImages );
if ( bmPsWriteBitmapData( &bp, 0, 0,
abi->abiBitmap.bdPixelsWide,
abi->abiBitmap.bdPixelsHigh,
&(abi->abiBitmap), abi->abiBuffer ) )
{ LDEB(1); return -1; }
bmCloseBitmapPrinter( &bp );
sioOutPrintf( sos, "%%\n" );
sioOutPrintf( sos, "pop /fill-data exch store\n" );
sioOutPrintf( sos, "/fill-wide %d store\n", abi->abiBitmap.bdPixelsWide );
sioOutPrintf( sos, "/fill-high %d store\n", abi->abiBitmap.bdPixelsHigh );
sioOutPrintf( sos, "/fill-cell " );
sioOutPrintf( sos, "{ " );
sioOutPrintf( sos, "gsave " );
sioOutPrintf( sos, "%d %d scale\n" ,
abi->abiBitmap.bdPixelsWide,
abi->abiBitmap.bdPixelsHigh );
sioOutPrintf( sos, "1 setgray 0 0 1 1 rectfill\n" );
bmPsWriteImageInstructions( sos,
&(abi->abiBitmap),
abi->abiBitmap.bdPixelsWide,
abi->abiBitmap.bdPixelsHigh,
"{ /fill-data load } bind",
indexedImages );
sioOutPrintf( sos, "grestore " );
sioOutPrintf( sos, "} bind def\n" );
return 0;
}
|