Пример #1
0
        public int GetKerning(int firstUnicode, int secondUnicode)
        {
            NativeMethods.ABC first  = m_glyphSizes[ToInternalGlyphIndex(firstUnicode)];
            NativeMethods.ABC second = m_glyphSizes[ToInternalGlyphIndex(secondUnicode)];

            return(first.abcC + second.abcA); // http://msdn.microsoft.com/en-us/library/dd183418(VS.85).aspx
        }
Пример #2
0
        private unsafe void ObtainMetrics()
        {
            m_glyphSizes = new NativeMethods.ABC[m_toUnicode - m_fromUnicode + 1];

            IntPtr graphicsHdc = m_tempGraphics.GetHdc();
            IntPtr hGdiFont    = m_gdiFont.ToHfont();

            try
            {
                IntPtr lastHFont = NativeMethods.SelectObject(graphicsHdc, hGdiFont);

                NativeMethods.GetTextMetricsW(graphicsHdc, out m_textMetrics);

                fixed(NativeMethods.ABC *ptr = m_glyphSizes)
                {
                    NativeMethods.GetCharABCWidthsW(graphicsHdc, (uint)m_fromUnicode, (uint)m_toUnicode, ptr);
                }

                NativeMethods.SelectObject(graphicsHdc, lastHFont);
            }
            finally
            {
                NativeMethods.DeleteObject(hGdiFont);
                m_tempGraphics.ReleaseHdc(graphicsHdc);
            }

            m_cellSize = new Point2(m_textMetrics.tmMaxCharWidth, m_textMetrics.tmHeight);

            m_glyphs = new GlyphInfo[m_toUnicode - m_fromUnicode + 1];

            for (int i = 0; i < m_glyphs.Length; i++)
            {
                NativeMethods.ABC abcSize = m_glyphSizes[i];
                m_glyphs[i].Width = abcSize.abcA + (int)abcSize.abcB + abcSize.abcC;
            }

            //for (int i = m_fromUnicode; i <= m_toUnicode; i++)
            //{
            //    int width = (int)Math.Ceiling(m_tempGraphics.MeasureString(Convert.ToChar(i).ToString(), m_gdiFont).Width);
            //    if (width > m_cellSize.X) m_cellSize.X = width;

            //    m_glyphs[ToInternalGlyphIndex(i)].Width = width;
            //}
        }