Пример #1
0
 public static CT_RPrElt Parse(XmlNode node, XmlNamespaceManager namespaceManager)
 {
     if (node == null)
         return null;
     CT_RPrElt ctObj = new CT_RPrElt();
     foreach (XmlNode childNode in node.ChildNodes)
     {
         if (childNode.LocalName == "rFont")
             ctObj.rFont = CT_FontName.Parse(childNode, namespaceManager);
         else if (childNode.LocalName == "charset")
             ctObj.charset = CT_IntProperty.Parse(childNode, namespaceManager);
         else if (childNode.LocalName == "family")
             ctObj.family = CT_IntProperty.Parse(childNode, namespaceManager);
         else if (childNode.LocalName == "b")
             ctObj.b = CT_BooleanProperty.Parse(childNode, namespaceManager);
         else if (childNode.LocalName == "i")
             ctObj.i = CT_BooleanProperty.Parse(childNode, namespaceManager);
         else if (childNode.LocalName == "strike")
             ctObj.strike = CT_BooleanProperty.Parse(childNode, namespaceManager);
         else if (childNode.LocalName == "outline")
             ctObj.outline = CT_BooleanProperty.Parse(childNode, namespaceManager);
         else if (childNode.LocalName == "shadow")
             ctObj.shadow = CT_BooleanProperty.Parse(childNode, namespaceManager);
         else if (childNode.LocalName == "condense")
             ctObj.condense = CT_BooleanProperty.Parse(childNode, namespaceManager);
         else if (childNode.LocalName == "extend")
             ctObj.extend = CT_BooleanProperty.Parse(childNode, namespaceManager);
         else if (childNode.LocalName == "color")
             ctObj.color = CT_Color.Parse(childNode, namespaceManager);
         else if (childNode.LocalName == "sz")
             ctObj.sz = CT_FontSize.Parse(childNode, namespaceManager);
         else if (childNode.LocalName == "u")
             ctObj.u = CT_UnderlineProperty.Parse(childNode, namespaceManager);
         else if (childNode.LocalName == "vertAlign")
             ctObj.vertAlign = CT_VerticalAlignFontProperty.Parse(childNode, namespaceManager);
         else if (childNode.LocalName == "scheme")
             ctObj.scheme = CT_FontScheme.Parse(childNode, namespaceManager);
     }
     return ctObj;
 }
Пример #2
0
        /**
         *
         * org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt to
         * org.openxmlformats.schemas.drawingml.x2006.main.CTFont adapter
         */
        private static void ApplyAttributes(CT_RPrElt pr, CT_TextCharacterProperties rPr)
        {

            if (pr.sizeOfBArray() > 0) rPr.b = (pr.GetBArray(0).val);
            if (pr.sizeOfUArray() > 0)
            {
                ST_UnderlineValues u1 = pr.GetUArray(0).val;
                if (u1 == ST_UnderlineValues.single) rPr.u = (ST_TextUnderlineType.sng);
                else if (u1 == ST_UnderlineValues.@double) rPr.u = (ST_TextUnderlineType.dbl);
                else if (u1 == ST_UnderlineValues.none) rPr.u = (ST_TextUnderlineType.none);
            }
            if (pr.sizeOfIArray() > 0) rPr.i = (pr.GetIArray(0).val);

            if (pr.sizeOfFamilyArray() > 0)
            {
                CT_TextFont rFont = rPr.AddNewLatin();
                rFont.typeface = (pr.GetRFontArray(0).val);
            }

            if (pr.sizeOfSzArray() > 0)
            {
                int sz = (int)(pr.GetSzArray(0).val * 100);
                rPr.sz = (sz);
            }

            if (pr.sizeOfColorArray() > 0)
            {
                CT_SolidColorFillProperties fill = rPr.IsSetSolidFill() ? rPr.solidFill : rPr.AddNewSolidFill();
                NPOI.OpenXmlFormats.Spreadsheet.CT_Color xlsColor = pr.GetColorArray(0);
                if (xlsColor.IsSetRgb())
                {
                    CT_SRgbColor clr = fill.IsSetSrgbClr() ? fill.srgbClr : fill.AddNewSrgbClr();
                    clr.val = (xlsColor.rgb);
                }
                else if (xlsColor.IsSetIndexed())
                {
                    HSSFColor indexed = HSSFColor.GetIndexHash()[(int)xlsColor.indexed] as HSSFColor;
                    if (indexed != null)
                    {
                        byte[] rgb = new byte[3];
                        rgb[0] = (byte)indexed.GetTriplet()[0];
                        rgb[1] = (byte)indexed.GetTriplet()[1];
                        rgb[2] = (byte)indexed.GetTriplet()[2];
                        CT_SRgbColor clr = fill.IsSetSrgbClr() ? fill.srgbClr : fill.AddNewSrgbClr();
                        clr.val = (rgb);
                    }
                }
            }
        }
