Example #1
0
 public static extern int GetGlyphOutline(IntPtr hdc, uint uChar, uint fuFormat, out GLYPHMETRICS lpgm, uint cbBuffer, IntPtr lpBuffer, ref MAT2 lpmat2);
Example #2
0
        /// <summary>
        /// ��ȡ����������б�
        /// </summary>
        /// <param name="hdc">����</param>
        /// <param name="uChar">�ַ�</param>
        /// <returns></returns>
        private static DOutline GetOutline(IntPtr hdc, uint uChar)
        {
            // ת�þ���
            MAT2 mat2 = new MAT2();
            mat2.eM11.value = 1;
            mat2.eM22.value = 1;

            GLYPHMETRICS lpGlyph = new GLYPHMETRICS();

            //��ȡ��������С
            int bufferSize = GdiNativeMethods.GetGlyphOutline(hdc, uChar, GGO_NATIVE, out lpGlyph, 0, IntPtr.Zero, ref mat2);

            if (bufferSize > 0)
            {
                //��ȡ�ɹ��󣬷����й��ڴ�
                IntPtr buffer = Marshal.AllocHGlobal(bufferSize);
                try
                {
                    int ret = GdiNativeMethods.GetGlyphOutline(hdc, uChar, GGO_NATIVE, out lpGlyph, (uint)bufferSize, buffer, ref mat2);
                    if (ret > 0)
                    {
                        //��������
                        DOutline outline = new DOutline(lpGlyph.gmBlackBoxX, lpGlyph.gmBlackBoxY);
                        //�ӻ�����������������
                        FillPolygons(outline, buffer, bufferSize);

                        return outline;
                    }
                    else
                    {
                        throw new Exception("��ȡ��������ʧ�ܣ�");
                    }
                }
                finally
                {
                    //�ͷ��й��ڴ�
                    Marshal.FreeHGlobal(buffer);
                }
            }
            else
            {
                throw new Exception("δ�ܻ�ȡ��������");
            }
        }