Exemplo n.º 1
0
 /** Fetch the TextProp with this name, or null if it isn't present */
 public TextProp FindByName(String textPropName)
 {
     for (int i = 0; i < textPropList.Count; i++)
     {
         TextProp prop = textPropList[i];
         if (prop.GetName().Equals(textPropName))
         {
             return(prop);
         }
     }
     return(null);
 }
Exemplo n.º 2
0
        /**
         * Writes out to disk the header, and then all the properties
         */
        public void WriteOut(Stream o)
        {
            // First goes the number of characters we affect
            StyleTextPropAtom.WriteLittleEndian(charactersCovered, o);

            // Then we have the reserved field if required
            if (reservedField > -1)
            {
                StyleTextPropAtom.WriteLittleEndian(reservedField, o);
            }

            // Then the mask field
            int mask = maskSpecial;

            for (int i = 0; i < textPropList.Count; i++)
            {
                TextProp textProp = (TextProp)textPropList[i];
                //sometimes header indicates that the bitmask is present but its value is 0

                if (textProp is BitMaskTextProp)
                {
                    if (mask == 0)
                    {
                        mask |= textProp.GetWriteMask();
                    }
                }
                else
                {
                    mask |= textProp.GetWriteMask();
                }
            }
            StyleTextPropAtom.WriteLittleEndian(mask, o);

            // Then the contents of all the properties
            for (int i = 0; i < textPropList.Count; i++)
            {
                TextProp textProp = textPropList[i];
                int      val      = textProp.GetValue();
                if (textProp.GetSize() == 2)
                {
                    StyleTextPropAtom.WriteLittleEndian((short)val, o);
                }
                else if (textProp.GetSize() == 4)
                {
                    StyleTextPropAtom.WriteLittleEndian(val, o);
                }
            }
        }
Exemplo n.º 3
0
        /**
         * For an existing Set of text properties, build the list of
         *  properties coded for in a given run of properties.
         * @return the number of bytes that were used encoding the properties list
         */
        public int BuildTextPropList(int ContainsField, TextProp[] potentialProperties, byte[] data, int dataOffset)
        {
            int bytesPassed = 0;

            // For each possible entry, see if we match the mask
            // If we do, decode that, save it, and shuffle on
            for (int i = 0; i < potentialProperties.Length; i++)
            {
                // Check there's still data left to read

                // Check if this property is found in the mask
                if ((ContainsField & potentialProperties[i].GetMask()) != 0)
                {
                    if (dataOffset + bytesPassed >= data.Length)
                    {
                        // Out of data, can't be any more properties to go
                        // remember the mask and return
                        maskSpecial |= potentialProperties[i].GetMask();
                        return(bytesPassed);
                    }

                    // Bingo, data Contains this property
                    TextProp prop = (TextProp)potentialProperties[i].Clone();
                    int      val  = 0;
                    if (prop.GetSize() == 2)
                    {
                        val = LittleEndian.GetShort(data, dataOffset + bytesPassed);
                    }
                    else if (prop.GetSize() == 4)
                    {
                        val = LittleEndian.GetInt(data, dataOffset + bytesPassed);
                    }
                    else if (prop.GetSize() == 0)
                    {
                        //remember "special" bits.
                        maskSpecial |= potentialProperties[i].GetMask();
                        continue;
                    }
                    prop.SetValue(val);
                    bytesPassed += prop.GetSize();
                    textPropList.Add(prop);
                }
            }

            // Return how many bytes were used
            return(bytesPassed);
        }
Exemplo n.º 4
0
        /** Add the TextProp with this name to the list */
        public TextProp AddWithName(String name)
        {
            // Find the base TextProp to base on
            TextProp base1 = null;

            for (int i = 0; i < StyleTextPropAtom.characterTextPropTypes.Length; i++)
            {
                if (StyleTextPropAtom.characterTextPropTypes[i].GetName().Equals(name))
                {
                    base1 = StyleTextPropAtom.characterTextPropTypes[i];
                }
            }
            for (int i = 0; i < StyleTextPropAtom.paragraphTextPropTypes.Length; i++)
            {
                if (StyleTextPropAtom.paragraphTextPropTypes[i].GetName().Equals(name))
                {
                    base1 = StyleTextPropAtom.paragraphTextPropTypes[i];
                }
            }
            if (base1 == null)
            {
                throw new ArgumentException("No TextProp with name " + name + " is defined to add from");
            }

            // Add a copy of this property, in the right place to the list
            TextProp textProp = (TextProp)base1.Clone();
            int      pos      = 0;

            for (int i = 0; i < textPropList.Count; i++)
            {
                TextProp curProp = textPropList[i];
                if (textProp.GetMask() > curProp.GetMask())
                {
                    pos++;
                }
            }
            textPropList.Insert(pos, textProp);
            return(textProp);
        }
Exemplo n.º 5
0
        /**
         * For an existing Set of text properties, build the list of 
         *  properties coded for in a given run of properties.
         * @return the number of bytes that were used encoding the properties list
         */
        public int BuildTextPropList(int ContainsField, TextProp[] potentialProperties, byte[] data, int dataOffset)
        {
            int bytesPassed = 0;

            // For each possible entry, see if we match the mask
            // If we do, decode that, save it, and shuffle on
            for (int i = 0; i < potentialProperties.Length; i++)
            {
                // Check there's still data left to read

                // Check if this property is found in the mask
                if ((ContainsField & potentialProperties[i].GetMask()) != 0)
                {
                    if (dataOffset + bytesPassed >= data.Length)
                    {
                        // Out of data, can't be any more properties to go
                        // remember the mask and return
                        maskSpecial |= potentialProperties[i].GetMask();
                        return bytesPassed;
                    }

                    // Bingo, data Contains this property
                    TextProp prop = (TextProp)potentialProperties[i].Clone();
                    int val = 0;
                    if (prop.GetSize() == 2)
                    {
                        val = LittleEndian.GetShort(data, dataOffset + bytesPassed);
                    }
                    else if (prop.GetSize() == 4)
                    {
                        val = LittleEndian.GetInt(data, dataOffset + bytesPassed);
                    }
                    else if (prop.GetSize() == 0)
                    {
                        //remember "special" bits.
                        maskSpecial |= potentialProperties[i].GetMask();
                        continue;
                    }
                    prop.SetValue(val);
                    bytesPassed += prop.GetSize();
                    textPropList.Add(prop);
                }
            }

            // Return how many bytes were used
            return bytesPassed;
        }
Exemplo n.º 6
0
 /**
  * Clone, eg when you want to actually make use of one of these.
  */
 public virtual Object Clone()
 {
     TextProp tp = new TextProp(this.sizeOfDataBlock, this.maskInHeader, this.propName);
     return tp;
 }
Exemplo n.º 7
0
        /**
         * Clone, eg when you want to actually make use of one of these.
         */
        public virtual Object Clone()
        {
            TextProp tp = new TextProp(this.sizeOfDataBlock, this.maskInHeader, this.propName);

            return(tp);
        }