示例#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;
        }
示例#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();
    }
 private static System.Windows.Forms.NativeMethods.FONTDESC GetFONTDESCFromFont(System.Drawing.Font font)
 {
     System.Windows.Forms.NativeMethods.FONTDESC fontdesc = null;
     if (fontTable == null)
     {
         fontTable = new Hashtable();
     }
     else
     {
         fontdesc = (System.Windows.Forms.NativeMethods.FONTDESC) fontTable[font];
     }
     if (fontdesc == null)
     {
         fontdesc = new System.Windows.Forms.NativeMethods.FONTDESC {
             lpstrName = font.Name,
             cySize = (long) (font.SizeInPoints * 10000f)
         };
         System.Windows.Forms.NativeMethods.LOGFONT logFont = new System.Windows.Forms.NativeMethods.LOGFONT();
         font.ToLogFont(logFont);
         fontdesc.sWeight = (short) logFont.lfWeight;
         fontdesc.sCharset = logFont.lfCharSet;
         fontdesc.fItalic = font.Italic;
         fontdesc.fUnderline = font.Underline;
         fontdesc.fStrikethrough = font.Strikeout;
         fontTable[font] = fontdesc;
     }
     return fontdesc;
 }
示例#4
0
 /// <summary>	
 /// Creates a font object that matches the properties specified by the LOGFONT structure. 	
 /// </summary>	
 /// <param name="font">A <see cref="System.Drawing.Font"/> description. </param>
 /// <returns>a reference to a newly created <see cref="SharpDX.DirectWrite.Font"/>. </returns>
 /// <unmanaged>HRESULT IDWriteGdiInterop::CreateFontFromLOGFONT([In] const LOGFONTW* logFont,[Out] IDWriteFont** font)</unmanaged>
 public Font FromSystemDrawingFont(System.Drawing.Font font)
 {
     var logfontw = new Win32Native.LogFont();
     font.ToLogFont(logfontw);
     return FromLogFont(logfontw);
 }
        private static System.IntPtr CreateFont(System.Drawing.Font font)
        {
            Skybound.Windows.Forms.TextRenderer.LOGFONT logfont2;

            logfont2 = new Skybound.Windows.Forms.TextRenderer.LOGFONT();
            object obj = logfont2;
            font.ToLogFont(obj);
            Skybound.Windows.Forms.TextRenderer.LOGFONT logfont1 = (Skybound.Windows.Forms.TextRenderer.LOGFONT)obj;
            logfont1.lfFaceName = font.Name;
            logfont1.lfQuality = 0;
            return Skybound.Windows.Forms.TextRenderer.CreateFontIndirect(ref logfont1);
        }
 private static void FontToLogFont(System.Drawing.Font value, System.Windows.Forms.NativeMethods.LOGFONT logfont)
 {
     value.ToLogFont(logfont);
 }