Esempio n. 1
0
 public static string GetFontFaceName(string fn)
 {
     Font ft = new Font(fn, 9F);
     LOGFONT lt = new LOGFONT();
     ft.ToLogFont(lt);
     return lt.lfFaceName;
 }
Esempio n. 2
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));
        }
Esempio n. 3
0
        public void SetFont(Font font)
        {
            var lf = new LogFont();
            font.ToLogFont(lf);
            lf.lfPitchAndFamily = FIXED_PITCH | FF_MODERN;

            NativeMethods.SendMessage(hIMEWnd, (int) WindowMessage.WM_IME_CONTROL, IMC_SETCOMPOSITIONFONT, lf);
        }
Esempio n. 4
0
        private static IntPtr CreateFontObject(Font font, bool antiAliasing)
        {
            NativeStructs.LOGFONT logFont = new NativeStructs.LOGFONT();
            font.ToLogFont(logFont);

            int nHeight = logFont.lfHeight;
            int nWidth = logFont.lfWidth;
            int nEscapement = logFont.lfEscapement;
            int nOrientation = logFont.lfOrientation;
            int fnWeight = logFont.lfWeight;
            uint fdwItalic = logFont.lfItalic;
            uint fdwUnderline = logFont.lfUnderline;
            uint fdwStrikeOut = logFont.lfStrikeOut;
            uint fdwCharSet = logFont.lfCharSet;
            uint fdwOutputPrecision = logFont.lfOutPrecision;
            uint fdwClipPrecision = logFont.lfClipPrecision;
            uint fdwQuality;
            
            if (antiAliasing)
            {
                fdwQuality = NativeConstants.ANTIALIASED_QUALITY;
            }
            else
            {
                fdwQuality = NativeConstants.NONANTIALIASED_QUALITY;
            }

            uint fdwPitchAndFamily = logFont.lfPitchAndFamily;
            string lpszFace = logFont.lfFaceName;

            IntPtr hFont = SafeNativeMethods.CreateFontW(
                nHeight,
                nWidth,
                nEscapement,
                nOrientation,
                fnWeight,
                fdwItalic,
                fdwUnderline,
                fdwStrikeOut,
                fdwCharSet,
                fdwOutputPrecision,
                fdwClipPrecision,
                fdwQuality,
                fdwPitchAndFamily,
                lpszFace);

            if (hFont == IntPtr.Zero)
            {
                NativeMethods.ThrowOnWin32Error("CreateFontW returned NULL");
            }

            return hFont;
        }
Esempio n. 5
0
        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));
        }
Esempio n. 6
0
 private void SetIMEWindowFont(System.Drawing.Font f)
 {
     if (Ime.disableIME || this.hIMEWnd == IntPtr.Zero)
     {
         return;
     }
     if (this.lf == null)
     {
         this.lf = new Ime.LOGFONT();
         f.ToLogFont(this.lf);
         this.lf.lfFaceName = f.Name;
     }
     try
     {
         Ime.SendMessage(this.hIMEWnd, 643, new IntPtr(10), this.lf);
     }
     catch (AccessViolationException accessViolationException)
     {
         this.Handle(accessViolationException);
     }
 }
Esempio n. 7
0
		public void ToLogFont_TooSmall ()
		{
			Font f = new Font ("Arial", 10);
			object o = new object ();
			f.ToLogFont (o);
			// no PInvoke conversion exists !?!?
		}
