Exemplo n.º 1
0
        public void Draw()
        {
            GlyphPlanList glyphPlans = _line._glyphPlans;
            List <UserCharToGlyphIndexMap> userCharToGlyphIndexMap = _line._userCharToGlyphMap;

            if (_line.ContentChanged)
            {
                //re-calculate
                char[] textBuffer = _line._charBuffer.ToArray();
                glyphPlans.Clear();

                userCharToGlyphIndexMap.Clear();

                //read glyph plan and userCharToGlyphIndexMap

                _printer.GenerateGlyphPlan(textBuffer, 0, textBuffer.Length, glyphPlans, userCharToGlyphIndexMap);


                toPxScale            = _printer.Typeface.CalculateScaleToPixelFromPointSize(_printer.FontSizeInPoints);
                _line.ContentChanged = false;
            }

            if (glyphPlans.Count > 0)
            {
                _printer.DrawFromGlyphPlans(glyphPlans, X, Y);
                //draw caret
                //not blink in this version
                int caret_index = _line.CaretCharIndex;
                //find caret pos based on glyph plan
                //TODO: check when do gsub (glyph number may not match with user char number)

                if (caret_index == 0)
                {
                    _printer.DrawCaret(X, this.Y);
                }
                else
                {
                    UserCharToGlyphIndexMap map = userCharToGlyphIndexMap[caret_index - 1];
                    GlyphPlan p = glyphPlans[map.glyphIndexListOffset_plus1 + map.len - 2];
                    _printer.DrawCaret(X + p.ExactRight, this.Y);
                }
            }
            else
            {
                _printer.DrawCaret(X, this.Y);
            }
        }
        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.advX <= 0)
                    {
                        //caret can't rest here
                        //so
                        DoLeft();   //recursive ***
                        return;
                    }
                    //---------------------
                    //
                }
            }
            else
            {
            }
        }
Exemplo n.º 3
0
        public void DoRight()
        {
            int count = _charBuffer.Count;

            if (count == 0)
            {
                return;
            }
            else if (_caretCharIndex < count)
            {
                //this is on the end
                _caretCharIndex++;

                //check if the caret can rest on this glyph?
                if (_caretCharIndex < count)
                {
                    //find its mapping to glyph index
                    UserCharToGlyphIndexMap userCharToGlyphMap = _userCharToGlyphMap[_caretCharIndex];
                    int mapToGlyphIndex = userCharToGlyphMap.glyphIndexListOffset_plus1;
                    //
                    if (mapToGlyphIndex == 0)
                    {
                        //no map
                        DoRight();   //recursive ***
                        return;
                    }
                    //-------------------------
                    //we -1 ***
                    GlyphPlan glyphPlan = _glyphPlans[userCharToGlyphMap.glyphIndexListOffset_plus1 - 1];
                    if (!glyphPlan.AdvanceMoveForward)
                    {
                        //caret can't rest here
                        //so
                        DoRight();   //recursive ***
                        return;
                    }
                }
            }
            else
            {
            }
        }
        public void SetCharIndexFromPos(float x, float y, float toPxScale)
        {
            int   count   = _glyphPlans.Count;
            float accum_x = 0;

            for (int i = 0; i < count; ++i)
            {
                float thisGlyphW = _glyphPlans[i].advX * toPxScale;
                accum_x += thisGlyphW;
                if (accum_x > x)
                {
                    //TODO: review here
                    //for some glyph that has been substitued
                    //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))
                    {
                        _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].advX <= 0)
                            {
                                //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].advX <= 0)
                            {
                                //recursive ***
                                DoLeft();
                            }
                        }
                    }
                    //stop
                    break;
                }
            }
        }