Пример #3
0
        /**
         *
         * CT_RPrElt --> CTFont adapter
         */
        private static void ApplyAttributes(CT_RPrElt pr, CT_TextCharacterProperties rPr)
        {

            if (pr.sizeOfBArray() > 0) rPr.b = (pr.GetBArray(0).val);
            //if(pr.sizeOfUArray() > 0) rPr.SetU(pr.GetUArray(0).GetVal());
            if (pr.sizeOfIArray() > 0) rPr.i = (pr.GetIArray(0).val);

            CT_TextFont rFont = rPr.AddNewLatin();
            rFont.typeface = (pr.sizeOfRFontArray() > 0 ? pr.GetRFontArray(0).val : "Arial");
        }
Пример #4
0
        /**
         *
         * CTRPrElt --> CTFont adapter
         */
        protected static CT_Font ToCTFont(CT_RPrElt pr)
        {
            CT_Font ctFont = new CT_Font();

            if (pr.sizeOfBArray() > 0) ctFont.AddNewB().val = (pr.GetBArray(0).val);
            if (pr.sizeOfUArray() > 0) ctFont.AddNewU().val = (pr.GetUArray(0).val);
            if (pr.sizeOfIArray() > 0) ctFont.AddNewI().val = (pr.GetIArray(0).val);
            if (pr.sizeOfColorArray() > 0)
            {
                CT_Color c1 = pr.GetColorArray(0);
                CT_Color c2 = ctFont.AddNewColor();
                if (c1.IsSetAuto())
                {
                    c2.auto = (c1.auto);
                    c2.autoSpecified = true;
                }
                if (c1.IsSetIndexed())
                {
                    c2.indexed = (c1.indexed);
                    c2.indexedSpecified = true;
                }
                if (c1.IsSetRgb())
                {
                    c2.SetRgb(c1.GetRgb());
                    c2.rgbSpecified = true;
                }
                if (c1.IsSetTheme())
                {
                    c2.theme = (c1.theme);
                    c2.themeSpecified = true;
                }
                if (c1.IsSetTint())
                {
                    c2.tint = (c1.tint);
                    c2.tintSpecified = true;
                }
            }
 
            if (pr.sizeOfSzArray() > 0) ctFont.AddNewSz().val = (pr.GetSzArray(0).val);
            if (pr.sizeOfRFontArray() > 0) ctFont.AddNewName().val = (pr.GetRFontArray(0).val);
            if (pr.sizeOfFamilyArray() > 0) ctFont.AddNewFamily().val = (pr.GetFamilyArray(0).val);
            if (pr.sizeOfSchemeArray() > 0) ctFont.AddNewScheme().val = (pr.GetSchemeArray(0).val);
            if (pr.sizeOfCharsetArray() > 0) ctFont.AddNewCharset().val = (pr.GetCharsetArray(0).val);
            if (pr.sizeOfCondenseArray() > 0) ctFont.AddNewCondense().val = (pr.GetCondenseArray(0).val);
            if (pr.sizeOfExtendArray() > 0) ctFont.AddNewExtend().val = (pr.GetExtendArray(0).val);
            if (pr.sizeOfVertAlignArray() > 0) ctFont.AddNewVertAlign().val = (pr.GetVertAlignArray(0).val);
            if (pr.sizeOfOutlineArray() > 0) ctFont.AddNewOutline().val = (pr.GetOutlineArray(0).val);
            if (pr.sizeOfShadowArray() > 0) ctFont.AddNewShadow().val = (pr.GetShadowArray(0).val);
            if (pr.sizeOfStrikeArray() > 0) ctFont.AddNewStrike().val = (pr.GetStrikeArray(0).val);

            return ctFont;
        }
