📄 hzout.cpp
字号:
switch( nOutputCode ) //判断输出内码
{
case 0: //GB
case 1: //BIG5
// if ( bAreaNum < 0xB0 ) //1-9区,是中文字符区
dwPos=( ( bAreaNum-0XA1)*94L+bPosNum-0XA1 )*32L ;
// else //846=9*94 //16-87区,是汉字区
// dwPos=( ( bAreaNum-0XB0)*94L+bPosNum-0XA1+846L )*32L ;
if( dwPos<0 || dwPos > g_dwHzLibLen-32 ) //输入内码有问题
{
// for( i=0 ; i<32 ; i++ )
// sDotBuff[i] =0 ; //返回空
g_hpDotBuff =(BYTE huge*)g_sErrorDotBuff ;
return 0 ;
}
// for( i=0 ; i<32 ; i++ )
// sDotBuff[i] =~(*( hpHzLib+dwPos+i )) ;
g_hpDotBuff =g_hpHzLib+dwPos ;
return 1 ;
case 2: //SHIFT-JIS
if( bPosNum == 0x7f )
{
// for( int j=0 ; j<32 ; j++ )
// sDotBuff[j] =0xff ;
g_hpDotBuff =(BYTE huge*)g_sErrorDotBuff ;
return 0 ;
}
if( bPosNum > 0x7f )
bPosNum-- ;
if( (bAreaNum>=0x81 && bAreaNum<0x88) ||
(bAreaNum==0x88 && bPosNum<0x9e) )
dwPos =( ( bAreaNum-0x81 )*188L+bPosNum-0x40 )*32L ;
else if( (bAreaNum>0x88 && bAreaNum<=0x9f ) ||
(bAreaNum==0x88 && bPosNum>=0x9e ) )
dwPos =( ( bAreaNum-0x81-2 )*188L+bPosNum-0x40-0x5e )*32L ;
else if( (bAreaNum>=0xe0 && bAreaNum<0xea) ||
(bAreaNum==0xea && bPosNum<=0xa1 ) )
dwPos =( ( bAreaNum-0xe0-2 )*188L+bPosNum-0x40L-0x5eL+5828L )*32L ;
else
{
// for( int j=0 ; j<32 ; j++ )
// sDotBuff[j] =0xff ;
g_hpDotBuff =(BYTE huge*)g_sErrorDotBuff ;
return 0 ;
}
break ;
case 3: //EUC-JIS
if( bAreaNum<0xb0 )
dwPos =((bAreaNum-0xa1)*94L+bPosNum-0xa1)*32L ;
else
dwPos =((bAreaNum-0xb0)*94L+bPosNum-0xa1+940L)*32L ;
break ;
case 4: //KSC5601
if( bAreaNum<0xb0 )
dwPos =((bAreaNum-0xa1)*94L+bPosNum-0xa1)*32L ;
else
dwPos =((bAreaNum-0xb0)*94L+bPosNum-0xa1+1128L)*32L ;
break ;
default:
g_hpDotBuff =(BYTE huge*)g_sErrorDotBuff ;
return 0 ;
}
if( dwPos<0 || dwPos > g_dwOtherLibLen-32 ) //输入内码有问题
{
// for( i=0 ; i<32 ; i++ )
// sDotBuff[i] =0xff ; //返回空
g_hpDotBuff =(BYTE huge*)g_sErrorDotBuff ;
return 0 ;
}
// for( i=0 ; i<32 ; i++ )
// sDotBuff[i] =*( hpOtherLib+dwPos+i ) ;
g_hpDotBuff =g_hpOtherLib+dwPos ;
return 1 ;
}
BOOL HzOut( HDC hdc ,
int nX , int nY , //Left,upper original point
int nWidth , int nHeight , //Width and height of the HZ
LPCSTR sHz , int nHzNum ,
int nOneHzWidth , int nTab , //汉字逻辑宽度与汉字间隔
int nOutputCode )
{
//一个汉字的宽度为16
HDC memDC =::CreateCompatibleDC( hdc ) ;
HBITMAP hbm , hOldBitmap ;
int height ;
if( GetMapMode( hdc ) == MM_TEXT )
height =nHeight ;
else
height =-nHeight ;
COLORREF oldColor , oldBkColor ;
HBRUSH hBrush , hOldBrush ;
DWORD fdwRop ;
if( GetBkMode( hdc ) != OPAQUE )
{
oldColor =SetTextColor( hdc , RGB( 0 , 0 , 0 ) ) ;
oldBkColor=SetBkColor( hdc , RGB( 255 , 255 , 255 ));
hBrush =CreateSolidBrush( oldColor ) ;
hOldBrush =(HBRUSH)::SelectObject( hdc , hBrush ) ;
fdwRop =0xb8074a ;
}
else
fdwRop =SRCCOPY ;
int i ;
BYTE b1 , b2 ;
if( nHeight%2 ) //高度为奇数
{
// sDotBuff[32] =0xff ;
// sDotBuff[33] =0xff ;
for( i=0 ; i<nHzNum ; i++ )
{
GetDotMatrix( (BYTE)sHz[i*2] , (BYTE)sHz[i*2+1] , nOutputCode ) ;
//保存原来两字节内容
b1 =*(g_hpDotBuff+32) ;
b2 =*(g_hpDotBuff+33) ;
*(g_hpDotBuff+32) =0xff ;
*(g_hpDotBuff+33) =0xff ;
hbm =::CreateBitmap( 16 , 17 , 1 , 1 , g_hpDotBuff ) ;
hOldBitmap =(HBITMAP)::SelectObject( memDC , hbm ) ;
::StretchBlt( hdc , nX , nY , nOneHzWidth , height ,
memDC , 0 , 0 , 16 , 17 , fdwRop ) ;
::SelectObject( memDC , hOldBitmap ) ;
::DeleteObject( hbm ) ;
//恢复原来两字节内容
*(g_hpDotBuff+32) =b1 ;
*(g_hpDotBuff+33) =b2 ;
nX +=nOneHzWidth+nTab ;
}
}
else
{
for( i=0 ; i<nHzNum ; i++ )
{
GetDotMatrix( (BYTE)sHz[i*2] , (BYTE)sHz[i*2+1] , nOutputCode ) ;
hbm =::CreateBitmap( 16 , 16 , 1 , 1 , g_hpDotBuff ) ;
hOldBitmap =(HBITMAP)::SelectObject( memDC , hbm ) ;
::StretchBlt( hdc , nX , nY , nOneHzWidth , height ,
memDC , 0 , 0 , 16 , 16 , fdwRop ) ;
::SelectObject( memDC , hOldBitmap ) ;
::DeleteObject( hbm ) ;
nX +=nOneHzWidth+nTab ;
}
}
if( GetBkMode( hdc ) != OPAQUE )
{
SelectObject( hdc , hOldBrush ) ;
DeleteObject( hBrush ) ;
SetTextColor( hdc , oldColor ) ;
SetBkColor( hdc , oldBkColor ) ;
}
DeleteObject( memDC ) ;
return 1 ;
}
/*
//显示一个汉字或日文或韩文,nx,ny,nWidth,nHeight都用的是logical unit
BOOL HzOut( HDC hdc ,
int nX , int nY , //Left,upper original point
int nWidth , int nHeight , //Width and height of the HZ
LPCSTR sHz , int nHzNum ,
int nOneHzWidth , int nTab ) //汉字逻辑宽度与汉字间隔
{
//一个汉字的宽度为16
HDC memDC =::CreateCompatibleDC( hdc ) ;
HBITMAP hbm , hOldBitmap ;
int height ;
if( GetMapMode( hdc ) == MM_TEXT )
height =nHeight ;
else
height =-nHeight ;
COLORREF oldColor , oldBkColor ;
HBRUSH hBrush , hOldBrush ;
DWORD fdwRop ;
if( GetBkMode( hdc ) != OPAQUE )
{
oldColor =SetTextColor( hdc , RGB( 0 , 0 , 0 ) ) ;
oldBkColor=SetBkColor( hdc , RGB( 255 , 255 , 255 ));
hBrush =CreateSolidBrush( oldColor ) ;
hOldBrush =(HBRUSH)::SelectObject( hdc , hBrush ) ;
fdwRop =0xb8074a ;
}
else
fdwRop =SRCCOPY ;
int nCode ;
if( p_nOutputCode==1 ) //判断输出内码为BIG5
nCode =0 ;
else
nCode =p_nOutputCode ;
for( int i=0 ; i<nHzNum ; i++ )
{
hbm =GetOneCache( nCode , (BYTE)sHz[i*2] , (BYTE)sHz[i*2+1] ) ;
if( !i ) //第一个汉字
hOldBitmap =(HBITMAP)::SelectObject( memDC , hbm ) ;
else
(HBITMAP)::SelectObject( memDC , hbm ) ;
::StretchBlt( hdc , nX , nY , nOneHzWidth , height ,
memDC , 0 , 0 , 16 , 16 , fdwRop ) ;
nX +=nOneHzWidth+nTab ;
}
if( GetBkMode( hdc ) != OPAQUE )
{
SelectObject( hdc , hOldBrush ) ;
DeleteObject( hBrush ) ;
SetTextColor( hdc , oldColor ) ;
SetBkColor( hdc , oldBkColor ) ;
}
SelectObject( memDC , hOldBitmap ) ;
DeleteObject( memDC ) ;
return 1 ;
}
BOOL HzOut( HDC hdc ,
int nX , int nY , //Left,upper original point
int nWidth , int nHeight , //Width and height of the HZ
LPCSTR sHz , int nHzNum ,
int nOneHzWidth , int nTab ) //汉字逻辑宽度与汉字间隔
{
// if( nHzNum<=0 || nOneHzWidth<=0 || nTab <0 )
// return 0 ;
//一个汉字的宽度为16
int nHzTab =(16*nTab)/nOneHzWidth ; //转换汉字间隔
int nHzWidth =16 + nHzTab ; //一个汉字的宽度
int nHzStrWidth =nHzWidth*nHzNum ; //汉字串的宽度
if( nHzStrWidth > MAX_DOT_NUM )
return 0 ;
//获得汉字串的点阵
int i , j , k ;
int m , n ; //每行起始字节数和所余位数
for( i=0 ; i<nHzStrWidth+nHzStrWidth ; i++ )
sDotMatrix[i] =0xff ;
for( i=0 ; i<nHzNum ; i++ ) //nHzNum个汉字
{
//Get the dot matrix of the hz.
GetDotMatrix( sHz+i*2 , sHz+i*2+1 ) ;
//将这个字的点阵分布到汉字串中
for( j=0 ; j<16 ; j++ ) //一共是16行,每行两个字节
{
m =(j*nHzStrWidth+i*nHzWidth)/8 ; //起始字节
//起始字节中已用过的位数
n =(j*nHzStrWidth+i*nHzWidth)%8 ;
for( k=0 ; k<16 ; k++ , n++ ) //每行16列,即16个象素
if( (0x80>>(k%8)) & sDotBuff[j*2+k/8] ) //是1
sDotMatrix[m+(n/8)] &=(~(0x80>>(n%8))) ;
}
}
//--------------------------------------------------------------------------//
HDC memDC =::CreateCompatibleDC( hdc ) ;
//Create a bitmap for the hz
HBITMAP hbm=CreateBitmap( nHzStrWidth , 16 , 1 , 1 , //NULL ) ;
(const void FAR*)sDotMatrix ) ;
HBITMAP pOldBitmap =(HBITMAP)::SelectObject( memDC , hbm ) ;
int height ;
if( GetMapMode( hdc ) == MM_TEXT )
height =nHeight ;
else
height =-nHeight ;
if( GetBkMode( hdc ) == OPAQUE )
::StretchBlt( hdc , nX , nY , nWidth , height ,
memDC , 0 , 0 , nHzStrWidth , 16 , SRCCOPY ) ;
else
{
COLORREF oldColor =SetTextColor( hdc , RGB( 0 , 0 , 0 ) ) ;
COLORREF oldBkColor=SetBkColor( hdc , RGB( 255 , 255 , 255 ));
HBRUSH hBrush =CreateSolidBrush( oldColor ) ;
HBRUSH hOldBrush =(HBRUSH)::SelectObject( hdc , hBrush ) ;
::StretchBlt( hdc , nX , nY , nWidth , height ,
memDC , 0 , 0 , nHzStrWidth , 16 , 0xb8074a ) ;
SelectObject( hdc , hOldBrush ) ;
DeleteObject( hBrush ) ;
SetTextColor( hdc , oldColor ) ;
SetBkColor( hdc , oldBkColor ) ;
}
SelectObject( memDC , pOldBitmap ) ;
DeleteObject( memDC ) ;
DeleteObject( hbm ) ;
return 1 ;
}
//初始化cache
BOOL InitCache( void )
{
BYTE b1=0xb0 , b2=0xa1 ;
p_Cache[0].bCode =0 ; //GB
p_Cache[0].b1 =b1 ;
p_Cache[0].b2 =b2 ;
GetDotMatrix( 0 , b1 , b2 ) ;
p_Cache[0].hHz =::CreateBitmap( 16 , 16 , 1 , 1 ,
(const void FAR*)sDotBuff ) ;
if( !p_Cache[0].hHz )
return 0 ;
p_pFirstCache =&(p_Cache[0]) ;
for( int i=1 ; i<CACHE_HZ_NUM ; i++ )
{
if( b2==0xfe )
{
b1++ ;
b2 =0xa1 ;
}
else
b2++ ;
p_Cache[i].bCode =0 ;
p_Cache[i].b1 =b1 ;
p_Cache[i].b2 =b2 ;
GetDotMatrix( 0 , b1 , b2 ) ;
p_Cache[i].hHz =::CreateBitmap( 16 , 16 , 1 , 1 ,
(const void FAR*)sDotBuff ) ;
if( !p_Cache[i].hHz )
return 0 ;
p_Cache[i].pPrior =&(p_Cache[i-1]) ;
p_Cache[i-1].pNext =&(p_Cache[i]) ;
}
p_pLastCache =&(p_Cache[CACHE_HZ_NUM-1]) ;
p_Cache[CACHE_HZ_NUM-1].pNext =p_pFirstCache ;
p_Cache[0].pPrior =p_pLastCache ;
return 1 ;
}
//结束Cache
void ExitCache( void )
{
for( int i=0 ; i<CACHE_HZ_NUM ; i++ )
{
DeleteObject( p_pFirstCache->hHz ) ;
p_pFirstCache =p_pFirstCache->pNext ;
}
}
//得到一个汉字的位图句柄
HBITMAP GetOneCache( int bCode , BYTE b1 , BYTE b2 )
{
CACHE_ITEM *pItem ;
pItem =p_pFirstCache ;
for( int i=0 ; i<CACHE_HZ_NUM ; i++ )
{
if( bCode==pItem->bCode &&
b1==pItem->b1 && b2==pItem->b2 )
return pItem->hHz ;
pItem =pItem->pNext ;
}
//找不着,以这个汉字冲掉最后一个汉字
p_pLastCache->bCode =bCode ;
p_pLastCache->b1 =b1 ;
p_pLastCache->b2 =b2 ;
DeleteObject( p_pLastCache->hHz ) ; //删除原来的
GetDotMatrix( p_nOutputCode , b1 , b2 ) ;
p_pLastCache->hHz =::CreateBitmap( 16 , 16 , 1 , 1 ,
(const void FAR*)sDotBuff ) ;
p_pFirstCache =p_pLastCache ;
p_pLastCache =p_pLastCache->pPrior ;
return p_pFirstCache->hHz ;
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -