예제 #1
0
        public GDIFont(string lfFaceName, int lfHeight,
            byte lfPitchAndFamily, byte lfCharSet,
            FontQuality lfQuality, FontWeight lfWeight, bool lfItalic, bool lfStrikeOut, bool lfUnderline,
            byte lfClipPrecision, byte lfOutPrecision,
            int lfEscapement, int lfOrientation,
            int lfWidth, Guid aGuid)
            : base(true, aGuid)
        {
            fFaceName = lfFaceName;
            fHeight = lfHeight;

            fLogFont = new LOGFONT();
            //fLogFont.Init();
            fLogFont.lfCharSet = lfCharSet;
            fLogFont.lfClipPrecision = lfClipPrecision;
            fLogFont.lfEscapement = lfEscapement;
            fLogFont.lfFaceName = lfFaceName;
            fLogFont.lfHeight = lfHeight;
            fLogFont.lfItalic = (byte)(lfItalic ? 1 : 0);
            fLogFont.lfOrientation = lfOrientation;
            fLogFont.lfOutPrecision = lfOutPrecision;
            fLogFont.lfPitchAndFamily = lfPitchAndFamily;
            fLogFont.lfQuality = (byte)lfQuality;
            fLogFont.lfStrikeOut = (byte)(lfStrikeOut ? 1 : 0);
            fLogFont.lfUnderline = (byte)(lfUnderline ? 1 : 0);
            fLogFont.lfWeight = (int)lfWeight;
            fLogFont.lfWidth = lfWidth;

            //fFontHandle = GDI32.CreateFontIndirect(ref fLogFont);
            
            IntPtr fontHandle = GDI32.CreateFontW(
                lfHeight, lfWidth,
                lfEscapement, lfOrientation,
                (int)lfWeight,
                (uint)(lfItalic ? 1 : 0), 
                (uint)(lfUnderline ? 1 : 0), 
                (uint)(lfStrikeOut ? 1 : 0),
                lfCharSet, 
                lfOutPrecision, 
                lfClipPrecision,
                (uint)lfQuality, 
                lfPitchAndFamily, 
                lfFaceName);

            SetHandle(fontHandle);
        }
예제 #2
0
        public static uint SelectFont(GDIContext hdc, System.Drawing.Font font)
        {
            GDI32.SelectObject(hdc, font.ToHfont());

            uint size = GDI32.GetOutlineTextMetrics(hdc, 0, IntPtr.Zero);

            if (size != uint.MaxValue)
            {
                UnmanagedMemory otm = new UnmanagedMemory((int)size);
                uint err = GDI32.GetOutlineTextMetrics(hdc, size, otm.MemoryPointer);
                uint otmEMSquare = (uint)Marshal.ReadInt32(otm, 92);
                otm.Dispose();

                LOGFONT log = new LOGFONT();
                font.ToLogFont(log);
                log.lfHeight = -(int)otmEMSquare;

                font = System.Drawing.Font.FromLogFont(log);
                GDI32.SelectObject(hdc, font.ToHfont());
            }

            return size;
        }
예제 #3
0
 public static int GetObject(IntPtr hObject, LOGFONT lp)
 {
     return GetObject(hObject, Marshal.SizeOf(typeof(LOGFONT)), lp);
 }
예제 #4
0
 public static extern IntPtr CreateFontIndirect(ref LOGFONT lplf);