public static TableCellDescriptor ConvertBytesToTC(byte[] buf, int offset) { TableCellDescriptor tc = new TableCellDescriptor(); tc.FillFields(buf, offset); return(tc); }
public TableProperties(int columns) { field_7_itcMac = (short)columns; field_10_rgshd = new ShadingDescriptor[columns]; for (int x = 0; x < columns; x++) { field_10_rgshd[x] = new ShadingDescriptor(); } field_11_brcBottom = new BorderCode(); field_12_brcTop = new BorderCode(); field_13_brcLeft = new BorderCode(); field_14_brcRight = new BorderCode(); field_15_brcVertical = new BorderCode(); field_16_brcHorizontal = new BorderCode(); field_8_rgdxaCenter = new short[columns]; field_9_rgtc = new TableCellDescriptor[columns]; for (int x = 0; x < columns; x++) { field_9_rgtc[x] = new TableCellDescriptor(); } }
public static TableCellDescriptor ConvertBytesToTC(byte[] buf, int offset) { TableCellDescriptor tc = new TableCellDescriptor(); tc.FillFields(buf, offset); return tc; }
/** * Set the rgtc field for the TAP record. */ public void SetRgtc(TableCellDescriptor[] field_9_rgtc) { this.field_9_rgtc = field_9_rgtc; }
/** * 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; } }
private void initCells() { if (_cellsFound) { return; } short expectedCellsCount = _tprops.GetItcMac(); int lastCellStart = 0; List <TableCell> cells = new List <TableCell>( expectedCellsCount + 1); for (int p = 0; p < NumParagraphs; p++) { Paragraph paragraph = GetParagraph(p); String s = paragraph.Text; if (((s.Length > 0 && s[s.Length - 1] == TABLE_CELL_MARK) || paragraph .IsEmbeddedCellMark()) && paragraph.GetTableLevel() == _levelNum) { TableCellDescriptor tableCellDescriptor = _tprops.GetRgtc() != null && _tprops.GetRgtc().Length > cells.Count ? _tprops .GetRgtc()[cells.Count] : new TableCellDescriptor(); short leftEdge = (_tprops.GetRgdxaCenter() != null && _tprops.GetRgdxaCenter().Length > cells.Count) ? (short)_tprops .GetRgdxaCenter()[cells.Count] : (short)0; short rightEdge = (_tprops.GetRgdxaCenter() != null && _tprops.GetRgdxaCenter().Length > cells.Count + 1) ? (short)_tprops .GetRgdxaCenter()[cells.Count + 1] : (short)0; TableCell tableCell = new TableCell(GetParagraph( lastCellStart).StartOffset, GetParagraph(p) .EndOffset, this, _levelNum, tableCellDescriptor, leftEdge, rightEdge - leftEdge); cells.Add(tableCell); lastCellStart = p + 1; } } if (lastCellStart < (NumParagraphs - 1)) { TableCellDescriptor tableCellDescriptor = _tprops.GetRgtc() != null && _tprops.GetRgtc().Length > cells.Count ? _tprops .GetRgtc()[cells.Count] : new TableCellDescriptor(); short leftEdge = _tprops.GetRgdxaCenter() != null && _tprops.GetRgdxaCenter().Length > cells.Count ? (short)_tprops .GetRgdxaCenter()[cells.Count] : (short)0; short rightEdge = _tprops.GetRgdxaCenter() != null && _tprops.GetRgdxaCenter().Length > cells.Count + 1 ? (short)_tprops .GetRgdxaCenter()[cells.Count + 1] : (short)0; TableCell tableCell = new TableCell(lastCellStart, (NumParagraphs - 1), this, _levelNum, tableCellDescriptor, leftEdge, rightEdge - leftEdge); cells.Add(tableCell); } if (cells.Count > 0) { TableCell lastCell = cells[cells.Count - 1]; if (lastCell.NumParagraphs == 1 && (lastCell.GetParagraph(0).IsTableRowEnd())) { // remove "fake" cell cells.RemoveAt(cells.Count - 1); } } if (cells.Count != expectedCellsCount) { _tprops.SetItcMac((short)cells.Count); } _cells = cells.ToArray(); _cellsFound = true; }