/// <summary>
 /// Applies properties (name, italic, bold, underline) from the characteristics of the specified font
 /// </summary>
 /// <param name="sym"></param>
 /// <param name="f"></param>
 public static void Apply(this IFontSymbol sym, Font f)
 {
     Check.NotNull(sym, "sym"); //NOXLATE
     sym.FontName   = f.Name;
     sym.Italic     = f.Italic;
     sym.Bold       = f.Bold;
     sym.Underlined = f.Underline;
 }
        public static void RenderPreviewFontSymbol(Graphics g, Rectangle size, IFontSymbol item)
        {
            Font   font;
            Color? foreground = null;
            string text       = string.Empty;

            if (item == null || item.FontName == null)
            {
                RenderPreviewFont(g, size, null);
                return;
            }
            else
            {
                try { font = new Font(item.FontName, 12); }
                catch { font = new Font("Arial", 12); } //NOXLATE

                try
                {
                    if (string.IsNullOrEmpty(item.ForegroundColor))
                    {
                        foreground = Color.Black;
                    }
                    else
                    {
                        foreground = Utility.ParseHTMLColor(item.ForegroundColor);
                    }
                }
                catch { }

                FontStyle fs = FontStyle.Regular;
                if (item.Bold.HasValue && item.Bold.Value)
                {
                    fs |= FontStyle.Bold;
                }
                if (item.Italic.HasValue && item.Italic.Value)
                {
                    fs |= FontStyle.Italic;
                }
                if (item.Underlined.HasValue && item.Underlined.Value)
                {
                    fs |= FontStyle.Underline;
                }
                font = new Font(font, fs);

                text = item.Character;
            }

            SizeF textSize = g.MeasureString(text, font);

            PointF center = new PointF((size.Width - textSize.Width) / 2, (size.Height - textSize.Height) / 2);

            if (foreground.HasValue)
            {
                using (Brush b = new SolidBrush(foreground.Value))
                    g.DrawString(text, font, b, center);
            }
        }
 /// <summary>
 /// Sets the color of the foreground.
 /// </summary>
 /// <param name="sym">The sym.</param>
 /// <param name="c">The c.</param>
 public static void SetForegroundColor(this IFontSymbol sym, Color c)
 {
     Check.NotNull(sym, "sym"); //NOXLATE
     sym.ForegroundColor = Utility.SerializeHTMLColor(c, true);
 }
Example #4
0
        private void Symbol_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (m_inUpdate)
                return;

            bool isSymbol = false;
            ShapeType selectedShape = ShapeType.Circle;

            // see if need to change symbol type
            foreach (string s in Enum.GetNames(typeof(ShapeType)))
                if (string.Compare(s, (string)Symbol.SelectedValue, true) == 0)
                {
                    selectedShape = (ShapeType)Enum.Parse(typeof(ShapeType), s);
                    isSymbol = true;
                    break;
                }

            if (m_item.Symbol.Type == PointSymbolType.Mark)
                m_lastMark = (IMarkSymbol)m_item.Symbol;
            else if (m_item.Symbol.Type == PointSymbolType.Font)
                m_lastFont = (IFontSymbol)m_item.Symbol;

            if (isSymbol)
            {
                //W2D symbol is not selected, so invalidate
                grpW2DStyle.Tag = null;

                bool update = m_item.Symbol != m_lastMark;

                if (m_lastMark == null)
                    m_lastMark = _factory.CreateDefaultMarkSymbol();

                m_lastMark.Shape = selectedShape;
                m_item.Symbol = m_lastMark;

                setUIForMarkSymbol(true);
                if (update)
                    UpdateDisplay();
            }
            else if (Symbol.SelectedIndex == 6) //Font
            {
                //W2D symbol is not selected, so invalidate
                grpW2DStyle.Tag = null;

                // user wants to change away FROM a valid 'Mark' symbol type
                // if ("Font..." == Symbol.SelectedText)

                bool update = m_item.Symbol != m_lastFont;

                if (m_lastFont == null)
                {
                    m_lastFont = _factory.CreateDefaultFontSymbol();
                    m_lastFont.SizeContext = SizeContextType.DeviceUnits;
                    m_lastFont.Rotation = "0";
                    m_lastFont.SizeX = "10";
                    m_lastFont.SizeY = "10";
                    m_lastFont.Unit = LengthUnitType.Points;
                }

                m_item.Symbol = m_lastFont;
                setUIForMarkSymbol(false);
                if (update)
                    UpdateDisplay();
            }
            else if (Symbol.SelectedIndex == 7) //Symbol
            {
                using (var picker = new SymbolPicker(m_editor.GetEditedResource().CurrentConnection))
                {
                    if (picker.ShowDialog() == DialogResult.OK)
                    {
                        bool update = m_item.Symbol != m_lastSymbol;
                        if (m_lastSymbol == null)
                        {
                            m_lastSymbol = _factory.CreateDefaultW2DSymbol(picker.SymbolLibrary, picker.SymbolName);
                            m_lastSymbol.SizeContext = SizeContextType.DeviceUnits;
                            m_lastSymbol.Rotation = "0";
                            m_lastSymbol.SizeX = "10";
                            m_lastSymbol.SizeY = "10";
                            m_lastSymbol.Unit = LengthUnitType.Points;
                        }

                        m_item.Symbol = m_lastSymbol;
                        //Store the W2D preview image
                        grpW2DStyle.Tag = picker.SymbolImage;
                        setUIForMarkSymbol(false);
                        if (update)
                            UpdateDisplay();
                    }
                }
            }
            else
            {
                //W2D symbol is not selected, so invalidate
                grpW2DStyle.Tag = null;

                MessageBox.Show(this, Strings.SymbolTypeNotSupported, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            UpdatePreviewResult();
            if (Changed != null)
                Changed(this, new EventArgs());
        }
Example #5
0
        public static void RenderPreviewFontSymbol(Graphics g, Rectangle size, IFontSymbol item)
        {
            Font font;
            Color? foreground = null;
            string text = string.Empty;

            if (item == null || item.FontName == null)
            {
                RenderPreviewFont(g, size, null);
                return;
            }
            else
            {
                try { font = new Font(item.FontName, 12); }
                catch { font = new Font("Arial", 12); } //NOXLATE

                try
                {
                    if (string.IsNullOrEmpty(item.ForegroundColor))
                        foreground = Color.Black;
                    else
                        foreground = Utility.ParseHTMLColor(item.ForegroundColor);
                }
                catch { }

                FontStyle fs = FontStyle.Regular;
                if (item.Bold.HasValue && item.Bold.Value)
                    fs |= FontStyle.Bold;
                if (item.Italic.HasValue && item.Italic.Value)
                    fs |= FontStyle.Italic;
                if (item.Underlined.HasValue && item.Underlined.Value)
                    fs |= FontStyle.Underline;
                font = new Font(font, fs);

                text = item.Character;
            }

            SizeF textSize = g.MeasureString(text, font);

            PointF center = new PointF((size.Width - textSize.Width) / 2, (size.Height - textSize.Height) / 2);

            if (foreground.HasValue)
            {
                using (Brush b = new SolidBrush(foreground.Value))
                    g.DrawString(text, font, b, center);
            }
        }