Example #1
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, but had " + startIndex + " and " + endIndex);
            }
            if (startIndex < 0 || endIndex > Length)
            {
                throw new ArgumentException("Start and end index not in range, but had " + startIndex + " and " + endIndex);
            }
            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);
        }
Example #2
0
        public override bool Equals(Object o)
        {
            if (!(o is XSSFFont))
            {
                return(false);
            }

            XSSFFont cf = (XSSFFont)o;

            return(_ctFont.ToString().Equals(cf.GetCTFont().ToString()));
        }
Example #3
0
        /**
         * Append new text to this text run and apply the specify font to it
         *
         * @param text  the text to append
         * @param font  the font to apply to the Appended text or <code>null</code> if no formatting is required
         */
        public void Append(String text, XSSFFont font)
        {
            if (st.sizeOfRArray() == 0 && st.IsSetT())
            {
                //convert <t>string</t> into a text Run: <r><t>string</t></r>
                CT_RElt lt = st.AddNewR();
                lt.t = st.t;
                PreserveSpaces(lt.t);
                st.unsetT();
            }
            CT_RElt lt2 = st.AddNewR();

            lt2.t = (text);
            PreserveSpaces(lt2.t);
            CT_RPrElt pr = lt2.AddNewRPr();

            if (font != null)
            {
                SetRunAttributes(font.GetCTFont(), pr);
            }
        }
Example #4
0
 public void SetStylesTableReference(StylesTable stylestable)
 {
     this.styles = stylestable;
     if (st.sizeOfRArray() > 0)
     {
         foreach (CT_RElt r in st.r)
         {
             CT_RPrElt pr = r.rPr;
             if (pr != null && pr.SizeOfRFontArray() > 0)
             {
                 String fontName = pr.GetRFontArray(0).val;
                 if (fontName.StartsWith("#"))
                 {
                     int      idx  = int.Parse(fontName.Substring(1));
                     XSSFFont font = styles.GetFontAt(idx);
                     pr.rFont = null;
                     SetRunAttributes(font.GetCTFont(), pr);
                 }
             }
         }
     }
 }
Example #5
0
        public void TestConstructor()
        {
            XSSFFont xssfFont = new XSSFFont();

            Assert.IsNotNull(xssfFont.GetCTFont());
        }