12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820 |
- using FastReport.Barcode;
- using FastReport.Gauge.Radial;
- using FastReport.SVG;
- using FastReport.Table;
- using FastReport.Utils;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.IO;
- using System.Windows.Forms;
- namespace FastReport.Export
- {
- internal class ExportMatrix : IDisposable
- {
- private const int SVG_SCALE = 3;
- #region Private fields
- private Font defaultOneSizeFont;
- private List<ExportIEMObject> iemObjectList;
- private List<ExportIEMStyle> iemStyleList;
- private BinaryTree xPos;
- private BinaryTree yPos;
- private List<ExportIEMPage> pages;
- private int width;
- private int height;
- private float maxWidth;
- private float maxHeight;
- private float minLeft;
- private float minTop;
- private int[] matrix;
- private float deltaY;
- private bool showProgress;
- private float inaccuracy;
- private bool rotatedImage;
- private bool plainRich;
- private bool cropFillArea;
- private bool fillArea;
- private bool optFrames;
- private float left;
- private bool printable;
- private bool images;
- private int imageResolution;
- private bool wrap;
- private bool bookmarks;
- private bool brushAsBitmap;
- private List<string> fontList;
- private bool dotMatrix;
- private Report report;
- private MyRes res;
- private ExportIEMPage currentPage;
- private float zoom;
- private bool fullTrust;
- private bool dataOnly;
- private ImageFormat pictureFormat;
- private int jpegQuality;
- private bool fillAsBitmap;
- private bool htmlMode;
- private bool watermarks;
- private IDictionary picsCache;
- private string rowHeightIs;
- private bool saveRowHeight;
- private bool seamless;
- private bool firstPage;
- private bool repeatDataband;
- private bool keepRichText;
- private bool printOptimized;
- private bool autoSize;
- #endregion
- #region Properties
- public bool Seamless
- {
- get { return seamless; }
- set { seamless = value; }
- }
- public List<ExportIEMStyle> Styles
- {
- get { return iemStyleList; }
- set { iemStyleList = value; }
- }
- public List<ExportIEMPage> Pages
- {
- get { return pages; }
- }
- public bool Watermarks
- {
- get { return watermarks; }
- set { watermarks = value; }
- }
- public bool HTMLMode
- {
- get { return htmlMode; }
- set { htmlMode = value; }
- }
- public bool FillAsBitmap
- {
- get { return fillAsBitmap; }
- set { fillAsBitmap = value; }
- }
- public int JpegQuality
- {
- get { return jpegQuality; }
- set { jpegQuality = value; }
- }
- public ImageFormat ImageFormat
- {
- get { return pictureFormat; }
- set { pictureFormat = value; }
- }
- public bool FullTrust
- {
- get { return fullTrust; }
- set { fullTrust = value; }
- }
- public float Zoom
- {
- get { return zoom; }
- set { zoom = value; }
- }
- public int Width
- {
- get { return width; }
- }
- public int Height
- {
- get { return height; }
- }
- public float MaxWidth
- {
- get { return maxWidth; }
- }
- public float MaxHeight
- {
- get { return maxHeight; }
- }
- public float MinLeft
- {
- get { return minLeft; }
- }
- public float MinTop
- {
- get { return minTop; }
- }
- public bool ShowProgress
- {
- get { return showProgress; }
- set { showProgress = value; }
- }
- public float MaxCellHeight
- {
- get { return yPos.MaxDistance; }
- set { yPos.MaxDistance = value; }
- }
- public float MaxCellWidth
- {
- get { return xPos.MaxDistance; }
- set
- {
- xPos.MaxDistance = value;
- }
- }
- public int PagesCount
- {
- get { return pages.Count; }
- }
- public int StylesCount
- {
- get { return iemStyleList.Count; }
- }
- public int ObjectsCount
- {
- get { return iemObjectList.Count; }
- }
- public float Inaccuracy
- {
- get { return xPos.Inaccuracy; }
- set
- {
- xPos.Inaccuracy = value;
- yPos.Inaccuracy = value;
- }
- }
- public bool RotatedAsImage
- {
- get { return rotatedImage; }
- set { rotatedImage = value; }
- }
- public bool PlainRich
- {
- get { return plainRich; }
- set { plainRich = value; }
- }
- public bool AreaFill
- {
- get { return fillArea; }
- set { fillArea = value; }
- }
- public bool CropAreaFill
- {
- get { return cropFillArea; }
- set { cropFillArea = value; }
- }
- public bool FramesOptimization
- {
- get { return optFrames; }
- set { optFrames = value; }
- }
- public float Left
- {
- get { return left; }
- }
- public bool Printable
- {
- get { return printable; }
- set { printable = value; }
- }
- public bool Images
- {
- get { return images; }
- set { images = value; }
- }
- public int ImageResolution
- {
- get { return imageResolution; }
- set { imageResolution = value; }
- }
- public bool WrapText
- {
- get { return wrap; }
- set { wrap = value; }
- }
- public bool BrushAsBitmap
- {
- get { return brushAsBitmap; }
- set { brushAsBitmap = value; }
- }
- public bool Bookmarks
- {
- get { return bookmarks; }
- set { bookmarks = value; }
- }
- public bool DotMatrix
- {
- get { return dotMatrix; }
- set { dotMatrix = value; }
- }
- public bool DataOnly
- {
- get { return dataOnly; }
- set { dataOnly = value; }
- }
- public Report Report
- {
- get { return report; }
- set { report = value; }
- }
- public string RowHeightIs
- {
- get { return this.rowHeightIs; }
- set { this.rowHeightIs = value; }
- }
- public bool SaveRowHeight
- {
- get { return saveRowHeight; }
- set { saveRowHeight = value; }
- }
- public bool KeepRichText
- {
- get { return this.keepRichText; }
- set { this.keepRichText = value; }
- }
- public bool PrintOptimized
- {
- get { return printOptimized; }
- set { printOptimized = value; }
- }
- #endregion
- #region Private Methods
- private int AddStyleInternal(ExportIEMStyle Style)
- {
- for (int i = iemStyleList.Count - 1; i >= 0; i--)
- if (Style.Equals(iemStyleList[i]))
- return i;
- iemStyleList.Add(Style);
- return iemStyleList.Count - 1;
- }
- private int AddStyle(ReportComponentBase Obj)
- {
- ExportIEMStyle Style = new ExportIEMStyle();
- if (Obj is TextObject)
- {
- TextObject MObj = Obj as TextObject;
- Style.Font = zoom == 1 ? MObj.Font :
- new Font(MObj.Font.FontFamily, MObj.Font.Size * zoom, MObj.Font.Style, MObj.Font.Unit, MObj.Font.GdiCharSet, MObj.Font.GdiVerticalFont);
- Style.NeedDisposeFont = zoom != 1;
- Style.TextFill = MObj.TextFill;
- Style.RTL = MObj.RightToLeft;
- Style.WordWrap = MObj.WordWrap;
- Style.Fill = MObj.Fill;
- Style.Format = MObj.Format;
- Style.VAlign = MObj.VertAlign;
- if (Style.RTL)
- Style.HAlign = MObj.HorzAlign == HorzAlign.Left ?
- HorzAlign.Right : (MObj.HorzAlign == HorzAlign.Right ? HorzAlign.Left : MObj.HorzAlign);
- else
- Style.HAlign = MObj.HorzAlign;
- Style.Padding = new Padding(
- (int)Math.Round(MObj.Padding.Left * zoom),
- (int)Math.Round(MObj.Padding.Top * zoom),
- (int)Math.Round(MObj.Padding.Right * zoom),
- (int)Math.Round(MObj.Padding.Bottom * zoom));
- Style.FirstTabOffset = MObj.FirstTabOffset;
- if (zoom == 1)
- Style.Border = MObj.Border;
- else
- {
- Style.Border = MObj.Border.Clone();
- Style.Border.ZoomBorder(zoom);
- }
- Style.Angle = MObj.Angle;
- Style.LineHeight = MObj.LineHeight;
- Style.ParagraphOffset = MObj.ParagraphOffset;
- Style.FontWidthRatio = MObj.FontWidthRatio;
- Style.ForceJustify = MObj.ForceJustify;
- }
- else if (Obj is HtmlObject)
- {
- HtmlObject MObj = Obj as HtmlObject;
- Style.RTL = MObj.RightToLeft;
- Style.Fill = MObj.Fill;
- Style.Format = MObj.Format;
- Style.WordWrap = true;
- Style.TextFill = new SolidFill(Color.Black);
- Style.Padding = new Padding(
- (int)Math.Round(MObj.Padding.Left * zoom),
- (int)Math.Round(MObj.Padding.Top * zoom),
- (int)Math.Round(MObj.Padding.Right * zoom),
- (int)Math.Round(MObj.Padding.Bottom * zoom));
- Style.Border = MObj.Border.Clone();
- Style.Border.ZoomBorder(zoom);
- }
- else if (Obj is BandBase)
- {
- BandBase Band = Obj as BandBase;
- Style.Fill = Band.Fill;
- Style.Border = Band.Border;
- }
- else if (IsLine(Obj))
- {
- Style.Border = Obj.Border;
- if (Obj.Width == 0)
- Style.Border.Lines = BorderLines.Left;
- else if (Obj.Height == 0)
- Style.Border.Lines = BorderLines.Top;
- Style.Font = defaultOneSizeFont;
- }
- else if (Obj is ShapeObject)
- {
- if ((Obj as ShapeObject).Shape == ShapeKind.Rectangle &&
- Obj.Fill.IsTransparent)
- {
- Style.Border = Obj.Border;
- Style.Border.Lines = BorderLines.All;
- Style.Fill = Obj.Fill;
- }
- //do nothing
- }
- else if (Obj is PolygonObject ||
- Obj is BarcodeObject)
- {
- //do nothing
- }
- #if DOTNET_4
- else if (Obj is SVGObject)
- {
- if (Obj.Fill is SolidFill && !Obj.Fill.IsTransparent)
- Style.Fill = Obj.Fill;
- Style.Border = Obj.Border;
- Style.HAlign = HorzAlign.Center;
- Style.VAlign = VertAlign.Center;
- }
- #endif
- else
- {
- Style.Border = Obj.Border;
- // Fill in RadialGauge sets the background color of the radial gauge,
- // which fills the entire square in which this gauge is located
- if (!(Obj is RadialGauge))
- {
- Style.Fill = Obj.Fill;
- }
- Style.Font = defaultOneSizeFont;
- Style.Border.LeftLine.Width = Style.Border.LeftLine.Width > 1 ?
- Style.Border.LeftLine.Width * zoom : Style.Border.LeftLine.Width;
- Style.Border.RightLine.Width = Style.Border.RightLine.Width > 1 ?
- Style.Border.RightLine.Width * zoom : Style.Border.RightLine.Width;
- Style.Border.TopLine.Width = Style.Border.TopLine.Width > 1 ?
- Style.Border.TopLine.Width * zoom : Style.Border.TopLine.Width;
- Style.Border.BottomLine.Width = Style.Border.BottomLine.Width > 1 ?
- Style.Border.BottomLine.Width * zoom : Style.Border.BottomLine.Width;
- }
- return AddStyleInternal(Style);
- }
- private int AddInternalObject(ExportIEMObject Obj, int x, int y, int dx, int dy)
- {
- Obj.x = x;
- Obj.y = y;
- Obj.dx = dx;
- Obj.dy = dy;
- iemObjectList.Add(Obj);
- return iemObjectList.Count - 1;
- }
- private bool IsMemo(ReportComponentBase Obj)
- {
- if (Obj is TextObject)
- {
- TextObject aObj = Obj as TextObject;
- if ((aObj.Angle == 0 || !rotatedImage) && !aObj.TextOutline.Enabled)
- return true;
- }
- return false;
- }
- private bool IsLine(ReportComponentBase Obj)
- {
- return (Obj is LineObject) && ((Obj.Width == 0) || (Obj.Height == 0));
- }
- private bool IsRect(ReportComponentBase Obj)
- {
- return (Obj is ShapeObject) && ((Obj as ShapeObject).Shape == ShapeKind.Rectangle);
- }
- private void FillArea(int x, int y, int dx, int dy, int Value)
- {
- int k;
- int ddx = x + dx;
- int ddy = y + dy;
- for (int i = y; i < ddy; i++)
- {
- k = width * i;
- for (int j = x; j < ddx; j++)
- matrix[k + j] = Value;
- }
- }
- private void ReplaceRect(int ObjIndex, int x, int y, int dx, int dy, int Value)
- {
- int k;
- int ddx = x + dx;
- int ddy = y + dy;
- for (int i = y; i < ddy; i++)
- {
- k = width * i;
- for (int j = x; j < ddx; j++)
- if (matrix[k + j] == ObjIndex)
- matrix[k + j] = Value;
- }
- }
- private void FindRect(int x, int y, out int dx, out int dy)
- {
- int Obj = matrix[width * y + x];
- int px = x;
- int py = y;
- int ky;
- dx = 0;
- while (matrix[width * py + px] == Obj)
- {
- ky = width * py;
- while (matrix[ky + px] == Obj)
- px++;
- if (dx == 0)
- dx = px - x;
- else if ((px - x) < dx)
- break;
- py++;
- px = x;
- }
- dy = py - y;
- }
- private void Cut(int ObjIndex, int x, int y, int dx, int dy)
- {
- ExportIEMObject Obj = iemObjectList[ObjIndex];
- ExportIEMObject NewObject = new ExportIEMObject();
- NewObject.StyleIndex = Obj.StyleIndex;
- NewObject.Style = Obj.Style;
- NewObject.Left = xPos.Nodes[x].value;
- NewObject.Top = yPos.Nodes[y].value;
- NewObject.Width = xPos.Nodes[x + dx].value - xPos.Nodes[x].value;
- NewObject.Height = yPos.Nodes[y + dy].value - yPos.Nodes[y].value;
- NewObject.IsText = Obj.IsText;
- NewObject.IsRichText = Obj.IsRichText;
- NewObject.Metafile = Obj.Metafile;
- NewObject.PictureStream = Obj.PictureStream;
- NewObject.Base = Obj.Base;
- NewObject.Hash = Obj.Hash;
- NewObject.InlineImageCache = Obj.InlineImageCache;
- float fdy = Obj.Top + Obj.Height - NewObject.Top;
- float fdx = Obj.Left + Obj.Width - NewObject.Left;
- NewObject.ParagraphFormat = Obj.ParagraphFormat;
- NewObject.TabWidth = Obj.TabWidth;
- if ((fdy > Obj.Height / 3) && (fdx > Obj.Width / 3))
- {
- NewObject.IsText = Obj.IsText;
- NewObject.Text = Obj.Text;
- NewObject.TabPositions = Obj.TabPositions;
- NewObject.Value = Obj.Value;
- NewObject.IsNumeric = Obj.IsNumeric;
- NewObject.IsDateTime = Obj.IsDateTime;
- NewObject.TextRenderType = Obj.TextRenderType;
- NewObject.OriginalText = Obj.OriginalText;
- Obj.Text = String.Empty;
- Obj.OriginalText = null;
- Obj.Value = null;
- Obj.IsText = true;
- }
- int NewIndex = AddInternalObject(NewObject, x, y, dx, dy);
- ReplaceRect(ObjIndex, x, y, dx, dy, NewIndex);
- CloneFrames(ObjIndex, NewIndex);
- iemObjectList[NewIndex].Exist = true;
- }
- private void CloneFrames(int Obj1, int Obj2)
- {
- ExportIEMObject FOld, FNew;
- BorderLines FrameTyp;
- FOld = iemObjectList[Obj1];
- FNew = iemObjectList[Obj2];
- if ((FOld.Style != null) && (FNew.Style != null))
- {
- FrameTyp = BorderLines.None;
- if (((BorderLines.Top & FOld.Style.Border.Lines) != 0) &&
- (Math.Abs(FOld.Top - FNew.Top) <= inaccuracy))
- FrameTyp |= BorderLines.Top;
- if (((BorderLines.Left & FOld.Style.Border.Lines) != 0) &&
- (Math.Abs(FOld.Left - FNew.Left) <= inaccuracy))
- FrameTyp |= BorderLines.Left;
- if (((BorderLines.Bottom & FOld.Style.Border.Lines) != 0) &&
- (Math.Abs((FOld.Top + FOld.Height) - (FNew.Top + FNew.Height)) <= inaccuracy))
- FrameTyp |= BorderLines.Bottom;
- if (((BorderLines.Right & FOld.Style.Border.Lines) != 0) &&
- (Math.Abs((FOld.Left + FOld.Width) - (FNew.Left + FNew.Width)) <= inaccuracy))
- FrameTyp |= BorderLines.Right;
- if (FrameTyp != FNew.Style.Border.Lines)
- {
- ExportIEMStyle NewStyle = new ExportIEMStyle();
- NewStyle.Assign(FOld.Style);
- NewStyle.Border.Lines = FrameTyp;
- FNew.StyleIndex = AddStyleInternal(NewStyle);
- FNew.Style = iemStyleList[FNew.StyleIndex];
- }
- }
- }
- private void Render()
- {
- int i, k, Old;
- ExportIEMObject Obj;
- ExportIEMStyle Style;
- FillBase OldColor;
- xPos.Close();
- yPos.Close();
- width = xPos.Count;
- height = yPos.Count;
- k = width * height;
- matrix = new int[k];
- for (i = 0; i < k; i++)
- matrix[i] = -1;
- for (i = 0; i < iemObjectList.Count; i++)
- {
- Obj = iemObjectList[i];
- int xPos0 = this.xPos.IndexOf(Obj.Left);
- if (xPos0 != -1)
- {
- iemObjectList[i].x = xPos0;
- Obj.Left = this.xPos.Nodes[xPos0].value;
- k = this.xPos.IndexOf(Obj.Left + Obj.Width);
- iemObjectList[i].dx = k - xPos0;
- }
- int yPos0 = this.yPos.IndexOf(Obj.Top);
- if (yPos0 != -1)
- {
- iemObjectList[i].y = yPos0;
- Obj.Top = this.yPos.Nodes[yPos0].value;
- k = this.yPos.IndexOf(Obj.Top + Obj.Height);
- iemObjectList[i].dy = k - yPos0;
- }
- if ((Obj.Style != null) && Obj.Style.FillColor.A == 0)
- {
- Old = matrix[width * Obj.y + Obj.x];
- if (Old != -1 && iemObjectList[Old].Style != null)
- {
- OldColor = iemObjectList[Old].Style.Fill;
- if ((ExportUtils.GetColorFromFill(OldColor) != Obj.Style.FillColor) &&
- (ExportUtils.GetColorFromFill(OldColor) != Obj.Style.TextColor))
- {
- Style = new ExportIEMStyle();
- Style.Assign(Obj.Style);
- Style.Fill = OldColor;
- Obj.StyleIndex = AddStyleInternal(Style);
- Obj.Style = iemStyleList[Obj.StyleIndex];
- }
- }
- else if (Obj.Style.FillColor != Color.Transparent)
- {
- Style = new ExportIEMStyle();
- Style.Assign(Obj.Style);
- Style.Fill = new SolidFill(Color.Transparent);
- Obj.StyleIndex = AddStyleInternal(Style);
- Obj.Style = iemStyleList[Obj.StyleIndex];
- }
- }
- int bottomIndex = matrix[width * Obj.y + Obj.x];
- if (bottomIndex != -1)
- {
- ExportIEMObject bottomObject = iemObjectList[bottomIndex];
- if (Obj.Style != null && bottomObject.Style != null)
- {
- CheckFrameFromBottmObject(Obj, bottomObject,
- Obj.y + Obj.dy, bottomObject.y + bottomObject.dy, BorderLines.Bottom);
- CheckFrameFromBottmObject(Obj, bottomObject,
- Obj.x + Obj.dx, bottomObject.x + bottomObject.dx, BorderLines.Right);
- CheckFrameFromBottmObject(Obj, bottomObject,
- Obj.x, bottomObject.x, BorderLines.Left);
- CheckFrameFromBottmObject(Obj, bottomObject,
- Obj.y, bottomObject.y, BorderLines.Top);
- }
- }
- if (!(Obj.IsBand && Obj.Style != null &&
- ((Obj.Style.FillColor == Color.White) || (Obj.Style.FillColor.A == 0)) &&
- (Obj.Style.Border.Lines == BorderLines.None)))
- FillArea(Obj.x, Obj.y, Obj.dx, Obj.dy, i);
- if (i % 1000 == 0)
- Config.DoEvent();
- }
- }
- private void CheckFrameFromBottmObject(ExportIEMObject Obj, ExportIEMObject bottomObject, int pos1, int pos2, BorderLines line)
- {
- if (pos1 == pos2 &&
- ((line & Obj.Style.Border.Lines) == 0) &&
- ((line & bottomObject.Style.Border.Lines) != 0))
- {
- ExportIEMStyle Style = new ExportIEMStyle();
- Style.Assign(Obj.Style);
- Style.Border.Lines = Obj.Style.Border.Lines | line;
- if (line == BorderLines.Bottom)
- Style.Border.BottomLine = bottomObject.Style.Border.BottomLine;
- else if (line == BorderLines.Top)
- Style.Border.TopLine = bottomObject.Style.Border.TopLine;
- else if (line == BorderLines.Left)
- Style.Border.LeftLine = bottomObject.Style.Border.LeftLine;
- else if (line == BorderLines.Right)
- Style.Border.RightLine = bottomObject.Style.Border.RightLine;
- Obj.StyleIndex = AddStyleInternal(Style);
- Obj.Style = iemStyleList[Obj.StyleIndex];
- }
- }
- private void Analyze()
- {
- for (int i = 0; i < height - 1; i++)
- {
- int ki = width * i;
- for (int j = 0; j < width - 1; j++)
- {
- int k = matrix[ki + j];
- if (k != -1)
- {
- ExportIEMObject obj = iemObjectList[k];
- if (!obj.Exist)
- {
- int dx, dy;
- FindRect(j, i, out dx, out dy);
- if (j + dx >= xPos.Count)
- dx = xPos.Count - j - 1;
- if (i + dy >= yPos.Count)
- dy = yPos.Count - i - 1;
- if ((obj.x != j) || (obj.y != i) || (obj.dx != dx) || (obj.dy != dy))
- {
- if (!obj.Exist)
- Cut(k, j, i, dx, dy);
- else
- obj.Exist = true;
- }
- else
- {
- obj.Exist = true;
- }
- }
- }
- }
- if (i % 1000 == 0)
- Config.DoEvent();
- }
- }
- private void OptimizeFrames()
- {
- int x, y;
- ExportIEMObject Obj, PrevObj;
- BorderLines CurrentLines;
- ExportIEMStyle Style;
- for (y = 0; y < Height; y++)
- {
- for (x = 0; x < Width; x++)
- {
- Obj = GetObject(x, y);
- if (Obj == null)
- continue;
- if (Obj.Style != null && Obj.Style.Border.Lines != BorderLines.None)
- {
- CurrentLines = Obj.Style.Border.Lines;
- if (((BorderLines.Top & CurrentLines) > 0) && (y > 0))
- {
- PrevObj = GetObject(x, y - 1);
- if ((PrevObj != null) && (PrevObj != Obj) && (PrevObj.Style != null)
- && ((BorderLines.Bottom & PrevObj.Style.Border.Lines) > 0)
- && (PrevObj.Style.Border.BottomLine.Width == Obj.Style.Border.TopLine.Width)
- && (PrevObj.Style.Border.BottomLine.Color == Obj.Style.Border.TopLine.Color)
- )
- {
- CurrentLines = CurrentLines & ~BorderLines.Top;
- Style = new ExportIEMStyle();
- Style.Assign(Obj.Style);
- Style.Border.Lines = CurrentLines;
- Obj.StyleIndex = AddStyleInternal(Style);
- Obj.Style = iemStyleList[Obj.StyleIndex];
- }
- }
- if (((BorderLines.Left & CurrentLines) > 0) && (x > 0))
- {
- PrevObj = GetObject(x - 1, y);
- if ((PrevObj != null) && (PrevObj != Obj) && (PrevObj.Style != null)
- && ((BorderLines.Right & PrevObj.Style.Border.Lines) > 0)
- && (PrevObj.Style.Border.RightLine.Width == Obj.Style.Border.LeftLine.Width)
- && (PrevObj.Style.Border.RightLine.Color == Obj.Style.Border.LeftLine.Color)
- )
- {
- CurrentLines = CurrentLines & ~BorderLines.Left;
- Style = new ExportIEMStyle();
- Style.Assign(Obj.Style);
- Style.Border.Lines = CurrentLines;
- Obj.StyleIndex = AddStyleInternal(Style);
- Obj.Style = iemStyleList[Obj.StyleIndex];
- }
- }
- }
- }
- if (y % 1000 == 0)
- Config.DoEvent();
- }
- }
- private void AddSetObjectPos(ReportComponentBase Obj, ref ExportIEMObject FObj)
- {
- float Left = Obj.AbsLeft;
- float Top = Obj.AbsTop;
- float Width = Obj.Width;
- float Height = Obj.Height;
- if (Left >= 0)
- FObj.Left = Width > 0 ? Left * zoom : (Left + Width) * zoom;
- else
- FObj.Left = 0;
- if (Top >= 0)
- FObj.Top = Height > 0 ? deltaY + Top * zoom : deltaY + (Top + Height) * zoom;
- else
- FObj.Top = deltaY;
- if (IsLine(Obj))
- {
- FObj.Width = Math.Abs(Width) > 0 ? Math.Abs(Width) * zoom : Obj.Border.Width * zoom;
- FObj.Height = Math.Abs(Height) > 0 ? Math.Abs(Height) * zoom : Obj.Border.Width * zoom;
- }
- else
- {
- FObj.Width = Math.Abs(Width) * zoom;
- FObj.Height = Math.Abs(Height) * zoom;
- }
- if ((FObj.Left + FObj.Width) > (currentPage.Width - currentPage.LeftMargin - currentPage.RightMargin) * Units.Millimeters)
- FObj.Width = (currentPage.Width - currentPage.LeftMargin - currentPage.RightMargin) * Units.Millimeters - FObj.Left;
- if ((FObj.Top + FObj.Height) > maxHeight)
- maxHeight = FObj.Top + FObj.Height;
- if ((FObj.Left + FObj.Width) > maxWidth)
- maxWidth = FObj.Left + FObj.Width;
- if (FObj.Left < minLeft)
- minLeft = FObj.Left;
- if (FObj.Top < minTop)
- minTop = FObj.Top;
- if ((FObj.Left < left) || (left == 0))
- left = FObj.Left;
- float bottom = FObj.Top + FObj.Height;
- xPos.Add(FObj.Left);
- xPos.Add(FObj.Left + FObj.Width);
- yPos.Add(FObj.Top);
- yPos.Add(bottom);
- AddInternalObject(FObj, 0, 0, 1, 1);
- }
- #endregion
- #region Public Methods
- public ExportIEMStyle StyleById(int Index)
- {
- return iemStyleList[Index];
- }
- public int Cell(int x, int y)
- {
- if ((x < width) && (y < height) && (x >= 0) && (y >= 0))
- return matrix[width * y + x];
- return -1;
- }
- public ExportIEMObject ObjectById(int ObjIndex)
- {
- if (ObjIndex < iemObjectList.Count)
- return iemObjectList[ObjIndex];
- return null;
- }
- public bool IsYPosByIdNull(int PosIndex)
- {
- return yPos.Nodes[PosIndex] == null;
- }
- public float XPosById(int PosIndex)
- {
- return xPos.Nodes[PosIndex].value;
- }
- public float YPosById(int PosIndex)
- {
- return yPos.Nodes[PosIndex].value;
- }
- public ExportIEMObject GetObject(int x, int y)
- {
- int i = matrix[width * y + x];
- if (i == -1)
- return null;
- return iemObjectList[i];
- }
- public void Clear()
- {
- foreach (KeyValuePair<string, MemoryStream> cacheItem in (Dictionary<string, MemoryStream>)picsCache)
- cacheItem.Value.Dispose();
- picsCache.Clear();
- iemObjectList.Clear();
- xPos.Clear();
- yPos.Clear();
- pages.Clear();
- foreach (ExportIEMStyle style in Styles)
- {
- if (style.NeedDisposeFont)// !style.Font.Equals(DrawUtils.DefaultFont))
- {
- style.Font.Dispose();
- style.Font = null;
- }
- }
- iemStyleList.Clear();
- fontList.Clear();
- deltaY = 0;
- firstPage = true;
- if (PagesCount > 100)
- GC.Collect(2);
- }
- public void AddBandObject(BandBase Obj)
- {
- if (Obj.Fill is TextureFill)
- return;
- if (Obj.HasFill || Obj.HasBorder)
- {
- ExportIEMObject FObj = new ExportIEMObject();
- FObj.StyleIndex = AddStyle(Obj);
- if (FObj.StyleIndex != -1)
- FObj.Style = iemStyleList[FObj.StyleIndex];
- FObj.IsText = true;
- FObj.IsBand = true;
- AddSetObjectPos(Obj, ref FObj);
- }
- }
- private void AddLineObject(ReportComponentBase Obj)
- {
- ExportIEMObject FObj = new ExportIEMObject();
- FObj.StyleIndex = AddStyle(Obj);
- if (FObj.StyleIndex != -1)
- FObj.Style = iemStyleList[FObj.StyleIndex];
- FObj.IsText = true;
- AddSetObjectPos(Obj, ref FObj);
- }
- private Size GetImageSize(ExportIEMObject FObj, ReportComponentBase Obj)
- {
- float dx = FObj.Width;
- float dy = FObj.Height;
- if (htmlMode)
- {
- if ((Obj.Border.Lines & BorderLines.Left) != 0)
- dx -= Obj.Border.LeftLine.Width * zoom;
- if ((Obj.Border.Lines & BorderLines.Right) != 0)
- dx -= Obj.Border.RightLine.Width * zoom;
- if ((Obj.Border.Lines & BorderLines.Top) != 0)
- dy -= Obj.Border.TopLine.Width * zoom;
- if ((Obj.Border.Lines & BorderLines.Bottom) != 0)
- dy -= Obj.Border.BottomLine.Width * zoom;
- }
- dx = (dx >= 1 ? dx : 1);
- dy = (dy >= 1 ? dy : 1);
- int imageZoom = printOptimized ? 3 : 1;
- return new Size((int)Math.Round(dx * imageZoom), (int)Math.Round(dy * imageZoom));
- }
- private void DrawImage(Graphics g, ReportComponentBase Obj)
- {
- using (GraphicCache cache = new GraphicCache())
- {
- if (Obj is TextObjectBase)
- g.Clear(Color.Transparent);
- float Left = Obj.Width >= 0 ? Obj.AbsLeft : Obj.AbsLeft + Obj.Width;
- float Top = Obj.Height >= 0 ? Obj.AbsTop : Obj.AbsTop + Obj.Height;
- int imageZoom = printOptimized && pictureFormat != ImageFormat.Emf ? SVG_SCALE : 1;
- if (htmlMode)
- {
- float dx = (Obj.Border.Lines & BorderLines.Left) != 0 ? Obj.Border.LeftLine.Width : 0;
- float dy = (Obj.Border.Lines & BorderLines.Top) != 0 ? Obj.Border.TopLine.Width : 0;
- g.TranslateTransform((-Left - dx) * zoom * imageZoom, (-Top - dy) * zoom * imageZoom);
- }
- else
- g.TranslateTransform(-Left * zoom * imageZoom, -Top * zoom * imageZoom);
- BorderLines oldLines = Obj.Border.Lines;
- Obj.Border.Lines = BorderLines.None;
- Obj.Draw(new FRPaintEventArgs(g, zoom * imageZoom, zoom * imageZoom, cache));
- Obj.Border.Lines = oldLines;
- }
- }
- private Hyperlink GetHyperlink(Hyperlink h)
- {
- if (string.IsNullOrEmpty(h.Value))
- return null;
- h.SetParent(null);
- return h;
- }
- public void AddPictureObject(ReportComponentBase Obj)
- {
- if (IsVisible(Obj))
- {
- ExportIEMObject FObj = new ExportIEMObject();
- FObj.Hyperlink = GetHyperlink(Obj.Hyperlink);
- FObj.Bookmark = Obj.Bookmark;
- Padding oldPadding = new Padding();
- if (Obj is TextObject)
- {
- oldPadding = (Obj as TextObject).Padding;
- (Obj as TextObject).Padding = new Padding();
- }
- FObj.StyleIndex = AddStyle(Obj);
- if (Obj is TextObject)
- (Obj as TextObject).Padding = oldPadding;
- if (FObj.StyleIndex != -1)
- FObj.Style = iemStyleList[FObj.StyleIndex];
- FObj.IsText = false;
- AddSetObjectPos(Obj, ref FObj);
- FObj.PictureStream = new MemoryStream();
- using (Bitmap bmp = new Bitmap(1, 1))
- {
- using (Graphics g = Graphics.FromImage(bmp))
- {
- IntPtr hdc = g.GetHdc();
- try
- {
- FObj.Metafile = new Metafile(FObj.PictureStream, hdc,
- new Rectangle(new Point(0, 0), GetImageSize(FObj, Obj)), MetafileFrameUnit.Pixel);
- }
- finally
- {
- g.ReleaseHdc(hdc);
- }
- }
- }
- if (pictureFormat != ImageFormat.Emf)
- {
- Size imageSize = GetImageSize(FObj, Obj);
- using (System.Drawing.Image image = new Bitmap(imageSize.Width, imageSize.Height))
- {
- using (Graphics g = Graphics.FromImage(image))
- {
- DrawImage(g, Obj);
- }
- if (PrintOptimized)
- {
- using (Bitmap b = new Bitmap(
- (int)Math.Round((decimal)(imageSize.Width / SVG_SCALE)),
- (int)Math.Round((decimal)(imageSize.Height / SVG_SCALE))
- ))
- {
- using (Graphics g = Graphics.FromImage(b))
- {
- g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
- g.DrawImage(
- image,
- 0,
- 0,
- (int)Math.Round((decimal)(imageSize.Width / SVG_SCALE)),
- (int)Math.Round((decimal)(imageSize.Height / SVG_SCALE))
- );
- }
- if (pictureFormat == ImageFormat.Jpeg)
- ExportUtils.SaveJpeg(b, FObj.PictureStream, jpegQuality);
- else
- b.Save(FObj.PictureStream, pictureFormat);
- }
- }
- else
- {
- if (pictureFormat == ImageFormat.Jpeg)
- ExportUtils.SaveJpeg(image, FObj.PictureStream, jpegQuality);
- else
- image.Save(FObj.PictureStream, pictureFormat);
- image.Dispose();
- }
- }
- }
- else
- using (Graphics g = Graphics.FromImage(FObj.Metafile))
- {
- DrawImage(g, Obj);
- }
- FObj.PictureStream.Position = 0;
- CheckPicsCache(FObj);
- AddShadow(Obj);
- }
- }
- public void AddPictureObject_Safe(ReportComponentBase Obj)
- {
- if (IsVisible(Obj))
- {
- ExportIEMObject FObj = new ExportIEMObject();
- FObj.Hyperlink = GetHyperlink(Obj.Hyperlink);
- FObj.Bookmark = Obj.Bookmark;
- Padding oldPadding = new Padding();
- if (Obj is TextObject)
- {
- oldPadding = (Obj as TextObject).Padding;
- (Obj as TextObject).Padding = new Padding();
- }
- FObj.StyleIndex = AddStyle(Obj);
- if (Obj is TextObject)
- (Obj as TextObject).Padding = oldPadding;
- if (FObj.StyleIndex != -1)
- FObj.Style = iemStyleList[FObj.StyleIndex];
- FObj.IsText = false;
- AddSetObjectPos(Obj, ref FObj);
- FObj.PictureStream = new MemoryStream();
- float zoom = imageResolution / 96f;
- Size imageSize = GetImageSize(FObj, Obj);
- using (System.Drawing.Image image =
- new Bitmap(
- (int)Math.Round(imageSize.Width * zoom),
- (int)Math.Round(imageSize.Height * zoom)
- ))
- {
- using (Graphics g = Graphics.FromImage(image))
- {
- g.ScaleTransform(zoom, zoom);
- DrawImage(g, Obj);
- }
- if (printOptimized)
- {
- using (Bitmap b = new Bitmap(
- (int)Math.Round((decimal)(imageSize.Width / SVG_SCALE * zoom)),
- (int)Math.Round((decimal)(imageSize.Height / SVG_SCALE * zoom))
- ))
- {
- using (Graphics g = Graphics.FromImage(b))
- {
- g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
- g.DrawImage(
- image,
- 0,
- 0,
- (int)Math.Round((decimal)(imageSize.Width / SVG_SCALE * zoom)),
- (int)Math.Round((decimal)(imageSize.Height / SVG_SCALE * zoom))
- );
- image.Dispose();
- }
- if (pictureFormat == ImageFormat.Jpeg)
- ExportUtils.SaveJpeg(b, FObj.PictureStream, jpegQuality);
- else
- b.Save(FObj.PictureStream, pictureFormat);
- }
- }
- else
- {
- if (pictureFormat == ImageFormat.Jpeg)
- ExportUtils.SaveJpeg(image, FObj.PictureStream, jpegQuality);
- else
- image.Save(FObj.PictureStream, pictureFormat);
- }
- }
- FObj.PictureStream.Position = 0;
- CheckPicsCache(FObj);
- AddShadow(Obj);
- }
- }
- #if DOTNET_4
- private void AddSVG(SVGObject Obj)
- {
- if (IsVisible(Obj))
- {
- ExportIEMObject FObj = new ExportIEMObject();
- FObj.StyleIndex = AddStyle(Obj);
- if (FObj.StyleIndex != -1)
- FObj.Style = iemStyleList[FObj.StyleIndex];
- //FObj.Text = Obj.Text;
- FObj.IsNumeric = false;
- FObj.TextRenderType = TextRenderType.Default;
- FObj.Hyperlink = GetHyperlink(Obj.Hyperlink);
- FObj.Bookmark = Obj.Bookmark;
- FObj.IsText = false;
- FObj.IsRichText = false;
- FObj.IsSvg = true;
- AddSetObjectPos(Obj, ref FObj);
- FObj.PictureStream = new MemoryStream();
- if (Obj.Grayscale)
- Obj.SVGGrayscale.Write(FObj.PictureStream);
- else
- Obj.SvgDocument.Write(FObj.PictureStream);
- CheckPicsCache(FObj);
- }
- }
- #endif
- private void AddHtml(HtmlObject Obj)
- {
- if (IsVisible(Obj))
- {
- ExportIEMObject FObj = new ExportIEMObject();
- FObj.StyleIndex = AddStyle(Obj);
- if (FObj.StyleIndex != -1)
- FObj.Style = iemStyleList[FObj.StyleIndex];
- FObj.Text = Obj.Text;
- FObj.IsNumeric = false;
- FObj.TextRenderType = TextRenderType.HtmlTags;
- FObj.Hyperlink = GetHyperlink(Obj.Hyperlink);
- FObj.Bookmark = Obj.Bookmark;
- FObj.IsText = false;
- FObj.IsRichText = false;
- AddSetObjectPos(Obj, ref FObj);
- AddShadow(Obj);
- if (fillAsBitmap && !(FObj.Style.Fill is SolidFill))
- {
- float dx = FObj.Width;
- float dy = FObj.Height;
- dx = (dx >= 1 ? dx : 1);
- dy = (dy >= 1 ? dy : 1);
- System.Drawing.Image image = new Bitmap((int)dx, (int)dy);
- using (Graphics g = Graphics.FromImage(image))
- {
- g.Clear(Color.Transparent);
- g.TranslateTransform(-Obj.AbsLeft * zoom, -Obj.AbsTop * zoom);
- BorderLines oldLines = Obj.Border.Lines;
- Obj.Border.Lines = BorderLines.None;
- string oldText = Obj.Text;
- Obj.Text = String.Empty;
- Obj.Draw(new FRPaintEventArgs(g, zoom, zoom, Report.GraphicCache));
- Obj.Text = oldText;
- Obj.Border.Lines = oldLines;
- FObj.PictureStream = new MemoryStream();
- image.Save(FObj.PictureStream, pictureFormat);
- CheckPicsCache(FObj);
- }
- }
- }
- }
- public void AddTextObject(TextObject Obj)
- {
- AddTextObject(Obj, false);
- }
- public void AddTextObject(TextObject Obj, bool isHeader)
- {
- if (IsVisible(Obj))
- {
- ExportIEMObject FObj = new ExportIEMObject();
- FObj.StyleIndex = AddStyle(Obj);
- if (FObj.StyleIndex != -1)
- FObj.Style = iemStyleList[FObj.StyleIndex];
- FObj.Text = Obj.Text;
- FObj.AutoSize = autoSize;
- FObj.TabPositions = Obj.TabPositions.Count > 0 ? Obj.TabPositions : null;
- if (isHeader && Obj.OriginalComponent != null)
- FObj.OriginalText = (Obj.OriginalComponent as TextObject).Text;
- FObj.TabWidth = Obj.TabWidth;
- if (Obj.TextRenderType == TextRenderType.HtmlParagraph)
- {
- if (Obj.ParagraphFormat != null)
- FObj.ParagraphFormat = Obj.ParagraphFormat.MultipleScale(1);
- FObj.InlineImageCache = Obj.InlineImageCache;
- }
- FObj.IsDateTime = ExportUtils.ParseTextToDateTime(FObj.Text, FObj.Style.Format, out DateTime date);
- if (FObj.IsDateTime)
- FObj.Value = date;
- else
- {
- FObj.IsPercent = ExportUtils.ParseTextToPercent(FObj.Text, FObj.Style.Format, out decimal percent);
- if (FObj.IsPercent)
- FObj.Value = percent;
- else
- {
- FObj.IsNumeric = ExportUtils.ParseTextToDecimal(FObj.Text, FObj.Style.Format, out decimal numeric);
- if (FObj.IsNumeric)
- FObj.Value = numeric;
- }
- }
- FObj.TextRenderType = Obj.TextRenderType;
- FObj.Hyperlink = GetHyperlink(Obj.Hyperlink);
- FObj.Bookmark = Obj.Bookmark;
- FObj.IsText = true;
- FObj.IsRichText = false;
- AddSetObjectPos(Obj, ref FObj);
- AddShadow(Obj);
- if (fillAsBitmap && !(FObj.Style.Fill is SolidFill))
- {
- float dx = FObj.Width;
- float dy = FObj.Height;
- dx = (dx >= 1 ? dx : 1);
- dy = (dy >= 1 ? dy : 1);
- System.Drawing.Image image = new Bitmap((int)dx, (int)dy);
- using (Graphics g = Graphics.FromImage(image))
- {
- g.Clear(Color.Transparent);
- g.TranslateTransform(-Obj.AbsLeft * zoom, -Obj.AbsTop * zoom);
- BorderLines oldLines = Obj.Border.Lines;
- Obj.Border.Lines = BorderLines.None;
- string oldText = Obj.Text;
- Obj.Text = String.Empty;
- Obj.Draw(new FRPaintEventArgs(g, zoom, zoom, Report.GraphicCache));
- Obj.Text = oldText;
- Obj.Border.Lines = oldLines;
- FObj.PictureStream = new MemoryStream();
- image.Save(FObj.PictureStream, pictureFormat);
- CheckPicsCache(FObj);
- }
- }
- }
- }
- private bool IsVisible(ReportComponentBase Obj)
- {
- return !((Obj.AbsLeft + Obj.Width) < 0 ||
- (Obj.AbsTop + Obj.Height) < 0 ||
- (Obj.AbsLeft > (currentPage.Width / zoom * Units.Millimeters)) ||
- (Obj.AbsTop > (currentPage.Height / zoom * Units.Millimeters)));
- }
- private void AddShadow(ReportComponentBase Obj)
- {
- if (Obj.Border.Shadow)
- {
- using (TextObject shadow = new TextObject())
- {
- shadow.Left = Obj.AbsLeft + Obj.Width;
- shadow.Width = Obj.Border.ShadowWidth;
- shadow.Top = Obj.AbsTop + Obj.Border.ShadowWidth;
- shadow.Height = Obj.Height;
- shadow.Fill = new SolidFill(Obj.Border.ShadowColor);
- AddTextObject(shadow);
- }
- using (TextObject shadow = new TextObject())
- {
- shadow.Left = Obj.AbsLeft + Obj.Border.ShadowWidth;
- shadow.Width = Obj.Width - Obj.Border.ShadowWidth;
- shadow.Top = Obj.AbsTop + Obj.Height;
- shadow.Height = Obj.Border.ShadowWidth;
- shadow.Fill = new SolidFill(Obj.Border.ShadowColor);
- AddTextObject(shadow);
- }
- }
- }
- public void AddPageBegin(ReportPage page)
- {
- currentPage = new ExportIEMPage();
- currentPage.Landscape = page.Landscape;
- currentPage.Width = ExportUtils.GetPageWidth(page) * zoom;
- currentPage.Height = ExportUtils.GetPageHeight(page) * zoom;
- currentPage.RawPaperSize = page.RawPaperSize;
- currentPage.LeftMargin = page.LeftMargin * zoom;
- currentPage.TopMargin = page.TopMargin * zoom;
- currentPage.RightMargin = page.RightMargin * zoom;
- currentPage.BottomMargin = page.BottomMargin * zoom;
- repeatDataband = false;
- }
- public void AddBand(BandBase band, object sender)
- {
- AddBand(band, sender, false);
- }
- public void AddBand(BandBase band, object sender, bool isHeader)
- {
- if (dataOnly && !(band is DataBand))
- return;
- if (seamless && (((band is PageHeaderBand) && !firstPage) || (band is PageFooterBand)))
- return;
- if (!(band.Fill is TextureFill))
- AddBandObject(band);
- else
- if (images)
- {
- if (fullTrust)
- AddPictureObject(band);
- else
- AddPictureObject_Safe(band);
- }
- foreach (Base c in band.ForEachAllConvectedObjects(sender))
- {
- if (c is ReportComponentBase && (c as ReportComponentBase).Exportable)
- {
- ReportComponentBase obj = c as ReportComponentBase;
- if (obj is CellularTextObject)
- obj = (obj as CellularTextObject).GetTable();
- if (dataOnly && (obj.Parent == null || !(obj.Parent is DataBand)))
- continue;
- if (seamless &&
- (
- (obj.Parent is PageFooterBand) || (obj is PageFooterBand) ||
- (((obj.Parent is PageHeaderBand) || (obj is PageHeaderBand)) && !firstPage)
- )
- )
- continue;
- if (obj is TableCell)
- continue;
- else if (obj is TableBase)
- {
- AddTableObject(obj as TableBase);
- repeatDataband = true;
- }
- else if (IsMemo(obj))
- AddTextObject(obj as TextObject, isHeader);
- else if (obj is BandBase)
- {
- if (!repeatDataband)
- AddBandObject(obj as BandBase);
- repeatDataband = false;
- }
- else if (IsLine(obj) ||
- (IsRect(obj) && obj.Fill.IsTransparent))
- AddLineObject(obj);
- else if ((obj is HtmlObject) && htmlMode)
- AddHtml(obj as HtmlObject);
- else if (keepRichText && (obj is RichObject))
- AddRich(obj as RichObject);
- else if (!((obj is HtmlObject) && !htmlMode))
- {
- if (images)
- {
- #if DOTNET_4
- if ((obj is SVGObject) && htmlMode)
- AddSVG(obj as SVGObject);
- else
- #endif
- {
- if (fullTrust)
- AddPictureObject(obj);
- else
- AddPictureObject_Safe(obj);
- }
- }
- }
- }
- }
- }
- private void AddRich(RichObject richObject)
- {
- if (IsVisible(richObject))
- {
- ExportIEMObject FObj = new ExportIEMObject();
- FObj.StyleIndex = AddStyle(richObject);
- if (FObj.StyleIndex != -1)
- FObj.Style = iemStyleList[FObj.StyleIndex];
- FObj.Text = richObject.Text;
- #if CHECK_LATER
- FObj.TabWidth = richObject.TabWidth;
- if (Obj.ParagraphFormat != null)
- FObj.ParagraphFormat = Obj.ParagraphFormat.MultipleScale(1);
- if (Obj.TextRenderType == TextRenderType.HtmlParagraph)
- FObj.InlineImageCache = Obj.InlineImageCache;
- DateTime date;
- #endif
- FObj.IsDateTime = false;
- FObj.IsPercent = false;
- FObj.IsNumeric = false;
- FObj.Value = null;
- FObj.TextRenderType = TextRenderType.Default;
- FObj.Hyperlink = GetHyperlink(richObject.Hyperlink);
- FObj.Bookmark = richObject.Bookmark;
- FObj.IsText = true;
- FObj.IsRichText = true;
- #if CHECK_LATER
- if (wrap)
- FObj.WrappedText = WrapTextObject(richObject);
- #endif
- AddSetObjectPos(richObject, ref FObj);
- AddShadow(richObject);
- if (fillAsBitmap && !(FObj.Style.Fill is SolidFill))
- {
- float dx = FObj.Width;
- float dy = FObj.Height;
- dx = (dx >= 1 ? dx : 1);
- dy = (dy >= 1 ? dy : 1);
- System.Drawing.Image image = new Bitmap((int)dx, (int)dy);
- using (Graphics g = Graphics.FromImage(image))
- {
- g.Clear(Color.Transparent);
- g.TranslateTransform(-richObject.AbsLeft * zoom, -richObject.AbsTop * zoom);
- BorderLines oldLines = richObject.Border.Lines;
- richObject.Border.Lines = BorderLines.None;
- string oldText = richObject.Text;
- richObject.Text = String.Empty;
- richObject.Draw(new FRPaintEventArgs(g, zoom, zoom, Report.GraphicCache));
- richObject.Text = oldText;
- richObject.Border.Lines = oldLines;
- FObj.PictureStream = new MemoryStream();
- image.Save(FObj.PictureStream, pictureFormat);
- CheckPicsCache(FObj);
- }
- }
- }
- }
- public void AddTableObject(TableBase table)
- {
- if (table != null && table.ColumnCount > 0 && table.RowCount > 0)
- {
- table.EmulateOuterBorder();
- using (TextObject tableback = new TextObject())
- {
- tableback.Border = table.Border;
- tableback.Fill = table.Fill;
- tableback.Left = table.AbsLeft;
- tableback.Top = table.AbsTop;
- float tableWidth = 0;
- for (int i = 0; i < table.ColumnCount; i++)
- tableWidth += table.Columns[i].Width;// table[i, 0].Width;
- float tableHeight = 0;
- for (int i = 0; i < table.RowCount; i++)
- tableHeight += table.Rows[i].Height;
- tableback.Width = tableWidth;// (tableWidth < table.Width) ? tableWidth : table.Width;
- tableback.Height = tableHeight;
- AddTextObject(tableback);
- }
- float y = 0;
- for (int i = 0; i < table.RowCount; i++)
- {
- autoSize = table.Rows[i].AutoSize;
- float x = 0;
- for (int j = 0; j < table.ColumnCount; j++)
- {
- if (!table.IsInsideSpan(table[j, i]))
- {
- TableCell textcell = table[j, i];
- textcell.Left = x;
- textcell.Top = y;
- if (IsMemo(textcell))
- AddTextObject(textcell as TextObject);
- else if (images)
- if (fullTrust)
- AddPictureObject(textcell);
- else
- AddPictureObject_Safe(textcell);
- }
- x += (table.Columns[j]).Width;
- }
- y += (table.Rows[i]).Height;
- }
- }
- }
- public void AddPageEnd(ReportPage page)
- {
- if (watermarks)
- AddWatermark(page, currentPage);
- deltaY = maxHeight;
- currentPage.Value = maxHeight;
- pages.Add(currentPage);
- firstPage = false;
- //it is necessary to control the number of rows in the matrix
- height = yPos.Count - 1;
- /*ObjectCollection allObjects = page.AllObjects;
- for (int i = 0; i < allObjects.Count; i++)
- {
- ReportComponentBase c = allObjects[i] as ReportComponentBase;
- if (c != null)
- {
- c.Dispose();
- c = null;
- }
- }*/
- }
- private void AddWatermark(ReportPage page, ExportIEMPage matrixPage)
- {
- if (page.Watermark.Enabled)
- {
- int dx = (int)(ExportUtils.GetPageWidth(page) * Units.Millimeters * zoom);
- int dy = (int)(ExportUtils.GetPageHeight(page) * Units.Millimeters * zoom);
- using (System.Drawing.Image image = new Bitmap(dx, dy))
- {
- matrixPage.WatermarkPictureStream = new MemoryStream();
- using (Graphics g = Graphics.FromImage(image))
- {
- g.Clear(Color.White);
- page.Watermark.DrawImage(new FRPaintEventArgs(g, 1, 1, page.Report.GraphicCache),
- new Rectangle(0, 0, dx, dy), Report, true);
- page.Watermark.DrawText(new FRPaintEventArgs(g, 1, 1, page.Report.GraphicCache),
- new Rectangle(0, 0, dx, dy), Report, true);
- }
- if (pictureFormat == ImageFormat.Jpeg)
- ExportUtils.SaveJpeg(image, matrixPage.WatermarkPictureStream, jpegQuality);
- else
- image.Save(matrixPage.WatermarkPictureStream, pictureFormat);
- matrixPage.WatermarkPictureStream.Position = 0;
- }
- }
- }
- public void CheckPicsCache(ExportIEMObject FObj)
- {
- FObj.Hash = Crypter.ComputeHash(FObj.PictureStream);
- FObj.Base = !((Dictionary<string, MemoryStream>)picsCache).ContainsKey(FObj.Hash);
- if (FObj.Base)
- picsCache.Add(FObj.Hash, FObj.PictureStream);
- else
- FObj.PictureStream = ((Dictionary<string, MemoryStream>)picsCache)[FObj.Hash];
- }
- public void Prepare()
- {
- ExportIEMStyle Style;
- ExportIEMObject FObj;
- ExportIEMObject FObjItem;
- if (fillArea)
- {
- Style = new ExportIEMStyle();
- Style.Fill = new SolidFill(Color.Transparent);
- FObj = new ExportIEMObject();
- FObj.StyleIndex = AddStyleInternal(Style);
- FObj.Style = Style;
- if (cropFillArea)
- {
- FObj.Left = minLeft;
- FObj.Top = minTop;
- }
- else
- FObj.Left = FObj.Top = 0;
- FObj.Width = MaxWidth;
- FObj.Height = MaxHeight;
- FObj.IsText = true;
- xPos.Add(0);
- yPos.Add(0);
- FObjItem = FObj;
- FObjItem.x = FObjItem.y = 0;
- FObjItem.dx = FObjItem.dy = 1;
- iemObjectList.Insert(0, FObjItem);
- }
- if (showProgress)
- Config.ReportSettings.OnProgress(report, res.Get("OrderByCells"));
- Config.DoEvent();
- Render();
- if (showProgress)
- Config.ReportSettings.OnProgress(report, res.Get("AnalyzeObjects"));
- Config.DoEvent();
- Analyze();
- if (optFrames)
- OptimizeFrames();
- if (showProgress)
- Config.ReportSettings.OnProgress(report, res.Get("SaveFile"));
- Config.DoEvent();
- }
- public void ObjectPos(int ObjIndex, out int x, out int y, out int dx, out int dy)
- {
- x = iemObjectList[ObjIndex].x;
- y = iemObjectList[ObjIndex].y;
- dx = iemObjectList[ObjIndex].dx;
- dy = iemObjectList[ObjIndex].dy;
- }
- public float PageBreak(int Page)
- {
- if (Page < pages.Count)
- return pages[Page].Value;
- return 0f;
- }
- public float PageWidth(int Page)
- {
- if (Page < pages.Count)
- return pages[Page].Width;
- return 0f;
- }
- public float PageHeight(int Page)
- {
- if (Page < pages.Count)
- return pages[Page].Height;
- return 0f;
- }
- public int RawPaperSize(int Page)
- {
- if (Page < pages.Count)
- return pages[Page].RawPaperSize;
- return 0;
- }
- public float PageLMargin(int Page)
- {
- if (Page < pages.Count)
- return pages[Page].LeftMargin;
- return 0f;
- }
- public float PageTMargin(int Page)
- {
- if (Page < pages.Count)
- return pages[Page].TopMargin;
- return 0f;
- }
- public float PageRMargin(int Page)
- {
- if (Page < pages.Count)
- return pages[Page].RightMargin;
- return 0f;
- }
- public float PageBMargin(int Page)
- {
- if (Page < pages.Count)
- return pages[Page].BottomMargin;
- return 0f;
- }
- public bool Landscape(int Page)
- {
- if (Page < pages.Count)
- return pages[Page].Landscape;
- return false;
- }
- #endregion
- public void Dispose()
- {
- defaultOneSizeFont.Dispose();
- defaultOneSizeFont = null;
- Clear();
- }
- public ExportMatrix()
- {
- defaultOneSizeFont = new Font("Arial", 1);
- fontList = new List<string>();
- iemObjectList = new List<ExportIEMObject>();
- iemStyleList = new List<ExportIEMStyle>();
- xPos = new BinaryTree();
- yPos = new BinaryTree();
- pages = new List<ExportIEMPage>();
- maxWidth = 0;
- maxHeight = 0;
- minLeft = 99999;
- minTop = 99999;
- deltaY = 0;
- inaccuracy = 0.5F;
- rotatedImage = false;
- plainRich = true;
- fillArea = false;
- cropFillArea = false;
- optFrames = false;
- left = 0;
- printable = true;
- images = true;
- imageResolution = 96;
- wrap = false;
- brushAsBitmap = true;
- bookmarks = true;
- zoom = 1f;
- dataOnly = false;
- #if !SKIA && !MONO
- fullTrust = Config.FullTrust;
- #else
- fullTrust = false;
- #endif
- pictureFormat = ImageFormat.Png;
- jpegQuality = 100;
- res = new MyRes("Export,Misc");
- fillAsBitmap = false;
- htmlMode = false;
- watermarks = false;
- seamless = false;
- firstPage = true;
- rowHeightIs = "exact";
- picsCache = new Dictionary<string, MemoryStream>();
- printOptimized = false;
- }
- }
- }
|