public void CreateMapFromUserCharToGlyphIndics() { //(optional) //this method should be called after we finish the substitution process _mapUserCharToGlyphIndics.Clear(); //-------------------------------------- int userCharCount = _originalChars.Count; for (int i = 0; i < userCharCount; ++i) { var charToGlyphMap = new UserCharToGlyphIndexMap(); #if DEBUG charToGlyphMap.dbug_userCharIndex = (ushort)i; charToGlyphMap.dbug_userChar = _originalChars[i]; #endif _mapUserCharToGlyphIndics.Add(charToGlyphMap); } //-------------------------------------- //then fill with glyphindex to user char information int glyphIndexCount = _glyphIndices.Count; for (int i = 0; i < glyphIndexCount; ++i) { GlyphIndexToUserChar glyphIndexToUserChar = _mapGlyphIndexToUserChar[i]; // UserCharToGlyphIndexMap charToGlyphIndexMap = _mapUserCharToGlyphIndics[glyphIndexToUserChar.o_user_charOffset]; charToGlyphIndexMap.AppendData((ushort)(i + 1), (glyphIndexToUserChar.len)); //replace with the changed value _mapUserCharToGlyphIndics[glyphIndexToUserChar.o_user_charOffset] = charToGlyphIndexMap; } }
public void DoLeft() { int count = _charBuffer.Count; if (count == 0) { _caretCharIndex = 0; return; } else if (_caretCharIndex > 0) { //this is on the end _caretCharIndex--; //check if the caret can rest on this glyph? if (_caretCharIndex > 0) { //find its mapping to glyph index UserCharToGlyphIndexMap userCharToGlyphMap = _userCharToGlyphMap[_caretCharIndex]; int mapToGlyphIndex = userCharToGlyphMap.glyphIndexListOffset_plus1; // if (mapToGlyphIndex == 0) { //no map DoLeft(); //recursive *** return; } //------------------------- //we -1 *** GlyphPlan glyphPlan = _glyphPlans[userCharToGlyphMap.glyphIndexListOffset_plus1 - 1]; if (!glyphPlan.AdvanceMoveForward) { //caret can't rest here //so DoLeft(); //recursive *** return; } //--------------------- // } } else { } }
public void SetCharIndexFromPos(float x, float y) { int count = _glyphPlans.Count; float accum_x = 0; for (int i = 0; i < count; ++i) { float thisGlyphW = _glyphPlans[i].AdvanceX; accum_x += thisGlyphW; if (accum_x > x) { //TODO: review here //for some glyph that has been substituted //glyph may not match with actual user char in the _line float xoffset_on_glyph = (x - (accum_x - thisGlyphW)); if (xoffset_on_glyph >= (thisGlyphW / 2)) { if (i + 1 >= _userCharToGlyphMap.Count) { //break here _caretCharIndex = i + 1; return; } _caretCharIndex = i + 1; //check if the caret can rest on this pos or not UserCharToGlyphIndexMap map = _userCharToGlyphMap[_caretCharIndex]; if (map.glyphIndexListOffset_plus1 == 0) { //no map //cant rest here if (_caretCharIndex < count) { DoRight(); } } else { //has map if (_caretCharIndex < count && !_glyphPlans[map.glyphIndexListOffset_plus1 - 1].AdvanceMoveForward) { //recursive *** DoRight(); // } } } else { _caretCharIndex = i; //check if the caret can rest on this pos or not UserCharToGlyphIndexMap map = _userCharToGlyphMap[_caretCharIndex]; if (map.glyphIndexListOffset_plus1 == 0) { //no map //cant rest here if (_caretCharIndex > 0) { //recursive *** DoLeft(); } } else { //has map if (_caretCharIndex < count && !_glyphPlans[map.glyphIndexListOffset_plus1 - 1].AdvanceMoveForward) { //recursive *** DoLeft(); } } } //stop break; } } }