Esempio n. 1
0
        public Image CreateBitmap(Design design, int size, bool enableTexture)
        {
            if (design.LayoutComponent == null)
            {
                return(s_blankImage);
            }

            var designSize = design.GetStandardSizes().Where(r => r.Preferred).Single();

            // Determine scale that will resize design to the specified maximum pixel dimension.
            //
            var maxDimension = designSize.Width > designSize.Height ? designSize.Width : designSize.Height;
            var scale        = new DimensionScale(maxDimension.Value, maxDimension.Unit, size - 1, DimensionUnits.Pixel);

            // Rescale design.
            //
            var pageLayoutNode = new PageLayoutNode(designSize.Width * scale, designSize.Height * scale);

            pageLayoutNode.LayoutSites[0].Node = design.LayoutComponent.Expand(true);
            pageLayoutNode.UpdateBounds(PathOrientation.CreateDefault(), scale);

            var image = CreateBitmap(pageLayoutNode, size, enableTexture);

            return(image);
        }
Esempio n. 2
0
            private static MDesign_BlockPreview MDesign_BlockPreview(BlockComponent blockComponent, int size)
            {
                if (blockComponent == null)
                {
                    throw new ArgumentNullException(nameof(blockComponent));
                }

                var blockSize = new Dimension(12, DimensionUnits.Inch);

                var scale = new DimensionScale(blockSize.Value, blockSize.Unit, size, DimensionUnits.Pixel);

                var pageLayout = new PageLayoutNode(blockSize * scale, blockSize * scale);

                pageLayout.LayoutSites[0].Node = blockComponent.Expand(false);
                pageLayout.UpdateBounds(PathOrientation.CreateDefault(), scale);

                var result = new MDesign_BlockPreview()
                {
                    Width  = (int)(blockSize * scale).Value,
                    Height = (int)(blockSize * scale).Value,
                    Shapes = MDesign_Shapes(pageLayout)
                };

                return(result);
            }
Esempio n. 3
0
            private static XDesign_LayoutPreview XDesign_LayoutPreview(LayoutComponent layoutComponent, int size)
            {
                var blockSize = new Dimension(12, DimensionUnits.Inch);

                var layoutWidth  = blockSize * layoutComponent.ColumnCount;
                var layoutHeight = blockSize * layoutComponent.RowCount;

                var maxDimension = layoutWidth > layoutHeight ? layoutWidth : layoutHeight;

                var scale = new DimensionScale(maxDimension.Value, maxDimension.Unit, size, DimensionUnits.Pixel);

                var pageLayoutNode = new PageLayoutNode(layoutWidth * scale, layoutHeight * scale);

                pageLayoutNode.LayoutSites[0].Node = layoutComponent.Expand(false);
                pageLayoutNode.UpdateBounds(PathOrientation.CreateDefault(), scale);

                var result = new XDesign_LayoutPreview()
                {
                    width       = (int)(layoutWidth * scale).Value,
                    height      = (int)(layoutHeight * scale).Value,
                    layoutSites = XDesign_LayoutSites(pageLayoutNode, Palettes.Rainbow)
                };

                return(result);
            }
Esempio n. 4
0
            private static XDesign_DesignPreview XDesign_DesignPreview(Design.Core.Design design, int size)
            {
                if (design == null)
                {
                    throw new ArgumentNullException(nameof(design));
                }

                var result = new XDesign_DesignPreview();

                if (design.LayoutComponent != null)
                {
                    var designSize = design.GetStandardSizes().Where(r => r.Preferred).Single();

                    var maxDimension = designSize.Width > designSize.Height ? designSize.Width : designSize.Height;

                    var scale = new DimensionScale(maxDimension.Value, maxDimension.Unit, size, DimensionUnits.Pixel);

                    var pageLayoutNode = new PageLayoutNode(designSize.Width * scale, designSize.Height * scale);
                    pageLayoutNode.LayoutSites[0].Node = design.LayoutComponent.Expand(true);
                    pageLayoutNode.UpdateBounds(PathOrientation.CreateDefault(), scale);

                    //result.layoutSites = CreateLayoutSiteDataArray(pageLayoutNode.LayoutSites, Palettes.Rainbow);
                    result.shapes = XDesign_Shapes(pageLayoutNode);
                }

                return(result);
            }
