Ejemplo n.º 1
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);
                }
            }
        }
Ejemplo n.º 2
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);
        }