📄 t1aaset.c
字号:
} /* restore level */ T1aa_level=savelevel; return(&aastring_glyph); } /* Set some looping parameters for subsampling */ if (lsb<0){ aalsb=lsb/T1aa_level-1; aahstart=T1aa_level+(lsb%T1aa_level); } else{ aalsb=lsb/T1aa_level; aahstart=lsb%T1aa_level; } /* The horizontal number of steps: */ n_horz=(wd+aahstart+T1aa_level-1)/T1aa_level; /* And the padded value */ n_horz_pad=PAD( n_horz*T1aa_bpp, pFontBase->bitmap_pad )>>3; /* vertical number of steps: */ if (asc % T1aa_level){ /* not aligned */ if ( asc > 0){ n_asc=asc/T1aa_level+1; v_start=asc % T1aa_level; } else{ n_asc=asc/T1aa_level; v_start=T1aa_level + (asc % T1aa_level); } } else{ n_asc=asc/T1aa_level; v_start=T1aa_level; } if (dsc % T1aa_level){ /* not aligned */ if ( dsc < 0){ n_dsc=dsc/T1aa_level-1; v_end=-(dsc % T1aa_level); } else{ n_dsc=dsc/T1aa_level; v_end=T1aa_level - (dsc % T1aa_level); } } else{ n_dsc=dsc/T1aa_level; v_end=T1aa_level; } /* the total number of lines: */ n_vert=n_asc-n_dsc; /* Allocate memory for glyph */ memsize = n_horz_pad*n_vert; /* Note: we allocate 12 bytes more than necessary */ aastring_glyph.bits = (char *)malloc(memsize*sizeof( char) +12); if (aastring_glyph.bits == NULL) { T1_errno=T1ERR_ALLOC_MEM; return(NULL); } paddedW=PAD(wd,pFontBase->bitmap_pad)/8; offset=0; target_ptr=aastring_glyph.bits; /* We must check for n_vert==1 because the computation above is not valid in this case */ if (n_vert==1) v_start=v_start < v_end ? v_start : v_end; ptr = glyph->bits; for (i = 0; i < n_vert; i++) { if (i==0) y=v_start; else if (i==n_vert-1) y=v_end; else y=T1aa_level; T1_AADoLine ( T1aa_level, wd, y, paddedW, ptr, target_ptr, aahstart ); ptr += y * paddedW; target_ptr += n_horz_pad; } /* .. and set them in aastring_glyph */ aastring_glyph.metrics.leftSideBearing=aalsb; aastring_glyph.metrics.rightSideBearing=aalsb + n_horz; aastring_glyph.metrics.advanceX=(int) floor(glyph->metrics.advanceX/(float)T1aa_level+0.5); aastring_glyph.metrics.advanceY=(int) floor(glyph->metrics.advanceY/(float)T1aa_level+0.5); aastring_glyph.metrics.ascent=n_asc; aastring_glyph.metrics.descent=n_dsc; aastring_glyph.pFontCacheInfo=NULL; /* restore level */ T1aa_level=savelevel; return(&aastring_glyph);}/* T1_AASetGrayValues(): Sets the byte values that are put into the pixel position for the respective entries: Returns 0 if successfull. */int T1_AASetGrayValues(unsigned long white, unsigned long gray75, unsigned long gray50, unsigned long gray25, unsigned long black){ if (CheckForInit()){ T1_errno=T1ERR_OP_NOT_PERMITTED; return(-1); } gv[4]=(unsigned T1_AA_TYPE32)black; /* black value */ gv[3]=(unsigned T1_AA_TYPE32)gray25; /* gray 25% value */ gv[2]=(unsigned T1_AA_TYPE32)gray50; /* gray 50% value */ gv[1]=(unsigned T1_AA_TYPE32)gray75; /* gray 75% value */ gv[0]=(unsigned T1_AA_TYPE32)white; /* white value */ T1aa_bg=white; if ((T1_AAInit( T1_AA_LOW))) return(-1); return(0); } /* T1_AAHSetGrayValues(): Sets the byte values that are put into the pixel position for the respective entries (for 17 gray levels): Returns 0 if successfull. */int T1_AAHSetGrayValues( unsigned long *grayvals){ int i; if (CheckForInit()){ T1_errno=T1ERR_OP_NOT_PERMITTED; return(-1); } /* 0==white(background) ... 16==black(foreground) */ for (i=0; i<17; i++){ gv_h[i]=(unsigned T1_AA_TYPE32)grayvals[i]; } T1aa_bg=grayvals[0]; if ((T1_AAInit( T1_AA_HIGH))) return(-1); return(0); }/* T1_AANSetGrayValues(): Sets the byte values that are put into the pixel position for the respective entries (for 2 gray levels): Returns 0 if successfull. This is for the case the non-antialiased "bytemaps" should be generated. */int T1_AANSetGrayValues( unsigned long bg, unsigned long fg){ if (CheckForInit()){ T1_errno=T1ERR_OP_NOT_PERMITTED; return(-1); } gv_n[0]=bg; gv_n[1]=fg; T1aa_bg=bg; if ((T1_AAInit( T1_AA_NONE))) return(-1); return(0); }/* Get the current setting of graylevels for 2x antialiasing. The 5 values are stored at address pgrayvals in order from background to foreground */int T1_AAGetGrayValues( long *pgrayvals) { int i; if (CheckForInit()) { T1_errno=T1ERR_OP_NOT_PERMITTED; return(-1); } if (pgrayvals==NULL) { T1_errno=T1ERR_INVALID_PARAMETER; return(-1); } for ( i=0; i<5; i++) { /* bg (i=0) to fg (i=4) */ pgrayvals[i]=gv[i]; } return( 0); }/* Get the current setting of graylevels for 2x antialiasing. The 17 values are stored at address pgrayvals in order from background to foreground */int T1_AAHGetGrayValues( long *pgrayvals) { int i; if (CheckForInit()) { T1_errno=T1ERR_OP_NOT_PERMITTED; return(-1); } if (pgrayvals==NULL) { T1_errno=T1ERR_INVALID_PARAMETER; return(-1); } for ( i=0; i<17; i++) { /* bg (i=0) to fg (i=16) */ pgrayvals[i]=gv[i]; } return( 0);}/* Get the current setting of graylevels for 2x antialiasing. The 2 values are stored at address pgrayvals in order from background to foreground */int T1_AANGetGrayValues( long *pgrayvals) { if (CheckForInit()) { T1_errno=T1ERR_OP_NOT_PERMITTED; return(-1); } if (pgrayvals==NULL) { T1_errno=T1ERR_INVALID_PARAMETER; return(-1); } pgrayvals[0]=gv[0]; /* background */ pgrayvals[1]=gv[1]; /* foreground */ return( 0);}/* T1_AASetBitsPerPixel(): Sets the depths of the antialiased glyph pixel. Returns 0 if bpp is valid and -1 otherwise. If 24 is specified, meaning to be the depth rather than the bpp-value, automatically 32 bpp is chosen. */int T1_AASetBitsPerPixel( int bpp){ if (CheckForInit()){ T1_errno=T1ERR_OP_NOT_PERMITTED; return(-1); } /* T1aa_level = 0; */ if (bpp==8){ T1aa_bpp=8; return(0); } if (bpp==16){ T1aa_bpp=16; return(0); } if ((bpp==32)|(bpp==24)){ T1aa_bpp=32; return(0); } T1_errno=T1ERR_INVALID_PARAMETER; return(-1);}/* T1_AAGetBitsPerPixel(): Return the number of bits per pixel set in t1lib. */int T1_AAGetBitsPerPixel( void){ return( T1aa_bpp); }/* Set the Subsampling level for subsequent operations: */int T1_AASetLevel( int level){ if (CheckForInit()){ T1_errno=T1ERR_OP_NOT_PERMITTED; return(-1); } if (level==T1_AA_LOW){ T1aa_level=T1_AA_LOW; return(0); } else if (level==T1_AA_HIGH){ T1aa_level=T1_AA_HIGH; return(0); } else if (level==T1_AA_NONE){ T1aa_level=T1_AA_NONE; return(0); } T1_errno=T1ERR_INVALID_PARAMETER; return(-1); }/* Get the current subsampling level */int T1_AAGetLevel( void){ return( T1aa_level);}/* T1_AAFillOutline(): Create a filled glyph from an outline description */GLYPH *T1_AAFillOutline( T1_OUTLINE *path, int modflag){ GLYPH *glyph; /* pointer to bitmap glyph */ static GLYPH aaglyph={NULL,{0,0,0,0,0,0},NULL,DEFAULTBPP};/* The anti-aliased glyph */ long asc, dsc, ht, wd; long i; long n_horz, n_horz_pad, n_vert, n_asc, n_dsc; long v_start, v_end; char *target_ptr; long offset; char *ptr; int y; long lsb, aalsb, aahstart; int memsize; LONG paddedW; /* Reset character glyph, if necessary */ if (aaglyph.bits!=NULL){ free(aaglyph.bits); aaglyph.bits=NULL; } aaglyph.metrics.leftSideBearing=0; aaglyph.metrics.rightSideBearing=0; aaglyph.metrics.advanceX=0; aaglyph.metrics.advanceY=0; aaglyph.metrics.ascent=0; aaglyph.metrics.descent=0; aaglyph.pFontCacheInfo=NULL; aaglyph.bpp=T1aa_bpp; /* First, scale outline appropriately: */ path=T1_ScaleOutline( path, T1aa_level); /* Second, call routine to fill outline, all error checking is done in this function: */ if ((glyph=T1_FillOutline( path, modflag))==NULL) return(NULL); /* An error occured */ /* In case there are no black pixels, we simply set the dimensions and then return */ if ( glyph->bits == NULL) { aaglyph.bits=NULL; aaglyph.metrics.leftSideBearing=0; aaglyph.metrics.rightSideBearing=0; aaglyph.metrics.advanceX=(int) floor(glyph->metrics.advanceX/(float)T1aa_level+0.5); aaglyph.metrics.advanceY=(int) floor(glyph->metrics.advanceY/(float)T1aa_level+0.5); aaglyph.metrics.ascent=0; aaglyph.metrics.descent=0; aaglyph.pFontCacheInfo=NULL; return(&aaglyph); } /* Get dimensions of bitmap: */ asc=glyph->metrics.ascent; dsc=glyph->metrics.descent; lsb=glyph->metrics.leftSideBearing; ht=asc-dsc; wd=glyph->metrics.rightSideBearing-lsb; if (T1aa_level==T1_AA_NONE){ /* we only convert bitmap to bytemap */ aaglyph=*glyph; aaglyph.bpp=T1aa_bpp; /* Compute scanline length and such */ n_horz_pad=PAD( wd*T1aa_bpp, pFontBase->bitmap_pad )>>3; /* Allocate memory for glyph, we alloc 12 bytes more to simplify subsampling! */ memsize = n_horz_pad*ht*8; aaglyph.bits = (char *)malloc(memsize*sizeof( char) +12); if (aaglyph.bits == NULL) { T1_errno=T1ERR_ALLOC_MEM; return(NULL); } paddedW=PAD(wd,pFontBase->bitmap_pad)>>3; ptr=glyph->bits; target_ptr=aaglyph.bits; for (i = 0; i < ht; i++) { T1_DoLine ( wd, paddedW, ptr, target_ptr ); ptr += paddedW; target_ptr += n_horz_pad; } return(&aaglyph); } /* Set some looping parameters for subsampling */ if (lsb<0){ aalsb=lsb/T1aa_level-1; aahstart=T1aa_level+(lsb%T1aa_level); } else{ aalsb=lsb/T1aa_level; aahstart=lsb%T1aa_level; } /* The horizontal number of steps: */ n_horz=(wd+aahstart+T1aa_level-1)/T1aa_level; /* And the padded value */ n_horz_pad=PAD( n_horz*T1aa_bpp, pFontBase->bitmap_pad )>>3; /* vertical number of steps: */ if (asc % T1aa_level){ /* not aligned */ if ( asc > 0){ n_asc=asc/T1aa_level+1; v_start=asc % T1aa_level; } else{ n_asc=asc/T1aa_level; v_start=T1aa_level + (asc % T1aa_level); } } else{ n_asc=asc/T1aa_level; v_start=T1aa_level; } if (dsc % T1aa_level){ /* not aligned */ if ( dsc < 0){ n_dsc=dsc/T1aa_level-1; v_end=-(dsc % T1aa_level); } else{ n_dsc=dsc/T1aa_level; v_end=T1aa_level - (dsc % T1aa_level); } } else{ n_dsc=dsc/T1aa_level; v_end=T1aa_level; } /* the total number of lines: */ n_vert=n_asc-n_dsc; /* Allocate memory for glyph */ memsize = n_horz_pad*n_vert; aaglyph.bits = (char *)malloc(memsize*sizeof( char)+12); if (aaglyph.bits == NULL) { T1_errno=T1ERR_ALLOC_MEM; return(NULL); } paddedW=PAD(wd,pFontBase->bitmap_pad)/8; offset=0; target_ptr=aaglyph.bits; /* We must check for n_vert==1 because the computation above is not valid in this case */ if (n_vert==1) v_start=v_start < v_end ? v_start : v_end; ptr = glyph->bits; for (i = 0; i < n_vert; i++) { if (i==0) y=v_start; else if (i==n_vert-1) y=v_end; else y=T1aa_level; T1_AADoLine ( T1aa_level, wd, y, paddedW, ptr, target_ptr, aahstart ); ptr += y * paddedW; target_ptr += n_horz_pad; } /* .. and set them in aaglyph */ aaglyph.metrics.leftSideBearing=aalsb; aaglyph.metrics.rightSideBearing=aalsb + n_horz; aaglyph.metrics.advanceX=(int) floor(glyph->metrics.advanceX/(float)T1aa_level+0.5); aaglyph.metrics.advanceY=(int) floor(glyph->metrics.advanceY/(float)T1aa_level+0.5); aaglyph.metrics.ascent=n_asc; aaglyph.metrics.descent=n_dsc; aaglyph.pFontCacheInfo=NULL; return(&aaglyph);}/* T1_AASetSmartLimits(): Set the limit-values for smart antialiasing. Returns 0 if OK, and -1 else. */int T1_AASetSmartLimits( float limit1, float limit2){ if (limit1 > 0.0 && limit2 > 0.0 && limit2 >= limit2) { T1aa_smartlimit1=limit1; T1aa_smartlimit2=limit2; return( 0); } else{ T1_errno=T1ERR_INVALID_PARAMETER; return( -1); }}/* T1_AASetSmartMode(): Enable or disable smart anialiasing */int T1_AASetSmartMode( int smart){ if (smart==T1_YES) { T1aa_SmartOn=1; } else if (smart==T1_NO) { T1aa_SmartOn=0; } else { T1_errno=T1ERR_INVALID_PARAMETER; return( -1); } return( 0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -