public void Apply(TablePropertyExceptions tapx) { XmlElement tblBorders = _nodeFactory.CreateElement("w", "tblBorders", OpenXmlNamespaces.WordprocessingML); XmlElement tblCellMar = _nodeFactory.CreateElement("w", "tblCellMar", OpenXmlNamespaces.WordprocessingML); XmlElement tblLayout = _nodeFactory.CreateElement("w", "tblLayout", OpenXmlNamespaces.WordprocessingML); XmlElement tblpPr = _nodeFactory.CreateElement("w", "tblpPr", OpenXmlNamespaces.WordprocessingML); XmlAttribute layoutType = _nodeFactory.CreateAttribute("w", "type", OpenXmlNamespaces.WordprocessingML); layoutType.Value = "fixed"; Int16 tblIndent = 0; Int16 gabHalf = 0; Int16 marginLeft = 0; Int16 marginRight = 0; foreach (SinglePropertyModifier sprm in tapx.grpprl) { switch (sprm.OpCode) { case SinglePropertyModifier.OperationCode.sprmTDxaGapHalf: gabHalf = System.BitConverter.ToInt16(sprm.Arguments, 0); break; //table definition case SinglePropertyModifier.OperationCode.sprmTDefTable: SprmTDefTable tDef = new SprmTDefTable(sprm.Arguments); //Workaround for retrieving the indent of the table: //In some files there is a indent but no sprmTWidthIndent is set. //For this cases we can calculate the indent of the table by getting the //first boundary of the TDef and adding the padding of the cells tblIndent = System.BitConverter.ToInt16(sprm.Arguments, 1); //add the gabHalf tblIndent += gabHalf; //If there follows a real sprmTWidthIndent, this value will be overwritten break; //preferred table width case SinglePropertyModifier.OperationCode.sprmTTableWidth: WidthType fts = (WidthType)sprm.Arguments[0]; Int16 width = System.BitConverter.ToInt16(sprm.Arguments, 1); XmlElement tblW = _nodeFactory.CreateElement("w", "tblW", OpenXmlNamespaces.WordprocessingML); XmlAttribute w = _nodeFactory.CreateAttribute("w", "w", OpenXmlNamespaces.WordprocessingML); w.Value = width.ToString(); XmlAttribute type = _nodeFactory.CreateAttribute("w", "type", OpenXmlNamespaces.WordprocessingML); type.Value = fts.ToString(); tblW.Attributes.Append(type); tblW.Attributes.Append(w); _tblPr.AppendChild(tblW); break; //justification case SinglePropertyModifier.OperationCode.sprmTJc: case SinglePropertyModifier.OperationCode.sprmTJcRow: appendValueElement(_tblPr, "jc", ((Global.JustificationCode)sprm.Arguments[0]).ToString(), true); break; //indent case SinglePropertyModifier.OperationCode.sprmTWidthIndent: tblIndent = System.BitConverter.ToInt16(sprm.Arguments, 1); break; //style case SinglePropertyModifier.OperationCode.sprmTIstd: case SinglePropertyModifier.OperationCode.sprmTIstdPermute: Int16 styleIndex = System.BitConverter.ToInt16(sprm.Arguments, 0); if (_styles.Styles.Count > styleIndex) { string id = StyleSheetMapping.MakeStyleId(_styles.Styles[styleIndex]); if (id != "TableNormal") { appendValueElement(_tblPr, "tblStyle", id, true); } } break; //bidi case SinglePropertyModifier.OperationCode.sprmTFBiDi: case SinglePropertyModifier.OperationCode.sprmTFBiDi90: appendValueElement(_tblPr, "bidiVisual", System.BitConverter.ToInt16(sprm.Arguments, 0).ToString(), true); break; //table look case SinglePropertyModifier.OperationCode.sprmTTlp: appendValueElement(_tblPr, "tblLook", String.Format("{0:x4}", System.BitConverter.ToInt16(sprm.Arguments, 2)), true); break; //autofit case SinglePropertyModifier.OperationCode.sprmTFAutofit: if (sprm.Arguments[0] == 1) { layoutType.Value = "auto"; } break; //default cell padding (margin) case SinglePropertyModifier.OperationCode.sprmTCellPadding: case SinglePropertyModifier.OperationCode.sprmTCellPaddingDefault: case SinglePropertyModifier.OperationCode.sprmTCellPaddingOuter: byte grfbrc = sprm.Arguments[2]; Int16 wMar = System.BitConverter.ToInt16(sprm.Arguments, 4); if (Utils.BitmaskToBool((int)grfbrc, 0x01)) { appendDxaElement(tblCellMar, "top", wMar.ToString(), true); } if (Utils.BitmaskToBool((int)grfbrc, 0x02)) { marginLeft = wMar; } if (Utils.BitmaskToBool((int)grfbrc, 0x04)) { appendDxaElement(tblCellMar, "bottom", wMar.ToString(), true); } if (Utils.BitmaskToBool((int)grfbrc, 0x08)) { marginRight = wMar; } break; //row count case SinglePropertyModifier.OperationCode.sprmTCHorzBands: appendValueElement(_tblPr, "tblStyleRowBandSize", sprm.Arguments[0].ToString(), true); break; //col count case SinglePropertyModifier.OperationCode.sprmTCVertBands: appendValueElement(_tblPr, "tblStyleColBandSize", sprm.Arguments[0].ToString(), true); break; //overlap case SinglePropertyModifier.OperationCode.sprmTFNoAllowOverlap: bool noOverlap = Utils.ByteToBool(sprm.Arguments[0]); string tblOverlapVal = "overlap"; if (noOverlap) { tblOverlapVal = "never"; } appendValueElement(_tblPr, "tblOverlap", tblOverlapVal, true); break; //shading case SinglePropertyModifier.OperationCode.sprmTSetShdTable: ShadingDescriptor desc = new ShadingDescriptor(sprm.Arguments); appendShading(_tblPr, desc); break; //borders 80 exceptions case SinglePropertyModifier.OperationCode.sprmTTableBorders80: byte[] brc80 = new byte[4]; //top border Array.Copy(sprm.Arguments, 0, brc80, 0, 4); brcTop = new BorderCode(brc80); //left Array.Copy(sprm.Arguments, 4, brc80, 0, 4); brcLeft = new BorderCode(brc80); //bottom Array.Copy(sprm.Arguments, 8, brc80, 0, 4); brcBottom = new BorderCode(brc80); //right Array.Copy(sprm.Arguments, 12, brc80, 0, 4); brcRight = new BorderCode(brc80); //inside H Array.Copy(sprm.Arguments, 16, brc80, 0, 4); brcHorz = new BorderCode(brc80); //inside V Array.Copy(sprm.Arguments, 20, brc80, 0, 4); brcVert = new BorderCode(brc80); break; //border exceptions case SinglePropertyModifier.OperationCode.sprmTTableBorders: byte[] brc = new byte[8]; //top border Array.Copy(sprm.Arguments, 0, brc, 0, 8); brcTop = new BorderCode(brc); //left Array.Copy(sprm.Arguments, 8, brc, 0, 8); brcLeft = new BorderCode(brc); //bottom Array.Copy(sprm.Arguments, 16, brc, 0, 8); brcBottom = new BorderCode(brc); //right Array.Copy(sprm.Arguments, 24, brc, 0, 8); brcRight = new BorderCode(brc); //inside H Array.Copy(sprm.Arguments, 32, brc, 0, 8); brcHorz = new BorderCode(brc); //inside V Array.Copy(sprm.Arguments, 40, brc, 0, 8); brcVert = new BorderCode(brc); break; //floating table properties case SinglePropertyModifier.OperationCode.sprmTPc: byte flag = sprm.Arguments[0]; Global.VerticalPositionCode pcVert = (Global.VerticalPositionCode)((flag & 0x30) >> 4); Global.HorizontalPositionCode pcHorz = (Global.HorizontalPositionCode)((flag & 0xC0) >> 6); appendValueAttribute(tblpPr, "horzAnchor", pcHorz.ToString()); appendValueAttribute(tblpPr, "vertAnchor", pcVert.ToString()); break; case SinglePropertyModifier.OperationCode.sprmTDxaFromText: appendValueAttribute(tblpPr, "leftFromText", System.BitConverter.ToInt16(sprm.Arguments, 0).ToString()); break; case SinglePropertyModifier.OperationCode.sprmTDxaFromTextRight: appendValueAttribute(tblpPr, "rightFromText", System.BitConverter.ToInt16(sprm.Arguments, 0).ToString()); break; case SinglePropertyModifier.OperationCode.sprmTDyaFromText: appendValueAttribute(tblpPr, "topFromText", System.BitConverter.ToInt16(sprm.Arguments, 0).ToString()); break; case SinglePropertyModifier.OperationCode.sprmTDyaFromTextBottom: appendValueAttribute(tblpPr, "bottomFromText", System.BitConverter.ToInt16(sprm.Arguments, 0).ToString()); break; case SinglePropertyModifier.OperationCode.sprmTDxaAbs: appendValueAttribute(tblpPr, "tblpX", System.BitConverter.ToInt16(sprm.Arguments, 0).ToString()); break; case SinglePropertyModifier.OperationCode.sprmTDyaAbs: appendValueAttribute(tblpPr, "tblpY", System.BitConverter.ToInt16(sprm.Arguments, 0).ToString()); break; } } //indent if (tblIndent != 0) { XmlElement tblInd = _nodeFactory.CreateElement("w", "tblInd", OpenXmlNamespaces.WordprocessingML); XmlAttribute tblIndW = _nodeFactory.CreateAttribute("w", "w", OpenXmlNamespaces.WordprocessingML); tblIndW.Value = tblIndent.ToString(); tblInd.Attributes.Append(tblIndW); XmlAttribute tblIndType = _nodeFactory.CreateAttribute("w", "type", OpenXmlNamespaces.WordprocessingML); tblIndType.Value = "dxa"; tblInd.Attributes.Append(tblIndType); _tblPr.AppendChild(tblInd); } //append floating props if (tblpPr.Attributes.Count > 0) { _tblPr.AppendChild(tblpPr); } //set borders if (brcTop != null) { XmlNode topBorder = _nodeFactory.CreateNode(XmlNodeType.Element, "w", "top", OpenXmlNamespaces.WordprocessingML); appendBorderAttributes(brcTop, topBorder); addOrSetBorder(_tblBorders, topBorder); } if (brcLeft != null) { XmlNode leftBorder = _nodeFactory.CreateNode(XmlNodeType.Element, "w", "left", OpenXmlNamespaces.WordprocessingML); appendBorderAttributes(brcLeft, leftBorder); addOrSetBorder(_tblBorders, leftBorder); } if (brcBottom != null) { XmlNode bottomBorder = _nodeFactory.CreateNode(XmlNodeType.Element, "w", "bottom", OpenXmlNamespaces.WordprocessingML); appendBorderAttributes(brcBottom, bottomBorder); addOrSetBorder(_tblBorders, bottomBorder); } if (brcRight != null) { XmlNode rightBorder = _nodeFactory.CreateNode(XmlNodeType.Element, "w", "right", OpenXmlNamespaces.WordprocessingML); appendBorderAttributes(brcRight, rightBorder); addOrSetBorder(_tblBorders, rightBorder); } if (brcHorz != null) { XmlNode insideHBorder = _nodeFactory.CreateNode(XmlNodeType.Element, "w", "insideH", OpenXmlNamespaces.WordprocessingML); appendBorderAttributes(brcHorz, insideHBorder); addOrSetBorder(_tblBorders, insideHBorder); } if (brcVert != null) { XmlNode insideVBorder = _nodeFactory.CreateNode(XmlNodeType.Element, "w", "insideV", OpenXmlNamespaces.WordprocessingML); appendBorderAttributes(brcVert, insideVBorder); addOrSetBorder(_tblBorders, insideVBorder); } if (_tblBorders.ChildNodes.Count > 0) { _tblPr.AppendChild(_tblBorders); } //append layout type tblLayout.Attributes.Append(layoutType); _tblPr.AppendChild(tblLayout); //append margins if (marginLeft == 0 && gabHalf != 0) { appendDxaElement(tblCellMar, "left", gabHalf.ToString(), true); } else { appendDxaElement(tblCellMar, "left", marginLeft.ToString(), true); } if (marginRight == 0 && gabHalf != 0) { appendDxaElement(tblCellMar, "right", gabHalf.ToString(), true); } else { appendDxaElement(tblCellMar, "right", marginRight.ToString(), true); } _tblPr.AppendChild(tblCellMar); //write Properties if (_tblPr.ChildNodes.Count > 0 || _tblPr.Attributes.Count > 0) { _tblPr.WriteTo(_writer); } //append the grid _tblGrid = _nodeFactory.CreateElement("w", "tblGrid", OpenXmlNamespaces.WordprocessingML); foreach (Int16 colW in _grid) { XmlElement gridCol = _nodeFactory.CreateElement("w", "gridCol", OpenXmlNamespaces.WordprocessingML); XmlAttribute gridColW = _nodeFactory.CreateAttribute("w", "w", OpenXmlNamespaces.WordprocessingML); gridColW.Value = colW.ToString(); gridCol.Attributes.Append(gridColW); _tblGrid.AppendChild(gridCol); } _tblGrid.WriteTo(_writer); }
public void Apply(ParagraphPropertyExceptions papx) { XmlElement ind = _nodeFactory.CreateElement("w", "ind", OpenXmlNamespaces.WordprocessingML); XmlElement numPr = _nodeFactory.CreateElement("w", "numPr", OpenXmlNamespaces.WordprocessingML); XmlElement pBdr = _nodeFactory.CreateElement("w", "pBdr", OpenXmlNamespaces.WordprocessingML); XmlElement spacing = _nodeFactory.CreateElement("w", "spacing", OpenXmlNamespaces.WordprocessingML); XmlElement jc = null; //append style id , do not append "Normal" style (istd 0) XmlElement pStyle = _nodeFactory.CreateElement("w", "pStyle", OpenXmlNamespaces.WordprocessingML); XmlAttribute styleId = _nodeFactory.CreateAttribute("w", "val", OpenXmlNamespaces.WordprocessingML); styleId.Value = StyleSheetMapping.MakeStyleId(_parentDoc.Styles.Styles[papx.istd]); pStyle.Attributes.Append(styleId); _pPr.AppendChild(pStyle); //append formatting of paragraph end mark if (_paraEndChpx != null) { XmlElement rPr = _nodeFactory.CreateElement("w", "rPr", OpenXmlNamespaces.WordprocessingML); //append properties _paraEndChpx.Convert(new CharacterPropertiesMapping(rPr, _ctx.Doc, new RevisionData(_paraEndChpx), papx, false)); RevisionData rev = new RevisionData(_paraEndChpx); //append delete infos if (rev.Type == RevisionData.RevisionType.Deleted) { XmlElement del = _nodeFactory.CreateElement("w", "del", OpenXmlNamespaces.WordprocessingML); rPr.AppendChild(del); } if (rPr.ChildNodes.Count > 0) { _pPr.AppendChild(rPr); } } bool isRightToLeft = false; foreach (SinglePropertyModifier sprm in papx.grpprl) { switch (sprm.OpCode) { //rsid for paragraph property enditing (write to parent element) case SinglePropertyModifier.OperationCode.sprmPRsid: string rsid = String.Format("{0:x8}", System.BitConverter.ToInt32(sprm.Arguments, 0)); _ctx.AddRsid(rsid); _writer.WriteAttributeString("w", "rsidP", OpenXmlNamespaces.WordprocessingML, rsid); break; //attributes case SinglePropertyModifier.OperationCode.sprmPIpgp: XmlAttribute divId = _nodeFactory.CreateAttribute("w", "divId", OpenXmlNamespaces.WordprocessingML); divId.Value = System.BitConverter.ToUInt32(sprm.Arguments, 0).ToString(); _pPr.Attributes.Append(divId); break; case SinglePropertyModifier.OperationCode.sprmPFAutoSpaceDE: appendFlagAttribute(_pPr, sprm, "autoSpaceDE"); break; case SinglePropertyModifier.OperationCode.sprmPFAutoSpaceDN: appendFlagAttribute(_pPr, sprm, "autoSpaceDN"); break; case SinglePropertyModifier.OperationCode.sprmPFContextualSpacing: appendFlagAttribute(_pPr, sprm, "contextualSpacing"); break; //element flags case SinglePropertyModifier.OperationCode.sprmPFBiDi: isRightToLeft = true; appendFlagElement(_pPr, sprm, "bidi", true); break; case SinglePropertyModifier.OperationCode.sprmPFKeep: appendFlagElement(_pPr, sprm, "keepLines", true); break; case SinglePropertyModifier.OperationCode.sprmPFKeepFollow: appendFlagElement(_pPr, sprm, "keepNext", true); break; case SinglePropertyModifier.OperationCode.sprmPFKinsoku: appendFlagElement(_pPr, sprm, "kinsoku", true); break; case SinglePropertyModifier.OperationCode.sprmPFOverflowPunct: appendFlagElement(_pPr, sprm, "overflowPunct", true); break; case SinglePropertyModifier.OperationCode.sprmPFPageBreakBefore: appendFlagElement(_pPr, sprm, "pageBreakBefore", true); break; case SinglePropertyModifier.OperationCode.sprmPFNoAutoHyph: appendFlagElement(_pPr, sprm, "su_pPressAutoHyphens", true); break; case SinglePropertyModifier.OperationCode.sprmPFNoLineNumb: appendFlagElement(_pPr, sprm, "su_pPressLineNumbers", true); break; case SinglePropertyModifier.OperationCode.sprmPFNoAllowOverlap: appendFlagElement(_pPr, sprm, "su_pPressOverlap", true); break; case SinglePropertyModifier.OperationCode.sprmPFTopLinePunct: appendFlagElement(_pPr, sprm, "topLinePunct", true); break; case SinglePropertyModifier.OperationCode.sprmPFWidowControl: appendFlagElement(_pPr, sprm, "widowControl", true); break; case SinglePropertyModifier.OperationCode.sprmPFWordWrap: appendFlagElement(_pPr, sprm, "wordWrap", true); break; //indentation case SinglePropertyModifier.OperationCode.sprmPDxaLeft: case SinglePropertyModifier.OperationCode.sprmPDxaLeft80: case SinglePropertyModifier.OperationCode.sprmPNest: case SinglePropertyModifier.OperationCode.sprmPNest80: appendValueAttribute(ind, "left", System.BitConverter.ToInt16(sprm.Arguments, 0).ToString()); break; case SinglePropertyModifier.OperationCode.sprmPDxcLeft: appendValueAttribute(ind, "leftChars", System.BitConverter.ToInt16(sprm.Arguments, 0).ToString()); break; case SinglePropertyModifier.OperationCode.sprmPDxaLeft1: case SinglePropertyModifier.OperationCode.sprmPDxaLeft180: Int16 flValue = System.BitConverter.ToInt16(sprm.Arguments, 0); string flName; if (flValue >= 0) { flName = "firstLine"; } else { flName = "hanging"; flValue *= -1; } appendValueAttribute(ind, flName, flValue.ToString()); break; case SinglePropertyModifier.OperationCode.sprmPDxcLeft1: appendValueAttribute(ind, "firstLineChars", System.BitConverter.ToInt16(sprm.Arguments, 0).ToString()); break; case SinglePropertyModifier.OperationCode.sprmPDxaRight: case SinglePropertyModifier.OperationCode.sprmPDxaRight80: appendValueAttribute(ind, "right", System.BitConverter.ToInt16(sprm.Arguments, 0).ToString()); break; case SinglePropertyModifier.OperationCode.sprmPDxcRight: appendValueAttribute(ind, "rightChars", System.BitConverter.ToInt16(sprm.Arguments, 0).ToString()); break; //spacing case SinglePropertyModifier.OperationCode.sprmPDyaBefore: XmlAttribute before = _nodeFactory.CreateAttribute("w", "before", OpenXmlNamespaces.WordprocessingML); before.Value = System.BitConverter.ToUInt16(sprm.Arguments, 0).ToString(); spacing.Attributes.Append(before); break; case SinglePropertyModifier.OperationCode.sprmPDyaAfter: XmlAttribute after = _nodeFactory.CreateAttribute("w", "after", OpenXmlNamespaces.WordprocessingML); after.Value = System.BitConverter.ToUInt16(sprm.Arguments, 0).ToString(); spacing.Attributes.Append(after); break; case SinglePropertyModifier.OperationCode.sprmPFDyaAfterAuto: XmlAttribute afterAutospacing = _nodeFactory.CreateAttribute("w", "afterAutospacing", OpenXmlNamespaces.WordprocessingML); afterAutospacing.Value = sprm.Arguments[0].ToString(); spacing.Attributes.Append(afterAutospacing); break; case SinglePropertyModifier.OperationCode.sprmPFDyaBeforeAuto: XmlAttribute beforeAutospacing = _nodeFactory.CreateAttribute("w", "beforeAutospacing", OpenXmlNamespaces.WordprocessingML); beforeAutospacing.Value = sprm.Arguments[0].ToString(); spacing.Attributes.Append(beforeAutospacing); break; case SinglePropertyModifier.OperationCode.sprmPDyaLine: LineSpacingDescriptor lspd = new LineSpacingDescriptor(sprm.Arguments); XmlAttribute line = _nodeFactory.CreateAttribute("w", "line", OpenXmlNamespaces.WordprocessingML); line.Value = Math.Abs(lspd.dyaLine).ToString(); spacing.Attributes.Append(line); XmlAttribute lineRule = _nodeFactory.CreateAttribute("w", "lineRule", OpenXmlNamespaces.WordprocessingML); if (!lspd.fMultLinespace && lspd.dyaLine < 0) { lineRule.Value = "exact"; } else if (!lspd.fMultLinespace && lspd.dyaLine > 0) { lineRule.Value = "atLeast"; } //no line rule means auto spacing.Attributes.Append(lineRule); break; //justification code case SinglePropertyModifier.OperationCode.sprmPJc: case SinglePropertyModifier.OperationCode.sprmPJc80: jc = _nodeFactory.CreateElement("w", "jc", OpenXmlNamespaces.WordprocessingML); XmlAttribute jcVal = _nodeFactory.CreateAttribute("w", "val", OpenXmlNamespaces.WordprocessingML); jcVal.Value = ((Global.JustificationCode)sprm.Arguments[0]).ToString(); jc.Attributes.Append(jcVal); break; //borders //case 0x461C: case SinglePropertyModifier.OperationCode.sprmPBrcTop: //case 0x4424: case SinglePropertyModifier.OperationCode.sprmPBrcTop80: XmlNode topBorder = _nodeFactory.CreateNode(XmlNodeType.Element, "w", "top", OpenXmlNamespaces.WordprocessingML); appendBorderAttributes(new BorderCode(sprm.Arguments), topBorder); addOrSetBorder(pBdr, topBorder); break; //case 0x461D: case SinglePropertyModifier.OperationCode.sprmPBrcLeft: //case 0x4425: case SinglePropertyModifier.OperationCode.sprmPBrcLeft80: XmlNode leftBorder = _nodeFactory.CreateNode(XmlNodeType.Element, "w", "left", OpenXmlNamespaces.WordprocessingML); appendBorderAttributes(new BorderCode(sprm.Arguments), leftBorder); addOrSetBorder(pBdr, leftBorder); break; //case 0x461E: case SinglePropertyModifier.OperationCode.sprmPBrcBottom: //case 0x4426: case SinglePropertyModifier.OperationCode.sprmPBrcBottom80: XmlNode bottomBorder = _nodeFactory.CreateNode(XmlNodeType.Element, "w", "bottom", OpenXmlNamespaces.WordprocessingML); appendBorderAttributes(new BorderCode(sprm.Arguments), bottomBorder); addOrSetBorder(pBdr, bottomBorder); break; //case 0x461F: case SinglePropertyModifier.OperationCode.sprmPBrcRight: //case 0x4427: case SinglePropertyModifier.OperationCode.sprmPBrcRight80: XmlNode rightBorder = _nodeFactory.CreateNode(XmlNodeType.Element, "w", "right", OpenXmlNamespaces.WordprocessingML); appendBorderAttributes(new BorderCode(sprm.Arguments), rightBorder); addOrSetBorder(pBdr, rightBorder); break; //case 0x4620: case SinglePropertyModifier.OperationCode.sprmPBrcBetween: //case 0x4428: case SinglePropertyModifier.OperationCode.sprmPBrcBetween80: XmlNode betweenBorder = _nodeFactory.CreateNode(XmlNodeType.Element, "w", "between", OpenXmlNamespaces.WordprocessingML); appendBorderAttributes(new BorderCode(sprm.Arguments), betweenBorder); addOrSetBorder(pBdr, betweenBorder); break; //case 0x4621: case SinglePropertyModifier.OperationCode.sprmPBrcBar: //case 0x4629: case SinglePropertyModifier.OperationCode.sprmPBrcBar80: XmlNode barBorder = _nodeFactory.CreateNode(XmlNodeType.Element, "w", "bar", OpenXmlNamespaces.WordprocessingML); appendBorderAttributes(new BorderCode(sprm.Arguments), barBorder); addOrSetBorder(pBdr, barBorder); break; //shading case SinglePropertyModifier.OperationCode.sprmPShd80: case SinglePropertyModifier.OperationCode.sprmPShd: ShadingDescriptor desc = new ShadingDescriptor(sprm.Arguments); appendShading(_pPr, desc); break; //numbering case SinglePropertyModifier.OperationCode.sprmPIlvl: appendValueElement(numPr, "ilvl", sprm.Arguments[0].ToString(), true); break; case SinglePropertyModifier.OperationCode.sprmPIlfo: UInt16 val = System.BitConverter.ToUInt16(sprm.Arguments, 0); appendValueElement(numPr, "numId", val.ToString(), true); ////check if there is a ilvl reference, if not, check the count of LVLs. ////if only one LVL exists in the referenced list, create a hard reference to that LVL //if (containsLvlReference(papx.grpprl) == false) //{ // ListFormatOverride lfo = _ctx.Doc.ListFormatOverrideTable[val]; // int index = NumberingMapping.FindIndexbyId(_ctx.Doc.ListTable, lfo.lsid); // ListData lst = _ctx.Doc.ListTable[index]; // if (lst.rglvl.Length == 1) // { // appendValueElement(numPr, "ilvl", "0", true); // } //} break; //tabs case SinglePropertyModifier.OperationCode.sprmPChgTabsPapx: case SinglePropertyModifier.OperationCode.sprmPChgTabs: XmlElement tabs = _nodeFactory.CreateElement("w", "tabs", OpenXmlNamespaces.WordprocessingML); int pos = 0; //read the removed tabs byte itbdDelMax = sprm.Arguments[pos]; pos++; for (int i = 0; i < itbdDelMax; i++) { XmlElement tab = _nodeFactory.CreateElement("w", "tab", OpenXmlNamespaces.WordprocessingML); //clear XmlAttribute tabsVal = _nodeFactory.CreateAttribute("w", "val", OpenXmlNamespaces.WordprocessingML); tabsVal.Value = "clear"; tab.Attributes.Append(tabsVal); //position XmlAttribute tabsPos = _nodeFactory.CreateAttribute("w", "pos", OpenXmlNamespaces.WordprocessingML); tabsPos.Value = System.BitConverter.ToInt16(sprm.Arguments, pos).ToString(); tab.Attributes.Append(tabsPos); tabs.AppendChild(tab); //skip the tolerence array in sprm 0xC615 if (sprm.OpCode == SinglePropertyModifier.OperationCode.sprmPChgTabs) { pos += 4; } else { pos += 2; } } //read the added tabs byte itbdAddMax = sprm.Arguments[pos]; pos++; for (int i = 0; i < itbdAddMax; i++) { TabDescriptor tbd = new TabDescriptor(sprm.Arguments[pos + (itbdAddMax * 2) + i]); XmlElement tab = _nodeFactory.CreateElement("w", "tab", OpenXmlNamespaces.WordprocessingML); //justification XmlAttribute tabsVal = _nodeFactory.CreateAttribute("w", "val", OpenXmlNamespaces.WordprocessingML); tabsVal.Value = ((Global.JustificationCode)tbd.jc).ToString(); tab.Attributes.Append(tabsVal); //tab leader type XmlAttribute leader = _nodeFactory.CreateAttribute("w", "leader", OpenXmlNamespaces.WordprocessingML); leader.Value = ((Global.TabLeader)tbd.tlc).ToString(); tab.Attributes.Append(leader); //position XmlAttribute tabsPos = _nodeFactory.CreateAttribute("w", "pos", OpenXmlNamespaces.WordprocessingML); tabsPos.Value = System.BitConverter.ToInt16(sprm.Arguments, pos + (i * 2)).ToString(); tab.Attributes.Append(tabsPos); tabs.AppendChild(tab); } _pPr.AppendChild(tabs); break; //frame properties case SinglePropertyModifier.OperationCode.sprmPPc: //position code byte flag = sprm.Arguments[0]; Global.VerticalPositionCode pcVert = (Global.VerticalPositionCode)((flag & 0x30) >> 4); Global.HorizontalPositionCode pcHorz = (Global.HorizontalPositionCode)((flag & 0xC0) >> 6); appendValueAttribute(_framePr, "hAnchor", pcHorz.ToString()); appendValueAttribute(_framePr, "vAnchor", pcVert.ToString()); break; case SinglePropertyModifier.OperationCode.sprmPWr: Global.TextFrameWrapping wrapping = (Global.TextFrameWrapping)sprm.Arguments[0]; appendValueAttribute(_framePr, "wrap", wrapping.ToString()); break; case SinglePropertyModifier.OperationCode.sprmPDxaAbs: Int16 frameX = System.BitConverter.ToInt16(sprm.Arguments, 0); appendValueAttribute(_framePr, "x", frameX.ToString()); break; case SinglePropertyModifier.OperationCode.sprmPDyaAbs: Int16 frameY = System.BitConverter.ToInt16(sprm.Arguments, 0); appendValueAttribute(_framePr, "y", frameY.ToString()); break; case SinglePropertyModifier.OperationCode.sprmPWHeightAbs: Int16 frameHeight = System.BitConverter.ToInt16(sprm.Arguments, 0); appendValueAttribute(_framePr, "h", frameHeight.ToString()); break; case SinglePropertyModifier.OperationCode.sprmPDxaWidth: Int16 frameWidth = System.BitConverter.ToInt16(sprm.Arguments, 0); appendValueAttribute(_framePr, "w", frameWidth.ToString()); break; case SinglePropertyModifier.OperationCode.sprmPDxaFromText: Int16 frameSpaceH = System.BitConverter.ToInt16(sprm.Arguments, 0); appendValueAttribute(_framePr, "hSpace", frameSpaceH.ToString()); break; case SinglePropertyModifier.OperationCode.sprmPDyaFromText: Int16 frameSpaceV = System.BitConverter.ToInt16(sprm.Arguments, 0); appendValueAttribute(_framePr, "vSpace", frameSpaceV.ToString()); break; //outline level case SinglePropertyModifier.OperationCode.sprmPOutLvl: appendValueElement(_pPr, "outlineLvl", sprm.Arguments[0].ToString(), false); break; default: break; } } //append frame properties if (_framePr.Attributes.Count > 0) { _pPr.AppendChild(_framePr); } //append section properties if (_sepx != null) { XmlElement sectPr = _nodeFactory.CreateElement("w", "sectPr", OpenXmlNamespaces.WordprocessingML); _sepx.Convert(new SectionPropertiesMapping(sectPr, _ctx, _sectionNr)); _pPr.AppendChild(sectPr); } //append indent if (ind.Attributes.Count > 0) { _pPr.AppendChild(ind); } //append spacing if (spacing.Attributes.Count > 0) { _pPr.AppendChild(spacing); } //append justification if (jc != null) { XmlAttribute jcVal = jc.Attributes["val", OpenXmlNamespaces.WordprocessingML]; if ((isRightToLeft || isStyleRightToLeft(papx.istd)) && jcVal.Value == "right") { //ignore jc="right" for RTL documents } else { _pPr.AppendChild(jc); } } //append numPr if (numPr.ChildNodes.Count > 0) { _pPr.AppendChild(numPr); } //append borders if (pBdr.ChildNodes.Count > 0) { _pPr.AppendChild(pBdr); } //write Properties if (_pPr.ChildNodes.Count > 0 || _pPr.Attributes.Count > 0) { _pPr.WriteTo(_writer); } }