Esempio n. 8
0
		public void ToLogFont_AssertUnmanagedCode ()
		{
			Font f = new Font("Arial", 10);
			LOGFONT	lf = new LOGFONT();

			f.ToLogFont (lf);
			Assert.AreEqual (400, lf.lfWeight, "lfWeight");
			Assert.AreEqual (1, lf.lfCharSet, "lfCharSet");
			Assert.AreEqual (f.Name, lf.lfFaceName, "lfFaceName");

			LOGFONT_STRUCT lfs = new LOGFONT_STRUCT ();
			f.ToLogFont (lfs);
			Assert.AreEqual (0, lfs.lfWeight, "struct-lfWeight");
			Assert.AreEqual (0, lfs.lfCharSet, "struct-lfCharSet");
			Assert.AreEqual (0, lfs.lfHeight, "struct-lfHeight");
			Assert.AreEqual (0, lfs.lfWidth, "struct-lfWidth");
			Assert.AreEqual (0, lfs.lfEscapement, "struct-lfEscapement");
			Assert.AreEqual (0, lfs.lfOrientation, "struct-lfOrientation");
			Assert.AreEqual (0, lfs.lfWeight, "struct-lfWeight");
			Assert.AreEqual (0, lfs.lfItalic, "struct-lfItalic");
			Assert.AreEqual (0, lfs.lfUnderline, "struct-lfUnderline");
			Assert.AreEqual (0, lfs.lfStrikeOut, "struct-lfStrikeOut");
			Assert.AreEqual (0, lfs.lfCharSet, "struct-lfCharSet");
			Assert.AreEqual (0, lfs.lfOutPrecision, "struct-lfOutPrecision");
			Assert.AreEqual (0, lfs.lfClipPrecision, "struct-lfClipPrecision");
			Assert.AreEqual (0, lfs.lfQuality, "struct-lfQuality");
			Assert.AreEqual (0, lfs.lfPitchAndFamily, "struct-lfPitchAndFamily");
			Assert.IsNull (lfs.lfFaceName, "struct-lfFaceName");
		}
Esempio n. 9
0
		public void ToLogFont_DenyUnmanagedCode ()
		{
			Font f;
			LOGFONT	lf;

			lf = new LOGFONT();
			f = new Font("Arial", 10);

			f.ToLogFont(lf);
		}
Esempio n. 10
0
 public static void GetLogFont(Font font, Graphics graphics, out LOGFONT logfont)
 {
     object o = new LOGFONT();
     if (graphics != null)
     {
         font.ToLogFont(o, graphics);
     }
     else
     {
         font.ToLogFont(o);
     }
     logfont = (LOGFONT)o;
 }
Esempio n. 11
0
        private static NativeMethods.FONTDESC GetFONTDESCFromFont(Font font) {
            NativeMethods.FONTDESC fdesc = null;

            if (fontTable == null) {
                fontTable = new Hashtable();
            }
            else {
                fdesc = (NativeMethods.FONTDESC)fontTable[font];
            }

            if (fdesc == null) {
                fdesc = new NativeMethods.FONTDESC();
                fdesc.lpstrName = font.Name;
                fdesc.cySize = (long)(font.SizeInPoints * 10000);
                NativeMethods.LOGFONT logfont = new NativeMethods.LOGFONT();
                font.ToLogFont(logfont);
                fdesc.sWeight = (short) logfont.lfWeight;
                fdesc.sCharset = logfont.lfCharSet;
                fdesc.fItalic = font.Italic;
                fdesc.fUnderline = font.Underline;
                fdesc.fStrikethrough = font.Strikeout;

                fontTable[font] = fdesc;
            }

            return fdesc;
        }
Esempio n. 12
0
		public void Dispose_ToLogFont ()
		{
#if !TARGET_JVM
			Font f = new Font (name, 12.5f);
			f.Dispose ();
			LOGFONT	lf = new LOGFONT();
			f.ToLogFont (lf);
#endif
		}
