PowerPoint2007Export.cs 88 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149
  1. using FastReport.Gauge;
  2. using FastReport.Map;
  3. using FastReport.Table;
  4. using FastReport.Utils;
  5. using System;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. using System.Drawing;
  9. using System.Globalization;
  10. using System.IO;
  11. using System.Text;
  12. namespace FastReport.Export.OoXML
  13. {
  14. /// <summary>
  15. /// Power point shape
  16. /// </summary>
  17. internal class PptShape : OoXMLBase
  18. {
  19. const float PPT_DIVIDER = 360000 / 37.8f;
  20. #region Class overrides
  21. public override string RelationType
  22. {
  23. get
  24. {
  25. if (aObj.Fill is TextureFill ||
  26. aObj is PictureObjectBase ||
  27. aObj is Barcode.BarcodeObject ||
  28. aObj is CheckBoxObject ||
  29. aObj is ZipCodeObject ||
  30. #if MSCHART
  31. aObj is MSChart.MSChartObject ||
  32. #endif
  33. aObj is RichObject ||
  34. aObj is TextObject ||
  35. aObj is MapObject ||
  36. aObj is GaugeObject)
  37. return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image";
  38. // TODO check if throw realy need
  39. throw new Exception("Cant get relation type for this object");
  40. }
  41. }
  42. public override string ContentType { get { throw new Exception(); } }
  43. public override string FileName
  44. {
  45. get
  46. {
  47. if (aObj.Fill is TextureFill ||
  48. aObj is PictureObjectBase ||
  49. aObj is Barcode.BarcodeObject ||
  50. aObj is CheckBoxObject ||
  51. aObj is ZipCodeObject ||
  52. #if MSCHART
  53. aObj is MSChart.MSChartObject ||
  54. #endif
  55. aObj is RichObject ||
  56. aObj is TextObject ||
  57. aObj is MapObject ||
  58. aObj is GaugeObject)
  59. return name;
  60. // TODO check if throw realy need
  61. throw new Exception("Cannot store object as image");
  62. }
  63. }
  64. #endregion
  65. int id;
  66. int relationIdentifier;
  67. string name;
  68. PowerPoint2007Export pptExport;
  69. ulong x;
  70. ulong y;
  71. ulong cX;
  72. ulong cY;
  73. bool flipH;
  74. bool flipV;
  75. StringBuilder textStrings;
  76. ReportComponentBase aObj;
  77. #region "Private methods"
  78. private new string Quoted(string p) { return "\"" + p + "\" "; }
  79. private new string Quoted(long p) { return "\"" + p.ToString() + "\" "; }
  80. private string QuotedString(ulong a) { return "\"" + a.ToString() + "\" "; }
  81. private string GetRGBString(Color c)
  82. {
  83. return "\"" + ExportUtils.ByteToHex(c.R) + ExportUtils.ByteToHex(c.G) + ExportUtils.ByteToHex(c.B) + "\"";
  84. }
  85. private string GetDashType(LineStyle style)
  86. {
  87. switch (style)
  88. {
  89. case LineStyle.Solid: return "<a:prstDash val=\"solid\" />";
  90. case LineStyle.Dot: return "<a:prstDash val=\"sysDot\" />";
  91. case LineStyle.Dash: return "<a:prstDash val=\"sysDash\" />";
  92. case LineStyle.DashDot: return "<a:prstDash val=\"sysDashDot\" />";
  93. case LineStyle.DashDotDot: return "<a:prstDash val=\"sysDashDotDot\" />";
  94. case LineStyle.Double: return "";
  95. }
  96. throw new Exception("Unsupported dash style");
  97. }
  98. private string TranslateText(string text)
  99. {
  100. StringBuilder TextStrings = new StringBuilder();
  101. int start_idx = 0;
  102. while (true)
  103. {
  104. int idx = text.IndexOfAny("&<>".ToCharArray(), start_idx);
  105. if (idx != -1)
  106. {
  107. TextStrings.Append(text.Substring(start_idx, idx - start_idx));
  108. switch (text[idx])
  109. {
  110. case '&': TextStrings.Append("&amp;"); break;
  111. case '<': TextStrings.Append("&lt;"); break;
  112. case '>': TextStrings.Append("&gt;"); break;
  113. }
  114. start_idx = ++idx;
  115. continue;
  116. }
  117. TextStrings.Append(text.Substring(start_idx));
  118. break;
  119. }
  120. return TextStrings.ToString();
  121. }
  122. #endregion
  123. public int RelationID { get { return relationIdentifier; } }
  124. public ReportComponentBase Object { get { return aObj; } }
  125. #region Constructors
  126. public PptShape(int Id, int RelationID, string Name, ReportComponentBase obj, PowerPoint2007Export ppt_export)
  127. {
  128. this.id = Id;
  129. this.relationIdentifier = RelationID;
  130. this.name = Name;
  131. this.aObj = obj;
  132. this.pptExport = ppt_export;
  133. this.x = (ulong)(obj.AbsLeft * PPT_DIVIDER + pptExport.LeftMargin);
  134. this.y = (ulong)(obj.AbsTop * PPT_DIVIDER + pptExport.TopMargin);
  135. if (obj.Height < 0)
  136. { this.cY = (ulong)-(obj.Height * PPT_DIVIDER); flipV = true; }
  137. else
  138. { this.cY = (ulong)(obj.Height * PPT_DIVIDER); flipV = false; }
  139. if (obj.Width < 0)
  140. { this.cX = (ulong)-Math.Round((obj.Width + 1) * PPT_DIVIDER); flipH = true; }
  141. else
  142. { this.cX = (ulong)Math.Round((obj.Width + 1) * PPT_DIVIDER); flipH = false; }
  143. if (cX == 0) cX = 1; // 588;
  144. if (cY == 0) cY = 1588;
  145. textStrings = new StringBuilder();
  146. }
  147. #endregion
  148. private bool Export_Borders(Stream Out, bool rotated)
  149. {
  150. const long EMU = 12700;
  151. Border b = aObj.Border;
  152. bool same_border =
  153. b.Lines == BorderLines.All &&
  154. (b.BottomLine.Color == b.LeftLine.Color) &&
  155. (b.BottomLine.Color == b.TopLine.Color) &&
  156. (b.BottomLine.Color == b.RightLine.Color) &&
  157. (b.BottomLine.DashStyle == b.LeftLine.DashStyle) &&
  158. (b.BottomLine.DashStyle == b.TopLine.DashStyle) &&
  159. (b.BottomLine.DashStyle == b.RightLine.DashStyle) &&
  160. (b.BottomLine.Width == b.LeftLine.Width) &&
  161. (b.BottomLine.Width == b.TopLine.Width) &&
  162. (b.BottomLine.Width == b.RightLine.Width);
  163. if (aObj is LineObject || (aObj is ShapeObject) || (aObj is PolyLineObject)
  164. /*|| (FObject is TableCell)*/ ||
  165. (same_border && !rotated))
  166. {
  167. ulong bw = (ulong)(EMU * aObj.Border.Width);
  168. ExportUtils.WriteLn(Out, "<a:ln w=" + QuotedString(bw) + ">");
  169. ExportUtils.WriteLn(Out, "<a:solidFill>");
  170. ExportUtils.WriteLn(Out, "<a:srgbClr val=" + GetRGBString(b.Color) + " />");
  171. ExportUtils.WriteLn(Out, "</a:solidFill>");
  172. ExportUtils.WriteLn(Out, GetDashType(b.Style));
  173. if (aObj is LineObject)
  174. {
  175. LineObject line = aObj as LineObject;
  176. string StartCap = null;
  177. string EndCap = null;
  178. switch (line.StartCap.Style)
  179. {
  180. case CapStyle.Arrow: StartCap = "classic"; break;
  181. case CapStyle.Circle: StartCap = "oval"; break;
  182. case CapStyle.Diamond: StartCap = "diamond"; break;
  183. case CapStyle.Square: StartCap = "diamond"; break;
  184. }
  185. if (StartCap != null) ExportUtils.WriteLn(Out, "<a:tailEnd type=" + Quoted(StartCap) + " />");
  186. switch (line.EndCap.Style)
  187. {
  188. case CapStyle.Arrow: EndCap = "classic"; break;
  189. case CapStyle.Circle: EndCap = "oval"; break;
  190. case CapStyle.Diamond: EndCap = "diamond"; break;
  191. case CapStyle.Square: EndCap = "diamond"; break;
  192. }
  193. if (EndCap != null) ExportUtils.WriteLn(Out, "<a:headEnd type=" + Quoted(EndCap) + " />");
  194. }
  195. ExportUtils.WriteLn(Out, "</a:ln>");
  196. }
  197. return (!same_border || rotated) && (aObj.Border.Lines != BorderLines.None);
  198. }
  199. internal void ExportFourBorders(Stream Out, int id)
  200. {
  201. Border b = aObj.Border;
  202. if ((b.Lines & BorderLines.Left) == BorderLines.Left)
  203. {
  204. Export_Line(Out, x, y, 0, cY, b.LeftLine.Color, b.LeftLine.Width, b.LeftLine.Style, id++);
  205. }
  206. if ((b.Lines & BorderLines.Bottom) == BorderLines.Bottom)
  207. {
  208. Export_Line(Out, x, y + cY, cX, 0, b.BottomLine.Color, b.BottomLine.Width, b.BottomLine.Style, id++);
  209. }
  210. if ((b.Lines & BorderLines.Right) == BorderLines.Right)
  211. {
  212. Export_Line(Out, x + cX, y, 0, cY, b.RightLine.Color, b.RightLine.Width, b.RightLine.Style, id++);
  213. }
  214. if ((b.Lines & BorderLines.Top) == BorderLines.Top)
  215. {
  216. Export_Line(Out, x, y, cX, 0, b.TopLine.Color, b.TopLine.Width, b.TopLine.Style, id++);
  217. }
  218. }
  219. private void Export_Fills(Stream Out)
  220. {
  221. const long PXA = 60000;
  222. if (aObj.Fill is LinearGradientFill)
  223. {
  224. LinearGradientFill linear = aObj.Fill as LinearGradientFill;
  225. ExportUtils.WriteLn(Out, "<a:gradFill flip=\"none\" rotWithShape=\"1\">");
  226. ExportUtils.WriteLn(Out, "<a:gsLst>");
  227. ExportUtils.WriteLn(Out, "<a:gs pos=\"0\">");
  228. ExportUtils.WriteLn(Out, "<a:srgbClr val=" + GetRGBString(linear.StartColor) + " />");
  229. ExportUtils.WriteLn(Out, "</a:gs>");
  230. ExportUtils.WriteLn(Out, "<a:gs pos=\"100000\">");
  231. ExportUtils.WriteLn(Out, "<a:srgbClr val=" + GetRGBString(linear.EndColor) + " />");
  232. ExportUtils.WriteLn(Out, "</a:gs>");
  233. ExportUtils.WriteLn(Out, "</a:gsLst>");
  234. ExportUtils.WriteLn(Out, "<a:lin ang=" + Quoted((linear.Angle * PXA).ToString()) + " scaled=\"1\" />");
  235. ExportUtils.WriteLn(Out, "<a:tileRect />");
  236. ExportUtils.WriteLn(Out, "</a:gradFill>");
  237. }
  238. else if (aObj.Fill is SolidFill)
  239. {
  240. SolidFill fill = aObj.Fill as SolidFill;
  241. if (fill.IsTransparent)
  242. {
  243. ExportUtils.WriteLn(Out, "<a:noFill />");
  244. }
  245. else
  246. {
  247. ExportUtils.WriteLn(Out, "<a:solidFill>");
  248. ExportUtils.WriteLn(Out, "<a:srgbClr val=" + GetRGBString(fill.Color) + " />");
  249. ExportUtils.WriteLn(Out, "</a:solidFill>");
  250. }
  251. }
  252. else if (aObj.Fill is GlassFill)
  253. {
  254. GlassFill fill = aObj.Fill as GlassFill;
  255. ExportUtils.WriteLn(Out, "<a:gradFill flip=\"none\" rotWithShape=\"1\">");
  256. ExportUtils.WriteLn(Out, "<a:gsLst>");
  257. ExportUtils.WriteLn(Out, "<a:gs pos=\"0\">");
  258. ExportUtils.WriteLn(Out, "<a:srgbClr val=" + GetRGBString(fill.Color) + ">");
  259. ExportUtils.WriteLn(Out, "<a:alpha val=\"50000\" />");
  260. ExportUtils.WriteLn(Out, "</a:srgbClr>");
  261. ExportUtils.WriteLn(Out, "</a:gs>");
  262. ExportUtils.WriteLn(Out, "<a:gs pos=\"50000\">");
  263. ExportUtils.WriteLn(Out, "<a:srgbClr val=" + GetRGBString(fill.Color) + ">");
  264. ExportUtils.WriteLn(Out, "<a:alpha val=\"50000\" />");
  265. ExportUtils.WriteLn(Out, "</a:srgbClr>");
  266. ExportUtils.WriteLn(Out, "</a:gs>");
  267. ExportUtils.WriteLn(Out, "<a:gs pos=\"50001\">");
  268. ExportUtils.WriteLn(Out, "<a:srgbClr val=" + GetRGBString(fill.Color) + " />");
  269. ExportUtils.WriteLn(Out, "</a:gs>");
  270. ExportUtils.WriteLn(Out, "<a:gs pos=\"100000\">");
  271. ExportUtils.WriteLn(Out, "<a:srgbClr val=" + GetRGBString(fill.Color) + " />");
  272. ExportUtils.WriteLn(Out, "</a:gs>");
  273. ExportUtils.WriteLn(Out, "</a:gsLst>");
  274. ExportUtils.WriteLn(Out, "<a:lin ang=" + Quoted(5400000) + " scaled=\"1\" />");
  275. ExportUtils.WriteLn(Out, "<a:tileRect />");
  276. ExportUtils.WriteLn(Out, "</a:gradFill>");
  277. }
  278. else if (aObj.Fill is HatchFill)
  279. {
  280. ExportUtils.WriteLn(Out, "<a:blipFill dpi=\"0\" rotWithShape=\"1\">");
  281. ExportUtils.WriteLn(Out, "<a:blip r:embed=" + Quoted(rId) + " cstate=\"print\" />");
  282. ExportUtils.WriteLn(Out, "<a:srcRect />");
  283. ExportUtils.WriteLn(Out, "<a:stretch>");
  284. ExportUtils.WriteLn(Out, "<a:fillRect />");
  285. ExportUtils.WriteLn(Out, "</a:stretch>");
  286. ExportUtils.WriteLn(Out, "</a:blipFill>");
  287. }
  288. else if (aObj.Fill is PathGradientFill)
  289. {
  290. ExportUtils.WriteLn(Out, "<a:blipFill dpi=\"0\" rotWithShape=\"1\">");
  291. ExportUtils.WriteLn(Out, "<a:blip r:embed=" + Quoted(rId) + " cstate=\"print\" />");
  292. ExportUtils.WriteLn(Out, "<a:srcRect />");
  293. ExportUtils.WriteLn(Out, "<a:stretch>");
  294. ExportUtils.WriteLn(Out, "<a:fillRect />");
  295. ExportUtils.WriteLn(Out, "</a:stretch>");
  296. ExportUtils.WriteLn(Out, "</a:blipFill>");
  297. }
  298. else if (aObj.Fill is TextureFill)
  299. {
  300. //not implemented yet;
  301. }
  302. else
  303. {
  304. throw new Exception("Unknown fill");
  305. }
  306. }
  307. private string Get_Anchor()
  308. {
  309. if (aObj is TextObject) switch ((aObj as TextObject).VertAlign)
  310. {
  311. case VertAlign.Top: return "\"t\"";
  312. case VertAlign.Center: return "\"ctr\"";
  313. case VertAlign.Bottom: return "\"b\"";
  314. }
  315. if (aObj is TableBase) return "\"ctr\"";
  316. if (aObj is ShapeObject || aObj is PolyLineObject) return "\"ctr\"";
  317. throw new Exception("Bad vertical align");
  318. }
  319. private void GetCoords(PointF point, out ulong x, out ulong y)
  320. {
  321. x = (ulong)(point.X * PPT_DIVIDER);
  322. y = (ulong)(point.Y * PPT_DIVIDER);
  323. }
  324. private void ExportGdLst(Stream Out, PointF[] points)
  325. {
  326. ulong x, y;
  327. ExportUtils.WriteLn(Out, "<a:gdLst>");
  328. for (int i = 0; i < points.Length; i++)
  329. {
  330. GetCoords(points[i], out x, out y);
  331. ExportUtils.WriteLn(Out, "<a:gd name=\"connsiteX" + i + "\" fmla=\"*/ " + x + " w " + cX + "\"/>");
  332. ExportUtils.WriteLn(Out, "<a:gd name=\"connsiteY" + i + "\" fmla=\"*/ " + y + " h " + cY + "\"/>");
  333. }
  334. if (Object is PolygonObject)
  335. {
  336. GetCoords(points[0], out x, out y);
  337. ExportUtils.WriteLn(Out, "<a:gd name=\"connsiteX" + points.Length + "\" fmla=\"*/ " + x + " w " + cX + "\"/>");
  338. ExportUtils.WriteLn(Out, "<a:gd name=\"connsiteY" + points.Length + "\" fmla=\"*/ " + y + " h " + cY + "\"/>");
  339. }
  340. ExportUtils.WriteLn(Out, "</a:gdLst>");
  341. }
  342. private void ExportPathLst(Stream Out, PointF[] points)
  343. {
  344. ulong x, y;
  345. ExportUtils.WriteLn(Out, "<a:pathLst>");
  346. ExportUtils.WriteLn(Out, "<a:path w=\"" + cX + "\" h=\"" + cY + "\">");
  347. for (int i = 0; i < points.Length; i++)
  348. {
  349. GetCoords(points[i], out x, out y);
  350. if (i == 0)
  351. {
  352. ExportUtils.WriteLn(Out, "<a:moveTo>");
  353. ExportUtils.WriteLn(Out, "<a:pt x=\"" + x + "\" y=\"" + y + "\"/>");
  354. ExportUtils.WriteLn(Out, "</a:moveTo>");
  355. }
  356. else
  357. {
  358. ExportUtils.WriteLn(Out, "<a:lnTo>");
  359. ExportUtils.WriteLn(Out, "<a:pt x=\"" + x + "\" y=\"" + y + "\"/>");
  360. ExportUtils.WriteLn(Out, "</a:lnTo>");
  361. }
  362. }
  363. if (Object is PolygonObject)
  364. {
  365. GetCoords(points[0], out x, out y);
  366. ExportUtils.WriteLn(Out, "<a:lnTo>");
  367. ExportUtils.WriteLn(Out, "<a:pt x=\"" + x + "\" y=\"" + y + "\"/>");
  368. ExportUtils.WriteLn(Out, "</a:lnTo>");
  369. ExportUtils.WriteLn(Out, "<a:close/>");
  370. }
  371. ExportUtils.WriteLn(Out, "</a:path>");
  372. ExportUtils.WriteLn(Out, "</a:pathLst>");
  373. }
  374. internal bool Export_XFRM(Stream Out, char Ch)
  375. {
  376. bool swap = false;
  377. bool rotated = false;
  378. // <a:xfrm>
  379. if (aObj is LineObject && (aObj as LineObject).Diagonal)
  380. {
  381. if (flipV == true) y = y - cY;
  382. if (flipH == true) x = x - cX;
  383. ExportUtils.WriteLn(Out, "<" + Ch + ":xfrm flipH=" + Quoted(flipH ? "0" : "1") + " flipV=" + Quoted(flipV ? "0" : "1") + " >");
  384. }
  385. else if (aObj is TextObject)
  386. {
  387. TextObject obj = aObj as TextObject;
  388. long dy;
  389. unchecked { dy = ((long)(cY - cX)) / 2; }
  390. switch (obj.Angle)
  391. {
  392. case 0:
  393. ExportUtils.WriteLn(Out, "<" + Ch + ":xfrm>");
  394. break;
  395. case 90:
  396. y = (ulong)((long)y + dy);
  397. x = (ulong)((long)x - dy);
  398. ExportUtils.WriteLn(Out, "<" + Ch + ":xfrm rot=\"5400000\">");
  399. swap = true;
  400. break;
  401. case 180:
  402. ExportUtils.WriteLn(Out, "<" + Ch + ":xfrm rot=\"10800000\">");
  403. break;
  404. case 270:
  405. y = (ulong)((long)y + dy);
  406. x = (ulong)((long)x - dy);
  407. ExportUtils.WriteLn(Out, "<" + Ch + ":xfrm rot=\"16200000\">");
  408. swap = true;
  409. break;
  410. default:
  411. ExportUtils.WriteLn(Out, "<" + Ch + ":xfrm rot=\"" + 60000 * obj.Angle + "\">");
  412. rotated = true;
  413. break;
  414. }
  415. }
  416. else
  417. ExportUtils.WriteLn(Out, "<" + Ch + ":xfrm>");
  418. ExportUtils.WriteLn(Out, "<a:off x=" + QuotedString(x) + " y=" + QuotedString(y) + " />");
  419. if (swap)
  420. ExportUtils.WriteLn(Out, "<a:ext cx=" + QuotedString(cY) + " cy=" + QuotedString(cX) + " />");
  421. else
  422. ExportUtils.WriteLn(Out, "<a:ext cx=" + QuotedString(cX) + " cy=" + QuotedString(cY) + " />");
  423. ExportUtils.WriteLn(Out, "</" + Ch + ":xfrm>");
  424. return rotated;
  425. }
  426. internal bool Export_spPr(Stream Out, string PresetGeometry)
  427. {
  428. bool do_borders = false;
  429. bool rotated;
  430. if (cX != 0 && cY != 0)
  431. {
  432. ExportUtils.WriteLn(Out, "<p:spPr>");
  433. rotated = Export_XFRM(Out, 'a');
  434. if (PresetGeometry != null)
  435. {
  436. ExportUtils.WriteLn(Out, "<a:prstGeom prst=" + Quoted(PresetGeometry) + ">");
  437. ExportUtils.WriteLn(Out, "<a:avLst />");
  438. ExportUtils.WriteLn(Out, "</a:prstGeom>");
  439. }
  440. else if (Object is PolyLineObject) //polyline or polygon
  441. {
  442. PolyLineObject polyline = Object as PolyLineObject;
  443. //transform coords
  444. PointF[] points = polyline.PointsArray;
  445. for (int i = 0; i < points.Length; i++)
  446. {
  447. if (points[i].X < 0)
  448. {
  449. for (int j = 0; j < points.Length; j++)
  450. {
  451. if (j != i)
  452. points[j].X += Math.Abs(points[i].X);
  453. }
  454. points[i].X = 0;
  455. }
  456. if (points[i].Y < 0)
  457. {
  458. for (int j = 0; j < points.Length; j++)
  459. {
  460. if (j != i)
  461. points[j].Y += Math.Abs(points[i].Y);
  462. }
  463. points[i].Y = 0;
  464. }
  465. }
  466. ExportUtils.WriteLn(Out, "<a:custGeom>");
  467. ExportUtils.WriteLn(Out, "<a:avLst/>");
  468. ExportGdLst(Out, points);
  469. ExportUtils.WriteLn(Out, "<a:ahLst/>");
  470. ExportPathLst(Out, points);
  471. ExportUtils.WriteLn(Out, "</a:custGeom>");
  472. }
  473. if (Object.Fill is PathGradientFill || Object.Fill is HatchFill)
  474. Object.Fill = new SolidFill(ExportUtils.GetColorFromFill(Object.Fill));
  475. Export_Fills(Out);
  476. do_borders = Export_Borders(Out, rotated);
  477. if (do_borders)
  478. {
  479. float left, right, top, bottom;
  480. if ((aObj.Border.Lines & BorderLines.Left) == BorderLines.Left)
  481. left = aObj.Border.LeftLine.Width * PPT_DIVIDER;
  482. else left = 0;
  483. if ((aObj.Border.Lines & BorderLines.Top) == BorderLines.Top)
  484. top = aObj.Border.TopLine.Width * PPT_DIVIDER;
  485. else top = 0;
  486. if ((aObj.Border.Lines & BorderLines.Right) == BorderLines.Right)
  487. right = aObj.Border.RightLine.Width * PPT_DIVIDER;
  488. else right = 0;
  489. if ((aObj.Border.Lines & BorderLines.Bottom) == BorderLines.Bottom)
  490. bottom = aObj.Border.BottomLine.Width * PPT_DIVIDER;
  491. else bottom = 0;
  492. //X += (ulong)left;
  493. //Y += (ulong)top;
  494. //CX -= (ulong)(left + right);
  495. //CY -= (ulong)(top + bottom);
  496. }
  497. ExportUtils.WriteLn(Out, "</p:spPr>");
  498. }
  499. else
  500. ExportUtils.WriteLn(Out, "<p:spPr />");
  501. return do_borders;
  502. }
  503. #region "Export Non-Visual prroperties"
  504. internal void Export_nvPicPr(Stream Out, int PicCount)
  505. {
  506. ExportUtils.WriteLn(Out, "<p:nvPicPr>");
  507. ExportUtils.WriteLn(Out, "<p:cNvPr id=" + Quoted(id.ToString()) +
  508. " name=" + Quoted("Picture" + id) + " descr=" + Quoted("image" + PicCount.ToString() + ".png") + " />");
  509. ExportUtils.WriteLn(Out, "<p:cNvPicPr>");
  510. ExportUtils.WriteLn(Out, "<a:picLocks noChangeAspect=\"1\" />");
  511. ExportUtils.WriteLn(Out, "</p:cNvPicPr>");
  512. ExportUtils.WriteLn(Out, "<p:nvPr />");
  513. ExportUtils.WriteLn(Out, "</p:nvPicPr>");
  514. }
  515. internal void Export_nvSpPr(Stream Out)
  516. {
  517. ExportUtils.WriteLn(Out, "<p:nvSpPr>");
  518. ExportUtils.WriteLn(Out, "<p:cNvPr id=" + Quoted(id.ToString()) + " name=" + Quoted(name) + " />");
  519. ExportUtils.WriteLn(Out, "<p:cNvSpPr>");
  520. ExportUtils.WriteLn(Out, "<a:spLocks noGrp=" + Quoted("1") + " />"); // fix me
  521. ExportUtils.WriteLn(Out, "</p:cNvSpPr>");
  522. ExportUtils.WriteLn(Out, "<p:nvPr>");
  523. // Out placeholder
  524. ExportUtils.Write(Out, "<p:ph ");
  525. ExportUtils.Write(Out, "/>");
  526. ExportUtils.WriteLn(Out, "</p:nvPr>");
  527. ExportUtils.WriteLn(Out, "</p:nvSpPr>");
  528. }
  529. internal void Export_nvGraphicFramePr(Stream Out)
  530. {
  531. ExportUtils.Write(Out, "<p:nvGraphicFramePr>");
  532. ExportUtils.Write(Out, "<p:cNvPr id=" + Quoted(id.ToString()) + " name=" + Quoted(name) + " />");
  533. ExportUtils.Write(Out, "<p:cNvGraphicFramePr>");
  534. ExportUtils.Write(Out, "<a:graphicFrameLocks noGrp=\"1\" />");
  535. ExportUtils.Write(Out, "</p:cNvGraphicFramePr>");
  536. ExportUtils.Write(Out, "<p:nvPr />");
  537. ExportUtils.Write(Out, "</p:nvGraphicFramePr>");
  538. }
  539. internal void Export_nvCxnSpPr(Stream Out)
  540. {
  541. ExportUtils.WriteLn(Out, "<p:nvCxnSpPr>");
  542. ExportUtils.WriteLn(Out, "<p:cNvPr id=" + Quoted(id.ToString()) + " name=" + Quoted(name) + " />");
  543. ExportUtils.WriteLn(Out, "<p:cNvCxnSpPr />");
  544. ExportUtils.WriteLn(Out, "<p:nvPr />");
  545. ExportUtils.WriteLn(Out, "</p:nvCxnSpPr>");
  546. }
  547. #endregion
  548. internal void Export_blipFill(Stream Out)
  549. {
  550. ExportUtils.WriteLn(Out, "<p:blipFill>");
  551. ExportUtils.WriteLn(Out, "<a:blip r:embed=" + Quoted("rId" + this.RelationID.ToString()) + " cstate=\"print\" />");
  552. ExportUtils.WriteLn(Out, "<a:stretch>");
  553. ExportUtils.WriteLn(Out, "<a:fillRect />");
  554. ExportUtils.WriteLn(Out, "</a:stretch>");
  555. ExportUtils.WriteLn(Out, "</p:blipFill>");
  556. }
  557. internal void Open_Paragraph()
  558. {
  559. string align = "ctr";
  560. TextObject text_obj = (aObj is TextObject) ? aObj as TextObject : null;
  561. if (aObj is TextObject) switch (text_obj.HorzAlign)
  562. {
  563. case HorzAlign.Left: align = "l"; break;
  564. case HorzAlign.Right: align = "r"; break;
  565. case HorzAlign.Center: align = "ctr"; break;
  566. case HorzAlign.Justify: align = "just"; break;
  567. }
  568. textStrings.AppendLine("<a:p><a:pPr algn=" + Quoted(align) + " />");
  569. }
  570. internal void Add_Run(
  571. Font Font,
  572. Color TextColor,
  573. string Text
  574. )
  575. {
  576. float FDpiFX = 96f / DrawUtils.ScreenDpi;
  577. long Size = (long)(Font.Size * 100 / FDpiFX);
  578. bool Italic = Font.Italic;
  579. bool Underline = Font.Underline;
  580. if (Text != null)
  581. {
  582. textStrings.AppendLine("<a:r>");
  583. textStrings.AppendLine($"<a:rPr lang=\"{pptExport.GetLoacalizationName()}\" sz=" + Quoted(Size) +
  584. "b=" + Quoted(Font.Bold ? "1" : "0") +
  585. "i=" + Quoted(Font.Italic ? "1" : "0") +
  586. (Font.Underline ? ("u=" + Quoted("sng")) : "") +
  587. " smtClean=\"0\" >");
  588. textStrings.AppendLine("<a:solidFill><a:srgbClr val=" + GetRGBString(TextColor) + ">");
  589. if (TextColor.A != Byte.MaxValue)
  590. {
  591. long alpha = (100000 * TextColor.A) / Byte.MaxValue;
  592. textStrings.AppendLine("<a:alpha val=" + Quoted(alpha) + " />");
  593. }
  594. textStrings.AppendLine("</a:srgbClr></a:solidFill>");
  595. textStrings.AppendLine("<a:latin typeface=" + Quoted(Font.Name) + /*"pitchFamily=" + Quoted( "22" ) +*/ " />");
  596. textStrings.AppendLine("</a:rPr>");
  597. textStrings.AppendLine("<a:t>" + this.TranslateText(Text) + "</a:t>");
  598. textStrings.AppendLine("</a:r>");
  599. }
  600. textStrings.AppendLine($"<a:r><a:rPr lang=\"{pptExport.GetLoacalizationName()}\" sz=" + Quoted(Size) + "></a:rPr><a:t> </a:t></a:r>");
  601. }
  602. internal void Close_Paragraph()
  603. {
  604. textStrings.AppendLine("</a:p>");
  605. }
  606. internal void Export_txBody(Stream Out)
  607. {
  608. ExportUtils.WriteLn(Out, "<p:txBody>");
  609. ExportUtils.WriteLn(Out, "<a:bodyPr vert=\"horz\" lIns=\"45720\" tIns=\"22860\" rIns=\"45720\" bIns=\"22860\" rtlCol=\"0\" anchor=" + Get_Anchor() + ">");
  610. ExportUtils.WriteLn(Out, "<a:normAutofit />");
  611. ExportUtils.WriteLn(Out, "</a:bodyPr>");
  612. ExportUtils.WriteLn(Out, "<a:lstStyle />");
  613. ExportUtils.WriteLn(Out, textStrings.ToString());
  614. ExportUtils.WriteLn(Out, "</p:txBody>");
  615. }
  616. internal void ResetText()
  617. {
  618. textStrings = null;
  619. textStrings = new StringBuilder();
  620. }
  621. internal void MoveObject(ReportComponentBase obj)
  622. {
  623. this.aObj = obj;
  624. this.x = (ulong)(obj.AbsLeft * PPT_DIVIDER + pptExport.LeftMargin);
  625. this.y = (ulong)(obj.AbsTop * PPT_DIVIDER + pptExport.TopMargin);
  626. this.cX = (ulong)(obj.Width * PPT_DIVIDER);
  627. if (obj.Height < 0)
  628. { this.cY = (ulong)-(obj.Height * PPT_DIVIDER); flipV = true; }
  629. else { this.cY = (ulong)(obj.Height * PPT_DIVIDER); flipV = false; }
  630. if (obj.Width < 0)
  631. { this.cX = (ulong)-(obj.Width * PPT_DIVIDER); flipH = true; }
  632. else
  633. { this.cX = (ulong)(obj.Width * PPT_DIVIDER); flipH = false; }
  634. if (cX == 0) cX = 1588;
  635. if (cY == 0) cY = 1588;
  636. }
  637. private void Export_Line(Stream Out, ulong x, ulong y, ulong dx, ulong dy, Color LineColor, float width, LineStyle style, int id)
  638. {
  639. ExportUtils.WriteLn(Out, "<p:cxnSp>");
  640. ExportUtils.WriteLn(Out, "<p:nvCxnSpPr><p:cNvPr id=" + Quoted(id) + " name=\"Straight Connector 61\" /><p:cNvCxnSpPr />");
  641. ExportUtils.WriteLn(Out, "<p:nvPr />");
  642. ExportUtils.WriteLn(Out, "</p:nvCxnSpPr>");
  643. ExportUtils.WriteLn(Out, "<p:spPr>");
  644. ExportUtils.WriteLn(Out, "<a:xfrm>" +
  645. "<a:off x=" + Quoted(x.ToString()) + " y=" + Quoted(y.ToString()) + " />" +
  646. "<a:ext cx=" + Quoted(dx.ToString()) + " cy=" + Quoted(dy.ToString()) + " />" +
  647. "</a:xfrm>");
  648. width *= 12700;
  649. ExportUtils.WriteLn(Out, "<a:prstGeom prst=\"line\"><a:avLst /> </a:prstGeom>");
  650. ExportUtils.WriteLn(Out, "<a:ln w=" + Quoted(width.ToString()) + "><a:solidFill>");
  651. ExportUtils.WriteLn(Out, "<a:srgbClr val=" + GetRGBString(LineColor) + " />");
  652. ExportUtils.WriteLn(Out, "</a:solidFill>" + GetDashType(style) + "</a:ln></p:spPr>");
  653. ExportUtils.WriteLn(Out, "<p:style><a:lnRef idx=\"1\"><a:schemeClr val=\"accent1\" /></a:lnRef><a:fillRef idx=\"0\">");
  654. ExportUtils.WriteLn(Out, "<a:schemeClr val=\"accent1\" /></a:fillRef><a:effectRef idx=\"0\"><a:schemeClr val=\"accent1\" /></a:effectRef>");
  655. ExportUtils.WriteLn(Out, "<a:fontRef idx=\"minor\"><a:schemeClr val=\"tx1\" /></a:fontRef></p:style></p:cxnSp>");
  656. }
  657. internal void Export_Shadow(Stream Out, int id)
  658. {
  659. ulong x, y, cx, cy;
  660. x = (ulong)((Object.AbsLeft + Object.Border.ShadowWidth /*- 1*/) * PPT_DIVIDER + this.pptExport.LeftMargin);
  661. y = (ulong)((Object.AbsBottom + Object.Border.ShadowWidth / 2) * PPT_DIVIDER + this.pptExport.TopMargin);
  662. cx = (ulong)(Object.Width * PPT_DIVIDER);
  663. Export_Line(Out, x, y, cx, 0, Object.Border.ShadowColor, Object.Border.ShadowWidth, LineStyle.Solid, id++);
  664. x = (ulong)((Object.AbsRight + Object.Border.ShadowWidth / 2) * PPT_DIVIDER + this.pptExport.LeftMargin);
  665. y = (ulong)((Object.AbsTop + Object.Border.ShadowWidth /*- 1*/) * PPT_DIVIDER + this.pptExport.TopMargin);
  666. cy = (ulong)(Object.Height * PPT_DIVIDER);
  667. Export_Line(Out, x, y, 0, cy, Object.Border.ShadowColor, Object.Border.ShadowWidth, LineStyle.Solid, id);
  668. }
  669. };
  670. /// <summary>
  671. /// Power Point Layout Descriptor
  672. /// </summary>
  673. internal class PptLayoutDescriptor
  674. {
  675. public string name;
  676. public string type;
  677. public PptShape[] shapes;
  678. public PptLayoutDescriptor(string Type, string Name, PptShape[] Shapes)
  679. {
  680. this.type = Type;
  681. this.name = Name;
  682. this.shapes = Shapes;
  683. }
  684. }
  685. /// <summary>
  686. /// Power Point base class for style element
  687. /// </summary>
  688. internal class PptStyleBase
  689. {
  690. private uint level = 0;
  691. private long marL = 342900;
  692. private long indent = -342900;
  693. private char algn = 'l';
  694. private long defTabSz = 914400;
  695. private long rtl = 0;
  696. private long eaLnBrk = 1;
  697. private long latinLnBrk = 0;
  698. private long hangingPunct = 1;
  699. private string Quoted(long v) { return "\"" + v.ToString() + "\" "; }
  700. private string Quoted(char v) { return "\"" + v + "\" "; }
  701. private string Quoted(string v) { return "\"" + v + "\" "; }
  702. internal void Export(Stream Out)
  703. {
  704. ExportUtils.WriteLn(Out, "<a:lvl" + level.ToString() + "pPr ");
  705. ExportUtils.WriteLn(Out, "marL=" + Quoted(marL));
  706. ExportUtils.WriteLn(Out, "indent=" + Quoted(indent));
  707. ExportUtils.WriteLn(Out, "algn=" + Quoted(algn));
  708. ExportUtils.WriteLn(Out, "defTabSz=" + Quoted(defTabSz));
  709. ExportUtils.WriteLn(Out, "rtl=" + Quoted(rtl));
  710. ExportUtils.WriteLn(Out, "eaLnBrk=" + Quoted(eaLnBrk));
  711. ExportUtils.WriteLn(Out, "latinLnBrk=" + Quoted(latinLnBrk));
  712. ExportUtils.WriteLn(Out, "hangingPunct=" + Quoted(hangingPunct));
  713. ExportUtils.WriteLn(Out, ">");
  714. ExportUtils.WriteLn(Out, "<a:spcBef>");
  715. ExportUtils.WriteLn(Out, "<a:spcPct val=" + Quoted("0") + "/>");
  716. ExportUtils.WriteLn(Out, "</a:spcBef>");
  717. ExportUtils.WriteLn(Out, "<a:buNone />");
  718. ExportUtils.WriteLn(Out, "<a:defRPr sz=" + Quoted("4400") + "kern=" + Quoted("1200") + ">");
  719. ExportUtils.WriteLn(Out, "<a:solidFill>");
  720. ExportUtils.WriteLn(Out, "<a:schemeClr val=" + Quoted("tx1") + "/>");
  721. ExportUtils.WriteLn(Out, "</a:solidFill>");
  722. ExportUtils.WriteLn(Out, "<a:latin typeface=" + Quoted("+mj-lt") + "/>");
  723. ExportUtils.WriteLn(Out, "<a:ea typeface=" + Quoted("+mj-ea") + "/>");
  724. ExportUtils.WriteLn(Out, "<a:cs typeface=" + Quoted("+mj-cs") + "/>");
  725. ExportUtils.WriteLn(Out, "</a:defRPr>");
  726. ExportUtils.WriteLn(Out, "</a:lvl" + level.ToString() + "pPr>");
  727. }
  728. internal PptStyleBase(long MarL)
  729. {
  730. this.marL = MarL;
  731. }
  732. }
  733. /// <summary>
  734. /// Base class for styles group
  735. /// </summary>
  736. internal class PptStyleGroupBase
  737. {
  738. private ArrayList styleGroup = new ArrayList();
  739. internal void Export(Stream Out)
  740. {
  741. foreach (PptStyleBase style in styleGroup)
  742. {
  743. style.Export(Out);
  744. }
  745. }
  746. internal void AddStyle(PptStyleBase style)
  747. {
  748. styleGroup.Add(style);
  749. }
  750. }
  751. /// <summary>
  752. /// Base class for slides, masters, and layouts
  753. /// </summary>
  754. internal abstract class OoSlideBase : OoXMLBase
  755. {
  756. protected PowerPoint2007Export pptExport;
  757. protected ulong slideMasterId;
  758. protected void ExportShape(Stream Out, PptShape shape, string ShapeType, int id)
  759. {
  760. bool do_borders;
  761. ExportUtils.WriteLn(Out, "<p:sp>");
  762. shape.Export_nvSpPr(Out);
  763. do_borders = shape.Export_spPr(Out, ShapeType);
  764. shape.Export_txBody(Out);
  765. ExportUtils.WriteLn(Out, "</p:sp>");
  766. if (shape.Object.Border.Shadow)
  767. {
  768. shape.Export_Shadow(Out, id);
  769. id += 2;
  770. }
  771. if (do_borders == true)
  772. {
  773. shape.ExportFourBorders(Out, id);
  774. id += 4;
  775. }
  776. }
  777. protected void ExportColorMapOverride(Stream Out)
  778. {
  779. ExportUtils.WriteLn(Out, "<p:clrMapOvr>");
  780. ExportUtils.WriteLn(Out, "<a:masterClrMapping />");
  781. ExportUtils.WriteLn(Out, "</p:clrMapOvr>");
  782. }
  783. protected void ExportShapeTree(Stream Out, PptShape[] shape_list)
  784. {
  785. ExportUtils.WriteLn(Out, "<p:spTree>");
  786. ExportUtils.WriteLn(Out, "<p:nvGrpSpPr>");
  787. ExportUtils.WriteLn(Out, "<p:cNvPr id=\"1\" name=\"\" />");
  788. ExportUtils.WriteLn(Out, "<p:cNvGrpSpPr />");
  789. ExportUtils.WriteLn(Out, "<p:nvPr />");
  790. ExportUtils.WriteLn(Out, "</p:nvGrpSpPr>");
  791. ExportUtils.WriteLn(Out, "<p:grpSpPr>");
  792. ExportUtils.WriteLn(Out, "<a:xfrm>");
  793. ExportUtils.WriteLn(Out, "<a:off x=\"0\" y=\"0\" />");
  794. ExportUtils.WriteLn(Out, "<a:ext cx=\"0\" cy=\"0\" />");
  795. ExportUtils.WriteLn(Out, "<a:chOff x=\"0\" y=\"0\" />");
  796. ExportUtils.WriteLn(Out, "<a:chExt cx=\"0\" cy=\"0\" />");
  797. ExportUtils.WriteLn(Out, "</a:xfrm>");
  798. ExportUtils.WriteLn(Out, "</p:grpSpPr>");
  799. #if false
  800. for (int i = 0; i < shape_list.Length; i++)
  801. {
  802. ExportShape(Out, shape_list[i]);
  803. }
  804. #endif
  805. ExportUtils.WriteLn(Out, "</p:spTree>");
  806. }
  807. protected void ExportSlideBackground(Stream Out)
  808. {
  809. ExportUtils.WriteLn(Out, "<p:bg>");
  810. ExportUtils.WriteLn(Out, "<p:bgRef idx=\"1001\">");
  811. ExportUtils.WriteLn(Out, "<a:schemeClr val=\"bg1\" />");
  812. ExportUtils.WriteLn(Out, "</p:bgRef>");
  813. ExportUtils.WriteLn(Out, "</p:bg>");
  814. }
  815. internal ulong SlideMasterId { get { return slideMasterId; } }
  816. internal OoSlideBase(PowerPoint2007Export ppt_export)
  817. {
  818. pptExport = ppt_export;
  819. slideMasterId = this.pptExport.slideMasterID;
  820. this.pptExport.slideMasterID++;
  821. }
  822. }
  823. /// <summary>
  824. /// Slide masters object
  825. /// </summary>
  826. internal class OoPptSlideMaster : OoSlideBase
  827. {
  828. #region Class overrides
  829. public override string RelationType { get { return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster"; } }
  830. public override string ContentType { get { return "application/vnd.openxmlformats-officedocument.presentationml.slideMaster+xml"; } }
  831. public override string FileName { get { return "ppt/slideMasters/slideMaster1.xml"; } }
  832. #endregion
  833. #region Private methods
  834. private void ExportLayoutIDList(Stream Out, ArrayList LayoutList)
  835. {
  836. ExportUtils.WriteLn(Out, "<p:sldLayoutIdLst>");
  837. foreach (OoSlideBase layout_item in LayoutList)
  838. {
  839. ExportUtils.WriteLn(Out, "<p:sldLayoutId id=" + Quoted(layout_item.SlideMasterId.ToString()) + "r:id=" + Quoted(layout_item.rId) + "/>");
  840. }
  841. ExportUtils.WriteLn(Out, "</p:sldLayoutIdLst>");
  842. }
  843. private void ExportTitleStyles(Stream Out)
  844. {
  845. ExportUtils.WriteLn(Out, "<p:titleStyle>");
  846. #if false
  847. ExportUtils.WriteLn(Out, "<a:lvl1pPr algn=\"ctr\" defTabSz=\"914400\" rtl=\"0\" eaLnBrk=\"1\" latinLnBrk=\"0\" hangingPunct=\"1\">");
  848. ExportUtils.WriteLn(Out, "<a:spcBef>");
  849. ExportUtils.WriteLn(Out, "<a:spcPct val=\"0\" />");
  850. ExportUtils.WriteLn(Out, "</a:spcBef>");
  851. ExportUtils.WriteLn(Out, "<a:buNone />");
  852. ExportUtils.WriteLn(Out, "<a:defRPr sz=\"4400\" kern=\"1200\">");
  853. ExportUtils.WriteLn(Out, "<a:solidFill>");
  854. ExportUtils.WriteLn(Out, "<a:schemeClr val=\"tx1\" />");
  855. ExportUtils.WriteLn(Out, "</a:solidFill>");
  856. ExportUtils.WriteLn(Out, "<a:latin typeface=\"+mj-lt\" />");
  857. ExportUtils.WriteLn(Out, "<a:ea typeface=\"+mj-ea\" />");
  858. ExportUtils.WriteLn(Out, "<a:cs typeface=\"+mj-cs\" />");
  859. ExportUtils.WriteLn(Out, "</a:defRPr>");
  860. ExportUtils.WriteLn(Out, "</a:lvl1pPr>");
  861. #endif
  862. ExportUtils.WriteLn(Out, "</p:titleStyle>");
  863. }
  864. private void ExportBodyStyles(Stream Out)
  865. {
  866. ExportUtils.WriteLn(Out, "<p:bodyStyle>");
  867. #if false
  868. for (int i = 0; i < diffs.Length; i++)
  869. {
  870. ExportUtils.WriteLn(Out, "<a:lvl" + (1 + i) + "pPr marL=" + Quoted(diffs[i].MarL) + "indent=" + Quoted(diffs[i].ident) + "algn=\"l\" defTabSz=\"914400\" rtl=\"0\" eaLnBrk=\"1\" latinLnBrk=\"0\" hangingPunct=\"1\">");
  871. ExportUtils.WriteLn(Out, "<a:spcBef>");
  872. ExportUtils.WriteLn(Out, "<a:spcPct val=\"20000\" />");
  873. ExportUtils.WriteLn(Out, "</a:spcBef>");
  874. ExportUtils.WriteLn(Out, "<a:buFont typeface=\"Arial\" pitchFamily=\"34\" charset=\"0\" />");
  875. ExportUtils.WriteLn(Out, "<a:buChar char=" + Quoted(diffs[i].buChar) + " />");
  876. ExportUtils.WriteLn(Out, "<a:defRPr sz=" + Quoted(diffs[i].sz) + " kern=\"1200\">");
  877. ExportUtils.WriteLn(Out, "<a:solidFill>");
  878. ExportUtils.WriteLn(Out, "<a:schemeClr val=\"tx1\" />");
  879. ExportUtils.WriteLn(Out, "</a:solidFill>");
  880. ExportUtils.WriteLn(Out, "<a:latin typeface=\"+mn-lt\" />");
  881. ExportUtils.WriteLn(Out, "<a:ea typeface=\"+mn-ea\" />");
  882. ExportUtils.WriteLn(Out, "<a:cs typeface=\"+mn-cs\" />");
  883. ExportUtils.WriteLn(Out, "</a:defRPr>");
  884. ExportUtils.WriteLn(Out, "</a:lvl" + (1 + i) + "pPr>");
  885. }
  886. #endif
  887. ExportUtils.WriteLn(Out, "</p:bodyStyle>");
  888. }
  889. private void ExportOtherStyles(Stream Out)
  890. {
  891. ExportUtils.WriteLn(Out, "<p:otherStyle>");
  892. ExportUtils.WriteLn(Out, "<a:defPPr>");
  893. ExportUtils.WriteLn(Out, $"<a:defRPr lang=\"{pptExport.GetLoacalizationName()}\" />");
  894. ExportUtils.WriteLn(Out, "</a:defPPr>");
  895. #if false
  896. for (int i = 0; i < MarL.Length; i++)
  897. {
  898. ExportUtils.WriteLn(Out, "<a:lvl" + (1 + i) + "pPr marL=" + MarL[i] + " algn=\"l\" defTabSz=\"914400\" rtl=\"0\" eaLnBrk=\"1\" latinLnBrk=\"0\" hangingPunct=\"1\">");
  899. ExportUtils.WriteLn(Out, "<a:defRPr sz=\"1800\" kern=\"1200\">");
  900. ExportUtils.WriteLn(Out, "<a:solidFill>");
  901. ExportUtils.WriteLn(Out, "<a:schemeClr val=\"tx1\" />");
  902. ExportUtils.WriteLn(Out, "</a:solidFill>");
  903. ExportUtils.WriteLn(Out, "<a:latin typeface=\"+mn-lt\" />");
  904. ExportUtils.WriteLn(Out, "<a:ea typeface=\"+mn-ea\" />");
  905. ExportUtils.WriteLn(Out, "<a:cs typeface=\"+mn-cs\" />");
  906. ExportUtils.WriteLn(Out, "</a:defRPr>");
  907. ExportUtils.WriteLn(Out, "</a:lvl" + (1 + i) + "pPr>");
  908. }
  909. #endif
  910. ExportUtils.WriteLn(Out, "</p:otherStyle>");
  911. }
  912. #endregion
  913. #region Internal methods
  914. internal void Export(PowerPoint2007Export OoXML)
  915. {
  916. ExportRelations(OoXML);
  917. MemoryStream file = new MemoryStream();
  918. ExportUtils.WriteLn(file, xml_header);
  919. ExportUtils.WriteLn(file, "<p:sldMaster xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:p=\"http://schemas.openxmlformats.org/presentationml/2006/main\">");
  920. ExportUtils.WriteLn(file, "<p:cSld>");
  921. ExportSlideBackground(file);
  922. ExportShapeTree(file, null /*master_shapes*/ );
  923. ExportUtils.WriteLn(file, "</p:cSld>");
  924. ExportUtils.WriteLn(file, "<p:clrMap bg1=\"lt1\" tx1=\"dk1\" bg2=\"lt2\" tx2=\"dk2\" accent1=\"accent1\" accent2=\"accent2\" accent3=\"accent3\" accent4=\"accent4\" accent5=\"accent5\" accent6=\"accent6\" hlink=\"hlink\" folHlink=\"folHlink\" />");
  925. ExportLayoutIDList(file, OoXML.SlideLayoutList);
  926. ExportUtils.WriteLn(file, "<p:txStyles>");
  927. ExportTitleStyles(file);
  928. ExportBodyStyles(file);
  929. ExportOtherStyles(file);
  930. ExportUtils.WriteLn(file, "</p:txStyles>");
  931. ExportUtils.WriteLn(file, "</p:sldMaster>");
  932. file.Position = 0;
  933. OoXML.Zip.AddStream(ExportUtils.TruncLeadSlash(FileName), file);
  934. }
  935. #endregion
  936. internal OoPptSlideMaster(PowerPoint2007Export ppt_export)
  937. : base(ppt_export)
  938. {
  939. }
  940. }
  941. /// <summary>
  942. /// Ordinaty slide
  943. /// </summary>
  944. internal class OoPptSlide : OoSlideBase
  945. {
  946. public Dictionary<string, PptShape> checkboxList = new Dictionary<string, PptShape>();
  947. const float PPT_DIVIDER = 360000 / 37.8f;
  948. const int NO_RELATION = 0;
  949. #region "Class overrides"
  950. public override string RelationType { get { return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide"; } }
  951. public override string ContentType { get { return "application/vnd.openxmlformats-officedocument.presentationml.slide+xml"; } }
  952. public override string FileName { get { return "ppt/slides/slide" + slideNumber + ".xml"; } }
  953. #endregion
  954. #region "Private fields"
  955. private int slideNumber;
  956. private int slideID;
  957. private int id { get { return pptExport.identifier; } set { pptExport.identifier = value; } }
  958. #endregion
  959. #region "Public properties"
  960. public int SlideID { get { return slideID; } }
  961. public int PictureCount { get { return pptExport.PictureCount; } set { pptExport.PictureCount = value; } }
  962. #endregion
  963. #region "Private methods"
  964. private ulong GetTop(float p)
  965. {
  966. return (ulong)( /* FMarginWoBottom - */ p * PPT_DIVIDER);
  967. }
  968. private ulong GetLeft(float p)
  969. {
  970. return (ulong)( /* FMarginLeft + */ p * PPT_DIVIDER);
  971. }
  972. #endregion
  973. // Constructor
  974. internal OoPptSlide(PowerPoint2007Export ppt_export) : base(ppt_export)
  975. {
  976. slideNumber = ++pptExport.SlideCount;
  977. slideID = ++pptExport.SlideIDCount;
  978. id = 1;
  979. }
  980. internal void Reset()
  981. {
  982. pptExport.SlideCount = 1;
  983. slideNumber = 1;
  984. slideID = pptExport.SlideIDCount = 256;
  985. pptExport.slideMasterID = 2147483648;
  986. }
  987. private void AddBandObject(Stream outstream, BandBase band)
  988. {
  989. if (band.HasBorder || band.HasFill) using (TextObject newObj = new TextObject())
  990. {
  991. newObj.Left = band.AbsLeft;
  992. newObj.Top = band.AbsTop;
  993. newObj.Width = band.Width;
  994. newObj.Height = band.Height;
  995. newObj.Fill = band.Fill;
  996. newObj.Border = band.Border;
  997. newObj.Text = "";
  998. AddTextObject(outstream, 0, newObj);
  999. }
  1000. }
  1001. private void AddPolyline(Stream Out, PolyLineObject polyline)
  1002. {
  1003. PptShape shape = new PptShape(id + 1, NO_RELATION, polyline.ToString() + " " + id, polyline, this.pptExport);
  1004. using (Font f = new Font("system", 8))
  1005. {
  1006. // append epmty space to avoid anoying PPt notification
  1007. shape.Open_Paragraph();
  1008. shape.Add_Run(f, polyline.FillColor, null);
  1009. shape.Close_Paragraph();
  1010. }
  1011. ExportShape(Out, shape, null, id);
  1012. id += 8;
  1013. }
  1014. private void AddShape(Stream Out, ShapeObject shape_object)
  1015. {
  1016. string shape_name;
  1017. PptShape shape = new PptShape(id + 1, NO_RELATION, shape_object.ToString() + " " + id, shape_object, this.pptExport);
  1018. switch (shape_object.Shape)
  1019. {
  1020. case ShapeKind.Diamond: shape_name = "diamond"; break;
  1021. case ShapeKind.Ellipse: shape_name = "ellipse"; break;
  1022. case ShapeKind.Rectangle: shape_name = "rect"; break;
  1023. case ShapeKind.RoundRectangle: shape_name = "roundRect"; break;
  1024. case ShapeKind.Triangle: shape_name = "triangle"; break;
  1025. default: throw new Exception("Unsupported shape kind");
  1026. }
  1027. using (Font f = new Font("system", 8))
  1028. {
  1029. // append epmty space to avoid anoying PPt notification
  1030. shape.Open_Paragraph();
  1031. shape.Add_Run(f, shape_object.FillColor, null);
  1032. shape.Close_Paragraph();
  1033. }
  1034. ExportShape(Out, shape, shape_name, id);
  1035. id += 8;
  1036. }
  1037. private void AddTextObject(Stream outstream, int nRelationID, TextObject obj)
  1038. {
  1039. PptShape shape;
  1040. if (obj.Fill is HatchFill || obj.Fill is PathGradientFill)
  1041. {
  1042. string TempString = obj.Text;
  1043. obj.Text = "";
  1044. shape = SaveImage(obj, nRelationID, "ppt/media/HatchFill", false);
  1045. this.AddRelation(nRelationID, shape);
  1046. obj.Text = TempString;
  1047. }
  1048. else
  1049. {
  1050. shape = new PptShape(id + 1, NO_RELATION, "TextBox " + id, obj, pptExport);
  1051. }
  1052. float FDpiFX = 96f / DrawUtils.ScreenDpi;
  1053. IGraphics g = pptExport.Report.MeasureGraphics;
  1054. using (Font f = new Font(obj.Font.FontFamily, obj.Font.Size * FDpiFX, obj.Font.Style))
  1055. using (GraphicCache cache = new GraphicCache())
  1056. {
  1057. RectangleF textRect = new RectangleF(
  1058. obj.AbsLeft + obj.Padding.Left,
  1059. obj.AbsTop + obj.Padding.Top,
  1060. obj.Width - obj.Padding.Horizontal,
  1061. obj.Height - obj.Padding.Vertical);
  1062. StringFormat format = obj.GetStringFormat(cache, 0);
  1063. Brush textBrush = cache.GetBrush(obj.TextColor);
  1064. AdvancedTextRenderer renderer = new AdvancedTextRenderer(obj.Text, g, f, textBrush, null,
  1065. textRect, format, obj.HorzAlign, obj.VertAlign, obj.LineHeight, obj.Angle, obj.FontWidthRatio,
  1066. obj.ForceJustify, obj.Wysiwyg, obj.HasHtmlTags, true, FDpiFX, FDpiFX, obj.InlineImageCache);
  1067. float w = f.Height * 0.1f; // to match .net char X offset
  1068. // render
  1069. if (renderer.Paragraphs.Count == 0)
  1070. {
  1071. // append empty space
  1072. shape.Open_Paragraph();
  1073. shape.Add_Run(f, obj.TextColor, null);
  1074. shape.Close_Paragraph();
  1075. }
  1076. else foreach (AdvancedTextRenderer.Paragraph paragraph in renderer.Paragraphs)
  1077. {
  1078. shape.Open_Paragraph();
  1079. foreach (AdvancedTextRenderer.Line line in paragraph.Lines)
  1080. {
  1081. foreach (AdvancedTextRenderer.Word word in line.Words)
  1082. if (renderer.HtmlTags)
  1083. foreach (AdvancedTextRenderer.Run run in word.Runs)
  1084. using (Font fnt = run.GetFont())
  1085. {
  1086. shape.Add_Run(fnt, run.Style.Color, run.Text);
  1087. }
  1088. else
  1089. shape.Add_Run(f, obj.TextColor, word.Text);
  1090. }
  1091. shape.Close_Paragraph();
  1092. }
  1093. }
  1094. ExportShape(outstream, shape, "rect", id);
  1095. id += 6;
  1096. }
  1097. private void AddLine(Stream Out, LineObject obj)
  1098. {
  1099. PptShape shape = new PptShape(id + 1, NO_RELATION, "LineObject " + id, obj, pptExport);
  1100. ExportUtils.WriteLn(Out, "<p:cxnSp>");
  1101. shape.Export_nvCxnSpPr(Out);
  1102. if (obj.Diagonal)
  1103. shape.Export_spPr(Out, "line");
  1104. else
  1105. shape.Export_spPr(Out, "straightConnector1");
  1106. //ExportUtils.WriteLn(Out, "<a:ln>");
  1107. //ExportUtils.WriteLn(Out, "<a:tailEnd type="arrow" />");
  1108. //ExportUtils.WriteLn(Out, "</a:ln>");
  1109. //ExportUtils.WriteLn(Out, "</p:spPr>"); <<-- fix it
  1110. ExportUtils.WriteLn(Out, "<p:style>");
  1111. ExportUtils.WriteLn(Out, "<a:lnRef idx=\"1\">");
  1112. ExportUtils.WriteLn(Out, "<a:schemeClr val=\"accent1\" />");
  1113. ExportUtils.WriteLn(Out, "</a:lnRef>");
  1114. ExportUtils.WriteLn(Out, "<a:fillRef idx=\"0\">");
  1115. ExportUtils.WriteLn(Out, "<a:schemeClr val=\"accent1\" />");
  1116. ExportUtils.WriteLn(Out, "</a:fillRef>");
  1117. ExportUtils.WriteLn(Out, "<a:effectRef idx=\"0\">");
  1118. ExportUtils.WriteLn(Out, "<a:schemeClr val=\"accent1\" />");
  1119. ExportUtils.WriteLn(Out, "</a:effectRef>");
  1120. ExportUtils.WriteLn(Out, "<a:fontRef idx=\"minor\">");
  1121. ExportUtils.WriteLn(Out, "<a:schemeClr val=\"tx1\" />");
  1122. ExportUtils.WriteLn(Out, "</a:fontRef>");
  1123. ExportUtils.WriteLn(Out, "</p:style>");
  1124. ExportUtils.WriteLn(Out, "</p:cxnSp>");
  1125. id++;
  1126. }
  1127. // Save any object as image file
  1128. private PptShape SaveImage(ReportComponentBase obj, int rId, string FileName, bool ClearBackground)
  1129. {
  1130. return SaveImage(obj, rId, FileName, ClearBackground, 1);
  1131. }
  1132. // Save any object as image file
  1133. private PptShape SaveImage(ReportComponentBase obj, int rId, string FileName, bool ClearBackground, float printZoom)
  1134. {
  1135. pptExport.PictureCount++; // Increase picture counter
  1136. string file_extension = "png";
  1137. System.Drawing.Imaging.ImageFormat image_format = System.Drawing.Imaging.ImageFormat.Png;
  1138. if (this.pptExport.ImageFormat == PptImageFormat.Jpeg)
  1139. {
  1140. file_extension = "jpg";
  1141. image_format = System.Drawing.Imaging.ImageFormat.Jpeg;
  1142. }
  1143. string ImageFileName = FileName + pptExport.PictureCount.ToString() + "." + file_extension;
  1144. using (System.Drawing.Image image = new System.Drawing.Bitmap((int)Math.Round(obj.Width * printZoom), (int)Math.Round(obj.Height * printZoom)))
  1145. using (Graphics g = Graphics.FromImage(image))
  1146. using (GraphicCache cache = new GraphicCache())
  1147. {
  1148. g.TranslateTransform(-obj.AbsLeft * printZoom, -obj.AbsTop * printZoom);
  1149. if (ClearBackground)
  1150. {
  1151. g.Clear(Color.White);
  1152. }
  1153. obj.Draw(new FRPaintEventArgs(g, printZoom, printZoom, cache));
  1154. MemoryStream ms = new MemoryStream();
  1155. image.Save(ms, image_format);
  1156. ms.Position = 0;
  1157. pptExport.Zip.AddStream(ImageFileName, ms);
  1158. }
  1159. return new PptShape(id + 1, rId, ImageFileName, obj, pptExport);
  1160. }
  1161. private void AddCheckboxObject(Stream Out, int rId, CheckBoxObject checkbox, out int rIdOut)
  1162. {
  1163. PptShape shape;
  1164. string KEY = checkbox.Name + checkbox.Checked.ToString();
  1165. if (!checkboxList.ContainsKey(KEY))
  1166. {
  1167. rId++;
  1168. shape = SaveImage(checkbox, rId, "ppt/media/Checkbox", false);
  1169. this.AddRelation(rId, shape);
  1170. checkboxList.Add(KEY, shape);
  1171. }
  1172. else
  1173. {
  1174. shape = checkboxList[KEY];
  1175. shape.MoveObject(checkbox);
  1176. }
  1177. ExportUtils.WriteLn(Out, "<p:pic>");
  1178. shape.Export_nvPicPr(Out, id);
  1179. shape.Export_blipFill(Out);
  1180. shape.Export_spPr(Out, "rect");
  1181. ExportUtils.WriteLn(Out, "</p:pic>");
  1182. rIdOut = rId;
  1183. id++;
  1184. }
  1185. private void AddPictureObject(Stream Out, int rId, ReportComponentBase obj, string FileName)
  1186. {
  1187. if (obj.Height <= 0 || obj.Width <= 0)
  1188. return;
  1189. PptShape shape = SaveImage(obj, rId, FileName, !(obj is PictureObject), 3);
  1190. ExportUtils.WriteLn(Out, "<p:pic>");
  1191. shape.Export_nvPicPr(Out, pptExport.PictureCount);
  1192. shape.Export_blipFill(Out);
  1193. shape.Export_spPr(Out, "rect");
  1194. ExportUtils.WriteLn(Out, "</p:pic>");
  1195. this.AddRelation(rId, shape);
  1196. id++;
  1197. }
  1198. private void AddTable(Stream Out, TableBase table)
  1199. {
  1200. using (TextObject tableBack = new TextObject())
  1201. {
  1202. tableBack.Left = table.AbsLeft;
  1203. tableBack.Top = table.AbsTop;
  1204. float tableWidth = 0;
  1205. for (int i = 0; i < table.ColumnCount; i++)
  1206. tableWidth += table[i, 0].Width;
  1207. tableBack.Width = (tableWidth < table.Width) ? tableWidth : table.Width;
  1208. tableBack.Height = table.Height;
  1209. tableBack.Fill = table.Fill;
  1210. tableBack.Text = "";
  1211. // exporting the table fill
  1212. AddTextObject(Out, 0, tableBack);
  1213. // exporting the table cells
  1214. float x = 0;
  1215. for (int j = 0; j < table.Columns.Count; j++)
  1216. {
  1217. float y = 0;
  1218. for (int i = 0; i < table.RowCount; i++)
  1219. {
  1220. if (!table.IsInsideSpan(table[j, i]))
  1221. {
  1222. TableCell textcell = table[j, i];
  1223. textcell.Left = x;
  1224. textcell.Top = y;
  1225. AddTextObject(Out, 0, textcell);
  1226. }
  1227. y += (table.Rows[i]).Height;
  1228. }
  1229. x += (table.Columns[j]).Width;
  1230. }
  1231. // exporting the table border
  1232. tableBack.Fill = new SolidFill();
  1233. tableBack.Border = table.Border;
  1234. AddTextObject(Out, 0, tableBack);
  1235. }
  1236. }
  1237. private MemoryStream file;
  1238. private int r_Id;
  1239. internal void ExportBegin(PowerPoint2007Export OoXML, ReportPage page)
  1240. {
  1241. r_Id = 0;
  1242. foreach (OoPptSlideLayout layout in OoXML.SlideLayoutList)
  1243. {
  1244. AddRelation(++r_Id, OoXML.SlideLayoutList[0] as OoPptSlideLayout);
  1245. }
  1246. // Export slide
  1247. file = new MemoryStream();
  1248. ExportUtils.WriteLn(file, xml_header);
  1249. ExportUtils.WriteLn(file, "<p:sld xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:p=\"http://schemas.openxmlformats.org/presentationml/2006/main\">");
  1250. ExportUtils.WriteLn(file, "<p:cSld>");
  1251. ExportUtils.WriteLn(file, "<p:spTree>");
  1252. ExportUtils.WriteLn(file, "<p:nvGrpSpPr>");
  1253. ExportUtils.WriteLn(file, "<p:cNvPr id=\"1\" name=\"\" />");
  1254. ExportUtils.WriteLn(file, "<p:cNvGrpSpPr />");
  1255. ExportUtils.WriteLn(file, "<p:nvPr />");
  1256. ExportUtils.WriteLn(file, "</p:nvGrpSpPr>");
  1257. ExportUtils.WriteLn(file, "<p:grpSpPr>");
  1258. ExportUtils.WriteLn(file, "<a:xfrm>");
  1259. ExportUtils.WriteLn(file, "<a:off x=\"0\" y=\"0\" />");
  1260. ExportUtils.WriteLn(file, "<a:ext cx=\"0\" cy=\"0\" />");
  1261. ExportUtils.WriteLn(file, "<a:chOff x=\"0\" y=\"0\" />");
  1262. ExportUtils.WriteLn(file, "<a:chExt cx=\"0\" cy=\"0\" />");
  1263. ExportUtils.WriteLn(file, "</a:xfrm>");
  1264. ExportUtils.WriteLn(file, "</p:grpSpPr>");
  1265. // text watermark on bottom
  1266. if (page.Watermark.Enabled && !page.Watermark.ShowTextOnTop)
  1267. AddTextWatermark(file, page);
  1268. }
  1269. internal void ExportBand(PowerPoint2007Export OoXML, Base band)
  1270. {
  1271. if ((band as BandBase).Fill is TextureFill)
  1272. AddPictureObject(file, ++r_Id, band as BandBase, "ppt/media/FixMeImage");
  1273. else
  1274. AddBandObject(file, band as BandBase);
  1275. foreach (Base c in band.ForEachAllConvectedObjects(this))
  1276. {
  1277. ReportComponentBase obj = c as ReportComponentBase;
  1278. if (obj == null)
  1279. continue;
  1280. else if (obj.Fill is TextureFill)
  1281. {
  1282. AddPictureObject(file, ++r_Id, obj as ReportComponentBase, "ppt/media/FixMeImage");
  1283. continue;
  1284. }
  1285. if (obj is CellularTextObject)
  1286. obj = (obj as CellularTextObject).GetTable();
  1287. if (obj is TableCell)
  1288. continue;
  1289. else if (obj is TableBase)
  1290. AddTable(file, obj as TableBase);
  1291. else if (obj is TextObject)
  1292. AddTextObject(file, ++r_Id, obj as TextObject);
  1293. else if (obj is BandBase)
  1294. AddBandObject(file, obj as BandBase);
  1295. else if (obj is LineObject)
  1296. AddLine(file, obj as LineObject);
  1297. else if (obj is ShapeObject)
  1298. AddShape(file, obj as ShapeObject);
  1299. else if (obj is PolyLineObject)
  1300. AddPolyline(file, obj as PolyLineObject);
  1301. else if (obj is PictureObject)
  1302. AddPictureObject(file, ++r_Id, obj as PictureObject, "ppt/media/image");
  1303. else if (obj is Barcode.BarcodeObject)
  1304. AddPictureObject(file, ++r_Id, obj as ReportComponentBase, "ppt/media/BarcodeImage");
  1305. else if (obj is ZipCodeObject)
  1306. AddPictureObject(file, ++r_Id, obj as ReportComponentBase, "ppt/media/ZipCodeImage");
  1307. #if MSCHART
  1308. else if (obj is MSChart.MSChartObject)
  1309. AddPictureObject(file, ++r_Id, obj as ReportComponentBase, "ppt/media/MSChartImage");
  1310. #endif
  1311. else if (obj is RichObject)
  1312. AddPictureObject(file, ++r_Id, obj as ReportComponentBase, "ppt/media/RichTextImage");
  1313. else if (obj is CheckBoxObject)
  1314. AddCheckboxObject(file, r_Id, obj as CheckBoxObject, out r_Id);
  1315. else
  1316. {
  1317. AddPictureObject(file, ++r_Id, obj as ReportComponentBase, "ppt/media/FixMeImage");
  1318. }
  1319. }
  1320. }
  1321. internal void ExportEnd(PowerPoint2007Export OoXML, ReportPage page)
  1322. {
  1323. // text watermark on top
  1324. if (page.Watermark.Enabled && page.Watermark.ShowTextOnTop)
  1325. AddTextWatermark(file, page);
  1326. ExportUtils.WriteLn(file, "</p:spTree>");
  1327. ExportUtils.WriteLn(file, "</p:cSld>");
  1328. ExportColorMapOverride(file);
  1329. ExportUtils.WriteLn(file, "</p:sld>");
  1330. file.Position = 0;
  1331. OoXML.Zip.AddStream(ExportUtils.TruncLeadSlash(FileName), file);
  1332. ExportRelations(OoXML);
  1333. }
  1334. private void AddTextWatermark(Stream Out, ReportPage page)
  1335. {
  1336. TextObject obj = page.Watermark.TextObject;
  1337. if (obj == null) return;
  1338. RectangleF displayRect = new RectangleF(
  1339. page.LeftMargin * 3,
  1340. page.TopMargin * 3,
  1341. ExportUtils.GetPageWidth(page) * 3,
  1342. ExportUtils.GetPageHeight(page) * 3);
  1343. obj.Bounds = displayRect;
  1344. int angle = 0;
  1345. switch (page.Watermark.TextRotation)
  1346. {
  1347. case WatermarkTextRotation.Horizontal:
  1348. angle = 0;
  1349. break;
  1350. case WatermarkTextRotation.Vertical:
  1351. angle = 270;
  1352. break;
  1353. case WatermarkTextRotation.ForwardDiagonal:
  1354. angle = 360 - (int)(Math.Atan(displayRect.Height / displayRect.Width) * (180 / Math.PI));
  1355. break;
  1356. case WatermarkTextRotation.BackwardDiagonal:
  1357. angle = (int)(Math.Atan(displayRect.Height / displayRect.Width) * (180 / Math.PI));
  1358. break;
  1359. }
  1360. obj.Angle = angle;
  1361. AddTextObject(Out, 0, obj);
  1362. }
  1363. }
  1364. /// <summary>
  1365. /// Slide layout object
  1366. /// </summary>
  1367. internal class OoPptSlideLayout : OoSlideBase
  1368. {
  1369. #region Class overrides
  1370. public override string RelationType { get { return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout"; } }
  1371. public override string ContentType { get { return "application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml"; } }
  1372. public override string FileName { get { return "ppt/slideLayouts/slideLayout" + index.ToString() + ".xml"; } }
  1373. #endregion
  1374. #region Private fields
  1375. private PptLayoutDescriptor descriptor;
  1376. private int index;
  1377. #endregion
  1378. internal void Export(PowerPoint2007Export OoXML)
  1379. {
  1380. ExportRelations(OoXML);
  1381. MemoryStream file = new MemoryStream();
  1382. ExportUtils.WriteLn(file, xml_header);
  1383. ExportUtils.WriteLn(file, "<p:sldLayout ");
  1384. ExportUtils.WriteLn(file, "xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" ");
  1385. ExportUtils.WriteLn(file, "xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" ");
  1386. ExportUtils.WriteLn(file, "xmlns:p=\"http://schemas.openxmlformats.org/presentationml/2006/main\" type=" + Quoted(descriptor.type) + " preserve=\"1\">");
  1387. ExportUtils.WriteLn(file, "<p:cSld name=" + Quoted(descriptor.name) + ">");
  1388. ExportShapeTree(file, descriptor.shapes);
  1389. ExportUtils.WriteLn(file, "</p:cSld>");
  1390. ExportColorMapOverride(file);
  1391. ExportUtils.WriteLn(file, "</p:sldLayout>");
  1392. file.Position = 0;
  1393. OoXML.Zip.AddStream(ExportUtils.TruncLeadSlash(FileName), file);
  1394. }
  1395. // Constructor
  1396. internal OoPptSlideLayout(PowerPoint2007Export ppt_export, int Index, PptLayoutDescriptor descriptor) :
  1397. base(ppt_export)
  1398. {
  1399. this.descriptor = descriptor;
  1400. index = Index;
  1401. }
  1402. }
  1403. /// <summary>
  1404. /// Presentation class
  1405. /// </summary>
  1406. internal class OoPptPresentation : OoXMLBase
  1407. {
  1408. #region Class overrides
  1409. public override string RelationType { get { return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"; } }
  1410. public override string ContentType { get { return "application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml"; } }
  1411. public override string FileName { get { return "ppt/presentation.xml"; } }
  1412. #endregion
  1413. internal void Export(PowerPoint2007Export OoXML)
  1414. {
  1415. ExportRelations(OoXML);
  1416. MemoryStream file = new MemoryStream();
  1417. ExportUtils.WriteLn(file, xml_header);
  1418. ExportUtils.WriteLn(file, "<p:presentation xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:p=\"http://schemas.openxmlformats.org/presentationml/2006/main\" saveSubsetFonts=\"1\">");
  1419. ExportUtils.WriteLn(file, "<p:sldMasterIdLst>");
  1420. ExportUtils.WriteLn(file, "<p:sldMasterId id=" + Quoted(OoXML.SlideMaster.SlideMasterId.ToString()) + "r:id=" + Quoted(OoXML.SlideMaster.rId) + "/> ");
  1421. ExportUtils.WriteLn(file, "</p:sldMasterIdLst>");
  1422. ExportUtils.WriteLn(file, "<p:sldIdLst>");
  1423. foreach (OoXMLBase obj in RelationList) if (obj is OoPptSlide)
  1424. {
  1425. OoPptSlide slide = obj as OoPptSlide;
  1426. ExportUtils.WriteLn(file, "<p:sldId id=" + Quoted(slide.SlideID) + " r:id=" + Quoted(slide.rId) + " />");
  1427. }
  1428. ExportUtils.WriteLn(file, "</p:sldIdLst>");
  1429. ExportUtils.WriteLn(file, "<p:sldSz cx=" + Quoted(OoXML.PaperWidth) + " cy=" + Quoted(OoXML.PaperHeight) + " type=\"custom\" /> ");
  1430. ExportUtils.WriteLn(file, "<p:notesSz cx=\"6858000\" cy=\"9144000\" /> ");
  1431. //
  1432. ExportUtils.WriteLn(file, "<p:defaultTextStyle>");
  1433. ExportUtils.WriteLn(file, "<a:defPPr>");
  1434. ExportUtils.WriteLn(file, $"<a:defRPr lang=\"{OoXML.GetLoacalizationName()}\" />");
  1435. ExportUtils.WriteLn(file, "</a:defPPr>");
  1436. ExportUtils.WriteLn(file, "</p:defaultTextStyle>");
  1437. //
  1438. ExportUtils.WriteLn(file, "</p:presentation>");
  1439. file.Position = 0;
  1440. OoXML.Zip.AddStream("ppt/presentation.xml", file);
  1441. }
  1442. }
  1443. /// <summary>
  1444. /// PPt Application Properties class
  1445. /// </summary>
  1446. internal class OoPptApplicationProperties : OoXMLBase
  1447. {
  1448. #region Class overrides
  1449. public override string RelationType { get { return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties"; } }
  1450. public override string ContentType { get { return "application/vnd.openxmlformats-officedocument.extended-properties+xml"; } }
  1451. public override string FileName { get { return "docProps/app.xml"; } }
  1452. #endregion
  1453. public void Export(OOExportBase OoXML)
  1454. {
  1455. MemoryStream file = new MemoryStream();
  1456. ExportUtils.WriteLn(file, xml_header);
  1457. ExportUtils.WriteLn(file,
  1458. "<Properties xmlns=\"http://schemas.openxmlformats.org/officeDocument/2006/extended-properties\" xmlns:vt=\"http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes\">" +
  1459. "<TotalTime>1</TotalTime>" +
  1460. "<Words>0</Words>" +
  1461. "<Application>Microsoft Office PowerPoint</Application>" +
  1462. "<PresentationFormat>On-screen Show (4:3)</PresentationFormat>" +
  1463. "<Paragraphs>0</Paragraphs>" +
  1464. "<Slides>0</Slides>" +
  1465. "<Notes>0</Notes> " +
  1466. "<HiddenSlides>0</HiddenSlides>" +
  1467. "<MMClips>0</MMClips>" +
  1468. "<ScaleCrop>false</ScaleCrop>" +
  1469. "<HeadingPairs>" +
  1470. "<vt:vector size=\"4\" baseType=\"variant\">" +
  1471. "<vt:variant>" +
  1472. "<vt:lpstr>Theme</vt:lpstr>" +
  1473. "</vt:variant>" +
  1474. "<vt:variant>" +
  1475. "<vt:i4>1</vt:i4>" +
  1476. "</vt:variant>" +
  1477. "<vt:variant>" +
  1478. "<vt:lpstr>Slide Titles</vt:lpstr>" +
  1479. "</vt:variant>" +
  1480. "<vt:variant>" +
  1481. "<vt:i4>0</vt:i4>" +
  1482. "</vt:variant>" +
  1483. "</vt:vector>" +
  1484. "</HeadingPairs>" +
  1485. "<TitlesOfParts>" +
  1486. "<vt:vector size=\"1\" baseType=\"lpstr\">" +
  1487. "<vt:lpstr>Office Theme</vt:lpstr>" +
  1488. "</vt:vector>" +
  1489. "</TitlesOfParts>" +
  1490. "<LinksUpToDate>false</LinksUpToDate>" +
  1491. "<SharedDoc>false</SharedDoc>" +
  1492. "<HyperlinksChanged>false</HyperlinksChanged>" +
  1493. "<AppVersion>12.0000</AppVersion>" +
  1494. "</Properties>");
  1495. file.Position = 0;
  1496. OoXML.Zip.AddStream(ExportUtils.TruncLeadSlash(FileName), file);
  1497. }
  1498. }
  1499. /// <summary>
  1500. /// Ppt Table styles class
  1501. /// </summary>
  1502. internal class OoPptTableStyles : OoXMLBase
  1503. {
  1504. #region Class overrides
  1505. public override string RelationType { get { return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/tableStyles"; } }
  1506. public override string ContentType { get { return "application/vnd.openxmlformats-officedocument.presentationml.tableStyles+xml"; } }
  1507. public override string FileName { get { return "ppt/tableStyles.xml"; } }
  1508. #endregion
  1509. internal void Export(PowerPoint2007Export OoXML)
  1510. {
  1511. MemoryStream file = new MemoryStream();
  1512. ExportUtils.WriteLn(file, xml_header);
  1513. ExportUtils.WriteLn(file, "<a:tblStyleLst xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" def=\"{5C22544A-7EE6-4342-B048-85BDC9FD1C3A}\"/>");
  1514. file.Position = 0;
  1515. OoXML.Zip.AddStream(ExportUtils.TruncLeadSlash(FileName), file);
  1516. }
  1517. }
  1518. /// <summary>
  1519. /// Ppt Presentation properties class
  1520. /// </summary>
  1521. internal class OoPptPresProperties : OoXMLBase
  1522. {
  1523. #region Class overrides
  1524. public override string RelationType { get { return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/presProps"; } }
  1525. public override string ContentType { get { return "application/vnd.openxmlformats-officedocument.presentationml.presProps+xml"; } }
  1526. public override string FileName { get { return "ppt/presProps.xml"; } }
  1527. #endregion
  1528. internal void Export(PowerPoint2007Export OoXML)
  1529. {
  1530. MemoryStream file = new MemoryStream();
  1531. ExportUtils.WriteLn(file, xml_header);
  1532. ExportUtils.WriteLn(file, "<p:presentationPr xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:p=\"http://schemas.openxmlformats.org/presentationml/2006/main\" />");
  1533. file.Position = 0;
  1534. OoXML.Zip.AddStream(ExportUtils.TruncLeadSlash(FileName), file);
  1535. }
  1536. }
  1537. /// <summary>
  1538. /// Ppt View Properties class
  1539. /// </summary>
  1540. internal class OoPptViewProps : OoXMLBase
  1541. {
  1542. #region Class overrides
  1543. public override string RelationType { get { return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/viewProps"; } }
  1544. public override string ContentType { get { return "application/vnd.openxmlformats-officedocument.presentationml.viewProps+xml"; } }
  1545. public override string FileName { get { return "ppt/viewProps.xml"; } }
  1546. #endregion
  1547. internal void Export(PowerPoint2007Export OoXML)
  1548. {
  1549. MemoryStream file = new MemoryStream();
  1550. ExportUtils.WriteLn(file, xml_header);
  1551. ExportUtils.WriteLn(file, "<p:viewPr xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:p=\"http://schemas.openxmlformats.org/presentationml/2006/main\" lastView=\"sldThumbnailView\">");
  1552. ExportUtils.WriteLn(file, "<p:normalViewPr showfilelineIcons=\"0\">");
  1553. ExportUtils.WriteLn(file, "<p:restoredLeft sz=\"15620\" autoAdjust=\"0\" />");
  1554. ExportUtils.WriteLn(file, "<p:restoredTop sz=\"94660\" autoAdjust=\"0\" />");
  1555. ExportUtils.WriteLn(file, "</p:normalViewPr>");
  1556. ExportUtils.WriteLn(file, "<p:slideViewPr>");
  1557. ExportUtils.WriteLn(file, "<p:cSldViewPr>");
  1558. ExportUtils.WriteLn(file, "<p:cViewPr varScale=\"1\">");
  1559. ExportUtils.WriteLn(file, "<p:scale>");
  1560. ExportUtils.WriteLn(file, "<a:sx n=\"104\" d=\"100\" />");
  1561. ExportUtils.WriteLn(file, "<a:sy n=\"104\" d=\"100\" />");
  1562. ExportUtils.WriteLn(file, "</p:scale>");
  1563. ExportUtils.WriteLn(file, "<p:origin x=\"-222\" y=\"-90\" />");
  1564. ExportUtils.WriteLn(file, "</p:cViewPr>");
  1565. ExportUtils.WriteLn(file, "<p:guideLst>");
  1566. ExportUtils.WriteLn(file, "<p:guide orient=\"horz\" pos=\"2160\" />");
  1567. ExportUtils.WriteLn(file, "<p:guide pos=\"2880\" />");
  1568. ExportUtils.WriteLn(file, "</p:guideLst>");
  1569. ExportUtils.WriteLn(file, "</p:cSldViewPr>");
  1570. ExportUtils.WriteLn(file, "</p:slideViewPr>");
  1571. ExportUtils.WriteLn(file, "<p:outlineViewPr>");
  1572. ExportUtils.WriteLn(file, "<p:cViewPr>");
  1573. ExportUtils.WriteLn(file, "<p:scale>");
  1574. ExportUtils.WriteLn(file, "<a:sx n=\"33\" d=\"100\" />");
  1575. ExportUtils.WriteLn(file, "<a:sy n=\"33\" d=\"100\" />");
  1576. ExportUtils.WriteLn(file, "</p:scale>");
  1577. ExportUtils.WriteLn(file, "<p:origin x=\"0\" y=\"0\" />");
  1578. ExportUtils.WriteLn(file, "</p:cViewPr>");
  1579. ExportUtils.WriteLn(file, "</p:outlineViewPr>");
  1580. ExportUtils.WriteLn(file, "<p:notesTextViewPr>");
  1581. ExportUtils.WriteLn(file, "<p:cViewPr>");
  1582. ExportUtils.WriteLn(file, "<p:scale>");
  1583. ExportUtils.WriteLn(file, "<a:sx n=\"100\" d=\"100\" />");
  1584. ExportUtils.WriteLn(file, "<a:sy n=\"100\" d=\"100\" />");
  1585. ExportUtils.WriteLn(file, "</p:scale>");
  1586. ExportUtils.WriteLn(file, "<p:origin x=\"0\" y=\"0\" />");
  1587. ExportUtils.WriteLn(file, "</p:cViewPr>");
  1588. ExportUtils.WriteLn(file, "</p:notesTextViewPr>");
  1589. ExportUtils.WriteLn(file, "<p:gridSpacing cx=\"73736200\" cy=\"73736200\" />");
  1590. ExportUtils.WriteLn(file, "</p:viewPr>");
  1591. file.Position = 0;
  1592. OoXML.Zip.AddStream(ExportUtils.TruncLeadSlash(FileName), file);
  1593. }
  1594. }
  1595. /// <summary>
  1596. /// Specifies the image format in PowerPoint export.
  1597. /// </summary>
  1598. public enum PptImageFormat
  1599. {
  1600. /// <summary>
  1601. /// Specifies the .png format.
  1602. /// </summary>
  1603. Png,
  1604. /// <summary>
  1605. /// Specifies the .jpg format.
  1606. /// </summary>
  1607. Jpeg
  1608. }
  1609. /// <summary>
  1610. /// Represents the PowerPoint 2007 export.
  1611. /// </summary>
  1612. public partial class PowerPoint2007Export : OOExportBase
  1613. {
  1614. #region Slide layouts initializer
  1615. PptLayoutDescriptor[] layoutDescriptors =
  1616. {
  1617. new PptLayoutDescriptor("blank", "Blank", new PptShape[]
  1618. {
  1619. //new PptShape( 2, "Date Placeholder 1", 0, 0, 0, 0, "dt", "half", null, 10),
  1620. //new PptShape( 3, "Footer Placeholder 2", 0, 0, 0, 0, "ftr", "quarter", null, 11),
  1621. //new PptShape( 4, "Slide Number Placeholder 3", 0, 0, 0, 0, "sldNum", "quarter", null, 12)
  1622. }
  1623. )
  1624. };
  1625. #endregion
  1626. #region Private fields
  1627. private OoPptPresentation presentation;
  1628. private OoXMLCoreDocumentProperties coreDocProp;
  1629. private OoPptApplicationProperties appProp;
  1630. private OoPptViewProps viewProps;
  1631. private OoPptTableStyles tableStyles;
  1632. private OoPptPresProperties presentationProperties;
  1633. private OoXMLThemes themes;
  1634. private long paperWidth;
  1635. private long paperHeight;
  1636. private long leftMargin;
  1637. private long topMargin;
  1638. private OoPptSlideMaster slideMasters;
  1639. private ArrayList slideLayouts;
  1640. private ArrayList slideList;
  1641. private PptImageFormat imageFormat;
  1642. private int pictureCount;
  1643. private int slideIDCount;
  1644. private int slideCount;
  1645. internal int identifier;
  1646. internal uint slideMasterID;
  1647. private CultureInfo localization;
  1648. private bool exportLocale;
  1649. #endregion
  1650. #region Properties
  1651. internal int PictureCount
  1652. {
  1653. get { return pictureCount; }
  1654. set { pictureCount = value; }
  1655. }
  1656. internal OoPptSlideMaster SlideMaster { get { return slideMasters; } }
  1657. internal ArrayList SlideLayoutList { get { return slideLayouts; } }
  1658. internal ArrayList SlideList { get { return slideList; } }
  1659. internal long PaperWidth { get { return paperWidth; } }
  1660. internal long PaperHeight { get { return paperHeight; } }
  1661. internal long LeftMargin { get { return leftMargin; } }
  1662. internal long TopMargin { get { return topMargin; } }
  1663. internal int SlideCount { get { return slideCount; } set { slideCount = value; } }
  1664. internal int SlideIDCount { get { return slideIDCount; } set { slideIDCount = value; } }
  1665. /// <summary>
  1666. /// Gets or sets the image format used when exporting.
  1667. /// </summary>
  1668. public PptImageFormat ImageFormat
  1669. {
  1670. get { return imageFormat; }
  1671. set { imageFormat = value; }
  1672. }
  1673. /// <summary>
  1674. /// Get or set a locale for all document.
  1675. /// </summary>
  1676. public CultureInfo Locale
  1677. {
  1678. get { return localization; }
  1679. set { localization = value; }
  1680. }
  1681. /// <summary>
  1682. /// Gets or sets a value indicating that locale export are enabled.
  1683. /// </summary>
  1684. public bool ExportLocale
  1685. {
  1686. get { return exportLocale; }
  1687. set { exportLocale = value; }
  1688. }
  1689. #endregion
  1690. #region Private Methods
  1691. private void CreateRelations()
  1692. {
  1693. MemoryStream file = new MemoryStream();
  1694. ExportUtils.WriteLn(file, xml_header);
  1695. ExportUtils.WriteLn(file, "<Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\">");
  1696. ExportUtils.WriteLn(file, "<Relationship Id=\"rId3\" Type=" + Quoted(appProp.RelationType) + " Target=" + Quoted(appProp.FileName) + " />");
  1697. ExportUtils.WriteLn(file, "<Relationship Id=\"rId2\" Type=" + Quoted(coreDocProp.RelationType) + " Target=" + Quoted(coreDocProp.FileName) + " />");
  1698. ExportUtils.WriteLn(file, "<Relationship Id=\"rId1\" Type=" + Quoted(presentation.RelationType) + " Target=" + Quoted(presentation.FileName) + " />");
  1699. ExportUtils.WriteLn(file, "</Relationships>");
  1700. file.Position = 0;
  1701. Zip.AddStream("_rels/.rels", file);
  1702. }
  1703. private void CreateContentTypes()
  1704. {
  1705. MemoryStream file = new MemoryStream();
  1706. ExportUtils.WriteLn(file, xml_header);
  1707. ExportUtils.Write(file, "<Types xmlns=\"http://schemas.openxmlformats.org/package/2006/content-types\">");
  1708. for (int i = 0; i < slideLayouts.Count; i++)
  1709. {
  1710. OoPptSlideLayout layout = slideLayouts[i] as OoPptSlideLayout;
  1711. ExportUtils.Write(file, "<Override PartName=" + QuotedRoot(layout.FileName) + " ContentType=" + Quoted(layout.ContentType) + "/>");
  1712. }
  1713. for (int i = 0; i < slideList.Count; i++)
  1714. {
  1715. OoPptSlide slide = slideList[i] as OoPptSlide;
  1716. ExportUtils.Write(file, "<Override PartName=" + QuotedRoot(slide.FileName) + " ContentType=" + Quoted(slide.ContentType) + "/>");
  1717. }
  1718. ExportUtils.Write(file, "<Default Extension=\"rels\" ContentType=\"application/vnd.openxmlformats-package.relationships+xml\" />");
  1719. ExportUtils.Write(file, "<Default Extension=\"xml\" ContentType=\"application/xml\" />");
  1720. ExportUtils.Write(file, "<Default Extension=\"png\" ContentType=\"image/png\"/>");
  1721. ExportUtils.Write(file, "<Default Extension=\"jpg\" ContentType=\"image/jpeg\"/>");
  1722. ExportUtils.Write(file, "<Override PartName=" + QuotedRoot(presentation.FileName) + " ContentType=" + Quoted(presentation.ContentType) + "/>");
  1723. ExportUtils.Write(file, "<Override PartName=" + QuotedRoot(coreDocProp.FileName) + " ContentType=" + Quoted(coreDocProp.ContentType) + "/>");
  1724. ExportUtils.Write(file, "<Override PartName=" + QuotedRoot(appProp.FileName) + " ContentType=" + Quoted(appProp.ContentType) + "/>");
  1725. ExportUtils.Write(file, "<Override PartName=" + QuotedRoot(SlideMaster.FileName) + " ContentType=" + Quoted(SlideMaster.ContentType) + "/>");
  1726. ExportUtils.Write(file, "<Override PartName=" + QuotedRoot(tableStyles.FileName) + " ContentType=" + Quoted(tableStyles.ContentType) + "/>");
  1727. ExportUtils.Write(file, "<Override PartName=" + QuotedRoot(viewProps.FileName) + " ContentType=" + Quoted(viewProps.ContentType) + "/>");
  1728. ExportUtils.Write(file, "<Override PartName=" + QuotedRoot(presentationProperties.FileName) + " ContentType=" + Quoted(presentationProperties.ContentType) + "/>");
  1729. ExportUtils.Write(file, "<Override PartName=" + QuotedRoot(themes.FileName) + " ContentType=" + Quoted(themes.ContentType) + "/>");
  1730. ExportUtils.Write(file, "</Types>");
  1731. file.Position = 0;
  1732. Zip.AddStream("[Content_Types].xml", file);
  1733. }
  1734. private void ExportOOPPT(Stream Stream)
  1735. {
  1736. CreateContentTypes();
  1737. presentationProperties.Export(this);
  1738. tableStyles.Export(this);
  1739. viewProps.Export(this);
  1740. themes.Export(this, "FastReport.Resources.theme1.xml", "/ppt/theme/theme1.xml");
  1741. CreateRelations();
  1742. appProp.Export(this);
  1743. coreDocProp.Export(this);
  1744. presentation.Export(this);
  1745. slideMasters.Export(this);
  1746. foreach (OoPptSlideLayout layout in slideLayouts)
  1747. {
  1748. layout.Export(this);
  1749. }
  1750. }
  1751. #endregion
  1752. #region Protected Methods
  1753. /// <inheritdoc/>
  1754. protected override void Start()
  1755. {
  1756. base.Start();
  1757. //Init
  1758. pictureCount = 0;
  1759. slideIDCount = 0;
  1760. slideCount = 0;
  1761. identifier = 0;
  1762. slideMasterID = 0;
  1763. slideMasterID = 2147483648;
  1764. presentation = new OoPptPresentation();
  1765. coreDocProp = new OoXMLCoreDocumentProperties();
  1766. appProp = new OoPptApplicationProperties();
  1767. slideMasters = new OoPptSlideMaster(this);
  1768. viewProps = new OoPptViewProps();
  1769. tableStyles = new OoPptTableStyles();
  1770. presentationProperties = new OoPptPresProperties();
  1771. themes = new OoXMLThemes();
  1772. // Set relations to presentation.xml.rels
  1773. presentation.AddRelation(1, slideMasters);
  1774. presentation.AddRelation(2, presentationProperties);
  1775. presentation.AddRelation(3, viewProps);
  1776. presentation.AddRelation(4, themes);
  1777. presentation.AddRelation(5, tableStyles);
  1778. slideLayouts = new ArrayList();
  1779. slideList = new ArrayList();
  1780. // Set relations between layouts and Slide Master
  1781. for (int i = 0; i < layoutDescriptors.Length; i++)
  1782. {
  1783. OoPptSlideLayout current_layout = new OoPptSlideLayout(this, 1 + i, layoutDescriptors[i]);
  1784. current_layout.AddRelation(1, slideMasters);
  1785. slideMasters.AddRelation(1 + i, current_layout);
  1786. slideLayouts.Add(current_layout);
  1787. }
  1788. slideMasters.AddRelation(15000, themes);
  1789. Zip = new ZipArchive();
  1790. }
  1791. private OoPptSlide slide;
  1792. /// <inheritdoc/>
  1793. protected override void ExportPageBegin(ReportPage page)
  1794. {
  1795. base.ExportPageBegin(page);
  1796. const long EMUpmm = 36000;
  1797. this.paperWidth = (long)(ExportUtils.GetPageWidth(page) * EMUpmm);
  1798. this.paperHeight = (long)(ExportUtils.GetPageHeight(page) * EMUpmm);
  1799. this.leftMargin = (long)(page.LeftMargin * EMUpmm);
  1800. this.topMargin = (long)(page.TopMargin * EMUpmm);
  1801. slide = new OoPptSlide(this);
  1802. if (SlideIDCount < 255) slide.Reset();
  1803. slideList.Add(slide);
  1804. int relatives_count = presentation.RelationList.Count;
  1805. presentation.AddRelation(relatives_count + 1, slide);
  1806. slide.ExportBegin(this, page);
  1807. }
  1808. /// <inheritdoc/>
  1809. protected override void ExportBand(BandBase band)
  1810. {
  1811. base.ExportBand(band);
  1812. slide.ExportBand(this, band);
  1813. }
  1814. /// <inheritdoc/>
  1815. protected override void ExportPageEnd(ReportPage page)
  1816. {
  1817. slide.ExportEnd(this, page);
  1818. }
  1819. /// <inheritdoc/>
  1820. protected override void Finish()
  1821. {
  1822. ExportOOPPT(Stream);
  1823. Zip.SaveToStream(Stream);
  1824. Zip.Clear();
  1825. }
  1826. /// <inheritdoc/>
  1827. protected override string GetFileFilter()
  1828. {
  1829. return new MyRes("FileFilters").Get("PptxFile");
  1830. }
  1831. #endregion
  1832. /// <summary>
  1833. /// Get loacalization name.
  1834. /// </summary>
  1835. /// <returns></returns>
  1836. public string GetLoacalizationName()
  1837. {
  1838. if (localization == null || !exportLocale)
  1839. return Res.LocaleName;
  1840. return localization.Name;
  1841. }
  1842. /// <inheritdoc/>
  1843. public override void Serialize(FRWriter writer)
  1844. {
  1845. base.Serialize(writer);
  1846. writer.WriteValue("ImageFormat", ImageFormat);
  1847. writer.WriteValue("Locale", Locale);
  1848. writer.WriteBool("ExportLocale", ExportLocale);
  1849. }
  1850. /// <summary>
  1851. /// Creates a new instance of the <see cref="PowerPoint2007Export"/> class with the default settings.
  1852. /// </summary>
  1853. public PowerPoint2007Export()
  1854. {
  1855. ExportLocale = false;
  1856. }
  1857. }
  1858. }