283 lines
10 KiB
C#
283 lines
10 KiB
C#
using ceTe.DynamicPDF;
|
|
using ceTe.DynamicPDF.PageElements;
|
|
using Consulenza.ReportWriter.Business.Entity;
|
|
|
|
namespace Consulenza.ReportWriter.Business.OBJ_PDF
|
|
{
|
|
/// <summary>
|
|
/// Rappresenta una TextArea.
|
|
/// Il testo viene disegnato su più righe.
|
|
/// La TextArea è automaticamente ridimensionata in altezza(_height) a visualizzare l'intero contenuto(_text),
|
|
/// mentre il testo viene troncato qualora la largezza(_width) sia insufficiente.
|
|
/// La larghezza di default della TextArea è 520, pari all'area scrivibile del documento.
|
|
/// Di default il testo della TextArea viene disegnata con un _fontsize=8, di colore Black con un allineamento orizzonatale Left e uno verticale Center.
|
|
/// Per scrivere una label in Bold, Oblique o BoldOblique, impostare la proprietà _font con il relativo valore.
|
|
/// La proprietà _deltaheight, di default=0, impone un incremento o un decremento, a seconda se il valore passato sia positivo o negativo, del valore della _height.
|
|
/// Se l'altezza della TextArea è maggiore dello spazio disponibile del documento, la TextArea verrà disegnata in una nuova pagina, non effettua il salto pagina.
|
|
/// Il motore di renderizzazione dynamicpdf aggiunge un spazio superiore e uno inferiore alla TextArea tanto maggiore quanto è alta la _height(Attualmente sembra non esserci modo di eliminarlo).
|
|
/// Utilizza la classe primitiva ceTe.DynamicPDF.PageElements.FormattedTextArea.
|
|
/// </summary>
|
|
public class FormattedTextAreaPDF : ObjectPDF
|
|
{
|
|
#region Fields
|
|
|
|
private float _height;
|
|
private float _width = 520;
|
|
private float _fontsize = 8;
|
|
private ColorPDF _fontcolor = ColorPDF.Nero;
|
|
private TextAlign _texthorizontalalign = TextAlign.Left;
|
|
private VAlign _textverticalalign = VAlign.Center;
|
|
|
|
|
|
/// <summary>
|
|
/// Imposta o ottiene l'elemento base (PageElement)
|
|
/// </summary>
|
|
public ceTe.DynamicPDF.PageElements.FormattedTextArea BaseElement { get; set; }
|
|
|
|
/// <summary>
|
|
/// Imposta o recupera il testo da disegnare nella TextArea.
|
|
/// </summary>
|
|
public string Text { get; set; }
|
|
|
|
/// <summary>
|
|
/// Imposta o recupera la X del documento su cui disegnare la TextArea.
|
|
/// </summary>
|
|
public float X { get; set; }
|
|
|
|
/// <summary>
|
|
/// Imposta o recupera la Y del documento su cui disegnare la TextArea.
|
|
/// </summary>
|
|
public float Y { get; set; }
|
|
|
|
/// <summary>
|
|
/// Imposta o recupera un valore che indica l'incremento algebrico dell'incremento standard di Y.
|
|
/// Utilizzare questa proprietà se si vuole incrementare o decrementare la Y assegnata automaticamente dal motore di renderizzazione.
|
|
/// Di default=0;
|
|
/// </summary>
|
|
public float DeltaY { get; set; }
|
|
|
|
/// <summary>
|
|
/// Imposta o recupera un valore che indica l'incremento algebrico dell'incremento standard di X.
|
|
/// Utilizzare questa proprietà se si vuole incrementare o decrementare la X assegnata automaticamente dal motore di renderizzazione.
|
|
/// Di default=0;
|
|
/// </summary>
|
|
public float DeltaX { get; set; }
|
|
|
|
/// <summary>
|
|
/// Recupera l'altezza della TextArea.
|
|
/// </summary>
|
|
public float Height
|
|
{
|
|
get { return FixedHeight > 0 ? FixedHeight : _height; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Imposta o recupera il valore della altezza fissa.
|
|
/// Di default=0. Se impostato la Height varrà FixedHeight.
|
|
/// </summary>
|
|
public float FixedHeight { get; set; }
|
|
|
|
/// <summary>
|
|
/// Imposta o recupera la larghezza della TextArea.
|
|
/// Di default=520.
|
|
/// </summary>
|
|
public float Width
|
|
{
|
|
get { return _width; }
|
|
set { _width = value; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Imposta o recupera la grandezza del carattere della TextArea.
|
|
/// Di default=8.
|
|
/// </summary>
|
|
public float FontSize
|
|
{
|
|
get { return _fontsize; }
|
|
set { _fontsize = value; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Imposta o recupera un bool che indica il grassetto.
|
|
/// Di default = false
|
|
/// </summary>
|
|
public bool FontBold { get; set; }
|
|
|
|
/// <summary>
|
|
/// Imposta o recupera il colore del testo della TextArea.
|
|
/// Di default=black.
|
|
/// </summary>
|
|
public ColorPDF FontColor
|
|
{
|
|
get { return _fontcolor; }
|
|
set { _fontcolor = value; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Imposta o recupera l'allineamento orizzontale del testo della TextArea.
|
|
/// Di default=Left.
|
|
/// </summary>
|
|
public TextAlign TextHorizontalAlign
|
|
{
|
|
get { return _texthorizontalalign; }
|
|
set { _texthorizontalalign = value; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Imposta o recupera l'allineamento verticale del testo della TextArea.
|
|
/// Di default=Center.
|
|
/// </summary>
|
|
public VAlign TextVerticalAlign
|
|
{
|
|
get { return _textverticalalign; }
|
|
set { _textverticalalign = value; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Imposta o recupera un bool che indica se il testo sarà scritto in verticale.
|
|
/// Impone un Angle = -90 al BaseElement.
|
|
/// Di default = false.
|
|
/// </summary>
|
|
public bool TextVerticalDirection { get; set; }
|
|
|
|
/// <summary>
|
|
/// Imposta o ottiene un booleano che indica se l'oggetto ha una posizione assoluta.
|
|
/// Un oggetto con posizione assoluta ha una sua y, definita dall'utente, e non quella assegnata dal motore di renderizzazione.
|
|
/// Se impostato a true, il valore _ywritable del documento non sarà incrementato.
|
|
/// Di default=false.
|
|
/// </summary>
|
|
public bool AbsolutePosition { get; set; }
|
|
|
|
/// <summary>
|
|
/// Imposta o recupera il colore di sfondo.
|
|
/// Di default = null (non viene renderizzato).
|
|
/// </summary>
|
|
public ColorPDF BackGroundColor { get; set; }
|
|
|
|
/// <summary>
|
|
/// Imposta o recupera l'altezza del rettangolo di sfondo.
|
|
/// Di default = 23.
|
|
/// </summary>
|
|
public float BackGroundHeight { get; set; }
|
|
|
|
/// <summary>
|
|
/// Imposta o recupera il margine sinistro quando BackGroundColor è impostato.
|
|
/// Di default = 0.
|
|
/// </summary>
|
|
public float BackGroundMarginLeft { get; set; }
|
|
|
|
#endregion
|
|
|
|
#region Costruttori
|
|
|
|
/// <summary>
|
|
/// Costruttore
|
|
/// </summary>
|
|
public FormattedTextAreaPDF()
|
|
{
|
|
AbsolutePosition = false;
|
|
TextVerticalDirection = false;
|
|
FontBold = false;
|
|
DeltaY = 0;
|
|
BackGroundColor = null;
|
|
BackGroundHeight = 23;
|
|
ObjectType = ObjectTypePdf.FORMATTEDTEXTAREA;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Costruttore.
|
|
/// </summary>
|
|
/// <param name="text">Testo della FormattedTextAreaPDF</param>
|
|
/// <param name="x">X della FormattedTextAreaPDF</param>
|
|
public FormattedTextAreaPDF(string text, float x)
|
|
: this()
|
|
{
|
|
Text = text;
|
|
X = x;
|
|
|
|
//setHeight();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Costruttore.
|
|
/// </summary>
|
|
/// <param name="text">Testo della FormattedTextAreaPDF</param>
|
|
/// <param name="x">X della FormattedTextAreaPDF</param>
|
|
/// <param name="width">Larghezza della FormattedTextAreaPDF</param>
|
|
public FormattedTextAreaPDF(string text, float x, float width)
|
|
: this(text, x)
|
|
{
|
|
_width = width;
|
|
|
|
//if (_width > 0)
|
|
//{
|
|
// setHeight();
|
|
//}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Costruttore.
|
|
/// </summary>
|
|
/// <param name="text">Testo della FormattedTextAreaPDF</param>
|
|
/// <param name="x">X della FormattedTextAreaPDF</param>
|
|
/// <param name="width">Larghezza della FormattedTextAreaPDF</param>
|
|
/// <param name="horizontalAlign">Allineamento orizzontale.Di default=Left</param>
|
|
public FormattedTextAreaPDF(string text, float x, float width, TextAlign horizontalAlign)
|
|
: this(text, x, width)
|
|
{
|
|
_texthorizontalalign = horizontalAlign;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Metodi
|
|
|
|
/// <summary>
|
|
/// Ritorna l'oggetto che sarà stampato sulla pagina del documento.
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override PageElement ToElement()
|
|
{
|
|
return BaseElement;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Imposta l'altezza;
|
|
/// </summary>
|
|
public void SetHeight(float value)
|
|
{
|
|
_height = value;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ricalcola e recupera l'altezza.
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public void GetAndSetHeight(FontFamily fontfamily, bool fontbold)
|
|
{
|
|
var formattedTextArea = new ceTe.DynamicPDF.PageElements.FormattedTextArea(Text, 0, 0, _width, 0, fontfamily, _fontsize, true);
|
|
formattedTextArea.Style.Bold = fontbold;
|
|
var valueHeight = formattedTextArea.GetRequiredHeight();
|
|
|
|
SetHeight(valueHeight);
|
|
}
|
|
|
|
public float GetHeight(FontFamily fontfamily, bool fontbold)
|
|
{
|
|
var formattedTextArea = new ceTe.DynamicPDF.PageElements.FormattedTextArea(Text, 0, 0, _width, 0, fontfamily, _fontsize, true);
|
|
formattedTextArea.Style.Bold = fontbold;
|
|
return formattedTextArea.GetRequiredHeight();
|
|
}
|
|
|
|
public float GetWidthReal(FontFamily fontFamily, bool fontBold)
|
|
{
|
|
var formattedTextArea = new ceTe.DynamicPDF.PageElements.FormattedTextArea(Text, 0, 0, _width, 0, fontFamily, _fontsize, true);
|
|
formattedTextArea.Style.Bold = fontBold;
|
|
var styleUsed = new FormattedTextAreaStyle(fontFamily, _fontsize, false) { Bold = fontBold };
|
|
return styleUsed.GetFont().GetTextWidth(Text, styleUsed.Font.Size);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|