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.

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