示例#1
0
        public TableRow(int startIdx, int endIdx, Table parent, int levelNum)
            : base(startIdx, endIdx, parent)
        {
            Paragraph last = GetParagraph(NumParagraphs - 1);

            _papx     = last._papx;
            _tprops   = TableSprmUncompressor.UncompressTAP(_papx);
            _levelNum = levelNum;
            initCells();
        }
示例#2
0
        public TableRow(int startIdx, int endIdx, Table parent, int levelNum)
            : base(startIdx, endIdx, parent)
        {

            Paragraph last = GetParagraph(NumParagraphs - 1);
            _papx = last._papx;
            _tprops = TableSprmUncompressor.UncompressTAP(_papx);
            _levelNum = levelNum;
            initCells();

        }
示例#3
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;
        }
示例#4
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;
        }
示例#5
0
文件: Range.cs 项目: zzy092/npoi
        public Table InsertBefore(TableProperties props, int rows)
        {
            ParagraphProperties parProps = new ParagraphProperties();

            parProps.SetFInTable(true);
            parProps.SetItap(1);

            int columns = props.GetItcMac();

            for (int x = 0; x < rows; x++)
            {
                Paragraph cell = this.InsertBefore(parProps, StyleSheet.NIL_STYLE);
                cell.InsertAfter("\u0007");
                for (int y = 1; y < columns; y++)
                {
                    cell = cell.InsertAfter(parProps, StyleSheet.NIL_STYLE);
                    cell.InsertAfter("\u0007");
                }
                cell = cell.InsertAfter(parProps, StyleSheet.NIL_STYLE, "\u0007");
                cell.SetTableRowEnd(props);
            }
            return(new Table(_start, _start + (rows * (columns + 1)), this, 1));
        }
示例#6
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;
            }
        }
示例#7
0
        public static byte[] CompressTableProperty(TableProperties newTAP)
        {
            int size = 0;
            ArrayList sprmList = new ArrayList();

            if (newTAP.GetJc() != 0)
            {
                size += SprmUtils.AddSprm((short)0x5400, newTAP.GetJc(), null, sprmList);
            }
            if (newTAP.GetFCantSplit())
            {
                size += SprmUtils.AddSprm((short)0x3403, 1, null, sprmList);
            }
            if (newTAP.GetFTableHeader())
            {
                size += SprmUtils.AddSprm((short)0x3404, 1, null, sprmList);
            }
            byte[] brcBuf = new byte[6 * BorderCode.SIZE];
            int offset = 0;
            newTAP.GetBrcTop().Serialize(brcBuf, offset);
            offset += BorderCode.SIZE;
            newTAP.GetBrcLeft().Serialize(brcBuf, offset);
            offset += BorderCode.SIZE;
            newTAP.GetBrcBottom().Serialize(brcBuf, offset);
            offset += BorderCode.SIZE;
            newTAP.GetBrcRight().Serialize(brcBuf, offset);
            offset += BorderCode.SIZE;
            newTAP.GetBrcHorizontal().Serialize(brcBuf, offset);
            offset += BorderCode.SIZE;
            newTAP.GetBrcVertical().Serialize(brcBuf, offset);
            byte[] compare = new byte[6 * BorderCode.SIZE];
            if (!Arrays.Equals(brcBuf, compare))
            {
                size += SprmUtils.AddSprm(unchecked((short)0xD605), 0, brcBuf, sprmList);
            }
            if (newTAP.GetDyaRowHeight() != 0)
            {
                size += SprmUtils.AddSprm(unchecked((short)0x9407), newTAP.GetDyaRowHeight(), null, sprmList);
            }
            if (newTAP.GetItcMac() > 0)
            {
                int itcMac = newTAP.GetItcMac();
                byte[] buf = new byte[1 + (LittleEndianConsts.SHORT_SIZE * (itcMac + 1)) + (TableCellDescriptor.SIZE * itcMac)];
                buf[0] = (byte)itcMac;

                short[] dxaCenters = newTAP.GetRgdxaCenter();
                for (int x = 0; x < dxaCenters.Length; x++)
                {
                    LittleEndian.PutShort(buf, 1 + (x * LittleEndianConsts.SHORT_SIZE),
                                          dxaCenters[x]);
                }

                TableCellDescriptor[] cellDescriptors = newTAP.GetRgtc();
                for (int x = 0; x < cellDescriptors.Length; x++)
                {
                    cellDescriptors[x].Serialize(buf,
                      1 + ((itcMac + 1) * LittleEndianConsts.SHORT_SIZE) + (x * TableCellDescriptor.SIZE));
                }
                size += SprmUtils.AddSpecialSprm(unchecked((short)0xD608), buf, sprmList);

                //      buf = new byte[(itcMac * ShadingDescriptor.SIZE) + 1];
                //      buf[0] = (byte)itcMac;
                //      ShadingDescriptor[] shds = newTAP.GetRgshd();
                //      for (int x = 0; x < itcMac; x++)
                //      {
                //        shds[x].Serialize(buf, 1 + (x * ShadingDescriptor.SIZE));
                //      }
                //      size += SprmUtils.AddSpecialSprm((short)0xD609, buf, sprmList);
            }
            if (newTAP.GetTlp() != 0)
            {
                size += SprmUtils.AddSprm((short)0x740a, newTAP.GetTlp(), null, sprmList);
            }

            return SprmUtils.GetGrpprl(sprmList, size);
        }
示例#8
0
文件: Paragraph.cs 项目: 89sos98/npoi
 internal void SetTableRowEnd(TableProperties props)
 {
     SetTableRowEnd(true);
     byte[] grpprl = TableSprmCompressor.CompressTableProperty(props);
     _papx.Append(grpprl);
 }
示例#9
0
文件: Paragraph.cs 项目: zzy092/npoi
 internal void SetTableRowEnd(TableProperties props)
 {
     SetTableRowEnd(true);
     byte[] grpprl = TableSprmCompressor.CompressTableProperty(props);
     _papx.Append(grpprl);
 }