mirror of
https://github.com/fltk/fltk.git
synced 2026-05-20 12:41:27 +08:00
Changed functions supporting ASCII85 and RunLength encodings as private
members of the Fl_PostScript_Graphics_Driver class. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10604 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
+8
-6
@@ -59,6 +59,14 @@ extern "C" {
|
||||
<br> FLTK standard fonts are output using the corresponding PostScript standard fonts.
|
||||
*/
|
||||
class FL_EXPORT Fl_PostScript_Graphics_Driver : public Fl_Graphics_Driver {
|
||||
private:
|
||||
void transformed_draw_extra(const char* str, int n, double x, double y, int w, bool rtl);
|
||||
void *prepare_rle85();
|
||||
void write_rle85(uchar b, void *data);
|
||||
void close_rle85(void *data);
|
||||
void *prepare85();
|
||||
void write85(void *data, const uchar *p, int len);
|
||||
void close85(void *data);
|
||||
public:
|
||||
static const char *class_id;
|
||||
const char *class_name() {return class_id;};
|
||||
@@ -132,12 +140,6 @@ 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
|
||||
|
||||
+15
-15
@@ -1067,20 +1067,20 @@ static uchar *calc_mask(uchar *img, int w, int h, Fl_Color bg)
|
||||
}
|
||||
|
||||
// write to PostScript a bitmap image of a UTF8 string
|
||||
static void transformed_draw_extra(const char* str, int n, double x, double y, int w,
|
||||
FILE *output, Fl_PostScript_Graphics_Driver *driver, bool rtl) {
|
||||
void Fl_PostScript_Graphics_Driver::transformed_draw_extra(const char* str, int n, double x, double y, int w, bool rtl)
|
||||
{
|
||||
// scale for bitmask computation
|
||||
#if defined(USE_X11) && !USE_XFT
|
||||
float scale = 1; // don't scale because we can't expect to have scalable fonts
|
||||
#else
|
||||
float scale = 2;
|
||||
#endif
|
||||
Fl_Fontsize old_size = driver->size();
|
||||
Fl_Font fontnum = driver->Fl_Graphics_Driver::font();
|
||||
Fl_Fontsize old_size = size();
|
||||
Fl_Font fontnum = Fl_Graphics_Driver::font();
|
||||
int w_scaled = (int)(w * (scale + 0.5));
|
||||
int h = (int)(driver->height() * scale);
|
||||
int h = (int)(height() * scale);
|
||||
// create an offscreen image of the string
|
||||
Fl_Color text_color = driver->Fl_Graphics_Driver::color();
|
||||
Fl_Color text_color = Fl_Graphics_Driver::color();
|
||||
Fl_Color bg_color = fl_contrast(FL_WHITE, text_color);
|
||||
Fl_Offscreen off = fl_create_offscreen(w_scaled, (int)(h+3*scale) );
|
||||
fl_begin_offscreen(off);
|
||||
@@ -1101,25 +1101,25 @@ static void transformed_draw_extra(const char* str, int n, double x, double y, i
|
||||
// read (most of) the offscreen image
|
||||
uchar *img = fl_read_image(NULL, 1, 1, w2, h, 0);
|
||||
fl_end_offscreen();
|
||||
driver->font(fontnum, old_size);
|
||||
font(fontnum, old_size);
|
||||
fl_delete_offscreen(off);
|
||||
// compute the mask of what is not the background
|
||||
uchar *mask = calc_mask(img, w2, h, bg_color);
|
||||
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 MI\n", x, y - h*0.77/scale, w2/scale, h/scale, w2, h);
|
||||
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);
|
||||
void *rle85 = prepare_rle85();
|
||||
for (int j = h - 1; j >= 0; j--){
|
||||
di = mask + j * wmask;
|
||||
for (int i = 0; i < wmask; i++){
|
||||
Fl_PostScript_Graphics_Driver::write_rle85(*di, rle85);
|
||||
write_rle85(*di, rle85);
|
||||
di++;
|
||||
}
|
||||
}
|
||||
Fl_PostScript_Graphics_Driver::close_rle85(rle85); fputc('\n', output);
|
||||
close_rle85(rle85); fputc('\n', output);
|
||||
delete[] mask;
|
||||
}
|
||||
|
||||
@@ -1153,11 +1153,11 @@ void Fl_PostScript_Graphics_Driver::transformed_draw(const char* str, int n, dou
|
||||
int w = (int)width(str, n);
|
||||
if (w == 0) return;
|
||||
if (Fl_Graphics_Driver::font() >= FL_FREE_FONT) {
|
||||
transformed_draw_extra(str, n, x, y, w, output, this, false);
|
||||
transformed_draw_extra(str, n, x, y, w, false);
|
||||
return;
|
||||
}
|
||||
fprintf(output, "%d <~", w);
|
||||
void *data = prepare85(output);
|
||||
void *data = prepare85();
|
||||
// transforms UTF8 encoding to our custom PostScript encoding as follows:
|
||||
// extract each unicode character
|
||||
// if unicode <= 0x17F, unicode and PostScript codes are identical
|
||||
@@ -1179,7 +1179,7 @@ void Fl_PostScript_Graphics_Driver::transformed_draw(const char* str, int n, dou
|
||||
}
|
||||
else { // unhandled character: draw all string as bitmap image
|
||||
fprintf(output, "~> pop pop\n"); // close and ignore the opened hex string
|
||||
transformed_draw_extra(str, n, x, y, w, output, this, false);
|
||||
transformed_draw_extra(str, n, x, y, w, false);
|
||||
return;
|
||||
}
|
||||
// 2 bytes per character, high-order byte first, encode that to ASCII85
|
||||
@@ -1191,7 +1191,7 @@ void Fl_PostScript_Graphics_Driver::transformed_draw(const char* str, int n, dou
|
||||
|
||||
void Fl_PostScript_Graphics_Driver::rtl_draw(const char* str, int n, int x, int y) {
|
||||
int w = (int)width(str, n);
|
||||
transformed_draw_extra(str, n, x - w, y, w, output, this, true);
|
||||
transformed_draw_extra(str, n, x - w, y, w, true);
|
||||
}
|
||||
|
||||
void Fl_PostScript_Graphics_Driver::concat(){
|
||||
|
||||
+12
-14
@@ -33,7 +33,6 @@
|
||||
// as described in "PostScript LANGUAGE REFERENCE third edition" p. 131
|
||||
//
|
||||
struct struct85 {
|
||||
FILE* outfile; // receives ASCII85-encoded output
|
||||
uchar bytes4[4]; // holds up to 4 input bytes
|
||||
int l4; // # of unencoded input bytes
|
||||
int blocks; // counter to insert newlines after 80 output characters
|
||||
@@ -41,10 +40,9 @@ struct struct85 {
|
||||
};
|
||||
|
||||
|
||||
void *Fl_PostScript_Graphics_Driver::prepare85(FILE *outfile) // prepare to produce ASCII85-encoded output
|
||||
void *Fl_PostScript_Graphics_Driver::prepare85() // prepare to produce ASCII85-encoded output
|
||||
{
|
||||
struct85 *big = new struct85;
|
||||
big->outfile = outfile;
|
||||
big->l4 = 0;
|
||||
big->blocks = 0;
|
||||
return big;
|
||||
@@ -83,9 +81,9 @@ void Fl_PostScript_Graphics_Driver::write85(void *data, const uchar *p, int len)
|
||||
big->l4 += c;
|
||||
if (big->l4 == 4) {
|
||||
c = convert85(big->bytes4, big->chars5);
|
||||
fwrite(big->chars5, c, 1, big->outfile);
|
||||
fwrite(big->chars5, c, 1, output);
|
||||
big->l4 = 0;
|
||||
if (++big->blocks >= 16) { fputc('\n', big->outfile); big->blocks = 0; }
|
||||
if (++big->blocks >= 16) { fputc('\n', output); big->blocks = 0; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,9 +98,9 @@ void Fl_PostScript_Graphics_Driver::close85(void *data) // stops ASCII85-encodi
|
||||
while (l < 4) big->bytes4[l++] = 0; // complete them with 0s
|
||||
l = convert85(big->bytes4, big->chars5); // encode them
|
||||
if (l == 1) memset(big->chars5, '!', 5);
|
||||
fwrite(big->chars5, big->l4 + 1, 1, big->outfile);
|
||||
fwrite(big->chars5, big->l4 + 1, 1, output);
|
||||
}
|
||||
fputs("~>", big->outfile); // write EOD mark
|
||||
fputs("~>", output); // write EOD mark
|
||||
delete big;
|
||||
}
|
||||
|
||||
@@ -122,12 +120,12 @@ struct struct_rle85 {
|
||||
int run_length; // current length of run
|
||||
};
|
||||
|
||||
void *Fl_PostScript_Graphics_Driver::prepare_rle85(FILE *out) // prepare to produce RLE+ASCII85-encoded output
|
||||
void *Fl_PostScript_Graphics_Driver::prepare_rle85() // prepare to produce RLE+ASCII85-encoded output
|
||||
{
|
||||
struct_rle85 *rle = new struct_rle85;
|
||||
rle->count = 0;
|
||||
rle->run_length = 0;
|
||||
rle->data85 = (struct85*)prepare85(out);
|
||||
rle->data85 = (struct85*)prepare85();
|
||||
return rle;
|
||||
}
|
||||
|
||||
@@ -412,7 +410,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;
|
||||
void *big = prepare_rle85(output);
|
||||
void *big = prepare_rle85();
|
||||
|
||||
if (level2_mask) {
|
||||
for (j = ih - 1; j >= 0; j--) { // output full image data
|
||||
@@ -424,7 +422,7 @@ void Fl_PostScript_Graphics_Driver::draw_image(Fl_Draw_Image_Cb call, void *data
|
||||
}
|
||||
}
|
||||
close_rle85(big); fputc('\n', output);
|
||||
big = prepare_rle85(output);
|
||||
big = prepare_rle85();
|
||||
for (j = ih - 1; j >= 0; j--) { // output mask data
|
||||
curmask = mask + j * (my/ih) * ((mx+7)/8);
|
||||
for (k=0; k < my/ih; k++) {
|
||||
@@ -498,7 +496,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;
|
||||
void *big = prepare_rle85(output);
|
||||
void *big = prepare_rle85();
|
||||
for (j=0; j<ih;j++){
|
||||
if (mask){
|
||||
for (k=0;k<my/ih;k++){
|
||||
@@ -547,7 +545,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;
|
||||
void *big = prepare_rle85(output);
|
||||
void *big = prepare_rle85();
|
||||
for (j=0; j<ih;j++){
|
||||
|
||||
if (mask && lang_level_>2){ // InterleaveType 2 mask data
|
||||
@@ -629,7 +627,7 @@ void Fl_PostScript_Graphics_Driver::draw(Fl_Bitmap * bitmap,int XP, int YP, int
|
||||
push_clip(XP, YP, WP, HP);
|
||||
fprintf(output , "%i %i %i %i %i %i MI\n", XP - si, YP + HP , WP , -HP , w , h);
|
||||
|
||||
void *rle85 = prepare_rle85(output);
|
||||
void *rle85 = prepare_rle85();
|
||||
for (j=0; j<HP; j++){
|
||||
for (i=0; i<xx; i++){
|
||||
write_rle85(swap_byte(*di), rle85);
|
||||
|
||||
Reference in New Issue
Block a user