using System; using System.Collections; using System.Drawing; namespace HH.WMS.Utils.Gios.Pdf { /// /// Describes a Flow Text Area for writing text without use Pdf positioning. /// public class PdfFlowTextArea : PdfObject { private double posX,posY; private double endX,endY; private double startX,startY; private double interline; internal ArrayList Fonts; Font ActualFont;Color ActualColor; internal string Stream; /// /// gets the Actual X position of the writer. /// public double PosX { get { return this.posX; } } /// /// gets the Actual Y position of the writer. /// public double PosY { get { return this.posY; } } /// /// Creates a new Flow Text Area. /// /// the PdfArea which will contains the Text. /// the starting Font of the writings. /// the starting Color of the writings. public PdfFlowTextArea(PdfArea TextArea,Font Font,Color Color) { this.Stream=""; this.posX=TextArea.PosX; this.posY=TextArea.PosY; this.startX=TextArea.PosX; this.startY=TextArea.PosY; this.endX=TextArea.BottomRightCornerX; this.endY=TextArea.BottomRightCornerY; this.interline=Font.Size*1.6; this.Fonts=new ArrayList(); this.SetColor(Color); this.SetFont(Font); } /// /// Creates a new Flow Text Area. /// /// the PdfArea which will contains the Text. /// the starting Font of the writings. /// the starting Color of the writings. /// the starting X position of the writing cursor. /// the starting Y position of the writing cursor. public PdfFlowTextArea(PdfArea TextArea,Font Font,Color Color,double StartX,double StartY) { this.Stream=""; this.posX=TextArea.PosX; this.posY=TextArea.PosY; this.startX=StartX; this.startY=StartY; this.endX=TextArea.BottomRightCornerX; this.endY=TextArea.BottomRightCornerY; if (this.startXthis.endX) throw new Exception("Starting Point cannot be outside the FlowTextArea."); if (this.startYthis.endY) throw new Exception("Starting Point cannot be outside the FlowTextArea."); this.Fonts=new ArrayList(); this.SetColor(Color); this.SetFont(Font); this.interline=Font.Size*1.6; } /// /// Creates a new Flow Text Area. /// /// the PdfArea which will contains the Text. /// the starting Font of the writings. /// the starting Color of the writings. /// the starting X position of the writing cursor. /// the starting Y position of the writing cursor. /// the Interline Size. public PdfFlowTextArea(PdfArea TextArea,Font Font,Color Color,double StartX,double StartY,double Interline) { this.Stream=""; this.posX=TextArea.PosX; this.posY=TextArea.PosY; this.startX=StartX; this.startY=StartY; this.endX=TextArea.BottomRightCornerX; this.endY=TextArea.BottomRightCornerY; if (this.startXthis.endX) throw new Exception("Starting Point cannot be outside the FlowTextArea."); if (this.startYthis.endY) throw new Exception("Starting Point cannot be outside the FlowTextArea."); this.Fonts=new ArrayList(); this.SetColor(Color); this.SetFont(Font); this.interline=Interline; } /// /// Creates a new Flow Text Area. /// /// the PdfArea which will contains the Text. /// the starting Font of the writings. /// the starting Color of the writings. /// the Interline Size. public PdfFlowTextArea(PdfArea TextArea,Font Font,Color Color,double Interline) { this.Stream=""; this.posX=TextArea.PosX; this.posY=TextArea.PosY; this.startX=TextArea.PosX; this.startY=TextArea.PosY; this.endX=TextArea.BottomRightCornerX; this.endY=TextArea.BottomRightCornerY; this.Fonts=new ArrayList(); this.SetColor(Color); this.SetFont(Font); this.interline=Interline; } /// /// Writes a string to the FlowTextArea width the current font style, color and size. /// /// The string to be written. /// The Substring rejected by the method (text that doesn't fit inside the area. public string Write(string text) { if (text==null) throw new Exception("Text string cannot be null."); return this.Write(text,ActualFont,ActualColor); } /// /// Writes a string to the FlowTextArea width the current font style, color and size and /// applies a carriage return "\n" /// /// The line to be written. /// The Substring rejected by the method (text that doesn't fit inside the area. public string WriteLine(string text) { if (text==null) throw new Exception("Text string cannot be null."); return this.Write(text+"\n",ActualFont,ActualColor); } /// /// Sets the foreground color for the following writings. /// /// public void SetColor(Color Color) { this.Stream+=Utility.ColorrgLine(Color); this.ActualColor=Color; } /// /// Sets the font style for the following writings. /// /// public void SetFont(Font Font) { if (this.ActualFont==null) this.ActualFont=Font; Font f=new Font(Font.Name,ActualFont.Size,Font.Style); this.ActualFont=Font; this.Fonts.Add(Font); this.Stream+=Utility.FontToFontLine(Font); } private string Write(string text,Font Font,Color Color) { char[] textchars=text.ToCharArray(); ArrayList words=new ArrayList(); string aWord=""; for (int index=0;indexthis.endX) { this.Stream+=LineToStream(Color,Font,oldLine,startLine,this.posY); this.posY+=this.interline; newLineWidth=WordWidth; startLine=this.startX; if (word!=" ") newLine=word; else newLine=""; posX=this.startX; } if (wordIndex==words.Count-1) { this.Stream+=LineToStream(Color,Font,newLine,startLine,this.posY); this.posX=startLine+newLineWidth; } if (this.posY+this.interline>this.endY) { string s=""; for (int wordIndex2=wordIndex+1;wordIndex2