Esempio n. 1
0
        // Render a description to a bitmap for testing purposes. Hardcoded 40 pixel box size.
        public static Bitmap RenderToBitmap(SymbolDB symbolDB, DescriptionLine[] description, DescriptionKind kind, int numColumns)
        {
            DescriptionRenderer descriptionRenderer = new DescriptionRenderer(symbolDB);

            descriptionRenderer.Description     = description;
            descriptionRenderer.DescriptionKind = kind;
            descriptionRenderer.CellSize        = 40;
            descriptionRenderer.Margin          = 4;
            descriptionRenderer.NumberOfColumns = numColumns;

            SizeF size = descriptionRenderer.Measure();

            Bitmap   bm = new Bitmap((int)size.Width, (int)size.Height);
            Graphics g  = Graphics.FromImage(bm);

            g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

            g.Clear(Color.White);
            descriptionRenderer.RenderToGraphics(g, new RectangleF(0, 0, size.Width, size.Height));

            g.Dispose();

            return(bm);
        }
Esempio n. 2
0
        // Render a description to a bitmap for testing purposes. Does one pixel at a time to test clip rectangle.
        internal static Bitmap RenderToBitmapPixelAtATime(SymbolDB symbolDB, DescriptionLine[] description, DescriptionKind kind)
        {
            DescriptionRenderer descriptionRenderer = new DescriptionRenderer(symbolDB);

            descriptionRenderer.Description     = description;
            descriptionRenderer.DescriptionKind = kind;
            descriptionRenderer.CellSize        = 40;
            descriptionRenderer.Margin          = 4;

            SizeF size = descriptionRenderer.Measure();

            Bitmap   bm = new Bitmap((int)size.Width, (int)size.Height);
            Graphics g  = Graphics.FromImage(bm);

            g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

            g.Clear(Color.White);

            for (int x = 0; x < size.Width; ++x)
            {
                for (int y = 0; y < size.Height; ++y)
                {
                    Rectangle clip = new Rectangle(x, y, 1, 1);
                    g.SetClip(clip);
                    descriptionRenderer.RenderToGraphics(g, clip);
                }
            }

            g.Dispose();

            return(bm);
        }
Esempio n. 3
0
        // Try to fit the current description into the given width. Return the full size of the description
        // and the box size used.
        Size FitDescriptionToWidth(float width, out float boxSize)
        {
            boxSize = (width - (margin * 2)) / 8.0F;
            if (boxSize < minBoxSize)
            {
                boxSize = minBoxSize;
            }

            renderer.CellSize = boxSize;

            // Next, measure the size of the description and set the size of the panel to match.
            return(Size.Round(renderer.Measure()));
        }
