Пример #1
0
        private bool isStyleRightToLeft(ushort istd)
        {
            StyleSheetDescription style = _parentDoc.Styles.Styles[istd];

            foreach (SinglePropertyModifier sprm in style.papx.grpprl)
            {
                if (sprm.OpCode == SinglePropertyModifier.OperationCode.sprmPFBiDi)
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #2
0
 /// <summary>
 /// Chooses the correct style name.
 /// Word 2007 needs the identifier instead of the stylename for translating it into the UI language.
 /// </summary>
 /// <param name="std">The StyleSheetDescription</param>
 /// <returns></returns>
 private string getStyleName(StyleSheetDescription std)
 {
     if (std.sti != StyleSheetDescription.StyleIdentifier.User &&
         std.sti != StyleSheetDescription.StyleIdentifier.Null)
     {
         //use the identifier
         return(std.sti.ToString());
     }
     else
     {
         //if no identifier is set, use the name
         return(std.xstzName);
     }
 }
Пример #3
0
 /// <summary>
 /// Generates a style id for custom style names or returns the build-in identifier for build-in styles.
 /// </summary>
 /// <param name="std">The StyleSheetDescription</param>
 /// <returns></returns>
 public static string MakeStyleId(StyleSheetDescription std)
 {
     if (std.sti != StyleSheetDescription.StyleIdentifier.User &&
         std.sti != StyleSheetDescription.StyleIdentifier.Null)
     {
         //use the identifier
         return(std.sti.ToString());
     }
     else
     {
         //if no identifier is set, use the name
         string ret = std.xstzName;
         ret = ret.Replace(" ", "");
         ret = ret.Replace("(", "");
         ret = ret.Replace(")", "");
         ret = ret.Replace("'", "");
         ret = ret.Replace("\"", "");
         return(ret);
     }
 }
Пример #4
0
        /// <summary>
        /// prints the contents of the stylesheet
        /// </summary>
        private static void testSTSH()
        {
            StyleSheet stsh = new StyleSheet(doc.FIB, doc.TableStream, doc.DataStream);

            Console.WriteLine("Stylesheet contains " + stsh.Styles.Count + " Styles");

            for (int i = 0; i < stsh.Styles.Count; i++)
            {
                Console.WriteLine("Style " + i);
                StyleSheetDescription std = stsh.Styles[i];
                if (std != null)
                {
                    Console.WriteLine("\tIdentifier: " + std.sti);
                    Console.WriteLine("\tStyle Kind: " + std.stk);
                    Console.WriteLine("\tBased On: " + std.istdBase);
                    Console.WriteLine("\tName: " + std.xstzName);

                    if (std.papx != null)
                    {
                        Console.WriteLine("\t\tPAPX modifier:");
                        foreach (SinglePropertyModifier sprm in std.papx.grpprl)
                        {
                            Console.WriteLine(String.Format("\t\tSPRM: modifies " + sprm.Type + " property 0x{0:x4} (" + sprm.Arguments.Length + " bytes)", sprm.OpCode));
                        }
                    }

                    if (std.chpx != null)
                    {
                        Console.WriteLine("\t\tCHPX modifier:");
                        foreach (SinglePropertyModifier sprm in std.chpx.grpprl)
                        {
                            Console.WriteLine(String.Format("\t\tSPRM: modifies " + sprm.Type + " property 0x{0:x4} (" + sprm.Arguments.Length + " bytes)", sprm.OpCode));
                        }
                    }
                }
                else
                {
                    Console.WriteLine("\tEmpty Slot");
                }
            }
        }
Пример #5
0
        /// <summary>
        /// CHPX flags are special flags because the can be 0,1,128 and 129,
        /// so this method overrides the appendFlagElement method.
        /// </summary>
        protected override void appendFlagElement(XmlElement node, SinglePropertyModifier sprm, string elementName, bool unique)
        {
            byte flag = sprm.Arguments[0];

            if (flag != 128)
            {
                XmlElement   ele = _nodeFactory.CreateElement("w", elementName, OpenXmlNamespaces.WordprocessingML);
                XmlAttribute val = _nodeFactory.CreateAttribute("w", "val", OpenXmlNamespaces.WordprocessingML);

                if (unique)
                {
                    foreach (XmlElement exEle in node.ChildNodes)
                    {
                        if (exEle.Name == ele.Name)
                        {
                            node.RemoveChild(exEle);
                            break;
                        }
                    }
                }

                if (flag == 0)
                {
                    val.Value = "false";
                    ele.Attributes.Append(val);
                    node.AppendChild(ele);
                }
                else if (flag == 1)
                {
                    //dont append attribute val
                    //no attribute means true
                    node.AppendChild(ele);
                }
                else if (flag == 129)
                {
                    //Invert the value of the style

                    //determine the style id of the current style
                    UInt16 styleId = 0;
                    if (_currentIstd != UInt16.MaxValue)
                    {
                        styleId = _currentIstd;
                    }
                    else if (_currentPapx != null)
                    {
                        styleId = _currentPapx.istd;
                    }

                    //this chpx is the chpx of a style,
                    //don't use the id of the chpx or the papx, use the baseOn style
                    if (_styleChpx)
                    {
                        StyleSheetDescription thisStyle = _doc.Styles.Styles[styleId];
                        styleId = (UInt16)thisStyle.istdBase;
                    }

                    //build the style hierarchy
                    if (_hierarchy == null)
                    {
                        _hierarchy = buildHierarchy(_doc.Styles, styleId);
                    }

                    //apply the toggle values to get the real value of the style
                    bool stylesVal = applyToggleHierachy(sprm);

                    //invert it
                    if (stylesVal)
                    {
                        val.Value = "0";
                        ele.Attributes.Append(val);
                    }
                    node.AppendChild(ele);
                }
            }
        }