Esempio n. 1
0
        /// -------------------------------------------------------------------------------------------
        /// <summary>
        /// Calculate em value from the childAttribute
        /// Update absolute value in styles.xml, If absolute font-size found in the childAttribute.
        /// Update relative value in styles.xml, If relative font-size found in the childAttribute.
        /// 
        /// <list> 
        /// </list>
        /// </summary>
        /// <param name="styleFilePath">syles.xml path</param>
        /// <param name="parentFontsize">Parent Node'textElement Font Size</param>
        /// <param name="childAttribute">Child _attribute information</param>
        /// <returns>true, if absolute value found in childAttribute </returns>
        /// -------------------------------------------------------------------------------------------
        public string GetFontsizeInsideSpan(string styleFilePath, float parentFontsize, StyleAttribute childAttribute)
        {
            //string className = childAttribute.ClassName;
            //string attributeName = childAttribute.Name;
            var insideSpanAttribute = new StyleAttribute();

            float abs = parentFontsize * childAttribute.NumericValue; // Get from parent

            var doc = new XmlDocument();
            doc.Load(styleFilePath);

            var nsmgr = new XmlNamespaceManager(doc.NameTable);
            nsmgr.AddNamespace("st", "urn:oasis:names:tc:opendocument:xmlns:style:1.0");
            nsmgr.AddNamespace("fo", "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0");

            XmlElement root = doc.DocumentElement;
            string style = "//st:style[@st:name='" + childAttribute.ClassName + "']";
            if (root != null)
            {
                XmlNode node = root.SelectSingleNode(style, nsmgr);
                if (node != null)  // Get font-size inside the current class
                {
                    for (int i = 0; i < node.ChildNodes.Count; i++)
                    {
                        XmlNode child = node.ChildNodes[i];
                        XmlNode nodeFontSize = child.Attributes.GetNamedItem("fo:font-size");
                        if (nodeFontSize != null)
                        {
                            insideSpanAttribute.SetAttribute(nodeFontSize.Value);

                            if (insideSpanAttribute.Unit == "pt") // font-size: 10pt; line-space: 1em;
                            {
                                abs = insideSpanAttribute.NumericValue * childAttribute.NumericValue;
                            }
                            else if (insideSpanAttribute.Unit == "%")
                            {
                                abs = parentFontsize * insideSpanAttribute.NumericValue / 100.0F; // font-size: 100%; line-space: 1em;
                                abs = abs * childAttribute.NumericValue;
                            }
                            else if (insideSpanAttribute.Unit == "em") // font-size: 2em; line-space: 1em;
                            {
                                abs = parentFontsize * insideSpanAttribute.NumericValue;
                                abs = abs * childAttribute.NumericValue;
                            }
                        }
                    }
                }
            }
            string absValue = abs + "pt";
            return absValue;
        }
