[go: up one dir, main page]

Menu

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

Download this file

155 lines (124 with data), 3.5 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <sys/stat.h>
#include <libps/pslib.h>
#ifdef MEMORY_DEBUGGING
#include <libps/pslib-mp.h>
#endif
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);
}
#define LEFT_BORDER 50
#define EXAMPLE_BOX_HEIGHT 190
#define EXAMPLE_BOX_WIDTH 150
#define EXAMPLE_BOX_TITLE_HEIGHT 40
int main() {
PSDoc *ps;
int psfont;
int psimage;
int pstemplate;
int x, y, i, j;
float height, scale;
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, "imagereuse.ps")) {
printf("Cannot open PostScript file\n");
exit(1);
}
PS_set_parameter(ps, "warning", "true");
PS_set_parameter(ps, "imageencoding", "hex");
PS_set_parameter(ps, "imagereuse", "true");
PS_set_info(ps, "Creator", __FILE__);
PS_set_info(ps, "Author", "Uwe Steinmann");
PS_set_info(ps, "Title", "Image Reuse Example");
PS_set_info(ps, "Keywords", "Image Picture PNG Jpeg Reuse");
psimage = PS_open_image_file(ps, "png", "debian.png", NULL, 0);
pstemplate = PS_begin_template(ps, 30.0, 30.0);
PS_place_image(ps, psimage, 0, 0, 0.5);
PS_moveto(ps, 0, 0);
PS_lineto(ps, 30, 30);
PS_moveto(ps, 0, 30);
PS_lineto(ps, 30, 0);
PS_stroke(ps);
PS_end_template(ps);
PS_close_image(ps, psimage);
PS_begin_page(ps, 596, 842);
psfont = PS_findfont(ps, "Helvetica", "", 0);
PS_setfont(ps, psfont, 8.0);
psimage = PS_open_image_file(ps, "eps", "picture.eps", NULL, 0);
height = PS_get_value(ps, "imageheight", (float) psimage);
y = 0;
for(i=0; i<10; i++) {
scale = 1.0/(i+1);
PS_place_image(ps, psimage, 30, y+30, scale);
y += scale*height + 20;
}
PS_close_image(ps, psimage);
psimage = PS_open_image_file(ps, "png", "debian.png", NULL, 0);
height = PS_get_value(ps, "imageheight", (float) psimage);
y = 0;
for(i=0; i<10; i++) {
scale = 3.0/(i+1);
PS_place_image(ps, psimage, 350, y+30, scale);
y += scale*height + 20;
}
PS_close_image(ps, psimage);
PS_end_page(ps);
PS_set_parameter(ps, "imagereuse", "false");
PS_begin_page(ps, 596, 842);
psfont = PS_findfont(ps, "Helvetica", "", 0);
PS_setfont(ps, psfont, 18.0);
PS_show_xy(ps, "This page is created with imagereuse = false", 20, 815);
psimage = PS_open_image_file(ps, "png", "debian.png", NULL, 0);
x = 2;
for(j=0; j<30; j++) {
y = 2;
for(i=0; i<40; i++) {
PS_place_image(ps, psimage, x, y, 0.2);
y += 20;
}
x += 20;
}
PS_close_image(ps, psimage);
PS_end_page(ps);
PS_set_parameter(ps, "imagereuse", "true");
PS_begin_page(ps, 596, 842);
psfont = PS_findfont(ps, "Helvetica", "", 0);
PS_setfont(ps, psfont, 18.0);
PS_show_xy(ps, "This page is created with imagereuse = true", 20, 815);
psimage = PS_open_image_file(ps, "png", "debian.png", NULL, 0);
x = 2;
for(j=0; j<30; j++) {
y = 2;
for(i=0; i<40; i++) {
PS_place_image(ps, psimage, x, y, 0.2);
y += 20;
}
x += 20;
}
PS_close_image(ps, psimage);
PS_end_page(ps);
PS_begin_page(ps, 596, 842);
PS_place_image(ps, pstemplate, 20.0, 20.0, 1.0);
PS_end_page(ps);
PS_close(ps);
PS_delete(ps);
#ifdef MEMORY_DEBUGGING
PS_mp_list_unfreed();
#endif
PS_shutdown();
exit(0);
}