Exemplo n.º 1
0
        public SprmOperation Next()
        {
            SprmOperation op = new SprmOperation(_grpprl, _offset);

            _offset += op.Size;
            return(op);
        }
Exemplo n.º 2
0
        private SprmBuffer FindHuge(SprmBuffer buf, byte[] datastream)
        {
            byte[] grpprl = buf.ToByteArray();
            if (grpprl.Length == 8 && datastream != null) // then check for sprmPHugePapx
            {
                SprmOperation sprm = new SprmOperation(grpprl, 2);
                if ((sprm.Operation == 0x45 || sprm.Operation == 0x46)
                    && sprm.SizeCode == 3)
                {
                    int hugeGrpprlOffset = sprm.Operand;
                    if (hugeGrpprlOffset + 1 < datastream.Length)
                    {
                        int grpprlSize = LittleEndian.GetShort(datastream, hugeGrpprlOffset);
                        if (hugeGrpprlOffset + grpprlSize < datastream.Length)
                        {
                            byte[] hugeGrpprl = new byte[grpprlSize + 2];
                            // copy original istd into huge Grpprl
                            hugeGrpprl[0] = grpprl[0]; 
                            hugeGrpprl[1] = grpprl[1];
                            // copy Grpprl from dataStream
                            Array.Copy(datastream, hugeGrpprlOffset + 2, hugeGrpprl, 2,
                                             grpprlSize);

                            return new SprmBuffer(hugeGrpprl,2);
                        }
                    }
                }
            }
            return null;
        }
Exemplo n.º 3
0
        private static void handleTabs(ParagraphProperties pap, SprmOperation sprm)
        {
            byte[] grpprl  = sprm.Grpprl;
            int    offset  = sprm.GrpprlOffset;
            int    delSize = grpprl[offset++];

            int[]  tabPositions   = pap.GetRgdxaTab();
            byte[] tabDescriptors = pap.GetRgtbd();

            Hashtable tabMap = new Hashtable();

            for (int x = 0; x < tabPositions.Length; x++)
            {
                tabMap.Add(tabPositions[x], tabDescriptors[x]);
            }

            for (int x = 0; x < delSize; x++)
            {
                tabMap.Remove(LittleEndian.GetShort(grpprl, offset));
                offset += LittleEndianConsts.SHORT_SIZE;
            }

            int addSize = grpprl[offset++];
            int start   = offset;

            for (int x = 0; x < addSize; x++)
            {
                int  key = LittleEndian.GetShort(grpprl, offset);
                Byte val = grpprl[start + ((LittleEndianConsts.SHORT_SIZE * addSize) + x)];
                tabMap.Add(key, val);
                offset += LittleEndianConsts.SHORT_SIZE;
            }

            tabPositions   = new int[tabMap.Count];
            tabDescriptors = new byte[tabPositions.Length];
            ArrayList list = new ArrayList();

            IEnumerator keyIT = tabMap.Keys.GetEnumerator();

            while (keyIT.MoveNext())
            {
                list.Add(keyIT.Current);
            }
            list.Sort();

            for (int x = 0; x < tabPositions.Length; x++)
            {
                int key = (int)list[x];
                tabPositions[x]   = key;
                tabDescriptors[x] = (byte)tabMap[key];
            }

            pap.SetRgdxaTab(tabPositions);
            pap.SetRgtbd(tabDescriptors);
        }
Exemplo n.º 4
0
        internal int FindSprmOffset(short opcode)
        {
            SprmOperation sprmOperation = FindSprm(opcode);

            if (sprmOperation == null)
            {
                return(-1);
            }

            return(sprmOperation.GrpprlOffset);
        }
Exemplo n.º 5
0
        public static SectionProperties UncompressSEP(byte[] grpprl, int offset)
        {
            SectionProperties newProperties = new SectionProperties();

            SprmIterator sprmIt = new SprmIterator(grpprl, offset);

            while (sprmIt.HasNext())
            {
                SprmOperation sprm = (SprmOperation)sprmIt.Next();
                UncompressSEPOperation(newProperties, sprm);
            }

            return(newProperties);
        }
Exemplo n.º 6
0
        public SprmOperation FindSprm(short opcode)
        {
            int operation = SprmOperation.GetOperationFromOpcode(opcode);
            int type      = SprmOperation.GetTypeFromOpcode(opcode);

            SprmIterator si = new SprmIterator(_buf, 2);

            while (si.HasNext())
            {
                SprmOperation i = si.Next();
                if (i.Operation == operation && i.Type == type)
                {
                    return(i);
                }
            }
            return(null);
        }
Exemplo n.º 7
0
        public static CharacterProperties UncompressCHP(CharacterProperties parent,
                                                        byte[] grpprl,
                                                        int Offset)
        {
            CharacterProperties newProperties = null;

            newProperties = (CharacterProperties)parent.Clone();

            SprmIterator sprmIt = new SprmIterator(grpprl, Offset);

            while (sprmIt.HasNext())
            {
                SprmOperation sprm = sprmIt.Next();
                UncompressCHPOperation(parent, newProperties, sprm);
            }

            return(newProperties);
        }
Exemplo n.º 8
0
        public static TableProperties UncompressTAP(SprmBuffer sprmBuffer)
        {
            TableProperties tableProperties;

            SprmOperation sprmOperation = sprmBuffer.FindSprm(unchecked ((short)0xd608));

            if (sprmOperation != null)
            {
                byte[] grpprl = sprmOperation.Grpprl;
                int    offset = sprmOperation.GrpprlOffset;
                short  itcMac = grpprl[offset];
                tableProperties = new TableProperties(itcMac);
            }
            else
            {
                //logger.log(POILogger.WARN,
                //        "Some table rows didn't specify number of columns in SPRMs");
                tableProperties = new TableProperties((short)1);
            }

            for (SprmIterator iterator = sprmBuffer.Iterator(); iterator.HasNext();)
            {
                SprmOperation sprm = iterator.Next();

                /*
                 * TAPXs are actually PAPXs so we have to make sure we are only
                 * trying to uncompress the right type of sprm.
                 */
                if (sprm.Type == SprmOperation.TYPE_TAP)
                {
                    try
                    {
                        UncompressTAPOperation(tableProperties, sprm);
                    }
                    catch (IndexOutOfRangeException ex)
                    {
                        //logger.log(POILogger.ERROR, "Unable to apply ", sprm,
                        //        ": ", ex, ex);
                    }
                }
            }
            return(tableProperties);
        }
Exemplo n.º 9
0
        public static TableProperties UncompressTAP(byte[] grpprl,
                                                    int Offset)
        {
            TableProperties newProperties = new TableProperties();

            SprmIterator sprmIt = new SprmIterator(grpprl, Offset);

            while (sprmIt.HasNext())
            {
                SprmOperation sprm = sprmIt.Next();

                //TAPXs are actually PAPXs so we have to make sure we are only trying to
                //uncompress the right type of sprm.
                if (sprm.Type == SprmOperation.TYPE_TAP)
                {
                    UncompressTAPOperation(newProperties, sprm);
                }
            }

            return(newProperties);
        }
Exemplo n.º 10
0
        public static ParagraphProperties UncompressPAP(ParagraphProperties parent,
                                                        byte[] grpprl,
                                                        int Offset)
        {
            ParagraphProperties newProperties = null;

            newProperties = (ParagraphProperties)parent.Clone();

            SprmIterator sprmIt = new SprmIterator(grpprl, Offset);

            while (sprmIt.HasNext())
            {
                SprmOperation sprm = sprmIt.Next();

                // PAPXs can contain table sprms if the paragraph marks the end of a
                // table row
                if (sprm.Type == SprmOperation.TYPE_PAP)
                {
                    UncompressPAPOperation(newProperties, sprm);
                }
            }

            return(newProperties);
        }
Exemplo n.º 11
0
 public SprmOperation Next()
 {
     SprmOperation op = new SprmOperation(_grpprl, _offset);
     _offset += op.Size;
     return op;
 }
