Exemplo n.º 1
0
/* fonts can be up to 16 bits wide */
static void DrawChar(char const Char, unsigned char Op)
{
  unsigned int MaskBit = BIT0; //src
  unsigned char Rows = GetCurrentFontHeight();
  unsigned char CharWidth = GetCharacterWidth(Char);
  unsigned int bitmap[MAX_FONT_ROWS];

  GetCharacterBitmap(Char, (unsigned int *)&bitmap);

  /* do things bit by bit */
  unsigned char i;
  unsigned char row;

  for (i = 0; i < CharWidth && gColumn < BYTES_PER_LINE; i++)
  {
  	for (row = 0; row < Rows; row++)
    {
//      if ((MaskBit & bitmap[row])) pMyBuffer[gRow+row].Data[gColumn] |= gBitColumnMask;
      BitOp(&pMyBuffer[gRow+row].Data[gColumn], gBitColumnMask, MaskBit & bitmap[row], Op);
    }

    /* the shift direction seems backwards... */
    MaskBit <<= 1;
    
    gBitColumnMask <<= 1;
    if (gBitColumnMask == 0)
    {
      gBitColumnMask = BIT0;
      gColumn++;
    }
  }
}
Exemplo n.º 2
0
bool CDrawContext::GetTextFitWithWordWrap( int nMaxWidth, LPCTSTR &pcszText, CSize &size, bool bStartOfLine ) const
//	Get the text that fits within the length given, return the 'size' of the text object
//	needed.
//	Returns true if all of the text fits. If this is the case then pcszText points
//	to the next text needed to be rendered.
//  richg - 19990224 - This should break only at an acceptable boundary! If the text does not
//	fit into the space provided, continue anyway!
{
	size.cx = 0;
	size.cy = GetCurrentFontHeight();
	int nLength;
	const int *parrWidths = m_pFontInfo->m_nWidths;
	const int *parrOverhang = m_pFontInfo->m_nOverhang;
	LPCTSTR pcszPreviousSpace = pcszText;
	int nSpaceLength;
	nLength = nSpaceLength = 0;

	TBYTE ch;
	//	richg - 19990224 - The way this was originally written, it can break a word
	//	in the middle, if it is the first word on the line! Words should not break,
	//	and are able to exceed the length of the space provided.
	//	A better way is to locate one word at a time, and see it it continues to fit.
	//	Stop when a word will not fit. If it is the first word, get its length.
	//	This should NOT break on &nbsp;!
	//	Unfortunately, there is no way yet to know here if we are at the beginning of a line!
	
	//	If we are at the start of a line, look past the first word to get the
	//	length. There shouldn't be any leading spaces.
	TBYTE cLast = 0;
	if (bStartOfLine)
	{
		while ((ch = *pcszText) != 0 && ch != '\r' && ch != 32 && ch != 255)
		{
			nLength += parrWidths[ ch ];
			cLast = ch;
			pcszText++;
		}
	}

	//
	//	We calculate the maximum width that will fit, we take into account the overhang for this character too.
	while( (ch = *pcszText) != 0 && ch != '\r' && nLength + ( parrWidths[ ch ] + ( ( ch == 32 || ch == 255 ) ? 0 : parrOverhang[ ch ] ) ) <= nMaxWidth )
	{
		if( ch == 255 || ch == 32 )
		{
			pcszPreviousSpace = pcszText;
			nSpaceLength = nLength;
		}
		nLength += parrWidths[ ch ];
		cLast = ch;
		pcszText++;
	}

	//
	//	Spaces as the last character don't need overhang.
	if( cLast != 32 && cLast != 255 && cLast != 160 )
		nLength -= parrOverhang[ cLast ];

	//
	//	If we did not get to the ned of the text then use our *word* wrap stuff
	if( *pcszText )
	{
		if( *pcszText == '\r' )
		{
			size.cx = nLength;
		}
		else
		{
			if( nSpaceLength && *pcszText != ' ' )
			{
				pcszText = pcszPreviousSpace;
				//
				//	If we had to break on a space then we need to add the overhang onto the length
				if( cLast )
					nSpaceLength -= parrOverhang[ cLast ];
				size.cx = nSpaceLength;
			}
			else
			{
				size.cx = nLength;
			}
		}
		return false;
	}
	else
	{
		size.cx = nLength;
	}

	return true;
}