コード例 #1
0
ファイル: GdiExtensions.cs プロジェクト: jugstalt/gview5
        static public System.Drawing.FontStyle ToGdiFontStyle(this GraphicsEngine.FontStyle fontStyle)
        {
            switch (fontStyle)
            {
            case GraphicsEngine.FontStyle.Regular:
                return(System.Drawing.FontStyle.Regular);

            case GraphicsEngine.FontStyle.Bold:
                return(System.Drawing.FontStyle.Bold);

            case GraphicsEngine.FontStyle.Italic:
                return(System.Drawing.FontStyle.Italic);

            case GraphicsEngine.FontStyle.Strikeout:
                return(System.Drawing.FontStyle.Strikeout);

            case GraphicsEngine.FontStyle.Underline:
                return(System.Drawing.FontStyle.Underline);
            }

            return(System.Drawing.FontStyle.Regular);
        }
コード例 #2
0
        public object Deserialize <T>(MemoryStream ms, IErrorReport errorReport, object source, bool writeError = false)
        {
            // ToDo:
            if (typeof(T).Equals(typeof(GraphicsEngine.Abstraction.IFont)))
            {
                var         soap = Encoding.ASCII.GetString(ms.ToArray());
                XmlDocument doc  = new XmlDocument();
                doc.LoadXml(soap);

                string name = "Arial";
                float  size = 8;
                GraphicsEngine.FontStyle    fontStyle = GraphicsEngine.FontStyle.Regular;
                GraphicsEngine.GraphicsUnit grUnit    = GraphicsEngine.GraphicsUnit.Point;

                XmlNode nameNode = doc.SelectSingleNode("//Name");
                if (nameNode != null)
                {
                    name = nameNode.InnerText;
                }

                XmlNode sizeNode = doc.SelectSingleNode("//Size");
                if (sizeNode != null)
                {
                    size = NumberConverter.ToFloat(sizeNode.InnerText);
                }

                XmlNode styleNode = doc.SelectSingleNode("//Style");
                if (styleNode != null)
                {
                    fontStyle = (GraphicsEngine.FontStyle)Enum.Parse(typeof(GraphicsEngine.FontStyle), styleNode.InnerText);
                }

                XmlNode unitNode = doc.SelectSingleNode("//Unit");
                if (styleNode != null)
                {
                    grUnit = (GraphicsEngine.GraphicsUnit)Enum.Parse(typeof(GraphicsEngine.GraphicsUnit), unitNode.InnerText);
                }

                var fontFamily = System.Drawing.FontFamily.Families.Where(f => f.Name == name).FirstOrDefault();
                if (fontFamily == null)
                {
                    fontFamily = System.Drawing.FontFamily.GenericSansSerif;

                    if (errorReport != null)
                    {
                        var message = $"Font '{name}' not installed on target system. '{fontFamily.Name}' will be used instead.";
                        if (writeError == true)
                        {
                            errorReport.AddError(message, source);
                        }
                        else
                        {
                            errorReport.AddWarning(message, source);
                        }
                    }
                }

                var font = GraphicsEngine.Current.Engine.CreateFont(fontFamily.Name, size, fontStyle, grUnit);
                return(font);
            }

            return(default(T));
        }