Ejemplo n.º 1
0
        internal static void InitializeMap(this IDocumentStyle style)
        {
            var propertyInfos = style.GetType().Properties();

            foreach (var propertyInfo in propertyInfos)
            {
                style.PropeprtiesMap.Add(propertyInfo.Name, DefaultDocumentStyleName);
            }
        }
Ejemplo n.º 2
0
        public static bool Ensure(this IDocumentStyle documentStyle, Document document, IDocumentStyle[] usedStyles = null, Document defaultPropertiesProvider = null)
        {
            defaultPropertiesProvider ??= document;
            usedStyles ??= document.UsedStyles(documentStyle.DocumentStyleType, defaultPropertiesProvider).ToArray();
            if (usedStyles.Contains(documentStyle))
            {
                return(false);
            }

            documentStyle.Get(document, defaultPropertiesProvider);
            return(true);
        }
Ejemplo n.º 3
0
        private static TValue GetStylePropertyValueCore <TValue>(this IDocumentStyle style, string propertyName,
                                                                 IDocumentStyle documentStyle, Document document)
        {
            var styleName = documentStyle.PropeprtiesMap[propertyName];

            if (styleName == style.StyleName)
            {
                return((TValue)style.GetPropertyValue(propertyName));
            }
            if (styleName != DefaultDocumentStyleName)
            {
                var parentStyle = style.FromHierarchy(_ => _.Parent).First(_ => _.StyleName == styleName);
                parentStyle.Get(document);
            }

            return(default);
Ejemplo n.º 4
0
 public static void ApplyStyle(this Document document, IDocumentStyle documentStyle, Document defaultPropertiesProvider = null)
 {
     defaultPropertiesProvider ??= document;
     if (documentStyle.DocumentStyleType == DocumentStyleType.Paragraph)
     {
         document.BeginUpdate();
         var paragraphFromPosition = document.ParagraphFromPosition();
         document.Paragraphs[paragraphFromPosition].Style = (ParagraphStyle)documentStyle.Get(document, defaultPropertiesProvider);
         document.EndUpdate();
     }
     else
     {
         var range     = document.WordFromPosition();
         var charProps = document.BeginUpdateCharacters(range);
         charProps.Style = (CharacterStyle)documentStyle.Get(document, defaultPropertiesProvider);
         document.EndUpdateCharacters(charProps);
     }
 }
Ejemplo n.º 5
0
        public static CharacterPropertiesBase CreateNewStyle(this Document document, IDocumentStyle documentStyle, Document defaultPropertiesProvider = null)
        {
            if (defaultPropertiesProvider != null)
            {
                defaultPropertiesProvider.DefaultCharacterProperties.MapProperties(document.DefaultCharacterProperties);
                defaultPropertiesProvider.DefaultParagraphProperties.MapProperties(document.DefaultParagraphProperties);
            }
            var style = documentStyle.DocumentStyleType == DocumentStyleType.Paragraph
                        ? (CharacterPropertiesBase)document.ParagraphStyles.CreateNew()
                        : document.CharacterStyles.CreateNew();

            document.MapCommonProperties(style, documentStyle);
            if (style is ParagraphStyle paragraphStyle)
            {
                document.MapParagraphProperties(paragraphStyle, documentStyle);
                var styleNext = documentStyle.Next;
                if (styleNext != null)
                {
                    paragraphStyle.NextStyle = styleNext.StyleName == paragraphStyle.Name()
                                        ? paragraphStyle : (ParagraphStyle)styleNext.Get(document, defaultPropertiesProvider);
                }
                var existingStyle = document.ParagraphStyles.FirstOrDefault(_ => _.Name == style.Name());
                if (existingStyle != null)
                {
                    return(existingStyle);
                }
                document.ParagraphStyles.Add(paragraphStyle);
            }
            else
            {
                var existingStyle = document.CharacterStyles.FirstOrDefault(_ => _.Name == style.Name());
                if (existingStyle != null)
                {
                    return(existingStyle);
                }
                document.CharacterStyles.Add((CharacterStyle)style);
            }
            return(style);
        }
Ejemplo n.º 6
0
 public static CharacterPropertiesBase Find(this IDocumentStyle documentStyle, Document document)
 => documentStyle.DocumentStyleType == DocumentStyleType.Paragraph ?(CharacterPropertiesBase)document.ParagraphStyles
 .FirstOrDefault(_ => _.Name == documentStyle.StyleName):document.CharacterStyles
 .FirstOrDefault(_ => _.Name == documentStyle.StyleName);
Ejemplo n.º 7
0
 public static CharacterPropertiesBase Get(this IDocumentStyle documentStyle, Document document, Document defaultPropertiesProvider = null)
 => documentStyle.Find(document) ?? document.CreateNewStyle(documentStyle, defaultPropertiesProvider);
Ejemplo n.º 8
0
 private static TProperty GetStylePropertyValue <TStyle, TProperty>(this TStyle style, IDocumentStyle documentStyle, Document document,
                                                                    Expression <Func <IDocumentStyle, TProperty> > valueSelector) where TStyle : IDocumentStyle
 => style.GetStylePropertyValueCore <TProperty>(valueSelector.MemberExpressionName(), documentStyle, document);
Ejemplo n.º 9
0
        private static void MapCommonProperties(this Document document, CharacterPropertiesBase style, IDocumentStyle documentStyle)
        {
            style.SetPropertyValue("Name", documentStyle.StyleName);
            style.AllCaps        = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.AllCaps);
            style.BackColor      = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.BackColor);
            style.ForeColor      = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.ForeColor);
            style.Hidden         = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.Hidden);
            style.HighlightColor = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.HighlightColor);