Пример #5
0
        /**
         * Copy font attributes from CTFont bean into CTRPrElt bean
         */
        private void SetRunAttributes(CT_Font ctFont, CT_RPrElt pr)
        {
            if (ctFont.SizeOfBArray() > 0) pr.AddNewB().val = (ctFont.GetBArray(0).val);
            if (ctFont.sizeOfUArray() > 0) pr.AddNewU().val =(ctFont.GetUArray(0).val);
            if (ctFont.sizeOfIArray() > 0) pr.AddNewI().val =(ctFont.GetIArray(0).val);
            if (ctFont.sizeOfColorArray() > 0)
            {
                CT_Color c1 = ctFont.GetColorArray(0);
                CT_Color c2 = pr.AddNewColor();
                if (c1.IsSetAuto())
                {
                    c2.auto = (c1.auto);
                    c2.autoSpecified = true;
                }
                if (c1.IsSetIndexed())
                {
                    c2.indexed = (c1.indexed);
                    c2.indexedSpecified = true;
                }
                if (c1.IsSetRgb())
                {
                    c2.SetRgb(c1.rgb);
                    c2.rgbSpecified = true;
                }
                if (c1.IsSetTheme())
                {
                    c2.theme = (c1.theme);
                    c2.themeSpecified = true;
                }
                if (c1.IsSetTint())
                {
                    c2.tint = (c1.tint);
                    c2.tintSpecified = true;
                }
            }

            if (ctFont.sizeOfSzArray() > 0) pr.AddNewSz().val = (ctFont.GetSzArray(0).val);
            if (ctFont.sizeOfNameArray() > 0) pr.AddNewRFont().val = (ctFont.name.val);
            if (ctFont.sizeOfFamilyArray() > 0) pr.AddNewFamily().val =(ctFont.GetFamilyArray(0).val);
            if (ctFont.sizeOfSchemeArray() > 0) pr.AddNewScheme().val = (ctFont.GetSchemeArray(0).val);
            if (ctFont.sizeOfCharsetArray() > 0) pr.AddNewCharset().val = (ctFont.GetCharsetArray(0).val);
            if (ctFont.sizeOfCondenseArray() > 0) pr.AddNewCondense().val = (ctFont.GetCondenseArray(0).val);
            if (ctFont.sizeOfExtendArray() > 0) pr.AddNewExtend().val = (ctFont.GetExtendArray(0).val);
            if (ctFont.sizeOfVertAlignArray() > 0) pr.AddNewVertAlign().val = (ctFont.GetVertAlignArray(0).val);
            if (ctFont.sizeOfOutlineArray() > 0) pr.AddNewOutline().val =(ctFont.GetOutlineArray(0).val);
            if (ctFont.sizeOfShadowArray() > 0) pr.AddNewShadow().val =(ctFont.GetShadowArray(0).val);
            if (ctFont.sizeOfStrikeArray() > 0) pr.AddNewStrike().val = (ctFont.GetStrikeArray(0).val);
        }
Пример #6
0
        /**
         * Applies a font to the specified characters of a string.
         *
         * @param startIndex    The start index to apply the font to (inclusive)
         * @param endIndex      The end index to apply to font to (exclusive)
         * @param font          The index of the font to use.
         */
        public void ApplyFont(int startIndex, int endIndex, IFont font)
        {
            if (startIndex > endIndex)
                throw new ArgumentException("Start index must be less than end index.");
            if (startIndex < 0 || endIndex > Length)
                throw new ArgumentException("Start and end index not in range.");
            if (startIndex == endIndex)
                return;

            if (st.sizeOfRArray() == 0 && st.IsSetT())
            {
                //convert <t>string</t> into a text Run: <r><t>string</t></r>
                st.AddNewR().t = (st.t);
                st.unsetT();
            }

            String text = this.String;
            XSSFFont xssfFont = (XSSFFont)font;

            SortedDictionary<int, CT_RPrElt> formats = GetFormatMap(st);
            CT_RPrElt fmt = new CT_RPrElt();
            SetRunAttributes(xssfFont.GetCTFont(), fmt);
            ApplyFont(formats, startIndex, endIndex, fmt);

            CT_Rst newSt = buildCTRst(text, formats);
            st.Set(newSt);



        }
Пример #7
0
        internal void ApplyFont(SortedDictionary<int, CT_RPrElt> formats, int startIndex, int endIndex, CT_RPrElt fmt) 
        {
            
            // delete format runs that fit between startIndex and endIndex
            // runs intersecting startIndex and endIndex remain
            //int runStartIdx = 0;
            List<int> toRemoveKeys=new List<int>();
            for (SortedDictionary<int, CT_RPrElt>.KeyCollection.Enumerator it = formats.Keys.GetEnumerator(); it.MoveNext(); )
            {
                int runIdx = it.Current;
                if (runIdx >= startIndex && runIdx < endIndex)
                {
                    toRemoveKeys.Add(runIdx);
                }
            }
            foreach (int key in toRemoveKeys)
            {
                formats.Remove(key);
            }
            if (startIndex > 0 && !formats.ContainsKey(startIndex))
            {
                // If there's a format that starts later in the string, make it start now
                foreach (KeyValuePair<int, CT_RPrElt> entry in formats)
                {
                    if (entry.Key > startIndex)
                    {
                        formats[startIndex] = entry.Value;
                        break;
                    }
                }
            }
            formats[endIndex] = fmt;

            // assure that the range [startIndex, endIndex] consists if a single run
            // there can be two or three runs depending whether startIndex or endIndex
            // intersected existing format runs
            //SortedMap<int, CT_RPrElt> sub = formats.subMap(startIndex, endIndex);
            //while(sub.size() > 1) sub.remove(sub.lastKey());       
        }
