Old fashion design for PC-104
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

237 lines
5.3 KiB

//----------------------------------------------------------------------------
// Laser Guard Ltd.
// Copyright © 2000-2002. All Rights Reserved.
// Version 1.0 01/01/2000
// Last modification: 06/02/2002
// PROJECT:
// SUBSYSTEM:
// FILE: SymbolData.cpp
// AUTHOR: Sergey Chizhevskiy
// OVERVIEW
// ~~~~~~~~
// Source file of SymbolData.cpp
//----------------------------------------------------------------------------
#include "stdafx.h"
#include "..\LgLib\Version.h"
#include "SymbolData.h"
CSymbolData::CSymbolData()
{
m_pCharImage = NULL;
m_nCharImage = 0;
m_nWidth = 0;
m_nHeight = 0;
}
CSymbolData::~CSymbolData()
{
Destroy();
}
BOOL CSymbolData::Create( int x, int y, LPCTSTR pFontName )
{
Destroy();
m_nWidth = x;
m_nHeight = y;
m_nCharImage = m_nWidth * m_nHeight * 256;
m_pCharImage = new BYTE[ m_nCharImage ];
if( !m_pCharImage )
return FALSE;
HDC hMemDC = ::CreateCompatibleDC( NULL );
if( hMemDC )
{
HBITMAP hMemBitmap = ::CreateCompatibleBitmap( hMemDC, m_nWidth, m_nHeight * 256 );
if( hMemBitmap )
{
HFONT hMemFont = ::CreateFont( -m_nHeight, -m_nWidth, 0, 0, FW_NORMAL, 0UL, 0UL, 0UL,
OEM_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH, pFontName );
if( hMemFont )
{
HBITMAP hBitmap = (HBITMAP)::SelectObject( hMemDC, hMemBitmap );
HFONT hFont = (HFONT)::SelectObject( hMemDC, hMemFont );
COLORREF nBkColor = ::SetBkColor( hMemDC, RGB(0,0,0) );
COLORREF nColor = ::SetTextColor( hMemDC, RGB(0xFF,0xFF,0xFF) );
for( int i = 0; i < 256; i++ )
{
RECT rect;
TCHAR ch = (TCHAR)i;
::SetRect( &rect, 0, i * m_nHeight, m_nWidth-1, (i+1) * m_nHeight );
::DrawText( hMemDC, &ch, 1, &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
}
PBYTE pPtr = m_pCharImage;
for( y = 0; y < m_nHeight * 256; y++ )
{
for( x = 0; x < m_nWidth; x++ )
{
*pPtr ++ = ::GetPixel( hMemDC, x, y ) != RGB(0,0,0);
}
}
::SetBkColor( hMemDC, nBkColor );
::SetTextColor( hMemDC, nColor );
::SelectObject( hMemDC, hFont );
::SelectObject( hMemDC, hBitmap );
::DeleteObject( hMemFont );
}
::DeleteObject( hMemBitmap );
}
::DeleteDC( hMemDC );
}
return TRUE;
}
void CSymbolData::Destroy()
{
if( m_pCharImage )
{
delete [] m_pCharImage;
m_pCharImage = NULL;
}
m_nCharImage = 0;
m_nWidth = 0;
m_nHeight = 0;
}
LPBYTE CSymbolData::Get( INT nChar )
{
if( !m_pCharImage )
return NULL;
if( nChar < 0 || nChar > 255 )
return 0;
return m_pCharImage + (nChar << 7);
}
BOOL CSymbolData::PrintToDIB( LPBITMAPINFO pBitmapInfo, LPBYTE pBytes, LPCTSTR pFormat, ... )
{
if( !pFormat || !pBitmapInfo || !pBytes )
return FALSE;
if( pBitmapInfo->bmiHeader.biBitCount % 8 != 0 )
return FALSE;
if( !m_pCharImage )
return FALSE;
TCHAR pText[MAX_PATH];
va_list vaMarker;
va_start( vaMarker, pFormat );
int nStrLen = _vsntprintf( pText, MAX_PATH, pFormat, vaMarker );
va_end( vaMarker );
if( !nStrLen )
return FALSE;
COLORREF cColor = RGB(0xFF,0,0);
int nStrPixelSize = nStrLen * m_nWidth;
int nStrShift = ( pBitmapInfo->bmiHeader.biWidth - nStrPixelSize ) >> 1;
int nCharRowBegin = ( m_nHeight - 1 ) * m_nWidth;
PBYTE pPixel08Ptr;
PWORD pPixel16Ptr;
RGBTRIPLE* pPixel24Ptr;
BYTE color08;
WORD color16;
RGBTRIPLE color24;
int x, y;
switch( pBitmapInfo->bmiHeader.biBitCount )
{
case 8:
color08 = (BYTE)cColor;
pPixel08Ptr = (PBYTE)pBytes;
pPixel08Ptr += nStrShift;
for( y = 0; y < m_nHeight; y++ )
{
int nChar = 0;
int nCharColumn = 0;
for( x = 0; x < nStrPixelSize; x++ )
{
if( *( Get( pText[ nChar ] ) + nCharRowBegin + nCharColumn ) )
pPixel08Ptr[ x ] = color08;
if( ++nCharColumn == m_nWidth )
{
nCharColumn = 0;
nChar++;
}
}
pPixel08Ptr += pBitmapInfo->bmiHeader.biWidth;
nCharRowBegin -= m_nWidth;
}
break;
case 16:
color16 = ( ( GetRValue( cColor ) >> 3 ) << 11 ) |
( ( GetGValue( cColor ) >> 2 ) << 5 ) |
( ( GetBValue( cColor ) >> 3 ) << 0 );
pPixel16Ptr = (PWORD)pBytes;
pPixel16Ptr += nStrShift;
for( y = 0; y < m_nHeight; y++ )
{
int nChar = 0;
int nCharColumn = 0;
for( x = 0; x < nStrPixelSize; x++ )
{
if( *( Get( pText[ nChar ] ) + nCharRowBegin + nCharColumn ) )
pPixel16Ptr[ x ] = color16;
if( ++nCharColumn == m_nWidth )
{
nCharColumn = 0;
nChar++;
}
}
pPixel16Ptr += pBitmapInfo->bmiHeader.biWidth;
nCharRowBegin -= m_nWidth;
}
break;
case 24:
color24.rgbtRed = GetRValue( cColor );
color24.rgbtGreen = GetGValue( cColor );
color24.rgbtBlue = GetBValue( cColor );
pPixel24Ptr = (RGBTRIPLE*)pBytes;
pPixel24Ptr += nStrShift;
for( y = 0; y < m_nHeight; y++ )
{
int nChar = 0;
int nCharColumn = 0;
for( x = 0; x < nStrPixelSize; x++ )
{
if( *( Get( pText[ nChar ] ) + nCharRowBegin + nCharColumn ) )
pPixel24Ptr[ x ] = color24;
if( ++nCharColumn == m_nWidth )
{
nCharColumn = 0;
nChar++;
}
}
pPixel24Ptr += pBitmapInfo->bmiHeader.biWidth;
nCharRowBegin -= m_nWidth;
}
break;
}
return TRUE;
}