PDA

View Full Version : [JX] Ai Có thể cho mình xin code Represent2 hiển thị tiếng việt cho mình xin thank.



anhhaimientay
02-06-15, 10:28 PM
Ai Có thể cho mình xin code Represent2 hiển thị tiếng việt cho mình xin thank.

teemo_Az90
03-06-15, 12:35 AM
Ai Có thể cho mình xin code Represent2 hiển thị tiếng việt cho mình xin thank.

void KFont2::OutputText(const char* pszText, int nCount/*= KF_ZERO_END*/,
int nX/*=KF_FOLLOW*/, int nY/*=KF_FOLLOW*/,
unsigned int nColor/*=0xff000000*/, int nLineWidth/*=0*/)
{
if (!pszText || !m_bLoaded)
return;
unsigned char* lpByte = (unsigned char*) pszText;
int nL, h;
int nPos = 0;
int nHalfIndex = 0;

if (nCount == KRF_ZERO_END)
nCount = strlen(pszText);
if (nX == KRF_FOLLOW)
nX = m_nLastPosH;
if (nY == KRF_FOLLOW)
nY = m_nLastPosV;

h = 0;

KRColor c;
c.Color_dw = nColor;
int sColor = g_RGB(c.Color_b.r, c.Color_b.g, c.Color_b.b);

if (nLineWidth < m_nOutputWidth + m_nOutputWidth)
nLineWidth = 0;

while (nPos < nCount)
{
/* nL = lpByte[nPos++];
DrawCharacter(nX + h, nY, nL, 0, sColor);
if (nL != 0x0a)
{
h += m_nFontHalfWidth[nHalfIndex];
nHalfIndex ^= 1;
}
else
{
h = 0;
nY += m_nOutputHeight;
}*/
// new fix load font tieng viet
nL=lpByte[nPos++];
DrawCharacter(nX + h, nY, nL, 0, sColor);
if (nL != 0x0a)
{
h += m_nFontHalfWidth[nHalfIndex];
nHalfIndex ^= 1;
}
else
{
h = 0;
nY += m_nOutputHeight;
}
// end
if (nLineWidth)
{
if (h + m_nOutputWidth > nLineWidth)
{
if (nPos < nCount && lpByte[nPos] == 0x0a)
nPos++;
h = 0;
nY += m_nOutputHeight;
nHalfIndex = 0;
}
else if (h && nPos + 3 < nCount &&
h + m_nOutputWidth + m_nFontHalfWidth[nHalfIndex] >= nLineWidth)
{
const char* pNext = TGetSecondVisibleCharacterThisLine((const char*)lpByte, nPos, nCount);
if (pNext && TIsCharacterNotAlowAtLineHead(pNext))
{
h = 0;
nY += m_nOutputHeight;
nHalfIndex = 0;
}
}
}
}
m_nLastPosH = nX + h;
m_nLastPosV = nY;
}
---------------------------------------------
-----------------------------------------------------------------------------------------------------
//fix load font
unsigned char* KFontData::GetCharacterData(unsigned char cFirst, unsigned char cNext) const
{
if (m_pFontData)
{
unsigned int uCharIndex = cFirst;
if (uCharIndex < m_uCharCount && m_pdwOffs[uCharIndex])
return (m_pFontData + m_pdwOffs[uCharIndex]);
}
return NULL;
}
-------------------------------------------------------------------------------------------------------------
void KFont3::OutputText(const char *pszText, int nCount/*= KF_ZERO_END*/,
int nX/*= KF_FOLLOW*/, int nY/*= KF_FOLLOW*/,
unsigned int nColor /*=0xff000000*/, int nLineWidth/*= 0*/)
{
if (pszText == NULL || m_bLoaded == false || ms_pd3dDevice == NULL)
return;

unsigned int nNumChars = 0;
unsigned char* lpByte = (unsigned char*) pszText;
int nL, h;
BOOL bShowChar = false;
int nPos = 0;
int nDx = 0;
int nHalfIndex = 0;


unsigned short nCommitChars[KCS_CHAR_NUM_LIMIT];
KFontVertex vCharPolys[KCS_CHAR_NUM_LIMIT * 6];

if (nCount == KRF_ZERO_END)
nCount = strlen(pszText);
if (nX == KRF_FOLLOW)
nX = m_nLastPosH;
if (nY == KRF_FOLLOW)
nY = m_nLastPosV;

h = 0;
if (nLineWidth < m_fFontWidth + m_fFontWidth)
nLineWidth = 0;
{
m_pStateBlockSaved->Capture();
m_pStateBlockDrawText->Apply();
ms_pd3dDevice->SetFVF(KF_FONTPOLY);
ms_pd3dDevice->SetTexture(0, m_pTexture);
}

while (nPos < nCount)
{
bShowChar = false;
// fix tieng viet co dau 3D
nL=lpByte[nPos++];
nCommitChars[nNumChars] = nL;
bShowChar = true;
if (nL != 0x0a)
{
nDx = m_nFontHalfWidth[nHalfIndex];
nHalfIndex ^= 1;
}
else
{
nDx = -1;
}
if (bShowChar)
{
int n = nNumChars * 6;
KFontVertex *pCharPoly = &vCharPolys[n];
pCharPoly[0].x = ((float)(nX + h)) - 0.5f;
pCharPoly[0].y = ((float)nY) - 0.5f;

pCharPoly[4].x = pCharPoly[1].x = pCharPoly[0].x + m_fFontWidth;
pCharPoly[4].y = pCharPoly[1].y = pCharPoly[0].y;

pCharPoly[3].x = pCharPoly[2].x = pCharPoly[0].x;
pCharPoly[3].y = pCharPoly[2].y = pCharPoly[0].y + m_fFontHeight;

pCharPoly[5].x = pCharPoly[4].x;
pCharPoly[5].y = pCharPoly[2].y;

pCharPoly[0].z = 0.9f; pCharPoly[0].w = 1.0f; pCharPoly[0].color = nColor;
pCharPoly[1].z = 0.9f; pCharPoly[1].w = 1.0f; pCharPoly[1].color = nColor;
pCharPoly[2].z = 0.9f; pCharPoly[2].w = 1.0f; pCharPoly[2].color = nColor;
pCharPoly[3].z = 0.9f; pCharPoly[3].w = 1.0f; pCharPoly[3].color = nColor;
pCharPoly[4].z = 0.9f; pCharPoly[4].w = 1.0f; pCharPoly[4].color = nColor;
pCharPoly[5].z = 0.9f; pCharPoly[5].w = 1.0f; pCharPoly[5].color = nColor;

nNumChars++;

if (nNumChars >= KCS_CHAR_NUM_LIMIT)
{
m_Resources.CommitText(nCommitChars, nNumChars, vCharPolys);
ms_RenderText(vCharPolys, nNumChars * 2);
nNumChars = 0;
}
}

h += nDx;

if (nDx == -1 || (nLineWidth && h + m_nOutputWidth > nLineWidth))
{
if (nPos < nCount && lpByte[nPos] == 0x0a && nDx != -1)
nPos++;
h = 0;
nY += m_nOutputHeight;
nHalfIndex = 0;
}
else if (nDx > 0 && nLineWidth && h + nDx + m_nOutputWidth + m_nFontHalfWidth[nHalfIndex] >= nLineWidth)
{
const char* pNext = TGetSecondVisibleCharacterThisLine((const char*)lpByte, nPos, nCount);
if (pNext && TIsCharacterNotAlowAtLineHead(pNext))
{
h = 0;
nY += m_nOutputHeight;
nHalfIndex = 0;
}
}
}

if (nNumChars)
{
m_Resources.CommitText(nCommitChars, nNumChars, vCharPolys);
ms_RenderText(vCharPolys, nNumChars * 2);
nNumChars = 0;
}
{
m_pStateBlockSaved->Apply();
}
m_nLastPosH = nX + h;
m_nLastPosV = nY;
}