Exemplo n.º 1
0
        public static ShapeStyle CreateFromMemento(Memento snapshot)
        {
            //<ShapeStyle name="TypeName">
            //  <LineStyle color="16777215" width="1" />
            //  <FillStyle color="16777215" gradientColor="-1" mode="Solid" />
            //  <FontStyle color="-13921873" fontName="Consolas" size="10" bold="False" italic="False" underline="False" />
            //</ShapeStyle>

            ShapeStyle result = new ShapeStyle();
            result.Name = snapshot["name"];

            Memento line = snapshot.FindChild("LineStyle");
            if (line != null)
            {
                Color foreColor = line.GetColor("color");
                int width = line.GetInt("width");
                if (width == 0)
                {
                    width = 1;
                }
                result.LineStyleInfo = RendererSingleton.StyleFactory.ProduceNewLineStyleInfo(foreColor, width);
            }

            Memento fill = snapshot.FindChild("FillStyle");
            if (fill != null)
            {
                Color fillColor = fill.GetColor("color");
                Color gradientColor = Color.Transparent;
                FillMode mode = FillMode.Solid;
                if (!string.IsNullOrEmpty(fill["mode"]))
                {
                    gradientColor = fill.GetColor("gradientColor");
                    mode = fill.Get<FillMode>("mode");
                }
                result.FillStyleInfo
                    = RendererSingleton.StyleFactory.ProduceNewFillStyleInfo(
                    fillColor, gradientColor, mode);
            }

            Memento font = snapshot.FindChild("FontStyle");
            if (font != null)
            {
                Color fontColor = font.GetColor("color");
                string fontName = font["fontName"];
                int size = font.GetInt("size");
                bool bold = font.GetBool("bold");
                bool italic = font.GetBool("italic");
                bool underline = font.GetBool("underline");
                FontStyle style = FontStyle.Regular;
                if (bold)
                {
                    style |= FontStyle.Bold;
                }
                if (italic)
                {
                    style |= FontStyle.Italic;
                }
                if (underline)
                {
                    style |= FontStyle.Underline;
                }
                result.FontStyleInfo
                    = RendererSingleton.StyleFactory.ProduceNewFontStyleInfo(
                    fontName, size, style);
                result.FontColor = fontColor;
            }

            return result;
        }
Exemplo n.º 2
0
        public static ShapeStyle CreateFromMemento(Memento snapshot)
        {
            //<ShapeStyle name="TypeName">
            //  <LineStyle color="16777215" width="1" />
            //  <FillStyle color="16777215" gradientColor="-1" mode="Solid" />
            //  <FontStyle color="-13921873" fontName="Consolas" size="10" bold="False" italic="False" underline="False" />
            //</ShapeStyle>

            ShapeStyle result = new ShapeStyle();

            result.Name = snapshot["name"];

            Memento line = snapshot.FindChild("LineStyle");

            if (line != null)
            {
                Color foreColor = line.GetColor("color");
                int   width     = line.GetInt("width");
                if (width == 0)
                {
                    width = 1;
                }
                result.LineStyleInfo = RendererSingleton.StyleFactory.ProduceNewLineStyleInfo(foreColor, width);
            }

            Memento fill = snapshot.FindChild("FillStyle");

            if (fill != null)
            {
                Color    fillColor     = fill.GetColor("color");
                Color    gradientColor = Color.Transparent;
                FillMode mode          = FillMode.Solid;
                if (!string.IsNullOrEmpty(fill["mode"]))
                {
                    gradientColor = fill.GetColor("gradientColor");
                    mode          = fill.Get <FillMode>("mode");
                }
                result.FillStyleInfo
                    = RendererSingleton.StyleFactory.ProduceNewFillStyleInfo(
                          fillColor, gradientColor, mode);
            }

            Memento font = snapshot.FindChild("FontStyle");

            if (font != null)
            {
                Color     fontColor = font.GetColor("color");
                string    fontName  = font["fontName"];
                int       size      = font.GetInt("size");
                bool      bold      = font.GetBool("bold");
                bool      italic    = font.GetBool("italic");
                bool      underline = font.GetBool("underline");
                FontStyle style     = FontStyle.Regular;
                if (bold)
                {
                    style |= FontStyle.Bold;
                }
                if (italic)
                {
                    style |= FontStyle.Italic;
                }
                if (underline)
                {
                    style |= FontStyle.Underline;
                }
                result.FontStyleInfo
                    = RendererSingleton.StyleFactory.ProduceNewFontStyleInfo(
                          fontName, size, style);
                result.FontColor = fontColor;
            }

            return(result);
        }