[go: up one dir, main page]

Menu

[72b583]: / tests / c / spotcolor.c  Maximize  Restore  History

Download this file

132 lines (111 with data), 3.3 kB

  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
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <libps/pslib.h>
#ifdef MEMORY_DEBUGGING
#include <libps/pslib-mp.h>
#endif
#define LEFT_BORDER 50
struct spotcolor {
int id;
char *name;
char *colorspace;
float c1;
float c2;
float c3;
float c4;
};
void errorhandler(PSDoc *p, int error, const char *str, void *data) {
fprintf(stderr, "PSLib: %s\n", str);
}
size_t writeproc(PSDoc *p, void *data, size_t size) {
return fwrite(data, 1, size, stdout);
}
void footer(PSDoc *p, const char *text) {
int psfont;
char buffer[100];
psfont = PS_findfont(p, "Helvetica", "", 0);
PS_setfont(p, psfont, 8.0);
sprintf(buffer, "This file has been created with pslib %s", PS_get_parameter(p, "dottedversion", 0.0));
PS_show_xy(p, buffer, LEFT_BORDER, 25);
}
int colorline(PSDoc *ps, float leftborder, struct spotcolor *spot) {
int i;
int psfont;
char buffer[100];
for(i=1; i<=10; i++) {
PS_setcolor(ps, "fill", "spot", (float) spot->id, i*0.1, 0.0, 0.0);
PS_rect(ps, leftborder, 35+i*65, 50, 50);
PS_fill(ps);
}
PS_setcolor(ps, "stroke", "gray", 0.0, 0.0, 0.0, 0.0);
psfont = PS_findfont(ps, "Helvetica", "", 0);
PS_setfont(ps, psfont, 7.0);
PS_show_xy(ps, spot->name, leftborder, 100+10*65+13);
if(!strcmp(spot->colorspace, "cmyk")) {
sprintf(buffer, "%.2f, %.2f, %.2f, %.2f", spot->c1, spot->c2, spot->c3, spot->c4);
PS_show_xy(ps, buffer, leftborder, 100+10*65+3);
} else if(!strcmp(spot->colorspace, "rgb")) {
sprintf(buffer, "%.2f, %.2f, %.2f", spot->c1, spot->c2, spot->c3);
PS_show_xy(ps, buffer, leftborder, 100+10*65+3);
}
return(spot->id);
}
int main() {
PSDoc *ps;
int i;
struct spotcolor spotcolors[5] = {
{0, "PANTONE Violet C", "cmyk", 0.75, 0.94, 0.0, 0.0},
{0, "PANTONE 114 C", "cmyk", 0.0, 0.11, 0.69, 0.0},
{0, "PANTONE 5565 C", "cmyk", 0.37, 0.0, 0.34, 0.34},
{0, "RGB Blue", "rgb", 0.0, 0.0, 1.0, 0.0},
{0, "Gray Black", "gray", 0.0, 0.0, 0.0, 0.0}};
int psfont;
PS_boot();
#ifdef MEMORY_DEBUGGING
PS_mp_init();
#endif
#ifdef MEMORY_DEBUGGING
ps = PS_new2(errorhandler, PS_mp_malloc, PS_mp_realloc, PS_mp_free, NULL);
#else
ps = PS_new();
#endif
if (0 > PS_open_file(ps, "spotcolor.ps")) {
// if (0 > PS_open_mem(ps, writeproc)) {
printf("Cannot open PostScript file\n");
exit(1);
}
PS_set_parameter(ps, "warning", "true");
PS_set_info(ps, "Creator", __FILE__);
PS_set_info(ps, "Author", "Uwe Steinmann");
PS_set_info(ps, "Title", "Spotcolor demonstration");
PS_set_info(ps, "Keywords", "Spot color");
for(i=0; i<5; i++) {
PS_setcolor(ps, "fill", spotcolors[i].colorspace, spotcolors[i].c1, spotcolors[i].c2, spotcolors[i].c3, spotcolors[i].c4);
spotcolors[i].id = PS_makespotcolor(ps, spotcolors[i].name, 0);
}
PS_begin_page(ps, 596, 842);
footer(ps, "");
psfont = PS_findfont(ps, "Helvetica", "", 0);
PS_setfont(ps, psfont, 7.0);
for(i=1; i<=10; i++) {
char buffer[10];
sprintf(buffer, "%d %%", i*10);
PS_show_xy(ps, buffer, 60, 55+i*65);
}
colorline(ps, 100.0, &spotcolors[0]);
colorline(ps, 190.0, &spotcolors[1]);
colorline(ps, 280.0, &spotcolors[2]);
colorline(ps, 370.0, &spotcolors[3]);
colorline(ps, 460.0, &spotcolors[4]);
PS_end_page(ps);
PS_close(ps);
PS_delete(ps);
#ifdef MEMORY_DEBUGGING
PS_mp_list_unfreed();
#endif
PS_shutdown();
exit(0);
}