Esempio n. 5
0
        public BuildComponentQuilt(string id, KitSpecification kitSpecification, Core.Design design)
            : base(id)
        {
            m_kitSpecification = kitSpecification ?? throw new ArgumentNullException(nameof(kitSpecification));
            m_design           = design ?? throw new ArgumentNullException(nameof(design));

            m_styleKey = GetType().Name + StyleKeyDelimiter + Guid.NewGuid().ToString();

            m_pageLayoutNode = new PageLayoutNode(
                kitSpecification.Width + (kitSpecification.BorderWidth * 2),
                kitSpecification.Height + (kitSpecification.BorderWidth * 2));
            m_pageLayoutNode.LayoutSites[0].Node = kitSpecification.Expand(design);
            m_pageLayoutNode.UpdateBounds(PathOrientation.CreateDefault(), new DimensionScale(1, DimensionUnits.Inch, 1, DimensionUnits.Inch));
        }
Esempio n. 6
0
        public Image CreateBitmap(Node node, DimensionScale scale, bool enableTexture)
        {
            // Determine scale that will resize design to the specified maximum pixel dimension.
            //
            var nodeBounds = node.Path.GetBounds();
            var nodeWidth  = nodeBounds.MaximumX - nodeBounds.MinimumX;
            var nodeHeight = nodeBounds.MaximumY - nodeBounds.MinimumY;

            // Rescale design.
            //
            var pageLayoutNode = new PageLayoutNode(nodeWidth * scale, nodeHeight * scale);

            pageLayoutNode.LayoutSites[0].Node = node.Clone();
            pageLayoutNode.UpdateBounds(PathOrientation.CreateDefault(), scale);

            var image = CreateBitmap(pageLayoutNode, 0, enableTexture);

            return(image);
        }
Esempio n. 7
0
        private void RenderKit(Graphics graphics, Kit kit, int size)
        {
            if (kit.Design.LayoutComponent != null)
            {
                var maxDimension = kit.KitSpecification.Width > kit.KitSpecification.Height ? kit.KitSpecification.Width : kit.KitSpecification.Height;
                var origin       = new Point();

                var scale = new DimensionScale(maxDimension.Value, maxDimension.Unit, size, DimensionUnits.Pixel);

                var pageLayoutNode = new PageLayoutNode(kit.KitSpecification.Width * scale, kit.KitSpecification.Height * scale);
                pageLayoutNode.LayoutSites[0].Node = kit.Expand();
                pageLayoutNode.UpdateBounds(PathOrientation.CreateDefault(), scale);

                var shapeNodes = new List <ShapeNode>();
                pageLayoutNode.AddShapeNodesTo(shapeNodes);
                foreach (var shapeNode in shapeNodes)
                {
                    RenderShapeNode(graphics, shapeNode, origin);
                }
            }
        }
Esempio n. 8
0
        public async Task <byte[]> GetBlockThumbnailAsync(string blockId, int thumbnailSize)
        {
            using var log = BeginFunction(nameof(DesignMicroService), nameof(GetBlockThumbnailAsync), blockId, thumbnailSize);
            try
            {
                await Task.CompletedTask;

                var provider = new DatabaseBlockComponentProvider(QuiltContextFactory);
                var entry    = provider.GetComponent(BlockComponent.TypeName, Constants.DefaultComponentCategory, blockId);

                var node = entry.Component.Expand(true);

                var blockDimension     = new Dimension(1, DimensionUnits.Inch);
                var thumbnailDimension = new Dimension(thumbnailSize, DimensionUnits.Pixel);
                var scale = new DimensionScale(1, DimensionUnits.Inch, thumbnailSize, DimensionUnits.Pixel);

                var pageLayoutNode = new PageLayoutNode(blockDimension * scale, blockDimension * scale);
                pageLayoutNode.LayoutSites[0].Node = node;
                pageLayoutNode.UpdateBounds(PathOrientation.CreateDefault(), scale);

                var renderer = new DesignRenderer();
                using var image = renderer.CreateBitmap(node, DimensionScale.CreateIdentity(DimensionUnits.Pixel), false);

                using var ms = new MemoryStream();
                image.Save(ms, ImageFormat.Png);

                var result = ms.ToArray();

                log.Result(result);

                return(result);
            }
            catch (Exception ex)
            {
                log.Exception(ex);
                throw;
            }
        }