EAN13.cpp
// nPPM - pixels per module, nHeight - bar nHeight in pixels

pixels per module, nHeight - bar nHeight in pixels
pixels per module nHeight - bar nHeight in pixels
void CEAN13::Render (Gdiplus::Graphics* pGraphics, CRect rect)
{
	if (m_strBars.IsEmpty ())
		SetCode (m_strCode, m_strAddon);
	CSize size = GetSize ();
	int nPPM = (int) (((double) size.cy / (double) rect.Height ()) * (double) MODULE);
	int nHeight = (int) (((EAN13_HEIGHT - 1) * 100) / (double) size.cy * rect.Height ());
	int nTop = 1;	
	int nLeft = 7;	
	int nRight = 7;	
	if (m_nBackgroundMode == OPAQUE)
	{
		Color col;
		col.SetFromCOLORREF (m_colBackgroundColor);
		SolidBrush brush (col);
		pGraphics->FillRectangle (&brush, rect.left, rect.top, rect.Width (), rect.Height ());
	}
	Color col;
	col.SetFromCOLORREF (m_colForegroundColor);
	SolidBrush brush (col);
	for (int i = 0; i < 95; i++)
	{
		int h = nHeight + 5 * nPPM;
		if ((i >= 3) && (i < 45))
			h = nHeight;
		if ((i >= 50) && (i < 92))
			h = nHeight;
		if (m_strBars.GetAt (i) == '0')
			continue;
		pGraphics->FillRectangle (&brush, (nLeft + i + 3) * nPPM + rect.left, nTop * nPPM + rect.top, nPPM, h - 1);
	}
	BSTR bstrFont = m_strFont.AllocSysString ();
	Gdiplus::Font font (bstrFont, 8 * nPPM);
	::SysFreeString (bstrFont);
	if (m_nAddonType)
	{
		int nLeftAdd = 95 + nRight + nLeft;
		int nMax = m_nAddonType == 2 ? 20 : 47;
		for (int i = 0; i < nMax; i++)
		{
			int h = nHeight + 5 * nPPM;
			if (m_strAddBars.GetAt (i) == '0')
				continue;
			pGraphics->FillRectangle (&brush, (nLeftAdd + i) * nPPM + rect.left, (nTop + 9) * nPPM + rect.top, nPPM, h - 9 * nPPM - 1);
		}
		int nCount = 0;
		int nTxtFix = m_nAddonType == 2 ? 5 : 7;	
		for (int i = 0; i < m_nAddonType; i++)
		{
			BSTR bstrText = m_strAddon.Mid (i, 1).AllocSysString ();
			PointF pt ((nTxtFix + nLeftAdd + 7 * nCount++) * nPPM, 8 * nPPM);
			pGraphics->DrawString (bstrText, 1, &font, pt, &brush);
			::SysFreeString (bstrText);
		}
		pGraphics->DrawString (L">", 1, &font, PointF ((nLeftAdd + 1 + 9 * m_nAddonType) * nPPM, 8 * nPPM), &brush);
	}
	int nLevel = nHeight + (nTop + 0) * nPPM + rect.top;
	BSTR bstrText = m_strCode.Left (1).AllocSysString ();
	pGraphics->DrawString (bstrText, 1, &font, PointF ( rect.left, nLevel), &brush);
	::SysFreeString (bstrText);
	int nCount = 0;
	for (int i = 1; i < 13; i++)
	{
		if (i == 7)
			nCount = 0;
		bstrText = m_strCode.Mid (i, 1).AllocSysString ();
		PointF pt (((i < 7 ? 5 : 51) + nLeft + 7 * nCount++) * nPPM + rect.left, nLevel);
		pGraphics->DrawString (bstrText, 1, &font, pt, &brush);
		::SysFreeString (bstrText);
	}
	if (!m_nAddonType)
		pGraphics->DrawString (L">", 1, &font, PointF ((95 + nLeft) * nPPM + rect.left, nLevel), &brush);
}
void CEAN13 :: Render ( Gdiplus :: Graphics * pGraphics , CRect rect ) { if ( m_strBars . IsEmpty ( ) ) SetCode ( m_strCode , m_strAddon ) ; CSize size = GetSize ( ) ; int nPPM = ( int ) ( ( ( double ) size . cy / ( double ) rect . Height ( ) ) * ( double ) MODULE ) ; int nHeight = ( int ) ( ( ( EAN13_HEIGHT - 1 ) * 100 ) / ( double ) size . cy * rect . Height ( ) ) ; int nTop = 1 ; int nLeft = 7 ; int nRight = 7 ; if ( m_nBackgroundMode == OPAQUE ) { Color col ; col . SetFromCOLORREF ( m_colBackgroundColor ) ; SolidBrush brush ( col ) ; pGraphics -> FillRectangle ( & brush , rect . left , rect . top , rect . Width ( ) , rect . Height ( ) ) ; } Color col ; col . SetFromCOLORREF ( m_colForegroundColor ) ; SolidBrush brush ( col ) ; for ( int i = 0 ; i < 95 ; i ++ ) { int h = nHeight + 5 * nPPM ; if ( ( i >= 3 ) && ( i < 45 ) ) h = nHeight ; if ( ( i >= 50 ) && ( i < 92 ) ) h = nHeight ; if ( m_strBars . GetAt ( i ) == ' ' ) continue ; pGraphics -> FillRectangle ( & brush , ( nLeft + i + 3 ) * nPPM + rect . left , nTop * nPPM + rect . top , nPPM , h - 1 ) ; } BSTR bstrFont = m_strFont . AllocSysString ( ) ; Gdiplus :: Font font ( bstrFont , 8 * nPPM ) ; :: SysFreeString ( bstrFont ) ; if ( m_nAddonType ) { int nLeftAdd = 95 + nRight + nLeft ; int nMax = m_nAddonType == 2 ? 20 : 47 ; for ( int i = 0 ; i < nMax ; i ++ ) { int h = nHeight + 5 * nPPM ; if ( m_strAddBars . GetAt ( i ) == ' ' ) continue ; pGraphics -> FillRectangle ( & brush , ( nLeftAdd + i ) * nPPM + rect . left , ( nTop + 9 ) * nPPM + rect . top , nPPM , h - 9 * nPPM - 1 ) ; } int nCount = 0 ; int nTxtFix = m_nAddonType == 2 ? 5 : 7 ; for ( int i = 0 ; i < m_nAddonType ; i ++ ) { BSTR bstrText = m_strAddon . Mid ( i , 1 ) . AllocSysString ( ) ; PointF pt ( ( nTxtFix + nLeftAdd + 7 * nCount ++ ) * nPPM , 8 * nPPM ) ; pGraphics -> DrawString ( bstrText , 1 , & font , pt , & brush ) ; :: SysFreeString ( bstrText ) ; } pGraphics -> DrawString ( L" " , 1 , & font , PointF ( ( nLeftAdd + 1 + 9 * m_nAddonType ) * nPPM , 8 * nPPM ) , & brush ) ; } int nLevel = nHeight + ( nTop + 0 ) * nPPM + rect . top ; BSTR bstrText = m_strCode . Left ( 1 ) . AllocSysString ( ) ; pGraphics -> DrawString ( bstrText , 1 , & font , PointF ( rect . left , nLevel ) , & brush ) ; :: SysFreeString ( bstrText ) ; int nCount = 0 ; for ( int i = 1 ; i < 13 ; i ++ ) { if ( i == 7 ) nCount = 0 ; bstrText = m_strCode . Mid ( i , 1 ) . AllocSysString ( ) ; PointF pt ( ( ( i < 7 ? 5 : 51 ) + nLeft + 7 * nCount ++ ) * nPPM + rect . left , nLevel ) ; pGraphics -> DrawString ( bstrText , 1 , & font , pt , & brush ) ; :: SysFreeString ( bstrText ) ; } if ( ! m_nAddonType ) pGraphics -> DrawString ( L" " , 1 , & font , PointF ( ( 95 + nLeft ) * nPPM + rect . left , nLevel ) , & brush ) ; }
nPPM - pixels per module, nHeight - bar nHeight in pixels
nPPM - pixels per module nHeight - bar nHeight in pixels
// nTop margin
 // EAN-13 - 11, EAN-8 - 7
 // always 7				
 // fix for text output
 //pDC->TextOut ((nLeftAdd + 1 + 9 * m_nAddonType) * nPPM, 8 * nPPM, ">");
 /*7*/ //	pDC->TextOut (/*3 * nPPM + */rect.left, nLevel, m_strCode.Left (1));
 /*-3 * nPPM +*/ //PointF pt (((i < 7 ? 2 : 48) + nLeft + 7 * nCount++) * nPPM + rect.left, nLevel);