Esempio n. 13
0
    public bool LoadSubtitles(IGraphBuilder graphBuilder, string filename)
    {
      FreeSubtitles();
      LoadSettings();

      {
        //remove InternalScriptRenderer as it takes subtitle pin
        IBaseFilter isr = null;
        DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.InternalScriptRenderer, out isr);
        if (isr != null)
        {
          graphBuilder.RemoveFilter(isr);
          DirectShowUtil.ReleaseComObject(isr);
        }
      }

      vobSub = (IDirectVobSub)DirectVobSubUtil.AddToGraph(graphBuilder);
      if (vobSub == null)
        return false;

      {
        //set style
        Log.Debug("VideoPlayerVMR9: Setting DirectVobsub parameters");
        LOGFONT logFont = new LOGFONT();
        int txtcolor;
        bool fShadow, fOutLine, fAdvancedRenderer = false;
        int size = Marshal.SizeOf(typeof(LOGFONT));
        vobSub.get_TextSettings(logFont, size, out txtcolor, out fShadow, out fOutLine, out fAdvancedRenderer);
        FontStyle fontStyle = defStyle.fontIsBold ? FontStyle.Regular : FontStyle.Bold;
        Font Subfont = new Font(defStyle.fontName, defStyle.fontSize, fontStyle, GraphicsUnit.Point,
                                (byte)defStyle.fontCharset);
        Subfont.ToLogFont(logFont);
        fShadow = defStyle.shadow > 0;
        fOutLine = defStyle.isBorderOutline;
        vobSub.put_TextSettings(logFont, size, defStyle.fontColor, fShadow, fOutLine, fAdvancedRenderer);
        vobSub.put_FileName(filename);

        bool fBuffer, fOnlyForced, fPolygonize;
        vobSub.get_VobSubSettings(out fBuffer, out fOnlyForced, out fPolygonize);
        vobSub.put_VobSubSettings(fBuffer, !this.autoShow, fPolygonize);
      }

      {
        //load sub streams
        IBaseFilter hms = null;
        DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.HaaliGuid, out hms);
        if (hms == null)
          DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.LAVFilterSource, out hms);
        if (hms == null)
          DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.LAVFilter, out hms);
        embeddedSelector = hms as IAMStreamSelect;
        if (embeddedSelector != null)
        {
          AddStreams(embeddedSelector);
        }

        vobSub.get_LanguageCount(out extCount);
        if (intSubs.Count > 0)
        {
          //if there are embedded subtitles,
          //last stream of directvobsub is currently selected embedded subtitle
          extCount--;
        }
      }

      FFDShowEngine.DisableFFDShowSubtitles(graphBuilder);

      Current = 0;
      if (selectionOff)
      {
        Enable = false;
      }
      else
      {
        Enable = autoShow;
      }
      return true;
    }
