Author: manolo
Date: 2010-03-12 03:14:32 -0800 (Fri, 12 Mar 2010)
New Revision: 7244
Log:
Added support for PostScript level 2 output of Fl_Pixmap's transparent
background.
Modified:
branches/branch-1.3-Fl_Printer/FL/Fl_Printer.H
branches/branch-1.3-Fl_Printer/src/Fl_PS_Printer.cxx
branches/branch-1.3-Fl_Printer/src/ps_image.cxx
Modified: branches/branch-1.3-Fl_Printer/FL/Fl_Printer.H
===================================================================
--- branches/branch-1.3-Fl_Printer/FL/Fl_Printer.H 2010-03-11 07:31:35 UTC
(rev 7243)
+++ branches/branch-1.3-Fl_Printer/FL/Fl_Printer.H 2010-03-12 11:14:32 UTC
(rev 7244)
@@ -48,7 +48,7 @@
void *gc; // the printer's graphics context, if there's one, NULL otherwise
void delete_image_list(); // deletes the page image list
#ifndef FL_DOXYGEN
- Fl_Virtual_Printer(void) { gc = NULL; };
+ Fl_Virtual_Printer(void) { gc = NULL; bg_r_ = bg_g_ = bg_b_ = 0; };
#endif
public:
#ifdef FL_DOXYGEN
Modified: branches/branch-1.3-Fl_Printer/src/Fl_PS_Printer.cxx
===================================================================
--- branches/branch-1.3-Fl_Printer/src/Fl_PS_Printer.cxx 2010-03-11
07:31:35 UTC (rev 7243)
+++ branches/branch-1.3-Fl_Printer/src/Fl_PS_Printer.cxx 2010-03-12
11:14:32 UTC (rev 7244)
@@ -221,6 +221,55 @@
;
+static const char * prolog_2_pixmap = // prolog relevant only if lang_level
== 2 for pixmaps
+"/pixmap_size { /pixmap_sy exch def /pixmap_sx exch def } bind def\n"
+
+"/pixmap_mat {[ pixmap_sx 0 0 pixmap_sy neg 0 pixmap_sy ]} bind def\n"
+
+"/pixmap_dict {"
+"<< /PatternType 1 "
+"/PaintType 1 "
+"/TilingType 2 "
+"/BBox [0 0 pixmap_sx pixmap_sy] "
+"/XStep pixmap_sx "
+"/YStep pixmap_sy\n"
+"/PaintProc "
+"{ begin "
+"pixmap_sx pixmap_sy scale "
+"pixmap_sx pixmap_sy 8 "
+"pixmap_mat "
+"pixmap_data "
+"false 3 "
+"colorimage "
+"end "
+"} bind "
+">>\n"
+"} bind def\n"
+
+"/pixmap_plot {"
+"GS "
+"/pixmap_y exch def /pixmap_x exch def\n"
+"pixmap_x pixmap_y translate\n"
+"pixmap_dict matrix makepattern setpattern\n"
+"pixmap_sx pixmap_sy scale\n"
+"pixmap_sx pixmap_sy\n"
+"true\n"
+"pixmap_mat\n"
+"pixmap_mask\n"
+"imagemask\n"
+"GR\n"
+"} bind def\n"
+
+"/pixmap_loaddata { /pixmap_data currentfile pixmap_sx pixmap_sy 3 mul mul
string readhexstring "
+"} bind def\n"
+
+"/pixmap_loadmask { "
+"/pixmap_mask currentfile pixmap_sx 8 div ceiling cvi pixmap_sy mul string
readhexstring "
+"} bind def\n"
+;
+
+
+
static const char * prolog_3 = // prolog relevant only if lang_level >2
// masked color images
@@ -316,7 +365,6 @@
close_cmd_ = 0;
//lang_level_ = 3;
lang_level_ = 2;
- //lang_level_ = 1;
mask = 0;
ps_filename_ = NULL;
type_ = postscript_device;
@@ -353,22 +401,26 @@
fputs("%%EndFeature\n", output);
fputs("%%EndComments\n", output);
fputs(prolog, output);
- if(lang_level_ >1)
+ if (lang_level_ > 1) {
fputs(prolog_2, output);
- if(lang_level_ >2)
+ }
+ if (lang_level_ == 2) {
+ fputs(prolog_2_pixmap, output);
+ }
+ if (lang_level_ > 2)
fputs(prolog_3, output);
- if(lang_level_>=3){
+ if (lang_level_ >= 3) {
fputs("/CS { clipsave } bind def\n", output);
fputs("/CR { cliprestore } bind def\n", output);
- }else{
+ } else {
fputs("/CS { GS } bind def\n", output);
fputs("/CR { GR } bind def\n", output);
}
- page_policy_=1;
+ page_policy_ = 1;
fputs("%%EndProlog\n",output);
- if(lang_level_>=2)
+ if (lang_level_ >= 2)
fprintf(output,"<< /Policies << /Pagesize 1 >> >> setpagedevice\n");
reset();
@@ -494,7 +546,6 @@
void Fl_PSfile_Device::rectf(int x, int y, int w, int h) {
fprintf(output, "%g %g %i %i FR\n", x-0.5, y-0.5, w, h);
- Fl::get_color(color_, bg_r_, bg_g_, bg_b_);
}
void Fl_PSfile_Device::line(int x1, int y1, int x2, int y2) {
Modified: branches/branch-1.3-Fl_Printer/src/ps_image.cxx
===================================================================
--- branches/branch-1.3-Fl_Printer/src/ps_image.cxx 2010-03-11 07:31:35 UTC
(rev 7243)
+++ branches/branch-1.3-Fl_Printer/src/ps_image.cxx 2010-03-12 11:14:32 UTC
(rev 7244)
@@ -273,53 +273,88 @@
void Fl_PSfile_Device::draw_scaled_image(Fl_Draw_Image_Cb call, void *data,
double x, double y, double w, double h, int iw, int ih, int D) {
-
+ int level2_mask = 0;
fprintf(output,"save\n");
int i,j,k;
char * interpol;
- if(lang_level_>1){
- if(interpolate_) interpol="true";
+ if (lang_level_ > 1) {
+ if (interpolate_) interpol="true";
else interpol="false";
- if(mask && lang_level_>2)
+ if (mask && lang_level_ > 2) {
fprintf(output, "%g %g %g %g %i %i %i %i %s CIM\n", x , y+h , w , -h ,
iw , ih, mx, my, interpol);
- else
+ }
+ else if (mask && lang_level_ == 2) {
+ level2_mask = 1; // use method for drawing masked color image with
PostScript level 2
+ fprintf(output, "%d %d pixmap_size\n pixmap_loadmask\n", iw, ih);
+ }
+ else {
fprintf(output, "%g %g %g %g %i %i %s CII\n", x , y+h , w , -h , iw ,
ih, interpol);
- }else
+ }
+ } else {
fprintf(output , "%g %g %g %g %i %i CI", x , y+h , w , -h , iw , ih);
+ }
int LD=iw*D;
uchar *rgbdata=new uchar[LD];
uchar *curmask=mask;
- for (j=0; j<ih;j++){
- if(mask && lang_level_>2){ // InterleaveType 2 mask data
- for(k=0; k<my/ih;k++){ //for alpha pseudo-masking
- for (i=0; i<((mx+7)/8);i++){
- if (!(i%40)) fprintf(output, "\n");
- fprintf(output, "%.2x",swap_byte(*curmask));
- curmask++;
- }
- fprintf(output,"\n");
+ if(level2_mask) {
+ for (j = ih - 1; j >= 0; j--) {
+ curmask = mask + j * my/ih * ((mx+7)/8);
+ for(k=0; k < my/ih; k++) { // output mask data
+ for (i=0; i < ((mx+7)/8); i++) {
+ fprintf(output, "%.2x",swap_byte(*curmask));
+ curmask++;
+ }
+ fprintf(output,"\n");
+ }
}
+ fprintf(output,"pop def\n\npixmap_loaddata\n");
+ for (j = ih - 1; j >= 0; j--) { // output full image data
+ call(data,0,j,iw,rgbdata);
+ uchar *curdata=rgbdata;
+ for(i=0 ; i<iw ; i++) {
+ uchar r = curdata[0];
+ uchar g = curdata[1];
+ uchar b = curdata[2];
+ //if (!(i%40)) fprintf(output, "\n");
+ fprintf(output, "%.2x%.2x%.2x", r, g, b);
+ curdata += D;
+ }
+ fprintf(output,"\n");
+ }
+ fprintf(output,"pop def\n\n%g %g pixmap_plot\n", x, y); // draw the masked
image
}
- call(data,0,j,iw,rgbdata);
- uchar *curdata=rgbdata;
- for(i=0 ; i<iw ; i++) {
- uchar r = curdata[0];
- uchar g = curdata[1];
- uchar b = curdata[2];
+ else {
+ for (j=0; j<ih;j++) {
+ if(mask && lang_level_ > 2) { // InterleaveType 2 mask data
+ for(k=0; k<my/ih;k++) { //for alpha pseudo-masking
+ for (i=0; i<((mx+7)/8);i++) {
+ if (!(i%40)) fprintf(output, "\n");
+ fprintf(output, "%.2x",swap_byte(*curmask));
+ curmask++;
+ }
+ fprintf(output,"\n");
+ }
+ }
+ call(data,0,j,iw,rgbdata);
+ uchar *curdata=rgbdata;
+ for(i=0 ; i<iw ; i++) {
+ uchar r = curdata[0];
+ uchar g = curdata[1];
+ uchar b = curdata[2];
+ if (!(i%40)) fprintf(output, "\n");
+ fprintf(output, "%.2x%.2x%.2x", r, g, b);
- if (!(i%40)) fprintf(output, "\n");
- fprintf(output, "%.2x%.2x%.2x", r, g, b);
+ curdata +=D;
+ }
+ fprintf(output,"\n");
- curdata +=D;
}
- fprintf(output,"\n");
+ fprintf(output,">\n");
+ }
- }
- fprintf(output,">\n");
-
fprintf(output,"restore\n");
delete[] rgbdata;
}
@@ -443,7 +478,7 @@
mx = WP;
my = HP;
push_clip(XP, YP, WP, HP);
- fl_draw_pixmap(di,XP -cx, YP -cy, fl_rgb_color(bg_r_, bg_g_, bg_b_) );
//yes, it is dirty, but fl is dispatched, so it works!
+ fl_draw_pixmap(di,XP -cx, YP -cy, FL_BLACK );
pop_clip();
delete[] mask;
mask=0;
_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit