Beispiel #1
0
        /// <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);
        }
Beispiel #2
0
        /// <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);
        }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="value"></param>
        static void SetFont(object obj, object value)
        {
            Font font = (Font)value;

            NativeWindowCommon.LOGFONT logfont = new NativeWindowCommon.LOGFONT();
            font.ToLogFont(logfont);

            GuiUtils.setFont(obj, font, logfont.lfOrientation, 0);
        }
Beispiel #4
0
        /// <summary>
        /// Convert back logFont.lfHeight and convert to TWIPS (20ths of a point).
        /// </summary>
        /// <param name="logFont"></param>
        /// <returns></returns>
        public static int LogFontHeightToFontSize(NativeWindowCommon.LOGFONT logFont, Control control)
        {
            Point resolution = Utils.GetResolution(control);

            return(-NativeWindowCommon.MulDiv(logFont.lfHeight, 72 * 20, (int)resolution.Y));
        }
Beispiel #5
0
 public LogFontKey(NativeWindowCommon.LOGFONT logfont)
 {
     this.logfont = logfont;
 }
Beispiel #6
0
 public LogFontKey(Font key)
 {
     logfont = new NativeWindowCommon.LOGFONT();
     key.ToLogFont(logfont);
 }
Beispiel #7
0
        public FontHandleContainer Get(NativeWindowCommon.LOGFONT logfont)
        {
            LogFontKey logFontKey = new LogFontKey(logfont);

            return(base.Get(logFontKey));
        }