CachedTexture::CachedTexture( const string &f_,int flags,int w,int h,int first,int cnt ){ string f=f_; if( f.substr(0,2)==".\\" ) f=f.substr(2); if( path.size() ){ string t=path+tolower( filenamefile( f ) ); if( rep=findRep( t,flags,w,h,first,cnt ) ) return; rep=d_new Rep( t,flags,w,h,first,cnt ); if( rep->frames.size() ){ rep_set.insert( rep ); return; } delete rep; } string t=tolower( fullfilename( f ) ); if( rep=findRep( t,flags,w,h,first,cnt ) ) return; rep=d_new Rep( t,flags,w,h,first,cnt ); rep_set.insert( rep ); }
gxFont *gxGraphics::loadFont( const string &f,int height,int flags ){ int bold=flags & gxFont::FONT_BOLD ? FW_BOLD : FW_REGULAR; int italic=flags & gxFont::FONT_ITALIC ? 1 : 0; int underline=flags & gxFont::FONT_UNDERLINE ? 1 : 0; int strikeout=0; string t; int n=f.find('.'); if( n!=string::npos ){ t=fullfilename(f); if( !font_res.count(t) && AddFontResource( t.c_str() ) ) font_res.insert( t ); t=filenamefile( f.substr(0,n) ); }else{ t=f; } //save and turn off font smoothing.... BOOL smoothing=FALSE; SystemParametersInfo( SPI_GETFONTSMOOTHING,0,&smoothing,0 ); SystemParametersInfo( SPI_SETFONTSMOOTHING,FALSE,0,0 ); HFONT hfont=CreateFont( height,0,0,0, bold,italic,underline,strikeout, ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE,t.c_str() ); if( !hfont ){ //restore font smoothing SystemParametersInfo( SPI_SETFONTSMOOTHING,smoothing,0,0 ); return 0; } HDC hdc=CreateCompatibleDC( 0 ); HFONT pfont=(HFONT)SelectObject( hdc,hfont ); TEXTMETRIC tm={0}; if( !GetTextMetrics( hdc,&tm ) ){ SelectObject( hdc,pfont ); DeleteDC( hdc ); DeleteObject( hfont ); SystemParametersInfo( SPI_SETFONTSMOOTHING,smoothing,0,0 ); return 0; } height=tm.tmHeight; int first=tm.tmFirstChar,last=tm.tmLastChar; int sz=last-first+1; int *offs=d_new int[sz]; int *widths=d_new int[sz]; int *as=d_new int[sz]; //calc size of canvas to hold font. int x=0,y=0,max_x=0; for( int k=0;k<sz;++k ){ char t=k+first; SIZE sz; GetTextExtentPoint32( hdc,&t,1,&sz ); int w=sz.cx; as[k]=0; ABC abc; if( GetCharABCWidths( hdc,t,t,&abc ) ){ if( abc.abcA<0 ){ as[k]=ceil(-abc.abcA); w+=as[k]; } if( abc.abcC<0 ) w+=ceil(-abc.abcC); } if( x && x+w>getWidth() ){ x=0;y+=height; } offs[k]=(x<<16)|y; widths[k]=w; x+=w;if( x>max_x ) max_x=x; } SelectObject( hdc,pfont ); DeleteDC( hdc ); int cw=max_x,ch=y+height; if( gxCanvas *c=createCanvas( cw,ch,0 ) ){ ddSurf *surf=c->getSurface(); HDC surf_hdc; if( surf->GetDC( &surf_hdc )>=0 ){ HFONT pfont=(HFONT)SelectObject( surf_hdc,hfont ); SetBkColor( surf_hdc,0x000000 ); SetTextColor( surf_hdc,0xffffff ); for( int k=0;k<sz;++k ){ int x=(offs[k]>>16)&0xffff,y=offs[k]&0xffff; char t=k+first; RECT rect={x,y,x+widths[k],y+height}; ExtTextOut( surf_hdc,x+as[k],y,ETO_CLIPPED,&rect,&t,1,0 ); } SelectObject( surf_hdc,pfont ); surf->ReleaseDC( surf_hdc ); DeleteObject( hfont ); delete[] as; c->backup(); gxFont *font=d_new gxFont( this,c,tm.tmMaxCharWidth,height,first,last+1,tm.tmDefaultChar,offs,widths ); font_set.insert( font ); //restore font smoothing SystemParametersInfo( SPI_SETFONTSMOOTHING,smoothing,0,0 ); return font; }else{