#include <stdio.h>
#include <stdlib.h>
#define JAPANESE_TEST
#ifdef JAPANESE_TEST
#if defined(COCOA) || defined(MACOSX64) || defined(__MINGW32__)
#include "strings_utf8jp.h"
#elif (defined(_WIN32) && !defined(__CYGWIN32__)) || defined(MACOS)
#include "strings_sjis.h"
#else
#include "strings_eucjp.h"
#endif
#else
#define HELLO_STRING "Hello World"
#endif
void polygonTest(spPSFile *psfile, int width, int height)
{
spPSPolygonId polygon_id;
double r;
double rcos72, rsin72, rcos36, rsin36;
r = 30.0;
rcos72 = r * cos(2.0 * PI / 5.0); rsin72 = r * sin(2.0 * PI / 5.0);
rcos36 = r * cos(PI / 5.0); rsin36 = r * sin(PI / 5.0);
if (spPSStartPolygonPoint(psfile, width / 2, (
int)
spRound(2.0 * r)) ==
SP_TRUE) {
spPSAddPolygonRelativePoint(psfile, -(
int)
spRound(rsin36), (
int)
spRound(r + rcos36));
spPSAddPolygonRelativePoint(psfile, (
int)
spRound(rsin36 + rsin72), -(
int)
spRound(rcos36 + rcos72));
spPSAddPolygonRelativePoint(psfile, -(
int)
spRound(rsin72 * 2.0), 0);
spPSAddPolygonRelativePoint(psfile, (
int)
spRound(rsin72 + rsin36), (
int)
spRound(rcos36 + rcos72));
if ((polygon_id = spPSEndPolygonPoint(psfile)) != SP_PS_POLYGON_NONE) {
spPSDrawPolygon(psfile, polygon_id, 0, 0);
spPSDrawPolygon(psfile, polygon_id, width / 8, 0);
spPSFillPolygon(psfile, polygon_id, width / 8, (2 * height) / 3);
}
}
return;
}
int spMain(int argc, char *argv[])
{
int i;
spPaperOrientation orientation = SP_PAPER_ORIENTATION_PORTRAIT;
spPSFile *psfile;
int width, height;
double width_mm, height_mm;
unsigned long options = 0L;
#if 0
options |= SP_PS_HALF_SIZE;
#endif
#if 0
options |= SP_PS_SCREEN_COORDINATE;
#endif
#if 0
options |= SP_PS_DOUBLE_SIDED;
options |= SP_PS_TUMBLE;
#endif
#if 0
orientation = SP_PAPER_ORIENTATION_LANDSCAPE;
options |= SP_PS_LANDSCAPE;
#endif
if (spGetPaperDimensions(SP_PAPER_SIZE_A4, orientation,
&width_mm, &height_mm) ==
SP_TRUE) {
spDebug(-10,
"spMain",
"A4 paper: width_mm = %f, height_mm = %f\n", width_mm, height_mm);
width_mm -= 40.0;
height_mm -= 40.0;
} else {
width_mm = 170.0;
height_mm = 257.0;
}
if ((psfile = spPSOpenFile("test.ps", width_mm, height_mm, options)) != NULL) {
spPSSetScalingFactor(psfile, 1.0, 1.0);
#ifdef JAPANESE_TEST
spDebug(-10,
"spMain",
"lang = %s\n", STRING_LANG);
spPSSetLang(psfile, STRING_LANG);
#endif
if (spPSStartDrawing(psfile) ==
SP_TRUE) {
if (spPSGetClientSize(psfile, &width, &height) ==
SP_TRUE) {
spDebug(-10,
"spMain",
"width = %d, height = %d\n", width, height);
if (spPSGetPhisicalSize(psfile, &width_mm, &height_mm) ==
SP_TRUE) {
spDebug(-10,
"spMain",
"width_mm = %f, height_mm = %f\n", width_mm, height_mm);
}
spPSDrawLine(psfile, 0, 0, width, height);
spPSSetLineType(psfile, SP_PS_LINE_DASH);
spPSSetRGBColor(psfile, 1.0, 0.0, 0.0);
spPSDrawLineTo(psfile, width, 0);
spPSSetLineType(psfile, SP_PS_LINE_DOT);
spPSSetRGBColor(psfile, 0.0, 1.0, 0.0);
spPSSetLineWidth(psfile, 3);
spPSDrawLineTo(psfile, 0, 0);
spPSSetRGBColor(psfile, 0.0, 0.0, 1.0);
spPSSetLineType(psfile, SP_PS_LINE_DASH_DOT);
spPSDrawLineTo(psfile, 0, height);
spPSSetRGBColor(psfile, 1.0, 0.0, 1.0);
spPSSetLineWidth(psfile, 5);
spPSSetLineType(psfile, SP_PS_LINE_DASH_DOT_DOT);
spPSDrawLineTo(psfile, width, height);
spPSSetLineWidth(psfile, 1);
spPSSetRGBColor(psfile, 0.0, 0.0, 1.0);
spPSSetLineType(psfile, SP_PS_LINE_DASH);
spPSDrawRectangle(psfile, width / 2, height / 2, 100, 100);
spPSSetFontSize(psfile, 20);
spPSSetRGBColor(psfile, 0.0, 1.0, 0.0);
for (i = 0; i <= 180; i += 30) {
if (i <= 60) {
spPSSetStringAlignment(psfile, SP_PS_ALIGNMENT_BEGINNING);
} else if (i <= 120) {
spPSSetStringAlignment(psfile, SP_PS_ALIGNMENT_CENTER);
} else {
spPSSetStringAlignment(psfile, SP_PS_ALIGNMENT_END);
}
spPSSetStringRotation(psfile, i);
spPSDrawString(psfile, width / 2, height / 2, HELLO_STRING);
}
spPSSetFontSize(psfile, 0);
spPSSetStringRotation(psfile, 0);
spPSForwardPage(psfile);
spPSSetRGBColor(psfile, 1.0, 1.0, 0.0);
spPSSetStringAlignment(psfile, SP_PS_ALIGNMENT_CENTER);
spPSDrawString(psfile, width / 2, height / 2, HELLO_STRING);
spPSSetRGBColor(psfile, 0.0, 1.0, 1.0);
spPSDrawLine(psfile, width / 2, height / 2, width, height / 2);
spPSSetRGBColor(psfile, 0.0, 1.0, 0.0);
spPSSetFontSize(psfile, 20);
spPSSetStringAlignment(psfile, SP_PS_ALIGNMENT_END);
spPSDrawString(psfile, width, height / 2, HELLO_STRING);
spPSDrawLine(psfile, width, height / 2, width, height);
spPSSetRGBColor(psfile, 0.0, 0.0, 1.0);
spPSFillRectangle(psfile, width / 2, height / 4, 100, 100);
spPSDrawArc(psfile, 100, height - 100, 200, 100, 60, 330);
spPSSetRGBColor(psfile, 1.0, 0.0, 0.0);
spPSFillArc(psfile, 150, height - 100, 100, 100, 60, 330);
spPSSetRGBColor(psfile, 1.0, 0.0, 1.0);
polygonTest(psfile, width, height);
}
spPSEndDrawing(psfile);
}
spPSCloseFile(psfile);
}
return 0;
}
void spDebug(int level, const char *func_name, const char *format,...)
#define SP_TRUE
Definition spDefs.h:250