Ejemplo n.º 1
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;
        }
Ejemplo n.º 3
0
        // Render a course onto a map.
        public Map RenderToMap(MapRenderOptions mapRenderOptions)
        {
            // Create the map to render into.
            Map map = new Map(MapUtil.TextMetricsProvider, null);

            if (Count == 0)
            {
                return(map);
            }

            SymColor[] colors = new SymColor[LAYERCOUNT];

            using (map.Write()) {
                // Create dictionary for holding Symdef state
                Dictionary <object, SymDef>         dict         = new Dictionary <object, SymDef>();
                Dictionary <SpecialColor, SymColor> customColors = new Dictionary <SpecialColor, SymColor>();

                // 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[KeyWhiteOut] = whiteArea;

                // Create layout symdef.
                ImageSymDef layoutSymDef = new ImageSymDef(SymLayer.Layout);
                map.AddSymdef(layoutSymDef);
                dict[KeyLayout] = layoutSymDef;

                // Create colors for the special colors.
                short customColorId = 61;
                foreach (CourseObj courseObject in this)
                {
                    if (courseObject.CustomColor != null && courseObject.CustomColor.Kind == SpecialColor.ColorKind.Custom)
                    {
                        if (!customColors.ContainsKey(courseObject.CustomColor))
                        {
                            CmykColor cmyk = courseObject.CustomColor.CustomColor;
                            customColors.Add(courseObject.CustomColor, map.AddColor(string.Format("Color {0}", customColorId), customColorId,
                                                                                    cmyk.Cyan, cmyk.Magenta, cmyk.Yellow, cmyk.Black, false));
                            ++customColorId;
                        }
                    }
                }

                // Create colors for the regular colors in the correct order (lower on top).
                for (int layerIndex = LAYERCOUNT - 1; layerIndex >= 0; --layerIndex)
                {
                    if (colorName[layerIndex] != null)
                    {
                        // Create the symColor for rendering.
                        colors[layerIndex] = map.AddColor(colorName[layerIndex], ocadColorId[layerIndex],
                                                          colorC[layerIndex], colorM[layerIndex], colorY[layerIndex], colorK[layerIndex], colorOverprint[layerIndex]);
                    }
                }

                foreach (CourseObj courseObject in this)
                {
                    int layerIndex = (int)courseObject.layer;

                    if (courseObject.CustomColor != null && courseObject.CustomColor.Kind == SpecialColor.ColorKind.Black)
                    {
                        layerIndex = (int)CourseLayer.Descriptions;
                    }

                    SymColor color = colors[layerIndex];

                    if (courseObject.CustomColor != null && courseObject.CustomColor.Kind == SpecialColor.ColorKind.Custom)
                    {
                        color = customColors[courseObject.CustomColor];
                    }

                    courseObject.AddToMap(map, color, mapRenderOptions, dict);
                }
            }

            return(map);
        }
Ejemplo n.º 4
0
 protected override SymDef CreateSymDef(Map map, SymColor symColor)
 {
     AreaSymDef symdef = new AreaSymDef("Out-of-bounds area", "709", null, null);
     AreaSymDef.HatchInfo hatchInfo = new AreaSymDef.HatchInfo();
     hatchInfo.hatchColor = symColor;
     hatchInfo.hatchWidth = 0.25F * scaleRatio;
     hatchInfo.hatchSpacing = 0.6F * scaleRatio;
     hatchInfo.hatchAngle = 90;
     symdef.AddHatching(hatchInfo);
     symdef.ToolboxImage = MapUtil.CreateToolboxIcon(Properties.Resources.OOB_OcadToolbox);
     map.AddSymdef(symdef);
     return symdef;
 }
Ejemplo n.º 5
0
        // Render one course object to a map.
        internal Map RenderCourseObjToMap(CourseObj courseobj)
        {
            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;

                // Create layout symdef.
                ImageSymDef layoutSymDef = new ImageSymDef(SymLayer.Layout);
                map.AddSymdef(layoutSymDef);
                dict[CourseLayout.KeyLayout] = layoutSymDef;

                SymColor symColor = null;
                SpecialColor specialColor = courseobj.CustomColor ?? SpecialColor.Purple;
                switch (specialColor.Kind) {
                    case SpecialColor.ColorKind.Black:
                        symColor = map.AddColor("Black", 1, 0, 0, 0, 1F, false);
                        break;
                    case SpecialColor.ColorKind.Purple:
                        symColor = map.AddColor("Purple", 11, 0.045F, 0.59F, 0, 0.255F, false);
                        break;
                    case SpecialColor.ColorKind.Custom:
                        CmykColor cmyk = specialColor.CustomColor;
                        symColor = map.AddColor("Custom", 61, cmyk.Cyan, cmyk.Magenta, cmyk.Yellow, cmyk.Black, false);
                        break;
                }

                courseobj.AddToMap(map, symColor, dict);

                // Make drop targets visible for debugging.
                foreach (SymDef symdef in map.AllSymdefs) {
                    if (symdef.SymbolId == "781")
                        map.SetSymdefVisible(symdef, true);
                }
            }
            return map;
        }