Esempio n. 4
0
        // Render a description to a map, then to a bitmap for testing purposes. Hardcoded 6 mm box size.
        internal static Bitmap RenderToMapThenToBitmap(SymbolDB symbolDB, DescriptionLine[] description, DescriptionKind kind, int numColumns)
        {
            DescriptionRenderer descriptionRenderer = new DescriptionRenderer(symbolDB);

            descriptionRenderer.Description     = description;
            descriptionRenderer.DescriptionKind = kind;
            descriptionRenderer.CellSize        = 6.0F;
            descriptionRenderer.Margin          = 0.7F;
            descriptionRenderer.NumberOfColumns = numColumns;
            PointF location = new PointF(30, -100);

            SizeF size = descriptionRenderer.Measure();

            Bitmap   bm = new Bitmap((int)size.Width * 8, (int)size.Height * 8);
            Graphics g  = Graphics.FromImage(bm);

            g.ScaleTransform(bm.Width / size.Width, -bm.Height / size.Height);
            g.TranslateTransform(-location.X, -location.Y);

            g.Clear(Color.White);

            Map map = new Map(new GDIPlus_TextMetrics(), null);

            using (map.Write()) {
                Dictionary <object, SymDef> dict = new Dictionary <object, SymDef>();

                // Create white color and white-out symdef.
                SymColor   white     = map.AddColorBottom("White", 44, 0, 0, 0, 0, false);
                AreaSymDef whiteArea = new AreaSymDef("White out", "890", white, null);
                whiteArea.ToolboxImage = MapUtil.CreateToolboxIcon(Properties.Resources.WhiteOut_OcadToolbox);
                map.AddSymdef(whiteArea);
                dict[CourseLayout.KeyWhiteOut] = whiteArea;

                SymColor color = map.AddColor("Purple", 11, 0.045F, 0.59F, 0, 0.255F, false);
                descriptionRenderer.RenderToMap(map, color, location, dict);
            }

            InputOutput.WriteFile(TestUtil.GetTestFile("descriptions\\desc_temp.ocd"), map, new MapFileFormat(MapFileFormatKind.OCAD, 8));

            using (map.Read()) {
                RenderOptions renderOpts = new RenderOptions();
                renderOpts.usePatternBitmaps = true;
                renderOpts.minResolution     = 0.1F;
                renderOpts.renderTemplates   = RenderTemplateOption.MapAndTemplates;
                map.Draw(new GDIPlus_GraphicsTarget(g), new RectangleF(location.X, location.Y - size.Height, size.Width, size.Height), renderOpts, null);
            }

            g.Dispose();

            return(bm);
        }
        // Render a description to a map, then to a bitmap for testing purposes. Hardcoded 6 mm box size.
        internal static Bitmap RenderToMapThenToBitmap(SymbolDB symbolDB, DescriptionLine[] description, DescriptionKind kind, int numColumns)
        {
            DescriptionRenderer descriptionRenderer = new DescriptionRenderer(symbolDB);
            descriptionRenderer.Description = description;
            descriptionRenderer.DescriptionKind = kind;
            descriptionRenderer.CellSize = 6.0F;
            descriptionRenderer.Margin = 0.7F;
            descriptionRenderer.NumberOfColumns = numColumns;
            PointF location = new PointF(30, -100);

            SizeF size = descriptionRenderer.Measure();

            Bitmap bm = new Bitmap((int) size.Width * 8, (int) size.Height * 8);
            Graphics g = Graphics.FromImage(bm);
            g.ScaleTransform(bm.Width / size.Width, -bm.Height / size.Height);
            g.TranslateTransform(-location.X, -location.Y);

            g.Clear(Color.White);

            Map map = new Map(new GDIPlus_TextMetrics(), null);
            using (map.Write()) {
                Dictionary<object, SymDef> dict = new Dictionary<object, SymDef>();

                // Create white color and white-out symdef.
                SymColor white = map.AddColorBottom("White", 44, 0, 0, 0, 0, false);
                AreaSymDef whiteArea = new AreaSymDef("White out", "890", white, null);
                whiteArea.ToolboxImage = MapUtil.CreateToolboxIcon(Properties.Resources.WhiteOut_OcadToolbox);
                map.AddSymdef(whiteArea);
                dict[CourseLayout.KeyWhiteOut] = whiteArea;

                SymColor color = map.AddColor("Purple", 11, 0.045F, 0.59F, 0, 0.255F, false);
                descriptionRenderer.RenderToMap(map, color, location, dict);
            }

            InputOutput.WriteFile(TestUtil.GetTestFile("descriptions\\desc_temp.ocd"), map, new MapFileFormat(MapFileFormatKind.OCAD, 8));

            using (map.Read()) {
                RenderOptions renderOpts = new RenderOptions();
                renderOpts.usePatternBitmaps = true;
                renderOpts.minResolution = 0.1F;
                renderOpts.renderTemplates = RenderTemplateOption.MapAndTemplates;
                map.Draw(new GDIPlus_GraphicsTarget(g), new RectangleF(location.X, location.Y - size.Height, size.Width, size.Height), renderOpts, null);
            }

            g.Dispose();

            return bm;
        }
        // Render a description to a bitmap for testing purposes. Does one pixel at a time to test clip rectangle.
        internal static Bitmap RenderToBitmapPixelAtATime(SymbolDB symbolDB, DescriptionLine[] description, DescriptionKind kind)
        {
            DescriptionRenderer descriptionRenderer = new DescriptionRenderer(symbolDB);
            descriptionRenderer.Description = description;
            descriptionRenderer.DescriptionKind = kind;
            descriptionRenderer.CellSize = 40;
            descriptionRenderer.Margin = 4;

            SizeF size = descriptionRenderer.Measure();

            Bitmap bm = new Bitmap((int)size.Width, (int)size.Height);
            Graphics g = Graphics.FromImage(bm);

            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

            g.Clear(Color.White);

            for (int x = 0; x < size.Width; ++x) {
                for (int y = 0; y < size.Height; ++y) {
                    Rectangle clip = new Rectangle(x, y, 1, 1);
                    g.SetClip(clip);
                    descriptionRenderer.RenderToGraphics(g, clip);
                }
            }

            g.Dispose();

            return bm;
        }
Esempio n. 7
0
        // Render a description to a bitmap for testing purposes. Hardcoded 40 pixel box size.
        public static Bitmap RenderToBitmap(SymbolDB symbolDB, DescriptionLine[] description, DescriptionKind kind, int numColumns)
        {
            DescriptionRenderer descriptionRenderer = new DescriptionRenderer(symbolDB);
            descriptionRenderer.Description = description;
            descriptionRenderer.DescriptionKind = kind;
            descriptionRenderer.CellSize = 40;
            descriptionRenderer.Margin = 4;
            descriptionRenderer.NumberOfColumns = numColumns;

            SizeF size = descriptionRenderer.Measure();

            Bitmap bm = new Bitmap((int) size.Width, (int) size.Height);
            Graphics g = Graphics.FromImage(bm);

            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

            g.Clear(Color.White);
            descriptionRenderer.RenderToGraphics(g, new RectangleF(0, 0, size.Width, size.Height));

            g.Dispose();

            return bm;
        }
Esempio n. 8
0
        private void UpdateDescriptionSize()
        {
            UpdateDescriptionRenderer();

            pictureBoxDescription.Size = descriptionRenderer.Measure().ToSize();
        }