ExportMatrix.cs 65 KB

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