#if !XAF191 && !XAF192
            style.KerningThreshold = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.KerningThreshold);
            style.Position         = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.Position);
            style.Scale            = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.Scale);
            style.SnapToGrid       = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.SnapToGrid);
            style.Spacing          = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.Spacing);
#endif
#if !XAF191
            style.SmallCaps = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.SmallCaps);
#endif
            style.Strikeout      = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.Strikeout);
            style.Subscript      = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.Subscript);
            style.Superscript    = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.Superscript);
            style.UnderlineColor = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.UnderlineColor);
            style.Italic         = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.Italic);
            style.Bold           = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.Bold);
            style.Underline      = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.Underline);
            style.FontName       = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.FontName);
            style.FontSize       = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.FontSize);
            style.SetPropertyValue("Parent", documentStyle.Parent?.Get(document));
        }
Ejemplo n.º 10
0
 private static void MapParagraphProperties(this Document document, ParagraphStyle style, IDocumentStyle documentStyle)
 {
     style.Alignment             = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.Alignment);
     style.RightToLeft           = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.RightToLeft);
     style.LeftIndent            = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.LeftIndent);
     style.RightIndent           = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.LeftIndent);
     style.SpacingBefore         = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.LeftIndent);
     style.SpacingAfter          = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.LeftIndent);
     style.LineSpacingType       = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.LineSpacingType);
     style.LineSpacing           = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.LineSpacing);
     style.LineSpacingMultiplier = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.LineSpacingMultiplier);
     style.FirstLineIndentType   = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.FirstLineIndentType);
     style.FirstLineIndent       = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.FirstLineIndent);
     style.SuppressHyphenation   = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.SuppressHyphenation);
     style.SuppressLineNumbers   = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.SuppressLineNumbers);
     style.OutlineLevel          = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.OutlineLevel);
     style.WidowOrphanControl    = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.WidowOrphanControl);
     style.KeepWithNext          = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.KeepWithNext);
     style.KeepLinesTogether     = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.KeepLinesTogether);
     style.PageBreakBefore       = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.PageBreakBefore);
     style.ContextualSpacing     = documentStyle.GetStylePropertyValue(documentStyle, document, _ => _.ContextualSpacing);
 }