Пример #8
0
        //public static CT_RPrElt Parse(string xml)
        //{
        //    CT_RPrElt result;
        //    using (StringReader stream = new StringReader(xml))
        //    {
        //        result = (CT_RPrElt)serializer.Deserialize(stream);
        //    }
        //    return result;
        //}

        public static void Save(Stream stream, CT_RPrElt font)
        {
            serializer.Serialize(stream, font, namespaces);
        }
Пример #9
0
        private string tField = string.Empty; // required field 

        public CT_RPrElt AddNewRPr()
        {
            this.rPrField = new CT_RPrElt();
            return rPrField;
        }
Пример #10
0
        public static CT_RPrElt Parse(XmlNode node, XmlNamespaceManager namespaceManager)
        {
            if (node == null)
            {
                return(null);
            }
            CT_RPrElt ctObj = new CT_RPrElt();

            foreach (XmlNode childNode in node.ChildNodes)
            {
                if (childNode.LocalName == "rFont")
                {
                    ctObj.rFont = CT_FontName.Parse(childNode, namespaceManager);
                }
                else if (childNode.LocalName == "charset")
                {
                    ctObj.charset = CT_IntProperty.Parse(childNode, namespaceManager);
                }
                else if (childNode.LocalName == "family")
                {
                    ctObj.family = CT_IntProperty.Parse(childNode, namespaceManager);
                }
                else if (childNode.LocalName == "b")
                {
                    ctObj.b = CT_BooleanProperty.Parse(childNode, namespaceManager);
                }
                else if (childNode.LocalName == "i")
                {
                    ctObj.i = CT_BooleanProperty.Parse(childNode, namespaceManager);
                }
                else if (childNode.LocalName == "strike")
                {
                    ctObj.strike = CT_BooleanProperty.Parse(childNode, namespaceManager);
                }
                else if (childNode.LocalName == "outline")
                {
                    ctObj.outline = CT_BooleanProperty.Parse(childNode, namespaceManager);
                }
                else if (childNode.LocalName == "shadow")
                {
                    ctObj.shadow = CT_BooleanProperty.Parse(childNode, namespaceManager);
                }
                else if (childNode.LocalName == "condense")
                {
                    ctObj.condense = CT_BooleanProperty.Parse(childNode, namespaceManager);
                }
                else if (childNode.LocalName == "extend")
                {
                    ctObj.extend = CT_BooleanProperty.Parse(childNode, namespaceManager);
                }
                else if (childNode.LocalName == "color")
                {
                    ctObj.color = CT_Color.Parse(childNode, namespaceManager);
                }
                else if (childNode.LocalName == "sz")
                {
                    ctObj.sz = CT_FontSize.Parse(childNode, namespaceManager);
                }
                else if (childNode.LocalName == "u")
                {
                    ctObj.u = CT_UnderlineProperty.Parse(childNode, namespaceManager);
                }
                else if (childNode.LocalName == "vertAlign")
                {
                    ctObj.vertAlign = CT_VerticalAlignFontProperty.Parse(childNode, namespaceManager);
                }
                else if (childNode.LocalName == "scheme")
                {
                    ctObj.scheme = CT_FontScheme.Parse(childNode, namespaceManager);
                }
            }
            return(ctObj);
        }
Пример #11
0
        private string tField = string.Empty; // required field

        public CT_RPrElt AddNewRPr()
        {
            this.rPrField = new CT_RPrElt();
            return(rPrField);
        }
Пример #12
0
        //public static CT_RPrElt Parse(string xml)
        //{
        //    CT_RPrElt result;
        //    using (StringReader stream = new StringReader(xml))
        //    {
        //        result = (CT_RPrElt)serializer.Deserialize(stream);
        //    }
        //    return result;
        //}

        public static void Save(Stream stream, CT_RPrElt font)
        {
            serializer.Serialize(stream, font, namespaces);
        }