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.

240 lines
5.5 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 08/10/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: SymbolData.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of SymbolData.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "SymbolData.h"
  16. #include "..\..\LgLib\Version.h"
  17. CSymbolData::CSymbolData()
  18. {
  19. m_pCharImage = NULL;
  20. m_nCharImage = 0;
  21. m_nWidth = 0;
  22. m_nHeight = 0;
  23. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CSymbolData::CSymbolData") );
  24. }
  25. CSymbolData::~CSymbolData()
  26. {
  27. Destroy();
  28. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CSymbolData::~CSymbolData") );
  29. }
  30. BOOL CSymbolData::Create( int x, int y, LPCTSTR pFontName )
  31. {
  32. Destroy();
  33. m_nWidth = x;
  34. m_nHeight = y;
  35. m_nCharImage = m_nWidth * m_nHeight * 256;
  36. m_pCharImage = new BYTE[ m_nCharImage ];
  37. if( !m_pCharImage )
  38. return FALSE;
  39. HDC hMemDC = ::CreateCompatibleDC( NULL );
  40. if( hMemDC )
  41. {
  42. HBITMAP hMemBitmap = ::CreateCompatibleBitmap( hMemDC, m_nWidth, m_nHeight * 256 );
  43. if( hMemBitmap )
  44. {
  45. HFONT hMemFont = ::CreateFont( -m_nHeight, -m_nWidth, 0, 0, FW_NORMAL, 0UL, 0UL, 0UL,
  46. OEM_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
  47. DEFAULT_QUALITY, DEFAULT_PITCH, pFontName );
  48. if( hMemFont )
  49. {
  50. HBITMAP hBitmap = (HBITMAP)::SelectObject( hMemDC, hMemBitmap );
  51. HFONT hFont = (HFONT)::SelectObject( hMemDC, hMemFont );
  52. COLORREF nBkColor = ::SetBkColor( hMemDC, RGB(0,0,0) );
  53. COLORREF nColor = ::SetTextColor( hMemDC, RGB(0xFF,0xFF,0xFF) );
  54. for( int i = 0; i < 256; i++ )
  55. {
  56. RECT rect;
  57. TCHAR ch = (TCHAR)i;
  58. ::SetRect( &rect, 0, i * m_nHeight, m_nWidth-1, (i+1) * m_nHeight );
  59. ::DrawText( hMemDC, &ch, 1, &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
  60. }
  61. PBYTE pPtr = m_pCharImage;
  62. for( y = 0; y < m_nHeight * 256; y++ )
  63. {
  64. for( x = 0; x < m_nWidth; x++ )
  65. {
  66. *pPtr ++ = ::GetPixel( hMemDC, x, y ) != RGB(0,0,0);
  67. }
  68. }
  69. ::SetBkColor( hMemDC, nBkColor );
  70. ::SetTextColor( hMemDC, nColor );
  71. ::SelectObject( hMemDC, hFont );
  72. ::SelectObject( hMemDC, hBitmap );
  73. ::DeleteObject( hMemFont );
  74. }
  75. ::DeleteObject( hMemBitmap );
  76. }
  77. ::DeleteDC( hMemDC );
  78. }
  79. return TRUE;
  80. }
  81. void CSymbolData::Destroy()
  82. {
  83. if( m_pCharImage )
  84. {
  85. delete [] m_pCharImage;
  86. m_pCharImage = NULL;
  87. }
  88. m_nCharImage = 0;
  89. m_nWidth = 0;
  90. m_nHeight = 0;
  91. }
  92. LPBYTE CSymbolData::Get( INT nChar )
  93. {
  94. if( !m_pCharImage )
  95. return NULL;
  96. if( nChar < 0 || nChar > 255 )
  97. return 0;
  98. return m_pCharImage + (nChar << 7);
  99. }
  100. BOOL CSymbolData::PrintToDIB( LPBITMAPINFO pBitmapInfo, LPBYTE pBytes, LPCTSTR pFormat, ... )
  101. {
  102. if( !pFormat || !pBitmapInfo || !pBytes )
  103. return FALSE;
  104. if( pBitmapInfo->bmiHeader.biBitCount % 8 != 0 )
  105. return FALSE;
  106. if( !m_pCharImage )
  107. return FALSE;
  108. TCHAR pText[MAX_PATH];
  109. va_list vaMarker;
  110. va_start( vaMarker, pFormat );
  111. int nStrLen = _vsntprintf( pText, MAX_PATH, pFormat, vaMarker );
  112. va_end( vaMarker );
  113. if( !nStrLen )
  114. return FALSE;
  115. COLORREF cColor = RGB(0xFF,0,0);
  116. int nStrPixelSize = nStrLen * m_nWidth;
  117. int nStrShift = ( pBitmapInfo->bmiHeader.biWidth - nStrPixelSize ) >> 1;
  118. int nCharRowBegin = ( m_nHeight - 1 ) * m_nWidth;
  119. PBYTE pPixel08Ptr;
  120. PWORD pPixel16Ptr;
  121. RGBTRIPLE* pPixel24Ptr;
  122. BYTE color08;
  123. WORD color16;
  124. RGBTRIPLE color24;
  125. int x, y;
  126. switch( pBitmapInfo->bmiHeader.biBitCount )
  127. {
  128. case 8:
  129. color08 = (BYTE)cColor;
  130. pPixel08Ptr = (PBYTE)pBytes;
  131. pPixel08Ptr += nStrShift;
  132. for( y = 0; y < m_nHeight; y++ )
  133. {
  134. int nChar = 0;
  135. int nCharColumn = 0;
  136. for( x = 0; x < nStrPixelSize; x++ )
  137. {
  138. if( *( Get( pText[ nChar ] ) + nCharRowBegin + nCharColumn ) )
  139. pPixel08Ptr[ x ] = color08;
  140. if( ++nCharColumn == m_nWidth )
  141. {
  142. nCharColumn = 0;
  143. nChar++;
  144. }
  145. }
  146. pPixel08Ptr += pBitmapInfo->bmiHeader.biWidth;
  147. nCharRowBegin -= m_nWidth;
  148. }
  149. break;
  150. case 16:
  151. color16 = ( ( GetRValue( cColor ) >> 3 ) << 11 ) |
  152. ( ( GetGValue( cColor ) >> 2 ) << 5 ) |
  153. ( ( GetBValue( cColor ) >> 3 ) << 0 );
  154. pPixel16Ptr = (PWORD)pBytes;
  155. pPixel16Ptr += nStrShift;
  156. for( y = 0; y < m_nHeight; y++ )
  157. {
  158. int nChar = 0;
  159. int nCharColumn = 0;
  160. for( x = 0; x < nStrPixelSize; x++ )
  161. {
  162. if( *( Get( pText[ nChar ] ) + nCharRowBegin + nCharColumn ) )
  163. pPixel16Ptr[ x ] = color16;
  164. if( ++nCharColumn == m_nWidth )
  165. {
  166. nCharColumn = 0;
  167. nChar++;
  168. }
  169. }
  170. pPixel16Ptr += pBitmapInfo->bmiHeader.biWidth;
  171. nCharRowBegin -= m_nWidth;
  172. }
  173. break;
  174. case 24:
  175. color24.rgbtRed = GetRValue( cColor );
  176. color24.rgbtGreen = GetGValue( cColor );
  177. color24.rgbtBlue = GetBValue( cColor );
  178. pPixel24Ptr = (RGBTRIPLE*)pBytes;
  179. pPixel24Ptr += nStrShift;
  180. for( y = 0; y < m_nHeight; y++ )
  181. {
  182. int nChar = 0;
  183. int nCharColumn = 0;
  184. for( x = 0; x < nStrPixelSize; x++ )
  185. {
  186. if( *( Get( pText[ nChar ] ) + nCharRowBegin + nCharColumn ) )
  187. pPixel24Ptr[ x ] = color24;
  188. if( ++nCharColumn == m_nWidth )
  189. {
  190. nCharColumn = 0;
  191. nChar++;
  192. }
  193. }
  194. pPixel24Ptr += pBitmapInfo->bmiHeader.biWidth;
  195. nCharRowBegin -= m_nWidth;
  196. }
  197. break;
  198. }
  199. return TRUE;
  200. }