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

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