Esempio n. 1
0
        public void FontMeasures(string fontName)
        {
            var writer = new StringWriter();

            writer.WriteLine("public class FontMeasure{0}:FontMeasure {{", fontName);
            writer.WriteLine("\tpublic override void Make() {");
            var font = new Font(fontName, 10);

            CharacterRange[] characterRanges = { new CharacterRange(0, 0) };
            var stringFormat = GdiConverter.GetDefaultStringFormat().Clone() as StringFormat;

            stringFormat.SetMeasurableCharacterRanges(characterRanges);
            for (var i = 0x21; i < 0x17e; i++)
            {
                var c = char.ConvertFromUtf32(i);

                if (false)
                {
                    // something wrong here; gives always 0
                    var mcrSize = GdiUtils.DeviceContext.MeasureCharacterRanges(c, font, new Rectangle(0, 0, 1000, 1000), stringFormat);
                    ReportDetail("{0}\t{1}", c, mcrSize[0].GetBounds(GdiUtils.DeviceContext).Size.ToXwt());
                }
                var size = GdiUtils.GetTextDimension(font, c, new SizeF());
                ReportDetail("{0}\t{1}", c, size.Width);
                writer.WriteLine("Add({0},{1},{2}); // {3}", i, size.Width, size.Height, c);
            }
            ReportDetail(writer.ToString());
        }
Esempio n. 2
0
        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]));
        }