Esempio n. 14
0
        /// <summary>
        /// Create the font image using GDI+ functionality.
        /// </summary>
        void CreateGdiFontImage(XFont font, XPdfFontOptions options /*, XPrivateFontCollection privateFontCollection*/)
        {
            System.Drawing.Font gdiFont = font.RealizeGdiFont();
#if DEBUG_
            logFont = new NativeMethods.LOGFONT();
            gdiFont.ToLogFont(logFont);
            Debug.WriteLine("FontData: " + logFont.lfFaceName);
#endif
            this.data = null;

            // PFC
            //if (privateFontCollection != null)
            //{
            //  //XPrivateFont privateFont = privateFontCollection.FindFont(logFont.lfFaceName, logFont.lfWeight >= 700, logFont.lfItalic > 0);
            //  XGlyphTypeface privateFont = privateFontCollection.FindFont(font.Name, font.Bold, font.Italic);
            //  if (privateFont != null)
            //  {
            //    //////int size = privateFont.GetData(ref this.data);
            //    //////if (size > 0)
            //    //////{
            //    //////  this.data = new byte[size];
            //    //////  privateFont.GetData(ref this.data, size);
            //    //////}
            //  }
            //}
            if (this.data == null)
            {
                var assembly = FontDataConfig.ResourceAssembly;
                var name     = string.Format("{0}.FontHacks.{1}{2}{3}.fontdat",
                                             assembly != null ? assembly.GetName().Name : string.Empty,
                                             font.Name,
                                             font.Bold ? ".Bold" : string.Empty,
                                             font.Italic ? ".Italic" : string.Empty);
                if (assembly != null && new List <string>(assembly.GetManifestResourceNames()).Contains(name))
                {
                    System.Diagnostics.Debug.WriteLine("*** Reading fontdata from Resource");
                    using (var s = assembly.GetManifestResourceStream(name))
                    {
                        this.data = new byte[s.Length];
                        s.Read(this.data, 0, (int)s.Length);
                    }
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("*** Reading fontdata from GDI+");
                    int    error;
                    IntPtr hfont = gdiFont.ToHfont();
                    using (var dcBmp = new Bitmap(100, 100))
                        using (var dc = Graphics.FromImage(dcBmp))
                        {
                            IntPtr hdc = dc.GetHdc();
                            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();
                            if (size > 0)
                            {
                                this.data = new byte[size];
                                int effectiveSize = NativeMethods.GetFontData(hdc, 0, 0, this.data, this.data.Length);
                                Debug.Assert(size == effectiveSize);
                                if (FontDataConfig.SaveFont)
                                {
                                    FileExtensions.WriteFileBytes(this.data, string.Format("..\\..\\FontHacks\\{0}{1}{2}.fontdat",
                                                                                           font.Name,
                                                                                           font.Bold ? ".Bold" : string.Empty,
                                                                                           font.Italic ? ".Italic" : string.Empty));
                                }
                                NativeMethods.SelectObject(hdc, oldFont);
                                NativeMethods.ReleaseDC(IntPtr.Zero, hdc);
                                error.GetType();
                            }
                            else
                            {
                                // Sometimes size is -1 (GDI_ERROR), but I cannot determine why. It happens only with the font 'Symbol'.
                                // The issue occurs the first time in early 2005, when I start writing PDFsharp. I could not fix it and after
                                // some code refactoring the problem disappears.
                                // There was never a report from anyone about this issue.
                                // Now I get it again (while debugging QBX 2006). Maybe it is a problem with my PC at my home office.
                                // As a work-around I create a new font handle with a different height value. This works. Maybe the
                                // font file gets locked somewhere. Very very strange.

                                // IF SOMEONE ELSE COMES HERE PLEASE LET ME KNOW!

                                // Clean up old handles
                                NativeMethods.SelectObject(hdc, oldFont);
                                NativeMethods.ReleaseDC(IntPtr.Zero, hdc);

                                // Try again with new font handle
                                var logFont = new NativeMethods.LOGFONT();
                                gdiFont.ToLogFont(logFont);
                                logFont.lfHeight += 1; // force new handle
                                IntPtr hfont2 = NativeMethods.CreateFontIndirect(logFont);
                                hdc     = NativeMethods.GetDC(IntPtr.Zero);
                                error   = Marshal.GetLastWin32Error();
                                oldFont = NativeMethods.SelectObject(hdc, hfont2);
                                error   = Marshal.GetLastWin32Error();
                                // size is exactly the size of the font file.
                                size  = NativeMethods.GetFontData(hdc, 0, 0, null, 0);
                                error = Marshal.GetLastWin32Error();
                                if (size > 0)
                                {
                                    this.data = new byte[size];
                                    int effectiveSize = NativeMethods.GetFontData(hdc, 0, 0, this.data, this.data.Length);
                                    Debug.Assert(size == effectiveSize);
                                }
                                NativeMethods.SelectObject(hdc, oldFont);
                                NativeMethods.ReleaseDC(IntPtr.Zero, hdc);
                                NativeMethods.DeleteObject(hfont2);
                                error.GetType();
                            }
                        }
                }
                if (this.data == null)
                {
                    throw new InvalidOperationException("Internal error. Font data could not retrieved.");
                }
            }
        }
Esempio n. 15
0
 /// <summary>
 /// Determines whether a font uses the 'symbol' character set.
 /// </summary>
 /// <remarks>
 /// Symbol fonts do not typically contain glyphs that represent letters of the alphabet.
 /// Instead they might contain pictures and symbols. As such, they are not useful for
 /// drawing text. Which means you can't use a symbol font to write out its own name for
 /// illustrative purposes (like for the font drop-down chooser).
 /// </remarks>
 public static bool IsSymbolFont(Font font)
 {
     NativeStructs.LOGFONT logFont = new NativeStructs.LOGFONT();
     font.ToLogFont(logFont);
     return logFont.lfCharSet == NativeConstants.SYMBOL_CHARSET;
 }
