Example #1
0
File: font.cpp Project: viticm/pap2
UINT  Font::PreloadText(LPCSTR lpchText, int cchText)
{
	// check valid
	if ((NULL == lpchText)
		|| (-1 >  cchText)
		|| (0  == cchText))
	{
		return 0;
	}


	// draw text
	LPCWSTR lpchStr = charToUnicode(lpchText, cchText);
	UINT    nPreloadText = 0;

	while (*lpchStr)
	{
		// get char code
		if (charGlyphHit(* lpchStr ++))
		{
			++ nPreloadText;
		}

	}


	return nPreloadText;
}
// -----------------------------------------------------------------------
// Translate ANSI SQL names from Default ANSI SQL Name character set
// to UCS-2 encoding values.  The contents of the outWcs parameter is
// clear and set to the newly computed UCS2 string
// -----------------------------------------------------------------------
void CmAnsiNameToUCS2(const NAString &inMbs, NAWString &outWcs)
{
  outWcs.remove(0); // set to an empty string
  if (inMbs.length() <= 0)
  {
    return;
  }
  NAWString * pTargetNAWString =
    charToUnicode ( (Lng32)ComGetNameInterfaceCharSet() // in - Lng32        strCharSet
                  , inMbs.data()                        // in - const char * str
                  , (Int32)inMbs.length()               // in - Int32        len
                  , (NAMemory *)STMTHEAP                // in - NAMemory *   h
                  );
  ComASSERT(pTargetNAWString != NULL AND pTargetNAWString->length() > 0 AND
             pTargetNAWString->length() <= ComMAX_ANSI_IDENTIFIER_INTERNAL_LEN/*in NAWchars*/);
  outWcs.append(pTargetNAWString->data(), pTargetNAWString->length());
  delete pTargetNAWString;
}
Example #3
0
File: font.cpp Project: viticm/pap2
////////////////////////////////////////////////
// get char width / height
BOOL  Font::GetTextExtent(LPCTSTR lpchText, int cchText, FLOAT &fWidth, FLOAT &fHeight, FLOAT cchSpace)
{
	// check valid
	if ((NULL == lpchText)
		|| (-1 >  cchText)
		|| (0  == cchText))
	{
		return FALSE;
	}


	// draw text
	LPCWSTR lpchStr = charToUnicode(lpchText, cchText);
	FLOAT   penX = 0.0f, penY = 0.0f;
	FLOAT	spaceX = cchSpace * m_fontScalingX;
	FLOAT	spaceY = cchSpace * m_fontScalingY;


	while (*lpchStr)
	{
		// get char code
		WCHAR const charCode = * lpchStr ++;
		WCHAR const charNextCode = * lpchStr;


		// hinting and draw
		FLOAT glyphAdvX = 0.0f, glyphAdvY = 0.0f;

		if (charGlyphHit(charCode) && charGlyphAdvance(charCode, charNextCode, glyphAdvX, glyphAdvY))
		{
		}


		penX += glyphAdvX * m_fontScalingX + spaceX;
		penY += glyphAdvY * m_fontScalingY + spaceY;
	}


	fWidth = ( m_fontVertical ? GetCharWidth()  * m_fontScalingX: penX);
	fHeight = (!m_fontVertical ? GetCharHeight() * m_fontScalingY: penY);

	return TRUE;
}
Example #4
0
File: font.cpp Project: viticm/pap2
BOOL Font::GetTextPosExtent(LPCTSTR lpchText, int cchText, FLOAT fCursorPos, LPINT lpCharPos, FLOAT cchSpace)
{
	// check valid
	if (lpCharPos == NULL || lpchText == NULL || cchText < -1 || cchText == 0)
		return FALSE;

	// draw text
	LPCWSTR lpchStr = charToUnicode(lpchText, cchText);
	LPCTSTR lpchToken = lpchText;

	FLOAT penX = 0.0f, penEndX = fCursorPos;
	FLOAT scalingX = (m_fontVertical ? m_fontScalingY : m_fontScalingX);
	FLOAT spaceX = cchSpace * scalingX;

	for (; *lpchStr; ++ lpchStr, lpchToken = ::CharNext(lpchToken))
	{
		WCHAR const charCode = *lpchStr;
		WCHAR const charNextCode = * (lpchStr + 1);

		// hinting and draw
		FLOAT glyphAdvX = 0.0f, glyphAdvY = 0.0f;

		if (charGlyphHit(charCode) && charGlyphAdvance(charCode, charNextCode, glyphAdvX, glyphAdvY))
		{
		}


		penX += (m_fontVertical ? glyphAdvY : glyphAdvX) * scalingX + spaceX;

		if (penX > penEndX + 0.0001f)
		{
			break ;
		}
	}


	*lpCharPos = (INT)(lpchToken - lpchText);
	return TRUE;
}
NAString *charToChar(Lng32 targetCS, const char *s, Int32 sLenInBytes, Lng32 sourceCS, 
                     NAMemory *h /* = NULL */, NABoolean allowInvalidChar /* = FALSE */)
{
  NAString *res = NULL;
  if (s == NULL || sourceCS == (Lng32)CharInfo::UnknownCharSet || targetCS == (Lng32)CharInfo::UnknownCharSet)
  {
    return NULL; // error
  }
  if (sLenInBytes == 0)
  {
    if (h)
      res = new (h) NAString(h); // empty string
    else
      res = new NAString;
    return res;
  }
  if (targetCS == sourceCS)
  {
    if (h)
      res = new (h) NAString(s, sLenInBytes, h); // deep copy
    else
      res = new NAString(s, sLenInBytes); // deep copy

    return res;
  }

  // targetCS != sourceCS

  if ((CharInfo::CharSet)sourceCS == CharInfo::UCS2)
  {
    res = unicodeToChar ( (const NAWchar *)s              // source string
                        , sLenInBytes / BYTES_PER_NAWCHAR // src len in NAWchars
                        , targetCS
                        , h
                        , allowInvalidChar
                        );
    return res;
  }

  // sourceCS != CharInfo::UCS2

  NAWString * wstr = charToUnicode ( sourceCS     // src char set
                                   , s            // src str
                                   , sLenInBytes  // src str len in bytes
                                   , h            // heap for allocated target str
                                   );
  if (wstr == NULL) // conversion failed
  {
    return NULL; // error
  }
  if ((CharInfo::CharSet)targetCS == CharInfo::UCS2)
  {
    if (h)
      res = new (h) NAString ( (const char *)wstr->data()         // source string
                             , wstr->length() * BYTES_PER_NAWCHAR // source len in bytes
                             , h
                             );
    else
      res = new NAString ( (const char *)wstr->data()         // source string
                         , wstr->length() * BYTES_PER_NAWCHAR // source len in bytes
                         );

    delete wstr;
    return res;
  }

  // targetCS != CharInfo::UCS2
  
  res = unicodeToChar ( wstr->data()
                      , wstr->length() // in NAWchars
                      , targetCS
                      , h
                      , allowInvalidChar
                      );
  delete wstr;
  return res;
}
Example #6
0
File: font.cpp Project: viticm/pap2
void  Font::drawStandardText(FLOAT baseX, FLOAT baseY, LPCTSTR lpchText, int cchText, FN_DRAWGLYPH fnDrawText)
{
	LPCWSTR lpchStr = charToUnicode(lpchText, cchText);
	D3DCOLOR fontColour = GetTextColour();
	BYTE fontAlpha  = GetTextAlpha();

	if (m_fontEffect & KG3DFONT_STYLE_PROJECTION)
	{
		SetTextColor(m_fontProjectionColor);

		drawNormalText(baseX + (m_fontProjectionWeight << 1), baseY + m_fontProjectionWeight, lpchStr, fnDrawText);
	}
	if (m_fontEffect & KG3DFONT_STYLE_BORDER)
	{
		SetTextColor(m_fontBorderColor);

		if (1 == m_fontBorderWeight)
		{
			for (int y = -m_fontBorderWeight; y <= m_fontBorderWeight; ++ y)
			{
				for (int x = -m_fontBorderWeight; x <= m_fontBorderWeight; ++ x)
				{
					if ((0 == x) && (0 == y))
					{
						continue ;
					}
					
					drawNormalText(baseX + x, baseY + y, lpchStr, fnDrawText);
				}
			}
		}
		else
		{
			int xBegin = -m_fontBorderWeight + 1;
			int xEnd = m_fontBorderWeight - 1;

			for (int x = xBegin; x <= xEnd; ++ x)
				drawNormalText(baseX + x, baseY - m_fontBorderWeight, lpchStr, fnDrawText);

			for (int x = xBegin; x <= xEnd; ++ x)
				drawNormalText(baseX + x, baseY + m_fontBorderWeight, lpchStr, fnDrawText);

			int yBegin	= -m_fontBorderWeight + 1;
			int yEnd = m_fontBorderWeight - 1;

			for (int y = yBegin; y <= yEnd; ++ y)
			{
				for (int x = -m_fontBorderWeight; x <= m_fontBorderWeight; ++ x)
				{
					if ((0 == x) && (0 == y))
					{
						continue ;
					}

					drawNormalText(baseX + x, baseY + y, lpchStr, fnDrawText);
				}
			}
		}
	}
	
	SetTextAlpha(fontAlpha);
	SetTextColor(fontColour);

	drawNormalText(baseX, baseY, lpchStr, fnDrawText);
}