Exemplo n.º 12
0
        /**
         * Performs an operation on a ParagraphProperties object. Used to uncompress
         * from a papx.
         *
         * @param newPAP The ParagraphProperties object to perform the operation on.
         * @param operand The operand that defines the operation.
         * @param param The operation's parameter.
         * @param varParam The operation's variable length parameter.
         * @param grpprl The original papx.
         * @param offset The current offset in the papx.
         * @param spra A part of the sprm that defined this operation.
         */
        static void UncompressPAPOperation(ParagraphProperties newPAP, SprmOperation sprm)
        {
            switch (sprm.Operation)
            {
                case 0:
                    newPAP.SetIstd(sprm.Operand);
                    break;
                case 0x1:

                    // Used only for piece table grpprl's not for PAPX
                    //        int istdFirst = LittleEndian.Getshort (varParam, 2);
                    //        int istdLast = LittleEndian.Getshort (varParam, 4);
                    //        if ((newPAP.GetIstd () > istdFirst) || (newPAP.GetIstd () <= istdLast))
                    //        {
                    //          permuteIstd (newPAP, varParam, opSize);
                    //        }
                    break;
                case 0x2:
                    if (newPAP.GetIstd() <= 9 || newPAP.GetIstd() >= 1)
                    {
                        byte paramTmp = (byte)sprm.Operand;
                        newPAP.SetIstd(newPAP.GetIstd() + paramTmp);
                        newPAP.SetLvl((byte)(newPAP.GetLvl() + paramTmp));

                        if (((paramTmp >> 7) & 0x01) == 1)
                        {
                            newPAP.SetIstd(Math.Max(newPAP.GetIstd(), 1));
                        }
                        else
                        {
                            newPAP.SetIstd(Math.Min(newPAP.GetIstd(), 9));
                        }

                    }
                    break;
                case 0x3:
                    // Physical justification of the paragraph
                    newPAP.SetJc((byte)sprm.Operand);
                    break;
                case 0x4:
                    newPAP.SetFSideBySide(sprm.Operand!=0);
                    break;
                case 0x5:
                    newPAP.SetFKeep(sprm.Operand!=0);
                    break;
                case 0x6:
                    newPAP.SetFKeepFollow(sprm.Operand!=0);
                    break;
                case 0x7:
                    newPAP.SetFPageBreakBefore(sprm.Operand!=0);
                    break;
                case 0x8:
                    newPAP.SetBrcl((byte)sprm.Operand);
                    break;
                case 0x9:
                    newPAP.SetBrcp((byte)sprm.Operand);
                    break;
                case 0xa:
                    newPAP.SetIlvl((byte)sprm.Operand);
                    break;
                case 0xb:
                    newPAP.SetIlfo(sprm.Operand);
                    break;
                case 0xc:
                    newPAP.SetFNoLnn(sprm.Operand!=0);
                    break;
                case 0xd:
                    /**handle tabs . variable parameter. seperate Processing needed*/
                    handleTabs(newPAP, sprm);
                    break;
                case 0xe:
                    newPAP.SetDxaRight(sprm.Operand);
                    break;
                case 0xf:
                    newPAP.SetDxaLeft(sprm.Operand);
                    break;
                case 0x10:

                    // sprmPNest is only stored in grpprls linked to a piece table.
                    newPAP.SetDxaLeft(newPAP.GetDxaLeft() + sprm.Operand);
                    newPAP.SetDxaLeft(Math.Max(0, newPAP.GetDxaLeft()));
                    break;
                case 0x11:
                    newPAP.SetDxaLeft1(sprm.Operand);
                    break;
                case 0x12:
                    newPAP.SetLspd(new LineSpacingDescriptor(sprm.Grpprl, sprm.GrpprlOffset));
                    break;
                case 0x13:
                    newPAP.SetDyaBefore(sprm.Operand);
                    break;
                case 0x14:
                    newPAP.SetDyaAfter(sprm.Operand);
                    break;
                case 0x15:
                    // fast saved only
                    //ApplySprmPChgTabs (newPAP, varParam, opSize);
                    break;
                case 0x16:
                    newPAP.SetFInTable(sprm.Operand!=0);
                    break;
                case 0x17:
                    newPAP.SetFTtp(sprm.Operand!=0);
                    break;
                case 0x18:
                    newPAP.SetDxaAbs(sprm.Operand);
                    break;
                case 0x19:
                    newPAP.SetDyaAbs(sprm.Operand);
                    break;
                case 0x1a:
                    newPAP.SetDxaWidth(sprm.Operand);
                    break;
                case 0x1b:
                    byte param = (byte)sprm.Operand;
                    /** @todo handle paragraph postioning*/
                    byte pcVert = (byte)((param & 0x0c) >> 2);
                    byte pcHorz = (byte)(param & 0x03);
                    if (pcVert != 3)
                    {
                        newPAP.SetPcVert(pcVert);
                    }
                    if (pcHorz != 3)
                    {
                        newPAP.SetPcHorz(pcHorz);
                    }
                    break;

                // BrcXXX1 is older Version. Brc is used
                case 0x1c:

                    //newPAP.SetBrcTop1((short)param);
                    break;
                case 0x1d:

                    //newPAP.SetBrcLeft1((short)param);
                    break;
                case 0x1e:

                    //newPAP.SetBrcBottom1((short)param);
                    break;
                case 0x1f:

                    //newPAP.SetBrcRight1((short)param);
                    break;
                case 0x20:

                    //newPAP.SetBrcBetween1((short)param);
                    break;
                case 0x21:

                    //newPAP.SetBrcBar1((byte)param);
                    break;
                case 0x22:
                    newPAP.SetDxaFromText(sprm.Operand);
                    break;
                case 0x23:
                    newPAP.SetWr((byte)sprm.Operand);
                    break;
                case 0x24:
                    newPAP.SetBrcTop(new BorderCode(sprm.Grpprl, sprm.GrpprlOffset));
                    break;
                case 0x25:
                    newPAP.SetBrcLeft(new BorderCode(sprm.Grpprl, sprm.GrpprlOffset));
                    break;
                case 0x26:
                    newPAP.SetBrcBottom(new BorderCode(sprm.Grpprl, sprm.GrpprlOffset));
                    break;
                case 0x27:
                    newPAP.SetBrcRight(new BorderCode(sprm.Grpprl, sprm.GrpprlOffset));
                    break;
                case 0x28:
                    newPAP.SetBrcBetween(new BorderCode(sprm.Grpprl, sprm.GrpprlOffset));
                    break;
                case 0x29:
                    newPAP.SetBrcBar(new BorderCode(sprm.Grpprl, sprm.GrpprlOffset));
                    break;
                case 0x2a:
                    newPAP.SetFNoAutoHyph(sprm.Operand!=0);
                    break;
                case 0x2b:
                    newPAP.SetDyaHeight(sprm.Operand);
                    break;
                case 0x2c:
                    newPAP.SetDcs(new DropCapSpecifier((short)sprm.Operand));
                    break;
                case 0x2d:
                    newPAP.SetShd(new ShadingDescriptor((short)sprm.Operand));
                    break;
                case 0x2e:
                    newPAP.SetDyaFromText(sprm.Operand);
                    break;
                case 0x2f:
                    newPAP.SetDxaFromText(sprm.Operand);
                    break;
                case 0x30:
                    newPAP.SetFLocked(sprm.Operand!=0);
                    break;
                case 0x31:
                    newPAP.SetFWidowControl(sprm.Operand!=0);
                    break;
                case 0x32:

                    //undocumented
                    break;
                case 0x33:
                    newPAP.SetFKinsoku(sprm.Operand!=0);
                    break;
                case 0x34:
                    newPAP.SetFWordWrap(sprm.Operand!=0);
                    break;
                case 0x35:
                    newPAP.SetFOverflowPunct(sprm.Operand!=0);
                    break;
                case 0x36:
                    newPAP.SetFTopLinePunct(sprm.Operand!=0);
                    break;
                case 0x37:
                    newPAP.SetFAutoSpaceDE(sprm.Operand!=0);
                    break;
                case 0x38:
                    newPAP.SetFAutoSpaceDN(sprm.Operand!=0);
                    break;
                case 0x39:
                    newPAP.SetWAlignFont(sprm.Operand);
                    break;
                case 0x3a:
                    newPAP.SetFontAlign((short)sprm.Operand);
                    break;
                case 0x3b:

                    //obsolete
                    break;
                case 0x3e:
                    byte[] buf = new byte[sprm.Size - 3];
                    Array.Copy(buf, 0, sprm.Grpprl, sprm.GrpprlOffset,
                                     buf.Length);
                    newPAP.SetAnld(buf);
                    break;
                case 0x3f:
                    //don't really need this. spec is confusing regarding this
                    //sprm
                        byte[] varParam = sprm.Grpprl;
                        int offset = sprm.GrpprlOffset;
                        newPAP.SetFPropRMark(varParam[offset]!=0);
                        newPAP.SetIbstPropRMark(LittleEndian.GetShort(varParam, offset + 1));
                        newPAP.SetDttmPropRMark(new DateAndTime(varParam, offset + 3));

                    break;
                case 0x40:
                    // This condition commented out, as Word seems to set outline levels even for 
                    //  paragraph with other styles than Heading 1..9, even though specification 
                    //  does not say so. See bug 49820 for discussion.
                    //if (newPAP.GetIstd () < 1 && newPAP.GetIstd () > 9)
                    //{
                        newPAP.SetLvl((byte)sprm.Operand);
                    //}
                    break;
                case 0x41:

                    // undocumented
                    break;
                case 0x43:

                    //pap.fNumRMIns
                    newPAP.SetFNumRMIns(sprm.Operand!=0);
                    break;
                case 0x44:

                    //undocumented
                    break;
                case 0x45:
                    if (sprm.SizeCode == 6)
                    {
                        byte[] buf1 = new byte[sprm.Size - 3];
                        Array.Copy(buf1, 0, sprm.Grpprl, sprm.GrpprlOffset, buf1.Length);
                        newPAP.SetNumrm(buf1);
                    }
                    else
                    {
                        /**@todo handle large PAPX from data stream*/
                    }
                    break;

                case 0x47:
                    newPAP.SetFUsePgsuSettings(sprm.Operand!=0);
                    break;
                case 0x48:
                    newPAP.SetFAdjustRight(sprm.Operand!=0);
                    break;
                case 0x49:
                    // sprmPItap -- 0x6649
                    newPAP.SetItap(sprm.Operand);
                    break;
                case 0x4a:
                    // sprmPDtap -- 0x664a
                    newPAP.SetItap((byte)(newPAP.GetItap() + sprm.Operand));
                    break;
                case 0x4b:
                    // sprmPFInnerTableCell -- 0x244b
                    newPAP.SetFInnerTableCell(sprm.Operand!=0);
                    break;
                case 0x4c:
                    // sprmPFInnerTtp -- 0x244c
                    newPAP.SetFTtpEmbedded(sprm.Operand!=0);
                    break;
                case 0x61:
                    // sprmPJc 
                    newPAP.SetJustificationLogical((byte)sprm.Operand);
                    break;
                default:
                    break;
            }
        }
Exemplo n.º 13
0
        private static void handleTabs(ParagraphProperties pap, SprmOperation sprm)
        {
            byte[] grpprl = sprm.Grpprl;
            int offset = sprm.GrpprlOffset;
            int delSize = grpprl[offset++];
            int[] tabPositions = pap.GetRgdxaTab();
            byte[] tabDescriptors = pap.GetRgtbd();

            Hashtable tabMap = new Hashtable();
            for (int x = 0; x < tabPositions.Length; x++)
            {
                tabMap.Add(tabPositions[x], tabDescriptors[x]);
            }

            for (int x = 0; x < delSize; x++)
            {
                tabMap.Remove(LittleEndian.GetShort(grpprl, offset));
                offset += LittleEndianConsts.SHORT_SIZE;
            }

            int addSize = grpprl[offset++];
            int start = offset;
            for (int x = 0; x < addSize; x++)
            {
                int key = LittleEndian.GetShort(grpprl, offset);
                Byte val = grpprl[start + ((LittleEndianConsts.SHORT_SIZE * addSize) + x)];
                tabMap.Add(key, val);
                offset += LittleEndianConsts.SHORT_SIZE;
            }

            tabPositions = new int[tabMap.Count];
            tabDescriptors = new byte[tabPositions.Length];
            ArrayList list = new ArrayList();

            IEnumerator keyIT = tabMap.Keys.GetEnumerator();
            while (keyIT.MoveNext())
            {
                list.Add(keyIT.Current);
            }
            list.Sort();

            for (int x = 0; x < tabPositions.Length; x++)
            {
                int key = (int)list[x];
                tabPositions[x] = key;
                tabDescriptors[x] = (byte)tabMap[key];
            }

            pap.SetRgdxaTab(tabPositions);
            pap.SetRgtbd(tabDescriptors);
        }