Esempio n. 16
0
 static private void FontToLogFont(Font value, NativeMethods.LOGFONT logfont) {
     value.ToLogFont(logfont);
 }
Esempio n. 17
0
 public static string GetFontFaceName(Font ft)
 {
     LOGFONT lt = new LOGFONT();
     ft.ToLogFont(lt);
     return lt.lfFaceName;
 }
Esempio n. 18
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="LogicalFont"/> class.
		/// </summary>
		/// <param name="createFrom">The font to use as the basis for the logical font.</param>
		/// <remarks>If it's not obvious why we need this class in order to determine if a font
		/// is a symbol font, see the Dr. Gui article entitled
		/// <see href="http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dnaraskdr/html/askgui12302003.asp">
		/// Determining the Character Set Used by a Font</see></remarks>
		/// ------------------------------------------------------------------------------------
		public LogicalFont(Font createFrom)
		{
			createFrom.ToLogFont(this);
		}
Esempio n. 19
0
		public void Dispose_ToLogFont ()
		{
			Font f = new Font (name, 12.5f);
			f.Dispose ();
			LOGFONT	lf = new LOGFONT();
			f.ToLogFont (lf);
		}
Esempio n. 20
0
		public void ToLogFont_Int ()
		{
			Font f = new Font ("Arial", 10);
			int i = 1;
			f.ToLogFont (i);
			Assert.AreEqual (1, i);
		}
Esempio n. 21
0
		public void ToLogFont_Null ()
		{
			Font f = new Font ("Arial", 10);
			f.ToLogFont (null);
		}
Esempio n. 22
0
        protected override void OnCreateControl()
        {
            base.OnCreateControl();
            // This hack tries to apply the Roboto (24) font to all ListViewItems in this ListView
            // It only succeeds if the font is installed on the system.
            // Otherwise, a default sans serif font is used.
            Font roboto24 = new Font(SkinManager.ROBOTO_MEDIUM_12.FontFamily, 24);
            LogFont roboto24logfont = new LogFont();
            roboto24.ToLogFont(roboto24logfont);

            try
            {
                // Font.FromLogFont is the method used when drawing ListViewItems. I 'test' it in this safer context to avoid unhandled exceptions later.
                Font = Font.FromLogFont(roboto24logfont);
        }
            catch (ArgumentException)
            {
                Font = new Font(FontFamily.GenericSansSerif, 24);
    }
}
Esempio n. 23
0
		public void Dispose_ToLogFont_LoopCharSet ()
		{
#if !TARGET_JVM
			Font f = new Font (name, 12.5f);
			f.Dispose ();
			LOGFONT lf = new LOGFONT ();

			for (int i = Byte.MinValue; i < Byte.MaxValue; i++) {
				byte b = (byte) i;
				lf.lfHeight = b;
				lf.lfWidth = b;
				lf.lfEscapement = b;
				lf.lfOrientation = b;
				lf.lfWeight = b;
				lf.lfItalic = b;
				lf.lfUnderline = b;
				lf.lfStrikeOut = b;
				lf.lfCharSet = b;
				lf.lfOutPrecision = b;
				lf.lfClipPrecision = b;
				lf.lfQuality = b;
				lf.lfPitchAndFamily = b;
				lf.lfFaceName = b.ToString ();
				try {
					f.ToLogFont (lf);
				}
				catch (ArgumentException) {
					Assert.AreEqual (b, lf.lfHeight, "lfHeight");
					Assert.AreEqual (b, lf.lfWidth, "lfWidth");
					Assert.AreEqual (b, lf.lfEscapement, "lfEscapement");
					Assert.AreEqual (b, lf.lfOrientation, "lfOrientation");
					Assert.AreEqual (b, lf.lfWeight, "lfWeight");
					Assert.AreEqual (b, lf.lfItalic, "lfItalic");
					Assert.AreEqual (b, lf.lfUnderline, "lfUnderline");
					Assert.AreEqual (b, lf.lfStrikeOut, "lfStrikeOut");
					// special case for 0
					Assert.AreEqual ((i == 0) ? (byte)1 : b, lf.lfCharSet, "lfCharSet");
					Assert.AreEqual (b, lf.lfOutPrecision, "lfOutPrecision");
					Assert.AreEqual (b, lf.lfClipPrecision, "lfClipPrecision");
					Assert.AreEqual (b, lf.lfQuality, "lfQuality");
					Assert.AreEqual (b, lf.lfPitchAndFamily, "lfPitchAndFamily");
					Assert.AreEqual (b.ToString (), lf.lfFaceName, "lfFaceName");
				}
				catch (Exception e) {
					Assert.Fail ("Unexcepted exception {0} at iteration {1}", e, i);
				}
			}
#endif
		}
