Exemple #1
0
 public void Initialize()
 {
     _cssRegistrator = Substitute.For <ICssRegistrator>();
     _styleConveter  = Substitute.For <IStyleConverter>();
     _styleConveter.BuildRegistrator().Returns(_cssRegistrator);
     _config   = new StyleConfig();
     _instance = new StylePlugin(_styleConveter, _config);
     _css      = new StringBuilder();
     _state    = Substitute.For <IProcessingState>();
     _state.Css.Returns(_css);
     _state.Elements.Returns(_ => new ElementProcessingState[0]);
     _state.GetContext(out ICssRegistrator _)
     .Returns(x =>
     {
         x[0] = _cssRegistrator;
         return(true);
     });
     _parentVNode  = new VNode();
     _currentVNode = new VNode();
     _elemState    = Substitute.For <IElementProcessingState>();
     _elemState.ProcessingState.Returns(_state);
     _elemState
     .GetContext(out ParagraphContext _)
     .Returns(x =>
     {
         x[0] = new ParagraphContext {
             Parent = _parentVNode
         };
         return(true);
     });
     _elemState.CurrentVNode.Returns(_ => _currentVNode);
 }
        private static Style GetStyleByPlugin(StylePlugin styleProvider)
        {
            Style style       = null;
            bool  needRestore = false;

            if (!styleProvider.UseRandomColor)
            {
                styleProvider.UseRandomColor = true;
                needRestore = true;
            }

            // Apply more colors to avoid duplicated colors.
            GeoColorHelper.RandomColorType = RandomColorType.All;
            Style tmpStyle = styleProvider.GetDefaultStyle();

            GeoColorHelper.RandomColorType = RandomColorType.Pastel;

            if (needRestore)
            {
                styleProvider.UseRandomColor = false;
            }
            if (tmpStyle != null)
            {
                style      = tmpStyle.CloneDeep();
                style.Name = GisEditor.StyleManager.GetStylePluginByStyle(style).Name;
            }
            return(style);
        }
Exemple #3
0
        private static void AddStyle(StylePlugin styleProvider)
        {
            Style style = null;
            StyleBuilderArguments arguments           = new StyleBuilderArguments();
            FeatureLayer          currentFeatureLayer = null;

            if (GisEditor.LayerListManager.SelectedLayerListItem == null)
            {
                return;
            }

            //add a new style by right-clicking on a layer node
            if (GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject is FeatureLayer)
            {
                currentFeatureLayer = (FeatureLayer)GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject;
            }

            //add a new style by right-clicking on a zoomlevel node
            else if (GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject is ZoomLevel)
            {
                ZoomLevel editingZoomLevel = (ZoomLevel)GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject;
                arguments.FromZoomLevelIndex = GisEditor.ActiveMap.GetSnappedZoomLevelIndex(editingZoomLevel.Scale) + 1;
                arguments.ToZoomLevelIndex   = (int)editingZoomLevel.ApplyUntilZoomLevel;
                currentFeatureLayer          = (FeatureLayer)GisEditor.LayerListManager.SelectedLayerListItem.Parent.ConcreteObject;
            }

            //replace an existing style
            else if (GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject is Style)
            {
                Style currentStyle = (Style)GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject;
                currentFeatureLayer = LayerListHelper.FindMapElementInLayerList <FeatureLayer>(GisEditor.LayerListManager.SelectedLayerListItem);
            }

            arguments.AvailableStyleCategories = StylePluginHelper.GetStyleCategoriesByFeatureLayer(currentFeatureLayer);
            arguments.FeatureLayer             = currentFeatureLayer;
            arguments.FillRequiredColumnNames();
            arguments.AppliedCallback = args =>
            {
                if (args.CompositeStyle != null)
                {
                    ZoomLevelHelper.ApplyStyle(args.CompositeStyle, currentFeatureLayer, args.FromZoomLevelIndex, args.ToZoomLevelIndex);
                }
            };

            style      = styleProvider.GetDefaultStyle();
            style.Name = styleProvider.Name;
            var componentStyle = new CompositeStyle(style)
            {
                Name = currentFeatureLayer.Name
            };

            arguments.StyleToEdit = componentStyle;
            var styleResults = GisEditor.StyleManager.EditStyle(arguments);

            if (!styleResults.Canceled)
            {
                ZoomLevelHelper.ApplyStyle(styleResults.CompositeStyle, currentFeatureLayer, styleResults.FromZoomLevelIndex, styleResults.ToZoomLevelIndex);
            }
        }
Exemple #4
0
        public void Setup()
        {
            _wpDoc  = WordprocessingDocument.Open(Utils.GetAssetPath("shareholders.docx"), false);
            _plugin = new StylePlugin(_wpDoc);

            _styles =
                _wpDoc
                .MainDocumentPart
                .StyleDefinitionsPart
                .Styles
                .Elements <Style>()
                .Where(x => x.StyleId?.Value != null)
                .Distinct()
                .ToArray();

            _pPropsStyles =
                _styles
                .Where(x => x.Type?.Value == StyleValues.Paragraph)
                .Select(x => new ParagraphProperties
            {
                ParagraphStyleId = new ParagraphStyleId()
                {
                    Val = x.StyleId.Value
                }
            })
                .ToArray();

            _rPropsStyles =
                _styles
                .Where(x => x.Type?.Value == StyleValues.Character)
                .Select(x => new RunProperties
            {
                RunStyle = new RunStyle()
                {
                    Val = x.StyleId.Value
                }
            })
                .ToArray();

            _pPropsInlines =
                _wpDoc.MainDocumentPart.Document.Body
                .Descendants <ParagraphProperties>()
                .Where(x => x.ChildElements?.Count > 2)
                .Take(100)
                .ToArray();

            _rPropsInlines =
                _wpDoc.MainDocumentPart.Document.Body
                .Descendants <RunProperties>()
                .Where(x => x.ChildElements?.Count > 2)
                .Take(100)
                .ToArray();

            Console.WriteLine($"Paragraph style count: {_pPropsStyles.Length}\tRun style count: {_rPropsStyles.Length}");
        }
 public static string GetShortName(this StylePlugin stylePlugin)
 {
     if (stylePlugin.Name.Contains(area) ||
         stylePlugin.Name.Contains(line) ||
         stylePlugin.Name.Contains(point) ||
         stylePlugin.Name.Contains(text))
     {
         return(stylePlugin.Name.Replace(area, newValue).Replace(line, newValue).Replace(point, newValue).Replace(text, newValue));
     }
     return(stylePlugin.Name.Replace(common, newValue));
 }
Exemple #6
0
        public static MenuItem GetAddSpecifiedStyleByPluginMenuItem(StylePlugin styleProvider)
        {
            var image = new Image();

            image.BeginInit();
            image.Source = styleProvider.SmallIcon;
            image.EndInit();
            var command = new ObservedCommand(() => { AddStyle(styleProvider); },
                                              () =>
            {
                string stylePluginName = styleProvider.GetType().FullName;
                return(GisEditor.StyleManager.GetActiveStylePlugins().Any(p => p.GetType().FullName.Equals(stylePluginName, StringComparison.Ordinal)));
            });

            return(GetMenuItem(styleProvider.GetShortName(), image, command));
        }
Exemple #7
0
 public void Initialize()
 {
     _config   = new StyleConfig();
     _instance = new StylePlugin(Samples.NumberingSample3.BuildDoc(), _config);
 }
 public StyleSetting(StylePlugin stylePlugin)
 {
     this.stylePlugin = stylePlugin;
 }