示例#1
0
        /**
         * Create a new Character TextPropCollection, and add it to the list
         * @param charactersCovered The number of characters this TextPropCollection will cover
         * @return the new TextPropCollection, which will then be in the list
         */
        public TextPropCollection AddCharacterTextPropCollection(int charactersCovered)
        {
            TextPropCollection tpc = new TextPropCollection(charactersCovered);

            charStyles.Add(tpc);
            return(tpc);
        }
示例#2
0
        /**
         * Create a new Paragraph TextPropCollection, and add it to the list
         * @param charactersCovered The number of characters this TextPropCollection will cover
         * @return the new TextPropCollection, which will then be in the list
         */
        public TextPropCollection AddParagraphTextPropCollection(int charactersCovered)
        {
            TextPropCollection tpc = new TextPropCollection(charactersCovered, (short)0);

            paragraphStyles.Add(tpc);
            return(tpc);
        }
示例#3
0
        /**
         * Updates the cache of the raw contents. Serialised the styles out.
         */
        private void updateRawContents()
        {
            if (!Initialised)
            {
                // We haven't groked the styles since creation, so just stick
                // with what we found
                return;
            }

            MemoryStream baos = new MemoryStream();

            // First up, we need to serialise the paragraph properties
            for (int i = 0; i < paragraphStyles.Count; i++)
            {
                TextPropCollection tpc = paragraphStyles[i];
                tpc.WriteOut(baos);
            }

            // Now, we do the character ones
            for (int i = 0; i < charStyles.Count; i++)
            {
                TextPropCollection tpc = charStyles[i];
                tpc.WriteOut(baos);
            }

            rawContents = baos.ToArray();
        }
示例#4
0
        /**
         * A new Set of text style properties for some text without any.
         */
        public StyleTextPropAtom(int parentTextSize)
        {
            _header     = new byte[8];
            rawContents = new byte[0];
            reserved    = new byte[0];

            // Set our type
            LittleEndian.PutInt(_header, 2, (short)_type);
            // Our Initial size is 10
            LittleEndian.PutInt(_header, 4, 10);

            // Set empty paragraph and character styles
            paragraphStyles = new List <TextPropCollection>();
            charStyles      = new List <TextPropCollection>();

            TextPropCollection defaultParagraphTextProps =
                new TextPropCollection(parentTextSize, (short)0);

            paragraphStyles.Add(defaultParagraphTextProps);

            TextPropCollection defaultCharacterTextProps =
                new TextPropCollection(parentTextSize);

            charStyles.Add(defaultCharacterTextProps);

            // Set us as now Initialised
            Initialised = true;
        }
示例#5
0
        /**
         * Tell us how much text the parent TextCharsAtom or TextBytesAtom
         *  Contains, so we can go ahead and Initialise ourselves.
         */
        public void SetParentTextSize(int size)
        {
            int pos         = 0;
            int textHandled = 0;

            // While we have text in need of paragraph stylings, go ahead and
            // grok the contents as paragraph formatting data
            int prsize = size;

            while (pos < rawContents.Length && textHandled < prsize)
            {
                // First up, fetch the number of characters this applies to
                int textLen = LittleEndian.GetInt(rawContents, pos);
                textHandled += textLen;
                pos         += 4;

                short indent = LittleEndian.GetShort(rawContents, pos);
                pos += 2;

                // Grab the 4 byte value that tells us what properties follow
                int paraFlags = LittleEndian.GetInt(rawContents, pos);
                pos += 4;

                // Now make sense of those properties
                TextPropCollection thisCollection = new TextPropCollection(textLen, indent);
                int plSize = thisCollection.BuildTextPropList(
                    paraFlags, paragraphTextPropTypes, rawContents, pos);
                pos += plSize;

                // Save this properties Set
                paragraphStyles.Add(thisCollection);

                // Handle extra 1 paragraph styles at the end
                if (pos < rawContents.Length && textHandled == size)
                {
                    prsize++;
                }
            }
            if (rawContents.Length > 0 && textHandled != (size + 1))
            {
                logger.Log(POILogger.WARN, "Problem Reading paragraph style Runs: textHandled = " + textHandled + ", text.size+1 = " + (size + 1));
            }

            // Now do the character stylings
            textHandled = 0;
            int chsize = size;

            while (pos < rawContents.Length && textHandled < chsize)
            {
                // First up, fetch the number of characters this applies to
                int textLen = LittleEndian.GetInt(rawContents, pos);
                textHandled += textLen;
                pos         += 4;

                // There is no 2 byte value
                short no_val = -1;

                // Grab the 4 byte value that tells us what properties follow
                int charFlags = LittleEndian.GetInt(rawContents, pos);
                pos += 4;

                // Now make sense of those properties
                // (Assuming we actually have some)
                TextPropCollection thisCollection = new TextPropCollection(textLen, no_val);
                int chSize = thisCollection.BuildTextPropList(
                    charFlags, characterTextPropTypes, rawContents, pos);
                pos += chSize;

                // Save this properties Set
                charStyles.Add(thisCollection);

                // Handle extra 1 char styles at the end
                if (pos < rawContents.Length && textHandled == size)
                {
                    chsize++;
                }
            }
            if (rawContents.Length > 0 && textHandled != (size + 1))
            {
                logger.Log(POILogger.WARN, "Problem Reading character style Runs: textHandled = " + textHandled + ", text.size+1 = " + (size + 1));
            }

            // Handle anything left over
            if (pos < rawContents.Length)
            {
                reserved = new byte[rawContents.Length - pos];
                Array.Copy(rawContents, pos, reserved, 0, reserved.Length);
            }

            Initialised = true;
        }