Esempio n. 24
0
    private void SetIMEWindowFont(Font f)
    {
      if (disableIME || hIMEWnd == IntPtr.Zero) return;

      if (lf == null)
      {
        lf = new LOGFONT();
        f.ToLogFont(lf);
        lf.lfFaceName = f.Name;  // This is very important! "Font.ToLogFont" Method sets invalid value to LOGFONT.lfFaceName
      }

      try
      {
        SendMessage(hIMEWnd, WM_IME_CONTROL, new IntPtr(IMC_SETCOMPOSITIONFONT), lf );
      }
      catch (AccessViolationException ex)
      {
        Handle(ex);
      }
    }
Esempio n. 25
0
		private void SetIMEWindowFont(Font f)
		{
			LOGFONT lf = new LOGFONT();
			f.ToLogFont(lf);
			lf.lfPitchAndFamily = FIXED_PITCH | FF_MODERN;
			
			SendMessage(
			            hIMEWnd,
			            WM_IME_CONTROL,
			            IMC_SETCOMPOSITIONFONT,
			            lf
			            );
		}
Esempio n. 26
0
File: Ime.cs Progetto: viticm/pap2
		private void SetIMEWindowFont(Font f)
		{
			if (lf == null) {
				lf = new LOGFONT();
				f.ToLogFont(lf);
				lf.lfFaceName = f.Name;  // This is very important! "Font.ToLogFont" Method sets invalid value to LOGFONT.lfFaceName
			}

			SendMessage(
			            hIMEWnd,
			            WM_IME_CONTROL,
			            new IntPtr(IMC_SETCOMPOSITIONFONT),
			            lf
			           );
		}
Esempio n. 27
0
 public static IntPtr CreateNormalHFont(Font font, int width)
 {
     LOGFONT logf = new LOGFONT();
     font.ToLogFont(logf);
     logf.lfWidth = width;
     logf.lfOutPrecision = (byte)FontPrecision.OUT_TT_ONLY_PRECIS;
     var ret = CreateFontIndirect(logf);
     return ret;
 }