Exemplo n.º 14
0
        /**
         * Used in decompression of a sepx. This performs an operation defined by
         * a single sprm.
         *
         * @param newSEP The SectionProperty to perfrom the operation on.
         * @param operand The operation to perform.
         * @param param The operation's parameter.
         * @param varParam The operation variable length parameter.
         */
        static void UncompressSEPOperation(SectionProperties newSEP, SprmOperation sprm)
        {
            switch (sprm.Operation)
            {
            case 0:
                newSEP.SetCnsPgn((byte)sprm.Operand);
                break;

            case 0x1:
                newSEP.SetIHeadingPgn((byte)sprm.Operand);
                break;

            case 0x2:
                byte[] buf = new byte[sprm.Size - 3];
                Array.Copy(sprm.Grpprl, sprm.GrpprlOffset, buf, 0, buf.Length);
                newSEP.SetOlstAnm(buf);
                break;

            case 0x3:
                //not quite sure
                break;

            case 0x4:
                //not quite sure
                break;

            case 0x5:
                newSEP.SetFEvenlySpaced(GetFlag(sprm.Operand));
                break;

            case 0x6:
                newSEP.SetFUnlocked(GetFlag(sprm.Operand));
                break;

            case 0x7:
                newSEP.SetDmBinFirst((short)sprm.Operand);
                break;

            case 0x8:
                newSEP.SetDmBinOther((short)sprm.Operand);
                break;

            case 0x9:
                newSEP.SetBkc((byte)sprm.Operand);
                break;

            case 0xa:
                newSEP.SetFTitlePage(GetFlag(sprm.Operand));
                break;

            case 0xb:
                newSEP.SetCcolM1((short)sprm.Operand);
                break;

            case 0xc:
                newSEP.SetDxaColumns(sprm.Operand);
                break;

            case 0xd:
                newSEP.SetFAutoPgn(GetFlag(sprm.Operand));
                break;

            case 0xe:
                newSEP.SetNfcPgn((byte)sprm.Operand);
                break;

            case 0xf:
                newSEP.SetDyaPgn((short)sprm.Operand);
                break;

            case 0x10:
                newSEP.SetDxaPgn((short)sprm.Operand);
                break;

            case 0x11:
                newSEP.SetFPgnRestart(GetFlag(sprm.Operand));
                break;

            case 0x12:
                newSEP.SetFEndNote(GetFlag(sprm.Operand));
                break;

            case 0x13:
                newSEP.SetLnc((byte)sprm.Operand);
                break;

            case 0x14:
                newSEP.SetGrpfIhdt((byte)sprm.Operand);
                break;

            case 0x15:
                newSEP.SetNLnnMod((short)sprm.Operand);
                break;

            case 0x16:
                newSEP.SetDxaLnn(sprm.Operand);
                break;

            case 0x17:
                newSEP.SetDyaHdrTop(sprm.Operand);
                break;

            case 0x18:
                newSEP.SetDyaHdrBottom(sprm.Operand);
                break;

            case 0x19:
                newSEP.SetFLBetween(GetFlag(sprm.Operand));
                break;

            case 0x1a:
                newSEP.SetVjc((byte)sprm.Operand);
                break;

            case 0x1b:
                newSEP.SetLnnMin((short)sprm.Operand);
                break;

            case 0x1c:
                newSEP.SetPgnStart((short)sprm.Operand);
                break;

            case 0x1d:
                newSEP.SetDmOrientPage(sprm.Operand != 0);
                break;

            case 0x1e:

                //nothing
                break;

            case 0x1f:
                newSEP.SetXaPage(sprm.Operand);
                break;

            case 0x20:
                newSEP.SetYaPage(sprm.Operand);
                break;

            case 0x21:
                newSEP.SetDxaLeft(sprm.Operand);
                break;

            case 0x22:
                newSEP.SetDxaRight(sprm.Operand);
                break;

            case 0x23:
                newSEP.SetDyaTop(sprm.Operand);
                break;

            case 0x24:
                newSEP.SetDyaBottom(sprm.Operand);
                break;

            case 0x25:
                newSEP.SetDzaGutter(sprm.Operand);
                break;

            case 0x26:
                newSEP.SetDmPaperReq((short)sprm.Operand);
                break;

            case 0x27:
                newSEP.SetFPropMark(GetFlag(sprm.Operand));
                break;

            case 0x28:
                break;

            case 0x29:
                break;

            case 0x2a:
                break;

            case 0x2b:
                newSEP.SetBrcTop(new BorderCode(sprm.Grpprl, sprm.GrpprlOffset));
                break;

            case 0x2c:
                newSEP.SetBrcLeft(new BorderCode(sprm.Grpprl, sprm.GrpprlOffset));
                break;

            case 0x2d:
                newSEP.SetBrcBottom(new BorderCode(sprm.Grpprl, sprm.GrpprlOffset));
                break;

            case 0x2e:
                newSEP.SetBrcRight(new BorderCode(sprm.Grpprl, sprm.GrpprlOffset));
                break;

            case 0x2f:
                newSEP.SetPgbProp(sprm.Operand);
                break;

            case 0x30:
                newSEP.SetDxtCharSpace(sprm.Operand);
                break;

            case 0x31:
                newSEP.SetDyaLinePitch(sprm.Operand);
                break;

            case 0x33:
                newSEP.SetWTextFlow((short)sprm.Operand);
                break;

            default:
                break;
            }
        }
        /**
         * Used in decompression of a chpx. This performs an operation defined by
         * a single sprm.
         *
         * @param oldCHP The base CharacterProperties.
         * @param newCHP The current CharacterProperties.
         * @param operand The operand defined by the sprm (See Word file format spec)
         * @param param The parameter defined by the sprm (See Word file format spec)
         * @param varParam The variable length parameter defined by the sprm. (See
         *        Word file format spec)
         * @param grpprl The entire chpx that this operation is a part of.
         * @param offset The offset in the grpprl of the next sprm
         * @param styleSheet The StyleSheet for this document.
         */
        static void UncompressCHPOperation(CharacterProperties oldCHP,
                                            CharacterProperties newCHP,
                                            SprmOperation sprm)
        {

            switch (sprm.Operation)
            {
                case 0:
                    newCHP.SetFRMarkDel(GetFlag(sprm.Operand));
                    break;
                case 0x1:
                    newCHP.SetFRMark(GetFlag(sprm.Operand));
                    break;
                case 0x2:
                    newCHP.SetFFldVanish(GetFlag(sprm.Operand));
                    break;
                case 0x3:
                    newCHP.SetFcPic(sprm.Operand);
                    newCHP.SetFSpec(true);
                    break;
                case 0x4:
                    newCHP.SetIbstRMark((short)sprm.Operand);
                    break;
                case 0x5:
                    newCHP.SetDttmRMark(new DateAndTime(sprm.Grpprl, sprm.GrpprlOffset));
                    break;
                case 0x6:
                    newCHP.SetFData(GetFlag(sprm.Operand));
                    break;
                case 0x7:
                    //don't care about this
                    break;
                case 0x8:
                    //short chsDiff = (short)((param & 0xff0000) >>> 16);
                    int operand = sprm.Operand;
                    short chsDiff = (short)(operand & 0x0000ff);
                    newCHP.SetFChsDiff(GetFlag(chsDiff));
                    newCHP.SetChse((short)(operand & 0xffff00));
                    break;
                case 0x9:
                    newCHP.SetFSpec(true);
                    newCHP.SetFtcSym(LittleEndian.GetShort(sprm.Grpprl, sprm.GrpprlOffset));
                    newCHP.SetXchSym(LittleEndian.GetShort(sprm.Grpprl, sprm.GrpprlOffset + 2));
                    break;
                case 0xa:
                    newCHP.SetFOle2(GetFlag(sprm.Operand));
                    break;
                case 0xb:

                    // Obsolete
                    break;
                case 0xc:
                    newCHP.SetIcoHighlight((byte)sprm.Operand);
                    newCHP.SetFHighlight(GetFlag(sprm.Operand));
                    break;
                case 0xd:

                    //	undocumented
                    break;
                case 0xe:
                    newCHP.SetFcObj(sprm.Operand);
                    break;
                case 0xf:

                    // undocumented
                    break;
                case 0x10:

                    // undocumented
                    break;

                // undocumented till 0x30

                case 0x11:
                    // sprmCFWebHidden
                    break;
                case 0x12:
                    break;
                case 0x13:
                    break;
                case 0x14:
                    break;
                case 0x15:
                    // sprmCRsidProp
                    break;
                case 0x16:
                    // sprmCRsidText
                    break;
                case 0x17:
                    // sprmCRsidRMDel
                    break;
                case 0x18:
                    // sprmCFSpecVanish
                    break;
                case 0x19:
                    break;
                case 0x1a:
                    // sprmCFMathPr
                    break;
                case 0x1b:
                    break;
                case 0x1c:
                    break;
                case 0x1d:
                    break;
                case 0x1e:
                    break;
                case 0x1f:
                    break;
                case 0x20:
                    break;
                case 0x21:
                    break;
                case 0x22:
                    break;
                case 0x23:
                    break;
                case 0x24:
                    break;
                case 0x25:
                    break;
                case 0x26:
                    break;
                case 0x27:
                    break;
                case 0x28:
                    break;
                case 0x29:
                    break;
                case 0x2a:
                    break;
                case 0x2b:
                    break;
                case 0x2c:
                    break;
                case 0x2d:
                    break;
                case 0x2e:
                    break;
                case 0x2f:
                    break;
                case 0x30:
                    newCHP.SetIstd(sprm.Operand);
                    break;
                case 0x31:

                    //permutation vector for fast saves, who cares!
                    break;
                case 0x32:
                    newCHP.SetFBold(false);
                    newCHP.SetFItalic(false);
                    newCHP.SetFOutline(false);
                    newCHP.SetFStrike(false);
                    newCHP.SetFShadow(false);
                    newCHP.SetFSmallCaps(false);
                    newCHP.SetFCaps(false);
                    newCHP.SetFVanish(false);
                    newCHP.SetKul((byte)0);
                    newCHP.SetIco((byte)0);
                    break;
                case 0x33:
                    // preserve the fSpec Setting from the original CHP
                    bool fSpec = newCHP.IsFSpec();
                    newCHP = (CharacterProperties)oldCHP.Clone();
                    newCHP.SetFSpec(fSpec);

                    return;
                case 0x34:
                    // sprmCKcd
                    break;
                case 0x35:
                    newCHP.SetFBold(GetCHPFlag((byte)sprm.Operand, oldCHP.IsFBold()));
                    break;
                case 0x36:
                    newCHP.SetFItalic(GetCHPFlag((byte)sprm.Operand, oldCHP.IsFItalic()));
                    break;
                case 0x37:
                    newCHP.SetFStrike(GetCHPFlag((byte)sprm.Operand, oldCHP.IsFStrike()));
                    break;
                case 0x38:
                    newCHP.SetFOutline(GetCHPFlag((byte)sprm.Operand, oldCHP.IsFOutline()));
                    break;
                case 0x39:
                    newCHP.SetFShadow(GetCHPFlag((byte)sprm.Operand, oldCHP.IsFShadow()));
                    break;
                case 0x3a:
                    newCHP.SetFSmallCaps(GetCHPFlag((byte)sprm.Operand, oldCHP.IsFSmallCaps()));
                    break;
                case 0x3b:
                    newCHP.SetFCaps(GetCHPFlag((byte)sprm.Operand, oldCHP.IsFCaps()));
                    break;
                case 0x3c:
                    newCHP.SetFVanish(GetCHPFlag((byte)sprm.Operand, oldCHP.IsFVanish()));
                    break;
                case 0x3d:
                    newCHP.SetFtcAscii((short)sprm.Operand);
                    break;
                case 0x3e:
                    newCHP.SetKul((byte)sprm.Operand);
                    break;
                case 0x3f:
                    operand = sprm.Operand;
                    int hps = operand & 0xff;
                    if (hps != 0)
                    {
                        newCHP.SetHps(hps);
                    }

                    //byte cInc = (byte)(((byte)(param & 0xfe00) >>> 4) >> 1);
                    byte cInc = (byte)((operand & 0xff00) >> 8);
                    cInc = (byte)(cInc >> 1);
                    if (cInc != 0)
                    {
                        newCHP.SetHps(Math.Max(newCHP.GetHps() + (cInc * 2), 2));
                    }

                    //byte hpsPos = (byte)((param & 0xff0000) >>> 8);
                    byte hpsPos = (byte)((operand & 0xff0000) >> 16);
                    if (hpsPos != 0x80)
                    {
                        newCHP.SetHpsPos(hpsPos);
                    }
                    bool fAdjust = (operand & 0x0100) > 0;
                    if (fAdjust && hpsPos != 128 && hpsPos != 0 && oldCHP.GetHpsPos() == 0)
                    {
                        newCHP.SetHps(Math.Max(newCHP.GetHps() + (-2), 2));
                    }
                    if (fAdjust && hpsPos == 0 && oldCHP.GetHpsPos() != 0)
                    {
                        newCHP.SetHps(Math.Max(newCHP.GetHps() + 2, 2));
                    }
                    break;
                case 0x40:
                    newCHP.SetDxaSpace(sprm.Operand);
                    break;
                case 0x41:
                    newCHP.SetLidDefault((short)sprm.Operand);
                    break;
                case 0x42:
                    newCHP.SetIco((byte)sprm.Operand);
                    break;
                case 0x43:
                    newCHP.SetHps(sprm.Operand);
                    break;
                case 0x44:
                    byte hpsLvl = (byte)sprm.Operand;
                    newCHP.SetHps(Math.Max(newCHP.GetHps() + (hpsLvl * 2), 2));
                    break;
                case 0x45:
                    newCHP.SetHpsPos((short)sprm.Operand);
                    break;
                case 0x46:
                    if (sprm.Operand != 0)
                    {
                        if (oldCHP.GetHpsPos() == 0)
                        {
                            newCHP.SetHps(Math.Max(newCHP.GetHps() + (-2), 2));
                        }
                    }
                    else
                    {
                        if (oldCHP.GetHpsPos() != 0)
                        {
                            newCHP.SetHps(Math.Max(newCHP.GetHps() + 2, 2));
                        }
                    }
                    break;
                case 0x47:
                    /*CharacterProperties genCHP = new CharacterProperties ();
                    genCHP.SetFtcAscii (4);
                    genCHP = (CharacterProperties) unCompressProperty (varParam, genCHP,
                      styleSheet);
                    CharacterProperties styleCHP = styleSheet.GetStyleDescription (oldCHP.
                      GetBaseIstd ()).GetCHP ();
                    if (genCHP.IsFBold () == newCHP.IsFBold ())
                    {
                      newCHP.SetFBold (styleCHP.IsFBold ());
                    }
                    if (genCHP.IsFItalic () == newCHP.IsFItalic ())
                    {
                      newCHP.SetFItalic (styleCHP.IsFItalic ());
                    }
                    if (genCHP.IsFSmallCaps () == newCHP.IsFSmallCaps ())
                    {
                      newCHP.SetFSmallCaps (styleCHP.IsFSmallCaps ());
                    }
                    if (genCHP.IsFVanish () == newCHP.IsFVanish ())
                    {
                      newCHP.SetFVanish (styleCHP.IsFVanish ());
                    }
                    if (genCHP.IsFStrike () == newCHP.IsFStrike ())
                    {
                      newCHP.SetFStrike (styleCHP.IsFStrike ());
                    }
                    if (genCHP.IsFCaps () == newCHP.IsFCaps ())
                    {
                      newCHP.SetFCaps (styleCHP.IsFCaps ());
                    }
                    if (genCHP.GetFtcAscii () == newCHP.GetFtcAscii ())
                    {
                      newCHP.SetFtcAscii (styleCHP.GetFtcAscii ());
                    }
                    if (genCHP.GetFtcFE () == newCHP.GetFtcFE ())
                    {
                      newCHP.SetFtcFE (styleCHP.GetFtcFE ());
                    }
                    if (genCHP.GetFtcOther () == newCHP.GetFtcOther ())
                    {
                      newCHP.SetFtcOther (styleCHP.GetFtcOther ());
                    }
                    if (genCHP.GetHps () == newCHP.GetHps ())
                    {
                      newCHP.SetHps (styleCHP.GetHps ());
                    }
                    if (genCHP.GetHpsPos () == newCHP.GetHpsPos ())
                    {
                      newCHP.SetHpsPos (styleCHP.GetHpsPos ());
                    }
                    if (genCHP.GetKul () == newCHP.GetKul ())
                    {
                      newCHP.SetKul (styleCHP.GetKul ());
                    }
                    if (genCHP.GetDxaSpace () == newCHP.GetDxaSpace ())
                    {
                      newCHP.SetDxaSpace (styleCHP.GetDxaSpace ());
                    }
                    if (genCHP.GetIco () == newCHP.GetIco ())
                    {
                      newCHP.SetIco (styleCHP.GetIco ());
                    }
                    if (genCHP.GetLidDefault () == newCHP.GetLidDefault ())
                    {
                      newCHP.SetLidDefault (styleCHP.GetLidDefault ());
                    }
                    if (genCHP.GetLidFE () == newCHP.GetLidFE ())
                    {
                      newCHP.SetLidFE (styleCHP.GetLidFE ());
                    }*/
                    break;
                case 0x48:
                    newCHP.SetIss((byte)sprm.Operand);
                    break;
                case 0x49:
                    newCHP.SetHps(LittleEndian.GetShort(sprm.Grpprl, sprm.GrpprlOffset));
                    break;
                case 0x4a:
                    int increment = LittleEndian.GetShort(sprm.Grpprl, sprm.GrpprlOffset);
                    newCHP.SetHps(Math.Max(newCHP.GetHps() + increment, 8));
                    break;
                case 0x4b:
                    newCHP.SetHpsKern(sprm.Operand);
                    break;
                case 0x4c:
                    //        unCompressCHPOperation (oldCHP, newCHP, 0x47, param, varParam,
                    //                                styleSheet, opSize);
                    break;
                case 0x4d:
                    float percentage = sprm.Operand / 100.0f;
                    int add = (int)(percentage * newCHP.GetHps());
                    newCHP.SetHps(newCHP.GetHps() + add);
                    break;
                case 0x4e:
                    newCHP.SetYsr((byte)sprm.Operand);
                    break;
                case 0x4f:
                    newCHP.SetFtcAscii((short)sprm.Operand);
                    break;
                case 0x50:
                    newCHP.SetFtcFE((short)sprm.Operand);
                    break;
                case 0x51:
                    newCHP.SetFtcOther((short)sprm.Operand);
                    break;
                case 0x52:
                    // sprmCCharScale
                    break;
                case 0x53:
                    newCHP.SetFDStrike(GetFlag(sprm.Operand));
                    break;
                case 0x54:
                    newCHP.SetFImprint(GetFlag(sprm.Operand));
                    break;
                case 0x55:
                    newCHP.SetFSpec(GetFlag(sprm.Operand));
                    break;
                case 0x56:
                    newCHP.SetFObj(GetFlag(sprm.Operand));
                    break;
                case 0x57:
                    byte[] buf = sprm.Grpprl;
                    int offset = sprm.GrpprlOffset;
                    newCHP.SetFPropMark(buf[offset]);
                    newCHP.SetIbstPropRMark(LittleEndian.GetShort(buf, offset + 1));
                    newCHP.SetDttmPropRMark(new DateAndTime(buf, offset + 3));
                    break;
                case 0x58:
                    newCHP.SetFEmboss(GetFlag(sprm.Operand));
                    break;
                case 0x59:
                    newCHP.SetSfxtText((byte)sprm.Operand);
                    break;
                case 0x5a:
                    // sprmCFBiDi
                    break;
                case 0x5b:
                    break;
                case 0x5c:
                    // sprmCFBoldBi
                    break;
                case 0x5d:
                    // sprmCFItalicBi
                    break;
                case 0x5e:
                    // sprmCFtcBi
                    break;
                case 0x5f:
                    // sprmCLidBi 
                    break;
                case 0x60:
                    // sprmCIcoBi
                    break;
                case 0x61:
                    // sprmCHpsBi
                    break;
                case 0x62:
                    byte[] xstDispFldRMark = new byte[32];
                    buf = sprm.Grpprl;
                    offset = sprm.GrpprlOffset;
                    newCHP.SetFDispFldRMark(buf[offset]);
                    newCHP.SetIbstDispFldRMark(LittleEndian.GetShort(buf, offset + 1));
                    newCHP.SetDttmDispFldRMark(new DateAndTime(buf, offset + 3));
                    Array.Copy(buf, offset + 7, xstDispFldRMark, 0, 32);
                    newCHP.SetXstDispFldRMark(xstDispFldRMark);
                    break;
                case 0x63:
                    newCHP.SetIbstRMarkDel((short)sprm.Operand);
                    break;
                case 0x64:
                    newCHP.SetDttmRMarkDel(new DateAndTime(sprm.Grpprl, sprm.GrpprlOffset));
                    break;
                case 0x65:
                    newCHP.SetBrc(new BorderCode(sprm.Grpprl, sprm.GrpprlOffset));
                    break;
                case 0x66:
                    newCHP.SetShd(new ShadingDescriptor(sprm.Grpprl, sprm.GrpprlOffset));
                    break;
                case 0x67:
                    // Obsolete
                    break;
                case 0x68:
                    //  sprmCFUsePgsuSettings
                    break;
                case 0x69:
                    break;
                case 0x6a:
                    break;
                case 0x6b:
                    break;
                case 0x6c:
                    break;
                case 0x6d:
                    newCHP.SetLidDefault((short)sprm.Operand);
                    break;
                case 0x6e:
                    newCHP.SetLidFE((short)sprm.Operand);
                    break;
                case 0x6f:
                    newCHP.SetIdctHint((byte)sprm.Operand);
                    break;
                case 0x70:
                    newCHP.SetIco24(sprm.Operand);
                    break;
                case 0x71:
                    // sprmCShd
                    break;
                case 0x72:
                    // sprmCBrc
                    break;
                case 0x73:
                    // sprmCRgLid0
                    break;
                case 0x74:
                    // sprmCRgLid1
                    break;
            }
        }
