public static Font FromLogFont(object lf, IntPtr hdc) { IntPtr newObject; LOGFONT o = (LOGFONT)lf; Status status = GDIPlus.GdipCreateFontFromLogfont(hdc, ref o, out newObject); GDIPlus.CheckStatus(status); return(new Font(newObject, "Microsoft Sans Serif", FontStyle.Regular, 10)); }
public static Font GetThemeFont(IntPtr theme, Graphics graphics) { if (!_themeFontMap.ContainsKey(theme)) { using (var m = ManagedHdc.FromGraphics(graphics)) { LOGFONT font = new LOGFONT(); int ret = GetThemeFont(theme, m.Hdc, 1, 1, PropertyIdentifier.Font, out font); if (ret != 0) return SystemFonts.CaptionFont; Font themeFont = Font.FromLogFont(font); _themeFontMap.Add(theme, themeFont); return themeFont; } } return _themeFontMap[theme]; }
public IntPtr ToHfont() { if (fontObject == IntPtr.Zero) { throw new ArgumentException(Locale.GetText("Object has been disposed.")); } if (GDIPlus.RunningOnUnix()) { return(fontObject); } // win32 specific code if (olf == null) { olf = new LOGFONT(); ToLogFont(olf); } LOGFONT lf = (LOGFONT)olf; return(GDIPlus.CreateFontIndirect(ref lf)); }
public override IText AddText(string text, double fontSize, System.Windows.Media.SolidColorBrush brush) { if (cachedTypeface == null) { cachedTypeface = CreateTypeface(); } LOGFONT logfont = new LOGFONT(); logfont.lfFaceName = cachedTypeface.FontFamily.Source; logfont.lfHeight = -(int)fontSize; //logfont.lfOutPrecision = 4; //logfont.lfQuality = 5; MyText myText = new MyText { parent = this, text = text, color = brush.Color.R | (brush.Color.G << 8) | (brush.Color.B << 16), font = CreateFontIndirect(ref logfont) }; //myText.brush = new SolidBrush(myText.color); texts.Add(myText); return myText; }
static extern bool ImmGetCompositionFont(IntPtr hIMC, out LOGFONT font);
public static extern bool ImmSetCompositionFont(IntPtr hImc, LOGFONT lpLogfont);
public static Font FromHfont(IntPtr hfont) { IntPtr newObject; IntPtr hdc; FontStyle newStyle = FontStyle.Regular; float newSize; LOGFONT lf = new LOGFONT(); // Sanity. Should we throw an exception? if (hfont == IntPtr.Zero) { Font result = new Font("Arial", (float)10.0, FontStyle.Regular); return(result); } if (GDIPlus.RunningOnUnix()) { // If we're on Unix we use our private gdiplus API to avoid Wine // dependencies in S.D Status s = GDIPlus.GdipCreateFontFromHfont(hfont, out newObject, ref lf); GDIPlus.CheckStatus(s); } else { // This needs testing // GetDC, SelectObject, ReleaseDC GetTextMetric and // GetFontFace are not really GDIPlus, see gdipFunctions.cs newStyle = FontStyle.Regular; hdc = GDIPlus.GetDC(IntPtr.Zero); try { return(FromLogFont(lf, hdc)); } finally { GDIPlus.ReleaseDC(IntPtr.Zero, hdc); } } if (lf.lfItalic != 0) { newStyle |= FontStyle.Italic; } if (lf.lfUnderline != 0) { newStyle |= FontStyle.Underline; } if (lf.lfStrikeOut != 0) { newStyle |= FontStyle.Strikeout; } if (lf.lfWeight > 400) { newStyle |= FontStyle.Bold; } if (lf.lfHeight < 0) { newSize = lf.lfHeight * -1; } else { newSize = lf.lfHeight; } return(new Font(newObject, lf.lfFaceName, newStyle, newSize)); }
private static extern int GetThemeFont(IntPtr hTheme, IntPtr hdc, int iPartId, int iStateId, [MarshalAs(UnmanagedType.I4)] PropertyIdentifier iPropId, out LOGFONT pFont);
private extern static int GetThemeSysFont(IntPtr hTheme, int iFontId, out LOGFONT plf);
public LOGFONT( LOGFONT lf ) { Debug.Assert( lf != null, "lf is null" ); this.lfHeight = lf.lfHeight; this.lfWidth = lf.lfWidth; this.lfEscapement = lf.lfEscapement; this.lfOrientation = lf.lfOrientation; this.lfWeight = lf.lfWeight; this.lfItalic = lf.lfItalic; this.lfUnderline = lf.lfUnderline; this.lfStrikeOut = lf.lfStrikeOut; this.lfCharSet = lf.lfCharSet; this.lfOutPrecision = lf.lfOutPrecision; this.lfClipPrecision = lf.lfClipPrecision; this.lfQuality = lf.lfQuality; this.lfPitchAndFamily = lf.lfPitchAndFamily; this.lfFaceName = lf.lfFaceName; }
public void Dispose_ToLogFont () { #if !TARGET_JVM Font f = new Font (name, 12.5f); f.Dispose (); LOGFONT lf = new LOGFONT(); f.ToLogFont (lf); #endif }
public static Font FromHfont (IntPtr hfont) { IntPtr newObject; IntPtr hdc; FontStyle newStyle = FontStyle.Regular; float newSize; LOGFONT lf = new LOGFONT (); // Sanity. Should we throw an exception? if (hfont == IntPtr.Zero) { Font result = new Font ("Arial", (float)10.0, FontStyle.Regular); return(result); } if (GDIPlus.RunningOnUnix ()) { // If we're on Unix we use our private gdiplus API to avoid Wine // dependencies in S.D Status s = GDIPlus.GdipCreateFontFromHfont (hfont, out newObject, ref lf); GDIPlus.CheckStatus (s); } else { // This needs testing // GetDC, SelectObject, ReleaseDC GetTextMetric and // GetFontFace are not really GDIPlus, see gdipFunctions.cs newStyle = FontStyle.Regular; hdc = GDIPlus.GetDC (IntPtr.Zero); try { return FromLogFont (lf, hdc); } finally { GDIPlus.ReleaseDC (IntPtr.Zero, hdc); } } if (lf.lfItalic != 0) { newStyle |= FontStyle.Italic; } if (lf.lfUnderline != 0) { newStyle |= FontStyle.Underline; } if (lf.lfStrikeOut != 0) { newStyle |= FontStyle.Strikeout; } if (lf.lfWeight > 400) { newStyle |= FontStyle.Bold; } if (lf.lfHeight < 0) { newSize = lf.lfHeight * -1; } else { newSize = lf.lfHeight; } return (new Font (newObject, lf.lfFaceName, newStyle, newSize)); }
public void ToLogFont_DenyUnmanagedCode () { Font f; LOGFONT lf; lf = new LOGFONT(); f = new Font("Arial", 10); f.ToLogFont(lf); }
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"); }
//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; }
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; }
static LOGFONT CopyLogFont( LOGFONT source ) { LOGFONT dest = new LOGFONT() { lfHeight = source.lfHeight, lfWidth = source.lfWidth, lfEscapement = source.lfEscapement, lfOrientation = source.lfOrientation, lfWeight = source.lfWeight, lfItalic = source.lfItalic, lfUnderline = source.lfUnderline, lfStrikeOut = source.lfStrikeOut, lfCharSet = source.lfCharSet, lfOutPrecision = source.lfOutPrecision, lfClipPrecision = source.lfClipPrecision, lfQuality = source.lfQuality, lfPitchAndFamily = source.lfPitchAndFamily, lfFaceName = source.lfFaceName }; return dest; }
internal static extern Status GdipCreateFontFromHfont(IntPtr hdc, out IntPtr font, ref LOGFONT lf);
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 }
internal static extern IntPtr CreateFontIndirect (ref LOGFONT logfont);
private static LOGFONT createLogFont(string fontname) { LOGFONT lf = new LOGFONT(); lf.lfHeight = 0; lf.lfWidth = 0; lf.lfEscapement = 0; lf.lfOrientation = 0; lf.lfWeight = 0; lf.lfItalic = false; lf.lfUnderline = false; lf.lfStrikeOut = false; lf.lfCharSet = FontCharSet.DEFAULT_CHARSET; lf.lfOutPrecision = 0; lf.lfClipPrecision = 0; lf.lfQuality = 0; lf.lfPitchAndFamily = FontPitchAndFamily.FF_DONTCARE; lf.lfFaceName = ""; return lf; }
public IntPtr ToHfont () { if (fontObject == IntPtr.Zero) throw new ArgumentException (Locale.GetText ("Object has been disposed.")); if (GDIPlus.RunningOnUnix ()) return fontObject; // win32 specific code if (olf == null) { olf = new LOGFONT (); ToLogFont(olf); } LOGFONT lf = (LOGFONT)olf; return GDIPlus.CreateFontIndirect (ref lf); }
public static int GetObject(HandleRef hObject, LOGFONT lp) { return GetObject(hObject, Marshal.SizeOf(typeof(LOGFONT)), lp); }
private extern static int GetThemeFont(IntPtr hTheme, IntPtr hdc, int iPartId, int iStateId, int iPropId, out LOGFONT pFont);
public static unsafe int GetObject(HandleRef hObject, ref LOGFONT lp) => GetObject(hObject, sizeof(LOGFONT), ref lp);
public void CreateFont () { IntPtr family; GDIPlus.GdipCreateFontFamilyFromName ("Arial", IntPtr.Zero, out family); if (family == IntPtr.Zero) Assert.Ignore ("Arial isn't available on this platform"); IntPtr font; Assert.AreEqual (Status.Ok, GDIPlus.GdipCreateFont (family, 10f, FontStyle.Regular, GraphicsUnit.Point, out font), "GdipCreateFont"); Assert.IsTrue (font != IntPtr.Zero, "font"); LOGFONT lf = new LOGFONT (); lf.lfCharSet = 1; Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipGetLogFont (font, IntPtr.Zero, (object) lf), "GdipGetLogFont-null-graphics"); Assert.AreEqual (0, lf.lfCharSet, "lfCharSet-null-graphics"); // other lf members looks like garbage IntPtr image; GDIPlus.GdipCreateBitmapFromScan0 (10, 10, 0, PixelFormat.Format32bppArgb, IntPtr.Zero, out image); Assert.IsTrue (image != IntPtr.Zero, "image"); IntPtr graphics; GDIPlus.GdipGetImageGraphicsContext (image, out graphics); Assert.IsTrue (graphics != IntPtr.Zero, "graphics"); lf.lfCharSet = 1; Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipGetLogFont (IntPtr.Zero, graphics, (object) lf), "GdipGetLogFont-null"); Assert.AreEqual (0, lf.lfCharSet, "lfCharSet-null"); lf.lfCharSet = 1; Assert.AreEqual (Status.Ok, GDIPlus.GdipGetLogFont (font, graphics, (object) lf), "GdipGetLogFont"); Assert.AreEqual (0, lf.lfCharSet, "lfCharSet"); // strangely this is 1 in the managed side lf.lfCharSet = 2; Assert.AreEqual (Status.Ok, GDIPlus.GdipGetLogFont (font, graphics, (object) lf), "GdipGetLogFont-2"); Assert.AreEqual (0, lf.lfCharSet, "lfCharSet"); // strangely this is 2 in the managed side Assert.AreEqual (Status.Ok, GDIPlus.GdipDeleteFont (font), "GdipDeleteFont"); Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipDeleteFont (IntPtr.Zero), "GdipDeleteFont-null"); Assert.AreEqual (Status.Ok, GDIPlus.GdipDeleteFontFamily (family), "GdipDeleteFontFamily"); Assert.AreEqual (Status.Ok, GDIPlus.GdipDisposeImage (image), "GdipDisposeImage"); Assert.AreEqual (Status.Ok, GDIPlus.GdipDeleteGraphics (graphics), "GdipDeleteGraphics"); }
public static extern bool ImmSetCompositionFont(IntPtr hIMC, LOGFONT lf);
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 ); }
public static extern IntPtr CreateFontIndirect(ref LOGFONT lf);
public static extern int GetObject(HandleRef hObject, int nSize, ref LOGFONT lf);
private static extern int SendMessage(IntPtr hWnd, int msg, int wParam, LOGFONT lParam);
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); } }
internal static extern int GdipCreateFontFromLogfontW(IntPtr hdc, ref LOGFONT lf, out IntPtr font);
public static bool SetCompositionFont(HwndSource source, IntPtr hIMC, TextArea textArea) { if (textArea == null) throw new ArgumentNullException("textArea"); LOGFONT lf = new LOGFONT(); Rect characterBounds = textArea.TextView.GetCharacterBounds(textArea.Caret.Position, source); lf.lfFaceName = textArea.FontFamily.Source; lf.lfHeight = (int)characterBounds.Height; return ImmSetCompositionFont(hIMC, ref lf); }
internal static extern IntPtr CreateFontIndirect(ref LOGFONT logfont);
static extern bool ImmSetCompositionFont(IntPtr hIMC, ref LOGFONT font);
internal static extern Status GdipCreateFontFromLogfont(IntPtr hdc, ref LOGFONT lf, out IntPtr ptr);