⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 t1x11.c

📁 source code: Covert TXT to PDF
💻 C
📖 第 1 页 / 共 2 页
字号:
  height=pglyph->metrics.ascent-pglyph->metrics.descent;  	         /* Correct position */  if (T1_lposition){    x_dest += pglyph->metrics.leftSideBearing;    y_dest -= pglyph->metrics.ascent;  }  if (opaque==0){    clipmask_v=height;    clipmask_h=width;    width_pad=PAD(width*T1aa_bpp, pFontBase->bitmap_pad)/T1aa_bpp;    clipmask_ptr=(char *)calloc((PAD(clipmask_h, 8)>>3) * clipmask_v, sizeof( char));     if (clipmask_ptr==NULL){      T1_errno=T1ERR_ALLOC_MEM;      return(NULL);    }    /* Note: We pad the clipmask always to byte boundary */    if (pglyph->bpp==8)      for ( k=0; k<clipmask_v; k++){	line_off=k*(PAD(clipmask_h, 8)>>3);	for (j=0; j<clipmask_h; j++){	  if (((char *)(pglyph->bits))[k*width_pad+j]!=bg)	    clipmask_ptr[line_off+(j>>3)] |= (0x01<<(j%8));	}      }    else if (pglyph->bpp==16)      for ( k=0; k<clipmask_v; k++){	line_off=k*(PAD(clipmask_h, 8)>>3);	for (j=0; j<clipmask_h; j++){	  if (((T1_AA_TYPE16 *)(pglyph->bits))[k*width_pad+j]!=(T1_AA_TYPE16)bg)	    clipmask_ptr[line_off+(j>>3)] |= (0x01<<(j%8));	}      }    else       for ( k=0; k<clipmask_v; k++){	line_off=k*(PAD(clipmask_h, 8)>>3);	for (j=0; j<clipmask_h; j++){	  if (((T1_AA_TYPE32 *)(pglyph->bits))[k*width_pad+j]!=(T1_AA_TYPE32)bg)	    clipmask_ptr[line_off+(j>>3)] |= (0x01<<(j%8));	}      }        clipmask=XCreateBitmapFromData( T1_display,				    d,				    (char *)clipmask_ptr,				    width,				    height				    );    free( clipmask_ptr);    XSetClipMask(T1_display, gc, clipmask);    XSetClipOrigin(T1_display, gc, x_dest, y_dest);  }  ximage=XCreateImage( T1_display,		       T1_visual,		       T1_depth, 		       ZPixmap, /* XYBitmap or XYPixmap */		       0, /* No offset */		       (char *)pglyph->bits,		       width,		       height,		       pFontBase->bitmap_pad,  		       0 /*PAD(width,8)/8*/  /* number of bytes per line */		       );  ximage->byte_order=T1_byte_order;  XPutImage(T1_display,	    d,	    gc,	    ximage,	    0,  	    0,  	    x_dest,  	    y_dest,  	    width,	    height	    );  XDestroyImage(ximage);  if (clipmask){    XFreePixmap( T1_display, clipmask);    clipmask=0;    XSetClipMask(T1_display, gc, None);    XSetClipOrigin(T1_display, gc, 0, 0);  }    pglyph->bits=NULL;    /* Since XDestroyImage() free's this also! */  xglyph.metrics.leftSideBearing=pglyph->metrics.leftSideBearing;  xglyph.metrics.rightSideBearing=pglyph->metrics.rightSideBearing;  xglyph.metrics.advanceX=pglyph->metrics.advanceX;  xglyph.metrics.advanceY=pglyph->metrics.advanceY;  xglyph.metrics.ascent=pglyph->metrics.ascent;  xglyph.metrics.descent=pglyph->metrics.descent;  xglyph.bpp=pglyph->bpp;    return( &xglyph);    }/* T1_AASetStringX(...): Draw a string of characters into an X11 drawable */GLYPH *T1_AASetStringX( Drawable d, GC gc, int mode, int x_dest, int y_dest,			int FontID, char *string, int len, 			long spaceoff, int modflag, float size,			T1_TMATRIX *transform){  int  j, k;  GLYPH  *pglyph;  XImage *ximage;    static GLYPH xglyph={NULL,{0,0,0,0,0,0},NULL,0};  int height, width, width_pad;    XGCValues xgcvalues;  static unsigned long fg, bg;    Pixmap clipmask=0;  int clipmask_h, clipmask_v, line_off;  char *clipmask_ptr;    int opaque;    xglyph.metrics.leftSideBearing=0;  xglyph.metrics.rightSideBearing=0;  xglyph.metrics.advanceX=0;  xglyph.metrics.advanceY=0;  xglyph.metrics.ascent=0;  xglyph.metrics.descent=0;  xglyph.pFontCacheInfo=NULL;    opaque=mode;      /* In order to be able to contruct the pixmap we need to know     foreground and background color as well the copy function */  XGetGCValues( T1_display, gc, T1GCMASK, &xgcvalues);  fg=xgcvalues.foreground;  bg=xgcvalues.background;    xglyph.bpp=T1_depth;    /* At this point we must compute the colors that are needed to do     antialiasing between fore- and background. The following function     fills the static aacolors */  if (T1aa_SmartOn==0)    j=T1_AAGetLevel();  else if (size>=T1aa_smartlimit2)    j=1;  else if (size>=T1aa_smartlimit1)    j=2;  else    j=4;  if ( j!=lastlevel || fg!=oldfg || bg!=oldbg ){    switch ( j){    case 1:      if ( fg!=oldfg_n || bg!=oldbg_n){	oldfg_n=fg;	oldbg_n=bg;	/* computing colors is not necessary here */	T1_AANSetGrayValues( bg, fg);      }      break;    case 2:      if ( fg!=oldfg_l || bg!=oldbg_l){	T1_ComputeAAColorsX( fg, bg, AAMAXPLANES);	/*~derekn*/	/* If fg=bg, the clipmask will be messed up; in this case  */	/* we can arbitrarily change bg to get a correct clipmask. */	if (opaque == 0 && fg == bg)	  aapixels[0] = bg = (fg > 0) ? fg - 1 : fg + 1;	oldfg_l=fg;	oldbg_l=bg;	T1_AASetGrayValues(aapixels[0],   /* white */			   aapixels[4],			   aapixels[8],			   aapixels[12],			   aapixels[16] ); /* black */      }      break;    case 4:      if ( fg!=oldfg_h || bg!=oldbg_h){	T1_ComputeAAColorsX( fg, bg, AAMAXPLANES);	/*~derekn*/	/* If fg=bg, the clipmask will be messed up; in this case  */	/* we can arbitrarily change bg to get a correct clipmask. */	if (opaque == 0 && fg == bg)	  aapixels[0] = bg = (fg > 0) ? fg - 1 : fg + 1;	oldfg_h=fg;	oldbg_h=bg;	T1_AAHSetGrayValues( aapixels);       }      break;    }    lastlevel=j;    oldfg=fg;    oldbg=bg;  }    if ((pglyph=T1_AASetString( FontID, string, len, 			      spaceoff, modflag, size,			      transform))==NULL){    T1_PrintLog( "T1_AASetStringX()",		 "T1_AASetString() returned NULL-pointer!",		 T1LOG_WARNING);    return(NULL);  }  /* Check for empty bitmap */  if (pglyph->bits==NULL) {    xglyph=*pglyph;    return( &xglyph);  }  width=pglyph->metrics.rightSideBearing-pglyph->metrics.leftSideBearing;  height=pglyph->metrics.ascent-pglyph->metrics.descent;      /* Correct position */  if (T1_lposition){    x_dest += pglyph->metrics.leftSideBearing;    y_dest -= pglyph->metrics.ascent;  }  if (opaque==0){    clipmask_v=height;    clipmask_h=width;    width_pad=PAD(width*T1aa_bpp, pFontBase->bitmap_pad)/T1aa_bpp;    clipmask_ptr=(char *)calloc((PAD(clipmask_h, 8)>>3) * clipmask_v, sizeof( char));    if (clipmask_ptr==NULL){      T1_errno=T1ERR_ALLOC_MEM;      return(NULL);    }    /* Note: We pad the clipmask always to byte boundary */    if (pglyph->bpp==8)      for ( k=0; k<clipmask_v; k++){	line_off=k*(PAD(clipmask_h, 8)>>3);	for (j=0; j<clipmask_h; j++){	  if (((char *)(pglyph->bits))[k*width_pad+j]!=bg)	    clipmask_ptr[line_off+(j>>3)] |= (0x01<<(j%8));	}      }    else if (pglyph->bpp==16)      for ( k=0; k<clipmask_v; k++){	line_off=k*(PAD(clipmask_h, 8)>>3);	for (j=0; j<clipmask_h; j++){	  if (((T1_AA_TYPE16 *)(pglyph->bits))[k*width_pad+j]!=(T1_AA_TYPE16)bg)	    clipmask_ptr[line_off+(j>>3)] |= (0x01<<(j%8));	}      }    else       for ( k=0; k<clipmask_v; k++){	line_off=k*(PAD(clipmask_h, 8)>>3);	for (j=0; j<clipmask_h; j++){	  if (((T1_AA_TYPE32 *)(pglyph->bits))[k*width_pad+j]!=(T1_AA_TYPE32)bg)	    clipmask_ptr[line_off+(j>>3)] |= (0x01<<(j%8));	}      }        clipmask=XCreateBitmapFromData( T1_display,				    d,				    (char *)clipmask_ptr,				    width,				    height				    );    free( clipmask_ptr);    XSetClipMask(T1_display, gc, clipmask);    XSetClipOrigin(T1_display, gc, x_dest, y_dest);  }  ximage=XCreateImage( T1_display,		       T1_visual,		       T1_depth, 		       ZPixmap, /* XYBitmap or XYPixmap */		       0, /* No offset */		       (char *)pglyph->bits,		       width,		       height,		       pFontBase->bitmap_pad,  /* lines padded to bytes */		       0 /*PAD(width,8)/8*/  /* number of bytes per line */		       );  ximage->byte_order=T1_byte_order;  XPutImage(T1_display,	    d,	    gc,	    ximage,	    0,  	    0,  	    x_dest,  	    y_dest,  	    width,	    height	    );  XDestroyImage(ximage);  if (clipmask){    XFreePixmap( T1_display, clipmask);    clipmask=0;    XSetClipMask(T1_display, gc, None);    XSetClipOrigin(T1_display, gc, 0, 0);  }    pglyph->bits=NULL;    /* Since XDestroyImage() free's this also! */  xglyph.metrics.leftSideBearing=pglyph->metrics.leftSideBearing;  xglyph.metrics.rightSideBearing=pglyph->metrics.rightSideBearing;  xglyph.metrics.advanceX=pglyph->metrics.advanceX;  xglyph.metrics.advanceY=pglyph->metrics.advanceY;  xglyph.metrics.ascent=pglyph->metrics.ascent;  xglyph.metrics.descent=pglyph->metrics.descent;  xglyph.bpp=pglyph->bpp;    return( &xglyph);    }/* T1_ComputeAAColorsX(): Compute the antialiasing colors in dependency   of foreground and background */int T1_ComputeAAColorsX( unsigned long fg, unsigned long bg, int nolevels){  static unsigned long last_fg;  static unsigned long last_bg;  unsigned long delta_red, delta_green, delta_blue;  int i;  int nocolors=0;      aacolors[0].pixel=bg;  aacolors[nolevels-1].pixel=fg;  if ((fg==last_fg)&&(bg==last_bg))    return(nocolors);    /* Get RGB values for fore- and background */  XQueryColor( T1_display, T1_colormap, &aacolors[0]);  XQueryColor( T1_display, T1_colormap, &aacolors[nolevels-1]);  delta_red   = (aacolors[nolevels-1].red - aacolors[0].red)/(nolevels-1);  delta_green = (aacolors[nolevels-1].green - aacolors[0].green)/(nolevels-1);  delta_blue  = (aacolors[nolevels-1].blue - aacolors[0].blue)/(nolevels-1);  aapixels[0]=aacolors[0].pixel;  aapixels[nolevels-1]=aacolors[nolevels-1].pixel;    for (i=1; i<nolevels-1; i++){    aacolors[i].red   = aacolors[i-1].red + delta_red;    aacolors[i].green = aacolors[i-1].green + delta_green;    aacolors[i].blue  = aacolors[i-1].blue + delta_blue;    /* Allocate color in current palette */    if (XAllocColor( T1_display, T1_colormap, &aacolors[i])!=0){      aapixels[i]=aacolors[i].pixel;      nocolors++;    }      }    return(nocolors);}/* Set the positioning switch */void T1_LogicalPositionX( int pos_switch){  if (pos_switch)    T1_lposition=1;  else    T1_lposition=0;  return;}XImage *T1_XImageFromGlyph( GLYPH *pglyph){  XImage *ximage;    /* Check for empty bitmap */  if (pglyph->bits==NULL) {    T1_errno=T1ERR_INVALID_PARAMETER;    return( NULL);  }  if (pglyph->bpp==1) { /* we have a bitmap glyph */    ximage=XCreateImage( T1_display,			 T1_visual,			 1, 			 XYBitmap, /* XYBitmap or XYPixmap */			 0, /* No offset */			 (char *)pglyph->bits,			 pglyph->metrics.rightSideBearing-pglyph->metrics.leftSideBearing,			 pglyph->metrics.ascent-pglyph->metrics.descent,			 pFontBase->bitmap_pad,  			 0  /* number of bytes per line */			 );  }  else { /* we have an anztialiased glyph */    ximage=XCreateImage( T1_display,			 T1_visual,			 T1_depth, 			 ZPixmap, /* XYBitmap or XYPixmap */			 0, /* No offset */			 (char *)pglyph->bits,			 pglyph->metrics.rightSideBearing-pglyph->metrics.leftSideBearing,			 pglyph->metrics.ascent-pglyph->metrics.descent,			 pFontBase->bitmap_pad,  			 0  /* number of bytes per line */			 );  }    if (ximage==NULL) {    T1_errno=T1ERR_X11;    return( NULL);  }  ximage->byte_order=T1_byte_order; /* Set t1lib磗 byteorder */  return( ximage);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -