public void CreateMapFromUserCodePointToGlyphIndices(List <UserCodePointToGlyphIndex> mapUserCodePointToGlyphIndex) { //(optional) //this method should be called after we finish the substitution process //-------------------------------------- int codePointCount = _inputCodePointIndexList.Count; for (int i = 0; i < codePointCount; ++i) { // var codePointToGlyphIndexMap = new UserCodePointToGlyphIndex(); //set index that point to original codePointIndex codePointToGlyphIndexMap.userCodePointIndex = _inputCodePointIndexList[i]; // mapUserCodePointToGlyphIndex.Add(codePointToGlyphIndexMap); } //-------------------------------------- //then fill the user-codepoint with glyph information information int glyphIndexCount = _glyphIndices.Count; for (int i = 0; i < glyphIndexCount; ++i) { GlyphIndexToUserCodePoint glyphIndexToUserCodePoint = _mapGlyphIndexToUserCodePoint[i]; // UserCodePointToGlyphIndex charToGlyphIndexMap = mapUserCodePointToGlyphIndex[glyphIndexToUserCodePoint.o_codepoint_charOffset]; charToGlyphIndexMap.AppendData((ushort)(i + 1), (glyphIndexToUserCodePoint.len)); //replace with the changed value mapUserCodePointToGlyphIndex[glyphIndexToUserCodePoint.o_codepoint_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 UserCodePointToGlyphIndex userCodePointToGlyphIndex = _userCodePointToGlyphIndexMap[_caretCharIndex]; int mapToGlyphIndex = userCodePointToGlyphIndex.glyphIndexListOffset_plus1; // if (mapToGlyphIndex == 0) { //no map DoLeft(); //recursive *** return; } //------------------------- //we -1 *** PxScaledGlyphPlan glyphPlan = _glyphPlans[userCodePointToGlyphIndex.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.Length; 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 >= _userCodePointToGlyphIndexMap.Count) { //break here _caretCharIndex = i + 1; return; } _caretCharIndex = i + 1; //check if the caret can rest on this pos or not UserCodePointToGlyphIndex map = _userCodePointToGlyphIndexMap[_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 UserCodePointToGlyphIndex map = _userCodePointToGlyphIndexMap[_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; } } }