示例#1
0
        /// <summary>
        ///   FONT
        /// </summary>
        internal FontsTable()
        {
            _fontTable = new List <MgFont>();

            //init the default font
            _defaultFont = new MgFont(0, "MS Sans Serif", 8, 0, 0, 0);
        }
示例#2
0
文件: Utils.cs 项目: rinavin/RCJS
        /// <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);
        }
示例#3
0
        /// <summary>
        /// Font
        /// </summary>
        /// <param name="control"></param>
        /// <param name="properties"></param>
        static void BuildFontProperty(MgControlBase control, Dictionary <string, DesignerPropertyInfo> properties)
        {
            bool   isDefaultvalue = false;
            int    value          = GetRuntimeValueAsInt(control, PropInterface.PROP_TYPE_FONT, ref isDefaultvalue);
            MgFont mgFont         = isDefaultvalue ? null : Manager.GetFontsTable().getFont(value);

            properties.Add(Constants.WinPropFont, new DesignerPropertyInfo()
            {
                VisibleInPropertyGrid = true, Value = mgFont, IsDefaultValue = isDefaultvalue
            });
        }
示例#4
0
        /// <summary>
        /// get the new fonts after the font table changed
        /// </summary>
        internal void RecalculateFonts()
        {
            if (MgFontIndex != 0)
            {
                MgFont mgFont = Manager.GetFontsTable().getFont(MgFontIndex);
                Font = FontsCache.GetInstance().Get(mgFont);

                Control c = getEditorControl();
                if (c != null)
                {
                    ControlUtils.SetFont(c, Font);
                }
            }
        }
示例#5
0
            public void endElement(String elementName, String elementValue, NameValueCollection attributes)
            {
                if (elementName == XMLConstants.MG_TAG_FONT_ENTRY)
                {
                    String         styleName;
                    int            index       = 0;
                    int            height      = 0;
                    FontAttributes style       = 0;
                    String         typeFace    = null;
                    int            charSet     = 0;
                    int            orientation = 0;

                    IEnumerator enumerator = attributes.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        String attr = (String)enumerator.Current;
                        switch (attr)
                        {
                        case XMLConstants.MG_ATTR_ID:
                            index = Int32.Parse(attributes[attr]);
                            break;

                        case XMLConstants.MG_ATTR_HEIGHT:
                            height = Int32.Parse(attributes[attr]);
                            break;

                        case XMLConstants.MG_TYPE_FACE:
                            typeFace = attributes[attr];
                            break;

                        case XMLConstants.MG_ATTR_CHAR_SET:
                            charSet = Int32.Parse(attributes[attr]);
                            break;

                        case XMLConstants.MG_ATTR_STYLE:
                            styleName = attributes[attr];
                            if (styleName.IndexOf('B') > -1) // Check if styleName contains "B"
                            {
                                style |= FontAttributes.FontAttributeBold;
                            }
                            if (styleName.IndexOf('I') > -1) // Check if styleName contains "I"
                            {
                                style |= FontAttributes.FontAttributeItalic;
                            }
                            if (styleName.IndexOf('U') > -1) // Check if styleName contains "U"
                            {
                                style |= FontAttributes.FontAttributeUnderline;
                            }
                            if (styleName.IndexOf('S') > -1) // Check if styleName contains "S"
                            {
                                style |= FontAttributes.FontAttributeStrikethrough;
                            }
                            break;

                        case XMLConstants.MG_ATTR_ORIENTATION:
                            orientation = Int32.Parse(attributes[attr]);
                            break;

                        default:
                            Events.WriteExceptionToLog(
                                "There is no such tag in MgFont class. Insert case to FontTable.endElement() for: " + attr);
                            break;
                        }
                    }

                    MgFont font = new MgFont(index, typeFace, height, style, orientation, charSet);
                    lock (_enclosingInstance)
                    {
                        _enclosingInstance._fontTable.Add(font);
                    }
                }
                // It should come in this function only for FontTable tag or for Font tag..For other tags we should write error to log
                else if (elementName != XMLConstants.MG_TAG_FONTTABLE)
                {
                    Events.WriteExceptionToLog("There is no such tag in FontTable.endElement(): " +
                                               elementName);
                }
            }