Index: xc/programs/Xserver/Xprint/ps/psout.c =================================================================== RCS file: /cvs/xorg/xc/programs/Xserver/Xprint/ps/psout.c,v retrieving revision 1.5 diff -u -2 -0 -r1.5 psout.c --- ps/psout.c 4 Oct 2004 05:34:32 -0000 1.5 +++ ps/psout.c 12 Apr 2005 14:52:23 -0000 @@ -292,93 +292,94 @@ /* * Setup definitions */ static char *S_SetupDefs = "\ /mx_ mx d\ /im_ mx d\ /tm1_ mx d\ /tm2_ mx d\ /str3 3 str d\ /str1 1 str d\ "; /******************************************************************* * PRIVATE FUNCTIONS * *******************************************************************/ void S_Flush(PsOutPtr self) { - if( self->Buf[0] ) - { - if( self->Buf[strlen(self->Buf)-1]!='\n' ) strcat(self->Buf, "\n"); - - if (!ferror(self->Fp)) { - (void) fputs(self->Buf, self->Fp); - } - - self->Buf[0] = '\0'; - } + int len; + + if( self->Buf[0] == '\0' ) + return; + len = strlen(self->Buf); + if( self->Buf[len-1] != '\n' ) { self->Buf[len++] = '\n'; self->Buf[len] = '\0'; } + fwrite(self->Buf, len, 1, self->Fp); + self->Buf[0] = '\0'; } static void S_Comment(PsOutPtr self, char *comment) { S_Flush(self); strcpy(self->Buf, comment); S_Flush(self); } static void S_OutDefs(PsOutPtr self, char *defs) { int i, k=0; S_Flush(self); memset(self->Buf, 0, sizeof(self->Buf)); for( i=0 ; defs[i]!='\0' ;) { if( k>70 && (i==0 || (i && defs[i-1]!='/')) && (defs[i]==' ' || defs[i]=='/' || defs[i]=='{') ) { S_Flush(self); k = 0; memset(self->Buf, 0, sizeof(self->Buf)); } if( k && self->Buf[k-1]==' ' && defs[i]==' ' ) { i++; continue; } self->Buf[k] = defs[i]; k++; i++; } S_Flush(self); } void S_OutNum(PsOutPtr self, float num) { int i; char buf[64]; + int len; + sprintf(buf, "%.3f", num); for( i=strlen(buf)-1 ; buf[i]=='0' ; i-- ); buf[i+1] = '\0'; - if( buf[strlen(buf)-1]=='.' ) buf[strlen(buf)-1] = '\0'; - if( self->Buf[0] ) strcat(self->Buf, " "); - strcat(self->Buf, buf); - if( strlen(self->Buf)>70 ) S_Flush(self); + i = strlen(buf)-1; if( buf[i]=='.' ) buf[i] = '\0'; + len = strlen(self->Buf); + if( len > 0 ) { self->Buf[len++] = ' '; self->Buf[len] = '\0'; } + strcpy(&self->Buf[len], buf); + if( (len+i)>70 ) S_Flush(self); } static void S_OutStr(PsOutPtr self, char *txt, int txtl) { int i, k; char buf[1024]; for( i=0,k=0 ; i=' ' && txt[i]<='~') && txt[i]!='(' && txt[i]!=')' && txt[i]!='\\' ) { buf[k] = txt[i]; k++; continue; } buf[k] = '\\'; k++; sprintf(&buf[k], "%03o", txt[i]&0xFF); /* Skip to the end of the buffer */ while( buf[k] != '\0' ) k++; } strcat(self->Buf, "("); i = strlen(self->Buf); @@ -399,42 +400,47 @@ if( (txt[i]>=' ' && txt[i]<='~') && txt[i]!='(' && txt[i]!=')' && txt[i]!='\\' ) { buf[k] = txt[i]; k++; continue; } buf[k] = '\\'; k++; sprintf(&buf[k], "%03o", txt[i]&0xFFFF); /* Skip to the end of the buffer */ while( buf[k] != '\0' ) k++; } strcat(self->Buf, "("); i = strlen(self->Buf); memcpy(&self->Buf[i], buf, k); self->Buf[i+k] = '\0'; strcat(self->Buf, ")"); if( strlen(self->Buf)>70 ) S_Flush(self); } void S_OutTok(PsOutPtr self, char *tok, int cr) { - if( self->Buf[0] ) strcat(self->Buf, " "); - strcat(self->Buf, tok); + int len = strlen(self->Buf); + if( len > 0 ) + { + self->Buf[len++] = ' '; + self->Buf[len] = '\0'; + } + strcpy(&self->Buf[len], tok); if( cr ) S_Flush(self); } static void S_Color(PsOutPtr self, PsOutColor clr) { int ir, ig, ib; ir = PSOUTCOLOR_TO_REDBITS(clr); ig = PSOUTCOLOR_TO_GREENBITS(clr); ib = PSOUTCOLOR_TO_BLUEBITS(clr); if( ir==ig && ig==ib ) { S_OutNum(self, PSOUTCOLOR_BITS_TO_PSFLOAT(ir)); S_OutTok(self, "g", 1); } else { S_OutNum(self, PSOUTCOLOR_BITS_TO_PSFLOAT(ir)); S_OutNum(self, PSOUTCOLOR_BITS_TO_PSFLOAT(ig)); S_OutNum(self, PSOUTCOLOR_BITS_TO_PSFLOAT(ib)); S_OutTok(self, "sc", 1); } } @@ -1458,49 +1464,63 @@ #endif self->ImageFormat = 0; self->RevImage = 0; #ifdef BM_CACHE if(self->start_image) { self->start_image = 0; S_OutTok(self, "gr", 0); } else S_OutTok(self, "gr", 1); #else S_OutTok(self, "gr", 1); #endif } void PsOut_OutImageBytes(PsOutPtr self, int nBytes, char *bytes) { int i; - char buf[5]; + int b; + int len; + const char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; if( (!self->ImageFormat) || self->ImgSkip ) return; + + len = strlen(self->Buf); + for( i=0 ; iRevImage ) sprintf(buf, "%02x", (int)(bytes[i]^0xFF)&0xFF); - else sprintf(buf, "%02x", (int)bytes[i]&0xFF); - strcat(self->Buf, buf); - if( strlen(self->Buf)>70 ) S_Flush(self); + if( self->RevImage ) b = (int)((bytes[i]^0xFF)&0xFF); + else b = (int)(bytes[i]&0xFF); + + self->Buf[len++] = hex[(b&0xF0) >> 4]; + self->Buf[len++] = hex[(b&0x0F)]; + self->Buf[len] = '\0'; + + if( len>70 ) + { + S_Flush(self); + len = 0; + } } } void PsOut_BeginFrame(PsOutPtr self, int xoff, int yoff, int x, int y, int w, int h) { int xo = self->XOff; int yo = self->YOff; if( self->InFrame ) xo = yo = 0; S_OutTok(self, "gs", 0); S_OutNum(self, (float)(x+xo)); S_OutNum(self, (float)(y+yo)); S_OutNum(self, (float)w); S_OutNum(self, (float)h); S_OutTok(self, "R cl n", 0); xoff += xo; yoff += yo; if( xoff || yoff ) {