//--------------------------------------------------------------------------------- //public bool GetCharDscr(int cIdx, out float width, out float height, ref Vector2 inTexPos, ref Vector2 inTexSize) public bool GetCharDscr(int cIdx, out float width, ref Vector2 inTexPos, ref Vector2 inTexSize) { bool res = false; width = 0; //height = 0; if (Initialize()) { if (m_CharLookUpTable.ContainsKey(cIdx)) { C_CharDscr cDscr = (C_CharDscr)m_CharLookUpTable[cIdx]; width = cDscr.m_Width * m_CharMaxWidth; inTexPos.x = cDscr.m_CX; inTexPos.y = cDscr.m_CY; inTexSize.x = cDscr.m_CW - cDscr.m_CX; inTexSize.y = cDscr.m_CH - cDscr.m_CY; //height = inTexSize.y * 1024; // 1024 is size of our old texture res = true; } } return(res); }
//--------------------------------------------------------------------------------- public float GetCharHeight(int cIdx) { float height = 0.0f; if (Initialize()) { if (m_CharLookUpTable != null && m_CharLookUpTable.ContainsKey(cIdx)) { C_CharDscr cDscr = (C_CharDscr)m_CharLookUpTable[cIdx]; height = cDscr.m_CH - cDscr.m_CY; } } //Debug.Log("height of '" + cIdx + "' = " + height); return(height); }
//--------------------------------------------------------------------------------- public void AddChar(int cIdx, float width, float cx, float cy, float cw, float ch) { C_CharDscr cDscr = new C_CharDscr(cIdx, width, cx, cy, cw, ch); int length = 0; if (m_CharTable != null) { length = m_CharTable.Length; } C_CharDscr[] tmpArray = new C_CharDscr[length + 1]; if (length != 0) { m_CharTable.CopyTo(tmpArray, 0); } tmpArray[length] = cDscr; m_CharTable = tmpArray; }
//--------------------------------------------------------------------------------- bool Initialize() { if (!m_IsInitialized || m_CharLookUpTable == null) { if (m_CharTable != null && m_CharTable.Length > 0) { m_CharLookUpTable = new Hashtable(); for (int i = 0; i < m_CharTable.Length; ++i) { C_CharDscr charDscr = m_CharTable[i]; m_CharLookUpTable[charDscr.m_Idx] = charDscr; } m_IsInitialized = true; } } return(m_IsInitialized); }
public bool GetTextSize(string inText, out Vector2 outSize, bool inTreatSpecialChars, char inMissingChar) { outSize = Vector2.zero; if (Initialize() == false) { return(false); } bool hasMissingCharacter = inMissingChar > 0 ? m_CharLookUpTable.ContainsKey(inMissingChar) : false; for (int i = 0; i < inText.Length; i++) { int ch = inText[i]; if (m_CharLookUpTable.ContainsKey(ch) == false) { if (hasMissingCharacter == false) { continue; // or return false ??? } ch = inMissingChar; } C_CharDscr cDscr = (C_CharDscr)m_CharLookUpTable[ch]; outSize.x += cDscr.m_Width * m_CharMaxWidth; float h = cDscr.m_CH - cDscr.m_CY; if (h > outSize.y) { outSize.y = h; } } return(true); }