示例#1
0
UTF32String StringPrep::Map(
	const UTF32String str,
	std::map<unsigned, UTF32String> stringPrepMap)
{
	UTF32String mappedString;

	for(unsigned i = 0; i != str.size(); i++)
	{
		mappedString += MapCharacter(str[i], stringPrepMap);
	}
	return mappedString;
}
示例#2
0
//	---------------------------------------------------------------------------
//	---------------------------------------------------------------------------
//  ---------------------------------------------------------------------------
CUI_RESULTTYPE CUIPolyString_Impl::ApplyFont(
	CUIFont* pFont, 
	int16 index, 
	int16 num,
	bool  bProcessRemainder)
{
	uint8		cidx;
	uint8		*pFontMap;

	int32		i, len, storedWidth; 
	int32		w,h;
	int32		delta;

	uint32		texturew, textureh;
	uint32		fontFlags;

	bool 		draw,drawblank;

	float		pstrx, pstry;
  	float		cx, cy;
	float		spacing, em, bold;

	const char* str;
	
	HTEXTURE	pFontTex;

	LT_POLYGT4* pArray;

	// sanity checks
	if (!pDrawPrimInternal) return CUIR_ILT_DRAWPRIM_ERROR;
	if (!pFont) return CUIR_NO_FONT;

	if (pFont->IsProportional() && !pFont->GetFontTable())
		return CUIR_INVALID_FONT;

	pFontTex		= pFont->GetTexture();
	storedWidth		= m_CharScreenWidth;//pFont->GetCharScreenWidth();
	w				= storedWidth;					// padding
  	h				= m_CharScreenHeight;//pFont->GetCharScreenHeight(); // padding
	pFontMap		= pFont->GetFontMap();
  	spacing			= pFont->GetDefSpacingH();

	pTexInterface->GetTextureDims(pFontTex, texturew, textureh);
  
	// get some coords
	this->GetPosition(&cx, &cy);
	pstrx = cx;
	pstry = cy;
	
	// set flag attrs.
	fontFlags = pFont->GetAttributes();
	em   = 0;
	bold = 0;
	if (fontFlags & CUI_FONT_ITALIC) em    =	pFont->GetDefSlant();
	if (fontFlags & CUI_FONT_BOLD )  bold  =	pFont->GetDefBold();
	
	// are we applying to all of the string or only part?
  	len = m_Length;
	if (num == 0) num = (uint16)len;
	num = (index + num > len) ? (len) : (index+num);
	
	str      = m_pChars + index;
	pArray	 = m_pPolys;	

	// place this character next to the previous one
	if (index > 0) cx = (int16)(pArray[index-1].verts[1].x + spacing);		
	
	// the main polygon texturing loop 
  	for (i=index; i<num; i++) {

		draw		= true;
		drawblank	= false;

		// apply the font map(if any)
		//if (pFontMap) cidx = pFontMap[*str];
		//else		  cidx = (*str);
		cidx = (*str);

		// handle chars that shouldn't be subtracted (newlines, tabs, etc.)
		switch (cidx) {
			
			case 10:
				draw = false;
				break;

			case 32:
				drawblank = true;
				break;

			default:

				if (!pFontMap) {
					// if there's no fontmap, turn ascii into indices
					//cidx = (*str);
					cidx -= 33;
					if (cidx > 93) draw = false;
				}	
				else {
					cidx = pFontMap[cidx];
				}
		}
		
		if (!draw || drawblank) {			
			// draw a blank, transparent poly for a space
			w = storedWidth;
			this->MakeBlankPoly(&pArray[i]);
		}
		
		if (draw && !drawblank) {
			// set the UV coords
			MapCharacter(pFont, cidx, &pArray[i], &w, texturew, textureh);
		}
		else {
			if (!drawblank) w = 0 - (int16)(bold + spacing);
		}
    	
		// apply the new XYZ coords
		SetPolyXYZ(&pArray[i], cx, cy, w, h, em, bold);

		// increment the x position for the next char.
		cx = cx + int16(w + bold + spacing);			

		// increment our string pointer
    	str++;
  	}  	
	
	// move the polys we did not process so there won't be gaps or overlaps
	// in the string

	if (bProcessRemainder) {	
		if (num<len) {			
			delta = (int32) (pArray[num-1].verts[1].x - pArray[num].verts[0].x);
			
			for (i=num; i<len; i++) {
				pArray[i].verts[0].x += delta;
				pArray[i].verts[1].x += delta;
				pArray[i].verts[2].x += delta;
				pArray[i].verts[3].x += delta;
			}
		}
	}

	// get the extents of the new polystring
	GetExtents(&m_Rect);

	return CUIR_OK;
}