Initial Commit
This commit is contained in:
284
iTechSharp/iTextSharp/text/Anchor.cs
Normal file
284
iTechSharp/iTextSharp/text/Anchor.cs
Normal file
@@ -0,0 +1,284 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.util;
|
||||
|
||||
using iTextSharp.text.html;
|
||||
using iTextSharp.text.factories;
|
||||
|
||||
/*
|
||||
* $Id: Anchor.cs,v 1.9 2008/05/13 11:25:08 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iTextSharp, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text
|
||||
{
|
||||
/// <summary>
|
||||
/// An Anchor can be a reference or a destination of a reference.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// An Anchor is a special kind of <see cref="T:iTextSharp.text.Phrase"/>.
|
||||
/// It is constructed in the same way.
|
||||
/// </remarks>
|
||||
/// <seealso cref="T:iTextSharp.text.Element"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Phrase"/>
|
||||
public class Anchor : Phrase
|
||||
{
|
||||
|
||||
// membervariables
|
||||
|
||||
/// <summary>
|
||||
/// This is the name of the Anchor.
|
||||
/// </summary>
|
||||
protected string name = null;
|
||||
|
||||
/// <summary>
|
||||
/// This is the reference of the Anchor.
|
||||
/// </summary>
|
||||
protected string reference = null;
|
||||
|
||||
// constructors
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an Anchor without specifying a leading.
|
||||
/// </summary>
|
||||
/// <overloads>
|
||||
/// Has nine overloads.
|
||||
/// </overloads>
|
||||
public Anchor() : base(16) {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an Anchor with a certain leading.
|
||||
/// </summary>
|
||||
/// <param name="leading">the leading</param>
|
||||
public Anchor(float leading) : base(leading) {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an Anchor with a certain Chunk.
|
||||
/// </summary>
|
||||
/// <param name="chunk">a Chunk</param>
|
||||
public Anchor(Chunk chunk) : base(chunk) {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an Anchor with a certain string.
|
||||
/// </summary>
|
||||
/// <param name="str">a string</param>
|
||||
public Anchor(string str) : base(str) {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an Anchor with a certain string
|
||||
/// and a certain Font.
|
||||
/// </summary>
|
||||
/// <param name="str">a string</param>
|
||||
/// <param name="font">a Font</param>
|
||||
public Anchor(string str, Font font) : base(str, font) {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an Anchor with a certain Chunk
|
||||
/// and a certain leading.
|
||||
/// </summary>
|
||||
/// <param name="leading">the leading</param>
|
||||
/// <param name="chunk">a Chunk</param>
|
||||
public Anchor(float leading, Chunk chunk) : base(leading, chunk) {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an Anchor with a certain leading
|
||||
/// and a certain string.
|
||||
/// </summary>
|
||||
/// <param name="leading">the leading</param>
|
||||
/// <param name="str">a string</param>
|
||||
public Anchor(float leading, string str) : base(leading, str) {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an Anchor with a certain leading,
|
||||
/// a certain string and a certain Font.
|
||||
/// </summary>
|
||||
/// <param name="leading">the leading</param>
|
||||
/// <param name="str">a string</param>
|
||||
/// <param name="font">a Font</param>
|
||||
public Anchor(float leading, string str, Font font) : base(leading, str, font) {}
|
||||
|
||||
/**
|
||||
* Constructs an <CODE>Anchor</CODE> with a certain <CODE>Phrase</CODE>.
|
||||
*
|
||||
* @param phrase a <CODE>Phrase</CODE>
|
||||
*/
|
||||
public Anchor(Phrase phrase) : base(phrase) {
|
||||
if (phrase is Anchor) {
|
||||
Anchor a = (Anchor) phrase;
|
||||
Name = a.name;
|
||||
Reference = a.reference;
|
||||
}
|
||||
}
|
||||
// implementation of the Element-methods
|
||||
|
||||
/// <summary>
|
||||
/// Processes the element by adding it (or the different parts) to an
|
||||
/// <see cref="T:iTextSharp.text.IElementListener"/>
|
||||
/// </summary>
|
||||
/// <param name="listener">an IElementListener</param>
|
||||
/// <returns>true if the element was processed successfully</returns>
|
||||
public override bool Process(IElementListener listener)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool localDestination = (reference != null && reference.StartsWith("#"));
|
||||
bool notGotoOK = true;
|
||||
foreach (Chunk chunk in this.Chunks)
|
||||
{
|
||||
if (name != null && notGotoOK && !chunk.IsEmpty())
|
||||
{
|
||||
chunk.SetLocalDestination(name);
|
||||
notGotoOK = false;
|
||||
}
|
||||
if (localDestination)
|
||||
{
|
||||
chunk.SetLocalGoto(reference.Substring(1));
|
||||
}
|
||||
else if (reference != null)
|
||||
chunk.SetAnchor(reference);
|
||||
listener.Add(chunk);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (DocumentException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the chunks in this element.
|
||||
/// </summary>
|
||||
/// <value>an ArrayList</value>
|
||||
public override ArrayList Chunks
|
||||
{
|
||||
get
|
||||
{
|
||||
ArrayList tmp = new ArrayList();
|
||||
bool localDestination = (reference != null && reference.StartsWith("#"));
|
||||
bool notGotoOK = true;
|
||||
foreach (Chunk chunk in this)
|
||||
{
|
||||
if (name != null && notGotoOK && !chunk.IsEmpty())
|
||||
{
|
||||
chunk.SetLocalDestination(name);
|
||||
notGotoOK = false;
|
||||
}
|
||||
if (localDestination)
|
||||
{
|
||||
chunk.SetLocalGoto(reference.Substring(1));
|
||||
}
|
||||
else if (reference != null)
|
||||
{
|
||||
chunk.SetAnchor(reference);
|
||||
}
|
||||
|
||||
tmp.Add(chunk);
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of the text element.
|
||||
/// </summary>
|
||||
/// <value>a type</value>
|
||||
public override int Type
|
||||
{
|
||||
get
|
||||
{
|
||||
return Element.ANCHOR;
|
||||
}
|
||||
}
|
||||
|
||||
// methods
|
||||
|
||||
/// <summary>
|
||||
/// Name of this Anchor.
|
||||
/// </summary>
|
||||
public string Name {
|
||||
get {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
set {
|
||||
this.name = value;
|
||||
}
|
||||
}
|
||||
|
||||
// methods to retrieve information
|
||||
|
||||
/// <summary>
|
||||
/// reference of this Anchor.
|
||||
/// </summary>
|
||||
public string Reference {
|
||||
get {
|
||||
return reference;
|
||||
}
|
||||
|
||||
set {
|
||||
this.reference = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// reference of this Anchor.
|
||||
/// </summary>
|
||||
/// <value>an Uri</value>
|
||||
public Uri Url {
|
||||
get {
|
||||
try {
|
||||
return new Uri(reference);
|
||||
}
|
||||
catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
525
iTechSharp/iTextSharp/text/Annotation.cs
Normal file
525
iTechSharp/iTextSharp/text/Annotation.cs
Normal file
@@ -0,0 +1,525 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.util;
|
||||
using iTextSharp.text.factories;
|
||||
|
||||
/*
|
||||
* $Id: Annotation.cs,v 1.12 2008/05/13 11:25:08 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text
|
||||
{
|
||||
/// <summary>
|
||||
/// An Annotation is a little note that can be added to a page
|
||||
/// on a document.
|
||||
/// </summary>
|
||||
/// <seealso cref="T:iTextSharp.text.Element"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Anchor"/>
|
||||
public class Annotation : IElement
|
||||
{
|
||||
|
||||
// membervariables
|
||||
|
||||
/// <summary>This is a possible annotation type.</summary>
|
||||
public const int TEXT = 0;
|
||||
/// <summary>This is a possible annotation type.</summary>
|
||||
public const int URL_NET = 1;
|
||||
/// <summary>This is a possible annotation type.</summary>
|
||||
public const int URL_AS_STRING = 2;
|
||||
/// <summary>This is a possible annotation type.</summary>
|
||||
public const int FILE_DEST = 3;
|
||||
/// <summary>This is a possible annotation type.</summary>
|
||||
public const int FILE_PAGE = 4;
|
||||
/// <summary>This is a possible annotation type.</summary>
|
||||
public const int NAMED_DEST = 5;
|
||||
/// <summary>This is a possible annotation type.</summary>
|
||||
public const int LAUNCH = 6;
|
||||
/// <summary>This is a possible annotation type.</summary>
|
||||
public const int SCREEN = 7;
|
||||
|
||||
/// <summary>This is a possible attribute.</summary>
|
||||
public const string TITLE = "title";
|
||||
/// <summary>This is a possible attribute.</summary>
|
||||
public const string CONTENT = "content";
|
||||
/// <summary>This is a possible attribute.</summary>
|
||||
public const string URL = "url";
|
||||
/// <summary>This is a possible attribute.</summary>
|
||||
public const string FILE = "file";
|
||||
/// <summary>This is a possible attribute.</summary>
|
||||
public const string DESTINATION = "destination";
|
||||
/// <summary>This is a possible attribute.</summary>
|
||||
public const string PAGE = "page";
|
||||
/// <summary>This is a possible attribute.</summary>
|
||||
public const string NAMED = "named";
|
||||
/// <summary>This is a possible attribute.</summary>
|
||||
public const string APPLICATION = "application";
|
||||
/// <summary>This is a possible attribute.</summary>
|
||||
public const string PARAMETERS = "parameters";
|
||||
/// <summary>This is a possible attribute.</summary>
|
||||
public const string OPERATION = "operation";
|
||||
/// <summary>This is a possible attribute.</summary>
|
||||
public const string DEFAULTDIR = "defaultdir";
|
||||
/// <summary>This is a possible attribute.</summary>
|
||||
public const string LLX = "llx";
|
||||
/// <summary>This is a possible attribute.</summary>
|
||||
public const string LLY = "lly";
|
||||
/// <summary>This is a possible attribute.</summary>
|
||||
public const string URX = "urx";
|
||||
/// <summary>This is a possible attribute.</summary>
|
||||
public const string URY = "ury";
|
||||
/// <summary>This is a possible attribute.</summary>
|
||||
public const string MIMETYPE = "mime";
|
||||
|
||||
/// <summary>This is the type of annotation.</summary>
|
||||
protected int annotationtype;
|
||||
|
||||
/// <summary>This is the title of the Annotation.</summary>
|
||||
protected Hashtable annotationAttributes = new Hashtable();
|
||||
|
||||
/// <summary>This is the lower left x-value</summary>
|
||||
private float llx = float.NaN;
|
||||
/// <summary>This is the lower left y-value</summary>
|
||||
private float lly = float.NaN;
|
||||
/// <summary>This is the upper right x-value</summary>
|
||||
private float urx = float.NaN;
|
||||
/// <summary>This is the upper right y-value</summary>
|
||||
private float ury = float.NaN;
|
||||
|
||||
// constructors
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an Annotation with a certain title and some text.
|
||||
/// </summary>
|
||||
/// <param name="llx">the lower left x-value</param>
|
||||
/// <param name="lly">the lower left y-value</param>
|
||||
/// <param name="urx">the upper right x-value</param>
|
||||
/// <param name="ury">the upper right y-value</param>
|
||||
private Annotation(float llx, float lly, float urx, float ury)
|
||||
{
|
||||
this.llx = llx;
|
||||
this.lly = lly;
|
||||
this.urx = urx;
|
||||
this.ury = ury;
|
||||
}
|
||||
|
||||
public Annotation(Annotation an) {
|
||||
annotationtype = an.annotationtype;
|
||||
annotationAttributes = an.annotationAttributes;
|
||||
llx = an.llx;
|
||||
lly = an.lly;
|
||||
urx = an.urx;
|
||||
ury = an.ury;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an Annotation with a certain title and some text.
|
||||
/// </summary>
|
||||
/// <param name="title">the title of the annotation</param>
|
||||
/// <param name="text">the content of the annotation</param>
|
||||
public Annotation(string title, string text)
|
||||
{
|
||||
annotationtype = TEXT;
|
||||
annotationAttributes[TITLE] = title;
|
||||
annotationAttributes[CONTENT] = text;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an Annotation with a certain title and some text.
|
||||
/// </summary>
|
||||
/// <param name="title">the title of the annotation</param>
|
||||
/// <param name="text">the content of the annotation</param>
|
||||
/// <param name="llx">the lower left x-value</param>
|
||||
/// <param name="lly">the lower left y-value</param>
|
||||
/// <param name="urx">the upper right x-value</param>
|
||||
/// <param name="ury">the upper right y-value</param>
|
||||
public Annotation(string title, string text, float llx, float lly, float urx, float ury) : this(llx, lly, urx, ury)
|
||||
{
|
||||
annotationtype = TEXT;
|
||||
annotationAttributes[TITLE] = title;
|
||||
annotationAttributes[CONTENT] = text;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an Annotation.
|
||||
/// </summary>
|
||||
/// <param name="llx">the lower left x-value</param>
|
||||
/// <param name="lly">the lower left y-value</param>
|
||||
/// <param name="urx">the upper right x-value</param>
|
||||
/// <param name="ury">the upper right y-value</param>
|
||||
/// <param name="url">the external reference</param>
|
||||
public Annotation(float llx, float lly, float urx, float ury, Uri url) : this(llx, lly, urx, ury)
|
||||
{
|
||||
annotationtype = URL_NET;
|
||||
annotationAttributes[URL] = url;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an Annotation.
|
||||
/// </summary>
|
||||
/// <param name="llx">the lower left x-value</param>
|
||||
/// <param name="lly">the lower left y-value</param>
|
||||
/// <param name="urx">the upper right x-value</param>
|
||||
/// <param name="ury">the upper right y-value</param>
|
||||
/// <param name="url">the external reference</param>
|
||||
public Annotation(float llx, float lly, float urx, float ury, string url) : this(llx, lly, urx, ury)
|
||||
{
|
||||
annotationtype = URL_AS_STRING;
|
||||
annotationAttributes[FILE] = url;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an Annotation.
|
||||
/// </summary>
|
||||
/// <param name="llx">the lower left x-value</param>
|
||||
/// <param name="lly">the lower left y-value</param>
|
||||
/// <param name="urx">the upper right x-value</param>
|
||||
/// <param name="ury">the upper right y-value</param>
|
||||
/// <param name="file">an external PDF file</param>
|
||||
/// <param name="dest">the destination in this file</param>
|
||||
public Annotation(float llx, float lly, float urx, float ury, string file, string dest) : this(llx, lly, urx, ury)
|
||||
{
|
||||
annotationtype = FILE_DEST;
|
||||
annotationAttributes[FILE] = file;
|
||||
annotationAttributes[DESTINATION] = dest;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a Screen anotation to embed media clips
|
||||
/// </summary>
|
||||
/// <param name="llx">the lower left x-value</param>
|
||||
/// <param name="lly">the lower left y-value</param>
|
||||
/// <param name="urx">the upper right x-value</param>
|
||||
/// <param name="ury">the upper right y-value</param>
|
||||
/// <param name="moviePath">path to the media clip file</param>
|
||||
/// <param name="mimeType">mime type of the media</param>
|
||||
/// <param name="showOnDisplay">if true play on display of the page</param>
|
||||
public Annotation(float llx, float lly, float urx, float ury,
|
||||
string moviePath, string mimeType, bool showOnDisplay) : this(llx, lly, urx, ury)
|
||||
{
|
||||
annotationtype = SCREEN;
|
||||
annotationAttributes[FILE] = moviePath;
|
||||
annotationAttributes[MIMETYPE] = mimeType;
|
||||
annotationAttributes[PARAMETERS] = new bool[] {false /* embedded */, showOnDisplay };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an Annotation.
|
||||
/// </summary>
|
||||
/// <param name="llx">the lower left x-value</param>
|
||||
/// <param name="lly">the lower left y-value</param>
|
||||
/// <param name="urx">the upper right x-value</param>
|
||||
/// <param name="ury">the upper right y-value</param>
|
||||
/// <param name="file">an external PDF file</param>
|
||||
/// <param name="page">a page number in this file</param>
|
||||
public Annotation(float llx, float lly, float urx, float ury, string file, int page) : this(llx, lly, urx, ury)
|
||||
{
|
||||
annotationtype = FILE_PAGE;
|
||||
annotationAttributes[FILE] = file;
|
||||
annotationAttributes[PAGE] = page;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an Annotation.
|
||||
/// </summary>
|
||||
/// <param name="llx">the lower left x-value</param>
|
||||
/// <param name="lly">the lower left y-value</param>
|
||||
/// <param name="urx">the upper right x-value</param>
|
||||
/// <param name="ury">the upper right y-value</param>
|
||||
/// <param name="named">a named destination in this file</param>
|
||||
/// <overloads>
|
||||
/// Has nine overloads.
|
||||
/// </overloads>
|
||||
public Annotation(float llx, float lly, float urx, float ury, int named) : this(llx, lly, urx, ury)
|
||||
{
|
||||
annotationtype = NAMED_DEST;
|
||||
annotationAttributes[NAMED] = named;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an Annotation.
|
||||
/// </summary>
|
||||
/// <param name="llx">the lower left x-value</param>
|
||||
/// <param name="lly">the lower left y-value</param>
|
||||
/// <param name="urx">the upper right x-value</param>
|
||||
/// <param name="ury">the upper right y-value</param>
|
||||
/// <param name="application">an external application</param>
|
||||
/// <param name="parameters">parameters to pass to this application</param>
|
||||
/// <param name="operation">the operation to pass to this application</param>
|
||||
/// <param name="defaultdir">the default directory to run this application in</param>
|
||||
public Annotation(float llx, float lly, float urx, float ury, string application, string parameters, string operation, string defaultdir) : this(llx, lly, urx, ury)
|
||||
{
|
||||
annotationtype = LAUNCH;
|
||||
annotationAttributes[APPLICATION] = application;
|
||||
annotationAttributes[PARAMETERS] = parameters;
|
||||
annotationAttributes[OPERATION] = operation;
|
||||
annotationAttributes[DEFAULTDIR] = defaultdir;
|
||||
}
|
||||
|
||||
// implementation of the Element-methods
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of the text element
|
||||
/// </summary>
|
||||
public int Type
|
||||
{
|
||||
get
|
||||
{
|
||||
return Element.ANNOTATION;
|
||||
}
|
||||
}
|
||||
|
||||
// methods
|
||||
|
||||
/// <summary>
|
||||
/// Processes the element by adding it (or the different parts) to an
|
||||
/// IElementListener.
|
||||
/// </summary>
|
||||
/// <param name="listener">an IElementListener</param>
|
||||
/// <returns>true if the element was process successfully</returns>
|
||||
public bool Process(IElementListener listener)
|
||||
{
|
||||
try
|
||||
{
|
||||
return listener.Add(this);
|
||||
}
|
||||
catch (DocumentException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the chunks in this element.
|
||||
/// </summary>
|
||||
/// <value>an ArrayList</value>
|
||||
public ArrayList Chunks
|
||||
{
|
||||
get
|
||||
{
|
||||
return new ArrayList();
|
||||
}
|
||||
}
|
||||
|
||||
// methods
|
||||
|
||||
/// <summary>
|
||||
/// Sets the dimensions of this annotation.
|
||||
/// </summary>
|
||||
/// <param name="llx">the lower left x-value</param>
|
||||
/// <param name="lly">the lower left y-value</param>
|
||||
/// <param name="urx">the upper right x-value</param>
|
||||
/// <param name="ury">the upper right y-value</param>
|
||||
public void SetDimensions (float llx, float lly, float urx, float ury)
|
||||
{
|
||||
this.llx = llx;
|
||||
this.lly = lly;
|
||||
this.urx = urx;
|
||||
this.ury = ury;
|
||||
}
|
||||
|
||||
// methods to retrieve information
|
||||
|
||||
/// <summary>
|
||||
/// Returns the lower left x-value.
|
||||
/// </summary>
|
||||
/// <returns>a value</returns>
|
||||
public float GetLlx()
|
||||
{
|
||||
return llx;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the lower left y-value.
|
||||
/// </summary>
|
||||
/// <returns>a value</returns>
|
||||
public float GetLly()
|
||||
{
|
||||
return lly;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the uppper right x-value.
|
||||
/// </summary>
|
||||
/// <returns>a value</returns>
|
||||
public float GetUrx()
|
||||
{
|
||||
return urx;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the uppper right y-value.
|
||||
/// </summary>
|
||||
/// <returns>a value</returns>
|
||||
public float GetUry()
|
||||
{
|
||||
return ury;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the lower left x-value.
|
||||
/// </summary>
|
||||
/// <param name="def">the default value</param>
|
||||
/// <returns>a value</returns>
|
||||
public float GetLlx(float def)
|
||||
{
|
||||
if (float.IsNaN(llx))
|
||||
return def;
|
||||
return llx;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the lower left y-value.
|
||||
/// </summary>
|
||||
/// <param name="def">the default value</param>
|
||||
/// <returns>a value</returns>
|
||||
public float GetLly(float def)
|
||||
{
|
||||
if (float.IsNaN(lly))
|
||||
return def;
|
||||
return lly;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the upper right x-value.
|
||||
/// </summary>
|
||||
/// <param name="def">the default value</param>
|
||||
/// <returns>a value</returns>
|
||||
public float GetUrx(float def)
|
||||
{
|
||||
if (float.IsNaN(urx))
|
||||
return def;
|
||||
return urx;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the upper right y-value.
|
||||
/// </summary>
|
||||
/// <param name="def">the default value</param>
|
||||
/// <returns>a value</returns>
|
||||
public float GetUry(float def)
|
||||
{
|
||||
if (float.IsNaN(ury))
|
||||
return def;
|
||||
return ury;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the type of this Annotation.
|
||||
/// </summary>
|
||||
/// <value>a type</value>
|
||||
public int AnnotationType
|
||||
{
|
||||
get
|
||||
{
|
||||
return annotationtype;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the title of this Annotation.
|
||||
/// </summary>
|
||||
/// <value>a name</value>
|
||||
public string Title
|
||||
{
|
||||
get
|
||||
{
|
||||
string s = (string)annotationAttributes[TITLE];
|
||||
if (s == null)
|
||||
s = "";
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the content of this Annotation.
|
||||
/// </summary>
|
||||
/// <value>a reference</value>
|
||||
public string Content
|
||||
{
|
||||
get
|
||||
{
|
||||
string s = (string)annotationAttributes[CONTENT];
|
||||
if (s == null) s = "";
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the content of this Annotation.
|
||||
/// </summary>
|
||||
/// <value>a reference</value>
|
||||
public Hashtable Attributes
|
||||
{
|
||||
get
|
||||
{
|
||||
return annotationAttributes;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.lowagie.text.Element#isContent()
|
||||
* @since iText 2.0.8
|
||||
*/
|
||||
public bool IsContent() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.lowagie.text.Element#isNestable()
|
||||
* @since iText 2.0.8
|
||||
*/
|
||||
public bool IsNestable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return base.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
66
iTechSharp/iTextSharp/text/BadElementException.cs
Normal file
66
iTechSharp/iTextSharp/text/BadElementException.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
|
||||
/*
|
||||
* $Id: BadElementException.cs,v 1.3 2008/05/13 11:25:08 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text
|
||||
{
|
||||
/// <summary>
|
||||
/// Signals an attempt to create an Element that hasn't got the right form.
|
||||
/// </summary>
|
||||
/// <seealso cref="T:iTextSharp.text.Cell"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Table"/>
|
||||
public class BadElementException : DocumentException
|
||||
{
|
||||
public BadElementException() : base() {}
|
||||
|
||||
public BadElementException(string message) : base(message) {}
|
||||
}
|
||||
}
|
||||
873
iTechSharp/iTextSharp/text/Cell.cs
Normal file
873
iTechSharp/iTextSharp/text/Cell.cs
Normal file
@@ -0,0 +1,873 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.util;
|
||||
|
||||
using iTextSharp.text.html;
|
||||
using iTextSharp.text.pdf;
|
||||
using iTextSharp.text.factories;
|
||||
|
||||
/*
|
||||
* $Id: Cell.cs,v 1.17 2008/05/13 11:25:08 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text {
|
||||
/// <summary>
|
||||
/// A Cell is a Rectangle containing other Elements.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A Cell is a Rectangle containing other
|
||||
/// Elements.
|
||||
/// <p/>
|
||||
/// A Cell must be added to a Table.
|
||||
/// The Table will place the Cell in
|
||||
/// a Row.
|
||||
/// </remarks>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// Table table = new Table(3);
|
||||
/// table.SetBorderWidth(1);
|
||||
/// table.SetBorderColor(new Color(0, 0, 255));
|
||||
/// table.SetCellpadding(5);
|
||||
/// table.SetCellspacing(5);
|
||||
/// <strong>Cell cell = new Cell("header");
|
||||
/// cell.SetHeader(true);
|
||||
/// cell.SetColspan(3);</strong>
|
||||
/// table.AddCell(cell);
|
||||
/// <strong>cell = new Cell("example cell with colspan 1 and rowspan 2");
|
||||
/// cell.SetRowspan(2);
|
||||
/// cell.SetBorderColor(new Color(255, 0, 0));</strong>
|
||||
/// table.AddCell(cell);
|
||||
/// table.AddCell("1.1");
|
||||
/// table.AddCell("2.1");
|
||||
/// table.AddCell("1.2");
|
||||
/// table.AddCell("2.2");
|
||||
/// </code>
|
||||
/// </example>
|
||||
/// <seealso cref="T:iTextSharp.text.Rectangle"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Element"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Table"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Row"/>
|
||||
public class Cell : Rectangle, ITextElementArray {
|
||||
|
||||
// static membervariable
|
||||
|
||||
public static Cell DummyCell {
|
||||
get {
|
||||
Cell cell = new Cell(true);
|
||||
cell.Colspan = 3;
|
||||
cell.Border = NO_BORDER;
|
||||
return cell;
|
||||
}
|
||||
}
|
||||
|
||||
// membervariables
|
||||
|
||||
///<summary> This is the ArrayList of Elements. </summary>
|
||||
protected ArrayList arrayList = null;
|
||||
|
||||
///<summary> This is the horizontal Element. </summary>
|
||||
protected int horizontalAlignment = Element.ALIGN_UNDEFINED;
|
||||
|
||||
///<summary> This is the vertical Element. </summary>
|
||||
protected int verticalAlignment = Element.ALIGN_UNDEFINED;
|
||||
|
||||
///<summary> This is the vertical Element. </summary>
|
||||
protected float width;
|
||||
protected bool percentage = false;
|
||||
|
||||
///<summary> This is the colspan. </summary>
|
||||
protected int colspan = 1;
|
||||
|
||||
///<summary> This is the rowspan. </summary>
|
||||
protected int rowspan = 1;
|
||||
|
||||
///<summary> This is the leading. </summary>
|
||||
float leading = float.NaN;
|
||||
|
||||
///<summary> Is this Cell a header? </summary>
|
||||
protected bool header;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the largest ascender height should be used to determine the
|
||||
/// height of the first line. Note that this only has an effect when rendered
|
||||
/// to PDF. Setting this to true can help with vertical alignment problems.
|
||||
/// </summary>
|
||||
protected bool useAscender = false;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the largest descender height should be added to the height of
|
||||
/// the last line (so characters like y don't dip into the border). Note that
|
||||
/// this only has an effect when rendered to PDF.
|
||||
/// </summary>
|
||||
protected bool useDescender = false;
|
||||
|
||||
/// <summary>
|
||||
/// Adjusts the cell contents to compensate for border widths. Note that
|
||||
/// this only has an effect when rendered to PDF.
|
||||
/// </summary>
|
||||
protected bool useBorderPadding;
|
||||
|
||||
///<summary> Will the element have to be wrapped? </summary>
|
||||
protected bool noWrap;
|
||||
|
||||
// constructors
|
||||
|
||||
/**
|
||||
* Constructs an empty Cell.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Constructs an empty Cell.
|
||||
/// </summary>
|
||||
/// <overloads>
|
||||
/// Has five overloads.
|
||||
/// </overloads>
|
||||
public Cell() : base(0, 0, 0, 0) {
|
||||
// creates a Rectangle with BY DEFAULT a border of 0.5
|
||||
|
||||
this.Border = UNDEFINED;
|
||||
this.BorderWidth = 0.5F;
|
||||
|
||||
// initializes the arraylist and adds an element
|
||||
arrayList = new ArrayList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an empty Cell (for internal use only).
|
||||
/// </summary>
|
||||
/// <param name="dummy">a dummy value</param>
|
||||
public Cell(bool dummy) : this() {
|
||||
arrayList.Add(new Paragraph(0));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Cell with a certain content.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The string will be converted into a Paragraph.
|
||||
/// </remarks>
|
||||
/// <param name="content">a string</param>
|
||||
public Cell(string content) : this() {
|
||||
AddElement(new Paragraph(content));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Cell with a certain Element.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// if the element is a ListItem, Row or
|
||||
/// Cell, an exception will be thrown.
|
||||
/// </remarks>
|
||||
/// <param name="element">the element</param>
|
||||
public Cell(IElement element) : this() {
|
||||
if (element is Phrase) {
|
||||
Leading = ((Phrase)element).Leading;
|
||||
}
|
||||
AddElement(element);
|
||||
}
|
||||
|
||||
// implementation of the Element-methods
|
||||
|
||||
/// <summary>
|
||||
/// Processes the element by adding it (or the different parts) to an
|
||||
/// IElementListener.
|
||||
/// </summary>
|
||||
/// <param name="listener">an IElementListener</param>
|
||||
/// <returns>true if the element was processed successfully</returns>
|
||||
public override bool Process(IElementListener listener) {
|
||||
try {
|
||||
return listener.Add(this);
|
||||
}
|
||||
catch (DocumentException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of the text element.
|
||||
/// </summary>
|
||||
/// <value>a type</value>
|
||||
public override int Type {
|
||||
get {
|
||||
return Element.CELL;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the chunks in this element.
|
||||
/// </summary>
|
||||
/// <value>an ArrayList</value>
|
||||
public override ArrayList Chunks {
|
||||
get {
|
||||
ArrayList tmp = new ArrayList();
|
||||
foreach (IElement ele in arrayList) {
|
||||
tmp.AddRange(ele.Chunks);
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
|
||||
// methods to set the membervariables
|
||||
|
||||
/**
|
||||
* Adds an element to this Cell.
|
||||
* <P>
|
||||
* Remark: you can't add ListItems, Rows, Cells,
|
||||
* JPEGs, GIFs or PNGs to a Cell.
|
||||
*
|
||||
* @param element The Element to add
|
||||
* @throws BadElementException if the method was called with a ListItem, Row or Cell
|
||||
*/
|
||||
/// <summary>
|
||||
/// Adds an element to this Cell.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// You can't add ListItems, Rows, Cells,
|
||||
/// JPEGs, GIFs or PNGs to a Cell.
|
||||
/// </remarks>
|
||||
/// <param name="element">the Element to add</param>
|
||||
public void AddElement(IElement element) {
|
||||
if (IsTable()) {
|
||||
Table table = (Table) arrayList[0];
|
||||
Cell tmp = new Cell(element);
|
||||
tmp.Border = NO_BORDER;
|
||||
tmp.Colspan = table.Columns;
|
||||
table.AddCell(tmp);
|
||||
return;
|
||||
}
|
||||
switch (element.Type) {
|
||||
case Element.LISTITEM:
|
||||
case Element.ROW:
|
||||
case Element.CELL:
|
||||
throw new BadElementException("You can't add listitems, rows or cells to a cell.");
|
||||
case Element.JPEG:
|
||||
case Element.IMGRAW:
|
||||
case Element.IMGTEMPLATE:
|
||||
arrayList.Add(element);
|
||||
break;
|
||||
case Element.LIST:
|
||||
if (float.IsNaN(this.Leading)) {
|
||||
leading = ((List) element).TotalLeading;
|
||||
}
|
||||
if (((List) element).IsEmpty()) return;
|
||||
arrayList.Add(element);
|
||||
return;
|
||||
case Element.ANCHOR:
|
||||
case Element.PARAGRAPH:
|
||||
case Element.PHRASE:
|
||||
if (float.IsNaN(leading)) {
|
||||
leading = ((Phrase) element).Leading;
|
||||
}
|
||||
if (((Phrase) element).IsEmpty()) return;
|
||||
arrayList.Add(element);
|
||||
return;
|
||||
case Element.CHUNK:
|
||||
if (((Chunk) element).IsEmpty()) return;
|
||||
arrayList.Add(element);
|
||||
return;
|
||||
case Element.TABLE:
|
||||
Table table = new Table(3);
|
||||
float[] widths = new float[3];
|
||||
widths[1] = ((Table)element).Width;
|
||||
|
||||
switch (((Table)element).Alignment) {
|
||||
case Element.ALIGN_LEFT:
|
||||
widths[0] = 0f;
|
||||
widths[2] = 100f - widths[1];
|
||||
break;
|
||||
case Element.ALIGN_CENTER:
|
||||
widths[0] = (100f - widths[1]) / 2f;
|
||||
widths[2] = widths[0];
|
||||
break;
|
||||
case Element.ALIGN_RIGHT:
|
||||
widths[0] = 100f - widths[1];
|
||||
widths[2] = 0f;
|
||||
break;
|
||||
}
|
||||
table.Widths = widths;
|
||||
Cell tmp;
|
||||
if (arrayList.Count == 0) {
|
||||
table.AddCell(Cell.DummyCell);
|
||||
}
|
||||
else {
|
||||
tmp = new Cell();
|
||||
tmp.Border = NO_BORDER;
|
||||
tmp.Colspan = 3;
|
||||
foreach (IElement ele in arrayList) {
|
||||
tmp.Add(ele);
|
||||
}
|
||||
table.AddCell(tmp);
|
||||
}
|
||||
tmp = new Cell();
|
||||
tmp.Border = NO_BORDER;
|
||||
table.AddCell(tmp);
|
||||
table.InsertTable((Table)element);
|
||||
tmp = new Cell();
|
||||
tmp.Border = NO_BORDER;
|
||||
table.AddCell(tmp);
|
||||
table.AddCell(Cell.DummyCell);
|
||||
Clear();
|
||||
arrayList.Add(table);
|
||||
return;
|
||||
default:
|
||||
arrayList.Add(element);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add an Object to this cell.
|
||||
/// </summary>
|
||||
/// <param name="o">the object to add</param>
|
||||
/// <returns>always true</returns>
|
||||
public bool Add(Object o) {
|
||||
try {
|
||||
this.AddElement((IElement) o);
|
||||
return true;
|
||||
}
|
||||
catch (BadElementException bee) {
|
||||
throw new Exception(bee.Message);
|
||||
}
|
||||
catch {
|
||||
throw new Exception("You can only add objects that implement the Element interface.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the alignment of this cell.
|
||||
/// </summary>
|
||||
/// <param name="alignment">the new alignment as a string</param>
|
||||
public void SetHorizontalAlignment(string alignment) {
|
||||
if (Util.EqualsIgnoreCase(alignment, ElementTags.ALIGN_CENTER)) {
|
||||
this.HorizontalAlignment = Element.ALIGN_CENTER;
|
||||
return;
|
||||
}
|
||||
if (Util.EqualsIgnoreCase(alignment, ElementTags.ALIGN_RIGHT)) {
|
||||
this.HorizontalAlignment = Element.ALIGN_RIGHT;
|
||||
return;
|
||||
}
|
||||
if (Util.EqualsIgnoreCase(alignment, ElementTags.ALIGN_JUSTIFIED)) {
|
||||
this.HorizontalAlignment = Element.ALIGN_JUSTIFIED;
|
||||
return;
|
||||
}
|
||||
if (Util.EqualsIgnoreCase(alignment, ElementTags.ALIGN_JUSTIFIED_ALL)) {
|
||||
this.HorizontalAlignment = Element.ALIGN_JUSTIFIED_ALL;
|
||||
return;
|
||||
}
|
||||
this.HorizontalAlignment = Element.ALIGN_LEFT;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the alignment of this paragraph.
|
||||
/// </summary>
|
||||
/// <param name="alignment">the new alignment as a string</param>
|
||||
public void SetVerticalAlignment(string alignment) {
|
||||
if (Util.EqualsIgnoreCase(alignment, ElementTags.ALIGN_MIDDLE)) {
|
||||
this.VerticalAlignment = Element.ALIGN_MIDDLE;
|
||||
return;
|
||||
}
|
||||
if (Util.EqualsIgnoreCase(alignment, ElementTags.ALIGN_BOTTOM)) {
|
||||
this.VerticalAlignment = Element.ALIGN_BOTTOM;
|
||||
return;
|
||||
}
|
||||
if (Util.EqualsIgnoreCase(alignment, ElementTags.ALIGN_BASELINE)) {
|
||||
this.VerticalAlignment = Element.ALIGN_BASELINE;
|
||||
return;
|
||||
}
|
||||
this.VerticalAlignment = Element.ALIGN_TOP;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the width.
|
||||
/// </summary>
|
||||
/// <value>the new value</value>
|
||||
public override float Width {
|
||||
set {
|
||||
width = value;
|
||||
}
|
||||
get {
|
||||
return width;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the width.
|
||||
* It can be an absolute value "100" or a percentage "20%"
|
||||
*
|
||||
* @param value the new value
|
||||
*/
|
||||
public void SetWidth(String value) {
|
||||
if (value.EndsWith("%")) {
|
||||
value = value.Substring(0, value.Length - 1);
|
||||
percentage = true;
|
||||
}
|
||||
width = int.Parse(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the width as a String.
|
||||
*
|
||||
* @return a value
|
||||
*/
|
||||
public String GetWidthAsString() {
|
||||
String w = width.ToString(System.Globalization.CultureInfo.InvariantCulture);
|
||||
if (w.EndsWith(".0")) w = w.Substring(0, w.Length - 2);
|
||||
if (percentage) w += "%";
|
||||
return w;
|
||||
}
|
||||
|
||||
// methods to retrieve information
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of Elements in the Cell.
|
||||
/// </summary>
|
||||
/// <value>a size</value>
|
||||
public int Size {
|
||||
get {
|
||||
return arrayList.Count;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the Cell is empty.
|
||||
/// </summary>
|
||||
/// <returns>false if there are non-empty Elements in the Cell.</returns>
|
||||
public bool IsEmpty() {
|
||||
switch (this.Size) {
|
||||
case 0:
|
||||
return true;
|
||||
case 1:
|
||||
IElement element = (IElement)arrayList[0];
|
||||
switch (element.Type) {
|
||||
case Element.CHUNK:
|
||||
return ((Chunk) element).IsEmpty();
|
||||
case Element.ANCHOR:
|
||||
case Element.PHRASE:
|
||||
case Element.PARAGRAPH:
|
||||
return ((Phrase) element).IsEmpty();
|
||||
case Element.LIST:
|
||||
return ((List) element).IsEmpty();
|
||||
}
|
||||
return false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes sure there is at least 1 object in the Cell.
|
||||
/// Otherwise it might not be shown in the table.
|
||||
/// </summary>
|
||||
internal void Fill() {
|
||||
if (this.Size == 0) arrayList.Add(new Paragraph(0));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the Cell is empty.
|
||||
/// </summary>
|
||||
/// <returns>false if there are non-empty Elements in the Cell.</returns>
|
||||
public bool IsTable() {
|
||||
return (this.Size == 1) && (((IElement)arrayList[0]).Type == Element.TABLE);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets Elements.
|
||||
/// </summary>
|
||||
/// <value>an ArrayList</value>
|
||||
public ArrayList Elements {
|
||||
get {
|
||||
return arrayList;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets the horizontal Element.
|
||||
/// </summary>
|
||||
/// <value>a value</value>
|
||||
public int HorizontalAlignment {
|
||||
get {
|
||||
return horizontalAlignment;
|
||||
}
|
||||
|
||||
set {
|
||||
horizontalAlignment = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets/sets the vertical Element.
|
||||
/// </summary>
|
||||
/// <value>a value</value>
|
||||
public int VerticalAlignment {
|
||||
get {
|
||||
return verticalAlignment;
|
||||
}
|
||||
|
||||
set {
|
||||
verticalAlignment = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the colspan.
|
||||
*
|
||||
* @return a value
|
||||
*/
|
||||
/// <summary>
|
||||
/// Gets/sets the colspan.
|
||||
/// </summary>
|
||||
/// <value>a value</value>
|
||||
public int Colspan {
|
||||
get {
|
||||
return colspan;
|
||||
}
|
||||
|
||||
set {
|
||||
colspan = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets/sets the rowspan.
|
||||
/// </summary>
|
||||
/// <value>a value</value>
|
||||
public int Rowspan {
|
||||
get {
|
||||
return rowspan;
|
||||
}
|
||||
|
||||
set {
|
||||
rowspan = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets/sets the leading.
|
||||
/// </summary>
|
||||
/// <value>a value</value>
|
||||
public float Leading {
|
||||
get {
|
||||
if (float.IsNaN(leading)) {
|
||||
return 16;
|
||||
}
|
||||
return leading;
|
||||
}
|
||||
|
||||
set {
|
||||
leading = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets/sets header
|
||||
/// </summary>
|
||||
/// <value>a value</value>
|
||||
public bool Header {
|
||||
get {
|
||||
return header;
|
||||
}
|
||||
|
||||
set {
|
||||
header = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get nowrap.
|
||||
*
|
||||
* @return a value
|
||||
*/
|
||||
/// <summary>
|
||||
/// Get/set nowrap.
|
||||
/// </summary>
|
||||
/// <value>a value</value>
|
||||
public bool NoWrap {
|
||||
get {
|
||||
return (maxLines == 1);
|
||||
}
|
||||
|
||||
set {
|
||||
maxLines = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears all the Elements of this Cell.
|
||||
/// </summary>
|
||||
public void Clear() {
|
||||
arrayList.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This property throws an Exception.
|
||||
/// </summary>
|
||||
/// <value>none</value>
|
||||
public override float Top {
|
||||
get {
|
||||
throw new Exception("Dimensions of a Cell can't be calculated. See the FAQ.");
|
||||
}
|
||||
|
||||
set {
|
||||
throw new Exception("Dimensions of a Cell can't be calculated. See the FAQ.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This property throws an Exception.
|
||||
/// </summary>
|
||||
/// <value>none</value>
|
||||
public override float Bottom {
|
||||
get {
|
||||
throw new Exception("Dimensions of a Cell can't be calculated. See the FAQ.");
|
||||
}
|
||||
|
||||
set {
|
||||
throw new Exception("Dimensions of a Cell can't be calculated. See the FAQ.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This property throws an Exception.
|
||||
/// </summary>
|
||||
/// <value>none</value>
|
||||
public override float Left {
|
||||
get {
|
||||
throw new Exception("Dimensions of a Cell can't be calculated. See the FAQ.");
|
||||
}
|
||||
|
||||
set {
|
||||
throw new Exception("Dimensions of a Cell can't be calculated. See the FAQ.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This property throws an Exception.
|
||||
/// </summary>
|
||||
/// <value>none</value>
|
||||
public override float Right {
|
||||
get {
|
||||
throw new Exception("Dimensions of a Cell can't be calculated. See the FAQ.");
|
||||
}
|
||||
|
||||
set {
|
||||
throw new Exception("Dimensions of a Cell can't be calculated. See the FAQ.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method throws an Exception.
|
||||
/// </summary>
|
||||
/// <param name="margin">new value</param>
|
||||
/// <returns>none</returns>
|
||||
public float GetTop(int margin) {
|
||||
throw new Exception("Dimensions of a Cell can't be calculated. See the FAQ.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method throws an Exception.
|
||||
/// </summary>
|
||||
/// <param name="margin">new value</param>
|
||||
/// <returns>none</returns>
|
||||
public float GetBottom(int margin) {
|
||||
throw new Exception("Dimensions of a Cell can't be calculated. See the FAQ.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method throws an Exception.
|
||||
/// </summary>
|
||||
/// <param name="margin">new value</param>
|
||||
/// <returns>none</returns>
|
||||
public float GetLeft(int margin) {
|
||||
throw new Exception("Dimensions of a Cell can't be calculated. See the FAQ.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method throws an Exception.
|
||||
/// </summary>
|
||||
/// <param name="margin">new value</param>
|
||||
/// <returns>none</returns>
|
||||
public float GetRight(int margin) {
|
||||
throw new Exception("Dimensions of a Cell can't be calculated. See the FAQ.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a given tag corresponds with this object.
|
||||
/// </summary>
|
||||
/// <param name="tag">the given tag</param>
|
||||
/// <returns>true if the tag corresponds</returns>
|
||||
public static bool IsTag(string tag) {
|
||||
return ElementTags.CELL.Equals(tag);
|
||||
}
|
||||
|
||||
|
||||
///<summary>Does this <CODE>Cell</CODE> force a group change? </summary>
|
||||
protected bool groupChange = true;
|
||||
|
||||
/// <summary>
|
||||
/// Does this <CODE>Cell</CODE> force a group change?
|
||||
/// </summary>
|
||||
public bool GroupChange {
|
||||
get {
|
||||
return groupChange;
|
||||
}
|
||||
|
||||
set {
|
||||
groupChange = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get/set maxLines value
|
||||
/// </summary>
|
||||
public int MaxLines {
|
||||
get {
|
||||
return maxLines;
|
||||
}
|
||||
|
||||
set {
|
||||
maxLines = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Maximum number of lines allowed in the cell.
|
||||
/// The default value of this property is not to limit the maximum number of lines
|
||||
/// (contributed by dperezcar@fcc.es)
|
||||
/// </summary>
|
||||
protected int maxLines = int.MaxValue;
|
||||
|
||||
/// <summary>
|
||||
/// get/set showTruncation value
|
||||
/// </summary>
|
||||
public string ShowTruncation {
|
||||
get {
|
||||
return showTruncation;
|
||||
}
|
||||
|
||||
set {
|
||||
showTruncation = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If a truncation happens due to the {@link #maxLines} property, then this text will
|
||||
/// be added to indicate a truncation has happened.
|
||||
/// Default value is null, and means avoiding marking the truncation.
|
||||
/// A useful value of this property could be e.g. "..."
|
||||
/// (contributed by dperezcar@fcc.es)
|
||||
/// </summary>
|
||||
private string showTruncation;
|
||||
|
||||
/// <summary>
|
||||
/// get/set useAscender value
|
||||
/// </summary>
|
||||
public bool UseAscender {
|
||||
get {
|
||||
return useAscender;
|
||||
}
|
||||
|
||||
set {
|
||||
useAscender = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get/set useDescender value
|
||||
/// </summary>
|
||||
public bool UseDescender {
|
||||
get {
|
||||
return useDescender;
|
||||
}
|
||||
|
||||
set {
|
||||
useDescender = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get/set useBorderPadding value
|
||||
/// </summary>
|
||||
public bool UseBorderPadding {
|
||||
get {
|
||||
return useBorderPadding;
|
||||
}
|
||||
|
||||
set {
|
||||
useBorderPadding = value;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Creates a PdfPCell based on this Cell object.
|
||||
* @return a PdfPCell
|
||||
* @throws BadElementException
|
||||
*/
|
||||
public PdfPCell CreatePdfPCell() {
|
||||
if (rowspan > 1) throw new BadElementException("PdfPCells can't have a rowspan > 1");
|
||||
if (IsTable()) return new PdfPCell(((Table)arrayList[0]).CreatePdfPTable());
|
||||
PdfPCell cell = new PdfPCell();
|
||||
cell.VerticalAlignment = verticalAlignment;
|
||||
cell.HorizontalAlignment = horizontalAlignment;
|
||||
cell.Colspan = colspan;
|
||||
cell.UseBorderPadding = useBorderPadding;
|
||||
cell.UseDescender = useDescender;
|
||||
cell.SetLeading(Leading, 0);
|
||||
cell.CloneNonPositionParameters(this);
|
||||
cell.NoWrap = noWrap;
|
||||
foreach (IElement i in Elements) {
|
||||
if (i.Type == Element.PHRASE || i.Type == Element.PARAGRAPH) {
|
||||
Paragraph p = new Paragraph((Phrase)i);
|
||||
p.Alignment = horizontalAlignment;
|
||||
cell.AddElement(p);
|
||||
}
|
||||
else
|
||||
cell.AddElement(i);
|
||||
}
|
||||
return cell;
|
||||
}
|
||||
}
|
||||
}
|
||||
142
iTechSharp/iTextSharp/text/Chapter.cs
Normal file
142
iTechSharp/iTextSharp/text/Chapter.cs
Normal file
@@ -0,0 +1,142 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.util;
|
||||
using iTextSharp.text.factories;
|
||||
|
||||
/*
|
||||
* $Id: Chapter.cs,v 1.10 2008/05/13 11:25:08 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text
|
||||
{
|
||||
/// <summary>
|
||||
/// A Chapter is a special Section.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A chapter number has to be created using a Paragraph as title
|
||||
/// and an int as chapter number. The chapter number is shown be
|
||||
/// default. If you don't want to see the chapter number, you have to set the
|
||||
/// numberdepth to 0.
|
||||
/// </remarks>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// Paragraph title2 = new Paragraph("This is Chapter 2", FontFactory.GetFont(FontFactory.HELVETICA, 18, Font.BOLDITALIC, new Color(0, 0, 255)));
|
||||
/// <strong>Chapter chapter2 = new Chapter(title2, 2);
|
||||
/// chapter2.SetNumberDepth(0);</strong>
|
||||
/// Paragraph someText = new Paragraph("This is some text");
|
||||
/// <strong>chapter2.Add(someText);</strong>
|
||||
/// Paragraph title21 = new Paragraph("This is Section 1 in Chapter 2", FontFactory.GetFont(FontFactory.HELVETICA, 16, Font.BOLD, new Color(255, 0, 0)));
|
||||
/// Section section1 = <strong>chapter2.AddSection(title21);</strong>
|
||||
/// Paragraph someSectionText = new Paragraph("This is some silly paragraph in a chapter and/or section. It contains some text to test the functionality of Chapters and Section.");
|
||||
/// section1.Add(someSectionText);
|
||||
/// </code>
|
||||
/// </example>
|
||||
public class Chapter : Section
|
||||
{
|
||||
|
||||
// constructors
|
||||
|
||||
/**
|
||||
* Constructs a new <CODE>Chapter</CODE>.
|
||||
* @param number the Chapter number
|
||||
*/
|
||||
|
||||
public Chapter(int number) : base (null, 1) {
|
||||
numbers = new ArrayList();
|
||||
numbers.Add(number);
|
||||
triggerNewPage = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new Chapter.
|
||||
/// </summary>
|
||||
/// <param name="title">the Chapter title (as a Paragraph)</param>
|
||||
/// <param name="number">the Chapter number</param>
|
||||
/// <overoads>
|
||||
/// Has three overloads.
|
||||
/// </overoads>
|
||||
public Chapter(Paragraph title, int number) : base(title, 1)
|
||||
{
|
||||
numbers = new ArrayList();
|
||||
numbers.Add(number);
|
||||
triggerNewPage = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new Chapter.
|
||||
/// </summary>
|
||||
/// <param name="title">the Chapter title (as a string)</param>
|
||||
/// <param name="number">the Chapter number</param>
|
||||
/// <overoads>
|
||||
/// Has three overloads.
|
||||
/// </overoads>
|
||||
public Chapter(string title, int number) : this(new Paragraph(title), number) {}
|
||||
|
||||
// implementation of the Element-methods
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of the text element.
|
||||
/// </summary>
|
||||
/// <value>a type</value>
|
||||
public override int Type {
|
||||
get {
|
||||
return Element.CHAPTER;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.lowagie.text.Element#isNestable()
|
||||
* @since iText 2.0.8
|
||||
*/
|
||||
public override bool IsNestable() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
101
iTechSharp/iTextSharp/text/ChapterAutoNumber.cs
Normal file
101
iTechSharp/iTextSharp/text/ChapterAutoNumber.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
using System;
|
||||
|
||||
/*
|
||||
* Copyright 2005 by Michael Niedermair.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text {
|
||||
|
||||
/**
|
||||
* Chapter with auto numbering.
|
||||
*
|
||||
* @author Michael Niedermair
|
||||
*/
|
||||
public class ChapterAutoNumber : Chapter {
|
||||
|
||||
/**
|
||||
* Create a new object.
|
||||
*
|
||||
* @param para the Chapter title (as a <CODE>Paragraph</CODE>)
|
||||
*/
|
||||
public ChapterAutoNumber(Paragraph para) : base(para, 0) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new objet.
|
||||
*
|
||||
* @param title the Chapter title (as a <CODE>String</CODE>)
|
||||
*/
|
||||
public ChapterAutoNumber(String title) : base(title, 0) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new section for this chapter and ad it.
|
||||
*
|
||||
* @param title the Section title (as a <CODE>String</CODE>)
|
||||
* @return Returns the new section.
|
||||
*/
|
||||
public override Section AddSection(String title) {
|
||||
if (AddedCompletely) {
|
||||
throw new InvalidOperationException("This LargeElement has already been added to the Document.");
|
||||
}
|
||||
return AddSection(title, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new section for this chapter and add it.
|
||||
*
|
||||
* @param title the Section title (as a <CODE>Paragraph</CODE>)
|
||||
* @return Returns the new section.
|
||||
*/
|
||||
public override Section AddSection(Paragraph title) {
|
||||
if (AddedCompletely) {
|
||||
throw new InvalidOperationException("This LargeElement has already been added to the Document.");
|
||||
}
|
||||
return AddSection(title, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
733
iTechSharp/iTextSharp/text/Chunk.cs
Normal file
733
iTechSharp/iTextSharp/text/Chunk.cs
Normal file
@@ -0,0 +1,733 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using System.util;
|
||||
|
||||
using iTextSharp.text.pdf;
|
||||
using iTextSharp.text.html;
|
||||
using iTextSharp.text.factories;
|
||||
using iTextSharp.text.pdf.draw;
|
||||
|
||||
/*
|
||||
* $Id: Chunk.cs,v 1.20 2008/05/13 11:25:09 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text {
|
||||
/// <summary>
|
||||
/// This is the smallest significant part of text that can be added to a document.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Most elements can be divided in one or more Chunks.
|
||||
/// A chunk is a string with a certain Font.
|
||||
/// all other layoutparameters should be defined in the object to which
|
||||
/// this chunk of text is added.
|
||||
/// </remarks>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// <strong>Chunk chunk = new Chunk("Hello world", FontFactory.GetFont(FontFactory.COURIER, 20, Font.ITALIC, new Color(255, 0, 0)));</strong>
|
||||
/// document.Add(chunk);
|
||||
/// </code>
|
||||
/// </example>
|
||||
public class Chunk : IElement {
|
||||
|
||||
// public static membervariables
|
||||
|
||||
/** The character stand in for an image or a separator. */
|
||||
public const string OBJECT_REPLACEMENT_CHARACTER = "\ufffc";
|
||||
|
||||
///<summary> This is a Chunk containing a newline. </summary>
|
||||
public static readonly Chunk NEWLINE = new Chunk("\n");
|
||||
|
||||
/** This is a Chunk containing a newpage. */
|
||||
public static readonly Chunk NEXTPAGE = new Chunk("");
|
||||
static Chunk() {
|
||||
NEXTPAGE.SetNewPage();
|
||||
}
|
||||
|
||||
|
||||
// member variables
|
||||
|
||||
///<summary> This is the content of this chunk of text. </summary>
|
||||
protected StringBuilder content = null;
|
||||
|
||||
///<summary> This is the Font of this chunk of text. </summary>
|
||||
protected Font font = null;
|
||||
|
||||
///<summary> Contains some of the attributes for this Chunk. </summary>
|
||||
protected Hashtable attributes = null;
|
||||
|
||||
// constructors
|
||||
|
||||
/// <summary>
|
||||
/// Empty constructor.
|
||||
/// </summary>
|
||||
/// <overloads>
|
||||
/// Has six overloads.
|
||||
/// </overloads>
|
||||
public Chunk() {
|
||||
this.content = new StringBuilder();
|
||||
this.font = new Font();
|
||||
}
|
||||
|
||||
/**
|
||||
* A <CODE>Chunk</CODE> copy constructor.
|
||||
* @param ck the <CODE>Chunk</CODE> to be copied
|
||||
*/
|
||||
public Chunk(Chunk ck) {
|
||||
if (ck.content != null) {
|
||||
content = new StringBuilder(ck.content.ToString());
|
||||
}
|
||||
if (ck.font != null) {
|
||||
font = new Font(ck.font);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a chunk of text with a certain content and a certain Font.
|
||||
/// </summary>
|
||||
/// <param name="content">the content</param>
|
||||
/// <param name="font">the font</param>
|
||||
public Chunk(string content, Font font) {
|
||||
this.content = new StringBuilder(content);
|
||||
this.font = font;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a chunk of text with a certain content, without specifying a Font.
|
||||
/// </summary>
|
||||
/// <param name="content">the content</param>
|
||||
public Chunk(string content) : this(content, new Font()) {}
|
||||
|
||||
/**
|
||||
* Constructs a chunk of text with a char and a certain <CODE>Font</CODE>.
|
||||
*
|
||||
* @param c the content
|
||||
* @param font the font
|
||||
*/
|
||||
public Chunk(char c, Font font) {
|
||||
this.content = new StringBuilder();
|
||||
this.content.Append(c);
|
||||
this.font = font;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a chunk of text with a char, without specifying a <CODE>Font</CODE>.
|
||||
*
|
||||
* @param c the content
|
||||
*/
|
||||
public Chunk(char c) : this(c, new Font()) {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a chunk containing an Image.
|
||||
/// </summary>
|
||||
/// <param name="image">the image</param>
|
||||
/// <param name="offsetX">the image offset in the x direction</param>
|
||||
/// <param name="offsetY">the image offset in the y direction</param>
|
||||
public Chunk(Image image, float offsetX, float offsetY) : this(OBJECT_REPLACEMENT_CHARACTER, new Font()) {
|
||||
Image copyImage = Image.GetInstance(image);
|
||||
copyImage.SetAbsolutePosition(float.NaN, float.NaN);
|
||||
SetAttribute(IMAGE, new Object[]{copyImage, offsetX, offsetY, false});
|
||||
}
|
||||
|
||||
/**
|
||||
* Key for drawInterface of the Separator.
|
||||
* @since 2.1.2
|
||||
*/
|
||||
public const String SEPARATOR = "SEPARATOR";
|
||||
|
||||
/**
|
||||
* Creates a separator Chunk.
|
||||
* Note that separator chunks can't be used in combination with tab chunks!
|
||||
* @param separator the drawInterface to use to draw the separator.
|
||||
* @since 2.1.2
|
||||
*/
|
||||
public Chunk(IDrawInterface separator) : this(separator, false) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a separator Chunk.
|
||||
* Note that separator chunks can't be used in combination with tab chunks!
|
||||
* @param separator the drawInterface to use to draw the separator.
|
||||
* @param vertical true if this is a vertical separator
|
||||
* @since 2.1.2
|
||||
*/
|
||||
public Chunk(IDrawInterface separator, bool vertical) : this(OBJECT_REPLACEMENT_CHARACTER, new Font()) {
|
||||
SetAttribute(SEPARATOR, new Object[] {separator, vertical});
|
||||
}
|
||||
|
||||
/**
|
||||
* Key for drawInterface of the tab.
|
||||
* @since 2.1.2
|
||||
*/
|
||||
public const String TAB = "TAB";
|
||||
|
||||
/**
|
||||
* Creates a tab Chunk.
|
||||
* Note that separator chunks can't be used in combination with tab chunks!
|
||||
* @param separator the drawInterface to use to draw the tab.
|
||||
* @param tabPosition an X coordinate that will be used as start position for the next Chunk.
|
||||
* @since 2.1.2
|
||||
*/
|
||||
public Chunk(IDrawInterface separator, float tabPosition) : this(separator, tabPosition, false) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a tab Chunk.
|
||||
* Note that separator chunks can't be used in combination with tab chunks!
|
||||
* @param separator the drawInterface to use to draw the tab.
|
||||
* @param tabPosition an X coordinate that will be used as start position for the next Chunk.
|
||||
* @param newline if true, a newline will be added if the tabPosition has already been reached.
|
||||
* @since 2.1.2
|
||||
*/
|
||||
public Chunk(IDrawInterface separator, float tabPosition, bool newline) : this(OBJECT_REPLACEMENT_CHARACTER, new Font()) {
|
||||
if (tabPosition < 0) {
|
||||
throw new ArgumentException("A tab position may not be lower than 0; yours is " + tabPosition);
|
||||
}
|
||||
SetAttribute(TAB, new Object[] {separator, tabPosition, newline, 0});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a chunk containing an Image.
|
||||
/// </summary>
|
||||
/// <param name="image">the image</param>
|
||||
/// <param name="offsetX">the image offset in the x direction</param>
|
||||
/// <param name="offsetY">the image offset in the y direction</param>
|
||||
/// <param name="changeLeading">true if the leading has to be adapted to the image</param>
|
||||
public Chunk(Image image, float offsetX, float offsetY, bool changeLeading) : this(OBJECT_REPLACEMENT_CHARACTER, new Font()) {
|
||||
SetAttribute(IMAGE, new Object[]{image, offsetX, offsetY, changeLeading});
|
||||
}
|
||||
|
||||
// implementation of the Element-methods
|
||||
|
||||
/// <summary>
|
||||
/// Processes the element by adding it (or the different parts) to an
|
||||
/// IElementListener.
|
||||
/// </summary>
|
||||
/// <param name="listener">an IElementListener</param>
|
||||
/// <returns>true if the element was processed successfully</returns>
|
||||
public bool Process(IElementListener listener) {
|
||||
try {
|
||||
return listener.Add(this);
|
||||
}
|
||||
catch (DocumentException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of the text element.
|
||||
/// </summary>
|
||||
/// <value>a type</value>
|
||||
public int Type {
|
||||
get {
|
||||
return Element.CHUNK;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the chunks in this element.
|
||||
/// </summary>
|
||||
/// <value>an ArrayList</value>
|
||||
public ArrayList Chunks {
|
||||
get {
|
||||
ArrayList tmp = new ArrayList();
|
||||
tmp.Add(this);
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
|
||||
// methods
|
||||
|
||||
/// <summary>
|
||||
/// appends some text to this Chunk.
|
||||
/// </summary>
|
||||
/// <param name="str">a string</param>
|
||||
/// <returns>a StringBuilder</returns>
|
||||
public StringBuilder Append(string str) {
|
||||
return content.Append(str);
|
||||
}
|
||||
|
||||
// methods to retrieve information
|
||||
|
||||
/// <summary>
|
||||
/// Get/set the font of this Chunk.
|
||||
/// </summary>
|
||||
/// <value>a Font</value>
|
||||
public virtual Font Font {
|
||||
get {
|
||||
return font;
|
||||
}
|
||||
|
||||
set {
|
||||
this.font = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns the content of this Chunk.
|
||||
/// </summary>
|
||||
/// <value>a string</value>
|
||||
public virtual string Content {
|
||||
get {
|
||||
return content.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return content.ToString();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Checks is this Chunk is empty.
|
||||
/// </summary>
|
||||
/// <returns>false if the Chunk contains other characters than space.</returns>
|
||||
public virtual bool IsEmpty() {
|
||||
return (content.ToString().Trim().Length == 0) && (content.ToString().IndexOf("\n") == -1) && (attributes == null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the width of the Chunk in points.
|
||||
* @return a width in points
|
||||
*/
|
||||
public float GetWidthPoint() {
|
||||
if (GetImage() != null) {
|
||||
return GetImage().ScaledWidth;
|
||||
}
|
||||
return font.GetCalculatedBaseFont(true).GetWidthPoint(Content, font.CalculatedSize) * HorizontalScaling;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks the attributes of this Chunk.
|
||||
/// </summary>
|
||||
/// <returns>false if there aren't any.</returns>
|
||||
public bool HasAttributes() {
|
||||
return attributes != null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the attributes for this Chunk.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// It may be null.
|
||||
/// </remarks>
|
||||
/// <value>a Hashtable</value>
|
||||
public Hashtable Attributes {
|
||||
get {
|
||||
return attributes;
|
||||
}
|
||||
set {
|
||||
attributes = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets an arbitrary attribute.
|
||||
/// </summary>
|
||||
/// <param name="name">the key for the attribute</param>
|
||||
/// <param name="obj">the value of the attribute</param>
|
||||
/// <returns>this Chunk</returns>
|
||||
private Chunk SetAttribute(string name, Object obj) {
|
||||
if (attributes == null)
|
||||
attributes = new Hashtable();
|
||||
attributes[name] = obj;
|
||||
return this;
|
||||
}
|
||||
|
||||
/** Key for text horizontal scaling. */
|
||||
public const string HSCALE = "HSCALE";
|
||||
|
||||
/**
|
||||
* Sets the text horizontal scaling. A value of 1 is normal and a value of 0.5f
|
||||
* shrinks the text to half it's width.
|
||||
* @param scale the horizontal scaling factor
|
||||
* @return this <CODE>Chunk</CODE>
|
||||
*/
|
||||
public Chunk SetHorizontalScaling(float scale) {
|
||||
return SetAttribute(HSCALE, scale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the horizontal scaling.
|
||||
* @return a percentage in float
|
||||
*/
|
||||
public float HorizontalScaling {
|
||||
get {
|
||||
if (attributes == null) return 1f;
|
||||
Object f = attributes[HSCALE];
|
||||
if (f == null) return 1f;
|
||||
return (float)f;
|
||||
}
|
||||
}
|
||||
|
||||
///<summary> Key for underline. </summary>
|
||||
public const string UNDERLINE = "UNDERLINE";
|
||||
|
||||
/**
|
||||
* Sets an horizontal line that can be an underline or a strikethrough.
|
||||
* Actually, the line can be anywhere vertically and has always the
|
||||
* <CODE>Chunk</CODE> width. Multiple call to this method will
|
||||
* produce multiple lines.
|
||||
* @param thickness the absolute thickness of the line
|
||||
* @param yPosition the absolute y position relative to the baseline
|
||||
* @return this <CODE>Chunk</CODE>
|
||||
*/
|
||||
public Chunk SetUnderline(float thickness, float yPosition) {
|
||||
return SetUnderline(null, thickness, 0f, yPosition, 0f, PdfContentByte.LINE_CAP_BUTT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an horizontal line that can be an underline or a strikethrough.
|
||||
* Actually, the line can be anywhere vertically and has always the
|
||||
* <CODE>Chunk</CODE> width. Multiple call to this method will
|
||||
* produce multiple lines.
|
||||
* @param color the color of the line or <CODE>null</CODE> to follow
|
||||
* the text color
|
||||
* @param thickness the absolute thickness of the line
|
||||
* @param thicknessMul the thickness multiplication factor with the font size
|
||||
* @param yPosition the absolute y position relative to the baseline
|
||||
* @param yPositionMul the position multiplication factor with the font size
|
||||
* @param cap the end line cap. Allowed values are
|
||||
* PdfContentByte.LINE_CAP_BUTT, PdfContentByte.LINE_CAP_ROUND and
|
||||
* PdfContentByte.LINE_CAP_PROJECTING_SQUARE
|
||||
* @return this <CODE>Chunk</CODE>
|
||||
*/
|
||||
public Chunk SetUnderline(Color color, float thickness, float thicknessMul, float yPosition, float yPositionMul, int cap) {
|
||||
if (attributes == null)
|
||||
attributes = new Hashtable();
|
||||
Object[] obj = {color, new float[]{thickness, thicknessMul, yPosition, yPositionMul, (float)cap}};
|
||||
Object[][] unders = Utilities.AddToArray((Object[][])attributes[UNDERLINE], obj);
|
||||
return SetAttribute(UNDERLINE, unders);
|
||||
}
|
||||
|
||||
///<summary> Key for sub/basescript. </summary>
|
||||
public const string SUBSUPSCRIPT = "SUBSUPSCRIPT";
|
||||
|
||||
/// <summary>
|
||||
/// Sets the text displacement relative to the baseline. Positive values rise the text,
|
||||
/// negative values lower the text.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// It can be used to implement sub/basescript.
|
||||
/// </remarks>
|
||||
/// <param name="rise">the displacement in points</param>
|
||||
/// <returns>this Chunk</returns>
|
||||
public Chunk SetTextRise(float rise) {
|
||||
return SetAttribute(SUBSUPSCRIPT, rise);
|
||||
}
|
||||
|
||||
public float GetTextRise() {
|
||||
if (attributes != null && attributes.ContainsKey(SUBSUPSCRIPT)) {
|
||||
return (float)attributes[SUBSUPSCRIPT];
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
///<summary> Key for text skewing. </summary>
|
||||
public const string SKEW = "SKEW";
|
||||
|
||||
/**
|
||||
* Skews the text to simulate italic and other effects.
|
||||
* Try <CODE>alpha=0</CODE> and <CODE>beta=12</CODE>.
|
||||
* @param alpha the first angle in degrees
|
||||
* @param beta the second angle in degrees
|
||||
* @return this <CODE>Chunk</CODE>
|
||||
*/
|
||||
public Chunk SetSkew(float alpha, float beta) {
|
||||
alpha = (float)Math.Tan(alpha * Math.PI / 180);
|
||||
beta = (float)Math.Tan(beta * Math.PI / 180);
|
||||
return SetAttribute(SKEW, new float[]{alpha, beta});
|
||||
}
|
||||
|
||||
///<summary> Key for background. </summary>
|
||||
public const string BACKGROUND = "BACKGROUND";
|
||||
|
||||
/// <summary>
|
||||
/// Sets the color of the background Chunk.
|
||||
/// </summary>
|
||||
/// <param name="color">the color of the background</param>
|
||||
/// <returns>this Chunk</returns>
|
||||
public Chunk SetBackground(Color color) {
|
||||
return SetBackground(color, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
/** Sets the color and the size of the background <CODE>Chunk</CODE>.
|
||||
* @param color the color of the background
|
||||
* @param extraLeft increase the size of the rectangle in the left
|
||||
* @param extraBottom increase the size of the rectangle in the bottom
|
||||
* @param extraRight increase the size of the rectangle in the right
|
||||
* @param extraTop increase the size of the rectangle in the top
|
||||
* @return this <CODE>Chunk</CODE>
|
||||
*/
|
||||
public Chunk SetBackground(Color color, float extraLeft, float extraBottom, float extraRight, float extraTop) {
|
||||
return SetAttribute(BACKGROUND, new Object[]{color, new float[]{extraLeft, extraBottom, extraRight, extraTop}});
|
||||
}
|
||||
|
||||
///<summary> Key for text rendering mode.</summary>
|
||||
public const string TEXTRENDERMODE = "TEXTRENDERMODE";
|
||||
|
||||
/** Sets the text rendering mode. It can outline text, simulate bold and make
|
||||
* text invisible.
|
||||
* @param mode the text rendering mode. It can be <CODE>PdfContentByte.TEXT_RENDER_MODE_FILL</CODE>,
|
||||
* <CODE>PdfContentByte.TEXT_RENDER_MODE_STROKE</CODE>, <CODE>PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE</CODE>
|
||||
* and <CODE>PdfContentByte.TEXT_RENDER_MODE_INVISIBLE</CODE>.
|
||||
* @param strokeWidth the stroke line width for the modes <CODE>PdfContentByte.TEXT_RENDER_MODE_STROKE</CODE> and
|
||||
* <CODE>PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE</CODE>.
|
||||
* @param strokeColor the stroke color or <CODE>null</CODE> to follow the text color
|
||||
* @return this <CODE>Chunk</CODE>
|
||||
*/
|
||||
public Chunk SetTextRenderMode(int mode, float strokeWidth, Color strokeColor) {
|
||||
return SetAttribute(TEXTRENDERMODE, new Object[]{mode, strokeWidth, strokeColor});
|
||||
}
|
||||
|
||||
///<summary> Key for split character. </summary>
|
||||
public const string SPLITCHARACTER = "SPLITCHARACTER";
|
||||
|
||||
/// <summary>
|
||||
/// Sets the split characters.
|
||||
/// </summary>
|
||||
/// <param name="splitCharacter">the SplitCharacter interface</param>
|
||||
/// <returns>this Chunk</returns>
|
||||
public Chunk SetSplitCharacter(ISplitCharacter splitCharacter) {
|
||||
return SetAttribute(SPLITCHARACTER, splitCharacter);
|
||||
}
|
||||
|
||||
///<summary> Key for hyphenation. </summary>
|
||||
public const string HYPHENATION = "HYPHENATION";
|
||||
|
||||
/// <summary>
|
||||
/// sets the hyphenation engine to this Chunk.
|
||||
/// </summary>
|
||||
/// <param name="hyphenation">the hyphenation engine</param>
|
||||
/// <returns>this Chunk</returns>
|
||||
public Chunk SetHyphenation(IHyphenationEvent hyphenation) {
|
||||
return SetAttribute(HYPHENATION, hyphenation);
|
||||
}
|
||||
|
||||
///<summary> Key for remote goto. </summary>
|
||||
public const string REMOTEGOTO = "REMOTEGOTO";
|
||||
|
||||
/// <summary>
|
||||
/// Sets a goto for a remote destination for this Chunk.
|
||||
/// </summary>
|
||||
/// <param name="filename">the file name of the destination document</param>
|
||||
/// <param name="name">the name of the destination to go to</param>
|
||||
/// <returns>this Chunk</returns>
|
||||
public Chunk SetRemoteGoto(string filename, string name) {
|
||||
return SetAttribute(REMOTEGOTO, new Object[]{filename, name});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets a goto for a remote destination for this Chunk.
|
||||
/// </summary>
|
||||
/// <param name="filename">the file name of the destination document</param>
|
||||
/// <param name="page">the page of the destination to go to. First page is 1</param>
|
||||
/// <returns>this Chunk</returns>
|
||||
public Chunk SetRemoteGoto(string filename, int page) {
|
||||
return SetAttribute(REMOTEGOTO, new Object[]{filename, page});
|
||||
}
|
||||
|
||||
///<summary> Key for local goto. </summary>
|
||||
public const string LOCALGOTO = "LOCALGOTO";
|
||||
|
||||
/// <summary>
|
||||
/// Sets a local goto for this Chunk.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// There must be a local destination matching the name.
|
||||
/// </remarks>
|
||||
/// <param name="name">the name of the destination to go to</param>
|
||||
/// <returns>this Chunk</returns>
|
||||
public Chunk SetLocalGoto(string name) {
|
||||
return SetAttribute(LOCALGOTO, name);
|
||||
}
|
||||
|
||||
///<summary> Key for local destination. </summary>
|
||||
public const string LOCALDESTINATION = "LOCALDESTINATION";
|
||||
|
||||
/// <summary>
|
||||
/// Sets a local destination for this Chunk.
|
||||
/// </summary>
|
||||
/// <param name="name">the name for this destination</param>
|
||||
/// <returns>this Chunk</returns>
|
||||
public Chunk SetLocalDestination(string name) {
|
||||
return SetAttribute(LOCALDESTINATION, name);
|
||||
}
|
||||
|
||||
///<summary> Key for generic tag. </summary>
|
||||
public const string GENERICTAG = "GENERICTAG";
|
||||
|
||||
/// <summary>
|
||||
/// Sets the generic tag Chunk.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The text for this tag can be retrieved with PdfPageEvent.
|
||||
/// </remarks>
|
||||
/// <param name="text">the text for the tag</param>
|
||||
/// <returns>this Chunk</returns>
|
||||
public Chunk SetGenericTag(string text) {
|
||||
return SetAttribute(GENERICTAG, text);
|
||||
}
|
||||
|
||||
///<summary> Key for image. </summary>
|
||||
public const string IMAGE = "IMAGE";
|
||||
|
||||
/// <summary>
|
||||
/// Returns the image.
|
||||
/// </summary>
|
||||
/// <value>an Image</value>
|
||||
public Image GetImage() {
|
||||
if (attributes == null) return null;
|
||||
Object[] obj = (Object[])attributes[Chunk.IMAGE];
|
||||
if (obj == null)
|
||||
return null;
|
||||
else {
|
||||
return (Image)obj[0];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a given tag corresponds with this object.
|
||||
/// </summary>
|
||||
/// <param name="tag">the given tag</param>
|
||||
/// <returns>true if the tag corresponds</returns>
|
||||
public static bool IsTag(string tag) {
|
||||
return ElementTags.CHUNK.Equals(tag);
|
||||
}
|
||||
|
||||
///<summary> Key for Action. </summary>
|
||||
public const string ACTION = "ACTION";
|
||||
|
||||
/// <summary>
|
||||
/// Sets an action for this Chunk.
|
||||
/// </summary>
|
||||
/// <param name="action">the action</param>
|
||||
/// <returns>this Chunk</returns>
|
||||
public Chunk SetAction(PdfAction action) {
|
||||
return SetAttribute(ACTION, action);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets an anchor for this Chunk.
|
||||
/// </summary>
|
||||
/// <param name="url">the Uri to link to</param>
|
||||
/// <returns>this Chunk</returns>
|
||||
public Chunk SetAnchor(Uri url) {
|
||||
return SetAttribute(ACTION, new PdfAction(url));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets an anchor for this Chunk.
|
||||
/// </summary>
|
||||
/// <param name="url">the url to link to</param>
|
||||
/// <returns>this Chunk</returns>
|
||||
public Chunk SetAnchor(string url) {
|
||||
return SetAttribute(ACTION, new PdfAction(url));
|
||||
}
|
||||
|
||||
///<summary> Key for newpage. </summary>
|
||||
public const string NEWPAGE = "NEWPAGE";
|
||||
|
||||
/// <summary>
|
||||
/// Sets a new page tag.
|
||||
/// </summary>
|
||||
/// <returns>this Chunk</returns>
|
||||
public Chunk SetNewPage() {
|
||||
return SetAttribute(NEWPAGE, null);
|
||||
}
|
||||
|
||||
///<summary> Key for annotation. </summary>
|
||||
public const string PDFANNOTATION = "PDFANNOTATION";
|
||||
|
||||
/// <summary>
|
||||
/// Sets a generic annotation to this Chunk.
|
||||
/// </summary>
|
||||
/// <param name="annotation">the annotation</param>
|
||||
/// <returns>this Chunk</returns>
|
||||
public Chunk SetAnnotation(PdfAnnotation annotation) {
|
||||
return SetAttribute(PDFANNOTATION, annotation);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.lowagie.text.Element#isContent()
|
||||
* @since iText 2.0.8
|
||||
*/
|
||||
public bool IsContent() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.lowagie.text.Element#isNestable()
|
||||
* @since iText 2.0.8
|
||||
*/
|
||||
public bool IsNestable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hyphenation (if present).
|
||||
* @param hyphenation a HyphenationEvent instance
|
||||
* @since 2.1.2
|
||||
*/
|
||||
public IHyphenationEvent GetHyphenation() {
|
||||
if (attributes == null) return null;
|
||||
return (IHyphenationEvent) attributes[Chunk.HYPHENATION];
|
||||
}
|
||||
|
||||
// keys used in PdfChunk
|
||||
|
||||
///<summary> Key for color. </summary>
|
||||
public const string COLOR = "COLOR";
|
||||
|
||||
///<summary> Key for encoding. </summary>
|
||||
public const string ENCODING = "ENCODING";
|
||||
}
|
||||
}
|
||||
150
iTechSharp/iTextSharp/text/Color.cs
Normal file
150
iTechSharp/iTextSharp/text/Color.cs
Normal file
@@ -0,0 +1,150 @@
|
||||
using System;
|
||||
|
||||
namespace iTextSharp.text {
|
||||
/// <summary>
|
||||
/// Base class for Color, serves as wrapper class for <see cref="T:System.Drawing.Color"/>
|
||||
/// to allow extension.
|
||||
/// </summary>
|
||||
public class Color {
|
||||
public static readonly Color WHITE = new Color(255, 255, 255);
|
||||
public static readonly Color LIGHT_GRAY = new Color(192, 192, 192);
|
||||
public static readonly Color GRAY = new Color(128, 128, 128);
|
||||
public static readonly Color DARK_GRAY = new Color(64, 64, 64);
|
||||
public static readonly Color BLACK = new Color(0, 0, 0);
|
||||
public static readonly Color RED = new Color(255, 0, 0);
|
||||
public static readonly Color PINK = new Color(255, 175, 175);
|
||||
public static readonly Color ORANGE = new Color(255, 200, 0);
|
||||
public static readonly Color YELLOW = new Color(255, 255, 0);
|
||||
public static readonly Color GREEN = new Color(0, 255, 0);
|
||||
public static readonly Color MAGENTA = new Color(255, 0, 255);
|
||||
public static readonly Color CYAN = new Color(0, 255, 255);
|
||||
public static readonly Color BLUE = new Color(0, 0, 255);
|
||||
private const double FACTOR = 0.7;
|
||||
System.Drawing.Color color;
|
||||
|
||||
/// <summary>
|
||||
/// Constuctor for Color object.
|
||||
/// </summary>
|
||||
/// <param name="red">The red component value for the new Color structure. Valid values are 0 through 255.</param>
|
||||
/// <param name="green">The green component value for the new Color structure. Valid values are 0 through 255.</param>
|
||||
/// <param name="blue">The blue component value for the new Color structure. Valid values are 0 through 255.</param>
|
||||
public Color(int red, int green, int blue) {
|
||||
color = System.Drawing.Color.FromArgb(red, green, blue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constuctor for Color object.
|
||||
/// </summary>
|
||||
/// <param name="red">The red component value for the new Color structure. Valid values are 0 through 255.</param>
|
||||
/// <param name="green">The green component value for the new Color structure. Valid values are 0 through 255.</param>
|
||||
/// <param name="blue">The blue component value for the new Color structure. Valid values are 0 through 255.</param>
|
||||
/// <param name="alpha">The transparency component value for the new Color structure. Valid values are 0 through 255.</param>
|
||||
public Color(int red, int green, int blue, int alpha) {
|
||||
color = System.Drawing.Color.FromArgb(alpha, red, green, blue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for Color object
|
||||
/// </summary>
|
||||
/// <param name="red">The red component value for the new Color structure. Valid values are 0 through 1.</param>
|
||||
/// <param name="green">The green component value for the new Color structure. Valid values are 0 through 1.</param>
|
||||
/// <param name="blue">The blue component value for the new Color structure. Valid values are 0 through 1.</param>
|
||||
public Color(float red, float green, float blue) {
|
||||
color = System.Drawing.Color.FromArgb((int)(red * 255 + .5), (int)(green * 255 + .5), (int)(blue * 255 + .5));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for Color object
|
||||
/// </summary>
|
||||
/// <param name="red">The red component value for the new Color structure. Valid values are 0 through 1.</param>
|
||||
/// <param name="green">The green component value for the new Color structure. Valid values are 0 through 1.</param>
|
||||
/// <param name="blue">The blue component value for the new Color structure. Valid values are 0 through 1.</param>
|
||||
/// <param name="alpha">The transparency component value for the new Color structure. Valid values are 0 through 1.</param>
|
||||
public Color(float red, float green, float blue, float alpha) {
|
||||
color = System.Drawing.Color.FromArgb((int)(alpha * 255 + .5), (int)(red * 255 + .5), (int)(green * 255 + .5), (int)(blue * 255 + .5));
|
||||
}
|
||||
|
||||
public Color(int argb) {
|
||||
color = System.Drawing.Color.FromArgb(argb);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for Color object
|
||||
/// </summary>
|
||||
/// <param name="color">a Color object</param>
|
||||
/// <overloads>
|
||||
/// Has three overloads.
|
||||
/// </overloads>
|
||||
public Color(System.Drawing.Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the red component value of this <see cref="T:System.Drawing.Color"/> structure.
|
||||
/// </summary>
|
||||
/// <value>The red component value of this <see cref="T:System.Drawing.Color"/> structure.</value>
|
||||
public int R {
|
||||
get {
|
||||
return color.R;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the green component value of this <see cref="T:System.Drawing.Color"/> structure.
|
||||
/// </summary>
|
||||
/// <value>The green component value of this <see cref="T:System.Drawing.Color"/> structure.</value>
|
||||
public int G {
|
||||
get {
|
||||
return color.G;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the blue component value of this <see cref="T:System.Drawing.Color"/> structure.
|
||||
/// </summary>
|
||||
/// <value>The blue component value of this <see cref="T:System.Drawing.Color"/> structure.</value>
|
||||
public int B {
|
||||
get {
|
||||
return color.B;
|
||||
}
|
||||
}
|
||||
|
||||
public Color Brighter() {
|
||||
int r = color.R;
|
||||
int g = color.G;
|
||||
int b = color.B;
|
||||
|
||||
int i = (int)(1.0/(1.0-FACTOR));
|
||||
if ( r == 0 && g == 0 && b == 0) {
|
||||
return new Color(i, i, i);
|
||||
}
|
||||
if ( r > 0 && r < i ) r = i;
|
||||
if ( g > 0 && g < i ) g = i;
|
||||
if ( b > 0 && b < i ) b = i;
|
||||
|
||||
return new Color(Math.Min((int)(r/FACTOR), 255),
|
||||
Math.Min((int)(g/FACTOR), 255),
|
||||
Math.Min((int)(b/FACTOR), 255));
|
||||
}
|
||||
|
||||
public Color Darker() {
|
||||
return new Color(Math.Max((int)(color.R * FACTOR), 0),
|
||||
Math.Max((int)(color.G * FACTOR), 0),
|
||||
Math.Max((int)(color.B * FACTOR), 0));
|
||||
}
|
||||
|
||||
public override bool Equals(object obj) {
|
||||
if (!(obj is Color))
|
||||
return false;
|
||||
return color.Equals(((Color)obj).color);
|
||||
}
|
||||
|
||||
public override int GetHashCode() {
|
||||
return color.GetHashCode();
|
||||
}
|
||||
|
||||
public int ToArgb() {
|
||||
return color.ToArgb();
|
||||
}
|
||||
}
|
||||
}
|
||||
416
iTechSharp/iTextSharp/text/DocWriter.cs
Normal file
416
iTechSharp/iTextSharp/text/DocWriter.cs
Normal file
@@ -0,0 +1,416 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.util;
|
||||
using iTextSharp.text.pdf;
|
||||
/*
|
||||
* $Id: DocWriter.cs,v 1.7 2008/05/13 11:25:09 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text {
|
||||
/// <summary>
|
||||
/// An abstract Writer class for documents.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// DocWriter is the abstract class of several writers such
|
||||
/// as PdfWriter and HtmlWriter.
|
||||
/// A DocWriter can be added as a DocListener
|
||||
/// to a certain Document by getting an instance (see method
|
||||
/// GetInstance() in the specific writer-classes).
|
||||
/// Every Element added to the original Document
|
||||
/// will be written to the stream of the listening
|
||||
/// DocWriter.
|
||||
/// </remarks>
|
||||
/// <seealso cref="T:iTextSharp.text.Document"/>
|
||||
/// <seealso cref="T:iTextSharp.text.IDocListener"/>
|
||||
public abstract class DocWriter : IDocListener {
|
||||
|
||||
/// <summary> This is some byte that is often used. </summary>
|
||||
public const byte NEWLINE = (byte)'\n';
|
||||
|
||||
/// <summary> This is some byte that is often used. </summary>
|
||||
public const byte TAB = (byte)'\t';
|
||||
|
||||
/// <summary> This is some byte that is often used. </summary>
|
||||
public const byte LT = (byte)'<';
|
||||
|
||||
/// <summary> This is some byte that is often used. </summary>
|
||||
public const byte SPACE = (byte)' ';
|
||||
|
||||
/// <summary> This is some byte that is often used. </summary>
|
||||
public const byte EQUALS = (byte)'=';
|
||||
|
||||
/// <summary> This is some byte that is often used. </summary>
|
||||
public const byte QUOTE = (byte)'\"';
|
||||
|
||||
/// <summary> This is some byte that is often used. </summary>
|
||||
public const byte GT = (byte)'>';
|
||||
|
||||
/// <summary> This is some byte that is often used. </summary>
|
||||
public const byte FORWARD = (byte)'/';
|
||||
|
||||
// membervariables
|
||||
|
||||
/// <summary> The pageSize. </summary>
|
||||
protected Rectangle pageSize;
|
||||
|
||||
/// <summary> This is the document that has to be written. </summary>
|
||||
protected Document document;
|
||||
|
||||
/// <summary> The stream of this writer. </summary>
|
||||
protected OutputStreamCounter os;
|
||||
|
||||
/// <summary> Is the writer open for writing? </summary>
|
||||
protected bool open = false;
|
||||
|
||||
/// <summary> Do we have to pause all writing actions? </summary>
|
||||
protected bool pause = false;
|
||||
|
||||
/** Closes the stream on document close */
|
||||
protected bool closeStream = true;
|
||||
|
||||
// constructor
|
||||
|
||||
protected DocWriter() {
|
||||
}
|
||||
/// <summary>
|
||||
/// Constructs a DocWriter.
|
||||
/// </summary>
|
||||
/// <param name="document">The Document that has to be written</param>
|
||||
/// <param name="os">The Stream the writer has to write to.</param>
|
||||
protected DocWriter(Document document, Stream os)
|
||||
{
|
||||
this.document = document;
|
||||
this.os = new OutputStreamCounter(os);
|
||||
}
|
||||
|
||||
// implementation of the DocListener methods
|
||||
|
||||
/// <summary>
|
||||
/// Signals that an Element was added to the Document.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method should be overriden in the specific DocWriter classes
|
||||
/// derived from this abstract class.
|
||||
/// </remarks>
|
||||
/// <param name="element"></param>
|
||||
/// <returns>false</returns>
|
||||
public virtual bool Add(IElement element) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Signals that the Document was opened.
|
||||
/// </summary>
|
||||
public virtual void Open() {
|
||||
open = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the pagesize.
|
||||
/// </summary>
|
||||
/// <param name="pageSize">the new pagesize</param>
|
||||
/// <returns>a boolean</returns>
|
||||
public virtual bool SetPageSize(Rectangle pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the margins.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This does nothing. Has to be overridden if needed.
|
||||
/// </remarks>
|
||||
/// <param name="marginLeft">the margin on the left</param>
|
||||
/// <param name="marginRight">the margin on the right</param>
|
||||
/// <param name="marginTop">the margin on the top</param>
|
||||
/// <param name="marginBottom">the margin on the bottom</param>
|
||||
/// <returns></returns>
|
||||
public virtual bool SetMargins(float marginLeft, float marginRight, float marginTop, float marginBottom) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Signals that an new page has to be started.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This does nothing. Has to be overridden if needed.
|
||||
/// </remarks>
|
||||
/// <returns>true if the page was added, false if not.</returns>
|
||||
public virtual bool NewPage() {
|
||||
if (!open) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the header of this document.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method should be overriden in the specific DocWriter classes
|
||||
/// derived from this abstract class if they actually support the use of
|
||||
/// headers.
|
||||
/// </remarks>
|
||||
/// <value>the new header</value>
|
||||
public virtual HeaderFooter Header {
|
||||
set {}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the header of this document.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method should be overriden in the specific DocWriter classes
|
||||
/// derived from this abstract class if they actually support the use of
|
||||
/// headers.
|
||||
/// </remarks>
|
||||
public virtual void ResetHeader() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the footer of this document.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method should be overriden in the specific DocWriter classes
|
||||
/// derived from this abstract class if they actually support the use of
|
||||
/// footers.
|
||||
/// </remarks>
|
||||
/// <value>the new footer</value>
|
||||
public virtual HeaderFooter Footer {
|
||||
set {}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the footer of this document.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method should be overriden in the specific DocWriter classes
|
||||
/// derived from this abstract class if they actually support the use of
|
||||
/// footers.
|
||||
/// </remarks>
|
||||
public virtual void ResetFooter() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the page number to 0.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method should be overriden in the specific DocWriter classes
|
||||
/// derived from this abstract class if they actually support the use of
|
||||
/// pagenumbers.
|
||||
/// </remarks>
|
||||
public virtual void ResetPageCount() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the page number.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method should be overriden in the specific DocWriter classes
|
||||
/// derived from this abstract class if they actually support the use of
|
||||
/// pagenumbers.
|
||||
/// </remarks>
|
||||
public virtual int PageCount {
|
||||
set {}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Signals that the Document was closed and that no other
|
||||
/// Elements will be added.
|
||||
/// </summary>
|
||||
public virtual void Close() {
|
||||
open = false;
|
||||
os.Flush();
|
||||
if (closeStream)
|
||||
os.Close();
|
||||
}
|
||||
|
||||
// methods
|
||||
|
||||
/// <summary>
|
||||
/// Converts a string into a Byte array
|
||||
/// according to the ISO-8859-1 codepage.
|
||||
/// </summary>
|
||||
/// <param name="text">the text to be converted</param>
|
||||
/// <returns>the conversion result</returns>
|
||||
public static byte[] GetISOBytes(string text) {
|
||||
if (text == null)
|
||||
return null;
|
||||
int len = text.Length;
|
||||
byte[] b = new byte[len];
|
||||
for (int k = 0; k < len; ++k)
|
||||
b[k] = (byte)text[k];
|
||||
return b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Let the writer know that all writing has to be paused.
|
||||
/// </summary>
|
||||
public virtual void Pause() {
|
||||
pause = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if writing is paused.
|
||||
*
|
||||
* @return <CODE>true</CODE> if writing temporarely has to be paused, <CODE>false</CODE> otherwise.
|
||||
*/
|
||||
|
||||
public bool IsPaused() {
|
||||
return pause;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Let the writer know that writing may be resumed.
|
||||
/// </summary>
|
||||
public virtual void Resume() {
|
||||
pause = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Flushes the Stream.
|
||||
/// </summary>
|
||||
public virtual void Flush() {
|
||||
os.Flush();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a string to the stream.
|
||||
/// </summary>
|
||||
/// <param name="str">the string to write</param>
|
||||
protected void Write(string str) {
|
||||
byte[] tmp = GetISOBytes(str);
|
||||
os.Write(tmp, 0, tmp.Length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a number of tabs.
|
||||
/// </summary>
|
||||
/// <param name="indent">the number of tabs to add</param>
|
||||
protected void AddTabs(int indent) {
|
||||
os.WriteByte(NEWLINE);
|
||||
for (int i = 0; i < indent; i++) {
|
||||
os.WriteByte(TAB);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a key-value pair to the stream.
|
||||
/// </summary>
|
||||
/// <param name="key">the name of an attribute</param>
|
||||
/// <param name="value">the value of an attribute</param>
|
||||
protected void Write(string key, string value) {
|
||||
os.WriteByte(SPACE);
|
||||
Write(key);
|
||||
os.WriteByte(EQUALS);
|
||||
os.WriteByte(QUOTE);
|
||||
Write(value);
|
||||
os.WriteByte(QUOTE);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a starttag to the stream.
|
||||
/// </summary>
|
||||
/// <param name="tag">the name of the tag</param>
|
||||
protected void WriteStart(string tag) {
|
||||
os.WriteByte(LT);
|
||||
Write(tag);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes an endtag to the stream.
|
||||
/// </summary>
|
||||
/// <param name="tag">the name of the tag</param>
|
||||
protected void WriteEnd(string tag) {
|
||||
os.WriteByte(LT);
|
||||
os.WriteByte(FORWARD);
|
||||
Write(tag);
|
||||
os.WriteByte(GT);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes an endtag to the stream.
|
||||
/// </summary>
|
||||
protected void WriteEnd() {
|
||||
os.WriteByte(SPACE);
|
||||
os.WriteByte(FORWARD);
|
||||
os.WriteByte(GT);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the markup attributes of the specified MarkupAttributes
|
||||
/// object to the stream.
|
||||
/// </summary>
|
||||
/// <param name="mAtt">the MarkupAttributes to write.</param>
|
||||
/// <returns></returns>
|
||||
protected bool WriteMarkupAttributes(Properties markup) {
|
||||
if (markup == null) return false;
|
||||
foreach (String name in markup.Keys) {
|
||||
Write(name, markup[name]);
|
||||
}
|
||||
markup.Clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual bool CloseStream {
|
||||
get {
|
||||
return closeStream;
|
||||
}
|
||||
set {
|
||||
closeStream = value;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool SetMarginMirroring(bool marginMirroring) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
684
iTechSharp/iTextSharp/text/Document.cs
Normal file
684
iTechSharp/iTextSharp/text/Document.cs
Normal file
@@ -0,0 +1,684 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
/*
|
||||
* $Id: Document.cs,v 1.45 2008/05/25 13:08:44 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text {
|
||||
|
||||
/// <summary>
|
||||
/// A generic Document class.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// All kinds of Text-elements can be added to a HTMLDocument.
|
||||
/// The Document signals all the listeners when an element
|
||||
/// has been added.<p/>
|
||||
/// <OL>
|
||||
/// <LI/>Once a document is created you can add some meta information.
|
||||
/// <LI/>You can also set the headers/footers.
|
||||
/// <LI/>You have to open the document before you can write content.
|
||||
/// <LI/>You can only write content (no more meta-formation!) once a document is opened.
|
||||
/// <LI/>When you change the header/footer on a certain page, this will be effective starting on the next page.
|
||||
/// <LI/>Ater closing the document, every listener (as well as its OutputStream) is closed too.
|
||||
/// </OL>
|
||||
/// </remarks>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// // creation of the document with a certain size and certain margins
|
||||
/// <strong>Document document = new Document(PageSize.A4, 50, 50, 50, 50);</strong>
|
||||
/// try {
|
||||
/// // creation of the different writers
|
||||
/// HtmlWriter.GetInstance(<strong>document</strong>, System.out);
|
||||
/// PdfWriter.GetInstance(<strong>document</strong>, new FileOutputStream("text.pdf"));
|
||||
/// // we add some meta information to the document
|
||||
/// <strong>document.AddAuthor("Bruno Lowagie");
|
||||
/// document.AddSubject("This is the result of a Test.");</strong>
|
||||
///
|
||||
/// // we define a header and a footer
|
||||
/// HeaderFooter header = new HeaderFooter(new Phrase("This is a header."), false);
|
||||
/// HeaderFooter footer = new HeaderFooter(new Phrase("This is page "), new Phrase("."));
|
||||
/// footer.SetAlignment(Element.ALIGN_CENTER);
|
||||
/// <strong>document.SetHeader(header);
|
||||
/// document.SetFooter(footer);</strong>
|
||||
/// // we open the document for writing
|
||||
/// <strong>document.Open();
|
||||
/// document.Add(new Paragraph("Hello world"));</strong>
|
||||
/// }
|
||||
/// catch (DocumentException de) {
|
||||
/// Console.Error.WriteLine(de.Message);
|
||||
/// }
|
||||
/// <strong>document.Close();</strong>
|
||||
/// </code>
|
||||
/// </example>
|
||||
public class Document : IDocListener {
|
||||
|
||||
// membervariables
|
||||
|
||||
///<summary> This constant may only be changed by Paulo Soares and/or Bruno Lowagie. </summary>
|
||||
private const string ITEXT_VERSION = "iTextSharp 4.1.2 (based on iText 2.1.2u)";
|
||||
|
||||
///<summary> Allows the pdf documents to be produced without compression for debugging purposes. </summary>
|
||||
public static bool Compress = true;
|
||||
|
||||
///<summary> Scales the WMF font size. The default value is 0.86. </summary>
|
||||
public static float WmfFontCorrection = 0.86f;
|
||||
|
||||
///<summary> The IDocListener. </summary>
|
||||
private ArrayList listeners = new ArrayList();
|
||||
|
||||
///<summary> Is the document open or not? </summary>
|
||||
protected bool open;
|
||||
|
||||
///<summary> Has the document allready been closed? </summary>
|
||||
protected bool close;
|
||||
|
||||
// membervariables concerning the layout
|
||||
|
||||
///<summary> The size of the page. </summary>
|
||||
protected Rectangle pageSize;
|
||||
|
||||
///<summary> margin in x direction starting from the left </summary>
|
||||
protected float marginLeft = 0;
|
||||
|
||||
///<summary> margin in x direction starting from the right </summary>
|
||||
protected float marginRight = 0;
|
||||
|
||||
///<summary> margin in y direction starting from the top </summary>
|
||||
protected float marginTop = 0;
|
||||
|
||||
///<summary> margin in y direction starting from the bottom </summary>
|
||||
protected float marginBottom = 0;
|
||||
|
||||
protected bool marginMirroring = false;
|
||||
///<summary> Content of JavaScript onLoad function </summary>
|
||||
protected string javaScript_onLoad = null;
|
||||
|
||||
///<summary> Content of JavaScript onUnLoad function </summary>
|
||||
protected string javaScript_onUnLoad = null;
|
||||
|
||||
///<summary> Style class in HTML body tag </summary>
|
||||
protected string htmlStyleClass = null;
|
||||
|
||||
// headers, footers
|
||||
|
||||
///<summary> Current pagenumber </summary>
|
||||
protected int pageN = 0;
|
||||
|
||||
///<summary> This is the textual part of a Page; it can contain a header </summary>
|
||||
protected HeaderFooter header = null;
|
||||
|
||||
///<summary> This is the textual part of the footer </summary>
|
||||
protected HeaderFooter footer = null;
|
||||
|
||||
// constructor
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new Document-object.
|
||||
/// </summary>
|
||||
/// <overloads>
|
||||
/// Has three overloads.
|
||||
/// </overloads>
|
||||
public Document() : this(iTextSharp.text.PageSize.A4) {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new Document-object.
|
||||
/// </summary>
|
||||
/// <param name="pageSize">the pageSize</param>
|
||||
public Document(Rectangle pageSize) : this(pageSize, 36, 36, 36, 36) {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new Document-object.
|
||||
/// </summary>
|
||||
/// <param name="pageSize">the pageSize</param>
|
||||
/// <param name="marginLeft">the margin on the left</param>
|
||||
/// <param name="marginRight">the margin on the right</param>
|
||||
/// <param name="marginTop">the margin on the top</param>
|
||||
/// <param name="marginBottom">the margin on the bottom</param>
|
||||
public Document(Rectangle pageSize, float marginLeft, float marginRight, float marginTop, float marginBottom) {
|
||||
this.pageSize = pageSize;
|
||||
this.marginLeft = marginLeft;
|
||||
this.marginRight = marginRight;
|
||||
this.marginTop = marginTop;
|
||||
this.marginBottom = marginBottom;
|
||||
}
|
||||
|
||||
// listener methods
|
||||
|
||||
/// <summary>
|
||||
/// Adds a IDocListener to the Document.
|
||||
/// </summary>
|
||||
/// <param name="listener">the new IDocListener</param>
|
||||
public void AddDocListener(IDocListener listener) {
|
||||
listeners.Add(listener);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a IDocListener from the Document.
|
||||
/// </summary>
|
||||
/// <param name="listener">the IDocListener that has to be removed.</param>
|
||||
public void RemoveIDocListener(IDocListener listener) {
|
||||
listeners.Remove(listener);
|
||||
}
|
||||
|
||||
// methods implementing the IDocListener interface
|
||||
|
||||
/// <summary>
|
||||
/// Adds an Element to the Document.
|
||||
/// </summary>
|
||||
/// <param name="element">the Element to add</param>
|
||||
/// <returns>true if the element was added, false if not</returns>
|
||||
public virtual bool Add(IElement element) {
|
||||
if (close) {
|
||||
throw new DocumentException("The document has been closed. You can't add any Elements.");
|
||||
}
|
||||
if (!open && element.IsContent()) {
|
||||
throw new DocumentException("The document is not open yet; you can only add Meta information.");
|
||||
}
|
||||
bool success = false;
|
||||
foreach (IDocListener listener in listeners) {
|
||||
success |= listener.Add(element);
|
||||
}
|
||||
if (element is ILargeElement) {
|
||||
ILargeElement e = (ILargeElement)element;
|
||||
if (!e.ElementComplete)
|
||||
e.FlushContent();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens the document.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Once the document is opened, you can't write any Header- or Meta-information
|
||||
/// anymore. You have to open the document before you can begin to add content
|
||||
/// to the body of the document.
|
||||
/// </remarks>
|
||||
public virtual void Open() {
|
||||
if (! close) {
|
||||
open = true;
|
||||
}
|
||||
foreach (IDocListener listener in listeners) {
|
||||
listener.SetPageSize(pageSize);
|
||||
listener.SetMargins(marginLeft, marginRight, marginTop, marginBottom);
|
||||
listener.Open();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the pagesize.
|
||||
/// </summary>
|
||||
/// <param name="pageSize">the new pagesize</param>
|
||||
/// <returns>a bool</returns>
|
||||
public virtual bool SetPageSize(Rectangle pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
foreach (IDocListener listener in listeners) {
|
||||
listener.SetPageSize(pageSize);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the margins.
|
||||
/// </summary>
|
||||
/// <param name="marginLeft">the margin on the left</param>
|
||||
/// <param name="marginRight">the margin on the right</param>
|
||||
/// <param name="marginTop">the margin on the top</param>
|
||||
/// <param name="marginBottom">the margin on the bottom</param>
|
||||
/// <returns></returns>
|
||||
public virtual bool SetMargins(float marginLeft,float marginRight,float marginTop,float marginBottom) {
|
||||
this.marginLeft = marginLeft;
|
||||
this.marginRight = marginRight;
|
||||
this.marginTop = marginTop;
|
||||
this.marginBottom = marginBottom;
|
||||
foreach (IDocListener listener in listeners) {
|
||||
listener.SetMargins(marginLeft, marginRight, marginTop, marginBottom);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Signals that an new page has to be started.
|
||||
/// </summary>
|
||||
/// <returns>true if the page was added, false if not.</returns>
|
||||
public virtual bool NewPage() {
|
||||
if (!open || close) {
|
||||
return false;
|
||||
}
|
||||
foreach (IDocListener listener in listeners) {
|
||||
listener.NewPage();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the header of this document.
|
||||
/// </summary>
|
||||
/// <value>a HeaderFooter</value>
|
||||
public virtual HeaderFooter Header {
|
||||
set {
|
||||
this.header = value;
|
||||
foreach (IDocListener listener in listeners) {
|
||||
listener.Header = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the header of this document.
|
||||
/// </summary>
|
||||
public virtual void ResetHeader() {
|
||||
this.header = null;
|
||||
foreach (IDocListener listener in listeners) {
|
||||
listener.ResetHeader();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the footer of this document.
|
||||
/// </summary>
|
||||
/// <value>a HeaderFooter</value>
|
||||
public virtual HeaderFooter Footer {
|
||||
set {
|
||||
this.footer = value;
|
||||
foreach (IDocListener listener in listeners) {
|
||||
listener.Footer = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the footer of this document.
|
||||
/// </summary>
|
||||
public virtual void ResetFooter() {
|
||||
this.footer = null;
|
||||
foreach (IDocListener listener in listeners) {
|
||||
listener.ResetFooter();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the page number to 0.
|
||||
/// </summary>
|
||||
public virtual void ResetPageCount() {
|
||||
pageN = 0;
|
||||
foreach (IDocListener listener in listeners) {
|
||||
listener.ResetPageCount();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the page number.
|
||||
/// </summary>
|
||||
/// <value>an int</value>
|
||||
public virtual int PageCount {
|
||||
set {
|
||||
this.pageN = value;
|
||||
foreach (IDocListener listener in listeners) {
|
||||
listener.PageCount = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current page number.
|
||||
/// </summary>
|
||||
/// <value>an int</value>
|
||||
public int PageNumber {
|
||||
get {
|
||||
return this.pageN;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Closes the document.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Once all the content has been written in the body, you have to close
|
||||
/// the body. After that nothing can be written to the body anymore.
|
||||
/// </remarks>
|
||||
public virtual void Close() {
|
||||
if (!close) {
|
||||
open = false;
|
||||
close = true;
|
||||
}
|
||||
foreach (IDocListener listener in listeners) {
|
||||
listener.Close();
|
||||
}
|
||||
}
|
||||
|
||||
// methods concerning the header or some meta information
|
||||
|
||||
/// <summary>
|
||||
/// Adds a user defined header to the document.
|
||||
/// </summary>
|
||||
/// <param name="name">the name of the header</param>
|
||||
/// <param name="content">the content of the header</param>
|
||||
/// <returns>true if successful, false otherwise</returns>
|
||||
public bool AddHeader(string name, string content) {
|
||||
return Add(new Header(name, content));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the title to a Document.
|
||||
/// </summary>
|
||||
/// <param name="title">the title</param>
|
||||
/// <returns>true if successful, false otherwise</returns>
|
||||
public bool AddTitle(string title) {
|
||||
return Add(new Meta(Element.TITLE, title));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the subject to a Document.
|
||||
/// </summary>
|
||||
/// <param name="subject">the subject</param>
|
||||
/// <returns>true if successful, false otherwise</returns>
|
||||
public bool AddSubject(string subject) {
|
||||
return Add(new Meta(Element.SUBJECT, subject));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the keywords to a Document.
|
||||
/// </summary>
|
||||
/// <param name="keywords">keywords to add</param>
|
||||
/// <returns>true if successful, false otherwise</returns>
|
||||
public bool AddKeywords(string keywords) {
|
||||
return Add(new Meta(Element.KEYWORDS, keywords));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the author to a Document.
|
||||
/// </summary>
|
||||
/// <param name="author">the name of the author</param>
|
||||
/// <returns>true if successful, false otherwise</returns>
|
||||
public bool AddAuthor(string author) {
|
||||
return Add(new Meta(Element.AUTHOR, author));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the creator to a Document.
|
||||
/// </summary>
|
||||
/// <param name="creator">the name of the creator</param>
|
||||
/// <returns>true if successful, false otherwise</returns>
|
||||
public bool AddCreator(string creator) {
|
||||
return Add(new Meta(Element.CREATOR, creator));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the producer to a Document.
|
||||
/// </summary>
|
||||
/// <returns>true if successful, false otherwise</returns>
|
||||
public bool AddProducer() {
|
||||
return Add(new Meta(Element.PRODUCER, "iText# by lowagie.com"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the current date and time to a Document.
|
||||
/// </summary>
|
||||
/// <returns>true if successful, false otherwise</returns>
|
||||
public bool AddCreationDate() {
|
||||
return Add(new Meta(Element.CREATIONDATE, DateTime.Now.ToString("ddd MMM dd HH:mm:ss zzz yyyy")));
|
||||
}
|
||||
|
||||
// methods to get the layout of the document.
|
||||
|
||||
/// <summary>
|
||||
/// Returns the left margin.
|
||||
/// </summary>
|
||||
/// <value>the left margin</value>
|
||||
public float LeftMargin {
|
||||
get {
|
||||
return marginLeft;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the right margin.
|
||||
/// </summary>
|
||||
/// <value>the right margin</value>
|
||||
public float RightMargin {
|
||||
get {
|
||||
return marginRight;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the top margin.
|
||||
/// </summary>
|
||||
/// <value>the top margin</value>
|
||||
public float TopMargin {
|
||||
get {
|
||||
return marginTop;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the bottom margin.
|
||||
/// </summary>
|
||||
/// <value>the bottom margin</value>
|
||||
public float BottomMargin {
|
||||
get {
|
||||
return marginBottom;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the lower left x-coordinate.
|
||||
/// </summary>
|
||||
/// <value>the lower left x-coordinate</value>
|
||||
public float Left {
|
||||
get {
|
||||
return pageSize.GetLeft(marginLeft);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the upper right x-coordinate.
|
||||
/// </summary>
|
||||
/// <value>the upper right x-coordinate.</value>
|
||||
public float Right {
|
||||
get {
|
||||
return pageSize.GetRight(marginRight);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the upper right y-coordinate.
|
||||
/// </summary>
|
||||
/// <value>the upper right y-coordinate.</value>
|
||||
public float Top {
|
||||
get {
|
||||
return pageSize.GetTop(marginTop);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the lower left y-coordinate.
|
||||
/// </summary>
|
||||
/// <value>the lower left y-coordinate.</value>
|
||||
public float Bottom {
|
||||
get {
|
||||
return pageSize.GetBottom(marginBottom);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the lower left x-coordinate considering a given margin.
|
||||
/// </summary>
|
||||
/// <param name="margin">a margin</param>
|
||||
/// <returns>the lower left x-coordinate</returns>
|
||||
public float GetLeft(float margin) {
|
||||
return pageSize.GetLeft(marginLeft + margin);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the upper right x-coordinate, considering a given margin.
|
||||
/// </summary>
|
||||
/// <param name="margin">a margin</param>
|
||||
/// <returns>the upper right x-coordinate</returns>
|
||||
public float GetRight(float margin) {
|
||||
return pageSize.GetRight(marginRight + margin);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the upper right y-coordinate, considering a given margin.
|
||||
/// </summary>
|
||||
/// <param name="margin">a margin</param>
|
||||
/// <returns>the upper right y-coordinate</returns>
|
||||
public float GetTop(float margin) {
|
||||
return pageSize.GetTop(marginTop + margin);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the lower left y-coordinate, considering a given margin.
|
||||
/// </summary>
|
||||
/// <param name="margin">a margin</param>
|
||||
/// <returns>the lower left y-coordinate</returns>
|
||||
public float GetBottom(float margin) {
|
||||
return pageSize.GetBottom(marginBottom + margin);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the pagesize.
|
||||
/// </summary>
|
||||
/// <value>the page size</value>
|
||||
public Rectangle PageSize {
|
||||
get {
|
||||
return this.pageSize;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the document is open.
|
||||
/// </summary>
|
||||
/// <returns>true if the document is open</returns>
|
||||
public bool IsOpen() {
|
||||
return open;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the iText version.
|
||||
/// </summary>
|
||||
/// <value>iText version</value>
|
||||
public static string Version {
|
||||
get {
|
||||
return ITEXT_VERSION;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the JavaScript onLoad command.
|
||||
/// </summary>
|
||||
/// <value>the JavaScript onLoad command.</value>
|
||||
public string JavaScript_onLoad {
|
||||
get {
|
||||
return this.javaScript_onLoad;
|
||||
}
|
||||
|
||||
set {
|
||||
this.javaScript_onLoad = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the JavaScript onUnLoad command.
|
||||
/// </summary>
|
||||
/// <value>the JavaScript onUnLoad command</value>
|
||||
public string JavaScript_onUnLoad {
|
||||
get {
|
||||
return this.javaScript_onUnLoad;
|
||||
}
|
||||
|
||||
set {
|
||||
this.javaScript_onUnLoad = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the style class of the HTML body tag
|
||||
/// </summary>
|
||||
/// <value>the style class of the HTML body tag</value>
|
||||
public string HtmlStyleClass {
|
||||
get {
|
||||
return this.htmlStyleClass;
|
||||
}
|
||||
|
||||
set {
|
||||
this.htmlStyleClass = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the margin mirroring. It will mirror margins for odd/even pages.
|
||||
* <p>
|
||||
* Note: it will not work with {@link Table}.
|
||||
*
|
||||
* @param marginMirroring
|
||||
* <CODE>true</CODE> to mirror the margins
|
||||
* @return always <CODE>true</CODE>
|
||||
*/
|
||||
public virtual bool SetMarginMirroring(bool marginMirroring) {
|
||||
this.marginMirroring = marginMirroring;
|
||||
foreach (IDocListener listener in listeners) {
|
||||
listener.SetMarginMirroring(marginMirroring);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the margin mirroring flag.
|
||||
*
|
||||
* @return the margin mirroring flag
|
||||
*/
|
||||
public bool IsMarginMirroring() {
|
||||
return marginMirroring;
|
||||
}
|
||||
}
|
||||
}
|
||||
77
iTechSharp/iTextSharp/text/DocumentException.cs
Normal file
77
iTechSharp/iTextSharp/text/DocumentException.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using System;
|
||||
|
||||
/*
|
||||
* $Id: DocumentException.cs,v 1.3 2008/05/13 11:25:09 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text {
|
||||
/// <summary>
|
||||
/// Signals that an error has occurred in a Document.
|
||||
/// </summary>
|
||||
/// <seealso cref="T:iTextSharp.text.BadElementException"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Document"/>
|
||||
/// <seealso cref="T:iTextSharp.text.DocWriter"/>
|
||||
/// <seealso cref="T:iTextSharp.text.IDocListener"/>
|
||||
public class DocumentException : Exception {
|
||||
/// <summary>
|
||||
/// Constructs a new DocumentException
|
||||
/// </summary>
|
||||
/// <overloads>
|
||||
/// Has two overloads.
|
||||
/// </overloads>
|
||||
public DocumentException() : base() {}
|
||||
|
||||
/// <summary>
|
||||
/// Construct a new DocumentException
|
||||
/// </summary>
|
||||
/// <param name="message">error message</param>
|
||||
public DocumentException(string message) : base(message) {}
|
||||
}
|
||||
}
|
||||
285
iTechSharp/iTextSharp/text/Element.cs
Normal file
285
iTechSharp/iTextSharp/text/Element.cs
Normal file
@@ -0,0 +1,285 @@
|
||||
using System;
|
||||
|
||||
/*
|
||||
* $Id: Element.cs,v 1.7 2008/05/13 11:25:09 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Interface for a text element.
|
||||
/// </summary>
|
||||
/// <seealso cref="T:iTextSharp.text.Anchor"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Cell"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Chapter"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Chunk"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Gif"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Graphic"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Header"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Image"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Jpeg"/>
|
||||
/// <seealso cref="T:iTextSharp.text.List"/>
|
||||
/// <seealso cref="T:iTextSharp.text.ListItem"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Meta"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Paragraph"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Phrase"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Rectangle"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Row"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Section"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Table"/>
|
||||
public class Element
|
||||
{
|
||||
|
||||
// static membervariables (meta information)
|
||||
|
||||
/// <summary> This is a possible type of Element. </summary>
|
||||
public const int HEADER = 0;
|
||||
|
||||
/// <summary> This is a possible type of Element. </summary>
|
||||
public const int TITLE = 1;
|
||||
|
||||
/// <summary> This is a possible type of Element. </summary>
|
||||
public const int SUBJECT = 2;
|
||||
|
||||
/// <summary> This is a possible type of Element. </summary>
|
||||
public const int KEYWORDS = 3;
|
||||
|
||||
/// <summary> This is a possible type of Element. </summary>
|
||||
public const int AUTHOR = 4;
|
||||
|
||||
/// <summary> This is a possible type of Element. </summary>
|
||||
public const int PRODUCER = 5;
|
||||
|
||||
/// <summary> This is a possible type of Element. </summary>
|
||||
public const int CREATIONDATE = 6;
|
||||
|
||||
/// <summary> This is a possible type of Element. </summary>
|
||||
public const int CREATOR = 7;
|
||||
|
||||
// static membervariables (content)
|
||||
|
||||
/// <summary> This is a possible type of Element. </summary>
|
||||
public const int CHUNK = 10;
|
||||
|
||||
/// <summary> This is a possible type of Element. </summary>
|
||||
public const int PHRASE = 11;
|
||||
|
||||
/// <summary> This is a possible type of Element. </summary>
|
||||
public const int PARAGRAPH = 12;
|
||||
|
||||
/// <summary> This is a possible type of Element </summary>
|
||||
public const int SECTION = 13;
|
||||
|
||||
/// <summary> This is a possible type of Element </summary>
|
||||
public const int LIST = 14;
|
||||
|
||||
/// <summary> This is a possible type of Element </summary>
|
||||
public const int LISTITEM = 15;
|
||||
|
||||
/// <summary> This is a possible type of Element </summary>
|
||||
public const int CHAPTER = 16;
|
||||
|
||||
/// <summary> This is a possible type of Element </summary>
|
||||
public const int ANCHOR = 17;
|
||||
|
||||
// static membervariables (tables)
|
||||
|
||||
/// <summary> This is a possible type of Element. </summary>
|
||||
public const int CELL = 20;
|
||||
|
||||
/// <summary> This is a possible type of Element. </summary>
|
||||
public const int ROW = 21;
|
||||
|
||||
/// <summary> This is a possible type of Element. </summary>
|
||||
public const int TABLE = 22;
|
||||
|
||||
/// <summary> This is a possible type of Element. </summary>
|
||||
public const int PTABLE = 23;
|
||||
|
||||
// static membervariables (annotations)
|
||||
|
||||
/// <summary> This is a possible type of Element. </summary>
|
||||
public const int ANNOTATION = 29;
|
||||
|
||||
// static membervariables (geometric figures)
|
||||
|
||||
/// <summary> This is a possible type of Element. </summary>
|
||||
public const int RECTANGLE = 30;
|
||||
|
||||
/// <summary> This is a possible type of Element. </summary>
|
||||
public const int JPEG = 32;
|
||||
|
||||
/** This is a possible type of <CODE>Element</CODE>. */
|
||||
public const int JPEG2000 = 33;
|
||||
|
||||
/// <summary> This is a possible type of Element. </summary>
|
||||
public const int IMGRAW = 34;
|
||||
|
||||
/// <summary> This is a possible type of Element. </summary>
|
||||
public const int IMGTEMPLATE = 35;
|
||||
|
||||
/// <summary> This is a possible type of <CODE>Element</CODE>. </summary>
|
||||
public const int MULTI_COLUMN_TEXT = 40;
|
||||
|
||||
/** This is a possible type of <CODE>Element</CODE>. */
|
||||
public const int MARKED = 50;
|
||||
|
||||
/** This is a possible type of <CODE>Element</CODE>.
|
||||
* @since 2.1.2
|
||||
*/
|
||||
public const int YMARK = 55;
|
||||
|
||||
// static membervariables (alignment)
|
||||
|
||||
/// <summary>
|
||||
/// A possible value for paragraph Element. This
|
||||
/// specifies that the text is aligned to the left
|
||||
/// indent and extra whitespace should be placed on
|
||||
/// the right.
|
||||
/// </summary>
|
||||
public const int ALIGN_UNDEFINED = -1;
|
||||
|
||||
/// <summary>
|
||||
/// A possible value for paragraph Element. This
|
||||
/// specifies that the text is aligned to the left
|
||||
/// indent and extra whitespace should be placed on
|
||||
/// the right.
|
||||
/// </summary>
|
||||
public const int ALIGN_LEFT = 0;
|
||||
|
||||
/// <summary>
|
||||
/// A possible value for paragraph Element. This
|
||||
/// specifies that the text is aligned to the center
|
||||
/// and extra whitespace should be placed equally on
|
||||
/// the left and right.
|
||||
/// </summary>
|
||||
public const int ALIGN_CENTER = 1;
|
||||
|
||||
/// <summary>
|
||||
/// A possible value for paragraph Element. This
|
||||
/// specifies that the text is aligned to the right
|
||||
/// indent and extra whitespace should be placed on
|
||||
/// the left.
|
||||
/// </summary>
|
||||
public const int ALIGN_RIGHT = 2;
|
||||
|
||||
/// <summary>
|
||||
/// A possible value for paragraph Element. This
|
||||
/// specifies that extra whitespace should be spread
|
||||
/// out through the rows of the paragraph with the
|
||||
/// text lined up with the left and right indent
|
||||
/// except on the last line which should be aligned
|
||||
/// to the left.
|
||||
/// </summary>
|
||||
public const int ALIGN_JUSTIFIED = 3;
|
||||
|
||||
/// <summary>
|
||||
/// A possible value for vertical Element.
|
||||
/// </summary>
|
||||
public const int ALIGN_TOP = 4;
|
||||
|
||||
/// <summary>
|
||||
/// A possible value for vertical Element.
|
||||
/// </summary>
|
||||
public const int ALIGN_MIDDLE = 5;
|
||||
|
||||
/// <summary>
|
||||
/// A possible value for vertical Element.
|
||||
/// </summary>
|
||||
public const int ALIGN_BOTTOM = 6;
|
||||
|
||||
/// <summary>
|
||||
/// A possible value for vertical Element.
|
||||
/// </summary>
|
||||
public const int ALIGN_BASELINE = 7;
|
||||
|
||||
/// <summary>
|
||||
/// Does the same as ALIGN_JUSTIFIED but the last line is also spread out.
|
||||
/// </summary>
|
||||
public const int ALIGN_JUSTIFIED_ALL = 8;
|
||||
|
||||
// static member variables for CCITT compression
|
||||
|
||||
/// <summary>
|
||||
/// Pure two-dimensional encoding (Group 4)
|
||||
/// </summary>
|
||||
public const int CCITTG4 = 0x100;
|
||||
/// <summary>
|
||||
/// Pure one-dimensional encoding (Group 3, 1-D)
|
||||
/// </summary>
|
||||
public const int CCITTG3_1D = 0x101;
|
||||
/// <summary>
|
||||
/// Mixed one- and two-dimensional encoding (Group 3, 2-D)
|
||||
/// </summary>
|
||||
public const int CCITTG3_2D = 0x102;
|
||||
/// <summary>
|
||||
/// A flag indicating whether 1-bits are to be interpreted as black pixels
|
||||
/// and 0-bits as white pixels,
|
||||
/// </summary>
|
||||
public const int CCITT_BLACKIS1 = 1;
|
||||
/// <summary>
|
||||
/// A flag indicating whether the filter expects extra 0-bits before each
|
||||
/// encoded line so that the line begins on a byte boundary.
|
||||
/// </summary>
|
||||
public const int CCITT_ENCODEDBYTEALIGN = 2;
|
||||
/// <summary>
|
||||
/// A flag indicating whether end-of-line bit patterns are required to be
|
||||
/// present in the encoding.
|
||||
/// </summary>
|
||||
public const int CCITT_ENDOFLINE = 4;
|
||||
/// <summary>
|
||||
/// A flag indicating whether the filter expects the encoded data to be
|
||||
/// terminated by an end-of-block pattern, overriding the Rows
|
||||
/// parameter. The use of this flag will set the key /EndOfBlock to false.
|
||||
/// </summary>
|
||||
public const int CCITT_ENDOFBLOCK = 8;
|
||||
|
||||
}
|
||||
}
|
||||
521
iTechSharp/iTextSharp/text/ElementTags.cs
Normal file
521
iTechSharp/iTextSharp/text/ElementTags.cs
Normal file
@@ -0,0 +1,521 @@
|
||||
using System;
|
||||
using System.util;
|
||||
|
||||
/*
|
||||
* $Id: ElementTags.cs,v 1.8 2008/05/13 11:25:10 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2001, 2002 Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text
|
||||
{
|
||||
/// <summary>
|
||||
/// A class that contains all the possible tagnames and their attributes.
|
||||
/// </summary>
|
||||
public class ElementTags
|
||||
{
|
||||
|
||||
/// <summary> the root tag. </summary>
|
||||
public const string ITEXT = "itext";
|
||||
|
||||
/// <summary> attribute of the root and annotation tag (also a special tag within a chapter or section) </summary>
|
||||
public const string TITLE = "title";
|
||||
|
||||
/// <summary> attribute of the root tag </summary>
|
||||
public const string SUBJECT = "subject";
|
||||
|
||||
/// <summary> attribute of the root tag </summary>
|
||||
public const string KEYWORDS = "keywords";
|
||||
|
||||
/// <summary> attribute of the root tag </summary>
|
||||
public const string AUTHOR = "author";
|
||||
|
||||
/// <summary> attribute of the root tag </summary>
|
||||
public const string CREATIONDATE = "creationdate";
|
||||
|
||||
/// <summary> attribute of the root tag </summary>
|
||||
public const string PRODUCER = "producer";
|
||||
|
||||
// Chapters and Sections
|
||||
|
||||
/// <summary> the chapter tag </summary>
|
||||
public const string CHAPTER = "chapter";
|
||||
|
||||
/// <summary> the section tag </summary>
|
||||
public const string SECTION = "section";
|
||||
|
||||
/// <summary> attribute of section/chapter tag </summary>
|
||||
public const string NUMBERDEPTH = "numberdepth";
|
||||
|
||||
/// <summary> attribute of section/chapter tag </summary>
|
||||
public const string DEPTH = "depth";
|
||||
|
||||
/// <summary> attribute of section/chapter tag </summary>
|
||||
public const string NUMBER = "number";
|
||||
|
||||
/// <summary> attribute of section/chapter tag </summary>
|
||||
public const string INDENT = "indent";
|
||||
|
||||
/// <summary> attribute of chapter/section/paragraph/table/cell tag </summary>
|
||||
public const string LEFT = "left";
|
||||
|
||||
/// <summary> attribute of chapter/section/paragraph/table/cell tag </summary>
|
||||
public const string RIGHT = "right";
|
||||
|
||||
// Phrases, Anchors, Lists and Paragraphs
|
||||
|
||||
/// <summary> the phrase tag </summary>
|
||||
public const string PHRASE = "phrase";
|
||||
|
||||
/// <summary> the anchor tag </summary>
|
||||
public const string ANCHOR = "anchor";
|
||||
|
||||
/// <summary> the list tag </summary>
|
||||
public const string LIST = "list";
|
||||
|
||||
/// <summary> the listitem tag </summary>
|
||||
public const string LISTITEM = "listitem";
|
||||
|
||||
/// <summary> the paragraph tag </summary>
|
||||
public const string PARAGRAPH = "paragraph";
|
||||
|
||||
/// <summary> attribute of phrase/paragraph/cell tag </summary>
|
||||
public const string LEADING = "leading";
|
||||
|
||||
/// <summary> attribute of paragraph/image/table tag </summary>
|
||||
public const string ALIGN = "align";
|
||||
|
||||
/// <summary> attribute of paragraph </summary>
|
||||
public const string KEEPTOGETHER = "keeptogether";
|
||||
|
||||
/// <summary> attribute of anchor tag </summary>
|
||||
public const string NAME = "name";
|
||||
|
||||
/// <summary> attribute of anchor tag </summary>
|
||||
public const string REFERENCE = "reference";
|
||||
|
||||
/// <summary> attribute of list tag </summary>
|
||||
public const string LISTSYMBOL = "listsymbol";
|
||||
|
||||
/// <summary> attribute of list tag </summary>
|
||||
public const string NUMBERED = "numbered";
|
||||
|
||||
/// <summary> attribute of the list tag </summary>
|
||||
public const string LETTERED = "lettered";
|
||||
|
||||
/// <summary> attribute of list tag </summary>
|
||||
public const string FIRST = "first";
|
||||
|
||||
/// <summary> attribute of list tag </summary>
|
||||
public const string SYMBOLINDENT = "symbolindent";
|
||||
|
||||
/// <summary> attribute of list tag </summary>
|
||||
public const string INDENTATIONLEFT = "indentationleft";
|
||||
|
||||
/// <summary> attribute of list tag </summary>
|
||||
public const string INDENTATIONRIGHT = "indentationright";
|
||||
|
||||
// Chunks
|
||||
|
||||
/// <summary> the chunk tag </summary>
|
||||
public const string IGNORE = "ignore";
|
||||
|
||||
/// <summary> the chunk tag </summary>
|
||||
public const string ENTITY = "entity";
|
||||
|
||||
/// <summary> the chunk tag </summary>
|
||||
public const string ID = "id";
|
||||
|
||||
/// <summary> the chunk tag </summary>
|
||||
public const string CHUNK = "chunk";
|
||||
|
||||
/// <summary> attribute of the chunk tag </summary>
|
||||
public const string ENCODING = "encoding";
|
||||
|
||||
/// <summary> attribute of the chunk tag </summary>
|
||||
public const string EMBEDDED = "embedded";
|
||||
|
||||
/// <summary> attribute of the chunk/table/cell tag </summary>
|
||||
public const string COLOR = "color";
|
||||
|
||||
/// <summary> attribute of the chunk/table/cell tag </summary>
|
||||
public const string RED = "red";
|
||||
|
||||
/// <summary> attribute of the chunk/table/cell tag </summary>
|
||||
public const string GREEN = "green";
|
||||
|
||||
/// <summary> attribute of the chunk/table/cell tag </summary>
|
||||
public const string BLUE = "blue";
|
||||
|
||||
/// <summary> attribute of the chunk tag </summary>
|
||||
public static readonly string SUBSUPSCRIPT = Chunk.SUBSUPSCRIPT.ToLower(System.Globalization.CultureInfo.InvariantCulture);
|
||||
|
||||
/// <summary> attribute of the chunk tag </summary>
|
||||
public static readonly string LOCALGOTO = Chunk.LOCALGOTO.ToLower(System.Globalization.CultureInfo.InvariantCulture);
|
||||
|
||||
/// <summary> attribute of the chunk tag </summary>
|
||||
public static readonly string REMOTEGOTO = Chunk.REMOTEGOTO.ToLower(System.Globalization.CultureInfo.InvariantCulture);
|
||||
|
||||
/// <summary> attribute of the chunk tag </summary>
|
||||
public static readonly string LOCALDESTINATION = Chunk.LOCALDESTINATION.ToLower(System.Globalization.CultureInfo.InvariantCulture);
|
||||
|
||||
/// <summary> attribute of the chunk tag </summary>
|
||||
public static readonly string GENERICTAG = Chunk.GENERICTAG.ToLower(System.Globalization.CultureInfo.InvariantCulture);
|
||||
|
||||
// tables/cells
|
||||
|
||||
/// <summary> the table tag </summary>
|
||||
public const string TABLE = "table";
|
||||
|
||||
/// <summary> the cell tag </summary>
|
||||
public const string ROW = "row";
|
||||
|
||||
/// <summary> the cell tag </summary>
|
||||
public const string CELL = "cell";
|
||||
|
||||
/// <summary> attribute of the table tag </summary>
|
||||
public const string COLUMNS = "columns";
|
||||
|
||||
/// <summary> attribute of the table tag </summary>
|
||||
public const string LASTHEADERROW = "lastHeaderRow";
|
||||
|
||||
/// <summary> attribute of the table tag </summary>
|
||||
public const string CELLPADDING = "cellpadding";
|
||||
|
||||
/// <summary> attribute of the table tag </summary>
|
||||
public const string CELLSPACING = "cellspacing";
|
||||
|
||||
/// <summary> attribute of the table tag </summary>
|
||||
public const string OFFSET = "offset";
|
||||
|
||||
/// <summary> attribute of the table tag </summary>
|
||||
public const string WIDTHS = "widths";
|
||||
|
||||
/// <summary> attribute of the table tag </summary>
|
||||
public const string TABLEFITSPAGE = "tablefitspage";
|
||||
|
||||
/// <summary> attribute of the table tag </summary>
|
||||
public const string CELLSFITPAGE = "cellsfitpage";
|
||||
|
||||
/// <summary> attribute of the table tag </summary>
|
||||
public const string CONVERT2PDFP = "convert2pdfp";
|
||||
|
||||
/// <summary> attribute of the cell tag </summary>
|
||||
public const string HORIZONTALALIGN = "horizontalalign";
|
||||
|
||||
/// <summary> attribute of the cell tag </summary>
|
||||
public const string VERTICALALIGN = "verticalalign";
|
||||
|
||||
/// <summary> attribute of the cell tag </summary>
|
||||
public const string COLSPAN = "colspan";
|
||||
|
||||
/// <summary> attribute of the cell tag </summary>
|
||||
public const string ROWSPAN = "rowspan";
|
||||
|
||||
/// <summary> attribute of the cell tag </summary>
|
||||
public const string HEADER = "header";
|
||||
|
||||
/// <summary> attribute of the cell tag </summary>
|
||||
public const string FOOTER = "footer";
|
||||
|
||||
/// <summary> attribute of the cell tag </summary>
|
||||
public const string NOWRAP = "nowrap";
|
||||
|
||||
/// <summary> attribute of the table/cell tag </summary>
|
||||
public const string BORDERWIDTH = "borderwidth";
|
||||
|
||||
/// <summary> attribute of the table/cell tag </summary>
|
||||
public const string TOP = "top";
|
||||
|
||||
/// <summary> attribute of the table/cell tag </summary>
|
||||
public const string BOTTOM = "bottom";
|
||||
|
||||
/// <summary> attribute of the table/cell tag </summary>
|
||||
public const string WIDTH = "width";
|
||||
|
||||
/// <summary> attribute of the table/cell tag </summary>
|
||||
public const string BORDERCOLOR = "bordercolor";
|
||||
|
||||
/// <summary> attribute of the table/cell tag </summary>
|
||||
public const string BACKGROUNDCOLOR = "backgroundcolor";
|
||||
|
||||
/// <summary> attribute of the table/cell tag </summary>
|
||||
public const string BGRED = "bgred";
|
||||
|
||||
/// <summary> attribute of the table/cell tag </summary>
|
||||
public const string BGGREEN = "bggreen";
|
||||
|
||||
/// <summary> attribute of the table/cell tag </summary>
|
||||
public const string BGBLUE = "bgblue";
|
||||
|
||||
/// <summary> attribute of the table/cell tag </summary>
|
||||
public const string GRAYFILL = "grayfill";
|
||||
|
||||
// Misc
|
||||
|
||||
/// <summary> the image tag </summary>
|
||||
public const string IMAGE = "image";
|
||||
|
||||
/// <summary> the image tag </summary>
|
||||
public const string BOOKMARKOPEN = "bookmarkopen";
|
||||
|
||||
/// <summary> attribute of the image and annotation tag </summary>
|
||||
public const string URL = "url";
|
||||
|
||||
/// <summary> attribute of the image tag </summary>
|
||||
public const string UNDERLYING = "underlying";
|
||||
|
||||
/// <summary> attribute of the image tag </summary>
|
||||
public const string TEXTWRAP = "textwrap";
|
||||
|
||||
/// <summary> attribute of the image tag </summary>
|
||||
public const string ALT = "alt";
|
||||
|
||||
/// <summary> attribute of the image tag </summary>
|
||||
public const string ABSOLUTEX = "absolutex";
|
||||
|
||||
/// <summary> attribute of the image tag </summary>
|
||||
public const string ABSOLUTEY = "absolutey";
|
||||
|
||||
/// <summary> attribute of the image tag </summary>
|
||||
public const string PLAINWIDTH = "plainwidth";
|
||||
|
||||
/// <summary> attribute of the image tag </summary>
|
||||
public const string PLAINHEIGHT = "plainheight";
|
||||
|
||||
/// <summary> attribute of the image tag </summary>
|
||||
public const string SCALEDWIDTH = "scaledwidth";
|
||||
|
||||
/// <summary> attribute of the image tag </summary>
|
||||
public const string SCALEDHEIGHT = "scaledheight";
|
||||
|
||||
/// <summary> attribute of the image tag </summary>
|
||||
public const string ROTATION = "rotation";
|
||||
|
||||
/// <summary> the newpage tag </summary>
|
||||
public const string NEWPAGE = "newpage";
|
||||
|
||||
/// <summary> the newpage tag </summary>
|
||||
public const string NEWLINE = "newline";
|
||||
|
||||
/// <summary> the annotation tag </summary>
|
||||
public const string ANNOTATION = "annotation";
|
||||
|
||||
/// <summary> attribute of the annotation tag </summary>
|
||||
public const string FILE = "file";
|
||||
|
||||
/// <summary> attribute of the annotation tag </summary>
|
||||
public const string DESTINATION = "destination";
|
||||
|
||||
/// <summary> attribute of the annotation tag </summary>
|
||||
public const string PAGE = "page";
|
||||
|
||||
/// <summary> attribute of the annotation tag </summary>
|
||||
public const string NAMED = "named";
|
||||
|
||||
/// <summary> attribute of the annotation tag </summary>
|
||||
public const string APPLICATION = "application";
|
||||
|
||||
/// <summary> attribute of the annotation tag </summary>
|
||||
public const string PARAMETERS = "parameters";
|
||||
|
||||
/// <summary> attribute of the annotation tag </summary>
|
||||
public const string OPERATION = "operation";
|
||||
|
||||
/// <summary> attribute of the annotation tag </summary>
|
||||
public const string DEFAULTDIR = "defaultdir";
|
||||
|
||||
/// <summary> attribute of the annotation tag </summary>
|
||||
public const string LLX = "llx";
|
||||
|
||||
/// <summary> attribute of the annotation tag </summary>
|
||||
public const string LLY = "lly";
|
||||
|
||||
/// <summary> attribute of the annotation tag </summary>
|
||||
public const string URX = "urx";
|
||||
|
||||
/// <summary> attribute of the annotation tag </summary>
|
||||
public const string URY = "ury";
|
||||
|
||||
/// <summary> attribute of the annotation tag </summary>
|
||||
public const string CONTENT = "content";
|
||||
|
||||
// alignment attribute values
|
||||
|
||||
/// <summary> the possible value of an alignment attribute </summary>
|
||||
public const string ALIGN_LEFT = "Left";
|
||||
|
||||
/// <summary> the possible value of an alignment attribute </summary>
|
||||
public const string ALIGN_CENTER = "Center";
|
||||
|
||||
/// <summary> the possible value of an alignment attribute </summary>
|
||||
public const string ALIGN_RIGHT = "Right";
|
||||
|
||||
/// <summary> the possible value of an alignment attribute </summary>
|
||||
public const string ALIGN_JUSTIFIED = "Justify";
|
||||
|
||||
/// <summary> the possible value of an alignment attribute </summary>
|
||||
public const string ALIGN_JUSTIFIED_ALL = "JustifyAll";
|
||||
|
||||
/// <summary> the possible value of an alignment attribute </summary>
|
||||
public const string ALIGN_TOP = "Top";
|
||||
|
||||
/// <summary> the possible value of an alignment attribute </summary>
|
||||
public const string ALIGN_MIDDLE = "Middle";
|
||||
|
||||
/// <summary> the possible value of an alignment attribute </summary>
|
||||
public const string ALIGN_BOTTOM = "Bottom";
|
||||
|
||||
/// <summary> the possible value of an alignment attribute </summary>
|
||||
public const string ALIGN_BASELINE = "Baseline";
|
||||
|
||||
/// <summary> the possible value of an alignment attribute </summary>
|
||||
public const string DEFAULT = "Default";
|
||||
|
||||
/// <summary> the possible value of an alignment attribute </summary>
|
||||
public const string UNKNOWN = "unknown";
|
||||
|
||||
/// <summary> the possible value of an alignment attribute </summary>
|
||||
public const string FONT = "font";
|
||||
|
||||
/// <summary> the possible value of an alignment attribute </summary>
|
||||
public const string SIZE = "size";
|
||||
|
||||
/// <summary> the possible value of an alignment attribute </summary>
|
||||
public const string STYLE = "fontstyle";
|
||||
|
||||
/// <summary> the possible value of a tag </summary>
|
||||
public const string HORIZONTALRULE = "horizontalrule";
|
||||
/** the possible value of a tag */
|
||||
public const string PAGE_SIZE = "pagesize";
|
||||
|
||||
/** the possible value of a tag */
|
||||
public const string ORIENTATION = "orientation";
|
||||
|
||||
/** a possible list attribute */
|
||||
public const String ALIGN_INDENTATION_ITEMS = "alignindent";
|
||||
|
||||
/** a possible list attribute */
|
||||
public const String AUTO_INDENT_ITEMS = "autoindent";
|
||||
|
||||
/** a possible list attribute */
|
||||
public const String LOWERCASE = "lowercase";
|
||||
|
||||
// methods
|
||||
|
||||
/// <summary>
|
||||
/// Translates the alignment value to a String value.
|
||||
/// </summary>
|
||||
/// <param name="alignment">the alignment value</param>
|
||||
/// <returns>the translated value</returns>
|
||||
public static string GetAlignment(int alignment)
|
||||
{
|
||||
switch (alignment)
|
||||
{
|
||||
case Element.ALIGN_LEFT:
|
||||
return ALIGN_LEFT;
|
||||
case Element.ALIGN_CENTER:
|
||||
return ALIGN_CENTER;
|
||||
case Element.ALIGN_RIGHT:
|
||||
return ALIGN_RIGHT;
|
||||
case Element.ALIGN_JUSTIFIED:
|
||||
case Element.ALIGN_JUSTIFIED_ALL:
|
||||
return ALIGN_JUSTIFIED;
|
||||
case Element.ALIGN_TOP:
|
||||
return ALIGN_TOP;
|
||||
case Element.ALIGN_MIDDLE:
|
||||
return ALIGN_MIDDLE;
|
||||
case Element.ALIGN_BOTTOM:
|
||||
return ALIGN_BOTTOM;
|
||||
case Element.ALIGN_BASELINE:
|
||||
return ALIGN_BASELINE;
|
||||
default:
|
||||
return DEFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates a String value to an alignment value.
|
||||
* (written by Norman Richards, integrated into iText by Bruno)
|
||||
* @param a String (one of the ALIGN_ constants of this class)
|
||||
* @param an alignment value (one of the ALIGN_ constants of the Element interface)
|
||||
*/
|
||||
public static int AlignmentValue(String alignment) {
|
||||
if (alignment == null) return Element.ALIGN_UNDEFINED;
|
||||
if (Util.EqualsIgnoreCase(ALIGN_CENTER, alignment)) {
|
||||
return Element.ALIGN_CENTER;
|
||||
}
|
||||
if (Util.EqualsIgnoreCase(ALIGN_LEFT, alignment)) {
|
||||
return Element.ALIGN_LEFT;
|
||||
}
|
||||
if (Util.EqualsIgnoreCase(ALIGN_RIGHT, alignment)) {
|
||||
return Element.ALIGN_RIGHT;
|
||||
}
|
||||
if (Util.EqualsIgnoreCase(ALIGN_JUSTIFIED, alignment)) {
|
||||
return Element.ALIGN_JUSTIFIED;
|
||||
}
|
||||
if (Util.EqualsIgnoreCase(ALIGN_JUSTIFIED_ALL, alignment)) {
|
||||
return Element.ALIGN_JUSTIFIED_ALL;
|
||||
}
|
||||
if (Util.EqualsIgnoreCase(ALIGN_TOP, alignment)) {
|
||||
return Element.ALIGN_TOP;
|
||||
}
|
||||
if (Util.EqualsIgnoreCase(ALIGN_MIDDLE, alignment)) {
|
||||
return Element.ALIGN_MIDDLE;
|
||||
}
|
||||
if (Util.EqualsIgnoreCase(ALIGN_BOTTOM, alignment)) {
|
||||
return Element.ALIGN_BOTTOM;
|
||||
}
|
||||
if (Util.EqualsIgnoreCase(ALIGN_BASELINE, alignment)) {
|
||||
return Element.ALIGN_BASELINE;
|
||||
}
|
||||
|
||||
return Element.ALIGN_UNDEFINED;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
698
iTechSharp/iTextSharp/text/Font.cs
Normal file
698
iTechSharp/iTextSharp/text/Font.cs
Normal file
@@ -0,0 +1,698 @@
|
||||
using System;
|
||||
using System.util;
|
||||
|
||||
using iTextSharp.text.pdf;
|
||||
using iTextSharp.text.html;
|
||||
|
||||
/*
|
||||
* $Id: Font.cs,v 1.11 2008/05/13 11:25:10 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text {
|
||||
/// <summary>
|
||||
/// Contains all the specifications of a font: fontfamily, size, style and color.
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// Paragraph p = new Paragraph("This is a paragraph",
|
||||
/// <strong>new Font(Font.HELVETICA, 18, Font.BOLDITALIC, new Color(0, 0, 255))</strong>);
|
||||
/// </code>
|
||||
/// </example>
|
||||
public class Font : IComparable {
|
||||
|
||||
// static membervariables for the different families
|
||||
|
||||
/// <summary> a possible value of a font family. </summary>
|
||||
public const int COURIER = 0;
|
||||
|
||||
/// <summary> a possible value of a font family. </summary>
|
||||
public const int HELVETICA = 1;
|
||||
|
||||
/// <summary> a possible value of a font family. </summary>
|
||||
public const int TIMES_ROMAN = 2;
|
||||
|
||||
/// <summary> a possible value of a font family. </summary>
|
||||
public const int SYMBOL = 3;
|
||||
|
||||
/// <summary> a possible value of a font family. </summary>
|
||||
public const int ZAPFDINGBATS = 4;
|
||||
|
||||
// static membervariables for the different styles
|
||||
|
||||
/// <summary> this is a possible style. </summary>
|
||||
public const int NORMAL = 0;
|
||||
|
||||
/// <summary> this is a possible style. </summary>
|
||||
public const int BOLD = 1;
|
||||
|
||||
/// <summary> this is a possible style. </summary>
|
||||
public const int ITALIC = 2;
|
||||
|
||||
/// <summary> this is a possible style. </summary>
|
||||
public const int UNDERLINE = 4;
|
||||
|
||||
/// <summary> this is a possible style. </summary>
|
||||
public const int STRIKETHRU = 8;
|
||||
|
||||
/// <summary> this is a possible style. </summary>
|
||||
public const int BOLDITALIC = BOLD | ITALIC;
|
||||
|
||||
// static membervariables
|
||||
|
||||
/// <summary> the value of an undefined attribute. </summary>
|
||||
public const int UNDEFINED = -1;
|
||||
|
||||
/// <summary> the value of the default size. </summary>
|
||||
public const int DEFAULTSIZE = 12;
|
||||
|
||||
// membervariables
|
||||
|
||||
/// <summary> the value of the fontfamily. </summary>
|
||||
private int family = UNDEFINED;
|
||||
|
||||
/// <summary> the value of the fontsize. </summary>
|
||||
private float size = UNDEFINED;
|
||||
|
||||
/// <summary> the value of the style. </summary>
|
||||
private int style = UNDEFINED;
|
||||
|
||||
/// <summary> the value of the color. </summary>
|
||||
private Color color;
|
||||
|
||||
/// <summary> the external font </summary>
|
||||
private BaseFont baseFont = null;
|
||||
|
||||
// constructors
|
||||
|
||||
/**
|
||||
* Copy constructor of a Font
|
||||
* @param other the font that has to be copied
|
||||
*/
|
||||
public Font(Font other) {
|
||||
this.color = other.color;
|
||||
this.family = other.family;
|
||||
this.size = other.size;
|
||||
this.style = other.style;
|
||||
this.baseFont = other.baseFont;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font.
|
||||
/// </summary>
|
||||
/// <param name="family">the family to which this font belongs</param>
|
||||
/// <param name="size">the size of this font</param>
|
||||
/// <param name="style">the style of this font</param>
|
||||
/// <param name="color">the Color of this font.</param>
|
||||
public Font(int family, float size, int style, Color color) {
|
||||
this.family = family;
|
||||
this.size = size;
|
||||
this.style = style;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font.
|
||||
/// </summary>
|
||||
/// <param name="bf">the external font</param>
|
||||
/// <param name="size">the size of this font</param>
|
||||
/// <param name="style">the style of this font</param>
|
||||
/// <param name="color">the Color of this font.</param>
|
||||
public Font(BaseFont bf, float size, int style, Color color) {
|
||||
this.baseFont = bf;
|
||||
this.size = size;
|
||||
this.style = style;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font.
|
||||
/// </summary>
|
||||
/// <param name="bf">the external font</param>
|
||||
/// <param name="size">the size of this font</param>
|
||||
/// <param name="style">the style of this font</param>
|
||||
public Font(BaseFont bf, float size, int style) : this(bf, size, style, null) {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font.
|
||||
/// </summary>
|
||||
/// <param name="bf">the external font</param>
|
||||
/// <param name="size">the size of this font</param>
|
||||
public Font(BaseFont bf, float size) : this(bf, size, UNDEFINED, null) {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font.
|
||||
/// </summary>
|
||||
/// <param name="bf">the external font</param>
|
||||
public Font(BaseFont bf) : this(bf, UNDEFINED, UNDEFINED, null) {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font.
|
||||
/// </summary>
|
||||
/// <param name="family">the family to which this font belongs</param>
|
||||
/// <param name="size">the size of this font</param>
|
||||
/// <param name="style">the style of this font</param>
|
||||
public Font(int family, float size, int style) : this(family, size, style, null) {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font.
|
||||
/// </summary>
|
||||
/// <param name="family">the family to which this font belongs</param>
|
||||
/// <param name="size">the size of this font</param>
|
||||
public Font(int family, float size) : this(family, size, UNDEFINED, null) {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font.
|
||||
/// </summary>
|
||||
/// <param name="family">the family to which this font belongs</param>
|
||||
public Font(int family) : this(family, UNDEFINED, UNDEFINED, null) {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font.
|
||||
/// </summary>
|
||||
/// <overloads>
|
||||
/// Has nine overloads.
|
||||
/// </overloads>
|
||||
public Font() : this(UNDEFINED, UNDEFINED, UNDEFINED, null) {}
|
||||
|
||||
// implementation of the Comparable interface
|
||||
|
||||
/// <summary>
|
||||
/// Compares this Font with another
|
||||
/// </summary>
|
||||
/// <param name="obj">the other Font</param>
|
||||
/// <returns>a value</returns>
|
||||
public virtual int CompareTo(Object obj) {
|
||||
if (obj == null) {
|
||||
return -1;
|
||||
}
|
||||
Font font;
|
||||
try {
|
||||
font = (Font) obj;
|
||||
if (baseFont != null && !baseFont.Equals(font.BaseFont)) {
|
||||
return -2;
|
||||
}
|
||||
if (this.family != font.Family) {
|
||||
return 1;
|
||||
}
|
||||
if (this.size != font.Size) {
|
||||
return 2;
|
||||
}
|
||||
if (this.style != font.Style) {
|
||||
return 3;
|
||||
}
|
||||
if (this.color == null) {
|
||||
if (font.Color == null) {
|
||||
return 0;
|
||||
}
|
||||
return 4;
|
||||
}
|
||||
if (font.Color == null) {
|
||||
return 4;
|
||||
}
|
||||
if (((Color)this.color).Equals(font.Color)) {
|
||||
return 0;
|
||||
}
|
||||
return 4;
|
||||
}
|
||||
catch {
|
||||
return -3;
|
||||
}
|
||||
}
|
||||
|
||||
// FAMILY
|
||||
|
||||
/// <summary>
|
||||
/// Gets the family of this font.
|
||||
/// </summary>
|
||||
/// <value>the value of the family</value>
|
||||
public int Family {
|
||||
get {
|
||||
return family;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the familyname as a string.
|
||||
/// </summary>
|
||||
/// <value>the familyname</value>
|
||||
public virtual string Familyname {
|
||||
get {
|
||||
string tmp = "unknown";
|
||||
switch (this.Family) {
|
||||
case Font.COURIER:
|
||||
return FontFactory.COURIER;
|
||||
case Font.HELVETICA:
|
||||
return FontFactory.HELVETICA;
|
||||
case Font.TIMES_ROMAN:
|
||||
return FontFactory.TIMES_ROMAN;
|
||||
case Font.SYMBOL:
|
||||
return FontFactory.SYMBOL;
|
||||
case Font.ZAPFDINGBATS:
|
||||
return FontFactory.ZAPFDINGBATS;
|
||||
default:
|
||||
if (baseFont != null) {
|
||||
string[][] names = baseFont.FamilyFontName;
|
||||
for (int i = 0; i < names.Length; i++) {
|
||||
if ("0".Equals(names[i][2])) {
|
||||
return names[i][3];
|
||||
}
|
||||
if ("1033".Equals(names[i][2])) {
|
||||
tmp = names[i][3];
|
||||
}
|
||||
if ("".Equals(names[i][2])) {
|
||||
tmp = names[i][3];
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the family using a String ("Courier",
|
||||
/// "Helvetica", "Times New Roman", "Symbol" or "ZapfDingbats").
|
||||
/// </summary>
|
||||
/// <param name="family">A String representing a certain font-family.</param>
|
||||
public virtual void SetFamily(String family) {
|
||||
this.family = GetFamilyIndex(family);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Translates a string-value of a certain family
|
||||
/// into the index that is used for this family in this class.
|
||||
/// </summary>
|
||||
/// <param name="family">A string representing a certain font-family</param>
|
||||
/// <returns>the corresponding index</returns>
|
||||
public static int GetFamilyIndex(string family) {
|
||||
if (Util.EqualsIgnoreCase(family, FontFactory.COURIER)) {
|
||||
return COURIER;
|
||||
}
|
||||
if (Util.EqualsIgnoreCase(family, FontFactory.HELVETICA)) {
|
||||
return HELVETICA;
|
||||
}
|
||||
if (Util.EqualsIgnoreCase(family, FontFactory.TIMES_ROMAN)) {
|
||||
return TIMES_ROMAN;
|
||||
}
|
||||
if (Util.EqualsIgnoreCase(family, FontFactory.SYMBOL)) {
|
||||
return SYMBOL;
|
||||
}
|
||||
if (Util.EqualsIgnoreCase(family, FontFactory.ZAPFDINGBATS)) {
|
||||
return ZAPFDINGBATS;
|
||||
}
|
||||
return UNDEFINED;
|
||||
}
|
||||
|
||||
// SIZE
|
||||
|
||||
/// <summary>
|
||||
/// Get/set the size of this font.
|
||||
/// </summary>
|
||||
/// <value>the size of this font</value>
|
||||
public virtual float Size {
|
||||
get {
|
||||
return size;
|
||||
}
|
||||
set {
|
||||
this.size = value;
|
||||
}
|
||||
}
|
||||
|
||||
/** Gets the size that can be used with the calculated <CODE>BaseFont</CODE>.
|
||||
* @return the size that can be used with the calculated <CODE>BaseFont</CODE>
|
||||
*/
|
||||
public float CalculatedSize {
|
||||
get {
|
||||
float s = this.size;
|
||||
if (s == UNDEFINED) {
|
||||
s = DEFAULTSIZE;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the leading that can be used with this font.
|
||||
*
|
||||
* @param linespacing
|
||||
* a certain linespacing
|
||||
* @return the height of a line
|
||||
*/
|
||||
public float GetCalculatedLeading(float linespacing) {
|
||||
return linespacing * CalculatedSize;
|
||||
}
|
||||
|
||||
// STYLE
|
||||
|
||||
/// <summary>
|
||||
/// Gets the style of this font.
|
||||
/// </summary>
|
||||
/// <value>the style of this font</value>
|
||||
public int Style {
|
||||
get {
|
||||
return style;
|
||||
}
|
||||
}
|
||||
|
||||
/** Gets the style that can be used with the calculated <CODE>BaseFont</CODE>.
|
||||
* @return the style that can be used with the calculated <CODE>BaseFont</CODE>
|
||||
*/
|
||||
public int CalculatedStyle {
|
||||
get {
|
||||
int style = this.style;
|
||||
if (style == UNDEFINED) {
|
||||
style = NORMAL;
|
||||
}
|
||||
if (baseFont != null)
|
||||
return style;
|
||||
if (family == SYMBOL || family == ZAPFDINGBATS)
|
||||
return style;
|
||||
else
|
||||
return style & (~BOLDITALIC);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// checks if this font is Bold.
|
||||
/// </summary>
|
||||
/// <returns>a boolean</returns>
|
||||
public bool IsBold() {
|
||||
if (style == UNDEFINED) {
|
||||
return false;
|
||||
}
|
||||
return (style & BOLD) == BOLD;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// checks if this font is Bold.
|
||||
/// </summary>
|
||||
/// <returns>a boolean</returns>
|
||||
public bool IsItalic() {
|
||||
if (style == UNDEFINED) {
|
||||
return false;
|
||||
}
|
||||
return (style & ITALIC) == ITALIC;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// checks if this font is underlined.
|
||||
/// </summary>
|
||||
/// <returns>a boolean</returns>
|
||||
public bool IsUnderlined() {
|
||||
if (style == UNDEFINED) {
|
||||
return false;
|
||||
}
|
||||
return (style & UNDERLINE) == UNDERLINE;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// checks if the style of this font is STRIKETHRU.
|
||||
/// </summary>
|
||||
/// <returns>a boolean</returns>
|
||||
public bool IsStrikethru() {
|
||||
if (style == UNDEFINED) {
|
||||
return false;
|
||||
}
|
||||
return (style & STRIKETHRU) == STRIKETHRU;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the style using a String containing one of
|
||||
/// more of the following values: normal, bold, italic, underline, strike.
|
||||
/// </summary>
|
||||
/// <param name="style">A String representing a certain style.</param>
|
||||
public virtual void SetStyle(String style) {
|
||||
if (this.style == UNDEFINED) this.style = NORMAL;
|
||||
this.style |= GetStyleValue(style);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the style.
|
||||
* @param style the style.
|
||||
*/
|
||||
|
||||
public virtual void SetStyle(int style) {
|
||||
if (this.style == UNDEFINED) this.style = NORMAL;
|
||||
this.style |= style;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Translates a string-value of a certain style
|
||||
/// into the index value is used for this style in this class.
|
||||
/// </summary>
|
||||
/// <param name="style">a string</param>
|
||||
/// <returns>the corresponding value</returns>
|
||||
public static int GetStyleValue(string style) {
|
||||
int s = 0;
|
||||
if (style.IndexOf(Markup.CSS_VALUE_NORMAL) != -1) {
|
||||
s |= NORMAL;
|
||||
}
|
||||
if (style.IndexOf(Markup.CSS_VALUE_BOLD) != -1) {
|
||||
s |= BOLD;
|
||||
}
|
||||
if (style.IndexOf(Markup.CSS_VALUE_ITALIC) != -1) {
|
||||
s |= ITALIC;
|
||||
}
|
||||
if (style.IndexOf(Markup.CSS_VALUE_OBLIQUE) != -1) {
|
||||
s |= ITALIC;
|
||||
}
|
||||
if (style.IndexOf(Markup.CSS_VALUE_UNDERLINE) != -1) {
|
||||
s |= UNDERLINE;
|
||||
}
|
||||
if (style.IndexOf(Markup.CSS_VALUE_LINETHROUGH) != -1) {
|
||||
s |= STRIKETHRU;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
// COLOR
|
||||
|
||||
/// <summary>
|
||||
/// Get/set the color of this font.
|
||||
/// </summary>
|
||||
/// <value>the color of this font</value>
|
||||
public virtual Color Color {
|
||||
get {
|
||||
return color;
|
||||
}
|
||||
set {
|
||||
this.color = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the color.
|
||||
/// </summary>
|
||||
/// <param name="red">the red-value of the new color</param>
|
||||
/// <param name="green">the green-value of the new color</param>
|
||||
/// <param name="blue">the blue-value of the new color</param>
|
||||
public virtual void SetColor(int red, int green, int blue) {
|
||||
this.color = new Color(red, green, blue);
|
||||
}
|
||||
|
||||
// BASEFONT
|
||||
|
||||
/// <summary>
|
||||
/// Gets the BaseFont inside this object.
|
||||
/// </summary>
|
||||
/// <value>the BaseFont</value>
|
||||
public BaseFont BaseFont {
|
||||
get {
|
||||
return baseFont;
|
||||
}
|
||||
}
|
||||
|
||||
/** Gets the <CODE>BaseFont</CODE> this class represents.
|
||||
* For the built-in fonts a <CODE>BaseFont</CODE> is calculated.
|
||||
* @param specialEncoding <CODE>true</CODE> to use the special encoding for Symbol and ZapfDingbats,
|
||||
* <CODE>false</CODE> to always use <CODE>Cp1252</CODE>
|
||||
* @return the <CODE>BaseFont</CODE> this class represents
|
||||
*/
|
||||
public BaseFont GetCalculatedBaseFont(bool specialEncoding) {
|
||||
if (baseFont != null)
|
||||
return baseFont;
|
||||
int style = this.style;
|
||||
if (style == UNDEFINED) {
|
||||
style = NORMAL;
|
||||
}
|
||||
String fontName = BaseFont.HELVETICA;
|
||||
String encoding = BaseFont.WINANSI;
|
||||
BaseFont cfont = null;
|
||||
switch (family) {
|
||||
case COURIER:
|
||||
switch (style & BOLDITALIC) {
|
||||
case BOLD:
|
||||
fontName = BaseFont.COURIER_BOLD;
|
||||
break;
|
||||
case ITALIC:
|
||||
fontName = BaseFont.COURIER_OBLIQUE;
|
||||
break;
|
||||
case BOLDITALIC:
|
||||
fontName = BaseFont.COURIER_BOLDOBLIQUE;
|
||||
break;
|
||||
default:
|
||||
//case NORMAL:
|
||||
fontName = BaseFont.COURIER;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case TIMES_ROMAN:
|
||||
switch (style & BOLDITALIC) {
|
||||
case BOLD:
|
||||
fontName = BaseFont.TIMES_BOLD;
|
||||
break;
|
||||
case ITALIC:
|
||||
fontName = BaseFont.TIMES_ITALIC;
|
||||
break;
|
||||
case BOLDITALIC:
|
||||
fontName = BaseFont.TIMES_BOLDITALIC;
|
||||
break;
|
||||
default:
|
||||
//case NORMAL:
|
||||
fontName = BaseFont.TIMES_ROMAN;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SYMBOL:
|
||||
fontName = BaseFont.SYMBOL;
|
||||
if (specialEncoding)
|
||||
encoding = BaseFont.SYMBOL;
|
||||
break;
|
||||
case ZAPFDINGBATS:
|
||||
fontName = BaseFont.ZAPFDINGBATS;
|
||||
if (specialEncoding)
|
||||
encoding = BaseFont.ZAPFDINGBATS;
|
||||
break;
|
||||
default:
|
||||
//case Font.HELVETICA:
|
||||
switch (style & BOLDITALIC) {
|
||||
case BOLD:
|
||||
fontName = BaseFont.HELVETICA_BOLD;
|
||||
break;
|
||||
case ITALIC:
|
||||
fontName = BaseFont.HELVETICA_OBLIQUE;
|
||||
break;
|
||||
case BOLDITALIC:
|
||||
fontName = BaseFont.HELVETICA_BOLDOBLIQUE;
|
||||
break;
|
||||
default:
|
||||
//case NORMAL:
|
||||
fontName = BaseFont.HELVETICA;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
cfont = BaseFont.CreateFont(fontName, encoding, false);
|
||||
return cfont;
|
||||
}
|
||||
|
||||
// Helper methods
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the properties of this font are undefined or null.
|
||||
/// <p/>
|
||||
/// If so, the standard should be used.
|
||||
/// </summary>
|
||||
/// <returns>a boolean</returns>
|
||||
public virtual bool IsStandardFont() {
|
||||
return (family == UNDEFINED
|
||||
&& size == UNDEFINED
|
||||
&& style == UNDEFINED
|
||||
&& color == null
|
||||
&& baseFont == null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replaces the attributes that are equal to null with
|
||||
/// the attributes of a given font.
|
||||
/// </summary>
|
||||
/// <param name="font">the font of a bigger element class</param>
|
||||
/// <returns>a Font</returns>
|
||||
public virtual Font Difference(Font font) {
|
||||
if (font == null) return this;
|
||||
// size
|
||||
float dSize = font.size;
|
||||
if (dSize == UNDEFINED) {
|
||||
dSize = this.size;
|
||||
}
|
||||
// style
|
||||
int dStyle = UNDEFINED;
|
||||
int style1 = this.Style;
|
||||
int style2 = font.Style;
|
||||
if (style1 != UNDEFINED || style2 != UNDEFINED) {
|
||||
if (style1 == UNDEFINED) style1 = 0;
|
||||
if (style2 == UNDEFINED) style2 = 0;
|
||||
dStyle = style1 | style2;
|
||||
}
|
||||
// color
|
||||
object dColor = (Color)font.Color;
|
||||
if (dColor == null) {
|
||||
dColor = this.Color;
|
||||
}
|
||||
// family
|
||||
if (font.baseFont != null) {
|
||||
return new Font(font.BaseFont, dSize, dStyle, (Color)dColor);
|
||||
}
|
||||
if (font.Family != UNDEFINED) {
|
||||
return new Font(font.Family, dSize, dStyle, (Color)dColor);
|
||||
}
|
||||
if (this.baseFont != null) {
|
||||
if (dStyle == style1) {
|
||||
return new Font(this.BaseFont, dSize, dStyle, (Color)dColor);
|
||||
}
|
||||
else {
|
||||
return FontFactory.GetFont(this.Familyname, dSize, dStyle, (Color)dColor);
|
||||
}
|
||||
}
|
||||
return new Font(this.Family, dSize, dStyle, (Color)dColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
426
iTechSharp/iTextSharp/text/FontFactory.cs
Normal file
426
iTechSharp/iTextSharp/text/FontFactory.cs
Normal file
@@ -0,0 +1,426 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.util;
|
||||
using System.Globalization;
|
||||
|
||||
using iTextSharp.text.html;
|
||||
using iTextSharp.text.pdf;
|
||||
using iTextSharp.text;
|
||||
|
||||
/*
|
||||
* $Id: FontFactory.cs,v 1.16 2008/05/13 11:25:10 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
namespace iTextSharp.text {
|
||||
/// <summary>
|
||||
/// If you are using True Type fonts, you can declare the paths of the different ttf- and ttc-files
|
||||
/// to this static class first and then create fonts in your code using one of the static getFont-method
|
||||
/// without having to enter a path as parameter.
|
||||
/// </summary>
|
||||
public sealed class FontFactory {
|
||||
|
||||
/// <summary> This is a possible value of a base 14 type 1 font </summary>
|
||||
public const string COURIER = BaseFont.COURIER;
|
||||
|
||||
/// <summary> This is a possible value of a base 14 type 1 font </summary>
|
||||
public const string COURIER_BOLD = BaseFont.COURIER_BOLD;
|
||||
|
||||
/// <summary> This is a possible value of a base 14 type 1 font </summary>
|
||||
public const string COURIER_OBLIQUE = BaseFont.COURIER_OBLIQUE;
|
||||
|
||||
/// <summary> This is a possible value of a base 14 type 1 font </summary>
|
||||
public const string COURIER_BOLDOBLIQUE = BaseFont.COURIER_BOLDOBLIQUE;
|
||||
|
||||
/// <summary> This is a possible value of a base 14 type 1 font </summary>
|
||||
public const string HELVETICA = BaseFont.HELVETICA;
|
||||
|
||||
/// <summary> This is a possible value of a base 14 type 1 font </summary>
|
||||
public const string HELVETICA_BOLD = BaseFont.HELVETICA_BOLD;
|
||||
|
||||
/// <summary> This is a possible value of a base 14 type 1 font </summary>
|
||||
public const string HELVETICA_OBLIQUE = BaseFont.HELVETICA_OBLIQUE;
|
||||
|
||||
/// <summary> This is a possible value of a base 14 type 1 font </summary>
|
||||
public const string HELVETICA_BOLDOBLIQUE = BaseFont.HELVETICA_BOLDOBLIQUE;
|
||||
|
||||
/// <summary> This is a possible value of a base 14 type 1 font </summary>
|
||||
public const string SYMBOL = BaseFont.SYMBOL;
|
||||
|
||||
/// <summary> This is a possible value of a base 14 type 1 font </summary>
|
||||
public const string TIMES = "Times";
|
||||
|
||||
/// <summary> This is a possible value of a base 14 type 1 font </summary>
|
||||
public const string TIMES_ROMAN = BaseFont.TIMES_ROMAN;
|
||||
|
||||
/// <summary> This is a possible value of a base 14 type 1 font </summary>
|
||||
public const string TIMES_BOLD = BaseFont.TIMES_BOLD;
|
||||
|
||||
/// <summary> This is a possible value of a base 14 type 1 font </summary>
|
||||
public const string TIMES_ITALIC = BaseFont.TIMES_ITALIC;
|
||||
|
||||
/// <summary> This is a possible value of a base 14 type 1 font </summary>
|
||||
public const string TIMES_BOLDITALIC = BaseFont.TIMES_BOLDITALIC;
|
||||
|
||||
/// <summary> This is a possible value of a base 14 type 1 font </summary>
|
||||
public const string ZAPFDINGBATS = BaseFont.ZAPFDINGBATS;
|
||||
|
||||
private static FontFactoryImp fontImp = new FontFactoryImp();
|
||||
|
||||
/// <summary> This is the default encoding to use. </summary>
|
||||
private static string defaultEncoding = BaseFont.WINANSI;
|
||||
|
||||
/// <summary> This is the default value of the <VAR>embedded</VAR> variable. </summary>
|
||||
private static bool defaultEmbedding = BaseFont.NOT_EMBEDDED;
|
||||
|
||||
/// <summary> Creates new FontFactory </summary>
|
||||
private FontFactory() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font-object.
|
||||
/// </summary>
|
||||
/// <param name="fontname">the name of the font</param>
|
||||
/// <param name="encoding">the encoding of the font</param>
|
||||
/// <param name="embedded">true if the font is to be embedded in the PDF</param>
|
||||
/// <param name="size">the size of this font</param>
|
||||
/// <param name="style">the style of this font</param>
|
||||
/// <param name="color">the Color of this font</param>
|
||||
/// <returns>a Font object</returns>
|
||||
public static Font GetFont(string fontname, string encoding, bool embedded, float size, int style, Color color) {
|
||||
return fontImp.GetFont(fontname, encoding, embedded, size, style, color);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font-object.
|
||||
/// </summary>
|
||||
/// <param name="fontname">the name of the font</param>
|
||||
/// <param name="encoding">the encoding of the font</param>
|
||||
/// <param name="embedded">true if the font is to be embedded in the PDF</param>
|
||||
/// <param name="size">the size of this font</param>
|
||||
/// <param name="style">the style of this font</param>
|
||||
/// <param name="color">the Color of this font</param>
|
||||
/// <param name="cached">true if the font comes from the cache or is added to the cache if new, false if the font is always created new</param>
|
||||
/// <returns>a Font object</returns>
|
||||
public static Font GetFont(string fontname, string encoding, bool embedded, float size, int style, Color color, bool cached) {
|
||||
return fontImp.GetFont(fontname, encoding, embedded, size, style, color, cached);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font-object.
|
||||
/// </summary>
|
||||
/// <param name="attributes">the attributes of a Font object</param>
|
||||
/// <returns>a Font object</returns>
|
||||
public static Font GetFont(Properties attributes) {
|
||||
fontImp.DefaultEmbedding = defaultEmbedding;
|
||||
fontImp.DefaultEncoding = defaultEncoding;
|
||||
return fontImp.GetFont(attributes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font-object.
|
||||
/// </summary>
|
||||
/// <param name="fontname">the name of the font</param>
|
||||
/// <param name="encoding">the encoding of the font</param>
|
||||
/// <param name="embedded">true if the font is to be embedded in the PDF</param>
|
||||
/// <param name="size">the size of this font</param>
|
||||
/// <param name="style">the style of this font</param>
|
||||
/// <returns>a Font object</returns>
|
||||
public static Font GetFont(string fontname, string encoding, bool embedded, float size, int style) {
|
||||
return GetFont(fontname, encoding, embedded, size, style, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font-object.
|
||||
/// </summary>
|
||||
/// <param name="fontname">the name of the font</param>
|
||||
/// <param name="encoding">the encoding of the font</param>
|
||||
/// <param name="embedded">true if the font is to be embedded in the PDF</param>
|
||||
/// <param name="size">the size of this font</param>
|
||||
/// <returns></returns>
|
||||
public static Font GetFont(string fontname, string encoding, bool embedded, float size) {
|
||||
return GetFont(fontname, encoding, embedded, size, Font.UNDEFINED, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font-object.
|
||||
/// </summary>
|
||||
/// <param name="fontname">the name of the font</param>
|
||||
/// <param name="encoding">the encoding of the font</param>
|
||||
/// <param name="embedded">true if the font is to be embedded in the PDF</param>
|
||||
/// <returns>a Font object</returns>
|
||||
public static Font GetFont(string fontname, string encoding, bool embedded) {
|
||||
return GetFont(fontname, encoding, embedded, Font.UNDEFINED, Font.UNDEFINED, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font-object.
|
||||
/// </summary>
|
||||
/// <param name="fontname">the name of the font</param>
|
||||
/// <param name="encoding">the encoding of the font</param>
|
||||
/// <param name="size">the size of this font</param>
|
||||
/// <param name="style">the style of this font</param>
|
||||
/// <param name="color">the Color of this font</param>
|
||||
/// <returns>a Font object</returns>
|
||||
public static Font GetFont(string fontname, string encoding, float size, int style, Color color) {
|
||||
return GetFont(fontname, encoding, defaultEmbedding, size, style, color);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font-object.
|
||||
/// </summary>
|
||||
/// <param name="fontname">the name of the font</param>
|
||||
/// <param name="encoding">the encoding of the font</param>
|
||||
/// <param name="size">the size of this font</param>
|
||||
/// <param name="style">the style of this font</param>
|
||||
/// <returns>a Font object</returns>
|
||||
public static Font GetFont(string fontname, string encoding, float size, int style) {
|
||||
return GetFont(fontname, encoding, defaultEmbedding, size, style, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font-object.
|
||||
/// </summary>
|
||||
/// <param name="fontname">the name of the font</param>
|
||||
/// <param name="encoding">the encoding of the font</param>
|
||||
/// <param name="size">the size of this font</param>
|
||||
/// <returns>a Font object</returns>
|
||||
public static Font GetFont(string fontname, string encoding, float size) {
|
||||
return GetFont(fontname, encoding, defaultEmbedding, size, Font.UNDEFINED, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font-object.
|
||||
/// </summary>
|
||||
/// <param name="fontname">the name of the font</param>
|
||||
/// <param name="encoding">the encoding of the font</param>
|
||||
/// <returns>a Font object</returns>
|
||||
public static Font GetFont(string fontname, string encoding) {
|
||||
return GetFont(fontname, encoding, defaultEmbedding, Font.UNDEFINED, Font.UNDEFINED, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font-object.
|
||||
/// </summary>
|
||||
/// <param name="fontname">the name of the font</param>
|
||||
/// <param name="size">the size of this font</param>
|
||||
/// <param name="style">the style of this font</param>
|
||||
/// <param name="color">the Color of this font</param>
|
||||
/// <returns>a Font object</returns>
|
||||
public static Font GetFont(string fontname, float size, int style, Color color) {
|
||||
return GetFont(fontname, defaultEncoding, defaultEmbedding, size, style, color);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font-object.
|
||||
/// </summary>
|
||||
/// <param name="fontname">the name of the font</param>
|
||||
/// <param name="size">the size of this font</param>
|
||||
/// <param name="color">the Color of this font</param>
|
||||
/// <returns>a Font object</returns>
|
||||
public static Font GetFont(string fontname, float size, Color color) {
|
||||
return GetFont(fontname, defaultEncoding, defaultEmbedding, size, Font.UNDEFINED, color);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font-object.
|
||||
/// </summary>
|
||||
/// <param name="fontname">the name of the font</param>
|
||||
/// <param name="size">the size of this font</param>
|
||||
/// <param name="style">the style of this font</param>
|
||||
/// <returns>a Font object</returns>
|
||||
public static Font GetFont(string fontname, float size, int style) {
|
||||
return GetFont(fontname, defaultEncoding, defaultEmbedding, size, style, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font-object.
|
||||
/// </summary>
|
||||
/// <param name="fontname">the name of the font</param>
|
||||
/// <param name="size">the size of this font</param>
|
||||
/// <returns>a Font object</returns>
|
||||
public static Font GetFont(string fontname, float size) {
|
||||
return GetFont(fontname, defaultEncoding, defaultEmbedding, size, Font.UNDEFINED, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font-object.
|
||||
/// </summary>
|
||||
/// <param name="fontname">the name of the font</param>
|
||||
/// <returns>a Font object</returns>
|
||||
public static Font GetFont(string fontname) {
|
||||
return GetFont(fontname, defaultEncoding, defaultEmbedding, Font.UNDEFINED, Font.UNDEFINED, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a font by giving explicitly the font family and name.
|
||||
* @param familyName the font family
|
||||
* @param fullName the font name
|
||||
* @param path the font path
|
||||
*/
|
||||
public void RegisterFamily(String familyName, String fullName, String path) {
|
||||
fontImp.RegisterFamily(familyName, fullName, path);
|
||||
}
|
||||
|
||||
public static void Register(Properties attributes) {
|
||||
string path;
|
||||
string alias = null;
|
||||
|
||||
path = attributes.Remove("path");
|
||||
alias = attributes.Remove("alias");
|
||||
|
||||
fontImp.Register(path, alias);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register a ttf- or a ttc-file.
|
||||
/// </summary>
|
||||
/// <param name="path">the path to a ttf- or ttc-file</param>
|
||||
public static void Register(string path) {
|
||||
Register(path, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register a ttf- or a ttc-file and use an alias for the font contained in the ttf-file.
|
||||
/// </summary>
|
||||
/// <param name="path">the path to a ttf- or ttc-file</param>
|
||||
/// <param name="alias">the alias you want to use for the font</param>
|
||||
public static void Register(string path, string alias) {
|
||||
fontImp.Register(path, alias);
|
||||
}
|
||||
|
||||
/** Register all the fonts in a directory.
|
||||
* @param dir the directory
|
||||
* @return the number of fonts registered
|
||||
*/
|
||||
public static int RegisterDirectory(String dir) {
|
||||
return fontImp.RegisterDirectory(dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register all the fonts in a directory and possibly its subdirectories.
|
||||
* @param dir the directory
|
||||
* @param scanSubdirectories recursively scan subdirectories if <code>true</true>
|
||||
* @return the number of fonts registered
|
||||
* @since 2.1.2
|
||||
*/
|
||||
public static int RegisterDirectory(String dir, bool scanSubdirectories) {
|
||||
return fontImp.RegisterDirectory(dir, scanSubdirectories);
|
||||
}
|
||||
|
||||
/** Register fonts in some probable directories. It usually works in Windows,
|
||||
* Linux and Solaris.
|
||||
* @return the number of fonts registered
|
||||
*/
|
||||
public static int RegisterDirectories() {
|
||||
return fontImp.RegisterDirectories();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a set of registered fontnames.
|
||||
/// </summary>
|
||||
/// <value>a set of registered fontnames</value>
|
||||
public static ICollection RegisteredFonts {
|
||||
get {
|
||||
return fontImp.RegisteredFonts;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a set of registered font families.
|
||||
/// </summary>
|
||||
/// <value>a set of registered font families</value>
|
||||
public static ICollection RegisteredFamilies {
|
||||
get {
|
||||
return fontImp.RegisteredFamilies;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether the given font is contained within the object
|
||||
/// </summary>
|
||||
/// <param name="fontname">the name of the font</param>
|
||||
/// <returns>true if font is contained within the object</returns>
|
||||
public static bool Contains(string fontname) {
|
||||
return fontImp.IsRegistered(fontname);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a certain font is registered.
|
||||
/// </summary>
|
||||
/// <param name="fontname">the name of the font that has to be checked</param>
|
||||
/// <returns>true if the font is found</returns>
|
||||
public static bool IsRegistered(string fontname) {
|
||||
return fontImp.IsRegistered(fontname);
|
||||
}
|
||||
|
||||
public static string DefaultEncoding {
|
||||
get {
|
||||
return defaultEncoding;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool DefaultEmbedding {
|
||||
get {
|
||||
return defaultEmbedding;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static FontFactoryImp FontImp {
|
||||
get {
|
||||
return fontImp;
|
||||
}
|
||||
set {
|
||||
if (value == null)
|
||||
throw new ArgumentNullException("FontFactoryImp cannot be null.");
|
||||
fontImp = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
677
iTechSharp/iTextSharp/text/FontFactoryImp.cs
Normal file
677
iTechSharp/iTextSharp/text/FontFactoryImp.cs
Normal file
@@ -0,0 +1,677 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.util;
|
||||
using System.Globalization;
|
||||
|
||||
using iTextSharp.text.html;
|
||||
using iTextSharp.text.pdf;
|
||||
using iTextSharp.text;
|
||||
|
||||
/*
|
||||
* $Id: FontFactoryImp.cs,v 1.13 2008/05/13 11:25:10 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
namespace iTextSharp.text {
|
||||
/// <summary>
|
||||
/// If you are using True Type fonts, you can declare the paths of the different ttf- and ttc-files
|
||||
/// to this class first and then create fonts in your code using one of the getFont method
|
||||
/// without having to enter a path as parameter.
|
||||
/// </summary>
|
||||
public class FontFactoryImp {
|
||||
|
||||
/// <summary> This is a map of postscriptfontnames of True Type fonts and the path of their ttf- or ttc-file. </summary>
|
||||
private Properties trueTypeFonts = new Properties();
|
||||
|
||||
private static String[] TTFamilyOrder = {
|
||||
"3", "1", "1033",
|
||||
"3", "0", "1033",
|
||||
"1", "0", "0",
|
||||
"0", "3", "0"
|
||||
};
|
||||
|
||||
/// <summary> This is a map of fontfamilies. </summary>
|
||||
private Hashtable fontFamilies = new Hashtable();
|
||||
|
||||
/// <summary> This is the default encoding to use. </summary>
|
||||
private string defaultEncoding = BaseFont.WINANSI;
|
||||
|
||||
/// <summary> This is the default value of the <VAR>embedded</VAR> variable. </summary>
|
||||
private bool defaultEmbedding = BaseFont.NOT_EMBEDDED;
|
||||
|
||||
/// <summary> Creates new FontFactory </summary>
|
||||
public FontFactoryImp() {
|
||||
trueTypeFonts.Add(FontFactory.COURIER.ToLower(CultureInfo.InvariantCulture), FontFactory.COURIER);
|
||||
trueTypeFonts.Add(FontFactory.COURIER_BOLD.ToLower(CultureInfo.InvariantCulture), FontFactory.COURIER_BOLD);
|
||||
trueTypeFonts.Add(FontFactory.COURIER_OBLIQUE.ToLower(CultureInfo.InvariantCulture), FontFactory.COURIER_OBLIQUE);
|
||||
trueTypeFonts.Add(FontFactory.COURIER_BOLDOBLIQUE.ToLower(CultureInfo.InvariantCulture), FontFactory.COURIER_BOLDOBLIQUE);
|
||||
trueTypeFonts.Add(FontFactory.HELVETICA.ToLower(CultureInfo.InvariantCulture), FontFactory.HELVETICA);
|
||||
trueTypeFonts.Add(FontFactory.HELVETICA_BOLD.ToLower(CultureInfo.InvariantCulture), FontFactory.HELVETICA_BOLD);
|
||||
trueTypeFonts.Add(FontFactory.HELVETICA_OBLIQUE.ToLower(CultureInfo.InvariantCulture), FontFactory.HELVETICA_OBLIQUE);
|
||||
trueTypeFonts.Add(FontFactory.HELVETICA_BOLDOBLIQUE.ToLower(CultureInfo.InvariantCulture), FontFactory.HELVETICA_BOLDOBLIQUE);
|
||||
trueTypeFonts.Add(FontFactory.SYMBOL.ToLower(CultureInfo.InvariantCulture), FontFactory.SYMBOL);
|
||||
trueTypeFonts.Add(FontFactory.TIMES_ROMAN.ToLower(CultureInfo.InvariantCulture), FontFactory.TIMES_ROMAN);
|
||||
trueTypeFonts.Add(FontFactory.TIMES_BOLD.ToLower(CultureInfo.InvariantCulture), FontFactory.TIMES_BOLD);
|
||||
trueTypeFonts.Add(FontFactory.TIMES_ITALIC.ToLower(CultureInfo.InvariantCulture), FontFactory.TIMES_ITALIC);
|
||||
trueTypeFonts.Add(FontFactory.TIMES_BOLDITALIC.ToLower(CultureInfo.InvariantCulture), FontFactory.TIMES_BOLDITALIC);
|
||||
trueTypeFonts.Add(FontFactory.ZAPFDINGBATS.ToLower(CultureInfo.InvariantCulture), FontFactory.ZAPFDINGBATS);
|
||||
|
||||
ArrayList tmp;
|
||||
tmp = new ArrayList();
|
||||
tmp.Add(FontFactory.COURIER);
|
||||
tmp.Add(FontFactory.COURIER_BOLD);
|
||||
tmp.Add(FontFactory.COURIER_OBLIQUE);
|
||||
tmp.Add(FontFactory.COURIER_BOLDOBLIQUE);
|
||||
fontFamilies[FontFactory.COURIER.ToLower(CultureInfo.InvariantCulture)] = tmp;
|
||||
tmp = new ArrayList();
|
||||
tmp.Add(FontFactory.HELVETICA);
|
||||
tmp.Add(FontFactory.HELVETICA_BOLD);
|
||||
tmp.Add(FontFactory.HELVETICA_OBLIQUE);
|
||||
tmp.Add(FontFactory.HELVETICA_BOLDOBLIQUE);
|
||||
fontFamilies[FontFactory.HELVETICA.ToLower(CultureInfo.InvariantCulture)] = tmp;
|
||||
tmp = new ArrayList();
|
||||
tmp.Add(FontFactory.SYMBOL);
|
||||
fontFamilies[FontFactory.SYMBOL.ToLower(CultureInfo.InvariantCulture)] = tmp;
|
||||
tmp = new ArrayList();
|
||||
tmp.Add(FontFactory.TIMES_ROMAN);
|
||||
tmp.Add(FontFactory.TIMES_BOLD);
|
||||
tmp.Add(FontFactory.TIMES_ITALIC);
|
||||
tmp.Add(FontFactory.TIMES_BOLDITALIC);
|
||||
fontFamilies[FontFactory.TIMES.ToLower(CultureInfo.InvariantCulture)] = tmp;
|
||||
fontFamilies[FontFactory.TIMES_ROMAN.ToLower(CultureInfo.InvariantCulture)] = tmp;
|
||||
tmp = new ArrayList();
|
||||
tmp.Add(FontFactory.ZAPFDINGBATS);
|
||||
fontFamilies[FontFactory.ZAPFDINGBATS.ToLower(CultureInfo.InvariantCulture)] = tmp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font-object.
|
||||
/// </summary>
|
||||
/// <param name="fontname">the name of the font</param>
|
||||
/// <param name="encoding">the encoding of the font</param>
|
||||
/// <param name="embedded">true if the font is to be embedded in the PDF</param>
|
||||
/// <param name="size">the size of this font</param>
|
||||
/// <param name="style">the style of this font</param>
|
||||
/// <param name="color">the Color of this font</param>
|
||||
/// <returns>a Font object</returns>
|
||||
public virtual Font GetFont(string fontname, string encoding, bool embedded, float size, int style, Color color) {
|
||||
return GetFont(fontname, encoding, embedded, size, style, color, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font-object.
|
||||
/// </summary>
|
||||
/// <param name="fontname">the name of the font</param>
|
||||
/// <param name="encoding">the encoding of the font</param>
|
||||
/// <param name="embedded">true if the font is to be embedded in the PDF</param>
|
||||
/// <param name="size">the size of this font</param>
|
||||
/// <param name="style">the style of this font</param>
|
||||
/// <param name="color">the Color of this font</param>
|
||||
/// <param name="cached">true if the font comes from the cache or is added to the cache if new, false if the font is always created new</param>
|
||||
/// <returns>a Font object</returns>
|
||||
public virtual Font GetFont(string fontname, string encoding, bool embedded, float size, int style, Color color, bool cached) {
|
||||
if (fontname == null) return new Font(Font.UNDEFINED, size, style, color);
|
||||
string lowercasefontname = fontname.ToLower(CultureInfo.InvariantCulture);
|
||||
ArrayList tmp = (ArrayList) fontFamilies[lowercasefontname];
|
||||
if (tmp != null) {
|
||||
// some bugs were fixed here by Daniel Marczisovszky
|
||||
int fs = Font.NORMAL;
|
||||
bool found = false;
|
||||
int s = style == Font.UNDEFINED ? Font.NORMAL : style;
|
||||
foreach (string f in tmp) {
|
||||
string lcf = f.ToLower(CultureInfo.InvariantCulture);
|
||||
fs = Font.NORMAL;
|
||||
if (lcf.ToLower(CultureInfo.InvariantCulture).IndexOf("bold") != -1) fs |= Font.BOLD;
|
||||
if (lcf.ToLower(CultureInfo.InvariantCulture).IndexOf("italic") != -1 || lcf.ToLower(CultureInfo.InvariantCulture).IndexOf("oblique") != -1) fs |= Font.ITALIC;
|
||||
if ((s & Font.BOLDITALIC) == fs) {
|
||||
fontname = f;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (style != Font.UNDEFINED && found) {
|
||||
style &= ~fs;
|
||||
}
|
||||
}
|
||||
BaseFont basefont = null;
|
||||
try {
|
||||
try {
|
||||
// the font is a type 1 font or CJK font
|
||||
basefont = BaseFont.CreateFont(fontname, encoding, embedded, cached, null, null, true);
|
||||
}
|
||||
catch (DocumentException) {
|
||||
}
|
||||
if (basefont == null) {
|
||||
// the font is a true type font or an unknown font
|
||||
fontname = trueTypeFonts[fontname.ToLower(CultureInfo.InvariantCulture)];
|
||||
// the font is not registered as truetype font
|
||||
if (fontname == null) return new Font(Font.UNDEFINED, size, style, color);
|
||||
// the font is registered as truetype font
|
||||
basefont = BaseFont.CreateFont(fontname, encoding, embedded, cached, null, null);
|
||||
}
|
||||
}
|
||||
catch (DocumentException de) {
|
||||
// this shouldn't happen
|
||||
throw de;
|
||||
}
|
||||
catch (System.IO.IOException) {
|
||||
// the font is registered as a true type font, but the path was wrong
|
||||
return new Font(Font.UNDEFINED, size, style, color);
|
||||
}
|
||||
catch {
|
||||
// null was entered as fontname and/or encoding
|
||||
return new Font(Font.UNDEFINED, size, style, color);
|
||||
}
|
||||
return new Font(basefont, size, style, color);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font-object.
|
||||
/// </summary>
|
||||
/// <param name="attributes">the attributes of a Font object</param>
|
||||
/// <returns>a Font object</returns>
|
||||
public virtual Font GetFont(Properties attributes) {
|
||||
string fontname = null;
|
||||
string encoding = defaultEncoding;
|
||||
bool embedded = defaultEmbedding;
|
||||
float size = Font.UNDEFINED;
|
||||
int style = Font.NORMAL;
|
||||
Color color = null;
|
||||
string value = attributes[Markup.HTML_ATTR_STYLE];
|
||||
if (value != null && value.Length > 0) {
|
||||
Properties styleAttributes = Markup.ParseAttributes(value);
|
||||
if (styleAttributes.Count == 0) {
|
||||
attributes.Add(Markup.HTML_ATTR_STYLE, value);
|
||||
}
|
||||
else {
|
||||
fontname = styleAttributes[Markup.CSS_KEY_FONTFAMILY];
|
||||
if (fontname != null) {
|
||||
string tmp;
|
||||
while (fontname.IndexOf(',') != -1) {
|
||||
tmp = fontname.Substring(0, fontname.IndexOf(','));
|
||||
if (IsRegistered(tmp)) {
|
||||
fontname = tmp;
|
||||
}
|
||||
else {
|
||||
fontname = fontname.Substring(fontname.IndexOf(',') + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((value = styleAttributes[Markup.CSS_KEY_FONTSIZE]) != null) {
|
||||
size = Markup.ParseLength(value);
|
||||
}
|
||||
if ((value = styleAttributes[Markup.CSS_KEY_FONTWEIGHT]) != null) {
|
||||
style |= Font.GetStyleValue(value);
|
||||
}
|
||||
if ((value = styleAttributes[Markup.CSS_KEY_FONTSTYLE]) != null) {
|
||||
style |= Font.GetStyleValue(value);
|
||||
}
|
||||
if ((value = styleAttributes[Markup.CSS_KEY_COLOR]) != null) {
|
||||
color = Markup.DecodeColor(value);
|
||||
}
|
||||
attributes.AddAll(styleAttributes);
|
||||
}
|
||||
}
|
||||
if ((value = attributes[ElementTags.ENCODING]) != null) {
|
||||
encoding = value;
|
||||
}
|
||||
if ("true".Equals(attributes[ElementTags.EMBEDDED])) {
|
||||
embedded = true;
|
||||
}
|
||||
if ((value = attributes[ElementTags.FONT]) != null) {
|
||||
fontname = value;
|
||||
}
|
||||
if ((value = attributes[ElementTags.SIZE]) != null) {
|
||||
size = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
}
|
||||
if ((value = attributes[Markup.HTML_ATTR_STYLE]) != null) {
|
||||
style |= Font.GetStyleValue(value);
|
||||
}
|
||||
if ((value = attributes[ElementTags.STYLE]) != null) {
|
||||
style |= Font.GetStyleValue(value);
|
||||
}
|
||||
string r = attributes[ElementTags.RED];
|
||||
string g = attributes[ElementTags.GREEN];
|
||||
string b = attributes[ElementTags.BLUE];
|
||||
if (r != null || g != null || b != null) {
|
||||
int red = 0;
|
||||
int green = 0;
|
||||
int blue = 0;
|
||||
if (r != null) red = int.Parse(r);
|
||||
if (g != null) green = int.Parse(g);
|
||||
if (b != null) blue = int.Parse(b);
|
||||
color = new Color(red, green, blue);
|
||||
}
|
||||
else if ((value = attributes[ElementTags.COLOR]) != null) {
|
||||
color = Markup.DecodeColor(value);
|
||||
}
|
||||
if (fontname == null) {
|
||||
return GetFont(null, encoding, embedded, size, style, color);
|
||||
}
|
||||
return GetFont(fontname, encoding, embedded, size, style, color);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font-object.
|
||||
/// </summary>
|
||||
/// <param name="fontname">the name of the font</param>
|
||||
/// <param name="encoding">the encoding of the font</param>
|
||||
/// <param name="embedded">true if the font is to be embedded in the PDF</param>
|
||||
/// <param name="size">the size of this font</param>
|
||||
/// <param name="style">the style of this font</param>
|
||||
/// <returns>a Font object</returns>
|
||||
public Font GetFont(string fontname, string encoding, bool embedded, float size, int style) {
|
||||
return GetFont(fontname, encoding, embedded, size, style, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font-object.
|
||||
/// </summary>
|
||||
/// <param name="fontname">the name of the font</param>
|
||||
/// <param name="encoding">the encoding of the font</param>
|
||||
/// <param name="embedded">true if the font is to be embedded in the PDF</param>
|
||||
/// <param name="size">the size of this font</param>
|
||||
/// <returns></returns>
|
||||
public virtual Font GetFont(string fontname, string encoding, bool embedded, float size) {
|
||||
return GetFont(fontname, encoding, embedded, size, Font.UNDEFINED, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font-object.
|
||||
/// </summary>
|
||||
/// <param name="fontname">the name of the font</param>
|
||||
/// <param name="encoding">the encoding of the font</param>
|
||||
/// <param name="embedded">true if the font is to be embedded in the PDF</param>
|
||||
/// <returns>a Font object</returns>
|
||||
public virtual Font GetFont(string fontname, string encoding, bool embedded) {
|
||||
return GetFont(fontname, encoding, embedded, Font.UNDEFINED, Font.UNDEFINED, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font-object.
|
||||
/// </summary>
|
||||
/// <param name="fontname">the name of the font</param>
|
||||
/// <param name="encoding">the encoding of the font</param>
|
||||
/// <param name="size">the size of this font</param>
|
||||
/// <param name="style">the style of this font</param>
|
||||
/// <param name="color">the Color of this font</param>
|
||||
/// <returns>a Font object</returns>
|
||||
public virtual Font GetFont(string fontname, string encoding, float size, int style, Color color) {
|
||||
return GetFont(fontname, encoding, defaultEmbedding, size, style, color);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font-object.
|
||||
/// </summary>
|
||||
/// <param name="fontname">the name of the font</param>
|
||||
/// <param name="encoding">the encoding of the font</param>
|
||||
/// <param name="size">the size of this font</param>
|
||||
/// <param name="style">the style of this font</param>
|
||||
/// <returns>a Font object</returns>
|
||||
public virtual Font GetFont(string fontname, string encoding, float size, int style) {
|
||||
return GetFont(fontname, encoding, defaultEmbedding, size, style, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font-object.
|
||||
/// </summary>
|
||||
/// <param name="fontname">the name of the font</param>
|
||||
/// <param name="encoding">the encoding of the font</param>
|
||||
/// <param name="size">the size of this font</param>
|
||||
/// <returns>a Font object</returns>
|
||||
public virtual Font GetFont(string fontname, string encoding, float size) {
|
||||
return GetFont(fontname, encoding, defaultEmbedding, size, Font.UNDEFINED, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font-object.
|
||||
/// </summary>
|
||||
/// <param name="fontname">the name of the font</param>
|
||||
/// <param name="encoding">the encoding of the font</param>
|
||||
/// <returns>a Font object</returns>
|
||||
public virtual Font GetFont(string fontname, string encoding) {
|
||||
return GetFont(fontname, encoding, defaultEmbedding, Font.UNDEFINED, Font.UNDEFINED, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font-object.
|
||||
/// </summary>
|
||||
/// <param name="fontname">the name of the font</param>
|
||||
/// <param name="size">the size of this font</param>
|
||||
/// <param name="style">the style of this font</param>
|
||||
/// <param name="color">the Color of this font</param>
|
||||
/// <returns>a Font object</returns>
|
||||
public virtual Font GetFont(string fontname, float size, int style, Color color) {
|
||||
return GetFont(fontname, defaultEncoding, defaultEmbedding, size, style, color);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font-object.
|
||||
/// </summary>
|
||||
/// <param name="fontname">the name of the font</param>
|
||||
/// <param name="size">the size of this font</param>
|
||||
/// <param name="color">the Color of this font</param>
|
||||
/// <returns>a Font object</returns>
|
||||
public virtual Font GetFont(string fontname, float size, Color color) {
|
||||
return GetFont(fontname, defaultEncoding, defaultEmbedding, size, Font.UNDEFINED, color);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font-object.
|
||||
/// </summary>
|
||||
/// <param name="fontname">the name of the font</param>
|
||||
/// <param name="size">the size of this font</param>
|
||||
/// <param name="style">the style of this font</param>
|
||||
/// <returns>a Font object</returns>
|
||||
public virtual Font GetFont(string fontname, float size, int style) {
|
||||
return GetFont(fontname, defaultEncoding, defaultEmbedding, size, style, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font-object.
|
||||
/// </summary>
|
||||
/// <param name="fontname">the name of the font</param>
|
||||
/// <param name="size">the size of this font</param>
|
||||
/// <returns>a Font object</returns>
|
||||
public virtual Font GetFont(string fontname, float size) {
|
||||
return GetFont(fontname, defaultEncoding, defaultEmbedding, size, Font.UNDEFINED, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Font-object.
|
||||
/// </summary>
|
||||
/// <param name="fontname">the name of the font</param>
|
||||
/// <returns>a Font object</returns>
|
||||
public virtual Font GetFont(string fontname) {
|
||||
return GetFont(fontname, defaultEncoding, defaultEmbedding, Font.UNDEFINED, Font.UNDEFINED, null);
|
||||
}
|
||||
|
||||
public virtual void Register(Properties attributes) {
|
||||
string path;
|
||||
string alias = null;
|
||||
|
||||
path = attributes.Remove("path");
|
||||
alias = attributes.Remove("alias");
|
||||
|
||||
Register(path, alias);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a font by giving explicitly the font family and name.
|
||||
* @param familyName the font family
|
||||
* @param fullName the font name
|
||||
* @param path the font path
|
||||
*/
|
||||
public void RegisterFamily(String familyName, String fullName, String path) {
|
||||
if (path != null)
|
||||
trueTypeFonts.Add(fullName, path);
|
||||
ArrayList tmp = (ArrayList) fontFamilies[familyName];
|
||||
if (tmp == null) {
|
||||
tmp = new ArrayList();
|
||||
tmp.Add(fullName);
|
||||
fontFamilies[familyName] = tmp;
|
||||
}
|
||||
else {
|
||||
int fullNameLength = fullName.Length;
|
||||
bool inserted = false;
|
||||
for (int j = 0; j < tmp.Count; ++j) {
|
||||
if (((String)tmp[j]).Length >= fullNameLength) {
|
||||
tmp.Insert(j, fullName);
|
||||
inserted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!inserted)
|
||||
tmp.Add(fullName);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register a ttf- or a ttc-file.
|
||||
/// </summary>
|
||||
/// <param name="path">the path to a ttf- or ttc-file</param>
|
||||
public virtual void Register(string path) {
|
||||
Register(path, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register a ttf- or a ttc-file and use an alias for the font contained in the ttf-file.
|
||||
/// </summary>
|
||||
/// <param name="path">the path to a ttf- or ttc-file</param>
|
||||
/// <param name="alias">the alias you want to use for the font</param>
|
||||
public virtual void Register(string path, string alias) {
|
||||
try {
|
||||
if (path.ToLower(CultureInfo.InvariantCulture).EndsWith(".ttf") || path.ToLower(CultureInfo.InvariantCulture).EndsWith(".otf") || path.ToLower(CultureInfo.InvariantCulture).IndexOf(".ttc,") > 0) {
|
||||
Object[] allNames = BaseFont.GetAllFontNames(path, BaseFont.WINANSI, null);
|
||||
trueTypeFonts.Add(((string)allNames[0]).ToLower(CultureInfo.InvariantCulture), path);
|
||||
if (alias != null) {
|
||||
trueTypeFonts.Add(alias.ToLower(CultureInfo.InvariantCulture), path);
|
||||
}
|
||||
// register all the font names with all the locales
|
||||
string[][] names = (string[][])allNames[2]; //full name
|
||||
for (int i = 0; i < names.Length; i++) {
|
||||
trueTypeFonts.Add(names[i][3].ToLower(CultureInfo.InvariantCulture), path);
|
||||
}
|
||||
string fullName = null;
|
||||
string familyName = null;
|
||||
names = (string[][])allNames[1]; //family name
|
||||
for (int k = 0; k < TTFamilyOrder.Length; k += 3) {
|
||||
for (int i = 0; i < names.Length; i++) {
|
||||
if (TTFamilyOrder[k].Equals(names[i][0]) && TTFamilyOrder[k + 1].Equals(names[i][1]) && TTFamilyOrder[k + 2].Equals(names[i][2])) {
|
||||
familyName = names[i][3].ToLower(CultureInfo.InvariantCulture);
|
||||
k = TTFamilyOrder.Length;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (familyName != null) {
|
||||
String lastName = "";
|
||||
names = (string[][])allNames[2]; //full name
|
||||
for (int i = 0; i < names.Length; i++) {
|
||||
for (int k = 0; k < TTFamilyOrder.Length; k += 3) {
|
||||
if (TTFamilyOrder[k].Equals(names[i][0]) && TTFamilyOrder[k + 1].Equals(names[i][1]) && TTFamilyOrder[k + 2].Equals(names[i][2])) {
|
||||
fullName = names[i][3];
|
||||
if (fullName.Equals(lastName))
|
||||
continue;
|
||||
lastName = fullName;
|
||||
RegisterFamily(familyName, fullName, null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (path.ToLower(CultureInfo.InvariantCulture).EndsWith(".ttc")) {
|
||||
string[] names = BaseFont.EnumerateTTCNames(path);
|
||||
for (int i = 0; i < names.Length; i++) {
|
||||
Register(path + "," + i);
|
||||
}
|
||||
}
|
||||
else if (path.ToLower(CultureInfo.InvariantCulture).EndsWith(".afm") || path.ToLower(CultureInfo.InvariantCulture).EndsWith(".pfm")) {
|
||||
BaseFont bf = BaseFont.CreateFont(path, BaseFont.CP1252, false);
|
||||
String fullName = (bf.FullFontName[0][3]).ToLower(CultureInfo.InvariantCulture);
|
||||
String familyName = (bf.FamilyFontName[0][3]).ToLower(CultureInfo.InvariantCulture);
|
||||
String psName = bf.PostscriptFontName.ToLower(CultureInfo.InvariantCulture);
|
||||
RegisterFamily(familyName, fullName, null);
|
||||
trueTypeFonts.Add(psName, path);
|
||||
trueTypeFonts.Add(fullName, path);
|
||||
}
|
||||
}
|
||||
catch (DocumentException de) {
|
||||
// this shouldn't happen
|
||||
throw de;
|
||||
}
|
||||
catch (System.IO.IOException ioe) {
|
||||
throw ioe;
|
||||
}
|
||||
}
|
||||
|
||||
/** Register all the fonts in a directory.
|
||||
* @param dir the directory
|
||||
* @return the number of fonts registered
|
||||
*/
|
||||
public virtual int RegisterDirectory(String dir) {
|
||||
return RegisterDirectory(dir, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register all the fonts in a directory and possibly its subdirectories.
|
||||
* @param dir the directory
|
||||
* @param scanSubdirectories recursively scan subdirectories if <code>true</true>
|
||||
* @return the number of fonts registered
|
||||
* @since 2.1.2
|
||||
*/
|
||||
public int RegisterDirectory(String dir, bool scanSubdirectories) {
|
||||
int count = 0;
|
||||
try {
|
||||
if (!Directory.Exists(dir))
|
||||
return 0;
|
||||
string[] files = Directory.GetFiles(dir);
|
||||
if (files == null)
|
||||
return 0;
|
||||
for (int k = 0; k < files.Length; ++k) {
|
||||
try {
|
||||
if (Directory.Exists(files[k])) {
|
||||
if (scanSubdirectories) {
|
||||
count += RegisterDirectory(Path.GetFullPath(files[k]), true);
|
||||
}
|
||||
} else {
|
||||
String name = Path.GetFullPath(files[k]);
|
||||
String suffix = name.Length < 4 ? null : name.Substring(name.Length - 4).ToLower(CultureInfo.InvariantCulture);
|
||||
if (".afm".Equals(suffix) || ".pfm".Equals(suffix)) {
|
||||
/* Only register Type 1 fonts with matching .pfb files */
|
||||
string pfb = name.Substring(0, name.Length - 4) + ".pfb";
|
||||
if (File.Exists(pfb)) {
|
||||
Register(name, null);
|
||||
++count;
|
||||
}
|
||||
} else if (".ttf".Equals(suffix) || ".otf".Equals(suffix) || ".ttc".Equals(suffix)) {
|
||||
Register(name, null);
|
||||
++count;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch {
|
||||
//empty on purpose
|
||||
}
|
||||
}
|
||||
}
|
||||
catch {
|
||||
//empty on purpose
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/** Register fonts in some probable directories. It usually works in Windows,
|
||||
* Linux and Solaris.
|
||||
* @return the number of fonts registered
|
||||
*/
|
||||
public virtual int RegisterDirectories() {
|
||||
int count = 0;
|
||||
count += RegisterDirectory("c:/windows/fonts");
|
||||
count += RegisterDirectory("c:/winnt/fonts");
|
||||
count += RegisterDirectory("d:/windows/fonts");
|
||||
count += RegisterDirectory("d:/winnt/fonts");
|
||||
count += RegisterDirectory("/usr/share/X11/fonts", true);
|
||||
count += RegisterDirectory("/usr/X/lib/X11/fonts", true);
|
||||
count += RegisterDirectory("/usr/openwin/lib/X11/fonts", true);
|
||||
count += RegisterDirectory("/usr/share/fonts", true);
|
||||
count += RegisterDirectory("/usr/X11R6/lib/X11/fonts", true);
|
||||
count += RegisterDirectory("/Library/Fonts");
|
||||
count += RegisterDirectory("/System/Library/Fonts");
|
||||
return count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a set of registered fontnames.
|
||||
/// </summary>
|
||||
/// <value>a set of registered fontnames</value>
|
||||
public virtual ICollection RegisteredFonts {
|
||||
get {
|
||||
return trueTypeFonts.Keys;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a set of registered font families.
|
||||
/// </summary>
|
||||
/// <value>a set of registered font families</value>
|
||||
public virtual ICollection RegisteredFamilies {
|
||||
get {
|
||||
return fontFamilies.Keys;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a certain font is registered.
|
||||
/// </summary>
|
||||
/// <param name="fontname">the name of the font that has to be checked</param>
|
||||
/// <returns>true if the font is found</returns>
|
||||
public virtual bool IsRegistered(string fontname) {
|
||||
return trueTypeFonts.ContainsKey(fontname.ToLower(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
public virtual string DefaultEncoding {
|
||||
get {
|
||||
return defaultEncoding;
|
||||
}
|
||||
set {
|
||||
defaultEncoding = value;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool DefaultEmbedding {
|
||||
get {
|
||||
return defaultEmbedding;
|
||||
}
|
||||
set {
|
||||
defaultEmbedding = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
124
iTechSharp/iTextSharp/text/GreekList.cs
Normal file
124
iTechSharp/iTextSharp/text/GreekList.cs
Normal file
@@ -0,0 +1,124 @@
|
||||
using System;
|
||||
using iTextSharp.text.factories;
|
||||
/*
|
||||
* Copyright 2003 by Michael Niedermair.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text
|
||||
{
|
||||
/**
|
||||
*
|
||||
* A special-version of <CODE>LIST</CODE> whitch use greek-letters.
|
||||
*
|
||||
* @see com.lowagie.text.List
|
||||
*/
|
||||
public class GreekList : List {
|
||||
/**
|
||||
* Initialization
|
||||
*
|
||||
* @param symbolIndent indent
|
||||
*/
|
||||
public GreekList() : base(true) {
|
||||
SetGreekFont();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialisierung
|
||||
*
|
||||
* @param symbolIndent indent
|
||||
*/
|
||||
public GreekList(int symbolIndent) : base(true, symbolIndent) {
|
||||
SetGreekFont();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialisierung
|
||||
* @param greeklower greek-char in lowercase
|
||||
* @param symbolIndent indent
|
||||
*/
|
||||
public GreekList(bool greeklower, int symbolIndent) : base(true, symbolIndent) {
|
||||
lowercase = greeklower;
|
||||
SetGreekFont();
|
||||
}
|
||||
|
||||
/**
|
||||
* change the font to SYMBOL
|
||||
*/
|
||||
protected void SetGreekFont() {
|
||||
float fontsize = symbol.Font.Size;
|
||||
symbol.Font = FontFactory.GetFont(FontFactory.SYMBOL, fontsize, Font.NORMAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an <CODE>Object</CODE> to the <CODE>List</CODE>.
|
||||
*
|
||||
* @param o the object to add.
|
||||
* @return true if adding the object succeeded
|
||||
*/
|
||||
public override bool Add(Object o) {
|
||||
if (o is ListItem) {
|
||||
ListItem item = (ListItem) o;
|
||||
Chunk chunk = new Chunk(preSymbol, symbol.Font);
|
||||
chunk.Append(GreekAlphabetFactory.GetString(first + list.Count, lowercase));
|
||||
chunk.Append(postSymbol);
|
||||
item.ListSymbol = chunk;
|
||||
item.SetIndentationLeft(symbolIndent, autoindent);
|
||||
item.IndentationRight = 0;
|
||||
list.Add(item);
|
||||
return true;
|
||||
} else if (o is List) {
|
||||
List nested = (List) o;
|
||||
nested.IndentationLeft = nested.IndentationLeft + symbolIndent;
|
||||
first--;
|
||||
list.Add(nested);
|
||||
return true;
|
||||
} else if (o is string) {
|
||||
return this.Add(new ListItem((string)o));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
94
iTechSharp/iTextSharp/text/Header.cs
Normal file
94
iTechSharp/iTextSharp/text/Header.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
/*
|
||||
* $Id: Header.cs,v 1.4 2008/05/13 11:25:10 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text {
|
||||
/// <summary>
|
||||
/// This is an Element that contains
|
||||
/// some userdefined meta information about the document.
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// <strong>Header header = new Header("inspired by", "William Shakespeare");</strong>
|
||||
/// </code>
|
||||
/// </example>
|
||||
public class Header : Meta {
|
||||
|
||||
// membervariables
|
||||
|
||||
/// <summary> This is the content of this chunk of text. </summary>
|
||||
private StringBuilder name;
|
||||
|
||||
// constructors
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Header.
|
||||
/// </summary>
|
||||
/// <param name="name">the name of the meta-information</param>
|
||||
/// <param name="content">the content</param>
|
||||
public Header(string name, string content) : base(Element.HEADER, content) {
|
||||
this.name = new StringBuilder(name);
|
||||
}
|
||||
|
||||
// methods to retrieve information
|
||||
|
||||
/// <summary>
|
||||
/// Returns the name of the meta information.
|
||||
/// </summary>
|
||||
/// <value>a string</value>
|
||||
public override string Name {
|
||||
get {
|
||||
return name.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
234
iTechSharp/iTextSharp/text/HeaderFooter.cs
Normal file
234
iTechSharp/iTextSharp/text/HeaderFooter.cs
Normal file
@@ -0,0 +1,234 @@
|
||||
using System;
|
||||
using System.util;
|
||||
using System.Collections;
|
||||
|
||||
/*
|
||||
* $Id: HeaderFooter.cs,v 1.6 2008/05/13 11:25:10 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text {
|
||||
/// <summary>
|
||||
/// A HeaderFooter-object is a Rectangle with text
|
||||
/// that can be put above and/or below every page.
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// <strong>HeaderFooter header = new HeaderFooter(new Phrase("This is a header."), false);
|
||||
/// HeaderFooter footer = new HeaderFooter(new Phrase("This is page "), new Phrase("."));</strong>
|
||||
/// document.SetHeader(header);
|
||||
/// document.SetFooter(footer);
|
||||
/// </code>
|
||||
/// </example>
|
||||
public class HeaderFooter : Rectangle {
|
||||
|
||||
// membervariables
|
||||
|
||||
/// <summary> Does the page contain a pagenumber? </summary>
|
||||
private bool numbered;
|
||||
|
||||
/// <summary> This is the Phrase that comes before the pagenumber. </summary>
|
||||
private Phrase before = null;
|
||||
|
||||
/// <summary> This is number of the page. </summary>
|
||||
private int pageN;
|
||||
|
||||
/// <summary> This is the Phrase that comes after the pagenumber. </summary>
|
||||
private Phrase after = null;
|
||||
|
||||
/// <summary> This is alignment of the header/footer. </summary>
|
||||
private int alignment;
|
||||
|
||||
// constructors
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a HeaderFooter-object.
|
||||
/// </summary>
|
||||
/// <param name="before">the Phrase before the pagenumber</param>
|
||||
/// <param name="after">the Phrase after the pagenumber</param>
|
||||
public HeaderFooter(Phrase before, Phrase after) : base(0, 0, 0, 0) {
|
||||
this.Border = TOP_BORDER + BOTTOM_BORDER;
|
||||
this.BorderWidth = 1;
|
||||
|
||||
numbered = true;
|
||||
this.before = before;
|
||||
this.after = after;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Header-object with a pagenumber at the end.
|
||||
/// </summary>
|
||||
/// <param name="before">the Phrase before the pagenumber</param>
|
||||
/// <param name="numbered">true if the page has to be numbered</param>
|
||||
public HeaderFooter(Phrase before, bool numbered) : base(0, 0, 0, 0) {
|
||||
this.Border = TOP_BORDER + BOTTOM_BORDER;
|
||||
this.BorderWidth = 1;
|
||||
|
||||
this.numbered = numbered;
|
||||
this.before = before;
|
||||
}
|
||||
|
||||
public HeaderFooter(Properties attributes) : base(0, 0, 0, 0) {
|
||||
string value;
|
||||
|
||||
if ((value = attributes.Remove(ElementTags.NUMBERED)) != null) {
|
||||
this.numbered = bool.Parse(value);
|
||||
}
|
||||
if ((value = attributes.Remove(ElementTags.ALIGN)) != null) {
|
||||
this.SetAlignment(value);
|
||||
}
|
||||
if ((value = attributes.Remove("border")) != null) {
|
||||
this.Border = int.Parse(value);
|
||||
} else {
|
||||
this.Border = TOP_BORDER + BOTTOM_BORDER;
|
||||
}
|
||||
}
|
||||
|
||||
// methods
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the HeaderFooter contains a page number.
|
||||
/// </summary>
|
||||
/// <returns>true if the page has to be numbered</returns>
|
||||
public bool IsNumbered() {
|
||||
return numbered;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get/set the part that comes before the pageNumber.
|
||||
/// </summary>
|
||||
/// <value>a Phrase</value>
|
||||
public Phrase Before {
|
||||
get {
|
||||
return before;
|
||||
}
|
||||
|
||||
set {
|
||||
this.before = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get/set the part that comes after the pageNumber.
|
||||
/// </summary>
|
||||
/// <value>a Phrase</value>
|
||||
public Phrase After {
|
||||
get {
|
||||
return after;
|
||||
}
|
||||
|
||||
set {
|
||||
this.after = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the page number.
|
||||
/// </summary>
|
||||
/// <value>the new page number</value>
|
||||
public int PageNumber {
|
||||
set {
|
||||
this.pageN = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the Element.
|
||||
/// </summary>
|
||||
/// <value>the new alignment</value>
|
||||
public int Alignment{
|
||||
set {
|
||||
this.alignment = value;
|
||||
}
|
||||
get {
|
||||
return this.alignment;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the alignment of this HeaderFooter.
|
||||
/// </summary>
|
||||
/// <param name="alignment">the new alignment as a string</param>
|
||||
public void SetAlignment(string alignment) {
|
||||
if (Util.EqualsIgnoreCase(alignment, ElementTags.ALIGN_CENTER)) {
|
||||
this.alignment = Element.ALIGN_CENTER;
|
||||
return;
|
||||
}
|
||||
if (Util.EqualsIgnoreCase(alignment, ElementTags.ALIGN_RIGHT)) {
|
||||
this.alignment = Element.ALIGN_RIGHT;
|
||||
return;
|
||||
}
|
||||
if (Util.EqualsIgnoreCase(alignment, ElementTags.ALIGN_JUSTIFIED)) {
|
||||
this.alignment = Element.ALIGN_JUSTIFIED;
|
||||
return;
|
||||
}
|
||||
this.alignment = Element.ALIGN_LEFT;
|
||||
}
|
||||
|
||||
// methods to retrieve the membervariables
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Paragraph that can be used as header or footer.
|
||||
/// </summary>
|
||||
/// <returns>a Paragraph</returns>
|
||||
public Paragraph Paragraph {
|
||||
get {
|
||||
Paragraph paragraph = new Paragraph(before.Leading);
|
||||
paragraph.Add(before);
|
||||
if (numbered) {
|
||||
paragraph.AddSpecial(new Chunk(pageN.ToString(), before.Font));
|
||||
}
|
||||
if (after != null) {
|
||||
paragraph.AddSpecial(after);
|
||||
}
|
||||
paragraph.Alignment = alignment;
|
||||
return paragraph;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
149
iTechSharp/iTextSharp/text/IDocListener.cs
Normal file
149
iTechSharp/iTextSharp/text/IDocListener.cs
Normal file
@@ -0,0 +1,149 @@
|
||||
using System;
|
||||
|
||||
/*
|
||||
* $Id: IDocListener.cs,v 1.5 2008/05/13 11:25:10 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright (c) 1999, 2000, 2001, 2002 Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text {
|
||||
/// <summary>
|
||||
/// A class that implements DocListener will perform some
|
||||
/// actions when some actions are performed on a Document.
|
||||
/// </summary>
|
||||
/// <seealso cref="T:iTextSharp.text.IElementListener"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Document"/>
|
||||
/// <seealso cref="T:iTextSharp.text.DocWriter"/>
|
||||
public interface IDocListener : IElementListener {
|
||||
|
||||
// methods
|
||||
|
||||
/// <summary>
|
||||
/// Signals that the Document has been opened and that
|
||||
/// Elements can be added.
|
||||
/// </summary>
|
||||
void Open();
|
||||
|
||||
/// <summary>
|
||||
/// Signals that the Document was closed and that no other
|
||||
/// Elements will be added.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The output stream of every writer implementing IDocListener will be closed.
|
||||
/// </remarks>
|
||||
void Close();
|
||||
|
||||
/// <summary>
|
||||
/// Signals that an new page has to be started.
|
||||
/// </summary>
|
||||
/// <returns>true if the page was added, false if not.</returns>
|
||||
bool NewPage();
|
||||
|
||||
/// <summary>
|
||||
/// Sets the pagesize.
|
||||
/// </summary>
|
||||
/// <param name="pageSize">the new pagesize</param>
|
||||
/// <returns>a boolean</returns>
|
||||
bool SetPageSize(Rectangle pageSize);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the margins.
|
||||
/// </summary>
|
||||
/// <param name="marginLeft">the margin on the left</param>
|
||||
/// <param name="marginRight">the margin on the right</param>
|
||||
/// <param name="marginTop">the margin on the top</param>
|
||||
/// <param name="marginBottom">the margin on the bottom</param>
|
||||
/// <returns></returns>
|
||||
bool SetMargins(float marginLeft, float marginRight, float marginTop, float marginBottom);
|
||||
|
||||
/**
|
||||
* Parameter that allows you to do margin mirroring (odd/even pages)
|
||||
* @param marginMirroring
|
||||
* @return true if succesfull
|
||||
*/
|
||||
bool SetMarginMirroring(bool marginMirroring);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the page number.
|
||||
/// </summary>
|
||||
/// <value>the new page number</value>
|
||||
int PageCount {
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the page number to 0.
|
||||
/// </summary>
|
||||
void ResetPageCount();
|
||||
|
||||
/// <summary>
|
||||
/// Changes the header of this document.
|
||||
/// </summary>
|
||||
/// <value>a Header</value>
|
||||
HeaderFooter Header {
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the header of this document.
|
||||
/// </summary>
|
||||
void ResetHeader();
|
||||
|
||||
/// <summary>
|
||||
/// Changes the footer of this document.
|
||||
/// </summary>
|
||||
/// <value>a Footer</value>
|
||||
HeaderFooter Footer {
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the footer of this document.
|
||||
/// </summary>
|
||||
void ResetFooter();
|
||||
}
|
||||
}
|
||||
126
iTechSharp/iTextSharp/text/IElement.cs
Normal file
126
iTechSharp/iTextSharp/text/IElement.cs
Normal file
@@ -0,0 +1,126 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
/*
|
||||
* $Id: IElement.cs,v 1.4 2008/05/13 11:25:10 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
namespace iTextSharp.text {
|
||||
/// <summary>
|
||||
/// Interface for a text element.
|
||||
/// </summary>
|
||||
/// <seealso cref="T:iTextSharp.text.Anchor"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Cell"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Chapter"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Chunk"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Gif"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Graphic"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Header"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Image"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Jpeg"/>
|
||||
/// <seealso cref="T:iTextSharp.text.List"/>
|
||||
/// <seealso cref="T:iTextSharp.text.ListItem"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Meta"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Paragraph"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Phrase"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Rectangle"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Row"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Section"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Table"/>
|
||||
public interface IElement {
|
||||
|
||||
// methods
|
||||
|
||||
/// <summary>
|
||||
/// Processes the element by adding it (or the different parts) to an
|
||||
/// IElementListener.
|
||||
/// </summary>
|
||||
/// <param name="listener">an IElementListener</param>
|
||||
/// <returns>true if the element was processed successfully</returns>
|
||||
bool Process(IElementListener listener);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of the text element.
|
||||
/// </summary>
|
||||
/// <value>a type</value>
|
||||
int Type {
|
||||
get;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this element is a content object.
|
||||
* If not, it's a metadata object.
|
||||
* @since iText 2.0.8
|
||||
* @return true if this is a 'content' element; false if this is a 'medadata' element
|
||||
*/
|
||||
|
||||
bool IsContent();
|
||||
|
||||
/**
|
||||
* Checks if this element is nestable.
|
||||
* @since iText 2.0.8
|
||||
* @return true if this element can be nested inside other elements.
|
||||
*/
|
||||
|
||||
bool IsNestable();
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the chunks in this element.
|
||||
/// </summary>
|
||||
/// <value>an ArrayList</value>
|
||||
ArrayList Chunks {
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the content of the text element.
|
||||
/// </summary>
|
||||
/// <returns>the content of the text element</returns>
|
||||
string ToString();
|
||||
}
|
||||
}
|
||||
16
iTechSharp/iTextSharp/text/IElementListener.cs
Normal file
16
iTechSharp/iTextSharp/text/IElementListener.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
|
||||
namespace iTextSharp.text {
|
||||
/// <summary>
|
||||
/// A class that implements ElementListener will perform some
|
||||
/// actions when an Element is added.
|
||||
/// </summary>
|
||||
public interface IElementListener {
|
||||
/// <summary>
|
||||
/// Signals that an Element was added to the Document.
|
||||
/// </summary>
|
||||
/// <param name="element">Element added</param>
|
||||
/// <returns>true if the element was added, false if not.</returns>
|
||||
bool Add(IElement element);
|
||||
}
|
||||
}
|
||||
84
iTechSharp/iTextSharp/text/ILargeElement.cs
Normal file
84
iTechSharp/iTextSharp/text/ILargeElement.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using System;
|
||||
/*
|
||||
* $Id: ILargeElement.cs,v 1.2 2008/05/13 11:25:10 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text {
|
||||
|
||||
/**
|
||||
* Interface implemented by Element objects that can potentially consume
|
||||
* a lot of memory. Objects implementing the LargeElement interface can
|
||||
* be added to a Document more than once. If you have invoked setCompleted(false),
|
||||
* they will be added partially and the content that was added will be
|
||||
* removed until you've invoked setCompleted(true);
|
||||
* @since iText 2.0.8
|
||||
*/
|
||||
|
||||
public interface ILargeElement : IElement {
|
||||
|
||||
/**
|
||||
* If you invoke setCompleted(false), you indicate that the content
|
||||
* of the object isn't complete yet; it can be added to the document
|
||||
* partially, but more will follow. If you invoke setCompleted(true),
|
||||
* you indicate that you won't add any more data to the object.
|
||||
* @since iText 2.0.8
|
||||
* @param complete false if you'll be adding more data after
|
||||
* adding the object to the document.
|
||||
*/
|
||||
bool ElementComplete {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes the content that has been added.
|
||||
*/
|
||||
void FlushContent();
|
||||
}
|
||||
}
|
||||
60
iTechSharp/iTextSharp/text/IRtfElementInterface.cs
Normal file
60
iTechSharp/iTextSharp/text/IRtfElementInterface.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* $Id: IRtfElementInterface.cs,v 1.2 2008/05/13 11:25:11 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2008 by Bruno Lowagie
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text {
|
||||
|
||||
/**
|
||||
* The RTF jar depends on the iText jar, but the iText jar may not
|
||||
* depend on the RTF jar. This interface offers a temporary solution
|
||||
* until we find a more elegant way to solve this.
|
||||
*/
|
||||
public interface IRtfElementInterface {
|
||||
}
|
||||
}
|
||||
94
iTechSharp/iTextSharp/text/ISplitCharacter.cs
Normal file
94
iTechSharp/iTextSharp/text/ISplitCharacter.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using System;
|
||||
using iTextSharp.text.pdf;
|
||||
/*
|
||||
* $Id: ISplitCharacter.cs,v 1.3 2008/05/13 11:25:11 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2001, 2002 by Paulo Soares
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
namespace iTextSharp.text {
|
||||
/// <summary>
|
||||
/// Interface for customizing the split character.
|
||||
/// </summary>
|
||||
public interface ISplitCharacter {
|
||||
/**
|
||||
* Returns <CODE>true</CODE> if the character can split a line. The splitting implementation
|
||||
* is free to look ahead or look behind characters to make a decision.
|
||||
* <p>
|
||||
* The default implementation is:
|
||||
* <p>
|
||||
* <pre>
|
||||
* public boolean IsSplitCharacter(int start, int current, int end, char[] cc, PdfChunk[] ck) {
|
||||
* char c;
|
||||
* if (ck == null)
|
||||
* c = cc[current];
|
||||
* else
|
||||
* c = ck[Math.Min(current, ck.length - 1)].GetUnicodeEquivalent(cc[current]);
|
||||
* if (c <= ' ' || c == '-') {
|
||||
* return true;
|
||||
* }
|
||||
* if (c < 0x2e80)
|
||||
* return false;
|
||||
* return ((c >= 0x2e80 && c < 0xd7a0)
|
||||
* || (c >= 0xf900 && c < 0xfb00)
|
||||
* || (c >= 0xfe30 && c < 0xfe50)
|
||||
* || (c >= 0xff61 && c < 0xffa0));
|
||||
* }
|
||||
* </pre>
|
||||
* @param start the lower limit of <CODE>cc</CODE> inclusive
|
||||
* @param current the pointer to the character in <CODE>cc</CODE>
|
||||
* @param end the upper limit of <CODE>cc</CODE> exclusive
|
||||
* @param cc an array of characters at least <CODE>end</CODE> sized
|
||||
* @param ck an array of <CODE>PdfChunk</CODE>. The main use is to be able to call
|
||||
* {@link PdfChunk#getUnicodeEquivalent(char)}. It may be <CODE>null</CODE>
|
||||
* or shorter than <CODE>end</CODE>. If <CODE>null</CODE> no convertion takes place.
|
||||
* If shorter than <CODE>end</CODE> the last element is used
|
||||
* @return <CODE>true</CODE> if the Character(s) can split a line
|
||||
*/
|
||||
|
||||
bool IsSplitCharacter(int start, int current, int end, char[] cc, PdfChunk[] ck);
|
||||
}
|
||||
}
|
||||
22
iTechSharp/iTextSharp/text/ITextElementArray.cs
Normal file
22
iTechSharp/iTextSharp/text/ITextElementArray.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
|
||||
namespace iTextSharp.text {
|
||||
/// <summary>
|
||||
/// Interface for a text element to which other objects can be added.
|
||||
/// </summary>
|
||||
/// <seealso cref="T:iTextSharp.text.Phrase"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Paragraph"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Section"/>
|
||||
/// <seealso cref="T:iTextSharp.text.ListItem"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Chapter"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Anchor"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Cell"/>
|
||||
public interface ITextElementArray : IElement {
|
||||
/// <summary>
|
||||
/// Adds an object to the TextElementArray.
|
||||
/// </summary>
|
||||
/// <param name="o">an object that has to be added</param>
|
||||
/// <returns>true if the addition succeeded; false otherwise</returns>
|
||||
bool Add(Object o);
|
||||
}
|
||||
}
|
||||
1483
iTechSharp/iTextSharp/text/Image.cs
Normal file
1483
iTechSharp/iTextSharp/text/Image.cs
Normal file
File diff suppressed because it is too large
Load Diff
107
iTechSharp/iTextSharp/text/ImgCCITT.cs
Normal file
107
iTechSharp/iTextSharp/text/ImgCCITT.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
using System;
|
||||
using iTextSharp.text.pdf.codec;
|
||||
|
||||
/*
|
||||
* $Id: ImgCCITT.cs,v 1.6 2008/05/13 11:25:11 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2000, 2001, 2002 by Paulo Soares.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text {
|
||||
/**
|
||||
* CCITT Image data that has to be inserted into the document
|
||||
*
|
||||
* @see Element
|
||||
* @see Image
|
||||
*
|
||||
* @author Paulo Soares
|
||||
*/
|
||||
/// <summary>
|
||||
/// CCITT Image data that has to be inserted into the document
|
||||
/// </summary>
|
||||
/// <seealso cref="T:iTextSharp.text.Element"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Image"/>
|
||||
public class ImgCCITT : Image {
|
||||
public ImgCCITT(Image image) : base(image) {}
|
||||
|
||||
/// <summary>
|
||||
/// Creats an Image in CCITT mode.
|
||||
/// </summary>
|
||||
/// <param name="width">the exact width of the image</param>
|
||||
/// <param name="height">the exact height of the image</param>
|
||||
/// <param name="reverseBits">
|
||||
/// reverses the bits in data.
|
||||
/// Bit 0 is swapped with bit 7 and so on
|
||||
/// </param>
|
||||
/// <param name="typeCCITT">
|
||||
/// the type of compression in data. It can be
|
||||
/// CCITTG4, CCITTG31D, CCITTG32D
|
||||
/// </param>
|
||||
/// <param name="parameters">
|
||||
/// parameters associated with this stream. Possible values are
|
||||
/// CCITT_BLACKIS1, CCITT_ENCODEDBYTEALIGN, CCITT_ENDOFLINE and CCITT_ENDOFBLOCK or a
|
||||
/// combination of them
|
||||
/// </param>
|
||||
/// <param name="data">the image data</param>
|
||||
public ImgCCITT(int width, int height, bool reverseBits, int typeCCITT, int parameters, byte[] data) : base((Uri)null) {
|
||||
if (typeCCITT != Element.CCITTG4 && typeCCITT != Element.CCITTG3_1D && typeCCITT != Element.CCITTG3_2D)
|
||||
throw new BadElementException("The CCITT compression type must be CCITTG4, CCITTG3_1D or CCITTG3_2D");
|
||||
if (reverseBits)
|
||||
TIFFFaxDecoder.ReverseBits(data);
|
||||
type = Element.IMGRAW;
|
||||
scaledHeight = height;
|
||||
this.Top = scaledHeight;
|
||||
scaledWidth = width;
|
||||
this.Right = scaledWidth;
|
||||
colorspace = parameters;
|
||||
bpc = typeCCITT;
|
||||
rawData = data;
|
||||
plainWidth = this.Width;
|
||||
plainHeight = this.Height;
|
||||
}
|
||||
}
|
||||
}
|
||||
88
iTechSharp/iTextSharp/text/ImgRaw.cs
Normal file
88
iTechSharp/iTextSharp/text/ImgRaw.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
using System;
|
||||
|
||||
/*
|
||||
* $Id: ImgRaw.cs,v 1.5 2008/05/13 11:25:11 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2000, 2001, 2002 by Paulo Soares.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text {
|
||||
/// <summary>
|
||||
/// Raw Image data that has to be inserted into the document
|
||||
/// </summary>
|
||||
/// <seealso cref="T:iTextSharp.text.Element"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Image"/>
|
||||
public class ImgRaw : Image {
|
||||
|
||||
public ImgRaw(Image image) : base(image) {}
|
||||
|
||||
/// <summary>
|
||||
/// Creats an Image in raw mode.
|
||||
/// </summary>
|
||||
/// <param name="width">the exact width of the image</param>
|
||||
/// <param name="height">the exact height of the image</param>
|
||||
/// <param name="components">1,3 or 4 for GrayScale, RGB and CMYK</param>
|
||||
/// <param name="bpc">bits per component. Must be 1,2,4 or 8</param>
|
||||
/// <param name="data">data the image data</param>
|
||||
public ImgRaw(int width, int height, int components, int bpc, byte[] data) : base((Uri)null) {
|
||||
type = Element.IMGRAW;
|
||||
scaledHeight = height;
|
||||
this.Top = scaledHeight;
|
||||
scaledWidth = width;
|
||||
this.Right = scaledWidth;
|
||||
if (components != 1 && components != 3 && components != 4)
|
||||
throw new BadElementException("Components must be 1, 3, or 4.");
|
||||
if (bpc != 1 && bpc != 2 && bpc != 4 && bpc != 8)
|
||||
throw new BadElementException("Bits-per-component must be 1, 2, 4, or 8.");
|
||||
colorspace = components;
|
||||
this.bpc = bpc;
|
||||
rawData = data;
|
||||
plainWidth = this.Width;
|
||||
plainHeight = this.Height;
|
||||
}
|
||||
}
|
||||
}
|
||||
88
iTechSharp/iTextSharp/text/ImgTemplate.cs
Normal file
88
iTechSharp/iTextSharp/text/ImgTemplate.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
using System;
|
||||
|
||||
using iTextSharp.text.pdf;
|
||||
|
||||
/*
|
||||
* $Id: ImgTemplate.cs,v 1.5 2008/05/13 11:25:11 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2000, 2001, 2002 by Paulo Soares.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text {
|
||||
/// <summary>
|
||||
/// PdfTemplate that has to be inserted into the document
|
||||
/// </summary>
|
||||
/// <seealso cref="T:iTextSharp.text.Element"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Image"/>
|
||||
public class ImgTemplate : Image {
|
||||
|
||||
/// <summary>
|
||||
/// Creats an Image from a PdfTemplate.
|
||||
/// </summary>
|
||||
/// <param name="image">the Image</param>
|
||||
public ImgTemplate(Image image) : base(image) {}
|
||||
|
||||
/// <summary>
|
||||
/// Creats an Image from a PdfTemplate.
|
||||
/// </summary>
|
||||
/// <param name="template">the PdfTemplate</param>
|
||||
public ImgTemplate(PdfTemplate template) : base((Uri)null) {
|
||||
if (template == null)
|
||||
throw new BadElementException("The template can not be null.");
|
||||
if (template.Type == PdfTemplate.TYPE_PATTERN)
|
||||
throw new BadElementException("A pattern can not be used as a template to create an image.");
|
||||
type = Element.IMGTEMPLATE;
|
||||
scaledHeight = template.Height;
|
||||
this.Top = scaledHeight;
|
||||
scaledWidth = template.Width;
|
||||
this.Right = scaledWidth;
|
||||
TemplateData = template;
|
||||
plainWidth = this.Width;
|
||||
plainHeight = this.Height;
|
||||
}
|
||||
}
|
||||
}
|
||||
176
iTechSharp/iTextSharp/text/ImgWMF.cs
Normal file
176
iTechSharp/iTextSharp/text/ImgWMF.cs
Normal file
@@ -0,0 +1,176 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
|
||||
using iTextSharp.text.pdf;
|
||||
using iTextSharp.text.pdf.codec.wmf;
|
||||
|
||||
/*
|
||||
* $Id: ImgWMF.cs,v 1.7 2008/05/13 11:25:11 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 1999, 2000, 2001, 2002 by Paulo Soares.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text {
|
||||
/**
|
||||
* An ImgWMF is the representation of a windows metafile
|
||||
* that has to be inserted into the document
|
||||
*
|
||||
* @see Element
|
||||
* @see Image
|
||||
* @see Gif
|
||||
* @see Png
|
||||
*/
|
||||
/// <summary>
|
||||
/// An ImgWMF is the representation of a windows metafile
|
||||
/// that has to be inserted into the document
|
||||
/// </summary>
|
||||
public class ImgWMF : Image {
|
||||
|
||||
// Constructors
|
||||
/// <summary>
|
||||
/// Constructs an ImgWMF-object
|
||||
/// </summary>
|
||||
/// <param name="image">a Image</param>
|
||||
public ImgWMF(Image image) : base(image) {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an ImgWMF-object, using an url.
|
||||
/// </summary>
|
||||
/// <param name="url">the URL where the image can be found</param>
|
||||
public ImgWMF(Uri url) : base(url) {
|
||||
ProcessParameters();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an ImgWMF-object, using a filename.
|
||||
/// </summary>
|
||||
/// <param name="filename">a string-representation of the file that contains the image.</param>
|
||||
public ImgWMF(string filename) : this(Utilities.ToURL(filename)) {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an ImgWMF-object from memory.
|
||||
/// </summary>
|
||||
/// <param name="img">the memory image</param>
|
||||
public ImgWMF(byte[] img) : base((Uri)null) {
|
||||
rawData = img;
|
||||
originalData = img;
|
||||
ProcessParameters();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method checks if the image is a valid WMF and processes some parameters.
|
||||
/// </summary>
|
||||
private void ProcessParameters() {
|
||||
type = Element.IMGTEMPLATE;
|
||||
originalType = ORIGINAL_WMF;
|
||||
Stream istr = null;
|
||||
try {
|
||||
string errorID;
|
||||
if (rawData == null){
|
||||
WebRequest w = WebRequest.Create(url);
|
||||
istr = w.GetResponse().GetResponseStream();
|
||||
errorID = url.ToString();
|
||||
}
|
||||
else{
|
||||
istr = new MemoryStream(rawData);
|
||||
errorID = "Byte array";
|
||||
}
|
||||
InputMeta im = new InputMeta(istr);
|
||||
if (im.ReadInt() != unchecked((int)0x9AC6CDD7)) {
|
||||
throw new BadElementException(errorID + " is not a valid placeable windows metafile.");
|
||||
}
|
||||
im.ReadWord();
|
||||
int left = im.ReadShort();
|
||||
int top = im.ReadShort();
|
||||
int right = im.ReadShort();
|
||||
int bottom = im.ReadShort();
|
||||
int inch = im.ReadWord();
|
||||
dpiX = 72;
|
||||
dpiY = 72;
|
||||
scaledHeight = (float)(bottom - top) / inch * 72f;
|
||||
this.Top =scaledHeight;
|
||||
scaledWidth = (float)(right - left) / inch * 72f;
|
||||
this.Right = scaledWidth;
|
||||
}
|
||||
finally {
|
||||
if (istr != null) {
|
||||
istr.Close();
|
||||
}
|
||||
plainWidth = this.Width;
|
||||
plainHeight = this.Height;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the WMF into a template.
|
||||
/// </summary>
|
||||
/// <param name="template">the template to read to</param>
|
||||
public void ReadWMF(PdfTemplate template) {
|
||||
TemplateData = template;
|
||||
template.Width = this.Width;
|
||||
template.Height = this.Height;
|
||||
Stream istr = null;
|
||||
try {
|
||||
if (rawData == null){
|
||||
WebRequest w = WebRequest.Create(url);
|
||||
istr = w.GetResponse().GetResponseStream();
|
||||
}
|
||||
else{
|
||||
istr = new MemoryStream(rawData);
|
||||
}
|
||||
MetaDo meta = new MetaDo(istr, template);
|
||||
meta.ReadAll();
|
||||
}
|
||||
finally {
|
||||
if (istr != null) {
|
||||
istr.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
335
iTechSharp/iTextSharp/text/Jpeg.cs
Normal file
335
iTechSharp/iTextSharp/text/Jpeg.cs
Normal file
@@ -0,0 +1,335 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.util;
|
||||
using iTextSharp.text.pdf;
|
||||
|
||||
/*
|
||||
* $Id: Jpeg.cs,v 1.11 2008/05/13 11:25:11 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text {
|
||||
/// <summary>
|
||||
/// An Jpeg is the representation of a graphic element (JPEG)
|
||||
/// that has to be inserted into the document
|
||||
/// </summary>
|
||||
/// <seealso cref="T:iTextSharp.text.Element"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Image"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Gif"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Png"/>
|
||||
public class Jpeg : Image {
|
||||
|
||||
// public static membervariables
|
||||
|
||||
/// <summary> This is a type of marker. </summary>
|
||||
public const int NOT_A_MARKER = -1;
|
||||
|
||||
/// <summary> This is a type of marker. </summary>
|
||||
public const int VALID_MARKER = 0;
|
||||
|
||||
/// <summary> Acceptable Jpeg markers. </summary>
|
||||
public static int[] VALID_MARKERS = {0xC0, 0xC1, 0xC2};
|
||||
|
||||
/// <summary> This is a type of marker. </summary>
|
||||
public const int UNSUPPORTED_MARKER = 1;
|
||||
|
||||
/// <summary> Unsupported Jpeg markers. </summary>
|
||||
public static int[] UNSUPPORTED_MARKERS = {0xC3, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCD, 0xCE, 0xCF};
|
||||
|
||||
/// <summary> This is a type of marker. </summary>
|
||||
public const int NOPARAM_MARKER = 2;
|
||||
|
||||
/// <summary> Jpeg markers without additional parameters. </summary>
|
||||
public static int[] NOPARAM_MARKERS = {0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0x01};
|
||||
|
||||
public const int M_APP0 = 0xE0;
|
||||
public const int M_APP2 = 0xE2;
|
||||
public const int M_APPE = 0xEE;
|
||||
|
||||
public static byte[] JFIF_ID = {0x4A, 0x46, 0x49, 0x46, 0x00};
|
||||
|
||||
private byte[][] icc;
|
||||
|
||||
// Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Construct a Jpeg-object, using a Image
|
||||
/// </summary>
|
||||
/// <param name="image">a Image</param>
|
||||
public Jpeg(Image image) : base(image) {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Jpeg-object, using an Uri.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Deprecated, use Image.GetInstance(...) to create an Image
|
||||
/// </remarks>
|
||||
/// <param name="Uri">the Uri where the image can be found</param>
|
||||
public Jpeg(Uri Uri) : base(Uri) {
|
||||
ProcessParameters();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Jpeg-object from memory.
|
||||
/// </summary>
|
||||
/// <param name="img">the memory image</param>
|
||||
public Jpeg(byte[] img) : base((Uri)null) {
|
||||
rawData = img;
|
||||
originalData = img;
|
||||
ProcessParameters();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Jpeg-object from memory.
|
||||
/// </summary>
|
||||
/// <param name="img">the memory image.</param>
|
||||
/// <param name="width">the width you want the image to have</param>
|
||||
/// <param name="height">the height you want the image to have</param>
|
||||
public Jpeg(byte[] img, float width, float height) : this(img) {
|
||||
scaledWidth = width;
|
||||
scaledHeight = height;
|
||||
}
|
||||
|
||||
// private static methods
|
||||
|
||||
/// <summary>
|
||||
/// Reads a short from the Stream.
|
||||
/// </summary>
|
||||
/// <param name="istr">the Stream</param>
|
||||
/// <returns>an int</returns>
|
||||
private static int GetShort(Stream istr) {
|
||||
return (istr.ReadByte() << 8) + istr.ReadByte();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads an inverted short from the Stream.
|
||||
/// </summary>
|
||||
/// <param name="istr">the Stream</param>
|
||||
/// <returns>an int</returns>
|
||||
private static int GetShortInverted(Stream istr) {
|
||||
return (istr.ReadByte() + istr.ReadByte() << 8);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a type of marker.
|
||||
/// </summary>
|
||||
/// <param name="marker">an int</param>
|
||||
/// <returns>a type: VALID_MARKER, UNSUPPORTED_MARKER or NOPARAM_MARKER</returns>
|
||||
private static int MarkerType(int marker) {
|
||||
for (int i = 0; i < VALID_MARKERS.Length; i++) {
|
||||
if (marker == VALID_MARKERS[i]) {
|
||||
return VALID_MARKER;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < NOPARAM_MARKERS.Length; i++) {
|
||||
if (marker == NOPARAM_MARKERS[i]) {
|
||||
return NOPARAM_MARKER;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < UNSUPPORTED_MARKERS.Length; i++) {
|
||||
if (marker == UNSUPPORTED_MARKERS[i]) {
|
||||
return UNSUPPORTED_MARKER;
|
||||
}
|
||||
}
|
||||
return NOT_A_MARKER;
|
||||
}
|
||||
|
||||
// private methods
|
||||
|
||||
/// <summary>
|
||||
/// This method checks if the image is a valid JPEG and processes some parameters.
|
||||
/// </summary>
|
||||
private void ProcessParameters() {
|
||||
type = Element.JPEG;
|
||||
originalType = ORIGINAL_JPEG;
|
||||
Stream istr = null;
|
||||
try {
|
||||
string errorID;
|
||||
if (rawData == null){
|
||||
WebRequest w = WebRequest.Create(url);
|
||||
istr = w.GetResponse().GetResponseStream();
|
||||
errorID = url.ToString();
|
||||
}
|
||||
else{
|
||||
istr = new MemoryStream(rawData);
|
||||
errorID = "Byte array";
|
||||
}
|
||||
if (istr.ReadByte() != 0xFF || istr.ReadByte() != 0xD8) {
|
||||
throw new BadElementException(errorID + " is not a valid JPEG-file.");
|
||||
}
|
||||
bool firstPass = true;
|
||||
int len;
|
||||
while (true) {
|
||||
int v = istr.ReadByte();
|
||||
if (v < 0)
|
||||
throw new IOException("Premature EOF while reading JPG.");
|
||||
if (v == 0xFF) {
|
||||
int marker = istr.ReadByte();
|
||||
if (firstPass && marker == M_APP0) {
|
||||
firstPass = false;
|
||||
len = GetShort(istr);
|
||||
if (len < 16) {
|
||||
Utilities.Skip(istr, len - 2);
|
||||
continue;
|
||||
}
|
||||
byte[] bcomp = new byte[JFIF_ID.Length];
|
||||
int r = istr.Read(bcomp, 0, bcomp.Length);
|
||||
if (r != bcomp.Length)
|
||||
throw new BadElementException(errorID + " corrupted JFIF marker.");
|
||||
bool found = true;
|
||||
for (int k = 0; k < bcomp.Length; ++k) {
|
||||
if (bcomp[k] != JFIF_ID[k]) {
|
||||
found = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
Utilities.Skip(istr, len - 2 - bcomp.Length);
|
||||
continue;
|
||||
}
|
||||
Utilities.Skip(istr, 2);
|
||||
int units = istr.ReadByte();
|
||||
int dx = GetShort(istr);
|
||||
int dy = GetShort(istr);
|
||||
if (units == 1) {
|
||||
dpiX = dx;
|
||||
dpiY = dy;
|
||||
}
|
||||
else if (units == 2) {
|
||||
dpiX = (int)((float)dx * 2.54f + 0.5f);
|
||||
dpiY = (int)((float)dy * 2.54f + 0.5f);
|
||||
}
|
||||
Utilities.Skip(istr, len - 2 - bcomp.Length - 7);
|
||||
continue;
|
||||
}
|
||||
if (marker == M_APPE) {
|
||||
len = GetShort(istr) - 2;
|
||||
byte[] byteappe = new byte[len];
|
||||
for (int k = 0; k < len; ++k) {
|
||||
byteappe[k] = (byte)istr.ReadByte();
|
||||
}
|
||||
if (byteappe.Length >= 12) {
|
||||
string appe = System.Text.ASCIIEncoding.ASCII.GetString(byteappe,0,5);
|
||||
if (Util.EqualsIgnoreCase(appe, "adobe")) {
|
||||
invert = true;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (marker == M_APP2) {
|
||||
len = GetShort(istr) - 2;
|
||||
byte[] byteapp2 = new byte[len];
|
||||
for (int k = 0; k < len; ++k) {
|
||||
byteapp2[k] = (byte)istr.ReadByte();
|
||||
}
|
||||
if (byteapp2.Length >= 14) {
|
||||
String app2 = System.Text.ASCIIEncoding.ASCII.GetString(byteapp2, 0, 11);
|
||||
if (app2.Equals("ICC_PROFILE")) {
|
||||
int order = byteapp2[12] & 0xff;
|
||||
int count = byteapp2[13] & 0xff;
|
||||
if (icc == null)
|
||||
icc = new byte[count][];
|
||||
icc[order - 1] = byteapp2;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
firstPass = false;
|
||||
int markertype = MarkerType(marker);
|
||||
if (markertype == VALID_MARKER) {
|
||||
Utilities.Skip(istr, 2);
|
||||
if (istr.ReadByte() != 0x08) {
|
||||
throw new BadElementException(errorID + " must have 8 bits per component.");
|
||||
}
|
||||
scaledHeight = GetShort(istr);
|
||||
Top = scaledHeight;
|
||||
scaledWidth = GetShort(istr);
|
||||
Right = scaledWidth;
|
||||
colorspace = istr.ReadByte();
|
||||
bpc = 8;
|
||||
break;
|
||||
}
|
||||
else if (markertype == UNSUPPORTED_MARKER) {
|
||||
throw new BadElementException(errorID + ": unsupported JPEG marker: " + marker);
|
||||
}
|
||||
else if (markertype != NOPARAM_MARKER) {
|
||||
Utilities.Skip(istr, GetShort(istr) - 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (istr != null) {
|
||||
istr.Close();
|
||||
}
|
||||
}
|
||||
plainWidth = this.Width;
|
||||
plainHeight = this.Height;
|
||||
if (icc != null) {
|
||||
int total = 0;
|
||||
for (int k = 0; k < icc.Length; ++k) {
|
||||
if (icc[k] == null) {
|
||||
icc = null;
|
||||
return;
|
||||
}
|
||||
total += icc[k].Length - 14;
|
||||
}
|
||||
byte[] ficc = new byte[total];
|
||||
total = 0;
|
||||
for (int k = 0; k < icc.Length; ++k) {
|
||||
System.Array.Copy(icc[k], 14, ficc, total, icc[k].Length - 14);
|
||||
total += icc[k].Length - 14;
|
||||
}
|
||||
ICC_Profile icc_prof = ICC_Profile.GetInstance(ficc);
|
||||
TagICC = icc_prof;
|
||||
icc = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
239
iTechSharp/iTextSharp/text/Jpeg2000.cs
Normal file
239
iTechSharp/iTextSharp/text/Jpeg2000.cs
Normal file
@@ -0,0 +1,239 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.util;
|
||||
using iTextSharp.text.pdf;
|
||||
/*
|
||||
* $Id: Jpeg2000.cs,v 1.5 2008/05/13 11:25:11 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text {
|
||||
|
||||
/**
|
||||
* An <CODE>Jpeg2000</CODE> is the representation of a graphic element (JPEG)
|
||||
* that has to be inserted into the document
|
||||
*
|
||||
* @see Element
|
||||
* @see Image
|
||||
*/
|
||||
|
||||
public class Jpeg2000 : Image {
|
||||
|
||||
// public static final membervariables
|
||||
|
||||
public const int JP2_JP = 0x6a502020;
|
||||
public const int JP2_IHDR = 0x69686472;
|
||||
public const int JPIP_JPIP = 0x6a706970;
|
||||
|
||||
public const int JP2_FTYP = 0x66747970;
|
||||
public const int JP2_JP2H = 0x6a703268;
|
||||
public const int JP2_COLR = 0x636f6c72;
|
||||
public const int JP2_JP2C = 0x6a703263;
|
||||
public const int JP2_URL = 0x75726c20;
|
||||
public const int JP2_DBTL = 0x6474626c;
|
||||
public const int JP2_BPCC = 0x62706363;
|
||||
public const int JP2_JP2 = 0x6a703220;
|
||||
|
||||
private Stream inp;
|
||||
private int boxLength;
|
||||
private int boxType;
|
||||
|
||||
// Constructors
|
||||
|
||||
public Jpeg2000(Image image) : base(image) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <CODE>Jpeg2000</CODE>-object, using an <VAR>url</VAR>.
|
||||
*
|
||||
* @param url the <CODE>URL</CODE> where the image can be found
|
||||
* @throws BadElementException
|
||||
* @throws IOException
|
||||
*/
|
||||
public Jpeg2000(Uri url) : base(url) {
|
||||
ProcessParameters();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <CODE>Jpeg2000</CODE>-object from memory.
|
||||
*
|
||||
* @param img the memory image
|
||||
* @throws BadElementException
|
||||
* @throws IOException
|
||||
*/
|
||||
|
||||
public Jpeg2000(byte[] img) : base((Uri)null) {
|
||||
rawData = img;
|
||||
originalData = img;
|
||||
ProcessParameters();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <CODE>Jpeg2000</CODE>-object from memory.
|
||||
*
|
||||
* @param img the memory image.
|
||||
* @param width the width you want the image to have
|
||||
* @param height the height you want the image to have
|
||||
* @throws BadElementException
|
||||
* @throws IOException
|
||||
*/
|
||||
|
||||
public Jpeg2000(byte[] img, float width, float height) : this(img) {
|
||||
scaledWidth = width;
|
||||
scaledHeight = height;
|
||||
}
|
||||
|
||||
private int Cio_read(int n) {
|
||||
int v = 0;
|
||||
for (int i = n - 1; i >= 0; i--) {
|
||||
v += inp.ReadByte() << (i << 3);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
public void Jp2_read_boxhdr() {
|
||||
boxLength = Cio_read(4);
|
||||
boxType = Cio_read(4);
|
||||
if (boxLength == 1) {
|
||||
if (Cio_read(4) != 0) {
|
||||
throw new IOException("Cannot handle box sizes higher than 2^32");
|
||||
}
|
||||
boxLength = Cio_read(4);
|
||||
if (boxLength == 0)
|
||||
throw new IOException("Unsupported box size == 0");
|
||||
}
|
||||
else if (boxLength == 0) {
|
||||
throw new IOException("Unsupported box size == 0");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method checks if the image is a valid JPEG and processes some parameters.
|
||||
* @throws BadElementException
|
||||
* @throws IOException
|
||||
*/
|
||||
private void ProcessParameters() {
|
||||
type = JPEG2000;
|
||||
originalType = ORIGINAL_JPEG2000;
|
||||
inp = null;
|
||||
try {
|
||||
string errorID;
|
||||
if (rawData == null){
|
||||
WebRequest w = WebRequest.Create(url);
|
||||
inp = w.GetResponse().GetResponseStream();
|
||||
errorID = url.ToString();
|
||||
}
|
||||
else{
|
||||
inp = new MemoryStream(rawData);
|
||||
errorID = "Byte array";
|
||||
}
|
||||
boxLength = Cio_read(4);
|
||||
if (boxLength == 0x0000000c) {
|
||||
boxType = Cio_read(4);
|
||||
if (JP2_JP != boxType) {
|
||||
throw new IOException("Expected JP Marker");
|
||||
}
|
||||
if (0x0d0a870a != Cio_read(4)) {
|
||||
throw new IOException("Error with JP Marker");
|
||||
}
|
||||
|
||||
Jp2_read_boxhdr();
|
||||
if (JP2_FTYP != boxType) {
|
||||
throw new IOException("Expected FTYP Marker");
|
||||
}
|
||||
Utilities.Skip(inp, boxLength - 8);
|
||||
Jp2_read_boxhdr();
|
||||
do {
|
||||
if (JP2_JP2H != boxType) {
|
||||
if (boxType == JP2_JP2C) {
|
||||
throw new IOException("Expected JP2H Marker");
|
||||
}
|
||||
Utilities.Skip(inp, boxLength - 8);
|
||||
Jp2_read_boxhdr();
|
||||
}
|
||||
} while (JP2_JP2H != boxType);
|
||||
Jp2_read_boxhdr();
|
||||
if (JP2_IHDR != boxType) {
|
||||
throw new IOException("Expected IHDR Marker");
|
||||
}
|
||||
scaledHeight = Cio_read(4);
|
||||
Top = scaledHeight;
|
||||
scaledWidth = Cio_read(4);
|
||||
Right = scaledWidth;
|
||||
bpc = -1;
|
||||
}
|
||||
else if ((uint)boxLength == 0xff4fff51) {
|
||||
Utilities.Skip(inp, 4);
|
||||
int x1 = Cio_read(4);
|
||||
int y1 = Cio_read(4);
|
||||
int x0 = Cio_read(4);
|
||||
int y0 = Cio_read(4);
|
||||
Utilities.Skip(inp, 16);
|
||||
colorspace = Cio_read(2);
|
||||
bpc = 8;
|
||||
scaledHeight = y1 - y0;
|
||||
Top = scaledHeight;
|
||||
scaledWidth = x1 - x0;
|
||||
Right = scaledWidth;
|
||||
}
|
||||
else {
|
||||
throw new IOException("Not a valid Jpeg2000 file");
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (inp != null) {
|
||||
try{inp.Close();}catch{}
|
||||
inp = null;
|
||||
}
|
||||
}
|
||||
plainWidth = this.Width;
|
||||
plainHeight = this.Height;
|
||||
}
|
||||
}
|
||||
}
|
||||
555
iTechSharp/iTextSharp/text/List.cs
Normal file
555
iTechSharp/iTextSharp/text/List.cs
Normal file
@@ -0,0 +1,555 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.util;
|
||||
using iTextSharp.text.factories;
|
||||
|
||||
/*
|
||||
* $Id: List.cs,v 1.20 2008/05/13 11:25:11 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text {
|
||||
/// <summary>
|
||||
/// A List contains several ListItems.
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// <B>Example 1:</B>
|
||||
/// <code>
|
||||
/// <strong>List list = new List(true, 20);
|
||||
/// list.Add(new ListItem("First line"));
|
||||
/// list.Add(new ListItem("The second line is longer to see what happens once the end of the line is reached. Will it start on a new line?"));
|
||||
/// list.Add(new ListItem("Third line"));</strong>
|
||||
/// </code>
|
||||
///
|
||||
/// The result of this code looks like this:
|
||||
/// <OL>
|
||||
/// <LI>
|
||||
/// First line
|
||||
/// </LI>
|
||||
/// <LI>
|
||||
/// The second line is longer to see what happens once the end of the line is reached. Will it start on a new line?
|
||||
/// </LI>
|
||||
/// <LI>
|
||||
/// Third line
|
||||
/// </LI>
|
||||
/// </OL>
|
||||
///
|
||||
/// <B>Example 2:</B>
|
||||
/// <code>
|
||||
/// <strong>List overview = new List(false, 10);
|
||||
/// overview.Add(new ListItem("This is an item"));
|
||||
/// overview.Add("This is another item");</strong>
|
||||
/// </code>
|
||||
///
|
||||
/// The result of this code looks like this:
|
||||
/// <UL>
|
||||
/// <LI>
|
||||
/// This is an item
|
||||
/// </LI>
|
||||
/// <LI>
|
||||
/// This is another item
|
||||
/// </LI>
|
||||
/// </UL>
|
||||
/// </example>
|
||||
/// <seealso cref="T:iTextSharp.text.Element"/>
|
||||
/// <seealso cref="T:iTextSharp.text.ListItem"/>
|
||||
public class List : ITextElementArray {
|
||||
|
||||
// membervariables
|
||||
/** a possible value for the numbered parameter */
|
||||
public const bool ORDERED = true;
|
||||
/** a possible value for the numbered parameter */
|
||||
public const bool UNORDERED = false;
|
||||
/** a possible value for the lettered parameter */
|
||||
public const bool NUMERICAL = false;
|
||||
/** a possible value for the lettered parameter */
|
||||
public const bool ALPHABETICAL = true;
|
||||
/** a possible value for the lettered parameter */
|
||||
public const bool UPPERCASE = false;
|
||||
/** a possible value for the lettered parameter */
|
||||
public const bool LOWERCASE = true;
|
||||
|
||||
/// <summary> This is the ArrayList containing the different ListItems. </summary>
|
||||
protected ArrayList list = new ArrayList();
|
||||
|
||||
/** Indicates if the list has to be numbered. */
|
||||
protected bool numbered = false;
|
||||
/** Indicates if the listsymbols are numerical or alphabetical. */
|
||||
protected bool lettered = false;
|
||||
/** Indicates if the listsymbols are lowercase or uppercase. */
|
||||
protected bool lowercase = false;
|
||||
/** Indicates if the indentation has to be set automatically. */
|
||||
protected bool autoindent = false;
|
||||
/** Indicates if the indentation of all the items has to be aligned. */
|
||||
protected bool alignindent = false;
|
||||
|
||||
/// <summary> This variable indicates the first number of a numbered list. </summary>
|
||||
protected int first = 1;
|
||||
|
||||
/// <summary> This is the listsymbol of a list that is not numbered. </summary>
|
||||
protected Chunk symbol = new Chunk("-");
|
||||
/**
|
||||
* In case you are using numbered/lettered lists, this String is added before the number/letter.
|
||||
* @since iText 2.1.1
|
||||
*/
|
||||
protected String preSymbol = "";
|
||||
/**
|
||||
* In case you are using numbered/lettered lists, this String is added after the number/letter.
|
||||
* @since iText 2.1.1
|
||||
*/
|
||||
protected String postSymbol = ". ";
|
||||
|
||||
/// <summary> The indentation of this list on the left side. </summary>
|
||||
protected float indentationLeft = 0;
|
||||
|
||||
/// <summary> The indentation of this list on the right side. </summary>
|
||||
protected float indentationRight = 0;
|
||||
|
||||
/// <summary> The indentation of the listitems. </summary>
|
||||
protected float symbolIndent = 0;
|
||||
|
||||
// constructors
|
||||
|
||||
/**
|
||||
* Constructs a <CODE>List</CODE>.
|
||||
*/
|
||||
public List() : this(false, false) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <CODE>List</CODE> with a specific symbol indentation.
|
||||
* @param symbolIndent the symbol indentation
|
||||
* @since iText 2.0.8
|
||||
*/
|
||||
public List(float symbolIndent) {
|
||||
this.symbolIndent = symbolIndent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <CODE>List</CODE>.
|
||||
*
|
||||
* @param numbered a bool
|
||||
*/
|
||||
public List(bool numbered) : this(numbered, false) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <CODE>List</CODE>.
|
||||
*
|
||||
* @param numbered a bool
|
||||
* @param lettered has the list to be 'numbered' with letters
|
||||
*/
|
||||
public List(bool numbered, bool lettered) {
|
||||
this.numbered = numbered;
|
||||
this.lettered = lettered;
|
||||
this.autoindent = true;
|
||||
this.alignindent = true;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a List.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// the parameter symbolIndent is important for instance when
|
||||
/// generating PDF-documents; it indicates the indentation of the listsymbol.
|
||||
/// </remarks>
|
||||
/// <param name="numbered">a bool</param>
|
||||
/// <param name="symbolIndent">the indentation that has to be used for the listsymbol</param>
|
||||
public List(bool numbered, float symbolIndent) : this(numbered, false, symbolIndent) {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a List.
|
||||
/// </summary>
|
||||
/// <param name="numbered">a bool</param>
|
||||
/// <param name="lettered">a bool</param>
|
||||
/// <param name="symbolIndent">the indentation that has to be used for the listsymbol</param>
|
||||
public List(bool numbered, bool lettered, float symbolIndent ) {
|
||||
this.numbered = numbered;
|
||||
this.lettered = lettered;
|
||||
this.symbolIndent = symbolIndent;
|
||||
}
|
||||
|
||||
// implementation of the Element-methods
|
||||
|
||||
/// <summary>
|
||||
/// Processes the element by adding it (or the different parts) to an
|
||||
/// IElementListener.
|
||||
/// </summary>
|
||||
/// <param name="listener">an IElementListener</param>
|
||||
/// <returns>true if the element was processed successfully</returns>
|
||||
public bool Process(IElementListener listener) {
|
||||
try {
|
||||
foreach (IElement ele in list) {
|
||||
listener.Add(ele);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (DocumentException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of the text element.
|
||||
/// </summary>
|
||||
/// <value>a type</value>
|
||||
public int Type {
|
||||
get {
|
||||
return Element.LIST;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the chunks in this element.
|
||||
/// </summary>
|
||||
/// <value>an ArrayList</value>
|
||||
public ArrayList Chunks {
|
||||
get {
|
||||
ArrayList tmp = new ArrayList();
|
||||
foreach (IElement ele in list) {
|
||||
tmp.AddRange(ele.Chunks);
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
|
||||
// methods to set the membervariables
|
||||
|
||||
/// <summary>
|
||||
/// Adds an Object to the List.
|
||||
/// </summary>
|
||||
/// <param name="o">the object to add</param>
|
||||
/// <returns>true is successful</returns>
|
||||
public virtual bool Add(Object o) {
|
||||
if (o is ListItem) {
|
||||
ListItem item = (ListItem) o;
|
||||
if (numbered || lettered) {
|
||||
Chunk chunk = new Chunk(preSymbol, symbol.Font);
|
||||
int index = first + list.Count;
|
||||
if (lettered)
|
||||
chunk.Append(RomanAlphabetFactory.GetString(index, lowercase));
|
||||
else
|
||||
chunk.Append(index.ToString());
|
||||
chunk.Append(postSymbol);
|
||||
item.ListSymbol = chunk;
|
||||
}
|
||||
else {
|
||||
item.ListSymbol = symbol;
|
||||
}
|
||||
item.SetIndentationLeft(symbolIndent, autoindent);
|
||||
item.IndentationRight = 0;
|
||||
list.Add(item);
|
||||
return true;
|
||||
}
|
||||
else if (o is List) {
|
||||
List nested = (List) o;
|
||||
nested.IndentationLeft = nested.IndentationLeft + symbolIndent;
|
||||
first--;
|
||||
list.Add(nested);
|
||||
return true;
|
||||
}
|
||||
else if (o is string) {
|
||||
return this.Add(new ListItem((string) o));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// extra methods
|
||||
|
||||
/** Makes sure all the items in the list have the same indentation. */
|
||||
public void NormalizeIndentation() {
|
||||
float max = 0;
|
||||
foreach (IElement o in list) {
|
||||
if (o is ListItem) {
|
||||
max = Math.Max(max, ((ListItem)o).IndentationLeft);
|
||||
}
|
||||
}
|
||||
foreach (IElement o in list) {
|
||||
if (o is ListItem) {
|
||||
((ListItem)o).IndentationLeft = max;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//setters/getters
|
||||
|
||||
public bool Numbered {
|
||||
set {
|
||||
numbered = value;
|
||||
}
|
||||
get {
|
||||
return numbered;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Lettered {
|
||||
set {
|
||||
lettered = value;
|
||||
}
|
||||
get {
|
||||
return lettered;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Lowercase {
|
||||
set {
|
||||
lowercase = value;
|
||||
}
|
||||
get {
|
||||
return lowercase;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Autoindent {
|
||||
set {
|
||||
autoindent = value;
|
||||
}
|
||||
get {
|
||||
return autoindent;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Alignindent {
|
||||
set {
|
||||
alignindent = value;
|
||||
}
|
||||
get {
|
||||
return alignindent;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get/set the first number
|
||||
/// </summary>
|
||||
/// <value>an int</value>
|
||||
public int First {
|
||||
get {
|
||||
return first;
|
||||
}
|
||||
|
||||
set {
|
||||
this.first = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the symbol
|
||||
/// </summary>
|
||||
/// <value>a Chunk</value>
|
||||
public Chunk ListSymbol {
|
||||
set {
|
||||
this.symbol = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the listsymbol.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is a shortcut for SetListSymbol(Chunk symbol).
|
||||
/// </remarks>
|
||||
/// <param name="symbol">a string</param>
|
||||
public void SetListSymbol(string symbol) {
|
||||
this.symbol = new Chunk(symbol);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get/set the indentation of this paragraph on the left side.
|
||||
/// </summary>
|
||||
/// <value>the indentation</value>
|
||||
public float IndentationLeft {
|
||||
get {
|
||||
return indentationLeft;
|
||||
}
|
||||
|
||||
set {
|
||||
this.indentationLeft = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get/set the indentation of this paragraph on the right side.
|
||||
/// </summary>
|
||||
/// <value>the indentation</value>
|
||||
public float IndentationRight {
|
||||
get {
|
||||
return indentationRight;
|
||||
}
|
||||
|
||||
set {
|
||||
this.indentationRight = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the symbol indentation.
|
||||
/// </summary>
|
||||
/// <value>the symbol indentation</value>
|
||||
public float SymbolIndent {
|
||||
set {
|
||||
symbolIndent = value;
|
||||
}
|
||||
get {
|
||||
return symbolIndent;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.lowagie.text.Element#isContent()
|
||||
* @since iText 2.0.8
|
||||
*/
|
||||
public bool IsContent() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.lowagie.text.Element#isNestable()
|
||||
* @since iText 2.0.8
|
||||
*/
|
||||
public bool IsNestable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
// methods to retrieve information
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the items in the list.
|
||||
/// </summary>
|
||||
/// <value>an ArrayList containing ListItems</value>
|
||||
public ArrayList Items {
|
||||
get {
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the size of the list.
|
||||
/// </summary>
|
||||
/// <value>a size</value>
|
||||
public int Size {
|
||||
get {
|
||||
return list.Count;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <CODE>true</CODE> if the list is empty.
|
||||
*
|
||||
* @return <CODE>true</CODE> if the list is empty
|
||||
*/
|
||||
public virtual bool IsEmpty() {
|
||||
return list.Count == 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the leading of the first listitem.
|
||||
/// </summary>
|
||||
/// <value>a leading</value>
|
||||
public float TotalLeading {
|
||||
get {
|
||||
if (list.Count < 1) {
|
||||
return -1;
|
||||
}
|
||||
ListItem item = (ListItem)list[0];
|
||||
return item.TotalLeading;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get/set the symbol indentation.
|
||||
/// </summary>
|
||||
/// <value>a Chunk</value>
|
||||
public Chunk Symbol {
|
||||
get {
|
||||
return symbol;
|
||||
}
|
||||
set {
|
||||
this.symbol = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the String that is after a number or letter in the list symbol.
|
||||
* @return the String that is after a number or letter in the list symbol
|
||||
* @since iText 2.1.1
|
||||
*/
|
||||
public String getPostSymbol() {
|
||||
return postSymbol;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the String that has to be added after a number or letter in the list symbol.
|
||||
* @since iText 2.1.1
|
||||
* @param postSymbol the String that has to be added after a number or letter in the list symbol.
|
||||
*/
|
||||
public String PostSymbol {
|
||||
set {
|
||||
postSymbol = value;
|
||||
}
|
||||
get {
|
||||
return postSymbol;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the String that has to be added before a number or letter in the list symbol.
|
||||
* @since iText 2.1.1
|
||||
* @param preSymbol the String that has to be added before a number or letter in the list symbol.
|
||||
*/
|
||||
public String PreSymbol {
|
||||
set {
|
||||
preSymbol = value;
|
||||
}
|
||||
get {
|
||||
return preSymbol;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
239
iTechSharp/iTextSharp/text/ListItem.cs
Normal file
239
iTechSharp/iTextSharp/text/ListItem.cs
Normal file
@@ -0,0 +1,239 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.util;
|
||||
using iTextSharp.text.factories;
|
||||
/*
|
||||
* $Id: ListItem.cs,v 1.11 2008/05/13 11:25:11 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text {
|
||||
/// <summary>
|
||||
/// A ListItem is a Paragraph
|
||||
/// that can be added to a List.
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// <B>Example 1:</B>
|
||||
/// <code>
|
||||
/// List list = new List(true, 20);
|
||||
/// list.Add(<strong>new ListItem("First line")</strong>);
|
||||
/// list.Add(<strong>new ListItem("The second line is longer to see what happens once the end of the line is reached. Will it start on a new line?")</strong>);
|
||||
/// list.Add(<strong>new ListItem("Third line")</strong>);
|
||||
/// </code>
|
||||
///
|
||||
/// The result of this code looks like this:
|
||||
/// <OL>
|
||||
/// <LI>
|
||||
/// First line
|
||||
/// </LI>
|
||||
/// <LI>
|
||||
/// The second line is longer to see what happens once the end of the line is reached. Will it start on a new line?
|
||||
/// </LI>
|
||||
/// <LI>
|
||||
/// Third line
|
||||
/// </LI>
|
||||
/// </OL>
|
||||
///
|
||||
/// <B>Example 2:</B>
|
||||
/// <code>
|
||||
/// List overview = new List(false, 10);
|
||||
/// overview.Add(<strong>new ListItem("This is an item")</strong>);
|
||||
/// overview.Add("This is another item");
|
||||
/// </code>
|
||||
///
|
||||
/// The result of this code looks like this:
|
||||
/// <UL>
|
||||
/// <LI>
|
||||
/// This is an item
|
||||
/// </LI>
|
||||
/// <LI>
|
||||
/// This is another item
|
||||
/// </LI>
|
||||
/// </UL>
|
||||
/// </example>
|
||||
/// <seealso cref="T:iTextSharp.text.Element"/>
|
||||
/// <seealso cref="T:iTextSharp.text.List"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Paragraph"/>
|
||||
public class ListItem : Paragraph {
|
||||
|
||||
// membervariables
|
||||
|
||||
/// <summary> this is the symbol that wil proceed the listitem. </summary>
|
||||
private Chunk symbol;
|
||||
|
||||
// constructors
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a ListItem.
|
||||
/// </summary>
|
||||
public ListItem() : base() {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a ListItem with a certain leading.
|
||||
/// </summary>
|
||||
/// <param name="leading">the leading</param>
|
||||
public ListItem(float leading) : base(leading) {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a ListItem with a certain Chunk.
|
||||
/// </summary>
|
||||
/// <param name="chunk">a Chunk</param>
|
||||
public ListItem(Chunk chunk) : base(chunk) {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a ListItem with a certain string.
|
||||
/// </summary>
|
||||
/// <param name="str">a string</param>
|
||||
public ListItem(string str) : base(str) {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a ListItem with a certain string
|
||||
/// and a certain Font.
|
||||
/// </summary>
|
||||
/// <param name="str">a string</param>
|
||||
/// <param name="font">a string</param>
|
||||
public ListItem(string str, Font font) : base(str, font) {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a ListItem with a certain Chunk
|
||||
/// and a certain leading.
|
||||
/// </summary>
|
||||
/// <param name="leading">the leading</param>
|
||||
/// <param name="chunk">a Chunk</param>
|
||||
public ListItem(float leading, Chunk chunk) : base(leading, chunk) {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a ListItem with a certain string
|
||||
/// and a certain leading.
|
||||
/// </summary>
|
||||
/// <param name="leading">the leading</param>
|
||||
/// <param name="str">a string</param>
|
||||
public ListItem(float leading, string str) : base(leading, str) {}
|
||||
|
||||
/**
|
||||
* Constructs a ListItem with a certain leading, string
|
||||
* and Font.
|
||||
*
|
||||
* @param leading the leading
|
||||
* @param string a string
|
||||
* @param font a Font
|
||||
*/
|
||||
/// <summary>
|
||||
/// Constructs a ListItem with a certain leading, string
|
||||
/// and Font.
|
||||
/// </summary>
|
||||
/// <param name="leading">the leading</param>
|
||||
/// <param name="str">a string</param>
|
||||
/// <param name="font">a Font</param>
|
||||
public ListItem(float leading, string str, Font font) : base(leading, str, font) {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a ListItem with a certain Phrase.
|
||||
/// </summary>
|
||||
/// <param name="phrase">a Phrase</param>
|
||||
public ListItem(Phrase phrase) : base(phrase) {}
|
||||
|
||||
// implementation of the Element-methods
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of the text element.
|
||||
/// </summary>
|
||||
/// <value>a type</value>
|
||||
public override int Type {
|
||||
get {
|
||||
return Element.LISTITEM;
|
||||
}
|
||||
}
|
||||
|
||||
// methods
|
||||
|
||||
// methods to retrieve information
|
||||
|
||||
/// <summary>
|
||||
/// Get/set the listsymbol.
|
||||
/// </summary>
|
||||
/// <value>a Chunk</value>
|
||||
public Chunk ListSymbol {
|
||||
get {
|
||||
return symbol;
|
||||
}
|
||||
|
||||
set {
|
||||
if (this.symbol == null) {
|
||||
this.symbol = value;
|
||||
if (this.symbol.Font.IsStandardFont()) {
|
||||
this.symbol.Font = font;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a given tag corresponds with this object.
|
||||
/// </summary>
|
||||
/// <param name="tag">the given tag</param>
|
||||
/// <returns>true if the tag corresponds</returns>
|
||||
public new static bool IsTag(string tag) {
|
||||
return ElementTags.LISTITEM.Equals(tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the indentation of this paragraph on the left side.
|
||||
*
|
||||
* @param indentation the new indentation
|
||||
*/
|
||||
public void SetIndentationLeft(float indentation, bool autoindent) {
|
||||
if (autoindent) {
|
||||
IndentationLeft = ListSymbol.GetWidthPoint();
|
||||
}
|
||||
else {
|
||||
IndentationLeft = indentation;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
154
iTechSharp/iTextSharp/text/MarkedObject.cs
Normal file
154
iTechSharp/iTextSharp/text/MarkedObject.cs
Normal file
@@ -0,0 +1,154 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.util;
|
||||
/*
|
||||
* $Id: MarkedObject.cs,v 1.4 2008/05/13 11:25:11 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2007 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999-2007 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000-2007 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text {
|
||||
|
||||
/**
|
||||
* Wrapper that allows to add properties to 'basic building block' objects.
|
||||
* Before iText 1.5 every 'basic building block' implemented the MarkupAttributes interface.
|
||||
* By setting attributes, you could add markup to the corresponding XML and/or HTML tag.
|
||||
* This functionality was hardly used by anyone, so it was removed, and replaced by
|
||||
* the MarkedObject functionality.
|
||||
*/
|
||||
|
||||
public class MarkedObject : IElement {
|
||||
|
||||
/** The element that is wrapped in a MarkedObject. */
|
||||
protected internal IElement element;
|
||||
|
||||
/** Contains extra markupAttributes */
|
||||
protected internal Properties markupAttributes = new Properties();
|
||||
|
||||
/**
|
||||
* This constructor is for internal use only.
|
||||
*/
|
||||
protected MarkedObject() {
|
||||
element = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a MarkedObject.
|
||||
*/
|
||||
public MarkedObject(IElement element) {
|
||||
this.element = element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all the chunks in this element.
|
||||
*
|
||||
* @return an <CODE>ArrayList</CODE>
|
||||
*/
|
||||
public virtual ArrayList Chunks {
|
||||
get {
|
||||
return element.Chunks;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the element by adding it (or the different parts) to an
|
||||
* <CODE>ElementListener</CODE>.
|
||||
*
|
||||
* @param listener an <CODE>ElementListener</CODE>
|
||||
* @return <CODE>true</CODE> if the element was processed successfully
|
||||
*/
|
||||
public virtual bool Process(IElementListener listener) {
|
||||
try {
|
||||
return listener.Add(element);
|
||||
}
|
||||
catch (DocumentException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type of the text element.
|
||||
*
|
||||
* @return a type
|
||||
*/
|
||||
public virtual int Type {
|
||||
get {
|
||||
return Element.MARKED;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.lowagie.text.Element#isContent()
|
||||
* @since iText 2.0.8
|
||||
*/
|
||||
public bool IsContent() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.lowagie.text.Element#isNestable()
|
||||
* @since iText 2.0.8
|
||||
*/
|
||||
public bool IsNestable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the markupAttributes
|
||||
*/
|
||||
public virtual Properties MarkupAttributes {
|
||||
get {
|
||||
return markupAttributes;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void SetMarkupAttribute(String key, String value) {
|
||||
markupAttributes.Add(key, value);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
297
iTechSharp/iTextSharp/text/MarkedSection.cs
Normal file
297
iTechSharp/iTextSharp/text/MarkedSection.cs
Normal file
@@ -0,0 +1,297 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Text;
|
||||
using System.util;
|
||||
/*
|
||||
* $Id: MarkedSection.cs,v 1.7 2008/05/13 11:25:12 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2007 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999-2007 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000-2007 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text {
|
||||
|
||||
/**
|
||||
* Wrapper that allows to add properties to a Chapter/Section object.
|
||||
* Before iText 1.5 every 'basic building block' implemented the MarkupAttributes interface.
|
||||
* By setting attributes, you could add markup to the corresponding XML and/or HTML tag.
|
||||
* This functionality was hardly used by anyone, so it was removed, and replaced by
|
||||
* the MarkedObject functionality.
|
||||
*/
|
||||
|
||||
public class MarkedSection : MarkedObject {
|
||||
|
||||
/** This is the title of this section. */
|
||||
protected MarkedObject title = null;
|
||||
|
||||
/**
|
||||
* Creates a MarkedObject with a Section or Chapter object.
|
||||
* @param section the marked section
|
||||
*/
|
||||
public MarkedSection(Section section) : base() {
|
||||
if (section.Title != null) {
|
||||
title = new MarkedObject(section.Title);
|
||||
section.Title = null;
|
||||
}
|
||||
this.element = section;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a <CODE>Paragraph</CODE>, <CODE>List</CODE> or <CODE>Table</CODE>
|
||||
* to this <CODE>Section</CODE>.
|
||||
*
|
||||
* @param index index at which the specified element is to be inserted
|
||||
* @param o an object of type <CODE>Paragraph</CODE>, <CODE>List</CODE> or <CODE>Table</CODE>=
|
||||
* @throws ClassCastException if the object is not a <CODE>Paragraph</CODE>, <CODE>List</CODE> or <CODE>Table</CODE>
|
||||
*/
|
||||
|
||||
public void Add(int index, Object o) {
|
||||
((Section)element).Add(index, o);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a <CODE>Paragraph</CODE>, <CODE>List</CODE>, <CODE>Table</CODE> or another <CODE>Section</CODE>
|
||||
* to this <CODE>Section</CODE>.
|
||||
*
|
||||
* @param o an object of type <CODE>Paragraph</CODE>, <CODE>List</CODE>, <CODE>Table</CODE> or another <CODE>Section</CODE>
|
||||
* @return a bool
|
||||
* @throws ClassCastException if the object is not a <CODE>Paragraph</CODE>, <CODE>List</CODE>, <CODE>Table</CODE> or <CODE>Section</CODE>
|
||||
*/
|
||||
|
||||
public bool Add(Object o) {
|
||||
return ((Section)element).Add(o);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the element by adding it (or the different parts) to an
|
||||
* <CODE>ElementListener</CODE>.
|
||||
*
|
||||
* @param listener an <CODE>ElementListener</CODE>
|
||||
* @return <CODE>true</CODE> if the element was processed successfully
|
||||
*/
|
||||
public override bool Process(IElementListener listener) {
|
||||
try {
|
||||
foreach (IElement element in ((Section)this.element)) {
|
||||
listener.Add(element);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (DocumentException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a collection of <CODE>Element</CODE>s
|
||||
* to this <CODE>Section</CODE>.
|
||||
*
|
||||
* @param collection a collection of <CODE>Paragraph</CODE>s, <CODE>List</CODE>s and/or <CODE>Table</CODE>s
|
||||
* @return <CODE>true</CODE> if the action succeeded, <CODE>false</CODE> if not.
|
||||
* @throws ClassCastException if one of the objects isn't a <CODE>Paragraph</CODE>, <CODE>List</CODE>, <CODE>Table</CODE>
|
||||
*/
|
||||
|
||||
public bool AddAll(ICollection collection) {
|
||||
return ((Section)element).AddAll(collection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <CODE>Section</CODE>, adds it to this <CODE>Section</CODE> and returns it.
|
||||
*
|
||||
* @param indentation the indentation of the new section
|
||||
* @param numberDepth the numberDepth of the section
|
||||
* @return a new Section object
|
||||
*/
|
||||
|
||||
public MarkedSection AddSection(float indentation, int numberDepth) {
|
||||
MarkedSection section = ((Section)element).AddMarkedSection();
|
||||
section.Indentation = indentation;
|
||||
section.NumberDepth = numberDepth;
|
||||
return section;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <CODE>Section</CODE>, adds it to this <CODE>Section</CODE> and returns it.
|
||||
*
|
||||
* @param indentation the indentation of the new section
|
||||
* @return a new Section object
|
||||
*/
|
||||
|
||||
public MarkedSection AddSection(float indentation) {
|
||||
MarkedSection section = ((Section)element).AddMarkedSection();
|
||||
section.Indentation = indentation;
|
||||
return section;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <CODE>Section</CODE>, add it to this <CODE>Section</CODE> and returns it.
|
||||
*
|
||||
* @param numberDepth the numberDepth of the section
|
||||
* @return a new Section object
|
||||
*/
|
||||
public MarkedSection AddSection(int numberDepth) {
|
||||
MarkedSection section = ((Section)element).AddMarkedSection();
|
||||
section.NumberDepth = numberDepth;
|
||||
return section;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <CODE>Section</CODE>, adds it to this <CODE>Section</CODE> and returns it.
|
||||
*
|
||||
* @return a new Section object
|
||||
*/
|
||||
public MarkedSection AddSection() {
|
||||
return ((Section)element).AddMarkedSection();
|
||||
}
|
||||
|
||||
// public methods
|
||||
|
||||
/**
|
||||
* Sets the title of this section.
|
||||
*
|
||||
* @param title the new title
|
||||
*/
|
||||
public MarkedObject Title {
|
||||
set {
|
||||
if (value.element is Paragraph)
|
||||
this.title = value;
|
||||
}
|
||||
get {
|
||||
Paragraph result = Section.ConstructTitle((Paragraph)title.element, ((Section)element).numbers, ((Section)element).NumberDepth, ((Section)element).NumberStyle);
|
||||
MarkedObject mo = new MarkedObject(result);
|
||||
mo.markupAttributes = title.MarkupAttributes;
|
||||
return mo;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the depth of the sectionnumbers that will be shown preceding the title.
|
||||
* <P>
|
||||
* If the numberdepth is 0, the sections will not be numbered. If the numberdepth
|
||||
* is 1, the section will be numbered with their own number. If the numberdepth is
|
||||
* higher (for instance x > 1), the numbers of x - 1 parents will be shown.
|
||||
*
|
||||
* @param numberDepth the new numberDepth
|
||||
*/
|
||||
public int NumberDepth {
|
||||
set {
|
||||
((Section)element).NumberDepth = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the indentation of this <CODE>Section</CODE> on the left side.
|
||||
*
|
||||
* @param indentation the indentation
|
||||
*/
|
||||
public float IndentationLeft {
|
||||
set {
|
||||
((Section)element).IndentationLeft = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the indentation of this <CODE>Section</CODE> on the right side.
|
||||
*
|
||||
* @param indentation the indentation
|
||||
*/
|
||||
|
||||
public float IndentationRight {
|
||||
set {
|
||||
((Section)element).IndentationRight = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the indentation of the content of this <CODE>Section</CODE>.
|
||||
*
|
||||
* @param indentation the indentation
|
||||
*/
|
||||
public float Indentation {
|
||||
set {
|
||||
((Section)element).Indentation = value;
|
||||
}
|
||||
}
|
||||
|
||||
/** Setter for property bookmarkOpen.
|
||||
* @param bookmarkOpen false if the bookmark children are not
|
||||
* visible.
|
||||
*/
|
||||
public bool BookmarkOpen {
|
||||
set {
|
||||
((Section)element).BookmarkOpen = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for property triggerNewPage.
|
||||
* @param triggerNewPage true if a new page has to be triggered.
|
||||
*/
|
||||
public bool TriggerNewPage {
|
||||
set {
|
||||
((Section)element).TriggerNewPage = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the bookmark title. The bookmark title is the same as the section title but
|
||||
* can be changed with this method.
|
||||
* @param bookmarkTitle the bookmark title
|
||||
*/
|
||||
public String BookmarkTitle {
|
||||
set {
|
||||
((Section)element).BookmarkTitle = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new page to the section.
|
||||
* @since 2.1.1
|
||||
*/
|
||||
public void NewPage() {
|
||||
((Section)element).NewPage();
|
||||
}
|
||||
}
|
||||
}
|
||||
234
iTechSharp/iTextSharp/text/Meta.cs
Normal file
234
iTechSharp/iTextSharp/text/Meta.cs
Normal file
@@ -0,0 +1,234 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using System.util;
|
||||
|
||||
/*
|
||||
* $Id: Meta.cs,v 1.6 2008/05/13 11:25:12 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text {
|
||||
/// <summary>
|
||||
/// This is an Element that contains
|
||||
/// some meta information about the document.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// An object of type Meta can not be constructed by the user.
|
||||
/// Userdefined meta information should be placed in a Header-object.
|
||||
/// Meta is reserved for: Subject, Keywords, Author, Title, Producer
|
||||
/// and Creationdate information.
|
||||
/// </remarks>
|
||||
/// <seealso cref="T:iTextSharp.text.Element"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Header"/>
|
||||
public class Meta : IElement {
|
||||
|
||||
// membervariables
|
||||
|
||||
///<summary> This is the type of Meta-information this object contains. </summary>
|
||||
private int type;
|
||||
|
||||
///<summary> This is the content of the Meta-information. </summary>
|
||||
private StringBuilder content;
|
||||
|
||||
// constructors
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Meta.
|
||||
/// </summary>
|
||||
/// <param name="type">the type of meta-information</param>
|
||||
/// <param name="content">the content</param>
|
||||
public Meta(int type, string content) {
|
||||
this.type = type;
|
||||
this.content = new StringBuilder(content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Meta.
|
||||
/// </summary>
|
||||
/// <param name="tag">the tagname of the meta-information</param>
|
||||
/// <param name="content">the content</param>
|
||||
public Meta(string tag, string content) {
|
||||
this.type = Meta.GetType(tag);
|
||||
this.content = new StringBuilder(content);
|
||||
}
|
||||
|
||||
// implementation of the Element-methods
|
||||
|
||||
/// <summary>
|
||||
/// Processes the element by adding it (or the different parts) to a
|
||||
/// IElementListener.
|
||||
/// </summary>
|
||||
/// <param name="listener">the IElementListener</param>
|
||||
/// <returns>true if the element was processed successfully</returns>
|
||||
public bool Process(IElementListener listener) {
|
||||
try {
|
||||
return listener.Add(this);
|
||||
}
|
||||
catch (DocumentException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of the text element.
|
||||
/// </summary>
|
||||
/// <value>a type</value>
|
||||
public int Type {
|
||||
get {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the chunks in this element.
|
||||
/// </summary>
|
||||
/// <value>an ArrayList</value>
|
||||
public ArrayList Chunks {
|
||||
get {
|
||||
return new ArrayList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.lowagie.text.Element#isContent()
|
||||
* @since iText 2.0.8
|
||||
*/
|
||||
public bool IsContent() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.lowagie.text.Element#isNestable()
|
||||
* @since iText 2.0.8
|
||||
*/
|
||||
public bool IsNestable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// methods
|
||||
|
||||
/// <summary>
|
||||
/// appends some text to this Meta.
|
||||
/// </summary>
|
||||
/// <param name="str">a string</param>
|
||||
/// <returns>a StringBuilder</returns>
|
||||
public StringBuilder Append(string str) {
|
||||
return content.Append(str);
|
||||
}
|
||||
|
||||
// methods to retrieve information
|
||||
|
||||
/// <summary>
|
||||
/// Returns the content of the meta information.
|
||||
/// </summary>
|
||||
/// <value>a string</value>
|
||||
public string Content {
|
||||
get {
|
||||
return content.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the name of the meta information.
|
||||
/// </summary>
|
||||
/// <value>a string</value>
|
||||
public virtual string Name {
|
||||
get {
|
||||
switch (type) {
|
||||
case Element.SUBJECT:
|
||||
return ElementTags.SUBJECT;
|
||||
case Element.KEYWORDS:
|
||||
return ElementTags.KEYWORDS;
|
||||
case Element.AUTHOR:
|
||||
return ElementTags.AUTHOR;
|
||||
case Element.TITLE:
|
||||
return ElementTags.TITLE;
|
||||
case Element.PRODUCER:
|
||||
return ElementTags.PRODUCER;
|
||||
case Element.CREATIONDATE:
|
||||
return ElementTags.CREATIONDATE;
|
||||
default:
|
||||
return ElementTags.UNKNOWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the name of the meta information.
|
||||
/// </summary>
|
||||
/// <param name="tag">name to match</param>
|
||||
/// <returns>a string</returns>
|
||||
public static int GetType(string tag) {
|
||||
if (ElementTags.SUBJECT.Equals(tag)) {
|
||||
return Element.SUBJECT;
|
||||
}
|
||||
if (ElementTags.KEYWORDS.Equals(tag)) {
|
||||
return Element.KEYWORDS;
|
||||
}
|
||||
if (ElementTags.AUTHOR.Equals(tag)) {
|
||||
return Element.AUTHOR;
|
||||
}
|
||||
if (ElementTags.TITLE.Equals(tag)) {
|
||||
return Element.TITLE;
|
||||
}
|
||||
if (ElementTags.PRODUCER.Equals(tag)) {
|
||||
return Element.PRODUCER;
|
||||
}
|
||||
if (ElementTags.CREATIONDATE.Equals(tag)) {
|
||||
return Element.CREATIONDATE;
|
||||
}
|
||||
return Element.HEADER;
|
||||
}
|
||||
|
||||
|
||||
public override string ToString() {
|
||||
return base.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
244
iTechSharp/iTextSharp/text/PageSize.cs
Normal file
244
iTechSharp/iTextSharp/text/PageSize.cs
Normal file
@@ -0,0 +1,244 @@
|
||||
using System;
|
||||
|
||||
/*
|
||||
* $Id: PageSize.cs,v 1.9 2008/05/13 11:25:12 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text {
|
||||
/// <summary>
|
||||
/// The PageSize-object contains a number of read only rectangles representing the most common paper sizes.
|
||||
/// </summary>
|
||||
/// <seealso cref="T:iTextSharp.text.RectangleReadOnly"/>
|
||||
public class PageSize {
|
||||
|
||||
// membervariables
|
||||
|
||||
/** This is the letter format */
|
||||
public static readonly Rectangle LETTER = new RectangleReadOnly(612,792);
|
||||
|
||||
/** This is the note format */
|
||||
public static readonly Rectangle NOTE = new RectangleReadOnly(540,720);
|
||||
|
||||
/** This is the legal format */
|
||||
public static readonly Rectangle LEGAL = new RectangleReadOnly(612,1008);
|
||||
|
||||
/** This is the tabloid format */
|
||||
public static readonly Rectangle TABLOID = new RectangleReadOnly(792,1224);
|
||||
|
||||
/** This is the executive format */
|
||||
public static readonly Rectangle EXECUTIVE = new RectangleReadOnly(522,756);
|
||||
|
||||
/** This is the postcard format */
|
||||
public static readonly Rectangle POSTCARD = new RectangleReadOnly(283,416);
|
||||
|
||||
/** This is the a0 format */
|
||||
public static readonly Rectangle A0 = new RectangleReadOnly(2384,3370);
|
||||
|
||||
/** This is the a1 format */
|
||||
public static readonly Rectangle A1 = new RectangleReadOnly(1684,2384);
|
||||
|
||||
/** This is the a2 format */
|
||||
public static readonly Rectangle A2 = new RectangleReadOnly(1191,1684);
|
||||
|
||||
/** This is the a3 format */
|
||||
public static readonly Rectangle A3 = new RectangleReadOnly(842,1191);
|
||||
|
||||
/** This is the a4 format */
|
||||
public static readonly Rectangle A4 = new RectangleReadOnly(595,842);
|
||||
|
||||
/** This is the a5 format */
|
||||
public static readonly Rectangle A5 = new RectangleReadOnly(420,595);
|
||||
|
||||
/** This is the a6 format */
|
||||
public static readonly Rectangle A6 = new RectangleReadOnly(297,420);
|
||||
|
||||
/** This is the a7 format */
|
||||
public static readonly Rectangle A7 = new RectangleReadOnly(210,297);
|
||||
|
||||
/** This is the a8 format */
|
||||
public static readonly Rectangle A8 = new RectangleReadOnly(148,210);
|
||||
|
||||
/** This is the a9 format */
|
||||
public static readonly Rectangle A9 = new RectangleReadOnly(105,148);
|
||||
|
||||
/** This is the a10 format */
|
||||
public static readonly Rectangle A10 = new RectangleReadOnly(73,105);
|
||||
|
||||
/** This is the b0 format */
|
||||
public static readonly Rectangle B0 = new RectangleReadOnly(2834,4008);
|
||||
|
||||
/** This is the b1 format */
|
||||
public static readonly Rectangle B1 = new RectangleReadOnly(2004,2834);
|
||||
|
||||
/** This is the b2 format */
|
||||
public static readonly Rectangle B2 = new RectangleReadOnly(1417,2004);
|
||||
|
||||
/** This is the b3 format */
|
||||
public static readonly Rectangle B3 = new RectangleReadOnly(1000,1417);
|
||||
|
||||
/** This is the b4 format */
|
||||
public static readonly Rectangle B4 = new RectangleReadOnly(708,1000);
|
||||
|
||||
/** This is the b5 format */
|
||||
public static readonly Rectangle B5 = new RectangleReadOnly(498,708);
|
||||
|
||||
/** This is the b6 format */
|
||||
public static readonly Rectangle B6 = new RectangleReadOnly(354,498);
|
||||
|
||||
/** This is the b7 format */
|
||||
public static readonly Rectangle B7 = new RectangleReadOnly(249,354);
|
||||
|
||||
/** This is the b8 format */
|
||||
public static readonly Rectangle B8 = new RectangleReadOnly(175,249);
|
||||
|
||||
/** This is the b9 format */
|
||||
public static readonly Rectangle B9 = new RectangleReadOnly(124,175);
|
||||
|
||||
/** This is the b10 format */
|
||||
public static readonly Rectangle B10 = new RectangleReadOnly(87,124);
|
||||
|
||||
/** This is the archE format */
|
||||
public static readonly Rectangle ARCH_E = new RectangleReadOnly(2592,3456);
|
||||
|
||||
/** This is the archD format */
|
||||
public static readonly Rectangle ARCH_D = new RectangleReadOnly(1728,2592);
|
||||
|
||||
/** This is the archC format */
|
||||
public static readonly Rectangle ARCH_C = new RectangleReadOnly(1296,1728);
|
||||
|
||||
/** This is the archB format */
|
||||
public static readonly Rectangle ARCH_B = new RectangleReadOnly(864,1296);
|
||||
|
||||
/** This is the archA format */
|
||||
public static readonly Rectangle ARCH_A = new RectangleReadOnly(648,864);
|
||||
|
||||
/** This is the American Foolscap format */
|
||||
public static readonly Rectangle FLSA = new RectangleReadOnly(612,936);
|
||||
|
||||
/** This is the European Foolscap format */
|
||||
public static readonly Rectangle FLSE = new RectangleReadOnly(648,936);
|
||||
|
||||
/** This is the halfletter format */
|
||||
public static readonly Rectangle HALFLETTER = new RectangleReadOnly(396,612);
|
||||
|
||||
/** This is the 11x17 format */
|
||||
public static readonly Rectangle _11X17 = new RectangleReadOnly(792,1224);
|
||||
|
||||
/** This is the ISO 7810 ID-1 format (85.60 x 53.98 mm or 3.370 x 2.125 inch) */
|
||||
public static readonly Rectangle ID_1 = new RectangleReadOnly(242.65f,153);
|
||||
|
||||
/** This is the ISO 7810 ID-2 format (A7 rotated) */
|
||||
public static readonly Rectangle ID_2 = new RectangleReadOnly(297,210);
|
||||
|
||||
/** This is the ISO 7810 ID-3 format (B7 rotated) */
|
||||
public static readonly Rectangle ID_3 = new RectangleReadOnly(354,249);
|
||||
|
||||
/** This is the ledger format */
|
||||
public static readonly Rectangle LEDGER = new RectangleReadOnly(1224,792);
|
||||
|
||||
/** This is the Crown Quarto format */
|
||||
public static readonly Rectangle CROWN_QUARTO = new RectangleReadOnly(535,697);
|
||||
|
||||
/** This is the Large Crown Quarto format */
|
||||
public static readonly Rectangle LARGE_CROWN_QUARTO = new RectangleReadOnly(569,731);
|
||||
|
||||
/** This is the Demy Quarto format. */
|
||||
public static readonly Rectangle DEMY_QUARTO = new RectangleReadOnly(620,782);
|
||||
|
||||
/** This is the Royal Quarto format. */
|
||||
public static readonly Rectangle ROYAL_QUARTO = new RectangleReadOnly(671,884);
|
||||
|
||||
/** This is the Crown Octavo format */
|
||||
public static readonly Rectangle CROWN_OCTAVO = new RectangleReadOnly(348,527);
|
||||
|
||||
/** This is the Large Crown Octavo format */
|
||||
public static readonly Rectangle LARGE_CROWN_OCTAVO = new RectangleReadOnly(365,561);
|
||||
|
||||
/** This is the Demy Octavo format */
|
||||
public static readonly Rectangle DEMY_OCTAVO = new RectangleReadOnly(391,612);
|
||||
|
||||
/** This is the Royal Octavo format. */
|
||||
public static readonly Rectangle ROYAL_OCTAVO = new RectangleReadOnly(442,663);
|
||||
|
||||
/** This is the small paperback format. */
|
||||
public static readonly Rectangle SMALL_PAPERBACK = new RectangleReadOnly(314,504);
|
||||
|
||||
/** This is the Pengiun small paperback format. */
|
||||
public static readonly Rectangle PENGUIN_SMALL_PAPERBACK = new RectangleReadOnly(314,513);
|
||||
|
||||
/** This is the Penguin large paparback format. */
|
||||
public static readonly Rectangle PENGUIN_LARGE_PAPERBACK = new RectangleReadOnly(365,561);
|
||||
|
||||
/**
|
||||
* This method returns a Rectangle based on a String.
|
||||
* Possible values are the the names of a constant in this class
|
||||
* (for instance "A4", "LETTER",...) or a value like "595 842"
|
||||
*/
|
||||
public static Rectangle GetRectangle(String name) {
|
||||
name = name.Trim().ToUpper(System.Globalization.CultureInfo.InvariantCulture);
|
||||
int pos = name.IndexOf(' ');
|
||||
if (pos == -1) {
|
||||
try {
|
||||
return (Rectangle)typeof(PageSize).GetField(name).GetValue(null);
|
||||
} catch (Exception) {
|
||||
throw new ArgumentException("Can't find page size " + name);
|
||||
}
|
||||
}
|
||||
else {
|
||||
try {
|
||||
String width = name.Substring(0, pos);
|
||||
String height = name.Substring(pos + 1);
|
||||
return new Rectangle(float.Parse(width, System.Globalization.NumberFormatInfo.InvariantInfo), float.Parse(height, System.Globalization.NumberFormatInfo.InvariantInfo));
|
||||
} catch(Exception e) {
|
||||
throw new ArgumentException(name + " is not a valid page size format: " + e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
408
iTechSharp/iTextSharp/text/Paragraph.cs
Normal file
408
iTechSharp/iTextSharp/text/Paragraph.cs
Normal file
@@ -0,0 +1,408 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.util;
|
||||
using iTextSharp.text.factories;
|
||||
|
||||
/*
|
||||
* $Id: Paragraph.cs,v 1.13 2008/05/13 11:25:12 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text {
|
||||
/// <summary>
|
||||
/// A Paragraph is a series of Chunks and/or Phrases.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A Paragraph has the same qualities of a Phrase, but also
|
||||
/// some additional layout-parameters:
|
||||
/// <UL>
|
||||
/// <LI/>the indentation
|
||||
/// <LI/>the alignment of the text
|
||||
/// </UL>
|
||||
/// </remarks>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// <strong>Paragraph p = new Paragraph("This is a paragraph",
|
||||
/// FontFactory.GetFont(FontFactory.HELVETICA, 18, Font.BOLDITALIC, new Color(0, 0, 255)));</strong>
|
||||
/// </code>
|
||||
/// </example>
|
||||
/// <seealso cref="T:iTextSharp.text.Element"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Phrase"/>
|
||||
/// <seealso cref="T:iTextSharp.text.ListItem"/>
|
||||
public class Paragraph : Phrase {
|
||||
|
||||
// membervariables
|
||||
|
||||
///<summary> The alignment of the text. </summary>
|
||||
protected int alignment = Element.ALIGN_UNDEFINED;
|
||||
|
||||
/** The text leading that is multiplied by the biggest font size in the line. */
|
||||
protected float multipliedLeading = 0;
|
||||
|
||||
///<summary> The indentation of this paragraph on the left side. </summary>
|
||||
protected float indentationLeft;
|
||||
|
||||
///<summary> The indentation of this paragraph on the right side. </summary>
|
||||
protected float indentationRight;
|
||||
|
||||
/**
|
||||
* Holds value of property firstLineIndent.
|
||||
*/
|
||||
private float firstLineIndent = 0;
|
||||
|
||||
/** The spacing before the paragraph. */
|
||||
protected float spacingBefore;
|
||||
|
||||
/** The spacing after the paragraph. */
|
||||
protected float spacingAfter;
|
||||
|
||||
|
||||
/**
|
||||
* Holds value of property extraParagraphSpace.
|
||||
*/
|
||||
private float extraParagraphSpace = 0;
|
||||
|
||||
///<summary> Does the paragraph has to be kept together on 1 page. </summary>
|
||||
protected bool keeptogether = false;
|
||||
|
||||
// constructors
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Paragraph.
|
||||
/// </summary>
|
||||
public Paragraph() : base() {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Paragraph with a certain leading.
|
||||
/// </summary>
|
||||
/// <param name="leading">the leading</param>
|
||||
public Paragraph(float leading) : base(leading) {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Paragraph with a certain Chunk.
|
||||
/// </summary>
|
||||
/// <param name="chunk">a Chunk</param>
|
||||
public Paragraph(Chunk chunk) : base(chunk) {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Paragraph with a certain Chunk
|
||||
/// and a certain leading.
|
||||
/// </summary>
|
||||
/// <param name="leading">the leading</param>
|
||||
/// <param name="chunk">a Chunk</param>
|
||||
public Paragraph(float leading, Chunk chunk) : base(leading, chunk) {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Paragraph with a certain string.
|
||||
/// </summary>
|
||||
/// <param name="str">a string</param>
|
||||
public Paragraph(string str) : base(str) {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Paragraph with a certain string
|
||||
/// and a certain Font.
|
||||
/// </summary>
|
||||
/// <param name="str">a string</param>
|
||||
/// <param name="font">a Font</param>
|
||||
public Paragraph(string str, Font font) : base(str, font) {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Paragraph with a certain string
|
||||
/// and a certain leading.
|
||||
/// </summary>
|
||||
/// <param name="leading">the leading</param>
|
||||
/// <param name="str">a string</param>
|
||||
public Paragraph(float leading, string str) : base(leading, str) {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Paragraph with a certain leading, string
|
||||
/// and Font.
|
||||
/// </summary>
|
||||
/// <param name="leading">the leading</param>
|
||||
/// <param name="str">a string</param>
|
||||
/// <param name="font">a Font</param>
|
||||
public Paragraph(float leading, string str, Font font) : base(leading, str, font) {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Paragraph with a certain Phrase.
|
||||
/// </summary>
|
||||
/// <param name="phrase">a Phrase</param>
|
||||
public Paragraph(Phrase phrase) : base(phrase) {
|
||||
if (phrase is Paragraph) {
|
||||
Paragraph p = (Paragraph)phrase;
|
||||
Alignment = p.Alignment;
|
||||
ExtraParagraphSpace = p.ExtraParagraphSpace;
|
||||
FirstLineIndent = p.FirstLineIndent;
|
||||
IndentationLeft = p.IndentationLeft;
|
||||
IndentationRight = p.IndentationRight;
|
||||
SpacingAfter = p.SpacingAfter;
|
||||
SpacingBefore = p.SpacingBefore;
|
||||
}
|
||||
}
|
||||
|
||||
// implementation of the Element-methods
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of the text element.
|
||||
/// </summary>
|
||||
/// <value>a type</value>
|
||||
public override int Type {
|
||||
get {
|
||||
return Element.PARAGRAPH;
|
||||
}
|
||||
}
|
||||
|
||||
// methods
|
||||
|
||||
/// <summary>
|
||||
/// Adds an Object to the Paragraph.
|
||||
/// </summary>
|
||||
/// <param name="o">the object to add</param>
|
||||
/// <returns>a bool</returns>
|
||||
public override bool Add(Object o) {
|
||||
if (o is List) {
|
||||
List list = (List) o;
|
||||
list.IndentationLeft = list.IndentationLeft + indentationLeft;
|
||||
list.IndentationRight = indentationRight;
|
||||
base.Add(list);
|
||||
return true;
|
||||
}
|
||||
else if (o is Image) {
|
||||
base.AddSpecial((Image) o);
|
||||
return true;
|
||||
}
|
||||
else if (o is Paragraph) {
|
||||
base.Add(o);
|
||||
base.Add(Chunk.NEWLINE);
|
||||
return true;
|
||||
}
|
||||
base.Add(o);
|
||||
return true;
|
||||
}
|
||||
|
||||
// setting the membervariables
|
||||
|
||||
/// <summary>
|
||||
/// Sets the alignment of this paragraph.
|
||||
/// </summary>
|
||||
/// <param name="alignment">the new alignment as a string</param>
|
||||
public void SetAlignment(string alignment) {
|
||||
if (Util.EqualsIgnoreCase(alignment, ElementTags.ALIGN_CENTER)) {
|
||||
this.alignment = Element.ALIGN_CENTER;
|
||||
return;
|
||||
}
|
||||
if (Util.EqualsIgnoreCase(alignment, ElementTags.ALIGN_RIGHT)) {
|
||||
this.alignment = Element.ALIGN_RIGHT;
|
||||
return;
|
||||
}
|
||||
if (Util.EqualsIgnoreCase(alignment, ElementTags.ALIGN_JUSTIFIED)) {
|
||||
this.alignment = Element.ALIGN_JUSTIFIED;
|
||||
return;
|
||||
}
|
||||
if (Util.EqualsIgnoreCase(alignment, ElementTags.ALIGN_JUSTIFIED_ALL)) {
|
||||
this.alignment = Element.ALIGN_JUSTIFIED_ALL;
|
||||
return;
|
||||
}
|
||||
this.alignment = Element.ALIGN_LEFT;
|
||||
}
|
||||
|
||||
public override float Leading {
|
||||
set {
|
||||
this.leading = value;
|
||||
this.multipliedLeading = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the leading fixed and variable. The resultant leading will be
|
||||
* fixedLeading+multipliedLeading*maxFontSize where maxFontSize is the
|
||||
* size of the bigest font in the line.
|
||||
* @param fixedLeading the fixed leading
|
||||
* @param multipliedLeading the variable leading
|
||||
*/
|
||||
public void SetLeading(float fixedLeading, float multipliedLeading) {
|
||||
this.leading = fixedLeading;
|
||||
this.multipliedLeading = multipliedLeading;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the variable leading. The resultant leading will be
|
||||
* multipliedLeading*maxFontSize where maxFontSize is the
|
||||
* size of the bigest font in the line.
|
||||
* @param multipliedLeading the variable leading
|
||||
*/
|
||||
public float MultipliedLeading {
|
||||
get {
|
||||
return this.multipliedLeading;
|
||||
}
|
||||
set {
|
||||
this.leading = 0;
|
||||
this.multipliedLeading = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get/set the alignment of this paragraph.
|
||||
/// </summary>
|
||||
/// <value>a integer</value>
|
||||
public int Alignment{
|
||||
get {
|
||||
return alignment;
|
||||
}
|
||||
set {
|
||||
this.alignment = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get/set the indentation of this paragraph on the left side.
|
||||
/// </summary>
|
||||
/// <value>a float</value>
|
||||
public float IndentationLeft {
|
||||
get {
|
||||
return indentationLeft;
|
||||
}
|
||||
|
||||
set {
|
||||
this.indentationLeft = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get/set the indentation of this paragraph on the right side.
|
||||
/// </summary>
|
||||
/// <value>a float</value>
|
||||
public float IndentationRight {
|
||||
get {
|
||||
return indentationRight;
|
||||
}
|
||||
|
||||
set {
|
||||
this.indentationRight = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a given tag corresponds with this object.
|
||||
/// </summary>
|
||||
/// <param name="tag">the given tag</param>
|
||||
/// <returns>true if the tag corresponds</returns>
|
||||
public new static bool IsTag(string tag) {
|
||||
return ElementTags.PARAGRAPH.Equals(tag);
|
||||
}
|
||||
|
||||
public float SpacingBefore {
|
||||
get {
|
||||
return spacingBefore;
|
||||
}
|
||||
set {
|
||||
spacingBefore = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float SpacingAfter {
|
||||
get {
|
||||
return spacingAfter;
|
||||
}
|
||||
set {
|
||||
spacingAfter = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set/get if this paragraph has to be kept together on one page.
|
||||
/// </summary>
|
||||
/// <value>a bool</value>
|
||||
public bool KeepTogether {
|
||||
get {
|
||||
return keeptogether;
|
||||
}
|
||||
set {
|
||||
this.keeptogether = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the total leading.
|
||||
* This method is based on the assumption that the
|
||||
* font of the Paragraph is the font of all the elements
|
||||
* that make part of the paragraph. This isn't necessarily
|
||||
* true.
|
||||
* @return the total leading (fixed and multiplied)
|
||||
*/
|
||||
public float TotalLeading {
|
||||
get {
|
||||
float m = font == null ?
|
||||
Font.DEFAULTSIZE * multipliedLeading : font.GetCalculatedLeading(multipliedLeading);
|
||||
if (m > 0 && !HasLeading()) {
|
||||
return m;
|
||||
}
|
||||
return Leading + m;
|
||||
}
|
||||
}
|
||||
|
||||
public float FirstLineIndent {
|
||||
get {
|
||||
return this.firstLineIndent;
|
||||
}
|
||||
set {
|
||||
this.firstLineIndent = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float ExtraParagraphSpace {
|
||||
get {
|
||||
return this.extraParagraphSpace;
|
||||
}
|
||||
set {
|
||||
this.extraParagraphSpace = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
509
iTechSharp/iTextSharp/text/Phrase.cs
Normal file
509
iTechSharp/iTextSharp/text/Phrase.cs
Normal file
@@ -0,0 +1,509 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using System.util;
|
||||
using iTextSharp.text.html;
|
||||
using iTextSharp.text.pdf;
|
||||
using iTextSharp.text.factories;
|
||||
|
||||
namespace iTextSharp.text {
|
||||
/// <summary>
|
||||
/// A Phrase is a series of Chunks.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A Phrase has a main Font, but some chunks
|
||||
/// within the phrase can have a Font that differs from the
|
||||
/// main Font. All the Chunks in a Phrase
|
||||
/// have the same leading.
|
||||
/// </remarks>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// // When no parameters are passed, the default leading = 16
|
||||
/// <strong>Phrase phrase0 = new Phrase();
|
||||
/// Phrase phrase1 = new Phrase("this is a phrase");</strong>
|
||||
/// // In this example the leading is passed as a parameter
|
||||
/// <strong>Phrase phrase2 = new Phrase(16, "this is a phrase with leading 16");</strong>
|
||||
/// // When a Font is passed (explicitely or embedded in a chunk), the default leading = 1.5 * size of the font
|
||||
/// <strong>Phrase phrase3 = new Phrase("this is a phrase with a red, normal font Courier, size 12", FontFactory.GetFont(FontFactory.COURIER, 12, Font.NORMAL, new Color(255, 0, 0)));
|
||||
/// Phrase phrase4 = new Phrase(new Chunk("this is a phrase"));
|
||||
/// Phrase phrase5 = new Phrase(18, new Chunk("this is a phrase", FontFactory.GetFont(FontFactory.HELVETICA, 16, Font.BOLD, new Color(255, 0, 0)));</strong>
|
||||
/// </code>
|
||||
/// </example>
|
||||
public class Phrase : ArrayList, ITextElementArray {
|
||||
|
||||
// membervariables
|
||||
|
||||
/// <summary>This is the leading of this phrase.</summary>
|
||||
protected Single leading = Single.NaN;
|
||||
|
||||
///<summary> This is the font of this phrase. </summary>
|
||||
protected Font font;
|
||||
|
||||
/** Null, unless the Phrase has to be hyphenated.
|
||||
* @since 2.1.2
|
||||
*/
|
||||
protected IHyphenationEvent hyphenation = null;
|
||||
|
||||
// constructors
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Phrase without specifying a leading.
|
||||
/// </summary>
|
||||
/// <overloads>
|
||||
/// Has nine overloads.
|
||||
/// </overloads>
|
||||
public Phrase() : this(16) {}
|
||||
|
||||
/**
|
||||
* Copy constructor for <CODE>Phrase</CODE>.
|
||||
*/
|
||||
public Phrase(Phrase phrase) : base() {
|
||||
this.AddAll(phrase);
|
||||
leading = phrase.Leading;
|
||||
font = phrase.Font;
|
||||
hyphenation = phrase.hyphenation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Phrase with a certain leading.
|
||||
/// </summary>
|
||||
/// <param name="leading">the leading</param>
|
||||
public Phrase(float leading) {
|
||||
this.leading = leading;
|
||||
font = new Font();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Phrase with a certain Chunk.
|
||||
/// </summary>
|
||||
/// <param name="chunk">a Chunk</param>
|
||||
public Phrase(Chunk chunk) {
|
||||
base.Add(chunk);
|
||||
font = chunk.Font;
|
||||
hyphenation = chunk.GetHyphenation();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Phrase with a certain Chunk and a certain leading.
|
||||
/// </summary>
|
||||
/// <param name="leading">the leading</param>
|
||||
/// <param name="chunk">a Chunk</param>
|
||||
public Phrase(float leading, Chunk chunk) {
|
||||
this.leading = leading;
|
||||
base.Add(chunk);
|
||||
font = chunk.Font;
|
||||
hyphenation = chunk.GetHyphenation();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Phrase with a certain string.
|
||||
/// </summary>
|
||||
/// <param name="str">a string</param>
|
||||
public Phrase(string str) : this(float.NaN, str, new Font()) {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Phrase with a certain string and a certain Font.
|
||||
/// </summary>
|
||||
/// <param name="str">a string</param>
|
||||
/// <param name="font">a Font</param>
|
||||
public Phrase(string str, Font font) : this(float.NaN, str, font) {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Phrase with a certain leading and a certain string.
|
||||
/// </summary>
|
||||
/// <param name="leading">the leading</param>
|
||||
/// <param name="str">a string</param>
|
||||
public Phrase(float leading, string str) : this(leading, str, new Font()) {}
|
||||
|
||||
public Phrase(float leading, string str, Font font) {
|
||||
this.leading = leading;
|
||||
this.font = font;
|
||||
/* bugfix by August Detlefsen */
|
||||
if (str != null && str.Length != 0) {
|
||||
base.Add(new Chunk(str, font));
|
||||
}
|
||||
}
|
||||
|
||||
// implementation of the Element-methods
|
||||
|
||||
/// <summary>
|
||||
/// Processes the element by adding it (or the different parts) to an
|
||||
/// <see cref="iTextSharp.text.IElementListener"/>.
|
||||
/// </summary>
|
||||
/// <param name="listener">an IElementListener</param>
|
||||
/// <returns>true if the element was processed successfully</returns>
|
||||
public virtual bool Process(IElementListener listener) {
|
||||
try {
|
||||
foreach (IElement ele in this) {
|
||||
listener.Add(ele);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (DocumentException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of the text element.
|
||||
/// </summary>
|
||||
/// <value>a type</value>
|
||||
public virtual int Type {
|
||||
get {
|
||||
return Element.PHRASE;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the chunks in this element.
|
||||
/// </summary>
|
||||
/// <value>an ArrayList</value>
|
||||
public virtual ArrayList Chunks {
|
||||
get {
|
||||
ArrayList tmp = new ArrayList();
|
||||
foreach (IElement ele in this) {
|
||||
tmp.AddRange(ele.Chunks);
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.lowagie.text.Element#isContent()
|
||||
* @since iText 2.0.8
|
||||
*/
|
||||
public bool IsContent() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.lowagie.text.Element#isNestable()
|
||||
* @since iText 2.0.8
|
||||
*/
|
||||
public bool IsNestable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
// overriding some of the ArrayList-methods
|
||||
|
||||
/// <summary>
|
||||
/// Adds a Chunk, an Anchor or another Phrase
|
||||
/// to this Phrase.
|
||||
/// </summary>
|
||||
/// <param name="index">index at which the specified element is to be inserted</param>
|
||||
/// <param name="o">an object of type Chunk, Anchor, or Phrase</param>
|
||||
public virtual void Add(int index, Object o) {
|
||||
if (o == null) return;
|
||||
try {
|
||||
IElement element = (IElement) o;
|
||||
if (element.Type == Element.CHUNK) {
|
||||
Chunk chunk = (Chunk)element;
|
||||
if (!font.IsStandardFont()) {
|
||||
chunk.Font = font.Difference(chunk.Font);
|
||||
}
|
||||
if (hyphenation != null) {
|
||||
chunk.SetHyphenation(hyphenation);
|
||||
}
|
||||
base.Insert(index, chunk);
|
||||
}
|
||||
else if (element.Type == Element.PHRASE ||
|
||||
element.Type == Element.ANCHOR ||
|
||||
element.Type == Element.ANNOTATION ||
|
||||
element.Type == Element.TABLE || // line added by David Freels
|
||||
element.Type == Element.YMARK ||
|
||||
element.Type == Element.MARKED) {
|
||||
base.Insert(index, element);
|
||||
}
|
||||
else {
|
||||
throw new Exception(element.Type.ToString());
|
||||
}
|
||||
}
|
||||
catch (Exception cce) {
|
||||
throw new Exception("Insertion of illegal Element: " + cce.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a Chunk, Anchor or another Phrase
|
||||
/// to this Phrase.
|
||||
/// </summary>
|
||||
/// <param name="o">an object of type Chunk, Anchor or Phrase</param>
|
||||
/// <returns>a bool</returns>
|
||||
public virtual new bool Add(Object o) {
|
||||
if (o == null) return false;
|
||||
if (o is string) {
|
||||
base.Add(new Chunk((string) o, font));
|
||||
return true;
|
||||
}
|
||||
if (o is IRtfElementInterface) {
|
||||
base.Add(o);
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
IElement element = (IElement) o;
|
||||
switch (element.Type) {
|
||||
case Element.CHUNK:
|
||||
return AddChunk((Chunk) o);
|
||||
case Element.PHRASE:
|
||||
case Element.PARAGRAPH:
|
||||
Phrase phrase = (Phrase) o;
|
||||
bool success = true;
|
||||
foreach (IElement e in phrase) {
|
||||
if (e is Chunk) {
|
||||
success &= AddChunk((Chunk)e);
|
||||
}
|
||||
else {
|
||||
success &= this.Add(e);
|
||||
}
|
||||
}
|
||||
return success;
|
||||
case Element.MARKED:
|
||||
case Element.ANCHOR:
|
||||
case Element.ANNOTATION:
|
||||
case Element.TABLE: // case added by David Freels
|
||||
case Element.PTABLE: // case added by Karen Vardanyan
|
||||
// This will only work for PDF!!! Not for RTF/HTML
|
||||
case Element.LIST:
|
||||
case Element.YMARK:
|
||||
base.Add(o);
|
||||
return true;
|
||||
default:
|
||||
throw new Exception(element.Type.ToString());
|
||||
}
|
||||
}
|
||||
catch (Exception cce) {
|
||||
throw new Exception("Insertion of illegal Element: " + cce.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a collection of Chunks
|
||||
/// to this Phrase.
|
||||
/// </summary>
|
||||
/// <param name="collection">a collection of Chunks, Anchors and Phrases.</param>
|
||||
/// <returns>true if the action succeeded, false if not.</returns>
|
||||
public bool AddAll(ICollection collection) {
|
||||
foreach (object itm in collection) {
|
||||
this.Add(itm);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a Chunk.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method is a hack to solve a problem I had with phrases that were split between chunks
|
||||
/// in the wrong place.
|
||||
/// </remarks>
|
||||
/// <param name="chunk">a Chunk</param>
|
||||
/// <returns>a bool</returns>
|
||||
protected bool AddChunk(Chunk chunk) {
|
||||
Font f = chunk.Font;
|
||||
String c = chunk.Content;
|
||||
if (font != null && !font.IsStandardFont()) {
|
||||
f = font.Difference(chunk.Font);
|
||||
}
|
||||
if (Count > 0 && !chunk.HasAttributes()) {
|
||||
try {
|
||||
Chunk previous = (Chunk) this[Count - 1];
|
||||
if (!previous.HasAttributes()
|
||||
&& (f == null
|
||||
|| f.CompareTo(previous.Font) == 0)
|
||||
&& previous.Font.CompareTo(f) == 0
|
||||
&& !"".Equals(previous.Content.Trim())
|
||||
&& !"".Equals(c.Trim())) {
|
||||
previous.Append(c);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch {
|
||||
}
|
||||
}
|
||||
Chunk newChunk = new Chunk(c, f);
|
||||
newChunk.Attributes = chunk.Attributes;
|
||||
if (newChunk.GetHyphenation() == null) {
|
||||
newChunk.SetHyphenation(hyphenation);
|
||||
}
|
||||
base.Add(newChunk);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a Object to the Paragraph.
|
||||
/// </summary>
|
||||
/// <param name="obj">the object to add.</param>
|
||||
public void AddSpecial(Object obj) {
|
||||
base.Add(obj);
|
||||
}
|
||||
|
||||
// methods
|
||||
|
||||
// methods to retrieve information
|
||||
|
||||
/// <summary>
|
||||
/// Checks is this Phrase contains no or 1 empty Chunk.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// false if the Phrase
|
||||
/// contains more than one or more non-emptyChunks.
|
||||
/// </returns>
|
||||
public bool IsEmpty() {
|
||||
switch (Count) {
|
||||
case 0:
|
||||
return true;
|
||||
case 1:
|
||||
IElement element = (IElement) this[0];
|
||||
if (element.Type == Element.CHUNK && ((Chunk) element).IsEmpty()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasLeading() {
|
||||
if (float.IsNaN(leading)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets/sets the leading of this phrase.
|
||||
/// </summary>
|
||||
/// <value>the linespacing</value>
|
||||
public virtual float Leading {
|
||||
get {
|
||||
if (float.IsNaN(leading) && font != null) {
|
||||
return font.GetCalculatedLeading(1.5f);
|
||||
}
|
||||
return leading;
|
||||
}
|
||||
|
||||
set {
|
||||
this.leading = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the font of the first Chunk that appears in this Phrase.
|
||||
/// </summary>
|
||||
/// <value>a Font</value>
|
||||
public Font Font {
|
||||
get {
|
||||
return font;
|
||||
}
|
||||
set {
|
||||
font = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the content as a String object.
|
||||
* This method differs from toString because toString will return an ArrayList with the toString value of the Chunks in this Phrase.
|
||||
*/
|
||||
public String Content {
|
||||
get {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
foreach (object obj in Chunks)
|
||||
buf.Append(obj.ToString());
|
||||
return buf.ToString();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Checks if a given tag corresponds with this object.
|
||||
/// </summary>
|
||||
/// <param name="tag">the given tag</param>
|
||||
/// <returns>true if the tag corresponds</returns>
|
||||
public static bool IsTag(string tag) {
|
||||
return ElementTags.PHRASE.Equals(tag);
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return base.ToString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter/getter for the hyphenation.
|
||||
* @param hyphenation a HyphenationEvent instance
|
||||
* @since 2.1.2
|
||||
*/
|
||||
public IHyphenationEvent Hyphenation {
|
||||
set {
|
||||
hyphenation = value;
|
||||
}
|
||||
get {
|
||||
return hyphenation;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// kept for historical reasons; people should use FontSelector
|
||||
// eligable for deprecation, but the methods are mentioned in the book p277.
|
||||
|
||||
/**
|
||||
* Constructs a Phrase that can be used in the static GetInstance() method.
|
||||
* @param dummy a dummy parameter
|
||||
*/
|
||||
private Phrase(bool dummy) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a special kind of Phrase that changes some characters into corresponding symbols.
|
||||
* @param string
|
||||
* @return a newly constructed Phrase
|
||||
*/
|
||||
public static Phrase GetInstance(String str) {
|
||||
return GetInstance(16, str, new Font());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a special kind of Phrase that changes some characters into corresponding symbols.
|
||||
* @param leading
|
||||
* @param string
|
||||
* @return a newly constructed Phrase
|
||||
*/
|
||||
public static Phrase GetInstance(int leading, String str) {
|
||||
return GetInstance(leading, str, new Font());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a special kind of Phrase that changes some characters into corresponding symbols.
|
||||
* @param leading
|
||||
* @param string
|
||||
* @param font
|
||||
* @return a newly constructed Phrase
|
||||
*/
|
||||
public static Phrase GetInstance(int leading, String str, Font font) {
|
||||
Phrase p = new Phrase(true);
|
||||
p.Leading = leading;
|
||||
p.font = font;
|
||||
if (font.Family != Font.SYMBOL && font.Family != Font.ZAPFDINGBATS && font.BaseFont == null) {
|
||||
int index;
|
||||
while ((index = SpecialSymbol.Index(str)) > -1) {
|
||||
if (index > 0) {
|
||||
String firstPart = str.Substring(0, index);
|
||||
((ArrayList)p).Add(new Chunk(firstPart, font));
|
||||
str = str.Substring(index);
|
||||
}
|
||||
Font symbol = new Font(Font.SYMBOL, font.Size, font.Style, font.Color);
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.Append(SpecialSymbol.GetCorrespondingSymbol(str[0]));
|
||||
str = str.Substring(1);
|
||||
while (SpecialSymbol.Index(str) == 0) {
|
||||
buf.Append(SpecialSymbol.GetCorrespondingSymbol(str[0]));
|
||||
str = str.Substring(1);
|
||||
}
|
||||
((ArrayList)p).Add(new Chunk(buf.ToString(), symbol));
|
||||
}
|
||||
}
|
||||
if (str != null && str.Length != 0) {
|
||||
((ArrayList)p).Add(new Chunk(str, font));
|
||||
}
|
||||
return p;
|
||||
}
|
||||
}
|
||||
}
|
||||
733
iTechSharp/iTextSharp/text/Rectangle.cs
Normal file
733
iTechSharp/iTextSharp/text/Rectangle.cs
Normal file
@@ -0,0 +1,733 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Text;
|
||||
using System.util;
|
||||
using iTextSharp.text.pdf;
|
||||
|
||||
/*
|
||||
* $Id: Rectangle.cs,v 1.18 2008/05/13 11:25:12 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text {
|
||||
/// <summary>
|
||||
/// A Rectangle is the representation of a geometric figure.
|
||||
/// </summary>
|
||||
/// <seealso cref="T:iTextSharp.text.Element"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Table"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Cell"/>
|
||||
/// <seealso cref="T:iTextSharp.text.HeaderFooter"/>
|
||||
public class Rectangle : Element, IElement {
|
||||
|
||||
// static membervariables (concerning the presence of borders)
|
||||
|
||||
///<summary> This is the value that will be used as <VAR>undefined</VAR>. </summary>
|
||||
public const int UNDEFINED = -1;
|
||||
|
||||
///<summary> This represents one side of the border of the Rectangle. </summary>
|
||||
public const int TOP_BORDER = 1;
|
||||
|
||||
///<summary> This represents one side of the border of the Rectangle. </summary>
|
||||
public const int BOTTOM_BORDER = 2;
|
||||
|
||||
///<summary> This represents one side of the border of the Rectangle. </summary>
|
||||
public const int LEFT_BORDER = 4;
|
||||
|
||||
///<summary> This represents one side of the border of the Rectangle. </summary>
|
||||
public const int RIGHT_BORDER = 8;
|
||||
|
||||
///<summary> This represents a rectangle without borders. </summary>
|
||||
public const int NO_BORDER = 0;
|
||||
|
||||
///<summary> This represents a type of border. </summary>
|
||||
public const int BOX = TOP_BORDER + BOTTOM_BORDER + LEFT_BORDER + RIGHT_BORDER;
|
||||
|
||||
// membervariables
|
||||
|
||||
///<summary> the lower left x-coordinate. </summary>
|
||||
protected float llx;
|
||||
|
||||
///<summary> the lower left y-coordinate. </summary>
|
||||
protected float lly;
|
||||
|
||||
///<summary> the upper right x-coordinate. </summary>
|
||||
protected float urx;
|
||||
|
||||
///<summary> the upper right y-coordinate. </summary>
|
||||
protected float ury;
|
||||
|
||||
///<summary> This represents the status of the 4 sides of the rectangle. </summary>
|
||||
protected int border = UNDEFINED;
|
||||
|
||||
///<summary> This is the width of the border around this rectangle. </summary>
|
||||
protected float borderWidth = UNDEFINED;
|
||||
|
||||
///<summary> This is the color of the border of this rectangle. </summary>
|
||||
protected Color borderColor = null;
|
||||
|
||||
/** The color of the left border of this rectangle. */
|
||||
protected Color borderColorLeft = null;
|
||||
|
||||
/** The color of the right border of this rectangle. */
|
||||
protected Color borderColorRight = null;
|
||||
|
||||
/** The color of the top border of this rectangle. */
|
||||
protected Color borderColorTop = null;
|
||||
|
||||
/** The color of the bottom border of this rectangle. */
|
||||
protected Color borderColorBottom = null;
|
||||
|
||||
/** The width of the left border of this rectangle. */
|
||||
protected float borderWidthLeft = UNDEFINED;
|
||||
|
||||
/** The width of the right border of this rectangle. */
|
||||
protected float borderWidthRight = UNDEFINED;
|
||||
|
||||
/** The width of the top border of this rectangle. */
|
||||
protected float borderWidthTop = UNDEFINED;
|
||||
|
||||
/** The width of the bottom border of this rectangle. */
|
||||
protected float borderWidthBottom = UNDEFINED;
|
||||
|
||||
/** Whether variable width borders are used. */
|
||||
protected bool useVariableBorders = false;
|
||||
|
||||
///<summary> This is the color of the background of this rectangle. </summary>
|
||||
protected Color backgroundColor = null;
|
||||
|
||||
///<summary> This is the rotation value of this rectangle. </summary>
|
||||
protected int rotation = 0;
|
||||
|
||||
// constructors
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Rectangle-object.
|
||||
/// </summary>
|
||||
/// <param name="llx">lower left x</param>
|
||||
/// <param name="lly">lower left y</param>
|
||||
/// <param name="urx">upper right x</param>
|
||||
/// <param name="ury">upper right y</param>
|
||||
public Rectangle(float llx, float lly, float urx, float ury) {
|
||||
this.llx = llx;
|
||||
this.lly = lly;
|
||||
this.urx = urx;
|
||||
this.ury = ury;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Rectangle-object starting from the origin (0, 0).
|
||||
/// </summary>
|
||||
/// <param name="urx">upper right x</param>
|
||||
/// <param name="ury">upper right y</param>
|
||||
public Rectangle(float urx, float ury) : this(0, 0, urx, ury) {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Rectangle-object.
|
||||
/// </summary>
|
||||
/// <param name="rect">another Rectangle</param>
|
||||
public Rectangle(Rectangle rect) : this(rect.llx, rect.lly, rect.urx, rect.ury) {
|
||||
CloneNonPositionParameters(rect);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all of the parameters from a <CODE>Rectangle</CODE> object
|
||||
* except the position.
|
||||
*
|
||||
* @param rect
|
||||
* <CODE>Rectangle</CODE> to copy from
|
||||
*/
|
||||
|
||||
public virtual void CloneNonPositionParameters(Rectangle rect) {
|
||||
this.rotation = rect.rotation;
|
||||
this.border = rect.border;
|
||||
this.borderWidth = rect.borderWidth;
|
||||
this.borderColor = rect.borderColor;
|
||||
this.backgroundColor = rect.backgroundColor;
|
||||
this.borderColorLeft = rect.borderColorLeft;
|
||||
this.borderColorRight = rect.borderColorRight;
|
||||
this.borderColorTop = rect.borderColorTop;
|
||||
this.borderColorBottom = rect.borderColorBottom;
|
||||
this.borderWidthLeft = rect.borderWidthLeft;
|
||||
this.borderWidthRight = rect.borderWidthRight;
|
||||
this.borderWidthTop = rect.borderWidthTop;
|
||||
this.borderWidthBottom = rect.borderWidthBottom;
|
||||
this.useVariableBorders = rect.useVariableBorders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all of the parameters from a <CODE>Rectangle</CODE> object
|
||||
* except the position.
|
||||
*
|
||||
* @param rect
|
||||
* <CODE>Rectangle</CODE> to copy from
|
||||
*/
|
||||
|
||||
public virtual void SoftCloneNonPositionParameters(Rectangle rect) {
|
||||
if (rect.rotation != 0)
|
||||
this.rotation = rect.rotation;
|
||||
if (rect.border != UNDEFINED)
|
||||
this.border = rect.border;
|
||||
if (rect.borderWidth != UNDEFINED)
|
||||
this.borderWidth = rect.borderWidth;
|
||||
if (rect.borderColor != null)
|
||||
this.borderColor = rect.borderColor;
|
||||
if (rect.backgroundColor != null)
|
||||
this.backgroundColor = rect.backgroundColor;
|
||||
if (rect.borderColorLeft != null)
|
||||
this.borderColorLeft = rect.borderColorLeft;
|
||||
if (rect.borderColorRight != null)
|
||||
this.borderColorRight = rect.borderColorRight;
|
||||
if (rect.borderColorTop != null)
|
||||
this.borderColorTop = rect.borderColorTop;
|
||||
if (rect.borderColorBottom != null)
|
||||
this.borderColorBottom = rect.borderColorBottom;
|
||||
if (rect.borderWidthLeft != UNDEFINED)
|
||||
this.borderWidthLeft = rect.borderWidthLeft;
|
||||
if (rect.borderWidthRight != UNDEFINED)
|
||||
this.borderWidthRight = rect.borderWidthRight;
|
||||
if (rect.borderWidthTop != UNDEFINED)
|
||||
this.borderWidthTop = rect.borderWidthTop;
|
||||
if (rect.borderWidthBottom != UNDEFINED)
|
||||
this.borderWidthBottom = rect.borderWidthBottom;
|
||||
if (useVariableBorders)
|
||||
this.useVariableBorders = rect.useVariableBorders;
|
||||
}
|
||||
|
||||
// implementation of the Element interface
|
||||
|
||||
/// <summary>
|
||||
/// Processes the element by adding it (or the different parts) to an
|
||||
/// IElementListener.
|
||||
/// </summary>
|
||||
/// <param name="listener">an IElementListener</param>
|
||||
/// <returns>true if the element was processed successfully</returns>
|
||||
public virtual bool Process(IElementListener listener) {
|
||||
try {
|
||||
return listener.Add(this);
|
||||
}
|
||||
catch (DocumentException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of the text element.
|
||||
/// </summary>
|
||||
/// <value>a type</value>
|
||||
public virtual int Type {
|
||||
get {
|
||||
return Element.RECTANGLE;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the chunks in this element.
|
||||
/// </summary>
|
||||
/// <value>an ArrayList</value>
|
||||
public virtual ArrayList Chunks {
|
||||
get {
|
||||
return new ArrayList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.lowagie.text.Element#isContent()
|
||||
* @since iText 2.0.8
|
||||
*/
|
||||
public bool IsContent() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.lowagie.text.Element#isNestable()
|
||||
* @since iText 2.0.8
|
||||
*/
|
||||
public virtual bool IsNestable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// methods
|
||||
|
||||
/**
|
||||
* Switches lowerleft with upperright
|
||||
*/
|
||||
public virtual void Normalize() {
|
||||
if (llx > urx) {
|
||||
float a = llx;
|
||||
llx = urx;
|
||||
urx = a;
|
||||
}
|
||||
if (lly > ury) {
|
||||
float a = lly;
|
||||
lly = ury;
|
||||
ury = a;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a Rectangle that is altered to fit on the page.
|
||||
/// </summary>
|
||||
/// <param name="top">the top position</param>
|
||||
/// <param name="bottom">the bottom position</param>
|
||||
/// <returns>a Rectangle</returns>
|
||||
public Rectangle GetRectangle(float top, float bottom) {
|
||||
Rectangle tmp = new Rectangle(this);
|
||||
if (this.Top > top) {
|
||||
tmp.Top = top;
|
||||
tmp.Border = border - (border & TOP_BORDER);
|
||||
}
|
||||
if (Bottom < bottom) {
|
||||
tmp.Bottom = bottom;
|
||||
tmp.Border = border - (border & BOTTOM_BORDER);
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Swaps the values of urx and ury and of lly and llx in order to rotate the rectangle.
|
||||
/// </summary>
|
||||
/// <returns>a Rectangle</returns>
|
||||
public Rectangle Rotate() {
|
||||
Rectangle rect = new Rectangle(lly, llx, ury, urx);
|
||||
rect.rotation = rotation + 90;
|
||||
rect.rotation %= 360;
|
||||
return rect;
|
||||
}
|
||||
|
||||
// methods to set the membervariables
|
||||
|
||||
/// <summary>
|
||||
/// Get/set the upper right y-coordinate.
|
||||
/// </summary>
|
||||
/// <value>a float</value>
|
||||
public virtual float Top {
|
||||
get {
|
||||
return ury;
|
||||
}
|
||||
|
||||
set {
|
||||
ury = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables the border on the specified side.
|
||||
*
|
||||
* @param side
|
||||
* the side to enable. One of <CODE>LEFT, RIGHT, TOP, BOTTOM
|
||||
* </CODE>
|
||||
*/
|
||||
public virtual void EnableBorderSide(int side) {
|
||||
if (border == UNDEFINED) {
|
||||
border = 0;
|
||||
}
|
||||
border |= side;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the border on the specified side.
|
||||
*
|
||||
* @param side
|
||||
* the side to disable. One of <CODE>LEFT, RIGHT, TOP, BOTTOM
|
||||
* </CODE>
|
||||
*/
|
||||
public virtual void DisableBorderSide(int side) {
|
||||
if (border == UNDEFINED) {
|
||||
border = 0;
|
||||
}
|
||||
border &= ~side;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get/set the border
|
||||
/// </summary>
|
||||
/// <value>a int</value>
|
||||
public virtual int Border {
|
||||
get {
|
||||
return this.border;
|
||||
}
|
||||
|
||||
set {
|
||||
border = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get/set the grayscale of the rectangle.
|
||||
/// </summary>
|
||||
/// <value>a float</value>
|
||||
public virtual float GrayFill {
|
||||
get {
|
||||
if (backgroundColor is GrayColor)
|
||||
return ((GrayColor)backgroundColor).Gray;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
set {
|
||||
backgroundColor = new GrayColor(value); }
|
||||
}
|
||||
|
||||
// methods to get the membervariables
|
||||
|
||||
/// <summary>
|
||||
/// Get/set the lower left x-coordinate.
|
||||
/// </summary>
|
||||
/// <value>a float</value>
|
||||
public virtual float Left {
|
||||
get {
|
||||
return llx;
|
||||
}
|
||||
|
||||
set {
|
||||
llx = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get/set the upper right x-coordinate.
|
||||
/// </summary>
|
||||
/// <value>a float</value>
|
||||
public virtual float Right {
|
||||
get {
|
||||
return urx;
|
||||
}
|
||||
|
||||
set {
|
||||
urx = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get/set the lower left y-coordinate.
|
||||
/// </summary>
|
||||
/// <value>a float</value>
|
||||
public virtual float Bottom {
|
||||
get {
|
||||
return lly;
|
||||
}
|
||||
set {
|
||||
lly = value;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual Color BorderColorBottom {
|
||||
get {
|
||||
if (borderColorBottom == null) return borderColor;
|
||||
return borderColorBottom;
|
||||
}
|
||||
set {
|
||||
borderColorBottom = value;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual Color BorderColorTop {
|
||||
get {
|
||||
if (borderColorTop == null) return borderColor;
|
||||
return borderColorTop;
|
||||
}
|
||||
set {
|
||||
borderColorTop = value;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual Color BorderColorLeft {
|
||||
get {
|
||||
if (borderColorLeft == null) return borderColor;
|
||||
return borderColorLeft;
|
||||
}
|
||||
set {
|
||||
borderColorLeft = value;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual Color BorderColorRight {
|
||||
get {
|
||||
if (borderColorRight == null) return borderColor;
|
||||
return borderColorRight;
|
||||
}
|
||||
set {
|
||||
borderColorRight = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the lower left x-coordinate, considering a given margin.
|
||||
/// </summary>
|
||||
/// <param name="margin">a margin</param>
|
||||
/// <returns>the lower left x-coordinate</returns>
|
||||
public virtual float GetLeft(float margin) {
|
||||
return llx + margin;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the upper right x-coordinate, considering a given margin.
|
||||
/// </summary>
|
||||
/// <param name="margin">a margin</param>
|
||||
/// <returns>the upper right x-coordinate</returns>
|
||||
public virtual float GetRight(float margin) {
|
||||
return urx - margin;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the upper right y-coordinate, considering a given margin.
|
||||
/// </summary>
|
||||
/// <param name="margin">a margin</param>
|
||||
/// <returns>the upper right y-coordinate</returns>
|
||||
public virtual float GetTop(float margin) {
|
||||
return ury - margin;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the lower left y-coordinate, considering a given margin.
|
||||
/// </summary>
|
||||
/// <param name="margin">a margin</param>
|
||||
/// <returns>the lower left y-coordinate</returns>
|
||||
public virtual float GetBottom(float margin) {
|
||||
return lly + margin;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the width of the rectangle.
|
||||
/// </summary>
|
||||
/// <value>a width</value>
|
||||
public virtual float Width {
|
||||
get {
|
||||
return urx - llx;
|
||||
}
|
||||
set {
|
||||
throw new InvalidOperationException("The width cannot be set.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the height of the rectangle.
|
||||
/// </summary>
|
||||
/// <value>a height</value>
|
||||
public float Height {
|
||||
get {
|
||||
return ury - lly;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if the table has borders.
|
||||
/// </summary>
|
||||
/// <returns>a bool</returns>
|
||||
public bool HasBorders() {
|
||||
return (border > 0)
|
||||
&& ((borderWidth > 0) || (borderWidthLeft > 0)
|
||||
|| (borderWidthRight > 0) || (borderWidthTop > 0) || (borderWidthBottom > 0));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if the table has a some type of border.
|
||||
/// </summary>
|
||||
/// <param name="type">the type of border</param>
|
||||
/// <returns>a bool</returns>
|
||||
public bool HasBorder(int type) {
|
||||
return border != UNDEFINED && (border & type) == type;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get/set the borderwidth.
|
||||
/// </summary>
|
||||
/// <value>a float</value>
|
||||
public virtual float BorderWidth {
|
||||
get {
|
||||
return borderWidth;
|
||||
}
|
||||
|
||||
set {
|
||||
borderWidth = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the color of the border.
|
||||
*
|
||||
* @return a value
|
||||
*/
|
||||
/// <summary>
|
||||
/// Get/set the color of the border.
|
||||
/// </summary>
|
||||
/// <value>a Color</value>
|
||||
public virtual Color BorderColor {
|
||||
get {
|
||||
return borderColor;
|
||||
}
|
||||
|
||||
set {
|
||||
borderColor = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the backgroundcolor.
|
||||
*
|
||||
* @return a value
|
||||
*/
|
||||
/// <summary>
|
||||
/// Get/set the backgroundcolor.
|
||||
/// </summary>
|
||||
/// <value>a Color</value>
|
||||
public virtual Color BackgroundColor {
|
||||
get {
|
||||
return backgroundColor;
|
||||
}
|
||||
|
||||
set {
|
||||
backgroundColor = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the rotation
|
||||
/// </summary>
|
||||
/// <value>a int</value>
|
||||
public int Rotation {
|
||||
get {
|
||||
return rotation;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual float BorderWidthLeft {
|
||||
get {
|
||||
return GetVariableBorderWidth(borderWidthLeft, LEFT_BORDER);
|
||||
}
|
||||
set {
|
||||
borderWidthLeft = value;
|
||||
UpdateBorderBasedOnWidth(value, LEFT_BORDER);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual float BorderWidthRight {
|
||||
get {
|
||||
return GetVariableBorderWidth(borderWidthRight, RIGHT_BORDER);
|
||||
}
|
||||
set {
|
||||
borderWidthRight = value;
|
||||
UpdateBorderBasedOnWidth(value, RIGHT_BORDER);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual float BorderWidthTop {
|
||||
get {
|
||||
return GetVariableBorderWidth(borderWidthTop, TOP_BORDER);
|
||||
}
|
||||
set {
|
||||
borderWidthTop = value;
|
||||
UpdateBorderBasedOnWidth(value, TOP_BORDER);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual float BorderWidthBottom {
|
||||
get {
|
||||
return GetVariableBorderWidth(borderWidthBottom, BOTTOM_BORDER);
|
||||
}
|
||||
set {
|
||||
borderWidthBottom = value;
|
||||
UpdateBorderBasedOnWidth(value, BOTTOM_BORDER);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the border flag for a side based on the specified width. A width
|
||||
* of 0 will disable the border on that side. Any other width enables it.
|
||||
*
|
||||
* @param width
|
||||
* width of border
|
||||
* @param side
|
||||
* border side constant
|
||||
*/
|
||||
|
||||
private void UpdateBorderBasedOnWidth(float width, int side) {
|
||||
useVariableBorders = true;
|
||||
if (width > 0) {
|
||||
EnableBorderSide(side);
|
||||
} else {
|
||||
DisableBorderSide(side);
|
||||
}
|
||||
}
|
||||
|
||||
private float GetVariableBorderWidth(float variableWidthValue, int side) {
|
||||
if ((border & side) != 0) {
|
||||
return variableWidthValue != UNDEFINED ? variableWidthValue
|
||||
: borderWidth;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a parameter indicating if the rectangle has variable borders
|
||||
*
|
||||
* @param useVariableBorders
|
||||
* indication if the rectangle has variable borders
|
||||
*/
|
||||
public virtual bool UseVariableBorders{
|
||||
get {
|
||||
return useVariableBorders;
|
||||
}
|
||||
set {
|
||||
useVariableBorders = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override String ToString() {
|
||||
StringBuilder buf = new StringBuilder("Rectangle: ");
|
||||
buf.Append(Width);
|
||||
buf.Append('x');
|
||||
buf.Append(Height);
|
||||
buf.Append(" (rot: ");
|
||||
buf.Append(rotation);
|
||||
buf.Append(" degrees)");
|
||||
return buf.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
329
iTechSharp/iTextSharp/text/RectangleReadOnly.cs
Normal file
329
iTechSharp/iTextSharp/text/RectangleReadOnly.cs
Normal file
@@ -0,0 +1,329 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Text;
|
||||
using System.util;
|
||||
using iTextSharp.text.pdf;
|
||||
|
||||
/*
|
||||
* $Id: RectangleReadOnly.cs,v 1.2 2008/05/13 11:25:12 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text {
|
||||
/// <summary>
|
||||
/// A RectangleReadOnly is the representation of a geometric figure.
|
||||
/// It's the same as a Rectangle but immutable.
|
||||
/// </summary>
|
||||
/// <seealso cref="T:iTextSharp.text.Element"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Table"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Cell"/>
|
||||
/// <seealso cref="T:iTextSharp.text.HeaderFooter"/>
|
||||
public class RectangleReadOnly : Rectangle {
|
||||
|
||||
// constructors
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a RectangleReadOnly-object.
|
||||
/// </summary>
|
||||
/// <param name="llx">lower left x</param>
|
||||
/// <param name="lly">lower left y</param>
|
||||
/// <param name="urx">upper right x</param>
|
||||
/// <param name="ury">upper right y</param>
|
||||
public RectangleReadOnly(float llx, float lly, float urx, float ury) : base(llx, lly, urx, ury) {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a RectangleReadOnly-object starting from the origin (0, 0).
|
||||
/// </summary>
|
||||
/// <param name="urx">upper right x</param>
|
||||
/// <param name="ury">upper right y</param>
|
||||
public RectangleReadOnly(float urx, float ury) : base(0, 0, urx, ury) {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a RectangleReadOnly-object.
|
||||
/// </summary>
|
||||
/// <param name="rect">another Rectangle</param>
|
||||
public RectangleReadOnly(Rectangle rect) : base(rect.Left, rect.Bottom, rect.Right, rect.Top) {
|
||||
base.CloneNonPositionParameters(rect);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all of the parameters from a <CODE>Rectangle</CODE> object
|
||||
* except the position.
|
||||
*
|
||||
* @param rect
|
||||
* <CODE>Rectangle</CODE> to copy from
|
||||
*/
|
||||
public override void CloneNonPositionParameters(Rectangle rect) {
|
||||
ThrowReadOnlyError();
|
||||
}
|
||||
|
||||
private void ThrowReadOnlyError() {
|
||||
throw new InvalidOperationException("RectangleReadOnly: this Rectangle is read only.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all of the parameters from a <CODE>Rectangle</CODE> object
|
||||
* except the position.
|
||||
*
|
||||
* @param rect
|
||||
* <CODE>Rectangle</CODE> to copy from
|
||||
*/
|
||||
|
||||
public override void SoftCloneNonPositionParameters(Rectangle rect) {
|
||||
ThrowReadOnlyError();
|
||||
}
|
||||
|
||||
// methods
|
||||
|
||||
/**
|
||||
* Switches lowerleft with upperright
|
||||
*/
|
||||
public override void Normalize() {
|
||||
ThrowReadOnlyError();
|
||||
}
|
||||
|
||||
// methods to set the membervariables
|
||||
|
||||
/// <summary>
|
||||
/// Get/set the upper right y-coordinate.
|
||||
/// </summary>
|
||||
/// <value>a float</value>
|
||||
public override float Top {
|
||||
set {
|
||||
ThrowReadOnlyError();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables the border on the specified side.
|
||||
*
|
||||
* @param side
|
||||
* the side to enable. One of <CODE>LEFT, RIGHT, TOP, BOTTOM
|
||||
* </CODE>
|
||||
*/
|
||||
public override void EnableBorderSide(int side) {
|
||||
ThrowReadOnlyError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the border on the specified side.
|
||||
*
|
||||
* @param side
|
||||
* the side to disable. One of <CODE>LEFT, RIGHT, TOP, BOTTOM
|
||||
* </CODE>
|
||||
*/
|
||||
public override void DisableBorderSide(int side) {
|
||||
ThrowReadOnlyError();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get/set the border
|
||||
/// </summary>
|
||||
/// <value>a int</value>
|
||||
public override int Border {
|
||||
set {
|
||||
ThrowReadOnlyError();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get/set the grayscale of the rectangle.
|
||||
/// </summary>
|
||||
/// <value>a float</value>
|
||||
public override float GrayFill {
|
||||
set {
|
||||
ThrowReadOnlyError();
|
||||
}
|
||||
}
|
||||
|
||||
// methods to get the membervariables
|
||||
|
||||
/// <summary>
|
||||
/// Get/set the lower left x-coordinate.
|
||||
/// </summary>
|
||||
/// <value>a float</value>
|
||||
public override float Left {
|
||||
set {
|
||||
ThrowReadOnlyError();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get/set the upper right x-coordinate.
|
||||
/// </summary>
|
||||
/// <value>a float</value>
|
||||
public override float Right {
|
||||
set {
|
||||
ThrowReadOnlyError();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get/set the lower left y-coordinate.
|
||||
/// </summary>
|
||||
/// <value>a float</value>
|
||||
public override float Bottom {
|
||||
set {
|
||||
ThrowReadOnlyError();
|
||||
}
|
||||
}
|
||||
|
||||
public override Color BorderColorBottom {
|
||||
set {
|
||||
ThrowReadOnlyError();
|
||||
}
|
||||
}
|
||||
|
||||
public override Color BorderColorTop {
|
||||
set {
|
||||
ThrowReadOnlyError();
|
||||
}
|
||||
}
|
||||
|
||||
public override Color BorderColorLeft {
|
||||
set {
|
||||
ThrowReadOnlyError();
|
||||
}
|
||||
}
|
||||
|
||||
public override Color BorderColorRight {
|
||||
set {
|
||||
ThrowReadOnlyError();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get/set the borderwidth.
|
||||
/// </summary>
|
||||
/// <value>a float</value>
|
||||
public override float BorderWidth {
|
||||
set {
|
||||
ThrowReadOnlyError();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the color of the border.
|
||||
*
|
||||
* @return a value
|
||||
*/
|
||||
/// <summary>
|
||||
/// Get/set the color of the border.
|
||||
/// </summary>
|
||||
/// <value>a Color</value>
|
||||
public override Color BorderColor {
|
||||
set {
|
||||
ThrowReadOnlyError();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the backgroundcolor.
|
||||
*
|
||||
* @return a value
|
||||
*/
|
||||
/// <summary>
|
||||
/// Get/set the backgroundcolor.
|
||||
/// </summary>
|
||||
/// <value>a Color</value>
|
||||
public override Color BackgroundColor {
|
||||
set {
|
||||
ThrowReadOnlyError();
|
||||
}
|
||||
}
|
||||
|
||||
public override float BorderWidthLeft {
|
||||
set {
|
||||
ThrowReadOnlyError();
|
||||
}
|
||||
}
|
||||
|
||||
public override float BorderWidthRight {
|
||||
set {
|
||||
ThrowReadOnlyError();
|
||||
}
|
||||
}
|
||||
|
||||
public override float BorderWidthTop {
|
||||
set {
|
||||
ThrowReadOnlyError();
|
||||
}
|
||||
}
|
||||
|
||||
public override float BorderWidthBottom {
|
||||
set {
|
||||
ThrowReadOnlyError();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a parameter indicating if the rectangle has variable borders
|
||||
*
|
||||
* @param useVariableBorders
|
||||
* indication if the rectangle has variable borders
|
||||
*/
|
||||
public override bool UseVariableBorders{
|
||||
set {
|
||||
ThrowReadOnlyError();
|
||||
}
|
||||
}
|
||||
|
||||
public override String ToString() {
|
||||
StringBuilder buf = new StringBuilder("RectangleReadOnly: ");
|
||||
buf.Append(Width);
|
||||
buf.Append('x');
|
||||
buf.Append(Height);
|
||||
buf.Append(" (rot: ");
|
||||
buf.Append(rotation);
|
||||
buf.Append(" degrees)");
|
||||
return buf.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
116
iTechSharp/iTextSharp/text/RomanList.cs
Normal file
116
iTechSharp/iTextSharp/text/RomanList.cs
Normal file
@@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using iTextSharp.text.factories;
|
||||
|
||||
/*
|
||||
* Copyright 2003 by Michael Niedermair.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
namespace iTextSharp.text {
|
||||
|
||||
/**
|
||||
*
|
||||
* A special-version of <CODE>LIST</CODE> which use roman-letters.
|
||||
*
|
||||
* @see com.lowagie.text.List
|
||||
* @version 2003-06-22
|
||||
* @author Michael Niedermair
|
||||
*/
|
||||
|
||||
public class RomanList : List {
|
||||
|
||||
/**
|
||||
* Initialization
|
||||
*/
|
||||
public RomanList() : base(true) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialization
|
||||
*
|
||||
* @param symbolIndent indent
|
||||
*/
|
||||
public RomanList(int symbolIndent) : base(true, symbolIndent){
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialization
|
||||
* @param romanlower roman-char in lowercase
|
||||
* @param symbolIndent indent
|
||||
*/
|
||||
public RomanList(bool romanlower, int symbolIndent) : base(true, symbolIndent) {
|
||||
this.lowercase = romanlower;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an <CODE>Object</CODE> to the <CODE>List</CODE>.
|
||||
*
|
||||
* @param o the object to add.
|
||||
* @return true if adding the object succeeded
|
||||
*/
|
||||
public override bool Add(Object o) {
|
||||
if (o is ListItem) {
|
||||
ListItem item = (ListItem) o;
|
||||
Chunk chunk = new Chunk(preSymbol, symbol.Font);
|
||||
chunk.Append(RomanNumberFactory.GetString(first + list.Count, lowercase));
|
||||
chunk.Append(postSymbol);
|
||||
item.ListSymbol = chunk;
|
||||
item.SetIndentationLeft(symbolIndent, autoindent);
|
||||
item.IndentationRight = 0;
|
||||
list.Add(item);
|
||||
return true;
|
||||
} else if (o is List) {
|
||||
List nested = (List) o;
|
||||
nested.IndentationLeft = nested.IndentationLeft + symbolIndent;
|
||||
first--;
|
||||
list.Add(nested);
|
||||
return true;
|
||||
} else if (o is string) {
|
||||
return this.Add(new ListItem((string) o));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
376
iTechSharp/iTextSharp/text/Row.cs
Normal file
376
iTechSharp/iTextSharp/text/Row.cs
Normal file
@@ -0,0 +1,376 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.util;
|
||||
|
||||
/*
|
||||
* $Id: Row.cs,v 1.10 2008/05/13 11:25:12 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 LIBRARY GENERAL PUBLIC LICENSE for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text {
|
||||
/// <summary>
|
||||
/// A Row is part of a Table
|
||||
/// and contains some Cells.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// All Rows are constructed by a Table-object.
|
||||
/// You don't have to construct any Row yourself.
|
||||
/// In fact you can't construct a Row outside the package.
|
||||
/// <P/>
|
||||
/// Since a Cell can span several rows and/or columns
|
||||
/// a row can contain reserved space without any content.
|
||||
/// </remarks>
|
||||
/// <seealso cref="T:iTextSharp.text.Element"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Cell"/>
|
||||
/// <seealso cref="T:iTextSharp.text.Table"/>
|
||||
public class Row : IElement {
|
||||
|
||||
// membervariables
|
||||
|
||||
/// <summary> id of a null element in a Row</summary>
|
||||
public static int NULL = 0;
|
||||
|
||||
/// <summary> id of the Cell element in a Row</summary>
|
||||
public static int CELL = 1;
|
||||
|
||||
/// <summary> id of the Table element in a Row</summary>
|
||||
public static int TABLE = 2;
|
||||
|
||||
/// <summary> This is the number of columns in the Row. </summary>
|
||||
protected int columns;
|
||||
|
||||
/// <summary> This is a valid position the Row. </summary>
|
||||
protected int currentColumn;
|
||||
|
||||
/// <summary> This is the array that keeps track of reserved cells. </summary>
|
||||
protected bool[] reserved;
|
||||
|
||||
/// <summary> This is the array of Objects (Cell or Table). </summary>
|
||||
protected Object[] cells;
|
||||
|
||||
/// <summary> This is the horizontal alignment. </summary>
|
||||
protected int horizontalAlignment;
|
||||
|
||||
// constructors
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Row with a certain number of columns.
|
||||
/// </summary>
|
||||
/// <param name="columns">a number of columns</param>
|
||||
internal Row(int columns) {
|
||||
this.columns = columns;
|
||||
reserved = new bool[columns];
|
||||
cells = new Object[columns];
|
||||
currentColumn = 0;
|
||||
}
|
||||
|
||||
// implementation of the Element-methods
|
||||
|
||||
/// <summary>
|
||||
/// Processes the element by adding it (or the different parts) to a
|
||||
/// IElementListener.
|
||||
/// </summary>
|
||||
/// <param name="listener">an IElementListener</param>
|
||||
/// <returns>true if the element was processed successfully</returns>
|
||||
public bool Process(IElementListener listener) {
|
||||
try {
|
||||
return listener.Add(this);
|
||||
}
|
||||
catch (DocumentException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of the text element.
|
||||
/// </summary>
|
||||
/// <value>a type</value>
|
||||
public int Type {
|
||||
get {
|
||||
return Element.ROW;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the chunks in this element.
|
||||
/// </summary>
|
||||
/// <value>an ArrayList</value>
|
||||
public ArrayList Chunks {
|
||||
get {
|
||||
return new ArrayList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.lowagie.text.Element#isContent()
|
||||
* @since iText 2.0.8
|
||||
*/
|
||||
public bool IsContent() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.lowagie.text.Element#isNestable()
|
||||
* @since iText 2.0.8
|
||||
*/
|
||||
public bool IsNestable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a certain column has been deleted.
|
||||
/// </summary>
|
||||
/// <param name="column">the number of the column to delete</param>
|
||||
internal void DeleteColumn(int column) {
|
||||
if ((column >= columns) || (column < 0)) {
|
||||
throw new Exception("getCell at illegal index : " + column);
|
||||
}
|
||||
columns--;
|
||||
bool[] newReserved = new bool[columns];
|
||||
Object[] newCells = new Cell[columns];
|
||||
|
||||
for (int i = 0; i < column; i++) {
|
||||
newReserved[i] = reserved[i];
|
||||
newCells[i] = cells[i];
|
||||
if (newCells[i] != null && (i + ((Cell) newCells[i]).Colspan > column)) {
|
||||
((Cell) newCells[i]).Colspan = ((Cell) cells[i]).Colspan - 1;
|
||||
}
|
||||
}
|
||||
for (int i = column; i < columns; i++) {
|
||||
newReserved[i] = reserved[i + 1];
|
||||
newCells[i] = cells[i + 1];
|
||||
}
|
||||
if (cells[column] != null && ((Cell) cells[column]).Colspan > 1) {
|
||||
newCells[column] = cells[column];
|
||||
((Cell) newCells[column]).Colspan = ((Cell) newCells[column]).Colspan - 1;
|
||||
}
|
||||
reserved = newReserved;
|
||||
cells = newCells;
|
||||
}
|
||||
|
||||
// methods
|
||||
|
||||
/// <summary>
|
||||
/// Adds a Cell to the Row.
|
||||
/// </summary>
|
||||
/// <param name="element">the element to add (currently only Cells and Tables supported)</param>
|
||||
/// <returns>
|
||||
/// the column position the Cell was added,
|
||||
/// or -1 if the element couldn't be added.
|
||||
/// </returns>
|
||||
internal int AddElement(Object element) {
|
||||
return AddElement(element, currentColumn);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds an element to the Row at the position given.
|
||||
/// </summary>
|
||||
/// <param name="element">the element to add. (currently only Cells and Tables supported</param>
|
||||
/// <param name="column">the position where to add the cell</param>
|
||||
/// <returns>
|
||||
/// the column position the Cell was added,
|
||||
/// or -1 if the Cell couldn't be added.
|
||||
/// </returns>
|
||||
internal int AddElement(Object element, int column) {
|
||||
if (element == null) throw new Exception("addCell - null argument");
|
||||
if ((column < 0) || (column > columns)) throw new Exception("addCell - illegal column argument");
|
||||
if ( !((GetObjectID(element) == CELL) || (GetObjectID(element) == TABLE)) ) throw new ArgumentException("addCell - only Cells or Tables allowed");
|
||||
|
||||
int lColspan = ((element is Cell) ? ((Cell)element).Colspan : 1);
|
||||
|
||||
if (!Reserve(column, lColspan)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
cells[column] = element;
|
||||
currentColumn += lColspan - 1;
|
||||
|
||||
return column;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Puts Cell to the Row at the position given, doesn't reserve colspan.
|
||||
/// </summary>
|
||||
/// <param name="aElement">the cell to add.</param>
|
||||
/// <param name="column">the position where to add the cell.</param>
|
||||
internal void SetElement(Object aElement, int column) {
|
||||
if (reserved[column]) throw new ArgumentException("setElement - position already taken");
|
||||
|
||||
cells[column] = aElement;
|
||||
if (aElement != null) {
|
||||
reserved[column] = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reserves a Cell in the Row.
|
||||
/// </summary>
|
||||
/// <param name="column">the column that has to be reserved.</param>
|
||||
/// <returns>true if the column was reserved, false if not.</returns>
|
||||
internal bool Reserve(int column) {
|
||||
return Reserve(column, 1);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Reserves a Cell in the Row.
|
||||
/// </summary>
|
||||
/// <param name="column">the column that has to be reserved.</param>
|
||||
/// <param name="size">the number of columns</param>
|
||||
/// <returns>true if the column was reserved, false if not.</returns>
|
||||
internal bool Reserve(int column, int size) {
|
||||
if ((column < 0) || ((column + size) > columns)) throw new Exception("reserve - incorrect column/size");
|
||||
|
||||
for (int i=column; i < column + size; i++) {
|
||||
if (reserved[i]) {
|
||||
// undo reserve
|
||||
for (int j=i; j >= column; j--) {
|
||||
reserved[j] = false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
reserved[i] = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// methods to retrieve information
|
||||
|
||||
/// <summary>
|
||||
/// Returns true/false when this position in the Row has been reserved, either filled or through a colspan of an Element.
|
||||
/// </summary>
|
||||
/// <param name="column">the column.</param>
|
||||
/// <returns>true if the column was reserved, false if not.</returns>
|
||||
internal bool IsReserved(int column) {
|
||||
return reserved[column];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the type-id of the element in a Row.
|
||||
/// </summary>
|
||||
/// <param name="column">the column of which you'd like to know the type</param>
|
||||
/// <returns>the element id</returns>
|
||||
int GetElementID(int column) {
|
||||
if (cells[column] == null) return NULL;
|
||||
else if (cells[column] is Cell) return CELL;
|
||||
else if (cells[column] is Table) return TABLE;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns the type-id of an Object.
|
||||
/// </summary>
|
||||
/// <param name="element"></param>
|
||||
/// <returns>the object of which you'd like to know the type-id, -1 if invalid</returns>
|
||||
int GetObjectID(Object element) {
|
||||
if (element == null) return NULL;
|
||||
else if (element is Cell) return CELL;
|
||||
else if (element is Table) return TABLE;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets a Cell or Table from a certain column.
|
||||
/// </summary>
|
||||
/// <param name="column">the column the Cell/Table is in.</param>
|
||||
/// <returns>
|
||||
/// the Cell,Table or Object if the column was
|
||||
/// reserved or null if empty.
|
||||
/// </returns>
|
||||
public Object GetCell(int column) {
|
||||
if ((column < 0) || (column > columns)) {
|
||||
throw new Exception("getCell at illegal index :" + column + " max is " + columns);
|
||||
}
|
||||
return cells[column];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the row is empty.
|
||||
/// </summary>
|
||||
/// <returns>true if none of the columns is reserved.</returns>
|
||||
public bool IsEmpty() {
|
||||
for (int i = 0; i < columns; i++) {
|
||||
if (cells[i] != null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of columns.
|
||||
/// </summary>
|
||||
/// <value>a value</value>
|
||||
public int Columns {
|
||||
get {
|
||||
return columns;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the horizontal Element.
|
||||
/// </summary>
|
||||
/// <value>a value</value>
|
||||
public int HorizontalAlignment {
|
||||
get {
|
||||
return horizontalAlignment;
|
||||
}
|
||||
set {
|
||||
horizontalAlignment = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return base.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
756
iTechSharp/iTextSharp/text/Section.cs
Normal file
756
iTechSharp/iTextSharp/text/Section.cs
Normal file
@@ -0,0 +1,756 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using System.util;
|
||||
using iTextSharp.text.factories;
|
||||
|
||||
/*
|
||||
* $Id: Section.cs,v 1.17 2008/05/13 11:25:13 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text {
|
||||
/// <summary>
|
||||
/// A Section is a part of a Document containing
|
||||
/// other Sections, Paragraphs, List
|
||||
/// and/or Tables.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// You can not construct a Section yourself.
|
||||
/// You will have to ask an instance of Section to the
|
||||
/// Chapter or Section to which you want to
|
||||
/// add the new Section.
|
||||
/// </remarks>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// Paragraph title2 = new Paragraph("This is Chapter 2", FontFactory.GetFont(FontFactory.HELVETICA, 18, Font.BOLDITALIC, new Color(0, 0, 255)));
|
||||
/// Chapter chapter2 = new Chapter(title2, 2);
|
||||
/// Paragraph someText = new Paragraph("This is some text");
|
||||
/// chapter2.Add(someText);
|
||||
/// Paragraph title21 = new Paragraph("This is Section 1 in Chapter 2", FontFactory.GetFont(FontFactory.HELVETICA, 16, Font.BOLD, new Color(255, 0, 0)));
|
||||
/// <strong>Section section1 = chapter2.AddSection(title21);</strong>
|
||||
/// Paragraph someSectionText = new Paragraph("This is some silly paragraph in a chapter and/or section. It contains some text to test the functionality of Chapters and Section.");
|
||||
/// <strong>section1.Add(someSectionText);</strong>
|
||||
/// Paragraph title211 = new Paragraph("This is SubSection 1 in Section 1 in Chapter 2", FontFactory.GetFont(FontFactory.HELVETICA, 14, Font.BOLD, new Color(255, 0, 0)));
|
||||
/// <strong>Section section11 = section1.AddSection(40, title211, 2);
|
||||
/// section11.Add(someSectionText);</strong>strong>
|
||||
/// </code>
|
||||
/// </example>
|
||||
public class Section : ArrayList, ITextElementArray, ILargeElement {
|
||||
|
||||
// constant
|
||||
/**
|
||||
* A possible number style. The default number style: "1.2.3."
|
||||
* @since iText 2.0.8
|
||||
*/
|
||||
public const int NUMBERSTYLE_DOTTED = 0;
|
||||
/**
|
||||
* A possible number style. For instance: "1.2.3"
|
||||
* @since iText 2.0.8
|
||||
*/
|
||||
public const int NUMBERSTYLE_DOTTED_WITHOUT_FINAL_DOT = 1;
|
||||
|
||||
// membervariables
|
||||
|
||||
///<summary> This is the title of this section. </summary>
|
||||
protected Paragraph title;
|
||||
|
||||
///<summary> This is the number of sectionnumbers that has to be shown before the section title. </summary>
|
||||
protected int numberDepth;
|
||||
|
||||
/**
|
||||
* The style for sectionnumbers.
|
||||
* @since iText 2.0.8
|
||||
*/
|
||||
protected int numberStyle = NUMBERSTYLE_DOTTED;
|
||||
|
||||
///<summary> The indentation of this section on the left side. </summary>
|
||||
protected float indentationLeft;
|
||||
|
||||
///<summary> The indentation of this section on the right side. </summary>
|
||||
protected float indentationRight;
|
||||
|
||||
///<summary> The additional indentation of the content of this section. </summary>
|
||||
protected float indentation;
|
||||
|
||||
///<summary> This is the number of subsections. </summary>
|
||||
protected int subsections = 0;
|
||||
|
||||
///<summary> This is the complete list of sectionnumbers of this section and the parents of this section. </summary>
|
||||
protected internal ArrayList numbers = null;
|
||||
|
||||
/**
|
||||
* Indicates if the Section will be complete once added to the document.
|
||||
* @since iText 2.0.8
|
||||
*/
|
||||
protected bool complete = true;
|
||||
|
||||
/**
|
||||
* Indicates if the Section was added completely to the document.
|
||||
* @since iText 2.0.8
|
||||
*/
|
||||
protected bool addedCompletely = false;
|
||||
|
||||
/**
|
||||
* Indicates if this is the first time the section was added.
|
||||
* @since iText 2.0.8
|
||||
*/
|
||||
protected bool notAddedYet = true;
|
||||
|
||||
///<summary> false if the bookmark children are not visible </summary>
|
||||
protected bool bookmarkOpen = true;
|
||||
|
||||
/** true if the section has to trigger a new page */
|
||||
protected bool triggerNewPage = false;
|
||||
|
||||
/** The bookmark title if different from the content title */
|
||||
protected string bookmarkTitle;
|
||||
|
||||
// constructors
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new Section.
|
||||
/// </summary>
|
||||
/// <overloads>
|
||||
/// Has 2 overloads.
|
||||
/// </overloads>
|
||||
protected internal Section() {
|
||||
title = new Paragraph();
|
||||
numberDepth = 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new Section.
|
||||
/// </summary>
|
||||
/// <param name="title">a Paragraph</param>
|
||||
/// <param name="numberDepth">the numberDepth</param>
|
||||
protected internal Section(Paragraph title, int numberDepth) {
|
||||
this.numberDepth = numberDepth;
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
// private methods
|
||||
|
||||
/// <summary>
|
||||
/// Sets the number of this section.
|
||||
/// </summary>
|
||||
/// <param name="number">the number of this section</param>
|
||||
/// <param name="numbers">an ArrayList, containing the numbers of the Parent</param>
|
||||
private void SetNumbers(int number, ArrayList numbers) {
|
||||
this.numbers = new ArrayList();
|
||||
this.numbers.Add(number);
|
||||
this.numbers.AddRange(numbers);
|
||||
}
|
||||
|
||||
// implementation of the Element-methods
|
||||
|
||||
/// <summary>
|
||||
/// Processes the element by adding it (or the different parts) to an
|
||||
/// IElementListener.
|
||||
/// </summary>
|
||||
/// <param name="listener">the IElementListener</param>
|
||||
/// <returns>true if the element was processed successfully</returns>
|
||||
public bool Process(IElementListener listener) {
|
||||
try {
|
||||
foreach (IElement ele in this) {
|
||||
listener.Add(ele);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (DocumentException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of the text element.
|
||||
/// </summary>
|
||||
/// <value>a type</value>
|
||||
public virtual int Type {
|
||||
get {
|
||||
return Element.SECTION;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the chunks in this element.
|
||||
/// </summary>
|
||||
/// <value>an ArrayList</value>
|
||||
public ArrayList Chunks {
|
||||
get {
|
||||
ArrayList tmp = new ArrayList();
|
||||
foreach (IElement ele in this) {
|
||||
tmp.AddRange(ele.Chunks);
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.lowagie.text.Element#isContent()
|
||||
* @since iText 2.0.8
|
||||
*/
|
||||
public bool IsContent() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.lowagie.text.Element#isNestable()
|
||||
* @since iText 2.0.8
|
||||
*/
|
||||
public virtual bool IsNestable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// overriding some of the ArrayList-methods
|
||||
|
||||
/// <summary>
|
||||
/// Adds a Paragraph, List or Table
|
||||
/// to this Section.
|
||||
/// </summary>
|
||||
/// <param name="index">index at which the specified element is to be inserted</param>
|
||||
/// <param name="o">an object of type Paragraph, List or Table</param>
|
||||
public void Add(int index, Object o) {
|
||||
if (AddedCompletely) {
|
||||
throw new InvalidOperationException("This LargeElement has already been added to the Document.");
|
||||
}
|
||||
try {
|
||||
IElement element = (IElement) o;
|
||||
if (element.IsNestable()) {
|
||||
base.Insert(index, element);
|
||||
}
|
||||
else {
|
||||
throw new Exception(element.Type.ToString());
|
||||
}
|
||||
}
|
||||
catch (Exception cce) {
|
||||
throw new Exception("Insertion of illegal Element: " + cce.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a Paragraph, List, Table or another Section
|
||||
/// to this Section.
|
||||
/// </summary>
|
||||
/// <param name="o">an object of type Paragraph, List, Table or another Section</param>
|
||||
/// <returns>a bool</returns>
|
||||
public new bool Add(Object o) {
|
||||
try {
|
||||
IElement element = (IElement) o;
|
||||
if (element.Type == Element.SECTION) {
|
||||
Section section = (Section) o;
|
||||
section.SetNumbers(++subsections, numbers);
|
||||
base.Add(section);
|
||||
return true;
|
||||
}
|
||||
else if (o is MarkedSection && ((MarkedObject)o).element.Type == Element.SECTION) {
|
||||
MarkedSection mo = (MarkedSection)o;
|
||||
Section section = (Section)(mo.element);
|
||||
section.SetNumbers(++subsections, numbers);
|
||||
base.Add(mo);
|
||||
return true;
|
||||
}
|
||||
else if (element.IsNestable()) {
|
||||
base.Add(o);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
throw new Exception(element.Type.ToString());
|
||||
}
|
||||
}
|
||||
catch (Exception cce) {
|
||||
throw new Exception("Insertion of illegal Element: " + cce.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a collection of Elements
|
||||
/// to this Section.
|
||||
/// </summary>
|
||||
/// <param name="collection">a collection of Paragraphs, Lists and/or Tables</param>
|
||||
/// <returns>true if the action succeeded, false if not.</returns>
|
||||
public bool AddAll(ICollection collection) {
|
||||
foreach (object itm in collection) {
|
||||
this.Add(itm);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// methods that return a Section
|
||||
|
||||
/// <summary>
|
||||
/// Creates a Section, adds it to this Section and returns it.
|
||||
/// </summary>
|
||||
/// <param name="indentation">the indentation of the new section</param>
|
||||
/// <param name="title">the title of the new section</param>
|
||||
/// <param name="numberDepth">the numberDepth of the section</param>
|
||||
/// <returns>the newly added Section</returns>
|
||||
public virtual Section AddSection(float indentation, Paragraph title, int numberDepth) {
|
||||
if (AddedCompletely) {
|
||||
throw new InvalidOperationException("This LargeElement has already been added to the Document.");
|
||||
}
|
||||
Section section = new Section(title, numberDepth);
|
||||
section.Indentation = indentation;
|
||||
Add(section);
|
||||
return section;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a Section, adds it to this Section and returns it.
|
||||
/// </summary>
|
||||
/// <param name="indentation">the indentation of the new section</param>
|
||||
/// <param name="title">the title of the new section</param>
|
||||
/// <returns>the newly added Section</returns>
|
||||
public virtual Section AddSection(float indentation, Paragraph title) {
|
||||
return AddSection(indentation, title, numberDepth + 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a Section, add it to this Section and returns it.
|
||||
/// </summary>
|
||||
/// <param name="title">the title of the new section</param>
|
||||
/// <param name="numberDepth">the numberDepth of the section</param>
|
||||
/// <returns>the newly added Section</returns>
|
||||
public virtual Section AddSection(Paragraph title, int numberDepth) {
|
||||
return AddSection(0, title, numberDepth);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a marked section. For use in class MarkedSection only!
|
||||
*/
|
||||
public MarkedSection AddMarkedSection() {
|
||||
MarkedSection section = new MarkedSection(new Section(null, numberDepth + 1));
|
||||
Add(section);
|
||||
return section;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a Section, adds it to this Section and returns it.
|
||||
/// </summary>
|
||||
/// <param name="title">the title of the new section</param>
|
||||
/// <returns>the newly added Section</returns>
|
||||
public virtual Section AddSection(Paragraph title) {
|
||||
return AddSection(0, title, numberDepth + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a Section to this Section and returns it.
|
||||
*
|
||||
* @param indentation the indentation of the new section
|
||||
* @param title the title of the new section
|
||||
* @param numberDepth the numberDepth of the section
|
||||
*/
|
||||
/// <summary>
|
||||
/// Adds a Section to this Section and returns it.
|
||||
/// </summary>
|
||||
/// <param name="indentation">the indentation of the new section</param>
|
||||
/// <param name="title">the title of the new section</param>
|
||||
/// <param name="numberDepth">the numberDepth of the section</param>
|
||||
/// <returns>the newly added Section</returns>
|
||||
public virtual Section AddSection(float indentation, string title, int numberDepth) {
|
||||
return AddSection(indentation, new Paragraph(title), numberDepth);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a Section to this Section and returns it.
|
||||
*
|
||||
* @param title the title of the new section
|
||||
* @param numberDepth the numberDepth of the section
|
||||
*/
|
||||
/// <summary>
|
||||
/// Adds a Section to this Section and returns it.
|
||||
/// </summary>
|
||||
/// <param name="title">the title of the new section</param>
|
||||
/// <param name="numberDepth">the numberDepth of the section</param>
|
||||
/// <returns>the newly added Section</returns>
|
||||
public virtual Section AddSection(string title, int numberDepth) {
|
||||
return AddSection(new Paragraph(title), numberDepth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a Section to this Section and returns it.
|
||||
/// </summary>
|
||||
/// <param name="indentation">the indentation of the new section</param>
|
||||
/// <param name="title">the title of the new section</param>
|
||||
/// <returns>the newly added Section</returns>
|
||||
public virtual Section AddSection(float indentation, string title) {
|
||||
return AddSection(indentation, new Paragraph(title));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a Section to this Section and returns it.
|
||||
/// </summary>
|
||||
/// <param name="title">the title of the new section</param>
|
||||
/// <returns>the newly added Section</returns>
|
||||
public virtual Section AddSection(string title) {
|
||||
return AddSection(new Paragraph(title));
|
||||
}
|
||||
|
||||
// public methods
|
||||
|
||||
/// <summary>
|
||||
/// Alters the attributes of this Section.
|
||||
/// </summary>
|
||||
/// <param name="attributes">the attributes</param>
|
||||
public void Set(Properties attributes) {
|
||||
string value;
|
||||
if ((value = attributes.Remove(ElementTags.NUMBERDEPTH)) != null) {
|
||||
NumberDepth = int.Parse(value);
|
||||
}
|
||||
if ((value = attributes.Remove(ElementTags.INDENT)) != null) {
|
||||
Indentation = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
}
|
||||
if ((value = attributes.Remove(ElementTags.INDENTATIONLEFT)) != null) {
|
||||
IndentationLeft = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
}
|
||||
if ((value = attributes.Remove(ElementTags.INDENTATIONRIGHT)) != null) {
|
||||
IndentationRight = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get/set the title of this section
|
||||
/// </summary>
|
||||
/// <value>a Paragraph</value>
|
||||
public Paragraph Title {
|
||||
get {
|
||||
return ConstructTitle(title, numbers, numberDepth, numberStyle);
|
||||
}
|
||||
|
||||
set {
|
||||
this.title = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the style for numbering sections.
|
||||
* Possible values are NUMBERSTYLE_DOTTED: 1.2.3. (the default)
|
||||
* or NUMBERSTYLE_DOTTED_WITHOUT_FINAL_DOT: 1.2.3
|
||||
* @since iText 2.0.8
|
||||
*/
|
||||
public int NumberStyle {
|
||||
set {
|
||||
numberStyle = value;
|
||||
}
|
||||
get {
|
||||
return numberStyle;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a Paragraph that will be used as title for a Section or Chapter.
|
||||
* @param title the title of the section
|
||||
* @param numbers a list of sectionnumbers
|
||||
* @param numberDepth how many numbers have to be shown
|
||||
* @param numberStyle the numbering style
|
||||
* @return a Paragraph object
|
||||
* @since iText 2.0.8
|
||||
*/
|
||||
public static Paragraph ConstructTitle(Paragraph title, ArrayList numbers, int numberDepth, int numberStyle) {
|
||||
if (title == null) {
|
||||
return null;
|
||||
}
|
||||
int depth = Math.Min(numbers.Count, numberDepth);
|
||||
if (depth < 1) {
|
||||
return title;
|
||||
}
|
||||
StringBuilder buf = new StringBuilder(" ");
|
||||
for (int i = 0; i < depth; i++) {
|
||||
buf.Insert(0, ".");
|
||||
buf.Insert(0, (int)numbers[i]);
|
||||
}
|
||||
if (numberStyle == NUMBERSTYLE_DOTTED_WITHOUT_FINAL_DOT) {
|
||||
buf.Remove(buf.Length - 2, 1);
|
||||
}
|
||||
Paragraph result = new Paragraph(title);
|
||||
result.Insert(0, new Chunk(buf.ToString(), title.Font));
|
||||
return result;
|
||||
}
|
||||
|
||||
// methods to retrieve information
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this object is a Chapter.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// true if it is a Chapter,
|
||||
/// false if it is a Section
|
||||
/// </returns>
|
||||
public bool IsChapter() {
|
||||
return Type == Element.CHAPTER;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this object is a Section.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// true if it is a Section,
|
||||
/// false if it is a Chapter.
|
||||
/// </returns>
|
||||
public bool IsSection() {
|
||||
return Type == Element.SECTION;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get/set the numberdepth of this Section.
|
||||
/// </summary>
|
||||
/// <value>a int</value>
|
||||
public int NumberDepth {
|
||||
get {
|
||||
return numberDepth;
|
||||
}
|
||||
|
||||
set {
|
||||
this.numberDepth = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get/set the indentation of this Section on the left side.
|
||||
/// </summary>
|
||||
/// <value>the indentation</value>
|
||||
public float IndentationLeft {
|
||||
get {
|
||||
return indentationLeft;
|
||||
}
|
||||
|
||||
set {
|
||||
indentationLeft = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get/set the indentation of this Section on the right side.
|
||||
/// </summary>
|
||||
/// <value>the indentation</value>
|
||||
public float IndentationRight {
|
||||
get {
|
||||
return indentationRight;
|
||||
}
|
||||
|
||||
set {
|
||||
indentationRight = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get/set the indentation of the content of this Section.
|
||||
/// </summary>
|
||||
/// <value>the indentation</value>
|
||||
public float Indentation {
|
||||
get {
|
||||
return indentation;
|
||||
}
|
||||
|
||||
set {
|
||||
indentation = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the depth of this section.
|
||||
/// </summary>
|
||||
/// <value>the depth</value>
|
||||
public int Depth {
|
||||
get {
|
||||
return numbers.Count;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a given tag corresponds with a title tag for this object.
|
||||
/// </summary>
|
||||
/// <param name="tag">the given tag</param>
|
||||
/// <returns>true if the tag corresponds</returns>
|
||||
public static bool IsTitle(string tag) {
|
||||
return ElementTags.TITLE.Equals(tag);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a given tag corresponds with this object.
|
||||
/// </summary>
|
||||
/// <param name="tag">the given tag</param>
|
||||
/// <returns>true if the tag corresponds</returns>
|
||||
public static bool IsTag(string tag) {
|
||||
return ElementTags.SECTION.Equals(tag);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get/set the bookmark
|
||||
/// </summary>
|
||||
/// <value>a bool</value>
|
||||
public bool BookmarkOpen {
|
||||
get {
|
||||
return bookmarkOpen;
|
||||
}
|
||||
|
||||
set {
|
||||
this.bookmarkOpen = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the bookmark title.
|
||||
* @return the bookmark title
|
||||
*/
|
||||
public Paragraph GetBookmarkTitle() {
|
||||
if (bookmarkTitle == null)
|
||||
return Title;
|
||||
else
|
||||
return new Paragraph(bookmarkTitle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the bookmark title. The bookmark title is the same as the section title but
|
||||
* can be changed with this method.
|
||||
* @param bookmarkTitle the bookmark title
|
||||
*/
|
||||
public String BookmarkTitle {
|
||||
set {
|
||||
this.bookmarkTitle = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return base.ToString();
|
||||
}
|
||||
|
||||
public virtual bool TriggerNewPage {
|
||||
get {
|
||||
return triggerNewPage && notAddedYet;
|
||||
}
|
||||
set {
|
||||
triggerNewPage = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the Chapter number.
|
||||
*/
|
||||
public void SetChapterNumber(int number) {
|
||||
numbers[numbers.Count - 1] = number;
|
||||
foreach (Object s in this) {
|
||||
if (s is Section) {
|
||||
((Section)s).SetChapterNumber(number);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if this is the first time the section is added.
|
||||
* @since iText2.0.8
|
||||
* @return true if the section wasn't added yet
|
||||
*/
|
||||
public bool NotAddedYet {
|
||||
get {
|
||||
return notAddedYet;
|
||||
}
|
||||
set {
|
||||
notAddedYet = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.lowagie.text.LargeElement#isAddedCompletely()
|
||||
* @since iText 2.0.8
|
||||
*/
|
||||
protected bool AddedCompletely {
|
||||
get {
|
||||
return addedCompletely;
|
||||
}
|
||||
set {
|
||||
addedCompletely = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since iText 2.0.8
|
||||
* @see com.lowagie.text.LargeElement#flushContent()
|
||||
*/
|
||||
public void FlushContent() {
|
||||
NotAddedYet = false;
|
||||
title = null;
|
||||
for (int k = 0; k < Count; ++k) {
|
||||
IElement element = (IElement)this[k];
|
||||
if (element is Section) {
|
||||
Section s = (Section)element;
|
||||
if (!s.ElementComplete && Count == 1) {
|
||||
s.FlushContent();
|
||||
return;
|
||||
}
|
||||
else {
|
||||
s.AddedCompletely = true;
|
||||
}
|
||||
}
|
||||
this.RemoveAt(k);
|
||||
--k;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since iText 2.0.8
|
||||
* @see com.lowagie.text.LargeElement#isComplete()
|
||||
*/
|
||||
public bool ElementComplete {
|
||||
get {
|
||||
return complete;
|
||||
}
|
||||
set {
|
||||
complete = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new page to the section.
|
||||
* @since 2.1.1
|
||||
*/
|
||||
public void NewPage() {
|
||||
this.Add(Chunk.NEXTPAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
453
iTechSharp/iTextSharp/text/SimpleCell.cs
Normal file
453
iTechSharp/iTextSharp/text/SimpleCell.cs
Normal file
@@ -0,0 +1,453 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using iTextSharp.text.pdf;
|
||||
|
||||
namespace iTextSharp.text
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for SimpleCell.
|
||||
/// </summary>
|
||||
public class SimpleCell : Rectangle, IPdfPCellEvent, ITextElementArray {
|
||||
|
||||
/** the CellAttributes object represents a row. */
|
||||
public new const bool ROW = true;
|
||||
/** the CellAttributes object represents a cell. */
|
||||
public new const bool CELL = false;
|
||||
/** the content of the Cell. */
|
||||
private ArrayList content = new ArrayList();
|
||||
/** the width of the Cell. */
|
||||
private float width = 0f;
|
||||
/** the widthpercentage of the Cell. */
|
||||
private float widthpercentage = 0f;
|
||||
/** an extra spacing variable */
|
||||
private float spacing_left = float.NaN;
|
||||
/** an extra spacing variable */
|
||||
private float spacing_right = float.NaN;
|
||||
/** an extra spacing variable */
|
||||
private float spacing_top = float.NaN;
|
||||
/** an extra spacing variable */
|
||||
private float spacing_bottom = float.NaN;
|
||||
/** an extra padding variable */
|
||||
private float padding_left = float.NaN;
|
||||
/** an extra padding variable */
|
||||
private float padding_right = float.NaN;
|
||||
/** an extra padding variable */
|
||||
private float padding_top = float.NaN;
|
||||
/** an extra padding variable */
|
||||
private float padding_bottom = float.NaN;
|
||||
/** the colspan of a Cell */
|
||||
private int colspan = 1;
|
||||
/** horizontal alignment inside the Cell. */
|
||||
private int horizontalAlignment = Element.ALIGN_UNDEFINED;
|
||||
/** vertical alignment inside the Cell. */
|
||||
private int verticalAlignment = Element.ALIGN_UNDEFINED;
|
||||
/** indicates if these are the attributes of a single Cell (false) or a group of Cells (true). */
|
||||
private bool cellgroup = false;
|
||||
/** Indicates that the largest ascender height should be used to determine the
|
||||
* height of the first line. Note that this only has an effect when rendered
|
||||
* to PDF. Setting this to true can help with vertical alignment problems. */
|
||||
protected bool useAscender = false;
|
||||
/** Indicates that the largest descender height should be added to the height of
|
||||
* the last line (so characters like y don't dip into the border). Note that
|
||||
* this only has an effect when rendered to PDF. */
|
||||
protected bool useDescender = false;
|
||||
/**
|
||||
* Adjusts the cell contents to compensate for border widths. Note that
|
||||
* this only has an effect when rendered to PDF.
|
||||
*/
|
||||
protected bool useBorderPadding;
|
||||
|
||||
/**
|
||||
* A CellAttributes object is always constructed without any dimensions.
|
||||
* Dimensions are defined after creation.
|
||||
* @param row only true if the CellAttributes object represents a row.
|
||||
*/
|
||||
public SimpleCell(bool row) : base (0f, 0f, 0f, 0f) {
|
||||
cellgroup = row;
|
||||
Border = BOX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds content to this object.
|
||||
* @param element
|
||||
* @throws BadElementException
|
||||
*/
|
||||
public void AddElement(IElement element) {
|
||||
if (cellgroup) {
|
||||
if (element is SimpleCell) {
|
||||
if (((SimpleCell)element).Cellgroup) {
|
||||
throw new BadElementException("You can't add one row to another row.");
|
||||
}
|
||||
content.Add(element);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
throw new BadElementException("You can only add cells to rows, no objects of type " + element.GetType().ToString());
|
||||
}
|
||||
}
|
||||
if (element.Type == Element.PARAGRAPH
|
||||
|| element.Type == Element.PHRASE
|
||||
|| element.Type == Element.ANCHOR
|
||||
|| element.Type == Element.CHUNK
|
||||
|| element.Type == Element.LIST
|
||||
|| element.Type == Element.MARKED
|
||||
|| element.Type == Element.JPEG
|
||||
|| element.Type == Element.JPEG2000
|
||||
|| element.Type == Element.IMGRAW
|
||||
|| element.Type == Element.IMGTEMPLATE) {
|
||||
content.Add(element);
|
||||
}
|
||||
else {
|
||||
throw new BadElementException("You can't add an element of type " + element.GetType().ToString() + " to a SimpleCell.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Cell with these attributes.
|
||||
* @param rowAttributes
|
||||
* @return a cell based on these attributes.
|
||||
* @throws BadElementException
|
||||
*/
|
||||
public Cell CreateCell(SimpleCell rowAttributes) {
|
||||
Cell cell = new Cell();
|
||||
cell.CloneNonPositionParameters(rowAttributes);
|
||||
cell.SoftCloneNonPositionParameters(this);
|
||||
cell.Colspan = colspan;
|
||||
cell.HorizontalAlignment = horizontalAlignment;
|
||||
cell.VerticalAlignment = verticalAlignment;
|
||||
cell.UseAscender = useAscender;
|
||||
cell.UseBorderPadding = useBorderPadding;
|
||||
cell.UseDescender = useDescender;
|
||||
foreach (IElement element in content) {
|
||||
cell.AddElement(element);
|
||||
}
|
||||
return cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a PdfPCell with these attributes.
|
||||
* @param rowAttributes
|
||||
* @return a PdfPCell based on these attributes.
|
||||
*/
|
||||
public PdfPCell CreatePdfPCell(SimpleCell rowAttributes) {
|
||||
PdfPCell cell = new PdfPCell();
|
||||
cell.Border = NO_BORDER;
|
||||
SimpleCell tmp = new SimpleCell(CELL);
|
||||
tmp.Spacing_left = spacing_left;
|
||||
tmp.Spacing_right = spacing_right;
|
||||
tmp.Spacing_top = spacing_top;
|
||||
tmp.Spacing_bottom = spacing_bottom;
|
||||
tmp.CloneNonPositionParameters(rowAttributes);
|
||||
tmp.SoftCloneNonPositionParameters(this);
|
||||
cell.CellEvent = tmp;
|
||||
cell.HorizontalAlignment = rowAttributes.horizontalAlignment;
|
||||
cell.VerticalAlignment = rowAttributes.verticalAlignment;
|
||||
cell.UseAscender = rowAttributes.useAscender;
|
||||
cell.UseBorderPadding = rowAttributes.useBorderPadding;
|
||||
cell.UseDescender = rowAttributes.useDescender;
|
||||
cell.Colspan = colspan;
|
||||
if (horizontalAlignment != Element.ALIGN_UNDEFINED)
|
||||
cell.HorizontalAlignment = horizontalAlignment;
|
||||
if (verticalAlignment != Element.ALIGN_UNDEFINED)
|
||||
cell.VerticalAlignment = verticalAlignment;
|
||||
if (useAscender)
|
||||
cell.UseAscender = useAscender;
|
||||
if (useBorderPadding)
|
||||
cell.UseBorderPadding = useBorderPadding;
|
||||
if (useDescender)
|
||||
cell.UseDescender = useDescender;
|
||||
float p;
|
||||
float sp_left = spacing_left;
|
||||
if (float.IsNaN(sp_left)) sp_left = 0f;
|
||||
float sp_right = spacing_right;
|
||||
if (float.IsNaN(sp_right)) sp_right = 0f;
|
||||
float sp_top = spacing_top;
|
||||
if (float.IsNaN(sp_top)) sp_top = 0f;
|
||||
float sp_bottom = spacing_bottom;
|
||||
if (float.IsNaN(sp_bottom)) sp_bottom = 0f;
|
||||
p = padding_left;
|
||||
if (float.IsNaN(p)) p = 0f;
|
||||
cell.PaddingLeft = p + sp_left;
|
||||
p = padding_right;
|
||||
if (float.IsNaN(p)) p = 0f;
|
||||
cell.PaddingRight = p + sp_right;
|
||||
p = padding_top;
|
||||
if (float.IsNaN(p)) p = 0f;
|
||||
cell.PaddingTop = p + sp_top;
|
||||
p = padding_bottom;
|
||||
if (float.IsNaN(p)) p = 0f;
|
||||
cell.PaddingBottom = p + sp_bottom;
|
||||
foreach (IElement element in content) {
|
||||
cell.AddElement(element);
|
||||
}
|
||||
return cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param rectangle
|
||||
* @param spacing
|
||||
* @return a rectangle
|
||||
*/
|
||||
public static SimpleCell GetDimensionlessInstance(Rectangle rectangle, float spacing) {
|
||||
SimpleCell cell = new SimpleCell(CELL);
|
||||
cell.CloneNonPositionParameters(rectangle);
|
||||
cell.Spacing = spacing * 2;
|
||||
return cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.lowagie.text.pdf.PdfPCellEvent#cellLayout(com.lowagie.text.pdf.PdfPCell, com.lowagie.text.Rectangle, com.lowagie.text.pdf.PdfContentByte[])
|
||||
*/
|
||||
public void CellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) {
|
||||
float sp_left = spacing_left;
|
||||
if (float.IsNaN(sp_left)) sp_left = 0f;
|
||||
float sp_right = spacing_right;
|
||||
if (float.IsNaN(sp_right)) sp_right = 0f;
|
||||
float sp_top = spacing_top;
|
||||
if (float.IsNaN(sp_top)) sp_top = 0f;
|
||||
float sp_bottom = spacing_bottom;
|
||||
if (float.IsNaN(sp_bottom)) sp_bottom = 0f;
|
||||
Rectangle rect = new Rectangle(position.GetLeft(sp_left), position.GetBottom(sp_bottom), position.GetRight(sp_right), position.GetTop(sp_top));
|
||||
rect.CloneNonPositionParameters(this);
|
||||
canvases[PdfPTable.BACKGROUNDCANVAS].Rectangle(rect);
|
||||
rect.BackgroundColor = null;
|
||||
canvases[PdfPTable.LINECANVAS].Rectangle(rect);
|
||||
}
|
||||
|
||||
/** Sets the padding parameters if they are undefined.
|
||||
* @param padding*/
|
||||
public float Padding {
|
||||
set {
|
||||
if (float.IsNaN(padding_right)) {
|
||||
Padding_right = value;
|
||||
}
|
||||
if (float.IsNaN(padding_left)) {
|
||||
Padding_left = value;
|
||||
}
|
||||
if (float.IsNaN(padding_bottom)) {
|
||||
Padding_bottom = value;
|
||||
}
|
||||
if (float.IsNaN(padding_top)) {
|
||||
Padding_top = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the colspan.
|
||||
*/
|
||||
public int Colspan {
|
||||
get {
|
||||
return colspan;
|
||||
}
|
||||
set {
|
||||
if (value > 0) this.colspan = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param padding_bottom The padding_bottom to set.
|
||||
*/
|
||||
public float Padding_bottom {
|
||||
get {
|
||||
return padding_bottom;
|
||||
}
|
||||
set {
|
||||
padding_bottom = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float Padding_left {
|
||||
get {
|
||||
return padding_left;
|
||||
}
|
||||
set {
|
||||
padding_left = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float Padding_right {
|
||||
get {
|
||||
return padding_right;
|
||||
}
|
||||
set {
|
||||
padding_right = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float Padding_top {
|
||||
get {
|
||||
return padding_top;
|
||||
}
|
||||
set {
|
||||
padding_top = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the spacing.
|
||||
*/
|
||||
public float Spacing {
|
||||
set {
|
||||
this.spacing_left = value;
|
||||
this.spacing_right = value;
|
||||
this.spacing_top = value;
|
||||
this.spacing_bottom = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public float Spacing_top {
|
||||
get {
|
||||
return spacing_top;
|
||||
}
|
||||
set {
|
||||
spacing_top = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float Spacing_bottom {
|
||||
get {
|
||||
return spacing_bottom;
|
||||
}
|
||||
set {
|
||||
spacing_bottom = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float Spacing_left {
|
||||
get {
|
||||
return spacing_left;
|
||||
}
|
||||
set {
|
||||
spacing_left = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float Spacing_right {
|
||||
get {
|
||||
return spacing_right;
|
||||
}
|
||||
set {
|
||||
spacing_right = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the cellgroup.
|
||||
*/
|
||||
public bool Cellgroup {
|
||||
get {
|
||||
return cellgroup;
|
||||
}
|
||||
set {
|
||||
cellgroup = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the horizontal alignment.
|
||||
*/
|
||||
public int HorizontalAlignment {
|
||||
get {
|
||||
return horizontalAlignment;
|
||||
}
|
||||
set {
|
||||
horizontalAlignment = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int VerticalAlignment {
|
||||
get {
|
||||
return verticalAlignment;
|
||||
}
|
||||
set {
|
||||
verticalAlignment = value;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @return Returns the width.
|
||||
*/
|
||||
public new float Width {
|
||||
get {
|
||||
return width;
|
||||
}
|
||||
set {
|
||||
width = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the widthpercentage.
|
||||
*/
|
||||
public float Widthpercentage {
|
||||
get {
|
||||
return widthpercentage;
|
||||
}
|
||||
set {
|
||||
widthpercentage = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the useAscender.
|
||||
*/
|
||||
public bool UseAscender {
|
||||
get {
|
||||
return useAscender;
|
||||
}
|
||||
set {
|
||||
useAscender = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool UseDescender {
|
||||
get {
|
||||
return useDescender;
|
||||
}
|
||||
set {
|
||||
useDescender = value;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @return Returns the useBorderPadding.
|
||||
*/
|
||||
public bool UseBorderPadding {
|
||||
get {
|
||||
return useBorderPadding;
|
||||
}
|
||||
set {
|
||||
useBorderPadding = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the content.
|
||||
*/
|
||||
internal ArrayList Content {
|
||||
get {
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.lowagie.text.TextElementArray#add(java.lang.Object)
|
||||
*/
|
||||
public bool Add(Object o) {
|
||||
try {
|
||||
AddElement((IElement)o);
|
||||
return true;
|
||||
}
|
||||
catch (InvalidCastException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override int Type {
|
||||
get {
|
||||
return Element.CELL;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
302
iTechSharp/iTextSharp/text/SimpleTable.cs
Normal file
302
iTechSharp/iTextSharp/text/SimpleTable.cs
Normal file
@@ -0,0 +1,302 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using iTextSharp.text.pdf;
|
||||
|
||||
namespace iTextSharp.text
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for SimpleTable.
|
||||
/// </summary>
|
||||
public class SimpleTable : Rectangle, IPdfPTableEvent, ITextElementArray {
|
||||
|
||||
/** the content of a Table. */
|
||||
private ArrayList content = new ArrayList();
|
||||
/** the width of the Table. */
|
||||
private float width = 0f;
|
||||
/** the widthpercentage of the Table. */
|
||||
private float widthpercentage = 0f;
|
||||
/** the spacing of the Cells. */
|
||||
private float cellspacing;
|
||||
/** the padding of the Cells. */
|
||||
private float cellpadding;
|
||||
/** the alignment of the table. */
|
||||
private int alignment;
|
||||
|
||||
/**
|
||||
* A RectangleCell is always constructed without any dimensions.
|
||||
* Dimensions are defined after creation.
|
||||
*/
|
||||
public SimpleTable() : base(0f, 0f, 0f, 0f) {
|
||||
Border = BOX;
|
||||
BorderWidth = 2f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds content to this object.
|
||||
* @param element
|
||||
* @throws BadElementException
|
||||
*/
|
||||
public void AddElement(SimpleCell element) {
|
||||
if (!element.Cellgroup) {
|
||||
throw new BadElementException("You can't add cells to a table directly, add them to a row first.");
|
||||
}
|
||||
content.Add(element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Table object based on this TableAttributes object.
|
||||
* @return a com.lowagie.text.Table object
|
||||
* @throws BadElementException
|
||||
*/
|
||||
public Table CreateTable() {
|
||||
if (content.Count == 0) throw new BadElementException("Trying to create a table without rows.");
|
||||
SimpleCell rowx = (SimpleCell)content[0];
|
||||
int columns = 0;
|
||||
foreach (SimpleCell cell in rowx.Content) {
|
||||
columns += cell.Colspan;
|
||||
}
|
||||
float[] widths = new float[columns];
|
||||
float[] widthpercentages = new float[columns];
|
||||
Table table = new Table(columns);
|
||||
table.Alignment = alignment;
|
||||
table.Spacing = cellspacing;
|
||||
table.Padding = cellpadding;
|
||||
table.CloneNonPositionParameters(this);
|
||||
int pos;
|
||||
foreach (SimpleCell row in content) {
|
||||
pos = 0;
|
||||
foreach (SimpleCell cell in row.Content) {
|
||||
table.AddCell(cell.CreateCell(row));
|
||||
if (cell.Colspan == 1) {
|
||||
if (cell.Width > 0) widths[pos] = cell.Width;
|
||||
if (cell.Widthpercentage > 0) widthpercentages[pos] = cell.Widthpercentage;
|
||||
}
|
||||
pos += cell.Colspan;
|
||||
}
|
||||
}
|
||||
float sumWidths = 0f;
|
||||
for (int i = 0; i < columns; i++) {
|
||||
if (widths[i] == 0) {
|
||||
sumWidths = 0;
|
||||
break;
|
||||
}
|
||||
sumWidths += widths[i];
|
||||
}
|
||||
if (sumWidths > 0) {
|
||||
table.Width = sumWidths;
|
||||
table.Locked = true;
|
||||
table.Widths = widths;
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < columns; i++) {
|
||||
if (widthpercentages[i] == 0) {
|
||||
sumWidths = 0;
|
||||
break;
|
||||
}
|
||||
sumWidths += widthpercentages[i];
|
||||
}
|
||||
if (sumWidths > 0) {
|
||||
table.Widths = widthpercentages;
|
||||
}
|
||||
}
|
||||
if (width > 0) {
|
||||
table.Width = width;
|
||||
table.Locked = true;
|
||||
}
|
||||
else if (widthpercentage > 0) {
|
||||
table.Width = widthpercentage;
|
||||
}
|
||||
return table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a PdfPTable object based on this TableAttributes object.
|
||||
* @return a com.lowagie.text.pdf.PdfPTable object
|
||||
* @throws DocumentException
|
||||
*/
|
||||
public PdfPTable CreatePdfPTable() {
|
||||
if (content.Count == 0) throw new BadElementException("Trying to create a table without rows.");
|
||||
SimpleCell rowx = (SimpleCell)content[0];
|
||||
int columns = 0;
|
||||
foreach (SimpleCell cell in rowx.Content) {
|
||||
columns += cell.Colspan;
|
||||
}
|
||||
float[] widths = new float[columns];
|
||||
float[] widthpercentages = new float[columns];
|
||||
PdfPTable table = new PdfPTable(columns);
|
||||
table.TableEvent = this;
|
||||
table.HorizontalAlignment = alignment;
|
||||
int pos;
|
||||
foreach (SimpleCell row in content) {
|
||||
pos = 0;
|
||||
foreach (SimpleCell cell in row.Content) {
|
||||
if (float.IsNaN(cell.Spacing_left)) {
|
||||
cell.Spacing_left = cellspacing / 2f;
|
||||
}
|
||||
if (float.IsNaN(cell.Spacing_right)) {
|
||||
cell.Spacing_right = cellspacing / 2f;
|
||||
}
|
||||
if (float.IsNaN(cell.Spacing_top)) {
|
||||
cell.Spacing_top = cellspacing / 2f;
|
||||
}
|
||||
if (float.IsNaN(cell.Spacing_bottom)) {
|
||||
cell.Spacing_bottom = cellspacing / 2f;
|
||||
}
|
||||
cell.Padding = cellpadding;
|
||||
table.AddCell(cell.CreatePdfPCell(row));
|
||||
if (cell.Colspan == 1) {
|
||||
if (cell.Width > 0) widths[pos] = cell.Width;
|
||||
if (cell.Widthpercentage > 0) widthpercentages[pos] = cell.Widthpercentage;
|
||||
}
|
||||
pos += cell.Colspan;
|
||||
}
|
||||
}
|
||||
float sumWidths = 0f;
|
||||
for (int i = 0; i < columns; i++) {
|
||||
if (widths[i] == 0) {
|
||||
sumWidths = 0;
|
||||
break;
|
||||
}
|
||||
sumWidths += widths[i];
|
||||
}
|
||||
if (sumWidths > 0) {
|
||||
table.TotalWidth = sumWidths;
|
||||
table.SetWidths(widths);
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < columns; i++) {
|
||||
if (widthpercentages[i] == 0) {
|
||||
sumWidths = 0;
|
||||
break;
|
||||
}
|
||||
sumWidths += widthpercentages[i];
|
||||
}
|
||||
if (sumWidths > 0) {
|
||||
table.SetWidths(widthpercentages);
|
||||
}
|
||||
}
|
||||
if (width > 0) {
|
||||
table.TotalWidth = width;
|
||||
}
|
||||
if (widthpercentage > 0) {
|
||||
table.WidthPercentage = widthpercentage;
|
||||
}
|
||||
return table;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param rectangle
|
||||
* @param spacing
|
||||
* @return a rectangle
|
||||
*/
|
||||
public static SimpleTable GetDimensionlessInstance(Rectangle rectangle, float spacing) {
|
||||
SimpleTable ev = new SimpleTable();
|
||||
ev.CloneNonPositionParameters(rectangle);
|
||||
ev.Cellspacing = spacing;
|
||||
return ev;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.lowagie.text.pdf.PdfPTableEvent#tableLayout(com.lowagie.text.pdf.PdfPTable, float[][], float[], int, int, com.lowagie.text.pdf.PdfContentByte[])
|
||||
*/
|
||||
public void TableLayout(PdfPTable table, float[][] widths, float[] heights, int headerRows, int rowStart, PdfContentByte[] canvases) {
|
||||
float[] width = widths[0];
|
||||
Rectangle rect = new Rectangle(width[0], heights[heights.Length - 1], width[width.Length - 1], heights[0]);
|
||||
rect.CloneNonPositionParameters(this);
|
||||
int bd = rect.Border;
|
||||
rect.Border = Rectangle.NO_BORDER;
|
||||
canvases[PdfPTable.BACKGROUNDCANVAS].Rectangle(rect);
|
||||
rect.Border = bd;
|
||||
rect.BackgroundColor = null;
|
||||
canvases[PdfPTable.LINECANVAS].Rectangle(rect);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the cellpadding.
|
||||
*/
|
||||
public float Cellpadding {
|
||||
get {
|
||||
return cellpadding;
|
||||
}
|
||||
set {
|
||||
cellpadding = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the cellspacing.
|
||||
*/
|
||||
public float Cellspacing {
|
||||
get {
|
||||
return cellspacing;
|
||||
}
|
||||
set {
|
||||
cellspacing = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the alignment.
|
||||
*/
|
||||
public int Alignment {
|
||||
get {
|
||||
return alignment;
|
||||
}
|
||||
set {
|
||||
alignment = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the width.
|
||||
*/
|
||||
public override float Width {
|
||||
get {
|
||||
return width;
|
||||
}
|
||||
set {
|
||||
width = value;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @return Returns the widthpercentage.
|
||||
*/
|
||||
public float Widthpercentage {
|
||||
get {
|
||||
return widthpercentage;
|
||||
}
|
||||
set {
|
||||
widthpercentage = value;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @see com.lowagie.text.Element#type()
|
||||
*/
|
||||
public override int Type {
|
||||
get {
|
||||
return Element.TABLE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.lowagie.text.Element#isNestable()
|
||||
* @since iText 2.0.8
|
||||
*/
|
||||
public override bool IsNestable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.lowagie.text.TextElementArray#add(java.lang.Object)
|
||||
*/
|
||||
public bool Add(Object o) {
|
||||
try {
|
||||
AddElement((SimpleCell)o);
|
||||
return true;
|
||||
}
|
||||
catch (InvalidCastException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
202
iTechSharp/iTextSharp/text/SpecialSymbol.cs
Normal file
202
iTechSharp/iTextSharp/text/SpecialSymbol.cs
Normal file
@@ -0,0 +1,202 @@
|
||||
using System;
|
||||
|
||||
/*
|
||||
* $Id: SpecialSymbol.cs,v 1.4 2008/05/13 11:25:13 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text
|
||||
{
|
||||
public class SpecialSymbol {
|
||||
|
||||
/**
|
||||
* Returns the first occurrence of a special symbol in a <CODE>String</CODE>.
|
||||
*
|
||||
* @param string a <CODE>String</CODE>
|
||||
* @return an index of -1 if no special symbol was found
|
||||
*/
|
||||
|
||||
public static int Index(string str) {
|
||||
int length = str.Length;
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (GetCorrespondingSymbol(str[i]) != ' ') {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a chunk with a symbol character.
|
||||
* @param c a character that has to be changed into a symbol
|
||||
* @param font Font if there is no SYMBOL character corresponding with c
|
||||
* @return a SYMBOL version of a character
|
||||
*/
|
||||
|
||||
public static Chunk Get(char c, Font font) {
|
||||
char greek = SpecialSymbol.GetCorrespondingSymbol(c);
|
||||
if (greek == ' ') {
|
||||
return new Chunk(c.ToString(), font);
|
||||
}
|
||||
Font symbol = new Font(Font.SYMBOL, font.Size, font.Style, font.Color);
|
||||
return new Chunk(greek.ToString(), symbol);
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks for the corresponding symbol in the font Symbol.
|
||||
*
|
||||
* @param c the original ASCII-char
|
||||
* @return the corresponding symbol in font Symbol
|
||||
*/
|
||||
|
||||
public static char GetCorrespondingSymbol(char c) {
|
||||
switch (c) {
|
||||
case (char)913:
|
||||
return 'A'; // ALFA
|
||||
case (char)914:
|
||||
return 'B'; // BETA
|
||||
case (char)915:
|
||||
return 'G'; // GAMMA
|
||||
case (char)916:
|
||||
return 'D'; // DELTA
|
||||
case (char)917:
|
||||
return 'E'; // EPSILON
|
||||
case (char)918:
|
||||
return 'Z'; // ZETA
|
||||
case (char)919:
|
||||
return 'H'; // ETA
|
||||
case (char)920:
|
||||
return 'Q'; // THETA
|
||||
case (char)921:
|
||||
return 'I'; // IOTA
|
||||
case (char)922:
|
||||
return 'K'; // KAPPA
|
||||
case (char)923:
|
||||
return 'L'; // LAMBDA
|
||||
case (char)924:
|
||||
return 'M'; // MU
|
||||
case (char)925:
|
||||
return 'N'; // NU
|
||||
case (char)926:
|
||||
return 'X'; // XI
|
||||
case (char)927:
|
||||
return 'O'; // OMICRON
|
||||
case (char)928:
|
||||
return 'P'; // PI
|
||||
case (char)929:
|
||||
return 'R'; // RHO
|
||||
case (char)931:
|
||||
return 'S'; // SIGMA
|
||||
case (char)932:
|
||||
return 'T'; // TAU
|
||||
case (char)933:
|
||||
return 'U'; // UPSILON
|
||||
case (char)934:
|
||||
return 'J'; // PHI
|
||||
case (char)935:
|
||||
return 'C'; // CHI
|
||||
case (char)936:
|
||||
return 'Y'; // PSI
|
||||
case (char)937:
|
||||
return 'W'; // OMEGA
|
||||
case (char)945:
|
||||
return 'a'; // alfa
|
||||
case (char)946:
|
||||
return 'b'; // beta
|
||||
case (char)947:
|
||||
return 'g'; // gamma
|
||||
case (char)948:
|
||||
return 'd'; // delta
|
||||
case (char)949:
|
||||
return 'e'; // epsilon
|
||||
case (char)950:
|
||||
return 'z'; // zeta
|
||||
case (char)951:
|
||||
return 'h'; // eta
|
||||
case (char)952:
|
||||
return 'q'; // theta
|
||||
case (char)953:
|
||||
return 'i'; // iota
|
||||
case (char)954:
|
||||
return 'k'; // kappa
|
||||
case (char)955:
|
||||
return 'l'; // lambda
|
||||
case (char)956:
|
||||
return 'm'; // mu
|
||||
case (char)957:
|
||||
return 'n'; // nu
|
||||
case (char)958:
|
||||
return 'x'; // xi
|
||||
case (char)959:
|
||||
return 'o'; // omicron
|
||||
case (char)960:
|
||||
return 'p'; // pi
|
||||
case (char)961:
|
||||
return 'r'; // rho
|
||||
case (char)962:
|
||||
return 'V'; // sigma
|
||||
case (char)963:
|
||||
return 's'; // sigma
|
||||
case (char)964:
|
||||
return 't'; // tau
|
||||
case (char)965:
|
||||
return 'u'; // upsilon
|
||||
case (char)966:
|
||||
return 'j'; // phi
|
||||
case (char)967:
|
||||
return 'c'; // chi
|
||||
case (char)968:
|
||||
return 'y'; // psi
|
||||
case (char)969:
|
||||
return 'w'; // omega
|
||||
default:
|
||||
return ' ';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1577
iTechSharp/iTextSharp/text/Table.cs
Normal file
1577
iTechSharp/iTextSharp/text/Table.cs
Normal file
File diff suppressed because it is too large
Load Diff
267
iTechSharp/iTextSharp/text/Utilities.cs
Normal file
267
iTechSharp/iTextSharp/text/Utilities.cs
Normal file
@@ -0,0 +1,267 @@
|
||||
using System;
|
||||
using System.util;
|
||||
using System.Collections;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using iTextSharp.text.pdf;
|
||||
/*
|
||||
* $Id: Utilities.cs,v 1.9 2008/05/13 11:25:13 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
namespace iTextSharp.text {
|
||||
|
||||
/**
|
||||
* A collection of convenience methods that were present in many different iText
|
||||
* classes.
|
||||
*/
|
||||
|
||||
public class Utilities {
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="table"></param>
|
||||
/// <returns></returns>
|
||||
public static ICollection GetKeySet(Properties table) {
|
||||
return (table == null) ? new Properties().Keys : table.Keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method to extend an array.
|
||||
* @param original the original array or <CODE>null</CODE>
|
||||
* @param item the item to be added to the array
|
||||
* @return a new array with the item appended
|
||||
*/
|
||||
public static Object[][] AddToArray(Object[][] original, Object[] item) {
|
||||
if (original == null) {
|
||||
original = new Object[1][];
|
||||
original[0] = item;
|
||||
return original;
|
||||
}
|
||||
else {
|
||||
Object[][] original2 = new Object[original.Length + 1][];
|
||||
Array.Copy(original, 0, original2, 0, original.Length);
|
||||
original2[original.Length] = item;
|
||||
return original2;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for a true/false value of a key in a Properties object.
|
||||
* @param attributes
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public static bool CheckTrueOrFalse(Properties attributes, String key) {
|
||||
return Util.EqualsIgnoreCase("true", attributes[key]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method makes a valid URL from a given filename.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
/// <param name="filename">a given filename</param>
|
||||
/// <returns>a valid URL</returns>
|
||||
public static Uri ToURL(string filename) {
|
||||
try {
|
||||
return new Uri(filename);
|
||||
}
|
||||
catch {
|
||||
return new Uri("file:///" + filename);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unescapes an URL. All the "%xx" are replaced by the 'xx' hex char value.
|
||||
* @param src the url to unescape
|
||||
* @return the eunescaped value
|
||||
*/
|
||||
public static String UnEscapeURL(String src) {
|
||||
StringBuilder bf = new StringBuilder();
|
||||
char[] s = src.ToCharArray();
|
||||
for (int k = 0; k < s.Length; ++k) {
|
||||
char c = s[k];
|
||||
if (c == '%') {
|
||||
if (k + 2 >= s.Length) {
|
||||
bf.Append(c);
|
||||
continue;
|
||||
}
|
||||
int a0 = PRTokeniser.GetHex((int)s[k + 1]);
|
||||
int a1 = PRTokeniser.GetHex((int)s[k + 2]);
|
||||
if (a0 < 0 || a1 < 0) {
|
||||
bf.Append(c);
|
||||
continue;
|
||||
}
|
||||
bf.Append((char)(a0 * 16 + a1));
|
||||
k += 2;
|
||||
}
|
||||
else
|
||||
bf.Append(c);
|
||||
}
|
||||
return bf.ToString();
|
||||
}
|
||||
|
||||
private static byte[] skipBuffer = new byte[4096];
|
||||
|
||||
/// <summary>
|
||||
/// This method is an alternative for the Stream.Skip()-method
|
||||
/// that doesn't seem to work properly for big values of size.
|
||||
/// </summary>
|
||||
/// <param name="istr">the stream</param>
|
||||
/// <param name="size">the number of bytes to skip</param>
|
||||
public static void Skip(Stream istr, int size) {
|
||||
while (size > 0) {
|
||||
int r = istr.Read(skipBuffer, 0, Math.Min(skipBuffer.Length, size));
|
||||
if (r <= 0)
|
||||
return;
|
||||
size -= r;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Measurement conversion from millimeters to points.
|
||||
* @param value a value in millimeters
|
||||
* @return a value in points
|
||||
* @since 2.1.2
|
||||
*/
|
||||
public static float MillimetersToPoints(float value) {
|
||||
return InchesToPoints(MillimetersToInches(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Measurement conversion from millimeters to inches.
|
||||
* @param value a value in millimeters
|
||||
* @return a value in inches
|
||||
* @since 2.1.2
|
||||
*/
|
||||
public static float MillimetersToInches(float value) {
|
||||
return value / 25.4f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Measurement conversion from points to millimeters.
|
||||
* @param value a value in points
|
||||
* @return a value in millimeters
|
||||
* @since 2.1.2
|
||||
*/
|
||||
public static float PointsToMillimeters(float value) {
|
||||
return InchesToMillimeters(PointsToInches(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Measurement conversion from points to inches.
|
||||
* @param value a value in points
|
||||
* @return a value in inches
|
||||
* @since 2.1.2
|
||||
*/
|
||||
public static float PointsToInches(float value) {
|
||||
return value / 72f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Measurement conversion from inches to millimeters.
|
||||
* @param value a value in inches
|
||||
* @return a value in millimeters
|
||||
* @since 2.1.2
|
||||
*/
|
||||
public static float InchesToMillimeters(float value) {
|
||||
return value * 25.4f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Measurement conversion from inches to points.
|
||||
* @param value a value in inches
|
||||
* @return a value in points
|
||||
* @since 2.1.2
|
||||
*/
|
||||
public static float InchesToPoints(float value) {
|
||||
return value * 72f;
|
||||
}
|
||||
|
||||
public static bool IsSurrogateHigh(char c) {
|
||||
return c >= '\ud800' && c <= '\udbff';
|
||||
}
|
||||
|
||||
public static bool IsSurrogateLow(char c) {
|
||||
return c >= '\udc00' && c <= '\udfff';
|
||||
}
|
||||
|
||||
public static bool IsSurrogatePair(string text, int idx) {
|
||||
if (idx < 0 || idx > text.Length - 2)
|
||||
return false;
|
||||
return IsSurrogateHigh(text[idx]) && IsSurrogateLow(text[idx + 1]);
|
||||
}
|
||||
|
||||
public static bool IsSurrogatePair(char[] text, int idx) {
|
||||
if (idx < 0 || idx > text.Length - 2)
|
||||
return false;
|
||||
return IsSurrogateHigh(text[idx]) && IsSurrogateLow(text[idx + 1]);
|
||||
}
|
||||
|
||||
public static int ConvertToUtf32(char highSurrogate, char lowSurrogate) {
|
||||
return (((highSurrogate - 0xd800) * 0x400) + (lowSurrogate - 0xdc00)) + 0x10000;
|
||||
}
|
||||
|
||||
public static int ConvertToUtf32(char[] text, int idx) {
|
||||
return (((text[idx] - 0xd800) * 0x400) + (text[idx + 1] - 0xdc00)) + 0x10000;
|
||||
}
|
||||
|
||||
public static int ConvertToUtf32(string text, int idx) {
|
||||
return (((text[idx] - 0xd800) * 0x400) + (text[idx + 1] - 0xdc00)) + 0x10000;
|
||||
}
|
||||
|
||||
public static string ConvertFromUtf32(int codePoint) {
|
||||
if (codePoint < 0x10000)
|
||||
return Char.ToString((char)codePoint);
|
||||
codePoint -= 0x10000;
|
||||
return new string(new char[]{(char)((codePoint / 0x400) + 0xd800), (char)((codePoint % 0x400) + 0xdc00)});
|
||||
}
|
||||
}
|
||||
}
|
||||
85
iTechSharp/iTextSharp/text/ZapfDingbatsList.cs
Normal file
85
iTechSharp/iTextSharp/text/ZapfDingbatsList.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
using System;
|
||||
|
||||
namespace iTextSharp.text
|
||||
{
|
||||
/**
|
||||
*
|
||||
* A special-version of <CODE>LIST</CODE> whitch use zapfdingbats-letters.
|
||||
*
|
||||
* @see com.lowagie.text.List
|
||||
* @author Michael Niedermair and Bruno Lowagie
|
||||
*/
|
||||
public class ZapfDingbatsList : List {
|
||||
/**
|
||||
* char-number in zapfdingbats
|
||||
*/
|
||||
protected int zn;
|
||||
|
||||
/**
|
||||
* Creates a ZapfDingbatsList
|
||||
*
|
||||
* @param zn a char-number
|
||||
*/
|
||||
public ZapfDingbatsList(int zn) : base(true) {
|
||||
this.zn = zn;
|
||||
float fontsize = symbol.Font.Size;
|
||||
symbol.Font = FontFactory.GetFont(FontFactory.ZAPFDINGBATS, fontsize, Font.NORMAL);
|
||||
postSymbol = " ";
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a ZapfDingbatsList
|
||||
*
|
||||
* @param zn a char-number
|
||||
* @param symbolIndent indent
|
||||
*/
|
||||
public ZapfDingbatsList(int zn, int symbolIndent) : base(true, symbolIndent) {
|
||||
this.zn = zn;
|
||||
float fontsize = symbol.Font.Size;
|
||||
symbol.Font = FontFactory.GetFont(FontFactory.ZAPFDINGBATS, fontsize, Font.NORMAL);
|
||||
postSymbol = " ";
|
||||
}
|
||||
|
||||
/**
|
||||
* set the char-number
|
||||
* @param zn a char-number
|
||||
*/
|
||||
public int CharNumber {
|
||||
set {
|
||||
this.zn = value;
|
||||
}
|
||||
get {
|
||||
return this.zn;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an <CODE>Object</CODE> to the <CODE>List</CODE>.
|
||||
*
|
||||
* @param o the object to add.
|
||||
* @return true if adding the object succeeded
|
||||
*/
|
||||
public override bool Add(Object o) {
|
||||
if (o is ListItem) {
|
||||
ListItem item = (ListItem) o;
|
||||
Chunk chunk = new Chunk(preSymbol, symbol.Font);
|
||||
chunk.Append(((char)zn).ToString());
|
||||
chunk.Append(postSymbol);
|
||||
item.ListSymbol = chunk;
|
||||
item.SetIndentationLeft(symbolIndent, autoindent);
|
||||
item.IndentationRight = 0;
|
||||
list.Add(item);
|
||||
return true;
|
||||
} else if (o is List) {
|
||||
List nested = (List) o;
|
||||
nested.IndentationLeft = nested.IndentationLeft + symbolIndent;
|
||||
first--;
|
||||
list.Add(nested);
|
||||
return true;
|
||||
} else if (o is String) {
|
||||
return this.Add(new ListItem((string) o));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
100
iTechSharp/iTextSharp/text/ZapfDingbatsNumberList.cs
Normal file
100
iTechSharp/iTextSharp/text/ZapfDingbatsNumberList.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
using System;
|
||||
|
||||
namespace iTextSharp.text
|
||||
{
|
||||
/**
|
||||
*
|
||||
* A special-version of <CODE>LIST</CODE> whitch use zapfdingbats-numbers (1..10).
|
||||
*
|
||||
* @see com.lowagie.text.List
|
||||
* @version 2003-06-22
|
||||
* @author Michael Niedermair
|
||||
*/
|
||||
public class ZapfDingbatsNumberList : List {
|
||||
|
||||
/**
|
||||
* which type
|
||||
*/
|
||||
protected int type;
|
||||
|
||||
/**
|
||||
* Creates a ZapdDingbatsNumberList
|
||||
* @param type the type of list
|
||||
* @param symbolIndent indent
|
||||
*/
|
||||
public ZapfDingbatsNumberList(int type) : base(true) {
|
||||
this.type = type;
|
||||
float fontsize = symbol.Font.Size;
|
||||
symbol.Font = FontFactory.GetFont(FontFactory.ZAPFDINGBATS, fontsize, Font.NORMAL);
|
||||
postSymbol = " ";
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a ZapdDingbatsNumberList
|
||||
* @param type the type of list
|
||||
* @param symbolIndent indent
|
||||
*/
|
||||
public ZapfDingbatsNumberList(int type, int symbolIndent) : base(true, symbolIndent) {
|
||||
this.type = type;
|
||||
float fontsize = symbol.Font.Size;
|
||||
symbol.Font = FontFactory.GetFont(FontFactory.ZAPFDINGBATS, fontsize, Font.NORMAL);
|
||||
postSymbol = " ";
|
||||
}
|
||||
|
||||
/**
|
||||
* get the type
|
||||
*
|
||||
* @return char-number
|
||||
*/
|
||||
public int NumberType {
|
||||
get {
|
||||
return type;
|
||||
}
|
||||
set {
|
||||
type = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an <CODE>Object</CODE> to the <CODE>List</CODE>.
|
||||
*
|
||||
* @param o the object to add.
|
||||
* @return true if adding the object succeeded
|
||||
*/
|
||||
public override bool Add(Object o) {
|
||||
if (o is ListItem) {
|
||||
ListItem item = (ListItem) o;
|
||||
Chunk chunk = new Chunk(preSymbol, symbol.Font);
|
||||
switch (type ) {
|
||||
case 0:
|
||||
chunk.Append(((char)(first + list.Count + 171)).ToString());
|
||||
break;
|
||||
case 1:
|
||||
chunk.Append(((char)(first + list.Count + 181)).ToString());
|
||||
break;
|
||||
case 2:
|
||||
chunk.Append(((char)(first + list.Count + 191)).ToString());
|
||||
break;
|
||||
default:
|
||||
chunk.Append(((char)(first + list.Count + 201)).ToString());
|
||||
break;
|
||||
}
|
||||
chunk.Append(postSymbol);
|
||||
item.ListSymbol = chunk;
|
||||
item.SetIndentationLeft(symbolIndent, autoindent);
|
||||
item.IndentationRight = 0;
|
||||
list.Add(item);
|
||||
return true;
|
||||
} else if (o is List) {
|
||||
List nested = (List) o;
|
||||
nested.IndentationLeft = nested.IndentationLeft + symbolIndent;
|
||||
first--;
|
||||
list.Add(nested);
|
||||
return true;
|
||||
} else if (o is String) {
|
||||
return this.Add(new ListItem((string) o));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
533
iTechSharp/iTextSharp/text/factories/ElementFactory.cs
Normal file
533
iTechSharp/iTextSharp/text/factories/ElementFactory.cs
Normal file
@@ -0,0 +1,533 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.util;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.html;
|
||||
using iTextSharp.text.factories;
|
||||
/*
|
||||
* $Id: ElementFactory.cs,v 1.9 2008/05/13 11:25:14 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2007 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
namespace iTextSharp.text.factories {
|
||||
|
||||
/**
|
||||
* This class is able to create Element objects based on a list of properties.
|
||||
*/
|
||||
|
||||
public class ElementFactory {
|
||||
|
||||
public static Chunk GetChunk(Properties attributes) {
|
||||
Chunk chunk = new Chunk();
|
||||
|
||||
chunk.Font = FontFactory.GetFont(attributes);
|
||||
String value;
|
||||
|
||||
value = attributes[ElementTags.ITEXT];
|
||||
if (value != null) {
|
||||
chunk.Append(value);
|
||||
}
|
||||
value = attributes[ElementTags.LOCALGOTO];
|
||||
if (value != null) {
|
||||
chunk.SetLocalGoto(value);
|
||||
}
|
||||
value = attributes[ElementTags.REMOTEGOTO];
|
||||
if (value != null) {
|
||||
String page = attributes[ElementTags.PAGE];
|
||||
if (page != null) {
|
||||
chunk.SetRemoteGoto(value, int.Parse(page));
|
||||
}
|
||||
else {
|
||||
String destination = attributes[ElementTags.DESTINATION];
|
||||
if (destination != null) {
|
||||
chunk.SetRemoteGoto(value, destination);
|
||||
}
|
||||
}
|
||||
}
|
||||
value = attributes[ElementTags.LOCALDESTINATION];
|
||||
if (value != null) {
|
||||
chunk.SetLocalDestination(value);
|
||||
}
|
||||
value = attributes[ElementTags.SUBSUPSCRIPT];
|
||||
if (value != null) {
|
||||
chunk.SetTextRise(float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo));
|
||||
}
|
||||
value = attributes[Markup.CSS_KEY_VERTICALALIGN];
|
||||
if (value != null && value.EndsWith("%")) {
|
||||
float p = float.Parse(value.Substring(0, value.Length - 1), System.Globalization.NumberFormatInfo.InvariantInfo) / 100f;
|
||||
chunk.SetTextRise(p * chunk.Font.Size);
|
||||
}
|
||||
value = attributes[ElementTags.GENERICTAG];
|
||||
if (value != null) {
|
||||
chunk.SetGenericTag(value);
|
||||
}
|
||||
value = attributes[ElementTags.BACKGROUNDCOLOR];
|
||||
if (value != null) {
|
||||
chunk.SetBackground(Markup.DecodeColor(value));
|
||||
}
|
||||
return chunk;
|
||||
}
|
||||
|
||||
public static Phrase GetPhrase(Properties attributes) {
|
||||
Phrase phrase = new Phrase();
|
||||
phrase.Font = FontFactory.GetFont(attributes);
|
||||
String value;
|
||||
value = attributes[ElementTags.LEADING];
|
||||
if (value != null) {
|
||||
phrase.Leading = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
}
|
||||
value = attributes[Markup.CSS_KEY_LINEHEIGHT];
|
||||
if (value != null) {
|
||||
phrase.Leading = Markup.ParseLength(value);
|
||||
}
|
||||
value = attributes[ElementTags.ITEXT];
|
||||
if (value != null) {
|
||||
Chunk chunk = new Chunk(value);
|
||||
if ((value = attributes[ElementTags.GENERICTAG]) != null) {
|
||||
chunk.SetGenericTag(value);
|
||||
}
|
||||
phrase.Add(chunk);
|
||||
}
|
||||
return phrase;
|
||||
}
|
||||
|
||||
public static Anchor GetAnchor(Properties attributes) {
|
||||
Anchor anchor = new Anchor(GetPhrase(attributes));
|
||||
String value;
|
||||
value = attributes[ElementTags.NAME];
|
||||
if (value != null) {
|
||||
anchor.Name = value;
|
||||
}
|
||||
value = (String)attributes.Remove(ElementTags.REFERENCE);
|
||||
if (value != null) {
|
||||
anchor.Reference = value;
|
||||
}
|
||||
return anchor;
|
||||
}
|
||||
|
||||
public static Paragraph GetParagraph(Properties attributes) {
|
||||
Paragraph paragraph = new Paragraph(GetPhrase(attributes));
|
||||
String value;
|
||||
value = attributes[ElementTags.ALIGN];
|
||||
if (value != null) {
|
||||
paragraph.SetAlignment(value);
|
||||
}
|
||||
value = attributes[ElementTags.INDENTATIONLEFT];
|
||||
if (value != null) {
|
||||
paragraph.IndentationLeft = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
}
|
||||
value = attributes[ElementTags.INDENTATIONRIGHT];
|
||||
if (value != null) {
|
||||
paragraph.IndentationRight = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
}
|
||||
return paragraph;
|
||||
}
|
||||
|
||||
public static ListItem GetListItem(Properties attributes) {
|
||||
ListItem item = new ListItem(GetParagraph(attributes));
|
||||
return item;
|
||||
}
|
||||
|
||||
public static List GetList(Properties attributes) {
|
||||
List list = new List();
|
||||
|
||||
list.Numbered = Utilities.CheckTrueOrFalse(attributes, ElementTags.NUMBERED);
|
||||
list.Lettered = Utilities.CheckTrueOrFalse(attributes, ElementTags.LETTERED);
|
||||
list.Lowercase = Utilities.CheckTrueOrFalse(attributes, ElementTags.LOWERCASE);
|
||||
list.Autoindent = Utilities.CheckTrueOrFalse(attributes, ElementTags.AUTO_INDENT_ITEMS);
|
||||
list.Alignindent = Utilities.CheckTrueOrFalse(attributes, ElementTags.ALIGN_INDENTATION_ITEMS);
|
||||
|
||||
String value;
|
||||
|
||||
value = attributes[ElementTags.FIRST];
|
||||
if (value != null) {
|
||||
char character = value[0];
|
||||
if (char.IsLetter(character) ) {
|
||||
list.First = (int)character;
|
||||
}
|
||||
else {
|
||||
list.First = int.Parse(value);
|
||||
}
|
||||
}
|
||||
|
||||
value = attributes[ElementTags.LISTSYMBOL];
|
||||
if (value != null) {
|
||||
list.ListSymbol = new Chunk(value, FontFactory.GetFont(attributes));
|
||||
}
|
||||
|
||||
value = attributes[ElementTags.INDENTATIONLEFT];
|
||||
if (value != null) {
|
||||
list.IndentationLeft = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
}
|
||||
|
||||
value = attributes[ElementTags.INDENTATIONRIGHT];
|
||||
if (value != null) {
|
||||
list.IndentationRight = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
}
|
||||
|
||||
value = attributes[ElementTags.SYMBOLINDENT];
|
||||
if (value != null) {
|
||||
list.SymbolIndent = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public static Cell GetCell(Properties attributes) {
|
||||
Cell cell = new Cell();
|
||||
String value;
|
||||
|
||||
cell.SetHorizontalAlignment(attributes[ElementTags.HORIZONTALALIGN]);
|
||||
cell.SetVerticalAlignment(attributes[ElementTags.VERTICALALIGN]);
|
||||
value = attributes[ElementTags.WIDTH];
|
||||
if (value != null) {
|
||||
cell.SetWidth(value);
|
||||
}
|
||||
value = attributes[ElementTags.COLSPAN];
|
||||
if (value != null) {
|
||||
cell.Colspan = int.Parse(value);
|
||||
}
|
||||
value = attributes[ElementTags.ROWSPAN];
|
||||
if (value != null) {
|
||||
cell.Rowspan = int.Parse(value);
|
||||
}
|
||||
value = attributes[ElementTags.LEADING];
|
||||
if (value != null) {
|
||||
cell.Leading = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
}
|
||||
cell.Header = Utilities.CheckTrueOrFalse(attributes, ElementTags.HEADER);
|
||||
if (Utilities.CheckTrueOrFalse(attributes, ElementTags.NOWRAP)) {
|
||||
cell.MaxLines = 1;
|
||||
}
|
||||
SetRectangleProperties(cell, attributes);
|
||||
return cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an Table object based on a list of properties.
|
||||
* @param attributes
|
||||
* @return a Table
|
||||
*/
|
||||
public static Table GetTable(Properties attributes) {
|
||||
String value;
|
||||
Table table;
|
||||
|
||||
value = attributes[ElementTags.WIDTHS];
|
||||
if (value != null) {
|
||||
StringTokenizer widthTokens = new StringTokenizer(value, ";");
|
||||
ArrayList values = new ArrayList();
|
||||
while (widthTokens.HasMoreTokens()) {
|
||||
values.Add(widthTokens.NextToken());
|
||||
}
|
||||
table = new Table(values.Count);
|
||||
float[] widths = new float[table.Columns];
|
||||
for (int i = 0; i < values.Count; i++) {
|
||||
value = (String)values[i];
|
||||
widths[i] = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
}
|
||||
table.Widths = widths;
|
||||
}
|
||||
else {
|
||||
value = attributes[ElementTags.COLUMNS];
|
||||
try {
|
||||
table = new Table(int.Parse(value));
|
||||
}
|
||||
catch {
|
||||
table = new Table(1);
|
||||
}
|
||||
}
|
||||
|
||||
table.Border = Table.BOX;
|
||||
table.BorderWidth = 1;
|
||||
table.DefaultCell.Border = Table.BOX;
|
||||
|
||||
value = attributes[ElementTags.LASTHEADERROW];
|
||||
if (value != null) {
|
||||
table.LastHeaderRow = int.Parse(value);
|
||||
}
|
||||
value = attributes[ElementTags.ALIGN];
|
||||
if (value != null) {
|
||||
table.SetAlignment(value);
|
||||
}
|
||||
value = attributes[ElementTags.CELLSPACING];
|
||||
if (value != null) {
|
||||
table.Spacing = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
}
|
||||
value = attributes[ElementTags.CELLPADDING];
|
||||
if (value != null) {
|
||||
table.Padding = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
}
|
||||
value = attributes[ElementTags.OFFSET];
|
||||
if (value != null) {
|
||||
table.Offset = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
}
|
||||
value = attributes[ElementTags.WIDTH];
|
||||
if (value != null) {
|
||||
if (value.EndsWith("%"))
|
||||
table.Width = float.Parse(value.Substring(0, value.Length - 1), System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
else {
|
||||
table.Width = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
table.Locked = true;
|
||||
}
|
||||
}
|
||||
table.TableFitsPage = Utilities.CheckTrueOrFalse(attributes, ElementTags.TABLEFITSPAGE);
|
||||
table.CellsFitPage = Utilities.CheckTrueOrFalse(attributes, ElementTags.CELLSFITPAGE);
|
||||
table.Convert2pdfptable = Utilities.CheckTrueOrFalse(attributes, ElementTags.CONVERT2PDFP);
|
||||
|
||||
SetRectangleProperties(table, attributes);
|
||||
return table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets some Rectangle properties (for a Cell, Table,...).
|
||||
*/
|
||||
private static void SetRectangleProperties(Rectangle rect, Properties attributes) {
|
||||
String value;
|
||||
value = attributes[ElementTags.BORDERWIDTH];
|
||||
if (value != null) {
|
||||
rect.BorderWidth = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
}
|
||||
int border = 0;
|
||||
if (Utilities.CheckTrueOrFalse(attributes, ElementTags.LEFT)) {
|
||||
border |= Rectangle.LEFT_BORDER;
|
||||
}
|
||||
if (Utilities.CheckTrueOrFalse(attributes, ElementTags.RIGHT)) {
|
||||
border |= Rectangle.RIGHT_BORDER;
|
||||
}
|
||||
if (Utilities.CheckTrueOrFalse(attributes, ElementTags.TOP)) {
|
||||
border |= Rectangle.TOP_BORDER;
|
||||
}
|
||||
if (Utilities.CheckTrueOrFalse(attributes, ElementTags.BOTTOM)) {
|
||||
border |= Rectangle.BOTTOM_BORDER;
|
||||
}
|
||||
rect.Border = border;
|
||||
|
||||
String r = attributes[ElementTags.RED];
|
||||
String g = attributes[ElementTags.GREEN];
|
||||
String b = attributes[ElementTags.BLUE];
|
||||
if (r != null || g != null || b != null) {
|
||||
int red = 0;
|
||||
int green = 0;
|
||||
int blue = 0;
|
||||
if (r != null) red = int.Parse(r);
|
||||
if (g != null) green = int.Parse(g);
|
||||
if (b != null) blue = int.Parse(b);
|
||||
rect.BorderColor = new Color(red, green, blue);
|
||||
}
|
||||
else {
|
||||
rect.BorderColor = Markup.DecodeColor(attributes[ElementTags.BORDERCOLOR]);
|
||||
}
|
||||
r = (String)attributes.Remove(ElementTags.BGRED);
|
||||
g = (String)attributes.Remove(ElementTags.BGGREEN);
|
||||
b = (String)attributes.Remove(ElementTags.BGBLUE);
|
||||
value = attributes[ElementTags.BACKGROUNDCOLOR];
|
||||
if (r != null || g != null || b != null) {
|
||||
int red = 0;
|
||||
int green = 0;
|
||||
int blue = 0;
|
||||
if (r != null) red = int.Parse(r);
|
||||
if (g != null) green = int.Parse(g);
|
||||
if (b != null) blue = int.Parse(b);
|
||||
rect.BackgroundColor = new Color(red, green, blue);
|
||||
}
|
||||
else if (value != null) {
|
||||
rect.BackgroundColor = Markup.DecodeColor(value);
|
||||
}
|
||||
else {
|
||||
value = attributes[ElementTags.GRAYFILL];
|
||||
if (value != null) {
|
||||
rect.GrayFill = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ChapterAutoNumber GetChapter(Properties attributes) {
|
||||
ChapterAutoNumber chapter = new ChapterAutoNumber("");
|
||||
SetSectionParameters(chapter, attributes);
|
||||
return chapter;
|
||||
}
|
||||
|
||||
public static Section GetSection(Section parent, Properties attributes) {
|
||||
Section section = parent.AddSection("");
|
||||
SetSectionParameters(section, attributes);
|
||||
return section;
|
||||
}
|
||||
|
||||
private static void SetSectionParameters(Section section, Properties attributes) {
|
||||
String value;
|
||||
value = attributes[ElementTags.NUMBERDEPTH];
|
||||
if (value != null) {
|
||||
section.NumberDepth = int.Parse(value);
|
||||
}
|
||||
value = attributes[ElementTags.INDENT];
|
||||
if (value != null) {
|
||||
section.Indentation = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
}
|
||||
value = attributes[ElementTags.INDENTATIONLEFT];
|
||||
if (value != null) {
|
||||
section.IndentationLeft = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
}
|
||||
value = attributes[ElementTags.INDENTATIONRIGHT];
|
||||
if (value != null) {
|
||||
section.IndentationRight = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an Image that has been constructed taking in account
|
||||
/// the value of some attributes.
|
||||
/// </summary>
|
||||
/// <param name="attributes">Some attributes</param>
|
||||
/// <returns>an Image</returns>
|
||||
public static Image GetImage(Properties attributes) {
|
||||
String value;
|
||||
|
||||
value = attributes[ElementTags.URL];
|
||||
if (value == null)
|
||||
throw new ArgumentException("The URL of the image is missing.");
|
||||
Image image = Image.GetInstance(value);
|
||||
|
||||
value = attributes[ElementTags.ALIGN];
|
||||
int align = 0;
|
||||
if (value != null) {
|
||||
if (Util.EqualsIgnoreCase(ElementTags.ALIGN_LEFT, value))
|
||||
align |= Image.ALIGN_LEFT;
|
||||
else if (Util.EqualsIgnoreCase(ElementTags.ALIGN_RIGHT, value))
|
||||
align |= Image.ALIGN_RIGHT;
|
||||
else if (Util.EqualsIgnoreCase(ElementTags.ALIGN_MIDDLE, value))
|
||||
align |= Image.ALIGN_MIDDLE;
|
||||
}
|
||||
if (Util.EqualsIgnoreCase("true", attributes[ElementTags.UNDERLYING]))
|
||||
align |= Image.UNDERLYING;
|
||||
if (Util.EqualsIgnoreCase("true", attributes[ElementTags.TEXTWRAP]))
|
||||
align |= Image.TEXTWRAP;
|
||||
image.Alignment = align;
|
||||
|
||||
value = attributes[ElementTags.ALT];
|
||||
if (value != null) {
|
||||
image.Alt = value;
|
||||
}
|
||||
|
||||
String x = attributes[ElementTags.ABSOLUTEX];
|
||||
String y = attributes[ElementTags.ABSOLUTEY];
|
||||
if ((x != null) && (y != null)) {
|
||||
image.SetAbsolutePosition(float.Parse(x, System.Globalization.NumberFormatInfo.InvariantInfo),
|
||||
float.Parse(y, System.Globalization.NumberFormatInfo.InvariantInfo));
|
||||
}
|
||||
value = attributes[ElementTags.PLAINWIDTH];
|
||||
if (value != null) {
|
||||
image.ScaleAbsoluteWidth(float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo));
|
||||
}
|
||||
value = attributes[ElementTags.PLAINHEIGHT];
|
||||
if (value != null) {
|
||||
image.ScaleAbsoluteHeight(float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo));
|
||||
}
|
||||
value = attributes[ElementTags.ROTATION];
|
||||
if (value != null) {
|
||||
image.Rotation = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an Annotation object based on a list of properties.
|
||||
* @param attributes
|
||||
* @return an Annotation
|
||||
*/
|
||||
public static Annotation GetAnnotation(Properties attributes) {
|
||||
float llx = 0, lly = 0, urx = 0, ury = 0;
|
||||
String value;
|
||||
|
||||
value = attributes[ElementTags.LLX];
|
||||
if (value != null) {
|
||||
llx = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
}
|
||||
value = attributes[ElementTags.LLY];
|
||||
if (value != null) {
|
||||
lly = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
}
|
||||
value = attributes[ElementTags.URX];
|
||||
if (value != null) {
|
||||
urx = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
}
|
||||
value = attributes[ElementTags.URY];
|
||||
if (value != null) {
|
||||
ury = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
}
|
||||
|
||||
String title = attributes[ElementTags.TITLE];
|
||||
String text = attributes[ElementTags.CONTENT];
|
||||
if (title != null || text != null) {
|
||||
return new Annotation(title, text, llx, lly, urx, ury);
|
||||
}
|
||||
value = attributes[ElementTags.URL];
|
||||
if (value != null) {
|
||||
return new Annotation(llx, lly, urx, ury, value);
|
||||
}
|
||||
value = attributes[ElementTags.NAMED];
|
||||
if (value != null) {
|
||||
return new Annotation(llx, lly, urx, ury, int.Parse(value));
|
||||
}
|
||||
String file = attributes[ElementTags.FILE];
|
||||
String destination = attributes[ElementTags.DESTINATION];
|
||||
String page = (String) attributes.Remove(ElementTags.PAGE);
|
||||
if (file != null) {
|
||||
if (destination != null) {
|
||||
return new Annotation(llx, lly, urx, ury, file, destination);
|
||||
}
|
||||
if (page != null) {
|
||||
return new Annotation(llx, lly, urx, ury, file, int.Parse(page));
|
||||
}
|
||||
}
|
||||
if (title == null)
|
||||
title = "";
|
||||
if (text == null)
|
||||
text = "";
|
||||
return new Annotation(title, text, llx, lly, urx, ury);
|
||||
}
|
||||
}
|
||||
}
|
||||
122
iTechSharp/iTextSharp/text/factories/GreekAlphabetFactory.cs
Normal file
122
iTechSharp/iTextSharp/text/factories/GreekAlphabetFactory.cs
Normal file
@@ -0,0 +1,122 @@
|
||||
using System;
|
||||
using iTextSharp.text;
|
||||
/*
|
||||
* $Id: GreekAlphabetFactory.cs,v 1.2 2008/05/13 11:25:14 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2007 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
namespace iTextSharp.text.factories {
|
||||
|
||||
/**
|
||||
* This class can produce String combinations representing a number built with
|
||||
* Greek letters (from alpha to omega, then alpha alpha, alpha beta, alpha gamma).
|
||||
* We are aware of the fact that the original Greek numbering is different;
|
||||
* See http://www.cogsci.indiana.edu/farg/harry/lan/grknum.htm#ancient
|
||||
* but this isn't implemented yet; the main reason being the fact that we
|
||||
* need a font that has the obsolete Greek characters qoppa and sampi.
|
||||
*/
|
||||
public class GreekAlphabetFactory {
|
||||
/**
|
||||
* Changes an int into a lower case Greek letter combination.
|
||||
* @param index the original number
|
||||
* @return the letter combination
|
||||
*/
|
||||
public static String GetString(int index) {
|
||||
return GetString(index, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes an int into a lower case Greek letter combination.
|
||||
* @param index the original number
|
||||
* @return the letter combination
|
||||
*/
|
||||
public static String GetLowerCaseString(int index) {
|
||||
return GetString(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes an int into a upper case Greek letter combination.
|
||||
* @param index the original number
|
||||
* @return the letter combination
|
||||
*/
|
||||
public static String GetUpperCaseString(int index) {
|
||||
return GetString(index).ToUpper(System.Globalization.CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes an int into a Greek letter combination.
|
||||
* @param index the original number
|
||||
* @return the letter combination
|
||||
*/
|
||||
public static String GetString(int index, bool lowercase) {
|
||||
if (index < 1) return "";
|
||||
index--;
|
||||
|
||||
int bytes = 1;
|
||||
int start = 0;
|
||||
int symbols = 24;
|
||||
while (index >= symbols + start) {
|
||||
bytes++;
|
||||
start += symbols;
|
||||
symbols *= 24;
|
||||
}
|
||||
|
||||
int c = index - start;
|
||||
char[] value = new char[bytes];
|
||||
while (bytes > 0) {
|
||||
bytes--;
|
||||
value[bytes] = (char)(c % 24);
|
||||
if (value[bytes] > 16) value[bytes]++;
|
||||
value[bytes] += (char)(lowercase ? 945 : 913);
|
||||
value[bytes] = SpecialSymbol.GetCorrespondingSymbol(value[bytes]);
|
||||
c /= 24;
|
||||
}
|
||||
|
||||
return new String(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
122
iTechSharp/iTextSharp/text/factories/RomanAlphabetFactory.cs
Normal file
122
iTechSharp/iTextSharp/text/factories/RomanAlphabetFactory.cs
Normal file
@@ -0,0 +1,122 @@
|
||||
using System;
|
||||
/*
|
||||
* $Id: RomanAlphabetFactory.cs,v 1.2 2008/05/13 11:25:14 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2007 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.factories {
|
||||
|
||||
/**
|
||||
* This class can produce String combinations representing a number.
|
||||
* "a" to "z" represent 1 to 26, "AA" represents 27, "AB" represents 28,
|
||||
* and so on; "ZZ" is followed by "AAA".
|
||||
*/
|
||||
public class RomanAlphabetFactory {
|
||||
|
||||
/**
|
||||
* Translates a positive integer (not equal to zero)
|
||||
* into a String using the letters 'a' to 'z';
|
||||
* 1 = a, 2 = b, ..., 26 = z, 27 = aa, 28 = ab,...
|
||||
*/
|
||||
public static String GetString(int index) {
|
||||
if (index < 1) throw new FormatException("You can't translate a negative number into an alphabetical value.");
|
||||
|
||||
index--;
|
||||
int bytes = 1;
|
||||
int start = 0;
|
||||
int symbols = 26;
|
||||
while (index >= symbols + start) {
|
||||
bytes++;
|
||||
start += symbols;
|
||||
symbols *= 26;
|
||||
}
|
||||
|
||||
int c = index - start;
|
||||
char[] value = new char[bytes];
|
||||
while (bytes > 0) {
|
||||
value[--bytes] = (char)( 'a' + (c % 26));
|
||||
c /= 26;
|
||||
}
|
||||
|
||||
return new String(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates a positive integer (not equal to zero)
|
||||
* into a String using the letters 'a' to 'z';
|
||||
* 1 = a, 2 = b, ..., 26 = z, 27 = aa, 28 = ab,...
|
||||
*/
|
||||
public static String GetLowerCaseString(int index) {
|
||||
return GetString(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates a positive integer (not equal to zero)
|
||||
* into a String using the letters 'A' to 'Z';
|
||||
* 1 = A, 2 = B, ..., 26 = Z, 27 = AA, 28 = AB,...
|
||||
*/
|
||||
public static String GetUpperCaseString(int index) {
|
||||
return GetString(index).ToUpper(System.Globalization.CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Translates a positive integer (not equal to zero)
|
||||
* into a String using the letters 'a' to 'z'
|
||||
* (a = 1, b = 2, ..., z = 26, aa = 27, ab = 28,...).
|
||||
*/
|
||||
public static String GetString(int index, bool lowercase) {
|
||||
if (lowercase) {
|
||||
return GetLowerCaseString(index);
|
||||
}
|
||||
else {
|
||||
return GetUpperCaseString(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
180
iTechSharp/iTextSharp/text/factories/RomanNumberFactory.cs
Normal file
180
iTechSharp/iTextSharp/text/factories/RomanNumberFactory.cs
Normal file
@@ -0,0 +1,180 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
/*
|
||||
* $Id: RomanNumberFactory.cs,v 1.2 2008/05/13 11:25:14 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2007 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
namespace iTextSharp.text.factories {
|
||||
/**
|
||||
* This class can produce String combinations representing a roman number.
|
||||
*/
|
||||
public class RomanNumberFactory {
|
||||
/**
|
||||
* Helper class for Roman Digits
|
||||
*/
|
||||
internal class RomanDigit {
|
||||
|
||||
/** part of a roman number */
|
||||
public char digit;
|
||||
|
||||
/** value of the roman digit */
|
||||
public int value;
|
||||
|
||||
/** can the digit be used as a prefix */
|
||||
public bool pre;
|
||||
|
||||
/**
|
||||
* Constructs a roman digit
|
||||
* @param digit the roman digit
|
||||
* @param value the value
|
||||
* @param pre can it be used as a prefix
|
||||
*/
|
||||
internal RomanDigit(char digit, int value, bool pre) {
|
||||
this.digit = digit;
|
||||
this.value = value;
|
||||
this.pre = pre;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Array with Roman digits.
|
||||
*/
|
||||
private static RomanDigit[] roman = {
|
||||
new RomanDigit('m', 1000, false),
|
||||
new RomanDigit('d', 500, false),
|
||||
new RomanDigit('c', 100, true),
|
||||
new RomanDigit('l', 50, false),
|
||||
new RomanDigit('x', 10, true),
|
||||
new RomanDigit('v', 5, false),
|
||||
new RomanDigit('i', 1, true)
|
||||
};
|
||||
|
||||
/**
|
||||
* Changes an int into a lower case roman number.
|
||||
* @param index the original number
|
||||
* @return the roman number (lower case)
|
||||
*/
|
||||
public static String GetString(int index) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
|
||||
// lower than 0 ? Add minus
|
||||
if (index < 0) {
|
||||
buf.Append('-');
|
||||
index = -index;
|
||||
}
|
||||
|
||||
// greater than 3000
|
||||
if (index > 3000) {
|
||||
buf.Append('|');
|
||||
buf.Append(GetString(index / 1000));
|
||||
buf.Append('|');
|
||||
// remainder
|
||||
index = index - (index / 1000) * 1000;
|
||||
}
|
||||
|
||||
// number between 1 and 3000
|
||||
int pos = 0;
|
||||
while (true) {
|
||||
// loop over the array with values for m-d-c-l-x-v-i
|
||||
RomanDigit dig = roman[pos];
|
||||
// adding as many digits as we can
|
||||
while (index >= dig.value) {
|
||||
buf.Append(dig.digit);
|
||||
index -= dig.value;
|
||||
}
|
||||
// we have the complete number
|
||||
if (index <= 0) {
|
||||
break;
|
||||
}
|
||||
// look for the next digit that can be used in a special way
|
||||
int j = pos;
|
||||
while (!roman[++j].pre);
|
||||
|
||||
// does the special notation apply?
|
||||
if (index + roman[j].value >= dig.value) {
|
||||
buf.Append(roman[j].digit).Append(dig.digit);
|
||||
index -= dig.value - roman[j].value;
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
return buf.ToString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes an int into a lower case roman number.
|
||||
* @param index the original number
|
||||
* @return the roman number (lower case)
|
||||
*/
|
||||
public static String GetLowerCaseString(int index) {
|
||||
return GetString(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes an int into an upper case roman number.
|
||||
* @param index the original number
|
||||
* @return the roman number (lower case)
|
||||
*/
|
||||
public static String GetUpperCaseString(int index) {
|
||||
return GetString(index).ToUpper(System.Globalization.CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes an int into a roman number.
|
||||
* @param index the original number
|
||||
* @return the roman number (lower case)
|
||||
*/
|
||||
public static String GetString(int index, bool lowercase) {
|
||||
if (lowercase) {
|
||||
return GetLowerCaseString(index);
|
||||
}
|
||||
else {
|
||||
return GetUpperCaseString(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
213
iTechSharp/iTextSharp/text/html/HtmlEncoder.cs
Normal file
213
iTechSharp/iTextSharp/text/html/HtmlEncoder.cs
Normal file
@@ -0,0 +1,213 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
|
||||
using iTextSharp.text;
|
||||
|
||||
/*
|
||||
* $Id: HtmlEncoder.cs,v 1.6 2008/05/13 11:25:15 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.html {
|
||||
/**
|
||||
* This class converts a <CODE>String</CODE> to the HTML-format of a String.
|
||||
* <P>
|
||||
* To convert the <CODE>String</CODE>, each character is examined:
|
||||
* <UL>
|
||||
* <LI>ASCII-characters from 000 till 031 are represented as &#xxx;<BR>
|
||||
* (with xxx = the value of the character)
|
||||
* <LI>ASCII-characters from 032 t/m 127 are represented by the character itself, except for:
|
||||
* <UL>
|
||||
* <LI>'\n' becomes <BR>\n
|
||||
* <LI>" becomes &quot;
|
||||
* <LI>& becomes &amp;
|
||||
* <LI>< becomes &lt;
|
||||
* <LI>> becomes &gt;
|
||||
* </UL>
|
||||
* <LI>ASCII-characters from 128 till 255 are represented as &#xxx;<BR>
|
||||
* (with xxx = the value of the character)
|
||||
* </UL>
|
||||
* <P>
|
||||
* Example:
|
||||
* <P><BLOCKQUOTE><PRE>
|
||||
* String htmlPresentation = HtmlEncoder.Encode("Marie-Thérèse Sørensen");
|
||||
* </PRE></BLOCKQUOTE><P>
|
||||
* for more info: see O'Reilly; "HTML: The Definitive Guide" (page 164)
|
||||
*
|
||||
* @author mario.maccarini@rug.ac.be
|
||||
*/
|
||||
|
||||
public sealed class HtmlEncoder {
|
||||
|
||||
// membervariables
|
||||
|
||||
/** List with the HTML translation of all the characters. */
|
||||
private static String[] htmlCode = new String[256];
|
||||
|
||||
static HtmlEncoder() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
htmlCode[i] = "�" + i + ";";
|
||||
}
|
||||
|
||||
for (int i = 10; i < 32; i++) {
|
||||
htmlCode[i] = "�" + i + ";";
|
||||
}
|
||||
|
||||
for (int i = 32; i < 128; i++) {
|
||||
htmlCode[i] = ((char)i).ToString();
|
||||
}
|
||||
|
||||
// Special characters
|
||||
htmlCode['\t'] = "\t";
|
||||
htmlCode['\n'] = "<" + HtmlTags.NEWLINE + " />\n";
|
||||
htmlCode['\"'] = """; // double quote
|
||||
htmlCode['&'] = "&"; // ampersand
|
||||
htmlCode['<'] = "<"; // lower than
|
||||
htmlCode['>'] = ">"; // greater than
|
||||
|
||||
for (int i = 128; i < 256; i++) {
|
||||
htmlCode[i] = "&#" + i + ";";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// constructors
|
||||
|
||||
/**
|
||||
* This class will never be constructed.
|
||||
* <P>
|
||||
* HtmlEncoder only contains static methods.
|
||||
*/
|
||||
|
||||
private HtmlEncoder () { }
|
||||
|
||||
// methods
|
||||
|
||||
/**
|
||||
* Converts a <CODE>String</CODE> to the HTML-format of this <CODE>String</CODE>.
|
||||
*
|
||||
* @param string The <CODE>String</CODE> to convert
|
||||
* @return a <CODE>String</CODE>
|
||||
*/
|
||||
|
||||
public static String Encode(String str) {
|
||||
int n = str.Length;
|
||||
char character;
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
// loop over all the characters of the String.
|
||||
for (int i = 0; i < n; i++) {
|
||||
character = str[i];
|
||||
// the Htmlcode of these characters are added to a StringBuilder one by one
|
||||
if (character < 256) {
|
||||
buffer.Append(htmlCode[character]);
|
||||
}
|
||||
else {
|
||||
// Improvement posted by Joachim Eyrich
|
||||
buffer.Append("&#").Append((int)character).Append(';');
|
||||
}
|
||||
}
|
||||
return buffer.ToString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a <CODE>Color</CODE> into a HTML representation of this <CODE>Color</CODE>.
|
||||
*
|
||||
* @param color the <CODE>Color</CODE> that has to be converted.
|
||||
* @return the HTML representation of this <COLOR>Color</COLOR>
|
||||
*/
|
||||
|
||||
public static String Encode(Color color) {
|
||||
StringBuilder buffer = new StringBuilder("#");
|
||||
if (color.R < 16) {
|
||||
buffer.Append('0');
|
||||
}
|
||||
buffer.Append(System.Convert.ToString(color.R, 16));
|
||||
if (color.G < 16) {
|
||||
buffer.Append('0');
|
||||
}
|
||||
buffer.Append(System.Convert.ToString(color.G, 16));
|
||||
if (color.B < 16) {
|
||||
buffer.Append('0');
|
||||
}
|
||||
buffer.Append(System.Convert.ToString(color.B, 16));
|
||||
return buffer.ToString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates the alignment value.
|
||||
*
|
||||
* @param alignment the alignment value
|
||||
* @return the translated value
|
||||
*/
|
||||
|
||||
public static String GetAlignment(int alignment) {
|
||||
switch (alignment) {
|
||||
case Element.ALIGN_LEFT:
|
||||
return HtmlTags.ALIGN_LEFT;
|
||||
case Element.ALIGN_CENTER:
|
||||
return HtmlTags.ALIGN_CENTER;
|
||||
case Element.ALIGN_RIGHT:
|
||||
return HtmlTags.ALIGN_RIGHT;
|
||||
case Element.ALIGN_JUSTIFIED:
|
||||
case Element.ALIGN_JUSTIFIED_ALL:
|
||||
return HtmlTags.ALIGN_JUSTIFIED;
|
||||
case Element.ALIGN_TOP:
|
||||
return HtmlTags.ALIGN_TOP;
|
||||
case Element.ALIGN_MIDDLE:
|
||||
return HtmlTags.ALIGN_MIDDLE;
|
||||
case Element.ALIGN_BOTTOM:
|
||||
return HtmlTags.ALIGN_BOTTOM;
|
||||
case Element.ALIGN_BASELINE:
|
||||
return HtmlTags.ALIGN_BASELINE;
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
239
iTechSharp/iTextSharp/text/html/HtmlParser.cs
Normal file
239
iTechSharp/iTextSharp/text/html/HtmlParser.cs
Normal file
@@ -0,0 +1,239 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using System.Collections;
|
||||
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.xml;
|
||||
|
||||
/*
|
||||
* Copyright 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.html {
|
||||
|
||||
/// <summary>
|
||||
/// This class can be used to parse an XML file.
|
||||
/// </summary>
|
||||
public class HtmlParser : XmlParser{
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an XmlParser.
|
||||
/// </summary>
|
||||
public HtmlParser() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses a given file.
|
||||
/// </summary>
|
||||
/// <param name="document"></param>
|
||||
/// <param name="file"></param>
|
||||
public override void Go(IDocListener document, XmlDocument xDoc) {
|
||||
parser = new ITextmyHtmlHandler(document);
|
||||
parser.Parse(xDoc);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses a given file.
|
||||
/// </summary>
|
||||
/// <param name="document"></param>
|
||||
/// <param name="file"></param>
|
||||
public override void Go(IDocListener document, String file) {
|
||||
parser = new ITextmyHtmlHandler(document);
|
||||
parser.Parse(file);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses a given XmlTextReader.
|
||||
/// </summary>
|
||||
/// <param name="document"></param>
|
||||
/// <param name="reader"></param>
|
||||
public override void Go(IDocListener document, XmlTextReader reader) {
|
||||
parser = new ITextmyHtmlHandler(document);
|
||||
parser.Parse(reader);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses a given file.
|
||||
/// </summary>
|
||||
/// <param name="document"></param>
|
||||
/// <param name="file"></param>
|
||||
/// <param name="tagmap"></param>
|
||||
public override void Go(IDocListener document, XmlDocument xDoc, XmlDocument xTagmap) {
|
||||
parser = new ITextmyHtmlHandler(document, new TagMap(xTagmap));
|
||||
parser.Parse(xDoc);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses a given XmlTextReader.
|
||||
/// </summary>
|
||||
/// <param name="document"></param>
|
||||
/// <param name="reader"></param>
|
||||
/// <param name="tagmap"></param>
|
||||
public override void Go(IDocListener document, XmlTextReader reader, String tagmap) {
|
||||
parser = new ITextmyHtmlHandler(document, new TagMap(tagmap));
|
||||
parser.Parse(reader);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses a given file.
|
||||
/// </summary>
|
||||
/// <param name="document"></param>
|
||||
/// <param name="file"></param>
|
||||
/// <param name="tagmap"></param>
|
||||
public override void Go(IDocListener document, String file, String tagmap) {
|
||||
parser = new ITextmyHtmlHandler(document, new TagMap(tagmap));
|
||||
parser.Parse(file);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses a given file.
|
||||
/// </summary>
|
||||
/// <param name="document"></param>
|
||||
/// <param name="file"></param>
|
||||
/// <param name="tagmap"></param>
|
||||
public override void Go(IDocListener document, String file, Hashtable tagmap) {
|
||||
parser = new ITextmyHtmlHandler(document, tagmap);
|
||||
parser.Parse(file);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses a given XmlTextReader.
|
||||
/// </summary>
|
||||
/// <param name="document"></param>
|
||||
/// <param name="reader"></param>
|
||||
/// <param name="tagmap"></param>
|
||||
public override void Go(IDocListener document, XmlTextReader reader, Hashtable tagmap) {
|
||||
parser = new ITextmyHtmlHandler(document, tagmap);
|
||||
parser.Parse(reader);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses a given file.
|
||||
/// </summary>
|
||||
/// <param name="document"></param>
|
||||
/// <param name="file"></param>
|
||||
public new static void Parse(IDocListener document, XmlDocument xDoc) {
|
||||
HtmlParser p = new HtmlParser();
|
||||
p.Go(document, xDoc);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses a given file.
|
||||
/// </summary>
|
||||
/// <param name="document"></param>
|
||||
/// <param name="file"></param>
|
||||
public new static void Parse(IDocListener document, String file) {
|
||||
HtmlParser p = new HtmlParser();
|
||||
p.Go(document, file);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses a given XmlTextReader.
|
||||
/// </summary>
|
||||
/// <param name="document"></param>
|
||||
/// <param name="reader"></param>
|
||||
public new static void Parse(IDocListener document, XmlTextReader reader) {
|
||||
HtmlParser p = new HtmlParser();
|
||||
p.Go(document, reader);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses a given file.
|
||||
/// </summary>
|
||||
/// <param name="document"></param>
|
||||
/// <param name="file"></param>
|
||||
/// <param name="tagmap"></param>
|
||||
public new static void Parse(IDocListener document, XmlDocument xDoc, XmlDocument xTagmap) {
|
||||
HtmlParser p = new HtmlParser();
|
||||
p.Go(document, xDoc, xTagmap);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses a given file.
|
||||
/// </summary>
|
||||
/// <param name="document"></param>
|
||||
/// <param name="file"></param>
|
||||
/// <param name="tagmap"></param>
|
||||
public new static void Parse(IDocListener document, String file, String tagmap) {
|
||||
HtmlParser p = new HtmlParser();
|
||||
p.Go(document, file, tagmap);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses a given file.
|
||||
/// </summary>
|
||||
/// <param name="document"></param>
|
||||
/// <param name="file"></param>
|
||||
/// <param name="tagmap"></param>
|
||||
public new static void Parse(IDocListener document, String file, Hashtable tagmap) {
|
||||
HtmlParser p = new HtmlParser();
|
||||
p.Go(document, file, tagmap);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses a given XmlTextReader.
|
||||
/// </summary>
|
||||
/// <param name="document"></param>
|
||||
/// <param name="reader"></param>
|
||||
/// <param name="tagmap"></param>
|
||||
public new static void Parse(IDocListener document, XmlTextReader reader, String tagmap) {
|
||||
HtmlParser p = new HtmlParser();
|
||||
p.Go(document, reader, tagmap);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses a given XmlTextReader.
|
||||
/// </summary>
|
||||
/// <param name="document"></param>
|
||||
/// <param name="reader"></param>
|
||||
/// <param name="tagmap"></param>
|
||||
public new static void Parse(IDocListener document, XmlTextReader reader, Hashtable tagmap) {
|
||||
HtmlParser p = new HtmlParser();
|
||||
p.Go(document, reader, tagmap);
|
||||
}
|
||||
}
|
||||
}
|
||||
102
iTechSharp/iTextSharp/text/html/HtmlPeer.cs
Normal file
102
iTechSharp/iTextSharp/text/html/HtmlPeer.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Collections;
|
||||
using iTextSharp.text.xml;
|
||||
using System.util;
|
||||
|
||||
/*
|
||||
* $Id: HtmlPeer.cs,v 1.4 2008/05/13 11:25:15 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.html {
|
||||
|
||||
/**
|
||||
* This interface is implemented by the peer of all the iText objects.
|
||||
*/
|
||||
|
||||
public class HtmlPeer : XmlPeer {
|
||||
|
||||
/**
|
||||
* Creates a XmlPeer.
|
||||
* @param name the iText name of the tag
|
||||
* @param alias the Html name of the tag
|
||||
*/
|
||||
|
||||
public HtmlPeer(String name, String alias) : base(name, alias.ToLower(CultureInfo.InvariantCulture)) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an alias for an attribute.
|
||||
*
|
||||
* @param name the iText tagname
|
||||
* @param alias the custom tagname
|
||||
*/
|
||||
|
||||
public override void AddAlias(String name, String alias) {
|
||||
attributeAliases.Add(alias.ToLower(CultureInfo.InvariantCulture), name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.lowagie.text.xml.XmlPeer#getAttributes(org.xml.sax.Attributes)
|
||||
*/
|
||||
public override Properties GetAttributes(Hashtable attrs) {
|
||||
Properties attributes = new Properties();
|
||||
attributes.AddAll(attributeValues);
|
||||
if (defaultContent != null) {
|
||||
attributes[ElementTags.ITEXT] = defaultContent;
|
||||
}
|
||||
if (attrs != null) {
|
||||
foreach (string key in attrs.Keys) {
|
||||
attributes.Add(GetName(key).ToLower(CultureInfo.InvariantCulture), (string)attrs[key]);
|
||||
}
|
||||
}
|
||||
return attributes;
|
||||
}
|
||||
}
|
||||
}
|
||||
289
iTechSharp/iTextSharp/text/html/HtmlTagMap.cs
Normal file
289
iTechSharp/iTextSharp/text/html/HtmlTagMap.cs
Normal file
@@ -0,0 +1,289 @@
|
||||
using System;
|
||||
using System.util;
|
||||
using System.Collections;
|
||||
using iTextSharp.text;
|
||||
|
||||
/*
|
||||
* $Id: HtmlTagMap.cs,v 1.4 2008/05/13 11:25:15 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.html {
|
||||
|
||||
/**
|
||||
* The <CODE>Tags</CODE>-class maps several XHTML-tags to iText-objects.
|
||||
*/
|
||||
|
||||
public class HtmlTagMap : Hashtable {
|
||||
|
||||
/**
|
||||
* Constructs an HtmlTagMap.
|
||||
*/
|
||||
|
||||
public HtmlTagMap() {
|
||||
HtmlPeer peer;
|
||||
|
||||
peer = new HtmlPeer(ElementTags.ITEXT, HtmlTags.HTML);
|
||||
this[peer.Alias] = peer;
|
||||
|
||||
peer = new HtmlPeer(ElementTags.PHRASE, HtmlTags.SPAN);
|
||||
this[peer.Alias] = peer;
|
||||
|
||||
peer = new HtmlPeer(ElementTags.CHUNK, HtmlTags.CHUNK);
|
||||
peer.AddAlias(ElementTags.FONT, HtmlTags.FONT);
|
||||
peer.AddAlias(ElementTags.SIZE, HtmlTags.SIZE);
|
||||
peer.AddAlias(ElementTags.COLOR, HtmlTags.COLOR);
|
||||
this[peer.Alias] = peer;
|
||||
|
||||
peer = new HtmlPeer(ElementTags.ANCHOR, HtmlTags.ANCHOR);
|
||||
peer.AddAlias(ElementTags.NAME, HtmlTags.NAME);
|
||||
peer.AddAlias(ElementTags.REFERENCE, HtmlTags.REFERENCE);
|
||||
this[peer.Alias] = peer;
|
||||
|
||||
peer = new HtmlPeer(ElementTags.PARAGRAPH, HtmlTags.PARAGRAPH);
|
||||
peer.AddAlias(ElementTags.ALIGN, HtmlTags.ALIGN);
|
||||
this[peer.Alias] = peer;
|
||||
|
||||
peer = new HtmlPeer(ElementTags.PARAGRAPH, HtmlTags.DIV);
|
||||
peer.AddAlias(ElementTags.ALIGN, HtmlTags.ALIGN);
|
||||
this[peer.Alias] = peer;
|
||||
|
||||
peer = new HtmlPeer(ElementTags.PARAGRAPH, HtmlTags.H[0]);
|
||||
peer.AddValue(ElementTags.SIZE, "20");
|
||||
this[peer.Alias] = peer;
|
||||
|
||||
peer = new HtmlPeer(ElementTags.PARAGRAPH, HtmlTags.H[1]);
|
||||
peer.AddValue(ElementTags.SIZE, "18");
|
||||
this[peer.Alias] = peer;
|
||||
|
||||
peer = new HtmlPeer(ElementTags.PARAGRAPH, HtmlTags.H[2]);
|
||||
peer.AddValue(ElementTags.SIZE, "16");
|
||||
this[peer.Alias] = peer;
|
||||
|
||||
peer = new HtmlPeer(ElementTags.PARAGRAPH, HtmlTags.H[3]);
|
||||
peer.AddValue(ElementTags.SIZE, "14");
|
||||
this[peer.Alias] = peer;
|
||||
|
||||
peer = new HtmlPeer(ElementTags.PARAGRAPH, HtmlTags.H[4]);
|
||||
peer.AddValue(ElementTags.SIZE, "12");
|
||||
this[peer.Alias] = peer;
|
||||
|
||||
peer = new HtmlPeer(ElementTags.PARAGRAPH, HtmlTags.H[5]);
|
||||
peer.AddValue(ElementTags.SIZE, "10");
|
||||
this[peer.Alias] = peer;
|
||||
|
||||
peer = new HtmlPeer(ElementTags.LIST, HtmlTags.ORDEREDLIST);
|
||||
peer.AddValue(ElementTags.NUMBERED, "true");
|
||||
peer.AddValue(ElementTags.SYMBOLINDENT, "20");
|
||||
this[peer.Alias] = peer;
|
||||
|
||||
peer = new HtmlPeer(ElementTags.LIST, HtmlTags.UNORDEREDLIST);
|
||||
peer.AddValue(ElementTags.NUMBERED, "false");
|
||||
peer.AddValue(ElementTags.SYMBOLINDENT, "20");
|
||||
this[peer.Alias] = peer;
|
||||
|
||||
peer = new HtmlPeer(ElementTags.LISTITEM, HtmlTags.LISTITEM);
|
||||
this[peer.Alias] = peer;
|
||||
|
||||
peer = new HtmlPeer(ElementTags.PHRASE, HtmlTags.I);
|
||||
peer.AddValue(ElementTags.STYLE, Markup.CSS_VALUE_ITALIC);
|
||||
this[peer.Alias] = peer;
|
||||
|
||||
peer = new HtmlPeer(ElementTags.PHRASE, HtmlTags.EM);
|
||||
peer.AddValue(ElementTags.STYLE, Markup.CSS_VALUE_ITALIC);
|
||||
this[peer.Alias] = peer;
|
||||
|
||||
peer = new HtmlPeer(ElementTags.PHRASE, HtmlTags.B);
|
||||
peer.AddValue(ElementTags.STYLE, Markup.CSS_VALUE_BOLD);
|
||||
this[peer.Alias] = peer;
|
||||
|
||||
peer = new HtmlPeer(ElementTags.PHRASE, HtmlTags.STRONG);
|
||||
peer.AddValue(ElementTags.STYLE, Markup.CSS_VALUE_BOLD);
|
||||
this[peer.Alias] = peer;
|
||||
|
||||
peer = new HtmlPeer(ElementTags.PHRASE, HtmlTags.S);
|
||||
peer.AddValue(ElementTags.STYLE, Markup.CSS_VALUE_LINETHROUGH);
|
||||
this[peer.Alias] = peer;
|
||||
|
||||
peer = new HtmlPeer(ElementTags.PHRASE, HtmlTags.CODE);
|
||||
peer.AddValue(ElementTags.FONT, FontFactory.COURIER);
|
||||
this[peer.Alias] = peer;
|
||||
|
||||
peer = new HtmlPeer(ElementTags.PHRASE, HtmlTags.VAR);
|
||||
peer.AddValue(ElementTags.FONT, FontFactory.COURIER);
|
||||
peer.AddValue(ElementTags.STYLE, Markup.CSS_VALUE_ITALIC);
|
||||
this[peer.Alias] = peer;
|
||||
|
||||
peer = new HtmlPeer(ElementTags.PHRASE, HtmlTags.U);
|
||||
peer.AddValue(ElementTags.STYLE, Markup.CSS_VALUE_UNDERLINE);
|
||||
this[peer.Alias] = peer;
|
||||
|
||||
peer = new HtmlPeer(ElementTags.CHUNK, HtmlTags.SUP);
|
||||
peer.AddValue(ElementTags.SUBSUPSCRIPT, "6.0");
|
||||
this[peer.Alias] = peer;
|
||||
|
||||
peer = new HtmlPeer(ElementTags.CHUNK, HtmlTags.SUB);
|
||||
peer.AddValue(ElementTags.SUBSUPSCRIPT, "-6.0");
|
||||
this[peer.Alias] = peer;
|
||||
|
||||
peer = new HtmlPeer(ElementTags.HORIZONTALRULE, HtmlTags.HORIZONTALRULE);
|
||||
this[peer.Alias] = peer;
|
||||
|
||||
peer = new HtmlPeer(ElementTags.TABLE, HtmlTags.TABLE);
|
||||
peer.AddAlias(ElementTags.WIDTH, HtmlTags.WIDTH);
|
||||
peer.AddAlias(ElementTags.BACKGROUNDCOLOR, HtmlTags.BACKGROUNDCOLOR);
|
||||
peer.AddAlias(ElementTags.BORDERCOLOR, HtmlTags.BORDERCOLOR);
|
||||
peer.AddAlias(ElementTags.COLUMNS, HtmlTags.COLUMNS);
|
||||
peer.AddAlias(ElementTags.CELLPADDING, HtmlTags.CELLPADDING);
|
||||
peer.AddAlias(ElementTags.CELLSPACING, HtmlTags.CELLSPACING);
|
||||
peer.AddAlias(ElementTags.BORDERWIDTH, HtmlTags.BORDERWIDTH);
|
||||
peer.AddAlias(ElementTags.ALIGN, HtmlTags.ALIGN);
|
||||
this[peer.Alias] = peer;
|
||||
|
||||
peer = new HtmlPeer(ElementTags.ROW, HtmlTags.ROW);
|
||||
this[peer.Alias] = peer;
|
||||
|
||||
peer = new HtmlPeer(ElementTags.CELL, HtmlTags.CELL);
|
||||
peer.AddAlias(ElementTags.WIDTH, HtmlTags.WIDTH);
|
||||
peer.AddAlias(ElementTags.BACKGROUNDCOLOR, HtmlTags.BACKGROUNDCOLOR);
|
||||
peer.AddAlias(ElementTags.BORDERCOLOR, HtmlTags.BORDERCOLOR);
|
||||
peer.AddAlias(ElementTags.COLSPAN, HtmlTags.COLSPAN);
|
||||
peer.AddAlias(ElementTags.ROWSPAN, HtmlTags.ROWSPAN);
|
||||
peer.AddAlias(ElementTags.NOWRAP, HtmlTags.NOWRAP);
|
||||
peer.AddAlias(ElementTags.HORIZONTALALIGN, HtmlTags.HORIZONTALALIGN);
|
||||
peer.AddAlias(ElementTags.VERTICALALIGN, HtmlTags.VERTICALALIGN);
|
||||
peer.AddValue(ElementTags.HEADER, "false");
|
||||
this[peer.Alias] = peer;
|
||||
|
||||
peer = new HtmlPeer(ElementTags.CELL, HtmlTags.HEADERCELL);
|
||||
peer.AddAlias(ElementTags.WIDTH, HtmlTags.WIDTH);
|
||||
peer.AddAlias(ElementTags.BACKGROUNDCOLOR, HtmlTags.BACKGROUNDCOLOR);
|
||||
peer.AddAlias(ElementTags.BORDERCOLOR, HtmlTags.BORDERCOLOR);
|
||||
peer.AddAlias(ElementTags.COLSPAN, HtmlTags.COLSPAN);
|
||||
peer.AddAlias(ElementTags.ROWSPAN, HtmlTags.ROWSPAN);
|
||||
peer.AddAlias(ElementTags.NOWRAP, HtmlTags.NOWRAP);
|
||||
peer.AddAlias(ElementTags.HORIZONTALALIGN, HtmlTags.HORIZONTALALIGN);
|
||||
peer.AddAlias(ElementTags.VERTICALALIGN, HtmlTags.VERTICALALIGN);
|
||||
peer.AddValue(ElementTags.HEADER, "true");
|
||||
this[peer.Alias] = peer;
|
||||
|
||||
peer = new HtmlPeer(ElementTags.IMAGE, HtmlTags.IMAGE);
|
||||
peer.AddAlias(ElementTags.URL, HtmlTags.URL);
|
||||
peer.AddAlias(ElementTags.ALT, HtmlTags.ALT);
|
||||
peer.AddAlias(ElementTags.PLAINWIDTH, HtmlTags.PLAINWIDTH);
|
||||
peer.AddAlias(ElementTags.PLAINHEIGHT, HtmlTags.PLAINHEIGHT);
|
||||
this[peer.Alias] = peer;
|
||||
|
||||
peer = new HtmlPeer(ElementTags.NEWLINE, HtmlTags.NEWLINE);
|
||||
this[peer.Alias] = peer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this is the root tag.
|
||||
* @param tag a tagvalue
|
||||
* @return true if tag is HTML or html
|
||||
*/
|
||||
public static bool IsHtml(String tag) {
|
||||
return Util.EqualsIgnoreCase(HtmlTags.HTML, tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this is the head tag.
|
||||
* @param tag a tagvalue
|
||||
* @return true if tag is HEAD or head
|
||||
*/
|
||||
public static bool IsHead(String tag) {
|
||||
return Util.EqualsIgnoreCase(HtmlTags.HEAD, tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this is the meta tag.
|
||||
* @param tag a tagvalue
|
||||
* @return true if tag is META or meta
|
||||
*/
|
||||
public static bool IsMeta(String tag) {
|
||||
return Util.EqualsIgnoreCase(HtmlTags.META, tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this is the linl tag.
|
||||
* @param tag a tagvalue
|
||||
* @return true if tag is LINK or link
|
||||
*/
|
||||
public static bool IsLink(String tag) {
|
||||
return Util.EqualsIgnoreCase(HtmlTags.LINK, tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this is the title tag.
|
||||
* @param tag a tagvalue
|
||||
* @return true if tag is TITLE or title
|
||||
*/
|
||||
public static bool IsTitle(String tag) {
|
||||
return Util.EqualsIgnoreCase(HtmlTags.TITLE, tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this is the root tag.
|
||||
* @param tag a tagvalue
|
||||
* @return true if tag is BODY or body
|
||||
*/
|
||||
public static bool IsBody(String tag) {
|
||||
return Util.EqualsIgnoreCase(HtmlTags.BODY, tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this is a special tag.
|
||||
* @param tag a tagvalue
|
||||
* @return true if tag is a HTML, HEAD, META, LINK or BODY tag (case insensitive)
|
||||
*/
|
||||
public static bool IsSpecialTag(String tag) {
|
||||
return IsHtml(tag) || IsHead(tag) || IsMeta(tag) || IsLink(tag) || IsBody(tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
325
iTechSharp/iTextSharp/text/html/HtmlTags.cs
Normal file
325
iTechSharp/iTextSharp/text/html/HtmlTags.cs
Normal file
@@ -0,0 +1,325 @@
|
||||
using System;
|
||||
|
||||
/*
|
||||
* $Id: HtmlTags.cs,v 1.4 2008/05/13 11:25:15 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.html {
|
||||
|
||||
/**
|
||||
* A class that contains all the possible tagnames and their attributes.
|
||||
*/
|
||||
|
||||
public class HtmlTags {
|
||||
|
||||
/** the root tag. */
|
||||
public const string HTML = "html";
|
||||
|
||||
/** the head tag */
|
||||
public const string HEAD = "head";
|
||||
|
||||
/** This is a possible HTML attribute for the HEAD tag. */
|
||||
public const string CONTENT = "content";
|
||||
|
||||
/** the meta tag */
|
||||
public const string META = "meta";
|
||||
|
||||
/** attribute of the root tag */
|
||||
public const string SUBJECT = "subject";
|
||||
|
||||
/** attribute of the root tag */
|
||||
public const string KEYWORDS = "keywords";
|
||||
|
||||
/** attribute of the root tag */
|
||||
public const string AUTHOR = "author";
|
||||
|
||||
/** the title tag. */
|
||||
public const string TITLE = "title";
|
||||
|
||||
/** the script tag. */
|
||||
public const string SCRIPT = "script";
|
||||
|
||||
/** This is a possible HTML attribute for the SCRIPT tag. */
|
||||
public const string LANGUAGE = "language";
|
||||
|
||||
/** This is a possible value for the LANGUAGE attribute. */
|
||||
public const string JAVASCRIPT = "JavaScript";
|
||||
|
||||
/** the body tag. */
|
||||
public const string BODY = "body";
|
||||
|
||||
/** This is a possible HTML attribute for the BODY tag */
|
||||
public const string JAVASCRIPT_ONLOAD = "onLoad";
|
||||
|
||||
/** This is a possible HTML attribute for the BODY tag */
|
||||
public const string JAVASCRIPT_ONUNLOAD = "onUnLoad";
|
||||
|
||||
/** This is a possible HTML attribute for the BODY tag. */
|
||||
public const string TOPMARGIN = "topmargin";
|
||||
|
||||
/** This is a possible HTML attribute for the BODY tag. */
|
||||
public const string BOTTOMMARGIN = "bottommargin";
|
||||
|
||||
/** This is a possible HTML attribute for the BODY tag. */
|
||||
public const string LEFTMARGIN = "leftmargin";
|
||||
|
||||
/** This is a possible HTML attribute for the BODY tag. */
|
||||
public const string RIGHTMARGIN = "rightmargin";
|
||||
|
||||
// Phrases, Anchors, Lists and Paragraphs
|
||||
|
||||
/** the chunk tag */
|
||||
public const string CHUNK = "font";
|
||||
|
||||
/** the phrase tag */
|
||||
public const string CODE = "code";
|
||||
|
||||
/** the phrase tag */
|
||||
public const string VAR = "var";
|
||||
|
||||
/** the anchor tag */
|
||||
public const string ANCHOR = "a";
|
||||
|
||||
/** the list tag */
|
||||
public const string ORDEREDLIST = "ol";
|
||||
|
||||
/** the list tag */
|
||||
public const string UNORDEREDLIST = "ul";
|
||||
|
||||
/** the listitem tag */
|
||||
public const string LISTITEM = "li";
|
||||
|
||||
/** the paragraph tag */
|
||||
public const string PARAGRAPH = "p";
|
||||
|
||||
/** attribute of anchor tag */
|
||||
public const string NAME = "name";
|
||||
|
||||
/** attribute of anchor tag */
|
||||
public const string REFERENCE = "href";
|
||||
|
||||
/** attribute of anchor tag */
|
||||
public static string[] H = {"h1", "h2", "h3", "h4", "h5", "h6"};
|
||||
|
||||
// Chunks
|
||||
|
||||
/** attribute of the chunk tag */
|
||||
public const string FONT = "face";
|
||||
|
||||
/** attribute of the chunk tag */
|
||||
public const string SIZE = "point-size";
|
||||
|
||||
/** attribute of the chunk/table/cell tag */
|
||||
public const string COLOR = "color";
|
||||
|
||||
/** some phrase tag */
|
||||
public const string EM = "em";
|
||||
|
||||
/** some phrase tag */
|
||||
public const string I = "i";
|
||||
|
||||
/** some phrase tag */
|
||||
public const string STRONG = "strong";
|
||||
|
||||
/** some phrase tag */
|
||||
public const string B = "b";
|
||||
|
||||
/** some phrase tag */
|
||||
public const string S = "s";
|
||||
|
||||
/** some phrase tag */
|
||||
public const string U = "u";
|
||||
|
||||
/** some phrase tag */
|
||||
public const string SUB = "sub";
|
||||
|
||||
/** some phrase tag */
|
||||
public const string SUP = "sup";
|
||||
|
||||
/** the possible value of a tag */
|
||||
public const string HORIZONTALRULE = "hr";
|
||||
|
||||
// tables/cells
|
||||
|
||||
/** the table tag */
|
||||
public const string TABLE = "table";
|
||||
|
||||
/** the cell tag */
|
||||
public const string ROW = "tr";
|
||||
|
||||
/** the cell tag */
|
||||
public const string CELL = "td";
|
||||
|
||||
/** attribute of the cell tag */
|
||||
public const string HEADERCELL = "th";
|
||||
|
||||
/** attribute of the table tag */
|
||||
public const string COLUMNS = "cols";
|
||||
|
||||
/** attribute of the table tag */
|
||||
public const string CELLPADDING = "cellpadding";
|
||||
|
||||
/** attribute of the table tag */
|
||||
public const string CELLSPACING = "cellspacing";
|
||||
|
||||
/** attribute of the cell tag */
|
||||
public const string COLSPAN = "colspan";
|
||||
|
||||
/** attribute of the cell tag */
|
||||
public const string ROWSPAN = "rowspan";
|
||||
|
||||
/** attribute of the cell tag */
|
||||
public const string NOWRAP = "nowrap";
|
||||
|
||||
/** attribute of the table/cell tag */
|
||||
public const string BORDERWIDTH = "border";
|
||||
|
||||
/** attribute of the table/cell tag */
|
||||
public const string WIDTH = "width";
|
||||
|
||||
/** attribute of the table/cell tag */
|
||||
public const string BACKGROUNDCOLOR = "bgcolor";
|
||||
|
||||
/** attribute of the table/cell tag */
|
||||
public const string BORDERCOLOR = "bordercolor";
|
||||
|
||||
/** attribute of paragraph/image/table tag */
|
||||
public const string ALIGN = "align";
|
||||
|
||||
/** attribute of chapter/section/paragraph/table/cell tag */
|
||||
public const string LEFT = "left";
|
||||
|
||||
/** attribute of chapter/section/paragraph/table/cell tag */
|
||||
public const string RIGHT = "right";
|
||||
|
||||
/** attribute of the cell tag */
|
||||
public const string HORIZONTALALIGN = "align";
|
||||
|
||||
/** attribute of the cell tag */
|
||||
public const string VERTICALALIGN = "valign";
|
||||
|
||||
/** attribute of the table/cell tag */
|
||||
public const string TOP = "top";
|
||||
|
||||
/** attribute of the table/cell tag */
|
||||
public const string BOTTOM = "bottom";
|
||||
|
||||
// Misc
|
||||
|
||||
/** the image tag */
|
||||
public const string IMAGE = "img";
|
||||
|
||||
/** attribute of the image tag */
|
||||
public const string URL = "src";
|
||||
|
||||
/** attribute of the image tag */
|
||||
public const string ALT = "alt";
|
||||
|
||||
/** attribute of the image tag */
|
||||
public const string PLAINWIDTH = "width";
|
||||
|
||||
/** attribute of the image tag */
|
||||
public const string PLAINHEIGHT = "height";
|
||||
|
||||
/** the newpage tag */
|
||||
public const string NEWLINE = "br";
|
||||
|
||||
// alignment attribute values
|
||||
|
||||
/** the possible value of an alignment attribute */
|
||||
public const string ALIGN_LEFT = "Left";
|
||||
|
||||
/** the possible value of an alignment attribute */
|
||||
public const string ALIGN_CENTER = "Center";
|
||||
|
||||
/** the possible value of an alignment attribute */
|
||||
public const string ALIGN_RIGHT = "Right";
|
||||
|
||||
/** the possible value of an alignment attribute */
|
||||
public const string ALIGN_JUSTIFIED = "Justify";
|
||||
|
||||
/** the possible value of an alignment attribute */
|
||||
public const string ALIGN_TOP = "Top";
|
||||
|
||||
/** the possible value of an alignment attribute */
|
||||
public const string ALIGN_MIDDLE = "Middle";
|
||||
|
||||
/** the possible value of an alignment attribute */
|
||||
public const string ALIGN_BOTTOM = "Bottom";
|
||||
|
||||
/** the possible value of an alignment attribute */
|
||||
public const string ALIGN_BASELINE = "Baseline";
|
||||
|
||||
/** the possible value of an alignment attribute */
|
||||
public const string DEFAULT = "Default";
|
||||
|
||||
/** The DIV tag. */
|
||||
public const string DIV = "div";
|
||||
|
||||
/** The SPAN tag. */
|
||||
public const string SPAN = "span";
|
||||
/** The LINK tag. */
|
||||
public const string LINK = "link";
|
||||
|
||||
/** This is a possible HTML attribute for the LINK tag. */
|
||||
public const string TEXT_CSS = "text/css";
|
||||
|
||||
/** This is a possible HTML attribute for the LINK tag. */
|
||||
public const string REL = "rel";
|
||||
|
||||
/** This is used for inline css style information */
|
||||
public const string STYLE = "style";
|
||||
|
||||
/** This is a possible HTML attribute for the LINK tag. */
|
||||
public const string TYPE = "type";
|
||||
|
||||
/** This is a possible HTML attribute. */
|
||||
public const string STYLESHEET = "stylesheet";
|
||||
}
|
||||
}
|
||||
1041
iTechSharp/iTextSharp/text/html/HtmlWriter.cs
Normal file
1041
iTechSharp/iTextSharp/text/html/HtmlWriter.cs
Normal file
File diff suppressed because it is too large
Load Diff
239
iTechSharp/iTextSharp/text/html/ITextmyHtmlHandler.cs
Normal file
239
iTechSharp/iTextSharp/text/html/ITextmyHtmlHandler.cs
Normal file
@@ -0,0 +1,239 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Globalization;
|
||||
using System.util;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.xml;
|
||||
using iTextSharp.text.pdf;
|
||||
using iTextSharp.text.factories;
|
||||
|
||||
/*
|
||||
* $Id: ITextmyHtmlHandler.cs,v 1.9 2008/05/13 11:25:15 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.html {
|
||||
|
||||
/**
|
||||
* The <CODE>Tags</CODE>-class maps several XHTML-tags to iText-objects.
|
||||
*/
|
||||
|
||||
public class ITextmyHtmlHandler : ITextHandler {
|
||||
|
||||
/** These are the properties of the body section. */
|
||||
private Properties bodyAttributes = new Properties();
|
||||
|
||||
/** This is the status of the table border. */
|
||||
private bool tableBorder = false;
|
||||
|
||||
/**
|
||||
* Constructs a new SAXiTextHandler that will translate all the events
|
||||
* triggered by the parser to actions on the <CODE>Document</CODE>-object.
|
||||
*
|
||||
* @param document this is the document on which events must be triggered
|
||||
*/
|
||||
|
||||
public ITextmyHtmlHandler(IDocListener document) : base(document, new HtmlTagMap()) {
|
||||
}
|
||||
|
||||
public ITextmyHtmlHandler(IDocListener document, BaseFont bf) : base(document, new HtmlTagMap(), bf) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new SAXiTextHandler that will translate all the events
|
||||
* triggered by the parser to actions on the <CODE>Document</CODE>-object.
|
||||
*
|
||||
* @param document this is the document on which events must be triggered
|
||||
* @param htmlTags a tagmap translating HTML tags to iText tags
|
||||
*/
|
||||
|
||||
public ITextmyHtmlHandler(IDocListener document, Hashtable htmlTags) : base(document, htmlTags) {
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a start tag is encountered.
|
||||
*
|
||||
* @param uri the Uniform Resource Identifier
|
||||
* @param lname the local name (without prefix), or the empty string if Namespace processing is not being performed.
|
||||
* @param name the name of the tag that is encountered
|
||||
* @param attrs the list of attributes
|
||||
*/
|
||||
|
||||
public override void StartElement(String uri, String lname, String name, Hashtable attrs) {
|
||||
//System.err.Println("Start: " + name);
|
||||
|
||||
// super.handleStartingTags is replaced with handleStartingTags
|
||||
// suggestion by Vu Ngoc Tan/Hop
|
||||
name = name.ToLower(CultureInfo.InvariantCulture);
|
||||
if (HtmlTagMap.IsHtml(name)) {
|
||||
// we do nothing
|
||||
return;
|
||||
}
|
||||
if (HtmlTagMap.IsHead(name)) {
|
||||
// we do nothing
|
||||
return;
|
||||
}
|
||||
if (HtmlTagMap.IsTitle(name)) {
|
||||
// we do nothing
|
||||
return;
|
||||
}
|
||||
if (HtmlTagMap.IsMeta(name)) {
|
||||
// we look if we can change the body attributes
|
||||
String meta = null;
|
||||
String content = null;
|
||||
if (attrs != null) {
|
||||
foreach (String attribute in attrs.Keys) {
|
||||
if (Util.EqualsIgnoreCase(attribute, HtmlTags.CONTENT))
|
||||
content = (String)attrs[attribute];
|
||||
else if (Util.EqualsIgnoreCase(attribute, HtmlTags.NAME))
|
||||
meta = (String)attrs[attribute];
|
||||
}
|
||||
}
|
||||
if (meta != null && content != null) {
|
||||
bodyAttributes.Add(meta, content);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (HtmlTagMap.IsLink(name)) {
|
||||
// we do nothing for the moment, in a later version we could extract the style sheet
|
||||
return;
|
||||
}
|
||||
if (HtmlTagMap.IsBody(name)) {
|
||||
// maybe we could extract some info about the document: color, margins,...
|
||||
// but that's for a later version...
|
||||
XmlPeer peer = new XmlPeer(ElementTags.ITEXT, name);
|
||||
peer.AddAlias(ElementTags.TOP, HtmlTags.TOPMARGIN);
|
||||
peer.AddAlias(ElementTags.BOTTOM, HtmlTags.BOTTOMMARGIN);
|
||||
peer.AddAlias(ElementTags.RIGHT, HtmlTags.RIGHTMARGIN);
|
||||
peer.AddAlias(ElementTags.LEFT, HtmlTags.LEFTMARGIN);
|
||||
bodyAttributes.AddAll(peer.GetAttributes(attrs));
|
||||
HandleStartingTags(peer.Tag, bodyAttributes);
|
||||
return;
|
||||
}
|
||||
if (myTags.ContainsKey(name)) {
|
||||
XmlPeer peer = (XmlPeer) myTags[name];
|
||||
if (ElementTags.TABLE.Equals(peer.Tag) || ElementTags.CELL.Equals(peer.Tag)) {
|
||||
Properties p = peer.GetAttributes(attrs);
|
||||
String value;
|
||||
if (ElementTags.TABLE.Equals(peer.Tag) && (value = p[ElementTags.BORDERWIDTH]) != null) {
|
||||
if (float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo) > 0) {
|
||||
tableBorder = true;
|
||||
}
|
||||
}
|
||||
if (tableBorder) {
|
||||
p.Add(ElementTags.LEFT, "true");
|
||||
p.Add(ElementTags.RIGHT, "true");
|
||||
p.Add(ElementTags.TOP, "true");
|
||||
p.Add(ElementTags.BOTTOM, "true");
|
||||
}
|
||||
HandleStartingTags(peer.Tag, p);
|
||||
return;
|
||||
}
|
||||
HandleStartingTags(peer.Tag, peer.GetAttributes(attrs));
|
||||
return;
|
||||
}
|
||||
Properties attributes = new Properties();
|
||||
if (attrs != null) {
|
||||
foreach (String attribute in attrs.Keys) {
|
||||
attributes.Add(attribute.ToLower(CultureInfo.InvariantCulture), ((String)attrs[attribute]).ToLower(CultureInfo.InvariantCulture));
|
||||
}
|
||||
}
|
||||
HandleStartingTags(name, attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when an end tag is encountered.
|
||||
*
|
||||
* @param uri the Uniform Resource Identifier
|
||||
* @param lname the local name (without prefix), or the empty string if Namespace processing is not being performed.
|
||||
* @param name the name of the tag that ends
|
||||
*/
|
||||
|
||||
public override void EndElement(String uri, String lname, String name) {
|
||||
//System.err.Println("End: " + name);
|
||||
name = name.ToLower(CultureInfo.InvariantCulture);
|
||||
if (ElementTags.PARAGRAPH.Equals(name)) {
|
||||
document.Add((IElement) stack.Pop());
|
||||
return;
|
||||
}
|
||||
if (HtmlTagMap.IsHead(name)) {
|
||||
// we do nothing
|
||||
return;
|
||||
}
|
||||
if (HtmlTagMap.IsTitle(name)) {
|
||||
if (currentChunk != null) {
|
||||
bodyAttributes.Add(ElementTags.TITLE, currentChunk.Content);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (HtmlTagMap.IsMeta(name)) {
|
||||
// we do nothing
|
||||
return;
|
||||
}
|
||||
if (HtmlTagMap.IsLink(name)) {
|
||||
// we do nothing
|
||||
return;
|
||||
}
|
||||
if (HtmlTagMap.IsBody(name)) {
|
||||
// we do nothing
|
||||
return;
|
||||
}
|
||||
if (myTags.ContainsKey(name)) {
|
||||
XmlPeer peer = (XmlPeer) myTags[name];
|
||||
if (ElementTags.TABLE.Equals(peer.Tag)) {
|
||||
tableBorder = false;
|
||||
}
|
||||
base.HandleEndingTags(peer.Tag);
|
||||
return;
|
||||
}
|
||||
// super.handleEndingTags is replaced with handleEndingTags
|
||||
// suggestion by Ken Auer
|
||||
HandleEndingTags(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
427
iTechSharp/iTextSharp/text/html/Markup.cs
Normal file
427
iTechSharp/iTextSharp/text/html/Markup.cs
Normal file
@@ -0,0 +1,427 @@
|
||||
using System;
|
||||
using System.util;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using System.Globalization;
|
||||
using iTextSharp.text;
|
||||
|
||||
/*
|
||||
* $Id: Markup.cs,v 1.2 2008/05/13 11:25:16 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.html {
|
||||
/// <summary>
|
||||
/// A class that contains all the possible tagnames and their attributes.
|
||||
/// </summary>
|
||||
public class Markup {
|
||||
// iText specific
|
||||
|
||||
/** the key for any tag */
|
||||
public const string ITEXT_TAG = "tag";
|
||||
|
||||
// HTML tags
|
||||
|
||||
/** the markup for the body part of a file */
|
||||
public const string HTML_TAG_BODY = "body";
|
||||
|
||||
/** The DIV tag. */
|
||||
public const string HTML_TAG_DIV = "div";
|
||||
|
||||
/** This is a possible HTML-tag. */
|
||||
public const string HTML_TAG_LINK = "link";
|
||||
|
||||
/** The SPAN tag. */
|
||||
public const string HTML_TAG_SPAN = "span";
|
||||
|
||||
// HTML attributes
|
||||
|
||||
/** the height attribute. */
|
||||
public const string HTML_ATTR_HEIGHT = "height";
|
||||
|
||||
/** the hyperlink reference attribute. */
|
||||
public const string HTML_ATTR_HREF = "href";
|
||||
|
||||
/** This is a possible HTML attribute for the LINK tag. */
|
||||
public const string HTML_ATTR_REL = "rel";
|
||||
|
||||
/** This is used for inline css style information */
|
||||
public const string HTML_ATTR_STYLE = "style";
|
||||
|
||||
/** This is a possible HTML attribute for the LINK tag. */
|
||||
public const string HTML_ATTR_TYPE = "type";
|
||||
|
||||
/** This is a possible HTML attribute. */
|
||||
public const string HTML_ATTR_STYLESHEET = "stylesheet";
|
||||
|
||||
/** the width attribute. */
|
||||
public const string HTML_ATTR_WIDTH = "width";
|
||||
|
||||
/** attribute for specifying externally defined CSS class */
|
||||
public const string HTML_ATTR_CSS_CLASS = "class";
|
||||
|
||||
/** The ID attribute. */
|
||||
public const string HTML_ATTR_CSS_ID = "id";
|
||||
|
||||
// HTML values
|
||||
|
||||
/** This is a possible value for the language attribute (SCRIPT tag). */
|
||||
public const string HTML_VALUE_JAVASCRIPT = "text/javascript";
|
||||
|
||||
/** This is a possible HTML attribute for the LINK tag. */
|
||||
public const string HTML_VALUE_CSS = "text/css";
|
||||
|
||||
// CSS keys
|
||||
|
||||
/** the CSS tag for background color */
|
||||
public const string CSS_KEY_BGCOLOR = "background-color";
|
||||
|
||||
/** the CSS tag for text color */
|
||||
public const string CSS_KEY_COLOR = "color";
|
||||
|
||||
/** CSS key that indicate the way something has to be displayed */
|
||||
public const string CSS_KEY_DISPLAY = "display";
|
||||
|
||||
/** the CSS tag for the font family */
|
||||
public const string CSS_KEY_FONTFAMILY = "font-family";
|
||||
|
||||
/** the CSS tag for the font size */
|
||||
public const string CSS_KEY_FONTSIZE = "font-size";
|
||||
|
||||
/** the CSS tag for the font style */
|
||||
public const string CSS_KEY_FONTSTYLE = "font-style";
|
||||
|
||||
/** the CSS tag for the font weight */
|
||||
public const string CSS_KEY_FONTWEIGHT = "font-weight";
|
||||
|
||||
/** the CSS tag for text decorations */
|
||||
public const string CSS_KEY_LINEHEIGHT = "line-height";
|
||||
|
||||
/** the CSS tag for the margin of an object */
|
||||
public const string CSS_KEY_MARGIN = "margin";
|
||||
|
||||
/** the CSS tag for the margin of an object */
|
||||
public const string CSS_KEY_MARGINLEFT = "margin-left";
|
||||
|
||||
/** the CSS tag for the margin of an object */
|
||||
public const string CSS_KEY_MARGINRIGHT = "margin-right";
|
||||
|
||||
/** the CSS tag for the margin of an object */
|
||||
public const string CSS_KEY_MARGINTOP = "margin-top";
|
||||
|
||||
/** the CSS tag for the margin of an object */
|
||||
public const string CSS_KEY_MARGINBOTTOM = "margin-bottom";
|
||||
|
||||
/** the CSS tag for the margin of an object */
|
||||
public const String CSS_KEY_PADDING = "padding";
|
||||
|
||||
/** the CSS tag for the margin of an object */
|
||||
public const String CSS_KEY_PADDINGLEFT = "padding-left";
|
||||
|
||||
/** the CSS tag for the margin of an object */
|
||||
public const String CSS_KEY_PADDINGRIGHT = "padding-right";
|
||||
|
||||
/** the CSS tag for the margin of an object */
|
||||
public const String CSS_KEY_PADDINGTOP = "padding-top";
|
||||
|
||||
/** the CSS tag for the margin of an object */
|
||||
public const String CSS_KEY_PADDINGBOTTOM = "padding-bottom";
|
||||
|
||||
/** the CSS tag for the margin of an object */
|
||||
public const String CSS_KEY_BORDERCOLOR = "border-color";
|
||||
|
||||
/** the CSS tag for the margin of an object */
|
||||
public const String CSS_KEY_BORDERWIDTH = "border-width";
|
||||
|
||||
/** the CSS tag for the margin of an object */
|
||||
public const String CSS_KEY_BORDERWIDTHLEFT = "border-left-width";
|
||||
|
||||
/** the CSS tag for the margin of an object */
|
||||
public const String CSS_KEY_BORDERWIDTHRIGHT = "border-right-width";
|
||||
|
||||
/** the CSS tag for the margin of an object */
|
||||
public const String CSS_KEY_BORDERWIDTHTOP = "border-top-width";
|
||||
|
||||
/** the CSS tag for the margin of an object */
|
||||
public const String CSS_KEY_BORDERWIDTHBOTTOM = "border-bottom-width";
|
||||
|
||||
/** the CSS tag for adding a page break when the document is printed */
|
||||
public const string CSS_KEY_PAGE_BREAK_AFTER = "page-break-after";
|
||||
|
||||
/** the CSS tag for adding a page break when the document is printed */
|
||||
public const string CSS_KEY_PAGE_BREAK_BEFORE = "page-break-before";
|
||||
|
||||
/** the CSS tag for the horizontal alignment of an object */
|
||||
public const string CSS_KEY_TEXTALIGN = "text-align";
|
||||
|
||||
/** the CSS tag for text decorations */
|
||||
public const string CSS_KEY_TEXTDECORATION = "text-decoration";
|
||||
|
||||
/** the CSS tag for text decorations */
|
||||
public const string CSS_KEY_VERTICALALIGN = "vertical-align";
|
||||
|
||||
/** the CSS tag for the visibility of objects */
|
||||
public const string CSS_KEY_VISIBILITY = "visibility";
|
||||
|
||||
// CSS values
|
||||
|
||||
/** value for the CSS tag for adding a page break when the document is printed */
|
||||
public const string CSS_VALUE_ALWAYS = "always";
|
||||
|
||||
/** A possible value for the DISPLAY key */
|
||||
public const string CSS_VALUE_BLOCK = "block";
|
||||
|
||||
/** a CSS value for text font weight */
|
||||
public const string CSS_VALUE_BOLD = "bold";
|
||||
|
||||
/** the value if you want to hide objects. */
|
||||
public const string CSS_VALUE_HIDDEN = "hidden";
|
||||
|
||||
/** A possible value for the DISPLAY key */
|
||||
public const string CSS_VALUE_INLINE = "inline";
|
||||
|
||||
/** a CSS value for text font style */
|
||||
public const string CSS_VALUE_ITALIC = "italic";
|
||||
|
||||
/** a CSS value for text decoration */
|
||||
public const string CSS_VALUE_LINETHROUGH = "line-through";
|
||||
|
||||
/** A possible value for the DISPLAY key */
|
||||
public const string CSS_VALUE_LISTITEM = "list-item";
|
||||
|
||||
/** a CSS value */
|
||||
public const string CSS_VALUE_NONE = "none";
|
||||
|
||||
/** a CSS value */
|
||||
public const string CSS_VALUE_NORMAL = "normal";
|
||||
|
||||
/** a CSS value for text font style */
|
||||
public const string CSS_VALUE_OBLIQUE = "oblique";
|
||||
|
||||
/** A possible value for the DISPLAY key */
|
||||
public const string CSS_VALUE_TABLE = "table";
|
||||
|
||||
/** A possible value for the DISPLAY key */
|
||||
public const string CSS_VALUE_TABLEROW = "table-row";
|
||||
|
||||
/** A possible value for the DISPLAY key */
|
||||
public const string CSS_VALUE_TABLECELL = "table-cell";
|
||||
|
||||
/** the CSS value for a horizontal alignment of an object */
|
||||
public const string CSS_VALUE_TEXTALIGNLEFT = "left";
|
||||
|
||||
/** the CSS value for a horizontal alignment of an object */
|
||||
public const string CSS_VALUE_TEXTALIGNRIGHT = "right";
|
||||
|
||||
/** the CSS value for a horizontal alignment of an object */
|
||||
public const string CSS_VALUE_TEXTALIGNCENTER = "center";
|
||||
|
||||
/** the CSS value for a horizontal alignment of an object */
|
||||
public const string CSS_VALUE_TEXTALIGNJUSTIFY = "justify";
|
||||
|
||||
/** a CSS value for text decoration */
|
||||
public const string CSS_VALUE_UNDERLINE = "underline";
|
||||
|
||||
/// <summary>
|
||||
/// Parses a length.
|
||||
/// </summary>
|
||||
/// <param name="str">a length in the form of an optional + or -, followed by a number and a unit.</param>
|
||||
/// <returns>a float</returns>
|
||||
public static float ParseLength(string str) {
|
||||
int pos = 0;
|
||||
int length = str.Length;
|
||||
bool ok = true;
|
||||
while (ok && pos < length) {
|
||||
switch (str[pos]) {
|
||||
case '+':
|
||||
case '-':
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
case '.':
|
||||
pos++;
|
||||
break;
|
||||
default:
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (pos == 0) return 0f;
|
||||
if (pos == length) return float.Parse(str, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
float f = float.Parse(str.Substring(0, pos), System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
str = str.Substring(pos);
|
||||
// inches
|
||||
if (str.StartsWith("in")) {
|
||||
return f * 72f;
|
||||
}
|
||||
// centimeters
|
||||
if (str.StartsWith("cm")) {
|
||||
return (f / 2.54f) * 72f;
|
||||
}
|
||||
// millimeters
|
||||
if (str.StartsWith("mm")) {
|
||||
return (f / 25.4f) * 72f;
|
||||
}
|
||||
// picas
|
||||
if (str.StartsWith("pc")) {
|
||||
return f * 12f;
|
||||
}
|
||||
// default: we assume the length was measured in points
|
||||
return f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a <CODE>Color</CODE> into a HTML representation of this <CODE>Color</CODE>.
|
||||
/// </summary>
|
||||
/// <param name="color">the <CODE>Color</CODE> that has to be converted.</param>
|
||||
/// <returns>the HTML representation of this <CODE>Color</CODE></returns>
|
||||
public static Color DecodeColor(String s) {
|
||||
if (s == null)
|
||||
return null;
|
||||
s = s.ToLower(CultureInfo.InvariantCulture).Trim();
|
||||
Color c = (Color)WebColors.GetRGBColor(s);
|
||||
if (c != null)
|
||||
return c;
|
||||
try {
|
||||
if (s.StartsWith("#")) {
|
||||
if (s.Length == 4)
|
||||
s = "#" + s.Substring(1, 1) + s.Substring(1, 1)
|
||||
+ s.Substring(2, 1) + s.Substring(2, 1)
|
||||
+ s.Substring(3, 1) + s.Substring(3, 1);
|
||||
if (s.Length == 7)
|
||||
return new Color(int.Parse(s.Substring(1), NumberStyles.HexNumber));
|
||||
}
|
||||
else if (s.StartsWith("rgb")) {
|
||||
StringTokenizer tk = new StringTokenizer(s.Substring(3), " \t\r\n\f(),");
|
||||
int[] cc = new int [3];
|
||||
for (int k = 0; k < 3; ++k) {
|
||||
if (!tk.HasMoreTokens())
|
||||
return null;
|
||||
String t = tk.NextToken();
|
||||
float n;
|
||||
if (t.EndsWith("%")) {
|
||||
n = float.Parse(t.Substring(0, t.Length - 1), System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
n = n * 255f / 100f;
|
||||
}
|
||||
else
|
||||
n = float.Parse(t, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
int ni = (int)n;
|
||||
if (ni > 255)
|
||||
ni = 255;
|
||||
else if (ni < 0)
|
||||
ni = 0;
|
||||
cc[k] = ni;
|
||||
}
|
||||
return new Color(cc[0], cc[1], cc[2]);
|
||||
}
|
||||
}
|
||||
catch {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method parses a string with attributes and returns a Properties object.
|
||||
/// </summary>
|
||||
/// <param name="str">a string of this form: 'key1="value1"; key2="value2";... keyN="valueN" '</param>
|
||||
/// <returns>a Properties object</returns>
|
||||
public static Properties ParseAttributes(string str) {
|
||||
Properties result = new Properties();
|
||||
if (str == null) return result;
|
||||
StringTokenizer keyValuePairs = new StringTokenizer(str, ";");
|
||||
StringTokenizer keyValuePair;
|
||||
string key;
|
||||
string value;
|
||||
while (keyValuePairs.HasMoreTokens()) {
|
||||
keyValuePair = new StringTokenizer(keyValuePairs.NextToken(), ":");
|
||||
if (keyValuePair.HasMoreTokens()) key = keyValuePair.NextToken().Trim().Trim();
|
||||
else continue;
|
||||
if (keyValuePair.HasMoreTokens()) value = keyValuePair.NextToken().Trim();
|
||||
else continue;
|
||||
if (value.StartsWith("\"")) value = value.Substring(1);
|
||||
if (value.EndsWith("\"")) value = value.Substring(0, value.Length - 1);
|
||||
result.Add(key.ToLower(CultureInfo.InvariantCulture), value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the comments sections of a String.
|
||||
*
|
||||
* @param string
|
||||
* the original String
|
||||
* @param startComment
|
||||
* the String that marks the start of a Comment section
|
||||
* @param endComment
|
||||
* the String that marks the end of a Comment section.
|
||||
* @return the String stripped of its comment section
|
||||
*/
|
||||
public static string RemoveComment(String str, String startComment,
|
||||
String endComment) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
int pos = 0;
|
||||
int end = endComment.Length;
|
||||
int start = str.IndexOf(startComment, pos);
|
||||
while (start > -1) {
|
||||
result.Append(str.Substring(pos, start - pos));
|
||||
pos = str.IndexOf(endComment, start) + end;
|
||||
start = str.IndexOf(startComment, pos);
|
||||
}
|
||||
result.Append(str.Substring(pos));
|
||||
return result.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
263
iTechSharp/iTextSharp/text/html/WebColors.cs
Normal file
263
iTechSharp/iTextSharp/text/html/WebColors.cs
Normal file
@@ -0,0 +1,263 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Globalization;
|
||||
using iTextSharp.text;
|
||||
using System.util;
|
||||
/*
|
||||
* $Id: WebColors.cs,v 1.3 2008/05/13 11:25:16 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.html {
|
||||
|
||||
/**
|
||||
* This class is a HashMap that contains the names of colors as a key and the
|
||||
* corresponding Color as value. (Source: Wikipedia
|
||||
* http://en.wikipedia.org/wiki/Web_colors )
|
||||
*
|
||||
* @author blowagie
|
||||
*/
|
||||
public class WebColors : Hashtable {
|
||||
|
||||
public static WebColors NAMES = new WebColors();
|
||||
static WebColors() {
|
||||
NAMES["aliceblue"] = new int[] { 0xf0, 0xf8, 0xff, 0x00 };
|
||||
NAMES["antiquewhite"] = new int[] { 0xfa, 0xeb, 0xd7, 0x00 };
|
||||
NAMES["aqua"] = new int[] { 0x00, 0xff, 0xff, 0x00 };
|
||||
NAMES["aquamarine"] = new int[] { 0x7f, 0xff, 0xd4, 0x00 };
|
||||
NAMES["azure"] = new int[] { 0xf0, 0xff, 0xff, 0x00 };
|
||||
NAMES["beige"] = new int[] { 0xf5, 0xf5, 0xdc, 0x00 };
|
||||
NAMES["bisque"] = new int[] { 0xff, 0xe4, 0xc4, 0x00 };
|
||||
NAMES["black"] = new int[] { 0x00, 0x00, 0x00, 0x00 };
|
||||
NAMES["blanchedalmond"] = new int[] { 0xff, 0xeb, 0xcd, 0x00 };
|
||||
NAMES["blue"] = new int[] { 0x00, 0x00, 0xff, 0x00 };
|
||||
NAMES["blueviolet"] = new int[] { 0x8a, 0x2b, 0xe2, 0x00 };
|
||||
NAMES["brown"] = new int[] { 0xa5, 0x2a, 0x2a, 0x00 };
|
||||
NAMES["burlywood"] = new int[] { 0xde, 0xb8, 0x87, 0x00 };
|
||||
NAMES["cadetblue"] = new int[] { 0x5f, 0x9e, 0xa0, 0x00 };
|
||||
NAMES["chartreuse"] = new int[] { 0x7f, 0xff, 0x00, 0x00 };
|
||||
NAMES["chocolate"] = new int[] { 0xd2, 0x69, 0x1e, 0x00 };
|
||||
NAMES["coral"] = new int[] { 0xff, 0x7f, 0x50, 0x00 };
|
||||
NAMES["cornflowerblue"] = new int[] { 0x64, 0x95, 0xed, 0x00 };
|
||||
NAMES["cornsilk"] = new int[] { 0xff, 0xf8, 0xdc, 0x00 };
|
||||
NAMES["crimson"] = new int[] { 0xdc, 0x14, 0x3c, 0x00 };
|
||||
NAMES["cyan"] = new int[] { 0x00, 0xff, 0xff, 0x00 };
|
||||
NAMES["darkblue"] = new int[] { 0x00, 0x00, 0x8b, 0x00 };
|
||||
NAMES["darkcyan"] = new int[] { 0x00, 0x8b, 0x8b, 0x00 };
|
||||
NAMES["darkgoldenrod"] = new int[] { 0xb8, 0x86, 0x0b, 0x00 };
|
||||
NAMES["darkgray"] = new int[] { 0xa9, 0xa9, 0xa9, 0x00 };
|
||||
NAMES["darkgreen"] = new int[] { 0x00, 0x64, 0x00, 0x00 };
|
||||
NAMES["darkkhaki"] = new int[] { 0xbd, 0xb7, 0x6b, 0x00 };
|
||||
NAMES["darkmagenta"] = new int[] { 0x8b, 0x00, 0x8b, 0x00 };
|
||||
NAMES["darkolivegreen"] = new int[] { 0x55, 0x6b, 0x2f, 0x00 };
|
||||
NAMES["darkorange"] = new int[] { 0xff, 0x8c, 0x00, 0x00 };
|
||||
NAMES["darkorchid"] = new int[] { 0x99, 0x32, 0xcc, 0x00 };
|
||||
NAMES["darkred"] = new int[] { 0x8b, 0x00, 0x00, 0x00 };
|
||||
NAMES["darksalmon"] = new int[] { 0xe9, 0x96, 0x7a, 0x00 };
|
||||
NAMES["darkseagreen"] = new int[] { 0x8f, 0xbc, 0x8f, 0x00 };
|
||||
NAMES["darkslateblue"] = new int[] { 0x48, 0x3d, 0x8b, 0x00 };
|
||||
NAMES["darkslategray"] = new int[] { 0x2f, 0x4f, 0x4f, 0x00 };
|
||||
NAMES["darkturquoise"] = new int[] { 0x00, 0xce, 0xd1, 0x00 };
|
||||
NAMES["darkviolet"] = new int[] { 0x94, 0x00, 0xd3, 0x00 };
|
||||
NAMES["deeppink"] = new int[] { 0xff, 0x14, 0x93, 0x00 };
|
||||
NAMES["deepskyblue"] = new int[] { 0x00, 0xbf, 0xff, 0x00 };
|
||||
NAMES["dimgray"] = new int[] { 0x69, 0x69, 0x69, 0x00 };
|
||||
NAMES["dodgerblue"] = new int[] { 0x1e, 0x90, 0xff, 0x00 };
|
||||
NAMES["firebrick"] = new int[] { 0xb2, 0x22, 0x22, 0x00 };
|
||||
NAMES["floralwhite"] = new int[] { 0xff, 0xfa, 0xf0, 0x00 };
|
||||
NAMES["forestgreen"] = new int[] { 0x22, 0x8b, 0x22, 0x00 };
|
||||
NAMES["fuchsia"] = new int[] { 0xff, 0x00, 0xff, 0x00 };
|
||||
NAMES["gainsboro"] = new int[] { 0xdc, 0xdc, 0xdc, 0x00 };
|
||||
NAMES["ghostwhite"] = new int[] { 0xf8, 0xf8, 0xff, 0x00 };
|
||||
NAMES["gold"] = new int[] { 0xff, 0xd7, 0x00, 0x00 };
|
||||
NAMES["goldenrod"] = new int[] { 0xda, 0xa5, 0x20, 0x00 };
|
||||
NAMES["gray"] = new int[] { 0x80, 0x80, 0x80, 0x00 };
|
||||
NAMES["green"] = new int[] { 0x00, 0x80, 0x00, 0x00 };
|
||||
NAMES["greenyellow"] = new int[] { 0xad, 0xff, 0x2f, 0x00 };
|
||||
NAMES["honeydew"] = new int[] { 0xf0, 0xff, 0xf0, 0x00 };
|
||||
NAMES["hotpink"] = new int[] { 0xff, 0x69, 0xb4, 0x00 };
|
||||
NAMES["indianred"] = new int[] { 0xcd, 0x5c, 0x5c, 0x00 };
|
||||
NAMES["indigo"] = new int[] { 0x4b, 0x00, 0x82, 0x00 };
|
||||
NAMES["ivory"] = new int[] { 0xff, 0xff, 0xf0, 0x00 };
|
||||
NAMES["khaki"] = new int[] { 0xf0, 0xe6, 0x8c, 0x00 };
|
||||
NAMES["lavender"] = new int[] { 0xe6, 0xe6, 0xfa, 0x00 };
|
||||
NAMES["lavenderblush"] = new int[] { 0xff, 0xf0, 0xf5, 0x00 };
|
||||
NAMES["lawngreen"] = new int[] { 0x7c, 0xfc, 0x00, 0x00 };
|
||||
NAMES["lemonchiffon"] = new int[] { 0xff, 0xfa, 0xcd, 0x00 };
|
||||
NAMES["lightblue"] = new int[] { 0xad, 0xd8, 0xe6, 0x00 };
|
||||
NAMES["lightcoral"] = new int[] { 0xf0, 0x80, 0x80, 0x00 };
|
||||
NAMES["lightcyan"] = new int[] { 0xe0, 0xff, 0xff, 0x00 };
|
||||
NAMES["lightgoldenrodyellow"] = new int[] { 0xfa, 0xfa, 0xd2, 0x00 };
|
||||
NAMES["lightgreen"] = new int[] { 0x90, 0xee, 0x90, 0x00 };
|
||||
NAMES["lightgrey"] = new int[] { 0xd3, 0xd3, 0xd3, 0x00 };
|
||||
NAMES["lightpink"] = new int[] { 0xff, 0xb6, 0xc1, 0x00 };
|
||||
NAMES["lightsalmon"] = new int[] { 0xff, 0xa0, 0x7a, 0x00 };
|
||||
NAMES["lightseagreen"] = new int[] { 0x20, 0xb2, 0xaa, 0x00 };
|
||||
NAMES["lightskyblue"] = new int[] { 0x87, 0xce, 0xfa, 0x00 };
|
||||
NAMES["lightslategray"] = new int[] { 0x77, 0x88, 0x99, 0x00 };
|
||||
NAMES["lightsteelblue"] = new int[] { 0xb0, 0xc4, 0xde, 0x00 };
|
||||
NAMES["lightyellow"] = new int[] { 0xff, 0xff, 0xe0, 0x00 };
|
||||
NAMES["lime"] = new int[] { 0x00, 0xff, 0x00, 0x00 };
|
||||
NAMES["limegreen"] = new int[] { 0x32, 0xcd, 0x32, 0x00 };
|
||||
NAMES["linen"] = new int[] { 0xfa, 0xf0, 0xe6, 0x00 };
|
||||
NAMES["magenta"] = new int[] { 0xff, 0x00, 0xff, 0x00 };
|
||||
NAMES["maroon"] = new int[] { 0x80, 0x00, 0x00, 0x00 };
|
||||
NAMES["mediumaquamarine"] = new int[] { 0x66, 0xcd, 0xaa, 0x00 };
|
||||
NAMES["mediumblue"] = new int[] { 0x00, 0x00, 0xcd, 0x00 };
|
||||
NAMES["mediumorchid"] = new int[] { 0xba, 0x55, 0xd3, 0x00 };
|
||||
NAMES["mediumpurple"] = new int[] { 0x93, 0x70, 0xdb, 0x00 };
|
||||
NAMES["mediumseagreen"] = new int[] { 0x3c, 0xb3, 0x71, 0x00 };
|
||||
NAMES["mediumslateblue"] = new int[] { 0x7b, 0x68, 0xee, 0x00 };
|
||||
NAMES["mediumspringgreen"] = new int[] { 0x00, 0xfa, 0x9a, 0x00 };
|
||||
NAMES["mediumturquoise"] = new int[] { 0x48, 0xd1, 0xcc, 0x00 };
|
||||
NAMES["mediumvioletred"] = new int[] { 0xc7, 0x15, 0x85, 0x00 };
|
||||
NAMES["midnightblue"] = new int[] { 0x19, 0x19, 0x70, 0x00 };
|
||||
NAMES["mintcream"] = new int[] { 0xf5, 0xff, 0xfa, 0x00 };
|
||||
NAMES["mistyrose"] = new int[] { 0xff, 0xe4, 0xe1, 0x00 };
|
||||
NAMES["moccasin"] = new int[] { 0xff, 0xe4, 0xb5, 0x00 };
|
||||
NAMES["navajowhite"] = new int[] { 0xff, 0xde, 0xad, 0x00 };
|
||||
NAMES["navy"] = new int[] { 0x00, 0x00, 0x80, 0x00 };
|
||||
NAMES["oldlace"] = new int[] { 0xfd, 0xf5, 0xe6, 0x00 };
|
||||
NAMES["olive"] = new int[] { 0x80, 0x80, 0x00, 0x00 };
|
||||
NAMES["olivedrab"] = new int[] { 0x6b, 0x8e, 0x23, 0x00 };
|
||||
NAMES["orange"] = new int[] { 0xff, 0xa5, 0x00, 0x00 };
|
||||
NAMES["orangered"] = new int[] { 0xff, 0x45, 0x00, 0x00 };
|
||||
NAMES["orchid"] = new int[] { 0xda, 0x70, 0xd6, 0x00 };
|
||||
NAMES["palegoldenrod"] = new int[] { 0xee, 0xe8, 0xaa, 0x00 };
|
||||
NAMES["palegreen"] = new int[] { 0x98, 0xfb, 0x98, 0x00 };
|
||||
NAMES["paleturquoise"] = new int[] { 0xaf, 0xee, 0xee, 0x00 };
|
||||
NAMES["palevioletred"] = new int[] { 0xdb, 0x70, 0x93, 0x00 };
|
||||
NAMES["papayawhip"] = new int[] { 0xff, 0xef, 0xd5, 0x00 };
|
||||
NAMES["peachpuff"] = new int[] { 0xff, 0xda, 0xb9, 0x00 };
|
||||
NAMES["peru"] = new int[] { 0xcd, 0x85, 0x3f, 0x00 };
|
||||
NAMES["pink"] = new int[] { 0xff, 0xc0, 0xcb, 0x00 };
|
||||
NAMES["plum"] = new int[] { 0xdd, 0xa0, 0xdd, 0x00 };
|
||||
NAMES["powderblue"] = new int[] { 0xb0, 0xe0, 0xe6, 0x00 };
|
||||
NAMES["purple"] = new int[] { 0x80, 0x00, 0x80, 0x00 };
|
||||
NAMES["red"] = new int[] { 0xff, 0x00, 0x00, 0x00 };
|
||||
NAMES["rosybrown"] = new int[] { 0xbc, 0x8f, 0x8f, 0x00 };
|
||||
NAMES["royalblue"] = new int[] { 0x41, 0x69, 0xe1, 0x00 };
|
||||
NAMES["saddlebrown"] = new int[] { 0x8b, 0x45, 0x13, 0x00 };
|
||||
NAMES["salmon"] = new int[] { 0xfa, 0x80, 0x72, 0x00 };
|
||||
NAMES["sandybrown"] = new int[] { 0xf4, 0xa4, 0x60, 0x00 };
|
||||
NAMES["seagreen"] = new int[] { 0x2e, 0x8b, 0x57, 0x00 };
|
||||
NAMES["seashell"] = new int[] { 0xff, 0xf5, 0xee, 0x00 };
|
||||
NAMES["sienna"] = new int[] { 0xa0, 0x52, 0x2d, 0x00 };
|
||||
NAMES["silver"] = new int[] { 0xc0, 0xc0, 0xc0, 0x00 };
|
||||
NAMES["skyblue"] = new int[] { 0x87, 0xce, 0xeb, 0x00 };
|
||||
NAMES["slateblue"] = new int[] { 0x6a, 0x5a, 0xcd, 0x00 };
|
||||
NAMES["slategray"] = new int[] { 0x70, 0x80, 0x90, 0x00 };
|
||||
NAMES["snow"] = new int[] { 0xff, 0xfa, 0xfa, 0x00 };
|
||||
NAMES["springgreen"] = new int[] { 0x00, 0xff, 0x7f, 0x00 };
|
||||
NAMES["steelblue"] = new int[] { 0x46, 0x82, 0xb4, 0x00 };
|
||||
NAMES["tan"] = new int[] { 0xd2, 0xb4, 0x8c, 0x00 };
|
||||
NAMES["transparent"] = new int[] { 0x00, 0x00, 0x00, 0xff };
|
||||
NAMES["teal"] = new int[] { 0x00, 0x80, 0x80, 0x00 };
|
||||
NAMES["thistle"] = new int[] { 0xd8, 0xbf, 0xd8, 0x00 };
|
||||
NAMES["tomato"] = new int[] { 0xff, 0x63, 0x47, 0x00 };
|
||||
NAMES["turquoise"] = new int[] { 0x40, 0xe0, 0xd0, 0x00 };
|
||||
NAMES["violet"] = new int[] { 0xee, 0x82, 0xee, 0x00 };
|
||||
NAMES["wheat"] = new int[] { 0xf5, 0xde, 0xb3, 0x00 };
|
||||
NAMES["white"] = new int[] { 0xff, 0xff, 0xff, 0x00 };
|
||||
NAMES["whitesmoke"] = new int[] { 0xf5, 0xf5, 0xf5, 0x00 };
|
||||
NAMES["yellow"] = new int[] { 0xff, 0xff, 0x00, 0x00 };
|
||||
NAMES["yellowgreen"] = new int[] { 0x9, 0xacd, 0x32, 0x00 };
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives you a Color based on a name.
|
||||
*
|
||||
* @param name
|
||||
* a name such as black, violet, cornflowerblue or #RGB or #RRGGBB
|
||||
* or rgb(R,G,B)
|
||||
* @return the corresponding Color object
|
||||
* @throws IllegalArgumentException
|
||||
* if the String isn't a know representation of a color.
|
||||
*/
|
||||
public static Color GetRGBColor(String name) {
|
||||
int[] c = { 0, 0, 0, 0 };
|
||||
if (name.StartsWith("#")) {
|
||||
if (name.Length == 4) {
|
||||
c[0] = int.Parse(name.Substring(1, 1), NumberStyles.HexNumber) * 16;
|
||||
c[1] = int.Parse(name.Substring(2, 1), NumberStyles.HexNumber) * 16;
|
||||
c[2] = int.Parse(name.Substring(3), NumberStyles.HexNumber) * 16;
|
||||
return new Color(c[0], c[1], c[2], c[3]);
|
||||
}
|
||||
if (name.Length == 7) {
|
||||
c[0] = int.Parse(name.Substring(1, 2), NumberStyles.HexNumber);
|
||||
c[1] = int.Parse(name.Substring(3, 2), NumberStyles.HexNumber);
|
||||
c[2] = int.Parse(name.Substring(5), NumberStyles.HexNumber);
|
||||
return new Color(c[0], c[1], c[2], c[3]);
|
||||
}
|
||||
throw new ArgumentException(
|
||||
"Unknown color format. Must be #RGB or #RRGGBB");
|
||||
}
|
||||
else if (name.StartsWith("rgb(")) {
|
||||
StringTokenizer tok = new StringTokenizer(name, "rgb(), \t\r\n\f");
|
||||
for (int k = 0; k < 3; ++k) {
|
||||
String v = tok.NextToken();
|
||||
if (v.EndsWith("%"))
|
||||
c[k] = int.Parse(v.Substring(0, v.Length - 1)) * 255 / 100;
|
||||
else
|
||||
c[k] = int.Parse(v);
|
||||
if (c[k] < 0)
|
||||
c[k] = 0;
|
||||
else if (c[k] > 255)
|
||||
c[k] = 255;
|
||||
}
|
||||
return new Color(c[0], c[1], c[2], c[3]);
|
||||
}
|
||||
name = name.ToLower(CultureInfo.InvariantCulture);
|
||||
if (!NAMES.ContainsKey(name))
|
||||
throw new ArgumentException("Color '" + name
|
||||
+ "' not found.");
|
||||
c = (int[]) NAMES[name];
|
||||
return new Color(c[0], c[1], c[2], c[3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
/*
|
||||
* Copyright 2004 Paulo Soares
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.html.simpleparser {
|
||||
|
||||
public class ChainedProperties {
|
||||
|
||||
public static int[] fontSizes = {8, 10, 12, 14, 18, 24, 36};
|
||||
public ArrayList chain = new ArrayList();
|
||||
|
||||
/** Creates a new instance of ChainedProperties */
|
||||
public ChainedProperties() {
|
||||
}
|
||||
|
||||
public String this[String key] {
|
||||
get {
|
||||
for (int k = chain.Count - 1; k >= 0; --k) {
|
||||
Object[] obj = (Object[])chain[k];
|
||||
Hashtable prop = (Hashtable)obj[1];
|
||||
String ret = (String)prop[key];
|
||||
if (ret != null)
|
||||
return ret;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasProperty(String key) {
|
||||
for (int k = chain.Count - 1; k >= 0; --k) {
|
||||
Object[] obj = (Object[])chain[k];
|
||||
Hashtable prop = (Hashtable)obj[1];
|
||||
if (prop.ContainsKey(key))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void AddToChain(String key, Hashtable prop) {
|
||||
// adjust the font size
|
||||
String value = (String)prop["size"];
|
||||
if (value != null) {
|
||||
if (value.EndsWith("px")) {
|
||||
prop["size"] = value.Substring(0, value.Length - 2);
|
||||
}
|
||||
else {
|
||||
int s = 0;
|
||||
if (value.StartsWith("+") || value.StartsWith("-")) {
|
||||
String old = this["basefontsize"];
|
||||
if (old == null)
|
||||
old = "12";
|
||||
float f = float.Parse(old, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
int c = (int)f;
|
||||
for (int k = fontSizes.Length - 1; k >= 0; --k) {
|
||||
if (c >= fontSizes[k]) {
|
||||
s = k;
|
||||
break;
|
||||
}
|
||||
}
|
||||
int inc = int.Parse(value.StartsWith("+") ? value.Substring(1) : value);
|
||||
s += inc;
|
||||
}
|
||||
else {
|
||||
try {
|
||||
s = int.Parse(value) - 1;
|
||||
}
|
||||
catch {
|
||||
s = 0;
|
||||
}
|
||||
}
|
||||
if (s < 0)
|
||||
s = 0;
|
||||
else if (s >= fontSizes.Length)
|
||||
s = fontSizes.Length - 1;
|
||||
prop["size"] = fontSizes[s].ToString();
|
||||
}
|
||||
}
|
||||
chain.Add(new Object[]{key, prop});
|
||||
}
|
||||
|
||||
public void RemoveChain(String key) {
|
||||
for (int k = chain.Count - 1; k >= 0; --k) {
|
||||
if (key.Equals(((Object[])chain[k])[0])) {
|
||||
chain.RemoveAt(k);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,338 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Globalization;
|
||||
using System.util;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.pdf;
|
||||
using iTextSharp.text.html;
|
||||
/*
|
||||
* Copyright 2004 Paulo Soares
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.html.simpleparser {
|
||||
|
||||
/**
|
||||
*
|
||||
* @author psoares
|
||||
*/
|
||||
public class FactoryProperties {
|
||||
|
||||
private FontFactoryImp fontImp = FontFactory.FontImp;
|
||||
|
||||
/** Creates a new instance of FactoryProperties */
|
||||
public FactoryProperties() {
|
||||
}
|
||||
|
||||
public Chunk CreateChunk(String text, ChainedProperties props) {
|
||||
Font font = GetFont(props);
|
||||
float size = font.Size;
|
||||
size /= 2;
|
||||
Chunk ck = new Chunk(text, font);
|
||||
if (props.HasProperty("sub"))
|
||||
ck.SetTextRise(-size);
|
||||
else if (props.HasProperty("sup"))
|
||||
ck.SetTextRise(size);
|
||||
ck.SetHyphenation(GetHyphenation(props));
|
||||
return ck;
|
||||
}
|
||||
|
||||
private static void SetParagraphLeading(Paragraph p, String leading) {
|
||||
if (leading == null) {
|
||||
p.SetLeading(0, 1.5f);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
StringTokenizer tk = new StringTokenizer(leading, " ,");
|
||||
String v = tk.NextToken();
|
||||
float v1 = float.Parse(v, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
if (!tk.HasMoreTokens()) {
|
||||
p.SetLeading(v1, 0);
|
||||
return;
|
||||
}
|
||||
v = tk.NextToken();
|
||||
float v2 = float.Parse(v, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
p.SetLeading(v1, v2);
|
||||
}
|
||||
catch {
|
||||
p.SetLeading(0, 1.5f);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Paragraph CreateParagraph(Hashtable props) {
|
||||
Paragraph p = new Paragraph();
|
||||
String value = (String)props["align"];
|
||||
if (value != null) {
|
||||
if (Util.EqualsIgnoreCase(value, "center"))
|
||||
p.Alignment = Element.ALIGN_CENTER;
|
||||
else if (Util.EqualsIgnoreCase(value, "right"))
|
||||
p.Alignment = Element.ALIGN_RIGHT;
|
||||
else if (Util.EqualsIgnoreCase(value, "justify"))
|
||||
p.Alignment = Element.ALIGN_JUSTIFIED;
|
||||
}
|
||||
SetParagraphLeading(p, (String)props["leading"]);
|
||||
p.Hyphenation = GetHyphenation(props);
|
||||
return p;
|
||||
}
|
||||
|
||||
public static void CreateParagraph(Paragraph p, ChainedProperties props) {
|
||||
String value = props["align"];
|
||||
if (value != null) {
|
||||
if (Util.EqualsIgnoreCase(value, "center"))
|
||||
p.Alignment = Element.ALIGN_CENTER;
|
||||
else if (Util.EqualsIgnoreCase(value, "right"))
|
||||
p.Alignment = Element.ALIGN_RIGHT;
|
||||
else if (Util.EqualsIgnoreCase(value, "justify"))
|
||||
p.Alignment = Element.ALIGN_JUSTIFIED;
|
||||
}
|
||||
p.Hyphenation = GetHyphenation(props);
|
||||
SetParagraphLeading(p, props["leading"]);
|
||||
value = props["before"];
|
||||
if (value != null) {
|
||||
try {
|
||||
p.SpacingBefore = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
}
|
||||
catch {}
|
||||
}
|
||||
value = props["after"];
|
||||
if (value != null) {
|
||||
try {
|
||||
p.SpacingAfter = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
}
|
||||
catch {}
|
||||
}
|
||||
value = props["extraparaspace"];
|
||||
if (value != null) {
|
||||
try {
|
||||
p.ExtraParagraphSpace = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
}
|
||||
catch {}
|
||||
}
|
||||
}
|
||||
|
||||
public static Paragraph CreateParagraph(ChainedProperties props) {
|
||||
Paragraph p = new Paragraph();
|
||||
CreateParagraph(p, props);
|
||||
return p;
|
||||
}
|
||||
|
||||
public static ListItem CreateListItem(ChainedProperties props) {
|
||||
ListItem p = new ListItem();
|
||||
CreateParagraph(p, props);
|
||||
return p;
|
||||
}
|
||||
|
||||
public Font GetFont(ChainedProperties props) {
|
||||
String face = props["face"];
|
||||
if (face != null) {
|
||||
StringTokenizer tok = new StringTokenizer(face, ",");
|
||||
while (tok.HasMoreTokens()) {
|
||||
face = tok.NextToken().Trim();
|
||||
if (face.StartsWith("\""))
|
||||
face = face.Substring(1);
|
||||
if (face.EndsWith("\""))
|
||||
face = face.Substring(0, face.Length - 1);
|
||||
if (fontImp.IsRegistered(face))
|
||||
break;
|
||||
}
|
||||
}
|
||||
int style = 0;
|
||||
if (props.HasProperty("i"))
|
||||
style |= Font.ITALIC;
|
||||
if (props.HasProperty("b"))
|
||||
style |= Font.BOLD;
|
||||
if (props.HasProperty("u"))
|
||||
style |= Font.UNDERLINE;
|
||||
if (props.HasProperty("s"))
|
||||
style |= Font.STRIKETHRU ;
|
||||
|
||||
String value = props["size"];
|
||||
float size = 12;
|
||||
if (value != null)
|
||||
size = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
Color color = Markup.DecodeColor(props["color"]);
|
||||
String encoding = props["encoding"];
|
||||
if (encoding == null)
|
||||
encoding = BaseFont.WINANSI;
|
||||
return fontImp.GetFont(face, encoding, true, size, style, color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a HyphenationEvent based on the hyphenation entry in ChainedProperties.
|
||||
* @param props ChainedProperties
|
||||
* @return a HyphenationEvent
|
||||
* @since 2.1.2
|
||||
*/
|
||||
public static IHyphenationEvent GetHyphenation(ChainedProperties props) {
|
||||
return GetHyphenation(props["hyphenation"]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a HyphenationEvent based on the hyphenation entry in a HashMap.
|
||||
* @param props a HashMap with properties
|
||||
* @return a HyphenationEvent
|
||||
* @since 2.1.2
|
||||
*/
|
||||
public static IHyphenationEvent GetHyphenation(Hashtable props) {
|
||||
return GetHyphenation((String)props["hyphenation"]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a HyphenationEvent based on a String.
|
||||
* For instance "en_UK,3,2" returns new HyphenationAuto("en", "UK", 3, 2);
|
||||
* @param a String, for instance "en_UK,2,2"
|
||||
* @return a HyphenationEvent
|
||||
* @since 2.1.2
|
||||
*/
|
||||
public static IHyphenationEvent GetHyphenation(String s) {
|
||||
if (s == null || s.Length == 0) {
|
||||
return null;
|
||||
}
|
||||
String lang = s;
|
||||
String country = null;
|
||||
int leftMin = 2;
|
||||
int rightMin = 2;
|
||||
|
||||
int pos = s.IndexOf('_');
|
||||
if (pos == -1) {
|
||||
return new HyphenationAuto(lang, country, leftMin, rightMin);
|
||||
}
|
||||
lang = s.Substring(0, pos);
|
||||
country = s.Substring(pos + 1);
|
||||
pos = country.IndexOf(',');
|
||||
if (pos == -1) {
|
||||
return new HyphenationAuto(lang, country, leftMin, rightMin);
|
||||
}
|
||||
s = country.Substring(pos + 1);
|
||||
country = country.Substring(0, pos);
|
||||
pos = s.IndexOf(',');
|
||||
if (pos == -1) {
|
||||
leftMin = int.Parse(s);
|
||||
}
|
||||
else {
|
||||
leftMin = int.Parse(s.Substring(0, pos));
|
||||
rightMin = int.Parse(s.Substring(pos + 1));
|
||||
}
|
||||
return new HyphenationAuto(lang, country, leftMin, rightMin);
|
||||
}
|
||||
|
||||
public static void InsertStyle(Hashtable h) {
|
||||
String style = (String)h["style"];
|
||||
if (style == null)
|
||||
return;
|
||||
Properties prop = Markup.ParseAttributes(style);
|
||||
foreach (String key in prop.Keys) {
|
||||
if (key.Equals(Markup.CSS_KEY_FONTFAMILY)) {
|
||||
h["face"] = prop[key];
|
||||
}
|
||||
else if (key.Equals(Markup.CSS_KEY_FONTSIZE)) {
|
||||
h["size"] = Markup.ParseLength(prop[key]).ToString(NumberFormatInfo.InvariantInfo) + "px";
|
||||
}
|
||||
else if (key.Equals(Markup.CSS_KEY_FONTSTYLE)) {
|
||||
String ss = prop[key].Trim().ToLower(CultureInfo.InvariantCulture);
|
||||
if (ss.Equals("italic") || ss.Equals("oblique"))
|
||||
h["i"] = null;
|
||||
}
|
||||
else if (key.Equals(Markup.CSS_KEY_FONTWEIGHT)) {
|
||||
String ss = prop[key].Trim().ToLower(CultureInfo.InvariantCulture);
|
||||
if (ss.Equals("bold") || ss.Equals("700") || ss.Equals("800") || ss.Equals("900"))
|
||||
h["b"] = null;
|
||||
}
|
||||
else if (key.Equals(Markup.CSS_KEY_FONTWEIGHT)) {
|
||||
String ss = prop[key].Trim().ToLower(CultureInfo.InvariantCulture);
|
||||
if (ss.Equals("underline"))
|
||||
h["u"] = null;
|
||||
}
|
||||
else if (key.Equals(Markup.CSS_KEY_COLOR)) {
|
||||
Color c = Markup.DecodeColor(prop[key]);
|
||||
if (c != null) {
|
||||
int hh = c.ToArgb() & 0xffffff;
|
||||
String hs = "#" + hh.ToString("X06", NumberFormatInfo.InvariantInfo);
|
||||
h["color"] = hs;
|
||||
}
|
||||
}
|
||||
else if (key.Equals(Markup.CSS_KEY_LINEHEIGHT)) {
|
||||
String ss = prop[key].Trim();
|
||||
float v = Markup.ParseLength(prop[key]);
|
||||
if (ss.EndsWith("%")) {
|
||||
v /= 100;
|
||||
h["leading"] = "0," + v.ToString(NumberFormatInfo.InvariantInfo);
|
||||
}
|
||||
else {
|
||||
h["leading"] = v.ToString(NumberFormatInfo.InvariantInfo) + ",0";
|
||||
}
|
||||
}
|
||||
else if (key.Equals(Markup.CSS_KEY_TEXTALIGN)) {
|
||||
String ss = prop[key].Trim().ToLower(System.Globalization.CultureInfo.InvariantCulture);
|
||||
h["align"] = ss;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public FontFactoryImp FontImp {
|
||||
get {
|
||||
return fontImp;
|
||||
}
|
||||
set {
|
||||
fontImp = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static Hashtable followTags = new Hashtable();
|
||||
|
||||
static FactoryProperties() {
|
||||
followTags["i"] = "i";
|
||||
followTags["b"] = "b";
|
||||
followTags["u"] = "u";
|
||||
followTags["sub"] = "sub";
|
||||
followTags["sup"] = "sup";
|
||||
followTags["em"] = "i";
|
||||
followTags["strong"] = "b";
|
||||
followTags["s"] = "s";
|
||||
followTags["strike"] = "s";
|
||||
}
|
||||
}
|
||||
}
|
||||
624
iTechSharp/iTextSharp/text/html/simpleparser/HTMLWorker.cs
Normal file
624
iTechSharp/iTextSharp/text/html/simpleparser/HTMLWorker.cs
Normal file
@@ -0,0 +1,624 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using System.Globalization;
|
||||
using System.util;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.pdf;
|
||||
using iTextSharp.text.xml.simpleparser;
|
||||
/*
|
||||
* Copyright 2004 Paulo Soares
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.html.simpleparser {
|
||||
|
||||
public class HTMLWorker : ISimpleXMLDocHandler, IDocListener {
|
||||
|
||||
protected ArrayList objectList;
|
||||
protected IDocListener document;
|
||||
private Paragraph currentParagraph;
|
||||
private ChainedProperties cprops = new ChainedProperties();
|
||||
private Stack stack = new Stack();
|
||||
private bool pendingTR = false;
|
||||
private bool pendingTD = false;
|
||||
private bool pendingLI = false;
|
||||
private StyleSheet style = new StyleSheet();
|
||||
private bool isPRE = false;
|
||||
private Stack tableState = new Stack();
|
||||
private bool skipText = false;
|
||||
private Hashtable interfaceProps;
|
||||
private FactoryProperties factoryProperties = new FactoryProperties();
|
||||
|
||||
/** Creates a new instance of HTMLWorker */
|
||||
public HTMLWorker(IDocListener document) {
|
||||
this.document = document;
|
||||
}
|
||||
|
||||
public StyleSheet Style {
|
||||
set {
|
||||
style = value;
|
||||
}
|
||||
get {
|
||||
return style;
|
||||
}
|
||||
}
|
||||
|
||||
public Hashtable InterfaceProps {
|
||||
set {
|
||||
interfaceProps = value;
|
||||
FontFactoryImp ff = null;
|
||||
if (interfaceProps != null)
|
||||
ff = (FontFactoryImp)interfaceProps["font_factory"];
|
||||
if (ff != null)
|
||||
factoryProperties.FontImp = ff;
|
||||
}
|
||||
get {
|
||||
return interfaceProps;
|
||||
}
|
||||
}
|
||||
|
||||
public void Parse(TextReader reader) {
|
||||
SimpleXMLParser.Parse(this, null, reader, true);
|
||||
}
|
||||
|
||||
public static ArrayList ParseToList(TextReader reader, StyleSheet style) {
|
||||
return ParseToList(reader, style, null);
|
||||
}
|
||||
|
||||
public static ArrayList ParseToList(TextReader reader, StyleSheet style, Hashtable interfaceProps) {
|
||||
HTMLWorker worker = new HTMLWorker(null);
|
||||
if (style != null)
|
||||
worker.Style = style;
|
||||
worker.document = worker;
|
||||
worker.InterfaceProps = interfaceProps;
|
||||
worker.objectList = new ArrayList();
|
||||
worker.Parse(reader);
|
||||
return worker.objectList;
|
||||
}
|
||||
|
||||
public virtual void EndDocument() {
|
||||
foreach (IElement e in stack)
|
||||
document.Add(e);
|
||||
if (currentParagraph != null)
|
||||
document.Add(currentParagraph);
|
||||
currentParagraph = null;
|
||||
}
|
||||
|
||||
public virtual void StartDocument() {
|
||||
Hashtable h = new Hashtable();
|
||||
style.ApplyStyle("body", h);
|
||||
cprops.AddToChain("body", h);
|
||||
}
|
||||
|
||||
public virtual void StartElement(String tag, Hashtable h) {
|
||||
if (!tagsSupported.ContainsKey(tag))
|
||||
return;
|
||||
style.ApplyStyle(tag, h);
|
||||
String follow = (String)FactoryProperties.followTags[tag];
|
||||
if (follow != null) {
|
||||
Hashtable prop = new Hashtable();
|
||||
prop[follow] = null;
|
||||
cprops.AddToChain(follow, prop);
|
||||
return;
|
||||
}
|
||||
FactoryProperties.InsertStyle(h);
|
||||
if (tag.Equals("a")) {
|
||||
cprops.AddToChain(tag, h);
|
||||
if (currentParagraph == null)
|
||||
currentParagraph = new Paragraph();
|
||||
stack.Push(currentParagraph);
|
||||
currentParagraph = new Paragraph();
|
||||
return;
|
||||
}
|
||||
if (tag.Equals("br")) {
|
||||
if (currentParagraph == null)
|
||||
currentParagraph = new Paragraph();
|
||||
currentParagraph.Add(factoryProperties.CreateChunk("\n", cprops));
|
||||
return;
|
||||
}
|
||||
if (tag.Equals("font") || tag.Equals("span")) {
|
||||
cprops.AddToChain(tag, h);
|
||||
return;
|
||||
}
|
||||
if (tag.Equals("img")) {
|
||||
String src = (String)h["src"];
|
||||
if (src == null)
|
||||
return;
|
||||
cprops.AddToChain(tag, h);
|
||||
Image img = null;
|
||||
if (interfaceProps != null) {
|
||||
IImageProvider ip = (IImageProvider)interfaceProps["img_provider"];
|
||||
if (ip != null)
|
||||
img = ip.GetImage(src, h, cprops, document);
|
||||
if (img == null) {
|
||||
Hashtable images = (Hashtable)interfaceProps["img_static"];
|
||||
if (images != null) {
|
||||
Image tim = (Image)images[src];
|
||||
if (tim != null)
|
||||
img = Image.GetInstance(tim);
|
||||
} else {
|
||||
if (!src.StartsWith("http")) { // relative src references only
|
||||
String baseurl = (String)interfaceProps["img_baseurl"];
|
||||
if (baseurl != null) {
|
||||
src = baseurl + src;
|
||||
img = Image.GetInstance(src);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (img == null) {
|
||||
if (!src.StartsWith("http")) {
|
||||
String path = cprops["image_path"];
|
||||
if (path == null)
|
||||
path = "";
|
||||
src = Path.Combine(path, src);
|
||||
}
|
||||
img = Image.GetInstance(src);
|
||||
}
|
||||
String align = (String)h["align"];
|
||||
String width = (String)h["width"];
|
||||
String height = (String)h["height"];
|
||||
String before = cprops["before"];
|
||||
String after = cprops["after"];
|
||||
if (before != null)
|
||||
img.SpacingBefore = float.Parse(before, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
if (after != null)
|
||||
img.SpacingAfter = float.Parse(after, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
float wp = LengthParse(width, (int)img.Width);
|
||||
float lp = LengthParse(height, (int)img.Height);
|
||||
if (wp > 0 && lp > 0)
|
||||
img.ScalePercent(wp > lp ? lp : wp);
|
||||
else if (wp > 0)
|
||||
img.ScalePercent(wp);
|
||||
else if (lp > 0)
|
||||
img.ScalePercent(lp);
|
||||
img.WidthPercentage = 0;
|
||||
if (align != null) {
|
||||
EndElement("p");
|
||||
int ralign = Image.MIDDLE_ALIGN;
|
||||
if (Util.EqualsIgnoreCase(align, "left"))
|
||||
ralign = Image.LEFT_ALIGN;
|
||||
else if (Util.EqualsIgnoreCase(align, "right"))
|
||||
ralign = Image.RIGHT_ALIGN;
|
||||
img.Alignment = ralign;
|
||||
IImg i = null;
|
||||
bool skip = false;
|
||||
if (interfaceProps != null) {
|
||||
i = (IImg)interfaceProps["img_interface"];
|
||||
if (i != null)
|
||||
skip = i.Process(img, h, cprops, document);
|
||||
}
|
||||
if (!skip)
|
||||
document.Add(img);
|
||||
cprops.RemoveChain(tag);
|
||||
}
|
||||
else {
|
||||
cprops.RemoveChain(tag);
|
||||
if (currentParagraph == null)
|
||||
currentParagraph = FactoryProperties.CreateParagraph(cprops);
|
||||
currentParagraph.Add(new Chunk(img, 0, 0));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
EndElement("p");
|
||||
if (tag.Equals("h1") || tag.Equals("h2") || tag.Equals("h3") || tag.Equals("h4") || tag.Equals("h5") || tag.Equals("h6")) {
|
||||
if (!h.ContainsKey("size")) {
|
||||
int v = 7 - int.Parse(tag.Substring(1));
|
||||
h["size"] = v.ToString();
|
||||
}
|
||||
cprops.AddToChain(tag, h);
|
||||
return;
|
||||
}
|
||||
if (tag.Equals("ul")) {
|
||||
if (pendingLI)
|
||||
EndElement("li");
|
||||
skipText = true;
|
||||
cprops.AddToChain(tag, h);
|
||||
List list = new List(false, 10);
|
||||
list.SetListSymbol("\u2022");
|
||||
stack.Push(list);
|
||||
return;
|
||||
}
|
||||
if (tag.Equals("ol")) {
|
||||
if (pendingLI)
|
||||
EndElement("li");
|
||||
skipText = true;
|
||||
cprops.AddToChain(tag, h);
|
||||
List list = new List(true, 10);
|
||||
stack.Push(list);
|
||||
return;
|
||||
}
|
||||
if (tag.Equals("li")) {
|
||||
if (pendingLI)
|
||||
EndElement("li");
|
||||
skipText = false;
|
||||
pendingLI = true;
|
||||
cprops.AddToChain(tag, h);
|
||||
stack.Push(FactoryProperties.CreateListItem(cprops));
|
||||
return;
|
||||
}
|
||||
if (tag.Equals("div") || tag.Equals("body")) {
|
||||
cprops.AddToChain(tag, h);
|
||||
return;
|
||||
}
|
||||
if (tag.Equals("pre")) {
|
||||
if (!h.ContainsKey("face")) {
|
||||
h["face"] = "Courier";
|
||||
}
|
||||
cprops.AddToChain(tag, h);
|
||||
isPRE = true;
|
||||
return;
|
||||
}
|
||||
if (tag.Equals("p")) {
|
||||
cprops.AddToChain(tag, h);
|
||||
currentParagraph = FactoryProperties.CreateParagraph(h);
|
||||
return;
|
||||
}
|
||||
if (tag.Equals("tr")) {
|
||||
if (pendingTR)
|
||||
EndElement("tr");
|
||||
skipText = true;
|
||||
pendingTR = true;
|
||||
cprops.AddToChain("tr", h);
|
||||
return;
|
||||
}
|
||||
if (tag.Equals("td") || tag.Equals("th")) {
|
||||
if (pendingTD)
|
||||
EndElement(tag);
|
||||
skipText = false;
|
||||
pendingTD = true;
|
||||
cprops.AddToChain("td", h);
|
||||
stack.Push(new IncCell(tag, cprops));
|
||||
return;
|
||||
}
|
||||
if (tag.Equals("table")) {
|
||||
cprops.AddToChain("table", h);
|
||||
IncTable table = new IncTable(h);
|
||||
stack.Push(table);
|
||||
tableState.Push(new bool[]{pendingTR, pendingTD});
|
||||
pendingTR = pendingTD = false;
|
||||
skipText = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void EndElement(String tag) {
|
||||
if (!tagsSupported.ContainsKey(tag))
|
||||
return;
|
||||
String follow = (String)FactoryProperties.followTags[tag];
|
||||
if (follow != null) {
|
||||
cprops.RemoveChain(follow);
|
||||
return;
|
||||
}
|
||||
if (tag.Equals("font") || tag.Equals("span")) {
|
||||
cprops.RemoveChain(tag);
|
||||
return;
|
||||
}
|
||||
if (tag.Equals("a")) {
|
||||
if (currentParagraph == null)
|
||||
currentParagraph = new Paragraph();
|
||||
IALink i = null;
|
||||
bool skip = false;
|
||||
if (interfaceProps != null) {
|
||||
i = (IALink)interfaceProps["alink_interface"];
|
||||
if (i != null)
|
||||
skip = i.Process(currentParagraph, cprops);
|
||||
}
|
||||
if (!skip) {
|
||||
String href = cprops["href"];
|
||||
if (href != null) {
|
||||
ArrayList chunks = currentParagraph.Chunks;
|
||||
for (int k = 0; k < chunks.Count; ++k) {
|
||||
Chunk ck = (Chunk)chunks[k];
|
||||
ck.SetAnchor(href);
|
||||
}
|
||||
}
|
||||
}
|
||||
Paragraph tmp = (Paragraph)stack.Pop();
|
||||
Phrase tmp2 = new Phrase();
|
||||
tmp2.Add(currentParagraph);
|
||||
tmp.Add(tmp2);
|
||||
currentParagraph = tmp;
|
||||
cprops.RemoveChain("a");
|
||||
return;
|
||||
}
|
||||
if (tag.Equals("br")) {
|
||||
return;
|
||||
}
|
||||
if (currentParagraph != null) {
|
||||
if (stack.Count == 0)
|
||||
document.Add(currentParagraph);
|
||||
else {
|
||||
Object obj = stack.Pop();
|
||||
if (obj is ITextElementArray) {
|
||||
ITextElementArray current = (ITextElementArray)obj;
|
||||
current.Add(currentParagraph);
|
||||
}
|
||||
stack.Push(obj);
|
||||
}
|
||||
}
|
||||
currentParagraph = null;
|
||||
if (tag.Equals("ul") || tag.Equals("ol")) {
|
||||
if (pendingLI)
|
||||
EndElement("li");
|
||||
skipText = false;
|
||||
cprops.RemoveChain(tag);
|
||||
if (stack.Count == 0)
|
||||
return;
|
||||
Object obj = stack.Pop();
|
||||
if (!(obj is List)) {
|
||||
stack.Push(obj);
|
||||
return;
|
||||
}
|
||||
if (stack.Count == 0)
|
||||
document.Add((IElement)obj);
|
||||
else
|
||||
((ITextElementArray)stack.Peek()).Add(obj);
|
||||
return;
|
||||
}
|
||||
if (tag.Equals("li")) {
|
||||
pendingLI = false;
|
||||
skipText = true;
|
||||
cprops.RemoveChain(tag);
|
||||
if (stack.Count == 0)
|
||||
return;
|
||||
Object obj = stack.Pop();
|
||||
if (!(obj is ListItem)) {
|
||||
stack.Push(obj);
|
||||
return;
|
||||
}
|
||||
if (stack.Count == 0) {
|
||||
document.Add((IElement)obj);
|
||||
return;
|
||||
}
|
||||
Object list = stack.Pop();
|
||||
if (!(list is List)) {
|
||||
stack.Push(list);
|
||||
return;
|
||||
}
|
||||
ListItem item = (ListItem)obj;
|
||||
((List)list).Add(item);
|
||||
ArrayList cks = item.Chunks;
|
||||
if (cks.Count > 0)
|
||||
item.ListSymbol.Font = ((Chunk)cks[0]).Font;
|
||||
stack.Push(list);
|
||||
return;
|
||||
}
|
||||
if (tag.Equals("div") || tag.Equals("body")) {
|
||||
cprops.RemoveChain(tag);
|
||||
return;
|
||||
}
|
||||
if (tag.Equals("pre")) {
|
||||
cprops.RemoveChain(tag);
|
||||
isPRE = false;
|
||||
return;
|
||||
}
|
||||
if (tag.Equals("p")) {
|
||||
cprops.RemoveChain(tag);
|
||||
return;
|
||||
}
|
||||
if (tag.Equals("h1") || tag.Equals("h2") || tag.Equals("h3") || tag.Equals("h4") || tag.Equals("h5") || tag.Equals("h6")) {
|
||||
cprops.RemoveChain(tag);
|
||||
return;
|
||||
}
|
||||
if (tag.Equals("table")) {
|
||||
if (pendingTR)
|
||||
EndElement("tr");
|
||||
cprops.RemoveChain("table");
|
||||
IncTable table = (IncTable) stack.Pop();
|
||||
PdfPTable tb = table.BuildTable();
|
||||
tb.SplitRows = true;
|
||||
if (stack.Count == 0)
|
||||
document.Add(tb);
|
||||
else
|
||||
((ITextElementArray)stack.Peek()).Add(tb);
|
||||
bool[] state = (bool[])tableState.Pop();
|
||||
pendingTR = state[0];
|
||||
pendingTD = state[1];
|
||||
skipText = false;
|
||||
return;
|
||||
}
|
||||
if (tag.Equals("tr")) {
|
||||
if (pendingTD)
|
||||
EndElement("td");
|
||||
pendingTR = false;
|
||||
cprops.RemoveChain("tr");
|
||||
ArrayList cells = new ArrayList();
|
||||
IncTable table = null;
|
||||
while (true) {
|
||||
Object obj = stack.Pop();
|
||||
if (obj is IncCell) {
|
||||
cells.Add(((IncCell)obj).Cell);
|
||||
}
|
||||
if (obj is IncTable) {
|
||||
table = (IncTable)obj;
|
||||
break;
|
||||
}
|
||||
}
|
||||
table.AddCols(cells);
|
||||
table.EndRow();
|
||||
stack.Push(table);
|
||||
skipText = true;
|
||||
return;
|
||||
}
|
||||
if (tag.Equals("td") || tag.Equals("th")) {
|
||||
pendingTD = false;
|
||||
cprops.RemoveChain("td");
|
||||
skipText = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Text(String str) {
|
||||
if (skipText)
|
||||
return;
|
||||
String content = str;
|
||||
if (isPRE) {
|
||||
if (currentParagraph == null)
|
||||
currentParagraph = FactoryProperties.CreateParagraph(cprops);
|
||||
currentParagraph.Add(factoryProperties.CreateChunk(content, cprops));
|
||||
return;
|
||||
}
|
||||
if (content.Trim().Length == 0 && content.IndexOf(' ') < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuilder buf = new StringBuilder();
|
||||
int len = content.Length;
|
||||
char character;
|
||||
bool newline = false;
|
||||
for (int i = 0; i < len; i++) {
|
||||
switch (character = content[i]) {
|
||||
case ' ':
|
||||
if (!newline) {
|
||||
buf.Append(character);
|
||||
}
|
||||
break;
|
||||
case '\n':
|
||||
if (i > 0) {
|
||||
newline = true;
|
||||
buf.Append(' ');
|
||||
}
|
||||
break;
|
||||
case '\r':
|
||||
break;
|
||||
case '\t':
|
||||
break;
|
||||
default:
|
||||
newline = false;
|
||||
buf.Append(character);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (currentParagraph == null)
|
||||
currentParagraph = FactoryProperties.CreateParagraph(cprops);
|
||||
currentParagraph.Add(factoryProperties.CreateChunk(buf.ToString(), cprops));
|
||||
}
|
||||
|
||||
public bool Add(IElement element) {
|
||||
objectList.Add(element);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void ClearTextWrap() {
|
||||
}
|
||||
|
||||
public void Close() {
|
||||
}
|
||||
|
||||
public bool NewPage() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Open() {
|
||||
}
|
||||
|
||||
public void ResetFooter() {
|
||||
}
|
||||
|
||||
public void ResetHeader() {
|
||||
}
|
||||
|
||||
public void ResetPageCount() {
|
||||
}
|
||||
|
||||
public bool SetMarginMirroring(bool marginMirroring) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool SetMargins(float marginLeft, float marginRight, float marginTop, float marginBottom) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool SetPageSize(Rectangle pageSize) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public const String tagsSupportedString = "ol ul li a pre font span br p div body table td th tr i b u sub sup em strong s strike"
|
||||
+ " h1 h2 h3 h4 h5 h6 img";
|
||||
|
||||
public static Hashtable tagsSupported = new Hashtable();
|
||||
|
||||
static HTMLWorker() {
|
||||
StringTokenizer tok = new StringTokenizer(tagsSupportedString);
|
||||
while (tok.HasMoreTokens())
|
||||
tagsSupported[tok.NextToken()] = null;
|
||||
}
|
||||
|
||||
public HeaderFooter Footer {
|
||||
set {
|
||||
}
|
||||
}
|
||||
|
||||
public HeaderFooter Header {
|
||||
set {
|
||||
}
|
||||
}
|
||||
|
||||
public int PageCount {
|
||||
set {
|
||||
}
|
||||
}
|
||||
|
||||
private static float LengthParse(String txt, int c) {
|
||||
if (txt == null)
|
||||
return -1;
|
||||
if (txt.EndsWith("%")) {
|
||||
float vf = float.Parse(txt.Substring(0, txt.Length - 1), System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
return vf;
|
||||
}
|
||||
if (txt.EndsWith("px")) {
|
||||
float vf = float.Parse(txt.Substring(0, txt.Length - 2), System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
return vf;
|
||||
}
|
||||
int v = int.Parse(txt);
|
||||
return (float)v / c * 100f;
|
||||
}
|
||||
}
|
||||
}
|
||||
54
iTechSharp/iTextSharp/text/html/simpleparser/IALink.cs
Normal file
54
iTechSharp/iTextSharp/text/html/simpleparser/IALink.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using iTextSharp.text;
|
||||
/*
|
||||
* Copyright 2005 Paulo Soares
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.html.simpleparser {
|
||||
public interface IALink {
|
||||
bool Process(Paragraph current, ChainedProperties cprops);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using iTextSharp.text;
|
||||
/*
|
||||
* Copyright 2007 Paulo Soares
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.html.simpleparser {
|
||||
public interface IImageProvider {
|
||||
Image GetImage(String src, Hashtable h, ChainedProperties cprops, IDocListener doc);
|
||||
}
|
||||
}
|
||||
55
iTechSharp/iTextSharp/text/html/simpleparser/IImg.cs
Normal file
55
iTechSharp/iTextSharp/text/html/simpleparser/IImg.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using iTextSharp.text;
|
||||
|
||||
/*
|
||||
* Copyright 2005 Paulo Soares
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
namespace iTextSharp.text.html.simpleparser {
|
||||
public interface IImg {
|
||||
bool Process(Image img, Hashtable h, ChainedProperties cprops, IDocListener doc);
|
||||
}
|
||||
}
|
||||
153
iTechSharp/iTextSharp/text/html/simpleparser/IncCell.cs
Normal file
153
iTechSharp/iTextSharp/text/html/simpleparser/IncCell.cs
Normal file
@@ -0,0 +1,153 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.util;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.pdf;
|
||||
using iTextSharp.text.html;
|
||||
/*
|
||||
* Copyright 2004 Paulo Soares
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.html.simpleparser {
|
||||
/**
|
||||
*
|
||||
* @author psoares
|
||||
*/
|
||||
public class IncCell : ITextElementArray {
|
||||
|
||||
private ArrayList chunks = new ArrayList();
|
||||
private PdfPCell cell;
|
||||
|
||||
/** Creates a new instance of IncCell */
|
||||
public IncCell(String tag, ChainedProperties props) {
|
||||
cell = new PdfPCell();
|
||||
String value = props["colspan"];
|
||||
if (value != null)
|
||||
cell.Colspan = int.Parse(value);
|
||||
value = props["align"];
|
||||
if (tag.Equals("th"))
|
||||
cell.HorizontalAlignment = Element.ALIGN_CENTER;
|
||||
if (value != null) {
|
||||
if (Util.EqualsIgnoreCase(value, "center"))
|
||||
cell.HorizontalAlignment = Element.ALIGN_CENTER;
|
||||
else if (Util.EqualsIgnoreCase(value, "right"))
|
||||
cell.HorizontalAlignment = Element.ALIGN_RIGHT;
|
||||
else if (Util.EqualsIgnoreCase(value, "left"))
|
||||
cell.HorizontalAlignment = Element.ALIGN_LEFT;
|
||||
else if (Util.EqualsIgnoreCase(value, "justify"))
|
||||
cell.HorizontalAlignment = Element.ALIGN_JUSTIFIED;
|
||||
}
|
||||
value = props["valign"];
|
||||
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
|
||||
if (value != null) {
|
||||
if (Util.EqualsIgnoreCase(value, "top"))
|
||||
cell.VerticalAlignment = Element.ALIGN_TOP;
|
||||
else if (Util.EqualsIgnoreCase(value, "bottom"))
|
||||
cell.VerticalAlignment = Element.ALIGN_BOTTOM;
|
||||
}
|
||||
value = props["border"];
|
||||
float border = 0;
|
||||
if (value != null)
|
||||
border = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
cell.BorderWidth = border;
|
||||
value = props["cellpadding"];
|
||||
if (value != null)
|
||||
cell.Padding = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
cell.UseDescender = true;
|
||||
value = props["bgcolor"];
|
||||
cell.BackgroundColor = Markup.DecodeColor(value);
|
||||
}
|
||||
|
||||
public bool Add(Object o) {
|
||||
if (!(o is IElement))
|
||||
return false;
|
||||
cell.AddElement((IElement)o);
|
||||
return true;
|
||||
}
|
||||
|
||||
public ArrayList Chunks {
|
||||
get {
|
||||
return chunks;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Process(IElementListener listener) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public int Type {
|
||||
get {
|
||||
return Element.RECTANGLE;
|
||||
}
|
||||
}
|
||||
|
||||
public PdfPCell Cell {
|
||||
get {
|
||||
return cell;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.lowagie.text.Element#isContent()
|
||||
* @since iText 2.0.8
|
||||
*/
|
||||
public bool IsContent() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.lowagie.text.Element#isNestable()
|
||||
* @since iText 2.0.8
|
||||
*/
|
||||
public bool IsNestable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return base.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
124
iTechSharp/iTextSharp/text/html/simpleparser/IncTable.cs
Normal file
124
iTechSharp/iTextSharp/text/html/simpleparser/IncTable.cs
Normal file
@@ -0,0 +1,124 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.pdf;
|
||||
/*
|
||||
* Copyright 2004 Paulo Soares
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.html.simpleparser {
|
||||
|
||||
/**
|
||||
*
|
||||
* @author psoares
|
||||
*/
|
||||
public class IncTable {
|
||||
private Hashtable props = new Hashtable();
|
||||
private ArrayList rows = new ArrayList();
|
||||
private ArrayList cols;
|
||||
/** Creates a new instance of IncTable */
|
||||
public IncTable(Hashtable props) {
|
||||
foreach (DictionaryEntry dc in props)
|
||||
this.props[dc.Key] = dc.Value;
|
||||
}
|
||||
|
||||
public void AddCol(PdfPCell cell) {
|
||||
if (cols == null)
|
||||
cols = new ArrayList();
|
||||
cols.Add(cell);
|
||||
}
|
||||
|
||||
public void AddCols(ArrayList ncols) {
|
||||
if (cols == null)
|
||||
cols = new ArrayList(ncols);
|
||||
else
|
||||
cols.AddRange(ncols);
|
||||
}
|
||||
|
||||
public void EndRow() {
|
||||
if (cols != null) {
|
||||
cols.Reverse();
|
||||
rows.Add(cols);
|
||||
cols = null;
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList Rows {
|
||||
get {
|
||||
return rows;
|
||||
}
|
||||
}
|
||||
|
||||
public PdfPTable BuildTable() {
|
||||
if (rows.Count == 0)
|
||||
return new PdfPTable(1);
|
||||
int ncol = 0;
|
||||
ArrayList c0 = (ArrayList)rows[0];
|
||||
for (int k = 0; k < c0.Count; ++k) {
|
||||
ncol += ((PdfPCell)c0[k]).Colspan;
|
||||
}
|
||||
PdfPTable table = new PdfPTable(ncol);
|
||||
String width = (String)props["width"];
|
||||
if (width == null)
|
||||
table.WidthPercentage = 100;
|
||||
else {
|
||||
if (width.EndsWith("%"))
|
||||
table.WidthPercentage = float.Parse(width.Substring(0, width.Length - 1), System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
else {
|
||||
table.TotalWidth = float.Parse(width, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
table.LockedWidth = true;
|
||||
}
|
||||
}
|
||||
for (int row = 0; row < rows.Count; ++row) {
|
||||
ArrayList col = (ArrayList)rows[row];
|
||||
for (int k = 0; k < col.Count; ++k) {
|
||||
table.AddCell((PdfPCell)col[k]);
|
||||
}
|
||||
}
|
||||
return table;
|
||||
}
|
||||
}
|
||||
}
|
||||
117
iTechSharp/iTextSharp/text/html/simpleparser/StyleSheet.cs
Normal file
117
iTechSharp/iTextSharp/text/html/simpleparser/StyleSheet.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
/*
|
||||
* Copyright 2004 Paulo Soares
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.html.simpleparser {
|
||||
|
||||
public class StyleSheet {
|
||||
|
||||
public Hashtable classMap = new Hashtable();
|
||||
public Hashtable tagMap = new Hashtable();
|
||||
|
||||
/** Creates a new instance of StyleSheet */
|
||||
public StyleSheet() {
|
||||
}
|
||||
|
||||
public void ApplyStyle(String tag, Hashtable props) {
|
||||
Hashtable map = (Hashtable)tagMap[tag.ToLower(System.Globalization.CultureInfo.InvariantCulture)];
|
||||
Hashtable temp;
|
||||
if (map != null) {
|
||||
temp = new Hashtable(map);
|
||||
foreach (DictionaryEntry dc in props)
|
||||
temp[dc.Key] = dc.Value;
|
||||
foreach (DictionaryEntry dc in temp)
|
||||
props[dc.Key] = dc.Value;
|
||||
}
|
||||
String cm = (String)props["class"];
|
||||
if (cm == null)
|
||||
return;
|
||||
map = (Hashtable)classMap[cm.ToLower(System.Globalization.CultureInfo.InvariantCulture)];
|
||||
if (map == null)
|
||||
return;
|
||||
props.Remove("class");
|
||||
temp = new Hashtable(map);
|
||||
foreach (DictionaryEntry dc in props)
|
||||
temp[dc.Key] = dc.Value;
|
||||
foreach (DictionaryEntry dc in temp)
|
||||
props[dc.Key] = dc.Value;
|
||||
}
|
||||
|
||||
private void ApplyMap(Hashtable map, Hashtable props) {
|
||||
|
||||
}
|
||||
|
||||
public void LoadStyle(String style, Hashtable props) {
|
||||
classMap[style.ToLower(System.Globalization.CultureInfo.InvariantCulture)] = props;
|
||||
}
|
||||
|
||||
public void LoadStyle(String style, String key, String value) {
|
||||
style = style.ToLower(System.Globalization.CultureInfo.InvariantCulture);
|
||||
Hashtable props = (Hashtable)classMap[style];
|
||||
if (props == null) {
|
||||
props = new Hashtable();
|
||||
classMap[style] = props;
|
||||
}
|
||||
props[key] = value;
|
||||
}
|
||||
|
||||
public void LoadTagStyle(String tag, Hashtable props) {
|
||||
tagMap[tag.ToLower(System.Globalization.CultureInfo.InvariantCulture)] = props;
|
||||
}
|
||||
|
||||
public void LoadTagStyle(String tag, String key, String value) {
|
||||
tag = tag.ToLower(System.Globalization.CultureInfo.InvariantCulture);
|
||||
Hashtable props = (Hashtable)tagMap[tag];
|
||||
if (props == null) {
|
||||
props = new Hashtable();
|
||||
tagMap[tag] = props;
|
||||
}
|
||||
props[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
2126
iTechSharp/iTextSharp/text/pdf/AcroFields.cs
Normal file
2126
iTechSharp/iTextSharp/text/pdf/AcroFields.cs
Normal file
File diff suppressed because it is too large
Load Diff
772
iTechSharp/iTextSharp/text/pdf/ArabicLigaturizer.cs
Normal file
772
iTechSharp/iTextSharp/text/pdf/ArabicLigaturizer.cs
Normal file
@@ -0,0 +1,772 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
/*
|
||||
* Copyright 2003 by Paulo Soares.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.pdf {
|
||||
|
||||
/**
|
||||
* Shape arabic characters. This code was inspired by an LGPL'ed C library:
|
||||
* Pango ( see http://www.pango.com/ ). Note that the code of this is the
|
||||
* original work of Paulo Soares. Hence it is perfectly justifiable to distribute
|
||||
* it under the MPL.
|
||||
*
|
||||
* @author Paulo Soares (psoares@consiste.pt)
|
||||
*/
|
||||
public class ArabicLigaturizer {
|
||||
|
||||
static bool IsVowel(char s) {
|
||||
return ((s >= '\u064B') && (s <= '\u0655')) || (s == '\u0670');
|
||||
}
|
||||
|
||||
static char Charshape(char s, int which)
|
||||
/* which 0=isolated 1=final 2=initial 3=medial */
|
||||
{
|
||||
int l, r, m;
|
||||
if ((s >= '\u0621') && (s <= '\u06D3')) {
|
||||
l = 0;
|
||||
r = chartable.Length - 1;
|
||||
while (l <= r) {
|
||||
m = (l + r) / 2;
|
||||
if (s == chartable[m][0]) {
|
||||
return chartable[m][which + 1];
|
||||
}
|
||||
else if (s < chartable[m][0]) {
|
||||
r = m - 1;
|
||||
}
|
||||
else {
|
||||
l = m + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (s >= '\ufef5' && s <= '\ufefb')
|
||||
return (char)(s + which);
|
||||
return s;
|
||||
}
|
||||
|
||||
static int Shapecount(char s) {
|
||||
int l, r, m;
|
||||
if ((s >= '\u0621') && (s <= '\u06D3') && !IsVowel(s)) {
|
||||
l = 0;
|
||||
r = chartable.Length - 1;
|
||||
while (l <= r) {
|
||||
m = (l + r) / 2;
|
||||
if (s == chartable[m][0]) {
|
||||
return chartable[m].Length - 1;
|
||||
}
|
||||
else if (s < chartable[m][0]) {
|
||||
r = m - 1;
|
||||
}
|
||||
else {
|
||||
l = m + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (s == ZWJ) {
|
||||
return 4;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int Ligature(char newchar, Charstruct oldchar) {
|
||||
/* 0 == no ligature possible; 1 == vowel; 2 == two chars; 3 == Lam+Alef */
|
||||
int retval = 0;
|
||||
|
||||
if (oldchar.basechar == 0)
|
||||
return 0;
|
||||
if (IsVowel(newchar)) {
|
||||
retval = 1;
|
||||
if ((oldchar.vowel != 0) && (newchar != SHADDA)) {
|
||||
retval = 2; /* we eliminate the old vowel .. */
|
||||
}
|
||||
switch (newchar) {
|
||||
case SHADDA:
|
||||
if (oldchar.mark1 == 0) {
|
||||
oldchar.mark1 = SHADDA;
|
||||
}
|
||||
else {
|
||||
return 0; /* no ligature possible */
|
||||
}
|
||||
break;
|
||||
case HAMZABELOW:
|
||||
switch (oldchar.basechar) {
|
||||
case ALEF:
|
||||
oldchar.basechar = ALEFHAMZABELOW;
|
||||
retval = 2;
|
||||
break;
|
||||
case LAM_ALEF:
|
||||
oldchar.basechar = LAM_ALEFHAMZABELOW;
|
||||
retval = 2;
|
||||
break;
|
||||
default:
|
||||
oldchar.mark1 = HAMZABELOW;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case HAMZAABOVE:
|
||||
switch (oldchar.basechar) {
|
||||
case ALEF:
|
||||
oldchar.basechar = ALEFHAMZA;
|
||||
retval = 2;
|
||||
break;
|
||||
case LAM_ALEF:
|
||||
oldchar.basechar = LAM_ALEFHAMZA;
|
||||
retval = 2;
|
||||
break;
|
||||
case WAW:
|
||||
oldchar.basechar = WAWHAMZA;
|
||||
retval = 2;
|
||||
break;
|
||||
case YEH:
|
||||
case ALEFMAKSURA:
|
||||
case FARSIYEH:
|
||||
oldchar.basechar = YEHHAMZA;
|
||||
retval = 2;
|
||||
break;
|
||||
default: /* whatever sense this may make .. */
|
||||
oldchar.mark1 = HAMZAABOVE;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case MADDA:
|
||||
switch (oldchar.basechar) {
|
||||
case ALEF:
|
||||
oldchar.basechar = ALEFMADDA;
|
||||
retval = 2;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
oldchar.vowel = newchar;
|
||||
break;
|
||||
}
|
||||
if (retval == 1) {
|
||||
oldchar.lignum++;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
if (oldchar.vowel != 0) { /* if we already joined a vowel, we can't join a Hamza */
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (oldchar.basechar) {
|
||||
case LAM:
|
||||
switch (newchar) {
|
||||
case ALEF:
|
||||
oldchar.basechar = LAM_ALEF;
|
||||
oldchar.numshapes = 2;
|
||||
retval = 3;
|
||||
break;
|
||||
case ALEFHAMZA:
|
||||
oldchar.basechar = LAM_ALEFHAMZA;
|
||||
oldchar.numshapes = 2;
|
||||
retval = 3;
|
||||
break;
|
||||
case ALEFHAMZABELOW:
|
||||
oldchar.basechar = LAM_ALEFHAMZABELOW;
|
||||
oldchar.numshapes = 2;
|
||||
retval = 3;
|
||||
break;
|
||||
case ALEFMADDA:
|
||||
oldchar.basechar = LAM_ALEFMADDA;
|
||||
oldchar.numshapes = 2;
|
||||
retval = 3;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case (char)0:
|
||||
oldchar.basechar = newchar;
|
||||
oldchar.numshapes = Shapecount(newchar);
|
||||
retval = 1;
|
||||
break;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
static void Copycstostring(StringBuilder str, Charstruct s, int level) {
|
||||
/* s is a shaped charstruct; i is the index into the string */
|
||||
if (s.basechar == 0)
|
||||
return;
|
||||
|
||||
str.Append(s.basechar);
|
||||
s.lignum--;
|
||||
if (s.mark1 != 0) {
|
||||
if ((level & ar_novowel) == 0) {
|
||||
str.Append(s.mark1);
|
||||
s.lignum--;
|
||||
}
|
||||
else {
|
||||
s.lignum--;
|
||||
}
|
||||
}
|
||||
if (s.vowel != 0) {
|
||||
if ((level & ar_novowel) == 0) {
|
||||
str.Append(s.vowel);
|
||||
s.lignum--;
|
||||
}
|
||||
else { /* vowel elimination */
|
||||
s.lignum--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// return len
|
||||
internal static void Doublelig(StringBuilder str, int level)
|
||||
/* Ok. We have presentation ligatures in our font. */
|
||||
{
|
||||
int len;
|
||||
int olen = len = str.Length;
|
||||
int j = 0, si = 1;
|
||||
char lapresult;
|
||||
|
||||
while (si < olen) {
|
||||
lapresult = (char)0;
|
||||
if ((level & ar_composedtashkeel) != 0) {
|
||||
switch (str[j]) {
|
||||
case SHADDA:
|
||||
switch (str[si]) {
|
||||
case KASRA:
|
||||
lapresult = '\uFC62';
|
||||
break;
|
||||
case FATHA:
|
||||
lapresult = '\uFC60';
|
||||
break;
|
||||
case DAMMA:
|
||||
lapresult = '\uFC61';
|
||||
break;
|
||||
case '\u064C':
|
||||
lapresult = '\uFC5E';
|
||||
break;
|
||||
case '\u064D':
|
||||
lapresult = '\uFC5F';
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case KASRA:
|
||||
if (str[si] == SHADDA)
|
||||
lapresult = '\uFC62';
|
||||
break;
|
||||
case FATHA:
|
||||
if (str[si] == SHADDA)
|
||||
lapresult = '\uFC60';
|
||||
break;
|
||||
case DAMMA:
|
||||
if (str[si] == SHADDA)
|
||||
lapresult = '\uFC61';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ((level & ar_lig) != 0) {
|
||||
switch (str[j]) {
|
||||
case '\uFEDF': /* LAM initial */
|
||||
switch (str[si]) {
|
||||
case '\uFE9E':
|
||||
lapresult = '\uFC3F';
|
||||
break; /* JEEM final */
|
||||
case '\uFEA0':
|
||||
lapresult = '\uFCC9';
|
||||
break; /* JEEM medial */
|
||||
case '\uFEA2':
|
||||
lapresult = '\uFC40';
|
||||
break; /* HAH final */
|
||||
case '\uFEA4':
|
||||
lapresult = '\uFCCA';
|
||||
break; /* HAH medial */
|
||||
case '\uFEA6':
|
||||
lapresult = '\uFC41';
|
||||
break; /* KHAH final */
|
||||
case '\uFEA8':
|
||||
lapresult = '\uFCCB';
|
||||
break; /* KHAH medial */
|
||||
case '\uFEE2':
|
||||
lapresult = '\uFC42';
|
||||
break; /* MEEM final */
|
||||
case '\uFEE4':
|
||||
lapresult = '\uFCCC';
|
||||
break; /* MEEM medial */
|
||||
}
|
||||
break;
|
||||
case '\uFE97': /* TEH inital */
|
||||
switch (str[si]) {
|
||||
case '\uFEA0':
|
||||
lapresult = '\uFCA1';
|
||||
break; /* JEEM medial */
|
||||
case '\uFEA4':
|
||||
lapresult = '\uFCA2';
|
||||
break; /* HAH medial */
|
||||
case '\uFEA8':
|
||||
lapresult = '\uFCA3';
|
||||
break; /* KHAH medial */
|
||||
}
|
||||
break;
|
||||
case '\uFE91': /* BEH inital */
|
||||
switch (str[si]) {
|
||||
case '\uFEA0':
|
||||
lapresult = '\uFC9C';
|
||||
break; /* JEEM medial */
|
||||
case '\uFEA4':
|
||||
lapresult = '\uFC9D';
|
||||
break; /* HAH medial */
|
||||
case '\uFEA8':
|
||||
lapresult = '\uFC9E';
|
||||
break; /* KHAH medial */
|
||||
}
|
||||
break;
|
||||
case '\uFEE7': /* NOON inital */
|
||||
switch (str[si]) {
|
||||
case '\uFEA0':
|
||||
lapresult = '\uFCD2';
|
||||
break; /* JEEM initial */
|
||||
case '\uFEA4':
|
||||
lapresult = '\uFCD3';
|
||||
break; /* HAH medial */
|
||||
case '\uFEA8':
|
||||
lapresult = '\uFCD4';
|
||||
break; /* KHAH medial */
|
||||
}
|
||||
break;
|
||||
|
||||
case '\uFEE8': /* NOON medial */
|
||||
switch (str[si]) {
|
||||
case '\uFEAE':
|
||||
lapresult = '\uFC8A';
|
||||
break; /* REH final */
|
||||
case '\uFEB0':
|
||||
lapresult = '\uFC8B';
|
||||
break; /* ZAIN final */
|
||||
}
|
||||
break;
|
||||
case '\uFEE3': /* MEEM initial */
|
||||
switch (str[si]) {
|
||||
case '\uFEA0':
|
||||
lapresult = '\uFCCE';
|
||||
break; /* JEEM medial */
|
||||
case '\uFEA4':
|
||||
lapresult = '\uFCCF';
|
||||
break; /* HAH medial */
|
||||
case '\uFEA8':
|
||||
lapresult = '\uFCD0';
|
||||
break; /* KHAH medial */
|
||||
case '\uFEE4':
|
||||
lapresult = '\uFCD1';
|
||||
break; /* MEEM medial */
|
||||
}
|
||||
break;
|
||||
|
||||
case '\uFED3': /* FEH initial */
|
||||
switch (str[si]) {
|
||||
case '\uFEF2':
|
||||
lapresult = '\uFC32';
|
||||
break; /* YEH final */
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
} /* end switch string[si] */
|
||||
}
|
||||
if (lapresult != 0) {
|
||||
str[j] = lapresult;
|
||||
len--;
|
||||
si++; /* jump over one character */
|
||||
/* we'll have to change this, too. */
|
||||
}
|
||||
else {
|
||||
j++;
|
||||
str[j] = str[si];
|
||||
si++;
|
||||
}
|
||||
}
|
||||
str.Length = len;
|
||||
}
|
||||
|
||||
static bool Connects_to_left(Charstruct a) {
|
||||
return a.numshapes > 2;
|
||||
}
|
||||
|
||||
internal static void Shape(char[] text, StringBuilder str, int level) {
|
||||
/* string is assumed to be empty and big enough.
|
||||
* text is the original text.
|
||||
* This routine does the basic arabic reshaping.
|
||||
* *len the number of non-null characters.
|
||||
*
|
||||
* Note: We have to unshape each character first!
|
||||
*/
|
||||
int join;
|
||||
int which;
|
||||
char nextletter;
|
||||
|
||||
int p = 0; /* initialize for output */
|
||||
Charstruct oldchar = new Charstruct();
|
||||
Charstruct curchar = new Charstruct();
|
||||
while (p < text.Length) {
|
||||
nextletter = text[p++];
|
||||
//nextletter = unshape (nextletter);
|
||||
|
||||
join = Ligature(nextletter, curchar);
|
||||
if (join == 0) { /* shape curchar */
|
||||
int nc = Shapecount(nextletter);
|
||||
//(*len)++;
|
||||
if (nc == 1) {
|
||||
which = 0; /* final or isolated */
|
||||
}
|
||||
else {
|
||||
which = 2; /* medial or initial */
|
||||
}
|
||||
if (Connects_to_left(oldchar)) {
|
||||
which++;
|
||||
}
|
||||
|
||||
which = which % (curchar.numshapes);
|
||||
curchar.basechar = Charshape(curchar.basechar, which);
|
||||
|
||||
/* get rid of oldchar */
|
||||
Copycstostring(str, oldchar, level);
|
||||
oldchar = curchar; /* new values in oldchar */
|
||||
|
||||
/* init new curchar */
|
||||
curchar = new Charstruct();
|
||||
curchar.basechar = nextletter;
|
||||
curchar.numshapes = nc;
|
||||
curchar.lignum++;
|
||||
// (*len) += unligature (&curchar, level);
|
||||
}
|
||||
else if (join == 1) {
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// (*len) += unligature (&curchar, level);
|
||||
// }
|
||||
// p = g_utf8_next_char (p);
|
||||
}
|
||||
|
||||
/* Handle last char */
|
||||
if (Connects_to_left(oldchar))
|
||||
which = 1;
|
||||
else
|
||||
which = 0;
|
||||
which = which % (curchar.numshapes);
|
||||
curchar.basechar = Charshape(curchar.basechar, which);
|
||||
|
||||
/* get rid of oldchar */
|
||||
Copycstostring(str, oldchar, level);
|
||||
Copycstostring(str, curchar, level);
|
||||
}
|
||||
|
||||
internal static int Arabic_shape(char[] src, int srcoffset, int srclength, char[] dest, int destoffset, int destlength, int level) {
|
||||
char[] str = new char[srclength];
|
||||
for (int k = srclength + srcoffset - 1; k >= srcoffset; --k)
|
||||
str[k - srcoffset] = src[k];
|
||||
StringBuilder str2 = new StringBuilder(srclength);
|
||||
Shape(str, str2, level);
|
||||
if ((level & (ar_composedtashkeel | ar_lig)) != 0)
|
||||
Doublelig(str2, level);
|
||||
// string.Reverse();
|
||||
System.Array.Copy(str2.ToString().ToCharArray(), 0, dest, destoffset, str2.Length);
|
||||
return str2.Length;
|
||||
}
|
||||
|
||||
internal static void ProcessNumbers(char[] text, int offset, int length, int options) {
|
||||
int limit = offset + length;
|
||||
if ((options & DIGITS_MASK) != 0) {
|
||||
char digitBase = '\u0030'; // European digits
|
||||
switch (options & DIGIT_TYPE_MASK) {
|
||||
case DIGIT_TYPE_AN:
|
||||
digitBase = '\u0660'; // Arabic-Indic digits
|
||||
break;
|
||||
|
||||
case DIGIT_TYPE_AN_EXTENDED:
|
||||
digitBase = '\u06f0'; // Eastern Arabic-Indic digits (Persian and Urdu)
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (options & DIGITS_MASK) {
|
||||
case DIGITS_EN2AN: {
|
||||
int digitDelta = digitBase - '\u0030';
|
||||
for (int i = offset; i < limit; ++i) {
|
||||
char ch = text[i];
|
||||
if (ch <= '\u0039' && ch >= '\u0030') {
|
||||
text[i] += (char)digitDelta;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case DIGITS_AN2EN: {
|
||||
char digitTop = (char)(digitBase + 9);
|
||||
int digitDelta = '\u0030' - digitBase;
|
||||
for (int i = offset; i < limit; ++i) {
|
||||
char ch = text[i];
|
||||
if (ch <= digitTop && ch >= digitBase) {
|
||||
text[i] += (char)digitDelta;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case DIGITS_EN2AN_INIT_LR:
|
||||
ShapeToArabicDigitsWithContext(text, 0, length, digitBase, false);
|
||||
break;
|
||||
|
||||
case DIGITS_EN2AN_INIT_AL:
|
||||
ShapeToArabicDigitsWithContext(text, 0, length, digitBase, true);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static void ShapeToArabicDigitsWithContext(char[] dest, int start, int length, char digitBase, bool lastStrongWasAL) {
|
||||
digitBase -= '0'; // move common adjustment out of loop
|
||||
|
||||
int limit = start + length;
|
||||
for (int i = start; i < limit; ++i) {
|
||||
char ch = dest[i];
|
||||
switch (BidiOrder.GetDirection(ch)) {
|
||||
case BidiOrder.L:
|
||||
case BidiOrder.R:
|
||||
lastStrongWasAL = false;
|
||||
break;
|
||||
case BidiOrder.AL:
|
||||
lastStrongWasAL = true;
|
||||
break;
|
||||
case BidiOrder.EN:
|
||||
if (lastStrongWasAL && ch <= '\u0039') {
|
||||
dest[i] = (char)(ch + digitBase);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private const char ALEF = '\u0627';
|
||||
private const char ALEFHAMZA = '\u0623';
|
||||
private const char ALEFHAMZABELOW = '\u0625';
|
||||
private const char ALEFMADDA = '\u0622';
|
||||
private const char LAM = '\u0644';
|
||||
private const char HAMZA = '\u0621';
|
||||
private const char TATWEEL = '\u0640';
|
||||
private const char ZWJ = '\u200D';
|
||||
|
||||
private const char HAMZAABOVE = '\u0654';
|
||||
private const char HAMZABELOW = '\u0655';
|
||||
|
||||
private const char WAWHAMZA = '\u0624';
|
||||
private const char YEHHAMZA = '\u0626';
|
||||
private const char WAW = '\u0648';
|
||||
private const char ALEFMAKSURA = '\u0649';
|
||||
private const char YEH = '\u064A';
|
||||
private const char FARSIYEH = '\u06CC';
|
||||
|
||||
private const char SHADDA = '\u0651';
|
||||
private const char KASRA = '\u0650';
|
||||
private const char FATHA = '\u064E';
|
||||
private const char DAMMA = '\u064F';
|
||||
private const char MADDA = '\u0653';
|
||||
|
||||
private const char LAM_ALEF = '\uFEFB';
|
||||
private const char LAM_ALEFHAMZA = '\uFEF7';
|
||||
private const char LAM_ALEFHAMZABELOW = '\uFEF9';
|
||||
private const char LAM_ALEFMADDA = '\uFEF5';
|
||||
|
||||
private static char[][] chartable = {
|
||||
new char[]{'\u0621', '\uFE80'}, /* HAMZA */
|
||||
new char[]{'\u0622', '\uFE81', '\uFE82'}, /* ALEF WITH MADDA ABOVE */
|
||||
new char[]{'\u0623', '\uFE83', '\uFE84'}, /* ALEF WITH HAMZA ABOVE */
|
||||
new char[]{'\u0624', '\uFE85', '\uFE86'}, /* WAW WITH HAMZA ABOVE */
|
||||
new char[]{'\u0625', '\uFE87', '\uFE88'}, /* ALEF WITH HAMZA BELOW */
|
||||
new char[]{'\u0626', '\uFE89', '\uFE8A', '\uFE8B', '\uFE8C'}, /* YEH WITH HAMZA ABOVE */
|
||||
new char[]{'\u0627', '\uFE8D', '\uFE8E'}, /* ALEF */
|
||||
new char[]{'\u0628', '\uFE8F', '\uFE90', '\uFE91', '\uFE92'}, /* BEH */
|
||||
new char[]{'\u0629', '\uFE93', '\uFE94'}, /* TEH MARBUTA */
|
||||
new char[]{'\u062A', '\uFE95', '\uFE96', '\uFE97', '\uFE98'}, /* TEH */
|
||||
new char[]{'\u062B', '\uFE99', '\uFE9A', '\uFE9B', '\uFE9C'}, /* THEH */
|
||||
new char[]{'\u062C', '\uFE9D', '\uFE9E', '\uFE9F', '\uFEA0'}, /* JEEM */
|
||||
new char[]{'\u062D', '\uFEA1', '\uFEA2', '\uFEA3', '\uFEA4'}, /* HAH */
|
||||
new char[]{'\u062E', '\uFEA5', '\uFEA6', '\uFEA7', '\uFEA8'}, /* KHAH */
|
||||
new char[]{'\u062F', '\uFEA9', '\uFEAA'}, /* DAL */
|
||||
new char[]{'\u0630', '\uFEAB', '\uFEAC'}, /* THAL */
|
||||
new char[]{'\u0631', '\uFEAD', '\uFEAE'}, /* REH */
|
||||
new char[]{'\u0632', '\uFEAF', '\uFEB0'}, /* ZAIN */
|
||||
new char[]{'\u0633', '\uFEB1', '\uFEB2', '\uFEB3', '\uFEB4'}, /* SEEN */
|
||||
new char[]{'\u0634', '\uFEB5', '\uFEB6', '\uFEB7', '\uFEB8'}, /* SHEEN */
|
||||
new char[]{'\u0635', '\uFEB9', '\uFEBA', '\uFEBB', '\uFEBC'}, /* SAD */
|
||||
new char[]{'\u0636', '\uFEBD', '\uFEBE', '\uFEBF', '\uFEC0'}, /* DAD */
|
||||
new char[]{'\u0637', '\uFEC1', '\uFEC2', '\uFEC3', '\uFEC4'}, /* TAH */
|
||||
new char[]{'\u0638', '\uFEC5', '\uFEC6', '\uFEC7', '\uFEC8'}, /* ZAH */
|
||||
new char[]{'\u0639', '\uFEC9', '\uFECA', '\uFECB', '\uFECC'}, /* AIN */
|
||||
new char[]{'\u063A', '\uFECD', '\uFECE', '\uFECF', '\uFED0'}, /* GHAIN */
|
||||
new char[]{'\u0640', '\u0640', '\u0640', '\u0640', '\u0640'}, /* TATWEEL */
|
||||
new char[]{'\u0641', '\uFED1', '\uFED2', '\uFED3', '\uFED4'}, /* FEH */
|
||||
new char[]{'\u0642', '\uFED5', '\uFED6', '\uFED7', '\uFED8'}, /* QAF */
|
||||
new char[]{'\u0643', '\uFED9', '\uFEDA', '\uFEDB', '\uFEDC'}, /* KAF */
|
||||
new char[]{'\u0644', '\uFEDD', '\uFEDE', '\uFEDF', '\uFEE0'}, /* LAM */
|
||||
new char[]{'\u0645', '\uFEE1', '\uFEE2', '\uFEE3', '\uFEE4'}, /* MEEM */
|
||||
new char[]{'\u0646', '\uFEE5', '\uFEE6', '\uFEE7', '\uFEE8'}, /* NOON */
|
||||
new char[]{'\u0647', '\uFEE9', '\uFEEA', '\uFEEB', '\uFEEC'}, /* HEH */
|
||||
new char[]{'\u0648', '\uFEED', '\uFEEE'}, /* WAW */
|
||||
new char[]{'\u0649', '\uFEEF', '\uFEF0', '\uFBE8', '\uFBE9'}, /* ALEF MAKSURA */
|
||||
new char[]{'\u064A', '\uFEF1', '\uFEF2', '\uFEF3', '\uFEF4'}, /* YEH */
|
||||
new char[]{'\u0671', '\uFB50', '\uFB51'}, /* ALEF WASLA */
|
||||
new char[]{'\u0679', '\uFB66', '\uFB67', '\uFB68', '\uFB69'}, /* TTEH */
|
||||
new char[]{'\u067A', '\uFB5E', '\uFB5F', '\uFB60', '\uFB61'}, /* TTEHEH */
|
||||
new char[]{'\u067B', '\uFB52', '\uFB53', '\uFB54', '\uFB55'}, /* BEEH */
|
||||
new char[]{'\u067E', '\uFB56', '\uFB57', '\uFB58', '\uFB59'}, /* PEH */
|
||||
new char[]{'\u067F', '\uFB62', '\uFB63', '\uFB64', '\uFB65'}, /* TEHEH */
|
||||
new char[]{'\u0680', '\uFB5A', '\uFB5B', '\uFB5C', '\uFB5D'}, /* BEHEH */
|
||||
new char[]{'\u0683', '\uFB76', '\uFB77', '\uFB78', '\uFB79'}, /* NYEH */
|
||||
new char[]{'\u0684', '\uFB72', '\uFB73', '\uFB74', '\uFB75'}, /* DYEH */
|
||||
new char[]{'\u0686', '\uFB7A', '\uFB7B', '\uFB7C', '\uFB7D'}, /* TCHEH */
|
||||
new char[]{'\u0687', '\uFB7E', '\uFB7F', '\uFB80', '\uFB81'}, /* TCHEHEH */
|
||||
new char[]{'\u0688', '\uFB88', '\uFB89'}, /* DDAL */
|
||||
new char[]{'\u068C', '\uFB84', '\uFB85'}, /* DAHAL */
|
||||
new char[]{'\u068D', '\uFB82', '\uFB83'}, /* DDAHAL */
|
||||
new char[]{'\u068E', '\uFB86', '\uFB87'}, /* DUL */
|
||||
new char[]{'\u0691', '\uFB8C', '\uFB8D'}, /* RREH */
|
||||
new char[]{'\u0698', '\uFB8A', '\uFB8B'}, /* JEH */
|
||||
new char[]{'\u06A4', '\uFB6A', '\uFB6B', '\uFB6C', '\uFB6D'}, /* VEH */
|
||||
new char[]{'\u06A6', '\uFB6E', '\uFB6F', '\uFB70', '\uFB71'}, /* PEHEH */
|
||||
new char[]{'\u06A9', '\uFB8E', '\uFB8F', '\uFB90', '\uFB91'}, /* KEHEH */
|
||||
new char[]{'\u06AD', '\uFBD3', '\uFBD4', '\uFBD5', '\uFBD6'}, /* NG */
|
||||
new char[]{'\u06AF', '\uFB92', '\uFB93', '\uFB94', '\uFB95'}, /* GAF */
|
||||
new char[]{'\u06B1', '\uFB9A', '\uFB9B', '\uFB9C', '\uFB9D'}, /* NGOEH */
|
||||
new char[]{'\u06B3', '\uFB96', '\uFB97', '\uFB98', '\uFB99'}, /* GUEH */
|
||||
new char[]{'\u06BA', '\uFB9E', '\uFB9F'}, /* NOON GHUNNA */
|
||||
new char[]{'\u06BB', '\uFBA0', '\uFBA1', '\uFBA2', '\uFBA3'}, /* RNOON */
|
||||
new char[]{'\u06BE', '\uFBAA', '\uFBAB', '\uFBAC', '\uFBAD'}, /* HEH DOACHASHMEE */
|
||||
new char[]{'\u06C0', '\uFBA4', '\uFBA5'}, /* HEH WITH YEH ABOVE */
|
||||
new char[]{'\u06C1', '\uFBA6', '\uFBA7', '\uFBA8', '\uFBA9'}, /* HEH GOAL */
|
||||
new char[]{'\u06C5', '\uFBE0', '\uFBE1'}, /* KIRGHIZ OE */
|
||||
new char[]{'\u06C6', '\uFBD9', '\uFBDA'}, /* OE */
|
||||
new char[]{'\u06C7', '\uFBD7', '\uFBD8'}, /* U */
|
||||
new char[]{'\u06C8', '\uFBDB', '\uFBDC'}, /* YU */
|
||||
new char[]{'\u06C9', '\uFBE2', '\uFBE3'}, /* KIRGHIZ YU */
|
||||
new char[]{'\u06CB', '\uFBDE', '\uFBDF'}, /* VE */
|
||||
new char[]{'\u06CC', '\uFBFC', '\uFBFD', '\uFBFE', '\uFBFF'}, /* FARSI YEH */
|
||||
new char[]{'\u06D0', '\uFBE4', '\uFBE5', '\uFBE6', '\uFBE7'}, /* E */
|
||||
new char[]{'\u06D2', '\uFBAE', '\uFBAF'}, /* YEH BARREE */
|
||||
new char[]{'\u06D3', '\uFBB0', '\uFBB1'} /* YEH BARREE WITH HAMZA ABOVE */
|
||||
};
|
||||
|
||||
public const int ar_nothing = 0x0;
|
||||
public const int ar_novowel = 0x1;
|
||||
public const int ar_composedtashkeel = 0x4;
|
||||
public const int ar_lig = 0x8;
|
||||
/**
|
||||
* Digit shaping option: Replace European digits (U+0030...U+0039) by Arabic-Indic digits.
|
||||
*/
|
||||
public const int DIGITS_EN2AN = 0x20;
|
||||
|
||||
/**
|
||||
* Digit shaping option: Replace Arabic-Indic digits by European digits (U+0030...U+0039).
|
||||
*/
|
||||
public const int DIGITS_AN2EN = 0x40;
|
||||
|
||||
/**
|
||||
* Digit shaping option:
|
||||
* Replace European digits (U+0030...U+0039) by Arabic-Indic digits
|
||||
* if the most recent strongly directional character
|
||||
* is an Arabic letter (its Bidi direction value is RIGHT_TO_LEFT_ARABIC).
|
||||
* The initial state at the start of the text is assumed to be not an Arabic,
|
||||
* letter, so European digits at the start of the text will not change.
|
||||
* Compare to DIGITS_ALEN2AN_INIT_AL.
|
||||
*/
|
||||
public const int DIGITS_EN2AN_INIT_LR = 0x60;
|
||||
|
||||
/**
|
||||
* Digit shaping option:
|
||||
* Replace European digits (U+0030...U+0039) by Arabic-Indic digits
|
||||
* if the most recent strongly directional character
|
||||
* is an Arabic letter (its Bidi direction value is RIGHT_TO_LEFT_ARABIC).
|
||||
* The initial state at the start of the text is assumed to be an Arabic,
|
||||
* letter, so European digits at the start of the text will change.
|
||||
* Compare to DIGITS_ALEN2AN_INT_LR.
|
||||
*/
|
||||
public const int DIGITS_EN2AN_INIT_AL = 0x80;
|
||||
|
||||
/** Not a valid option value. */
|
||||
private const int DIGITS_RESERVED = 0xa0;
|
||||
|
||||
/**
|
||||
* Bit mask for digit shaping options.
|
||||
*/
|
||||
public const int DIGITS_MASK = 0xe0;
|
||||
|
||||
/**
|
||||
* Digit type option: Use Arabic-Indic digits (U+0660...U+0669).
|
||||
*/
|
||||
public const int DIGIT_TYPE_AN = 0;
|
||||
|
||||
/**
|
||||
* Digit type option: Use Eastern (Extended) Arabic-Indic digits (U+06f0...U+06f9).
|
||||
*/
|
||||
public const int DIGIT_TYPE_AN_EXTENDED = 0x100;
|
||||
|
||||
/**
|
||||
* Bit mask for digit type options.
|
||||
*/
|
||||
public const int DIGIT_TYPE_MASK = '\u0100'; // '\u3f00'?
|
||||
|
||||
private class Charstruct {
|
||||
internal char basechar;
|
||||
internal char mark1; /* has to be initialized to zero */
|
||||
internal char vowel;
|
||||
internal int lignum; /* is a ligature with lignum aditional characters */
|
||||
internal int numshapes = 1;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
59
iTechSharp/iTextSharp/text/pdf/BadPasswordException.cs
Normal file
59
iTechSharp/iTextSharp/text/pdf/BadPasswordException.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
/*
|
||||
* $Id: BadPasswordException.cs,v 1.1 2008/01/10 15:49:39 psoares33 Exp $
|
||||
*
|
||||
* Copyright 2008 Bruno Lowagie
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.pdf {
|
||||
|
||||
public class BadPasswordException : IOException {
|
||||
public BadPasswordException() : base("Bad user Password") {
|
||||
}
|
||||
}
|
||||
}
|
||||
72
iTechSharp/iTextSharp/text/pdf/BadPdfFormatException.cs
Normal file
72
iTechSharp/iTextSharp/text/pdf/BadPdfFormatException.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
|
||||
/*
|
||||
* $Id: BadPdfFormatException.cs,v 1.3 2008/05/13 11:25:16 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.pdf
|
||||
{
|
||||
/**
|
||||
* Signals that a bad PDF format has been used to construct a <CODE>PdfObject</CODE>.
|
||||
*
|
||||
* @see PdfException
|
||||
* @see PdfBoolean
|
||||
* @see PdfNumber
|
||||
* @see PdfString
|
||||
* @see PdfName
|
||||
* @see PdfDictionary
|
||||
* @see PdfFont
|
||||
*/
|
||||
|
||||
public class BadPdfFormatException : Exception
|
||||
{
|
||||
public BadPdfFormatException() : base() {}
|
||||
public BadPdfFormatException(string message) : base(message) {}
|
||||
}
|
||||
}
|
||||
430
iTechSharp/iTextSharp/text/pdf/Barcode.cs
Normal file
430
iTechSharp/iTextSharp/text/pdf/Barcode.cs
Normal file
@@ -0,0 +1,430 @@
|
||||
using System;
|
||||
using iTextSharp.text;
|
||||
/*
|
||||
* $Id: Barcode.cs,v 1.4 2006/07/31 13:51:38 psoares33 Exp $
|
||||
*
|
||||
* Copyright 2002-2006 by Paulo Soares.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
namespace iTextSharp.text.pdf {
|
||||
/** Base class containing properties and methods commom to all
|
||||
* barcode types.
|
||||
*
|
||||
* @author Paulo Soares (psoares@consiste.pt)
|
||||
*/
|
||||
public abstract class Barcode {
|
||||
/** A type of barcode */
|
||||
public const int EAN13 = 1;
|
||||
/** A type of barcode */
|
||||
public const int EAN8 = 2;
|
||||
/** A type of barcode */
|
||||
public const int UPCA = 3;
|
||||
/** A type of barcode */
|
||||
public const int UPCE = 4;
|
||||
/** A type of barcode */
|
||||
public const int SUPP2 = 5;
|
||||
/** A type of barcode */
|
||||
public const int SUPP5 = 6;
|
||||
/** A type of barcode */
|
||||
public const int POSTNET = 7;
|
||||
/** A type of barcode */
|
||||
public const int PLANET = 8;
|
||||
/** A type of barcode */
|
||||
public const int CODE128 = 9;
|
||||
/** A type of barcode */
|
||||
public const int CODE128_UCC = 10;
|
||||
/** A type of barcode */
|
||||
public const int CODE128_RAW = 11;
|
||||
/** A type of barcode */
|
||||
public const int CODABAR = 12;
|
||||
|
||||
/** The minimum bar width.
|
||||
*/
|
||||
protected float x;
|
||||
|
||||
/** The bar multiplier for wide bars or the distance between
|
||||
* bars for Postnet and Planet.
|
||||
*/
|
||||
protected float n;
|
||||
|
||||
/** The text font. <CODE>null</CODE> if no text.
|
||||
*/
|
||||
protected BaseFont font;
|
||||
|
||||
/** The size of the text or the height of the shorter bar
|
||||
* in Postnet.
|
||||
*/
|
||||
protected float size;
|
||||
|
||||
/** If positive, the text distance under the bars. If zero or negative,
|
||||
* the text distance above the bars.
|
||||
*/
|
||||
protected float baseline;
|
||||
|
||||
/** The height of the bars.
|
||||
*/
|
||||
protected float barHeight;
|
||||
|
||||
/** The text Element. Can be <CODE>Element.ALIGN_LEFT</CODE>,
|
||||
* <CODE>Element.ALIGN_CENTER</CODE> or <CODE>Element.ALIGN_RIGHT</CODE>.
|
||||
*/
|
||||
protected int textAlignment;
|
||||
|
||||
/** The optional checksum generation.
|
||||
*/
|
||||
protected bool generateChecksum;
|
||||
|
||||
/** Shows the generated checksum in the the text.
|
||||
*/
|
||||
protected bool checksumText;
|
||||
|
||||
/** Show the start and stop character '*' in the text for
|
||||
* the barcode 39 or 'ABCD' for codabar.
|
||||
*/
|
||||
protected bool startStopText;
|
||||
|
||||
/** Generates extended barcode 39.
|
||||
*/
|
||||
protected bool extended;
|
||||
|
||||
/** The code to generate.
|
||||
*/
|
||||
protected string code = "";
|
||||
|
||||
/** Show the guard bars for barcode EAN.
|
||||
*/
|
||||
protected bool guardBars;
|
||||
|
||||
/** The code type.
|
||||
*/
|
||||
protected int codeType;
|
||||
|
||||
/** The ink spreading. */
|
||||
protected float inkSpreading = 0;
|
||||
|
||||
/** Gets the minimum bar width.
|
||||
* @return the minimum bar width
|
||||
*/
|
||||
public float X {
|
||||
get {
|
||||
return x;
|
||||
}
|
||||
|
||||
set {
|
||||
this.x = value;
|
||||
}
|
||||
}
|
||||
|
||||
/** Gets the bar multiplier for wide bars.
|
||||
* @return the bar multiplier for wide bars
|
||||
*/
|
||||
public float N {
|
||||
get {
|
||||
return n;
|
||||
}
|
||||
|
||||
set {
|
||||
this.n = value;
|
||||
}
|
||||
}
|
||||
|
||||
/** Gets the text font. <CODE>null</CODE> if no text.
|
||||
* @return the text font. <CODE>null</CODE> if no text
|
||||
*/
|
||||
public BaseFont Font {
|
||||
get {
|
||||
return font;
|
||||
}
|
||||
|
||||
set {
|
||||
this.font = value;
|
||||
}
|
||||
}
|
||||
|
||||
/** Gets the size of the text.
|
||||
* @return the size of the text
|
||||
*/
|
||||
public float Size {
|
||||
get {
|
||||
return size;
|
||||
}
|
||||
|
||||
set {
|
||||
this.size = value;
|
||||
}
|
||||
}
|
||||
|
||||
/** Gets the text baseline.
|
||||
* If positive, the text distance under the bars. If zero or negative,
|
||||
* the text distance above the bars.
|
||||
* @return the baseline.
|
||||
*/
|
||||
public float Baseline {
|
||||
get {
|
||||
return baseline;
|
||||
}
|
||||
|
||||
set {
|
||||
this.baseline = value;
|
||||
}
|
||||
}
|
||||
|
||||
/** Gets the height of the bars.
|
||||
* @return the height of the bars
|
||||
*/
|
||||
public float BarHeight {
|
||||
get {
|
||||
return barHeight;
|
||||
}
|
||||
|
||||
set {
|
||||
this.barHeight = value;
|
||||
}
|
||||
}
|
||||
|
||||
/** Gets the text Element. Can be <CODE>Element.ALIGN_LEFT</CODE>,
|
||||
* <CODE>Element.ALIGN_CENTER</CODE> or <CODE>Element.ALIGN_RIGHT</CODE>.
|
||||
* @return the text alignment
|
||||
*/
|
||||
public int TextAlignment{
|
||||
get {
|
||||
return textAlignment;
|
||||
}
|
||||
|
||||
set {
|
||||
this.textAlignment = value;
|
||||
}
|
||||
}
|
||||
|
||||
/** The property for the optional checksum generation.
|
||||
*/
|
||||
public bool GenerateChecksum {
|
||||
set {
|
||||
this.generateChecksum = value;
|
||||
}
|
||||
get {
|
||||
return generateChecksum;
|
||||
}
|
||||
}
|
||||
|
||||
/** Sets the property to show the generated checksum in the the text.
|
||||
* @param checksumText new value of property checksumText
|
||||
*/
|
||||
public bool ChecksumText {
|
||||
set {
|
||||
this.checksumText = value;
|
||||
}
|
||||
get {
|
||||
return checksumText;
|
||||
}
|
||||
}
|
||||
|
||||
/** Gets the property to show the start and stop character '*' in the text for
|
||||
* the barcode 39.
|
||||
* @param startStopText new value of property startStopText
|
||||
*/
|
||||
public bool StartStopText {
|
||||
set {
|
||||
this.startStopText = value;
|
||||
}
|
||||
get {
|
||||
return startStopText;
|
||||
}
|
||||
}
|
||||
|
||||
/** Sets the property to generate extended barcode 39.
|
||||
* @param extended new value of property extended
|
||||
*/
|
||||
public bool Extended {
|
||||
set {
|
||||
this.extended = value;
|
||||
}
|
||||
get {
|
||||
return extended;
|
||||
}
|
||||
}
|
||||
|
||||
/** Gets the code to generate.
|
||||
* @return the code to generate
|
||||
*/
|
||||
public virtual string Code {
|
||||
get {
|
||||
return code;
|
||||
}
|
||||
|
||||
set {
|
||||
this.code = value;
|
||||
}
|
||||
}
|
||||
|
||||
/** Sets the property to show the guard bars for barcode EAN.
|
||||
* @param guardBars new value of property guardBars
|
||||
*/
|
||||
public bool GuardBars {
|
||||
set {
|
||||
this.guardBars = value;
|
||||
}
|
||||
get {
|
||||
return guardBars;
|
||||
}
|
||||
}
|
||||
|
||||
/** Gets the code type.
|
||||
* @return the code type
|
||||
*/
|
||||
public int CodeType {
|
||||
get {
|
||||
return codeType;
|
||||
}
|
||||
|
||||
set {
|
||||
this.codeType = value;
|
||||
}
|
||||
}
|
||||
|
||||
/** Gets the maximum area that the barcode and the text, if
|
||||
* any, will occupy. The lower left corner is always (0, 0).
|
||||
* @return the size the barcode occupies.
|
||||
*/
|
||||
public abstract Rectangle BarcodeSize {
|
||||
get;
|
||||
}
|
||||
|
||||
public float InkSpreading {
|
||||
set {
|
||||
inkSpreading = value;
|
||||
}
|
||||
get {
|
||||
return inkSpreading;
|
||||
}
|
||||
}
|
||||
|
||||
/** Places the barcode in a <CODE>PdfContentByte</CODE>. The
|
||||
* barcode is always placed at coodinates (0, 0). Use the
|
||||
* translation matrix to move it elsewhere.<p>
|
||||
* The bars and text are written in the following colors:<p>
|
||||
* <P><TABLE BORDER=1>
|
||||
* <TR>
|
||||
* <TH><P><CODE>barColor</CODE></TH>
|
||||
* <TH><P><CODE>textColor</CODE></TH>
|
||||
* <TH><P>Result</TH>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD><P><CODE>null</CODE></TD>
|
||||
* <TD><P><CODE>null</CODE></TD>
|
||||
* <TD><P>bars and text painted with current fill color</TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD><P><CODE>barColor</CODE></TD>
|
||||
* <TD><P><CODE>null</CODE></TD>
|
||||
* <TD><P>bars and text painted with <CODE>barColor</CODE></TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD><P><CODE>null</CODE></TD>
|
||||
* <TD><P><CODE>textColor</CODE></TD>
|
||||
* <TD><P>bars painted with current color<br>text painted with <CODE>textColor</CODE></TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD><P><CODE>barColor</CODE></TD>
|
||||
* <TD><P><CODE>textColor</CODE></TD>
|
||||
* <TD><P>bars painted with <CODE>barColor</CODE><br>text painted with <CODE>textColor</CODE></TD>
|
||||
* </TR>
|
||||
* </TABLE>
|
||||
* @param cb the <CODE>PdfContentByte</CODE> where the barcode will be placed
|
||||
* @param barColor the color of the bars. It can be <CODE>null</CODE>
|
||||
* @param textColor the color of the text. It can be <CODE>null</CODE>
|
||||
* @return the dimensions the barcode occupies
|
||||
*/
|
||||
public abstract Rectangle PlaceBarcode(PdfContentByte cb, Color barColor, Color textColor);
|
||||
|
||||
/** Creates a template with the barcode.
|
||||
* @param cb the <CODE>PdfContentByte</CODE> to create the template. It
|
||||
* serves no other use
|
||||
* @param barColor the color of the bars. It can be <CODE>null</CODE>
|
||||
* @param textColor the color of the text. It can be <CODE>null</CODE>
|
||||
* @return the template
|
||||
* @see #placeBarcode(PdfContentByte cb, Color barColor, Color textColor)
|
||||
*/
|
||||
public PdfTemplate CreateTemplateWithBarcode(PdfContentByte cb, Color barColor, Color textColor) {
|
||||
PdfTemplate tp = cb.CreateTemplate(0, 0);
|
||||
Rectangle rect = PlaceBarcode(tp, barColor, textColor);
|
||||
tp.BoundingBox = rect;
|
||||
return tp;
|
||||
}
|
||||
|
||||
/** Creates an <CODE>Image</CODE> with the barcode.
|
||||
* @param cb the <CODE>PdfContentByte</CODE> to create the <CODE>Image</CODE>. It
|
||||
* serves no other use
|
||||
* @param barColor the color of the bars. It can be <CODE>null</CODE>
|
||||
* @param textColor the color of the text. It can be <CODE>null</CODE>
|
||||
* @return the <CODE>Image</CODE>
|
||||
* @see #placeBarcode(PdfContentByte cb, Color barColor, Color textColor)
|
||||
*/
|
||||
public Image CreateImageWithBarcode(PdfContentByte cb, Color barColor, Color textColor) {
|
||||
return Image.GetInstance(CreateTemplateWithBarcode(cb, barColor, textColor));
|
||||
}
|
||||
|
||||
/**
|
||||
* The alternate text to be used, if present.
|
||||
*/
|
||||
protected String altText;
|
||||
|
||||
/**
|
||||
* Sets the alternate text. If present, this text will be used instead of the
|
||||
* text derived from the supplied code.
|
||||
* @param altText the alternate text
|
||||
*/
|
||||
public String AltText {
|
||||
set {
|
||||
altText = value;
|
||||
}
|
||||
get {
|
||||
return altText;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract System.Drawing.Image CreateDrawingImage(System.Drawing.Color foreground, System.Drawing.Color background);
|
||||
}
|
||||
}
|
||||
809
iTechSharp/iTextSharp/text/pdf/Barcode128.cs
Normal file
809
iTechSharp/iTextSharp/text/pdf/Barcode128.cs
Normal file
@@ -0,0 +1,809 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using iTextSharp.text;
|
||||
/*
|
||||
* $Id: Barcode128.cs,v 1.6 2007/10/24 16:31:54 psoares33 Exp $
|
||||
*
|
||||
* Copyright 2002-2006 by Paulo Soares.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
namespace iTextSharp.text.pdf {
|
||||
/** Implements the code 128 and UCC/EAN-128. Other symbologies are allowed in raw mode.<p>
|
||||
* The code types allowed are:<br>
|
||||
* <ul>
|
||||
* <li><b>CODE128</b> - plain barcode 128.
|
||||
* <li><b>CODE128_UCC</b> - support for UCC/EAN-128 with a full list of AI.
|
||||
* <li><b>CODE128_RAW</b> - raw mode. The code attribute has the actual codes from 0
|
||||
* to 105 followed by '\uffff' and the human readable text.
|
||||
* </ul>
|
||||
* The default parameters are:
|
||||
* <pre>
|
||||
* x = 0.8f;
|
||||
* font = BaseFont.CreateFont("Helvetica", "winansi", false);
|
||||
* size = 8;
|
||||
* baseline = size;
|
||||
* barHeight = size * 3;
|
||||
* textint= Element.ALIGN_CENTER;
|
||||
* codeType = CODE128;
|
||||
* </pre>
|
||||
*
|
||||
* @author Paulo Soares (psoares@consiste.pt)
|
||||
*/
|
||||
public class Barcode128 : Barcode {
|
||||
|
||||
/** The bars to generate the code.
|
||||
*/
|
||||
private static readonly byte[][] BARS =
|
||||
{
|
||||
new byte[] {2, 1, 2, 2, 2, 2},
|
||||
new byte[] {2, 2, 2, 1, 2, 2},
|
||||
new byte[] {2, 2, 2, 2, 2, 1},
|
||||
new byte[] {1, 2, 1, 2, 2, 3},
|
||||
new byte[] {1, 2, 1, 3, 2, 2},
|
||||
new byte[] {1, 3, 1, 2, 2, 2},
|
||||
new byte[] {1, 2, 2, 2, 1, 3},
|
||||
new byte[] {1, 2, 2, 3, 1, 2},
|
||||
new byte[] {1, 3, 2, 2, 1, 2},
|
||||
new byte[] {2, 2, 1, 2, 1, 3},
|
||||
new byte[] {2, 2, 1, 3, 1, 2},
|
||||
new byte[] {2, 3, 1, 2, 1, 2},
|
||||
new byte[] {1, 1, 2, 2, 3, 2},
|
||||
new byte[] {1, 2, 2, 1, 3, 2},
|
||||
new byte[] {1, 2, 2, 2, 3, 1},
|
||||
new byte[] {1, 1, 3, 2, 2, 2},
|
||||
new byte[] {1, 2, 3, 1, 2, 2},
|
||||
new byte[] {1, 2, 3, 2, 2, 1},
|
||||
new byte[] {2, 2, 3, 2, 1, 1},
|
||||
new byte[] {2, 2, 1, 1, 3, 2},
|
||||
new byte[] {2, 2, 1, 2, 3, 1},
|
||||
new byte[] {2, 1, 3, 2, 1, 2},
|
||||
new byte[] {2, 2, 3, 1, 1, 2},
|
||||
new byte[] {3, 1, 2, 1, 3, 1},
|
||||
new byte[] {3, 1, 1, 2, 2, 2},
|
||||
new byte[] {3, 2, 1, 1, 2, 2},
|
||||
new byte[] {3, 2, 1, 2, 2, 1},
|
||||
new byte[] {3, 1, 2, 2, 1, 2},
|
||||
new byte[] {3, 2, 2, 1, 1, 2},
|
||||
new byte[] {3, 2, 2, 2, 1, 1},
|
||||
new byte[] {2, 1, 2, 1, 2, 3},
|
||||
new byte[] {2, 1, 2, 3, 2, 1},
|
||||
new byte[] {2, 3, 2, 1, 2, 1},
|
||||
new byte[] {1, 1, 1, 3, 2, 3},
|
||||
new byte[] {1, 3, 1, 1, 2, 3},
|
||||
new byte[] {1, 3, 1, 3, 2, 1},
|
||||
new byte[] {1, 1, 2, 3, 1, 3},
|
||||
new byte[] {1, 3, 2, 1, 1, 3},
|
||||
new byte[] {1, 3, 2, 3, 1, 1},
|
||||
new byte[] {2, 1, 1, 3, 1, 3},
|
||||
new byte[] {2, 3, 1, 1, 1, 3},
|
||||
new byte[] {2, 3, 1, 3, 1, 1},
|
||||
new byte[] {1, 1, 2, 1, 3, 3},
|
||||
new byte[] {1, 1, 2, 3, 3, 1},
|
||||
new byte[] {1, 3, 2, 1, 3, 1},
|
||||
new byte[] {1, 1, 3, 1, 2, 3},
|
||||
new byte[] {1, 1, 3, 3, 2, 1},
|
||||
new byte[] {1, 3, 3, 1, 2, 1},
|
||||
new byte[] {3, 1, 3, 1, 2, 1},
|
||||
new byte[] {2, 1, 1, 3, 3, 1},
|
||||
new byte[] {2, 3, 1, 1, 3, 1},
|
||||
new byte[] {2, 1, 3, 1, 1, 3},
|
||||
new byte[] {2, 1, 3, 3, 1, 1},
|
||||
new byte[] {2, 1, 3, 1, 3, 1},
|
||||
new byte[] {3, 1, 1, 1, 2, 3},
|
||||
new byte[] {3, 1, 1, 3, 2, 1},
|
||||
new byte[] {3, 3, 1, 1, 2, 1},
|
||||
new byte[] {3, 1, 2, 1, 1, 3},
|
||||
new byte[] {3, 1, 2, 3, 1, 1},
|
||||
new byte[] {3, 3, 2, 1, 1, 1},
|
||||
new byte[] {3, 1, 4, 1, 1, 1},
|
||||
new byte[] {2, 2, 1, 4, 1, 1},
|
||||
new byte[] {4, 3, 1, 1, 1, 1},
|
||||
new byte[] {1, 1, 1, 2, 2, 4},
|
||||
new byte[] {1, 1, 1, 4, 2, 2},
|
||||
new byte[] {1, 2, 1, 1, 2, 4},
|
||||
new byte[] {1, 2, 1, 4, 2, 1},
|
||||
new byte[] {1, 4, 1, 1, 2, 2},
|
||||
new byte[] {1, 4, 1, 2, 2, 1},
|
||||
new byte[] {1, 1, 2, 2, 1, 4},
|
||||
new byte[] {1, 1, 2, 4, 1, 2},
|
||||
new byte[] {1, 2, 2, 1, 1, 4},
|
||||
new byte[] {1, 2, 2, 4, 1, 1},
|
||||
new byte[] {1, 4, 2, 1, 1, 2},
|
||||
new byte[] {1, 4, 2, 2, 1, 1},
|
||||
new byte[] {2, 4, 1, 2, 1, 1},
|
||||
new byte[] {2, 2, 1, 1, 1, 4},
|
||||
new byte[] {4, 1, 3, 1, 1, 1},
|
||||
new byte[] {2, 4, 1, 1, 1, 2},
|
||||
new byte[] {1, 3, 4, 1, 1, 1},
|
||||
new byte[] {1, 1, 1, 2, 4, 2},
|
||||
new byte[] {1, 2, 1, 1, 4, 2},
|
||||
new byte[] {1, 2, 1, 2, 4, 1},
|
||||
new byte[] {1, 1, 4, 2, 1, 2},
|
||||
new byte[] {1, 2, 4, 1, 1, 2},
|
||||
new byte[] {1, 2, 4, 2, 1, 1},
|
||||
new byte[] {4, 1, 1, 2, 1, 2},
|
||||
new byte[] {4, 2, 1, 1, 1, 2},
|
||||
new byte[] {4, 2, 1, 2, 1, 1},
|
||||
new byte[] {2, 1, 2, 1, 4, 1},
|
||||
new byte[] {2, 1, 4, 1, 2, 1},
|
||||
new byte[] {4, 1, 2, 1, 2, 1},
|
||||
new byte[] {1, 1, 1, 1, 4, 3},
|
||||
new byte[] {1, 1, 1, 3, 4, 1},
|
||||
new byte[] {1, 3, 1, 1, 4, 1},
|
||||
new byte[] {1, 1, 4, 1, 1, 3},
|
||||
new byte[] {1, 1, 4, 3, 1, 1},
|
||||
new byte[] {4, 1, 1, 1, 1, 3},
|
||||
new byte[] {4, 1, 1, 3, 1, 1},
|
||||
new byte[] {1, 1, 3, 1, 4, 1},
|
||||
new byte[] {1, 1, 4, 1, 3, 1},
|
||||
new byte[] {3, 1, 1, 1, 4, 1},
|
||||
new byte[] {4, 1, 1, 1, 3, 1},
|
||||
new byte[] {2, 1, 1, 4, 1, 2},
|
||||
new byte[] {2, 1, 1, 2, 1, 4},
|
||||
new byte[] {2, 1, 1, 2, 3, 2}
|
||||
};
|
||||
|
||||
/** The stop bars.
|
||||
*/
|
||||
private static readonly byte[] BARS_STOP = {2, 3, 3, 1, 1, 1, 2};
|
||||
/** The charset code change.
|
||||
*/
|
||||
public const char CODE_AB_TO_C = (char)99;
|
||||
/** The charset code change.
|
||||
*/
|
||||
public const char CODE_AC_TO_B = (char)100;
|
||||
/** The charset code change.
|
||||
*/
|
||||
public const char CODE_BC_TO_A = (char)101;
|
||||
/** The code for UCC/EAN-128.
|
||||
*/
|
||||
public const char FNC1_INDEX = (char)102;
|
||||
/** The start code.
|
||||
*/
|
||||
public const char START_A = (char)103;
|
||||
/** The start code.
|
||||
*/
|
||||
public const char START_B = (char)104;
|
||||
/** The start code.
|
||||
*/
|
||||
public const char START_C = (char)105;
|
||||
|
||||
public const char FNC1 = '\u00ca';
|
||||
public const char DEL = '\u00c3';
|
||||
public const char FNC3 = '\u00c4';
|
||||
public const char FNC2 = '\u00c5';
|
||||
public const char SHIFT = '\u00c6';
|
||||
public const char CODE_C = '\u00c7';
|
||||
public const char CODE_A = '\u00c8';
|
||||
public const char FNC4 = '\u00c8';
|
||||
public const char STARTA = '\u00cb';
|
||||
public const char STARTB = '\u00cc';
|
||||
public const char STARTC = '\u00cd';
|
||||
|
||||
private static IntHashtable ais = new IntHashtable();
|
||||
|
||||
/** Creates new Barcode128 */
|
||||
public Barcode128() {
|
||||
x = 0.8f;
|
||||
font = BaseFont.CreateFont("Helvetica", "winansi", false);
|
||||
size = 8;
|
||||
baseline = size;
|
||||
barHeight = size * 3;
|
||||
textAlignment = Element.ALIGN_CENTER;
|
||||
codeType = CODE128;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the FNC1 codes in the text.
|
||||
* @param code the text to clean
|
||||
* @return the cleaned text
|
||||
*/
|
||||
public static String RemoveFNC1(String code) {
|
||||
int len = code.Length;
|
||||
StringBuilder buf = new StringBuilder(len);
|
||||
for (int k = 0; k < len; ++k) {
|
||||
char c = code[k];
|
||||
if (c >= 32 && c <= 126)
|
||||
buf.Append(c);
|
||||
}
|
||||
return buf.ToString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the human readable text of a sequence of AI.
|
||||
* @param code the text
|
||||
* @return the human readable text
|
||||
*/
|
||||
public static String GetHumanReadableUCCEAN(String code) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
String fnc1 = FNC1.ToString();
|
||||
try {
|
||||
while (true) {
|
||||
if (code.StartsWith(fnc1)) {
|
||||
code = code.Substring(1);
|
||||
continue;
|
||||
}
|
||||
int n = 0;
|
||||
int idlen = 0;
|
||||
for (int k = 2; k < 5; ++k) {
|
||||
if (code.Length < k)
|
||||
break;
|
||||
if ((n = ais[int.Parse(code.Substring(0, k))]) != 0) {
|
||||
idlen = k;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (idlen == 0)
|
||||
break;
|
||||
buf.Append('(').Append(code.Substring(0, idlen)).Append(')');
|
||||
code = code.Substring(idlen);
|
||||
if (n > 0) {
|
||||
n -= idlen;
|
||||
if (code.Length <= n)
|
||||
break;
|
||||
buf.Append(RemoveFNC1(code.Substring(0, n)));
|
||||
code = code.Substring(n);
|
||||
}
|
||||
else {
|
||||
int idx = code.IndexOf(FNC1);
|
||||
if (idx < 0)
|
||||
break;
|
||||
buf.Append(code.Substring(0,idx));
|
||||
code = code.Substring(idx + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch {
|
||||
//empty
|
||||
}
|
||||
buf.Append(RemoveFNC1(code));
|
||||
return buf.ToString();
|
||||
}
|
||||
|
||||
/** Returns <CODE>true</CODE> if the next <CODE>numDigits</CODE>
|
||||
* starting from index <CODE>textIndex</CODE> are numeric skipping any FNC1.
|
||||
* @param text the text to check
|
||||
* @param textIndex where to check from
|
||||
* @param numDigits the number of digits to check
|
||||
* @return the check result
|
||||
*/
|
||||
internal static bool IsNextDigits(string text, int textIndex, int numDigits) {
|
||||
int len = text.Length;
|
||||
while (textIndex < len && numDigits > 0) {
|
||||
if (text[textIndex] == FNC1) {
|
||||
++textIndex;
|
||||
continue;
|
||||
}
|
||||
int n = Math.Min(2, numDigits);
|
||||
if (textIndex + n > len)
|
||||
return false;
|
||||
while (n-- > 0) {
|
||||
char c = text[textIndex++];
|
||||
if (c < '0' || c > '9')
|
||||
return false;
|
||||
--numDigits;
|
||||
}
|
||||
}
|
||||
return numDigits == 0;
|
||||
}
|
||||
|
||||
/** Packs the digits for charset C also considering FNC1. It assumes that all the parameters
|
||||
* are valid.
|
||||
* @param text the text to pack
|
||||
* @param textIndex where to pack from
|
||||
* @param numDigits the number of digits to pack. It is always an even number
|
||||
* @return the packed digits, two digits per character
|
||||
*/
|
||||
internal static String GetPackedRawDigits(String text, int textIndex, int numDigits) {
|
||||
String outs = "";
|
||||
int start = textIndex;
|
||||
while (numDigits > 0) {
|
||||
if (text[textIndex] == FNC1) {
|
||||
outs += FNC1_INDEX;
|
||||
++textIndex;
|
||||
continue;
|
||||
}
|
||||
numDigits -= 2;
|
||||
int c1 = text[textIndex++] - '0';
|
||||
int c2 = text[textIndex++] - '0';
|
||||
outs += (char)(c1 * 10 + c2);
|
||||
}
|
||||
return (char)(textIndex - start) + outs;
|
||||
}
|
||||
|
||||
/** Converts the human readable text to the characters needed to
|
||||
* create a barcode. Some optimization is done to get the shortest code.
|
||||
* @param text the text to convert
|
||||
* @param ucc <CODE>true</CODE> if it is an UCC/EAN-128. In this case
|
||||
* the character FNC1 is added
|
||||
* @return the code ready to be fed to GetBarsCode128Raw()
|
||||
*/
|
||||
public static string GetRawText(string text, bool ucc) {
|
||||
String outs = "";
|
||||
int tLen = text.Length;
|
||||
if (tLen == 0) {
|
||||
outs += START_B;
|
||||
if (ucc)
|
||||
outs += FNC1_INDEX;
|
||||
return outs;
|
||||
}
|
||||
int c = 0;
|
||||
for (int k = 0; k < tLen; ++k) {
|
||||
c = text[k];
|
||||
if (c > 127 && c != FNC1)
|
||||
throw new ArgumentException("There are illegal characters for barcode 128 in '" + text + "'.");
|
||||
}
|
||||
c = text[0];
|
||||
char currentCode = START_B;
|
||||
int index = 0;
|
||||
if (IsNextDigits(text, index, 2)) {
|
||||
currentCode = START_C;
|
||||
outs += currentCode;
|
||||
if (ucc)
|
||||
outs += FNC1_INDEX;
|
||||
String out2 = GetPackedRawDigits(text, index, 2);
|
||||
index += (int)out2[0];
|
||||
outs += out2.Substring(1);
|
||||
}
|
||||
else if (c < ' ') {
|
||||
currentCode = START_A;
|
||||
outs += currentCode;
|
||||
if (ucc)
|
||||
outs += FNC1_INDEX;
|
||||
outs += (char)(c + 64);
|
||||
++index;
|
||||
}
|
||||
else {
|
||||
outs += currentCode;
|
||||
if (ucc)
|
||||
outs += FNC1_INDEX;
|
||||
if (c == FNC1)
|
||||
outs += FNC1_INDEX;
|
||||
else
|
||||
outs += (char)(c - ' ');
|
||||
++index;
|
||||
}
|
||||
while (index < tLen) {
|
||||
switch (currentCode) {
|
||||
case START_A:
|
||||
{
|
||||
if (IsNextDigits(text, index, 4)) {
|
||||
currentCode = START_C;
|
||||
outs += CODE_AB_TO_C;
|
||||
String out2 = GetPackedRawDigits(text, index, 4);
|
||||
index += (int)out2[0];
|
||||
outs += out2.Substring(1);
|
||||
}
|
||||
else {
|
||||
c = text[index++];
|
||||
if (c == FNC1)
|
||||
outs += FNC1_INDEX;
|
||||
else if (c > '_') {
|
||||
currentCode = START_B;
|
||||
outs += CODE_AC_TO_B;
|
||||
outs += (char)(c - ' ');
|
||||
}
|
||||
else if (c < ' ')
|
||||
outs += (char)(c + 64);
|
||||
else
|
||||
outs += (char)(c - ' ');
|
||||
}
|
||||
}
|
||||
break;
|
||||
case START_B:
|
||||
{
|
||||
if (IsNextDigits(text, index, 4)) {
|
||||
currentCode = START_C;
|
||||
outs += CODE_AB_TO_C;
|
||||
String out2 = GetPackedRawDigits(text, index, 4);
|
||||
index += (int)out2[0];
|
||||
outs += out2.Substring(1);
|
||||
}
|
||||
else {
|
||||
c = text[index++];
|
||||
if (c == FNC1)
|
||||
outs += FNC1_INDEX;
|
||||
else if (c < ' ') {
|
||||
currentCode = START_A;
|
||||
outs += CODE_BC_TO_A;
|
||||
outs += (char)(c + 64);
|
||||
}
|
||||
else {
|
||||
outs += (char)(c - ' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case START_C:
|
||||
{
|
||||
if (IsNextDigits(text, index, 2)) {
|
||||
String out2 = GetPackedRawDigits(text, index, 2);
|
||||
index += (int)out2[0];
|
||||
outs += out2.Substring(1);
|
||||
}
|
||||
else {
|
||||
c = text[index++];
|
||||
if (c == FNC1)
|
||||
outs += FNC1_INDEX;
|
||||
else if (c < ' ') {
|
||||
currentCode = START_A;
|
||||
outs += CODE_BC_TO_A;
|
||||
outs += (char)(c + 64);
|
||||
}
|
||||
else {
|
||||
currentCode = START_B;
|
||||
outs += CODE_AC_TO_B;
|
||||
outs += (char)(c - ' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return outs;
|
||||
}
|
||||
|
||||
/** Generates the bars. The input has the actual barcodes, not
|
||||
* the human readable text.
|
||||
* @param text the barcode
|
||||
* @return the bars
|
||||
*/
|
||||
public static byte[] GetBarsCode128Raw(string text) {
|
||||
int k;
|
||||
int idx = text.IndexOf('\uffff');
|
||||
if (idx >= 0)
|
||||
text = text.Substring(0, idx);
|
||||
int chk = text[0];
|
||||
for (k = 1; k < text.Length; ++k)
|
||||
chk += k * text[k];
|
||||
chk = chk % 103;
|
||||
text += (char)chk;
|
||||
byte[] bars = new byte[(text.Length + 1) * 6 + 7];
|
||||
for (k = 0; k < text.Length; ++k)
|
||||
Array.Copy(BARS[text[k]], 0, bars, k * 6, 6);
|
||||
Array.Copy(BARS_STOP, 0, bars, k * 6, 7);
|
||||
return bars;
|
||||
}
|
||||
|
||||
/** Gets the maximum area that the barcode and the text, if
|
||||
* any, will occupy. The lower left corner is always (0, 0).
|
||||
* @return the size the barcode occupies.
|
||||
*/
|
||||
public override Rectangle BarcodeSize {
|
||||
get {
|
||||
float fontX = 0;
|
||||
float fontY = 0;
|
||||
string fullCode;
|
||||
if (font != null) {
|
||||
if (baseline > 0)
|
||||
fontY = baseline - font.GetFontDescriptor(BaseFont.DESCENT, size);
|
||||
else
|
||||
fontY = -baseline + size;
|
||||
if (codeType == CODE128_RAW) {
|
||||
int idx = code.IndexOf('\uffff');
|
||||
if (idx < 0)
|
||||
fullCode = "";
|
||||
else
|
||||
fullCode = code.Substring(idx + 1);
|
||||
}
|
||||
else if (codeType == CODE128_UCC)
|
||||
fullCode = GetHumanReadableUCCEAN(code);
|
||||
else
|
||||
fullCode = RemoveFNC1(code);
|
||||
fontX = font.GetWidthPoint(altText != null ? altText : fullCode, size);
|
||||
}
|
||||
if (codeType == CODE128_RAW) {
|
||||
int idx = code.IndexOf('\uffff');
|
||||
if (idx >= 0)
|
||||
fullCode = code.Substring(0, idx);
|
||||
else
|
||||
fullCode = code;
|
||||
}
|
||||
else {
|
||||
fullCode = GetRawText(code, codeType == CODE128_UCC);
|
||||
}
|
||||
int len = fullCode.Length;
|
||||
float fullWidth = (len + 2) * 11 * x + 2 * x;
|
||||
fullWidth = Math.Max(fullWidth, fontX);
|
||||
float fullHeight = barHeight + fontY;
|
||||
return new Rectangle(fullWidth, fullHeight);
|
||||
}
|
||||
}
|
||||
|
||||
/** Places the barcode in a <CODE>PdfContentByte</CODE>. The
|
||||
* barcode is always placed at coodinates (0, 0). Use the
|
||||
* translation matrix to move it elsewhere.<p>
|
||||
* The bars and text are written in the following colors:<p>
|
||||
* <P><TABLE BORDER=1>
|
||||
* <TR>
|
||||
* <TH><P><CODE>barColor</CODE></TH>
|
||||
* <TH><P><CODE>textColor</CODE></TH>
|
||||
* <TH><P>Result</TH>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD><P><CODE>null</CODE></TD>
|
||||
* <TD><P><CODE>null</CODE></TD>
|
||||
* <TD><P>bars and text painted with current fill color</TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD><P><CODE>barColor</CODE></TD>
|
||||
* <TD><P><CODE>null</CODE></TD>
|
||||
* <TD><P>bars and text painted with <CODE>barColor</CODE></TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD><P><CODE>null</CODE></TD>
|
||||
* <TD><P><CODE>textColor</CODE></TD>
|
||||
* <TD><P>bars painted with current color<br>text painted with <CODE>textColor</CODE></TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD><P><CODE>barColor</CODE></TD>
|
||||
* <TD><P><CODE>textColor</CODE></TD>
|
||||
* <TD><P>bars painted with <CODE>barColor</CODE><br>text painted with <CODE>textColor</CODE></TD>
|
||||
* </TR>
|
||||
* </TABLE>
|
||||
* @param cb the <CODE>PdfContentByte</CODE> where the barcode will be placed
|
||||
* @param barColor the color of the bars. It can be <CODE>null</CODE>
|
||||
* @param textColor the color of the text. It can be <CODE>null</CODE>
|
||||
* @return the dimensions the barcode occupies
|
||||
*/
|
||||
public override Rectangle PlaceBarcode(PdfContentByte cb, Color barColor, Color textColor) {
|
||||
string fullCode;
|
||||
if (codeType == CODE128_RAW) {
|
||||
int idx = code.IndexOf('\uffff');
|
||||
if (idx < 0)
|
||||
fullCode = "";
|
||||
else
|
||||
fullCode = code.Substring(idx + 1);
|
||||
}
|
||||
else if (codeType == CODE128_UCC)
|
||||
fullCode = GetHumanReadableUCCEAN(code);
|
||||
else
|
||||
fullCode = RemoveFNC1(code);
|
||||
float fontX = 0;
|
||||
if (font != null) {
|
||||
fontX = font.GetWidthPoint(fullCode = altText != null ? altText : fullCode, size);
|
||||
}
|
||||
string bCode;
|
||||
if (codeType == CODE128_RAW) {
|
||||
int idx = code.IndexOf('\uffff');
|
||||
if (idx >= 0)
|
||||
bCode = code.Substring(0, idx);
|
||||
else
|
||||
bCode = code;
|
||||
}
|
||||
else {
|
||||
bCode = GetRawText(code, codeType == CODE128_UCC);
|
||||
}
|
||||
int len = bCode.Length;
|
||||
float fullWidth = (len + 2) * 11 * x + 2 * x;
|
||||
float barStartX = 0;
|
||||
float textStartX = 0;
|
||||
switch (textAlignment) {
|
||||
case Element.ALIGN_LEFT:
|
||||
break;
|
||||
case Element.ALIGN_RIGHT:
|
||||
if (fontX > fullWidth)
|
||||
barStartX = fontX - fullWidth;
|
||||
else
|
||||
textStartX = fullWidth - fontX;
|
||||
break;
|
||||
default:
|
||||
if (fontX > fullWidth)
|
||||
barStartX = (fontX - fullWidth) / 2;
|
||||
else
|
||||
textStartX = (fullWidth - fontX) / 2;
|
||||
break;
|
||||
}
|
||||
float barStartY = 0;
|
||||
float textStartY = 0;
|
||||
if (font != null) {
|
||||
if (baseline <= 0)
|
||||
textStartY = barHeight - baseline;
|
||||
else {
|
||||
textStartY = -font.GetFontDescriptor(BaseFont.DESCENT, size);
|
||||
barStartY = textStartY + baseline;
|
||||
}
|
||||
}
|
||||
byte[] bars = GetBarsCode128Raw(bCode);
|
||||
bool print = true;
|
||||
if (barColor != null)
|
||||
cb.SetColorFill(barColor);
|
||||
for (int k = 0; k < bars.Length; ++k) {
|
||||
float w = bars[k] * x;
|
||||
if (print)
|
||||
cb.Rectangle(barStartX, barStartY, w - inkSpreading, barHeight);
|
||||
print = !print;
|
||||
barStartX += w;
|
||||
}
|
||||
cb.Fill();
|
||||
if (font != null) {
|
||||
if (textColor != null)
|
||||
cb.SetColorFill(textColor);
|
||||
cb.BeginText();
|
||||
cb.SetFontAndSize(font, size);
|
||||
cb.SetTextMatrix(textStartX, textStartY);
|
||||
cb.ShowText(fullCode);
|
||||
cb.EndText();
|
||||
}
|
||||
return this.BarcodeSize;
|
||||
}
|
||||
|
||||
public override System.Drawing.Image CreateDrawingImage(System.Drawing.Color foreground, System.Drawing.Color background) {
|
||||
String bCode;
|
||||
if (codeType == CODE128_RAW) {
|
||||
int idx = code.IndexOf('\uffff');
|
||||
if (idx >= 0)
|
||||
bCode = code.Substring(0, idx);
|
||||
else
|
||||
bCode = code;
|
||||
}
|
||||
else {
|
||||
bCode = GetRawText(code, codeType == CODE128_UCC);
|
||||
}
|
||||
int len = bCode.Length;
|
||||
int fullWidth = (len + 2) * 11 + 2;
|
||||
byte[] bars = GetBarsCode128Raw(bCode);
|
||||
int height = (int)barHeight;
|
||||
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(fullWidth, height);
|
||||
for (int h = 0; h < height; ++h) {
|
||||
bool print = true;
|
||||
int ptr = 0;
|
||||
for (int k = 0; k < bars.Length; ++k) {
|
||||
int w = bars[k];
|
||||
System.Drawing.Color c = background;
|
||||
if (print)
|
||||
c = foreground;
|
||||
print = !print;
|
||||
for (int j = 0; j < w; ++j)
|
||||
bmp.SetPixel(ptr++, h, c);
|
||||
}
|
||||
}
|
||||
return bmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the code to generate. If it's an UCC code and starts with '(' it will
|
||||
* be split by the AI. This code in UCC mode is valid:
|
||||
* <p>
|
||||
* <code>(01)00000090311314(10)ABC123(15)060916</code>
|
||||
* @param code the code to generate
|
||||
*/
|
||||
public override string Code {
|
||||
set {
|
||||
string code = value;
|
||||
if (CodeType == Barcode128.CODE128_UCC && code.StartsWith("(")) {
|
||||
int idx = 0;
|
||||
String ret = "";
|
||||
while (idx >= 0) {
|
||||
int end = code.IndexOf(')', idx);
|
||||
if (end < 0)
|
||||
throw new ArgumentException("Badly formed UCC string: " + code);
|
||||
String sai = code.Substring(idx + 1, end - (idx + 1));
|
||||
if (sai.Length < 2)
|
||||
throw new ArgumentException("AI too short: (" + sai + ")");
|
||||
int ai = int.Parse(sai);
|
||||
int len = ais[ai];
|
||||
if (len == 0)
|
||||
throw new ArgumentException("AI not found: (" + sai + ")");
|
||||
sai = ai.ToString();
|
||||
if (sai.Length == 1)
|
||||
sai = "0" + sai;
|
||||
idx = code.IndexOf('(', end);
|
||||
int next = (idx < 0 ? code.Length : idx);
|
||||
ret += sai + code.Substring(end + 1, next - (end + 1));
|
||||
if (len < 0) {
|
||||
if (idx >= 0)
|
||||
ret += FNC1;
|
||||
}
|
||||
else if (next - end - 1 + sai.Length != len)
|
||||
throw new ArgumentException("Invalid AI length: (" + sai + ")");
|
||||
}
|
||||
base.Code = ret;
|
||||
}
|
||||
else
|
||||
base.Code = code;
|
||||
}
|
||||
}
|
||||
|
||||
static Barcode128 () {
|
||||
ais[0] = 20;
|
||||
ais[1] = 16;
|
||||
ais[2] = 16;
|
||||
ais[10] = -1;
|
||||
ais[11] = 9;
|
||||
ais[12] = 8;
|
||||
ais[13] = 8;
|
||||
ais[15] = 8;
|
||||
ais[17] = 8;
|
||||
ais[20] = 4;
|
||||
ais[21] = -1;
|
||||
ais[22] = -1;
|
||||
ais[23] = -1;
|
||||
ais[240] = -1;
|
||||
ais[241] = -1;
|
||||
ais[250] = -1;
|
||||
ais[251] = -1;
|
||||
ais[252] = -1;
|
||||
ais[30] = -1;
|
||||
for (int k = 3100; k < 3700; ++k)
|
||||
ais[k] = 10;
|
||||
ais[37] = -1;
|
||||
for (int k = 3900; k < 3940; ++k)
|
||||
ais[k] = -1;
|
||||
ais[400] = -1;
|
||||
ais[401] = -1;
|
||||
ais[402] = 20;
|
||||
ais[403] = -1;
|
||||
for (int k = 410; k < 416; ++k)
|
||||
ais[k] = 16;
|
||||
ais[420] = -1;
|
||||
ais[421] = -1;
|
||||
ais[422] = 6;
|
||||
ais[423] = -1;
|
||||
ais[424] = 6;
|
||||
ais[425] = 6;
|
||||
ais[426] = 6;
|
||||
ais[7001] = 17;
|
||||
ais[7002] = -1;
|
||||
for (int k = 7030; k < 7040; ++k)
|
||||
ais[k] = -1;
|
||||
ais[8001] = 18;
|
||||
ais[8002] = -1;
|
||||
ais[8003] = -1;
|
||||
ais[8004] = -1;
|
||||
ais[8005] = 10;
|
||||
ais[8006] = 22;
|
||||
ais[8007] = -1;
|
||||
ais[8008] = -1;
|
||||
ais[8018] = 22;
|
||||
ais[8020] = -1;
|
||||
ais[8100] = 10;
|
||||
ais[8101] = 14;
|
||||
ais[8102] = 6;
|
||||
for (int k = 90; k < 100; ++k)
|
||||
ais[k] = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
370
iTechSharp/iTextSharp/text/pdf/Barcode39.cs
Normal file
370
iTechSharp/iTextSharp/text/pdf/Barcode39.cs
Normal file
@@ -0,0 +1,370 @@
|
||||
using System;
|
||||
using iTextSharp.text;
|
||||
/*
|
||||
* $Id: Barcode39.cs,v 1.6 2007/05/03 19:36:07 psoares33 Exp $
|
||||
*
|
||||
* Copyright 2002-2006 by Paulo Soares.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
namespace iTextSharp.text.pdf {
|
||||
/** Implements the code 39 and code 39 extended. The default parameters are:
|
||||
* <pre>
|
||||
*x = 0.8f;
|
||||
*n = 2;
|
||||
*font = BaseFont.CreateFont("Helvetica", "winansi", false);
|
||||
*size = 8;
|
||||
*baseline = size;
|
||||
*barHeight = size * 3;
|
||||
*textint= Element.ALIGN_CENTER;
|
||||
*generateChecksum = false;
|
||||
*checksumText = false;
|
||||
*startStopText = true;
|
||||
*extended = false;
|
||||
* </pre>
|
||||
*
|
||||
* @author Paulo Soares (psoares@consiste.pt)
|
||||
*/
|
||||
public class Barcode39 : Barcode {
|
||||
|
||||
/** The bars to generate the code.
|
||||
*/
|
||||
private static readonly byte[][] BARS =
|
||||
{
|
||||
new byte[] {0,0,0,1,1,0,1,0,0},
|
||||
new byte[] {1,0,0,1,0,0,0,0,1},
|
||||
new byte[] {0,0,1,1,0,0,0,0,1},
|
||||
new byte[] {1,0,1,1,0,0,0,0,0},
|
||||
new byte[] {0,0,0,1,1,0,0,0,1},
|
||||
new byte[] {1,0,0,1,1,0,0,0,0},
|
||||
new byte[] {0,0,1,1,1,0,0,0,0},
|
||||
new byte[] {0,0,0,1,0,0,1,0,1},
|
||||
new byte[] {1,0,0,1,0,0,1,0,0},
|
||||
new byte[] {0,0,1,1,0,0,1,0,0},
|
||||
new byte[] {1,0,0,0,0,1,0,0,1},
|
||||
new byte[] {0,0,1,0,0,1,0,0,1},
|
||||
new byte[] {1,0,1,0,0,1,0,0,0},
|
||||
new byte[] {0,0,0,0,1,1,0,0,1},
|
||||
new byte[] {1,0,0,0,1,1,0,0,0},
|
||||
new byte[] {0,0,1,0,1,1,0,0,0},
|
||||
new byte[] {0,0,0,0,0,1,1,0,1},
|
||||
new byte[] {1,0,0,0,0,1,1,0,0},
|
||||
new byte[] {0,0,1,0,0,1,1,0,0},
|
||||
new byte[] {0,0,0,0,1,1,1,0,0},
|
||||
new byte[] {1,0,0,0,0,0,0,1,1},
|
||||
new byte[] {0,0,1,0,0,0,0,1,1},
|
||||
new byte[] {1,0,1,0,0,0,0,1,0},
|
||||
new byte[] {0,0,0,0,1,0,0,1,1},
|
||||
new byte[] {1,0,0,0,1,0,0,1,0},
|
||||
new byte[] {0,0,1,0,1,0,0,1,0},
|
||||
new byte[] {0,0,0,0,0,0,1,1,1},
|
||||
new byte[] {1,0,0,0,0,0,1,1,0},
|
||||
new byte[] {0,0,1,0,0,0,1,1,0},
|
||||
new byte[] {0,0,0,0,1,0,1,1,0},
|
||||
new byte[] {1,1,0,0,0,0,0,0,1},
|
||||
new byte[] {0,1,1,0,0,0,0,0,1},
|
||||
new byte[] {1,1,1,0,0,0,0,0,0},
|
||||
new byte[] {0,1,0,0,1,0,0,0,1},
|
||||
new byte[] {1,1,0,0,1,0,0,0,0},
|
||||
new byte[] {0,1,1,0,1,0,0,0,0},
|
||||
new byte[] {0,1,0,0,0,0,1,0,1},
|
||||
new byte[] {1,1,0,0,0,0,1,0,0},
|
||||
new byte[] {0,1,1,0,0,0,1,0,0},
|
||||
new byte[] {0,1,0,1,0,1,0,0,0},
|
||||
new byte[] {0,1,0,1,0,0,0,1,0},
|
||||
new byte[] {0,1,0,0,0,1,0,1,0},
|
||||
new byte[] {0,0,0,1,0,1,0,1,0},
|
||||
new byte[] {0,1,0,0,1,0,1,0,0}
|
||||
};
|
||||
|
||||
/** The index chars to <CODE>BARS</CODE>.
|
||||
*/
|
||||
private const string CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%*";
|
||||
|
||||
/** The character combinations to make the code 39 extended.
|
||||
*/
|
||||
private const string EXTENDED = "%U" +
|
||||
"$A$B$C$D$E$F$G$H$I$J$K$L$M$N$O$P$Q$R$S$T$U$V$W$X$Y$Z" +
|
||||
"%A%B%C%D%E /A/B/C/D/E/F/G/H/I/J/K/L - ./O" +
|
||||
" 0 1 2 3 4 5 6 7 8 9/Z%F%G%H%I%J%V" +
|
||||
" A B C D E F G H I J K L M N O P Q R S T U V W X Y Z" +
|
||||
"%K%L%M%N%O%W" +
|
||||
"+A+B+C+D+E+F+G+H+I+J+K+L+M+N+O+P+Q+R+S+T+U+V+W+X+Y+Z" +
|
||||
"%P%Q%R%S%T";
|
||||
|
||||
/** Creates a new Barcode39.
|
||||
*/
|
||||
public Barcode39() {
|
||||
x = 0.8f;
|
||||
n = 2;
|
||||
font = BaseFont.CreateFont("Helvetica", "winansi", false);
|
||||
size = 8;
|
||||
baseline = size;
|
||||
barHeight = size * 3;
|
||||
textAlignment = Element.ALIGN_CENTER;
|
||||
generateChecksum = false;
|
||||
checksumText = false;
|
||||
startStopText = true;
|
||||
extended = false;
|
||||
}
|
||||
|
||||
/** Creates the bars.
|
||||
* @param text the text to create the bars. This text does not include the start and
|
||||
* stop characters
|
||||
* @return the bars
|
||||
*/
|
||||
public static byte[] GetBarsCode39(string text) {
|
||||
text = "*" + text + "*";
|
||||
byte[] bars = new byte[text.Length * 10 - 1];
|
||||
for (int k = 0; k < text.Length; ++k) {
|
||||
int idx = CHARS.IndexOf(text[k]);
|
||||
if (idx < 0)
|
||||
throw new ArgumentException("The character '" + text[k] + "' is illegal in code 39.");
|
||||
Array.Copy(BARS[idx], 0, bars, k * 10, 9);
|
||||
}
|
||||
return bars;
|
||||
}
|
||||
|
||||
/** Converts the extended text into a normal, escaped text,
|
||||
* ready to generate bars.
|
||||
* @param text the extended text
|
||||
* @return the escaped text
|
||||
*/
|
||||
public static string GetCode39Ex(string text) {
|
||||
string ret = "";
|
||||
for (int k = 0; k < text.Length; ++k) {
|
||||
char c = text[k];
|
||||
if (c > 127)
|
||||
throw new ArgumentException("The character '" + c + "' is illegal in code 39 extended.");
|
||||
char c1 = EXTENDED[c * 2];
|
||||
char c2 = EXTENDED[c * 2 + 1];
|
||||
if (c1 != ' ')
|
||||
ret += c1;
|
||||
ret += c2;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** Calculates the checksum.
|
||||
* @param text the text
|
||||
* @return the checksum
|
||||
*/
|
||||
internal static char GetChecksum(string text) {
|
||||
int chk = 0;
|
||||
for (int k = 0; k < text.Length; ++k) {
|
||||
int idx = CHARS.IndexOf(text[k]);
|
||||
if (idx < 0)
|
||||
throw new ArgumentException("The character '" + text[k] + "' is illegal in code 39.");
|
||||
chk += idx;
|
||||
}
|
||||
return CHARS[chk % 43];
|
||||
}
|
||||
|
||||
/** Gets the maximum area that the barcode and the text, if
|
||||
* any, will occupy. The lower left corner is always (0, 0).
|
||||
* @return the size the barcode occupies.
|
||||
*/
|
||||
public override Rectangle BarcodeSize {
|
||||
get {
|
||||
float fontX = 0;
|
||||
float fontY = 0;
|
||||
string fCode = code;
|
||||
if (extended)
|
||||
fCode = GetCode39Ex(code);
|
||||
if (font != null) {
|
||||
if (baseline > 0)
|
||||
fontY = baseline - font.GetFontDescriptor(BaseFont.DESCENT, size);
|
||||
else
|
||||
fontY = -baseline + size;
|
||||
string fullCode = code;
|
||||
if (generateChecksum && checksumText)
|
||||
fullCode += GetChecksum(fCode);
|
||||
if (startStopText)
|
||||
fullCode = "*" + fullCode + "*";
|
||||
fontX = font.GetWidthPoint(altText != null ? altText : fullCode, size);
|
||||
}
|
||||
int len = fCode.Length + 2;
|
||||
if (generateChecksum)
|
||||
++len;
|
||||
float fullWidth = len * (6 * x + 3 * x * n) + (len - 1) * x;
|
||||
fullWidth = Math.Max(fullWidth, fontX);
|
||||
float fullHeight = barHeight + fontY;
|
||||
return new Rectangle(fullWidth, fullHeight);
|
||||
}
|
||||
}
|
||||
|
||||
/** Places the barcode in a <CODE>PdfContentByte</CODE>. The
|
||||
* barcode is always placed at coodinates (0, 0). Use the
|
||||
* translation matrix to move it elsewhere.<p>
|
||||
* The bars and text are written in the following colors:<p>
|
||||
* <P><TABLE BORDER=1>
|
||||
* <TR>
|
||||
* <TH><P><CODE>barColor</CODE></TH>
|
||||
* <TH><P><CODE>textColor</CODE></TH>
|
||||
* <TH><P>Result</TH>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD><P><CODE>null</CODE></TD>
|
||||
* <TD><P><CODE>null</CODE></TD>
|
||||
* <TD><P>bars and text painted with current fill color</TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD><P><CODE>barColor</CODE></TD>
|
||||
* <TD><P><CODE>null</CODE></TD>
|
||||
* <TD><P>bars and text painted with <CODE>barColor</CODE></TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD><P><CODE>null</CODE></TD>
|
||||
* <TD><P><CODE>textColor</CODE></TD>
|
||||
* <TD><P>bars painted with current color<br>text painted with <CODE>textColor</CODE></TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD><P><CODE>barColor</CODE></TD>
|
||||
* <TD><P><CODE>textColor</CODE></TD>
|
||||
* <TD><P>bars painted with <CODE>barColor</CODE><br>text painted with <CODE>textColor</CODE></TD>
|
||||
* </TR>
|
||||
* </TABLE>
|
||||
* @param cb the <CODE>PdfContentByte</CODE> where the barcode will be placed
|
||||
* @param barColor the color of the bars. It can be <CODE>null</CODE>
|
||||
* @param textColor the color of the text. It can be <CODE>null</CODE>
|
||||
* @return the dimensions the barcode occupies
|
||||
*/
|
||||
public override Rectangle PlaceBarcode(PdfContentByte cb, Color barColor, Color textColor) {
|
||||
string fullCode = code;
|
||||
float fontX = 0;
|
||||
string bCode = code;
|
||||
if (extended)
|
||||
bCode = GetCode39Ex(code);
|
||||
if (font != null) {
|
||||
if (generateChecksum && checksumText)
|
||||
fullCode += GetChecksum(bCode);
|
||||
if (startStopText)
|
||||
fullCode = "*" + fullCode + "*";
|
||||
fontX = font.GetWidthPoint(fullCode = altText != null ? altText : fullCode, size);
|
||||
}
|
||||
if (generateChecksum)
|
||||
bCode += GetChecksum(bCode);
|
||||
int len = bCode.Length + 2;
|
||||
float fullWidth = len * (6 * x + 3 * x * n) + (len - 1) * x;
|
||||
float barStartX = 0;
|
||||
float textStartX = 0;
|
||||
switch (textAlignment) {
|
||||
case Element.ALIGN_LEFT:
|
||||
break;
|
||||
case Element.ALIGN_RIGHT:
|
||||
if (fontX > fullWidth)
|
||||
barStartX = fontX - fullWidth;
|
||||
else
|
||||
textStartX = fullWidth - fontX;
|
||||
break;
|
||||
default:
|
||||
if (fontX > fullWidth)
|
||||
barStartX = (fontX - fullWidth) / 2;
|
||||
else
|
||||
textStartX = (fullWidth - fontX) / 2;
|
||||
break;
|
||||
}
|
||||
float barStartY = 0;
|
||||
float textStartY = 0;
|
||||
if (font != null) {
|
||||
if (baseline <= 0)
|
||||
textStartY = barHeight - baseline;
|
||||
else {
|
||||
textStartY = -font.GetFontDescriptor(BaseFont.DESCENT, size);
|
||||
barStartY = textStartY + baseline;
|
||||
}
|
||||
}
|
||||
byte[] bars = GetBarsCode39(bCode);
|
||||
bool print = true;
|
||||
if (barColor != null)
|
||||
cb.SetColorFill(barColor);
|
||||
for (int k = 0; k < bars.Length; ++k) {
|
||||
float w = (bars[k] == 0 ? x : x * n);
|
||||
if (print)
|
||||
cb.Rectangle(barStartX, barStartY, w - inkSpreading, barHeight);
|
||||
print = !print;
|
||||
barStartX += w;
|
||||
}
|
||||
cb.Fill();
|
||||
if (font != null) {
|
||||
if (textColor != null)
|
||||
cb.SetColorFill(textColor);
|
||||
cb.BeginText();
|
||||
cb.SetFontAndSize(font, size);
|
||||
cb.SetTextMatrix(textStartX, textStartY);
|
||||
cb.ShowText(fullCode);
|
||||
cb.EndText();
|
||||
}
|
||||
return this.BarcodeSize;
|
||||
}
|
||||
|
||||
public override System.Drawing.Image CreateDrawingImage(System.Drawing.Color foreground, System.Drawing.Color background) {
|
||||
String bCode = code;
|
||||
if (extended)
|
||||
bCode = GetCode39Ex(code);
|
||||
if (generateChecksum)
|
||||
bCode += GetChecksum(bCode);
|
||||
int len = bCode.Length + 2;
|
||||
int nn = (int)n;
|
||||
int fullWidth = len * (6 + 3 * nn) + (len - 1);
|
||||
int height = (int)barHeight;
|
||||
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(fullWidth, height);
|
||||
byte[] bars = GetBarsCode39(bCode);
|
||||
for (int h = 0; h < height; ++h) {
|
||||
bool print = true;
|
||||
int ptr = 0;
|
||||
for (int k = 0; k < bars.Length; ++k) {
|
||||
int w = (bars[k] == 0 ? 1 : nn);
|
||||
System.Drawing.Color c = background;
|
||||
if (print)
|
||||
c = foreground;
|
||||
print = !print;
|
||||
for (int j = 0; j < w; ++j)
|
||||
bmp.SetPixel(ptr++, h, c);
|
||||
}
|
||||
}
|
||||
return bmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
324
iTechSharp/iTextSharp/text/pdf/BarcodeCodabar.cs
Normal file
324
iTechSharp/iTextSharp/text/pdf/BarcodeCodabar.cs
Normal file
@@ -0,0 +1,324 @@
|
||||
using System;
|
||||
using iTextSharp.text;
|
||||
/*
|
||||
* $Id: BarcodeCodabar.cs,v 1.7 2007/02/22 20:48:38 psoares33 Exp $
|
||||
*
|
||||
* Copyright 2002-2006 by Paulo Soares.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.pdf
|
||||
{
|
||||
/** Implements the code codabar. The default parameters are:
|
||||
* <pre>
|
||||
*x = 0.8f;
|
||||
*n = 2;
|
||||
*font = BaseFont.CreateFont("Helvetica", "winansi", false);
|
||||
*size = 8;
|
||||
*baseline = size;
|
||||
*barHeight = size * 3;
|
||||
*textAlignment = Element.ALIGN_CENTER;
|
||||
*generateChecksum = false;
|
||||
*checksumText = false;
|
||||
*startStopText = false;
|
||||
* </pre>
|
||||
*
|
||||
* @author Paulo Soares (psoares@consiste.pt)
|
||||
*/
|
||||
public class BarcodeCodabar : Barcode{
|
||||
|
||||
/** The bars to generate the code.
|
||||
*/
|
||||
private static readonly byte[][] BARS = new byte[][] {
|
||||
new byte[]{0,0,0,0,0,1,1}, // 0
|
||||
new byte[]{0,0,0,0,1,1,0}, // 1
|
||||
new byte[]{0,0,0,1,0,0,1}, // 2
|
||||
new byte[]{1,1,0,0,0,0,0}, // 3
|
||||
new byte[]{0,0,1,0,0,1,0}, // 4
|
||||
new byte[]{1,0,0,0,0,1,0}, // 5
|
||||
new byte[]{0,1,0,0,0,0,1}, // 6
|
||||
new byte[]{0,1,0,0,1,0,0}, // 7
|
||||
new byte[]{0,1,1,0,0,0,0}, // 8
|
||||
new byte[]{1,0,0,1,0,0,0}, // 9
|
||||
new byte[]{0,0,0,1,1,0,0}, // -
|
||||
new byte[]{0,0,1,1,0,0,0}, // $
|
||||
new byte[]{1,0,0,0,1,0,1}, // :
|
||||
new byte[]{1,0,1,0,0,0,1}, // /
|
||||
new byte[]{1,0,1,0,1,0,0}, // .
|
||||
new byte[]{0,0,1,0,1,0,1}, // +
|
||||
new byte[]{0,0,1,1,0,1,0}, // a
|
||||
new byte[]{0,1,0,1,0,0,1}, // b
|
||||
new byte[]{0,0,0,1,0,1,1}, // c
|
||||
new byte[]{0,0,0,1,1,1,0} // d
|
||||
};
|
||||
|
||||
/** The index chars to <CODE>BARS</CODE>.
|
||||
*/
|
||||
private const string CHARS = "0123456789-$:/.+ABCD";
|
||||
|
||||
private const int START_STOP_IDX = 16;
|
||||
/** Creates a new BarcodeCodabar.
|
||||
*/
|
||||
public BarcodeCodabar() {
|
||||
x = 0.8f;
|
||||
n = 2;
|
||||
font = BaseFont.CreateFont("Helvetica", "winansi", false);
|
||||
size = 8;
|
||||
baseline = size;
|
||||
barHeight = size * 3;
|
||||
textAlignment = Element.ALIGN_CENTER;
|
||||
generateChecksum = false;
|
||||
checksumText = false;
|
||||
startStopText = false;
|
||||
codeType = CODABAR;
|
||||
}
|
||||
|
||||
/** Creates the bars.
|
||||
* @param text the text to create the bars
|
||||
* @return the bars
|
||||
*/
|
||||
public static byte[] GetBarsCodabar(String text) {
|
||||
text = text.ToUpper(System.Globalization.CultureInfo.InvariantCulture);
|
||||
int len = text.Length;
|
||||
if (len < 2)
|
||||
throw new ArgumentException("Codabar must have at least a start and stop character.");
|
||||
if (CHARS.IndexOf(text[0]) < START_STOP_IDX || CHARS.IndexOf(text[len - 1]) < START_STOP_IDX)
|
||||
throw new ArgumentException("Codabar must have one of 'ABCD' as start/stop character.");
|
||||
byte[] bars = new byte[text.Length * 8 - 1];
|
||||
for (int k = 0; k < len; ++k) {
|
||||
int idx = CHARS.IndexOf(text[k]);
|
||||
if (idx >= START_STOP_IDX && k > 0 && k < len - 1)
|
||||
throw new ArgumentException("In codabar, start/stop characters are only allowed at the extremes.");
|
||||
if (idx < 0)
|
||||
throw new ArgumentException("The character '" + text[k] + "' is illegal in codabar.");
|
||||
Array.Copy(BARS[idx], 0, bars, k * 8, 7);
|
||||
}
|
||||
return bars;
|
||||
}
|
||||
|
||||
public static String CalculateChecksum(String code) {
|
||||
if (code.Length < 2)
|
||||
return code;
|
||||
String text = code.ToUpper(System.Globalization.CultureInfo.InvariantCulture);
|
||||
int sum = 0;
|
||||
int len = text.Length;
|
||||
for (int k = 0; k < len; ++k)
|
||||
sum += CHARS.IndexOf(text[k]);
|
||||
sum = (sum + 15) / 16 * 16 - sum;
|
||||
return code.Substring(0, len - 1) + CHARS[sum] + code.Substring(len - 1);
|
||||
}
|
||||
|
||||
/** Gets the maximum area that the barcode and the text, if
|
||||
* any, will occupy. The lower left corner is always (0, 0).
|
||||
* @return the size the barcode occupies.
|
||||
*/
|
||||
public override Rectangle BarcodeSize {
|
||||
get {
|
||||
float fontX = 0;
|
||||
float fontY = 0;
|
||||
String text = code;
|
||||
if (generateChecksum && checksumText)
|
||||
text = CalculateChecksum(code);
|
||||
if (!startStopText)
|
||||
text = text.Substring(1, text.Length - 2);
|
||||
if (font != null) {
|
||||
if (baseline > 0)
|
||||
fontY = baseline - font.GetFontDescriptor(BaseFont.DESCENT, size);
|
||||
else
|
||||
fontY = -baseline + size;
|
||||
fontX = font.GetWidthPoint(altText != null ? altText : text, size);
|
||||
}
|
||||
text = code;
|
||||
if (generateChecksum)
|
||||
text = CalculateChecksum(code);
|
||||
byte[] bars = GetBarsCodabar(text);
|
||||
int wide = 0;
|
||||
for (int k = 0; k < bars.Length; ++k) {
|
||||
wide += (int)bars[k];
|
||||
}
|
||||
int narrow = bars.Length - wide;
|
||||
float fullWidth = x * (narrow + wide * n);
|
||||
fullWidth = Math.Max(fullWidth, fontX);
|
||||
float fullHeight = barHeight + fontY;
|
||||
return new Rectangle(fullWidth, fullHeight);
|
||||
}
|
||||
}
|
||||
|
||||
/** Places the barcode in a <CODE>PdfContentByte</CODE>. The
|
||||
* barcode is always placed at coodinates (0, 0). Use the
|
||||
* translation matrix to move it elsewhere.<p>
|
||||
* The bars and text are written in the following colors:<p>
|
||||
* <P><TABLE BORDER=1>
|
||||
* <TR>
|
||||
* <TH><P><CODE>barColor</CODE></TH>
|
||||
* <TH><P><CODE>textColor</CODE></TH>
|
||||
* <TH><P>Result</TH>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD><P><CODE>null</CODE></TD>
|
||||
* <TD><P><CODE>null</CODE></TD>
|
||||
* <TD><P>bars and text painted with current fill color</TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD><P><CODE>barColor</CODE></TD>
|
||||
* <TD><P><CODE>null</CODE></TD>
|
||||
* <TD><P>bars and text painted with <CODE>barColor</CODE></TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD><P><CODE>null</CODE></TD>
|
||||
* <TD><P><CODE>textColor</CODE></TD>
|
||||
* <TD><P>bars painted with current color<br>text painted with <CODE>textColor</CODE></TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD><P><CODE>barColor</CODE></TD>
|
||||
* <TD><P><CODE>textColor</CODE></TD>
|
||||
* <TD><P>bars painted with <CODE>barColor</CODE><br>text painted with <CODE>textColor</CODE></TD>
|
||||
* </TR>
|
||||
* </TABLE>
|
||||
* @param cb the <CODE>PdfContentByte</CODE> where the barcode will be placed
|
||||
* @param barColor the color of the bars. It can be <CODE>null</CODE>
|
||||
* @param textColor the color of the text. It can be <CODE>null</CODE>
|
||||
* @return the dimensions the barcode occupies
|
||||
*/
|
||||
public override Rectangle PlaceBarcode(PdfContentByte cb, Color barColor, Color textColor) {
|
||||
String fullCode = code;
|
||||
if (generateChecksum && checksumText)
|
||||
fullCode = CalculateChecksum(code);
|
||||
if (!startStopText)
|
||||
fullCode = fullCode.Substring(1, fullCode.Length - 2);
|
||||
float fontX = 0;
|
||||
if (font != null) {
|
||||
fontX = font.GetWidthPoint(fullCode = altText != null ? altText : fullCode, size);
|
||||
}
|
||||
byte[] bars = GetBarsCodabar(generateChecksum ? CalculateChecksum(code) : code);
|
||||
int wide = 0;
|
||||
for (int k = 0; k < bars.Length; ++k) {
|
||||
wide += (int)bars[k];
|
||||
}
|
||||
int narrow = bars.Length - wide;
|
||||
float fullWidth = x * (narrow + wide * n);
|
||||
float barStartX = 0;
|
||||
float textStartX = 0;
|
||||
switch (textAlignment) {
|
||||
case Element.ALIGN_LEFT:
|
||||
break;
|
||||
case Element.ALIGN_RIGHT:
|
||||
if (fontX > fullWidth)
|
||||
barStartX = fontX - fullWidth;
|
||||
else
|
||||
textStartX = fullWidth - fontX;
|
||||
break;
|
||||
default:
|
||||
if (fontX > fullWidth)
|
||||
barStartX = (fontX - fullWidth) / 2;
|
||||
else
|
||||
textStartX = (fullWidth - fontX) / 2;
|
||||
break;
|
||||
}
|
||||
float barStartY = 0;
|
||||
float textStartY = 0;
|
||||
if (font != null) {
|
||||
if (baseline <= 0)
|
||||
textStartY = barHeight - baseline;
|
||||
else {
|
||||
textStartY = -font.GetFontDescriptor(BaseFont.DESCENT, size);
|
||||
barStartY = textStartY + baseline;
|
||||
}
|
||||
}
|
||||
bool print = true;
|
||||
if (barColor != null)
|
||||
cb.SetColorFill(barColor);
|
||||
for (int k = 0; k < bars.Length; ++k) {
|
||||
float w = (bars[k] == 0 ? x : x * n);
|
||||
if (print)
|
||||
cb.Rectangle(barStartX, barStartY, w - inkSpreading, barHeight);
|
||||
print = !print;
|
||||
barStartX += w;
|
||||
}
|
||||
cb.Fill();
|
||||
if (font != null) {
|
||||
if (textColor != null)
|
||||
cb.SetColorFill(textColor);
|
||||
cb.BeginText();
|
||||
cb.SetFontAndSize(font, size);
|
||||
cb.SetTextMatrix(textStartX, textStartY);
|
||||
cb.ShowText(fullCode);
|
||||
cb.EndText();
|
||||
}
|
||||
return BarcodeSize;
|
||||
}
|
||||
|
||||
public override System.Drawing.Image CreateDrawingImage(System.Drawing.Color foreground, System.Drawing.Color background) {
|
||||
String fullCode = code;
|
||||
if (generateChecksum && checksumText)
|
||||
fullCode = CalculateChecksum(code);
|
||||
if (!startStopText)
|
||||
fullCode = fullCode.Substring(1, fullCode.Length - 2);
|
||||
byte[] bars = GetBarsCodabar(generateChecksum ? CalculateChecksum(code) : code);
|
||||
int wide = 0;
|
||||
for (int k = 0; k < bars.Length; ++k) {
|
||||
wide += (int)bars[k];
|
||||
}
|
||||
int narrow = bars.Length - wide;
|
||||
int fullWidth = narrow + wide * (int)n;
|
||||
int height = (int)barHeight;
|
||||
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(fullWidth, height);
|
||||
for (int h = 0; h < height; ++h) {
|
||||
bool print = true;
|
||||
int ptr = 0;
|
||||
for (int k = 0; k < bars.Length; ++k) {
|
||||
int w = (bars[k] == 0 ? 1 : (int)n);
|
||||
System.Drawing.Color c = background;
|
||||
if (print)
|
||||
c = foreground;
|
||||
print = !print;
|
||||
for (int j = 0; j < w; ++j)
|
||||
bmp.SetPixel(ptr++, h, c);
|
||||
}
|
||||
}
|
||||
return bmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
1265
iTechSharp/iTextSharp/text/pdf/BarcodeDatamatrix.cs
Normal file
1265
iTechSharp/iTextSharp/text/pdf/BarcodeDatamatrix.cs
Normal file
File diff suppressed because it is too large
Load Diff
697
iTechSharp/iTextSharp/text/pdf/BarcodeEAN.cs
Normal file
697
iTechSharp/iTextSharp/text/pdf/BarcodeEAN.cs
Normal file
@@ -0,0 +1,697 @@
|
||||
using System;
|
||||
using iTextSharp.text;
|
||||
using System.Collections;
|
||||
|
||||
/*
|
||||
* Copyright 2002 by Paulo Soares.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
namespace iTextSharp.text.pdf {
|
||||
/** Generates barcodes in several formats: EAN13, EAN8, UPCA, UPCE,
|
||||
* supplemental 2 and 5. The default parameters are:
|
||||
* <pre>
|
||||
*x = 0.8f;
|
||||
*font = BaseFont.CreateFont("Helvetica", "winansi", false);
|
||||
*size = 8;
|
||||
*baseline = size;
|
||||
*barHeight = size * 3;
|
||||
*guardBars = true;
|
||||
*codeType = EAN13;
|
||||
*code = "";
|
||||
* </pre>
|
||||
*
|
||||
* @author Paulo Soares (psoares@consiste.pt)
|
||||
*/
|
||||
public class BarcodeEAN : Barcode {
|
||||
|
||||
/** The bar positions that are guard bars.*/
|
||||
private static readonly int[] GUARD_EMPTY = {};
|
||||
/** The bar positions that are guard bars.*/
|
||||
private static readonly int[] GUARD_UPCA = {0, 2, 4, 6, 28, 30, 52, 54, 56, 58};
|
||||
/** The bar positions that are guard bars.*/
|
||||
private static readonly int[] GUARD_EAN13 = {0, 2, 28, 30, 56, 58};
|
||||
/** The bar positions that are guard bars.*/
|
||||
private static readonly int[] GUARD_EAN8 = {0, 2, 20, 22, 40, 42};
|
||||
/** The bar positions that are guard bars.*/
|
||||
private static readonly int[] GUARD_UPCE = {0, 2, 28, 30, 32};
|
||||
/** The x coordinates to place the text.*/
|
||||
private static readonly float[] TEXTPOS_EAN13 = {6.5f, 13.5f, 20.5f, 27.5f, 34.5f, 41.5f, 53.5f, 60.5f, 67.5f, 74.5f, 81.5f, 88.5f};
|
||||
/** The x coordinates to place the text.*/
|
||||
private static readonly float[] TEXTPOS_EAN8 = {6.5f, 13.5f, 20.5f, 27.5f, 39.5f, 46.5f, 53.5f, 60.5f};
|
||||
/** The basic bar widths.*/
|
||||
private static readonly byte[][] BARS =
|
||||
{
|
||||
new byte[] {3, 2, 1, 1}, // 0
|
||||
new byte[] {2, 2, 2, 1}, // 1
|
||||
new byte[] {2, 1, 2, 2}, // 2
|
||||
new byte[] {1, 4, 1, 1}, // 3
|
||||
new byte[] {1, 1, 3, 2}, // 4
|
||||
new byte[] {1, 2, 3, 1}, // 5
|
||||
new byte[] {1, 1, 1, 4}, // 6
|
||||
new byte[] {1, 3, 1, 2}, // 7
|
||||
new byte[] {1, 2, 1, 3}, // 8
|
||||
new byte[] {3, 1, 1, 2} // 9
|
||||
};
|
||||
|
||||
/** The total number of bars for EAN13.*/
|
||||
private const int TOTALBARS_EAN13 = 11 + 12 * 4;
|
||||
/** The total number of bars for EAN8.*/
|
||||
private const int TOTALBARS_EAN8 = 11 + 8 * 4;
|
||||
/** The total number of bars for UPCE.*/
|
||||
private const int TOTALBARS_UPCE = 9 + 6 * 4;
|
||||
/** The total number of bars for supplemental 2.*/
|
||||
private const int TOTALBARS_SUPP2 = 13;
|
||||
/** The total number of bars for supplemental 5.*/
|
||||
private const int TOTALBARS_SUPP5 = 31;
|
||||
/** Marker for odd parity.*/
|
||||
private const byte ODD = 0;
|
||||
/** Marker for even parity.*/
|
||||
private const byte EVEN = 1;
|
||||
|
||||
/** Sequence of parities to be used with EAN13.*/
|
||||
private static readonly byte[][] PARITY13 =
|
||||
{
|
||||
new byte[] {ODD, ODD, ODD, ODD, ODD, ODD}, // 0
|
||||
new byte[] {ODD, ODD, EVEN, ODD, EVEN, EVEN}, // 1
|
||||
new byte[] {ODD, ODD, EVEN, EVEN, ODD, EVEN}, // 2
|
||||
new byte[] {ODD, ODD, EVEN, EVEN, EVEN, ODD}, // 3
|
||||
new byte[] {ODD, EVEN, ODD, ODD, EVEN, EVEN}, // 4
|
||||
new byte[] {ODD, EVEN, EVEN, ODD, ODD, EVEN}, // 5
|
||||
new byte[] {ODD, EVEN, EVEN, EVEN, ODD, ODD}, // 6
|
||||
new byte[] {ODD, EVEN, ODD, EVEN, ODD, EVEN}, // 7
|
||||
new byte[] {ODD, EVEN, ODD, EVEN, EVEN, ODD}, // 8
|
||||
new byte[] {ODD, EVEN, EVEN, ODD, EVEN, ODD} // 9
|
||||
};
|
||||
|
||||
/** Sequence of parities to be used with supplemental 2.*/
|
||||
private static readonly byte[][] PARITY2 =
|
||||
{
|
||||
new byte[] {ODD, ODD}, // 0
|
||||
new byte[] {ODD, EVEN}, // 1
|
||||
new byte[] {EVEN, ODD}, // 2
|
||||
new byte[] {EVEN, EVEN} // 3
|
||||
};
|
||||
|
||||
/** Sequence of parities to be used with supplemental 2.*/
|
||||
private static readonly byte[][] PARITY5 =
|
||||
{
|
||||
new byte[] {EVEN, EVEN, ODD, ODD, ODD}, // 0
|
||||
new byte[] {EVEN, ODD, EVEN, ODD, ODD}, // 1
|
||||
new byte[] {EVEN, ODD, ODD, EVEN, ODD}, // 2
|
||||
new byte[] {EVEN, ODD, ODD, ODD, EVEN}, // 3
|
||||
new byte[] {ODD, EVEN, EVEN, ODD, ODD}, // 4
|
||||
new byte[] {ODD, ODD, EVEN, EVEN, ODD}, // 5
|
||||
new byte[] {ODD, ODD, ODD, EVEN, EVEN}, // 6
|
||||
new byte[] {ODD, EVEN, ODD, EVEN, ODD}, // 7
|
||||
new byte[] {ODD, EVEN, ODD, ODD, EVEN}, // 8
|
||||
new byte[] {ODD, ODD, EVEN, ODD, EVEN} // 9
|
||||
};
|
||||
|
||||
/** Sequence of parities to be used with UPCE.*/
|
||||
private static readonly byte[][] PARITYE =
|
||||
{
|
||||
new byte[] {EVEN, EVEN, EVEN, ODD, ODD, ODD}, // 0
|
||||
new byte[] {EVEN, EVEN, ODD, EVEN, ODD, ODD}, // 1
|
||||
new byte[] {EVEN, EVEN, ODD, ODD, EVEN, ODD}, // 2
|
||||
new byte[] {EVEN, EVEN, ODD, ODD, ODD, EVEN}, // 3
|
||||
new byte[] {EVEN, ODD, EVEN, EVEN, ODD, ODD}, // 4
|
||||
new byte[] {EVEN, ODD, ODD, EVEN, EVEN, ODD}, // 5
|
||||
new byte[] {EVEN, ODD, ODD, ODD, EVEN, EVEN}, // 6
|
||||
new byte[] {EVEN, ODD, EVEN, ODD, EVEN, ODD}, // 7
|
||||
new byte[] {EVEN, ODD, EVEN, ODD, ODD, EVEN}, // 8
|
||||
new byte[] {EVEN, ODD, ODD, EVEN, ODD, EVEN} // 9
|
||||
};
|
||||
|
||||
/** Creates new BarcodeEAN */
|
||||
public BarcodeEAN() {
|
||||
x = 0.8f;
|
||||
font = BaseFont.CreateFont("Helvetica", "winansi", false);
|
||||
size = 8;
|
||||
baseline = size;
|
||||
barHeight = size * 3;
|
||||
guardBars = true;
|
||||
codeType = EAN13;
|
||||
code = "";
|
||||
}
|
||||
|
||||
/** Calculates the EAN parity character.
|
||||
* @param code the code
|
||||
* @return the parity character
|
||||
*/
|
||||
public static int CalculateEANParity(string code) {
|
||||
int mul = 3;
|
||||
int total = 0;
|
||||
for (int k = code.Length - 1; k >= 0; --k) {
|
||||
int n = code[k] - '0';
|
||||
total += mul * n;
|
||||
mul ^= 2;
|
||||
}
|
||||
return (10 - (total % 10)) % 10;
|
||||
}
|
||||
|
||||
/** Converts an UPCA code into an UPCE code. If the code can not
|
||||
* be converted a <CODE>null</CODE> is returned.
|
||||
* @param text the code to convert. It must have 12 numeric characters
|
||||
* @return the 8 converted digits or <CODE>null</CODE> if the
|
||||
* code could not be converted
|
||||
*/
|
||||
static public string ConvertUPCAtoUPCE(string text) {
|
||||
if (text.Length != 12 || !(text.StartsWith("0") || text.StartsWith("1")))
|
||||
return null;
|
||||
if (text.Substring(3, 3).Equals("000") || text.Substring(3, 3).Equals("100")
|
||||
|| text.Substring(3, 3).Equals("200")) {
|
||||
if (text.Substring(6, 2).Equals("00"))
|
||||
return text.Substring(0, 1) + text.Substring(1, 2) + text.Substring(8, 3) + text.Substring(3, 1) + text.Substring(11);
|
||||
}
|
||||
else if (text.Substring(4, 2).Equals("00")) {
|
||||
if (text.Substring(6, 3).Equals("000"))
|
||||
return text.Substring(0, 1) + text.Substring(1, 3) + text.Substring(9, 2) + "3" + text.Substring(11);
|
||||
}
|
||||
else if (text.Substring(5, 1).Equals("0")) {
|
||||
if (text.Substring(6, 4).Equals("0000"))
|
||||
return text.Substring(0, 1) + text.Substring(1, 4) + text.Substring(10, 1) + "4" + text.Substring(11);
|
||||
}
|
||||
else if (text[10] >= '5') {
|
||||
if (text.Substring(6, 4).Equals("0000"))
|
||||
return text.Substring(0, 1) + text.Substring(1, 5) + text.Substring(10, 1) + text.Substring(11);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Creates the bars for the barcode EAN13 and UPCA.
|
||||
* @param _code the text with 13 digits
|
||||
* @return the barcode
|
||||
*/
|
||||
public static byte[] GetBarsEAN13(string _code) {
|
||||
int[] code = new int[_code.Length];
|
||||
for (int k = 0; k < code.Length; ++k)
|
||||
code[k] = _code[k] - '0';
|
||||
byte[] bars = new byte[TOTALBARS_EAN13];
|
||||
int pb = 0;
|
||||
bars[pb++] = 1;
|
||||
bars[pb++] = 1;
|
||||
bars[pb++] = 1;
|
||||
byte[] sequence = PARITY13[code[0]];
|
||||
for (int k = 0; k < sequence.Length; ++k) {
|
||||
int c = code[k + 1];
|
||||
byte[] stripes = BARS[c];
|
||||
if (sequence[k] == ODD) {
|
||||
bars[pb++] = stripes[0];
|
||||
bars[pb++] = stripes[1];
|
||||
bars[pb++] = stripes[2];
|
||||
bars[pb++] = stripes[3];
|
||||
}
|
||||
else {
|
||||
bars[pb++] = stripes[3];
|
||||
bars[pb++] = stripes[2];
|
||||
bars[pb++] = stripes[1];
|
||||
bars[pb++] = stripes[0];
|
||||
}
|
||||
}
|
||||
bars[pb++] = 1;
|
||||
bars[pb++] = 1;
|
||||
bars[pb++] = 1;
|
||||
bars[pb++] = 1;
|
||||
bars[pb++] = 1;
|
||||
for (int k = 7; k < 13; ++k) {
|
||||
int c = code[k];
|
||||
byte[] stripes = BARS[c];
|
||||
bars[pb++] = stripes[0];
|
||||
bars[pb++] = stripes[1];
|
||||
bars[pb++] = stripes[2];
|
||||
bars[pb++] = stripes[3];
|
||||
}
|
||||
bars[pb++] = 1;
|
||||
bars[pb++] = 1;
|
||||
bars[pb++] = 1;
|
||||
return bars;
|
||||
}
|
||||
|
||||
/** Creates the bars for the barcode EAN8.
|
||||
* @param _code the text with 8 digits
|
||||
* @return the barcode
|
||||
*/
|
||||
public static byte[] GetBarsEAN8(string _code) {
|
||||
int[] code = new int[_code.Length];
|
||||
for (int k = 0; k < code.Length; ++k)
|
||||
code[k] = _code[k] - '0';
|
||||
byte[] bars = new byte[TOTALBARS_EAN8];
|
||||
int pb = 0;
|
||||
bars[pb++] = 1;
|
||||
bars[pb++] = 1;
|
||||
bars[pb++] = 1;
|
||||
for (int k = 0; k < 4; ++k) {
|
||||
int c = code[k];
|
||||
byte[] stripes = BARS[c];
|
||||
bars[pb++] = stripes[0];
|
||||
bars[pb++] = stripes[1];
|
||||
bars[pb++] = stripes[2];
|
||||
bars[pb++] = stripes[3];
|
||||
}
|
||||
bars[pb++] = 1;
|
||||
bars[pb++] = 1;
|
||||
bars[pb++] = 1;
|
||||
bars[pb++] = 1;
|
||||
bars[pb++] = 1;
|
||||
for (int k = 4; k < 8; ++k) {
|
||||
int c = code[k];
|
||||
byte[] stripes = BARS[c];
|
||||
bars[pb++] = stripes[0];
|
||||
bars[pb++] = stripes[1];
|
||||
bars[pb++] = stripes[2];
|
||||
bars[pb++] = stripes[3];
|
||||
}
|
||||
bars[pb++] = 1;
|
||||
bars[pb++] = 1;
|
||||
bars[pb++] = 1;
|
||||
return bars;
|
||||
}
|
||||
|
||||
/** Creates the bars for the barcode UPCE.
|
||||
* @param _code the text with 8 digits
|
||||
* @return the barcode
|
||||
*/
|
||||
public static byte[] GetBarsUPCE(string _code) {
|
||||
int[] code = new int[_code.Length];
|
||||
for (int k = 0; k < code.Length; ++k)
|
||||
code[k] = _code[k] - '0';
|
||||
byte[] bars = new byte[TOTALBARS_UPCE];
|
||||
bool flip = (code[0] != 0);
|
||||
int pb = 0;
|
||||
bars[pb++] = 1;
|
||||
bars[pb++] = 1;
|
||||
bars[pb++] = 1;
|
||||
byte[] sequence = PARITYE[code[code.Length - 1]];
|
||||
for (int k = 1; k < code.Length - 1; ++k) {
|
||||
int c = code[k];
|
||||
byte[] stripes = BARS[c];
|
||||
if (sequence[k - 1] == (flip ? EVEN : ODD)) {
|
||||
bars[pb++] = stripes[0];
|
||||
bars[pb++] = stripes[1];
|
||||
bars[pb++] = stripes[2];
|
||||
bars[pb++] = stripes[3];
|
||||
}
|
||||
else {
|
||||
bars[pb++] = stripes[3];
|
||||
bars[pb++] = stripes[2];
|
||||
bars[pb++] = stripes[1];
|
||||
bars[pb++] = stripes[0];
|
||||
}
|
||||
}
|
||||
bars[pb++] = 1;
|
||||
bars[pb++] = 1;
|
||||
bars[pb++] = 1;
|
||||
bars[pb++] = 1;
|
||||
bars[pb++] = 1;
|
||||
bars[pb++] = 1;
|
||||
return bars;
|
||||
}
|
||||
|
||||
/** Creates the bars for the barcode supplemental 2.
|
||||
* @param _code the text with 2 digits
|
||||
* @return the barcode
|
||||
*/
|
||||
public static byte[] GetBarsSupplemental2(string _code) {
|
||||
int[] code = new int[2];
|
||||
for (int k = 0; k < code.Length; ++k)
|
||||
code[k] = _code[k] - '0';
|
||||
byte[] bars = new byte[TOTALBARS_SUPP2];
|
||||
int pb = 0;
|
||||
int parity = (code[0] * 10 + code[1]) % 4;
|
||||
bars[pb++] = 1;
|
||||
bars[pb++] = 1;
|
||||
bars[pb++] = 2;
|
||||
byte[] sequence = PARITY2[parity];
|
||||
for (int k = 0; k < sequence.Length; ++k) {
|
||||
if (k == 1) {
|
||||
bars[pb++] = 1;
|
||||
bars[pb++] = 1;
|
||||
}
|
||||
int c = code[k];
|
||||
byte[] stripes = BARS[c];
|
||||
if (sequence[k] == ODD) {
|
||||
bars[pb++] = stripes[0];
|
||||
bars[pb++] = stripes[1];
|
||||
bars[pb++] = stripes[2];
|
||||
bars[pb++] = stripes[3];
|
||||
}
|
||||
else {
|
||||
bars[pb++] = stripes[3];
|
||||
bars[pb++] = stripes[2];
|
||||
bars[pb++] = stripes[1];
|
||||
bars[pb++] = stripes[0];
|
||||
}
|
||||
}
|
||||
return bars;
|
||||
}
|
||||
|
||||
/** Creates the bars for the barcode supplemental 5.
|
||||
* @param _code the text with 5 digits
|
||||
* @return the barcode
|
||||
*/
|
||||
public static byte[] GetBarsSupplemental5(string _code) {
|
||||
int[] code = new int[5];
|
||||
for (int k = 0; k < code.Length; ++k)
|
||||
code[k] = _code[k] - '0';
|
||||
byte[] bars = new byte[TOTALBARS_SUPP5];
|
||||
int pb = 0;
|
||||
int parity = (((code[0] + code[2] + code[4]) * 3) + ((code[1] + code[3]) * 9)) % 10;
|
||||
bars[pb++] = 1;
|
||||
bars[pb++] = 1;
|
||||
bars[pb++] = 2;
|
||||
byte[] sequence = PARITY5[parity];
|
||||
for (int k = 0; k < sequence.Length; ++k) {
|
||||
if (k != 0) {
|
||||
bars[pb++] = 1;
|
||||
bars[pb++] = 1;
|
||||
}
|
||||
int c = code[k];
|
||||
byte[] stripes = BARS[c];
|
||||
if (sequence[k] == ODD) {
|
||||
bars[pb++] = stripes[0];
|
||||
bars[pb++] = stripes[1];
|
||||
bars[pb++] = stripes[2];
|
||||
bars[pb++] = stripes[3];
|
||||
}
|
||||
else {
|
||||
bars[pb++] = stripes[3];
|
||||
bars[pb++] = stripes[2];
|
||||
bars[pb++] = stripes[1];
|
||||
bars[pb++] = stripes[0];
|
||||
}
|
||||
}
|
||||
return bars;
|
||||
}
|
||||
|
||||
/** Gets the maximum area that the barcode and the text, if
|
||||
* any, will occupy. The lower left corner is always (0, 0).
|
||||
* @return the size the barcode occupies.
|
||||
*/
|
||||
public override Rectangle BarcodeSize {
|
||||
get {
|
||||
float width = 0;
|
||||
float height = barHeight;
|
||||
if (font != null) {
|
||||
if (baseline <= 0)
|
||||
height += -baseline + size;
|
||||
else
|
||||
height += baseline - font.GetFontDescriptor(BaseFont.DESCENT, size);
|
||||
}
|
||||
switch (codeType) {
|
||||
case BarcodeEAN.EAN13:
|
||||
width = x * (11 + 12 * 7);
|
||||
if (font != null) {
|
||||
width += font.GetWidthPoint(code[0], size);
|
||||
}
|
||||
break;
|
||||
case EAN8:
|
||||
width = x * (11 + 8 * 7);
|
||||
break;
|
||||
case UPCA:
|
||||
width = x * (11 + 12 * 7);
|
||||
if (font != null) {
|
||||
width += font.GetWidthPoint(code[0], size) + font.GetWidthPoint(code[11], size);
|
||||
}
|
||||
break;
|
||||
case UPCE:
|
||||
width = x * (9 + 6 * 7);
|
||||
if (font != null) {
|
||||
width += font.GetWidthPoint(code[0], size) + font.GetWidthPoint(code[7], size);
|
||||
}
|
||||
break;
|
||||
case SUPP2:
|
||||
width = x * (6 + 2 * 7);
|
||||
break;
|
||||
case SUPP5:
|
||||
width = x * (4 + 5 * 7 + 4 * 2);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("Invalid code type.");
|
||||
}
|
||||
return new Rectangle(width, height);
|
||||
}
|
||||
}
|
||||
|
||||
/** Places the barcode in a <CODE>PdfContentByte</CODE>. The
|
||||
* barcode is always placed at coodinates (0, 0). Use the
|
||||
* translation matrix to move it elsewhere.<p>
|
||||
* The bars and text are written in the following colors:<p>
|
||||
* <P><TABLE BORDER=1>
|
||||
* <TR>
|
||||
* <TH><P><CODE>barColor</CODE></TH>
|
||||
* <TH><P><CODE>textColor</CODE></TH>
|
||||
* <TH><P>Result</TH>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD><P><CODE>null</CODE></TD>
|
||||
* <TD><P><CODE>null</CODE></TD>
|
||||
* <TD><P>bars and text painted with current fill color</TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD><P><CODE>barColor</CODE></TD>
|
||||
* <TD><P><CODE>null</CODE></TD>
|
||||
* <TD><P>bars and text painted with <CODE>barColor</CODE></TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD><P><CODE>null</CODE></TD>
|
||||
* <TD><P><CODE>textColor</CODE></TD>
|
||||
* <TD><P>bars painted with current color<br>text painted with <CODE>textColor</CODE></TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD><P><CODE>barColor</CODE></TD>
|
||||
* <TD><P><CODE>textColor</CODE></TD>
|
||||
* <TD><P>bars painted with <CODE>barColor</CODE><br>text painted with <CODE>textColor</CODE></TD>
|
||||
* </TR>
|
||||
* </TABLE>
|
||||
* @param cb the <CODE>PdfContentByte</CODE> where the barcode will be placed
|
||||
* @param barColor the color of the bars. It can be <CODE>null</CODE>
|
||||
* @param textColor the color of the text. It can be <CODE>null</CODE>
|
||||
* @return the dimensions the barcode occupies
|
||||
*/
|
||||
public override Rectangle PlaceBarcode(PdfContentByte cb, Color barColor, Color textColor) {
|
||||
Rectangle rect = this.BarcodeSize;
|
||||
float barStartX = 0;
|
||||
float barStartY = 0;
|
||||
float textStartY = 0;
|
||||
if (font != null) {
|
||||
if (baseline <= 0)
|
||||
textStartY = barHeight - baseline;
|
||||
else {
|
||||
textStartY = -font.GetFontDescriptor(BaseFont.DESCENT, size);
|
||||
barStartY = textStartY + baseline;
|
||||
}
|
||||
}
|
||||
switch (codeType) {
|
||||
case EAN13:
|
||||
case UPCA:
|
||||
case UPCE:
|
||||
if (font != null)
|
||||
barStartX += font.GetWidthPoint(code[0], size);
|
||||
break;
|
||||
}
|
||||
byte[] bars = null;
|
||||
int[] guard = GUARD_EMPTY;
|
||||
switch (codeType) {
|
||||
case EAN13:
|
||||
bars = GetBarsEAN13(code);
|
||||
guard = GUARD_EAN13;
|
||||
break;
|
||||
case EAN8:
|
||||
bars = GetBarsEAN8(code);
|
||||
guard = GUARD_EAN8;
|
||||
break;
|
||||
case UPCA:
|
||||
bars = GetBarsEAN13("0" + code);
|
||||
guard = GUARD_UPCA;
|
||||
break;
|
||||
case UPCE:
|
||||
bars = GetBarsUPCE(code);
|
||||
guard = GUARD_UPCE;
|
||||
break;
|
||||
case SUPP2:
|
||||
bars = GetBarsSupplemental2(code);
|
||||
break;
|
||||
case SUPP5:
|
||||
bars = GetBarsSupplemental5(code);
|
||||
break;
|
||||
}
|
||||
float keepBarX = barStartX;
|
||||
bool print = true;
|
||||
float gd = 0;
|
||||
if (font != null && baseline > 0 && guardBars) {
|
||||
gd = baseline / 2;
|
||||
}
|
||||
if (barColor != null)
|
||||
cb.SetColorFill(barColor);
|
||||
for (int k = 0; k < bars.Length; ++k) {
|
||||
float w = bars[k] * x;
|
||||
if (print) {
|
||||
if (Array.BinarySearch(guard, k) >= 0)
|
||||
cb.Rectangle(barStartX, barStartY - gd, w - inkSpreading, barHeight + gd);
|
||||
else
|
||||
cb.Rectangle(barStartX, barStartY, w - inkSpreading, barHeight);
|
||||
}
|
||||
print = !print;
|
||||
barStartX += w;
|
||||
}
|
||||
cb.Fill();
|
||||
if (font != null) {
|
||||
if (textColor != null)
|
||||
cb.SetColorFill(textColor);
|
||||
cb.BeginText();
|
||||
cb.SetFontAndSize(font, size);
|
||||
switch (codeType) {
|
||||
case EAN13:
|
||||
cb.SetTextMatrix(0, textStartY);
|
||||
cb.ShowText(code.Substring(0, 1));
|
||||
for (int k = 1; k < 13; ++k) {
|
||||
string c = code.Substring(k, 1);
|
||||
float len = font.GetWidthPoint(c, size);
|
||||
float pX = keepBarX + TEXTPOS_EAN13[k - 1] * x - len / 2;
|
||||
cb.SetTextMatrix(pX, textStartY);
|
||||
cb.ShowText(c);
|
||||
}
|
||||
break;
|
||||
case EAN8:
|
||||
for (int k = 0; k < 8; ++k) {
|
||||
string c = code.Substring(k, 1);
|
||||
float len = font.GetWidthPoint(c, size);
|
||||
float pX = TEXTPOS_EAN8[k] * x - len / 2;
|
||||
cb.SetTextMatrix(pX, textStartY);
|
||||
cb.ShowText(c);
|
||||
}
|
||||
break;
|
||||
case UPCA:
|
||||
cb.SetTextMatrix(0, textStartY);
|
||||
cb.ShowText(code.Substring(0, 1));
|
||||
for (int k = 1; k < 11; ++k) {
|
||||
string c = code.Substring(k, 1);
|
||||
float len = font.GetWidthPoint(c, size);
|
||||
float pX = keepBarX + TEXTPOS_EAN13[k] * x - len / 2;
|
||||
cb.SetTextMatrix(pX, textStartY);
|
||||
cb.ShowText(c);
|
||||
}
|
||||
cb.SetTextMatrix(keepBarX + x * (11 + 12 * 7), textStartY);
|
||||
cb.ShowText(code.Substring(11, 1));
|
||||
break;
|
||||
case UPCE:
|
||||
cb.SetTextMatrix(0, textStartY);
|
||||
cb.ShowText(code.Substring(0, 1));
|
||||
for (int k = 1; k < 7; ++k) {
|
||||
string c = code.Substring(k, 1);
|
||||
float len = font.GetWidthPoint(c, size);
|
||||
float pX = keepBarX + TEXTPOS_EAN13[k - 1] * x - len / 2;
|
||||
cb.SetTextMatrix(pX, textStartY);
|
||||
cb.ShowText(c);
|
||||
}
|
||||
cb.SetTextMatrix(keepBarX + x * (9 + 6 * 7), textStartY);
|
||||
cb.ShowText(code.Substring(7, 1));
|
||||
break;
|
||||
case SUPP2:
|
||||
case SUPP5:
|
||||
for (int k = 0; k < code.Length; ++k) {
|
||||
string c = code.Substring(k, 1);
|
||||
float len = font.GetWidthPoint(c, size);
|
||||
float pX = (7.5f + (9 * k)) * x - len / 2;
|
||||
cb.SetTextMatrix(pX, textStartY);
|
||||
cb.ShowText(c);
|
||||
}
|
||||
break;
|
||||
}
|
||||
cb.EndText();
|
||||
}
|
||||
return rect;
|
||||
}
|
||||
|
||||
public override System.Drawing.Image CreateDrawingImage(System.Drawing.Color foreground, System.Drawing.Color background) {
|
||||
int width = 0;
|
||||
byte[] bars = null;
|
||||
switch (codeType) {
|
||||
case EAN13:
|
||||
bars = GetBarsEAN13(code);
|
||||
width = 11 + 12 * 7;
|
||||
break;
|
||||
case EAN8:
|
||||
bars = GetBarsEAN8(code);
|
||||
width = 11 + 8 * 7;
|
||||
break;
|
||||
case UPCA:
|
||||
bars = GetBarsEAN13("0" + code);
|
||||
width = 11 + 12 * 7;
|
||||
break;
|
||||
case UPCE:
|
||||
bars = GetBarsUPCE(code);
|
||||
width = 9 + 6 * 7;
|
||||
break;
|
||||
case SUPP2:
|
||||
bars = GetBarsSupplemental2(code);
|
||||
width = 6 + 2 * 7;
|
||||
break;
|
||||
case SUPP5:
|
||||
bars = GetBarsSupplemental5(code);
|
||||
width = 4 + 5 * 7 + 4 * 2;
|
||||
break;
|
||||
default:
|
||||
throw new InvalidOperationException("Invalid code type.");
|
||||
}
|
||||
int height = (int)barHeight;
|
||||
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(width, height);
|
||||
for (int h = 0; h < height; ++h) {
|
||||
bool print = true;
|
||||
int ptr = 0;
|
||||
for (int k = 0; k < bars.Length; ++k) {
|
||||
int w = bars[k];
|
||||
System.Drawing.Color c = background;
|
||||
if (print)
|
||||
c = foreground;
|
||||
print = !print;
|
||||
for (int j = 0; j < w; ++j)
|
||||
bmp.SetPixel(ptr++, h, c);
|
||||
}
|
||||
}
|
||||
return bmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
150
iTechSharp/iTextSharp/text/pdf/BarcodeEANSUPP.cs
Normal file
150
iTechSharp/iTextSharp/text/pdf/BarcodeEANSUPP.cs
Normal file
@@ -0,0 +1,150 @@
|
||||
using System;
|
||||
using iTextSharp.text;
|
||||
|
||||
/*
|
||||
* Copyright 2002 by Paulo Soares.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
namespace iTextSharp.text.pdf {
|
||||
/** This class takes 2 barcodes, an EAN/UPC and a supplemental
|
||||
* and creates a single barcode with both combined in the
|
||||
* expected layout. The UPC/EAN should have a positive text
|
||||
* baseline and the supplemental a negative one (in the supplemental
|
||||
* the text is on the top of the barcode.<p>
|
||||
* The default parameters are:
|
||||
* <pre>
|
||||
*n = 8; // horizontal distance between the two barcodes
|
||||
* </pre>
|
||||
*
|
||||
* @author Paulo Soares (psoares@consiste.pt)
|
||||
*/
|
||||
public class BarcodeEANSUPP : Barcode {
|
||||
|
||||
/** The barcode with the EAN/UPC.
|
||||
*/
|
||||
protected Barcode ean;
|
||||
/** The barcode with the supplemental.
|
||||
*/
|
||||
protected Barcode supp;
|
||||
|
||||
/** Creates new combined barcode.
|
||||
* @param ean the EAN/UPC barcode
|
||||
* @param supp the supplemental barcode
|
||||
*/
|
||||
public BarcodeEANSUPP(Barcode ean, Barcode supp) {
|
||||
n = 8; // horizontal distance between the two barcodes
|
||||
this.ean = ean;
|
||||
this.supp = supp;
|
||||
}
|
||||
|
||||
/** Gets the maximum area that the barcode and the text, if
|
||||
* any, will occupy. The lower left corner is always (0, 0).
|
||||
* @return the size the barcode occupies.
|
||||
*/
|
||||
public override Rectangle BarcodeSize {
|
||||
get {
|
||||
Rectangle rect = ean.BarcodeSize;
|
||||
rect.Right = rect.Width + supp.BarcodeSize.Width + n;
|
||||
return rect;
|
||||
}
|
||||
}
|
||||
|
||||
/** Places the barcode in a <CODE>PdfContentByte</CODE>. The
|
||||
* barcode is always placed at coodinates (0, 0). Use the
|
||||
* translation matrix to move it elsewhere.<p>
|
||||
* The bars and text are written in the following colors:<p>
|
||||
* <P><TABLE BORDER=1>
|
||||
* <TR>
|
||||
* <TH><P><CODE>barColor</CODE></TH>
|
||||
* <TH><P><CODE>textColor</CODE></TH>
|
||||
* <TH><P>Result</TH>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD><P><CODE>null</CODE></TD>
|
||||
* <TD><P><CODE>null</CODE></TD>
|
||||
* <TD><P>bars and text painted with current fill color</TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD><P><CODE>barColor</CODE></TD>
|
||||
* <TD><P><CODE>null</CODE></TD>
|
||||
* <TD><P>bars and text painted with <CODE>barColor</CODE></TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD><P><CODE>null</CODE></TD>
|
||||
* <TD><P><CODE>textColor</CODE></TD>
|
||||
* <TD><P>bars painted with current color<br>text painted with <CODE>textColor</CODE></TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD><P><CODE>barColor</CODE></TD>
|
||||
* <TD><P><CODE>textColor</CODE></TD>
|
||||
* <TD><P>bars painted with <CODE>barColor</CODE><br>text painted with <CODE>textColor</CODE></TD>
|
||||
* </TR>
|
||||
* </TABLE>
|
||||
* @param cb the <CODE>PdfContentByte</CODE> where the barcode will be placed
|
||||
* @param barColor the color of the bars. It can be <CODE>null</CODE>
|
||||
* @param textColor the color of the text. It can be <CODE>null</CODE>
|
||||
* @return the dimensions the barcode occupies
|
||||
*/
|
||||
public override Rectangle PlaceBarcode(PdfContentByte cb, Color barColor, Color textColor) {
|
||||
if (supp.Font != null)
|
||||
supp.BarHeight = ean.BarHeight + supp.Baseline - supp.Font.GetFontDescriptor(BaseFont.CAPHEIGHT, supp.Size);
|
||||
else
|
||||
supp.BarHeight = ean.BarHeight;
|
||||
Rectangle eanR = ean.BarcodeSize;
|
||||
cb.SaveState();
|
||||
ean.PlaceBarcode(cb, barColor, textColor);
|
||||
cb.RestoreState();
|
||||
cb.SaveState();
|
||||
cb.ConcatCTM(1, 0, 0, 1, eanR.Width + n, eanR.Height - ean.BarHeight);
|
||||
supp.PlaceBarcode(cb, barColor, textColor);
|
||||
cb.RestoreState();
|
||||
return this.BarcodeSize;
|
||||
}
|
||||
|
||||
public override System.Drawing.Image CreateDrawingImage(System.Drawing.Color foreground, System.Drawing.Color background) {
|
||||
throw new InvalidOperationException("The two barcodes must be composed externally.");
|
||||
}
|
||||
}
|
||||
}
|
||||
317
iTechSharp/iTextSharp/text/pdf/BarcodeInter25.cs
Normal file
317
iTechSharp/iTextSharp/text/pdf/BarcodeInter25.cs
Normal file
@@ -0,0 +1,317 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using iTextSharp.text;
|
||||
|
||||
/*
|
||||
* $Id: BarcodeInter25.cs,v 1.5 2006/09/17 15:58:51 psoares33 Exp $
|
||||
*
|
||||
* Copyright 2002-2006 by Paulo Soares.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
namespace iTextSharp.text.pdf {
|
||||
/** Implements the code interleaved 2 of 5. The text can include
|
||||
* non numeric characters that are printed but do not generate bars.
|
||||
* The default parameters are:
|
||||
* <pre>
|
||||
*x = 0.8f;
|
||||
*n = 2;
|
||||
*font = BaseFont.CreateFont("Helvetica", "winansi", false);
|
||||
*size = 8;
|
||||
*baseline = size;
|
||||
*barHeight = size * 3;
|
||||
*textint= Element.ALIGN_CENTER;
|
||||
*generateChecksum = false;
|
||||
*checksumText = false;
|
||||
* </pre>
|
||||
*
|
||||
* @author Paulo Soares (psoares@consiste.pt)
|
||||
*/
|
||||
public class BarcodeInter25 : Barcode {
|
||||
|
||||
/** The bars to generate the code.
|
||||
*/
|
||||
private static readonly byte[][] BARS = {
|
||||
new byte[] {0,0,1,1,0},
|
||||
new byte[] {1,0,0,0,1},
|
||||
new byte[] {0,1,0,0,1},
|
||||
new byte[] {1,1,0,0,0},
|
||||
new byte[] {0,0,1,0,1},
|
||||
new byte[] {1,0,1,0,0},
|
||||
new byte[] {0,1,1,0,0},
|
||||
new byte[] {0,0,0,1,1},
|
||||
new byte[] {1,0,0,1,0},
|
||||
new byte[] {0,1,0,1,0}
|
||||
};
|
||||
|
||||
/** Creates new BarcodeInter25 */
|
||||
public BarcodeInter25() {
|
||||
x = 0.8f;
|
||||
n = 2;
|
||||
font = BaseFont.CreateFont("Helvetica", "winansi", false);
|
||||
size = 8;
|
||||
baseline = size;
|
||||
barHeight = size * 3;
|
||||
textAlignment = Element.ALIGN_CENTER;
|
||||
generateChecksum = false;
|
||||
checksumText = false;
|
||||
}
|
||||
|
||||
/** Deletes all the non numeric characters from <CODE>text</CODE>.
|
||||
* @param text the text
|
||||
* @return a <CODE>string</CODE> with only numeric characters
|
||||
*/
|
||||
public static string KeepNumbers(string text) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int k = 0; k < text.Length; ++k) {
|
||||
char c = text[k];
|
||||
if (c >= '0' && c <= '9')
|
||||
sb.Append(c);
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/** Calculates the checksum.
|
||||
* @param text the numeric text
|
||||
* @return the checksum
|
||||
*/
|
||||
public static char GetChecksum(string text) {
|
||||
int mul = 3;
|
||||
int total = 0;
|
||||
for (int k = text.Length - 1; k >= 0; --k) {
|
||||
int n = text[k] - '0';
|
||||
total += mul * n;
|
||||
mul ^= 2;
|
||||
}
|
||||
return (char)(((10 - (total % 10)) % 10) + '0');
|
||||
}
|
||||
|
||||
/** Creates the bars for the barcode.
|
||||
* @param text the text. It can contain non numeric characters
|
||||
* @return the barcode
|
||||
*/
|
||||
public static byte[] GetBarsInter25(string text) {
|
||||
text = KeepNumbers(text);
|
||||
if ((text.Length & 1) != 0)
|
||||
throw new ArgumentException("The text length must be even.");
|
||||
byte[] bars = new byte[text.Length * 5 + 7];
|
||||
int pb = 0;
|
||||
bars[pb++] = 0;
|
||||
bars[pb++] = 0;
|
||||
bars[pb++] = 0;
|
||||
bars[pb++] = 0;
|
||||
int len = text.Length / 2;
|
||||
for (int k = 0; k < len; ++k) {
|
||||
int c1 = text[k * 2] - '0';
|
||||
int c2 = text[k * 2 + 1] - '0';
|
||||
byte[] b1 = BARS[c1];
|
||||
byte[] b2 = BARS[c2];
|
||||
for (int j = 0; j < 5; ++j) {
|
||||
bars[pb++] = b1[j];
|
||||
bars[pb++] = b2[j];
|
||||
}
|
||||
}
|
||||
bars[pb++] = 1;
|
||||
bars[pb++] = 0;
|
||||
bars[pb++] = 0;
|
||||
return bars;
|
||||
}
|
||||
|
||||
/** Gets the maximum area that the barcode and the text, if
|
||||
* any, will occupy. The lower left corner is always (0, 0).
|
||||
* @return the size the barcode occupies.
|
||||
*/
|
||||
public override Rectangle BarcodeSize {
|
||||
get {
|
||||
float fontX = 0;
|
||||
float fontY = 0;
|
||||
if (font != null) {
|
||||
if (baseline > 0)
|
||||
fontY = baseline - font.GetFontDescriptor(BaseFont.DESCENT, size);
|
||||
else
|
||||
fontY = -baseline + size;
|
||||
string fullCode = code;
|
||||
if (generateChecksum && checksumText)
|
||||
fullCode += GetChecksum(fullCode);
|
||||
fontX = font.GetWidthPoint(altText != null ? altText : fullCode, size);
|
||||
}
|
||||
string fCode = KeepNumbers(code);
|
||||
int len = fCode.Length;
|
||||
if (generateChecksum)
|
||||
++len;
|
||||
float fullWidth = len * (3 * x + 2 * x * n) + (6 + n ) * x;
|
||||
fullWidth = Math.Max(fullWidth, fontX);
|
||||
float fullHeight = barHeight + fontY;
|
||||
return new Rectangle(fullWidth, fullHeight);
|
||||
}
|
||||
}
|
||||
|
||||
/** Places the barcode in a <CODE>PdfContentByte</CODE>. The
|
||||
* barcode is always placed at coodinates (0, 0). Use the
|
||||
* translation matrix to move it elsewhere.<p>
|
||||
* The bars and text are written in the following colors:<p>
|
||||
* <P><TABLE BORDER=1>
|
||||
* <TR>
|
||||
* <TH><P><CODE>barColor</CODE></TH>
|
||||
* <TH><P><CODE>textColor</CODE></TH>
|
||||
* <TH><P>Result</TH>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD><P><CODE>null</CODE></TD>
|
||||
* <TD><P><CODE>null</CODE></TD>
|
||||
* <TD><P>bars and text painted with current fill color</TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD><P><CODE>barColor</CODE></TD>
|
||||
* <TD><P><CODE>null</CODE></TD>
|
||||
* <TD><P>bars and text painted with <CODE>barColor</CODE></TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD><P><CODE>null</CODE></TD>
|
||||
* <TD><P><CODE>textColor</CODE></TD>
|
||||
* <TD><P>bars painted with current color<br>text painted with <CODE>textColor</CODE></TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD><P><CODE>barColor</CODE></TD>
|
||||
* <TD><P><CODE>textColor</CODE></TD>
|
||||
* <TD><P>bars painted with <CODE>barColor</CODE><br>text painted with <CODE>textColor</CODE></TD>
|
||||
* </TR>
|
||||
* </TABLE>
|
||||
* @param cb the <CODE>PdfContentByte</CODE> where the barcode will be placed
|
||||
* @param barColor the color of the bars. It can be <CODE>null</CODE>
|
||||
* @param textColor the color of the text. It can be <CODE>null</CODE>
|
||||
* @return the dimensions the barcode occupies
|
||||
*/
|
||||
public override Rectangle PlaceBarcode(PdfContentByte cb, Color barColor, Color textColor) {
|
||||
string fullCode = code;
|
||||
float fontX = 0;
|
||||
if (font != null) {
|
||||
if (generateChecksum && checksumText)
|
||||
fullCode += GetChecksum(fullCode);
|
||||
fontX = font.GetWidthPoint(fullCode = altText != null ? altText : fullCode, size);
|
||||
}
|
||||
string bCode = KeepNumbers(code);
|
||||
if (generateChecksum)
|
||||
bCode += GetChecksum(bCode);
|
||||
int len = bCode.Length;
|
||||
float fullWidth = len * (3 * x + 2 * x * n) + (6 + n ) * x;
|
||||
float barStartX = 0;
|
||||
float textStartX = 0;
|
||||
switch (textAlignment) {
|
||||
case Element.ALIGN_LEFT:
|
||||
break;
|
||||
case Element.ALIGN_RIGHT:
|
||||
if (fontX > fullWidth)
|
||||
barStartX = fontX - fullWidth;
|
||||
else
|
||||
textStartX = fullWidth - fontX;
|
||||
break;
|
||||
default:
|
||||
if (fontX > fullWidth)
|
||||
barStartX = (fontX - fullWidth) / 2;
|
||||
else
|
||||
textStartX = (fullWidth - fontX) / 2;
|
||||
break;
|
||||
}
|
||||
float barStartY = 0;
|
||||
float textStartY = 0;
|
||||
if (font != null) {
|
||||
if (baseline <= 0)
|
||||
textStartY = barHeight - baseline;
|
||||
else {
|
||||
textStartY = -font.GetFontDescriptor(BaseFont.DESCENT, size);
|
||||
barStartY = textStartY + baseline;
|
||||
}
|
||||
}
|
||||
byte[] bars = GetBarsInter25(bCode);
|
||||
bool print = true;
|
||||
if (barColor != null)
|
||||
cb.SetColorFill(barColor);
|
||||
for (int k = 0; k < bars.Length; ++k) {
|
||||
float w = (bars[k] == 0 ? x : x * n);
|
||||
if (print)
|
||||
cb.Rectangle(barStartX, barStartY, w - inkSpreading, barHeight);
|
||||
print = !print;
|
||||
barStartX += w;
|
||||
}
|
||||
cb.Fill();
|
||||
if (font != null) {
|
||||
if (textColor != null)
|
||||
cb.SetColorFill(textColor);
|
||||
cb.BeginText();
|
||||
cb.SetFontAndSize(font, size);
|
||||
cb.SetTextMatrix(textStartX, textStartY);
|
||||
cb.ShowText(fullCode);
|
||||
cb.EndText();
|
||||
}
|
||||
return this.BarcodeSize;
|
||||
}
|
||||
|
||||
public override System.Drawing.Image CreateDrawingImage(System.Drawing.Color foreground, System.Drawing.Color background) {
|
||||
String bCode = KeepNumbers(code);
|
||||
if (generateChecksum)
|
||||
bCode += GetChecksum(bCode);
|
||||
int len = bCode.Length;
|
||||
int nn = (int)n;
|
||||
int fullWidth = len * (3 + 2 * nn) + (6 + nn );
|
||||
byte[] bars = GetBarsInter25(bCode);
|
||||
int height = (int)barHeight;
|
||||
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(fullWidth, height);
|
||||
for (int h = 0; h < height; ++h) {
|
||||
bool print = true;
|
||||
int ptr = 0;
|
||||
for (int k = 0; k < bars.Length; ++k) {
|
||||
int w = (bars[k] == 0 ? 1 : nn);
|
||||
System.Drawing.Color c = background;
|
||||
if (print)
|
||||
c = foreground;
|
||||
print = !print;
|
||||
for (int j = 0; j < w; ++j)
|
||||
bmp.SetPixel(ptr++, h, c);
|
||||
}
|
||||
}
|
||||
return bmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
1551
iTechSharp/iTextSharp/text/pdf/BarcodePDF417.cs
Normal file
1551
iTechSharp/iTextSharp/text/pdf/BarcodePDF417.cs
Normal file
File diff suppressed because it is too large
Load Diff
219
iTechSharp/iTextSharp/text/pdf/BarcodePostnet.cs
Normal file
219
iTechSharp/iTextSharp/text/pdf/BarcodePostnet.cs
Normal file
@@ -0,0 +1,219 @@
|
||||
using System;
|
||||
using iTextSharp.text;
|
||||
|
||||
/*
|
||||
* Copyright 2002 by Paulo Soares.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
namespace iTextSharp.text.pdf {
|
||||
|
||||
/** Implements the Postnet and Planet barcodes. The default parameters are:
|
||||
* <pre>
|
||||
*n = 72f / 22f; // distance between bars
|
||||
*x = 0.02f * 72f; // bar width
|
||||
*barHeight = 0.125f * 72f; // height of the tall bars
|
||||
*size = 0.05f * 72f; // height of the short bars
|
||||
*codeType = POSTNET; // type of code
|
||||
* </pre>
|
||||
*
|
||||
* @author Paulo Soares (psoares@consiste.pt)
|
||||
*/
|
||||
public class BarcodePostnet : Barcode{
|
||||
|
||||
/** The bars for each character.
|
||||
*/
|
||||
private static readonly byte[][] BARS = {
|
||||
new byte[] {1,1,0,0,0},
|
||||
new byte[] {0,0,0,1,1},
|
||||
new byte[] {0,0,1,0,1},
|
||||
new byte[] {0,0,1,1,0},
|
||||
new byte[] {0,1,0,0,1},
|
||||
new byte[] {0,1,0,1,0},
|
||||
new byte[] {0,1,1,0,0},
|
||||
new byte[] {1,0,0,0,1},
|
||||
new byte[] {1,0,0,1,0},
|
||||
new byte[] {1,0,1,0,0}
|
||||
};
|
||||
|
||||
/** Creates new BarcodePostnet */
|
||||
public BarcodePostnet() {
|
||||
n = 72f / 22f; // distance between bars
|
||||
x = 0.02f * 72f; // bar width
|
||||
barHeight = 0.125f * 72f; // height of the tall bars
|
||||
size = 0.05f * 72f; // height of the short bars
|
||||
codeType = POSTNET; // type of code
|
||||
}
|
||||
|
||||
/** Creates the bars for Postnet.
|
||||
* @param text the code to be created without checksum
|
||||
* @return the bars
|
||||
*/
|
||||
public static byte[] GetBarsPostnet(string text) {
|
||||
int total = 0;
|
||||
for (int k = text.Length - 1; k >= 0; --k) {
|
||||
int n = text[k] - '0';
|
||||
total += n;
|
||||
}
|
||||
text += (char)(((10 - (total % 10)) % 10) + '0');
|
||||
byte[] bars = new byte[text.Length * 5 + 2];
|
||||
bars[0] = 1;
|
||||
bars[bars.Length - 1] = 1;
|
||||
for (int k = 0; k < text.Length; ++k) {
|
||||
int c = text[k] - '0';
|
||||
Array.Copy(BARS[c], 0, bars, k * 5 + 1, 5);
|
||||
}
|
||||
return bars;
|
||||
}
|
||||
|
||||
/** Gets the maximum area that the barcode and the text, if
|
||||
* any, will occupy. The lower left corner is always (0, 0).
|
||||
* @return the size the barcode occupies.
|
||||
*/
|
||||
public override Rectangle BarcodeSize {
|
||||
get {
|
||||
float width = ((code.Length + 1) * 5 + 1) * n + x;
|
||||
return new Rectangle(width, barHeight);
|
||||
}
|
||||
}
|
||||
|
||||
/** Places the barcode in a <CODE>PdfContentByte</CODE>. The
|
||||
* barcode is always placed at coodinates (0, 0). Use the
|
||||
* translation matrix to move it elsewhere.<p>
|
||||
* The bars and text are written in the following colors:<p>
|
||||
* <P><TABLE BORDER=1>
|
||||
* <TR>
|
||||
* <TH><P><CODE>barColor</CODE></TH>
|
||||
* <TH><P><CODE>textColor</CODE></TH>
|
||||
* <TH><P>Result</TH>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD><P><CODE>null</CODE></TD>
|
||||
* <TD><P><CODE>null</CODE></TD>
|
||||
* <TD><P>bars and text painted with current fill color</TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD><P><CODE>barColor</CODE></TD>
|
||||
* <TD><P><CODE>null</CODE></TD>
|
||||
* <TD><P>bars and text painted with <CODE>barColor</CODE></TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD><P><CODE>null</CODE></TD>
|
||||
* <TD><P><CODE>textColor</CODE></TD>
|
||||
* <TD><P>bars painted with current color<br>text painted with <CODE>textColor</CODE></TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD><P><CODE>barColor</CODE></TD>
|
||||
* <TD><P><CODE>textColor</CODE></TD>
|
||||
* <TD><P>bars painted with <CODE>barColor</CODE><br>text painted with <CODE>textColor</CODE></TD>
|
||||
* </TR>
|
||||
* </TABLE>
|
||||
* @param cb the <CODE>PdfContentByte</CODE> where the barcode will be placed
|
||||
* @param barColor the color of the bars. It can be <CODE>null</CODE>
|
||||
* @param textColor the color of the text. It can be <CODE>null</CODE>
|
||||
* @return the dimensions the barcode occupies
|
||||
*/
|
||||
public override Rectangle PlaceBarcode(PdfContentByte cb, Color barColor, Color textColor) {
|
||||
if (barColor != null)
|
||||
cb.SetColorFill(barColor);
|
||||
byte[] bars = GetBarsPostnet(code);
|
||||
byte flip = 1;
|
||||
if (codeType == PLANET) {
|
||||
flip = 0;
|
||||
bars[0] = 0;
|
||||
bars[bars.Length - 1] = 0;
|
||||
}
|
||||
float startX = 0;
|
||||
for (int k = 0; k < bars.Length; ++k) {
|
||||
cb.Rectangle(startX, 0, x - inkSpreading, bars[k] == flip ? barHeight : size);
|
||||
startX += n;
|
||||
}
|
||||
cb.Fill();
|
||||
return this.BarcodeSize;
|
||||
}
|
||||
|
||||
public override System.Drawing.Image CreateDrawingImage(System.Drawing.Color foreground, System.Drawing.Color background) {
|
||||
int barWidth = (int)x;
|
||||
if (barWidth <= 0)
|
||||
barWidth = 1;
|
||||
int barDistance = (int)n;
|
||||
if (barDistance <= barWidth)
|
||||
barDistance = barWidth + 1;
|
||||
int barShort = (int)size;
|
||||
if (barShort <= 0)
|
||||
barShort = 1;
|
||||
int barTall = (int)barHeight;
|
||||
if (barTall <= barShort)
|
||||
barTall = barShort + 1;
|
||||
byte[] bars = GetBarsPostnet(code);
|
||||
int width = bars.Length * barDistance;
|
||||
byte flip = 1;
|
||||
if (codeType == PLANET) {
|
||||
flip = 0;
|
||||
bars[0] = 0;
|
||||
bars[bars.Length - 1] = 0;
|
||||
}
|
||||
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(width, barTall);
|
||||
int seg1 = barTall - barShort;
|
||||
for (int i = 0; i < seg1; ++i) {
|
||||
int idx = 0;
|
||||
for (int k = 0; k < bars.Length; ++k) {
|
||||
bool dot = (bars[k] == flip);
|
||||
for (int j = 0; j < barDistance; ++j) {
|
||||
bmp.SetPixel(idx++, i, (dot && j < barWidth) ? foreground : background);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = seg1; i < barTall; ++i) {
|
||||
int idx = 0;
|
||||
for (int k = 0; k < bars.Length; ++k) {
|
||||
for (int j = 0; j < barDistance; ++j) {
|
||||
bmp.SetPixel(idx++, i, (j < barWidth) ? foreground : background);
|
||||
}
|
||||
}
|
||||
}
|
||||
return bmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
630
iTechSharp/iTextSharp/text/pdf/BaseField.cs
Normal file
630
iTechSharp/iTextSharp/text/pdf/BaseField.cs
Normal file
@@ -0,0 +1,630 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Text;
|
||||
/*
|
||||
* Copyright 2005 by Paulo Soares.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.pdf
|
||||
{
|
||||
public abstract class BaseField {
|
||||
|
||||
/** A thin border with 1 point width. */
|
||||
public const float BORDER_WIDTH_THIN = 1;
|
||||
/** A medium border with 2 point width. */
|
||||
public const float BORDER_WIDTH_MEDIUM = 2;
|
||||
/** A thick border with 3 point width. */
|
||||
public const float BORDER_WIDTH_THICK = 3;
|
||||
/** The field is visible. */
|
||||
public const int VISIBLE = 0;
|
||||
/** The field is hidden. */
|
||||
public const int HIDDEN = 1;
|
||||
/** The field is visible but does not print. */
|
||||
public const int VISIBLE_BUT_DOES_NOT_PRINT = 2;
|
||||
/** The field is hidden but is printable. */
|
||||
public const int HIDDEN_BUT_PRINTABLE = 3;
|
||||
/** The user may not change the value of the field. */
|
||||
public const int READ_ONLY = PdfFormField.FF_READ_ONLY;
|
||||
/** The field must have a value at the time it is exported by a submit-form
|
||||
* action.
|
||||
*/
|
||||
public const int REQUIRED = PdfFormField.FF_REQUIRED;
|
||||
/** The field may contain multiple lines of text.
|
||||
* This flag is only meaningful with text fields.
|
||||
*/
|
||||
public const int MULTILINE = PdfFormField.FF_MULTILINE;
|
||||
/** The field will not scroll (horizontally for single-line
|
||||
* fields, vertically for multiple-line fields) to accommodate more text
|
||||
* than will fit within its annotation rectangle. Once the field is full, no
|
||||
* further text will be accepted.
|
||||
*/
|
||||
public const int DO_NOT_SCROLL = PdfFormField.FF_DONOTSCROLL;
|
||||
/** The field is intended for entering a secure password that should
|
||||
* not be echoed visibly to the screen.
|
||||
*/
|
||||
public const int PASSWORD = PdfFormField.FF_PASSWORD;
|
||||
/** The text entered in the field represents the pathname of
|
||||
* a file whose contents are to be submitted as the value of the field.
|
||||
*/
|
||||
public const int FILE_SELECTION = PdfFormField.FF_FILESELECT;
|
||||
/** The text entered in the field will not be spell-checked.
|
||||
* This flag is meaningful only in text fields and in combo
|
||||
* fields with the <CODE>EDIT</CODE> flag set.
|
||||
*/
|
||||
public const int DO_NOT_SPELL_CHECK = PdfFormField.FF_DONOTSPELLCHECK;
|
||||
/** If set the combo box includes an editable text box as well as a drop list; if
|
||||
* clear, it includes only a drop list.
|
||||
* This flag is only meaningful with combo fields.
|
||||
*/
|
||||
public const int EDIT = PdfFormField.FF_EDIT;
|
||||
|
||||
/**
|
||||
* combo box flag.
|
||||
*/
|
||||
public const int COMB = PdfFormField.FF_COMB;
|
||||
|
||||
protected float borderWidth = BORDER_WIDTH_THIN;
|
||||
protected int borderStyle = PdfBorderDictionary.STYLE_SOLID;
|
||||
protected Color borderColor;
|
||||
protected Color backgroundColor;
|
||||
protected Color textColor;
|
||||
protected BaseFont font;
|
||||
protected float fontSize = 0;
|
||||
protected int alignment = Element.ALIGN_LEFT;
|
||||
protected PdfWriter writer;
|
||||
protected String text;
|
||||
protected Rectangle box;
|
||||
|
||||
/** Holds value of property rotation. */
|
||||
protected int rotation = 0;
|
||||
|
||||
/** Holds value of property visibility. */
|
||||
protected int visibility;
|
||||
|
||||
/** Holds value of property fieldName. */
|
||||
protected String fieldName;
|
||||
|
||||
/** Holds value of property options. */
|
||||
protected int options;
|
||||
|
||||
/** Holds value of property maxCharacterLength. */
|
||||
protected int maxCharacterLength;
|
||||
|
||||
private static Hashtable fieldKeys = new Hashtable();
|
||||
|
||||
static BaseField() {
|
||||
foreach (DictionaryEntry entry in PdfCopyFieldsImp.fieldKeys)
|
||||
fieldKeys[entry.Key] = entry.Value;
|
||||
fieldKeys[PdfName.T] = 1;
|
||||
}
|
||||
/** Creates a new <CODE>TextField</CODE>.
|
||||
* @param writer the document <CODE>PdfWriter</CODE>
|
||||
* @param box the field location and dimensions
|
||||
* @param fieldName the field name. If <CODE>null</CODE> only the widget keys
|
||||
* will be included in the field allowing it to be used as a kid field.
|
||||
*/
|
||||
public BaseField(PdfWriter writer, Rectangle box, String fieldName) {
|
||||
this.writer = writer;
|
||||
Box = box;
|
||||
this.fieldName = fieldName;
|
||||
}
|
||||
|
||||
protected BaseFont RealFont {
|
||||
get {
|
||||
if (font == null)
|
||||
return BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.WINANSI, false);
|
||||
else
|
||||
return font;
|
||||
}
|
||||
}
|
||||
|
||||
protected PdfAppearance GetBorderAppearance() {
|
||||
PdfAppearance app = PdfAppearance.CreateAppearance(writer, box.Width, box.Height);
|
||||
switch (rotation) {
|
||||
case 90:
|
||||
app.SetMatrix(0, 1, -1, 0, box.Height, 0);
|
||||
break;
|
||||
case 180:
|
||||
app.SetMatrix(-1, 0, 0, -1, box.Width, box.Height);
|
||||
break;
|
||||
case 270:
|
||||
app.SetMatrix(0, -1, 1, 0, 0, box.Width);
|
||||
break;
|
||||
}
|
||||
app.SaveState();
|
||||
// background
|
||||
if (backgroundColor != null) {
|
||||
app.SetColorFill(backgroundColor);
|
||||
app.Rectangle(0, 0, box.Width, box.Height);
|
||||
app.Fill();
|
||||
}
|
||||
// border
|
||||
if (borderStyle == PdfBorderDictionary.STYLE_UNDERLINE) {
|
||||
if (borderWidth != 0 && borderColor != null) {
|
||||
app.SetColorStroke(borderColor);
|
||||
app.SetLineWidth(borderWidth);
|
||||
app.MoveTo(0, borderWidth / 2);
|
||||
app.LineTo(box.Width, borderWidth / 2);
|
||||
app.Stroke();
|
||||
}
|
||||
}
|
||||
else if (borderStyle == PdfBorderDictionary.STYLE_BEVELED) {
|
||||
if (borderWidth != 0 && borderColor != null) {
|
||||
app.SetColorStroke(borderColor);
|
||||
app.SetLineWidth(borderWidth);
|
||||
app.Rectangle(borderWidth / 2, borderWidth / 2, box.Width - borderWidth, box.Height - borderWidth);
|
||||
app.Stroke();
|
||||
}
|
||||
// beveled
|
||||
Color actual = backgroundColor;
|
||||
if (actual == null)
|
||||
actual = Color.WHITE;
|
||||
app.SetGrayFill(1);
|
||||
DrawTopFrame(app);
|
||||
app.SetColorFill(actual.Darker());
|
||||
DrawBottomFrame(app);
|
||||
}
|
||||
else if (borderStyle == PdfBorderDictionary.STYLE_INSET) {
|
||||
if (borderWidth != 0 && borderColor != null) {
|
||||
app.SetColorStroke(borderColor);
|
||||
app.SetLineWidth(borderWidth);
|
||||
app.Rectangle(borderWidth / 2, borderWidth / 2, box.Width - borderWidth, box.Height - borderWidth);
|
||||
app.Stroke();
|
||||
}
|
||||
// inset
|
||||
app.SetGrayFill(0.5f);
|
||||
DrawTopFrame(app);
|
||||
app.SetGrayFill(0.75f);
|
||||
DrawBottomFrame(app);
|
||||
}
|
||||
else {
|
||||
if (borderWidth != 0 && borderColor != null) {
|
||||
if (borderStyle == PdfBorderDictionary.STYLE_DASHED)
|
||||
app.SetLineDash(3, 0);
|
||||
app.SetColorStroke(borderColor);
|
||||
app.SetLineWidth(borderWidth);
|
||||
app.Rectangle(borderWidth / 2, borderWidth / 2, box.Width - borderWidth, box.Height - borderWidth);
|
||||
app.Stroke();
|
||||
if ((options & COMB) != 0 && maxCharacterLength > 1) {
|
||||
float step = box.Width / maxCharacterLength;
|
||||
float yb = borderWidth / 2;
|
||||
float yt = box.Height - borderWidth / 2;
|
||||
for (int k = 1; k < maxCharacterLength; ++k) {
|
||||
float x = step * k;
|
||||
app.MoveTo(x, yb);
|
||||
app.LineTo(x, yt);
|
||||
}
|
||||
app.Stroke();
|
||||
}
|
||||
}
|
||||
}
|
||||
app.RestoreState();
|
||||
return app;
|
||||
}
|
||||
|
||||
protected static ArrayList GetHardBreaks(String text) {
|
||||
ArrayList arr = new ArrayList();
|
||||
char[] cs = text.ToCharArray();
|
||||
int len = cs.Length;
|
||||
StringBuilder buf = new StringBuilder();
|
||||
for (int k = 0; k < len; ++k) {
|
||||
char c = cs[k];
|
||||
if (c == '\r') {
|
||||
if (k + 1 < len && cs[k + 1] == '\n')
|
||||
++k;
|
||||
arr.Add(buf.ToString());
|
||||
buf = new StringBuilder();
|
||||
}
|
||||
else if (c == '\n') {
|
||||
arr.Add(buf.ToString());
|
||||
buf = new StringBuilder();
|
||||
}
|
||||
else
|
||||
buf.Append(c);
|
||||
}
|
||||
arr.Add(buf.ToString());
|
||||
return arr;
|
||||
}
|
||||
|
||||
protected static void TrimRight(StringBuilder buf) {
|
||||
int len = buf.Length;
|
||||
while (true) {
|
||||
if (len == 0)
|
||||
return;
|
||||
if (buf[--len] != ' ')
|
||||
return;
|
||||
buf.Length = len;
|
||||
}
|
||||
}
|
||||
|
||||
protected static ArrayList BreakLines(ArrayList breaks, BaseFont font, float fontSize, float width) {
|
||||
ArrayList lines = new ArrayList();
|
||||
StringBuilder buf = new StringBuilder();
|
||||
for (int ck = 0; ck < breaks.Count; ++ck) {
|
||||
buf.Length = 0;
|
||||
float w = 0;
|
||||
char[] cs = ((String)breaks[ck]).ToCharArray();
|
||||
int len = cs.Length;
|
||||
// 0 inline first, 1 inline, 2 spaces
|
||||
int state = 0;
|
||||
int lastspace = -1;
|
||||
char c = (char)0;
|
||||
int refk = 0;
|
||||
for (int k = 0; k < len; ++k) {
|
||||
c = cs[k];
|
||||
switch (state) {
|
||||
case 0:
|
||||
w += font.GetWidthPoint(c, fontSize);
|
||||
buf.Append(c);
|
||||
if (w > width) {
|
||||
w = 0;
|
||||
if (buf.Length > 1) {
|
||||
--k;
|
||||
buf.Length = buf.Length - 1;
|
||||
}
|
||||
lines.Add(buf.ToString());
|
||||
buf.Length = 0;
|
||||
refk = k;
|
||||
if (c == ' ')
|
||||
state = 2;
|
||||
else
|
||||
state = 1;
|
||||
}
|
||||
else {
|
||||
if (c != ' ')
|
||||
state = 1;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
w += font.GetWidthPoint(c, fontSize);
|
||||
buf.Append(c);
|
||||
if (c == ' ')
|
||||
lastspace = k;
|
||||
if (w > width) {
|
||||
w = 0;
|
||||
if (lastspace >= 0) {
|
||||
k = lastspace;
|
||||
buf.Length = lastspace - refk;
|
||||
TrimRight(buf);
|
||||
lines.Add(buf.ToString());
|
||||
buf.Length = 0;
|
||||
refk = k;
|
||||
lastspace = -1;
|
||||
state = 2;
|
||||
}
|
||||
else {
|
||||
if (buf.Length > 1) {
|
||||
--k;
|
||||
buf.Length = buf.Length - 1;
|
||||
}
|
||||
lines.Add(buf.ToString());
|
||||
buf.Length = 0;
|
||||
refk = k;
|
||||
if (c == ' ')
|
||||
state = 2;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (c != ' ') {
|
||||
w = 0;
|
||||
--k;
|
||||
state = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
TrimRight(buf);
|
||||
lines.Add(buf.ToString());
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
private void DrawTopFrame(PdfAppearance app) {
|
||||
app.MoveTo(borderWidth, borderWidth);
|
||||
app.LineTo(borderWidth, box.Height - borderWidth);
|
||||
app.LineTo(box.Width - borderWidth, box.Height - borderWidth);
|
||||
app.LineTo(box.Width - 2 * borderWidth, box.Height - 2 * borderWidth);
|
||||
app.LineTo(2 * borderWidth, box.Height - 2 * borderWidth);
|
||||
app.LineTo(2 * borderWidth, 2 * borderWidth);
|
||||
app.LineTo(borderWidth, borderWidth);
|
||||
app.Fill();
|
||||
}
|
||||
|
||||
private void DrawBottomFrame(PdfAppearance app) {
|
||||
app.MoveTo(borderWidth, borderWidth);
|
||||
app.LineTo(box.Width - borderWidth, borderWidth);
|
||||
app.LineTo(box.Width - borderWidth, box.Height - borderWidth);
|
||||
app.LineTo(box.Width - 2 * borderWidth, box.Height - 2 * borderWidth);
|
||||
app.LineTo(box.Width - 2 * borderWidth, 2 * borderWidth);
|
||||
app.LineTo(2 * borderWidth, 2 * borderWidth);
|
||||
app.LineTo(borderWidth, borderWidth);
|
||||
app.Fill();
|
||||
}
|
||||
|
||||
/** Sets the border width in points. To eliminate the border
|
||||
* set the border color to <CODE>null</CODE>.
|
||||
* @param borderWidth the border width in points
|
||||
*/
|
||||
public float BorderWidth {
|
||||
set {
|
||||
this.borderWidth = value;
|
||||
}
|
||||
get {
|
||||
return borderWidth;
|
||||
}
|
||||
}
|
||||
|
||||
/** Sets the border style. The styles are found in <CODE>PdfBorderDictionary</CODE>
|
||||
* and can be <CODE>STYLE_SOLID</CODE>, <CODE>STYLE_DASHED</CODE>,
|
||||
* <CODE>STYLE_BEVELED</CODE>, <CODE>STYLE_INSET</CODE> and
|
||||
* <CODE>STYLE_UNDERLINE</CODE>.
|
||||
* @param borderStyle the border style
|
||||
*/
|
||||
public int BorderStyle {
|
||||
set {
|
||||
this.borderStyle = value;
|
||||
}
|
||||
get {
|
||||
return borderStyle;
|
||||
}
|
||||
}
|
||||
|
||||
/** Sets the border color. Set to <CODE>null</CODE> to remove
|
||||
* the border.
|
||||
* @param borderColor the border color
|
||||
*/
|
||||
public Color BorderColor {
|
||||
set {
|
||||
this.borderColor = value;
|
||||
}
|
||||
get {
|
||||
return borderColor;
|
||||
}
|
||||
}
|
||||
|
||||
/** Sets the background color. Set to <CODE>null</CODE> for
|
||||
* transparent background.
|
||||
* @param backgroundColor the background color
|
||||
*/
|
||||
public Color BackgroundColor {
|
||||
set {
|
||||
this.backgroundColor = value;
|
||||
}
|
||||
get {
|
||||
return backgroundColor;
|
||||
}
|
||||
}
|
||||
|
||||
/** Sets the text color. If <CODE>null</CODE> the color used
|
||||
* will be black.
|
||||
* @param textColor the text color
|
||||
*/
|
||||
public Color TextColor {
|
||||
set {
|
||||
this.textColor = value;
|
||||
}
|
||||
get {
|
||||
return textColor;
|
||||
}
|
||||
}
|
||||
|
||||
/** Sets the text font. If <CODE>null</CODE> then Helvetica
|
||||
* will be used.
|
||||
* @param font the text font
|
||||
*/
|
||||
public BaseFont Font {
|
||||
set {
|
||||
this.font = value;
|
||||
}
|
||||
get {
|
||||
return font;
|
||||
}
|
||||
}
|
||||
|
||||
/** Sets the font size. If 0 then auto-sizing will be used but
|
||||
* only for text fields.
|
||||
* @param fontSize the font size
|
||||
*/
|
||||
public float FontSize {
|
||||
set {
|
||||
this.fontSize = value;
|
||||
}
|
||||
get {
|
||||
return fontSize;
|
||||
}
|
||||
}
|
||||
|
||||
/** Sets the text horizontal alignment. It can be <CODE>Element.ALIGN_LEFT</CODE>,
|
||||
* <CODE>Element.ALIGN_CENTER</CODE> and <CODE>Element.ALIGN_RIGHT</CODE>.
|
||||
* @param alignment the text horizontal alignment
|
||||
*/
|
||||
public int Alignment {
|
||||
set {
|
||||
this.alignment = value;
|
||||
}
|
||||
get {
|
||||
return alignment;
|
||||
}
|
||||
}
|
||||
|
||||
/** Sets the text for text fields.
|
||||
* @param text the text
|
||||
*/
|
||||
public string Text {
|
||||
set {
|
||||
this.text = value;
|
||||
}
|
||||
get {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
/** Sets the field dimension and position.
|
||||
* @param box the field dimension and position
|
||||
*/
|
||||
public Rectangle Box {
|
||||
set {
|
||||
if (value == null)
|
||||
box = null;
|
||||
else {
|
||||
box = new Rectangle(value);
|
||||
box.Normalize();
|
||||
}
|
||||
}
|
||||
get {
|
||||
return box;
|
||||
}
|
||||
}
|
||||
|
||||
/** Sets the field rotation. This value should be the same as
|
||||
* the page rotation where the field will be shown.
|
||||
* @param rotation the field rotation
|
||||
*/
|
||||
public int Rotation {
|
||||
set {
|
||||
if (value % 90 != 0)
|
||||
throw new ArgumentException("Rotation must be a multiple of 90.");
|
||||
rotation = (value % 360);
|
||||
if (rotation < 0)
|
||||
rotation += 360;
|
||||
}
|
||||
get {
|
||||
return rotation;
|
||||
}
|
||||
}
|
||||
|
||||
/** Convenience method to set the field rotation the same as the
|
||||
* page rotation.
|
||||
* @param page the page
|
||||
*/
|
||||
public void SetRotationFromPage(Rectangle page) {
|
||||
Rotation = page.Rotation;
|
||||
}
|
||||
|
||||
/** Sets the field visibility flag. This flags can be one of
|
||||
* <CODE>VISIBLE</CODE>, <CODE>HIDDEN</CODE>, <CODE>VISIBLE_BUT_DOES_NOT_PRINT</CODE>
|
||||
* and <CODE>HIDDEN_BUT_PRINTABLE</CODE>.
|
||||
* @param visibility field visibility flag
|
||||
*/
|
||||
public int Visibility {
|
||||
set {
|
||||
this.visibility = value;
|
||||
}
|
||||
get {
|
||||
return visibility;
|
||||
}
|
||||
}
|
||||
|
||||
/** Sets the field name.
|
||||
* @param fieldName the field name. If <CODE>null</CODE> only the widget keys
|
||||
* will be included in the field allowing it to be used as a kid field.
|
||||
*/
|
||||
public string FieldName {
|
||||
set {
|
||||
this.fieldName = value;
|
||||
}
|
||||
get {
|
||||
return fieldName;
|
||||
}
|
||||
}
|
||||
|
||||
/** Sets the option flags. The option flags can be a combination by oring of
|
||||
* <CODE>READ_ONLY</CODE>, <CODE>REQUIRED</CODE>,
|
||||
* <CODE>MULTILINE</CODE>, <CODE>DO_NOT_SCROLL</CODE>,
|
||||
* <CODE>PASSWORD</CODE>, <CODE>FILE_SELECTION</CODE>,
|
||||
* <CODE>DO_NOT_SPELL_CHECK</CODE> and <CODE>EDIT</CODE>.
|
||||
* @param options the option flags
|
||||
*/
|
||||
public int Options {
|
||||
set {
|
||||
this.options = value;
|
||||
}
|
||||
get {
|
||||
return options;
|
||||
}
|
||||
}
|
||||
|
||||
/** Sets the maximum length of the field<6C>s text, in characters.
|
||||
* It is only meaningful for text fields.
|
||||
* @param maxCharacterLength the maximum length of the field<6C>s text, in characters
|
||||
*/
|
||||
public int MaxCharacterLength {
|
||||
set {
|
||||
this.maxCharacterLength = value;
|
||||
}
|
||||
get {
|
||||
return maxCharacterLength;
|
||||
}
|
||||
}
|
||||
|
||||
public PdfWriter Writer {
|
||||
get {
|
||||
return writer;
|
||||
}
|
||||
set {
|
||||
writer = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the field keys from <CODE>from</CODE> to <CODE>to</CODE>. The moved keys
|
||||
* are removed from <CODE>from</CODE>.
|
||||
* @param from the source
|
||||
* @param to the destination. It may be <CODE>null</CODE>
|
||||
*/
|
||||
public static void MoveFields(PdfDictionary from, PdfDictionary to) {
|
||||
PdfName[] keys = new PdfName[from.Size];
|
||||
foreach (PdfName key in keys) {
|
||||
if (fieldKeys.ContainsKey(key)) {
|
||||
if (to != null)
|
||||
to.Put(key, from.Get(key));
|
||||
from.Remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1433
iTechSharp/iTextSharp/text/pdf/BaseFont.cs
Normal file
1433
iTechSharp/iTextSharp/text/pdf/BaseFont.cs
Normal file
File diff suppressed because it is too large
Load Diff
946
iTechSharp/iTextSharp/text/pdf/BidiLine.cs
Normal file
946
iTechSharp/iTextSharp/text/pdf/BidiLine.cs
Normal file
@@ -0,0 +1,946 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Text;
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright 2002 Paulo Soares
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.pdf {
|
||||
|
||||
/** Does all the line bidirectional processing with PdfChunk assembly.
|
||||
*
|
||||
* @author Paulo Soares (psoares@consiste.pt)
|
||||
*/
|
||||
public class BidiLine {
|
||||
private const int pieceSizeStart = 256;
|
||||
|
||||
protected int runDirection;
|
||||
protected int pieceSize = pieceSizeStart;
|
||||
protected char[] text = new char[pieceSizeStart];
|
||||
protected PdfChunk[] detailChunks = new PdfChunk[pieceSizeStart];
|
||||
protected int totalTextLength = 0;
|
||||
|
||||
protected byte[] orderLevels = new byte[pieceSizeStart];
|
||||
protected int[] indexChars = new int[pieceSizeStart];
|
||||
|
||||
protected ArrayList chunks = new ArrayList();
|
||||
protected int indexChunk = 0;
|
||||
protected int indexChunkChar = 0;
|
||||
protected int currentChar = 0;
|
||||
|
||||
protected int storedRunDirection;
|
||||
protected char[] storedText = new char[0];
|
||||
protected PdfChunk[] storedDetailChunks = new PdfChunk[0];
|
||||
protected int storedTotalTextLength = 0;
|
||||
|
||||
protected byte[] storedOrderLevels = new byte[0];
|
||||
protected int[] storedIndexChars = new int[0];
|
||||
|
||||
protected int storedIndexChunk = 0;
|
||||
protected int storedIndexChunkChar = 0;
|
||||
protected int storedCurrentChar = 0;
|
||||
|
||||
protected bool shortStore;
|
||||
protected static IntHashtable mirrorChars = new IntHashtable();
|
||||
protected int arabicOptions;
|
||||
|
||||
/** Creates new BidiLine */
|
||||
public BidiLine() {
|
||||
}
|
||||
|
||||
public BidiLine(BidiLine org) {
|
||||
runDirection = org.runDirection;
|
||||
pieceSize = org.pieceSize;
|
||||
text = (char[])org.text.Clone();
|
||||
detailChunks = (PdfChunk[])org.detailChunks.Clone();
|
||||
totalTextLength = org.totalTextLength;
|
||||
|
||||
orderLevels = (byte[])org.orderLevels.Clone();
|
||||
indexChars = (int[])org.indexChars.Clone();
|
||||
|
||||
chunks = new ArrayList(org.chunks);
|
||||
indexChunk = org.indexChunk;
|
||||
indexChunkChar = org.indexChunkChar;
|
||||
currentChar = org.currentChar;
|
||||
|
||||
storedRunDirection = org.storedRunDirection;
|
||||
storedText = (char[])org.storedText.Clone();
|
||||
storedDetailChunks = (PdfChunk[])org.storedDetailChunks.Clone();
|
||||
storedTotalTextLength = org.storedTotalTextLength;
|
||||
|
||||
storedOrderLevels = (byte[])org.storedOrderLevels.Clone();
|
||||
storedIndexChars = (int[])org.storedIndexChars.Clone();
|
||||
|
||||
storedIndexChunk = org.storedIndexChunk;
|
||||
storedIndexChunkChar = org.storedIndexChunkChar;
|
||||
storedCurrentChar = org.storedCurrentChar;
|
||||
|
||||
shortStore = org.shortStore;
|
||||
arabicOptions = org.arabicOptions;
|
||||
}
|
||||
|
||||
public bool IsEmpty() {
|
||||
return (currentChar >= totalTextLength && indexChunk >= chunks.Count);
|
||||
}
|
||||
|
||||
public void ClearChunks() {
|
||||
chunks.Clear();
|
||||
totalTextLength = 0;
|
||||
currentChar = 0;
|
||||
}
|
||||
|
||||
public bool GetParagraph(int runDirection) {
|
||||
this.runDirection = runDirection;
|
||||
currentChar = 0;
|
||||
totalTextLength = 0;
|
||||
bool hasText = false;
|
||||
char c;
|
||||
char uniC;
|
||||
BaseFont bf;
|
||||
for (; indexChunk < chunks.Count; ++indexChunk) {
|
||||
PdfChunk ck = (PdfChunk)chunks[indexChunk];
|
||||
bf = ck.Font.Font;
|
||||
string s = ck.ToString();
|
||||
int len = s.Length;
|
||||
for (; indexChunkChar < len; ++indexChunkChar) {
|
||||
c = s[indexChunkChar];
|
||||
uniC = (char)bf.GetUnicodeEquivalent(c);
|
||||
if (uniC == '\r' || uniC == '\n') {
|
||||
// next condition is never true for CID
|
||||
if (uniC == '\r' && indexChunkChar + 1 < len && s[indexChunkChar + 1] == '\n')
|
||||
++indexChunkChar;
|
||||
++indexChunkChar;
|
||||
if (indexChunkChar >= len) {
|
||||
indexChunkChar = 0;
|
||||
++indexChunk;
|
||||
}
|
||||
hasText = true;
|
||||
if (totalTextLength == 0)
|
||||
detailChunks[0] = ck;
|
||||
break;
|
||||
}
|
||||
AddPiece(c, ck);
|
||||
}
|
||||
if (hasText)
|
||||
break;
|
||||
indexChunkChar = 0;
|
||||
}
|
||||
if (totalTextLength == 0)
|
||||
return hasText;
|
||||
|
||||
// remove trailing WS
|
||||
totalTextLength = TrimRight(0, totalTextLength - 1) + 1;
|
||||
if (totalTextLength == 0)
|
||||
return true;
|
||||
|
||||
if (runDirection == PdfWriter.RUN_DIRECTION_LTR || runDirection == PdfWriter.RUN_DIRECTION_RTL) {
|
||||
if (orderLevels.Length < totalTextLength) {
|
||||
orderLevels = new byte[pieceSize];
|
||||
indexChars = new int[pieceSize];
|
||||
}
|
||||
|
||||
ArabicLigaturizer.ProcessNumbers(text, 0, totalTextLength, arabicOptions);
|
||||
BidiOrder order = new BidiOrder(text, 0, totalTextLength, (sbyte)(runDirection == PdfWriter.RUN_DIRECTION_RTL ? 1 : 0));
|
||||
byte[] od = order.GetLevels();
|
||||
for (int k = 0; k < totalTextLength; ++k) {
|
||||
orderLevels[k] = od[k];
|
||||
indexChars[k] = k;
|
||||
}
|
||||
DoArabicShapping();
|
||||
MirrorGlyphs();
|
||||
}
|
||||
totalTextLength = TrimRightEx(0, totalTextLength - 1) + 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void AddChunk(PdfChunk chunk) {
|
||||
chunks.Add(chunk);
|
||||
}
|
||||
|
||||
public void AddChunks(ArrayList chunks) {
|
||||
this.chunks.AddRange(chunks);
|
||||
}
|
||||
|
||||
public void AddPiece(char c, PdfChunk chunk) {
|
||||
if (totalTextLength >= pieceSize) {
|
||||
char[] tempText = text;
|
||||
PdfChunk[] tempDetailChunks = detailChunks;
|
||||
pieceSize *= 2;
|
||||
text = new char[pieceSize];
|
||||
detailChunks = new PdfChunk[pieceSize];
|
||||
Array.Copy(tempText, 0, text, 0, totalTextLength);
|
||||
Array.Copy(tempDetailChunks, 0, detailChunks, 0, totalTextLength);
|
||||
}
|
||||
text[totalTextLength] = c;
|
||||
detailChunks[totalTextLength++] = chunk;
|
||||
}
|
||||
|
||||
public void Save() {
|
||||
if (indexChunk > 0) {
|
||||
if (indexChunk >= chunks.Count)
|
||||
chunks.Clear();
|
||||
else {
|
||||
for (--indexChunk; indexChunk >= 0; --indexChunk)
|
||||
chunks.RemoveAt(indexChunk);
|
||||
}
|
||||
indexChunk = 0;
|
||||
}
|
||||
storedRunDirection = runDirection;
|
||||
storedTotalTextLength = totalTextLength;
|
||||
storedIndexChunk = indexChunk;
|
||||
storedIndexChunkChar = indexChunkChar;
|
||||
storedCurrentChar = currentChar;
|
||||
shortStore = (currentChar < totalTextLength);
|
||||
if (!shortStore) {
|
||||
// long save
|
||||
if (storedText.Length < totalTextLength) {
|
||||
storedText = new char[totalTextLength];
|
||||
storedDetailChunks = new PdfChunk[totalTextLength];
|
||||
}
|
||||
Array.Copy(text, 0, storedText, 0, totalTextLength);
|
||||
Array.Copy(detailChunks, 0, storedDetailChunks, 0, totalTextLength);
|
||||
}
|
||||
if (runDirection == PdfWriter.RUN_DIRECTION_LTR || runDirection == PdfWriter.RUN_DIRECTION_RTL) {
|
||||
if (storedOrderLevels.Length < totalTextLength) {
|
||||
storedOrderLevels = new byte[totalTextLength];
|
||||
storedIndexChars = new int[totalTextLength];
|
||||
}
|
||||
Array.Copy(orderLevels, currentChar, storedOrderLevels, currentChar, totalTextLength - currentChar);
|
||||
Array.Copy(indexChars, currentChar, storedIndexChars, currentChar, totalTextLength - currentChar);
|
||||
}
|
||||
}
|
||||
|
||||
public void Restore() {
|
||||
runDirection = storedRunDirection;
|
||||
totalTextLength = storedTotalTextLength;
|
||||
indexChunk = storedIndexChunk;
|
||||
indexChunkChar = storedIndexChunkChar;
|
||||
currentChar = storedCurrentChar;
|
||||
if (!shortStore) {
|
||||
// long restore
|
||||
Array.Copy(storedText, 0, text, 0, totalTextLength);
|
||||
Array.Copy(storedDetailChunks, 0, detailChunks, 0, totalTextLength);
|
||||
}
|
||||
if (runDirection == PdfWriter.RUN_DIRECTION_LTR || runDirection == PdfWriter.RUN_DIRECTION_RTL) {
|
||||
Array.Copy(storedOrderLevels, currentChar, orderLevels, currentChar, totalTextLength - currentChar);
|
||||
Array.Copy(storedIndexChars, currentChar, indexChars, currentChar, totalTextLength - currentChar);
|
||||
}
|
||||
}
|
||||
|
||||
public void MirrorGlyphs() {
|
||||
for (int k = 0; k < totalTextLength; ++k) {
|
||||
if ((orderLevels[k] & 1) == 1) {
|
||||
int mirror = mirrorChars[text[k]];
|
||||
if (mirror != 0)
|
||||
text[k] = (char)mirror;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void DoArabicShapping() {
|
||||
int src = 0;
|
||||
int dest = 0;
|
||||
for (;;) {
|
||||
while (src < totalTextLength) {
|
||||
char c = text[src];
|
||||
if (c >= 0x0600 && c <= 0x06ff)
|
||||
break;
|
||||
if (src != dest) {
|
||||
text[dest] = text[src];
|
||||
detailChunks[dest] = detailChunks[src];
|
||||
orderLevels[dest] = orderLevels[src];
|
||||
}
|
||||
++src;
|
||||
++dest;
|
||||
}
|
||||
if (src >= totalTextLength) {
|
||||
totalTextLength = dest;
|
||||
return;
|
||||
}
|
||||
int startArabicIdx = src;
|
||||
++src;
|
||||
while (src < totalTextLength) {
|
||||
char c = text[src];
|
||||
if (c < 0x0600 || c > 0x06ff)
|
||||
break;
|
||||
++src;
|
||||
}
|
||||
int arabicWordSize = src - startArabicIdx;
|
||||
int size = ArabicLigaturizer.Arabic_shape(text, startArabicIdx, arabicWordSize, text, dest, arabicWordSize, arabicOptions);
|
||||
if (startArabicIdx != dest) {
|
||||
for (int k = 0; k < size; ++k) {
|
||||
detailChunks[dest] = detailChunks[startArabicIdx];
|
||||
orderLevels[dest++] = orderLevels[startArabicIdx++];
|
||||
}
|
||||
}
|
||||
else
|
||||
dest += size;
|
||||
}
|
||||
}
|
||||
|
||||
public PdfLine ProcessLine(float leftX, float width, int alignment, int runDirection, int arabicOptions) {
|
||||
this.arabicOptions = arabicOptions;
|
||||
Save();
|
||||
bool isRTL = (runDirection == PdfWriter.RUN_DIRECTION_RTL);
|
||||
if (currentChar >= totalTextLength) {
|
||||
bool hasText = GetParagraph(runDirection);
|
||||
if (!hasText)
|
||||
return null;
|
||||
if (totalTextLength == 0) {
|
||||
ArrayList ar = new ArrayList();
|
||||
PdfChunk ckx = new PdfChunk("", detailChunks[0]);
|
||||
ar.Add(ckx);
|
||||
return new PdfLine(0, 0, 0, alignment, true, ar, isRTL);
|
||||
}
|
||||
}
|
||||
float originalWidth = width;
|
||||
int lastSplit = -1;
|
||||
if (currentChar != 0)
|
||||
currentChar = TrimLeftEx(currentChar, totalTextLength - 1);
|
||||
int oldCurrentChar = currentChar;
|
||||
int uniC = 0;
|
||||
PdfChunk ck = null;
|
||||
float charWidth = 0;
|
||||
PdfChunk lastValidChunk = null;
|
||||
bool splitChar = false;
|
||||
bool surrogate = false;
|
||||
for (; currentChar < totalTextLength; ++currentChar) {
|
||||
ck = detailChunks[currentChar];
|
||||
surrogate = Utilities.IsSurrogatePair(text, currentChar);
|
||||
if (surrogate)
|
||||
uniC = ck.GetUnicodeEquivalent(Utilities.ConvertToUtf32(text, currentChar));
|
||||
else
|
||||
uniC = ck.GetUnicodeEquivalent(text[currentChar]);
|
||||
if (PdfChunk.NoPrint(uniC))
|
||||
continue;
|
||||
if (surrogate)
|
||||
charWidth = ck.GetCharWidth(uniC);
|
||||
else
|
||||
charWidth = ck.GetCharWidth(text[currentChar]);
|
||||
splitChar = ck.IsExtSplitCharacter(oldCurrentChar, currentChar, totalTextLength, text, detailChunks);
|
||||
if (splitChar && Char.IsWhiteSpace((char)uniC))
|
||||
lastSplit = currentChar;
|
||||
if (width - charWidth < 0)
|
||||
break;
|
||||
if (splitChar)
|
||||
lastSplit = currentChar;
|
||||
width -= charWidth;
|
||||
lastValidChunk = ck;
|
||||
if (surrogate)
|
||||
++currentChar;
|
||||
if (ck.IsTab()) {
|
||||
Object[] tab = (Object[])ck.GetAttribute(Chunk.TAB);
|
||||
float tabPosition = (float)tab[1];
|
||||
bool newLine = (bool)tab[2];
|
||||
if (newLine && tabPosition < originalWidth - width) {
|
||||
return new PdfLine(0, originalWidth, width, alignment, true, CreateArrayOfPdfChunks(oldCurrentChar, currentChar - 1), isRTL);
|
||||
}
|
||||
detailChunks[currentChar].AdjustLeft(leftX);
|
||||
width = originalWidth - tabPosition;
|
||||
}
|
||||
}
|
||||
if (lastValidChunk == null) {
|
||||
// not even a single char fit; must output the first char
|
||||
++currentChar;
|
||||
if (surrogate)
|
||||
++currentChar;
|
||||
return new PdfLine(0, originalWidth, 0, alignment, false, CreateArrayOfPdfChunks(currentChar - 1, currentChar - 1), isRTL);
|
||||
}
|
||||
if (currentChar >= totalTextLength) {
|
||||
// there was more line than text
|
||||
return new PdfLine(0, originalWidth, width, alignment, true, CreateArrayOfPdfChunks(oldCurrentChar, totalTextLength - 1), isRTL);
|
||||
}
|
||||
int newCurrentChar = TrimRightEx(oldCurrentChar, currentChar - 1);
|
||||
if (newCurrentChar < oldCurrentChar) {
|
||||
// only WS
|
||||
return new PdfLine(0, originalWidth, width, alignment, false, CreateArrayOfPdfChunks(oldCurrentChar, currentChar - 1), isRTL);
|
||||
}
|
||||
if (newCurrentChar == currentChar - 1) { // middle of word
|
||||
IHyphenationEvent he = (IHyphenationEvent)lastValidChunk.GetAttribute(Chunk.HYPHENATION);
|
||||
if (he != null) {
|
||||
int[] word = GetWord(oldCurrentChar, newCurrentChar);
|
||||
if (word != null) {
|
||||
float testWidth = width + GetWidth(word[0], currentChar - 1);
|
||||
String pre = he.GetHyphenatedWordPre(new String(text, word[0], word[1] - word[0]), lastValidChunk.Font.Font, lastValidChunk.Font.Size, testWidth);
|
||||
String post = he.HyphenatedWordPost;
|
||||
if (pre.Length > 0) {
|
||||
PdfChunk extra = new PdfChunk(pre, lastValidChunk);
|
||||
currentChar = word[1] - post.Length;
|
||||
return new PdfLine(0, originalWidth, testWidth - lastValidChunk.Font.Width(pre), alignment, false, CreateArrayOfPdfChunks(oldCurrentChar, word[0] - 1, extra), isRTL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (lastSplit == -1 || lastSplit >= newCurrentChar) {
|
||||
// no split point or split point ahead of end
|
||||
return new PdfLine(0, originalWidth, width + GetWidth(newCurrentChar + 1, currentChar - 1), alignment, false, CreateArrayOfPdfChunks(oldCurrentChar, newCurrentChar), isRTL);
|
||||
}
|
||||
// standard split
|
||||
currentChar = lastSplit + 1;
|
||||
newCurrentChar = TrimRightEx(oldCurrentChar, lastSplit);
|
||||
if (newCurrentChar < oldCurrentChar) {
|
||||
// only WS again
|
||||
newCurrentChar = currentChar - 1;
|
||||
}
|
||||
return new PdfLine(0, originalWidth, originalWidth - GetWidth(oldCurrentChar, newCurrentChar), alignment, false, CreateArrayOfPdfChunks(oldCurrentChar, newCurrentChar), isRTL);
|
||||
}
|
||||
|
||||
/** Gets the width of a range of characters.
|
||||
* @param startIdx the first index to calculate
|
||||
* @param lastIdx the last inclusive index to calculate
|
||||
* @return the sum of all widths
|
||||
*/
|
||||
public float GetWidth(int startIdx, int lastIdx) {
|
||||
char c = (char)0;
|
||||
PdfChunk ck = null;
|
||||
float width = 0;
|
||||
for (; startIdx <= lastIdx; ++startIdx) {
|
||||
bool surrogate = Utilities.IsSurrogatePair(text, startIdx);
|
||||
if (surrogate) {
|
||||
width += detailChunks[startIdx].GetCharWidth(Utilities.ConvertToUtf32(text, startIdx));
|
||||
++startIdx;
|
||||
}
|
||||
else {
|
||||
c = text[startIdx];
|
||||
ck = detailChunks[startIdx];
|
||||
if (PdfChunk.NoPrint(ck.GetUnicodeEquivalent(c)))
|
||||
continue;
|
||||
width += detailChunks[startIdx].GetCharWidth(c);
|
||||
}
|
||||
}
|
||||
return width;
|
||||
}
|
||||
|
||||
public ArrayList CreateArrayOfPdfChunks(int startIdx, int endIdx) {
|
||||
return CreateArrayOfPdfChunks(startIdx, endIdx, null);
|
||||
}
|
||||
|
||||
public ArrayList CreateArrayOfPdfChunks(int startIdx, int endIdx, PdfChunk extraPdfChunk) {
|
||||
bool bidi = (runDirection == PdfWriter.RUN_DIRECTION_LTR || runDirection == PdfWriter.RUN_DIRECTION_RTL);
|
||||
if (bidi)
|
||||
Reorder(startIdx, endIdx);
|
||||
ArrayList ar = new ArrayList();
|
||||
PdfChunk refCk = detailChunks[startIdx];
|
||||
PdfChunk ck = null;
|
||||
StringBuilder buf = new StringBuilder();
|
||||
char c;
|
||||
int idx = 0;
|
||||
for (; startIdx <= endIdx; ++startIdx) {
|
||||
idx = bidi ? indexChars[startIdx] : startIdx;
|
||||
c = text[idx];
|
||||
ck = detailChunks[idx];
|
||||
if (PdfChunk.NoPrint(ck.GetUnicodeEquivalent(c)))
|
||||
continue;
|
||||
if (ck.IsImage() || ck.IsSeparator() || ck.IsTab()) {
|
||||
if (buf.Length > 0) {
|
||||
ar.Add(new PdfChunk(buf.ToString(), refCk));
|
||||
buf = new StringBuilder();
|
||||
}
|
||||
ar.Add(ck);
|
||||
}
|
||||
else if (ck == refCk) {
|
||||
buf.Append(c);
|
||||
}
|
||||
else {
|
||||
if (buf.Length > 0) {
|
||||
ar.Add(new PdfChunk(buf.ToString(), refCk));
|
||||
buf = new StringBuilder();
|
||||
}
|
||||
if (!ck.IsImage() && !ck.IsSeparator() && !ck.IsTab())
|
||||
buf.Append(c);
|
||||
refCk = ck;
|
||||
}
|
||||
}
|
||||
if (buf.Length > 0) {
|
||||
ar.Add(new PdfChunk(buf.ToString(), refCk));
|
||||
}
|
||||
if (extraPdfChunk != null)
|
||||
ar.Add(extraPdfChunk);
|
||||
return ar;
|
||||
}
|
||||
|
||||
public int[] GetWord(int startIdx, int idx) {
|
||||
int last = idx;
|
||||
int first = idx;
|
||||
// forward
|
||||
for (; last < totalTextLength; ++last) {
|
||||
if (!char.IsLetter(text[last]))
|
||||
break;
|
||||
}
|
||||
if (last == idx)
|
||||
return null;
|
||||
// backward
|
||||
for (; first >= startIdx; --first) {
|
||||
if (!char.IsLetter(text[first]))
|
||||
break;
|
||||
}
|
||||
++first;
|
||||
return new int[]{first, last};
|
||||
}
|
||||
|
||||
public int TrimRight(int startIdx, int endIdx) {
|
||||
int idx = endIdx;
|
||||
char c;
|
||||
for (; idx >= startIdx; --idx) {
|
||||
c = (char)detailChunks[idx].GetUnicodeEquivalent(text[idx]);
|
||||
if (!IsWS(c))
|
||||
break;
|
||||
}
|
||||
return idx;
|
||||
}
|
||||
|
||||
public int TrimLeft(int startIdx, int endIdx) {
|
||||
int idx = startIdx;
|
||||
char c;
|
||||
for (; idx <= endIdx; ++idx) {
|
||||
c = (char)detailChunks[idx].GetUnicodeEquivalent(text[idx]);
|
||||
if (!IsWS(c))
|
||||
break;
|
||||
}
|
||||
return idx;
|
||||
}
|
||||
|
||||
public int TrimRightEx(int startIdx, int endIdx) {
|
||||
int idx = endIdx;
|
||||
char c = (char)0;
|
||||
for (; idx >= startIdx; --idx) {
|
||||
c = (char)detailChunks[idx].GetUnicodeEquivalent(text[idx]);
|
||||
if (!IsWS(c) && !PdfChunk.NoPrint(c))
|
||||
break;
|
||||
}
|
||||
return idx;
|
||||
}
|
||||
|
||||
public int TrimLeftEx(int startIdx, int endIdx) {
|
||||
int idx = startIdx;
|
||||
char c = (char)0;
|
||||
for (; idx <= endIdx; ++idx) {
|
||||
c = (char)detailChunks[idx].GetUnicodeEquivalent(text[idx]);
|
||||
if (!IsWS(c) && !PdfChunk.NoPrint(c))
|
||||
break;
|
||||
}
|
||||
return idx;
|
||||
}
|
||||
|
||||
public void Reorder(int start, int end) {
|
||||
byte maxLevel = orderLevels[start];
|
||||
byte minLevel = maxLevel;
|
||||
byte onlyOddLevels = maxLevel;
|
||||
byte onlyEvenLevels = maxLevel;
|
||||
for (int k = start + 1; k <= end; ++k) {
|
||||
byte b = orderLevels[k];
|
||||
if (b > maxLevel)
|
||||
maxLevel = b;
|
||||
else if (b < minLevel)
|
||||
minLevel = b;
|
||||
onlyOddLevels &= b;
|
||||
onlyEvenLevels |= b;
|
||||
}
|
||||
if ((onlyEvenLevels & 1) == 0) // nothing to do
|
||||
return;
|
||||
if ((onlyOddLevels & 1) == 1) { // single inversion
|
||||
Flip(start, end + 1);
|
||||
return;
|
||||
}
|
||||
minLevel |= 1;
|
||||
for (; maxLevel >= minLevel; --maxLevel) {
|
||||
int pstart = start;
|
||||
for (;;) {
|
||||
for (;pstart <= end; ++pstart) {
|
||||
if (orderLevels[pstart] >= maxLevel)
|
||||
break;
|
||||
}
|
||||
if (pstart > end)
|
||||
break;
|
||||
int pend = pstart + 1;
|
||||
for (; pend <= end; ++pend) {
|
||||
if (orderLevels[pend] < maxLevel)
|
||||
break;
|
||||
}
|
||||
Flip(pstart, pend);
|
||||
pstart = pend + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Flip(int start, int end) {
|
||||
int mid = (start + end) / 2;
|
||||
--end;
|
||||
for (; start < mid; ++start, --end) {
|
||||
int temp = indexChars[start];
|
||||
indexChars[start] = indexChars[end];
|
||||
indexChars[end] = temp;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsWS(char c) {
|
||||
return (c <= ' ');
|
||||
}
|
||||
|
||||
static BidiLine() {
|
||||
mirrorChars[0x0028] = 0x0029; // LEFT PARENTHESIS
|
||||
mirrorChars[0x0029] = 0x0028; // RIGHT PARENTHESIS
|
||||
mirrorChars[0x003C] = 0x003E; // LESS-THAN SIGN
|
||||
mirrorChars[0x003E] = 0x003C; // GREATER-THAN SIGN
|
||||
mirrorChars[0x005B] = 0x005D; // LEFT SQUARE BRACKET
|
||||
mirrorChars[0x005D] = 0x005B; // RIGHT SQUARE BRACKET
|
||||
mirrorChars[0x007B] = 0x007D; // LEFT CURLY BRACKET
|
||||
mirrorChars[0x007D] = 0x007B; // RIGHT CURLY BRACKET
|
||||
mirrorChars[0x00AB] = 0x00BB; // LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
|
||||
mirrorChars[0x00BB] = 0x00AB; // RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
|
||||
mirrorChars[0x2039] = 0x203A; // SINGLE LEFT-POINTING ANGLE QUOTATION MARK
|
||||
mirrorChars[0x203A] = 0x2039; // SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
|
||||
mirrorChars[0x2045] = 0x2046; // LEFT SQUARE BRACKET WITH QUILL
|
||||
mirrorChars[0x2046] = 0x2045; // RIGHT SQUARE BRACKET WITH QUILL
|
||||
mirrorChars[0x207D] = 0x207E; // SUPERSCRIPT LEFT PARENTHESIS
|
||||
mirrorChars[0x207E] = 0x207D; // SUPERSCRIPT RIGHT PARENTHESIS
|
||||
mirrorChars[0x208D] = 0x208E; // SUBSCRIPT LEFT PARENTHESIS
|
||||
mirrorChars[0x208E] = 0x208D; // SUBSCRIPT RIGHT PARENTHESIS
|
||||
mirrorChars[0x2208] = 0x220B; // ELEMENT OF
|
||||
mirrorChars[0x2209] = 0x220C; // NOT AN ELEMENT OF
|
||||
mirrorChars[0x220A] = 0x220D; // SMALL ELEMENT OF
|
||||
mirrorChars[0x220B] = 0x2208; // CONTAINS AS MEMBER
|
||||
mirrorChars[0x220C] = 0x2209; // DOES NOT CONTAIN AS MEMBER
|
||||
mirrorChars[0x220D] = 0x220A; // SMALL CONTAINS AS MEMBER
|
||||
mirrorChars[0x2215] = 0x29F5; // DIVISION SLASH
|
||||
mirrorChars[0x223C] = 0x223D; // TILDE OPERATOR
|
||||
mirrorChars[0x223D] = 0x223C; // REVERSED TILDE
|
||||
mirrorChars[0x2243] = 0x22CD; // ASYMPTOTICALLY EQUAL TO
|
||||
mirrorChars[0x2252] = 0x2253; // APPROXIMATELY EQUAL TO OR THE IMAGE OF
|
||||
mirrorChars[0x2253] = 0x2252; // IMAGE OF OR APPROXIMATELY EQUAL TO
|
||||
mirrorChars[0x2254] = 0x2255; // COLON EQUALS
|
||||
mirrorChars[0x2255] = 0x2254; // EQUALS COLON
|
||||
mirrorChars[0x2264] = 0x2265; // LESS-THAN OR EQUAL TO
|
||||
mirrorChars[0x2265] = 0x2264; // GREATER-THAN OR EQUAL TO
|
||||
mirrorChars[0x2266] = 0x2267; // LESS-THAN OVER EQUAL TO
|
||||
mirrorChars[0x2267] = 0x2266; // GREATER-THAN OVER EQUAL TO
|
||||
mirrorChars[0x2268] = 0x2269; // [BEST FIT] LESS-THAN BUT NOT EQUAL TO
|
||||
mirrorChars[0x2269] = 0x2268; // [BEST FIT] GREATER-THAN BUT NOT EQUAL TO
|
||||
mirrorChars[0x226A] = 0x226B; // MUCH LESS-THAN
|
||||
mirrorChars[0x226B] = 0x226A; // MUCH GREATER-THAN
|
||||
mirrorChars[0x226E] = 0x226F; // [BEST FIT] NOT LESS-THAN
|
||||
mirrorChars[0x226F] = 0x226E; // [BEST FIT] NOT GREATER-THAN
|
||||
mirrorChars[0x2270] = 0x2271; // [BEST FIT] NEITHER LESS-THAN NOR EQUAL TO
|
||||
mirrorChars[0x2271] = 0x2270; // [BEST FIT] NEITHER GREATER-THAN NOR EQUAL TO
|
||||
mirrorChars[0x2272] = 0x2273; // [BEST FIT] LESS-THAN OR EQUIVALENT TO
|
||||
mirrorChars[0x2273] = 0x2272; // [BEST FIT] GREATER-THAN OR EQUIVALENT TO
|
||||
mirrorChars[0x2274] = 0x2275; // [BEST FIT] NEITHER LESS-THAN NOR EQUIVALENT TO
|
||||
mirrorChars[0x2275] = 0x2274; // [BEST FIT] NEITHER GREATER-THAN NOR EQUIVALENT TO
|
||||
mirrorChars[0x2276] = 0x2277; // LESS-THAN OR GREATER-THAN
|
||||
mirrorChars[0x2277] = 0x2276; // GREATER-THAN OR LESS-THAN
|
||||
mirrorChars[0x2278] = 0x2279; // NEITHER LESS-THAN NOR GREATER-THAN
|
||||
mirrorChars[0x2279] = 0x2278; // NEITHER GREATER-THAN NOR LESS-THAN
|
||||
mirrorChars[0x227A] = 0x227B; // PRECEDES
|
||||
mirrorChars[0x227B] = 0x227A; // SUCCEEDS
|
||||
mirrorChars[0x227C] = 0x227D; // PRECEDES OR EQUAL TO
|
||||
mirrorChars[0x227D] = 0x227C; // SUCCEEDS OR EQUAL TO
|
||||
mirrorChars[0x227E] = 0x227F; // [BEST FIT] PRECEDES OR EQUIVALENT TO
|
||||
mirrorChars[0x227F] = 0x227E; // [BEST FIT] SUCCEEDS OR EQUIVALENT TO
|
||||
mirrorChars[0x2280] = 0x2281; // [BEST FIT] DOES NOT PRECEDE
|
||||
mirrorChars[0x2281] = 0x2280; // [BEST FIT] DOES NOT SUCCEED
|
||||
mirrorChars[0x2282] = 0x2283; // SUBSET OF
|
||||
mirrorChars[0x2283] = 0x2282; // SUPERSET OF
|
||||
mirrorChars[0x2284] = 0x2285; // [BEST FIT] NOT A SUBSET OF
|
||||
mirrorChars[0x2285] = 0x2284; // [BEST FIT] NOT A SUPERSET OF
|
||||
mirrorChars[0x2286] = 0x2287; // SUBSET OF OR EQUAL TO
|
||||
mirrorChars[0x2287] = 0x2286; // SUPERSET OF OR EQUAL TO
|
||||
mirrorChars[0x2288] = 0x2289; // [BEST FIT] NEITHER A SUBSET OF NOR EQUAL TO
|
||||
mirrorChars[0x2289] = 0x2288; // [BEST FIT] NEITHER A SUPERSET OF NOR EQUAL TO
|
||||
mirrorChars[0x228A] = 0x228B; // [BEST FIT] SUBSET OF WITH NOT EQUAL TO
|
||||
mirrorChars[0x228B] = 0x228A; // [BEST FIT] SUPERSET OF WITH NOT EQUAL TO
|
||||
mirrorChars[0x228F] = 0x2290; // SQUARE IMAGE OF
|
||||
mirrorChars[0x2290] = 0x228F; // SQUARE ORIGINAL OF
|
||||
mirrorChars[0x2291] = 0x2292; // SQUARE IMAGE OF OR EQUAL TO
|
||||
mirrorChars[0x2292] = 0x2291; // SQUARE ORIGINAL OF OR EQUAL TO
|
||||
mirrorChars[0x2298] = 0x29B8; // CIRCLED DIVISION SLASH
|
||||
mirrorChars[0x22A2] = 0x22A3; // RIGHT TACK
|
||||
mirrorChars[0x22A3] = 0x22A2; // LEFT TACK
|
||||
mirrorChars[0x22A6] = 0x2ADE; // ASSERTION
|
||||
mirrorChars[0x22A8] = 0x2AE4; // TRUE
|
||||
mirrorChars[0x22A9] = 0x2AE3; // FORCES
|
||||
mirrorChars[0x22AB] = 0x2AE5; // DOUBLE VERTICAL BAR DOUBLE RIGHT TURNSTILE
|
||||
mirrorChars[0x22B0] = 0x22B1; // PRECEDES UNDER RELATION
|
||||
mirrorChars[0x22B1] = 0x22B0; // SUCCEEDS UNDER RELATION
|
||||
mirrorChars[0x22B2] = 0x22B3; // NORMAL SUBGROUP OF
|
||||
mirrorChars[0x22B3] = 0x22B2; // CONTAINS AS NORMAL SUBGROUP
|
||||
mirrorChars[0x22B4] = 0x22B5; // NORMAL SUBGROUP OF OR EQUAL TO
|
||||
mirrorChars[0x22B5] = 0x22B4; // CONTAINS AS NORMAL SUBGROUP OR EQUAL TO
|
||||
mirrorChars[0x22B6] = 0x22B7; // ORIGINAL OF
|
||||
mirrorChars[0x22B7] = 0x22B6; // IMAGE OF
|
||||
mirrorChars[0x22C9] = 0x22CA; // LEFT NORMAL FACTOR SEMIDIRECT PRODUCT
|
||||
mirrorChars[0x22CA] = 0x22C9; // RIGHT NORMAL FACTOR SEMIDIRECT PRODUCT
|
||||
mirrorChars[0x22CB] = 0x22CC; // LEFT SEMIDIRECT PRODUCT
|
||||
mirrorChars[0x22CC] = 0x22CB; // RIGHT SEMIDIRECT PRODUCT
|
||||
mirrorChars[0x22CD] = 0x2243; // REVERSED TILDE EQUALS
|
||||
mirrorChars[0x22D0] = 0x22D1; // DOUBLE SUBSET
|
||||
mirrorChars[0x22D1] = 0x22D0; // DOUBLE SUPERSET
|
||||
mirrorChars[0x22D6] = 0x22D7; // LESS-THAN WITH DOT
|
||||
mirrorChars[0x22D7] = 0x22D6; // GREATER-THAN WITH DOT
|
||||
mirrorChars[0x22D8] = 0x22D9; // VERY MUCH LESS-THAN
|
||||
mirrorChars[0x22D9] = 0x22D8; // VERY MUCH GREATER-THAN
|
||||
mirrorChars[0x22DA] = 0x22DB; // LESS-THAN EQUAL TO OR GREATER-THAN
|
||||
mirrorChars[0x22DB] = 0x22DA; // GREATER-THAN EQUAL TO OR LESS-THAN
|
||||
mirrorChars[0x22DC] = 0x22DD; // EQUAL TO OR LESS-THAN
|
||||
mirrorChars[0x22DD] = 0x22DC; // EQUAL TO OR GREATER-THAN
|
||||
mirrorChars[0x22DE] = 0x22DF; // EQUAL TO OR PRECEDES
|
||||
mirrorChars[0x22DF] = 0x22DE; // EQUAL TO OR SUCCEEDS
|
||||
mirrorChars[0x22E0] = 0x22E1; // [BEST FIT] DOES NOT PRECEDE OR EQUAL
|
||||
mirrorChars[0x22E1] = 0x22E0; // [BEST FIT] DOES NOT SUCCEED OR EQUAL
|
||||
mirrorChars[0x22E2] = 0x22E3; // [BEST FIT] NOT SQUARE IMAGE OF OR EQUAL TO
|
||||
mirrorChars[0x22E3] = 0x22E2; // [BEST FIT] NOT SQUARE ORIGINAL OF OR EQUAL TO
|
||||
mirrorChars[0x22E4] = 0x22E5; // [BEST FIT] SQUARE IMAGE OF OR NOT EQUAL TO
|
||||
mirrorChars[0x22E5] = 0x22E4; // [BEST FIT] SQUARE ORIGINAL OF OR NOT EQUAL TO
|
||||
mirrorChars[0x22E6] = 0x22E7; // [BEST FIT] LESS-THAN BUT NOT EQUIVALENT TO
|
||||
mirrorChars[0x22E7] = 0x22E6; // [BEST FIT] GREATER-THAN BUT NOT EQUIVALENT TO
|
||||
mirrorChars[0x22E8] = 0x22E9; // [BEST FIT] PRECEDES BUT NOT EQUIVALENT TO
|
||||
mirrorChars[0x22E9] = 0x22E8; // [BEST FIT] SUCCEEDS BUT NOT EQUIVALENT TO
|
||||
mirrorChars[0x22EA] = 0x22EB; // [BEST FIT] NOT NORMAL SUBGROUP OF
|
||||
mirrorChars[0x22EB] = 0x22EA; // [BEST FIT] DOES NOT CONTAIN AS NORMAL SUBGROUP
|
||||
mirrorChars[0x22EC] = 0x22ED; // [BEST FIT] NOT NORMAL SUBGROUP OF OR EQUAL TO
|
||||
mirrorChars[0x22ED] = 0x22EC; // [BEST FIT] DOES NOT CONTAIN AS NORMAL SUBGROUP OR EQUAL
|
||||
mirrorChars[0x22F0] = 0x22F1; // UP RIGHT DIAGONAL ELLIPSIS
|
||||
mirrorChars[0x22F1] = 0x22F0; // DOWN RIGHT DIAGONAL ELLIPSIS
|
||||
mirrorChars[0x22F2] = 0x22FA; // ELEMENT OF WITH LONG HORIZONTAL STROKE
|
||||
mirrorChars[0x22F3] = 0x22FB; // ELEMENT OF WITH VERTICAL BAR AT END OF HORIZONTAL STROKE
|
||||
mirrorChars[0x22F4] = 0x22FC; // SMALL ELEMENT OF WITH VERTICAL BAR AT END OF HORIZONTAL STROKE
|
||||
mirrorChars[0x22F6] = 0x22FD; // ELEMENT OF WITH OVERBAR
|
||||
mirrorChars[0x22F7] = 0x22FE; // SMALL ELEMENT OF WITH OVERBAR
|
||||
mirrorChars[0x22FA] = 0x22F2; // CONTAINS WITH LONG HORIZONTAL STROKE
|
||||
mirrorChars[0x22FB] = 0x22F3; // CONTAINS WITH VERTICAL BAR AT END OF HORIZONTAL STROKE
|
||||
mirrorChars[0x22FC] = 0x22F4; // SMALL CONTAINS WITH VERTICAL BAR AT END OF HORIZONTAL STROKE
|
||||
mirrorChars[0x22FD] = 0x22F6; // CONTAINS WITH OVERBAR
|
||||
mirrorChars[0x22FE] = 0x22F7; // SMALL CONTAINS WITH OVERBAR
|
||||
mirrorChars[0x2308] = 0x2309; // LEFT CEILING
|
||||
mirrorChars[0x2309] = 0x2308; // RIGHT CEILING
|
||||
mirrorChars[0x230A] = 0x230B; // LEFT FLOOR
|
||||
mirrorChars[0x230B] = 0x230A; // RIGHT FLOOR
|
||||
mirrorChars[0x2329] = 0x232A; // LEFT-POINTING ANGLE BRACKET
|
||||
mirrorChars[0x232A] = 0x2329; // RIGHT-POINTING ANGLE BRACKET
|
||||
mirrorChars[0x2768] = 0x2769; // MEDIUM LEFT PARENTHESIS ORNAMENT
|
||||
mirrorChars[0x2769] = 0x2768; // MEDIUM RIGHT PARENTHESIS ORNAMENT
|
||||
mirrorChars[0x276A] = 0x276B; // MEDIUM FLATTENED LEFT PARENTHESIS ORNAMENT
|
||||
mirrorChars[0x276B] = 0x276A; // MEDIUM FLATTENED RIGHT PARENTHESIS ORNAMENT
|
||||
mirrorChars[0x276C] = 0x276D; // MEDIUM LEFT-POINTING ANGLE BRACKET ORNAMENT
|
||||
mirrorChars[0x276D] = 0x276C; // MEDIUM RIGHT-POINTING ANGLE BRACKET ORNAMENT
|
||||
mirrorChars[0x276E] = 0x276F; // HEAVY LEFT-POINTING ANGLE QUOTATION MARK ORNAMENT
|
||||
mirrorChars[0x276F] = 0x276E; // HEAVY RIGHT-POINTING ANGLE QUOTATION MARK ORNAMENT
|
||||
mirrorChars[0x2770] = 0x2771; // HEAVY LEFT-POINTING ANGLE BRACKET ORNAMENT
|
||||
mirrorChars[0x2771] = 0x2770; // HEAVY RIGHT-POINTING ANGLE BRACKET ORNAMENT
|
||||
mirrorChars[0x2772] = 0x2773; // LIGHT LEFT TORTOISE SHELL BRACKET
|
||||
mirrorChars[0x2773] = 0x2772; // LIGHT RIGHT TORTOISE SHELL BRACKET
|
||||
mirrorChars[0x2774] = 0x2775; // MEDIUM LEFT CURLY BRACKET ORNAMENT
|
||||
mirrorChars[0x2775] = 0x2774; // MEDIUM RIGHT CURLY BRACKET ORNAMENT
|
||||
mirrorChars[0x27D5] = 0x27D6; // LEFT OUTER JOIN
|
||||
mirrorChars[0x27D6] = 0x27D5; // RIGHT OUTER JOIN
|
||||
mirrorChars[0x27DD] = 0x27DE; // LONG RIGHT TACK
|
||||
mirrorChars[0x27DE] = 0x27DD; // LONG LEFT TACK
|
||||
mirrorChars[0x27E2] = 0x27E3; // WHITE CONCAVE-SIDED DIAMOND WITH LEFTWARDS TICK
|
||||
mirrorChars[0x27E3] = 0x27E2; // WHITE CONCAVE-SIDED DIAMOND WITH RIGHTWARDS TICK
|
||||
mirrorChars[0x27E4] = 0x27E5; // WHITE SQUARE WITH LEFTWARDS TICK
|
||||
mirrorChars[0x27E5] = 0x27E4; // WHITE SQUARE WITH RIGHTWARDS TICK
|
||||
mirrorChars[0x27E6] = 0x27E7; // MATHEMATICAL LEFT WHITE SQUARE BRACKET
|
||||
mirrorChars[0x27E7] = 0x27E6; // MATHEMATICAL RIGHT WHITE SQUARE BRACKET
|
||||
mirrorChars[0x27E8] = 0x27E9; // MATHEMATICAL LEFT ANGLE BRACKET
|
||||
mirrorChars[0x27E9] = 0x27E8; // MATHEMATICAL RIGHT ANGLE BRACKET
|
||||
mirrorChars[0x27EA] = 0x27EB; // MATHEMATICAL LEFT DOUBLE ANGLE BRACKET
|
||||
mirrorChars[0x27EB] = 0x27EA; // MATHEMATICAL RIGHT DOUBLE ANGLE BRACKET
|
||||
mirrorChars[0x2983] = 0x2984; // LEFT WHITE CURLY BRACKET
|
||||
mirrorChars[0x2984] = 0x2983; // RIGHT WHITE CURLY BRACKET
|
||||
mirrorChars[0x2985] = 0x2986; // LEFT WHITE PARENTHESIS
|
||||
mirrorChars[0x2986] = 0x2985; // RIGHT WHITE PARENTHESIS
|
||||
mirrorChars[0x2987] = 0x2988; // Z NOTATION LEFT IMAGE BRACKET
|
||||
mirrorChars[0x2988] = 0x2987; // Z NOTATION RIGHT IMAGE BRACKET
|
||||
mirrorChars[0x2989] = 0x298A; // Z NOTATION LEFT BINDING BRACKET
|
||||
mirrorChars[0x298A] = 0x2989; // Z NOTATION RIGHT BINDING BRACKET
|
||||
mirrorChars[0x298B] = 0x298C; // LEFT SQUARE BRACKET WITH UNDERBAR
|
||||
mirrorChars[0x298C] = 0x298B; // RIGHT SQUARE BRACKET WITH UNDERBAR
|
||||
mirrorChars[0x298D] = 0x2990; // LEFT SQUARE BRACKET WITH TICK IN TOP CORNER
|
||||
mirrorChars[0x298E] = 0x298F; // RIGHT SQUARE BRACKET WITH TICK IN BOTTOM CORNER
|
||||
mirrorChars[0x298F] = 0x298E; // LEFT SQUARE BRACKET WITH TICK IN BOTTOM CORNER
|
||||
mirrorChars[0x2990] = 0x298D; // RIGHT SQUARE BRACKET WITH TICK IN TOP CORNER
|
||||
mirrorChars[0x2991] = 0x2992; // LEFT ANGLE BRACKET WITH DOT
|
||||
mirrorChars[0x2992] = 0x2991; // RIGHT ANGLE BRACKET WITH DOT
|
||||
mirrorChars[0x2993] = 0x2994; // LEFT ARC LESS-THAN BRACKET
|
||||
mirrorChars[0x2994] = 0x2993; // RIGHT ARC GREATER-THAN BRACKET
|
||||
mirrorChars[0x2995] = 0x2996; // DOUBLE LEFT ARC GREATER-THAN BRACKET
|
||||
mirrorChars[0x2996] = 0x2995; // DOUBLE RIGHT ARC LESS-THAN BRACKET
|
||||
mirrorChars[0x2997] = 0x2998; // LEFT BLACK TORTOISE SHELL BRACKET
|
||||
mirrorChars[0x2998] = 0x2997; // RIGHT BLACK TORTOISE SHELL BRACKET
|
||||
mirrorChars[0x29B8] = 0x2298; // CIRCLED REVERSE SOLIDUS
|
||||
mirrorChars[0x29C0] = 0x29C1; // CIRCLED LESS-THAN
|
||||
mirrorChars[0x29C1] = 0x29C0; // CIRCLED GREATER-THAN
|
||||
mirrorChars[0x29C4] = 0x29C5; // SQUARED RISING DIAGONAL SLASH
|
||||
mirrorChars[0x29C5] = 0x29C4; // SQUARED FALLING DIAGONAL SLASH
|
||||
mirrorChars[0x29CF] = 0x29D0; // LEFT TRIANGLE BESIDE VERTICAL BAR
|
||||
mirrorChars[0x29D0] = 0x29CF; // VERTICAL BAR BESIDE RIGHT TRIANGLE
|
||||
mirrorChars[0x29D1] = 0x29D2; // BOWTIE WITH LEFT HALF BLACK
|
||||
mirrorChars[0x29D2] = 0x29D1; // BOWTIE WITH RIGHT HALF BLACK
|
||||
mirrorChars[0x29D4] = 0x29D5; // TIMES WITH LEFT HALF BLACK
|
||||
mirrorChars[0x29D5] = 0x29D4; // TIMES WITH RIGHT HALF BLACK
|
||||
mirrorChars[0x29D8] = 0x29D9; // LEFT WIGGLY FENCE
|
||||
mirrorChars[0x29D9] = 0x29D8; // RIGHT WIGGLY FENCE
|
||||
mirrorChars[0x29DA] = 0x29DB; // LEFT DOUBLE WIGGLY FENCE
|
||||
mirrorChars[0x29DB] = 0x29DA; // RIGHT DOUBLE WIGGLY FENCE
|
||||
mirrorChars[0x29F5] = 0x2215; // REVERSE SOLIDUS OPERATOR
|
||||
mirrorChars[0x29F8] = 0x29F9; // BIG SOLIDUS
|
||||
mirrorChars[0x29F9] = 0x29F8; // BIG REVERSE SOLIDUS
|
||||
mirrorChars[0x29FC] = 0x29FD; // LEFT-POINTING CURVED ANGLE BRACKET
|
||||
mirrorChars[0x29FD] = 0x29FC; // RIGHT-POINTING CURVED ANGLE BRACKET
|
||||
mirrorChars[0x2A2B] = 0x2A2C; // MINUS SIGN WITH FALLING DOTS
|
||||
mirrorChars[0x2A2C] = 0x2A2B; // MINUS SIGN WITH RISING DOTS
|
||||
mirrorChars[0x2A2D] = 0x2A2C; // PLUS SIGN IN LEFT HALF CIRCLE
|
||||
mirrorChars[0x2A2E] = 0x2A2D; // PLUS SIGN IN RIGHT HALF CIRCLE
|
||||
mirrorChars[0x2A34] = 0x2A35; // MULTIPLICATION SIGN IN LEFT HALF CIRCLE
|
||||
mirrorChars[0x2A35] = 0x2A34; // MULTIPLICATION SIGN IN RIGHT HALF CIRCLE
|
||||
mirrorChars[0x2A3C] = 0x2A3D; // INTERIOR PRODUCT
|
||||
mirrorChars[0x2A3D] = 0x2A3C; // RIGHTHAND INTERIOR PRODUCT
|
||||
mirrorChars[0x2A64] = 0x2A65; // Z NOTATION DOMAIN ANTIRESTRICTION
|
||||
mirrorChars[0x2A65] = 0x2A64; // Z NOTATION RANGE ANTIRESTRICTION
|
||||
mirrorChars[0x2A79] = 0x2A7A; // LESS-THAN WITH CIRCLE INSIDE
|
||||
mirrorChars[0x2A7A] = 0x2A79; // GREATER-THAN WITH CIRCLE INSIDE
|
||||
mirrorChars[0x2A7D] = 0x2A7E; // LESS-THAN OR SLANTED EQUAL TO
|
||||
mirrorChars[0x2A7E] = 0x2A7D; // GREATER-THAN OR SLANTED EQUAL TO
|
||||
mirrorChars[0x2A7F] = 0x2A80; // LESS-THAN OR SLANTED EQUAL TO WITH DOT INSIDE
|
||||
mirrorChars[0x2A80] = 0x2A7F; // GREATER-THAN OR SLANTED EQUAL TO WITH DOT INSIDE
|
||||
mirrorChars[0x2A81] = 0x2A82; // LESS-THAN OR SLANTED EQUAL TO WITH DOT ABOVE
|
||||
mirrorChars[0x2A82] = 0x2A81; // GREATER-THAN OR SLANTED EQUAL TO WITH DOT ABOVE
|
||||
mirrorChars[0x2A83] = 0x2A84; // LESS-THAN OR SLANTED EQUAL TO WITH DOT ABOVE RIGHT
|
||||
mirrorChars[0x2A84] = 0x2A83; // GREATER-THAN OR SLANTED EQUAL TO WITH DOT ABOVE LEFT
|
||||
mirrorChars[0x2A8B] = 0x2A8C; // LESS-THAN ABOVE DOUBLE-LINE EQUAL ABOVE GREATER-THAN
|
||||
mirrorChars[0x2A8C] = 0x2A8B; // GREATER-THAN ABOVE DOUBLE-LINE EQUAL ABOVE LESS-THAN
|
||||
mirrorChars[0x2A91] = 0x2A92; // LESS-THAN ABOVE GREATER-THAN ABOVE DOUBLE-LINE EQUAL
|
||||
mirrorChars[0x2A92] = 0x2A91; // GREATER-THAN ABOVE LESS-THAN ABOVE DOUBLE-LINE EQUAL
|
||||
mirrorChars[0x2A93] = 0x2A94; // LESS-THAN ABOVE SLANTED EQUAL ABOVE GREATER-THAN ABOVE SLANTED EQUAL
|
||||
mirrorChars[0x2A94] = 0x2A93; // GREATER-THAN ABOVE SLANTED EQUAL ABOVE LESS-THAN ABOVE SLANTED EQUAL
|
||||
mirrorChars[0x2A95] = 0x2A96; // SLANTED EQUAL TO OR LESS-THAN
|
||||
mirrorChars[0x2A96] = 0x2A95; // SLANTED EQUAL TO OR GREATER-THAN
|
||||
mirrorChars[0x2A97] = 0x2A98; // SLANTED EQUAL TO OR LESS-THAN WITH DOT INSIDE
|
||||
mirrorChars[0x2A98] = 0x2A97; // SLANTED EQUAL TO OR GREATER-THAN WITH DOT INSIDE
|
||||
mirrorChars[0x2A99] = 0x2A9A; // DOUBLE-LINE EQUAL TO OR LESS-THAN
|
||||
mirrorChars[0x2A9A] = 0x2A99; // DOUBLE-LINE EQUAL TO OR GREATER-THAN
|
||||
mirrorChars[0x2A9B] = 0x2A9C; // DOUBLE-LINE SLANTED EQUAL TO OR LESS-THAN
|
||||
mirrorChars[0x2A9C] = 0x2A9B; // DOUBLE-LINE SLANTED EQUAL TO OR GREATER-THAN
|
||||
mirrorChars[0x2AA1] = 0x2AA2; // DOUBLE NESTED LESS-THAN
|
||||
mirrorChars[0x2AA2] = 0x2AA1; // DOUBLE NESTED GREATER-THAN
|
||||
mirrorChars[0x2AA6] = 0x2AA7; // LESS-THAN CLOSED BY CURVE
|
||||
mirrorChars[0x2AA7] = 0x2AA6; // GREATER-THAN CLOSED BY CURVE
|
||||
mirrorChars[0x2AA8] = 0x2AA9; // LESS-THAN CLOSED BY CURVE ABOVE SLANTED EQUAL
|
||||
mirrorChars[0x2AA9] = 0x2AA8; // GREATER-THAN CLOSED BY CURVE ABOVE SLANTED EQUAL
|
||||
mirrorChars[0x2AAA] = 0x2AAB; // SMALLER THAN
|
||||
mirrorChars[0x2AAB] = 0x2AAA; // LARGER THAN
|
||||
mirrorChars[0x2AAC] = 0x2AAD; // SMALLER THAN OR EQUAL TO
|
||||
mirrorChars[0x2AAD] = 0x2AAC; // LARGER THAN OR EQUAL TO
|
||||
mirrorChars[0x2AAF] = 0x2AB0; // PRECEDES ABOVE SINGLE-LINE EQUALS SIGN
|
||||
mirrorChars[0x2AB0] = 0x2AAF; // SUCCEEDS ABOVE SINGLE-LINE EQUALS SIGN
|
||||
mirrorChars[0x2AB3] = 0x2AB4; // PRECEDES ABOVE EQUALS SIGN
|
||||
mirrorChars[0x2AB4] = 0x2AB3; // SUCCEEDS ABOVE EQUALS SIGN
|
||||
mirrorChars[0x2ABB] = 0x2ABC; // DOUBLE PRECEDES
|
||||
mirrorChars[0x2ABC] = 0x2ABB; // DOUBLE SUCCEEDS
|
||||
mirrorChars[0x2ABD] = 0x2ABE; // SUBSET WITH DOT
|
||||
mirrorChars[0x2ABE] = 0x2ABD; // SUPERSET WITH DOT
|
||||
mirrorChars[0x2ABF] = 0x2AC0; // SUBSET WITH PLUS SIGN BELOW
|
||||
mirrorChars[0x2AC0] = 0x2ABF; // SUPERSET WITH PLUS SIGN BELOW
|
||||
mirrorChars[0x2AC1] = 0x2AC2; // SUBSET WITH MULTIPLICATION SIGN BELOW
|
||||
mirrorChars[0x2AC2] = 0x2AC1; // SUPERSET WITH MULTIPLICATION SIGN BELOW
|
||||
mirrorChars[0x2AC3] = 0x2AC4; // SUBSET OF OR EQUAL TO WITH DOT ABOVE
|
||||
mirrorChars[0x2AC4] = 0x2AC3; // SUPERSET OF OR EQUAL TO WITH DOT ABOVE
|
||||
mirrorChars[0x2AC5] = 0x2AC6; // SUBSET OF ABOVE EQUALS SIGN
|
||||
mirrorChars[0x2AC6] = 0x2AC5; // SUPERSET OF ABOVE EQUALS SIGN
|
||||
mirrorChars[0x2ACD] = 0x2ACE; // SQUARE LEFT OPEN BOX OPERATOR
|
||||
mirrorChars[0x2ACE] = 0x2ACD; // SQUARE RIGHT OPEN BOX OPERATOR
|
||||
mirrorChars[0x2ACF] = 0x2AD0; // CLOSED SUBSET
|
||||
mirrorChars[0x2AD0] = 0x2ACF; // CLOSED SUPERSET
|
||||
mirrorChars[0x2AD1] = 0x2AD2; // CLOSED SUBSET OR EQUAL TO
|
||||
mirrorChars[0x2AD2] = 0x2AD1; // CLOSED SUPERSET OR EQUAL TO
|
||||
mirrorChars[0x2AD3] = 0x2AD4; // SUBSET ABOVE SUPERSET
|
||||
mirrorChars[0x2AD4] = 0x2AD3; // SUPERSET ABOVE SUBSET
|
||||
mirrorChars[0x2AD5] = 0x2AD6; // SUBSET ABOVE SUBSET
|
||||
mirrorChars[0x2AD6] = 0x2AD5; // SUPERSET ABOVE SUPERSET
|
||||
mirrorChars[0x2ADE] = 0x22A6; // SHORT LEFT TACK
|
||||
mirrorChars[0x2AE3] = 0x22A9; // DOUBLE VERTICAL BAR LEFT TURNSTILE
|
||||
mirrorChars[0x2AE4] = 0x22A8; // VERTICAL BAR DOUBLE LEFT TURNSTILE
|
||||
mirrorChars[0x2AE5] = 0x22AB; // DOUBLE VERTICAL BAR DOUBLE LEFT TURNSTILE
|
||||
mirrorChars[0x2AEC] = 0x2AED; // DOUBLE STROKE NOT SIGN
|
||||
mirrorChars[0x2AED] = 0x2AEC; // REVERSED DOUBLE STROKE NOT SIGN
|
||||
mirrorChars[0x2AF7] = 0x2AF8; // TRIPLE NESTED LESS-THAN
|
||||
mirrorChars[0x2AF8] = 0x2AF7; // TRIPLE NESTED GREATER-THAN
|
||||
mirrorChars[0x2AF9] = 0x2AFA; // DOUBLE-LINE SLANTED LESS-THAN OR EQUAL TO
|
||||
mirrorChars[0x2AFA] = 0x2AF9; // DOUBLE-LINE SLANTED GREATER-THAN OR EQUAL TO
|
||||
mirrorChars[0x3008] = 0x3009; // LEFT ANGLE BRACKET
|
||||
mirrorChars[0x3009] = 0x3008; // RIGHT ANGLE BRACKET
|
||||
mirrorChars[0x300A] = 0x300B; // LEFT DOUBLE ANGLE BRACKET
|
||||
mirrorChars[0x300B] = 0x300A; // RIGHT DOUBLE ANGLE BRACKET
|
||||
mirrorChars[0x300C] = 0x300D; // [BEST FIT] LEFT CORNER BRACKET
|
||||
mirrorChars[0x300D] = 0x300C; // [BEST FIT] RIGHT CORNER BRACKET
|
||||
mirrorChars[0x300E] = 0x300F; // [BEST FIT] LEFT WHITE CORNER BRACKET
|
||||
mirrorChars[0x300F] = 0x300E; // [BEST FIT] RIGHT WHITE CORNER BRACKET
|
||||
mirrorChars[0x3010] = 0x3011; // LEFT BLACK LENTICULAR BRACKET
|
||||
mirrorChars[0x3011] = 0x3010; // RIGHT BLACK LENTICULAR BRACKET
|
||||
mirrorChars[0x3014] = 0x3015; // LEFT TORTOISE SHELL BRACKET
|
||||
mirrorChars[0x3015] = 0x3014; // RIGHT TORTOISE SHELL BRACKET
|
||||
mirrorChars[0x3016] = 0x3017; // LEFT WHITE LENTICULAR BRACKET
|
||||
mirrorChars[0x3017] = 0x3016; // RIGHT WHITE LENTICULAR BRACKET
|
||||
mirrorChars[0x3018] = 0x3019; // LEFT WHITE TORTOISE SHELL BRACKET
|
||||
mirrorChars[0x3019] = 0x3018; // RIGHT WHITE TORTOISE SHELL BRACKET
|
||||
mirrorChars[0x301A] = 0x301B; // LEFT WHITE SQUARE BRACKET
|
||||
mirrorChars[0x301B] = 0x301A; // RIGHT WHITE SQUARE BRACKET
|
||||
mirrorChars[0xFF08] = 0xFF09; // FULLWIDTH LEFT PARENTHESIS
|
||||
mirrorChars[0xFF09] = 0xFF08; // FULLWIDTH RIGHT PARENTHESIS
|
||||
mirrorChars[0xFF1C] = 0xFF1E; // FULLWIDTH LESS-THAN SIGN
|
||||
mirrorChars[0xFF1E] = 0xFF1C; // FULLWIDTH GREATER-THAN SIGN
|
||||
mirrorChars[0xFF3B] = 0xFF3D; // FULLWIDTH LEFT SQUARE BRACKET
|
||||
mirrorChars[0xFF3D] = 0xFF3B; // FULLWIDTH RIGHT SQUARE BRACKET
|
||||
mirrorChars[0xFF5B] = 0xFF5D; // FULLWIDTH LEFT CURLY BRACKET
|
||||
mirrorChars[0xFF5D] = 0xFF5B; // FULLWIDTH RIGHT CURLY BRACKET
|
||||
mirrorChars[0xFF5F] = 0xFF60; // FULLWIDTH LEFT WHITE PARENTHESIS
|
||||
mirrorChars[0xFF60] = 0xFF5F; // FULLWIDTH RIGHT WHITE PARENTHESIS
|
||||
mirrorChars[0xFF62] = 0xFF63; // [BEST FIT] HALFWIDTH LEFT CORNER BRACKET
|
||||
mirrorChars[0xFF63] = 0xFF62; // [BEST FIT] HALFWIDTH RIGHT CORNER BRACKET
|
||||
}
|
||||
}
|
||||
}
|
||||
1296
iTechSharp/iTextSharp/text/pdf/BidiOrder.cs
Normal file
1296
iTechSharp/iTextSharp/text/pdf/BidiOrder.cs
Normal file
File diff suppressed because it is too large
Load Diff
673
iTechSharp/iTextSharp/text/pdf/ByteBuffer.cs
Normal file
673
iTechSharp/iTextSharp/text/pdf/ByteBuffer.cs
Normal file
@@ -0,0 +1,673 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Globalization;
|
||||
|
||||
/*
|
||||
* $Id: ByteBuffer.cs,v 1.7 2008/05/13 11:25:17 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2000, 2001, 2002 by Paulo Soares.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.pdf {
|
||||
/**
|
||||
* Acts like a <CODE>StringBuilder</CODE> but works with <CODE>byte</CODE> arrays.
|
||||
* floating point is converted to a format suitable to the PDF.
|
||||
* @author Paulo Soares (psoares@consiste.pt)
|
||||
*/
|
||||
|
||||
public class ByteBuffer : Stream {
|
||||
/** The count of bytes in the buffer. */
|
||||
protected int count;
|
||||
|
||||
/** The buffer where the bytes are stored. */
|
||||
protected byte[] buf;
|
||||
|
||||
private static int byteCacheSize = 0;
|
||||
|
||||
private static byte[][] byteCache = new byte[byteCacheSize][];
|
||||
public const byte ZERO = (byte)'0';
|
||||
private static char[] chars = new char[] {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
|
||||
private static byte[] bytes = new byte[] {48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102};
|
||||
/**
|
||||
* If <CODE>true</CODE> always output floating point numbers with 6 decimal digits.
|
||||
* If <CODE>false</CODE> uses the faster, although less precise, representation.
|
||||
*/
|
||||
public static bool HIGH_PRECISION = false;
|
||||
|
||||
/** Creates new ByteBuffer with capacity 128 */
|
||||
public ByteBuffer() : this(128) {}
|
||||
|
||||
/**
|
||||
* Creates a byte buffer with a certain capacity.
|
||||
* @param size the initial capacity
|
||||
*/
|
||||
public ByteBuffer(int size) {
|
||||
if (size < 1)
|
||||
size = 128;
|
||||
buf = new byte[size];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cache size.
|
||||
* <P>
|
||||
* This can only be used to increment the size.
|
||||
* If the size that is passed through is smaller than the current size, nothing happens.
|
||||
*
|
||||
* @param size the size of the cache
|
||||
*/
|
||||
|
||||
public static void SetCacheSize(int size) {
|
||||
if (size > 3276700) size = 3276700;
|
||||
if (size <= byteCacheSize) return;
|
||||
byte[][] tmpCache = new byte[size][];
|
||||
System.Array.Copy(byteCache, 0, tmpCache, 0, byteCacheSize);
|
||||
byteCache = tmpCache;
|
||||
byteCacheSize = size;
|
||||
}
|
||||
|
||||
/**
|
||||
* You can fill the cache in advance if you want to.
|
||||
*
|
||||
* @param decimals
|
||||
*/
|
||||
|
||||
public static void FillCache(int decimals) {
|
||||
int step = 1;
|
||||
switch (decimals) {
|
||||
case 0:
|
||||
step = 100;
|
||||
break;
|
||||
case 1:
|
||||
step = 10;
|
||||
break;
|
||||
}
|
||||
for (int i = 1; i < byteCacheSize; i += step) {
|
||||
if (byteCache[i] != null) continue;
|
||||
byteCache[i] = ConvertToBytes(i);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an double (multiplied by 100 and cast to an int) into an array of bytes.
|
||||
*
|
||||
* @param i the int
|
||||
* @return a bytearray
|
||||
*/
|
||||
|
||||
private static byte[] ConvertToBytes(int i) {
|
||||
int size = (int)Math.Floor(Math.Log(i) / Math.Log(10));
|
||||
if (i % 100 != 0) {
|
||||
size += 2;
|
||||
}
|
||||
if (i % 10 != 0) {
|
||||
size++;
|
||||
}
|
||||
if (i < 100) {
|
||||
size++;
|
||||
if (i < 10) {
|
||||
size++;
|
||||
}
|
||||
}
|
||||
size--;
|
||||
byte[] cache = new byte[size];
|
||||
size --;
|
||||
if (i < 100) {
|
||||
cache[0] = (byte)'0';
|
||||
}
|
||||
if (i % 10 != 0) {
|
||||
cache[size--] = bytes[i % 10];
|
||||
}
|
||||
if (i % 100 != 0) {
|
||||
cache[size--] = bytes[(i / 10) % 10];
|
||||
cache[size--] = (byte)'.';
|
||||
}
|
||||
size = (int)Math.Floor(Math.Log(i) / Math.Log(10)) - 1;
|
||||
int add = 0;
|
||||
while (add < size) {
|
||||
cache[add] = bytes[(i / (int)Math.Pow(10, size - add + 1)) % 10];
|
||||
add++;
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends an <CODE>int</CODE>. The size of the array will grow by one.
|
||||
* @param b the int to be appended
|
||||
* @return a reference to this <CODE>ByteBuffer</CODE> object
|
||||
*/
|
||||
public ByteBuffer Append_i(int b) {
|
||||
int newcount = count + 1;
|
||||
if (newcount > buf.Length) {
|
||||
byte[] newbuf = new byte[Math.Max(buf.Length << 1, newcount)];
|
||||
Array.Copy(buf, 0, newbuf, 0, count);
|
||||
buf = newbuf;
|
||||
}
|
||||
buf[count] = (byte)b;
|
||||
count = newcount;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the subarray of the <CODE>byte</CODE> array. The buffer will grow by
|
||||
* <CODE>len</CODE> bytes.
|
||||
* @param b the array to be appended
|
||||
* @param off the offset to the start of the array
|
||||
* @param len the length of bytes to Append
|
||||
* @return a reference to this <CODE>ByteBuffer</CODE> object
|
||||
*/
|
||||
public ByteBuffer Append(byte[] b, int off, int len) {
|
||||
if ((off < 0) || (off > b.Length) || (len < 0) ||
|
||||
((off + len) > b.Length) || ((off + len) < 0) || len == 0)
|
||||
return this;
|
||||
int newcount = count + len;
|
||||
if (newcount > buf.Length) {
|
||||
byte[] newbuf = new byte[Math.Max(buf.Length << 1, newcount)];
|
||||
Array.Copy(buf, 0, newbuf, 0, count);
|
||||
buf = newbuf;
|
||||
}
|
||||
Array.Copy(b, off, buf, count, len);
|
||||
count = newcount;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends an array of bytes.
|
||||
* @param b the array to be appended
|
||||
* @return a reference to this <CODE>ByteBuffer</CODE> object
|
||||
*/
|
||||
public ByteBuffer Append(byte[] b) {
|
||||
return Append(b, 0, b.Length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a <CODE>string</CODE> to the buffer. The <CODE>string</CODE> is
|
||||
* converted according to the encoding ISO-8859-1.
|
||||
* @param str the <CODE>string</CODE> to be appended
|
||||
* @return a reference to this <CODE>ByteBuffer</CODE> object
|
||||
*/
|
||||
public ByteBuffer Append(string str) {
|
||||
if (str != null)
|
||||
return Append(DocWriter.GetISOBytes(str));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a <CODE>char</CODE> to the buffer. The <CODE>char</CODE> is
|
||||
* converted according to the encoding ISO-8859-1.
|
||||
* @param c the <CODE>char</CODE> to be appended
|
||||
* @return a reference to this <CODE>ByteBuffer</CODE> object
|
||||
*/
|
||||
public ByteBuffer Append(char c) {
|
||||
return Append_i(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends another <CODE>ByteBuffer</CODE> to this buffer.
|
||||
* @param buf the <CODE>ByteBuffer</CODE> to be appended
|
||||
* @return a reference to this <CODE>ByteBuffer</CODE> object
|
||||
*/
|
||||
public ByteBuffer Append(ByteBuffer buf) {
|
||||
return Append(buf.buf, 0, buf.count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the string representation of an <CODE>int</CODE>.
|
||||
* @param i the <CODE>int</CODE> to be appended
|
||||
* @return a reference to this <CODE>ByteBuffer</CODE> object
|
||||
*/
|
||||
public ByteBuffer Append(int i) {
|
||||
return Append((double)i);
|
||||
}
|
||||
|
||||
public ByteBuffer Append(byte b) {
|
||||
return Append_i(b);
|
||||
}
|
||||
|
||||
public ByteBuffer AppendHex(byte b) {
|
||||
Append(bytes[(b >> 4) & 0x0f]);
|
||||
return Append(bytes[b & 0x0f]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a string representation of a <CODE>float</CODE> according
|
||||
* to the Pdf conventions.
|
||||
* @param i the <CODE>float</CODE> to be appended
|
||||
* @return a reference to this <CODE>ByteBuffer</CODE> object
|
||||
*/
|
||||
public ByteBuffer Append(float i) {
|
||||
return Append((double)i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a string representation of a <CODE>double</CODE> according
|
||||
* to the Pdf conventions.
|
||||
* @param d the <CODE>double</CODE> to be appended
|
||||
* @return a reference to this <CODE>ByteBuffer</CODE> object
|
||||
*/
|
||||
public ByteBuffer Append(double d) {
|
||||
Append(FormatDouble(d, this));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs a <CODE>double</CODE> into a format suitable for the PDF.
|
||||
* @param d a double
|
||||
* @return the <CODE>string</CODE> representation of the <CODE>double</CODE>
|
||||
*/
|
||||
public static string FormatDouble(double d) {
|
||||
return FormatDouble(d, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs a <CODE>double</CODE> into a format suitable for the PDF.
|
||||
* @param d a double
|
||||
* @param buf a ByteBuffer
|
||||
* @return the <CODE>String</CODE> representation of the <CODE>double</CODE> if
|
||||
* <CODE>buf</CODE> is <CODE>null</CODE>. If <CODE>buf</CODE> is <B>not</B> <CODE>null</CODE>,
|
||||
* then the double is appended directly to the buffer and this methods returns <CODE>null</CODE>.
|
||||
*/
|
||||
public static string FormatDouble(double d, ByteBuffer buf) {
|
||||
if (HIGH_PRECISION) {
|
||||
String sform = d.ToString("0.######", CultureInfo.InvariantCulture);
|
||||
if (buf == null)
|
||||
return sform;
|
||||
else {
|
||||
buf.Append(sform);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
bool negative = false;
|
||||
if (Math.Abs(d) < 0.000015) {
|
||||
if (buf != null) {
|
||||
buf.Append(ZERO);
|
||||
return null;
|
||||
} else {
|
||||
return "0";
|
||||
}
|
||||
}
|
||||
if (d < 0) {
|
||||
negative = true;
|
||||
d = -d;
|
||||
}
|
||||
if (d < 1.0) {
|
||||
d += 0.000005;
|
||||
if (d >= 1) {
|
||||
if (negative) {
|
||||
if (buf != null) {
|
||||
buf.Append((byte)'-');
|
||||
buf.Append((byte)'1');
|
||||
return null;
|
||||
} else {
|
||||
return "-1";
|
||||
}
|
||||
} else {
|
||||
if (buf != null) {
|
||||
buf.Append((byte)'1');
|
||||
return null;
|
||||
} else {
|
||||
return "1";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (buf != null) {
|
||||
int v = (int) (d * 100000);
|
||||
|
||||
if (negative) buf.Append((byte)'-');
|
||||
buf.Append((byte)'0');
|
||||
buf.Append((byte)'.');
|
||||
|
||||
buf.Append( (byte)(v / 10000 + ZERO) );
|
||||
if (v % 10000 != 0) {
|
||||
buf.Append( (byte)((v / 1000) % 10 + ZERO) );
|
||||
if (v % 1000 != 0) {
|
||||
buf.Append( (byte)((v / 100) % 10 + ZERO) );
|
||||
if (v % 100 != 0) {
|
||||
buf.Append((byte)((v / 10) % 10 + ZERO) );
|
||||
if (v % 10 != 0) {
|
||||
buf.Append((byte)((v) % 10 + ZERO) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} else {
|
||||
int x = 100000;
|
||||
int v = (int) (d * x);
|
||||
|
||||
StringBuilder res = new StringBuilder();
|
||||
if (negative) res.Append('-');
|
||||
res.Append("0.");
|
||||
|
||||
while ( v < x/10 ) {
|
||||
res.Append('0');
|
||||
x /= 10;
|
||||
}
|
||||
res.Append(v);
|
||||
int cut = res.Length - 1;
|
||||
while (res[cut] == '0') {
|
||||
--cut;
|
||||
}
|
||||
res.Length = cut + 1;
|
||||
return res.ToString();
|
||||
}
|
||||
} else if (d <= 32767) {
|
||||
d += 0.005;
|
||||
int v = (int) (d * 100);
|
||||
|
||||
if (v < byteCacheSize && byteCache[v] != null) {
|
||||
if (buf != null) {
|
||||
if (negative) buf.Append((byte)'-');
|
||||
buf.Append(byteCache[v]);
|
||||
return null;
|
||||
} else {
|
||||
string tmp = PdfEncodings.ConvertToString(byteCache[v], null);
|
||||
if (negative) tmp = "-" + tmp;
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
if (buf != null) {
|
||||
if (v < byteCacheSize) {
|
||||
//create the cachebyte[]
|
||||
byte[] cache;
|
||||
int size = 0;
|
||||
if (v >= 1000000) {
|
||||
//the original number is >=10000, we need 5 more bytes
|
||||
size += 5;
|
||||
} else if (v >= 100000) {
|
||||
//the original number is >=1000, we need 4 more bytes
|
||||
size += 4;
|
||||
} else if (v >= 10000) {
|
||||
//the original number is >=100, we need 3 more bytes
|
||||
size += 3;
|
||||
} else if (v >= 1000) {
|
||||
//the original number is >=10, we need 2 more bytes
|
||||
size += 2;
|
||||
} else if (v >= 100) {
|
||||
//the original number is >=1, we need 1 more bytes
|
||||
size += 1;
|
||||
}
|
||||
|
||||
//now we must check if we have a decimal number
|
||||
if (v % 100 != 0) {
|
||||
//yes, do not forget the "."
|
||||
size += 2;
|
||||
}
|
||||
if (v % 10 != 0) {
|
||||
size++;
|
||||
}
|
||||
cache = new byte[size];
|
||||
int add = 0;
|
||||
if (v >= 1000000) {
|
||||
cache[add++] = bytes[(v / 1000000)];
|
||||
}
|
||||
if (v >= 100000) {
|
||||
cache[add++] = bytes[(v / 100000) % 10];
|
||||
}
|
||||
if (v >= 10000) {
|
||||
cache[add++] = bytes[(v / 10000) % 10];
|
||||
}
|
||||
if (v >= 1000) {
|
||||
cache[add++] = bytes[(v / 1000) % 10];
|
||||
}
|
||||
if (v >= 100) {
|
||||
cache[add++] = bytes[(v / 100) % 10];
|
||||
}
|
||||
|
||||
if (v % 100 != 0) {
|
||||
cache[add++] = (byte)'.';
|
||||
cache[add++] = bytes[(v / 10) % 10];
|
||||
if (v % 10 != 0) {
|
||||
cache[add++] = bytes[v % 10];
|
||||
}
|
||||
}
|
||||
byteCache[v] = cache;
|
||||
}
|
||||
|
||||
if (negative) buf.Append((byte)'-');
|
||||
if (v >= 1000000) {
|
||||
buf.Append( bytes[(v / 1000000)] );
|
||||
}
|
||||
if (v >= 100000) {
|
||||
buf.Append( bytes[(v / 100000) % 10] );
|
||||
}
|
||||
if (v >= 10000) {
|
||||
buf.Append( bytes[(v / 10000) % 10] );
|
||||
}
|
||||
if (v >= 1000) {
|
||||
buf.Append( bytes[(v / 1000) % 10] );
|
||||
}
|
||||
if (v >= 100) {
|
||||
buf.Append( bytes[(v / 100) % 10] );
|
||||
}
|
||||
|
||||
if (v % 100 != 0) {
|
||||
buf.Append((byte)'.');
|
||||
buf.Append( bytes[(v / 10) % 10] );
|
||||
if (v % 10 != 0) {
|
||||
buf.Append( bytes[v % 10] );
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} else {
|
||||
StringBuilder res = new StringBuilder();
|
||||
if (negative) res.Append('-');
|
||||
if (v >= 1000000) {
|
||||
res.Append( chars[(v / 1000000)] );
|
||||
}
|
||||
if (v >= 100000) {
|
||||
res.Append( chars[(v / 100000) % 10] );
|
||||
}
|
||||
if (v >= 10000) {
|
||||
res.Append( chars[(v / 10000) % 10] );
|
||||
}
|
||||
if (v >= 1000) {
|
||||
res.Append( chars[(v / 1000) % 10] );
|
||||
}
|
||||
if (v >= 100) {
|
||||
res.Append( chars[(v / 100) % 10] );
|
||||
}
|
||||
|
||||
if (v % 100 != 0) {
|
||||
res.Append('.');
|
||||
res.Append( chars[(v / 10) % 10] );
|
||||
if (v % 10 != 0) {
|
||||
res.Append( chars[v % 10] );
|
||||
}
|
||||
}
|
||||
return res.ToString();
|
||||
}
|
||||
} else {
|
||||
StringBuilder res = new StringBuilder();
|
||||
if (negative) res.Append('-');
|
||||
d += 0.5;
|
||||
long v = (long) d;
|
||||
return res.Append(v).ToString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the size to zero.
|
||||
*/
|
||||
public void Reset() {
|
||||
count = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a newly allocated byte array. Its size is the current
|
||||
* size of this output stream and the valid contents of the buffer
|
||||
* have been copied into it.
|
||||
*
|
||||
* @return the current contents of this output stream, as a byte array.
|
||||
*/
|
||||
public byte[] ToByteArray() {
|
||||
byte[] newbuf = new byte[count];
|
||||
Array.Copy(buf, 0, newbuf, 0, count);
|
||||
return newbuf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current size of the buffer.
|
||||
*
|
||||
* @return the value of the <code>count</code> field, which is the number of valid bytes in this byte buffer.
|
||||
*/
|
||||
public int Size {
|
||||
get {
|
||||
return count;
|
||||
}
|
||||
set {
|
||||
if (value > count || value < 0)
|
||||
throw new ArgumentOutOfRangeException("The new size must be positive and <= of the current size");
|
||||
count = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the buffer's contents into a string, translating bytes into
|
||||
* characters according to the platform's default character encoding.
|
||||
*
|
||||
* @return string translated from the buffer's contents.
|
||||
*/
|
||||
public override string ToString() {
|
||||
char[] tmp = this.ConvertToChar(buf);
|
||||
return new String(tmp, 0, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the buffer's contents into a string, translating bytes into
|
||||
* characters according to the specified character encoding.
|
||||
*
|
||||
* @param enc a character-encoding name.
|
||||
* @return string translated from the buffer's contents.
|
||||
* @throws UnsupportedEncodingException
|
||||
* If the named encoding is not supported.
|
||||
*/
|
||||
// public string ToString(System.Text.Encoding enc) {
|
||||
// return new String(ref buf, 0, count, enc);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Writes the complete contents of this byte buffer output to
|
||||
* the specified output stream argument, as if by calling the output
|
||||
* stream's write method using <code>out.Write(buf, 0, count)</code>.
|
||||
*
|
||||
* @param out the output stream to which to write the data.
|
||||
* @exception IOException if an I/O error occurs.
|
||||
*/
|
||||
public void WriteTo(Stream str) {
|
||||
str.Write(buf, 0, count);
|
||||
}
|
||||
|
||||
private char[] ConvertToChar(byte[] buf) {
|
||||
char[] retVal = new char[count + 1];
|
||||
for (int i = 0; i <= count; i++) {
|
||||
retVal[i] = (char)buf[i];
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public byte[] Buffer {
|
||||
get {
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanRead {
|
||||
get {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanSeek {
|
||||
get {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanWrite {
|
||||
get {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public override long Length {
|
||||
get {
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
public override long Position {
|
||||
get {
|
||||
return count;
|
||||
}
|
||||
set {
|
||||
}
|
||||
}
|
||||
|
||||
public override void Flush() {
|
||||
}
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public override long Seek(long offset, SeekOrigin origin) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public override void SetLength(long value) {
|
||||
}
|
||||
|
||||
public override void Write(byte[] buffer, int offset, int count) {
|
||||
Append(buffer, offset, count);
|
||||
}
|
||||
|
||||
public override void WriteByte(byte value) {
|
||||
Append(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
1111
iTechSharp/iTextSharp/text/pdf/CFFFont.cs
Normal file
1111
iTechSharp/iTextSharp/text/pdf/CFFFont.cs
Normal file
File diff suppressed because it is too large
Load Diff
1578
iTechSharp/iTextSharp/text/pdf/CFFFontSubset.cs
Normal file
1578
iTechSharp/iTextSharp/text/pdf/CFFFontSubset.cs
Normal file
File diff suppressed because it is too large
Load Diff
646
iTechSharp/iTextSharp/text/pdf/CJKFont.cs
Normal file
646
iTechSharp/iTextSharp/text/pdf/CJKFont.cs
Normal file
@@ -0,0 +1,646 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using System.util;
|
||||
|
||||
/*
|
||||
* $Id: CJKFont.cs,v 1.9 2008/05/13 11:25:17 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2000, 2001, 2002 by Paulo Soares.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.pdf {
|
||||
|
||||
/**
|
||||
* Creates a CJK font compatible with the fonts in the Adobe Asian font Pack.
|
||||
*
|
||||
* @author Paulo Soares (psoares@consiste.pt)
|
||||
*/
|
||||
|
||||
internal class CJKFont : BaseFont {
|
||||
/** The encoding used in the PDF document for CJK fonts
|
||||
*/
|
||||
internal const string CJK_ENCODING = "UNICODEBIGUNMARKED";
|
||||
private const int FIRST = 0;
|
||||
private const int BRACKET = 1;
|
||||
private const int SERIAL = 2;
|
||||
private const int V1Y = 880;
|
||||
|
||||
internal static Properties cjkFonts = new Properties();
|
||||
internal static Properties cjkEncodings = new Properties();
|
||||
internal static Hashtable allCMaps = Hashtable.Synchronized(new Hashtable());
|
||||
internal static Hashtable allFonts = Hashtable.Synchronized(new Hashtable());
|
||||
private static bool propertiesLoaded = false;
|
||||
|
||||
/** The font name */
|
||||
private string fontName;
|
||||
/** The style modifier */
|
||||
private string style = "";
|
||||
/** The CMap name associated with this font */
|
||||
private string CMap;
|
||||
|
||||
private bool cidDirect = false;
|
||||
|
||||
private char[] translationMap;
|
||||
private IntHashtable vMetrics;
|
||||
private IntHashtable hMetrics;
|
||||
private Hashtable fontDesc;
|
||||
private bool vertical = false;
|
||||
|
||||
private static void LoadProperties() {
|
||||
if (propertiesLoaded)
|
||||
return;
|
||||
lock (allFonts) {
|
||||
if (propertiesLoaded)
|
||||
return;
|
||||
try {
|
||||
Stream isp = GetResourceStream(RESOURCE_PATH + "cjkfonts.properties");
|
||||
cjkFonts.Load(isp);
|
||||
isp.Close();
|
||||
isp = GetResourceStream(RESOURCE_PATH + "cjkencodings.properties");
|
||||
cjkEncodings.Load(isp);
|
||||
isp.Close();
|
||||
}
|
||||
catch {
|
||||
cjkFonts = new Properties();
|
||||
cjkEncodings = new Properties();
|
||||
}
|
||||
propertiesLoaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
/** Creates a CJK font.
|
||||
* @param fontName the name of the font
|
||||
* @param enc the encoding of the font
|
||||
* @param emb always <CODE>false</CODE>. CJK font and not embedded
|
||||
* @throws DocumentException on error
|
||||
* @throws IOException on error
|
||||
*/
|
||||
internal CJKFont(string fontName, string enc, bool emb) {
|
||||
LoadProperties();
|
||||
this.FontType = FONT_TYPE_CJK;
|
||||
string nameBase = GetBaseName(fontName);
|
||||
if (!IsCJKFont(nameBase, enc))
|
||||
throw new DocumentException("Font '" + fontName + "' with '" + enc + "' encoding is not a CJK font.");
|
||||
if (nameBase.Length < fontName.Length) {
|
||||
style = fontName.Substring(nameBase.Length);
|
||||
fontName = nameBase;
|
||||
}
|
||||
this.fontName = fontName;
|
||||
encoding = CJK_ENCODING;
|
||||
vertical = enc.EndsWith("V");
|
||||
CMap = enc;
|
||||
if (enc.StartsWith("Identity-")) {
|
||||
cidDirect = true;
|
||||
string s = cjkFonts[fontName];
|
||||
s = s.Substring(0, s.IndexOf('_'));
|
||||
char[] c = (char[])allCMaps[s];
|
||||
if (c == null) {
|
||||
c = ReadCMap(s);
|
||||
if (c == null)
|
||||
throw new DocumentException("The cmap " + s + " does not exist as a resource.");
|
||||
c[CID_NEWLINE] = '\n';
|
||||
allCMaps.Add(s, c);
|
||||
}
|
||||
translationMap = c;
|
||||
}
|
||||
else {
|
||||
char[] c = (char[])allCMaps[enc];
|
||||
if (c == null) {
|
||||
string s = cjkEncodings[enc];
|
||||
if (s == null)
|
||||
throw new DocumentException("The resource cjkencodings.properties does not contain the encoding " + enc);
|
||||
StringTokenizer tk = new StringTokenizer(s);
|
||||
string nt = tk.NextToken();
|
||||
c = (char[])allCMaps[nt];
|
||||
if (c == null) {
|
||||
c = ReadCMap(nt);
|
||||
allCMaps.Add(nt, c);
|
||||
}
|
||||
if (tk.HasMoreTokens()) {
|
||||
string nt2 = tk.NextToken();
|
||||
char[] m2 = ReadCMap(nt2);
|
||||
for (int k = 0; k < 0x10000; ++k) {
|
||||
if (m2[k] == 0)
|
||||
m2[k] = c[k];
|
||||
}
|
||||
allCMaps.Add(enc, m2);
|
||||
c = m2;
|
||||
}
|
||||
}
|
||||
translationMap = c;
|
||||
}
|
||||
fontDesc = (Hashtable)allFonts[fontName];
|
||||
if (fontDesc == null) {
|
||||
fontDesc = ReadFontProperties(fontName);
|
||||
allFonts.Add(fontName, fontDesc);
|
||||
}
|
||||
hMetrics = (IntHashtable)fontDesc["W"];
|
||||
vMetrics = (IntHashtable)fontDesc["W2"];
|
||||
}
|
||||
|
||||
/** Checks if its a valid CJK font.
|
||||
* @param fontName the font name
|
||||
* @param enc the encoding
|
||||
* @return <CODE>true</CODE> if it is CJK font
|
||||
*/
|
||||
public static bool IsCJKFont(string fontName, string enc) {
|
||||
LoadProperties();
|
||||
string encodings = cjkFonts[fontName];
|
||||
return (encodings != null && (enc.Equals("Identity-H") || enc.Equals("Identity-V") || encodings.IndexOf("_" + enc + "_") >= 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the width of a <CODE>char</CODE> in normalized 1000 units.
|
||||
* @param char1 the unicode <CODE>char</CODE> to get the width of
|
||||
* @return the width in normalized 1000 units
|
||||
*/
|
||||
public override int GetWidth(int char1) {
|
||||
int c = (int)char1;
|
||||
if (!cidDirect)
|
||||
c = translationMap[c];
|
||||
int v;
|
||||
if (vertical)
|
||||
v = vMetrics[c];
|
||||
else
|
||||
v = hMetrics[c];
|
||||
if (v > 0)
|
||||
return v;
|
||||
else
|
||||
return 1000;
|
||||
}
|
||||
|
||||
public override int GetWidth(string text) {
|
||||
int total = 0;
|
||||
for (int k = 0; k < text.Length; ++k) {
|
||||
int c = text[k];
|
||||
if (!cidDirect)
|
||||
c = translationMap[c];
|
||||
int v;
|
||||
if (vertical)
|
||||
v = vMetrics[c];
|
||||
else
|
||||
v = hMetrics[c];
|
||||
if (v > 0)
|
||||
total += v;
|
||||
else
|
||||
total += 1000;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
internal override int GetRawWidth(int c, string name) {
|
||||
return 0;
|
||||
}
|
||||
public override int GetKerning(int char1, int char2) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
private PdfDictionary GetFontDescriptor() {
|
||||
PdfDictionary dic = new PdfDictionary(PdfName.FONTDESCRIPTOR);
|
||||
dic.Put(PdfName.ASCENT, new PdfLiteral((String)fontDesc["Ascent"]));
|
||||
dic.Put(PdfName.CAPHEIGHT, new PdfLiteral((String)fontDesc["CapHeight"]));
|
||||
dic.Put(PdfName.DESCENT, new PdfLiteral((String)fontDesc["Descent"]));
|
||||
dic.Put(PdfName.FLAGS, new PdfLiteral((String)fontDesc["Flags"]));
|
||||
dic.Put(PdfName.FONTBBOX, new PdfLiteral((String)fontDesc["FontBBox"]));
|
||||
dic.Put(PdfName.FONTNAME, new PdfName(fontName + style));
|
||||
dic.Put(PdfName.ITALICANGLE, new PdfLiteral((String)fontDesc["ItalicAngle"]));
|
||||
dic.Put(PdfName.STEMV, new PdfLiteral((String)fontDesc["StemV"]));
|
||||
PdfDictionary pdic = new PdfDictionary();
|
||||
pdic.Put(PdfName.PANOSE, new PdfString((String)fontDesc["Panose"], null));
|
||||
dic.Put(PdfName.STYLE, pdic);
|
||||
return dic;
|
||||
}
|
||||
|
||||
private PdfDictionary GetCIDFont(PdfIndirectReference fontDescriptor, IntHashtable cjkTag) {
|
||||
PdfDictionary dic = new PdfDictionary(PdfName.FONT);
|
||||
dic.Put(PdfName.SUBTYPE, PdfName.CIDFONTTYPE0);
|
||||
dic.Put(PdfName.BASEFONT, new PdfName(fontName + style));
|
||||
dic.Put(PdfName.FONTDESCRIPTOR, fontDescriptor);
|
||||
int[] keys = cjkTag.ToOrderedKeys();
|
||||
string w = ConvertToHCIDMetrics(keys, hMetrics);
|
||||
if (w != null)
|
||||
dic.Put(PdfName.W, new PdfLiteral(w));
|
||||
if (vertical) {
|
||||
w = ConvertToVCIDMetrics(keys, vMetrics, hMetrics);
|
||||
if (w != null)
|
||||
dic.Put(PdfName.W2, new PdfLiteral(w));
|
||||
}
|
||||
else
|
||||
dic.Put(PdfName.DW, new PdfNumber(1000));
|
||||
PdfDictionary cdic = new PdfDictionary();
|
||||
cdic.Put(PdfName.REGISTRY, new PdfString((string)fontDesc["Registry"], null));
|
||||
cdic.Put(PdfName.ORDERING, new PdfString((string)fontDesc["Ordering"], null));
|
||||
cdic.Put(PdfName.SUPPLEMENT, new PdfLiteral((string)fontDesc["Supplement"]));
|
||||
dic.Put(PdfName.CIDSYSTEMINFO, cdic);
|
||||
return dic;
|
||||
}
|
||||
|
||||
private PdfDictionary GetFontBaseType(PdfIndirectReference CIDFont) {
|
||||
PdfDictionary dic = new PdfDictionary(PdfName.FONT);
|
||||
dic.Put(PdfName.SUBTYPE, PdfName.TYPE0);
|
||||
string name = fontName;
|
||||
if (style.Length > 0)
|
||||
name += "-" + style.Substring(1);
|
||||
name += "-" + CMap;
|
||||
dic.Put(PdfName.BASEFONT, new PdfName(name));
|
||||
dic.Put(PdfName.ENCODING, new PdfName(CMap));
|
||||
dic.Put(PdfName.DESCENDANTFONTS, new PdfArray(CIDFont));
|
||||
return dic;
|
||||
}
|
||||
|
||||
internal override void WriteFont(PdfWriter writer, PdfIndirectReference piref, Object[] parms) {
|
||||
IntHashtable cjkTag = (IntHashtable)parms[0];
|
||||
PdfIndirectReference ind_font = null;
|
||||
PdfObject pobj = null;
|
||||
PdfIndirectObject obj = null;
|
||||
pobj = GetFontDescriptor();
|
||||
if (pobj != null){
|
||||
obj = writer.AddToBody(pobj);
|
||||
ind_font = obj.IndirectReference;
|
||||
}
|
||||
pobj = GetCIDFont(ind_font, cjkTag);
|
||||
if (pobj != null){
|
||||
obj = writer.AddToBody(pobj);
|
||||
ind_font = obj.IndirectReference;
|
||||
}
|
||||
pobj = GetFontBaseType(ind_font);
|
||||
writer.AddToBody(pobj, piref);
|
||||
}
|
||||
|
||||
private float GetDescNumber(string name) {
|
||||
return int.Parse((string)fontDesc[name]);
|
||||
}
|
||||
|
||||
private float GetBBox(int idx) {
|
||||
string s = (string)fontDesc["FontBBox"];
|
||||
StringTokenizer tk = new StringTokenizer(s, " []\r\n\t\f");
|
||||
string ret = tk.NextToken();
|
||||
for (int k = 0; k < idx; ++k)
|
||||
ret = tk.NextToken();
|
||||
return int.Parse(ret);
|
||||
}
|
||||
|
||||
/** Gets the font parameter identified by <CODE>key</CODE>. Valid values
|
||||
* for <CODE>key</CODE> are <CODE>ASCENT</CODE>, <CODE>CAPHEIGHT</CODE>, <CODE>DESCENT</CODE>
|
||||
* and <CODE>ITALICANGLE</CODE>.
|
||||
* @param key the parameter to be extracted
|
||||
* @param fontSize the font size in points
|
||||
* @return the parameter in points
|
||||
*/
|
||||
public override float GetFontDescriptor(int key, float fontSize) {
|
||||
switch (key) {
|
||||
case AWT_ASCENT:
|
||||
case ASCENT:
|
||||
return GetDescNumber("Ascent") * fontSize / 1000;
|
||||
case CAPHEIGHT:
|
||||
return GetDescNumber("CapHeight") * fontSize / 1000;
|
||||
case AWT_DESCENT:
|
||||
case DESCENT:
|
||||
return GetDescNumber("Descent") * fontSize / 1000;
|
||||
case ITALICANGLE:
|
||||
return GetDescNumber("ItalicAngle");
|
||||
case BBOXLLX:
|
||||
return fontSize * GetBBox(0) / 1000;
|
||||
case BBOXLLY:
|
||||
return fontSize * GetBBox(1) / 1000;
|
||||
case BBOXURX:
|
||||
return fontSize * GetBBox(2) / 1000;
|
||||
case BBOXURY:
|
||||
return fontSize * GetBBox(3) / 1000;
|
||||
case AWT_LEADING:
|
||||
return 0;
|
||||
case AWT_MAXADVANCE:
|
||||
return fontSize * (GetBBox(2) - GetBBox(0)) / 1000;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public override string PostscriptFontName {
|
||||
get {
|
||||
return fontName;
|
||||
}
|
||||
set {
|
||||
fontName = value;
|
||||
}
|
||||
}
|
||||
|
||||
/** Gets the full name of the font. If it is a True Type font
|
||||
* each array element will have {Platform ID, Platform Encoding ID,
|
||||
* Language ID, font name}. The interpretation of this values can be
|
||||
* found in the Open Type specification, chapter 2, in the 'name' table.<br>
|
||||
* For the other fonts the array has a single element with {"", "", "",
|
||||
* font name}.
|
||||
* @return the full name of the font
|
||||
*/
|
||||
public override string[][] FullFontName {
|
||||
get {
|
||||
return new string[][]{new string[] {"", "", "", fontName}};
|
||||
}
|
||||
}
|
||||
|
||||
/** Gets all the entries of the names-table. If it is a True Type font
|
||||
* each array element will have {Name ID, Platform ID, Platform Encoding ID,
|
||||
* Language ID, font name}. The interpretation of this values can be
|
||||
* found in the Open Type specification, chapter 2, in the 'name' table.<br>
|
||||
* For the other fonts the array has a single element with {"4", "", "", "",
|
||||
* font name}.
|
||||
* @return the full name of the font
|
||||
*/
|
||||
public override string[][] AllNameEntries {
|
||||
get {
|
||||
return new string[][]{new string[]{"4", "", "", "", fontName}};
|
||||
}
|
||||
}
|
||||
|
||||
/** Gets the family name of the font. If it is a True Type font
|
||||
* each array element will have {Platform ID, Platform Encoding ID,
|
||||
* Language ID, font name}. The interpretation of this values can be
|
||||
* found in the Open Type specification, chapter 2, in the 'name' table.<br>
|
||||
* For the other fonts the array has a single element with {"", "", "",
|
||||
* font name}.
|
||||
* @return the family name of the font
|
||||
*/
|
||||
public override string[][] FamilyFontName {
|
||||
get {
|
||||
return this.FullFontName;
|
||||
}
|
||||
}
|
||||
|
||||
internal static char[] ReadCMap(string name) {
|
||||
Stream istr = null;
|
||||
try {
|
||||
name = name + ".cmap";
|
||||
istr = GetResourceStream(RESOURCE_PATH + name);
|
||||
char[] c = new char[0x10000];
|
||||
for (int k = 0; k < 0x10000; ++k)
|
||||
c[k] = (char)((istr.ReadByte() << 8) + istr.ReadByte());
|
||||
return c;
|
||||
}
|
||||
catch {
|
||||
// empty on purpose
|
||||
}
|
||||
finally {
|
||||
try{istr.Close();}catch{}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
internal static IntHashtable CreateMetric(string s) {
|
||||
IntHashtable h = new IntHashtable();
|
||||
StringTokenizer tk = new StringTokenizer(s);
|
||||
while (tk.HasMoreTokens()) {
|
||||
int n1 = int.Parse(tk.NextToken());
|
||||
h[n1] = int.Parse(tk.NextToken());
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
internal static string ConvertToHCIDMetrics(int[] keys, IntHashtable h) {
|
||||
if (keys.Length == 0)
|
||||
return null;
|
||||
int lastCid = 0;
|
||||
int lastValue = 0;
|
||||
int start;
|
||||
for (start = 0; start < keys.Length; ++start) {
|
||||
lastCid = keys[start];
|
||||
lastValue = h[lastCid];
|
||||
if (lastValue != 0) {
|
||||
++start;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (lastValue == 0)
|
||||
return null;
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.Append('[');
|
||||
buf.Append(lastCid);
|
||||
int state = FIRST;
|
||||
for (int k = start; k < keys.Length; ++k) {
|
||||
int cid = keys[k];
|
||||
int value = h[cid];
|
||||
if (value == 0)
|
||||
continue;
|
||||
switch (state) {
|
||||
case FIRST: {
|
||||
if (cid == lastCid + 1 && value == lastValue) {
|
||||
state = SERIAL;
|
||||
}
|
||||
else if (cid == lastCid + 1) {
|
||||
state = BRACKET;
|
||||
buf.Append('[').Append(lastValue);
|
||||
}
|
||||
else {
|
||||
buf.Append('[').Append(lastValue).Append(']').Append(cid);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BRACKET: {
|
||||
if (cid == lastCid + 1 && value == lastValue) {
|
||||
state = SERIAL;
|
||||
buf.Append(']').Append(lastCid);
|
||||
}
|
||||
else if (cid == lastCid + 1) {
|
||||
buf.Append(' ').Append(lastValue);
|
||||
}
|
||||
else {
|
||||
state = FIRST;
|
||||
buf.Append(' ').Append(lastValue).Append(']').Append(cid);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SERIAL: {
|
||||
if (cid != lastCid + 1 || value != lastValue) {
|
||||
buf.Append(' ').Append(lastCid).Append(' ').Append(lastValue).Append(' ').Append(cid);
|
||||
state = FIRST;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
lastValue = value;
|
||||
lastCid = cid;
|
||||
}
|
||||
switch (state) {
|
||||
case FIRST: {
|
||||
buf.Append('[').Append(lastValue).Append("]]");
|
||||
break;
|
||||
}
|
||||
case BRACKET: {
|
||||
buf.Append(' ').Append(lastValue).Append("]]");
|
||||
break;
|
||||
}
|
||||
case SERIAL: {
|
||||
buf.Append(' ').Append(lastCid).Append(' ').Append(lastValue).Append(']');
|
||||
break;
|
||||
}
|
||||
}
|
||||
return buf.ToString();
|
||||
}
|
||||
|
||||
internal static string ConvertToVCIDMetrics(int[] keys, IntHashtable v, IntHashtable h) {
|
||||
if (keys.Length == 0)
|
||||
return null;
|
||||
int lastCid = 0;
|
||||
int lastValue = 0;
|
||||
int lastHValue = 0;
|
||||
int start;
|
||||
for (start = 0; start < keys.Length; ++start) {
|
||||
lastCid = keys[start];
|
||||
lastValue = v[lastCid];
|
||||
if (lastValue != 0) {
|
||||
++start;
|
||||
break;
|
||||
}
|
||||
else
|
||||
lastHValue = h[lastCid];
|
||||
}
|
||||
if (lastValue == 0)
|
||||
return null;
|
||||
if (lastHValue == 0)
|
||||
lastHValue = 1000;
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.Append('[');
|
||||
buf.Append(lastCid);
|
||||
int state = FIRST;
|
||||
for (int k = start; k < keys.Length; ++k) {
|
||||
int cid = keys[k];
|
||||
int value = v[cid];
|
||||
if (value == 0)
|
||||
continue;
|
||||
int hValue = h[lastCid];
|
||||
if (hValue == 0)
|
||||
hValue = 1000;
|
||||
switch (state) {
|
||||
case FIRST: {
|
||||
if (cid == lastCid + 1 && value == lastValue && hValue == lastHValue) {
|
||||
state = SERIAL;
|
||||
}
|
||||
else {
|
||||
buf.Append(' ').Append(lastCid).Append(' ').Append(-lastValue).Append(' ').Append(lastHValue / 2).Append(' ').Append(V1Y).Append(' ').Append(cid);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SERIAL: {
|
||||
if (cid != lastCid + 1 || value != lastValue || hValue != lastHValue) {
|
||||
buf.Append(' ').Append(lastCid).Append(' ').Append(-lastValue).Append(' ').Append(lastHValue / 2).Append(' ').Append(V1Y).Append(' ').Append(cid);
|
||||
state = FIRST;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
lastValue = value;
|
||||
lastCid = cid;
|
||||
lastHValue = hValue;
|
||||
}
|
||||
buf.Append(' ').Append(lastCid).Append(' ').Append(-lastValue).Append(' ').Append(lastHValue / 2).Append(' ').Append(V1Y).Append(" ]");
|
||||
return buf.ToString();
|
||||
}
|
||||
|
||||
internal static Hashtable ReadFontProperties(String name) {
|
||||
try {
|
||||
name += ".properties";
|
||||
Stream isp = GetResourceStream(RESOURCE_PATH + name);
|
||||
Properties p = new Properties();
|
||||
p.Load(isp);
|
||||
isp.Close();
|
||||
IntHashtable W = CreateMetric(p["W"]);
|
||||
p.Remove("W");
|
||||
IntHashtable W2 = CreateMetric(p["W2"]);
|
||||
p.Remove("W2");
|
||||
Hashtable map = new Hashtable();
|
||||
foreach (string key in p.Keys) {
|
||||
map[key] = p[key];
|
||||
}
|
||||
map["W"] = W;
|
||||
map["W2"] = W2;
|
||||
return map;
|
||||
}
|
||||
catch {
|
||||
// empty on purpose
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public override int GetUnicodeEquivalent(int c) {
|
||||
if (cidDirect)
|
||||
return translationMap[c];
|
||||
return c;
|
||||
}
|
||||
|
||||
public override int GetCidCode(int c) {
|
||||
if (cidDirect)
|
||||
return c;
|
||||
return translationMap[c];
|
||||
}
|
||||
|
||||
public override bool HasKernPairs() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool CharExists(int c) {
|
||||
return translationMap[c] != 0;
|
||||
}
|
||||
|
||||
public override bool SetCharAdvance(int c, int advance) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool SetKerning(int char1, int char2, int kern) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public override int[] GetCharBBox(int c) {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected override int[] GetRawCharBBox(int c, String name) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
112
iTechSharp/iTextSharp/text/pdf/CMYKColor.cs
Normal file
112
iTechSharp/iTextSharp/text/pdf/CMYKColor.cs
Normal file
@@ -0,0 +1,112 @@
|
||||
using System;
|
||||
|
||||
/*
|
||||
* $Id: CMYKColor.cs,v 1.4 2008/05/13 11:25:17 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2001, 2002 by Paulo Soares.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.pdf {
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Paulo Soares (psoares@consiste.pt)
|
||||
*/
|
||||
public class CMYKColor : ExtendedColor {
|
||||
|
||||
float ccyan;
|
||||
float cmagenta;
|
||||
float cyellow;
|
||||
float cblack;
|
||||
|
||||
public CMYKColor(int intCyan, int intMagenta, int intYellow, int intBlack) :
|
||||
this((float)intCyan / 255f, (float)intMagenta / 255f, (float)intYellow / 255f, (float)intBlack / 255f) {}
|
||||
|
||||
public CMYKColor(float floatCyan, float floatMagenta, float floatYellow, float floatBlack) :
|
||||
base(TYPE_CMYK, 1f - floatCyan - floatBlack, 1f - floatMagenta - floatBlack, 1f - floatYellow - floatBlack) {
|
||||
ccyan = Normalize(floatCyan);
|
||||
cmagenta = Normalize(floatMagenta);
|
||||
cyellow = Normalize(floatYellow);
|
||||
cblack = Normalize(floatBlack);
|
||||
}
|
||||
|
||||
public float Cyan {
|
||||
get {
|
||||
return ccyan;
|
||||
}
|
||||
}
|
||||
|
||||
public float Magenta {
|
||||
get {
|
||||
return cmagenta;
|
||||
}
|
||||
}
|
||||
|
||||
public float Yellow {
|
||||
get {
|
||||
return cyellow;
|
||||
}
|
||||
}
|
||||
|
||||
public float Black {
|
||||
get {
|
||||
return cblack;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals(Object obj) {
|
||||
if (!(obj is CMYKColor))
|
||||
return false;
|
||||
CMYKColor c2 = (CMYKColor)obj;
|
||||
return (ccyan == c2.ccyan && cmagenta == c2.cmagenta && cyellow == c2.cyellow && cblack == c2.cblack);
|
||||
}
|
||||
|
||||
public override int GetHashCode() {
|
||||
return ccyan.GetHashCode() ^ cmagenta.GetHashCode() ^ cyellow.GetHashCode() ^ cblack.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
0
iTechSharp/iTextSharp/text/pdf/CodeFile1.cs
Normal file
0
iTechSharp/iTextSharp/text/pdf/CodeFile1.cs
Normal file
107
iTechSharp/iTextSharp/text/pdf/ColorDetails.cs
Normal file
107
iTechSharp/iTextSharp/text/pdf/ColorDetails.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
using System;
|
||||
|
||||
/*
|
||||
* $Id: ColorDetails.cs,v 1.3 2008/05/13 11:25:17 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2001, 2002 by Paulo Soares.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or 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 Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.pdf {
|
||||
|
||||
/** Each spotcolor in the document will have an instance of this class
|
||||
*
|
||||
* @author Phillip Pan (phillip@formstar.com)
|
||||
*/
|
||||
public class ColorDetails {
|
||||
|
||||
/** The indirect reference to this color
|
||||
*/
|
||||
PdfIndirectReference indirectReference;
|
||||
/** The color name that appears in the document body stream
|
||||
*/
|
||||
PdfName colorName;
|
||||
/** The color
|
||||
*/
|
||||
PdfSpotColor spotcolor;
|
||||
|
||||
/** Each spot color used in a document has an instance of this class.
|
||||
* @param colorName the color name
|
||||
* @param indirectReference the indirect reference to the font
|
||||
* @param scolor the <CODE>PDfSpotColor</CODE>
|
||||
*/
|
||||
internal ColorDetails(PdfName colorName, PdfIndirectReference indirectReference, PdfSpotColor scolor) {
|
||||
this.colorName = colorName;
|
||||
this.indirectReference = indirectReference;
|
||||
this.spotcolor = scolor;
|
||||
}
|
||||
|
||||
/** Gets the indirect reference to this color.
|
||||
* @return the indirect reference to this color
|
||||
*/
|
||||
internal PdfIndirectReference IndirectReference {
|
||||
get {
|
||||
return indirectReference;
|
||||
}
|
||||
}
|
||||
|
||||
/** Gets the color name as it appears in the document body.
|
||||
* @return the color name
|
||||
*/
|
||||
internal PdfName ColorName {
|
||||
get {
|
||||
return colorName;
|
||||
}
|
||||
}
|
||||
|
||||
/** Gets the <CODE>SpotColor</CODE> object.
|
||||
* @return the <CODE>PdfSpotColor</CODE>
|
||||
*/
|
||||
internal PdfObject GetSpotColor(PdfWriter writer) {
|
||||
return spotcolor.GetSpotObject(writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user