Esempio n. 2
0
        // Public Methods

        #region GetFontweight(string styleFilePath, Stack styleStack, StyleAttribute childAttribute)

        /// -------------------------------------------------------------------------------------------
        /// <summary>
        /// Calculate the Fontweight value based on it'textElement parent _attribute value
        /// </summary>
        /// <param name="styleFilePath">syles.xml path</param>
        /// <param name="styleStack">Parent list</param>
        /// <param name="childAttribute">Child _attribute information</param>
        /// <returns>absolute value of relavite parameter</returns>
        /// -------------------------------------------------------------------------------------------
        public string GetFontweight(string styleFilePath, Stack styleStack, StyleAttribute childAttribute)
        {
            string attributeName = childAttribute.Name;
            var parentAttribute = new StyleAttribute();
            float abs;
            string absValue = string.Empty;

            var doc = new XmlDocument();
            doc.Load(styleFilePath);

            var nsmgr = new XmlNamespaceManager(doc.NameTable);
            nsmgr.AddNamespace("st", "urn:oasis:names:tc:opendocument:xmlns:style:1.0");
            nsmgr.AddNamespace("fo", "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0");

            XmlNode node;
            XmlElement root = doc.DocumentElement;

            MakeClassName = string.Empty;

            // Find parent value
            foreach (string parentClass in styleStack)
            {
                if (parentClass == "ClassEmpty")
                {
                    continue;
                }
                MakeClassName = MakeClassName + parentClass + "_";
                string style = "//st:style[@st:name='" + parentClass.Trim() + "']";
                if (root != null)
                {
                    node = root.SelectSingleNode(style, nsmgr); // work}
                    if (node != null)
                    {
                        for (int i = 0; i < node.ChildNodes.Count; i++)
                        {
                            XmlNode child = node.ChildNodes[i];
                            foreach (XmlAttribute attribute in child.Attributes)
                            {
                                if (attribute.Name == attributeName)
                                {
                                    parentAttribute.SetAttribute(attribute.Value);
                                    if (childAttribute.StringValue == "lighter")
                                    {
                                        abs = parentAttribute.NumericValue - 300;
                                        if (abs < 100)
                                        {
                                            abs = 100;
                                        }
                                        absValue = abs.ToString();
                                        return (absValue);
                                    }
                                    if (childAttribute.StringValue == "bolder")
                                    {
                                        abs = parentAttribute.NumericValue + 300;
                                        if (abs > 900)
                                        {
                                            abs = 900;
                                        }
                                        absValue = abs.ToString();
                                        return (absValue);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            // Apply default value to Related value

            MakeClassName = "Empty";
            if (childAttribute.StringValue == "lighter")
            {
                absValue = "400"; // 0.5em -> 6pt
            }
            else if (childAttribute.StringValue == "bolder")
            {
                absValue = "700"; // 50% -> 6pt
                //abs = 0.0F * childAttribute.NumericValue / 100.0F; // 50% -> 0pt
            }
            return (absValue);
        }
Esempio n. 3
0
        /// -------------------------------------------------------------------------------------------
        /// <summary>
        /// Calculate the absolute value based on it'textElement parent _attribute value
        /// <list> 
        /// </list>
        /// </summary>
        /// <param name="styleFilePath">syles.xml path</param>
        /// <param name="styleStack">Parent list</param>
        /// <param name="childAttribute">Child _attribute information</param>
        /// <returns>absolute value of relavite parameter</returns>
        /// -------------------------------------------------------------------------------------------
        public string GetFontsize(string styleFilePath, Stack styleStack, StyleAttribute childAttribute)
        {
            string attributeName = childAttribute.Name;
            var parentAttribute = new StyleAttribute();
             float abs = 0F;
            string absValue;

            var doc = new XmlDocument();
            try
            {
                doc.Load(styleFilePath);
            }
            catch (XmlException e)
            {
                var msg = new[] { e.Message, styleFilePath };
                LocDB.Message("errProcessXHTML", styleFilePath + " is Not Valid. " + "\n" + e.Message, msg, LocDB.MessageTypes.Info, LocDB.MessageDefault.First);
                return "";
            }

            var nsmgr = new XmlNamespaceManager(doc.NameTable);
            nsmgr.AddNamespace("st", "urn:oasis:names:tc:opendocument:xmlns:style:1.0");
            nsmgr.AddNamespace("fo", "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0");

            XmlNode node;
            XmlElement root = doc.DocumentElement;

            MakeClassName = string.Empty;

            if (childAttribute.Unit == "em")
            {
                attributeName = "fo:font-size";
            }

            // Find relative value(%)
            foreach (string parentClass in styleStack)
            {
                if (parentClass == "ClassEmpty")
                {
                    continue;
                }
                MakeClassName = MakeClassName + parentClass + "_";
                string style = "//st:style[@st:name='" + parentClass.Trim() + "']";
                if (root != null)
                {
                    node = root.SelectSingleNode(style, nsmgr); // work}
                    if (node != null)
                    {
                        for (int i = 0; i < node.ChildNodes.Count; i++)
                        {
                            XmlNode child = node.ChildNodes[i];
                            foreach (XmlAttribute attribute in child.Attributes)
                            {
                                if (attribute.Name == attributeName)
                                {
                                    parentAttribute.SetAttribute(attribute.Value);
                                    if (childAttribute.Unit == "%")
                                    {
                                        abs = parentAttribute.NumericValue*childAttribute.NumericValue/100.0F;
                                            // 0.5em = 50%
                                        absValue = abs + "pt";
                                        return (absValue);
                                    }
                                    if (childAttribute.Unit == "em")
                                    {
                                        abs = parentAttribute.NumericValue*childAttribute.NumericValue;
                                            // 0.5em = 50%
                                        absValue = abs + "pt";
                                        return (absValue);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            // Apply default value to Related value

            MakeClassName = "Empty";
            if (childAttribute.Unit == "em")
            {
                abs = 12.0F * childAttribute.NumericValue; // 0.5em -> 6pt
            }
            else if (childAttribute.Unit == "%")
            {
                abs = 12.0F * childAttribute.NumericValue / 100.0F; // 50% -> 6pt
            }
            absValue = abs + "pt";
            return (absValue);
        }