override public void AfterParentSet() { // Anmerkung: In OOXML kann ein Character-Properties-Element sich // nicht über mehrere Paragraphen hinweg erstrecken. // TODO: War das im Binärformat der Fall? // TODO: FindParentByType? FindChildByType? FindSiblingByType? ClientTextbox textbox = this.ParentRecord as ClientTextbox; if (textbox == null) { throw new Exception("Record of type StyleTextPropAtom doesn't have parent of type ClientTextbox"); } TextAtom textAtom = textbox.Children.Find( delegate(Record sibling) { return(sibling is TextAtom); } ) as TextAtom; /* This can legitimately happen... */ if (textAtom == null) { this.Reader.Read(new char[this.BodySize], 0, (int)this.BodySize); return; } // TODO: Length in bytes? UTF-16 characters? Full width unicode characters? uint seenLength = 0; while (seenLength < textAtom.Text.Length) { ParagraphRun run = new ParagraphRun(this.Reader); Console.WriteLine(run.ToString()); Console.WriteLine(" Text = {0}", Utils.StringInspect( textAtom.Text.Substring((int)seenLength, (int)run.Length))); Console.WriteLine(); seenLength += run.Length; } seenLength = 0; while (seenLength < textAtom.Text.Length) { CharacterRun run = new CharacterRun(this.Reader); Console.WriteLine(run.ToString()); Console.WriteLine(" Text = {0}", Utils.StringInspect( textAtom.Text.Substring((int)seenLength, (int)run.Length))); Console.WriteLine(); seenLength += run.Length; } }
public void writepPr(CharacterRun cr, ParagraphRun pr, ParagraphRun9 pr9, int IndentLevel, bool isTitle, bool isDefault) { //TextMasterStyleAtom defaultStyle = _ctx.Ppt.DocumentRecord.FirstChildWithType<b2xtranslator.PptFileFormat.Environment>().FirstChildWithType<TextMasterStyleAtom>(); this._writer.WriteStartElement("a", "lvl" + (IndentLevel + 1).ToString() + "pPr", OpenXmlNamespaces.DrawingML); //marL if (pr.LeftMarginPresent && !isDefault) { this._writer.WriteAttributeString("marL", Utils.MasterCoordToEMU((int)pr.LeftMargin).ToString()); } //marR //lvl if (pr.IndentLevel > 0) { this._writer.WriteAttributeString("lvl", pr.IndentLevel.ToString()); } //indent if (pr.IndentPresent && !isDefault) { this._writer.WriteAttributeString("indent", (-1 * (Utils.MasterCoordToEMU((int)(pr.LeftMargin - pr.Indent)))).ToString()); } //algn if (pr.AlignmentPresent) { switch (pr.Alignment) { case 0x0000: //Left this._writer.WriteAttributeString("algn", "l"); break; case 0x0001: //Center this._writer.WriteAttributeString("algn", "ctr"); break; case 0x0002: //Right this._writer.WriteAttributeString("algn", "r"); break; case 0x0003: //Justify this._writer.WriteAttributeString("algn", "just"); break; case 0x0004: //Distributed this._writer.WriteAttributeString("algn", "dist"); break; case 0x0005: //ThaiDistributed this._writer.WriteAttributeString("algn", "thaiDist"); break; case 0x0006: //JustifyLow this._writer.WriteAttributeString("algn", "justLow"); break; } } //defTabSz if (pr.DefaultTabSizePresent) { this._writer.WriteAttributeString("defTabSz", Utils.MasterCoordToEMU((int)pr.DefaultTabSize).ToString()); } //rtl if (pr.TextDirectionPresent) { switch (pr.TextDirection) { case 0x0000: this._writer.WriteAttributeString("rtl", "0"); break; case 0x0001: this._writer.WriteAttributeString("rtl", "1"); break; } } else { this._writer.WriteAttributeString("rtl", "0"); } //eaLnkBrk //fontAlgn if (pr.FontAlignPresent) { switch (pr.FontAlign) { case 0x0000: //Roman this._writer.WriteAttributeString("fontAlgn", "base"); break; case 0x0001: //Hanging this._writer.WriteAttributeString("fontAlgn", "t"); break; case 0x0002: //Center this._writer.WriteAttributeString("fontAlgn", "ctr"); break; case 0x0003: //UpholdFixed this._writer.WriteAttributeString("fontAlgn", "b"); break; } } //latinLnBrk //hangingPunct //lnSpc //spcBef if (pr.SpaceBeforePresent) { this._writer.WriteStartElement("a", "spcBef", OpenXmlNamespaces.DrawingML); if (pr.SpaceBefore < 0) { this._writer.WriteStartElement("a", "spcPts", OpenXmlNamespaces.DrawingML); this._writer.WriteAttributeString("val", (-1 * 12 * pr.SpaceBefore).ToString()); //TODO: the 12 is wrong this._writer.WriteEndElement(); //spcPct } else { this._writer.WriteStartElement("a", "spcPct", OpenXmlNamespaces.DrawingML); this._writer.WriteAttributeString("val", (1000 * pr.SpaceBefore).ToString()); this._writer.WriteEndElement(); //spcPct } this._writer.WriteEndElement(); //spcBef this.lastSpaceBefore = (int)pr.SpaceBefore; } else { if (this.lastSpaceBefore != 0) { this._writer.WriteStartElement("a", "spcBef", OpenXmlNamespaces.DrawingML); if (this.lastSpaceBefore < 0) { this._writer.WriteStartElement("a", "spcPts", OpenXmlNamespaces.DrawingML); this._writer.WriteAttributeString("val", (-1 * 12 * this.lastSpaceBefore).ToString()); //TODO: the 12 is wrong this._writer.WriteEndElement(); //spcPct } else { this._writer.WriteStartElement("a", "spcPct", OpenXmlNamespaces.DrawingML); this._writer.WriteAttributeString("val", (1000 * this.lastSpaceBefore).ToString()); this._writer.WriteEndElement(); //spcPct } this._writer.WriteEndElement(); //spcBef } } //spcAft if (pr.SpaceAfterPresent) { this._writer.WriteStartElement("a", "spcAft", OpenXmlNamespaces.DrawingML); if (pr.SpaceAfter < 0) { this._writer.WriteStartElement("a", "spcPts", OpenXmlNamespaces.DrawingML); this._writer.WriteAttributeString("val", (-1 * pr.SpaceAfter).ToString()); //TODO: this has to be verified! this._writer.WriteEndElement(); //spcPct } else { this._writer.WriteStartElement("a", "spcPct", OpenXmlNamespaces.DrawingML); this._writer.WriteAttributeString("val", pr.SpaceAfter.ToString()); this._writer.WriteEndElement(); //spcPct } this._writer.WriteEndElement(); //spcAft } //EG_TextBulletColor //EG_TextBulletSize //EG_TextBulletTypeFace //EG_TextBullet bool bulletwritten = false; if (pr9 != null) { if (pr9.BulletBlipReferencePresent) { foreach (var progtags in this._ctx.Ppt.DocumentRecord.FirstChildWithType <List>().AllChildrenWithType <ProgTags>()) { foreach (var bintags in progtags.AllChildrenWithType <ProgBinaryTag>()) { foreach (var data in bintags.AllChildrenWithType <ProgBinaryTagDataBlob>()) { foreach (var blips in data.AllChildrenWithType <BlipCollection9Container>()) { if (blips.Children.Count > pr9.bulletblipref & pr9.bulletblipref > -1) { ImagePart imgPart = null; var b = ((BlipEntityAtom)blips.Children[pr9.bulletblipref]).blip; if (b == null) { var mb = ((BlipEntityAtom)blips.Children[pr9.bulletblipref]).mblip; imgPart = this._parentSlideMapping.targetPart.AddImagePart(ShapeTreeMapping.getImageType(mb.TypeCode)); imgPart.TargetDirectory = "..\\media"; var outStream = imgPart.GetStream(); var decompressed = mb.Decrompress(); outStream.Write(decompressed, 0, decompressed.Length); //outStream.Write(mb.m_pvBits, 0, mb.m_pvBits.Length); } else { imgPart = this._parentSlideMapping.targetPart.AddImagePart(ShapeTreeMapping.getImageType(b.TypeCode)); imgPart.TargetDirectory = "..\\media"; var outStream = imgPart.GetStream(); outStream.Write(b.m_pvBits, 0, b.m_pvBits.Length); } this._writer.WriteStartElement("a", "buBlip", OpenXmlNamespaces.DrawingML); this._writer.WriteStartElement("a", "blip", OpenXmlNamespaces.DrawingML); this._writer.WriteAttributeString("r", "embed", OpenXmlNamespaces.Relationships, imgPart.RelIdToString); this._writer.WriteEndElement(); //blip this._writer.WriteEndElement(); //buBlip bulletwritten = true; } } } } } } } if (!bulletwritten & !isTitle) { if (pr.BulletFlagsFieldPresent & (pr.BulletFlags & (ushort)ParagraphMask.HasBullet) == 0) { this._writer.WriteElementString("a", "buNone", OpenXmlNamespaces.DrawingML, ""); } else { if (pr.BulletColorPresent && (!(pr.BulletFlagsFieldPresent && (pr.BulletFlags & 1 << 2) == 0))) { writeBuClr((RegularContainer)this._Master, pr.BulletColor, ref this.lastBulletColor); } else if (this.lastBulletColor.Length > 0) { this._writer.WriteStartElement("a", "buClr", OpenXmlNamespaces.DrawingML); this._writer.WriteStartElement("a", "srgbClr", OpenXmlNamespaces.DrawingML); this._writer.WriteAttributeString("val", this.lastBulletColor); this._writer.WriteEndElement(); this._writer.WriteEndElement(); //buClr } if (pr.BulletSizePresent) { if (pr.BulletSize > 0 && pr.BulletSize != 100) { this._writer.WriteStartElement("a", "buSzPct", OpenXmlNamespaces.DrawingML); this._writer.WriteAttributeString("val", (pr.BulletSize * 1000).ToString()); this._writer.WriteEndElement(); //buSzPct } else { //TODO } } if (pr.BulletFontPresent) { this._writer.WriteStartElement("a", "buFont", OpenXmlNamespaces.DrawingML); var fonts = this._ctx.Ppt.DocumentRecord.FirstChildWithType <b2xtranslator.PptFileFormat.Environment>().FirstChildWithType <FontCollection>(); var entity = fonts.entities[(int)pr.BulletTypefaceIdx]; if (entity.TypeFace.IndexOf('\0') > 0) { this._writer.WriteAttributeString("typeface", entity.TypeFace.Substring(0, entity.TypeFace.IndexOf('\0'))); } else { this._writer.WriteAttributeString("typeface", entity.TypeFace); } this._writer.WriteEndElement(); //buChar this.lastBulletFont = entity.TypeFace; } else if (this.lastBulletFont.Length > 0) { this._writer.WriteStartElement("a", "buFont", OpenXmlNamespaces.DrawingML); if (this.lastBulletFont.IndexOf('\0') > 0) { this._writer.WriteAttributeString("typeface", this.lastBulletFont.Substring(0, this.lastBulletFont.IndexOf('\0'))); } else { this._writer.WriteAttributeString("typeface", this.lastBulletFont); } this._writer.WriteEndElement(); //buChar } if (pr.BulletCharPresent) { this._writer.WriteStartElement("a", "buChar", OpenXmlNamespaces.DrawingML); this._writer.WriteAttributeString("char", pr.BulletChar.ToString()); this._writer.WriteEndElement(); //buChar this.lastBulletChar = pr.BulletChar.ToString(); } else if (this.lastBulletChar.Length > 0) { this._writer.WriteStartElement("a", "buChar", OpenXmlNamespaces.DrawingML); this._writer.WriteAttributeString("char", this.lastBulletChar); this._writer.WriteEndElement(); //buChar } } } //tabLst //defRPr //extLst new CharacterRunPropsMapping(this._ctx, this._writer).Apply(cr, "defRPr", (RegularContainer)this._Master, ref this.lastColor, ref this.lastSize, ref this.lastTypeface, "", "", null, IndentLevel, null, null, 0, false); this._writer.WriteEndElement(); //lvlXpPr }
public void writepPr(CharacterRun cr, ParagraphRun pr, ParagraphRun9 pr9, int IndentLevel, bool isTitle) { writepPr(cr, pr, pr9, IndentLevel, isTitle, false); }