Beispiel #1
0
        public System.Drawing.Font GetFont(FontMemento newFont)
        {
            bool doNewFont = cachedFont == null;

            if (!doNewFont)
            {
                doNewFont = cachedMemento.CompareTo(newFont) != 0;
            }
            if (doNewFont)
            {
                System.Drawing.Font lastFont = cachedFont;
                cachedFont    = new System.Drawing.Font(newFont.Name, newFont.SizeInPoints, newFont.Style);
                cachedMemento = new FontMemento(cachedFont);

                if (lastFont != null && !object.ReferenceEquals(lastFont, cachedFont))
                {
                    lastFont.Dispose();
                }
                lastFont = null;
            }
            return(cachedFont);
        }
        void StyleEditor()
        {
            var style   = Layout.StyleSheet.ItemStyle.DefaultStyle;
            var newFont = new FontMemento(style.Font.GetBackend() as System.Drawing.Font);

            newFont.SizeInPoints = (float)Camera.Matrix.TransformFontSize(newFont.SizeInPoints);
            editor.Font          = gdiFontCache.GetFont(newFont);

            editor.BorderStyle = BorderStyle.FixedSingle;
            editor.Multiline   = true;
            editor.ScrollBars  = ScrollBars.None;
            editor.WordWrap    = true;

            editor.BackColor = System.Drawing.Color.FromArgb((int)style.FillColor.ToRgb());
            var location = Camera.FromSource(Current.Location);
            var size     = Camera.FromSource(Current.Size);

            if (Current is IVisualEdge)
            {
                location = Camera.FromSource(Current.Shape[Anchor.Center]);
                var text = Current.Data == null ? "" : Current.Data.ToString();
                size = (Size)
                       GdiUtils.GetTextDimension(editor.Font, text, new System.Drawing.SizeF())
                ;
                size.Height = Math.Max(size.Height + 2, (int)newFont.SizeInPoints + 2);
                size.Width  = Math.Max(size.Width + 2, (int)newFont.SizeInPoints * 4);
                location.X  = location.X - size.Width / 2;
                location.Y  = location.Y - size.Height / 2;
            }
            editor.Location  = location.ToGdi();
            editor.Size      = size.ToGdi();
            editor.AllowDrop = true;
            editor.DragOver += editor_DragOver;
            editor.DragDrop += editor_DragDrop;
            // does not work:
            //editor.Scale (new SizeF (camera.Matrice.Elements[0], transformer.Matrice.Elements[3]));
        }