Exemplo n.º 16
0
        /**
         * Used in decompression of a sepx. This performs an operation defined by
         * a single sprm.
         *
         * @param newSEP The SectionProperty to perfrom the operation on.
         * @param operand The operation to perform.
         * @param param The operation's parameter.
         * @param varParam The operation variable length parameter.
         */
        static void UncompressSEPOperation(SectionProperties newSEP, SprmOperation sprm)
        {
            switch (sprm.Operation)
            {
                case 0:
                    newSEP.SetCnsPgn((byte)sprm.Operand);
                    break;
                case 0x1:
                    newSEP.SetIHeadingPgn((byte)sprm.Operand);
                    break;
                case 0x2:
                    byte[] buf = new byte[sprm.Size - 3];
                    Array.Copy(sprm.Grpprl, sprm.GrpprlOffset, buf, 0, buf.Length);
                    newSEP.SetOlstAnm(buf);
                    break;
                case 0x3:
                    //not quite sure
                    break;
                case 0x4:
                    //not quite sure
                    break;
                case 0x5:
                    newSEP.SetFEvenlySpaced(GetFlag(sprm.Operand));
                    break;
                case 0x6:
                    newSEP.SetFUnlocked(GetFlag(sprm.Operand));
                    break;
                case 0x7:
                    newSEP.SetDmBinFirst((short)sprm.Operand);
                    break;
                case 0x8:
                    newSEP.SetDmBinOther((short)sprm.Operand);
                    break;
                case 0x9:
                    newSEP.SetBkc((byte)sprm.Operand);
                    break;
                case 0xa:
                    newSEP.SetFTitlePage(GetFlag(sprm.Operand));
                    break;
                case 0xb:
                    newSEP.SetCcolM1((short)sprm.Operand);
                    break;
                case 0xc:
                    newSEP.SetDxaColumns(sprm.Operand);
                    break;
                case 0xd:
                    newSEP.SetFAutoPgn(GetFlag(sprm.Operand));
                    break;
                case 0xe:
                    newSEP.SetNfcPgn((byte)sprm.Operand);
                    break;
                case 0xf:
                    newSEP.SetDyaPgn((short)sprm.Operand);
                    break;
                case 0x10:
                    newSEP.SetDxaPgn((short)sprm.Operand);
                    break;
                case 0x11:
                    newSEP.SetFPgnRestart(GetFlag(sprm.Operand));
                    break;
                case 0x12:
                    newSEP.SetFEndNote(GetFlag(sprm.Operand));
                    break;
                case 0x13:
                    newSEP.SetLnc((byte)sprm.Operand);
                    break;
                case 0x14:
                    newSEP.SetGrpfIhdt((byte)sprm.Operand);
                    break;
                case 0x15:
                    newSEP.SetNLnnMod((short)sprm.Operand);
                    break;
                case 0x16:
                    newSEP.SetDxaLnn(sprm.Operand);
                    break;
                case 0x17:
                    newSEP.SetDyaHdrTop(sprm.Operand);
                    break;
                case 0x18:
                    newSEP.SetDyaHdrBottom(sprm.Operand);
                    break;
                case 0x19:
                    newSEP.SetFLBetween(GetFlag(sprm.Operand));
                    break;
                case 0x1a:
                    newSEP.SetVjc((byte)sprm.Operand);
                    break;
                case 0x1b:
                    newSEP.SetLnnMin((short)sprm.Operand);
                    break;
                case 0x1c:
                    newSEP.SetPgnStart((short)sprm.Operand);
                    break;
                case 0x1d:
                    newSEP.SetDmOrientPage(sprm.Operand!=0);
                    break;
                case 0x1e:

                    //nothing
                    break;
                case 0x1f:
                    newSEP.SetXaPage(sprm.Operand);
                    break;
                case 0x20:
                    newSEP.SetYaPage(sprm.Operand);
                    break;
                case 0x21:
                    newSEP.SetDxaLeft(sprm.Operand);
                    break;
                case 0x22:
                    newSEP.SetDxaRight(sprm.Operand);
                    break;
                case 0x23:
                    newSEP.SetDyaTop(sprm.Operand);
                    break;
                case 0x24:
                    newSEP.SetDyaBottom(sprm.Operand);
                    break;
                case 0x25:
                    newSEP.SetDzaGutter(sprm.Operand);
                    break;
                case 0x26:
                    newSEP.SetDmPaperReq((short)sprm.Operand);
                    break;
                case 0x27:
                    newSEP.SetFPropMark(GetFlag(sprm.Operand));
                    break;
                case 0x28:
                    break;
                case 0x29:
                    break;
                case 0x2a:
                    break;
                case 0x2b:
                    newSEP.SetBrcTop(new BorderCode(sprm.Grpprl, sprm.GrpprlOffset));
                    break;
                case 0x2c:
                    newSEP.SetBrcLeft(new BorderCode(sprm.Grpprl, sprm.GrpprlOffset));
                    break;
                case 0x2d:
                    newSEP.SetBrcBottom(new BorderCode(sprm.Grpprl, sprm.GrpprlOffset));
                    break;
                case 0x2e:
                    newSEP.SetBrcRight(new BorderCode(sprm.Grpprl, sprm.GrpprlOffset));
                    break;
                case 0x2f:
                    newSEP.SetPgbProp(sprm.Operand);
                    break;
                case 0x30:
                    newSEP.SetDxtCharSpace(sprm.Operand);
                    break;
                case 0x31:
                    newSEP.SetDyaLinePitch(sprm.Operand);
                    break;
                case 0x33:
                    newSEP.SetWTextFlow((short)sprm.Operand);
                    break;
                default:
                    break;
            }

        }
