Пример #1
0
        public BuildComponentRectangle(string id, FabricStyle fabricStyle, Area area)
            : base(id)
        {
            if (fabricStyle == null)
            {
                throw new ArgumentNullException(nameof(fabricStyle));
            }
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }

            if (area.Width < area.Height)
            {
                area = new Area(area.Height, area.Width);
            }

            m_area = area;

            m_styleKey = CreateStyleKey(fabricStyle, area);

            var rectangleShapeNode = new RectangleShapeNode(fabricStyle);
            var scale = DimensionScale.CreateIdentity(area.Width.Unit);

            rectangleShapeNode.UpdatePath(PathGeometries.Rectangle.CreatePath(m_area.Width, m_area.Height), PathOrientation.CreateDefault(), scale);

            m_rectangleShapeNode = rectangleShapeNode;
        }
        public BuildComponentFlyingGoose(string id, FabricStyle fabricStyleBody, FabricStyle fabricStyleCorner, Area area, bool trim)
            : base(id)
        {
            if (fabricStyleBody == null)
            {
                throw new ArgumentNullException(nameof(fabricStyleBody));
            }
            if (fabricStyleCorner == null)
            {
                throw new ArgumentNullException(nameof(fabricStyleCorner));
            }
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }

            if (area.Width < area.Height)
            {
                area = new Area(area.Height, area.Width);
            }

            m_area = area;

            m_fabricStyles = new FabricStyle[] { fabricStyleBody, fabricStyleCorner };

            m_trim = trim;

            m_styleKey = CreateStyleKey(fabricStyleBody, fabricStyleCorner, area);

            var halfSquareTriangleNode1 = new HalfSquareTriangleLayoutNode();

            halfSquareTriangleNode1.LayoutSites[0].Node = new TriangleShapeNode(fabricStyleCorner);
            halfSquareTriangleNode1.LayoutSites[1].Node = new TriangleShapeNode(fabricStyleBody);

            var halfSquareTriangleNode2 = new HalfSquareTriangleLayoutNode();

            halfSquareTriangleNode2.LayoutSites[0].Node = new TriangleShapeNode(fabricStyleCorner);
            halfSquareTriangleNode2.LayoutSites[1].Node = new TriangleShapeNode(fabricStyleBody);

            var gridLayoutNode = new GridLayoutNode(1, 2);

            gridLayoutNode.GetLayoutSite(0, 0).Node = halfSquareTriangleNode1;
            gridLayoutNode.GetLayoutSite(0, 1).Node = halfSquareTriangleNode2;
            gridLayoutNode.GetLayoutSite(0, 1).PathOrientation.PointOffset = 3;

            var scale = DimensionScale.CreateIdentity(area.Width.Unit);

            gridLayoutNode.UpdatePath(PathGeometries.Rectangle.CreatePath(area.Width, area.Height), PathOrientation.CreateDefault(), scale);

            m_gridLayoutNode = gridLayoutNode;
        }
Пример #3
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;
            }
        }