Esempio n. 1
0
File: Dib.cpp Progetto: F5000/spree
BOOL CDIB::DrawText(CDC *pDC, LPCTSTR szString, COLORREF fontcolor )
{
	CFont		pfont;	
	LOGFONT		lf;
	
	lf.lfHeight=16;
	lf.lfWidth=0;
	lf.lfEscapement=0;
	lf.lfOrientation=0;
	lf.lfWeight=FW_NORMAL;
	lf.lfItalic=0;
	lf.lfUnderline=0;
	lf.lfStrikeOut=0;
	lf.lfCharSet=DEFAULT_CHARSET; //ANSI_CHARSET;
	lf.lfOutPrecision=OUT_DEFAULT_PRECIS;
	lf.lfClipPrecision=CLIP_DEFAULT_PRECIS;
	lf.lfQuality=PROOF_QUALITY;
	lf.lfPitchAndFamily=VARIABLE_PITCH | FF_ROMAN;
	wcscpy(lf.lfFaceName, _T("MS Sans Serif") );
	
	pfont.CreateFontIndirect( &lf );		
	
	CDC BufferDC;
	CBitmap BufferBitmap, *OldBitmap;
	
	BufferDC.CreateCompatibleDC ( pDC );
	CFont *pOldFont = BufferDC.SelectObject(&pfont);
	
	SIZE  size;
	GetTextExtentPoint32( BufferDC.GetSafeHdc(), szString, wcslen(szString), &size );
	
	size.cx += 16;
	
	BufferBitmap.CreateCompatibleBitmap ( pDC, size.cx, size.cy );
	OldBitmap=BufferDC.SelectObject ( &BufferBitmap );
	
	BufferDC.FillSolidRect ( 0, 0, size.cx, size.cy, 0 );		
	
	RECT rect;
	rect.left = 2;
	rect.top  = 0;
	rect.right = size.cx-1;
	rect.bottom = size.cy-1;
	
	BufferDC.SetTextColor(fontcolor);	
	BufferDC.DrawText(szString,&rect,DT_LEFT|DT_VCENTER|DT_SINGLELINE);
	
	BufferDC.SelectObject ( OldBitmap );
	
	CDIB tempDIB;
	tempDIB.Create ( size.cx, size.cy );
	GetDIBits ( pDC->m_hDC, HBITMAP(BufferBitmap), 0, size.cy, tempDIB.m_Bits, &(tempDIB.m_Info), DIB_RGB_COLORS ); 	
	BufferDC.SelectObject(pOldFont);
	pfont.DeleteObject();

	BlendRect( &tempDIB, 0, 0 );
	
	return TRUE;
}
Esempio n. 2
0
void QTwain::Create24Bit(CDIB& source,CDIB& dest)
{
	int pal;
	dest.Create(source.Width(),source.Height(),24);
	pal = source.GetPaletteSize();
	BYTE palet[768];

	for(int i=0; i < pal; i++)
	{
		COLORREF col = source.PaletteColor(i);
		palet[i*3+2] = GetRValue(col);
		palet[i*3+1] = GetGValue(col);
		palet[i*3+0] = GetBValue(col);
	}

	int j;
	int i;
	BYTE *src,*dst,*ptr;

	for(i=0; i < source.Height(); i++)
	{
		src = source.GetLinePtr(i);
		dst = dest.GetLinePtr(i);
		ptr = dst;
		int index;
		for(j=0; j < source.Width(); j++,ptr+=3)
		{
			switch(pal)
			{
			case 2:
				if(src[j>>3] & masktable[j&7])
				{
					index = 1;
				}
				else
				{
					index = 0;
				}
				break;
			case 16:
				if(j & 1)
				{
					index = src[j>>1] & 0x0f;
				}
				else
				{
					index = (src[j>>1] >> 4) & 0x0f;
				}
				break;
			case 256:
				index = src[j];
				break;
			}