Esempio n. 1
0
        public static int GetNorAlignCharOffsetAt(HCCanvas aCanvas, string aText, int x)
        {
            int Result = -1;

            if (x < 0)
                Result = 0;
            else
            {
                int vLen = aText.Length;
                int[] vCharWArr = new int[vLen];
                SIZE vSize = new SIZE(0, 0);
                aCanvas.GetTextExtentExPoint(aText, vLen, vCharWArr, ref vSize);

                if (x > vSize.cx)
                    Result = vLen;
                else
                {
                    int i = 1;
                    while (i <= vLen)
                    {
                        #if UNPLACEHOLDERCHAR
                        i = HC.GetTextActualOffset(aText, i, true);
                        #endif

                        if (x == vCharWArr[i - 1])
                        {
                            Result = i;
                            break;
                        }
                        else
                        if (x > vCharWArr[i - 1])
                            i++;
                        else
                        {
                            if (x > HC.GetCharHalfFarfrom(
                                #if UNPLACEHOLDERCHAR
                                aText,
                                #endif
                                i, vCharWArr))
                            {
                                Result = i;
                            }
                            else
                            {
                                #if UNPLACEHOLDERCHAR
                                Result = HC.GetTextActualOffset(aText, i) - 1;
                                #else
                                Result = i - 1;
                                #endif
                            }

                            break;
                        }
                    }
                }
            }

            return Result;
        }