public static Style CreateStyle(string name, StyleValues styleType, string fontName = null, int? fontSize = null, bool bold = false, bool italic = false, string hexColour = null, Tabs tabs = null) { var style = new Style { Type = styleType, StyleId = name }; var runProps = new StyleRunProperties(); if (fontName != null) runProps.Append(new RunFonts { Ascii = fontName }); if (fontSize.HasValue) runProps.Append(new FontSize { Val = fontSize.Value.ToString() }); if (bold) runProps.Append(new Bold()); //?? this doesn't create bold text, it inverts the existing bold setting if (italic) runProps.Append(new Italic()); style.Append(new Name { Val = name }); if (hexColour != null) runProps.Append(new Color { Val = hexColour }); //style.Append(new BasedOn { Val = "Heading1" }); //style.Append(new NextParagraphStyle { Val = "Normal" }); style.Append(runProps); if (tabs != null) { var paragraphProps = new StyleParagraphProperties(tabs); style.Append(paragraphProps); } return style; }
ValueAnimation <StyleValues> ITransitionAnimations.Start(StyleValues to, int durationMs) { if (to.m_StyleValues == null) { to.Values(); } return(Start((e) => ReadCurrentValues(e, to), to, durationMs)); }
// Create a new style with the specified styleid and stylename and add it to the specified // style definitions part. private static void AddNewStyle(StyleDefinitionsPart styleDefinitionsPart, string styleid, string stylename, StyleValues type, Action <StyleRunProperties> prepareRunStyle, Action <StyleParagraphProperties> prepareParagraphStyle, string basedOn = "Normal") { // Get access to the root element of the styles part. Styles styles = styleDefinitionsPart.Styles; // Create a new paragraph style and specify some of the properties. Style style = new Style() { Type = type, StyleId = styleid, CustomStyle = true }; StyleName styleName1 = new StyleName() { Val = stylename }; BasedOn basedOn1 = new BasedOn() { Val = basedOn }; NextParagraphStyle nextParagraphStyle1 = new NextParagraphStyle() { Val = "Normal" }; style.Append(styleName1); if (!string.IsNullOrEmpty(basedOn)) { style.Append(basedOn1); } //style.Append(nextParagraphStyle1); // Create the StyleRunProperties object and specify some of the run properties. StyleRunProperties styleRunProperties = new StyleRunProperties(); prepareRunStyle(styleRunProperties); // Add the run properties to the style. style.Append(styleRunProperties); StyleParagraphProperties styleParaProperties = new StyleParagraphProperties(); prepareParagraphStyle(styleParaProperties); style.Append(styleParaProperties); // Add the style to the styles part. styles.Append(style); }
ValueAnimation <StyleValues> ITransitionAnimations.Start(StyleValues from, StyleValues to, int durationMs) { if (from.m_StyleValues == null) { from.Values(); } if (to.m_StyleValues == null) { to.Values(); } return(Start((e) => from, to, durationMs)); }
/// <summary> /// Gets the style associated with the specified name. /// </summary> /// <param name="name">The name whose style to get.</param> /// <param name="styleType">Specify the type of style seeked (Paragraph or Character).</param> /// <param name="style">When this method returns, the style associated with the specified name, if /// the key is found; otherwise, returns null. This parameter is passed uninitialized.</param> public bool TryGetValueIgnoreCase(String name, StyleValues styleType, out Style style) { // we'll use Binary Search algorithm because the collection is sorted (we inherits from SortedList) IList <String> keys = this.Keys; int low = 0, hi = keys.Count - 1, mid; while (low <= hi) { mid = low + (hi - low) / 2; // Do not use Ordinal for string comparison to avoid the '_' character not being considered (bug #13776 reported by giorand) int rc = String.Compare(name, keys[mid], StringComparison.CurrentCultureIgnoreCase); if (rc == 0) { style = this.Values[mid]; Style firstFoundStyle = style; // we have found the named style but maybe the style doesn't match (Paragraph is not Character) for (int i = mid; i < keys.Count && !style.Type.Equals <StyleValues>(styleType); i++) { style = this.Values[i]; if (!String.Equals(style.StyleName.Val, name, StringComparison.OrdinalIgnoreCase)) { break; } } if (!String.Equals(style.StyleName.Val, name, StringComparison.OrdinalIgnoreCase)) { style = firstFoundStyle; } return(style.Type.Equals <StyleValues>(styleType)); } else if (rc < 0) { hi = mid - 1; } else { low = mid + 1; } } style = null; return(false); }
/// <summary> /// Helper method to obtain the StyleId of a named style (invariant or localized name). /// </summary> /// <param name="name">The name of the style to look for.</param> /// <param name="styleType">True to obtain the character version of the given style.</param> /// <param name="ignoreCase">Indicate whether the search should be performed with the case-sensitive flag or not.</param> /// <returns>If not found, returns the given name argument.</returns> public String GetStyle(string name, StyleValues styleType = StyleValues.Paragraph, bool ignoreCase = false) { Style style; // OpenXml is case-sensitive but CSS is not. // We will try to find the styles another time with case-insensitive: if (ignoreCase) { if (!knownStyles.TryGetValueIgnoreCase(name, styleType, out style)) { if (StyleMissing != null) { StyleMissing(this, new StyleEventArgs(name, mainPart, styleType)); if (knownStyles.TryGetValueIgnoreCase(name, styleType, out style)) { return(style.StyleId); } } return(null); // null means we ignore this style (css class) } return(style.StyleId); } else { if (!knownStyles.TryGetValue(name, out style)) { if (!EnsureKnownStyle(name, out style)) { StyleMissing?.Invoke(this, new StyleEventArgs(name, mainPart, styleType)); return(name); } } if (styleType == StyleValues.Character && !style.Type.Equals <StyleValues>(StyleValues.Character)) { LinkedStyle linkStyle = style.GetFirstChild <LinkedStyle>(); if (linkStyle != null) { return(linkStyle.Val); } } return(style.StyleId); } }
private Style CreateStyle(string name, StyleValues type, string linkedTo = null) { var style = new Style { StyleId = name, CustomStyle = true, Type = type }; if (!string.IsNullOrEmpty(linkedTo)) { style.Append(new LinkedStyle { Val = linkedTo }); } style.Append(new StyleName { Val = name }); return(style); }
//File access restriction for .net Core, skipping in this version private static bool IsStyleIdInDocument(WordprocessingDocument document, string styleId, StyleValues styleValues = StyleValues.Paragraph) { // Get access to the Styles element for this document. var s = document.MainDocumentPart.StyleDefinitionsPart.Styles; // Check that there are styles and how many. var n = s.Elements <Style>().Count(); if (n == 0) { return(false); } // Look for a match on styleId. var style = s .Elements <Style>() .FirstOrDefault(st => (st.StyleId == styleId) && (st.Type == styleValues)); return(style != null); }
// Return styleId that matches the styleName, or null when there's no match. // //File access restriction for .net Core, skipping in this version private static string GetStyleIdFromStyleName(WordprocessingDocument document, string styleName, StyleValues styleValues = StyleValues.Paragraph) { var stylePart = document.MainDocumentPart.StyleDefinitionsPart;; string styleId = stylePart.Styles.Descendants <StyleName>() .Where(s => s.Val.Value.Equals(styleName) && ((Style)s.Parent).Type == styleValues) .Select(n => ((Style)n.Parent).StyleId).FirstOrDefault(); return(styleId); }
private ValueAnimation <StyleValues> Start(Func <VisualElement, StyleValues> fromValueGetter, StyleValues to, int durationMs) { return(StartAnimation(ValueAnimation <StyleValues> .Create(this, Lerp.Interpolate), fromValueGetter, to, durationMs, AssignStyleValues)); }
// Create a new style with the specified styleid and stylename and add it to the specified // style definitions part. private static void AddNewStyle(StyleDefinitionsPart styleDefinitionsPart, string styleid, string stylename, StyleValues type, Action<StyleRunProperties> prepareRunStyle, Action<StyleParagraphProperties> prepareParagraphStyle, string basedOn = "Normal") { // Get access to the root element of the styles part. Styles styles = styleDefinitionsPart.Styles; // Create a new paragraph style and specify some of the properties. Style style = new Style() { Type = type, StyleId = styleid, CustomStyle = true }; StyleName styleName1 = new StyleName() { Val = stylename }; BasedOn basedOn1 = new BasedOn() { Val = basedOn }; NextParagraphStyle nextParagraphStyle1 = new NextParagraphStyle() { Val = "Normal" }; style.Append(styleName1); if (!string.IsNullOrEmpty(basedOn)) style.Append(basedOn1); //style.Append(nextParagraphStyle1); // Create the StyleRunProperties object and specify some of the run properties. StyleRunProperties styleRunProperties = new StyleRunProperties(); prepareRunStyle(styleRunProperties); // Add the run properties to the style. style.Append(styleRunProperties); StyleParagraphProperties styleParaProperties = new StyleParagraphProperties(); prepareParagraphStyle(styleParaProperties); style.Append(styleParaProperties); // Add the style to the styles part. styles.Append(style); }
StyleValues ReadCurrentValues(VisualElement ve, StyleValues targetValuesToRead) { StyleValues s = new StyleValues(); var src = ve.resolvedStyle; foreach (var styleValue in targetValuesToRead.m_StyleValues.m_Values) { switch (styleValue.id) { case StyleSheets.StylePropertyID.Unknown: break; case StyleSheets.StylePropertyID.MarginLeft: s.marginLeft = src.marginLeft; break; case StyleSheets.StylePropertyID.MarginTop: s.marginTop = src.marginTop; break; case StyleSheets.StylePropertyID.MarginRight: s.marginRight = src.marginRight; break; case StyleSheets.StylePropertyID.MarginBottom: s.marginBottom = src.marginBottom; break; case StyleSheets.StylePropertyID.PaddingLeft: s.paddingLeft = src.paddingLeft; break; case StyleSheets.StylePropertyID.PaddingTop: s.paddingTop = src.paddingTop; break; case StyleSheets.StylePropertyID.PaddingRight: s.paddingRight = src.paddingRight; break; case StyleSheets.StylePropertyID.PaddingBottom: s.paddingBottom = src.paddingBottom; break; case StyleSheets.StylePropertyID.PositionLeft: s.left = src.left; break; case StyleSheets.StylePropertyID.PositionTop: s.top = src.top; break; case StyleSheets.StylePropertyID.PositionRight: s.right = src.right; break; case StyleSheets.StylePropertyID.PositionBottom: s.bottom = src.bottom; break; case StyleSheets.StylePropertyID.Width: s.width = src.width; break; case StyleSheets.StylePropertyID.Height: s.height = src.height; break; case StyleSheets.StylePropertyID.FlexGrow: s.flexGrow = src.flexGrow; break; case StyleSheets.StylePropertyID.FlexShrink: s.flexShrink = src.flexShrink; break; case StyleSheets.StylePropertyID.BorderLeftWidth: s.borderLeftWidth = src.borderLeftWidth; break; case StyleSheets.StylePropertyID.BorderTopWidth: s.borderTopWidth = src.borderTopWidth; break; case StyleSheets.StylePropertyID.BorderRightWidth: s.borderRightWidth = src.borderRightWidth; break; case StyleSheets.StylePropertyID.BorderBottomWidth: s.borderBottomWidth = src.borderBottomWidth; break; case StyleSheets.StylePropertyID.BorderTopLeftRadius: s.borderTopLeftRadius = src.borderTopLeftRadius; break; case StyleSheets.StylePropertyID.BorderTopRightRadius: s.borderTopRightRadius = src.borderTopRightRadius; break; case StyleSheets.StylePropertyID.BorderBottomRightRadius: s.borderBottomRightRadius = src.borderBottomRightRadius; break; case StyleSheets.StylePropertyID.BorderBottomLeftRadius: s.borderBottomLeftRadius = src.borderBottomLeftRadius; break; case StyleSheets.StylePropertyID.Color: s.color = src.color; break; case StyleSheets.StylePropertyID.BackgroundColor: s.backgroundColor = src.backgroundColor; break; case StyleSheets.StylePropertyID.BorderColor: s.borderColor = src.borderLeftColor; break; case StyleSheets.StylePropertyID.BackgroundImageTintColor: s.unityBackgroundImageTintColor = src.unityBackgroundImageTintColor; break; case StyleSheets.StylePropertyID.Opacity: s.opacity = src.opacity; break; default: break; } } return(s); }
ValueAnimation <StyleValues> ITransitionAnimations.Start(StyleValues to, int durationMs) { return(Start((e) => ReadCurrentValues(e, to), to, durationMs)); }
ValueAnimation <StyleValues> ITransitionAnimations.Start(StyleValues from, StyleValues to, int durationMs) { return(Start((e) => from, to, durationMs)); }
private static void AssignStyleValues(VisualElement ve, StyleValues src) { var s = ve.style; foreach (var styleValue in src.m_StyleValues.m_Values) { switch (styleValue.id) { case StyleSheets.StylePropertyID.Unknown: break; case StyleSheets.StylePropertyID.MarginLeft: s.marginLeft = styleValue.number; break; case StyleSheets.StylePropertyID.MarginTop: s.marginTop = styleValue.number; break; case StyleSheets.StylePropertyID.MarginRight: s.marginRight = styleValue.number; break; case StyleSheets.StylePropertyID.MarginBottom: s.marginBottom = styleValue.number; break; case StyleSheets.StylePropertyID.PaddingLeft: s.paddingLeft = styleValue.number; break; case StyleSheets.StylePropertyID.PaddingTop: s.paddingTop = styleValue.number; break; case StyleSheets.StylePropertyID.PaddingRight: s.paddingRight = styleValue.number; break; case StyleSheets.StylePropertyID.PaddingBottom: s.paddingBottom = styleValue.number; break; case StyleSheets.StylePropertyID.PositionLeft: s.left = styleValue.number; break; case StyleSheets.StylePropertyID.PositionTop: s.top = styleValue.number; break; case StyleSheets.StylePropertyID.PositionRight: s.right = styleValue.number; break; case StyleSheets.StylePropertyID.PositionBottom: s.bottom = styleValue.number; break; case StyleSheets.StylePropertyID.Width: s.width = styleValue.number; break; case StyleSheets.StylePropertyID.Height: s.height = styleValue.number; break; case StyleSheets.StylePropertyID.FlexGrow: s.flexGrow = styleValue.number; break; case StyleSheets.StylePropertyID.FlexShrink: s.flexShrink = styleValue.number; break; case StyleSheets.StylePropertyID.BorderLeftWidth: s.borderLeftWidth = styleValue.number; break; case StyleSheets.StylePropertyID.BorderTopWidth: s.borderTopWidth = styleValue.number; break; case StyleSheets.StylePropertyID.BorderRightWidth: s.borderRightWidth = styleValue.number; break; case StyleSheets.StylePropertyID.BorderBottomWidth: s.borderBottomWidth = styleValue.number; break; case StyleSheets.StylePropertyID.BorderTopLeftRadius: s.borderTopLeftRadius = styleValue.number; break; case StyleSheets.StylePropertyID.BorderTopRightRadius: s.borderTopRightRadius = styleValue.number; break; case StyleSheets.StylePropertyID.BorderBottomRightRadius: s.borderBottomRightRadius = styleValue.number; break; case StyleSheets.StylePropertyID.BorderBottomLeftRadius: s.borderBottomLeftRadius = styleValue.number; break; case StyleSheets.StylePropertyID.FontSize: s.fontSize = styleValue.number; break; case StyleSheets.StylePropertyID.Color: s.color = styleValue.color; break; case StyleSheets.StylePropertyID.BackgroundColor: s.backgroundColor = styleValue.color; break; case StyleSheets.StylePropertyID.BorderColor: s.borderLeftColor = styleValue.color; s.borderTopColor = styleValue.color; s.borderRightColor = styleValue.color; s.borderBottomColor = styleValue.color; break; case StyleSheets.StylePropertyID.BackgroundImageTintColor: s.unityBackgroundImageTintColor = styleValue.color; break; case StyleSheets.StylePropertyID.Opacity: s.opacity = styleValue.number; break; default: break; } } }
/// <summary> /// convert the StyleValue enum. /// </summary> /// <param name="value"></param> /// <returns></returns> public static DocumentFormat.OpenXml.Wordprocessing.StyleValues ToOOxml(this StyleValues value) { return((DocumentFormat.OpenXml.Wordprocessing.StyleValues)(int) value); }
internal StyleEventArgs(String styleId, MainDocumentPart mainPart, StyleValues type) { this.Name = styleId; this.StyleDefinitionsPart = mainPart.StyleDefinitionsPart; this.Type = type; }
/// <summary> /// Helper method to obtain the StyleId of a named style (invariant or localized name). /// </summary> /// <param name="name">The name of the style to look for.</param> /// <param name="styleType">True to obtain the character version of the given style.</param> /// <param name="ignoreCase">Indicate whether the search should be performed with the case-sensitive flag or not.</param> /// <returns>If not found, returns the given name argument.</returns> public String GetStyle(string name, StyleValues styleType = StyleValues.Paragraph, bool ignoreCase = false) { Style style; // OpenXml is case-sensitive but CSS is not. // We will try to find the styles another time with case-insensitive: if (ignoreCase) { if (!knownStyles.TryGetValueIgnoreCase(name, styleType, out style)) { if (StyleMissing != null) { StyleMissing(this, new StyleEventArgs(name, mainPart, styleType)); if (knownStyles.TryGetValueIgnoreCase(name, styleType, out style)) return style.StyleId; } return null; // null means we ignore this style (css class) } return style.StyleId; } else { if (!knownStyles.TryGetValue(name, out style)) { if (StyleMissing != null) StyleMissing(this, new StyleEventArgs(name, mainPart, styleType)); return name; } if (styleType == StyleValues.Character && !style.Type.Equals<StyleValues>(StyleValues.Character)) { LinkedStyle linkStyle = style.GetFirstChild<LinkedStyle>(); if (linkStyle != null) return linkStyle.Val; } return style.StyleId; } }
public BorderTag(StyleValues style, int width) { Style = style; Width = width; }