//============================================================================
//Gios Pdf.NET - A library for exporting Pdf Documents in C#
//Copyright (C) 2005 Paolo Gios - www.paologios.com
//
//This library is free software; you can redistribute it and/or
//modify it under the terms of the GNU Lesser General Public
//License as published by the Free Software Foundation; either
//version 2.1 of the License, or (at your option) any later version.
//
//This library is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
//Lesser General Public License for more details.
//
//You should have received a copy of the GNU Lesser General Public
//License along with this library; if not, write to the Free Software
//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//=============================================================================
using System;
using System.Collections;
using System.Drawing;
namespace HH.WMS.Utils.Gios.Pdf
{
///
/// an area to be use for Text writingsz
///
public class PdfTextArea : PdfObject
{
internal ArrayList tl;
internal string text;
internal PdfDocument PdfDocument
{
get
{
return this.PdfArea.PdfDocument;
}
}
//internal ArrayList TextLines;
internal PdfArea textArea;
///
/// gets the Area available for the Text
///
public PdfArea PdfArea
{
get
{
return this.textArea;
}
}
internal System.Drawing.Font Font;
internal System.Drawing.Color Color=System.Drawing.Color.Black;
internal int maxlines
{
get
{
return (int)(this.textArea.height/this.lineHeight);
}
}
internal double lineHeight;
internal int DrawnLines
{
get
{
int l=this.RenderLines().Count;
if (l>this.maxlines) return maxlines;
return l;
}
}
///
/// returns the Text that can't fit inside the estabilished area
///
public string OverFlowText
{
get
{
ArrayList lines=this.RenderLines();
string s="";
for (int index=this.maxlines;index
/// creates a new PdfTextArea
///
/// the font that will be used
/// the color of the font that will be used
/// the estabilished area for the Text
/// the ContentAlignment for the Text inside the area
/// the text that will be written inside the area
public PdfTextArea(System.Drawing.Font Font,System.Drawing.Color Color,PdfArea TextArea,ContentAlignment PdfTextAlign,string Text)
{
if (Text==null) throw new Exception("Text cannot be null.");
this.Font=Font;
this.Color=Color;
this.textArea=TextArea;
this.text=Text;
this.textAlign=PdfTextAlign;
this.lineHeight=(double)(Font.Size);
}
internal ArrayList RenderLines()
{
if (tl==null)
{
tl=new ArrayList();
string line="",oldline="";
double lineWidth=0,oldlineWidth=0;
char[] textchars=text.ToCharArray();
ArrayList words=new ArrayList();
string aWord="";
for (int index=0;indexthis.textArea.width)
{
if (oldline!=" "&&oldline!="")
{
tl.Add(oldline);
if (s==" ")
{ line=""; lineWidth=0;}
else
{ line=s; lineWidth=wordWidth;}
}
}
if (s2index==words.Count-1)
if (line!=" "&&line!="")
tl.Add(line);
}
}
return this.tl;
}
internal string ToLineStream()
{
System.Text.StringBuilder sb=new System.Text.StringBuilder();
//string text="";
double posx,posy;
ArrayList al=this.RenderLines();
//if (this.LineFits)
int l=al.Count;
int ml=this.maxlines;
for(int index=0;((index>\n";
s1+="stream\n";
string s3="\nendstream\n";
s3+="endobj\n";
Byte[] part1=System.Text.ASCIIEncoding.ASCII.GetBytes(s1);
Byte[] part3=System.Text.ASCIIEncoding.ASCII.GetBytes(s3);
stream.Write(part1,0,part1.Length);
stream.Write(part2,0,part2.Length);
stream.Write(part3,0,part3.Length);
return part1.Length+part2.Length+part3.Length;
}
}
}