/// <summary> /// /// </summary> /// <param name="hdc"></param> /// <param name="fontDescription"></param> /// <param name="orientation"></param> /// <param name="text"></param> /// <param name="rectangle"></param> /// <param name="contentAlignment"></param> /// <param name="rect"></param> internal static void PrintRotatedText(IntPtr hdc, FontDescription fontDescription, int orientation, string text, Rectangle rectangle, ContentAlignment contentAlignment, NativeWindowCommon.RECT rect, bool rightToLeft) { IntPtr hFont; Point point; // get the original font and its LOGFONT NativeWindowCommon.LOGFONT logfont = fontDescription.LogFont; // Set the rotation angle logfont.lfEscapement = logfont.lfOrientation = orientation; // create the new, rotated font hFont = NativeWindowCommon.CreateFontIndirect(logfont); NativeWindowCommon.SelectObject(hdc, hFont); point = CalculateStartCoordinates(hdc, rectangle, orientation, text, contentAlignment); uint fuOptions = NativeWindowCommon.ETO_CLIPPED; if (rightToLeft) { fuOptions = NativeWindowCommon.ETO_RTLREADING; } NativeWindowCommon.ExtTextOut(hdc, point.X, point.Y, fuOptions, ref rect, text, (uint)text.Length, null); NativeWindowCommon.DeleteObject(hFont); }
/// <summary> /// Returns the font text metrics for true type and non true type fonts assigned to control according to mgFont. /// </summary> /// <param name="control"></param> /// <param name="mgFont"></param> /// <returns></returns> public static PointF GetFontMetricsByMgFont(Control control, MgFont mgFont) { PointF retPoint; lock (_metricsMgFontCache) { if (!_metricsMgFontCache.TryGetValue(mgFont, out retPoint)) { #if PocketPC // In PocketPC, Panels don't have CreateGraphics. We go up the parents // tree until we find a non-panel one. while (control is Panel) { control = control.Parent; } #endif using (Graphics g = control.CreateGraphics()) { int dpiY = (int)g.DpiY; NativeWindowCommon.LOGFONT nativeLogFont = new NativeWindowCommon.LOGFONT(); nativeLogFont.lfFaceName = mgFont.TypeFace; nativeLogFont.lfHeight = -NativeWindowCommon.MulDiv(mgFont.Height, dpiY, 72); // Set the rotation angle nativeLogFont.lfEscapement = nativeLogFont.lfOrientation = mgFont.Orientation; nativeLogFont.lfItalic = Convert.ToByte(mgFont.Italic); nativeLogFont.lfStrikeOut = Convert.ToByte(mgFont.Strikethrough); nativeLogFont.lfUnderline = Convert.ToByte(mgFont.Underline); if (mgFont.Bold) { nativeLogFont.lfWeight = (int)NativeWindowCommon.FontWeight.FW_BOLD; } else { nativeLogFont.lfWeight = (int)NativeWindowCommon.FontWeight.FW_NORMAL; } nativeLogFont.lfCharSet = (byte)mgFont.CharSet; IntPtr hFont = NativeWindowCommon.CreateFontIndirect(nativeLogFont); // use the font in the DC GetTextMetrics(g, hFont, mgFont.TypeFace, mgFont.Height, out retPoint); //Release the resources. nativeLogFont = null; NativeWindowCommon.DeleteObject(hFont); } _metricsMgFontCache.Add(mgFont, retPoint); } } return(retPoint); }
public FontHandleContainer(LOGFONT key) { nativeFontHandle = NativeWindowCommon.CreateFontIndirect(key); }