PostScript output: : use ASCII85 encoding also for character strings.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10599 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
parent
4d1e372e09
commit
fe96d64a2b
@ -132,6 +132,12 @@ class Clip {
|
||||
|
||||
void page(double pw, double ph, int media = 0);
|
||||
void page(int format);
|
||||
static void *prepare_rle85(FILE *out);
|
||||
static void write_rle85(uchar b, void *data);
|
||||
static void close_rle85(void *data);
|
||||
static void *prepare85(FILE *out);
|
||||
static void write85(void *data, const uchar *p, int len);
|
||||
static void close85(void *data);
|
||||
#endif // FL_DOXYGEN
|
||||
|
||||
// implementation of drawing methods
|
||||
|
@ -262,11 +262,11 @@ static const char * prolog =
|
||||
|
||||
// single-color bitmask
|
||||
|
||||
"/MI { GS /filtername exch def /py exch def /px exch def /sy exch def /sx exch def \n"
|
||||
"/MI { GS /py exch def /px exch def /sy exch def /sx exch def \n"
|
||||
"translate \n"
|
||||
"sx sy scale px py true \n"
|
||||
"[ px 0 0 py neg 0 py ]\n"
|
||||
"currentfile filtername\n"
|
||||
"currentfile A85RLE\n"
|
||||
"imagemask GR\n"
|
||||
"} bind def\n"
|
||||
|
||||
@ -1108,19 +1108,18 @@ static void transformed_draw_extra(const char* str, int n, double x, double y, i
|
||||
delete[] img;
|
||||
// write the string image to PostScript as a scaled bitmask
|
||||
scale = w2 / float(w);
|
||||
driver->clocale_printf("%g %g %g %g %d %d {/ASCIIHexDecode filter} MI\n", x, y - h*0.77/scale, w2/scale, h/scale, w2, h);
|
||||
driver->clocale_printf("%g %g %g %g %d %d MI\n", x, y - h*0.77/scale, w2/scale, h/scale, w2, h);
|
||||
uchar *di;
|
||||
int wmask = (w2+7)/8;
|
||||
void *rle85 = Fl_PostScript_Graphics_Driver::prepare_rle85(output);
|
||||
for (int j = h - 1; j >= 0; j--){
|
||||
di = mask + j * wmask;
|
||||
for (int i = 0; i < wmask; i++){
|
||||
//if (!(i%80)) fprintf(output, "\n"); // don't have lines longer than 255 chars
|
||||
fprintf(output, "%2.2x", *di );
|
||||
Fl_PostScript_Graphics_Driver::write_rle85(*di, rle85);
|
||||
di++;
|
||||
}
|
||||
fprintf(output,"\n");
|
||||
}
|
||||
fprintf(output,">\n");
|
||||
Fl_PostScript_Graphics_Driver::close_rle85(rle85);
|
||||
delete[] mask;
|
||||
}
|
||||
|
||||
@ -1157,7 +1156,8 @@ void Fl_PostScript_Graphics_Driver::transformed_draw(const char* str, int n, dou
|
||||
transformed_draw_extra(str, n, x, y, w, output, this, false);
|
||||
return;
|
||||
}
|
||||
fprintf(output, "%d <", w);
|
||||
fprintf(output, "%d <~", w);
|
||||
void *data = prepare85(output);
|
||||
// transforms UTF8 encoding to our custom PostScript encoding as follows:
|
||||
// extract each unicode character
|
||||
// if unicode <= 0x17F, unicode and PostScript codes are identical
|
||||
@ -1178,13 +1178,15 @@ void Fl_PostScript_Graphics_Driver::transformed_draw(const char* str, int n, dou
|
||||
utf = code;
|
||||
}
|
||||
else { // unhandled character: draw all string as bitmap image
|
||||
fprintf(output, "> pop pop\n"); // close and ignore the opened hex string
|
||||
fprintf(output, "~> pop pop\n"); // close and ignore the opened hex string
|
||||
transformed_draw_extra(str, n, x, y, w, output, this, false);
|
||||
return;
|
||||
}
|
||||
fprintf(output, "%4.4X", utf);
|
||||
// 2 bytes per character, high-order byte first, encode that to ASCII85
|
||||
uchar c[2]; c[1] = utf & 0xFF; c[0] = (utf & 0xFF00)>>8; write85(data, c, 2);
|
||||
}
|
||||
clocale_printf("> %g %g show_pos_width\n", x, y);
|
||||
close85(data);
|
||||
clocale_printf(" %g %g show_pos_width\n", x, y);
|
||||
}
|
||||
|
||||
void Fl_PostScript_Graphics_Driver::rtl_draw(const char* str, int n, int x, int y) {
|
||||
|
@ -41,7 +41,7 @@ struct struct85 {
|
||||
};
|
||||
|
||||
|
||||
static struct85 *prepare85(FILE *outfile) // prepare to produce ASCII85-encoded output
|
||||
void *Fl_PostScript_Graphics_Driver::prepare85(FILE *outfile) // prepare to produce ASCII85-encoded output
|
||||
{
|
||||
struct85 *big = new struct85;
|
||||
big->outfile = outfile;
|
||||
@ -71,8 +71,9 @@ static int convert85(const uchar *bytes4, uchar *chars5)
|
||||
}
|
||||
|
||||
|
||||
static void write85(struct85 *big, const uchar *p, int len) // sends len input bytes for ASCII85 encoding
|
||||
void Fl_PostScript_Graphics_Driver::write85(void *data, const uchar *p, int len) // sends len input bytes for ASCII85 encoding
|
||||
{
|
||||
struct85 *big = (struct85 *)data;
|
||||
const uchar *last = p + len;
|
||||
while (p < last) {
|
||||
int c = 4 - big->l4;
|
||||
@ -90,8 +91,9 @@ static void write85(struct85 *big, const uchar *p, int len) // sends len input b
|
||||
}
|
||||
|
||||
|
||||
static void close85(struct85 *big) // stops ASCII85-encoding after processing remaining unencoded input bytes, if any
|
||||
void Fl_PostScript_Graphics_Driver::close85(void *data) // stops ASCII85-encoding after processing remaining unencoded input bytes, if any
|
||||
{
|
||||
struct85 *big = (struct85 *)data;
|
||||
int l;
|
||||
if (big->l4) { // # of remaining unencoded input bytes
|
||||
l = big->l4;
|
||||
@ -120,18 +122,19 @@ struct struct_rle85 {
|
||||
int run_length; // current length of run
|
||||
};
|
||||
|
||||
static struct_rle85 *prepare_rle85(FILE *out) // prepare to produce RLE+ASCII85-encoded output
|
||||
void *Fl_PostScript_Graphics_Driver::prepare_rle85(FILE *out) // prepare to produce RLE+ASCII85-encoded output
|
||||
{
|
||||
struct_rle85 *rle = new struct_rle85;
|
||||
rle->count = 0;
|
||||
rle->run_length = 0;
|
||||
rle->data85 = prepare85(out);
|
||||
rle->data85 = (struct85*)prepare85(out);
|
||||
return rle;
|
||||
}
|
||||
|
||||
|
||||
static void write_rle85(uchar b, struct_rle85 *rle) // sends one input byte to RLE+ASCII85 encoding
|
||||
void Fl_PostScript_Graphics_Driver::write_rle85(uchar b, void *data) // sends one input byte to RLE+ASCII85 encoding
|
||||
{
|
||||
struct_rle85 *rle = (struct_rle85 *)data;
|
||||
uchar c;
|
||||
if (rle->run_length > 0) { // if within a run
|
||||
if (b == rle->buffer[0] && rle->run_length < 128) { // the run can be extended
|
||||
@ -166,8 +169,9 @@ static void write_rle85(uchar b, struct_rle85 *rle) // sends one input byte to R
|
||||
}
|
||||
|
||||
|
||||
static void close_rle85(struct_rle85 *rle) // stop doing RLE+ASCII85 encoding
|
||||
void Fl_PostScript_Graphics_Driver::close_rle85(void *data) // stop doing RLE+ASCII85 encoding
|
||||
{
|
||||
struct_rle85 *rle = (struct_rle85 *)data;
|
||||
uchar c;
|
||||
if (rle->run_length > 0) { // if within a run, output it
|
||||
c = (uchar)(257 - rle->run_length);
|
||||
@ -408,7 +412,7 @@ void Fl_PostScript_Graphics_Driver::draw_image(Fl_Draw_Image_Cb call, void *data
|
||||
int LD=iw*D;
|
||||
uchar *rgbdata=new uchar[LD];
|
||||
uchar *curmask=mask;
|
||||
struct_rle85 *big = prepare_rle85(output);
|
||||
void *big = prepare_rle85(output);
|
||||
|
||||
if (level2_mask) {
|
||||
for (j = ih - 1; j >= 0; j--) { // output full image data
|
||||
@ -495,7 +499,7 @@ void Fl_PostScript_Graphics_Driver::draw_image_mono(const uchar *data, int ix, i
|
||||
int bg = (bg_r + bg_g + bg_b)/3;
|
||||
|
||||
uchar *curmask=mask;
|
||||
struct_rle85 *big = prepare_rle85(output);
|
||||
void *big = prepare_rle85(output);
|
||||
for (j=0; j<ih;j++){
|
||||
if (mask){
|
||||
for (k=0;k<my/ih;k++){
|
||||
@ -544,7 +548,7 @@ void Fl_PostScript_Graphics_Driver::draw_image_mono(Fl_Draw_Image_Cb call, void
|
||||
int LD=iw*D;
|
||||
uchar *rgbdata=new uchar[LD];
|
||||
uchar *curmask=mask;
|
||||
struct_rle85 *big = prepare_rle85(output);
|
||||
void *big = prepare_rle85(output);
|
||||
for (j=0; j<ih;j++){
|
||||
|
||||
if (mask && lang_level_>2){ // InterleaveType 2 mask data
|
||||
@ -624,16 +628,16 @@ void Fl_PostScript_Graphics_Driver::draw(Fl_Bitmap * bitmap,int XP, int YP, int
|
||||
|
||||
int i,j;
|
||||
push_clip(XP, YP, WP, HP);
|
||||
fprintf(output , "%i %i %i %i %i %i {A85RLE} MI\n", XP - si, YP + HP , WP , -HP , w , h);
|
||||
fprintf(output , "%i %i %i %i %i %i MI\n", XP - si, YP + HP , WP , -HP , w , h);
|
||||
|
||||
struct_rle85 *big = prepare_rle85(output);
|
||||
void *rle85 = prepare_rle85(output);
|
||||
for (j=0; j<HP; j++){
|
||||
for (i=0; i<xx; i++){
|
||||
write_rle85(swap_byte(*di), big);
|
||||
write_rle85(swap_byte(*di), rle85);
|
||||
di++;
|
||||
}
|
||||
}
|
||||
close_rle85(big);
|
||||
close_rle85(rle85);
|
||||
pop_clip();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user