Exemplo n.º 17
0
        /**
         * Used in decompression of a chpx. This performs an operation defined by
         * a single sprm.
         *
         * @param oldCHP The base CharacterProperties.
         * @param newCHP The current CharacterProperties.
         * @param operand The operand defined by the sprm (See Word file format spec)
         * @param param The parameter defined by the sprm (See Word file format spec)
         * @param varParam The variable length parameter defined by the sprm. (See
         *        Word file format spec)
         * @param grpprl The entire chpx that this operation is a part of.
         * @param offset The offset in the grpprl of the next sprm
         * @param styleSheet The StyleSheet for this document.
         */
        static void UncompressCHPOperation(CharacterProperties oldCHP,
                                           CharacterProperties newCHP,
                                           SprmOperation sprm)
        {
            switch (sprm.Operation)
            {
            case 0:
                newCHP.SetFRMarkDel(GetFlag(sprm.Operand));
                break;

            case 0x1:
                newCHP.SetFRMark(GetFlag(sprm.Operand));
                break;

            case 0x2:
                newCHP.SetFFldVanish(GetFlag(sprm.Operand));
                break;

            case 0x3:
                newCHP.SetFcPic(sprm.Operand);
                newCHP.SetFSpec(true);
                break;

            case 0x4:
                newCHP.SetIbstRMark((short)sprm.Operand);
                break;

            case 0x5:
                newCHP.SetDttmRMark(new DateAndTime(sprm.Grpprl, sprm.GrpprlOffset));
                break;

            case 0x6:
                newCHP.SetFData(GetFlag(sprm.Operand));
                break;

            case 0x7:
                //don't care about this
                break;

            case 0x8:
                //short chsDiff = (short)((param & 0xff0000) >>> 16);
                int   operand = sprm.Operand;
                short chsDiff = (short)(operand & 0x0000ff);
                newCHP.SetFChsDiff(GetFlag(chsDiff));
                newCHP.SetChse((short)(operand & 0xffff00));
                break;

            case 0x9:
                newCHP.SetFSpec(true);
                newCHP.SetFtcSym(LittleEndian.GetShort(sprm.Grpprl, sprm.GrpprlOffset));
                newCHP.SetXchSym(LittleEndian.GetShort(sprm.Grpprl, sprm.GrpprlOffset + 2));
                break;

            case 0xa:
                newCHP.SetFOle2(GetFlag(sprm.Operand));
                break;

            case 0xb:

                // Obsolete
                break;

            case 0xc:
                newCHP.SetIcoHighlight((byte)sprm.Operand);
                newCHP.SetFHighlight(GetFlag(sprm.Operand));
                break;

            case 0xd:

                //	undocumented
                break;

            case 0xe:
                newCHP.SetFcObj(sprm.Operand);
                break;

            case 0xf:

                // undocumented
                break;

            case 0x10:

                // undocumented
                break;

            // undocumented till 0x30

            case 0x11:
                // sprmCFWebHidden
                break;

            case 0x12:
                break;

            case 0x13:
                break;

            case 0x14:
                break;

            case 0x15:
                // sprmCRsidProp
                break;

            case 0x16:
                // sprmCRsidText
                break;

            case 0x17:
                // sprmCRsidRMDel
                break;

            case 0x18:
                // sprmCFSpecVanish
                break;

            case 0x19:
                break;

            case 0x1a:
                // sprmCFMathPr
                break;

            case 0x1b:
                break;

            case 0x1c:
                break;

            case 0x1d:
                break;

            case 0x1e:
                break;

            case 0x1f:
                break;

            case 0x20:
                break;

            case 0x21:
                break;

            case 0x22:
                break;

            case 0x23:
                break;

            case 0x24:
                break;

            case 0x25:
                break;

            case 0x26:
                break;

            case 0x27:
                break;

            case 0x28:
                break;

            case 0x29:
                break;

            case 0x2a:
                break;

            case 0x2b:
                break;

            case 0x2c:
                break;

            case 0x2d:
                break;

            case 0x2e:
                break;

            case 0x2f:
                break;

            case 0x30:
                newCHP.SetIstd(sprm.Operand);
                break;

            case 0x31:

                //permutation vector for fast saves, who cares!
                break;

            case 0x32:
                newCHP.SetFBold(false);
                newCHP.SetFItalic(false);
                newCHP.SetFOutline(false);
                newCHP.SetFStrike(false);
                newCHP.SetFShadow(false);
                newCHP.SetFSmallCaps(false);
                newCHP.SetFCaps(false);
                newCHP.SetFVanish(false);
                newCHP.SetKul((byte)0);
                newCHP.SetIco((byte)0);
                break;

            case 0x33:
                // preserve the fSpec Setting from the original CHP
                bool fSpec = newCHP.IsFSpec();
                newCHP = (CharacterProperties)oldCHP.Clone();
                newCHP.SetFSpec(fSpec);

                return;

            case 0x34:
                // sprmCKcd
                break;

            case 0x35:
                newCHP.SetFBold(GetCHPFlag((byte)sprm.Operand, oldCHP.IsFBold()));
                break;

            case 0x36:
                newCHP.SetFItalic(GetCHPFlag((byte)sprm.Operand, oldCHP.IsFItalic()));
                break;

            case 0x37:
                newCHP.SetFStrike(GetCHPFlag((byte)sprm.Operand, oldCHP.IsFStrike()));
                break;

            case 0x38:
                newCHP.SetFOutline(GetCHPFlag((byte)sprm.Operand, oldCHP.IsFOutline()));
                break;

            case 0x39:
                newCHP.SetFShadow(GetCHPFlag((byte)sprm.Operand, oldCHP.IsFShadow()));
                break;

            case 0x3a:
                newCHP.SetFSmallCaps(GetCHPFlag((byte)sprm.Operand, oldCHP.IsFSmallCaps()));
                break;

            case 0x3b:
                newCHP.SetFCaps(GetCHPFlag((byte)sprm.Operand, oldCHP.IsFCaps()));
                break;

            case 0x3c:
                newCHP.SetFVanish(GetCHPFlag((byte)sprm.Operand, oldCHP.IsFVanish()));
                break;

            case 0x3d:
                newCHP.SetFtcAscii((short)sprm.Operand);
                break;

            case 0x3e:
                newCHP.SetKul((byte)sprm.Operand);
                break;

            case 0x3f:
                operand = sprm.Operand;
                int hps = operand & 0xff;
                if (hps != 0)
                {
                    newCHP.SetHps(hps);
                }

                //byte cInc = (byte)(((byte)(param & 0xfe00) >>> 4) >> 1);
                byte cInc = (byte)((operand & 0xff00) >> 8);
                cInc = (byte)(cInc >> 1);
                if (cInc != 0)
                {
                    newCHP.SetHps(Math.Max(newCHP.GetHps() + (cInc * 2), 2));
                }

                //byte hpsPos = (byte)((param & 0xff0000) >>> 8);
                byte hpsPos = (byte)((operand & 0xff0000) >> 16);
                if (hpsPos != 0x80)
                {
                    newCHP.SetHpsPos(hpsPos);
                }
                bool fAdjust = (operand & 0x0100) > 0;
                if (fAdjust && hpsPos != 128 && hpsPos != 0 && oldCHP.GetHpsPos() == 0)
                {
                    newCHP.SetHps(Math.Max(newCHP.GetHps() + (-2), 2));
                }
                if (fAdjust && hpsPos == 0 && oldCHP.GetHpsPos() != 0)
                {
                    newCHP.SetHps(Math.Max(newCHP.GetHps() + 2, 2));
                }
                break;

            case 0x40:
                newCHP.SetDxaSpace(sprm.Operand);
                break;

            case 0x41:
                newCHP.SetLidDefault((short)sprm.Operand);
                break;

            case 0x42:
                newCHP.SetIco((byte)sprm.Operand);
                break;

            case 0x43:
                newCHP.SetHps(sprm.Operand);
                break;

            case 0x44:
                byte hpsLvl = (byte)sprm.Operand;
                newCHP.SetHps(Math.Max(newCHP.GetHps() + (hpsLvl * 2), 2));
                break;

            case 0x45:
                newCHP.SetHpsPos((short)sprm.Operand);
                break;

            case 0x46:
                if (sprm.Operand != 0)
                {
                    if (oldCHP.GetHpsPos() == 0)
                    {
                        newCHP.SetHps(Math.Max(newCHP.GetHps() + (-2), 2));
                    }
                }
                else
                {
                    if (oldCHP.GetHpsPos() != 0)
                    {
                        newCHP.SetHps(Math.Max(newCHP.GetHps() + 2, 2));
                    }
                }
                break;

            case 0x47:
                /*CharacterProperties genCHP = new CharacterProperties ();
                 * genCHP.SetFtcAscii (4);
                 * genCHP = (CharacterProperties) unCompressProperty (varParam, genCHP,
                 * styleSheet);
                 * CharacterProperties styleCHP = styleSheet.GetStyleDescription (oldCHP.
                 * GetBaseIstd ()).GetCHP ();
                 * if (genCHP.IsFBold () == newCHP.IsFBold ())
                 * {
                 * newCHP.SetFBold (styleCHP.IsFBold ());
                 * }
                 * if (genCHP.IsFItalic () == newCHP.IsFItalic ())
                 * {
                 * newCHP.SetFItalic (styleCHP.IsFItalic ());
                 * }
                 * if (genCHP.IsFSmallCaps () == newCHP.IsFSmallCaps ())
                 * {
                 * newCHP.SetFSmallCaps (styleCHP.IsFSmallCaps ());
                 * }
                 * if (genCHP.IsFVanish () == newCHP.IsFVanish ())
                 * {
                 * newCHP.SetFVanish (styleCHP.IsFVanish ());
                 * }
                 * if (genCHP.IsFStrike () == newCHP.IsFStrike ())
                 * {
                 * newCHP.SetFStrike (styleCHP.IsFStrike ());
                 * }
                 * if (genCHP.IsFCaps () == newCHP.IsFCaps ())
                 * {
                 * newCHP.SetFCaps (styleCHP.IsFCaps ());
                 * }
                 * if (genCHP.GetFtcAscii () == newCHP.GetFtcAscii ())
                 * {
                 * newCHP.SetFtcAscii (styleCHP.GetFtcAscii ());
                 * }
                 * if (genCHP.GetFtcFE () == newCHP.GetFtcFE ())
                 * {
                 * newCHP.SetFtcFE (styleCHP.GetFtcFE ());
                 * }
                 * if (genCHP.GetFtcOther () == newCHP.GetFtcOther ())
                 * {
                 * newCHP.SetFtcOther (styleCHP.GetFtcOther ());
                 * }
                 * if (genCHP.GetHps () == newCHP.GetHps ())
                 * {
                 * newCHP.SetHps (styleCHP.GetHps ());
                 * }
                 * if (genCHP.GetHpsPos () == newCHP.GetHpsPos ())
                 * {
                 * newCHP.SetHpsPos (styleCHP.GetHpsPos ());
                 * }
                 * if (genCHP.GetKul () == newCHP.GetKul ())
                 * {
                 * newCHP.SetKul (styleCHP.GetKul ());
                 * }
                 * if (genCHP.GetDxaSpace () == newCHP.GetDxaSpace ())
                 * {
                 * newCHP.SetDxaSpace (styleCHP.GetDxaSpace ());
                 * }
                 * if (genCHP.GetIco () == newCHP.GetIco ())
                 * {
                 * newCHP.SetIco (styleCHP.GetIco ());
                 * }
                 * if (genCHP.GetLidDefault () == newCHP.GetLidDefault ())
                 * {
                 * newCHP.SetLidDefault (styleCHP.GetLidDefault ());
                 * }
                 * if (genCHP.GetLidFE () == newCHP.GetLidFE ())
                 * {
                 * newCHP.SetLidFE (styleCHP.GetLidFE ());
                 * }*/
                break;

            case 0x48:
                newCHP.SetIss((byte)sprm.Operand);
                break;

            case 0x49:
                newCHP.SetHps(LittleEndian.GetShort(sprm.Grpprl, sprm.GrpprlOffset));
                break;

            case 0x4a:
                int increment = LittleEndian.GetShort(sprm.Grpprl, sprm.GrpprlOffset);
                newCHP.SetHps(Math.Max(newCHP.GetHps() + increment, 8));
                break;

            case 0x4b:
                newCHP.SetHpsKern(sprm.Operand);
                break;

            case 0x4c:
                //        unCompressCHPOperation (oldCHP, newCHP, 0x47, param, varParam,
                //                                styleSheet, opSize);
                break;

            case 0x4d:
                float percentage = sprm.Operand / 100.0f;
                int   add        = (int)(percentage * newCHP.GetHps());
                newCHP.SetHps(newCHP.GetHps() + add);
                break;

            case 0x4e:
                newCHP.SetYsr((byte)sprm.Operand);
                break;

            case 0x4f:
                newCHP.SetFtcAscii((short)sprm.Operand);
                break;

            case 0x50:
                newCHP.SetFtcFE((short)sprm.Operand);
                break;

            case 0x51:
                newCHP.SetFtcOther((short)sprm.Operand);
                break;

            case 0x52:
                // sprmCCharScale
                break;

            case 0x53:
                newCHP.SetFDStrike(GetFlag(sprm.Operand));
                break;

            case 0x54:
                newCHP.SetFImprint(GetFlag(sprm.Operand));
                break;

            case 0x55:
                newCHP.SetFSpec(GetFlag(sprm.Operand));
                break;

            case 0x56:
                newCHP.SetFObj(GetFlag(sprm.Operand));
                break;

            case 0x57:
                byte[] buf    = sprm.Grpprl;
                int    offset = sprm.GrpprlOffset;
                newCHP.SetFPropMark(buf[offset]);
                newCHP.SetIbstPropRMark(LittleEndian.GetShort(buf, offset + 1));
                newCHP.SetDttmPropRMark(new DateAndTime(buf, offset + 3));
                break;

            case 0x58:
                newCHP.SetFEmboss(GetFlag(sprm.Operand));
                break;

            case 0x59:
                newCHP.SetSfxtText((byte)sprm.Operand);
                break;

            case 0x5a:
                // sprmCFBiDi
                break;

            case 0x5b:
                break;

            case 0x5c:
                // sprmCFBoldBi
                break;

            case 0x5d:
                // sprmCFItalicBi
                break;

            case 0x5e:
                // sprmCFtcBi
                break;

            case 0x5f:
                // sprmCLidBi
                break;

            case 0x60:
                // sprmCIcoBi
                break;

            case 0x61:
                // sprmCHpsBi
                break;

            case 0x62:
                byte[] xstDispFldRMark = new byte[32];
                buf    = sprm.Grpprl;
                offset = sprm.GrpprlOffset;
                newCHP.SetFDispFldRMark(buf[offset]);
                newCHP.SetIbstDispFldRMark(LittleEndian.GetShort(buf, offset + 1));
                newCHP.SetDttmDispFldRMark(new DateAndTime(buf, offset + 3));
                Array.Copy(buf, offset + 7, xstDispFldRMark, 0, 32);
                newCHP.SetXstDispFldRMark(xstDispFldRMark);
                break;

            case 0x63:
                newCHP.SetIbstRMarkDel((short)sprm.Operand);
                break;

            case 0x64:
                newCHP.SetDttmRMarkDel(new DateAndTime(sprm.Grpprl, sprm.GrpprlOffset));
                break;

            case 0x65:
                newCHP.SetBrc(new BorderCode(sprm.Grpprl, sprm.GrpprlOffset));
                break;

            case 0x66:
                newCHP.SetShd(new ShadingDescriptor(sprm.Grpprl, sprm.GrpprlOffset));
                break;

            case 0x67:
                // Obsolete
                break;

            case 0x68:
                //  sprmCFUsePgsuSettings
                break;

            case 0x69:
                break;

            case 0x6a:
                break;

            case 0x6b:
                break;

            case 0x6c:
                break;

            case 0x6d:
                newCHP.SetLidDefault((short)sprm.Operand);
                break;

            case 0x6e:
                newCHP.SetLidFE((short)sprm.Operand);
                break;

            case 0x6f:
                newCHP.SetIdctHint((byte)sprm.Operand);
                break;

            case 0x70:
                newCHP.SetIco24(sprm.Operand);
                break;

            case 0x71:
                // sprmCShd
                break;

            case 0x72:
                // sprmCBrc
                break;

            case 0x73:
                // sprmCRgLid0
                break;

            case 0x74:
                // sprmCRgLid1
                break;
            }
        }