Esempio n. 28
0
        // Returns whether or not target was changed
        internal static bool FontToIFont(Font source, UnsafeNativeMethods.IFont target) {
            bool changed = false; 

            // we need to go through all the pain of the diff here because
            // it looks like setting them all has different results based on the
            // order and each individual IFont implementor...
            //
            string fontName = target.GetName();
            if (!source.Name.Equals(fontName)) {
                target.SetName(source.Name);
                changed = true;
            }

            // [....], Review: this always seems to come back as
            // the point size * 10000 (HIMETRIC?), regardless
            // or ratio or mapping mode, and despite what
            // the documentation says...
            //
            // Either figure out what's going on here or
            // do the process that the windows forms FONT object does here
            // or, worse case, just create another Font object
            // from the handle, but that's pretty heavy...
            //
            float fontSize = (float)target.GetSize() / 10000;

            // size must be in points
            float winformsSize = source.SizeInPoints;
            if (winformsSize != fontSize) {
                target.SetSize((long)(winformsSize * 10000));
                changed = true;
            }

            NativeMethods.LOGFONT logfont = new NativeMethods.LOGFONT();

            IntSecurity.ObjectFromWin32Handle.Assert();
            try {
                source.ToLogFont(logfont);
            }
            finally {
                CodeAccessPermission.RevertAssert();
            }

            short fontWeight = target.GetWeight();
            if (fontWeight != logfont.lfWeight) {
                target.SetWeight((short)logfont.lfWeight);
                changed = true;
            }

            bool fontBold = target.GetBold();
            if (fontBold != (logfont.lfWeight >= 700)) {
                target.SetBold(logfont.lfWeight >= 700);
                changed = true;
            }

            bool fontItalic = target.GetItalic();
            if (fontItalic != (0 != logfont.lfItalic)) {
                target.SetItalic(0 != logfont.lfItalic);
                changed = true;
            }

            bool fontUnderline = target.GetUnderline();
            if (fontUnderline != (0 != logfont.lfUnderline)) {
                target.SetUnderline(0 != logfont.lfUnderline);
                changed = true;
            }

            bool fontStrike = target.GetStrikethrough();
            if (fontStrike != (0 != logfont.lfStrikeOut)) {
                target.SetStrikethrough(0 != logfont.lfStrikeOut);
                changed = true;
            }

            short fontCharset = target.GetCharset();
            if (fontCharset != logfont.lfCharSet) {
                target.SetCharset(logfont.lfCharSet);
                changed = true;
            }

            return changed;
        }
 internal static bool FontToIFont(Font source, System.Windows.Forms.UnsafeNativeMethods.IFont target)
 {
     bool flag = false;
     string name = target.GetName();
     if (!source.Name.Equals(name))
     {
         target.SetName(source.Name);
         flag = true;
     }
     float num = ((float) target.GetSize()) / 10000f;
     float sizeInPoints = source.SizeInPoints;
     if (sizeInPoints != num)
     {
         target.SetSize((long) (sizeInPoints * 10000f));
         flag = true;
     }
     System.Windows.Forms.NativeMethods.LOGFONT logFont = new System.Windows.Forms.NativeMethods.LOGFONT();
     System.Windows.Forms.IntSecurity.ObjectFromWin32Handle.Assert();
     try
     {
         source.ToLogFont(logFont);
     }
     finally
     {
         CodeAccessPermission.RevertAssert();
     }
     if (target.GetWeight() != logFont.lfWeight)
     {
         target.SetWeight((short) logFont.lfWeight);
         flag = true;
     }
     if (target.GetBold() != (logFont.lfWeight >= 700))
     {
         target.SetBold(logFont.lfWeight >= 700);
         flag = true;
     }
     if (target.GetItalic() != (0 != logFont.lfItalic))
     {
         target.SetItalic(0 != logFont.lfItalic);
         flag = true;
     }
     if (target.GetUnderline() != (0 != logFont.lfUnderline))
     {
         target.SetUnderline(0 != logFont.lfUnderline);
         flag = true;
     }
     if (target.GetStrikethrough() != (0 != logFont.lfStrikeOut))
     {
         target.SetStrikethrough(0 != logFont.lfStrikeOut);
         flag = true;
     }
     if (target.GetCharset() != logFont.lfCharSet)
     {
         target.SetCharset(logFont.lfCharSet);
         flag = true;
     }
     return flag;
 }
Esempio n. 30
0
        //this returns an IntPtr HFONT because .net's Font class will erase the relevant properties when using its Font.FromLogFont()
        //note that whether this is rotated clockwise or CCW might affect how you have to position the text (right-aligned sometimes?, up or down by the height of the font?)
        public static IntPtr CreateRotatedHFont(Font font, bool CW)
        {
            LOGFONT logf = new LOGFONT();
            font.ToLogFont(logf);
            logf.lfEscapement = CW ? 2700 : 900;
            logf.lfOrientation = logf.lfEscapement;
            logf.lfOutPrecision = (byte)FontPrecision.OUT_TT_ONLY_PRECIS;

            //this doesnt work! .net erases the relevant propreties.. it seems?
            //return Font.FromLogFont(logf);

            var ret = CreateFontIndirect(logf);
            return ret;
        }