Example #1
0
        internal static void MeasureCharWidths(IntPtr hFont,
                                               out int[] charWidths,
                                               out NativeTextWin32.FontABC[] abcSizes)
        {
            //only in ascii range
            //current version
            charWidths = new int[MAX_CODEPOINT_NO + 1]; //
            MyWin32.SelectObject(win32MemDc.DC, hFont);
            unsafe
            {
                //see: https://msdn.microsoft.com/en-us/library/ms404377(v=vs.110).aspx
                //A code page contains 256 code points and is zero-based.
                //In most code pages, code points 0 through 127 represent the ASCII character set,
                //and code points 128 through 255 differ significantly between code pages
                abcSizes = new NativeTextWin32.FontABC[MAX_CODEPOINT_NO + 1];
                fixed(NativeTextWin32.FontABC *abc = abcSizes)
                {
                    NativeTextWin32.GetCharABCWidths(win32MemDc.DC, (uint)0, (uint)MAX_CODEPOINT_NO, abc);
                }

                for (int i = 0; i < (MAX_CODEPOINT_NO + 1); ++i)
                {
                    charWidths[i] = abcSizes[i].Sum;
                }
            }
        }
Example #2
0
        public void MeasureCharWidths(IntPtr hFont, out int[] charWidths, out NativeTextWin32.FontABC[] abcSizes)
        {
            if (!isInit)
            {
                Init();
            }
            //only in ascii range
            //current version
            charWidths = new int[256];
            MyWin32.SelectObject(hdc, hFont);
            unsafe
            {
                abcSizes = new NativeTextWin32.FontABC[256];
                fixed(NativeTextWin32.FontABC *abc = abcSizes)
                {
                    NativeTextWin32.GetCharABCWidths(hdc, (uint)0, (uint)255, abc);
                }

                for (int i = 0; i < 161; i++)
                {
                    charWidths[i] = abcSizes[i].Sum;
                }
                for (int i = 161; i < 255; i++)
                {
                    charWidths[i] = abcSizes[i].Sum;
                }
            }
        }