Exemplo n.º 18
0
        /**
         * Performs an operation on a ParagraphProperties object. Used to uncompress
         * from a papx.
         *
         * @param newPAP The ParagraphProperties object to perform the operation on.
         * @param operand The operand that defines the operation.
         * @param param The operation's parameter.
         * @param varParam The operation's variable length parameter.
         * @param grpprl The original papx.
         * @param offset The current offset in the papx.
         * @param spra A part of the sprm that defined this operation.
         */
        static void UncompressPAPOperation(ParagraphProperties newPAP, SprmOperation sprm)
        {
            switch (sprm.Operation)
            {
            case 0:
                newPAP.SetIstd(sprm.Operand);
                break;

            case 0x1:

                // Used only for piece table grpprl's not for PAPX
                //        int istdFirst = LittleEndian.Getshort (varParam, 2);
                //        int istdLast = LittleEndian.Getshort (varParam, 4);
                //        if ((newPAP.GetIstd () > istdFirst) || (newPAP.GetIstd () <= istdLast))
                //        {
                //          permuteIstd (newPAP, varParam, opSize);
                //        }
                break;

            case 0x2:
                if (newPAP.GetIstd() <= 9 || newPAP.GetIstd() >= 1)
                {
                    byte paramTmp = (byte)sprm.Operand;
                    newPAP.SetIstd(newPAP.GetIstd() + paramTmp);
                    newPAP.SetLvl((byte)(newPAP.GetLvl() + paramTmp));

                    if (((paramTmp >> 7) & 0x01) == 1)
                    {
                        newPAP.SetIstd(Math.Max(newPAP.GetIstd(), 1));
                    }
                    else
                    {
                        newPAP.SetIstd(Math.Min(newPAP.GetIstd(), 9));
                    }
                }
                break;

            case 0x3:
                // Physical justification of the paragraph
                newPAP.SetJc((byte)sprm.Operand);
                break;

            case 0x4:
                newPAP.SetFSideBySide(sprm.Operand != 0);
                break;

            case 0x5:
                newPAP.SetFKeep(sprm.Operand != 0);
                break;

            case 0x6:
                newPAP.SetFKeepFollow(sprm.Operand != 0);
                break;

            case 0x7:
                newPAP.SetFPageBreakBefore(sprm.Operand != 0);
                break;

            case 0x8:
                newPAP.SetBrcl((byte)sprm.Operand);
                break;

            case 0x9:
                newPAP.SetBrcp((byte)sprm.Operand);
                break;

            case 0xa:
                newPAP.SetIlvl((byte)sprm.Operand);
                break;

            case 0xb:
                newPAP.SetIlfo(sprm.Operand);
                break;

            case 0xc:
                newPAP.SetFNoLnn(sprm.Operand != 0);
                break;

            case 0xd:
                /**handle tabs . variable parameter. seperate Processing needed*/
                handleTabs(newPAP, sprm);
                break;

            case 0xe:
                newPAP.SetDxaRight(sprm.Operand);
                break;

            case 0xf:
                newPAP.SetDxaLeft(sprm.Operand);
                break;

            case 0x10:

                // sprmPNest is only stored in grpprls linked to a piece table.
                newPAP.SetDxaLeft(newPAP.GetDxaLeft() + sprm.Operand);
                newPAP.SetDxaLeft(Math.Max(0, newPAP.GetDxaLeft()));
                break;

            case 0x11:
                newPAP.SetDxaLeft1(sprm.Operand);
                break;

            case 0x12:
                newPAP.SetLspd(new LineSpacingDescriptor(sprm.Grpprl, sprm.GrpprlOffset));
                break;

            case 0x13:
                newPAP.SetDyaBefore(sprm.Operand);
                break;

            case 0x14:
                newPAP.SetDyaAfter(sprm.Operand);
                break;

            case 0x15:
                // fast saved only
                //ApplySprmPChgTabs (newPAP, varParam, opSize);
                break;

            case 0x16:
                newPAP.SetFInTable(sprm.Operand != 0);
                break;

            case 0x17:
                newPAP.SetFTtp(sprm.Operand != 0);
                break;

            case 0x18:
                newPAP.SetDxaAbs(sprm.Operand);
                break;

            case 0x19:
                newPAP.SetDyaAbs(sprm.Operand);
                break;

            case 0x1a:
                newPAP.SetDxaWidth(sprm.Operand);
                break;

            case 0x1b:
                byte param = (byte)sprm.Operand;
                /** @todo handle paragraph postioning*/
                byte pcVert = (byte)((param & 0x0c) >> 2);
                byte pcHorz = (byte)(param & 0x03);
                if (pcVert != 3)
                {
                    newPAP.SetPcVert(pcVert);
                }
                if (pcHorz != 3)
                {
                    newPAP.SetPcHorz(pcHorz);
                }
                break;

            // BrcXXX1 is older Version. Brc is used
            case 0x1c:

                //newPAP.SetBrcTop1((short)param);
                break;

            case 0x1d:

                //newPAP.SetBrcLeft1((short)param);
                break;

            case 0x1e:

                //newPAP.SetBrcBottom1((short)param);
                break;

            case 0x1f:

                //newPAP.SetBrcRight1((short)param);
                break;

            case 0x20:

                //newPAP.SetBrcBetween1((short)param);
                break;

            case 0x21:

                //newPAP.SetBrcBar1((byte)param);
                break;

            case 0x22:
                newPAP.SetDxaFromText(sprm.Operand);
                break;

            case 0x23:
                newPAP.SetWr((byte)sprm.Operand);
                break;

            case 0x24:
                newPAP.SetBrcTop(new BorderCode(sprm.Grpprl, sprm.GrpprlOffset));
                break;

            case 0x25:
                newPAP.SetBrcLeft(new BorderCode(sprm.Grpprl, sprm.GrpprlOffset));
                break;

            case 0x26:
                newPAP.SetBrcBottom(new BorderCode(sprm.Grpprl, sprm.GrpprlOffset));
                break;

            case 0x27:
                newPAP.SetBrcRight(new BorderCode(sprm.Grpprl, sprm.GrpprlOffset));
                break;

            case 0x28:
                newPAP.SetBrcBetween(new BorderCode(sprm.Grpprl, sprm.GrpprlOffset));
                break;

            case 0x29:
                newPAP.SetBrcBar(new BorderCode(sprm.Grpprl, sprm.GrpprlOffset));
                break;

            case 0x2a:
                newPAP.SetFNoAutoHyph(sprm.Operand != 0);
                break;

            case 0x2b:
                newPAP.SetDyaHeight(sprm.Operand);
                break;

            case 0x2c:
                newPAP.SetDcs(new DropCapSpecifier((short)sprm.Operand));
                break;

            case 0x2d:
                newPAP.SetShd(new ShadingDescriptor((short)sprm.Operand));
                break;

            case 0x2e:
                newPAP.SetDyaFromText(sprm.Operand);
                break;

            case 0x2f:
                newPAP.SetDxaFromText(sprm.Operand);
                break;

            case 0x30:
                newPAP.SetFLocked(sprm.Operand != 0);
                break;

            case 0x31:
                newPAP.SetFWidowControl(sprm.Operand != 0);
                break;

            case 0x32:

                //undocumented
                break;

            case 0x33:
                newPAP.SetFKinsoku(sprm.Operand != 0);
                break;

            case 0x34:
                newPAP.SetFWordWrap(sprm.Operand != 0);
                break;

            case 0x35:
                newPAP.SetFOverflowPunct(sprm.Operand != 0);
                break;

            case 0x36:
                newPAP.SetFTopLinePunct(sprm.Operand != 0);
                break;

            case 0x37:
                newPAP.SetFAutoSpaceDE(sprm.Operand != 0);
                break;

            case 0x38:
                newPAP.SetFAutoSpaceDN(sprm.Operand != 0);
                break;

            case 0x39:
                newPAP.SetWAlignFont(sprm.Operand);
                break;

            case 0x3a:
                newPAP.SetFontAlign((short)sprm.Operand);
                break;

            case 0x3b:

                //obsolete
                break;

            case 0x3e:
                byte[] buf = new byte[sprm.Size - 3];
                Array.Copy(buf, 0, sprm.Grpprl, sprm.GrpprlOffset,
                           buf.Length);
                newPAP.SetAnld(buf);
                break;

            case 0x3f:
                //don't really need this. spec is confusing regarding this
                //sprm
                byte[] varParam = sprm.Grpprl;
                int    offset   = sprm.GrpprlOffset;
                newPAP.SetFPropRMark(varParam[offset] != 0);
                newPAP.SetIbstPropRMark(LittleEndian.GetShort(varParam, offset + 1));
                newPAP.SetDttmPropRMark(new DateAndTime(varParam, offset + 3));

                break;

            case 0x40:
                // This condition commented out, as Word seems to set outline levels even for
                //  paragraph with other styles than Heading 1..9, even though specification
                //  does not say so. See bug 49820 for discussion.
                //if (newPAP.GetIstd () < 1 && newPAP.GetIstd () > 9)
                //{
                newPAP.SetLvl((byte)sprm.Operand);
                //}
                break;

            case 0x41:

                // undocumented
                break;

            case 0x43:

                //pap.fNumRMIns
                newPAP.SetFNumRMIns(sprm.Operand != 0);
                break;

            case 0x44:

                //undocumented
                break;

            case 0x45:
                if (sprm.SizeCode == 6)
                {
                    byte[] buf1 = new byte[sprm.Size - 3];
                    Array.Copy(buf1, 0, sprm.Grpprl, sprm.GrpprlOffset, buf1.Length);
                    newPAP.SetNumrm(buf1);
                }
                else
                {
                    /**@todo handle large PAPX from data stream*/
                }
                break;

            case 0x47:
                newPAP.SetFUsePgsuSettings(sprm.Operand != 0);
                break;

            case 0x48:
                newPAP.SetFAdjustRight(sprm.Operand != 0);
                break;

            case 0x49:
                // sprmPItap -- 0x6649
                newPAP.SetItap(sprm.Operand);
                break;

            case 0x4a:
                // sprmPDtap -- 0x664a
                newPAP.SetItap((byte)(newPAP.GetItap() + sprm.Operand));
                break;

            case 0x4b:
                // sprmPFInnerTableCell -- 0x244b
                newPAP.SetFInnerTableCell(sprm.Operand != 0);
                break;

            case 0x4c:
                // sprmPFInnerTtp -- 0x244c
                newPAP.SetFTtpEmbedded(sprm.Operand != 0);
                break;

            case 0x61:
                // sprmPJc
                newPAP.SetJustificationLogical((byte)sprm.Operand);
                break;

            default:
                break;
            }
        }
