ExportMatrix.cs 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820
  1. using FastReport.Barcode;
  2. using FastReport.Gauge.Radial;
  3. using FastReport.SVG;
  4. using FastReport.Table;
  5. using FastReport.Utils;
  6. using System;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. using System.Drawing;
  10. using System.Drawing.Imaging;
  11. using System.IO;
  12. using System.Windows.Forms;
  13. namespace FastReport.Export
  14. {
  15. internal class ExportMatrix : IDisposable
  16. {
  17. private const int SVG_SCALE = 3;
  18. #region Private fields
  19. private Font defaultOneSizeFont;
  20. private List<ExportIEMObject> iemObjectList;
  21. private List<ExportIEMStyle> iemStyleList;
  22. private BinaryTree xPos;
  23. private BinaryTree yPos;
  24. private List<ExportIEMPage> pages;
  25. private int width;
  26. private int height;
  27. private float maxWidth;
  28. private float maxHeight;
  29. private float minLeft;
  30. private float minTop;
  31. private int[] matrix;
  32. private float deltaY;
  33. private bool showProgress;
  34. private float inaccuracy;
  35. private bool rotatedImage;
  36. private bool plainRich;
  37. private bool cropFillArea;
  38. private bool fillArea;
  39. private bool optFrames;
  40. private float left;
  41. private bool printable;
  42. private bool images;
  43. private int imageResolution;
  44. private bool wrap;
  45. private bool bookmarks;
  46. private bool brushAsBitmap;
  47. private List<string> fontList;
  48. private bool dotMatrix;
  49. private Report report;
  50. private MyRes res;
  51. private ExportIEMPage currentPage;
  52. private float zoom;
  53. private bool fullTrust;
  54. private bool dataOnly;
  55. private ImageFormat pictureFormat;
  56. private int jpegQuality;
  57. private bool fillAsBitmap;
  58. private bool htmlMode;
  59. private bool watermarks;
  60. private IDictionary picsCache;
  61. private string rowHeightIs;
  62. private bool saveRowHeight;
  63. private bool seamless;
  64. private bool firstPage;
  65. private bool repeatDataband;
  66. private bool keepRichText;
  67. private bool printOptimized;
  68. private bool autoSize;
  69. #endregion
  70. #region Properties
  71. public bool Seamless
  72. {
  73. get { return seamless; }
  74. set { seamless = value; }
  75. }
  76. public List<ExportIEMStyle> Styles
  77. {
  78. get { return iemStyleList; }
  79. set { iemStyleList = value; }
  80. }
  81. public List<ExportIEMPage> Pages
  82. {
  83. get { return pages; }
  84. }
  85. public bool Watermarks
  86. {
  87. get { return watermarks; }
  88. set { watermarks = value; }
  89. }
  90. public bool HTMLMode
  91. {
  92. get { return htmlMode; }
  93. set { htmlMode = value; }
  94. }
  95. public bool FillAsBitmap
  96. {
  97. get { return fillAsBitmap; }
  98. set { fillAsBitmap = value; }
  99. }
  100. public int JpegQuality
  101. {
  102. get { return jpegQuality; }
  103. set { jpegQuality = value; }
  104. }
  105. public ImageFormat ImageFormat
  106. {
  107. get { return pictureFormat; }
  108. set { pictureFormat = value; }
  109. }
  110. public bool FullTrust
  111. {
  112. get { return fullTrust; }
  113. set { fullTrust = value; }
  114. }
  115. public float Zoom
  116. {
  117. get { return zoom; }
  118. set { zoom = value; }
  119. }
  120. public int Width
  121. {
  122. get { return width; }
  123. }
  124. public int Height
  125. {
  126. get { return height; }
  127. }
  128. public float MaxWidth
  129. {
  130. get { return maxWidth; }
  131. }
  132. public float MaxHeight
  133. {
  134. get { return maxHeight; }
  135. }
  136. public float MinLeft
  137. {
  138. get { return minLeft; }
  139. }
  140. public float MinTop
  141. {
  142. get { return minTop; }
  143. }
  144. public bool ShowProgress
  145. {
  146. get { return showProgress; }
  147. set { showProgress = value; }
  148. }
  149. public float MaxCellHeight
  150. {
  151. get { return yPos.MaxDistance; }
  152. set { yPos.MaxDistance = value; }
  153. }
  154. public float MaxCellWidth
  155. {
  156. get { return xPos.MaxDistance; }
  157. set
  158. {
  159. xPos.MaxDistance = value;
  160. }
  161. }
  162. public int PagesCount
  163. {
  164. get { return pages.Count; }
  165. }
  166. public int StylesCount
  167. {
  168. get { return iemStyleList.Count; }
  169. }
  170. public int ObjectsCount
  171. {
  172. get { return iemObjectList.Count; }
  173. }
  174. public float Inaccuracy
  175. {
  176. get { return xPos.Inaccuracy; }
  177. set
  178. {
  179. xPos.Inaccuracy = value;
  180. yPos.Inaccuracy = value;
  181. }
  182. }
  183. public bool RotatedAsImage
  184. {
  185. get { return rotatedImage; }
  186. set { rotatedImage = value; }
  187. }
  188. public bool PlainRich
  189. {
  190. get { return plainRich; }
  191. set { plainRich = value; }
  192. }
  193. public bool AreaFill
  194. {
  195. get { return fillArea; }
  196. set { fillArea = value; }
  197. }
  198. public bool CropAreaFill
  199. {
  200. get { return cropFillArea; }
  201. set { cropFillArea = value; }
  202. }
  203. public bool FramesOptimization
  204. {
  205. get { return optFrames; }
  206. set { optFrames = value; }
  207. }
  208. public float Left
  209. {
  210. get { return left; }
  211. }
  212. public bool Printable
  213. {
  214. get { return printable; }
  215. set { printable = value; }
  216. }
  217. public bool Images
  218. {
  219. get { return images; }
  220. set { images = value; }
  221. }
  222. public int ImageResolution
  223. {
  224. get { return imageResolution; }
  225. set { imageResolution = value; }
  226. }
  227. public bool WrapText
  228. {
  229. get { return wrap; }
  230. set { wrap = value; }
  231. }
  232. public bool BrushAsBitmap
  233. {
  234. get { return brushAsBitmap; }
  235. set { brushAsBitmap = value; }
  236. }
  237. public bool Bookmarks
  238. {
  239. get { return bookmarks; }
  240. set { bookmarks = value; }
  241. }
  242. public bool DotMatrix
  243. {
  244. get { return dotMatrix; }
  245. set { dotMatrix = value; }
  246. }
  247. public bool DataOnly
  248. {
  249. get { return dataOnly; }
  250. set { dataOnly = value; }
  251. }
  252. public Report Report
  253. {
  254. get { return report; }
  255. set { report = value; }
  256. }
  257. public string RowHeightIs
  258. {
  259. get { return this.rowHeightIs; }
  260. set { this.rowHeightIs = value; }
  261. }
  262. public bool SaveRowHeight
  263. {
  264. get { return saveRowHeight; }
  265. set { saveRowHeight = value; }
  266. }
  267. public bool KeepRichText
  268. {
  269. get { return this.keepRichText; }
  270. set { this.keepRichText = value; }
  271. }
  272. public bool PrintOptimized
  273. {
  274. get { return printOptimized; }
  275. set { printOptimized = value; }
  276. }
  277. #endregion
  278. #region Private Methods
  279. private int AddStyleInternal(ExportIEMStyle Style)
  280. {
  281. for (int i = iemStyleList.Count - 1; i >= 0; i--)
  282. if (Style.Equals(iemStyleList[i]))
  283. return i;
  284. iemStyleList.Add(Style);
  285. return iemStyleList.Count - 1;
  286. }
  287. private int AddStyle(ReportComponentBase Obj)
  288. {
  289. ExportIEMStyle Style = new ExportIEMStyle();
  290. if (Obj is TextObject)
  291. {
  292. TextObject MObj = Obj as TextObject;
  293. Style.Font = zoom == 1 ? MObj.Font :
  294. new Font(MObj.Font.FontFamily, MObj.Font.Size * zoom, MObj.Font.Style, MObj.Font.Unit, MObj.Font.GdiCharSet, MObj.Font.GdiVerticalFont);
  295. Style.NeedDisposeFont = zoom != 1;
  296. Style.TextFill = MObj.TextFill;
  297. Style.RTL = MObj.RightToLeft;
  298. Style.WordWrap = MObj.WordWrap;
  299. Style.Fill = MObj.Fill;
  300. Style.Format = MObj.Format;
  301. Style.VAlign = MObj.VertAlign;
  302. if (Style.RTL)
  303. Style.HAlign = MObj.HorzAlign == HorzAlign.Left ?
  304. HorzAlign.Right : (MObj.HorzAlign == HorzAlign.Right ? HorzAlign.Left : MObj.HorzAlign);
  305. else
  306. Style.HAlign = MObj.HorzAlign;
  307. Style.Padding = new Padding(
  308. (int)Math.Round(MObj.Padding.Left * zoom),
  309. (int)Math.Round(MObj.Padding.Top * zoom),
  310. (int)Math.Round(MObj.Padding.Right * zoom),
  311. (int)Math.Round(MObj.Padding.Bottom * zoom));
  312. Style.FirstTabOffset = MObj.FirstTabOffset;
  313. if (zoom == 1)
  314. Style.Border = MObj.Border;
  315. else
  316. {
  317. Style.Border = MObj.Border.Clone();
  318. Style.Border.ZoomBorder(zoom);
  319. }
  320. Style.Angle = MObj.Angle;
  321. Style.LineHeight = MObj.LineHeight;
  322. Style.ParagraphOffset = MObj.ParagraphOffset;
  323. Style.FontWidthRatio = MObj.FontWidthRatio;
  324. Style.ForceJustify = MObj.ForceJustify;
  325. }
  326. else if (Obj is HtmlObject)
  327. {
  328. HtmlObject MObj = Obj as HtmlObject;
  329. Style.RTL = MObj.RightToLeft;
  330. Style.Fill = MObj.Fill;
  331. Style.Format = MObj.Format;
  332. Style.WordWrap = true;
  333. Style.TextFill = new SolidFill(Color.Black);
  334. Style.Padding = new Padding(
  335. (int)Math.Round(MObj.Padding.Left * zoom),
  336. (int)Math.Round(MObj.Padding.Top * zoom),
  337. (int)Math.Round(MObj.Padding.Right * zoom),
  338. (int)Math.Round(MObj.Padding.Bottom * zoom));
  339. Style.Border = MObj.Border.Clone();
  340. Style.Border.ZoomBorder(zoom);
  341. }
  342. else if (Obj is BandBase)
  343. {
  344. BandBase Band = Obj as BandBase;
  345. Style.Fill = Band.Fill;
  346. Style.Border = Band.Border;
  347. }
  348. else if (IsLine(Obj))
  349. {
  350. Style.Border = Obj.Border;
  351. if (Obj.Width == 0)
  352. Style.Border.Lines = BorderLines.Left;
  353. else if (Obj.Height == 0)
  354. Style.Border.Lines = BorderLines.Top;
  355. Style.Font = defaultOneSizeFont;
  356. }
  357. else if (Obj is ShapeObject)
  358. {
  359. if ((Obj as ShapeObject).Shape == ShapeKind.Rectangle &&
  360. Obj.Fill.IsTransparent)
  361. {
  362. Style.Border = Obj.Border;
  363. Style.Border.Lines = BorderLines.All;
  364. Style.Fill = Obj.Fill;
  365. }
  366. //do nothing
  367. }
  368. else if (Obj is PolygonObject ||
  369. Obj is BarcodeObject)
  370. {
  371. //do nothing
  372. }
  373. #if DOTNET_4
  374. else if (Obj is SVGObject)
  375. {
  376. if (Obj.Fill is SolidFill && !Obj.Fill.IsTransparent)
  377. Style.Fill = Obj.Fill;
  378. Style.Border = Obj.Border;
  379. Style.HAlign = HorzAlign.Center;
  380. Style.VAlign = VertAlign.Center;
  381. }
  382. #endif
  383. else
  384. {
  385. Style.Border = Obj.Border;
  386. // Fill in RadialGauge sets the background color of the radial gauge,
  387. // which fills the entire square in which this gauge is located
  388. if (!(Obj is RadialGauge))
  389. {
  390. Style.Fill = Obj.Fill;
  391. }
  392. Style.Font = defaultOneSizeFont;
  393. Style.Border.LeftLine.Width = Style.Border.LeftLine.Width > 1 ?
  394. Style.Border.LeftLine.Width * zoom : Style.Border.LeftLine.Width;
  395. Style.Border.RightLine.Width = Style.Border.RightLine.Width > 1 ?
  396. Style.Border.RightLine.Width * zoom : Style.Border.RightLine.Width;
  397. Style.Border.TopLine.Width = Style.Border.TopLine.Width > 1 ?
  398. Style.Border.TopLine.Width * zoom : Style.Border.TopLine.Width;
  399. Style.Border.BottomLine.Width = Style.Border.BottomLine.Width > 1 ?
  400. Style.Border.BottomLine.Width * zoom : Style.Border.BottomLine.Width;
  401. }
  402. return AddStyleInternal(Style);
  403. }
  404. private int AddInternalObject(ExportIEMObject Obj, int x, int y, int dx, int dy)
  405. {
  406. Obj.x = x;
  407. Obj.y = y;
  408. Obj.dx = dx;
  409. Obj.dy = dy;
  410. iemObjectList.Add(Obj);
  411. return iemObjectList.Count - 1;
  412. }
  413. private bool IsMemo(ReportComponentBase Obj)
  414. {
  415. if (Obj is TextObject)
  416. {
  417. TextObject aObj = Obj as TextObject;
  418. if ((aObj.Angle == 0 || !rotatedImage) && !aObj.TextOutline.Enabled)
  419. return true;
  420. }
  421. return false;
  422. }
  423. private bool IsLine(ReportComponentBase Obj)
  424. {
  425. return (Obj is LineObject) && ((Obj.Width == 0) || (Obj.Height == 0));
  426. }
  427. private bool IsRect(ReportComponentBase Obj)
  428. {
  429. return (Obj is ShapeObject) && ((Obj as ShapeObject).Shape == ShapeKind.Rectangle);
  430. }
  431. private void FillArea(int x, int y, int dx, int dy, int Value)
  432. {
  433. int k;
  434. int ddx = x + dx;
  435. int ddy = y + dy;
  436. for (int i = y; i < ddy; i++)
  437. {
  438. k = width * i;
  439. for (int j = x; j < ddx; j++)
  440. matrix[k + j] = Value;
  441. }
  442. }
  443. private void ReplaceRect(int ObjIndex, int x, int y, int dx, int dy, int Value)
  444. {
  445. int k;
  446. int ddx = x + dx;
  447. int ddy = y + dy;
  448. for (int i = y; i < ddy; i++)
  449. {
  450. k = width * i;
  451. for (int j = x; j < ddx; j++)
  452. if (matrix[k + j] == ObjIndex)
  453. matrix[k + j] = Value;
  454. }
  455. }
  456. private void FindRect(int x, int y, out int dx, out int dy)
  457. {
  458. int Obj = matrix[width * y + x];
  459. int px = x;
  460. int py = y;
  461. int ky;
  462. dx = 0;
  463. while (matrix[width * py + px] == Obj)
  464. {
  465. ky = width * py;
  466. while (matrix[ky + px] == Obj)
  467. px++;
  468. if (dx == 0)
  469. dx = px - x;
  470. else if ((px - x) < dx)
  471. break;
  472. py++;
  473. px = x;
  474. }
  475. dy = py - y;
  476. }
  477. private void Cut(int ObjIndex, int x, int y, int dx, int dy)
  478. {
  479. ExportIEMObject Obj = iemObjectList[ObjIndex];
  480. ExportIEMObject NewObject = new ExportIEMObject();
  481. NewObject.StyleIndex = Obj.StyleIndex;
  482. NewObject.Style = Obj.Style;
  483. NewObject.Left = xPos.Nodes[x].value;
  484. NewObject.Top = yPos.Nodes[y].value;
  485. NewObject.Width = xPos.Nodes[x + dx].value - xPos.Nodes[x].value;
  486. NewObject.Height = yPos.Nodes[y + dy].value - yPos.Nodes[y].value;
  487. NewObject.IsText = Obj.IsText;
  488. NewObject.IsRichText = Obj.IsRichText;
  489. NewObject.Metafile = Obj.Metafile;
  490. NewObject.PictureStream = Obj.PictureStream;
  491. NewObject.Base = Obj.Base;
  492. NewObject.Hash = Obj.Hash;
  493. NewObject.InlineImageCache = Obj.InlineImageCache;
  494. float fdy = Obj.Top + Obj.Height - NewObject.Top;
  495. float fdx = Obj.Left + Obj.Width - NewObject.Left;
  496. NewObject.ParagraphFormat = Obj.ParagraphFormat;
  497. NewObject.TabWidth = Obj.TabWidth;
  498. if ((fdy > Obj.Height / 3) && (fdx > Obj.Width / 3))
  499. {
  500. NewObject.IsText = Obj.IsText;
  501. NewObject.Text = Obj.Text;
  502. NewObject.TabPositions = Obj.TabPositions;
  503. NewObject.Value = Obj.Value;
  504. NewObject.IsNumeric = Obj.IsNumeric;
  505. NewObject.IsDateTime = Obj.IsDateTime;
  506. NewObject.TextRenderType = Obj.TextRenderType;
  507. NewObject.OriginalText = Obj.OriginalText;
  508. Obj.Text = String.Empty;
  509. Obj.OriginalText = null;
  510. Obj.Value = null;
  511. Obj.IsText = true;
  512. }
  513. int NewIndex = AddInternalObject(NewObject, x, y, dx, dy);
  514. ReplaceRect(ObjIndex, x, y, dx, dy, NewIndex);
  515. CloneFrames(ObjIndex, NewIndex);
  516. iemObjectList[NewIndex].Exist = true;
  517. }
  518. private void CloneFrames(int Obj1, int Obj2)
  519. {
  520. ExportIEMObject FOld, FNew;
  521. BorderLines FrameTyp;
  522. FOld = iemObjectList[Obj1];
  523. FNew = iemObjectList[Obj2];
  524. if ((FOld.Style != null) && (FNew.Style != null))
  525. {
  526. FrameTyp = BorderLines.None;
  527. if (((BorderLines.Top & FOld.Style.Border.Lines) != 0) &&
  528. (Math.Abs(FOld.Top - FNew.Top) <= inaccuracy))
  529. FrameTyp |= BorderLines.Top;
  530. if (((BorderLines.Left & FOld.Style.Border.Lines) != 0) &&
  531. (Math.Abs(FOld.Left - FNew.Left) <= inaccuracy))
  532. FrameTyp |= BorderLines.Left;
  533. if (((BorderLines.Bottom & FOld.Style.Border.Lines) != 0) &&
  534. (Math.Abs((FOld.Top + FOld.Height) - (FNew.Top + FNew.Height)) <= inaccuracy))
  535. FrameTyp |= BorderLines.Bottom;
  536. if (((BorderLines.Right & FOld.Style.Border.Lines) != 0) &&
  537. (Math.Abs((FOld.Left + FOld.Width) - (FNew.Left + FNew.Width)) <= inaccuracy))
  538. FrameTyp |= BorderLines.Right;
  539. if (FrameTyp != FNew.Style.Border.Lines)
  540. {
  541. ExportIEMStyle NewStyle = new ExportIEMStyle();
  542. NewStyle.Assign(FOld.Style);
  543. NewStyle.Border.Lines = FrameTyp;
  544. FNew.StyleIndex = AddStyleInternal(NewStyle);
  545. FNew.Style = iemStyleList[FNew.StyleIndex];
  546. }
  547. }
  548. }
  549. private void Render()
  550. {
  551. int i, k, Old;
  552. ExportIEMObject Obj;
  553. ExportIEMStyle Style;
  554. FillBase OldColor;
  555. xPos.Close();
  556. yPos.Close();
  557. width = xPos.Count;
  558. height = yPos.Count;
  559. k = width * height;
  560. matrix = new int[k];
  561. for (i = 0; i < k; i++)
  562. matrix[i] = -1;
  563. for (i = 0; i < iemObjectList.Count; i++)
  564. {
  565. Obj = iemObjectList[i];
  566. int xPos0 = this.xPos.IndexOf(Obj.Left);
  567. if (xPos0 != -1)
  568. {
  569. iemObjectList[i].x = xPos0;
  570. Obj.Left = this.xPos.Nodes[xPos0].value;
  571. k = this.xPos.IndexOf(Obj.Left + Obj.Width);
  572. iemObjectList[i].dx = k - xPos0;
  573. }
  574. int yPos0 = this.yPos.IndexOf(Obj.Top);
  575. if (yPos0 != -1)
  576. {
  577. iemObjectList[i].y = yPos0;
  578. Obj.Top = this.yPos.Nodes[yPos0].value;
  579. k = this.yPos.IndexOf(Obj.Top + Obj.Height);
  580. iemObjectList[i].dy = k - yPos0;
  581. }
  582. if ((Obj.Style != null) && Obj.Style.FillColor.A == 0)
  583. {
  584. Old = matrix[width * Obj.y + Obj.x];
  585. if (Old != -1 && iemObjectList[Old].Style != null)
  586. {
  587. OldColor = iemObjectList[Old].Style.Fill;
  588. if ((ExportUtils.GetColorFromFill(OldColor) != Obj.Style.FillColor) &&
  589. (ExportUtils.GetColorFromFill(OldColor) != Obj.Style.TextColor))
  590. {
  591. Style = new ExportIEMStyle();
  592. Style.Assign(Obj.Style);
  593. Style.Fill = OldColor;
  594. Obj.StyleIndex = AddStyleInternal(Style);
  595. Obj.Style = iemStyleList[Obj.StyleIndex];
  596. }
  597. }
  598. else if (Obj.Style.FillColor != Color.Transparent)
  599. {
  600. Style = new ExportIEMStyle();
  601. Style.Assign(Obj.Style);
  602. Style.Fill = new SolidFill(Color.Transparent);
  603. Obj.StyleIndex = AddStyleInternal(Style);
  604. Obj.Style = iemStyleList[Obj.StyleIndex];
  605. }
  606. }
  607. int bottomIndex = matrix[width * Obj.y + Obj.x];
  608. if (bottomIndex != -1)
  609. {
  610. ExportIEMObject bottomObject = iemObjectList[bottomIndex];
  611. if (Obj.Style != null && bottomObject.Style != null)
  612. {
  613. CheckFrameFromBottmObject(Obj, bottomObject,
  614. Obj.y + Obj.dy, bottomObject.y + bottomObject.dy, BorderLines.Bottom);
  615. CheckFrameFromBottmObject(Obj, bottomObject,
  616. Obj.x + Obj.dx, bottomObject.x + bottomObject.dx, BorderLines.Right);
  617. CheckFrameFromBottmObject(Obj, bottomObject,
  618. Obj.x, bottomObject.x, BorderLines.Left);
  619. CheckFrameFromBottmObject(Obj, bottomObject,
  620. Obj.y, bottomObject.y, BorderLines.Top);
  621. }
  622. }
  623. if (!(Obj.IsBand && Obj.Style != null &&
  624. ((Obj.Style.FillColor == Color.White) || (Obj.Style.FillColor.A == 0)) &&
  625. (Obj.Style.Border.Lines == BorderLines.None)))
  626. FillArea(Obj.x, Obj.y, Obj.dx, Obj.dy, i);
  627. if (i % 1000 == 0)
  628. Config.DoEvent();
  629. }
  630. }
  631. private void CheckFrameFromBottmObject(ExportIEMObject Obj, ExportIEMObject bottomObject, int pos1, int pos2, BorderLines line)
  632. {
  633. if (pos1 == pos2 &&
  634. ((line & Obj.Style.Border.Lines) == 0) &&
  635. ((line & bottomObject.Style.Border.Lines) != 0))
  636. {
  637. ExportIEMStyle Style = new ExportIEMStyle();
  638. Style.Assign(Obj.Style);
  639. Style.Border.Lines = Obj.Style.Border.Lines | line;
  640. if (line == BorderLines.Bottom)
  641. Style.Border.BottomLine = bottomObject.Style.Border.BottomLine;
  642. else if (line == BorderLines.Top)
  643. Style.Border.TopLine = bottomObject.Style.Border.TopLine;
  644. else if (line == BorderLines.Left)
  645. Style.Border.LeftLine = bottomObject.Style.Border.LeftLine;
  646. else if (line == BorderLines.Right)
  647. Style.Border.RightLine = bottomObject.Style.Border.RightLine;
  648. Obj.StyleIndex = AddStyleInternal(Style);
  649. Obj.Style = iemStyleList[Obj.StyleIndex];
  650. }
  651. }
  652. private void Analyze()
  653. {
  654. for (int i = 0; i < height - 1; i++)
  655. {
  656. int ki = width * i;
  657. for (int j = 0; j < width - 1; j++)
  658. {
  659. int k = matrix[ki + j];
  660. if (k != -1)
  661. {
  662. ExportIEMObject obj = iemObjectList[k];
  663. if (!obj.Exist)
  664. {
  665. int dx, dy;
  666. FindRect(j, i, out dx, out dy);
  667. if (j + dx >= xPos.Count)
  668. dx = xPos.Count - j - 1;
  669. if (i + dy >= yPos.Count)
  670. dy = yPos.Count - i - 1;
  671. if ((obj.x != j) || (obj.y != i) || (obj.dx != dx) || (obj.dy != dy))
  672. {
  673. if (!obj.Exist)
  674. Cut(k, j, i, dx, dy);
  675. else
  676. obj.Exist = true;
  677. }
  678. else
  679. {
  680. obj.Exist = true;
  681. }
  682. }
  683. }
  684. }
  685. if (i % 1000 == 0)
  686. Config.DoEvent();
  687. }
  688. }
  689. private void OptimizeFrames()
  690. {
  691. int x, y;
  692. ExportIEMObject Obj, PrevObj;
  693. BorderLines CurrentLines;
  694. ExportIEMStyle Style;
  695. for (y = 0; y < Height; y++)
  696. {
  697. for (x = 0; x < Width; x++)
  698. {
  699. Obj = GetObject(x, y);
  700. if (Obj == null)
  701. continue;
  702. if (Obj.Style != null && Obj.Style.Border.Lines != BorderLines.None)
  703. {
  704. CurrentLines = Obj.Style.Border.Lines;
  705. if (((BorderLines.Top & CurrentLines) > 0) && (y > 0))
  706. {
  707. PrevObj = GetObject(x, y - 1);
  708. if ((PrevObj != null) && (PrevObj != Obj) && (PrevObj.Style != null)
  709. && ((BorderLines.Bottom & PrevObj.Style.Border.Lines) > 0)
  710. && (PrevObj.Style.Border.BottomLine.Width == Obj.Style.Border.TopLine.Width)
  711. && (PrevObj.Style.Border.BottomLine.Color == Obj.Style.Border.TopLine.Color)
  712. )
  713. {
  714. CurrentLines = CurrentLines & ~BorderLines.Top;
  715. Style = new ExportIEMStyle();
  716. Style.Assign(Obj.Style);
  717. Style.Border.Lines = CurrentLines;
  718. Obj.StyleIndex = AddStyleInternal(Style);
  719. Obj.Style = iemStyleList[Obj.StyleIndex];
  720. }
  721. }
  722. if (((BorderLines.Left & CurrentLines) > 0) && (x > 0))
  723. {
  724. PrevObj = GetObject(x - 1, y);
  725. if ((PrevObj != null) && (PrevObj != Obj) && (PrevObj.Style != null)
  726. && ((BorderLines.Right & PrevObj.Style.Border.Lines) > 0)
  727. && (PrevObj.Style.Border.RightLine.Width == Obj.Style.Border.LeftLine.Width)
  728. && (PrevObj.Style.Border.RightLine.Color == Obj.Style.Border.LeftLine.Color)
  729. )
  730. {
  731. CurrentLines = CurrentLines & ~BorderLines.Left;
  732. Style = new ExportIEMStyle();
  733. Style.Assign(Obj.Style);
  734. Style.Border.Lines = CurrentLines;
  735. Obj.StyleIndex = AddStyleInternal(Style);
  736. Obj.Style = iemStyleList[Obj.StyleIndex];
  737. }
  738. }
  739. }
  740. }
  741. if (y % 1000 == 0)
  742. Config.DoEvent();
  743. }
  744. }
  745. private void AddSetObjectPos(ReportComponentBase Obj, ref ExportIEMObject FObj)
  746. {
  747. float Left = Obj.AbsLeft;
  748. float Top = Obj.AbsTop;
  749. float Width = Obj.Width;
  750. float Height = Obj.Height;
  751. if (Left >= 0)
  752. FObj.Left = Width > 0 ? Left * zoom : (Left + Width) * zoom;
  753. else
  754. FObj.Left = 0;
  755. if (Top >= 0)
  756. FObj.Top = Height > 0 ? deltaY + Top * zoom : deltaY + (Top + Height) * zoom;
  757. else
  758. FObj.Top = deltaY;
  759. if (IsLine(Obj))
  760. {
  761. FObj.Width = Math.Abs(Width) > 0 ? Math.Abs(Width) * zoom : Obj.Border.Width * zoom;
  762. FObj.Height = Math.Abs(Height) > 0 ? Math.Abs(Height) * zoom : Obj.Border.Width * zoom;
  763. }
  764. else
  765. {
  766. FObj.Width = Math.Abs(Width) * zoom;
  767. FObj.Height = Math.Abs(Height) * zoom;
  768. }
  769. if ((FObj.Left + FObj.Width) > (currentPage.Width - currentPage.LeftMargin - currentPage.RightMargin) * Units.Millimeters)
  770. FObj.Width = (currentPage.Width - currentPage.LeftMargin - currentPage.RightMargin) * Units.Millimeters - FObj.Left;
  771. if ((FObj.Top + FObj.Height) > maxHeight)
  772. maxHeight = FObj.Top + FObj.Height;
  773. if ((FObj.Left + FObj.Width) > maxWidth)
  774. maxWidth = FObj.Left + FObj.Width;
  775. if (FObj.Left < minLeft)
  776. minLeft = FObj.Left;
  777. if (FObj.Top < minTop)
  778. minTop = FObj.Top;
  779. if ((FObj.Left < left) || (left == 0))
  780. left = FObj.Left;
  781. float bottom = FObj.Top + FObj.Height;
  782. xPos.Add(FObj.Left);
  783. xPos.Add(FObj.Left + FObj.Width);
  784. yPos.Add(FObj.Top);
  785. yPos.Add(bottom);
  786. AddInternalObject(FObj, 0, 0, 1, 1);
  787. }
  788. #endregion
  789. #region Public Methods
  790. public ExportIEMStyle StyleById(int Index)
  791. {
  792. return iemStyleList[Index];
  793. }
  794. public int Cell(int x, int y)
  795. {
  796. if ((x < width) && (y < height) && (x >= 0) && (y >= 0))
  797. return matrix[width * y + x];
  798. return -1;
  799. }
  800. public ExportIEMObject ObjectById(int ObjIndex)
  801. {
  802. if (ObjIndex < iemObjectList.Count)
  803. return iemObjectList[ObjIndex];
  804. return null;
  805. }
  806. public bool IsYPosByIdNull(int PosIndex)
  807. {
  808. return yPos.Nodes[PosIndex] == null;
  809. }
  810. public float XPosById(int PosIndex)
  811. {
  812. return xPos.Nodes[PosIndex].value;
  813. }
  814. public float YPosById(int PosIndex)
  815. {
  816. return yPos.Nodes[PosIndex].value;
  817. }
  818. public ExportIEMObject GetObject(int x, int y)
  819. {
  820. int i = matrix[width * y + x];
  821. if (i == -1)
  822. return null;
  823. return iemObjectList[i];
  824. }
  825. public void Clear()
  826. {
  827. foreach (KeyValuePair<string, MemoryStream> cacheItem in (Dictionary<string, MemoryStream>)picsCache)
  828. cacheItem.Value.Dispose();
  829. picsCache.Clear();
  830. iemObjectList.Clear();
  831. xPos.Clear();
  832. yPos.Clear();
  833. pages.Clear();
  834. foreach (ExportIEMStyle style in Styles)
  835. {
  836. if (style.NeedDisposeFont)// !style.Font.Equals(DrawUtils.DefaultFont))
  837. {
  838. style.Font.Dispose();
  839. style.Font = null;
  840. }
  841. }
  842. iemStyleList.Clear();
  843. fontList.Clear();
  844. deltaY = 0;
  845. firstPage = true;
  846. if (PagesCount > 100)
  847. GC.Collect(2);
  848. }
  849. public void AddBandObject(BandBase Obj)
  850. {
  851. if (Obj.Fill is TextureFill)
  852. return;
  853. if (Obj.HasFill || Obj.HasBorder)
  854. {
  855. ExportIEMObject FObj = new ExportIEMObject();
  856. FObj.StyleIndex = AddStyle(Obj);
  857. if (FObj.StyleIndex != -1)
  858. FObj.Style = iemStyleList[FObj.StyleIndex];
  859. FObj.IsText = true;
  860. FObj.IsBand = true;
  861. AddSetObjectPos(Obj, ref FObj);
  862. }
  863. }
  864. private void AddLineObject(ReportComponentBase Obj)
  865. {
  866. ExportIEMObject FObj = new ExportIEMObject();
  867. FObj.StyleIndex = AddStyle(Obj);
  868. if (FObj.StyleIndex != -1)
  869. FObj.Style = iemStyleList[FObj.StyleIndex];
  870. FObj.IsText = true;
  871. AddSetObjectPos(Obj, ref FObj);
  872. }
  873. private Size GetImageSize(ExportIEMObject FObj, ReportComponentBase Obj)
  874. {
  875. float dx = FObj.Width;
  876. float dy = FObj.Height;
  877. if (htmlMode)
  878. {
  879. if ((Obj.Border.Lines & BorderLines.Left) != 0)
  880. dx -= Obj.Border.LeftLine.Width * zoom;
  881. if ((Obj.Border.Lines & BorderLines.Right) != 0)
  882. dx -= Obj.Border.RightLine.Width * zoom;
  883. if ((Obj.Border.Lines & BorderLines.Top) != 0)
  884. dy -= Obj.Border.TopLine.Width * zoom;
  885. if ((Obj.Border.Lines & BorderLines.Bottom) != 0)
  886. dy -= Obj.Border.BottomLine.Width * zoom;
  887. }
  888. dx = (dx >= 1 ? dx : 1);
  889. dy = (dy >= 1 ? dy : 1);
  890. int imageZoom = printOptimized ? 3 : 1;
  891. return new Size((int)Math.Round(dx * imageZoom), (int)Math.Round(dy * imageZoom));
  892. }
  893. private void DrawImage(Graphics g, ReportComponentBase Obj)
  894. {
  895. using (GraphicCache cache = new GraphicCache())
  896. {
  897. if (Obj is TextObjectBase)
  898. g.Clear(Color.Transparent);
  899. float Left = Obj.Width >= 0 ? Obj.AbsLeft : Obj.AbsLeft + Obj.Width;
  900. float Top = Obj.Height >= 0 ? Obj.AbsTop : Obj.AbsTop + Obj.Height;
  901. int imageZoom = printOptimized && pictureFormat != ImageFormat.Emf ? SVG_SCALE : 1;
  902. if (htmlMode)
  903. {
  904. float dx = (Obj.Border.Lines & BorderLines.Left) != 0 ? Obj.Border.LeftLine.Width : 0;
  905. float dy = (Obj.Border.Lines & BorderLines.Top) != 0 ? Obj.Border.TopLine.Width : 0;
  906. g.TranslateTransform((-Left - dx) * zoom * imageZoom, (-Top - dy) * zoom * imageZoom);
  907. }
  908. else
  909. g.TranslateTransform(-Left * zoom * imageZoom, -Top * zoom * imageZoom);
  910. BorderLines oldLines = Obj.Border.Lines;
  911. Obj.Border.Lines = BorderLines.None;
  912. Obj.Draw(new FRPaintEventArgs(g, zoom * imageZoom, zoom * imageZoom, cache));
  913. Obj.Border.Lines = oldLines;
  914. }
  915. }
  916. private Hyperlink GetHyperlink(Hyperlink h)
  917. {
  918. if (string.IsNullOrEmpty(h.Value))
  919. return null;
  920. h.SetParent(null);
  921. return h;
  922. }
  923. public void AddPictureObject(ReportComponentBase Obj)
  924. {
  925. if (IsVisible(Obj))
  926. {
  927. ExportIEMObject FObj = new ExportIEMObject();
  928. FObj.Hyperlink = GetHyperlink(Obj.Hyperlink);
  929. FObj.Bookmark = Obj.Bookmark;
  930. Padding oldPadding = new Padding();
  931. if (Obj is TextObject)
  932. {
  933. oldPadding = (Obj as TextObject).Padding;
  934. (Obj as TextObject).Padding = new Padding();
  935. }
  936. FObj.StyleIndex = AddStyle(Obj);
  937. if (Obj is TextObject)
  938. (Obj as TextObject).Padding = oldPadding;
  939. if (FObj.StyleIndex != -1)
  940. FObj.Style = iemStyleList[FObj.StyleIndex];
  941. FObj.IsText = false;
  942. AddSetObjectPos(Obj, ref FObj);
  943. FObj.PictureStream = new MemoryStream();
  944. using (Bitmap bmp = new Bitmap(1, 1))
  945. {
  946. using (Graphics g = Graphics.FromImage(bmp))
  947. {
  948. IntPtr hdc = g.GetHdc();
  949. try
  950. {
  951. FObj.Metafile = new Metafile(FObj.PictureStream, hdc,
  952. new Rectangle(new Point(0, 0), GetImageSize(FObj, Obj)), MetafileFrameUnit.Pixel);
  953. }
  954. finally
  955. {
  956. g.ReleaseHdc(hdc);
  957. }
  958. }
  959. }
  960. if (pictureFormat != ImageFormat.Emf)
  961. {
  962. Size imageSize = GetImageSize(FObj, Obj);
  963. using (System.Drawing.Image image = new Bitmap(imageSize.Width, imageSize.Height))
  964. {
  965. using (Graphics g = Graphics.FromImage(image))
  966. {
  967. DrawImage(g, Obj);
  968. }
  969. if (PrintOptimized)
  970. {
  971. using (Bitmap b = new Bitmap(
  972. (int)Math.Round((decimal)(imageSize.Width / SVG_SCALE)),
  973. (int)Math.Round((decimal)(imageSize.Height / SVG_SCALE))
  974. ))
  975. {
  976. using (Graphics g = Graphics.FromImage(b))
  977. {
  978. g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
  979. g.DrawImage(
  980. image,
  981. 0,
  982. 0,
  983. (int)Math.Round((decimal)(imageSize.Width / SVG_SCALE)),
  984. (int)Math.Round((decimal)(imageSize.Height / SVG_SCALE))
  985. );
  986. }
  987. if (pictureFormat == ImageFormat.Jpeg)
  988. ExportUtils.SaveJpeg(b, FObj.PictureStream, jpegQuality);
  989. else
  990. b.Save(FObj.PictureStream, pictureFormat);
  991. }
  992. }
  993. else
  994. {
  995. if (pictureFormat == ImageFormat.Jpeg)
  996. ExportUtils.SaveJpeg(image, FObj.PictureStream, jpegQuality);
  997. else
  998. image.Save(FObj.PictureStream, pictureFormat);
  999. image.Dispose();
  1000. }
  1001. }
  1002. }
  1003. else
  1004. using (Graphics g = Graphics.FromImage(FObj.Metafile))
  1005. {
  1006. DrawImage(g, Obj);
  1007. }
  1008. FObj.PictureStream.Position = 0;
  1009. CheckPicsCache(FObj);
  1010. AddShadow(Obj);
  1011. }
  1012. }
  1013. public void AddPictureObject_Safe(ReportComponentBase Obj)
  1014. {
  1015. if (IsVisible(Obj))
  1016. {
  1017. ExportIEMObject FObj = new ExportIEMObject();
  1018. FObj.Hyperlink = GetHyperlink(Obj.Hyperlink);
  1019. FObj.Bookmark = Obj.Bookmark;
  1020. Padding oldPadding = new Padding();
  1021. if (Obj is TextObject)
  1022. {
  1023. oldPadding = (Obj as TextObject).Padding;
  1024. (Obj as TextObject).Padding = new Padding();
  1025. }
  1026. FObj.StyleIndex = AddStyle(Obj);
  1027. if (Obj is TextObject)
  1028. (Obj as TextObject).Padding = oldPadding;
  1029. if (FObj.StyleIndex != -1)
  1030. FObj.Style = iemStyleList[FObj.StyleIndex];
  1031. FObj.IsText = false;
  1032. AddSetObjectPos(Obj, ref FObj);
  1033. FObj.PictureStream = new MemoryStream();
  1034. float zoom = imageResolution / 96f;
  1035. Size imageSize = GetImageSize(FObj, Obj);
  1036. using (System.Drawing.Image image =
  1037. new Bitmap(
  1038. (int)Math.Round(imageSize.Width * zoom),
  1039. (int)Math.Round(imageSize.Height * zoom)
  1040. ))
  1041. {
  1042. using (Graphics g = Graphics.FromImage(image))
  1043. {
  1044. g.ScaleTransform(zoom, zoom);
  1045. DrawImage(g, Obj);
  1046. }
  1047. if (printOptimized)
  1048. {
  1049. using (Bitmap b = new Bitmap(
  1050. (int)Math.Round((decimal)(imageSize.Width / SVG_SCALE * zoom)),
  1051. (int)Math.Round((decimal)(imageSize.Height / SVG_SCALE * zoom))
  1052. ))
  1053. {
  1054. using (Graphics g = Graphics.FromImage(b))
  1055. {
  1056. g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
  1057. g.DrawImage(
  1058. image,
  1059. 0,
  1060. 0,
  1061. (int)Math.Round((decimal)(imageSize.Width / SVG_SCALE * zoom)),
  1062. (int)Math.Round((decimal)(imageSize.Height / SVG_SCALE * zoom))
  1063. );
  1064. image.Dispose();
  1065. }
  1066. if (pictureFormat == ImageFormat.Jpeg)
  1067. ExportUtils.SaveJpeg(b, FObj.PictureStream, jpegQuality);
  1068. else
  1069. b.Save(FObj.PictureStream, pictureFormat);
  1070. }
  1071. }
  1072. else
  1073. {
  1074. if (pictureFormat == ImageFormat.Jpeg)
  1075. ExportUtils.SaveJpeg(image, FObj.PictureStream, jpegQuality);
  1076. else
  1077. image.Save(FObj.PictureStream, pictureFormat);
  1078. }
  1079. }
  1080. FObj.PictureStream.Position = 0;
  1081. CheckPicsCache(FObj);
  1082. AddShadow(Obj);
  1083. }
  1084. }
  1085. #if DOTNET_4
  1086. private void AddSVG(SVGObject Obj)
  1087. {
  1088. if (IsVisible(Obj))
  1089. {
  1090. ExportIEMObject FObj = new ExportIEMObject();
  1091. FObj.StyleIndex = AddStyle(Obj);
  1092. if (FObj.StyleIndex != -1)
  1093. FObj.Style = iemStyleList[FObj.StyleIndex];
  1094. //FObj.Text = Obj.Text;
  1095. FObj.IsNumeric = false;
  1096. FObj.TextRenderType = TextRenderType.Default;
  1097. FObj.Hyperlink = GetHyperlink(Obj.Hyperlink);
  1098. FObj.Bookmark = Obj.Bookmark;
  1099. FObj.IsText = false;
  1100. FObj.IsRichText = false;
  1101. FObj.IsSvg = true;
  1102. AddSetObjectPos(Obj, ref FObj);
  1103. FObj.PictureStream = new MemoryStream();
  1104. if (Obj.Grayscale)
  1105. Obj.SVGGrayscale.Write(FObj.PictureStream);
  1106. else
  1107. Obj.SvgDocument.Write(FObj.PictureStream);
  1108. CheckPicsCache(FObj);
  1109. }
  1110. }
  1111. #endif
  1112. private void AddHtml(HtmlObject Obj)
  1113. {
  1114. if (IsVisible(Obj))
  1115. {
  1116. ExportIEMObject FObj = new ExportIEMObject();
  1117. FObj.StyleIndex = AddStyle(Obj);
  1118. if (FObj.StyleIndex != -1)
  1119. FObj.Style = iemStyleList[FObj.StyleIndex];
  1120. FObj.Text = Obj.Text;
  1121. FObj.IsNumeric = false;
  1122. FObj.TextRenderType = TextRenderType.HtmlTags;
  1123. FObj.Hyperlink = GetHyperlink(Obj.Hyperlink);
  1124. FObj.Bookmark = Obj.Bookmark;
  1125. FObj.IsText = false;
  1126. FObj.IsRichText = false;
  1127. AddSetObjectPos(Obj, ref FObj);
  1128. AddShadow(Obj);
  1129. if (fillAsBitmap && !(FObj.Style.Fill is SolidFill))
  1130. {
  1131. float dx = FObj.Width;
  1132. float dy = FObj.Height;
  1133. dx = (dx >= 1 ? dx : 1);
  1134. dy = (dy >= 1 ? dy : 1);
  1135. System.Drawing.Image image = new Bitmap((int)dx, (int)dy);
  1136. using (Graphics g = Graphics.FromImage(image))
  1137. {
  1138. g.Clear(Color.Transparent);
  1139. g.TranslateTransform(-Obj.AbsLeft * zoom, -Obj.AbsTop * zoom);
  1140. BorderLines oldLines = Obj.Border.Lines;
  1141. Obj.Border.Lines = BorderLines.None;
  1142. string oldText = Obj.Text;
  1143. Obj.Text = String.Empty;
  1144. Obj.Draw(new FRPaintEventArgs(g, zoom, zoom, Report.GraphicCache));
  1145. Obj.Text = oldText;
  1146. Obj.Border.Lines = oldLines;
  1147. FObj.PictureStream = new MemoryStream();
  1148. image.Save(FObj.PictureStream, pictureFormat);
  1149. CheckPicsCache(FObj);
  1150. }
  1151. }
  1152. }
  1153. }
  1154. public void AddTextObject(TextObject Obj)
  1155. {
  1156. AddTextObject(Obj, false);
  1157. }
  1158. public void AddTextObject(TextObject Obj, bool isHeader)
  1159. {
  1160. if (IsVisible(Obj))
  1161. {
  1162. ExportIEMObject FObj = new ExportIEMObject();
  1163. FObj.StyleIndex = AddStyle(Obj);
  1164. if (FObj.StyleIndex != -1)
  1165. FObj.Style = iemStyleList[FObj.StyleIndex];
  1166. FObj.Text = Obj.Text;
  1167. FObj.AutoSize = autoSize;
  1168. FObj.TabPositions = Obj.TabPositions.Count > 0 ? Obj.TabPositions : null;
  1169. if (isHeader && Obj.OriginalComponent != null)
  1170. FObj.OriginalText = (Obj.OriginalComponent as TextObject).Text;
  1171. FObj.TabWidth = Obj.TabWidth;
  1172. if (Obj.TextRenderType == TextRenderType.HtmlParagraph)
  1173. {
  1174. if (Obj.ParagraphFormat != null)
  1175. FObj.ParagraphFormat = Obj.ParagraphFormat.MultipleScale(1);
  1176. FObj.InlineImageCache = Obj.InlineImageCache;
  1177. }
  1178. FObj.IsDateTime = ExportUtils.ParseTextToDateTime(FObj.Text, FObj.Style.Format, out DateTime date);
  1179. if (FObj.IsDateTime)
  1180. FObj.Value = date;
  1181. else
  1182. {
  1183. FObj.IsPercent = ExportUtils.ParseTextToPercent(FObj.Text, FObj.Style.Format, out decimal percent);
  1184. if (FObj.IsPercent)
  1185. FObj.Value = percent;
  1186. else
  1187. {
  1188. FObj.IsNumeric = ExportUtils.ParseTextToDecimal(FObj.Text, FObj.Style.Format, out decimal numeric);
  1189. if (FObj.IsNumeric)
  1190. FObj.Value = numeric;
  1191. }
  1192. }
  1193. FObj.TextRenderType = Obj.TextRenderType;
  1194. FObj.Hyperlink = GetHyperlink(Obj.Hyperlink);
  1195. FObj.Bookmark = Obj.Bookmark;
  1196. FObj.IsText = true;
  1197. FObj.IsRichText = false;
  1198. AddSetObjectPos(Obj, ref FObj);
  1199. AddShadow(Obj);
  1200. if (fillAsBitmap && !(FObj.Style.Fill is SolidFill))
  1201. {
  1202. float dx = FObj.Width;
  1203. float dy = FObj.Height;
  1204. dx = (dx >= 1 ? dx : 1);
  1205. dy = (dy >= 1 ? dy : 1);
  1206. System.Drawing.Image image = new Bitmap((int)dx, (int)dy);
  1207. using (Graphics g = Graphics.FromImage(image))
  1208. {
  1209. g.Clear(Color.Transparent);
  1210. g.TranslateTransform(-Obj.AbsLeft * zoom, -Obj.AbsTop * zoom);
  1211. BorderLines oldLines = Obj.Border.Lines;
  1212. Obj.Border.Lines = BorderLines.None;
  1213. string oldText = Obj.Text;
  1214. Obj.Text = String.Empty;
  1215. Obj.Draw(new FRPaintEventArgs(g, zoom, zoom, Report.GraphicCache));
  1216. Obj.Text = oldText;
  1217. Obj.Border.Lines = oldLines;
  1218. FObj.PictureStream = new MemoryStream();
  1219. image.Save(FObj.PictureStream, pictureFormat);
  1220. CheckPicsCache(FObj);
  1221. }
  1222. }
  1223. }
  1224. }
  1225. private bool IsVisible(ReportComponentBase Obj)
  1226. {
  1227. return !((Obj.AbsLeft + Obj.Width) < 0 ||
  1228. (Obj.AbsTop + Obj.Height) < 0 ||
  1229. (Obj.AbsLeft > (currentPage.Width / zoom * Units.Millimeters)) ||
  1230. (Obj.AbsTop > (currentPage.Height / zoom * Units.Millimeters)));
  1231. }
  1232. private void AddShadow(ReportComponentBase Obj)
  1233. {
  1234. if (Obj.Border.Shadow)
  1235. {
  1236. using (TextObject shadow = new TextObject())
  1237. {
  1238. shadow.Left = Obj.AbsLeft + Obj.Width;
  1239. shadow.Width = Obj.Border.ShadowWidth;
  1240. shadow.Top = Obj.AbsTop + Obj.Border.ShadowWidth;
  1241. shadow.Height = Obj.Height;
  1242. shadow.Fill = new SolidFill(Obj.Border.ShadowColor);
  1243. AddTextObject(shadow);
  1244. }
  1245. using (TextObject shadow = new TextObject())
  1246. {
  1247. shadow.Left = Obj.AbsLeft + Obj.Border.ShadowWidth;
  1248. shadow.Width = Obj.Width - Obj.Border.ShadowWidth;
  1249. shadow.Top = Obj.AbsTop + Obj.Height;
  1250. shadow.Height = Obj.Border.ShadowWidth;
  1251. shadow.Fill = new SolidFill(Obj.Border.ShadowColor);
  1252. AddTextObject(shadow);
  1253. }
  1254. }
  1255. }
  1256. public void AddPageBegin(ReportPage page)
  1257. {
  1258. currentPage = new ExportIEMPage();
  1259. currentPage.Landscape = page.Landscape;
  1260. currentPage.Width = ExportUtils.GetPageWidth(page) * zoom;
  1261. currentPage.Height = ExportUtils.GetPageHeight(page) * zoom;
  1262. currentPage.RawPaperSize = page.RawPaperSize;
  1263. currentPage.LeftMargin = page.LeftMargin * zoom;
  1264. currentPage.TopMargin = page.TopMargin * zoom;
  1265. currentPage.RightMargin = page.RightMargin * zoom;
  1266. currentPage.BottomMargin = page.BottomMargin * zoom;
  1267. repeatDataband = false;
  1268. }
  1269. public void AddBand(BandBase band, object sender)
  1270. {
  1271. AddBand(band, sender, false);
  1272. }
  1273. public void AddBand(BandBase band, object sender, bool isHeader)
  1274. {
  1275. if (dataOnly && !(band is DataBand))
  1276. return;
  1277. if (seamless && (((band is PageHeaderBand) && !firstPage) || (band is PageFooterBand)))
  1278. return;
  1279. if (!(band.Fill is TextureFill))
  1280. AddBandObject(band);
  1281. else
  1282. if (images)
  1283. {
  1284. if (fullTrust)
  1285. AddPictureObject(band);
  1286. else
  1287. AddPictureObject_Safe(band);
  1288. }
  1289. foreach (Base c in band.ForEachAllConvectedObjects(sender))
  1290. {
  1291. if (c is ReportComponentBase && (c as ReportComponentBase).Exportable)
  1292. {
  1293. ReportComponentBase obj = c as ReportComponentBase;
  1294. if (obj is CellularTextObject)
  1295. obj = (obj as CellularTextObject).GetTable();
  1296. if (dataOnly && (obj.Parent == null || !(obj.Parent is DataBand)))
  1297. continue;
  1298. if (seamless &&
  1299. (
  1300. (obj.Parent is PageFooterBand) || (obj is PageFooterBand) ||
  1301. (((obj.Parent is PageHeaderBand) || (obj is PageHeaderBand)) && !firstPage)
  1302. )
  1303. )
  1304. continue;
  1305. if (obj is TableCell)
  1306. continue;
  1307. else if (obj is TableBase)
  1308. {
  1309. AddTableObject(obj as TableBase);
  1310. repeatDataband = true;
  1311. }
  1312. else if (IsMemo(obj))
  1313. AddTextObject(obj as TextObject, isHeader);
  1314. else if (obj is BandBase)
  1315. {
  1316. if (!repeatDataband)
  1317. AddBandObject(obj as BandBase);
  1318. repeatDataband = false;
  1319. }
  1320. else if (IsLine(obj) ||
  1321. (IsRect(obj) && obj.Fill.IsTransparent))
  1322. AddLineObject(obj);
  1323. else if ((obj is HtmlObject) && htmlMode)
  1324. AddHtml(obj as HtmlObject);
  1325. else if (keepRichText && (obj is RichObject))
  1326. AddRich(obj as RichObject);
  1327. else if (!((obj is HtmlObject) && !htmlMode))
  1328. {
  1329. if (images)
  1330. {
  1331. #if DOTNET_4
  1332. if ((obj is SVGObject) && htmlMode)
  1333. AddSVG(obj as SVGObject);
  1334. else
  1335. #endif
  1336. {
  1337. if (fullTrust)
  1338. AddPictureObject(obj);
  1339. else
  1340. AddPictureObject_Safe(obj);
  1341. }
  1342. }
  1343. }
  1344. }
  1345. }
  1346. }
  1347. private void AddRich(RichObject richObject)
  1348. {
  1349. if (IsVisible(richObject))
  1350. {
  1351. ExportIEMObject FObj = new ExportIEMObject();
  1352. FObj.StyleIndex = AddStyle(richObject);
  1353. if (FObj.StyleIndex != -1)
  1354. FObj.Style = iemStyleList[FObj.StyleIndex];
  1355. FObj.Text = richObject.Text;
  1356. #if CHECK_LATER
  1357. FObj.TabWidth = richObject.TabWidth;
  1358. if (Obj.ParagraphFormat != null)
  1359. FObj.ParagraphFormat = Obj.ParagraphFormat.MultipleScale(1);
  1360. if (Obj.TextRenderType == TextRenderType.HtmlParagraph)
  1361. FObj.InlineImageCache = Obj.InlineImageCache;
  1362. DateTime date;
  1363. #endif
  1364. FObj.IsDateTime = false;
  1365. FObj.IsPercent = false;
  1366. FObj.IsNumeric = false;
  1367. FObj.Value = null;
  1368. FObj.TextRenderType = TextRenderType.Default;
  1369. FObj.Hyperlink = GetHyperlink(richObject.Hyperlink);
  1370. FObj.Bookmark = richObject.Bookmark;
  1371. FObj.IsText = true;
  1372. FObj.IsRichText = true;
  1373. #if CHECK_LATER
  1374. if (wrap)
  1375. FObj.WrappedText = WrapTextObject(richObject);
  1376. #endif
  1377. AddSetObjectPos(richObject, ref FObj);
  1378. AddShadow(richObject);
  1379. if (fillAsBitmap && !(FObj.Style.Fill is SolidFill))
  1380. {
  1381. float dx = FObj.Width;
  1382. float dy = FObj.Height;
  1383. dx = (dx >= 1 ? dx : 1);
  1384. dy = (dy >= 1 ? dy : 1);
  1385. System.Drawing.Image image = new Bitmap((int)dx, (int)dy);
  1386. using (Graphics g = Graphics.FromImage(image))
  1387. {
  1388. g.Clear(Color.Transparent);
  1389. g.TranslateTransform(-richObject.AbsLeft * zoom, -richObject.AbsTop * zoom);
  1390. BorderLines oldLines = richObject.Border.Lines;
  1391. richObject.Border.Lines = BorderLines.None;
  1392. string oldText = richObject.Text;
  1393. richObject.Text = String.Empty;
  1394. richObject.Draw(new FRPaintEventArgs(g, zoom, zoom, Report.GraphicCache));
  1395. richObject.Text = oldText;
  1396. richObject.Border.Lines = oldLines;
  1397. FObj.PictureStream = new MemoryStream();
  1398. image.Save(FObj.PictureStream, pictureFormat);
  1399. CheckPicsCache(FObj);
  1400. }
  1401. }
  1402. }
  1403. }
  1404. public void AddTableObject(TableBase table)
  1405. {
  1406. if (table != null && table.ColumnCount > 0 && table.RowCount > 0)
  1407. {
  1408. table.EmulateOuterBorder();
  1409. using (TextObject tableback = new TextObject())
  1410. {
  1411. tableback.Border = table.Border;
  1412. tableback.Fill = table.Fill;
  1413. tableback.Left = table.AbsLeft;
  1414. tableback.Top = table.AbsTop;
  1415. float tableWidth = 0;
  1416. for (int i = 0; i < table.ColumnCount; i++)
  1417. tableWidth += table.Columns[i].Width;// table[i, 0].Width;
  1418. float tableHeight = 0;
  1419. for (int i = 0; i < table.RowCount; i++)
  1420. tableHeight += table.Rows[i].Height;
  1421. tableback.Width = tableWidth;// (tableWidth < table.Width) ? tableWidth : table.Width;
  1422. tableback.Height = tableHeight;
  1423. AddTextObject(tableback);
  1424. }
  1425. float y = 0;
  1426. for (int i = 0; i < table.RowCount; i++)
  1427. {
  1428. autoSize = table.Rows[i].AutoSize;
  1429. float x = 0;
  1430. for (int j = 0; j < table.ColumnCount; j++)
  1431. {
  1432. if (!table.IsInsideSpan(table[j, i]))
  1433. {
  1434. TableCell textcell = table[j, i];
  1435. textcell.Left = x;
  1436. textcell.Top = y;
  1437. if (IsMemo(textcell))
  1438. AddTextObject(textcell as TextObject);
  1439. else if (images)
  1440. if (fullTrust)
  1441. AddPictureObject(textcell);
  1442. else
  1443. AddPictureObject_Safe(textcell);
  1444. }
  1445. x += (table.Columns[j]).Width;
  1446. }
  1447. y += (table.Rows[i]).Height;
  1448. }
  1449. }
  1450. }
  1451. public void AddPageEnd(ReportPage page)
  1452. {
  1453. if (watermarks)
  1454. AddWatermark(page, currentPage);
  1455. deltaY = maxHeight;
  1456. currentPage.Value = maxHeight;
  1457. pages.Add(currentPage);
  1458. firstPage = false;
  1459. //it is necessary to control the number of rows in the matrix
  1460. height = yPos.Count - 1;
  1461. /*ObjectCollection allObjects = page.AllObjects;
  1462. for (int i = 0; i < allObjects.Count; i++)
  1463. {
  1464. ReportComponentBase c = allObjects[i] as ReportComponentBase;
  1465. if (c != null)
  1466. {
  1467. c.Dispose();
  1468. c = null;
  1469. }
  1470. }*/
  1471. }
  1472. private void AddWatermark(ReportPage page, ExportIEMPage matrixPage)
  1473. {
  1474. if (page.Watermark.Enabled)
  1475. {
  1476. int dx = (int)(ExportUtils.GetPageWidth(page) * Units.Millimeters * zoom);
  1477. int dy = (int)(ExportUtils.GetPageHeight(page) * Units.Millimeters * zoom);
  1478. using (System.Drawing.Image image = new Bitmap(dx, dy))
  1479. {
  1480. matrixPage.WatermarkPictureStream = new MemoryStream();
  1481. using (Graphics g = Graphics.FromImage(image))
  1482. {
  1483. g.Clear(Color.White);
  1484. page.Watermark.DrawImage(new FRPaintEventArgs(g, 1, 1, page.Report.GraphicCache),
  1485. new Rectangle(0, 0, dx, dy), Report, true);
  1486. page.Watermark.DrawText(new FRPaintEventArgs(g, 1, 1, page.Report.GraphicCache),
  1487. new Rectangle(0, 0, dx, dy), Report, true);
  1488. }
  1489. if (pictureFormat == ImageFormat.Jpeg)
  1490. ExportUtils.SaveJpeg(image, matrixPage.WatermarkPictureStream, jpegQuality);
  1491. else
  1492. image.Save(matrixPage.WatermarkPictureStream, pictureFormat);
  1493. matrixPage.WatermarkPictureStream.Position = 0;
  1494. }
  1495. }
  1496. }
  1497. public void CheckPicsCache(ExportIEMObject FObj)
  1498. {
  1499. FObj.Hash = Crypter.ComputeHash(FObj.PictureStream);
  1500. FObj.Base = !((Dictionary<string, MemoryStream>)picsCache).ContainsKey(FObj.Hash);
  1501. if (FObj.Base)
  1502. picsCache.Add(FObj.Hash, FObj.PictureStream);
  1503. else
  1504. FObj.PictureStream = ((Dictionary<string, MemoryStream>)picsCache)[FObj.Hash];
  1505. }
  1506. public void Prepare()
  1507. {
  1508. ExportIEMStyle Style;
  1509. ExportIEMObject FObj;
  1510. ExportIEMObject FObjItem;
  1511. if (fillArea)
  1512. {
  1513. Style = new ExportIEMStyle();
  1514. Style.Fill = new SolidFill(Color.Transparent);
  1515. FObj = new ExportIEMObject();
  1516. FObj.StyleIndex = AddStyleInternal(Style);
  1517. FObj.Style = Style;
  1518. if (cropFillArea)
  1519. {
  1520. FObj.Left = minLeft;
  1521. FObj.Top = minTop;
  1522. }
  1523. else
  1524. FObj.Left = FObj.Top = 0;
  1525. FObj.Width = MaxWidth;
  1526. FObj.Height = MaxHeight;
  1527. FObj.IsText = true;
  1528. xPos.Add(0);
  1529. yPos.Add(0);
  1530. FObjItem = FObj;
  1531. FObjItem.x = FObjItem.y = 0;
  1532. FObjItem.dx = FObjItem.dy = 1;
  1533. iemObjectList.Insert(0, FObjItem);
  1534. }
  1535. if (showProgress)
  1536. Config.ReportSettings.OnProgress(report, res.Get("OrderByCells"));
  1537. Config.DoEvent();
  1538. Render();
  1539. if (showProgress)
  1540. Config.ReportSettings.OnProgress(report, res.Get("AnalyzeObjects"));
  1541. Config.DoEvent();
  1542. Analyze();
  1543. if (optFrames)
  1544. OptimizeFrames();
  1545. if (showProgress)
  1546. Config.ReportSettings.OnProgress(report, res.Get("SaveFile"));
  1547. Config.DoEvent();
  1548. }
  1549. public void ObjectPos(int ObjIndex, out int x, out int y, out int dx, out int dy)
  1550. {
  1551. x = iemObjectList[ObjIndex].x;
  1552. y = iemObjectList[ObjIndex].y;
  1553. dx = iemObjectList[ObjIndex].dx;
  1554. dy = iemObjectList[ObjIndex].dy;
  1555. }
  1556. public float PageBreak(int Page)
  1557. {
  1558. if (Page < pages.Count)
  1559. return pages[Page].Value;
  1560. return 0f;
  1561. }
  1562. public float PageWidth(int Page)
  1563. {
  1564. if (Page < pages.Count)
  1565. return pages[Page].Width;
  1566. return 0f;
  1567. }
  1568. public float PageHeight(int Page)
  1569. {
  1570. if (Page < pages.Count)
  1571. return pages[Page].Height;
  1572. return 0f;
  1573. }
  1574. public int RawPaperSize(int Page)
  1575. {
  1576. if (Page < pages.Count)
  1577. return pages[Page].RawPaperSize;
  1578. return 0;
  1579. }
  1580. public float PageLMargin(int Page)
  1581. {
  1582. if (Page < pages.Count)
  1583. return pages[Page].LeftMargin;
  1584. return 0f;
  1585. }
  1586. public float PageTMargin(int Page)
  1587. {
  1588. if (Page < pages.Count)
  1589. return pages[Page].TopMargin;
  1590. return 0f;
  1591. }
  1592. public float PageRMargin(int Page)
  1593. {
  1594. if (Page < pages.Count)
  1595. return pages[Page].RightMargin;
  1596. return 0f;
  1597. }
  1598. public float PageBMargin(int Page)
  1599. {
  1600. if (Page < pages.Count)
  1601. return pages[Page].BottomMargin;
  1602. return 0f;
  1603. }
  1604. public bool Landscape(int Page)
  1605. {
  1606. if (Page < pages.Count)
  1607. return pages[Page].Landscape;
  1608. return false;
  1609. }
  1610. #endregion
  1611. public void Dispose()
  1612. {
  1613. defaultOneSizeFont.Dispose();
  1614. defaultOneSizeFont = null;
  1615. Clear();
  1616. }
  1617. public ExportMatrix()
  1618. {
  1619. defaultOneSizeFont = new Font("Arial", 1);
  1620. fontList = new List<string>();
  1621. iemObjectList = new List<ExportIEMObject>();
  1622. iemStyleList = new List<ExportIEMStyle>();
  1623. xPos = new BinaryTree();
  1624. yPos = new BinaryTree();
  1625. pages = new List<ExportIEMPage>();
  1626. maxWidth = 0;
  1627. maxHeight = 0;
  1628. minLeft = 99999;
  1629. minTop = 99999;
  1630. deltaY = 0;
  1631. inaccuracy = 0.5F;
  1632. rotatedImage = false;
  1633. plainRich = true;
  1634. fillArea = false;
  1635. cropFillArea = false;
  1636. optFrames = false;
  1637. left = 0;
  1638. printable = true;
  1639. images = true;
  1640. imageResolution = 96;
  1641. wrap = false;
  1642. brushAsBitmap = true;
  1643. bookmarks = true;
  1644. zoom = 1f;
  1645. dataOnly = false;
  1646. #if !SKIA && !MONO
  1647. fullTrust = Config.FullTrust;
  1648. #else
  1649. fullTrust = false;
  1650. #endif
  1651. pictureFormat = ImageFormat.Png;
  1652. jpegQuality = 100;
  1653. res = new MyRes("Export,Misc");
  1654. fillAsBitmap = false;
  1655. htmlMode = false;
  1656. watermarks = false;
  1657. seamless = false;
  1658. firstPage = true;
  1659. rowHeightIs = "exact";
  1660. picsCache = new Dictionary<string, MemoryStream>();
  1661. printOptimized = false;
  1662. }
  1663. }
  1664. }