public Slide(BinaryReader _reader, uint size, uint typeCode, uint version, uint instance) : base(_reader, size, typeCode, version, instance) { foreach (Record rec in Children) { switch (rec.TypeCode) { case 0x3ef: //SlideAtom case 0x3f9: //SlideShowSlideInfoAtom case 0x40c: //DrawingContainer break; case 0x422: //RoundTripContentMasterId12 RoundTripContentMasterId12 id = (RoundTripContentMasterId12)rec; break; case 0x7f0: //SlideSchemeColorSchemeAtom case 0xfa3: //TextMasterStyleAtom case 0xfd9: //SlideHeadersFootersContainer break; case 0x1388: //SlideProgTagsContainer RegularContainer con = (RegularContainer)rec; break; default: break; } } }
public void ApplyHandoutMaster(RegularContainer handoutMaster) { this._Master = handoutMaster; var m = this._ctx.Ppt.MainMasterRecords[0]; var atoms = m.AllChildrenWithType <TextMasterStyleAtom>(); foreach (var atom in atoms) { if (atom.Instance == 2) { this.noteAtoms.Add(atom); } } this._writer.WriteStartElement("p", "handoutStyle", OpenXmlNamespaces.PresentationML); ParagraphRun9 pr9 = null; foreach (var atom in this.noteAtoms) { this.lastSpaceBefore = 0; this.lastBulletFont = ""; this.lastBulletChar = ""; this.lastBulletColor = ""; this.lastColor = ""; this.lastSize = ""; for (int i = 0; i < atom.IndentLevelCount; i++) { pr9 = null; writepPr(atom.CRuns[i], atom.PRuns[i], pr9, i, true); } for (int i = atom.IndentLevelCount; i < 9; i++) { pr9 = null; writepPr(atom.CRuns[0], atom.PRuns[0], pr9, i, true); } } this._writer.WriteEndElement(); }
public void Apply(ShapeOptions so) { RegularContainer slide = so.FirstAncestorWithType <Slide>(); if (slide == null) { slide = so.FirstAncestorWithType <Note>(); } if (slide == null) { slide = so.FirstAncestorWithType <Handout>(); } string colorval = ""; string colorval2 = ""; uint fillType = 0; if (so.OptionsByID.ContainsKey(ShapeOptions.PropertyId.fillType)) { fillType = so.OptionsByID[ShapeOptions.PropertyId.fillType].op; } switch (fillType) { case 0x0: //solid string SchemeType = ""; if (so.OptionsByID.ContainsKey(ShapeOptions.PropertyId.fillColor)) { colorval = Utils.getRGBColorFromOfficeArtCOLORREF(so.OptionsByID[ShapeOptions.PropertyId.fillColor].op, (RegularContainer)slide, so, ref SchemeType); } else { colorval = "FFFFFF"; //TODO: find out which color to use in this case } _writer.WriteStartElement("a", "solidFill", OpenXmlNamespaces.DrawingML); if (SchemeType.Length == 0) { _writer.WriteStartElement("a", "srgbClr", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("val", colorval); } else { _writer.WriteStartElement("a", "schemeClr", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("val", SchemeType); } if (so.OptionsByID.ContainsKey(ShapeOptions.PropertyId.fillOpacity) && so.OptionsByID[ShapeOptions.PropertyId.fillOpacity].op != 65536) { _writer.WriteStartElement("a", "alpha", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("val", Math.Round(((decimal)so.OptionsByID[ShapeOptions.PropertyId.fillOpacity].op / 65536 * 100000)).ToString()); //we need the percentage of the opacity (65536 means 100%) _writer.WriteEndElement(); } _writer.WriteEndElement(); _writer.WriteEndElement(); break; case 0x1: //pattern uint blipIndex1 = so.OptionsByID[ShapeOptions.PropertyId.fillBlip].op; DrawingGroup gr1 = (DrawingGroup)this._ctx.Ppt.DocumentRecord.FirstChildWithType <PPDrawingGroup>().Children[0]; BlipStoreEntry bse1 = (BlipStoreEntry)gr1.FirstChildWithType <BlipStoreContainer>().Children[(int)blipIndex1 - 1]; BitmapBlip b1 = (BitmapBlip)_ctx.Ppt.PicturesContainer._pictures[bse1.foDelay]; _writer.WriteStartElement("a", "pattFill", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("prst", Utils.getPrstForPatternCode(b1.m_bTag)); //Utils.getPrstForPattern(blipNamePattern)); _writer.WriteStartElement("a", "fgClr", OpenXmlNamespaces.DrawingML); _writer.WriteStartElement("a", "srgbClr", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("val", Utils.getRGBColorFromOfficeArtCOLORREF(so.OptionsByID[ShapeOptions.PropertyId.fillColor].op, slide, so)); _writer.WriteEndElement(); _writer.WriteEndElement(); _writer.WriteStartElement("a", "bgClr", OpenXmlNamespaces.DrawingML); _writer.WriteStartElement("a", "srgbClr", OpenXmlNamespaces.DrawingML); if (so.OptionsByID.ContainsKey(ShapeOptions.PropertyId.fillBackColor)) { colorval = Utils.getRGBColorFromOfficeArtCOLORREF(so.OptionsByID[ShapeOptions.PropertyId.fillBackColor].op, slide, so); } else { colorval = "ffffff"; //TODO: find out which color to use in this case } _writer.WriteAttributeString("val", colorval); _writer.WriteEndElement(); _writer.WriteEndElement(); _writer.WriteEndElement(); break; case 0x2: //texture case 0x3: //picture uint blipIndex = 0; string strUrl = ""; if (so.OptionsByID.ContainsKey(ShapeOptions.PropertyId.fillBlip)) { blipIndex = so.OptionsByID[ShapeOptions.PropertyId.fillBlip].op; } else if (so.OptionsByID.ContainsKey(ShapeOptions.PropertyId.Pib)) { blipIndex = so.OptionsByID[ShapeOptions.PropertyId.Pib].op; } else if (so.OptionsByID.ContainsKey(ShapeOptions.PropertyId.fillBlipFlags) && so.OptionsByID.ContainsKey(ShapeOptions.PropertyId.fillBlipName)) { uint flags = so.OptionsByID[ShapeOptions.PropertyId.fillBlipFlags].op; bool comment = !Tools.Utils.BitmaskToBool(flags, 0x1); bool file = Tools.Utils.BitmaskToBool(flags, 0x1); bool url = Tools.Utils.BitmaskToBool(flags, 0x1 << 1); bool DoNotSave = Tools.Utils.BitmaskToBool(flags, 0x1 << 2); bool LinkToFile = Tools.Utils.BitmaskToBool(flags, 0x1 << 3); if (url) { strUrl = ASCIIEncoding.ASCII.GetString(so.OptionsByID[ShapeOptions.PropertyId.fillBlipName].opComplex); strUrl = strUrl.Replace("\0", ""); } } else { break; } //string blipName = Encoding.UTF8.GetString(so.OptionsByID[ShapeOptions.PropertyId.fillBlipName].opComplex); string rId = ""; DrawingGroup gr = (DrawingGroup)this._ctx.Ppt.DocumentRecord.FirstChildWithType <PPDrawingGroup>().Children[0]; ImagePart imgPart = null; if (strUrl.Length > 0) { ExternalRelationship er = _parentSlideMapping.targetPart.AddExternalRelationship(OpenXmlRelationshipTypes.Image, strUrl); rId = er.Id; _writer.WriteStartElement("a", "blipFill", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("dpi", "0"); _writer.WriteAttributeString("rotWithShape", "1"); _writer.WriteStartElement("a", "blip", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("r", "link", OpenXmlNamespaces.Relationships, rId); _writer.WriteEndElement(); _writer.WriteElementString("a", "srcRect", OpenXmlNamespaces.DrawingML, ""); if (fillType == 0x3) { _writer.WriteStartElement("a", "stretch", OpenXmlNamespaces.DrawingML); _writer.WriteElementString("a", "fillRect", OpenXmlNamespaces.DrawingML, ""); _writer.WriteEndElement(); } else { _writer.WriteStartElement("a", "tile", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("tx", "0"); _writer.WriteAttributeString("ty", "0"); _writer.WriteAttributeString("sx", "100000"); _writer.WriteAttributeString("sy", "100000"); _writer.WriteAttributeString("flip", "none"); _writer.WriteAttributeString("algn", "tl"); _writer.WriteEndElement(); } _writer.WriteEndElement(); } else if (blipIndex <= gr.FirstChildWithType <BlipStoreContainer>().Children.Count) { BlipStoreEntry bse = (BlipStoreEntry)gr.FirstChildWithType <BlipStoreContainer>().Children[(int)blipIndex - 1]; if (_ctx.Ppt.PicturesContainer._pictures.ContainsKey(bse.foDelay)) { Record rec = _ctx.Ppt.PicturesContainer._pictures[bse.foDelay]; if (rec is BitmapBlip) { BitmapBlip b = (BitmapBlip)_ctx.Ppt.PicturesContainer._pictures[bse.foDelay]; imgPart = _parentSlideMapping.targetPart.AddImagePart(ShapeTreeMapping.getImageType(b.TypeCode)); imgPart.TargetDirectory = "..\\media"; System.IO.Stream outStream = imgPart.GetStream(); outStream.Write(b.m_pvBits, 0, b.m_pvBits.Length); } else { MetafilePictBlip b = (MetafilePictBlip)_ctx.Ppt.PicturesContainer._pictures[bse.foDelay]; imgPart = _parentSlideMapping.targetPart.AddImagePart(ShapeTreeMapping.getImageType(b.TypeCode)); imgPart.TargetDirectory = "..\\media"; System.IO.Stream outStream = imgPart.GetStream(); byte[] decompressed = b.Decrompress(); outStream.Write(decompressed, 0, decompressed.Length); } rId = imgPart.RelIdToString; _writer.WriteStartElement("a", "blipFill", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("dpi", "0"); _writer.WriteAttributeString("rotWithShape", "1"); _writer.WriteStartElement("a", "blip", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("r", "embed", OpenXmlNamespaces.Relationships, rId); _writer.WriteEndElement(); _writer.WriteElementString("a", "srcRect", OpenXmlNamespaces.DrawingML, ""); if (fillType == 0x3) { _writer.WriteStartElement("a", "stretch", OpenXmlNamespaces.DrawingML); _writer.WriteElementString("a", "fillRect", OpenXmlNamespaces.DrawingML, ""); _writer.WriteEndElement(); } else { _writer.WriteStartElement("a", "tile", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("tx", "0"); _writer.WriteAttributeString("ty", "0"); _writer.WriteAttributeString("sx", "100000"); _writer.WriteAttributeString("sy", "100000"); _writer.WriteAttributeString("flip", "none"); _writer.WriteAttributeString("algn", "tl"); _writer.WriteEndElement(); } _writer.WriteEndElement(); } } break; case 0x4: //shade case 0x5: //shadecenter case 0x6: //shadeshape _writer.WriteStartElement("a", "gradFill", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("rotWithShape", "1"); _writer.WriteStartElement("a", "gsLst", OpenXmlNamespaces.DrawingML); bool useFillAndBack = true; if (so.OptionsByID.ContainsKey(ShapeOptions.PropertyId.fillShadeColors)) { byte[] colors = so.OptionsByID[ShapeOptions.PropertyId.fillShadeColors].opComplex; if (colors != null && colors.Length > 0) { useFillAndBack = false; ShapeOptions.OptionEntry type = so.OptionsByID[ShapeOptions.PropertyId.fillShadeType]; UInt16 nElems = System.BitConverter.ToUInt16(colors, 0); UInt16 nElemsAlloc = System.BitConverter.ToUInt16(colors, 2); UInt16 cbElem = System.BitConverter.ToUInt16(colors, 4); List <string> positions = new List <string>(); switch (nElems) { case 1: case 2: case 3: case 4: case 5: positions.Add("0"); positions.Add("30000"); positions.Add("65000"); positions.Add("90000"); positions.Add("100000"); break; case 6: case 7: case 8: case 9: case 10: default: positions.Add("0"); positions.Add("8000"); positions.Add("13000"); positions.Add("21000"); positions.Add("52000"); positions.Add("56000"); positions.Add("58000"); positions.Add("71000"); positions.Add("94000"); positions.Add("100000"); break; } string[] alphas = new string[nElems]; if (so.OptionsByID.ContainsKey(ShapeOptions.PropertyId.fillOpacity)) { decimal end = Math.Round(((decimal)so.OptionsByID[ShapeOptions.PropertyId.fillOpacity].op / 65536 * 100000)); decimal start = Math.Round(((decimal)so.OptionsByID[ShapeOptions.PropertyId.fillBackOpacity].op / 65536 * 100000)); alphas[0] = start.ToString(); for (int i = 1; i < nElems - 1; i++) { alphas[i] = Math.Round(start + (end - start) / 3 * i).ToString(); } //alphas[1] = Math.Round(start + (end - start) / 3).ToString(); //alphas[2] = Math.Round(start + (end - start) / 3 * 2).ToString(); //alphas[3] = Math.Round(start + (end - start) / 3 * 3).ToString(); alphas[nElems - 1] = end.ToString(); } for (int i = 0; i < nElems * cbElem; i += cbElem) { colorval = Utils.getRGBColorFromOfficeArtCOLORREF(System.BitConverter.ToUInt32(colors, 6 + i), slide, so); _writer.WriteStartElement("a", "gs", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("pos", positions[i / cbElem]); _writer.WriteStartElement("a", "srgbClr", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("val", colorval); if (so.OptionsByID.ContainsKey(ShapeOptions.PropertyId.fillOpacity) && so.OptionsByID[ShapeOptions.PropertyId.fillOpacity].op != 65536) { _writer.WriteStartElement("a", "alpha", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("val", alphas[i / cbElem]); //we need the percentage of the opacity (65536 means 100%) _writer.WriteEndElement(); } _writer.WriteEndElement(); _writer.WriteEndElement(); } } } if (useFillAndBack) { colorval = Utils.getRGBColorFromOfficeArtCOLORREF(so.OptionsByID[ShapeOptions.PropertyId.fillColor].op, slide, so); _writer.WriteStartElement("a", "gs", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("pos", "0"); _writer.WriteStartElement("a", "srgbClr", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("val", colorval); if (so.OptionsByID.ContainsKey(ShapeOptions.PropertyId.fillOpacity) && so.OptionsByID[ShapeOptions.PropertyId.fillOpacity].op != 65536) { _writer.WriteStartElement("a", "alpha", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("val", Math.Round(((decimal)so.OptionsByID[ShapeOptions.PropertyId.fillOpacity].op / 65536 * 100000)).ToString()); //we need the percentage of the opacity (65536 means 100%) _writer.WriteEndElement(); } _writer.WriteEndElement(); _writer.WriteEndElement(); if (so.OptionsByID.ContainsKey(ShapeOptions.PropertyId.fillBackColor)) { colorval = Utils.getRGBColorFromOfficeArtCOLORREF(so.OptionsByID[ShapeOptions.PropertyId.fillBackColor].op, slide, so); } else { if (so.OptionsByID.ContainsKey(ShapeOptions.PropertyId.shadowColor)) { colorval = Utils.getRGBColorFromOfficeArtCOLORREF(so.OptionsByID[ShapeOptions.PropertyId.shadowColor].op, slide, so); } else { //use filColor } } _writer.WriteStartElement("a", "gs", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("pos", "100000"); _writer.WriteStartElement("a", "srgbClr", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("val", colorval); if (so.OptionsByID.ContainsKey(ShapeOptions.PropertyId.fillBackOpacity) && so.OptionsByID[ShapeOptions.PropertyId.fillBackOpacity].op != 65536) { _writer.WriteStartElement("a", "alpha", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("val", Math.Round(((decimal)so.OptionsByID[ShapeOptions.PropertyId.fillBackOpacity].op / 65536 * 100000)).ToString()); //we need the percentage of the opacity (65536 means 100%) _writer.WriteEndElement(); } _writer.WriteEndElement(); _writer.WriteEndElement(); } _writer.WriteEndElement(); //gsLst switch (fillType) { case 0x5: case 0x6: _writer.WriteStartElement("a", "path", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("path", "shape"); _writer.WriteStartElement("a", "fillToRect", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("l", "50000"); _writer.WriteAttributeString("t", "50000"); _writer.WriteAttributeString("r", "50000"); _writer.WriteAttributeString("b", "50000"); _writer.WriteEndElement(); _writer.WriteEndElement(); //path break; default: _writer.WriteStartElement("a", "path", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("path", "rect"); _writer.WriteStartElement("a", "fillToRect", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("r", "100000"); _writer.WriteAttributeString("b", "100000"); _writer.WriteEndElement(); _writer.WriteEndElement(); //path break; } _writer.WriteEndElement(); //gradFill break; case 0x7: //shadescale _writer.WriteStartElement("a", "gradFill", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("rotWithShape", "1"); _writer.WriteStartElement("a", "gsLst", OpenXmlNamespaces.DrawingML); decimal angle = 90; bool switchColors = false; if (so.OptionsByID.ContainsKey(ShapeOptions.PropertyId.fillAngle)) { if (so.OptionsByID[ShapeOptions.PropertyId.fillAngle].op != 0) { byte[] bytes = BitConverter.GetBytes(so.OptionsByID[ShapeOptions.PropertyId.fillAngle].op); int integral = BitConverter.ToInt16(bytes, 0); uint fractional = BitConverter.ToUInt16(bytes, 2); Decimal result = integral + ((decimal)fractional / (decimal)65536); angle = 65536 - fractional; //I have no idea why this works!! angle = angle - 90; if (angle < 0) { angle += 360; switchColors = true; } } } Dictionary <int, string> shadeColorsDic = new Dictionary <int, string>(); List <string> shadeColors = new List <string>(); if (so.OptionsByID.ContainsKey(ShapeOptions.PropertyId.fillShadeColors) && so.OptionsByID[ShapeOptions.PropertyId.fillShadeColors].opComplex != null && so.OptionsByID[ShapeOptions.PropertyId.fillShadeColors].opComplex.Length > 0) { uint length = so.OptionsByID[ShapeOptions.PropertyId.fillShadeColors].op; //An IMsoArray record that specifies colors and their relative positions. //Each element of the array contains an OfficeArtCOLORREF record color and a FixedPoint, as specified in [MS-OSHARED] //section 2.2.1.6, that specifies its relative position along the gradient vector. byte[] data = so.OptionsByID[ShapeOptions.PropertyId.fillShadeColors].opComplex; int pos = 0; string colval; FixedPointNumber fixedpoint; UInt16 nElems = BitConverter.ToUInt16(data, pos); pos += 2; UInt16 nElemsAlloc = BitConverter.ToUInt16(data, pos); pos += 2; UInt16 cbElem = BitConverter.ToUInt16(data, pos); pos += 2; if (cbElem == 0xFFF0) { //If this value is 0xFFF0 then this record is an array of truncated 8 byte elements. Only the 4 low-order bytes are recorded. Each element's 4 high-order bytes equal 0x00000000 and each element's 4 low-order bytes are contained in data. } else { while (pos < length) { colval = Utils.getRGBColorFromOfficeArtCOLORREF(BitConverter.ToUInt32(data, pos), slide, so); pos += 4; fixedpoint = new FixedPointNumber(BitConverter.ToUInt16(data, pos), BitConverter.ToUInt16(data, pos + 2)); shadeColors.Insert(0, colval); pos += 4; } } } else { bool switchcolors = false; if (switchColors & so.OptionsByID.ContainsKey(ShapeOptions.PropertyId.fillBackColor)) { colorval = Utils.getRGBColorFromOfficeArtCOLORREF(so.OptionsByID[ShapeOptions.PropertyId.fillBackColor].op, slide, so); } else { if (so.OptionsByID.ContainsKey(ShapeOptions.PropertyId.fillColor)) { colorval = Utils.getRGBColorFromOfficeArtCOLORREF(so.OptionsByID[ShapeOptions.PropertyId.fillColor].op, slide, so); } else { colorval = "FFFFFF"; //TODO: find out which color to use in this case switchcolors = true; } } if (switchColors | !so.OptionsByID.ContainsKey(ShapeOptions.PropertyId.fillBackColor)) { colorval2 = Utils.getRGBColorFromOfficeArtCOLORREF(so.OptionsByID[ShapeOptions.PropertyId.fillColor].op, slide, so); } else { colorval2 = Utils.getRGBColorFromOfficeArtCOLORREF(so.OptionsByID[ShapeOptions.PropertyId.fillBackColor].op, slide, so); } if (switchcolors) { //this is a workaround for a bug. Further analysis necessarry string dummy = colorval; colorval = colorval2; colorval2 = dummy; } shadeColors.Add(colorval); shadeColors.Add(colorval2); } int gspos; string col; for (int i = 0; i < shadeColors.Count; i++) { col = shadeColors[i]; if (i == 0) { gspos = 0; } else if (i == shadeColors.Count - 1) { gspos = 100000; } else { gspos = i * 100000 / shadeColors.Count; } _writer.WriteStartElement("a", "gs", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("pos", gspos.ToString()); _writer.WriteStartElement("a", "srgbClr", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("val", col); if (so.OptionsByID.ContainsKey(ShapeOptions.PropertyId.fillOpacity) && so.OptionsByID[ShapeOptions.PropertyId.fillOpacity].op != 65536) { _writer.WriteStartElement("a", "alpha", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("val", Math.Round(((decimal)so.OptionsByID[ShapeOptions.PropertyId.fillOpacity].op / 65536 * 100000)).ToString()); //we need the percentage of the opacity (65536 means 100%) _writer.WriteEndElement(); } if (so.OptionsByID.ContainsKey(ShapeOptions.PropertyId.fillShadeType)) { uint flags = so.OptionsByID[ShapeOptions.PropertyId.fillShadeType].op; bool none = Tools.Utils.BitmaskToBool(flags, 0x1); bool gamma = Tools.Utils.BitmaskToBool(flags, 0x1 << 1); bool sigma = Tools.Utils.BitmaskToBool(flags, 0x1 << 2); bool band = Tools.Utils.BitmaskToBool(flags, 0x1 << 3); bool onecolor = Tools.Utils.BitmaskToBool(flags, 0x1 << 4); if (gamma) { _writer.WriteElementString("a", "gamma", OpenXmlNamespaces.DrawingML, ""); } if (band) { _writer.WriteStartElement("a", "shade", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("val", "37255"); _writer.WriteEndElement(); } if (gamma) { _writer.WriteElementString("a", "invGamma", OpenXmlNamespaces.DrawingML, ""); } } _writer.WriteEndElement(); _writer.WriteEndElement(); } ////new colorval //_writer.WriteStartElement("a", "gs", OpenXmlNamespaces.DrawingML); //_writer.WriteAttributeString("pos", "100000"); //_writer.WriteStartElement("a", "srgbClr", OpenXmlNamespaces.DrawingML); //_writer.WriteAttributeString("val", colorval2); //if (so.OptionsByID.ContainsKey(ShapeOptions.PropertyId.fillBackOpacity)) //{ // _writer.WriteStartElement("a", "alpha", OpenXmlNamespaces.DrawingML); // _writer.WriteAttributeString("val", Math.Round(((decimal)so.OptionsByID[ShapeOptions.PropertyId.fillBackOpacity].op / 65536 * 100000)).ToString()); //we need the percentage of the opacity (65536 means 100%) // _writer.WriteEndElement(); //} //_writer.WriteEndElement(); //_writer.WriteEndElement(); _writer.WriteEndElement(); //gsLst _writer.WriteStartElement("a", "lin", OpenXmlNamespaces.DrawingML); angle *= 60000; //if (angle > 5400000) angle = 5400000; _writer.WriteAttributeString("ang", angle.ToString()); _writer.WriteAttributeString("scaled", "1"); _writer.WriteEndElement(); _writer.WriteEndElement(); break; case 0x8: //shadetitle case 0x9: //background break; } }
public void writeBuClr(RegularContainer slide, GrColorAtom color, ref string lastColor) { if (color.IsSchemeColor) //TODO: to be fully implemented { //_writer.WriteStartElement("a", "schemeClr", OpenXmlNamespaces.DrawingML); if (slide == null) { ////TODO: what shall be used in this case (happens for default text style in presentation.xml) //_writer.WriteStartElement("a", "srgbClr", OpenXmlNamespaces.DrawingML); //_writer.WriteAttributeString("val", "000000"); //_writer.WriteEndElement(); this._writer.WriteStartElement("a", "buClr", OpenXmlNamespaces.DrawingML); this._writer.WriteStartElement("a", "schemeClr", OpenXmlNamespaces.DrawingML); switch (color.Index) { case 0x00: this._writer.WriteAttributeString("val", "bg1"); //background break; case 0x01: this._writer.WriteAttributeString("val", "tx1"); //text break; case 0x02: this._writer.WriteAttributeString("val", "dk1"); //shadow break; case 0x03: this._writer.WriteAttributeString("val", "tx1"); //title text break; case 0x04: this._writer.WriteAttributeString("val", "bg2"); //fill break; case 0x05: this._writer.WriteAttributeString("val", "accent1"); //accent1 break; case 0x06: this._writer.WriteAttributeString("val", "accent2"); //accent2 break; case 0x07: this._writer.WriteAttributeString("val", "accent3"); //accent3 break; case 0xFE: //sRGB lastColor = color.Red.ToString("X").PadLeft(2, '0') + color.Green.ToString("X").PadLeft(2, '0') + color.Blue.ToString("X").PadLeft(2, '0'); this._writer.WriteAttributeString("val", lastColor); break; case 0xFF: //undefined break; } this._writer.WriteEndElement(); this._writer.WriteEndElement(); } else { ColorSchemeAtom MasterScheme = null; var ato = slide.FirstChildWithType <SlideAtom>(); List <ColorSchemeAtom> colors; if (ato != null && Tools.Utils.BitmaskToBool(ato.Flags, 0x1 << 1) && ato.MasterId != 0) { colors = this._ctx.Ppt.FindMasterRecordById(ato.MasterId).AllChildrenWithType <ColorSchemeAtom>(); } else { colors = slide.AllChildrenWithType <ColorSchemeAtom>(); } foreach (var colorsch in colors) { if (colorsch.Instance == 1) { MasterScheme = colorsch; } } if (color.Index != 0xFF) { this._writer.WriteStartElement("a", "buClr", OpenXmlNamespaces.DrawingML); this._writer.WriteStartElement("a", "srgbClr", OpenXmlNamespaces.DrawingML); switch (color.Index) { case 0x00: //background lastColor = new RGBColor(MasterScheme.Background, RGBColor.ByteOrder.RedFirst).SixDigitHexCode; this._writer.WriteAttributeString("val", lastColor); break; case 0x01: //text lastColor = new RGBColor(MasterScheme.TextAndLines, RGBColor.ByteOrder.RedFirst).SixDigitHexCode; this._writer.WriteAttributeString("val", lastColor); break; case 0x02: //shadow lastColor = new RGBColor(MasterScheme.Shadows, RGBColor.ByteOrder.RedFirst).SixDigitHexCode; this._writer.WriteAttributeString("val", lastColor); break; case 0x03: //title lastColor = new RGBColor(MasterScheme.TitleText, RGBColor.ByteOrder.RedFirst).SixDigitHexCode; this._writer.WriteAttributeString("val", lastColor); break; case 0x04: //fill lastColor = new RGBColor(MasterScheme.Fills, RGBColor.ByteOrder.RedFirst).SixDigitHexCode; this._writer.WriteAttributeString("val", lastColor); break; case 0x05: //accent1 lastColor = new RGBColor(MasterScheme.Accent, RGBColor.ByteOrder.RedFirst).SixDigitHexCode; this._writer.WriteAttributeString("val", lastColor); break; case 0x06: //accent2 lastColor = new RGBColor(MasterScheme.AccentAndHyperlink, RGBColor.ByteOrder.RedFirst).SixDigitHexCode; this._writer.WriteAttributeString("val", lastColor); break; case 0x07: //accent3 lastColor = new RGBColor(MasterScheme.AccentAndFollowedHyperlink, RGBColor.ByteOrder.RedFirst).SixDigitHexCode; this._writer.WriteAttributeString("val", lastColor); break; case 0xFE: //sRGB lastColor = color.Red.ToString("X").PadLeft(2, '0') + color.Green.ToString("X").PadLeft(2, '0') + color.Blue.ToString("X").PadLeft(2, '0'); this._writer.WriteAttributeString("val", lastColor); break; case 0xFF: //undefined default: break; } this._writer.WriteEndElement(); this._writer.WriteEndElement(); } //_writer.WriteEndElement(); } } else { this._writer.WriteStartElement("a", "buClr", OpenXmlNamespaces.DrawingML); this._writer.WriteStartElement("a", "srgbClr", OpenXmlNamespaces.DrawingML); lastColor = color.Red.ToString("X").PadLeft(2, '0') + color.Green.ToString("X").PadLeft(2, '0') + color.Blue.ToString("X").PadLeft(2, '0'); this._writer.WriteAttributeString("val", lastColor); this._writer.WriteEndElement(); this._writer.WriteEndElement(); } }
public void Apply(RegularContainer Master) { this._Master = Master; var atoms = Master.AllChildrenWithType <TextMasterStyleAtom>(); var body9atoms = new List <TextMasterStyle9Atom>(); var title9atoms = new List <TextMasterStyle9Atom>(); foreach (var progtags in Master.AllChildrenWithType <ProgTags>()) { foreach (var progbinarytag in progtags.AllChildrenWithType <ProgBinaryTag>()) { foreach (var blob in progbinarytag.AllChildrenWithType <ProgBinaryTagDataBlob>()) { foreach (var atom in blob.AllChildrenWithType <TextMasterStyle9Atom>()) { if (atom.Instance == 0) { title9atoms.Add(atom); } if (atom.Instance == 1) { body9atoms.Add(atom); } } } } } foreach (var atom in atoms) { if (atom.Instance == 0) { this.titleAtoms.Add(atom); } if (atom.Instance == 1) { this.bodyAtoms.Add(atom); } if (atom.Instance == 5) { this.CenterBodyAtoms.Add(atom); } if (atom.Instance == 6) { this.CenterTitleAtoms.Add(atom); } } this._writer.WriteStartElement("p", "txStyles", OpenXmlNamespaces.PresentationML); this._writer.WriteStartElement("p", "titleStyle", OpenXmlNamespaces.PresentationML); ParagraphRun9 pr9 = null; foreach (var atom in this.titleAtoms) { this.lastSpaceBefore = 0; this.lastBulletFont = ""; this.lastBulletChar = ""; this.lastColor = ""; this.lastBulletColor = ""; this.lastSize = ""; for (int i = 0; i < atom.IndentLevelCount; i++) { pr9 = null; if (title9atoms.Count > 0 && title9atoms[0].pruns.Count > i) { pr9 = title9atoms[0].pruns[i]; } writepPr(atom.CRuns[i], atom.PRuns[i], pr9, i, true); } for (int i = atom.IndentLevelCount; i < 9; i++) { pr9 = null; if (title9atoms.Count > 0 && title9atoms[0].pruns.Count > i) { pr9 = title9atoms[0].pruns[i]; } writepPr(atom.CRuns[0], atom.PRuns[0], pr9, i, true); } } this._writer.WriteEndElement(); //titleStyle this._writer.WriteStartElement("p", "bodyStyle", OpenXmlNamespaces.PresentationML); foreach (var atom in this.bodyAtoms) { this.lastSpaceBefore = 0; this.lastColor = ""; this.lastBulletFont = ""; this.lastBulletChar = ""; this.lastBulletColor = ""; this.lastSize = ""; for (int i = 0; i < atom.IndentLevelCount; i++) { pr9 = null; if (body9atoms.Count > 0 && body9atoms[0].pruns.Count > i) { pr9 = body9atoms[0].pruns[i]; } writepPr(atom.CRuns[i], atom.PRuns[i], pr9, i, false); } for (int i = atom.IndentLevelCount; i < 9; i++) { pr9 = null; if (body9atoms.Count > 0 && body9atoms[0].pruns.Count > i) { pr9 = body9atoms[0].pruns[i]; } writepPr(atom.CRuns[0], atom.PRuns[0], pr9, i, false); } } this._writer.WriteEndElement(); //bodyStyle this._writer.WriteEndElement(); //txStyles }
/// <summary> /// Mapping definition for embedded objects /// </summary> /// <param name="objectsSequence"></param> public void Apply(ObjectsSequence objectsSequence) { _writer.WriteStartElement(Dml.SpreadsheetDrawing.Prefix, Dml.SpreadsheetDrawing.ElWsDr, Dml.SpreadsheetDrawing.Ns); _writer.WriteAttributeString("xmlns", Dml.SpreadsheetDrawing.Prefix, "", Dml.SpreadsheetDrawing.Ns); _writer.WriteAttributeString("xmlns", Dml.Prefix, "", Dml.Ns); foreach (DrawingsGroup drawingsGroup in objectsSequence.DrawingsGroup) { // TODO: currently only embedded charts are mapped. Shapes and images are not yet implemented. // The check on the type of object would have to be removed here once shapes and images are supported. // ObjectGroup objGroup = drawingsGroup.Objects.Find(p => p.ChartSheetSequence != null); if (objGroup != null) { MsoDrawing msoDrawing = drawingsGroup.MsoDrawing; // find OfficeArtClientAnchorSheet with drawing RegularContainer container = msoDrawing.rgChildRec as RegularContainer; if (container != null) { ClientAnchor clientAnchor = container.FirstDescendantWithType <ClientAnchor>(); if (clientAnchor != null) { OfficeArtClientAnchorSheet oartClientAnchor = new OfficeArtClientAnchorSheet(clientAnchor.RawData); // xdr:twoCellAnchor _writer.WriteStartElement(Dml.SpreadsheetDrawing.Prefix, Dml.SpreadsheetDrawing.ElTwoCellAnchor, Dml.SpreadsheetDrawing.Ns); string editAs = "absolute"; if (oartClientAnchor.fSize && oartClientAnchor.fMove) { // Move and resize with anchor cells editAs = "twoCell"; } else if (!oartClientAnchor.fSize && oartClientAnchor.fMove) { // Move with cells but do not resize editAs = "oneCell"; } _writer.WriteAttributeString(Dml.SpreadsheetDrawing.AttrEditAs, editAs); { // xdr:from _writer.WriteStartElement(Dml.SpreadsheetDrawing.Prefix, Dml.SpreadsheetDrawing.ElFrom, Dml.SpreadsheetDrawing.Ns); _writer.WriteElementString(Dml.SpreadsheetDrawing.Prefix, Dml.SpreadsheetDrawing.ElCol, Dml.SpreadsheetDrawing.Ns, oartClientAnchor.colL.ToString()); _writer.WriteElementString(Dml.SpreadsheetDrawing.Prefix, Dml.SpreadsheetDrawing.ElColOff, Dml.SpreadsheetDrawing.Ns, oartClientAnchor.dxL.ToString()); _writer.WriteElementString(Dml.SpreadsheetDrawing.Prefix, Dml.SpreadsheetDrawing.ElRow, Dml.SpreadsheetDrawing.Ns, oartClientAnchor.rwT.ToString()); _writer.WriteElementString(Dml.SpreadsheetDrawing.Prefix, Dml.SpreadsheetDrawing.ElRowOff, Dml.SpreadsheetDrawing.Ns, oartClientAnchor.dyT.ToString()); _writer.WriteEndElement(); // xdr:from // xdr:to _writer.WriteStartElement(Dml.SpreadsheetDrawing.Prefix, Dml.SpreadsheetDrawing.ElTo, Dml.SpreadsheetDrawing.Ns); _writer.WriteElementString(Dml.SpreadsheetDrawing.Prefix, Dml.SpreadsheetDrawing.ElCol, Dml.SpreadsheetDrawing.Ns, oartClientAnchor.colR.ToString()); _writer.WriteElementString(Dml.SpreadsheetDrawing.Prefix, Dml.SpreadsheetDrawing.ElColOff, Dml.SpreadsheetDrawing.Ns, oartClientAnchor.dxR.ToString()); _writer.WriteElementString(Dml.SpreadsheetDrawing.Prefix, Dml.SpreadsheetDrawing.ElRow, Dml.SpreadsheetDrawing.Ns, oartClientAnchor.rwB.ToString()); _writer.WriteElementString(Dml.SpreadsheetDrawing.Prefix, Dml.SpreadsheetDrawing.ElRowOff, Dml.SpreadsheetDrawing.Ns, oartClientAnchor.dyB.ToString()); _writer.WriteEndElement(); // xdr:to ObjectGroup objectGroup = drawingsGroup.Objects.Find(p => p.ChartSheetSequence != null); if (objectGroup != null) { ChartSheetContentSequence chartSheetContentSequence = objectGroup.ChartSheetSequence.ChartSheetContentSequence; insertObjectChoices(chartSheetContentSequence); } } _writer.WriteEndElement(); // xdr:twoCellAnchor } } } } _writer.WriteEndElement(); _writer.WriteEndDocument(); _writer.Flush(); }
public void Apply(CharacterRun run, string startElement, RegularContainer slide, ref string lastColor, ref string lastSize, ref string lastTypeface, string lang, string altLang, TextMasterStyleAtom defaultStyle, int lvl, List <MouseClickInteractiveInfoContainer> mciics, ShapeTreeMapping parentShapeTreeMapping, uint position, bool insideTable) { _writer.WriteStartElement("a", startElement, OpenXmlNamespaces.DrawingML); if (lang.Length == 0) { TextSIExceptionAtom siea = _ctx.Ppt.DocumentRecord.FirstDescendantWithType <TextSIExceptionAtom>(); if (siea != null) { if (siea.si.lang) { switch (siea.si.lid) { case 0x0: // no language break; case 0x13: //Any Dutch language is preferred over non-Dutch languages when proofing the text break; case 0x400: //no proofing break; default: try { lang = System.Globalization.CultureInfo.GetCultureInfo(siea.si.lid).IetfLanguageTag; } catch (Exception) { //ignore } break; } } } } if (altLang.Length == 0) { TextSIExceptionAtom siea = _ctx.Ppt.DocumentRecord.FirstDescendantWithType <TextSIExceptionAtom>(); if (siea != null) { if (siea.si.altLang) { switch (siea.si.altLid) { case 0x0: // no language break; case 0x13: //Any Dutch language is preferred over non-Dutch languages when proofing the text break; case 0x400: //no proofing break; default: try { altLang = System.Globalization.CultureInfo.GetCultureInfo(siea.si.altLid).IetfLanguageTag; } catch (Exception) { //ignore } break; } } } } if (lang.Length > 0) { _writer.WriteAttributeString("lang", lang); } if (altLang.Length > 0) { _writer.WriteAttributeString("altLang", altLang); } bool runExists = run != null; if (runExists && run.SizePresent) { if (run.Size > 0) { _writer.WriteAttributeString("sz", (run.Size * 100).ToString()); lastSize = (run.Size * 100).ToString(); } } else if (lastSize.Length > 0) { _writer.WriteAttributeString("sz", lastSize); } else if (defaultStyle != null) { if (defaultStyle.CRuns[lvl].SizePresent) { _writer.WriteAttributeString("sz", (defaultStyle.CRuns[lvl].Size * 100).ToString()); } } if (runExists && run.StyleFlagsFieldPresent) { if ((run.Style & StyleMask.IsBold) == StyleMask.IsBold) { _writer.WriteAttributeString("b", "1"); } if ((run.Style & StyleMask.IsItalic) == StyleMask.IsItalic) { _writer.WriteAttributeString("i", "1"); } if ((run.Style & StyleMask.IsUnderlined) == StyleMask.IsUnderlined) { _writer.WriteAttributeString("u", "sng"); } } else if (defaultStyle != null && defaultStyle.CRuns[lvl].StyleFlagsFieldPresent) { if ((defaultStyle.CRuns[lvl].Style & StyleMask.IsBold) == StyleMask.IsBold) { _writer.WriteAttributeString("b", "1"); } if ((defaultStyle.CRuns[lvl].Style & StyleMask.IsItalic) == StyleMask.IsItalic) { _writer.WriteAttributeString("i", "1"); } if ((defaultStyle.CRuns[lvl].Style & StyleMask.IsUnderlined) == StyleMask.IsUnderlined) { _writer.WriteAttributeString("u", "sng"); } } if (runExists && run.ColorPresent) { writeSolidFill(slide, run, ref lastColor); } else if (lastColor.Length > 0) { _writer.WriteStartElement("a", "solidFill", OpenXmlNamespaces.DrawingML); _writer.WriteStartElement("a", "srgbClr", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("val", lastColor); _writer.WriteEndElement(); _writer.WriteEndElement(); } else if (defaultStyle != null) { if (defaultStyle.CRuns[lvl].ColorPresent) { writeSolidFill((RegularContainer)defaultStyle.ParentRecord, defaultStyle.CRuns[lvl], ref lastColor); } } if (runExists && run.StyleFlagsFieldPresent) { if ((run.Style & StyleMask.HasShadow) == StyleMask.HasShadow) { //TODO: these values are default and have to be replaced _writer.WriteStartElement("a", "effectLst", OpenXmlNamespaces.DrawingML); _writer.WriteStartElement("a", "outerShdw", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("blurRad", "38100"); _writer.WriteAttributeString("dist", "38100"); _writer.WriteAttributeString("dir", "2700000"); _writer.WriteAttributeString("algn", "tl"); _writer.WriteStartElement("a", "srgbClr", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("val", "C0C0C0"); _writer.WriteEndElement(); _writer.WriteEndElement(); _writer.WriteEndElement(); } if ((run.Style & StyleMask.IsEmbossed) == StyleMask.IsEmbossed) { //TODO: these values are default and have to be replaced _writer.WriteStartElement("a", "effectDag", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("name", ""); _writer.WriteStartElement("a", "cont", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("type", "tree"); _writer.WriteAttributeString("name", ""); _writer.WriteStartElement("a", "effect", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("ref", "fillLine"); _writer.WriteEndElement(); _writer.WriteStartElement("a", "outerShdw", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("dist", "38100"); _writer.WriteAttributeString("dir", "13500000"); _writer.WriteAttributeString("algn", "br"); _writer.WriteStartElement("a", "srgbClr", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("val", "FFFFFF"); _writer.WriteEndElement(); _writer.WriteEndElement(); _writer.WriteEndElement(); _writer.WriteStartElement("a", "cont", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("type", "tree"); _writer.WriteAttributeString("name", ""); _writer.WriteStartElement("a", "effect", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("ref", "fillLine"); _writer.WriteEndElement(); _writer.WriteStartElement("a", "outerShdw", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("dist", "38100"); _writer.WriteAttributeString("dir", "2700000"); _writer.WriteAttributeString("algn", "tl"); _writer.WriteStartElement("a", "srgbClr", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("val", "999999"); _writer.WriteEndElement(); _writer.WriteEndElement(); _writer.WriteEndElement(); _writer.WriteStartElement("a", "effect", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("ref", "fillLine"); _writer.WriteEndElement(); _writer.WriteEndElement(); } //TODOS //HasAsianSmartQuotes //HasHorizonNumRendering //ExtensionNibble } //TODOs: //run.ANSITypefacePresent //run.FEOldTypefacePresent //run.PositionPresent //run.SymbolTypefacePresent //run.TypefacePresent if (runExists && run.TypefacePresent) { _writer.WriteStartElement("a", "latin", OpenXmlNamespaces.DrawingML); try { FontCollection fonts = _ctx.Ppt.DocumentRecord.FirstChildWithType <DIaLOGIKa.b2xtranslator.PptFileFormat.Environment>().FirstChildWithType <FontCollection>(); FontEntityAtom entity = fonts.entities[(int)run.TypefaceIdx]; if (entity.TypeFace.IndexOf('\0') > 0) { _writer.WriteAttributeString("typeface", entity.TypeFace.Substring(0, entity.TypeFace.IndexOf('\0'))); lastTypeface = entity.TypeFace.Substring(0, entity.TypeFace.IndexOf('\0')); } else { _writer.WriteAttributeString("typeface", entity.TypeFace); lastTypeface = entity.TypeFace; } //_writer.WriteAttributeString("charset", "0"); } catch (Exception ex) { throw; } _writer.WriteEndElement(); } else if (lastTypeface.Length > 0) { _writer.WriteStartElement("a", "latin", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("typeface", lastTypeface); _writer.WriteEndElement(); } else if (defaultStyle != null && defaultStyle.CRuns[lvl].TypefacePresent) { _writer.WriteStartElement("a", "latin", OpenXmlNamespaces.DrawingML); try { FontCollection fonts = _ctx.Ppt.DocumentRecord.FirstChildWithType <DIaLOGIKa.b2xtranslator.PptFileFormat.Environment>().FirstChildWithType <FontCollection>(); FontEntityAtom entity = fonts.entities[(int)defaultStyle.CRuns[lvl].TypefaceIdx]; if (entity.TypeFace.IndexOf('\0') > 0) { _writer.WriteAttributeString("typeface", entity.TypeFace.Substring(0, entity.TypeFace.IndexOf('\0'))); lastTypeface = entity.TypeFace.Substring(0, entity.TypeFace.IndexOf('\0')); } else { _writer.WriteAttributeString("typeface", entity.TypeFace); lastTypeface = entity.TypeFace; } //_writer.WriteAttributeString("charset", "0"); } catch (Exception ex) { throw; } _writer.WriteEndElement(); } else { if (insideTable) { if (slide.FirstChildWithType <SlideAtom>() != null && _ctx.Ppt.FindMasterRecordById(slide.FirstChildWithType <SlideAtom>().MasterId) != null) { foreach (TextMasterStyleAtom item in _ctx.Ppt.FindMasterRecordById(slide.FirstChildWithType <SlideAtom>().MasterId).AllChildrenWithType <TextMasterStyleAtom>()) { if (item.Instance == 1) { if (item.CRuns.Count > 0 && item.CRuns[0].TypefacePresent) { _writer.WriteStartElement("a", "latin", OpenXmlNamespaces.DrawingML); try { FontCollection fonts = _ctx.Ppt.DocumentRecord.FirstChildWithType <DIaLOGIKa.b2xtranslator.PptFileFormat.Environment>().FirstChildWithType <FontCollection>(); FontEntityAtom entity = fonts.entities[(int)item.CRuns[0].TypefaceIdx]; if (entity.TypeFace.IndexOf('\0') > 0) { _writer.WriteAttributeString("typeface", entity.TypeFace.Substring(0, entity.TypeFace.IndexOf('\0'))); lastTypeface = entity.TypeFace.Substring(0, entity.TypeFace.IndexOf('\0')); } else { _writer.WriteAttributeString("typeface", entity.TypeFace); lastTypeface = entity.TypeFace; } //_writer.WriteAttributeString("charset", "0"); } catch (Exception ex) { throw; } _writer.WriteEndElement(); } } } } } // try // { // CharacterRun cr = _ctx.Ppt.DocumentRecord.FirstChildWithType<PptFileFormat.Environment>().FirstChildWithType<TextMasterStyleAtom>().CRuns[0]; // if (cr.TypefacePresent) // { // FontCollection fonts = _ctx.Ppt.DocumentRecord.FirstChildWithType<DIaLOGIKa.b2xtranslator.PptFileFormat.Environment>().FirstChildWithType<FontCollection>(); // FontEntityAtom entity = fonts.entities[(int)cr.TypefaceIdx]; // if (entity.TypeFace.IndexOf('\0') > 0) // { // _writer.WriteStartElement("a", "latin", OpenXmlNamespaces.DrawingML); // _writer.WriteAttributeString("typeface", entity.TypeFace.Substring(0, entity.TypeFace.IndexOf('\0'))); // _writer.WriteEndElement(); // } // else // { // _writer.WriteStartElement("a", "latin", OpenXmlNamespaces.DrawingML); // _writer.WriteAttributeString("typeface", entity.TypeFace); // _writer.WriteEndElement(); // } // } // } // catch (Exception ex) // { // //throw; // } } if (runExists && run.FEOldTypefacePresent) { try { FontCollection fonts = _ctx.Ppt.DocumentRecord.FirstChildWithType <DIaLOGIKa.b2xtranslator.PptFileFormat.Environment>().FirstChildWithType <FontCollection>(); FontEntityAtom entity = fonts.entities[(int)run.FEOldTypefaceIdx]; if (entity.TypeFace.IndexOf('\0') > 0) { _writer.WriteStartElement("a", "ea", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("typeface", entity.TypeFace.Substring(0, entity.TypeFace.IndexOf('\0'))); _writer.WriteEndElement(); } else { _writer.WriteStartElement("a", "ea", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("typeface", entity.TypeFace); _writer.WriteEndElement(); } } catch (Exception ex) { //throw; } } else { try { CharacterRun cr = _ctx.Ppt.DocumentRecord.FirstChildWithType <PptFileFormat.Environment>().FirstChildWithType <TextMasterStyleAtom>().CRuns[0]; if (cr.FEOldTypefacePresent) { FontCollection fonts = _ctx.Ppt.DocumentRecord.FirstChildWithType <DIaLOGIKa.b2xtranslator.PptFileFormat.Environment>().FirstChildWithType <FontCollection>(); FontEntityAtom entity = fonts.entities[(int)cr.FEOldTypefaceIdx]; if (entity.TypeFace.IndexOf('\0') > 0) { _writer.WriteStartElement("a", "ea", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("typeface", entity.TypeFace.Substring(0, entity.TypeFace.IndexOf('\0'))); _writer.WriteEndElement(); } else { _writer.WriteStartElement("a", "ea", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("typeface", entity.TypeFace); _writer.WriteEndElement(); } } } catch (Exception ex) { //throw; } } if (runExists && run.SymbolTypefacePresent) { try { FontCollection fonts = _ctx.Ppt.DocumentRecord.FirstChildWithType <DIaLOGIKa.b2xtranslator.PptFileFormat.Environment>().FirstChildWithType <FontCollection>(); FontEntityAtom entity = fonts.entities[(int)run.SymbolTypefaceIdx]; if (entity.TypeFace.IndexOf('\0') > 0) { _writer.WriteStartElement("a", "sym", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("typeface", entity.TypeFace.Substring(0, entity.TypeFace.IndexOf('\0'))); _writer.WriteEndElement(); } else { _writer.WriteStartElement("a", "sym", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("typeface", entity.TypeFace); _writer.WriteEndElement(); } } catch (Exception ex) { //throw; } } if (mciics != null && mciics.Count > 0) { foreach (MouseClickInteractiveInfoContainer mciic in mciics) { InteractiveInfoAtom iia = mciic.FirstChildWithType <InteractiveInfoAtom>(); MouseClickTextInteractiveInfoAtom tiia = mciic.Range; if (tiia.begin <= position && tiia.end > position) { if (iia != null) { if (iia.action == InteractiveInfoActionEnum.Hyperlink) { foreach (ExHyperlinkContainer c in _ctx.Ppt.DocumentRecord.FirstDescendantWithType <ExObjListContainer>().AllChildrenWithType <ExHyperlinkContainer>()) { ExHyperlinkAtom a = c.FirstChildWithType <ExHyperlinkAtom>(); if (a.exHyperlinkId == iia.exHyperlinkIdRef) { CStringAtom s = c.FirstChildWithType <CStringAtom>(); ExternalRelationship er = parentShapeTreeMapping.parentSlideMapping.targetPart.AddExternalRelationship(OpenXmlRelationshipTypes.HyperLink, s.Text); _writer.WriteStartElement("a", "hlinkClick", OpenXmlNamespaces.DrawingML); _writer.WriteAttributeString("r", "id", OpenXmlNamespaces.Relationships, er.Id.ToString()); _writer.WriteEndElement(); } } } } } } } _writer.WriteEndElement(); }
public static string getRGBColorFromOfficeArtCOLORREF(uint value, RegularContainer slide, DIaLOGIKa.b2xtranslator.OfficeDrawing.ShapeOptions so, ref string SchemeType) { byte[] bytes = BitConverter.GetBytes(value); bool fPaletteIndex = (bytes[3] & 1) != 0; bool fPaletteRGB = (bytes[3] & (1 << 1)) != 0; bool fSystemRGB = (bytes[3] & (1 << 2)) != 0; bool fSchemeIndex = (bytes[3] & (1 << 3)) != 0; bool fSysIndex = (bytes[3] & (1 << 4)) != 0; List <ColorSchemeAtom> colors = slide.AllChildrenWithType <ColorSchemeAtom>(); ColorSchemeAtom MasterScheme = null; foreach (ColorSchemeAtom color in colors) { if (color.Instance == 1) { MasterScheme = color; } } if (fSysIndex) { UInt16 val = BitConverter.ToUInt16(bytes, 0); string result = ""; switch (val & 0x00ff) { case 0xF0: //shape fill color if (so.OptionsByID.ContainsKey(DIaLOGIKa.b2xtranslator.OfficeDrawing.ShapeOptions.PropertyId.fillColor)) { result = getRGBColorFromOfficeArtCOLORREF(so.OptionsByID[DIaLOGIKa.b2xtranslator.OfficeDrawing.ShapeOptions.PropertyId.fillColor].op, slide, so); } else { result = new RGBColor(MasterScheme.Fills, RGBColor.ByteOrder.RedFirst).SixDigitHexCode; //TODO: find out which color to use in this case } break; case 0xF1: //shape line color if it is a line else shape fill color TODO!! if (so.FirstAncestorWithType <OfficeDrawing.ShapeContainer>().FirstChildWithType <OfficeDrawing.Shape>().Instance == 1) { if (so.OptionsByID.ContainsKey(DIaLOGIKa.b2xtranslator.OfficeDrawing.ShapeOptions.PropertyId.fillColor)) { result = getRGBColorFromOfficeArtCOLORREF(so.OptionsByID[DIaLOGIKa.b2xtranslator.OfficeDrawing.ShapeOptions.PropertyId.fillColor].op, slide, so); } else { result = new RGBColor(MasterScheme.Fills, RGBColor.ByteOrder.RedFirst).SixDigitHexCode; //TODO: find out which color to use in this case } } else { if (so.OptionsByID.ContainsKey(DIaLOGIKa.b2xtranslator.OfficeDrawing.ShapeOptions.PropertyId.lineColor)) { result = getRGBColorFromOfficeArtCOLORREF(so.OptionsByID[DIaLOGIKa.b2xtranslator.OfficeDrawing.ShapeOptions.PropertyId.lineColor].op, slide, so); } else { result = new RGBColor(MasterScheme.TextAndLines, RGBColor.ByteOrder.RedFirst).SixDigitHexCode; //TODO: find out which color to use in this case } } break; case 0xF2: //shape line color if (so.OptionsByID.ContainsKey(DIaLOGIKa.b2xtranslator.OfficeDrawing.ShapeOptions.PropertyId.lineColor)) { result = getRGBColorFromOfficeArtCOLORREF(so.OptionsByID[DIaLOGIKa.b2xtranslator.OfficeDrawing.ShapeOptions.PropertyId.lineColor].op, slide, so); } else { result = new RGBColor(MasterScheme.TextAndLines, RGBColor.ByteOrder.RedFirst).SixDigitHexCode; //TODO: find out which color to use in this case } break; case 0xF3: //shape shadow color result = getRGBColorFromOfficeArtCOLORREF(so.OptionsByID[DIaLOGIKa.b2xtranslator.OfficeDrawing.ShapeOptions.PropertyId.shadowColor].op, slide, so); break; case 0xF4: //current or last used color case 0xF5: //shape fill background color result = getRGBColorFromOfficeArtCOLORREF(so.OptionsByID[DIaLOGIKa.b2xtranslator.OfficeDrawing.ShapeOptions.PropertyId.fillBackColor].op, slide, so); break; case 0xF6: //shape line background color result = getRGBColorFromOfficeArtCOLORREF(so.OptionsByID[DIaLOGIKa.b2xtranslator.OfficeDrawing.ShapeOptions.PropertyId.lineBackColor].op, slide, so); break; case 0xF7: //shape fill color if shape contains a fill else line color result = getRGBColorFromOfficeArtCOLORREF(so.OptionsByID[DIaLOGIKa.b2xtranslator.OfficeDrawing.ShapeOptions.PropertyId.fillColor].op, slide, so); break; case 0xFF: //undefined return(""); } if (result.Length == 0) { return(""); } int red = int.Parse(result.Substring(0, 2), System.Globalization.NumberStyles.HexNumber); int green = int.Parse(result.Substring(2, 2), System.Globalization.NumberStyles.HexNumber); int blue = int.Parse(result.Substring(4, 2), System.Globalization.NumberStyles.HexNumber); int v = (int)bytes[2]; int res; return(result); //switch (val & 0xff00) //{ // case 0x100: // if (blue == 0xff) return result; // if (blue == 0x00) return "000000"; // res = int.Parse(result, System.Globalization.NumberStyles.HexNumber); // if (!so.OptionsByID.ContainsKey(DIaLOGIKa.b2xtranslator.OfficeDrawing.ShapeOptions.PropertyId.ShadowStyleBooleanProperties)) // res -= v; //this is wrong for shadow17 // if (res < 0) res = 0; // return res.ToString("X").PadLeft(6, '0'); // case 0x200: // if (blue == 0xff) return result; // if (blue == 0x00) return "FFFFFF"; // res = int.Parse(result, System.Globalization.NumberStyles.HexNumber); // res += v; // return res.ToString("X").PadLeft(6, '0'); // case 0x300: // red += v; // green += v; // blue += v; // if (red > 0xff) red = 0xff; // if (green > 0xff) green = 0xff; // if (blue > 0xff) blue = 0xff; // return red.ToString("X").PadLeft(2, '0') + green.ToString("X").PadLeft(2, '0') + blue.ToString("X").PadLeft(2, '0'); // case 0x400: // red -= v; // green -= v; // blue -= v; // if (red < 0) red = 0x0; // if (green < 0) green = 0x0; // if (blue < 0) blue = 0x0; // return red.ToString("X").PadLeft(2, '0') + green.ToString("X").PadLeft(2, '0') + blue.ToString("X").PadLeft(2, '0'); // case 0x500: // red = v - red; // green = v - green; // blue = v - blue; // if (red < 0) red = 0x0; // if (green < 0) green = 0x0; // if (blue < 0) blue = 0x0; // return red.ToString("X").PadLeft(2, '0') + green.ToString("X").PadLeft(2, '0') + blue.ToString("X").PadLeft(2, '0'); // default: // break; //} } if (fSchemeIndex) { //red is the index to the color scheme //List<ColorSchemeAtom> colors = slide.AllChildrenWithType<ColorSchemeAtom>(); //ColorSchemeAtom MasterScheme = null; //foreach (ColorSchemeAtom color in colors) //{ // if (color.Instance == 1) MasterScheme = color; //} switch (bytes[0]) { case 0x00: //background SchemeType = "bg1"; return(new RGBColor(MasterScheme.Background, RGBColor.ByteOrder.RedFirst).SixDigitHexCode); case 0x01: //text SchemeType = "tx1"; return(new RGBColor(MasterScheme.TextAndLines, RGBColor.ByteOrder.RedFirst).SixDigitHexCode); case 0x02: //shadow return(new RGBColor(MasterScheme.Shadows, RGBColor.ByteOrder.RedFirst).SixDigitHexCode); case 0x03: //title return(new RGBColor(MasterScheme.TitleText, RGBColor.ByteOrder.RedFirst).SixDigitHexCode); case 0x04: //fill SchemeType = "accent1"; return(new RGBColor(MasterScheme.Fills, RGBColor.ByteOrder.RedFirst).SixDigitHexCode); case 0x05: //accent1 SchemeType = "accent2"; return(new RGBColor(MasterScheme.Accent, RGBColor.ByteOrder.RedFirst).SixDigitHexCode); case 0x06: //accent2 SchemeType = "hlink"; return(new RGBColor(MasterScheme.AccentAndHyperlink, RGBColor.ByteOrder.RedFirst).SixDigitHexCode); case 0x07: //accent3 return(new RGBColor(MasterScheme.AccentAndFollowedHyperlink, RGBColor.ByteOrder.RedFirst).SixDigitHexCode); case 0xFE: //sRGB return(bytes[0].ToString("X").PadLeft(2, '0') + bytes[1].ToString("X").PadLeft(2, '0') + bytes[3].ToString("X").PadLeft(2, '0')); case 0xFF: //undefined break; } } return(bytes[0].ToString("X").PadLeft(2, '0') + bytes[1].ToString("X").PadLeft(2, '0') + bytes[2].ToString("X").PadLeft(2, '0')); }
public static string getRGBColorFromOfficeArtCOLORREF(uint value, RegularContainer slide, DIaLOGIKa.b2xtranslator.OfficeDrawing.ShapeOptions so) { string dummy = ""; return(getRGBColorFromOfficeArtCOLORREF(value, slide, so, ref dummy)); }