Example #1
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;
        }
Example #2
0
    /// <summary>
    /// Initializes a new instance of the <see cref="FontImage"/> class.
    /// </summary>
    public FontImage(System.Drawing.Font font, XPdfFontOptions options)
    {
#if DEBUG_
      NativeMethods.LOGFONT logFont = new NativeMethods.LOGFONT();
      font.ToLogFont(logFont);
#endif
      int error;
      IntPtr hfont = font.ToHfont();
      IntPtr hdc = NativeMethods.GetDC(IntPtr.Zero);
      error = Marshal.GetLastWin32Error();
      IntPtr oldFont = NativeMethods.SelectObject(hdc, hfont);
      error = Marshal.GetLastWin32Error();
      // size is exactly the size of the font file.
      int size = NativeMethods.GetFontData(hdc, 0, 0, null, 0);
      error = Marshal.GetLastWin32Error();
      this.bytes = new byte[size];
      int xx = NativeMethods.GetFontData(hdc, 0, 0, this.bytes, this.bytes.Length);
      NativeMethods.SelectObject(hdc, oldFont);
      NativeMethods.ReleaseDC(IntPtr.Zero, hdc);
      error.GetType();

      Read();
    }
Example #3
0
        public static bool IsTrueType(GDIContext hdc, System.Drawing.Font font)
        {
            GDI32.SelectObject(hdc, font.ToHfont());

            UnmanagedMemory tmPtr = new UnmanagedMemory(Marshal.SizeOf(typeof(TEXTMETRIC)));
            uint err = GDI32.GetTextMetrics(hdc, tmPtr.MemoryPointer);
            TEXTMETRIC tm = (TEXTMETRIC)Marshal.PtrToStructure(tmPtr.MemoryPointer, typeof(TEXTMETRIC));
            tmPtr.Dispose();

            return (tm.tmPitchAndFamily & 4) != 0;
        }