Exemplo n.º 19
0
        /**
         * Used to uncompress a table property. Performs an operation defined
         * by a sprm stored in a tapx.
         *
         * @param newTAP The TableProperties object to perform the operation on.
         * @param operand The operand that defines this operation.
         * @param param The parameter for this operation.
         * @param varParam Variable length parameter for this operation.
         */
        static void UncompressTAPOperation(TableProperties newTAP, SprmOperation sprm)
        {
            switch (sprm.Operation)
            {
            case 0:
                newTAP.SetJc((short)sprm.Operand);
                break;

            case 0x01:
            {
                short[] rgdxaCenter = newTAP.GetRgdxaCenter();
                short   itcMac      = newTAP.GetItcMac();
                int     adjust      = sprm.Operand - (rgdxaCenter[0] + newTAP.GetDxaGapHalf());
                for (int x = 0; x < itcMac; x++)
                {
                    rgdxaCenter[x] += (short)adjust;
                }
                break;
            }

            case 0x02:
            {
                short[] rgdxaCenter = newTAP.GetRgdxaCenter();
                if (rgdxaCenter != null)
                {
                    int adjust = newTAP.GetDxaGapHalf() - sprm.Operand;
                    rgdxaCenter[0] += (short)adjust;
                }
                newTAP.SetDxaGapHalf(sprm.Operand);
                break;
            }

            case 0x03:
                newTAP.SetFCantSplit(GetFlag(sprm.Operand));
                break;

            case 0x04:
                newTAP.SetFTableHeader(GetFlag(sprm.Operand));
                break;

            case 0x05:
            {
                byte[] buf    = sprm.Grpprl;
                int    offset = sprm.GrpprlOffset;
                newTAP.SetBrcTop(new BorderCode(buf, offset));
                offset += BorderCode.SIZE;
                newTAP.SetBrcLeft(new BorderCode(buf, offset));
                offset += BorderCode.SIZE;
                newTAP.SetBrcBottom(new BorderCode(buf, offset));
                offset += BorderCode.SIZE;
                newTAP.SetBrcRight(new BorderCode(buf, offset));
                offset += BorderCode.SIZE;
                newTAP.SetBrcHorizontal(new BorderCode(buf, offset));
                offset += BorderCode.SIZE;
                newTAP.SetBrcVertical(new BorderCode(buf, offset));
                break;
            }

            case 0x06:

                //obsolete, used in word 1.x
                break;

            case 0x07:
                newTAP.SetDyaRowHeight(sprm.Operand);
                break;

            case 0x08:
            {
                byte[]  grpprl             = sprm.Grpprl;
                int     offset             = sprm.GrpprlOffset;
                short   itcMac             = grpprl[offset];
                short[] rgdxaCenter        = new short[itcMac + 1];
                TableCellDescriptor[] rgtc = new TableCellDescriptor[itcMac];
                //I use varParam[0] and newTAP._itcMac interchangably
                newTAP.SetItcMac(itcMac);
                newTAP.SetRgdxaCenter(rgdxaCenter);
                newTAP.SetRgtc(rgtc);

                // get the rgdxaCenters
                for (int x = 0; x < itcMac; x++)
                {
                    rgdxaCenter[x] = LittleEndian.GetShort(grpprl, offset + (1 + (x * 2)));
                }

                // only try to get the TC entries if they exist...
                int endOfSprm  = offset + sprm.Size - 6;        // -2 bytes for sprm - 2 for size short - 2 to correct Offsets being 0 based
                int startOfTCs = offset + (1 + (itcMac + 1) * 2);

                bool hasTCs = startOfTCs < endOfSprm;

                for (int x = 0; x < itcMac; x++)
                {
                    // Sometimes, the grpprl does not contain data at every Offset. I have no idea why this happens.
                    if (hasTCs && offset + (1 + ((itcMac + 1) * 2) + (x * 20)) < grpprl.Length)
                    {
                        rgtc[x] = TableCellDescriptor.ConvertBytesToTC(grpprl,
                                                                       offset + (1 + ((itcMac + 1) * 2) + (x * 20)));
                    }
                    else
                    {
                        rgtc[x] = new TableCellDescriptor();
                    }
                }

                rgdxaCenter[itcMac] = LittleEndian.GetShort(grpprl, offset + (1 + (itcMac * 2)));
                break;
            }

            case 0x09:

                /** @todo handle cell shading*/
                break;

            case 0x0a:

                /** @todo handle word defined table styles*/
                break;

            case 0x20:
                //      {
                //        TableCellDescriptor[] rgtc = newTAP.GetRgtc();
                //
                //        for (int x = varParam[0]; x < varParam[1]; x++)
                //        {
                //
                //          if ((varParam[2] & 0x08) > 0)
                //          {
                //            short[] brcRight = rgtc[x].GetBrcRight ();
                //            brcRight[0] = LittleEndian.Getshort (varParam, 6);
                //            brcRight[1] = LittleEndian.Getshort (varParam, 8);
                //          }
                //          else if ((varParam[2] & 0x04) > 0)
                //          {
                //            short[] brcBottom = rgtc[x].GetBrcBottom ();
                //            brcBottom[0] = LittleEndian.Getshort (varParam, 6);
                //            brcBottom[1] = LittleEndian.Getshort (varParam, 8);
                //          }
                //          else if ((varParam[2] & 0x02) > 0)
                //          {
                //            short[] brcLeft = rgtc[x].GetBrcLeft ();
                //            brcLeft[0] = LittleEndian.Getshort (varParam, 6);
                //            brcLeft[1] = LittleEndian.Getshort (varParam, 8);
                //          }
                //          else if ((varParam[2] & 0x01) > 0)
                //          {
                //            short[] brcTop = rgtc[x].GetBrcTop ();
                //            brcTop[0] = LittleEndian.Getshort (varParam, 6);
                //            brcTop[1] = LittleEndian.Getshort (varParam, 8);
                //          }
                //        }
                //        break;
                //      }
                break;

            case 0x21:
            {
                int param  = sprm.Operand;
                int index  = (int)(param & 0xff000000) >> 24;
                int count  = (param & 0x00ff0000) >> 16;
                int width  = (param & 0x0000ffff);
                int itcMac = newTAP.GetItcMac();

                short[] rgdxaCenter        = new short[itcMac + count + 1];
                TableCellDescriptor[] rgtc = new TableCellDescriptor[itcMac + count];
                if (index >= itcMac)
                {
                    index = itcMac;
                    Array.Copy(newTAP.GetRgdxaCenter(), 0, rgdxaCenter, 0,
                               itcMac + 1);
                    Array.Copy(newTAP.GetRgtc(), 0, rgtc, 0, itcMac);
                }
                else
                {
                    //copy rgdxaCenter
                    Array.Copy(newTAP.GetRgdxaCenter(), 0, rgdxaCenter, 0,
                               index + 1);
                    Array.Copy(newTAP.GetRgdxaCenter(), index + 1, rgdxaCenter,
                               index + count, itcMac - (index));
                    //copy rgtc
                    Array.Copy(newTAP.GetRgtc(), 0, rgtc, 0, index);
                    Array.Copy(newTAP.GetRgtc(), index, rgtc, index + count,
                               itcMac - index);
                }

                for (int x = index; x < index + count; x++)
                {
                    rgtc[x]        = new TableCellDescriptor();
                    rgdxaCenter[x] = (short)(rgdxaCenter[x - 1] + width);
                }
                rgdxaCenter[index +
                            count] = (short)(rgdxaCenter[(index + count) - 1] + width);
                break;
            }

            /**@todo handle table sprms from complex files*/
            case 0x22:
            case 0x23:
            case 0x24:
            case 0x25:
            case 0x26:
            case 0x27:
            case 0x28:
            case 0x29:
            case 0x2a:
            case 0x2b:
            case 0x2c:
                break;

            default:
                break;
            }
        }
