예제 #1
0
        void ApplyShapeStyle(SketchShapeGroup layer, UxNode targetNode)
        {
            var style = layer.Style;

            if (style.Blur.HasValue)
            {
                _log.Warning($"Skipping {style.Blur.Value.BlurType} blur on {layer.Name}. Not supported in UX");
            }

            targetNode.Children.AddRange(BuildShadows(layer.Name, layer.Style));

            var fillNodes = style.Fills
                            .Where(fill => fill.IsEnabled)
                            .Select(x => BuildBrush(x.Brush));

            targetNode.Children.AddRange(fillNodes);

            var strokeNodes = style.Borders
                              .Where(border => border.IsEnabled)
                              .Select(border => new UxNode
            {
                ClassName  = "Stroke",
                Attributes = new Dictionary <string, IUxSerializeable>
                {
                    { "Width", new UxFloat((float)border.Thickness) },
                    { "Alignment", new UxString(border.Position.ToString()) }
                },
                Children = new List <IUxSerializeable> {
                    BuildBrush(border.Brush)
                }
            });

            targetNode.Children.AddRange(strokeNodes);
        }
예제 #2
0
        UxNode BuildShapeGroup(SketchShapeGroup shapeGroupLayer)
        {
            var groupNode = new UxNode
            {
                ClassName       = "Panel",
                SketchLayerName = shapeGroupLayer.Name
            };

            if (shapeGroupLayer.Layers.Count == 0)
            {
                _log.Warning($"Shape group {shapeGroupLayer.Name} has no layers");
                return(groupNode);
            }

            // Warn if we have any combined shapes, as it is currently not supported
            var combinedShapes = shapeGroupLayer
                                 .Layers.Cast <SketchShapePath>()
                                 .Where(shape => shape.BooleanOperation !=
                                        SketchBooleanOperation.NoOperation);

            if (combinedShapes.Any())
            {
                groupNode.Children.Add(new UxComment("Combined shapes are not supported in UX"));
                _log.Warning("Combined shapes are not supported " + shapeGroupLayer.Name + " with " + combinedShapes.Count() + " number of combined layers");
                return(groupNode);
            }

            var shapeNodes = shapeGroupLayer
                             .Layers
                             .Cast <SketchShapePath>()
                             .Where(shape => shape.BooleanOperation ==
                                    SketchBooleanOperation.NoOperation)
                             .Select(BuildLayer);

            foreach (var shapeNode in shapeNodes)
            {
                ApplyShapeStyle(shapeGroupLayer, shapeNode);
                groupNode.Children.Add(shapeNode);
            }

            return(BuildLayout(shapeGroupLayer, groupNode));
        }
예제 #3
0
        public void BuildUxForSketchShapeGroupWithMaskingGivesUnsupportedWarnings()
        {
            var shapeGroup = new SketchShapeGroup(
                new SketchLayer(CreateLayer(5, 5), new List <SketchLayer>()),
                Mask);

            var parentGroup =
                new SketchGroup(
                    new SketchLayer(
                        new SketchLayer(
                            Guid.Empty,
                            new SketchLayer(
                                CreateLayer(20, 20),
                                new List <SketchLayer>()),
                            new SketchRect(0, 0, 10, 10, false),
                            "Dummy",
                            false,
                            DummyAlignment(),
                            0, false, false,
                            Optional.None(),
                            new List <SketchLayer>()),
                        new List <SketchLayer> {
                shapeGroup
            }));

            shapeGroup.Parent = parentGroup;

            var log       = new MessageListLogger();
            var uxBuilder = new UxBuilder(new SymbolClassNameBuilder(), Substitute.For <IAssetEmitter>(), log);

            var uxNode = uxBuilder.BuildLayer(parentGroup);

            Assert.That(uxNode, Is.Not.Null);

            var ux = uxNode.SerializeUx(new UxSerializerContext());

            Assert.That(ux, Is.EqualTo("<Panel Width=\"50%\" Height=\"50%\" Alignment=\"TopLeft\" Margin=\"0\">\n\t<!-- Dummy -->\n\t<!-- Masked shape group is not supported in UX -->\n</Panel>"));
            Assert.That(log.ErrorsAndWarnings().First(), Does.Match("WARNING:\tMasked shapes are not supported Dummy"));
        }