Exemplo n.º 20
0
        /**
         * Used to uncompress a table property. Performs an operation defined
         * by a sprm stored in a tapx.
         *
         * @param newTAP The TableProperties object to perform the operation on.
         * @param operand The operand that defines this operation.
         * @param param The parameter for this operation.
         * @param varParam Variable length parameter for this operation.
         */
        static void UncompressTAPOperation(TableProperties newTAP, SprmOperation sprm)
        {
            switch (sprm.Operation)
            {
                case 0:
                    newTAP.SetJc((short)sprm.Operand);
                    break;
                case 0x01:
                    {
                        short[] rgdxaCenter = newTAP.GetRgdxaCenter();
                        short itcMac = newTAP.GetItcMac();
                        int adjust = sprm.Operand - (rgdxaCenter[0] + newTAP.GetDxaGapHalf());
                        for (int x = 0; x < itcMac; x++)
                        {
                            rgdxaCenter[x] += (short)adjust;
                        }
                        break;
                    }
                case 0x02:
                    {
                        short[] rgdxaCenter = newTAP.GetRgdxaCenter();
                        if (rgdxaCenter != null)
                        {
                            int adjust = newTAP.GetDxaGapHalf() - sprm.Operand;
                            rgdxaCenter[0] += (short)adjust;
                        }
                        newTAP.SetDxaGapHalf(sprm.Operand);
                        break;
                    }
                case 0x03:
                    newTAP.SetFCantSplit(GetFlag(sprm.Operand));
                    break;
                case 0x04:
                    newTAP.SetFTableHeader(GetFlag(sprm.Operand));
                    break;
                case 0x05:
                    {
                        byte[] buf = sprm.Grpprl;
                        int offset = sprm.GrpprlOffset;
                        newTAP.SetBrcTop(new BorderCode(buf, offset));
                        offset += BorderCode.SIZE;
                        newTAP.SetBrcLeft(new BorderCode(buf, offset));
                        offset += BorderCode.SIZE;
                        newTAP.SetBrcBottom(new BorderCode(buf, offset));
                        offset += BorderCode.SIZE;
                        newTAP.SetBrcRight(new BorderCode(buf, offset));
                        offset += BorderCode.SIZE;
                        newTAP.SetBrcHorizontal(new BorderCode(buf, offset));
                        offset += BorderCode.SIZE;
                        newTAP.SetBrcVertical(new BorderCode(buf, offset));
                        break;
                    }
                case 0x06:

                    //obsolete, used in word 1.x
                    break;
                case 0x07:
                    newTAP.SetDyaRowHeight(sprm.Operand);
                    break;
                case 0x08:
                    {
                        byte[] grpprl = sprm.Grpprl;
                        int offset = sprm.GrpprlOffset;
                        short itcMac = grpprl[offset];
                        short[] rgdxaCenter = new short[itcMac + 1];
                        TableCellDescriptor[] rgtc = new TableCellDescriptor[itcMac];
                        //I use varParam[0] and newTAP._itcMac interchangably
                        newTAP.SetItcMac(itcMac);
                        newTAP.SetRgdxaCenter(rgdxaCenter);
                        newTAP.SetRgtc(rgtc);

                        // get the rgdxaCenters
                        for (int x = 0; x < itcMac; x++)
                        {
                            rgdxaCenter[x] = LittleEndian.GetShort(grpprl, offset + (1 + (x * 2)));
                        }

                        // only try to get the TC entries if they exist...
                        int endOfSprm = offset + sprm.Size - 6; // -2 bytes for sprm - 2 for size short - 2 to correct Offsets being 0 based
                        int startOfTCs = offset + (1 + (itcMac + 1) * 2);

                        bool hasTCs = startOfTCs < endOfSprm;

                        for (int x = 0; x < itcMac; x++)
                        {
                            // Sometimes, the grpprl does not contain data at every Offset. I have no idea why this happens.
                            if (hasTCs && offset + (1 + ((itcMac + 1) * 2) + (x * 20)) < grpprl.Length)
                                rgtc[x] = TableCellDescriptor.ConvertBytesToTC(grpprl,
                                   offset + (1 + ((itcMac + 1) * 2) + (x * 20)));
                            else
                                rgtc[x] = new TableCellDescriptor();
                        }

                        rgdxaCenter[itcMac] = LittleEndian.GetShort(grpprl, offset + (1 + (itcMac * 2)));
                        break;
                    }
                case 0x09:

                    /** @todo handle cell shading*/
                    break;
                case 0x0a:

                    /** @todo handle word defined table styles*/
                    break;
                case 0x20:
                    //      {
                    //        TableCellDescriptor[] rgtc = newTAP.GetRgtc();
                    //
                    //        for (int x = varParam[0]; x < varParam[1]; x++)
                    //        {
                    //
                    //          if ((varParam[2] & 0x08) > 0)
                    //          {
                    //            short[] brcRight = rgtc[x].GetBrcRight ();
                    //            brcRight[0] = LittleEndian.Getshort (varParam, 6);
                    //            brcRight[1] = LittleEndian.Getshort (varParam, 8);
                    //          }
                    //          else if ((varParam[2] & 0x04) > 0)
                    //          {
                    //            short[] brcBottom = rgtc[x].GetBrcBottom ();
                    //            brcBottom[0] = LittleEndian.Getshort (varParam, 6);
                    //            brcBottom[1] = LittleEndian.Getshort (varParam, 8);
                    //          }
                    //          else if ((varParam[2] & 0x02) > 0)
                    //          {
                    //            short[] brcLeft = rgtc[x].GetBrcLeft ();
                    //            brcLeft[0] = LittleEndian.Getshort (varParam, 6);
                    //            brcLeft[1] = LittleEndian.Getshort (varParam, 8);
                    //          }
                    //          else if ((varParam[2] & 0x01) > 0)
                    //          {
                    //            short[] brcTop = rgtc[x].GetBrcTop ();
                    //            brcTop[0] = LittleEndian.Getshort (varParam, 6);
                    //            brcTop[1] = LittleEndian.Getshort (varParam, 8);
                    //          }
                    //        }
                    //        break;
                    //      }
                    break;
                case 0x21:
                    {
                        int param = sprm.Operand;
                        int index = (int)(param & 0xff000000) >> 24;
                        int count = (param & 0x00ff0000) >> 16;
                        int width = (param & 0x0000ffff);
                        int itcMac = newTAP.GetItcMac();

                        short[] rgdxaCenter = new short[itcMac + count + 1];
                        TableCellDescriptor[] rgtc = new TableCellDescriptor[itcMac + count];
                        if (index >= itcMac)
                        {
                            index = itcMac;
                            Array.Copy(newTAP.GetRgdxaCenter(), 0, rgdxaCenter, 0,
                                             itcMac + 1);
                            Array.Copy(newTAP.GetRgtc(), 0, rgtc, 0, itcMac);
                        }
                        else
                        {
                            //copy rgdxaCenter
                            Array.Copy(newTAP.GetRgdxaCenter(), 0, rgdxaCenter, 0,
                                             index + 1);
                            Array.Copy(newTAP.GetRgdxaCenter(), index + 1, rgdxaCenter,
                                             index + count, itcMac - (index));
                            //copy rgtc
                            Array.Copy(newTAP.GetRgtc(), 0, rgtc, 0, index);
                            Array.Copy(newTAP.GetRgtc(), index, rgtc, index + count,
                                             itcMac - index);
                        }

                        for (int x = index; x < index + count; x++)
                        {
                            rgtc[x] = new TableCellDescriptor();
                            rgdxaCenter[x] = (short)(rgdxaCenter[x - 1] + width);
                        }
                        rgdxaCenter[index +
                          count] = (short)(rgdxaCenter[(index + count) - 1] + width);
                        break;
                    }
                /**@todo handle table sprms from complex files*/
                case 0x22:
                case 0x23:
                case 0x24:
                case 0x25:
                case 0x26:
                case 0x27:
                case 0x28:
                case 0x29:
                case 0x2a:
                case 0x2b:
                case 0x2c:
                    break;
                default:
                    break;
            }
        }