Initial Commit
This commit is contained in:
commit
c70248a520
BIN
Ionic/Ionic.Zip.dll
Normal file
BIN
Ionic/Ionic.Zip.dll
Normal file
Binary file not shown.
BIN
Ionic/Ionic.Zip.pdb
Normal file
BIN
Ionic/Ionic.Zip.pdb
Normal file
Binary file not shown.
18132
Ionic/Ionic.Zip.xml
Normal file
18132
Ionic/Ionic.Zip.xml
Normal file
File diff suppressed because it is too large
Load Diff
497
RtfConverter/Interpreter/Interpreter/RtfInterpreter.cs
Normal file
497
RtfConverter/Interpreter/Interpreter/RtfInterpreter.cs
Normal file
@ -0,0 +1,497 @@
|
||||
// -- FILE ------------------------------------------------------------------
|
||||
// name : RtfInterpreter.cs
|
||||
// project : RTF Framelet
|
||||
// created : Leon Poyyayil - 2008.05.20
|
||||
// language : c#
|
||||
// environment: .NET 2.0
|
||||
// copyright : (c) 2004-2008 by Itenso GmbH, Switzerland
|
||||
// --------------------------------------------------------------------------
|
||||
using System;
|
||||
using Itenso.Rtf.Model;
|
||||
using Itenso.Rtf.Support;
|
||||
|
||||
namespace Itenso.Rtf.Interpreter
|
||||
{
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
public sealed class RtfInterpreter : RtfInterpreterBase, IRtfElementVisitor
|
||||
{
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
public RtfInterpreter( params IRtfInterpreterListener[] listeners )
|
||||
: base( listeners )
|
||||
{
|
||||
this.fontTableBuilder = new RtfFontTableBuilder( Context.WritableFontTable );
|
||||
this.colorTableBuilder = new RtfColorTableBuilder( Context.WritableColorTable );
|
||||
this.documentInfoBuilder = new RtfDocumentInfoBuilder( Context.WritableDocumentInfo );
|
||||
this.userPropertyBuilder = new RtfUserPropertyBuilder( Context.WritableUserProperties );
|
||||
this.imageBuilder = new RtfImageBuilder();
|
||||
} // RtfInterpreter
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
public bool IsSupportedDocument( IRtfGroup rtfDocument )
|
||||
{
|
||||
try
|
||||
{
|
||||
GetSupportedDocument( rtfDocument );
|
||||
}
|
||||
catch ( RtfException )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} // IsSupportedDocument
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
public IRtfGroup GetSupportedDocument( IRtfGroup rtfDocument )
|
||||
{
|
||||
if ( rtfDocument == null )
|
||||
{
|
||||
throw new RtfException( "document is null" );
|
||||
}
|
||||
if ( rtfDocument.Contents.Count == 0 )
|
||||
{
|
||||
throw new RtfException( "document has not contents" );
|
||||
}
|
||||
IRtfElement firstElement = rtfDocument.Contents[ 0 ];
|
||||
if ( firstElement.Kind != RtfElementKind.Tag )
|
||||
{
|
||||
throw new RtfException( "first element in document is not a tag" );
|
||||
}
|
||||
IRtfTag firstTag = (IRtfTag)firstElement;
|
||||
if ( !RtfSpec.TagRtf.Equals( firstTag.Name ) )
|
||||
{
|
||||
throw new RtfException( "first tag in document is not " + RtfSpec.TagRtf );
|
||||
}
|
||||
if ( !firstTag.HasValue )
|
||||
{
|
||||
throw new RtfException( "unspecified RTF version" );
|
||||
}
|
||||
if ( firstTag.ValueAsNumber != RtfSpec.RtfVersion1 )
|
||||
{
|
||||
throw new RtfException( "unsupported RTF version: " + firstTag.ValueAsText );
|
||||
}
|
||||
return rtfDocument;
|
||||
} // GetSupportedDocument
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
protected override void DoInterpret( IRtfGroup rtfDocument )
|
||||
{
|
||||
InterpretContents( GetSupportedDocument( rtfDocument ) );
|
||||
} // DoInterpret
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
private void InterpretContents( IRtfGroup rtfDocument )
|
||||
{
|
||||
// by getting here we already know that the given document is supported, and hence
|
||||
// we know it has version 1
|
||||
Context.Reset(); // clears all previous content and sets the version to 1
|
||||
NotifyBeginDocument();
|
||||
VisitChildrenOf( rtfDocument );
|
||||
Context.State = RtfInterpreterState.Ended;
|
||||
NotifyEndDocument();
|
||||
} // InterpretContents
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
private void VisitChildrenOf( IRtfGroup group )
|
||||
{
|
||||
bool pushedTextFormat = false;
|
||||
if ( Context.State == RtfInterpreterState.InDocument )
|
||||
{
|
||||
Context.PushCurrentTextFormat();
|
||||
pushedTextFormat = true;
|
||||
}
|
||||
try
|
||||
{
|
||||
foreach ( IRtfElement child in group.Contents )
|
||||
{
|
||||
child.Visit( this );
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if ( pushedTextFormat )
|
||||
{
|
||||
Context.PopCurrentTextFormat();
|
||||
}
|
||||
}
|
||||
} // VisitChildrenOf
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
void IRtfElementVisitor.VisitTag( IRtfTag tag )
|
||||
{
|
||||
if ( Context.State != RtfInterpreterState.InDocument )
|
||||
{
|
||||
if ( Context.FontTable.Count > 0 )
|
||||
{
|
||||
// somewhat of a hack to detect state change from header to in-document for
|
||||
// rtf-docs which do neither have a generator group nor encapsulate the
|
||||
// actual document content in a group.
|
||||
if ( Context.ColorTable.Count > 0 || RtfSpec.TagViewKind.Equals( tag.Name ) )
|
||||
{
|
||||
Context.State = RtfInterpreterState.InDocument;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch ( Context.State )
|
||||
{
|
||||
case RtfInterpreterState.Init:
|
||||
if ( RtfSpec.TagRtf.Equals( tag.Name ) )
|
||||
{
|
||||
Context.State = RtfInterpreterState.InHeader;
|
||||
Context.RtfVersion = tag.ValueAsNumber;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new RtfException( "Init: illegal state for tag '" + tag + "'" );
|
||||
}
|
||||
break;
|
||||
case RtfInterpreterState.InHeader:
|
||||
switch ( tag.Name )
|
||||
{
|
||||
case RtfSpec.TagDefaultFont:
|
||||
Context.DefaultFontId = RtfSpec.TagFont + tag.ValueAsNumber.ToString();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case RtfInterpreterState.InDocument:
|
||||
switch ( tag.Name )
|
||||
{
|
||||
case RtfSpec.TagPlain:
|
||||
Context.WritableCurrentTextFormat =
|
||||
Context.WritableCurrentTextFormat.DeriveNormal();
|
||||
break;
|
||||
case RtfSpec.TagParagraphDefaults:
|
||||
case RtfSpec.TagSectionDefaults:
|
||||
Context.WritableCurrentTextFormat =
|
||||
Context.WritableCurrentTextFormat.DeriveWithAlignment( RtfTextAlignment.Left );
|
||||
break;
|
||||
case RtfSpec.TagBold:
|
||||
bool bold = !tag.HasValue || tag.ValueAsNumber != 0;
|
||||
Context.WritableCurrentTextFormat =
|
||||
Context.WritableCurrentTextFormat.DeriveWithBold( bold );
|
||||
break;
|
||||
case RtfSpec.TagItalic:
|
||||
bool italic = !tag.HasValue || tag.ValueAsNumber != 0;
|
||||
Context.WritableCurrentTextFormat =
|
||||
Context.WritableCurrentTextFormat.DeriveWithItalic( italic );
|
||||
break;
|
||||
case RtfSpec.TagUnderLine:
|
||||
bool underline = !tag.HasValue || tag.ValueAsNumber != 0;
|
||||
Context.WritableCurrentTextFormat =
|
||||
Context.WritableCurrentTextFormat.DeriveWithUnderline( underline );
|
||||
break;
|
||||
case RtfSpec.TagUnderLineNone:
|
||||
Context.WritableCurrentTextFormat =
|
||||
Context.WritableCurrentTextFormat.DeriveWithUnderline( false );
|
||||
break;
|
||||
case RtfSpec.TagStrikeThrough:
|
||||
bool strikeThrough = !tag.HasValue || tag.ValueAsNumber != 0;
|
||||
Context.WritableCurrentTextFormat =
|
||||
Context.WritableCurrentTextFormat.DeriveWithStrikeThrough( strikeThrough );
|
||||
break;
|
||||
case RtfSpec.TagHidden:
|
||||
bool hidden = !tag.HasValue || tag.ValueAsNumber != 0;
|
||||
Context.WritableCurrentTextFormat =
|
||||
Context.WritableCurrentTextFormat.DeriveWithHidden( hidden );
|
||||
break;
|
||||
case RtfSpec.TagFont:
|
||||
string fontId = tag.FullName;
|
||||
if ( Context.FontTable.ContainsFontWithId( fontId ) )
|
||||
{
|
||||
Context.WritableCurrentTextFormat =
|
||||
Context.WritableCurrentTextFormat.DeriveWithFont(
|
||||
Context.FontTable[ fontId ] );
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new RtfException( "undefined font: " + fontId );
|
||||
}
|
||||
break;
|
||||
case RtfSpec.TagFontSize:
|
||||
int fontSize = tag.ValueAsNumber;
|
||||
if ( fontSize > 0 )
|
||||
{
|
||||
Context.WritableCurrentTextFormat =
|
||||
Context.WritableCurrentTextFormat.DeriveWithFontSize( fontSize );
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new RtfException( "invalid font size: " + fontSize );
|
||||
}
|
||||
break;
|
||||
case RtfSpec.TagFontSubscript:
|
||||
Context.WritableCurrentTextFormat =
|
||||
Context.WritableCurrentTextFormat.DeriveWithSuperScript( false );
|
||||
break;
|
||||
case RtfSpec.TagFontSuperscript:
|
||||
Context.WritableCurrentTextFormat =
|
||||
Context.WritableCurrentTextFormat.DeriveWithSuperScript( true );
|
||||
break;
|
||||
case RtfSpec.TagFontNoSuperSub:
|
||||
Context.WritableCurrentTextFormat =
|
||||
Context.WritableCurrentTextFormat.DeriveWithSuperScript( 0 );
|
||||
break;
|
||||
case RtfSpec.TagFontDown:
|
||||
int moveDown = tag.ValueAsNumber;
|
||||
if ( moveDown == -1 )
|
||||
{
|
||||
moveDown = 6; // the default value according to rtf spec
|
||||
}
|
||||
Context.WritableCurrentTextFormat =
|
||||
Context.WritableCurrentTextFormat.DeriveWithSuperScript( -moveDown );
|
||||
break;
|
||||
case RtfSpec.TagFontUp:
|
||||
int moveUp = tag.ValueAsNumber;
|
||||
if ( moveUp == -1 )
|
||||
{
|
||||
moveUp = 6; // the default value according to rtf spec
|
||||
}
|
||||
Context.WritableCurrentTextFormat =
|
||||
Context.WritableCurrentTextFormat.DeriveWithSuperScript( moveUp );
|
||||
break;
|
||||
case RtfSpec.TagAlignLeft:
|
||||
Context.WritableCurrentTextFormat =
|
||||
Context.WritableCurrentTextFormat.DeriveWithAlignment( RtfTextAlignment.Left );
|
||||
break;
|
||||
case RtfSpec.TagAlignCenter:
|
||||
Context.WritableCurrentTextFormat =
|
||||
Context.WritableCurrentTextFormat.DeriveWithAlignment( RtfTextAlignment.Center );
|
||||
break;
|
||||
case RtfSpec.TagAlignRight:
|
||||
Context.WritableCurrentTextFormat =
|
||||
Context.WritableCurrentTextFormat.DeriveWithAlignment( RtfTextAlignment.Right );
|
||||
break;
|
||||
case RtfSpec.TagAlignJustify:
|
||||
Context.WritableCurrentTextFormat =
|
||||
Context.WritableCurrentTextFormat.DeriveWithAlignment( RtfTextAlignment.Justify );
|
||||
break;
|
||||
case RtfSpec.TagColorBackground:
|
||||
case RtfSpec.TagColorBackgroundWord:
|
||||
case RtfSpec.TagColorForeground:
|
||||
int colorIndex = tag.ValueAsNumber;
|
||||
if ( colorIndex >= 0 && colorIndex < Context.ColorTable.Count )
|
||||
{
|
||||
IRtfColor newColor = Context.ColorTable[ colorIndex ];
|
||||
bool isForeground = RtfSpec.TagColorForeground.Equals( tag.Name );
|
||||
Context.WritableCurrentTextFormat = isForeground ?
|
||||
Context.WritableCurrentTextFormat.DeriveWithForegroundColor( newColor ) :
|
||||
Context.WritableCurrentTextFormat.DeriveWithBackgroundColor( newColor );
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new RtfException( "undefined color index: " + colorIndex );
|
||||
}
|
||||
break;
|
||||
case RtfSpec.TagSection:
|
||||
NotifyInsertBreak( RtfVisualBreakKind.Section );
|
||||
break;
|
||||
case RtfSpec.TagParagraph:
|
||||
NotifyInsertBreak( RtfVisualBreakKind.Paragraph );
|
||||
break;
|
||||
case RtfSpec.TagLine:
|
||||
NotifyInsertBreak( RtfVisualBreakKind.Line );
|
||||
break;
|
||||
case RtfSpec.TagPage:
|
||||
NotifyInsertBreak( RtfVisualBreakKind.Page );
|
||||
break;
|
||||
case RtfSpec.TagTabulator:
|
||||
NotifyInsertSpecialChar( RtfVisualSpecialCharKind.Tabulator );
|
||||
break;
|
||||
case RtfSpec.TagTilde:
|
||||
NotifyInsertSpecialChar( RtfVisualSpecialCharKind.NonBreakingSpace );
|
||||
break;
|
||||
case RtfSpec.TagEmDash:
|
||||
NotifyInsertSpecialChar( RtfVisualSpecialCharKind.EmDash );
|
||||
break;
|
||||
case RtfSpec.TagEnDash:
|
||||
NotifyInsertSpecialChar( RtfVisualSpecialCharKind.EnDash );
|
||||
break;
|
||||
case RtfSpec.TagEmSpace:
|
||||
NotifyInsertSpecialChar( RtfVisualSpecialCharKind.EmSpace );
|
||||
break;
|
||||
case RtfSpec.TagEnSpace:
|
||||
NotifyInsertSpecialChar( RtfVisualSpecialCharKind.EnSpace );
|
||||
break;
|
||||
case RtfSpec.TagQmSpace:
|
||||
NotifyInsertSpecialChar( RtfVisualSpecialCharKind.QmSpace );
|
||||
break;
|
||||
case RtfSpec.TagBulltet:
|
||||
NotifyInsertSpecialChar( RtfVisualSpecialCharKind.Bullet );
|
||||
break;
|
||||
case RtfSpec.TagLeftSingleQuote:
|
||||
NotifyInsertSpecialChar( RtfVisualSpecialCharKind.LeftSingleQuote );
|
||||
break;
|
||||
case RtfSpec.TagRightSingleQuote:
|
||||
NotifyInsertSpecialChar( RtfVisualSpecialCharKind.RightSingleQuote );
|
||||
break;
|
||||
case RtfSpec.TagLeftDoubleQuote:
|
||||
NotifyInsertSpecialChar( RtfVisualSpecialCharKind.LeftDoubleQuote );
|
||||
break;
|
||||
case RtfSpec.TagRightDoubleQuote:
|
||||
NotifyInsertSpecialChar( RtfVisualSpecialCharKind.RightDoubleQuote );
|
||||
break;
|
||||
case RtfSpec.TagHyphen:
|
||||
NotifyInsertSpecialChar( RtfVisualSpecialCharKind.OptionalHyphen );
|
||||
break;
|
||||
case RtfSpec.TagUnderscore:
|
||||
NotifyInsertSpecialChar( RtfVisualSpecialCharKind.NonBreakingHyphen );
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
} // IRtfElementVisitor.VisitTag
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
void IRtfElementVisitor.VisitGroup( IRtfGroup group )
|
||||
{
|
||||
string groupDestination = group.Destination;
|
||||
switch ( Context.State )
|
||||
{
|
||||
case RtfInterpreterState.Init:
|
||||
if ( RtfSpec.TagRtf.Equals( groupDestination ) )
|
||||
{
|
||||
VisitChildrenOf( group );
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new RtfException( "Init: illegal state for group '" + groupDestination + "'" );
|
||||
}
|
||||
break;
|
||||
case RtfInterpreterState.InHeader:
|
||||
switch ( groupDestination )
|
||||
{
|
||||
case RtfSpec.TagFontTable:
|
||||
this.fontTableBuilder.VisitGroup( group );
|
||||
break;
|
||||
case RtfSpec.TagColorTable:
|
||||
this.colorTableBuilder.VisitGroup( group );
|
||||
break;
|
||||
case RtfSpec.TagGenerator:
|
||||
// last group with a destination in header, but no need to process its contents
|
||||
Context.State = RtfInterpreterState.InDocument;
|
||||
IRtfText generator = group.Contents.Count == 3 ? group.Contents[ 2 ] as IRtfText : null;
|
||||
if ( generator != null )
|
||||
{
|
||||
string generatorName = generator.Text;
|
||||
Context.Generator = generatorName.EndsWith( ";" ) ?
|
||||
generatorName.Substring( 0, generatorName.Length - 1 ) : generatorName;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new RtfException( "invalid generator group: " + group );
|
||||
}
|
||||
break;
|
||||
case null:
|
||||
// group without destination cannot be part of header, but need to process its contents
|
||||
Context.State = RtfInterpreterState.InDocument;
|
||||
if ( !group.IsExtensionDestination )
|
||||
{
|
||||
VisitChildrenOf( group );
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case RtfInterpreterState.InDocument:
|
||||
switch ( groupDestination )
|
||||
{
|
||||
case RtfSpec.TagUserProperties:
|
||||
this.userPropertyBuilder.VisitGroup( group );
|
||||
break;
|
||||
case RtfSpec.TagInfo:
|
||||
this.documentInfoBuilder.VisitGroup( group );
|
||||
break;
|
||||
case RtfSpec.TagUnicodeAlternativeChoices:
|
||||
IRtfGroup alternativeWithUnicodeSupport =
|
||||
group.SelectChildGroupWithDestination( RtfSpec.TagUnicodeAlternativeUnicode );
|
||||
if ( alternativeWithUnicodeSupport != null )
|
||||
{
|
||||
// there is an alternative with unicode formatted content -> use this
|
||||
VisitChildrenOf( alternativeWithUnicodeSupport );
|
||||
}
|
||||
else
|
||||
{
|
||||
// try to locate the alternative without unicode -> only ANSI fallbacks
|
||||
IRtfGroup alternativeWithoutUnicode = // must be the third element if present
|
||||
group.Contents.Count > 2 ? group.Contents[ 2 ] as IRtfGroup : null;
|
||||
if ( alternativeWithoutUnicode != null )
|
||||
{
|
||||
VisitChildrenOf( alternativeWithoutUnicode );
|
||||
}
|
||||
}
|
||||
break;
|
||||
case RtfSpec.TagHeader:
|
||||
case RtfSpec.TagHeaderFirst:
|
||||
case RtfSpec.TagHeaderLeft:
|
||||
case RtfSpec.TagHeaderRight:
|
||||
case RtfSpec.TagFooter:
|
||||
case RtfSpec.TagFooterFirst:
|
||||
case RtfSpec.TagFooterLeft:
|
||||
case RtfSpec.TagFooterRight:
|
||||
case RtfSpec.TagFootnote:
|
||||
case RtfSpec.TagStyleSheet:
|
||||
// groups we currently ignore, so their content doesn't intermix with
|
||||
// the actual document content
|
||||
break;
|
||||
case RtfSpec.TagPictureWrapper:
|
||||
VisitChildrenOf( group );
|
||||
break;
|
||||
case RtfSpec.TagPicture:
|
||||
this.imageBuilder.VisitGroup( group );
|
||||
NotifyInsertImage(
|
||||
this.imageBuilder.Format,
|
||||
this.imageBuilder.Width,
|
||||
this.imageBuilder.Height,
|
||||
this.imageBuilder.DesiredWidth,
|
||||
this.imageBuilder.DesiredHeight,
|
||||
this.imageBuilder.ScaleWidthPercent,
|
||||
this.imageBuilder.ScaleHeightPercent,
|
||||
this.imageBuilder.ImageDataHex );
|
||||
break;
|
||||
case RtfSpec.TagParagraphNumberText:
|
||||
case RtfSpec.TagListNumberText:
|
||||
NotifyInsertSpecialChar( RtfVisualSpecialCharKind.ParagraphNumberBegin );
|
||||
VisitChildrenOf( group );
|
||||
NotifyInsertSpecialChar( RtfVisualSpecialCharKind.ParagraphNumberEnd );
|
||||
break;
|
||||
default:
|
||||
if ( !group.IsExtensionDestination )
|
||||
{
|
||||
// nested text group
|
||||
VisitChildrenOf( group );
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
} // IRtfElementVisitor.VisitGroup
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
void IRtfElementVisitor.VisitText( IRtfText text )
|
||||
{
|
||||
switch ( Context.State )
|
||||
{
|
||||
case RtfInterpreterState.Init:
|
||||
throw new RtfException( "Init: illegal state for text '" + text.Text + "'" );
|
||||
case RtfInterpreterState.InHeader:
|
||||
Context.State = RtfInterpreterState.InDocument;
|
||||
break;
|
||||
case RtfInterpreterState.InDocument:
|
||||
break;
|
||||
}
|
||||
NotifyInsertText( text.Text );
|
||||
} // IRtfElementVisitor.VisitText
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// members
|
||||
private readonly RtfFontTableBuilder fontTableBuilder;
|
||||
private readonly RtfColorTableBuilder colorTableBuilder;
|
||||
private readonly RtfDocumentInfoBuilder documentInfoBuilder;
|
||||
private readonly RtfUserPropertyBuilder userPropertyBuilder;
|
||||
private readonly RtfImageBuilder imageBuilder;
|
||||
|
||||
} // class RtfInterpreter
|
||||
|
||||
} // namespace Itenso.Rtf.Interpreter
|
||||
// -- EOF -------------------------------------------------------------------
|
133
RtfConverter/Interpreter/Interpreter2005.csproj
Normal file
133
RtfConverter/Interpreter/Interpreter2005.csproj
Normal file
@ -0,0 +1,133 @@
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.50727</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{2A49B537-AFDB-4541-8683-468F2A0BE0AE}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Itenso.Rtf.Interpreter</RootNamespace>
|
||||
<AssemblyName>Itenso.Rtf.Interpreter</AssemblyName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Converter\Image\IRtfConvertedImageInfo.cs" />
|
||||
<Compile Include="Converter\Image\IRtfConvertedImageInfoCollection.cs" />
|
||||
<Compile Include="Converter\Image\IRtfVisualImageAdapter.cs" />
|
||||
<Compile Include="Converter\Image\RtfConvertedImageInfo.cs" />
|
||||
<Compile Include="Converter\Image\RtfConvertedImageInfoCollection.cs" />
|
||||
<Compile Include="Converter\Image\RtfImageConverter.cs" />
|
||||
<Compile Include="Converter\Image\RtfImageConvertSettings.cs" />
|
||||
<Compile Include="Converter\Image\RtfVisualImageAdapter.cs" />
|
||||
<Compile Include="Converter\Text\RtfTextConverter.cs" />
|
||||
<Compile Include="Converter\Text\RtfTextConvertSettings.cs" />
|
||||
<Compile Include="Interpreter\RtfColorTableBuilder.cs" />
|
||||
<Compile Include="Interpreter\RtfDocumentInfoBuilder.cs" />
|
||||
<Compile Include="Interpreter\RtfFontBuilder.cs" />
|
||||
<Compile Include="Interpreter\RtfFontTableBuilder.cs" />
|
||||
<Compile Include="Interpreter\RtfImageBuilder.cs" />
|
||||
<Compile Include="Interpreter\RtfInterpreter.cs" />
|
||||
<Compile Include="Interpreter\RtfInterpreterBase.cs" />
|
||||
<Compile Include="Interpreter\RtfInterpreterContext.cs" />
|
||||
<Compile Include="Interpreter\RtfInterpreterListenerBase.cs" />
|
||||
<Compile Include="Interpreter\RtfInterpreterListenerDocumentBuilder.cs" />
|
||||
<Compile Include="Interpreter\RtfInterpreterListenerFileLogger.cs" />
|
||||
<Compile Include="Interpreter\RtfInterpreterListenerLogger.cs" />
|
||||
<Compile Include="Interpreter\RtfInterpreterLoggerSettings.cs" />
|
||||
<Compile Include="Interpreter\RtfTextBuilder.cs" />
|
||||
<Compile Include="Interpreter\RtfTimestampBuilder.cs" />
|
||||
<Compile Include="Interpreter\RtfUserPropertyBuilder.cs" />
|
||||
<Compile Include="IRtfColor.cs" />
|
||||
<Compile Include="IRtfColorCollection.cs" />
|
||||
<Compile Include="IRtfDocument.cs" />
|
||||
<Compile Include="IRtfDocumentInfo.cs" />
|
||||
<Compile Include="IRtfDocumentProperty.cs" />
|
||||
<Compile Include="IRtfDocumentPropertyCollection.cs" />
|
||||
<Compile Include="IRtfFont.cs" />
|
||||
<Compile Include="IRtfFontCollection.cs" />
|
||||
<Compile Include="IRtfInterpreter.cs" />
|
||||
<Compile Include="IRtfInterpreterContext.cs" />
|
||||
<Compile Include="IRtfInterpreterListener.cs" />
|
||||
<Compile Include="IRtfTextFormat.cs" />
|
||||
<Compile Include="IRtfTextFormatCollection.cs" />
|
||||
<Compile Include="IRtfVisual.cs" />
|
||||
<Compile Include="IRtfVisualBreak.cs" />
|
||||
<Compile Include="IRtfVisualCollection.cs" />
|
||||
<Compile Include="IRtfVisualImage.cs" />
|
||||
<Compile Include="IRtfVisualSpecialChar.cs" />
|
||||
<Compile Include="IRtfVisualText.cs" />
|
||||
<Compile Include="IRtfVisualVisitor.cs" />
|
||||
<Compile Include="Model\RtfColor.cs" />
|
||||
<Compile Include="Model\RtfColorCollection.cs" />
|
||||
<Compile Include="Model\RtfDocument.cs" />
|
||||
<Compile Include="Model\RtfDocumentInfo.cs" />
|
||||
<Compile Include="Model\RtfDocumentProperty.cs" />
|
||||
<Compile Include="Model\RtfDocumentPropertyCollection.cs" />
|
||||
<Compile Include="Model\RtfFont.cs" />
|
||||
<Compile Include="Model\RtfFontCollection.cs" />
|
||||
<Compile Include="Model\RtfTextFormat.cs" />
|
||||
<Compile Include="Model\RtfTextFormatCollection.cs" />
|
||||
<Compile Include="Model\RtfVisual.cs" />
|
||||
<Compile Include="Model\RtfVisualBreak.cs" />
|
||||
<Compile Include="Model\RtfVisualCollection.cs" />
|
||||
<Compile Include="Model\RtfVisualImage.cs" />
|
||||
<Compile Include="Model\RtfVisualSpecialChar.cs" />
|
||||
<Compile Include="Model\RtfVisualText.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Properties\VersionInfo.cs" />
|
||||
<Compile Include="RtfFontKind.cs" />
|
||||
<Compile Include="RtfFontPitch.cs" />
|
||||
<Compile Include="RtfInterpreterState.cs" />
|
||||
<Compile Include="RtfPropertyKind.cs" />
|
||||
<Compile Include="RtfTextAlignment.cs" />
|
||||
<Compile Include="RtfVisualBreakKind.cs" />
|
||||
<Compile Include="RtfVisualImageFormat.cs" />
|
||||
<Compile Include="RtfVisualKind.cs" />
|
||||
<Compile Include="RtfVisualSpecialCharKind.cs" />
|
||||
<Compile Include="Support\RtfElementVisitorBase.cs" />
|
||||
<Compile Include="Support\RtfElementVisitorOrder.cs" />
|
||||
<Compile Include="Support\RtfInterpreterTool.cs" />
|
||||
<Compile Include="Support\RtfVisualVisitorBase.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Parser\Parser2005.csproj">
|
||||
<Project>{6FA3F1A8-4E10-459C-A8DC-C40A90D627B0}</Project>
|
||||
<Name>Parser2005</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Sys\Sys2005.csproj">
|
||||
<Project>{0F203536-FF4F-4783-992D-1DE210C3C485}</Project>
|
||||
<Name>Sys2005</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
79
RtfConverter/Parser/Parser2005.csproj
Normal file
79
RtfConverter/Parser/Parser2005.csproj
Normal file
@ -0,0 +1,79 @@
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.50727</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{6FA3F1A8-4E10-459C-A8DC-C40A90D627B0}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Itenso.Rtf.Parser</RootNamespace>
|
||||
<AssemblyName>Itenso.Rtf.Parser</AssemblyName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="IRtfElement.cs" />
|
||||
<Compile Include="IRtfElementCollection.cs" />
|
||||
<Compile Include="IRtfElementVisitor.cs" />
|
||||
<Compile Include="IRtfGroup.cs" />
|
||||
<Compile Include="IRtfParser.cs" />
|
||||
<Compile Include="IRtfParserListener.cs" />
|
||||
<Compile Include="IRtfSource.cs" />
|
||||
<Compile Include="IRtfTag.cs" />
|
||||
<Compile Include="IRtfText.cs" />
|
||||
<Compile Include="Model\ReadOnlyBaseCollection.cs" />
|
||||
<Compile Include="Model\RtfElement.cs" />
|
||||
<Compile Include="Model\RtfElementCollection.cs" />
|
||||
<Compile Include="Model\RtfGroup.cs" />
|
||||
<Compile Include="Model\RtfTag.cs" />
|
||||
<Compile Include="Model\RtfText.cs" />
|
||||
<Compile Include="Parser\RtfParser.cs" />
|
||||
<Compile Include="Parser\RtfParserBase.cs" />
|
||||
<Compile Include="Parser\RtfParserListenerBase.cs" />
|
||||
<Compile Include="Parser\RtfParserListenerFileLogger.cs" />
|
||||
<Compile Include="Parser\RtfParserListenerLogger.cs" />
|
||||
<Compile Include="Parser\RtfParserListenerStructureBuilder.cs" />
|
||||
<Compile Include="Parser\RtfParserLoggerSettings.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Properties\VersionInfo.cs" />
|
||||
<Compile Include="RtfElementKind.cs" />
|
||||
<Compile Include="RtfException.cs" />
|
||||
<Compile Include="RtfSpec.cs" />
|
||||
<Compile Include="Support\RtfParserTool.cs" />
|
||||
<Compile Include="Support\RtfSource.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Sys\Sys2005.csproj">
|
||||
<Project>{0F203536-FF4F-4783-992D-1DE210C3C485}</Project>
|
||||
<Name>Sys2005</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
BIN
RtfConverter/bin/Debug/Itenso.Rtf.Interpreter.dll
Normal file
BIN
RtfConverter/bin/Debug/Itenso.Rtf.Interpreter.dll
Normal file
Binary file not shown.
BIN
RtfConverter/bin/Debug/Itenso.Rtf.Parser.dll
Normal file
BIN
RtfConverter/bin/Debug/Itenso.Rtf.Parser.dll
Normal file
Binary file not shown.
58
iTechSharp/AssemblyInfo.cs
Normal file
58
iTechSharp/AssemblyInfo.cs
Normal file
@ -0,0 +1,58 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
//
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
//
|
||||
[assembly: AssemblyTitle("iTextSharp")]
|
||||
[assembly: AssemblyDescription("A free PDF library ported from Java iText.")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("")]
|
||||
[assembly: AssemblyCopyright("Copyright (C) 1999-2008 by Bruno Lowagie and Paulo Soares. All Rights Reserved.")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
//
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Revision and Build Numbers
|
||||
// by using the '*' as shown below:
|
||||
|
||||
[assembly: AssemblyVersion("4.1.2")]
|
||||
|
||||
//
|
||||
// In order to sign your assembly you must specify a key to use. Refer to the
|
||||
// Microsoft .NET Framework documentation for more information on assembly signing.
|
||||
//
|
||||
// Use the attributes below to control which key is used for signing.
|
||||
//
|
||||
// Notes:
|
||||
// (*) If no key is specified, the assembly is not signed.
|
||||
// (*) KeyName refers to a key that has been installed in the Crypto Service
|
||||
// Provider (CSP) on your machine. KeyFile refers to a file which contains
|
||||
// a key.
|
||||
// (*) If the KeyFile and the KeyName values are both specified, the
|
||||
// following processing occurs:
|
||||
// (1) If the KeyName can be found in the CSP, that key is used.
|
||||
// (2) If the KeyName does not exist and the KeyFile does exist, the key
|
||||
// in the KeyFile is installed into the CSP and used.
|
||||
// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
|
||||
// When specifying the KeyFile, the location of the KeyFile should be
|
||||
// relative to the project output directory which is
|
||||
// %Project Directory%\obj\<configuration>. For example, if your KeyFile is
|
||||
// located in the project directory, you would specify the AssemblyKeyFile
|
||||
// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
|
||||
// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
|
||||
// documentation for more information on this.
|
||||
//
|
||||
[assembly: AssemblyDelaySign(false)]
|
||||
[assembly: AssemblyKeyFile("..\\..\\itextsharp.snk")]
|
||||
[assembly: AssemblyKeyName("")]
|
158
iTechSharp/System/Drawing/Dimension.cs
Normal file
158
iTechSharp/System/Drawing/Dimension.cs
Normal file
@ -0,0 +1,158 @@
|
||||
using System;
|
||||
|
||||
namespace System.Drawing {
|
||||
/// <summary>
|
||||
/// The <code>Dimension</code> class encapsulates the width and
|
||||
/// height of a component (in int precision) in a single object.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The class is
|
||||
/// associated with certain properties of components. Several methods
|
||||
/// defined by the <code>Component</code> class and the
|
||||
/// <code>LayoutManager</code> interface return a <code>Dimension</code> object.
|
||||
/// <p/>
|
||||
/// Normally the values of <code>width</code>
|
||||
/// and <code>height</code> are non-negative ints.
|
||||
/// The constructors that allow you to create a dimension do
|
||||
/// not prevent you from setting a negative value for these properties.
|
||||
/// If the value of <code>width</code> or <code>height</code> is
|
||||
/// negative, the behavior of some methods defined by other objects is
|
||||
/// undefined.
|
||||
/// </remarks>
|
||||
public class Dimension : Dimension2D {
|
||||
|
||||
/// <summary>
|
||||
/// The width dimension. Negative values can be used.
|
||||
/// </summary>
|
||||
public int width;
|
||||
|
||||
/// <summary>
|
||||
/// The height dimension. Negative values can be used.
|
||||
/// </summary>
|
||||
public int height;
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of <code>Dimension</code> with a width
|
||||
/// of zero and a height of zero.
|
||||
/// </summary>
|
||||
public Dimension() : this(0, 0) {}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of <code>Dimension</code> whose width
|
||||
/// and height are the same as for the specified dimension.
|
||||
/// </summary>
|
||||
/// <param name="d">
|
||||
/// the specified dimension for the
|
||||
/// <code>width</code> and
|
||||
/// <code>height</code> values.
|
||||
/// </param>
|
||||
public Dimension(Dimension d) : this(d.width, d.height) {}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Dimension and initializes it to the specified width and
|
||||
/// specified height.
|
||||
/// </summary>
|
||||
/// <param name="width">the specified width dimension</param>
|
||||
/// <param name="height">the specified height dimension</param>
|
||||
public Dimension(int width, int height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the width of this dimension in double precision.
|
||||
/// </summary>
|
||||
/// <value>the width</value>
|
||||
public override double Width {
|
||||
get {
|
||||
return width;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the height of this dimension in double precision.
|
||||
/// </summary>
|
||||
/// <value>the height</value>
|
||||
public override double Height {
|
||||
get {
|
||||
return height;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the size of this Dimension object to the specified width
|
||||
/// and height in double precision.
|
||||
/// </summary>
|
||||
/// <param name="width">the new width for the Dimension object</param>
|
||||
/// <param name="height">the new height for the Dimension object</param>
|
||||
public override void SetSize(double width, double height) {
|
||||
width = (int) Math.Ceiling(width);
|
||||
height = (int) Math.Ceiling(height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get/set the size of this <code>Dimension</code> object.
|
||||
/// </summary>
|
||||
/// <value>the size</value>
|
||||
public new Dimension Size {
|
||||
get {
|
||||
return new Dimension(width, height);
|
||||
}
|
||||
|
||||
set {
|
||||
SetSize(value.width, value.height);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the size of this <code>Dimension</code> object
|
||||
/// to the specified width and height.
|
||||
/// </summary>
|
||||
/// <param name="width">the new width for this <code>Dimension</code> object.</param>
|
||||
/// <param name="height">the new height for this <code>Dimension</code> object.</param>
|
||||
public void SetSize(int width, int height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether two dimension objects have equal values.
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
public override bool Equals(Object obj) {
|
||||
if (obj is Dimension) {
|
||||
Dimension d = (Dimension)obj;
|
||||
return (width == d.width) && (height == d.height);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the hash code for this Dimension.
|
||||
/// </summary>
|
||||
/// <returns>a hash code</returns>
|
||||
public override int GetHashCode() {
|
||||
int sum = width + height;
|
||||
return sum * (sum + 1)/2 + width;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string representation of the values of this
|
||||
/// <code>Dimension</code> object's <code>height</code> and
|
||||
/// <code>width</code> fields.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method is intended to be used only
|
||||
/// for debugging purposes, and the content and format of the returned
|
||||
/// string may vary between implementations. The returned string may be
|
||||
/// empty but may not be <code>null</code>.
|
||||
/// </remarks>
|
||||
/// <returns>a string representation of this <code>Dimension</code>
|
||||
/// object.
|
||||
/// </returns>
|
||||
public override string ToString() {
|
||||
return this.GetType().Name + "[width=" + width + ",height=" + height + "]";
|
||||
}
|
||||
}
|
||||
}
|
69
iTechSharp/System/Drawing/Dimension2D.cs
Normal file
69
iTechSharp/System/Drawing/Dimension2D.cs
Normal file
@ -0,0 +1,69 @@
|
||||
using System;
|
||||
|
||||
namespace System.Drawing {
|
||||
/// <summary>
|
||||
/// The <code>Dimension2D</code> class is to encapsulate a width
|
||||
/// and a height dimension.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This class is only the abstract baseclass for all objects that
|
||||
/// store a 2D dimension.
|
||||
/// The actual storage representation of the sizes is left to
|
||||
/// the subclass.
|
||||
/// </remarks>
|
||||
public abstract class Dimension2D : ICloneable {
|
||||
/// <summary>
|
||||
/// This is an abstract class that cannot be instantiated directly.
|
||||
/// Type-specific implementation subclasses are available for
|
||||
/// instantiation and provide a number of formats for storing
|
||||
/// the information necessary to satisfy the various accessor
|
||||
/// methods below.
|
||||
/// </summary>
|
||||
/// <seealso cref="T:System.Drawing.Dimension"/>
|
||||
protected Dimension2D() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the width of this <code>Dimension</code> in double
|
||||
/// precision.
|
||||
/// </summary>
|
||||
/// <value>the width</value>
|
||||
public abstract double Width {get;}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the height of this <code>Dimension</code> in double
|
||||
/// precision.
|
||||
/// </summary>
|
||||
/// <value>the height</value>
|
||||
public abstract double Height {get;}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the size of this <code>Dimension</code> object to the
|
||||
/// specified width and height.
|
||||
/// </summary>
|
||||
/// <param name="width">the new width for the <code>Dimension</code>
|
||||
/// object</param>
|
||||
/// <param name="height">the new height for the <code>Dimension</code>
|
||||
/// object</param>
|
||||
public abstract void SetSize(double width, double height);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the size of this <code>Dimension2D</code> object to
|
||||
/// match the specified size.
|
||||
/// </summary>
|
||||
/// <value>the size</value>
|
||||
public Dimension2D Size {
|
||||
set {
|
||||
SetSize(value.Width, value.Height);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new object of the same class as this object.
|
||||
/// </summary>
|
||||
/// <returns>a clone of this instance</returns>
|
||||
public Object Clone() {
|
||||
throw new Exception("not implemented");
|
||||
}
|
||||
}
|
||||
}
|
43
iTechSharp/System/util/ListIterator.cs
Normal file
43
iTechSharp/System/util/ListIterator.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace System.util {
|
||||
/// <summary>
|
||||
/// Summary description for ListIterator.
|
||||
/// </summary>
|
||||
public class ListIterator {
|
||||
ArrayList col;
|
||||
int cursor = 0;
|
||||
int lastRet = -1;
|
||||
|
||||
public ListIterator(ArrayList col) {
|
||||
this.col = col;
|
||||
}
|
||||
|
||||
public bool HasNext() {
|
||||
return cursor != col.Count;
|
||||
}
|
||||
|
||||
public object Next() {
|
||||
Object next = col[cursor];
|
||||
lastRet = cursor++;
|
||||
return next;
|
||||
}
|
||||
|
||||
public object Previous() {
|
||||
int i = cursor - 1;
|
||||
Object previous = col[i];
|
||||
lastRet = cursor = i;
|
||||
return previous;
|
||||
}
|
||||
|
||||
public void Remove() {
|
||||
if (lastRet == -1)
|
||||
throw new InvalidOperationException();
|
||||
col.RemoveAt(lastRet);
|
||||
if (lastRet < cursor)
|
||||
cursor--;
|
||||
lastRet = -1;
|
||||
}
|
||||
}
|
||||
}
|
209
iTechSharp/System/util/Properties.cs
Normal file
209
iTechSharp/System/util/Properties.cs
Normal file
@ -0,0 +1,209 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
|
||||
namespace System.util
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for Properties.
|
||||
/// </summary>
|
||||
public class Properties
|
||||
{
|
||||
private Hashtable _col;
|
||||
private const string whiteSpaceChars = " \t\r\n\f";
|
||||
private const string keyValueSeparators = "=: \t\r\n\f";
|
||||
private const string strictKeyValueSeparators = "=:";
|
||||
|
||||
public Properties()
|
||||
{
|
||||
_col = new Hashtable();
|
||||
}
|
||||
|
||||
public string Remove(string key) {
|
||||
string retval = (string)_col[key];
|
||||
_col.Remove(key);
|
||||
return retval;
|
||||
}
|
||||
|
||||
public IEnumerator GetEnumerator() {
|
||||
return _col.GetEnumerator();
|
||||
}
|
||||
|
||||
public bool ContainsKey(string key) {
|
||||
return _col.ContainsKey(key);
|
||||
}
|
||||
|
||||
public virtual void Add(string key, string value) {
|
||||
_col[key] = value;
|
||||
}
|
||||
|
||||
public void AddAll(Properties col) {
|
||||
foreach (string itm in col.Keys) {
|
||||
_col[itm] = col[itm];
|
||||
}
|
||||
}
|
||||
|
||||
public int Count {
|
||||
get {
|
||||
return _col.Count;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual string this[string key] {
|
||||
get {
|
||||
return (string)_col[key];
|
||||
}
|
||||
|
||||
set {
|
||||
_col[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public ICollection Keys {
|
||||
get {
|
||||
return _col.Keys;
|
||||
}
|
||||
}
|
||||
|
||||
public void Clear() {
|
||||
_col.Clear();
|
||||
}
|
||||
|
||||
public void Load(Stream inStream) {
|
||||
StreamReader inp = new StreamReader(inStream, Encoding.GetEncoding(1252));
|
||||
while (true) {
|
||||
// Get next line
|
||||
String line = inp.ReadLine();
|
||||
if (line == null)
|
||||
return;
|
||||
|
||||
if (line.Length > 0) {
|
||||
|
||||
// Find start of key
|
||||
int len = line.Length;
|
||||
int keyStart;
|
||||
for (keyStart=0; keyStart<len; keyStart++)
|
||||
if (whiteSpaceChars.IndexOf(line[keyStart]) == -1)
|
||||
break;
|
||||
|
||||
// Blank lines are ignored
|
||||
if (keyStart == len)
|
||||
continue;
|
||||
|
||||
// Continue lines that end in slashes if they are not comments
|
||||
char firstChar = line[keyStart];
|
||||
if ((firstChar != '#') && (firstChar != '!')) {
|
||||
while (ContinueLine(line)) {
|
||||
String nextLine = inp.ReadLine();
|
||||
if (nextLine == null)
|
||||
nextLine = "";
|
||||
String loppedLine = line.Substring(0, len-1);
|
||||
// Advance beyond whitespace on new line
|
||||
int startIndex;
|
||||
for (startIndex=0; startIndex<nextLine.Length; startIndex++)
|
||||
if (whiteSpaceChars.IndexOf(nextLine[startIndex]) == -1)
|
||||
break;
|
||||
nextLine = nextLine.Substring(startIndex,nextLine.Length - startIndex);
|
||||
line = loppedLine+nextLine;
|
||||
len = line.Length;
|
||||
}
|
||||
|
||||
// Find separation between key and value
|
||||
int separatorIndex;
|
||||
for (separatorIndex=keyStart; separatorIndex<len; separatorIndex++) {
|
||||
char currentChar = line[separatorIndex];
|
||||
if (currentChar == '\\')
|
||||
separatorIndex++;
|
||||
else if (keyValueSeparators.IndexOf(currentChar) != -1)
|
||||
break;
|
||||
}
|
||||
|
||||
// Skip over whitespace after key if any
|
||||
int valueIndex;
|
||||
for (valueIndex=separatorIndex; valueIndex<len; valueIndex++)
|
||||
if (whiteSpaceChars.IndexOf(line[valueIndex]) == -1)
|
||||
break;
|
||||
|
||||
// Skip over one non whitespace key value separators if any
|
||||
if (valueIndex < len)
|
||||
if (strictKeyValueSeparators.IndexOf(line[valueIndex]) != -1)
|
||||
valueIndex++;
|
||||
|
||||
// Skip over white space after other separators if any
|
||||
while (valueIndex < len) {
|
||||
if (whiteSpaceChars.IndexOf(line[valueIndex]) == -1)
|
||||
break;
|
||||
valueIndex++;
|
||||
}
|
||||
String key = line.Substring(keyStart, separatorIndex - keyStart);
|
||||
String value = (separatorIndex < len) ? line.Substring(valueIndex, len - valueIndex) : "";
|
||||
|
||||
// Convert then store key and value
|
||||
key = LoadConvert(key);
|
||||
value = LoadConvert(value);
|
||||
Add(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Converts encoded \uxxxx to unicode chars
|
||||
* and changes special saved chars to their original forms
|
||||
*/
|
||||
private String LoadConvert(String theString) {
|
||||
char aChar;
|
||||
int len = theString.Length;
|
||||
StringBuilder outBuffer = new StringBuilder(len);
|
||||
|
||||
for (int x=0; x<len; ) {
|
||||
aChar = theString[x++];
|
||||
if (aChar == '\\') {
|
||||
aChar = theString[x++];
|
||||
if (aChar == 'u') {
|
||||
// Read the xxxx
|
||||
int value=0;
|
||||
for (int i=0; i<4; i++) {
|
||||
aChar = theString[x++];
|
||||
switch (aChar) {
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
value = (value << 4) + aChar - '0';
|
||||
break;
|
||||
case 'a': case 'b': case 'c':
|
||||
case 'd': case 'e': case 'f':
|
||||
value = (value << 4) + 10 + aChar - 'a';
|
||||
break;
|
||||
case 'A': case 'B': case 'C':
|
||||
case 'D': case 'E': case 'F':
|
||||
value = (value << 4) + 10 + aChar - 'A';
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException(
|
||||
"Malformed \\uxxxx encoding.");
|
||||
}
|
||||
}
|
||||
outBuffer.Append((char)value);
|
||||
} else {
|
||||
if (aChar == 't') aChar = '\t';
|
||||
else if (aChar == 'r') aChar = '\r';
|
||||
else if (aChar == 'n') aChar = '\n';
|
||||
else if (aChar == 'f') aChar = '\f';
|
||||
outBuffer.Append(aChar);
|
||||
}
|
||||
} else
|
||||
outBuffer.Append(aChar);
|
||||
}
|
||||
return outBuffer.ToString();
|
||||
}
|
||||
|
||||
private bool ContinueLine(String line) {
|
||||
int slashCount = 0;
|
||||
int index = line.Length - 1;
|
||||
while ((index >= 0) && (line[index--] == '\\'))
|
||||
slashCount++;
|
||||
return (slashCount % 2 == 1);
|
||||
}
|
||||
}
|
||||
}
|
130
iTechSharp/System/util/StringTokenizer.cs
Normal file
130
iTechSharp/System/util/StringTokenizer.cs
Normal file
@ -0,0 +1,130 @@
|
||||
using System;
|
||||
/*
|
||||
* $Id: StringTokenizer.cs,v 1.4 2006/06/16 10:52:26 psoares33 Exp $
|
||||
*
|
||||
* Copyright 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 isp 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 isp 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code isp 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 isp 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 isp 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 isp 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 System.util {
|
||||
|
||||
// a replacement for the StringTokenizer java class
|
||||
// it's more or less the same as the one in the GNU classpath
|
||||
public class StringTokenizer {
|
||||
private int pos;
|
||||
private String str;
|
||||
private int len;
|
||||
private String delim;
|
||||
private bool retDelims;
|
||||
|
||||
public StringTokenizer(String str) : this(str, " \t\n\r\f", false) {
|
||||
}
|
||||
|
||||
public StringTokenizer(String str, String delim) : this(str, delim, false) {
|
||||
}
|
||||
|
||||
public StringTokenizer(String str, String delim, bool retDelims) {
|
||||
len = str.Length;
|
||||
this.str = str;
|
||||
this.delim = delim;
|
||||
this.retDelims = retDelims;
|
||||
this.pos = 0;
|
||||
}
|
||||
|
||||
public bool HasMoreTokens() {
|
||||
if (! retDelims) {
|
||||
while (pos < len && delim.IndexOf(str[pos]) >= 0)
|
||||
pos++;
|
||||
}
|
||||
return pos < len;
|
||||
}
|
||||
|
||||
public String NextToken(String delim) {
|
||||
this.delim = delim;
|
||||
return NextToken();
|
||||
}
|
||||
|
||||
public String NextToken() {
|
||||
if (pos < len && delim.IndexOf(str[pos]) >= 0) {
|
||||
if (retDelims)
|
||||
return str.Substring(pos++, 1);
|
||||
while (++pos < len && delim.IndexOf(str[pos]) >= 0);
|
||||
}
|
||||
if (pos < len) {
|
||||
int start = pos;
|
||||
while (++pos < len && delim.IndexOf(str[pos]) < 0);
|
||||
|
||||
return str.Substring(start, pos - start);
|
||||
}
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
|
||||
public int CountTokens() {
|
||||
int count = 0;
|
||||
int delimiterCount = 0;
|
||||
bool tokenFound = false;
|
||||
int tmpPos = pos;
|
||||
|
||||
while (tmpPos < len) {
|
||||
if (delim.IndexOf(str[tmpPos++]) >= 0) {
|
||||
if (tokenFound) {
|
||||
count++;
|
||||
tokenFound = false;
|
||||
}
|
||||
delimiterCount++;
|
||||
}
|
||||
else {
|
||||
tokenFound = true;
|
||||
while (tmpPos < len
|
||||
&& delim.IndexOf(str[tmpPos]) < 0)
|
||||
++tmpPos;
|
||||
}
|
||||
}
|
||||
if (tokenFound)
|
||||
count++;
|
||||
return retDelims ? count + delimiterCount : count;
|
||||
}
|
||||
}
|
||||
}
|
27
iTechSharp/System/util/Util.cs
Normal file
27
iTechSharp/System/util/Util.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
namespace System.util
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for Util.
|
||||
/// </summary>
|
||||
public class Util
|
||||
{
|
||||
public static int USR(int op1, int op2) {
|
||||
if (op2 < 1) {
|
||||
return op1;
|
||||
} else {
|
||||
return unchecked((int)((uint)op1 >> op2));
|
||||
}
|
||||
}
|
||||
|
||||
public static bool EqualsIgnoreCase(string s1, string s2) {
|
||||
return CultureInfo.InvariantCulture.CompareInfo.Compare(s1, s2, CompareOptions.IgnoreCase) == 0;
|
||||
}
|
||||
|
||||
public static int CompareToIgnoreCase(string s1, string s2) {
|
||||
return CultureInfo.InvariantCulture.CompareInfo.Compare(s1, s2, CompareOptions.IgnoreCase);
|
||||
}
|
||||
}
|
||||
}
|
49
iTechSharp/System/util/collections/Algorithm.cs
Normal file
49
iTechSharp/System/util/collections/Algorithm.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using System;
|
||||
|
||||
namespace System.util.collections
|
||||
{
|
||||
/// <summary>
|
||||
/// Very basic algorithms tool class.
|
||||
/// </summary>
|
||||
public class k_Algorithm
|
||||
{
|
||||
public static k_Iterator Copy(k_Iterator ak_SrcFirst, k_Iterator ak_BehindSrcLast, k_Iterator ak_DstFirst)
|
||||
{
|
||||
k_Iterator lk_Src = ak_SrcFirst.Clone(), lk_Dst = ak_DstFirst.Clone();
|
||||
while (lk_Src != ak_BehindSrcLast)
|
||||
{
|
||||
lk_Dst.Current = lk_Src.Current;
|
||||
lk_Src.Next(); lk_Dst.Next();
|
||||
}
|
||||
return lk_Dst;
|
||||
}
|
||||
|
||||
public static k_Iterator CopyBackward(k_Iterator ak_SrcFirst, k_Iterator ak_BehindSrcLast, k_Iterator ak_BehindDstLast)
|
||||
{
|
||||
k_Iterator lk_Src = ak_BehindSrcLast.Clone(), lk_Dst = ak_BehindDstLast.Clone();
|
||||
while (lk_Src != ak_SrcFirst)
|
||||
{
|
||||
lk_Src.Prev(); lk_Dst.Prev();
|
||||
lk_Dst.Current = lk_Src.Current;
|
||||
}
|
||||
return lk_Dst;
|
||||
}
|
||||
|
||||
public static void Fill(k_Iterator ak_DstFirst, k_Iterator ak_BehindDstLast, object ak_Value)
|
||||
{
|
||||
for (k_Iterator lk_Iter = ak_DstFirst.Clone(); lk_Iter != ak_BehindDstLast; lk_Iter.Next())
|
||||
lk_Iter.Current = ak_Value;
|
||||
}
|
||||
|
||||
public static k_Iterator Find(k_Iterator ak_First, k_Iterator ak_Last, object ak_Value)
|
||||
{
|
||||
k_Iterator lk_Iter = ak_First.Clone();
|
||||
for (; lk_Iter != ak_Last; lk_Iter.Next())
|
||||
{
|
||||
if (object.Equals(lk_Iter.Current, ak_Value))
|
||||
break;
|
||||
}
|
||||
return lk_Iter;
|
||||
}
|
||||
}
|
||||
}
|
64
iTechSharp/System/util/collections/Container.cs
Normal file
64
iTechSharp/System/util/collections/Container.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace System.util.collections
|
||||
{
|
||||
/// <summary>
|
||||
/// Base interface for all containers
|
||||
/// </summary>
|
||||
public interface IContainer : ICollection, ICloneable
|
||||
{
|
||||
k_Iterator Begin { get; }
|
||||
k_Iterator End { get; }
|
||||
|
||||
bool IsEmpty { get; }
|
||||
|
||||
k_Iterator Find(object ak_Value);
|
||||
|
||||
k_Iterator Erase(k_Iterator ak_Where);
|
||||
k_Iterator Erase(k_Iterator ak_First, k_Iterator ak_Last);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Interface for non-associative sequential containers (k_Vector, k_Deque, k_List)
|
||||
/// </summary>
|
||||
public interface ISequence : IContainer, IList
|
||||
{
|
||||
object Front { get; set; }
|
||||
object Back { get; set; }
|
||||
|
||||
void PushFront(object ak_Value);
|
||||
void PopFront();
|
||||
|
||||
void PushBack(object ak_Value);
|
||||
void PopBack();
|
||||
|
||||
void Assign(k_Iterator ak_SrcBegin, k_Iterator ak_SrcEnd);
|
||||
void Assign(object ak_Value, int ai_Count);
|
||||
|
||||
void Insert(k_Iterator ak_Where, object ak_Value);
|
||||
void Insert(k_Iterator ak_Where, k_Iterator ak_SrcBegin, k_Iterator ak_SrcEnd);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Interface for IDictionary derived containers which provide key to value mapping (k_HashTable)
|
||||
/// </summary>
|
||||
public interface IMap : IContainer, IDictionary
|
||||
{
|
||||
k_Iterator FindKey(object ak_Key);
|
||||
|
||||
void Add(DictionaryEntry ar_Item);
|
||||
void Insert(k_Iterator ak_SrcBegin, k_Iterator ak_SrcEnd);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Interface for sorted mapping containers (k_SkipList, k_Tree)
|
||||
/// </summary>
|
||||
public interface ISortedMap : IMap
|
||||
{
|
||||
IComparer Comparer { get; }
|
||||
|
||||
k_Iterator LowerBound(object ak_Key);
|
||||
k_Iterator UpperBound(object ak_Key);
|
||||
}
|
||||
}
|
470
iTechSharp/System/util/collections/Deque.cs
Normal file
470
iTechSharp/System/util/collections/Deque.cs
Normal file
@ -0,0 +1,470 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace System.util.collections
|
||||
{
|
||||
/// <summary>
|
||||
/// Circular buffer of arrays
|
||||
/// </summary>
|
||||
public class k_Deque : ISequence
|
||||
{
|
||||
#region k_BlockIterator Implementation
|
||||
|
||||
private class k_BlockIterator : k_Iterator
|
||||
{
|
||||
private readonly k_Deque mk_Deque;
|
||||
private int mi_Index;
|
||||
private int mi_BlockIndex;
|
||||
private int mi_BlockOffset;
|
||||
|
||||
public k_BlockIterator(k_Deque ak_Deque, int ai_Index)
|
||||
{
|
||||
mk_Deque = ak_Deque;
|
||||
mi_Index = ai_Index;
|
||||
mi_BlockIndex = mk_Deque.CalcBlockAndPos(mi_Index, out mi_BlockOffset);
|
||||
}
|
||||
|
||||
public override void Move(int ai_Count)
|
||||
{
|
||||
int li_Index = mi_Index + ai_Count;
|
||||
|
||||
if (li_Index > mk_Deque.Count)
|
||||
throw new InvalidOperationException("Tried to move beyond end element.");
|
||||
else if (li_Index < 0)
|
||||
throw new InvalidOperationException("Tried to move before first element.");
|
||||
|
||||
mi_Index = li_Index;
|
||||
mi_BlockOffset += ai_Count;
|
||||
|
||||
if (mi_BlockOffset >= k_Deque.mi_BlockSize || mi_BlockOffset < 0)
|
||||
mi_BlockIndex = mk_Deque.CalcBlockAndPos(mi_Index, out mi_BlockOffset);
|
||||
}
|
||||
|
||||
public override int Distance(k_Iterator ak_Iter)
|
||||
{
|
||||
return mi_Index - ((k_BlockIterator)ak_Iter).mi_Index;
|
||||
}
|
||||
|
||||
public override object Collection
|
||||
{
|
||||
get { return mk_Deque; }
|
||||
}
|
||||
|
||||
public override object Current
|
||||
{
|
||||
get
|
||||
{
|
||||
if (mi_Index < 0 || mi_Index >= mk_Deque.mi_Count)
|
||||
throw new k_InvalidPositionException();
|
||||
return mk_Deque.mk_Blocks[mi_BlockIndex][mi_BlockOffset];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (mi_Index < 0 || mi_Index >= mk_Deque.mi_Count)
|
||||
throw new k_InvalidPositionException();
|
||||
mk_Deque.mk_Blocks[mi_BlockIndex][mi_BlockOffset] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals(object ak_Obj)
|
||||
{
|
||||
k_BlockIterator lk_Iter = ak_Obj as k_BlockIterator;
|
||||
if (lk_Iter == null)
|
||||
return false;
|
||||
|
||||
return (mi_Index == lk_Iter.mi_Index) && object.ReferenceEquals(this.Collection, lk_Iter.Collection);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return mk_Deque.GetHashCode() ^ mi_Index;
|
||||
}
|
||||
|
||||
public override k_Iterator Clone()
|
||||
{
|
||||
return new k_BlockIterator(mk_Deque, mi_Index);
|
||||
}
|
||||
|
||||
internal int Index
|
||||
{
|
||||
get { return mi_Index; }
|
||||
}
|
||||
}
|
||||
|
||||
private class k_PinnedBlockIterator : k_BlockIterator
|
||||
{
|
||||
public k_PinnedBlockIterator(k_Deque ak_Deque, int ai_Index)
|
||||
: base(ak_Deque, ai_Index)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Move(int ai_Count)
|
||||
{
|
||||
throw new k_IteratorPinnedException();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private const int mi_BlockSize = 16;
|
||||
private object[][] mk_Blocks;
|
||||
|
||||
private int mi_Offset;
|
||||
private int mi_Count;
|
||||
|
||||
public k_Deque()
|
||||
: this(mi_BlockSize)
|
||||
{
|
||||
}
|
||||
|
||||
public k_Deque(int ai_Capacity)
|
||||
{
|
||||
if (ai_Capacity < 0)
|
||||
throw new ArgumentException("Capacity must be positive.", "ai_Capacity");
|
||||
mk_Blocks = new object[(ai_Capacity+mi_BlockSize-1)/mi_BlockSize][];
|
||||
for (int i=0; i<mk_Blocks.Length; ++i)
|
||||
mk_Blocks[i] = new object[mi_BlockSize];
|
||||
}
|
||||
|
||||
// IContainer Members
|
||||
public k_Iterator Begin
|
||||
{
|
||||
get { return new k_PinnedBlockIterator(this, 0); }
|
||||
}
|
||||
|
||||
public k_Iterator End
|
||||
{
|
||||
get { return new k_PinnedBlockIterator(this, mi_Count); }
|
||||
}
|
||||
|
||||
public bool IsEmpty
|
||||
{
|
||||
get { return (this.Count == 0); }
|
||||
}
|
||||
|
||||
public k_Iterator Find(object ak_Value)
|
||||
{
|
||||
return k_Algorithm.Find(this.Begin, this.End, ak_Value);
|
||||
}
|
||||
|
||||
public k_Iterator Erase(k_Iterator ak_Where)
|
||||
{
|
||||
return Erase(ak_Where, ak_Where + 1);
|
||||
}
|
||||
|
||||
public k_Iterator Erase(k_Iterator ak_First, k_Iterator ak_Last)
|
||||
{
|
||||
if (ak_First == ak_Last)
|
||||
return ak_Last;
|
||||
|
||||
int li_FirstIndex = ((k_BlockIterator)ak_First).Index;
|
||||
int li_Count = ak_Last - ak_First;
|
||||
int li_LastCount = this.End - ak_Last;
|
||||
|
||||
if (li_FirstIndex < li_LastCount)
|
||||
{
|
||||
k_Algorithm.CopyBackward(this.Begin, ak_First, ak_Last);
|
||||
k_Algorithm.Fill(this.Begin, ak_First, null);
|
||||
mi_Offset += li_Count;
|
||||
mi_Offset %= (mk_Blocks.Length * mi_BlockSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
k_Algorithm.Copy(ak_Last, this.End, ak_First);
|
||||
k_Algorithm.Fill(ak_Last, this.End, null);
|
||||
}
|
||||
|
||||
mi_Count -= li_Count;
|
||||
|
||||
return new k_BlockIterator(this, li_FirstIndex);
|
||||
}
|
||||
|
||||
// ISequence Members
|
||||
public object Front
|
||||
{
|
||||
get { return this.Begin.Current; }
|
||||
set { this.Begin.Current = value; }
|
||||
}
|
||||
|
||||
public object Back
|
||||
{
|
||||
get { return (this.End-1).Current; }
|
||||
set { (this.End-1).Current = value; }
|
||||
}
|
||||
|
||||
public void PushFront(object ak_Value)
|
||||
{
|
||||
if (mi_Offset % mi_BlockSize == 0 // currently on block boundary
|
||||
&& mk_Blocks.Length * mi_BlockSize - mi_Count < mi_BlockSize)
|
||||
{
|
||||
AllocateBlock(mi_BlockSize);
|
||||
}
|
||||
|
||||
if (mi_Offset == 0)
|
||||
mi_Offset = mk_Blocks.Length * mi_BlockSize;
|
||||
--mi_Offset;
|
||||
mk_Blocks[mi_Offset/mi_BlockSize][mi_Offset%mi_BlockSize] = ak_Value;
|
||||
++mi_Count;
|
||||
}
|
||||
|
||||
public void PopFront()
|
||||
{
|
||||
Erase(this.Begin);
|
||||
}
|
||||
|
||||
public void PushBack(object ak_Value)
|
||||
{
|
||||
if ((mi_Offset+mi_Count) % mi_BlockSize == 0 // currently on block boundary
|
||||
&& mk_Blocks.Length * mi_BlockSize - mi_Count < mi_BlockSize)
|
||||
{
|
||||
AllocateBlock(mi_BlockSize);
|
||||
}
|
||||
|
||||
int li_Pos = mi_Offset + mi_Count;
|
||||
int li_Block = li_Pos/mi_BlockSize;
|
||||
if (li_Block >= mk_Blocks.Length)
|
||||
li_Block -= mk_Blocks.Length;
|
||||
mk_Blocks[li_Block][li_Pos%mi_BlockSize] = ak_Value;
|
||||
++mi_Count;
|
||||
}
|
||||
|
||||
public void PopBack()
|
||||
{
|
||||
Erase(this.End-1);
|
||||
}
|
||||
|
||||
public void Assign(k_Iterator ak_SrcBegin, k_Iterator ak_SrcEnd)
|
||||
{
|
||||
Clear();
|
||||
Insert(this.End, ak_SrcBegin, ak_SrcEnd);
|
||||
}
|
||||
|
||||
public void Assign(object ak_Value, int ai_Count)
|
||||
{
|
||||
Clear();
|
||||
for (int i = 0; i < ai_Count; ++i)
|
||||
Insert(this.End, ak_Value);
|
||||
}
|
||||
|
||||
public void Insert(k_Iterator ak_Where, object ak_Value)
|
||||
{
|
||||
if (ak_Where == this.Begin)
|
||||
PushFront(ak_Value);
|
||||
else if (ak_Where == this.End)
|
||||
PushBack(ak_Value);
|
||||
else
|
||||
{
|
||||
int li_Index = ((k_BlockIterator)ak_Where).Index;
|
||||
if (mk_Blocks.Length * mi_BlockSize - mi_Count < mi_BlockSize)
|
||||
AllocateBlock(mi_BlockSize);
|
||||
|
||||
++mi_Count;
|
||||
if (li_Index < mi_Count/2)
|
||||
{
|
||||
if (mi_Offset == 0)
|
||||
mi_Offset = mk_Blocks.Length * mi_BlockSize;
|
||||
--mi_Offset;
|
||||
k_Iterator lk_Dest = k_Algorithm.Copy(this.Begin+1, this.Begin+li_Index+1, this.Begin);
|
||||
lk_Dest.Current = ak_Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
// count has been incremented - there is a free element at the end
|
||||
k_Iterator lk_Dest = this.Begin + li_Index;
|
||||
k_Algorithm.CopyBackward(lk_Dest, this.End - 1, this.End);
|
||||
lk_Dest.Current = ak_Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Insert(k_Iterator ak_Where, k_Iterator ak_SrcBegin, k_Iterator ak_SrcEnd)
|
||||
{
|
||||
int li_FirstIndex = ((k_BlockIterator)ak_Where).Index;
|
||||
int li_Count = ak_SrcEnd - ak_SrcBegin;
|
||||
if (mk_Blocks.Length * mi_BlockSize <= mi_Count + li_Count + mi_BlockSize)
|
||||
AllocateBlock(li_Count);
|
||||
|
||||
mi_Count += li_Count;
|
||||
|
||||
k_Iterator lk_Dest;
|
||||
if (li_FirstIndex < li_Count/2)
|
||||
{
|
||||
if (mi_Offset == 0)
|
||||
mi_Offset = mk_Blocks.Length * mi_BlockSize;
|
||||
mi_Offset -= li_Count;
|
||||
lk_Dest = k_Algorithm.Copy(this.Begin+li_Count, this.Begin+li_FirstIndex+li_Count, this.Begin);
|
||||
}
|
||||
else
|
||||
{
|
||||
// count has been incremented - there are li_Count free elements at the end
|
||||
lk_Dest = this.Begin + li_FirstIndex;
|
||||
k_Algorithm.CopyBackward(lk_Dest, this.End - li_Count, this.End);
|
||||
}
|
||||
|
||||
k_Algorithm.Copy(ak_SrcBegin, ak_SrcEnd, lk_Dest);
|
||||
}
|
||||
|
||||
#region IList Members
|
||||
|
||||
public int Add(object ak_Value)
|
||||
{
|
||||
PushBack(ak_Value);
|
||||
return mi_Count;
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
for (int i=0; i<mk_Blocks.Length; ++i)
|
||||
mk_Blocks[i] = new object[mi_BlockSize];
|
||||
mi_Count = 0;
|
||||
mi_Offset = 0;
|
||||
}
|
||||
|
||||
public bool Contains(object ak_Value)
|
||||
{
|
||||
return (Find(ak_Value) != this.End);
|
||||
}
|
||||
|
||||
public int IndexOf(object ak_Value)
|
||||
{
|
||||
k_Iterator lk_Found = Find(ak_Value);
|
||||
if (lk_Found == this.End)
|
||||
return -1;
|
||||
return ((k_BlockIterator)lk_Found).Index;
|
||||
}
|
||||
|
||||
public void Insert(int ai_Index, object ak_Value)
|
||||
{
|
||||
Insert(this.Begin + ai_Index, ak_Value);
|
||||
}
|
||||
|
||||
public void Remove(object ak_Value)
|
||||
{
|
||||
Erase(Find(ak_Value));
|
||||
}
|
||||
|
||||
public void RemoveAt(int ai_Index)
|
||||
{
|
||||
Erase(this.Begin + ai_Index);
|
||||
}
|
||||
|
||||
public bool IsReadOnly
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public bool IsFixedSize
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public object this[int ai_Index]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (ai_Index >= mi_Count || ai_Index < 0)
|
||||
throw new ArgumentOutOfRangeException("Position out of boundary");
|
||||
|
||||
int li_Pos, li_Block = CalcBlockAndPos(ai_Index, out li_Pos);
|
||||
return mk_Blocks[li_Block][li_Pos];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (ai_Index >= mi_Count || ai_Index < 0)
|
||||
throw new ArgumentOutOfRangeException("Position out of boundary");
|
||||
|
||||
int li_Pos, li_Block = CalcBlockAndPos(ai_Index, out li_Pos);
|
||||
mk_Blocks[li_Block][li_Pos] = value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ICollection Members
|
||||
|
||||
public void CopyTo(Array ak_Array, int ai_Index)
|
||||
{
|
||||
for (k_Iterator lk_Iter = this.Begin.Clone(); lk_Iter != this.End; lk_Iter.Next())
|
||||
ak_Array.SetValue(lk_Iter.Current, ai_Index++);
|
||||
}
|
||||
|
||||
public int Count
|
||||
{
|
||||
get { return mi_Count; }
|
||||
}
|
||||
|
||||
public bool IsSynchronized
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public object SyncRoot
|
||||
{
|
||||
get { return this; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEnumerable Members
|
||||
|
||||
public IEnumerator GetEnumerator()
|
||||
{
|
||||
return new k_IteratorEnumerator(this.Begin, this.End);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ICloneable Members
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
k_Deque lk_Clone = new k_Deque(this.Count);
|
||||
lk_Clone.Insert(lk_Clone.End, this.Begin, this.End);
|
||||
return lk_Clone;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void AllocateBlock(int ai_MinElements)
|
||||
{
|
||||
// number of new blocks - grow by half block count (150%)
|
||||
int li_Increment = mk_Blocks.Length / 2;
|
||||
if (ai_MinElements > li_Increment*mi_BlockSize)
|
||||
li_Increment = (ai_MinElements + mi_BlockSize - 1)/mi_BlockSize;
|
||||
|
||||
object[][] lk_NewBlocks = new object[mk_Blocks.Length + li_Increment][];
|
||||
|
||||
// first move all blocks after offset to front
|
||||
int li_StartBlock = mi_Offset / mi_BlockSize;
|
||||
int li_BackCount = mk_Blocks.Length - li_StartBlock;
|
||||
Array.Copy(mk_Blocks, li_StartBlock, lk_NewBlocks, 0, li_BackCount);
|
||||
|
||||
int li_TotalOld = li_BackCount;
|
||||
|
||||
// second move all blocks before offset to end
|
||||
int li_FrontCount = (mi_Offset + mi_Count + mi_BlockSize - 1) / mi_BlockSize - mk_Blocks.Length;
|
||||
if (li_FrontCount > 0)
|
||||
{
|
||||
Array.Copy(mk_Blocks, 0, lk_NewBlocks, li_BackCount, li_FrontCount);
|
||||
li_TotalOld += li_FrontCount;
|
||||
}
|
||||
|
||||
// actually create new empty blocks
|
||||
for (int i=li_TotalOld; i < li_TotalOld+li_Increment; ++i)
|
||||
lk_NewBlocks[i] = new object[mi_BlockSize];
|
||||
|
||||
mk_Blocks = lk_NewBlocks;
|
||||
mi_Offset %= mi_BlockSize;
|
||||
}
|
||||
|
||||
private int CalcBlockAndPos(int ai_Index, out int ai_Pos)
|
||||
{
|
||||
ai_Pos = mi_Offset + ai_Index;
|
||||
int li_BlockIndex = ai_Pos / mi_BlockSize;
|
||||
if (li_BlockIndex >= mk_Blocks.Length)
|
||||
li_BlockIndex -= mk_Blocks.Length;
|
||||
ai_Pos %= mi_BlockSize;
|
||||
return li_BlockIndex;
|
||||
}
|
||||
}
|
||||
}
|
658
iTechSharp/System/util/collections/HashTable.cs
Normal file
658
iTechSharp/System/util/collections/HashTable.cs
Normal file
@ -0,0 +1,658 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace System.util.collections
|
||||
{
|
||||
/// <summary>
|
||||
/// A HashTable with iterators
|
||||
/// </summary>
|
||||
public class k_HashTable : IMap
|
||||
{
|
||||
#region static helper functions
|
||||
|
||||
private readonly static int[] mk_Primes =
|
||||
{
|
||||
11, 17, 23, 29, 37, 47, 59, 71, 89, 107, 131, 163, 197, 239, 293, 353, 431, 521, 631, 761, 919,
|
||||
1103, 1327, 1597, 1931, 2333, 2801, 3371, 4049, 4861, 5839, 7013, 8419, 10103, 12143, 14591,
|
||||
17519, 21023, 25229, 30293, 36353, 43627, 52361, 62851, 75431, 90523, 108631, 130363,
|
||||
156437, 187751, 225307, 270371, 324449, 389357, 467237, 560689, 672827, 807403,
|
||||
968897, 1162687, 1395263, 1674319, 2009191, 2411033, 2893249, 3471899, 4166287,
|
||||
4999559, 5999471, 7199369
|
||||
};
|
||||
|
||||
private static bool IsPrime(int ai_Number)
|
||||
{
|
||||
if ((ai_Number & 1) == 0)
|
||||
return (ai_Number == 2);
|
||||
|
||||
int li_Max = (int)Math.Sqrt(ai_Number);
|
||||
for (int li_Div=3; li_Div < li_Max; li_Div+=2)
|
||||
{
|
||||
if ((ai_Number % li_Div) == 0)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static int FindPrimeGreater(int ai_Min)
|
||||
{
|
||||
if (ai_Min < 0)
|
||||
throw new ArgumentException("k_HashTable capacity overflow.");
|
||||
|
||||
// do binary search lookup in primes array
|
||||
int li_Pos = Array.BinarySearch(mk_Primes, ai_Min);
|
||||
if (li_Pos >= 0)
|
||||
return mk_Primes[li_Pos];
|
||||
|
||||
li_Pos = ~li_Pos;
|
||||
if (li_Pos < mk_Primes.Length)
|
||||
return mk_Primes[li_Pos];
|
||||
|
||||
// ai_Min is greater than highest number in mk_Primes
|
||||
for (int i = (ai_Min|1); i <= Int32.MaxValue; i+=2)
|
||||
{
|
||||
if (IsPrime(i))
|
||||
return i;
|
||||
}
|
||||
return ai_Min;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Bucket Structure
|
||||
|
||||
private struct r_Bucket
|
||||
{
|
||||
public object mk_Key;
|
||||
public object mk_Value;
|
||||
public int mi_HashCode; // MSB (sign bit) indicates a collision.
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region k_BucketIterator Implementation
|
||||
|
||||
private class k_BucketIterator : k_Iterator
|
||||
{
|
||||
private readonly k_HashTable mk_Table;
|
||||
private int mi_Index;
|
||||
|
||||
public k_BucketIterator(k_HashTable ak_Table, int ai_Index)
|
||||
{
|
||||
mk_Table = ak_Table;
|
||||
mi_Index = -1;
|
||||
if (ai_Index >= 0)
|
||||
mi_Index = FindNext(ai_Index-1);
|
||||
}
|
||||
|
||||
public override object Current
|
||||
{
|
||||
get
|
||||
{
|
||||
if (mi_Index < 0 || mk_Table.mk_Buckets[mi_Index].mk_Key == null)
|
||||
throw new k_InvalidPositionException();
|
||||
|
||||
r_Bucket lr_Bucket = mk_Table.mk_Buckets[mi_Index];
|
||||
return new DictionaryEntry(lr_Bucket.mk_Key, lr_Bucket.mk_Value);
|
||||
}
|
||||
set
|
||||
{
|
||||
if (mi_Index < 0 || mk_Table.mk_Buckets[mi_Index].mk_Key == null)
|
||||
throw new k_InvalidPositionException();
|
||||
|
||||
DictionaryEntry lr_Entry = (DictionaryEntry)value;
|
||||
r_Bucket lr_Bucket = mk_Table.mk_Buckets[mi_Index];
|
||||
if (mk_Table.mk_Comparer.Compare(lr_Entry.Key, lr_Bucket.mk_Key) != 0)
|
||||
throw new ArgumentException("Key values must not be changed.");
|
||||
mk_Table.mk_Buckets[mi_Index].mk_Value = lr_Entry.Value;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Move(int ai_Count)
|
||||
{
|
||||
int li_NewIndex = mi_Index;
|
||||
|
||||
if (ai_Count > 0)
|
||||
{
|
||||
while (ai_Count-- > 0)
|
||||
{
|
||||
if (li_NewIndex < 0)
|
||||
throw new InvalidOperationException("Tried to moved beyond end element.");
|
||||
|
||||
li_NewIndex = FindNext(li_NewIndex);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (ai_Count++ < 0)
|
||||
{
|
||||
if (li_NewIndex < 0)
|
||||
li_NewIndex = FindPrev(mk_Table.mk_Buckets.Length);
|
||||
else
|
||||
li_NewIndex = FindPrev(li_NewIndex);
|
||||
|
||||
if (li_NewIndex < 0)
|
||||
throw new InvalidOperationException("Tried to move before first element.");
|
||||
}
|
||||
}
|
||||
|
||||
mi_Index = li_NewIndex;
|
||||
}
|
||||
|
||||
public override int Distance(k_Iterator ak_Iter)
|
||||
{
|
||||
k_BucketIterator lk_Iter = ak_Iter as k_BucketIterator;
|
||||
if (lk_Iter == null || !object.ReferenceEquals(lk_Iter.Collection, this.Collection))
|
||||
throw new ArgumentException("Cannot determine distance of iterators belonging to different collections.");
|
||||
|
||||
k_Iterator lk_End = mk_Table.End;
|
||||
|
||||
int li_IndexDiff;
|
||||
if (this != lk_End && ak_Iter != lk_End)
|
||||
li_IndexDiff = mi_Index - lk_Iter.mi_Index;
|
||||
else
|
||||
li_IndexDiff = (this == lk_End) ? 1 : -1; // 1 is also fine when both are End
|
||||
|
||||
if (li_IndexDiff < 0)
|
||||
{
|
||||
int li_Diff = 0;
|
||||
k_Iterator lk_Bck = this.Clone();
|
||||
for (; lk_Bck != ak_Iter && lk_Bck != lk_End; lk_Bck.Next())
|
||||
--li_Diff;
|
||||
|
||||
if (lk_Bck == ak_Iter)
|
||||
return li_Diff;
|
||||
}
|
||||
else
|
||||
{
|
||||
int li_Diff = 0;
|
||||
k_Iterator lk_Fwd = ak_Iter.Clone();
|
||||
for (; lk_Fwd != this && lk_Fwd != lk_End; lk_Fwd.Next())
|
||||
++li_Diff;
|
||||
|
||||
if (lk_Fwd == this)
|
||||
return li_Diff;
|
||||
}
|
||||
|
||||
throw new Exception("Inconsistent state. Concurrency?");
|
||||
}
|
||||
|
||||
public override object Collection
|
||||
{
|
||||
get { return mk_Table; }
|
||||
}
|
||||
|
||||
public override bool Equals(object ak_Obj)
|
||||
{
|
||||
k_BucketIterator lk_Iter = ak_Obj as k_BucketIterator;
|
||||
if (lk_Iter == null)
|
||||
return false;
|
||||
|
||||
return (mi_Index == lk_Iter.mi_Index && object.ReferenceEquals(mk_Table, lk_Iter.mk_Table));
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return mk_Table.GetHashCode() ^ mi_Index;
|
||||
}
|
||||
|
||||
public override k_Iterator Clone()
|
||||
{
|
||||
return new k_BucketIterator(mk_Table, mi_Index);
|
||||
}
|
||||
|
||||
private int FindPrev(int ai_Index)
|
||||
{
|
||||
--ai_Index;
|
||||
r_Bucket[] lk_Buckets = mk_Table.mk_Buckets;
|
||||
while (ai_Index >= 0 && lk_Buckets[ai_Index].mk_Key == null)
|
||||
--ai_Index;
|
||||
if (ai_Index < -1)
|
||||
return -1;
|
||||
return ai_Index;
|
||||
}
|
||||
|
||||
private int FindNext(int ai_Index)
|
||||
{
|
||||
++ai_Index;
|
||||
r_Bucket[] lk_Buckets = mk_Table.mk_Buckets;
|
||||
while (ai_Index < lk_Buckets.Length && lk_Buckets[ai_Index].mk_Key == null)
|
||||
++ai_Index;
|
||||
|
||||
if (ai_Index >= lk_Buckets.Length)
|
||||
return -1;
|
||||
return ai_Index;
|
||||
}
|
||||
|
||||
internal int Index
|
||||
{
|
||||
get { return mi_Index; }
|
||||
}
|
||||
}
|
||||
|
||||
private class k_PinnedBucketIterator : k_BucketIterator
|
||||
{
|
||||
public k_PinnedBucketIterator(k_HashTable ak_Table, int ai_Index)
|
||||
: base(ak_Table, ai_Index)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Move(int ai_Count)
|
||||
{
|
||||
throw new k_IteratorPinnedException();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private IHashCodeProvider mk_HashProvider;
|
||||
private IComparer mk_Comparer;
|
||||
private double md_LoadFactor;
|
||||
private int mi_GrowSize;
|
||||
private r_Bucket[] mk_Buckets;
|
||||
private int mi_Count;
|
||||
private readonly k_Iterator mk_End;
|
||||
|
||||
public k_HashTable()
|
||||
: this(0, 0.72)
|
||||
{
|
||||
}
|
||||
|
||||
public k_HashTable(int ai_Capacity, double ad_LoadFactor)
|
||||
: this(ai_Capacity, ad_LoadFactor, null, null)
|
||||
{
|
||||
}
|
||||
|
||||
public k_HashTable(int ai_Capacity, double ad_LoadFactor, IHashCodeProvider ak_HashProvider, IComparer ak_Comparer)
|
||||
{
|
||||
if (ad_LoadFactor <= .0 || ad_LoadFactor > 1.0)
|
||||
throw new ArgumentException("Load factor must be greater than .0 and smaller or equal to 1.0", "ad_LoadFactor");
|
||||
md_LoadFactor = ad_LoadFactor;
|
||||
|
||||
double ld_Size = ai_Capacity/ad_LoadFactor;
|
||||
if (ld_Size > int.MaxValue)
|
||||
throw new ArgumentException("k_HashTable overflow");
|
||||
|
||||
int li_TableSize = FindPrimeGreater((int)ld_Size);
|
||||
mk_Buckets = new r_Bucket[li_TableSize];
|
||||
mi_GrowSize = (md_LoadFactor < 1.0) ? (int)(md_LoadFactor * li_TableSize) : li_TableSize-1;
|
||||
|
||||
mk_HashProvider = ak_HashProvider;
|
||||
mk_Comparer = ak_Comparer;
|
||||
|
||||
mk_End = new k_PinnedBucketIterator(this, -1);
|
||||
}
|
||||
|
||||
// IContainer Members
|
||||
public k_Iterator Begin
|
||||
{
|
||||
get
|
||||
{
|
||||
if (mi_Count == 0)
|
||||
return mk_End;
|
||||
return new k_PinnedBucketIterator(this, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public k_Iterator End
|
||||
{
|
||||
get { return mk_End; }
|
||||
}
|
||||
|
||||
public bool IsEmpty
|
||||
{
|
||||
get { return (mi_Count == 0); }
|
||||
}
|
||||
|
||||
public k_Iterator Find(object ak_Value)
|
||||
{
|
||||
DictionaryEntry lr_Item = (DictionaryEntry)ak_Value;
|
||||
int li_Index = FindBucket(lr_Item.Key);
|
||||
if (li_Index < 0 || !object.Equals(mk_Buckets[li_Index].mk_Value, lr_Item.Value))
|
||||
return this.End;
|
||||
return new k_BucketIterator(this, li_Index);
|
||||
}
|
||||
|
||||
public k_Iterator Erase(k_Iterator ak_Where)
|
||||
{
|
||||
//System.Diagnostics.Debug.Assert(object.ReferenceEquals(this, ak_Where.Collection), "Iterator does not belong to this collection.");
|
||||
k_Iterator lk_Successor = ak_Where + 1;
|
||||
EmptyBucket(((k_BucketIterator)ak_Where).Index);
|
||||
return lk_Successor;
|
||||
}
|
||||
|
||||
public k_Iterator Erase(k_Iterator ak_First, k_Iterator ak_Last)
|
||||
{
|
||||
if (ak_First == this.Begin && ak_Last == this.End)
|
||||
{
|
||||
Clear();
|
||||
return ak_Last.Clone();
|
||||
}
|
||||
|
||||
k_Iterator lk_Current = ak_First;
|
||||
while (lk_Current != ak_Last)
|
||||
lk_Current = Erase(lk_Current);
|
||||
return lk_Current;
|
||||
}
|
||||
|
||||
// IMap Members
|
||||
public k_Iterator FindKey(object ak_Key)
|
||||
{
|
||||
return new k_BucketIterator(this, FindBucket(ak_Key));
|
||||
}
|
||||
|
||||
public void Add(DictionaryEntry ar_Item)
|
||||
{
|
||||
Add(ar_Item.Key, ar_Item.Value);
|
||||
}
|
||||
|
||||
public void Insert(k_Iterator ak_SrcBegin, k_Iterator ak_SrcEnd)
|
||||
{
|
||||
for (k_Iterator lk_Iter = ak_SrcBegin.Clone(); lk_Iter != ak_SrcEnd; lk_Iter.Next())
|
||||
Add((DictionaryEntry)lk_Iter.Current);
|
||||
}
|
||||
|
||||
#region IDictionary Members
|
||||
|
||||
public void Add(object ak_Key, object ak_Value)
|
||||
{
|
||||
SetValue(ak_Key, ak_Value, true);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
if (mi_Count == 0)
|
||||
return;
|
||||
|
||||
for (int i=0; i < mk_Buckets.Length; ++i)
|
||||
mk_Buckets[i] = new r_Bucket();
|
||||
|
||||
mi_Count = 0;
|
||||
}
|
||||
|
||||
public bool Contains(object ak_Key)
|
||||
{
|
||||
return (FindBucket(ak_Key) >= 0);
|
||||
}
|
||||
|
||||
public void Remove(object ak_Key)
|
||||
{
|
||||
EmptyBucket(FindBucket(ak_Key));
|
||||
}
|
||||
|
||||
public IDictionaryEnumerator GetEnumerator()
|
||||
{
|
||||
return new k_IteratorDictEnumerator(this.Begin, this.End);
|
||||
}
|
||||
|
||||
public bool IsReadOnly
|
||||
{
|
||||
get { return false; }
|
||||
|
||||
}
|
||||
public bool IsFixedSize
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public object this[object ak_Key]
|
||||
{
|
||||
get
|
||||
{
|
||||
int li_Index = FindBucket(ak_Key);
|
||||
if (li_Index < 0)
|
||||
return null;
|
||||
|
||||
return mk_Buckets[li_Index].mk_Value;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue(ak_Key, value, false);
|
||||
}
|
||||
}
|
||||
|
||||
public ICollection Keys
|
||||
{
|
||||
get
|
||||
{
|
||||
int i = 0;
|
||||
object[] lk_Keys = new object[mi_Count];
|
||||
foreach (DictionaryEntry lr_Entry in this)
|
||||
lk_Keys[i++] = lr_Entry.Key;
|
||||
return lk_Keys;
|
||||
}
|
||||
}
|
||||
|
||||
public ICollection Values
|
||||
{
|
||||
get
|
||||
{
|
||||
int i=0;
|
||||
object[] lk_Values = new object[mi_Count];
|
||||
foreach (DictionaryEntry lr_Entry in this)
|
||||
lk_Values[i++] = lr_Entry.Value;
|
||||
return lk_Values;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ICollection Members
|
||||
|
||||
public void CopyTo(Array ak_Array, int ai_Index)
|
||||
{
|
||||
foreach (DictionaryEntry lr_Entry in this)
|
||||
ak_Array.SetValue(lr_Entry, ai_Index++);
|
||||
}
|
||||
|
||||
public int Count
|
||||
{
|
||||
get { return mi_Count; }
|
||||
}
|
||||
|
||||
public bool IsSynchronized
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public object SyncRoot
|
||||
{
|
||||
get { return this; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEnumerable Members
|
||||
|
||||
IEnumerator System.Collections.IEnumerable.GetEnumerator()
|
||||
{
|
||||
return new k_IteratorEnumerator(this.Begin, this.End);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ICloneable Members
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
k_HashTable lk_Clone = new k_HashTable(this.Count, md_LoadFactor, mk_HashProvider, mk_Comparer);
|
||||
|
||||
int i = mk_Buckets.Length;
|
||||
while (i-- > 0)
|
||||
{
|
||||
object lk_Key = mk_Buckets[i].mk_Key;
|
||||
if (lk_Key != null)
|
||||
lk_Clone[lk_Key] = mk_Buckets[i].mk_Value;
|
||||
}
|
||||
return lk_Clone;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void EmptyBucket(int ai_Index)
|
||||
{
|
||||
if (ai_Index < 0 || ai_Index >= mk_Buckets.Length)
|
||||
return;
|
||||
|
||||
if (mk_Buckets[ai_Index].mk_Key == null)
|
||||
throw new InvalidOperationException("Key was removed earlier.");
|
||||
|
||||
mk_Buckets[ai_Index].mi_HashCode &= unchecked((int)0x80000000);
|
||||
mk_Buckets[ai_Index].mk_Key = null;
|
||||
mk_Buckets[ai_Index].mk_Value = null;
|
||||
--mi_Count;
|
||||
}
|
||||
|
||||
private int FindBucket(object ak_Key)
|
||||
{
|
||||
if (ak_Key == null)
|
||||
throw new ArgumentException("Key must not be null.", "ak_Key");
|
||||
|
||||
uint lui_BucketCount = (uint)mk_Buckets.Length;
|
||||
|
||||
uint lui_Increment;
|
||||
uint lui_HashCode = ComputeHashAndStep(ak_Key, out lui_Increment);
|
||||
|
||||
uint lui_Walker = lui_HashCode % lui_BucketCount;
|
||||
r_Bucket lr_Bucket;
|
||||
do
|
||||
{
|
||||
int li_Index = (int)lui_Walker;
|
||||
lr_Bucket = mk_Buckets[li_Index];
|
||||
if (lr_Bucket.mk_Key == null && lr_Bucket.mi_HashCode >= 0)
|
||||
break; // stop on empty non-duplicate
|
||||
|
||||
if ((lr_Bucket.mi_HashCode & 0x7fffffff) == lui_HashCode
|
||||
&& EqualsHelper(lr_Bucket.mk_Key, ak_Key))
|
||||
return li_Index;
|
||||
|
||||
lui_Walker += lui_Increment;
|
||||
lui_Walker %= lui_BucketCount;
|
||||
}
|
||||
while (lr_Bucket.mi_HashCode < 0 && lui_Walker != lui_HashCode);
|
||||
|
||||
return -1; // not found
|
||||
}
|
||||
|
||||
private void SetValue(object ak_Key, object ak_Value, bool ab_Add)
|
||||
{
|
||||
if (mi_Count >= mi_GrowSize)
|
||||
ExpandBucketsArray();
|
||||
|
||||
uint lui_BucketCount = (uint)mk_Buckets.Length;
|
||||
|
||||
uint lui_Increment;
|
||||
uint lui_HashCode = ComputeHashAndStep(ak_Key, out lui_Increment);
|
||||
|
||||
r_Bucket lr_Bucket;
|
||||
int li_Free = -1;
|
||||
uint lui_Walker = lui_HashCode % lui_BucketCount;
|
||||
do
|
||||
{
|
||||
int li_Index = (int)lui_Walker;
|
||||
lr_Bucket = mk_Buckets[li_Index];
|
||||
if (li_Free < 0 && lr_Bucket.mk_Key == null && lr_Bucket.mi_HashCode < 0)
|
||||
li_Free = li_Index;
|
||||
|
||||
if (lr_Bucket.mk_Key == null && (lr_Bucket.mi_HashCode & unchecked(0x80000000)) == 0)
|
||||
{
|
||||
if (li_Free >= 0)
|
||||
li_Index = li_Free;
|
||||
mk_Buckets[li_Index].mk_Key = ak_Key;
|
||||
mk_Buckets[li_Index].mk_Value = ak_Value;
|
||||
mk_Buckets[li_Index].mi_HashCode |= (int)lui_HashCode;
|
||||
++mi_Count;
|
||||
return;
|
||||
}
|
||||
|
||||
if ((lr_Bucket.mi_HashCode & 0x7fffffff) == lui_HashCode
|
||||
&& EqualsHelper(lr_Bucket.mk_Key, ak_Key))
|
||||
{
|
||||
if (ab_Add)
|
||||
throw new ArgumentException("duplicate key");
|
||||
mk_Buckets[li_Index].mk_Value = ak_Value;
|
||||
return;
|
||||
}
|
||||
|
||||
// mark all as dupes as long as we have not found a free bucket
|
||||
if (li_Free == -1)
|
||||
mk_Buckets[li_Index].mi_HashCode |= unchecked((int)0x80000000);
|
||||
|
||||
lui_Walker += lui_Increment;
|
||||
lui_Walker %= lui_BucketCount;
|
||||
}
|
||||
while (lui_Walker != lui_HashCode);
|
||||
|
||||
if (li_Free == -1)
|
||||
throw new InvalidOperationException("Corrupted hash table. Insert failed.");
|
||||
|
||||
mk_Buckets[li_Free].mk_Key = ak_Key;
|
||||
mk_Buckets[li_Free].mk_Value = ak_Value;
|
||||
mk_Buckets[li_Free].mi_HashCode |= (int)lui_HashCode;
|
||||
++mi_Count;
|
||||
}
|
||||
|
||||
private static void InternalExpandInsert(r_Bucket[] ak_Buckets, r_Bucket ar_Bucket)
|
||||
{
|
||||
ar_Bucket.mi_HashCode &= 0x7fffffff;
|
||||
uint lui_BucketCount = (uint)ak_Buckets.Length;
|
||||
uint lui_Increment = (uint)(1 + ((((uint)ar_Bucket.mi_HashCode >> 5) + 1) % (lui_BucketCount - 1)));
|
||||
|
||||
uint lui_Walker = (uint)ar_Bucket.mi_HashCode % lui_BucketCount;
|
||||
for (;;)
|
||||
{
|
||||
int li_Index = (int)lui_Walker;
|
||||
if (ak_Buckets[li_Index].mk_Key == null)
|
||||
{
|
||||
ak_Buckets[li_Index] = ar_Bucket;
|
||||
return;
|
||||
}
|
||||
|
||||
// since current bucket is occupied mark it as duplicate
|
||||
ak_Buckets[li_Index].mi_HashCode |= unchecked((int)0x80000000);
|
||||
|
||||
lui_Walker += lui_Increment;
|
||||
lui_Walker %= lui_BucketCount;
|
||||
}
|
||||
}
|
||||
|
||||
private void ExpandBucketsArray()
|
||||
{
|
||||
int li_NewSize = FindPrimeGreater(mk_Buckets.Length * 2);
|
||||
|
||||
r_Bucket[] lk_Buckets = new r_Bucket[li_NewSize];
|
||||
foreach (r_Bucket lr_Bucket in mk_Buckets)
|
||||
{
|
||||
if (lr_Bucket.mk_Key == null)
|
||||
continue;
|
||||
InternalExpandInsert(lk_Buckets, lr_Bucket);
|
||||
}
|
||||
|
||||
mk_Buckets = lk_Buckets;
|
||||
mi_GrowSize = (md_LoadFactor < 1.0) ? (int)(md_LoadFactor * li_NewSize) : li_NewSize-1;
|
||||
}
|
||||
|
||||
private uint ComputeHashAndStep(object ak_Key, out uint aui_Increment)
|
||||
{
|
||||
// mask the sign bit (our collision indicator)
|
||||
uint lui_HashCode = (uint)GetHashHelper(ak_Key) & 0x7fffffff;
|
||||
// calc increment value relatively prime to mk_Buckets.Length
|
||||
aui_Increment = (uint)(1 + (((lui_HashCode >> 5) + 1) % ((uint)mk_Buckets.Length - 1)));
|
||||
return lui_HashCode;
|
||||
}
|
||||
|
||||
private int GetHashHelper(object ak_Key)
|
||||
{
|
||||
if (mk_HashProvider != null)
|
||||
return mk_HashProvider.GetHashCode(ak_Key);
|
||||
return ak_Key.GetHashCode();
|
||||
}
|
||||
|
||||
private bool EqualsHelper(object ak_ObjA, object ak_ObjB)
|
||||
{
|
||||
if (mk_Comparer != null)
|
||||
return (mk_Comparer.Compare(ak_ObjA, ak_ObjB) == 0);
|
||||
return Object.Equals(ak_ObjA, ak_ObjB);
|
||||
}
|
||||
}
|
||||
}
|
323
iTechSharp/System/util/collections/Iterator.cs
Normal file
323
iTechSharp/System/util/collections/Iterator.cs
Normal file
@ -0,0 +1,323 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace System.util.collections
|
||||
{
|
||||
public abstract class k_Iterator : IComparable, ICloneable
|
||||
{
|
||||
public static k_Iterator operator ++(k_Iterator ak_Iter)
|
||||
{
|
||||
return ak_Iter + 1;
|
||||
}
|
||||
|
||||
public static k_Iterator operator --(k_Iterator ak_Iter)
|
||||
{
|
||||
return ak_Iter - 1;
|
||||
}
|
||||
|
||||
public static k_Iterator operator +(k_Iterator ak_Iter, int ai_Distance)
|
||||
{
|
||||
k_Iterator lk_Clone = ak_Iter.Clone();
|
||||
lk_Clone.Move(ai_Distance);
|
||||
return lk_Clone;
|
||||
}
|
||||
|
||||
public static k_Iterator operator -(k_Iterator ak_Iter, int ai_Distance)
|
||||
{
|
||||
k_Iterator lk_Clone = ak_Iter.Clone();
|
||||
lk_Clone.Move(-ai_Distance);
|
||||
return lk_Clone;
|
||||
}
|
||||
|
||||
public static int operator -(k_Iterator ak_Left, k_Iterator ak_Right)
|
||||
{
|
||||
return ak_Left.Distance(ak_Right);
|
||||
}
|
||||
|
||||
public static bool operator ==(k_Iterator ak_Left, k_Iterator ak_Right)
|
||||
{
|
||||
return object.Equals(ak_Left, ak_Right);
|
||||
}
|
||||
|
||||
public static bool operator !=(k_Iterator ak_Left, k_Iterator ak_Right)
|
||||
{
|
||||
return !object.Equals(ak_Left, ak_Right);
|
||||
}
|
||||
|
||||
public override bool Equals(object ak_Obj)
|
||||
{
|
||||
return base.Equals(ak_Obj); // implemented to avoid warning
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode(); // implemented to avoid warning
|
||||
}
|
||||
|
||||
public int CompareTo(object ak_Obj)
|
||||
{
|
||||
k_Iterator lk_Iter = ak_Obj as k_Iterator;
|
||||
if (lk_Iter == null || !object.ReferenceEquals(lk_Iter.Collection, this.Collection))
|
||||
throw new ArgumentException("Cannot compare iterators of different origin.");
|
||||
|
||||
return Distance(lk_Iter);
|
||||
}
|
||||
|
||||
object ICloneable.Clone()
|
||||
{
|
||||
return this.Clone();
|
||||
}
|
||||
|
||||
public void Next()
|
||||
{
|
||||
Move(1);
|
||||
}
|
||||
|
||||
public void Prev()
|
||||
{
|
||||
Move(-1);
|
||||
}
|
||||
|
||||
public abstract object Current { get; set; }
|
||||
public abstract object Collection { get; }
|
||||
public abstract k_Iterator Clone();
|
||||
|
||||
public abstract void Move(int ai_Count);
|
||||
public abstract int Distance(k_Iterator ak_Iter);
|
||||
}
|
||||
|
||||
public class k_IteratorEnumerator : IEnumerator
|
||||
{
|
||||
protected k_Iterator mk_Current;
|
||||
protected k_Iterator mk_Begin, mk_End;
|
||||
protected bool mb_Fresh;
|
||||
|
||||
public k_IteratorEnumerator(k_Iterator ak_Begin, k_Iterator ak_End)
|
||||
{
|
||||
mk_Begin = ak_Begin;
|
||||
mk_End = ak_End;
|
||||
mb_Fresh = true;
|
||||
}
|
||||
|
||||
#region IEnumerator Members
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (mb_Fresh)
|
||||
{
|
||||
mk_Current = mk_Begin.Clone();
|
||||
mb_Fresh = false;
|
||||
}
|
||||
else if (mk_Current != mk_End)
|
||||
mk_Current.Next();
|
||||
|
||||
return (mk_Current != mk_End);
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
mb_Fresh = true;
|
||||
mk_Current = null;
|
||||
}
|
||||
|
||||
public object Current
|
||||
{
|
||||
get
|
||||
{
|
||||
if (mb_Fresh || mk_Current == mk_End)
|
||||
throw new InvalidOperationException("The enumerator is positioned before the first element of the collection or after the last element.");
|
||||
return mk_Current.Current;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class k_IteratorDictEnumerator : k_IteratorEnumerator, IDictionaryEnumerator
|
||||
{
|
||||
public k_IteratorDictEnumerator(k_Iterator ak_Begin, k_Iterator ak_End)
|
||||
: base(ak_Begin, ak_End)
|
||||
{
|
||||
}
|
||||
|
||||
#region IDictionaryEnumerator Members
|
||||
|
||||
public object Key
|
||||
{
|
||||
get { return this.Entry.Key; }
|
||||
}
|
||||
|
||||
public object Value
|
||||
{
|
||||
get { return this.Entry.Value; }
|
||||
}
|
||||
|
||||
public DictionaryEntry Entry
|
||||
{
|
||||
get { return (DictionaryEntry)this.Current; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class k_IListIterator : k_Iterator
|
||||
{
|
||||
private readonly IList mk_List;
|
||||
private int mi_Index;
|
||||
|
||||
public static k_IListIterator CreateBegin(IList ak_List)
|
||||
{
|
||||
return new k_PinnedIListIterator(ak_List, 0);
|
||||
}
|
||||
|
||||
public static k_IListIterator CreateEnd(IList ak_List)
|
||||
{
|
||||
return new k_PinnedIListIterator(ak_List, ak_List.Count);
|
||||
}
|
||||
|
||||
public k_IListIterator(IList ak_List, int ai_Index)
|
||||
{
|
||||
mk_List = ak_List;
|
||||
mi_Index = ai_Index;
|
||||
}
|
||||
|
||||
public override void Move(int ai_Count)
|
||||
{
|
||||
int li_Index = mi_Index + ai_Count;
|
||||
|
||||
if (li_Index < 0)
|
||||
throw new InvalidOperationException("Tried to move before first element.");
|
||||
else if (li_Index > mk_List.Count)
|
||||
throw new InvalidOperationException("Tried to moved beyond end element.");
|
||||
|
||||
mi_Index = li_Index;
|
||||
}
|
||||
|
||||
public override int Distance(k_Iterator ak_Iter)
|
||||
{
|
||||
return mi_Index - ((k_IListIterator)ak_Iter).mi_Index;
|
||||
}
|
||||
|
||||
public override object Collection
|
||||
{
|
||||
get { return mk_List; }
|
||||
}
|
||||
|
||||
public override object Current
|
||||
{
|
||||
get
|
||||
{
|
||||
if (mi_Index < 0 || mi_Index >= mk_List.Count)
|
||||
throw new k_InvalidPositionException();
|
||||
return mk_List[mi_Index];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (mi_Index < 0 || mi_Index >= mk_List.Count)
|
||||
throw new k_InvalidPositionException();
|
||||
mk_List[mi_Index] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals(object ak_Obj)
|
||||
{
|
||||
k_IListIterator lk_Iter = ak_Obj as k_IListIterator;
|
||||
if (lk_Iter == null)
|
||||
return false;
|
||||
return (mi_Index == lk_Iter.mi_Index) && object.ReferenceEquals(this.Collection, lk_Iter.Collection);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return mk_List.GetHashCode() ^ mi_Index;
|
||||
}
|
||||
|
||||
public override k_Iterator Clone()
|
||||
{
|
||||
return new k_IListIterator(mk_List, mi_Index);
|
||||
}
|
||||
|
||||
internal int Index
|
||||
{
|
||||
get { return mi_Index; }
|
||||
}
|
||||
}
|
||||
|
||||
internal class k_PinnedIListIterator : k_IListIterator
|
||||
{
|
||||
public k_PinnedIListIterator(IList ak_List, int ai_Index)
|
||||
: base(ak_List, ai_Index)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Move(int ai_Count)
|
||||
{
|
||||
throw new k_IteratorPinnedException();
|
||||
}
|
||||
}
|
||||
|
||||
public class k_CollectionOnIterators : ICollection
|
||||
{
|
||||
private k_Iterator mk_Begin, mk_End;
|
||||
private int mi_Count;
|
||||
|
||||
public k_CollectionOnIterators(k_Iterator ak_Begin, k_Iterator ak_End)
|
||||
{
|
||||
mk_Begin = ak_Begin;
|
||||
mk_End = ak_End;
|
||||
mi_Count = mk_End - mk_Begin;
|
||||
}
|
||||
|
||||
#region ICollection Members
|
||||
|
||||
public int Count
|
||||
{
|
||||
get { return mi_Count; }
|
||||
}
|
||||
|
||||
public bool IsSynchronized
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public object SyncRoot
|
||||
{
|
||||
get { return mk_Begin.Collection; }
|
||||
}
|
||||
|
||||
public void CopyTo(Array ak_Array, int ai_Index)
|
||||
{
|
||||
foreach (object lk_Obj in this)
|
||||
ak_Array.SetValue(lk_Obj, ai_Index++);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEnumerable Members
|
||||
|
||||
public IEnumerator GetEnumerator()
|
||||
{
|
||||
return new k_IteratorEnumerator(mk_Begin, mk_End);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class k_IteratorPinnedException : InvalidOperationException
|
||||
{
|
||||
public k_IteratorPinnedException()
|
||||
: base("Cannot move pinned iterator. Use Clone() to create a movable copy.")
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class k_InvalidPositionException : InvalidOperationException
|
||||
{
|
||||
public k_InvalidPositionException()
|
||||
: base("Iterator positioned on End or invalid element.")
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
537
iTechSharp/System/util/collections/List.cs
Normal file
537
iTechSharp/System/util/collections/List.cs
Normal file
@ -0,0 +1,537 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace System.util.collections
|
||||
{
|
||||
/// <summary>
|
||||
/// A doubly linked list
|
||||
/// </summary>
|
||||
public class k_List : ISequence
|
||||
{
|
||||
#region k_Node Implementation
|
||||
|
||||
private class k_Node
|
||||
{
|
||||
private object mk_Value;
|
||||
public k_Node mk_Prev, mk_Next;
|
||||
|
||||
public k_Node(object ak_Value)
|
||||
{
|
||||
mk_Value = ak_Value;
|
||||
}
|
||||
|
||||
public object Value
|
||||
{
|
||||
get { return mk_Value; }
|
||||
set { mk_Value = value; }
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region k_NodeIterator Implementation
|
||||
|
||||
private class k_NodeIterator : k_Iterator, ICloneable
|
||||
{
|
||||
private readonly k_List mk_List;
|
||||
private k_Node mk_Current;
|
||||
|
||||
public k_NodeIterator(k_List ak_List, k_Node ak_Node)
|
||||
{
|
||||
mk_List = ak_List;
|
||||
mk_Current = ak_Node;
|
||||
}
|
||||
|
||||
public override object Current
|
||||
{
|
||||
get
|
||||
{
|
||||
if (mk_Current == null)
|
||||
throw new k_InvalidPositionException();
|
||||
return mk_Current.Value;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (mk_Current == null)
|
||||
throw new k_InvalidPositionException();
|
||||
mk_Current.Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override object Collection
|
||||
{
|
||||
get { return mk_List; }
|
||||
}
|
||||
|
||||
public override void Move(int ai_Count)
|
||||
{
|
||||
k_Node lk_NewPos = mk_Current;
|
||||
|
||||
int li_Count = ai_Count;
|
||||
if (li_Count > 0)
|
||||
{
|
||||
while (li_Count-- > 0)
|
||||
{
|
||||
if (lk_NewPos == null)
|
||||
throw new InvalidOperationException("Tried to moved beyond end element.");
|
||||
|
||||
lk_NewPos = lk_NewPos.mk_Next;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (li_Count++ < 0)
|
||||
{
|
||||
if (lk_NewPos == null)
|
||||
lk_NewPos = mk_List.mk_Tail;
|
||||
else
|
||||
lk_NewPos = lk_NewPos.mk_Prev;
|
||||
|
||||
if (lk_NewPos == null)
|
||||
throw new InvalidOperationException("Tried to move before first element.");
|
||||
}
|
||||
}
|
||||
|
||||
#if (DEBUG)
|
||||
if (ai_Count != 0 && object.ReferenceEquals(mk_Current, lk_NewPos))
|
||||
throw new IndexOutOfRangeException("Iterator is positioned on invalid node.");
|
||||
#endif
|
||||
|
||||
mk_Current = lk_NewPos;
|
||||
}
|
||||
|
||||
public override int Distance(k_Iterator ak_Iter)
|
||||
{
|
||||
k_NodeIterator lk_Iter = (k_NodeIterator)ak_Iter;
|
||||
|
||||
if (!this.IsValid || !lk_Iter.IsValid)
|
||||
throw new ArgumentException("Iterator is invalid.");
|
||||
|
||||
int li_Diff = 0;
|
||||
k_Iterator lk_End = mk_List.End;
|
||||
k_Iterator lk_Fwd = lk_Iter.Clone();
|
||||
for (; lk_Fwd != this && lk_Fwd != lk_End; lk_Fwd.Next())
|
||||
++li_Diff;
|
||||
|
||||
if (lk_Fwd == this)
|
||||
return li_Diff;
|
||||
|
||||
li_Diff = 0;
|
||||
k_Iterator lk_Bck = this.Clone();
|
||||
for (; lk_Bck != lk_Iter && lk_Bck != lk_End; lk_Bck.Next())
|
||||
--li_Diff;
|
||||
|
||||
if (lk_Bck == lk_Iter)
|
||||
return li_Diff;
|
||||
|
||||
throw new Exception("Inconsistent state. Concurrency?");
|
||||
}
|
||||
|
||||
public override bool Equals(object ak_Obj)
|
||||
{
|
||||
k_NodeIterator lk_Iter = ak_Obj as k_NodeIterator;
|
||||
if (lk_Iter == null)
|
||||
return false;
|
||||
return object.ReferenceEquals(mk_Current, lk_Iter.mk_Current);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
if (mk_Current == null)
|
||||
return mk_List.GetHashCode();
|
||||
return mk_Current.GetHashCode();
|
||||
}
|
||||
|
||||
public override k_Iterator Clone()
|
||||
{
|
||||
return new k_NodeIterator(mk_List, mk_Current);
|
||||
}
|
||||
|
||||
internal k_Node Node
|
||||
{
|
||||
get { return mk_Current; }
|
||||
}
|
||||
|
||||
internal bool IsValid
|
||||
{
|
||||
get { return (mk_Current == null || (!object.ReferenceEquals(mk_Current.mk_Next, mk_Current) && !object.ReferenceEquals(mk_Current.mk_Prev, mk_Current))); }
|
||||
}
|
||||
}
|
||||
|
||||
private class k_PinnedNodeIterator : k_NodeIterator
|
||||
{
|
||||
public k_PinnedNodeIterator(k_List ak_List, k_Node ak_Node)
|
||||
: base(ak_List, ak_Node)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Move(int ai_Count)
|
||||
{
|
||||
throw new k_IteratorPinnedException();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private int mi_Count;
|
||||
private k_Node mk_Head, mk_Tail;
|
||||
private k_Iterator mk_Begin, mk_End;
|
||||
|
||||
public k_List()
|
||||
{
|
||||
mk_End = new k_PinnedNodeIterator(this, null);
|
||||
mk_Begin = mk_End;
|
||||
}
|
||||
|
||||
// IContainer Members
|
||||
public k_Iterator Begin
|
||||
{
|
||||
get
|
||||
{
|
||||
if (mi_Count == 0)
|
||||
return mk_End;
|
||||
if (mk_Begin == null)
|
||||
mk_Begin = new k_PinnedNodeIterator(this, mk_Head);
|
||||
return mk_Begin;
|
||||
}
|
||||
}
|
||||
|
||||
public k_Iterator End
|
||||
{
|
||||
get { return mk_End; }
|
||||
}
|
||||
|
||||
public bool IsEmpty
|
||||
{
|
||||
get { return (mi_Count == 0); }
|
||||
}
|
||||
|
||||
public k_Iterator Find(object ak_Value)
|
||||
{
|
||||
return k_Algorithm.Find(this.Begin, this.End, ak_Value);
|
||||
}
|
||||
|
||||
public k_Iterator Erase(k_Iterator ak_Where)
|
||||
{
|
||||
//System.Diagnostics.Debug.Assert(object.ReferenceEquals(this, ak_Where.Collection), "Iterator does not belong to this list.");
|
||||
if (ak_Where == this.End)
|
||||
return this.End;
|
||||
return Erase(ak_Where, ak_Where + 1);
|
||||
}
|
||||
|
||||
public k_Iterator Erase(k_Iterator ak_First, k_Iterator ak_Last)
|
||||
{
|
||||
//System.Diagnostics.Debug.Assert(object.ReferenceEquals(this, ak_First.Collection) && object.ReferenceEquals(this, ak_Last.Collection), "Iterators do not belong to this collection.");
|
||||
int li_Distance = ak_Last - ak_First;
|
||||
if (li_Distance == 0)
|
||||
return ak_Last;
|
||||
|
||||
k_Node lk_First = ((k_NodeIterator)ak_First).Node;
|
||||
k_Node lk_Prev = lk_First.mk_Prev;
|
||||
k_Node lk_Next = (ak_Last != this.End) ? ((k_NodeIterator)ak_Last).Node : null;
|
||||
|
||||
if (lk_Prev != null)
|
||||
lk_Prev.mk_Next = lk_Next;
|
||||
else
|
||||
{
|
||||
//System.Diagnostics.Debug.Assert(object.ReferenceEquals(mk_Head, lk_First), "Inconsistent list state");
|
||||
mk_Head = lk_Next;
|
||||
mk_Begin = null;
|
||||
}
|
||||
|
||||
if (lk_Next != null)
|
||||
lk_Next.mk_Prev = lk_Prev;
|
||||
else
|
||||
{
|
||||
//System.Diagnostics.Debug.Assert(object.ReferenceEquals(mk_Tail, ((k_NodeIterator)(ak_Last-1)).Node), "Inconsistent list state");
|
||||
mk_Tail = lk_Prev;
|
||||
}
|
||||
|
||||
mi_Count -= li_Distance;
|
||||
|
||||
#if (DEBUG)
|
||||
// create invalid nodes linking to itself
|
||||
k_Node lk_Node = lk_First;
|
||||
while (lk_Node != null && lk_Node != lk_Next)
|
||||
{
|
||||
k_Node lk_Tmp = lk_Node.mk_Next;
|
||||
lk_Node.mk_Next = lk_Node;
|
||||
lk_Node.mk_Prev = lk_Node;
|
||||
|
||||
lk_Node = lk_Tmp;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ak_Last;
|
||||
}
|
||||
|
||||
// ISequence Members
|
||||
public object Front
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.IsEmpty)
|
||||
throw new InvalidOperationException("Empty list");
|
||||
return mk_Head.Value;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (this.IsEmpty)
|
||||
throw new InvalidOperationException("Empty list");
|
||||
mk_Head.Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public object Back
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.IsEmpty)
|
||||
throw new InvalidOperationException("Empty list");
|
||||
return mk_Tail.Value;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (this.IsEmpty)
|
||||
throw new InvalidOperationException("Empty list");
|
||||
mk_Tail.Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void PushFront(object ak_Value)
|
||||
{
|
||||
Insert(this.Begin, ak_Value);
|
||||
}
|
||||
|
||||
public void PopFront()
|
||||
{
|
||||
Erase(this.Begin);
|
||||
}
|
||||
|
||||
public void PushBack(object ak_Value)
|
||||
{
|
||||
Insert(this.End, ak_Value);
|
||||
}
|
||||
|
||||
public void PopBack()
|
||||
{
|
||||
Erase(this.End-1);
|
||||
}
|
||||
|
||||
public void Assign(k_Iterator ak_SrcBegin, k_Iterator ak_SrcEnd)
|
||||
{
|
||||
Clear();
|
||||
Insert(this.End, ak_SrcBegin, ak_SrcEnd);
|
||||
}
|
||||
|
||||
public void Assign(object ak_Value, int ai_Count)
|
||||
{
|
||||
Clear();
|
||||
Insert(this.End, ak_Value, ai_Count);
|
||||
}
|
||||
|
||||
public void Insert(k_Iterator ak_Where, object ak_Value)
|
||||
{
|
||||
//System.Diagnostics.Debug.Assert(object.ReferenceEquals(this, ak_Where.Collection), "Iterator does not belong to this collection.");
|
||||
|
||||
k_Node lk_New = new k_Node(ak_Value);
|
||||
PasteNodeRange((k_NodeIterator)ak_Where, lk_New, lk_New);
|
||||
++mi_Count;
|
||||
}
|
||||
|
||||
public void Insert(k_Iterator ak_Where, k_Iterator ak_SrcBegin, k_Iterator ak_SrcEnd)
|
||||
{
|
||||
//System.Diagnostics.Debug.Assert(object.ReferenceEquals(this, ak_Where.Collection), "Iterator does not belong to this collection.");
|
||||
|
||||
k_Node lk_Start = new k_Node(null), lk_End = lk_Start;
|
||||
|
||||
int li_Count = 0;
|
||||
for (k_Iterator lk_Iter = ak_SrcBegin.Clone(); lk_Iter != ak_SrcEnd; lk_Iter.Next(), ++li_Count)
|
||||
{
|
||||
k_Node lk_New = new k_Node(lk_Iter.Current);
|
||||
lk_End.mk_Next = lk_New;
|
||||
lk_New.mk_Prev = lk_End;
|
||||
lk_End = lk_New;
|
||||
}
|
||||
|
||||
if (li_Count > 0)
|
||||
{
|
||||
PasteNodeRange((k_NodeIterator)ak_Where, lk_Start.mk_Next, lk_End);
|
||||
mi_Count += li_Count;
|
||||
}
|
||||
}
|
||||
|
||||
public void Insert(k_Iterator ak_Where, object ak_Value, int ai_Count)
|
||||
{
|
||||
//System.Diagnostics.Debug.Assert(object.ReferenceEquals(this, ak_Where.Collection), "Iterator does not belong to this collection.");
|
||||
|
||||
k_Node lk_Start = new k_Node(null), lk_End = lk_Start;
|
||||
|
||||
for (int i=0; i<ai_Count; ++i)
|
||||
{
|
||||
k_Node lk_New = new k_Node(ak_Value);
|
||||
lk_End.mk_Next = lk_New;
|
||||
lk_New.mk_Prev = lk_End;
|
||||
lk_End = lk_New;
|
||||
}
|
||||
|
||||
if (ai_Count > 0)
|
||||
{
|
||||
PasteNodeRange((k_NodeIterator)ak_Where, lk_Start.mk_Next, lk_End);
|
||||
mi_Count += ai_Count;
|
||||
}
|
||||
}
|
||||
|
||||
#region IList Members
|
||||
|
||||
public int Add(object ak_Value)
|
||||
{
|
||||
Insert(this.End, ak_Value);
|
||||
return mi_Count;
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
mk_Head = mk_Tail = null;
|
||||
mk_Begin = mk_End;
|
||||
mi_Count = 0;
|
||||
}
|
||||
|
||||
public bool Contains(object ak_Value)
|
||||
{
|
||||
return (this.Find(ak_Value) != this.End);
|
||||
}
|
||||
|
||||
public int IndexOf(object ak_Value)
|
||||
{
|
||||
int li_Index = 0;
|
||||
foreach (object lk_Val in this)
|
||||
{
|
||||
if (object.Equals(lk_Val, ak_Value))
|
||||
return li_Index;
|
||||
++li_Index;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void IList.Insert(int ai_Index, object ak_Value)
|
||||
{
|
||||
this.Insert(this.Begin + ai_Index, ak_Value);
|
||||
}
|
||||
|
||||
void IList.Remove(object ak_Value)
|
||||
{
|
||||
k_NodeIterator lk_Found = (k_NodeIterator)this.Find(ak_Value);
|
||||
if (lk_Found != this.End)
|
||||
Erase(lk_Found);
|
||||
}
|
||||
|
||||
public void RemoveAt(int ai_Index)
|
||||
{
|
||||
Erase(this.Begin + ai_Index);
|
||||
}
|
||||
|
||||
public bool IsFixedSize
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
bool IList.IsReadOnly
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public object this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
k_Iterator lk_Iter = this.Begin + index;
|
||||
return lk_Iter.Current;
|
||||
}
|
||||
set
|
||||
{
|
||||
k_Iterator lk_Iter = this.Begin + index;
|
||||
lk_Iter.Current = value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ICollection Members
|
||||
|
||||
public void CopyTo(Array ak_Array, int ai_Index)
|
||||
{
|
||||
foreach (object lk_Obj in this)
|
||||
ak_Array.SetValue(lk_Obj, ai_Index++);
|
||||
}
|
||||
|
||||
public int Count
|
||||
{
|
||||
get { return mi_Count; }
|
||||
}
|
||||
|
||||
public bool IsSynchronized
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public object SyncRoot
|
||||
{
|
||||
get { return this; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEnumerable Members
|
||||
|
||||
public IEnumerator GetEnumerator()
|
||||
{
|
||||
return new k_IteratorEnumerator(this.Begin, this.End);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ICloneable Members
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
k_List lk_Clone = new k_List();
|
||||
for (k_Iterator lk_Iter = this.Begin.Clone(); lk_Iter != this.End; lk_Iter.Next())
|
||||
lk_Clone.Add(lk_Iter.Current);
|
||||
return lk_Clone;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void PasteNodeRange(k_NodeIterator ak_Where, k_Node ak_First, k_Node ak_Last)
|
||||
{
|
||||
if (ak_Where != this.End)
|
||||
{
|
||||
k_Node lk_Next = ak_Where.Node;
|
||||
k_Node lk_Prev = lk_Next.mk_Prev;
|
||||
|
||||
ak_Last.mk_Next = lk_Next;
|
||||
ak_First.mk_Prev = lk_Prev;
|
||||
if (lk_Next != null)
|
||||
lk_Next.mk_Prev = ak_Last;
|
||||
if (lk_Prev != null)
|
||||
lk_Prev.mk_Next = ak_First;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mk_Tail != null)
|
||||
{
|
||||
mk_Tail.mk_Next = ak_First;
|
||||
ak_First.mk_Prev = mk_Tail;
|
||||
}
|
||||
mk_Tail = ak_Last;
|
||||
}
|
||||
|
||||
if (ak_Where == this.Begin)
|
||||
{
|
||||
mk_Head = ak_First;
|
||||
mk_Begin = null; // recalc on next get
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
108
iTechSharp/System/util/collections/Queue.cs
Normal file
108
iTechSharp/System/util/collections/Queue.cs
Normal file
@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace System.util.collections
|
||||
{
|
||||
/// <summary>
|
||||
/// k_Queue is a first-in, first-out (FIFO) data structure.
|
||||
/// It hides functionality of the underlying container (e.g. k_List, k_Deque)
|
||||
/// and provides a a basic queue class.
|
||||
/// </summary>
|
||||
public class k_Queue : ICollection
|
||||
{
|
||||
private ISequence mk_Container;
|
||||
|
||||
public k_Queue()
|
||||
: this(typeof(k_Deque))
|
||||
{
|
||||
}
|
||||
|
||||
public k_Queue(Type ak_ContainerType)
|
||||
{
|
||||
mk_Container = Activator.CreateInstance(ak_ContainerType) as ISequence;
|
||||
if (mk_Container == null)
|
||||
throw new ArgumentException("Container type must implement ISequence.", "ak_ContainerType");
|
||||
}
|
||||
|
||||
public k_Iterator Begin
|
||||
{
|
||||
get { return mk_Container.Begin; }
|
||||
}
|
||||
|
||||
public k_Iterator End
|
||||
{
|
||||
get { return mk_Container.End; }
|
||||
}
|
||||
|
||||
public object Front
|
||||
{
|
||||
get { return mk_Container.Front; }
|
||||
}
|
||||
|
||||
public object Back
|
||||
{
|
||||
get { return mk_Container.Back; }
|
||||
}
|
||||
|
||||
public bool IsEmpty
|
||||
{
|
||||
get { return mk_Container.IsEmpty; }
|
||||
}
|
||||
|
||||
public k_Iterator Erase(k_Iterator ak_Where)
|
||||
{
|
||||
return mk_Container.Erase(ak_Where);
|
||||
}
|
||||
|
||||
public void Push(object ak_Value)
|
||||
{
|
||||
mk_Container.PushBack(ak_Value);
|
||||
}
|
||||
|
||||
public object Pop()
|
||||
{
|
||||
object lk_Obj = mk_Container.Front;
|
||||
mk_Container.PopFront();
|
||||
return lk_Obj;
|
||||
}
|
||||
|
||||
public IContainer UnderlyingContainer
|
||||
{
|
||||
get { return mk_Container; }
|
||||
}
|
||||
|
||||
#region ICollection Members
|
||||
|
||||
public void CopyTo(Array ak_Array, int ai_Index)
|
||||
{
|
||||
foreach (object lk_Obj in this)
|
||||
ak_Array.SetValue(lk_Obj, ai_Index++);
|
||||
}
|
||||
|
||||
public int Count
|
||||
{
|
||||
get { return mk_Container.Count; }
|
||||
}
|
||||
|
||||
public bool IsSynchronized
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public object SyncRoot
|
||||
{
|
||||
get { return this; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEnumerable Members
|
||||
|
||||
public IEnumerator GetEnumerator()
|
||||
{
|
||||
return new k_IteratorEnumerator(mk_Container.Begin, mk_Container.End);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
699
iTechSharp/System/util/collections/SkipList.cs
Normal file
699
iTechSharp/System/util/collections/SkipList.cs
Normal file
@ -0,0 +1,699 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace System.util.collections
|
||||
{
|
||||
/// <summary>
|
||||
/// A Skip List
|
||||
/// </summary>
|
||||
public class k_SkipList : ISortedMap
|
||||
{
|
||||
#region k_Node Implementation
|
||||
|
||||
private class k_Node
|
||||
{
|
||||
private object mk_Key;
|
||||
private object mk_Value;
|
||||
|
||||
private k_Node[] mk_Next;
|
||||
|
||||
public k_Node(object ak_Key, object ak_Value, int ai_Height)
|
||||
{
|
||||
mk_Next = new k_Node[ai_Height];
|
||||
mk_Key = ak_Key;
|
||||
mk_Value = ak_Value;
|
||||
}
|
||||
|
||||
public object Key
|
||||
{
|
||||
get { return mk_Key; }
|
||||
}
|
||||
|
||||
public object Value
|
||||
{
|
||||
get { return mk_Value; }
|
||||
set { mk_Value = Value; }
|
||||
}
|
||||
|
||||
public DictionaryEntry Item
|
||||
{
|
||||
get { return new DictionaryEntry(mk_Key, mk_Value); }
|
||||
}
|
||||
|
||||
public k_Node[] Next
|
||||
{
|
||||
get { return mk_Next; }
|
||||
}
|
||||
|
||||
public int Height
|
||||
{
|
||||
get { return mk_Next.Length; }
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region k_NodeIterator Implementation
|
||||
|
||||
private class k_NodeIterator : k_Iterator
|
||||
{
|
||||
private readonly k_SkipList mk_List;
|
||||
private k_Node mk_Current;
|
||||
|
||||
public k_NodeIterator(k_SkipList ak_List, k_Node ak_Node)
|
||||
{
|
||||
mk_List = ak_List;
|
||||
mk_Current = ak_Node;
|
||||
}
|
||||
|
||||
public override object Current
|
||||
{
|
||||
get
|
||||
{
|
||||
if (mk_Current == null)
|
||||
throw new k_InvalidPositionException();
|
||||
return mk_Current.Item;
|
||||
}
|
||||
set
|
||||
{
|
||||
DictionaryEntry lr_Entry = (DictionaryEntry)value;
|
||||
if (mk_List.mk_Comparer.Compare(lr_Entry.Key, mk_Current.Key) != 0)
|
||||
throw new ArgumentException("Key values must not be changed.");
|
||||
mk_Current.Value = lr_Entry.Value;
|
||||
}
|
||||
}
|
||||
|
||||
public override object Collection
|
||||
{
|
||||
get { return mk_List; }
|
||||
}
|
||||
|
||||
public override void Move(int ai_Count)
|
||||
{
|
||||
k_Node lk_NewPos = mk_Current;
|
||||
|
||||
if (ai_Count > 0)
|
||||
{
|
||||
while (ai_Count-- > 0)
|
||||
{
|
||||
if (lk_NewPos == null)
|
||||
throw new InvalidOperationException("Tried to moved beyond end element.");
|
||||
|
||||
lk_NewPos = mk_List.Next(lk_NewPos);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (ai_Count++ < 0)
|
||||
{
|
||||
if (lk_NewPos == null)
|
||||
lk_NewPos = mk_List.RightMost();
|
||||
else
|
||||
lk_NewPos = mk_List.Previous(lk_NewPos);
|
||||
|
||||
if (lk_NewPos == null)
|
||||
throw new InvalidOperationException("Tried to move before first element.");
|
||||
}
|
||||
}
|
||||
|
||||
mk_Current = lk_NewPos;
|
||||
}
|
||||
|
||||
public override int Distance(k_Iterator ak_Iter)
|
||||
{
|
||||
k_NodeIterator lk_Iter = (k_NodeIterator)ak_Iter;
|
||||
k_Iterator lk_End = mk_List.End;
|
||||
|
||||
int li_KeyDiff;
|
||||
if (this == lk_End || ak_Iter == lk_End)
|
||||
li_KeyDiff = (this == lk_End && this != ak_Iter) ? 1 : 0;
|
||||
else
|
||||
li_KeyDiff = mk_List.mk_Comparer.Compare(mk_Current.Key, lk_Iter.mk_Current.Key);
|
||||
|
||||
if (li_KeyDiff <= 0)
|
||||
{
|
||||
int li_Diff = 0;
|
||||
k_Iterator lk_Bck = this.Clone();
|
||||
for (; lk_Bck != lk_Iter && lk_Bck != lk_End; lk_Bck.Next())
|
||||
--li_Diff;
|
||||
|
||||
if (lk_Bck == lk_Iter)
|
||||
return li_Diff;
|
||||
}
|
||||
|
||||
if (li_KeyDiff >= 0)
|
||||
{
|
||||
int li_Diff = 0;
|
||||
k_Iterator lk_Fwd = lk_Iter.Clone();
|
||||
for (; lk_Fwd != this && lk_Fwd != lk_End; lk_Fwd.Next())
|
||||
++li_Diff;
|
||||
|
||||
if (lk_Fwd == this)
|
||||
return li_Diff;
|
||||
}
|
||||
|
||||
throw new Exception("Inconsistent state. Concurrency?");
|
||||
}
|
||||
|
||||
public override bool Equals(object ak_Obj)
|
||||
{
|
||||
k_NodeIterator lk_Iter = ak_Obj as k_NodeIterator;
|
||||
if (lk_Iter == null)
|
||||
return false;
|
||||
return object.ReferenceEquals(mk_Current, lk_Iter.mk_Current);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
if (mk_Current == null)
|
||||
return mk_List.GetHashCode();
|
||||
return mk_Current.GetHashCode();
|
||||
}
|
||||
|
||||
public override k_Iterator Clone()
|
||||
{
|
||||
return new k_NodeIterator(mk_List, mk_Current);
|
||||
}
|
||||
|
||||
internal k_Node Node
|
||||
{
|
||||
get { return mk_Current; }
|
||||
}
|
||||
}
|
||||
|
||||
private class k_PinnedNodeIterator : k_NodeIterator
|
||||
{
|
||||
public k_PinnedNodeIterator(k_SkipList ak_List, k_Node ak_Node)
|
||||
: base(ak_List, ak_Node)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Move(int ai_Count)
|
||||
{
|
||||
throw new k_IteratorPinnedException();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private static Random mk_Rand = new Random();
|
||||
|
||||
private IComparer mk_Comparer;
|
||||
private double md_Prob;
|
||||
private int mi_MaxLevel;
|
||||
private int mi_HighestNode;
|
||||
private k_Node mk_Head;
|
||||
private int mi_Count;
|
||||
private k_Iterator mk_End;
|
||||
|
||||
public k_SkipList()
|
||||
: this(System.Collections.Comparer.Default)
|
||||
{
|
||||
}
|
||||
|
||||
public k_SkipList(IComparer ak_Comparer)
|
||||
: this(ak_Comparer, 1.0/Math.E, 16)
|
||||
{
|
||||
}
|
||||
|
||||
public k_SkipList(IComparer ak_Comparer, double ad_Prob, int ai_MaxLevel)
|
||||
{
|
||||
if (ad_Prob >= 1.0 || ad_Prob <= 0)
|
||||
throw new ArgumentException("Invalid probability. Must be (0-1).", "ad_Prob");
|
||||
md_Prob = ad_Prob;
|
||||
mi_MaxLevel = ai_MaxLevel;
|
||||
mk_Comparer = ak_Comparer;
|
||||
mk_Head = new k_Node(null, null, ai_MaxLevel);
|
||||
mk_End = new k_PinnedNodeIterator(this, null);
|
||||
}
|
||||
|
||||
// IContainer Members
|
||||
public k_Iterator Begin
|
||||
{
|
||||
get
|
||||
{
|
||||
if (mi_Count == 0)
|
||||
return this.End;
|
||||
return new k_NodeIterator(this, this.LeftMost());
|
||||
}
|
||||
}
|
||||
|
||||
public k_Iterator End
|
||||
{
|
||||
get { return mk_End; }
|
||||
}
|
||||
|
||||
public bool IsEmpty
|
||||
{
|
||||
get { return (mi_Count == 0); }
|
||||
}
|
||||
|
||||
public k_Iterator Find(object ak_Value)
|
||||
{
|
||||
DictionaryEntry lr_Item = (DictionaryEntry)ak_Value;
|
||||
k_NodeIterator lk_Found = (k_NodeIterator)LowerBound(lr_Item.Key);
|
||||
if (lk_Found != this.End
|
||||
&& mk_Comparer.Compare(lr_Item.Key, lk_Found.Node.Key) == 0 && mk_Comparer.Compare(lr_Item.Value, lk_Found.Node.Value) == 0)
|
||||
return lk_Found;
|
||||
return this.End;
|
||||
}
|
||||
|
||||
public k_Iterator Erase(k_Iterator ak_Where)
|
||||
{
|
||||
return Erase(ak_Where, ak_Where+1);
|
||||
}
|
||||
|
||||
public k_Iterator Erase(k_Iterator ak_First, k_Iterator ak_Last)
|
||||
{
|
||||
if (ak_First == ak_Last)
|
||||
return ak_Last.Clone();
|
||||
|
||||
int li_Count = ak_Last - ak_First;
|
||||
|
||||
k_Node lk_First = ((k_NodeIterator)ak_First).Node;
|
||||
k_Node lk_Last = (ak_Last != this.End) ? ((k_NodeIterator)ak_Last).Node : null;
|
||||
k_Node lk_Node = new k_Node(null, null, mi_HighestNode);
|
||||
|
||||
k_Node lk_Current = mk_Head;
|
||||
for (int li_Level = mi_HighestNode-1; li_Level >= 0; --li_Level)
|
||||
{
|
||||
while (lk_Current.Next[li_Level] != null)
|
||||
{
|
||||
if (ComparePos(lk_Current.Next[li_Level], lk_First) >= 0)
|
||||
break;
|
||||
lk_Current = lk_Current.Next[li_Level];
|
||||
}
|
||||
lk_Node.Next[li_Level] = lk_Current;
|
||||
}
|
||||
|
||||
if (lk_Last == null)
|
||||
{
|
||||
for (int i=0; i<lk_Node.Height; ++i)
|
||||
{
|
||||
k_Node lk_Left = lk_Node.Next[i];
|
||||
lk_Left.Next[i] = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i=0; i<lk_Node.Height; ++i)
|
||||
{
|
||||
k_Node lk_Left = lk_Node.Next[i];
|
||||
|
||||
// for each level skip over erased range
|
||||
lk_Current = lk_Left.Next[i];
|
||||
while (lk_Current != null)
|
||||
{
|
||||
if (ComparePos(lk_Current, lk_Last) >= 0)
|
||||
break;
|
||||
lk_Current = lk_Current.Next[i];
|
||||
}
|
||||
lk_Left.Next[i] = lk_Current;
|
||||
}
|
||||
}
|
||||
|
||||
mi_Count -= li_Count;
|
||||
|
||||
while (mi_HighestNode > 0 && mk_Head.Next[mi_HighestNode-1] == null)
|
||||
--mi_HighestNode;
|
||||
|
||||
return ak_Last;
|
||||
}
|
||||
|
||||
// IMap Members
|
||||
public k_Iterator FindKey(object ak_Key)
|
||||
{
|
||||
k_NodeIterator lk_Found = (k_NodeIterator)LowerBound(ak_Key);
|
||||
if (lk_Found != this.End && mk_Comparer.Compare(ak_Key, lk_Found.Node.Key) == 0)
|
||||
return lk_Found;
|
||||
return this.End;
|
||||
}
|
||||
|
||||
public void Add(DictionaryEntry ar_Entry)
|
||||
{
|
||||
Add(ar_Entry.Key, ar_Entry.Value);
|
||||
}
|
||||
|
||||
public void Insert(k_Iterator ak_SrcBegin, k_Iterator ak_SrcEnd)
|
||||
{
|
||||
for (k_Iterator lk_Iter = ak_SrcBegin.Clone(); lk_Iter != ak_SrcEnd; lk_Iter.Next())
|
||||
Add((DictionaryEntry)lk_Iter.Current);
|
||||
}
|
||||
|
||||
// ISortedMap Members
|
||||
public IComparer Comparer
|
||||
{
|
||||
get { return mk_Comparer; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an iterator to the first element in a list with a key value
|
||||
/// that is equal to or greater than that of a specified key.
|
||||
/// </summary>
|
||||
/// <param name="ak_Key">
|
||||
/// The argument key value to be compared with the sort key of an element
|
||||
/// from the list being searched.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// Location of an element in a list that with a key that is equal to
|
||||
/// or greater than the argument key, or this.End if no match is found for the key.
|
||||
/// </returns>
|
||||
public k_Iterator LowerBound(object ak_Key)
|
||||
{
|
||||
k_Node lk_Found = null;
|
||||
k_Node lk_Current = mk_Head;
|
||||
for (int li_Level = mi_HighestNode-1; li_Level >= 0; --li_Level)
|
||||
{
|
||||
k_Node lk_Next = lk_Current.Next[li_Level];
|
||||
while (lk_Next != null)
|
||||
{
|
||||
int li_Diff = mk_Comparer.Compare(lk_Next.Key, ak_Key);
|
||||
if (li_Diff >= 0)
|
||||
{
|
||||
lk_Found = lk_Next;
|
||||
break;
|
||||
}
|
||||
|
||||
lk_Current = lk_Next;
|
||||
lk_Next = lk_Next.Next[li_Level];
|
||||
}
|
||||
}
|
||||
|
||||
return new k_NodeIterator(this, lk_Found);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an iterator to the first element in a list with a key value
|
||||
/// that is greater than that of a specified key.
|
||||
/// </summary>
|
||||
/// <param name="ak_Key">
|
||||
/// The argument key value to be compared with the sort key of an element
|
||||
/// from the list being searched.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// Location of an element in a list that with a key that is greater
|
||||
/// than the argument key, or this.End if no match is found for the key.
|
||||
/// </returns>
|
||||
public k_Iterator UpperBound(object ak_Key)
|
||||
{
|
||||
k_Node lk_Found = null;
|
||||
k_Node lk_Current = mk_Head;
|
||||
for (int li_Level = mi_HighestNode-1; li_Level >= 0; --li_Level)
|
||||
{
|
||||
k_Node lk_Next = lk_Current.Next[li_Level];
|
||||
while (lk_Next != null)
|
||||
{
|
||||
int li_Diff = mk_Comparer.Compare(lk_Next.Key, ak_Key);
|
||||
if (li_Diff > 0)
|
||||
{
|
||||
lk_Found = lk_Next;
|
||||
break;
|
||||
}
|
||||
|
||||
lk_Current = lk_Next;
|
||||
lk_Next = lk_Next.Next[li_Level];
|
||||
}
|
||||
}
|
||||
|
||||
return new k_NodeIterator(this, lk_Found);
|
||||
}
|
||||
|
||||
#region IDictionary Members
|
||||
|
||||
public void Add(object ak_Key, object ak_Value)
|
||||
{
|
||||
k_Node lk_Node = new k_Node(ak_Key, ak_Value, CalcNewNodeHeight());
|
||||
if (lk_Node.Height > mi_HighestNode)
|
||||
mi_HighestNode = lk_Node.Height;
|
||||
|
||||
FindInsertPos(lk_Node);
|
||||
for (int i=0; i<lk_Node.Height; ++i)
|
||||
{
|
||||
k_Node lk_Left = lk_Node.Next[i];
|
||||
k_Node lk_Tmp = lk_Left.Next[i];
|
||||
lk_Left.Next[i] = lk_Node;
|
||||
lk_Node.Next[i] = lk_Tmp;
|
||||
}
|
||||
|
||||
++mi_Count;
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
Array.Clear(mk_Head.Next, 0, mk_Head.Next.Length);
|
||||
mi_HighestNode = 0;
|
||||
mi_Count = 0;
|
||||
}
|
||||
|
||||
public bool Contains(object ak_Key)
|
||||
{
|
||||
return (FindKey(ak_Key) != this.End);
|
||||
}
|
||||
|
||||
public IDictionaryEnumerator GetEnumerator()
|
||||
{
|
||||
return new k_IteratorDictEnumerator(this.Begin, this.End);
|
||||
}
|
||||
|
||||
public void Remove(object ak_Key)
|
||||
{
|
||||
Erase(LowerBound(ak_Key), UpperBound(ak_Key));
|
||||
}
|
||||
|
||||
public bool IsFixedSize
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public bool IsReadOnly
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public object this[object ak_Key]
|
||||
{
|
||||
get
|
||||
{
|
||||
k_NodeIterator lk_Iter = (k_NodeIterator)FindKey(ak_Key);
|
||||
if (lk_Iter == this.End)
|
||||
return null;
|
||||
return lk_Iter.Node.Value;
|
||||
}
|
||||
set
|
||||
{
|
||||
k_NodeIterator lk_Iter = (k_NodeIterator)FindKey(ak_Key);
|
||||
if (lk_Iter == this.End)
|
||||
throw new ArgumentException("No element for key was found.", "ak_Key");
|
||||
lk_Iter.Node.Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public ICollection Keys
|
||||
{
|
||||
get
|
||||
{
|
||||
object[] lk_Keys = new object[mi_Count];
|
||||
int i = 0;
|
||||
for (k_Iterator lk_Iter = this.Begin.Clone(); lk_Iter != this.End; lk_Iter.Next())
|
||||
lk_Keys[i++] = ((k_NodeIterator)lk_Iter).Node.Key;
|
||||
return lk_Keys;
|
||||
}
|
||||
}
|
||||
|
||||
public ICollection Values
|
||||
{
|
||||
get
|
||||
{
|
||||
object[] lk_Values = new object[mi_Count];
|
||||
int i=0;
|
||||
for (k_Iterator lk_Iter = this.Begin.Clone(); lk_Iter != this.End; lk_Iter.Next())
|
||||
lk_Values[i++] = ((k_NodeIterator)lk_Iter).Node.Value;
|
||||
return lk_Values;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ICollection Members
|
||||
|
||||
public void CopyTo(Array ak_Array, int ai_Index)
|
||||
{
|
||||
foreach (object lk_Obj in this)
|
||||
ak_Array.SetValue(lk_Obj, ai_Index++);
|
||||
}
|
||||
|
||||
public int Count
|
||||
{
|
||||
get { return mi_Count; }
|
||||
}
|
||||
|
||||
public bool IsSynchronized
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public object SyncRoot
|
||||
{
|
||||
get { return this; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEnumerable Members
|
||||
|
||||
IEnumerator System.Collections.IEnumerable.GetEnumerator()
|
||||
{
|
||||
return new k_IteratorEnumerator(this.Begin, this.End);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ICloneable Members
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
k_SkipList lk_Clone = new k_SkipList(mk_Comparer, md_Prob, mi_MaxLevel);
|
||||
lk_Clone.mi_Count = mi_Count;
|
||||
lk_Clone.mi_HighestNode = mi_HighestNode;
|
||||
lk_Clone.mk_Head = CloneR(mk_Head, null);
|
||||
return lk_Clone;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private k_Node Previous(k_Node ak_Node)
|
||||
{
|
||||
k_Node lk_Current = mk_Head;
|
||||
for (int li_Level = mi_HighestNode-1; li_Level >= 0; --li_Level)
|
||||
{
|
||||
while (lk_Current.Next[li_Level] != null)
|
||||
{
|
||||
int li_Diff = mk_Comparer.Compare(lk_Current.Next[li_Level].Key, ak_Node.Key);
|
||||
if (li_Diff > 0)
|
||||
break;
|
||||
if (li_Diff == 0)
|
||||
{
|
||||
k_Node lk_Next = lk_Current;
|
||||
while (lk_Next != null && !object.ReferenceEquals(lk_Next.Next[0], ak_Node))
|
||||
{
|
||||
if (mk_Comparer.Compare(lk_Next.Key, ak_Node.Key) > 0)
|
||||
lk_Next = null;
|
||||
else
|
||||
lk_Next = lk_Next.Next[0];
|
||||
}
|
||||
if (lk_Next == null)
|
||||
break;
|
||||
|
||||
return lk_Next; // found previous node during right-scan of nodes with equal key value
|
||||
}
|
||||
lk_Current = lk_Current.Next[li_Level];
|
||||
}
|
||||
}
|
||||
if (object.ReferenceEquals(mk_Head, lk_Current))
|
||||
return null;
|
||||
return lk_Current;
|
||||
}
|
||||
|
||||
private k_Node Next(k_Node ak_Node)
|
||||
{
|
||||
return ak_Node.Next[0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return leftmost node in list.
|
||||
/// </summary>
|
||||
/// <returns>Found node</returns>
|
||||
private k_Node LeftMost()
|
||||
{
|
||||
return mk_Head.Next[0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return rightmost node in list.
|
||||
/// </summary>
|
||||
/// <returns>Found node</returns>
|
||||
private k_Node RightMost()
|
||||
{
|
||||
k_Node lk_Current = mk_Head.Next[mi_HighestNode-1];
|
||||
for (int li_Level = mi_HighestNode-1; li_Level >= 0; --li_Level)
|
||||
{
|
||||
while (lk_Current.Next[li_Level] != null)
|
||||
lk_Current = lk_Current.Next[li_Level];
|
||||
}
|
||||
return lk_Current;
|
||||
}
|
||||
|
||||
private void FindInsertPos(k_Node ak_Node)
|
||||
{
|
||||
k_Node lk_Current = mk_Head;
|
||||
for (int li_Level = mi_HighestNode-1; li_Level >= 0; --li_Level)
|
||||
{
|
||||
while (lk_Current.Next[li_Level] != null && mk_Comparer.Compare(lk_Current.Next[li_Level].Key, ak_Node.Key) < 0)
|
||||
lk_Current = lk_Current.Next[li_Level];
|
||||
|
||||
if (li_Level < ak_Node.Height)
|
||||
ak_Node.Next[li_Level] = lk_Current;
|
||||
}
|
||||
}
|
||||
|
||||
private int CalcNewNodeHeight()
|
||||
{
|
||||
double ld_Rnd = mk_Rand.NextDouble();
|
||||
|
||||
int li_Level = 1;
|
||||
for (double ld_Pow = md_Prob; li_Level < mi_MaxLevel; ++li_Level, ld_Pow*=md_Prob)
|
||||
{
|
||||
if (ld_Pow < ld_Rnd)
|
||||
break;
|
||||
}
|
||||
|
||||
return li_Level;
|
||||
}
|
||||
|
||||
private int ComparePos(k_Node ak_Left, k_Node ak_Right)
|
||||
{
|
||||
if (object.ReferenceEquals(ak_Left, ak_Right))
|
||||
return 0;
|
||||
|
||||
int li_Diff = mk_Comparer.Compare(ak_Left.Key, ak_Right.Key);
|
||||
if (li_Diff != 0)
|
||||
return li_Diff;
|
||||
|
||||
k_Node lk_Current = ak_Left;
|
||||
for (;;)
|
||||
{
|
||||
if (lk_Current == null || mk_Comparer.Compare(lk_Current.Key, ak_Right.Key) > 0)
|
||||
return 1;
|
||||
else if (object.ReferenceEquals(lk_Current, ak_Right))
|
||||
return -1;
|
||||
|
||||
lk_Current = lk_Current.Next[0];
|
||||
}
|
||||
}
|
||||
|
||||
private k_Node CloneR(k_Node ak_Node, k_Node ak_NextHigher)
|
||||
{
|
||||
k_Node lk_New = new k_Node(ak_Node.Key, ak_Node.Value, ak_Node.Height);
|
||||
|
||||
for (int i=ak_Node.Height-1; i>=0; --i)
|
||||
{
|
||||
// simply copy two links with equal target next to each other
|
||||
if (i < ak_Node.Height-1 && object.ReferenceEquals(ak_Node.Next[i], ak_Node.Next[i+1]))
|
||||
{
|
||||
lk_New.Next[i] = lk_New.Next[i+1];
|
||||
continue;
|
||||
}
|
||||
|
||||
k_Node lk_Next = ak_Node.Next[i];
|
||||
if (lk_Next != null && lk_Next.Height-1 <= i)
|
||||
{
|
||||
k_Node lk_Higher = (i < ak_Node.Height-1) ? ak_Node.Next[i+1] : ak_NextHigher;
|
||||
lk_New.Next[i] = CloneR(lk_Next, lk_Higher);
|
||||
}
|
||||
else
|
||||
lk_New.Next[i] = ak_NextHigher;
|
||||
}
|
||||
return lk_New;
|
||||
}
|
||||
}
|
||||
}
|
101
iTechSharp/System/util/collections/Stack.cs
Normal file
101
iTechSharp/System/util/collections/Stack.cs
Normal file
@ -0,0 +1,101 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace System.util.collections
|
||||
{
|
||||
/// <summary>
|
||||
/// A push-down stack using an underlying k_Vector.
|
||||
/// Last in first out (LIFO).
|
||||
/// </summary>
|
||||
public class k_Stack : ICollection
|
||||
{
|
||||
private ISequence mk_Items; // stack container
|
||||
private int mi_MaxSize;
|
||||
|
||||
public k_Stack()
|
||||
{
|
||||
mk_Items = new k_Vector();
|
||||
mi_MaxSize = int.MaxValue;
|
||||
}
|
||||
|
||||
public k_Stack(int ai_Capacity, bool ab_FixedSize)
|
||||
{
|
||||
mk_Items = new k_Vector(ai_Capacity);
|
||||
mi_MaxSize = (ab_FixedSize) ? ai_Capacity : int.MaxValue;
|
||||
}
|
||||
|
||||
public object Top
|
||||
{
|
||||
get { return mk_Items.Back; }
|
||||
set { mk_Items.Back = value; }
|
||||
}
|
||||
|
||||
public object this[int ai_Index]
|
||||
{
|
||||
get { return (mk_Items.Begin+ai_Index).Current; }
|
||||
set { (mk_Items.Begin+ai_Index).Current = value; }
|
||||
}
|
||||
|
||||
public void Push(object ak_Value)
|
||||
{
|
||||
if (mk_Items.Count >= mi_MaxSize)
|
||||
throw new StackOverflowException("Stack overflow");
|
||||
|
||||
mk_Items.PushBack(ak_Value);
|
||||
}
|
||||
|
||||
public object Pop()
|
||||
{
|
||||
if (mk_Items.Count == 0)
|
||||
throw new StackOverflowException("Stack underflow");
|
||||
|
||||
object lk_Obj = mk_Items.Back;
|
||||
mk_Items.PopBack();
|
||||
return lk_Obj;
|
||||
}
|
||||
|
||||
public bool IsEmpty
|
||||
{
|
||||
get { return mk_Items.IsEmpty; }
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
mk_Items.Clear();
|
||||
}
|
||||
|
||||
#region ICollection Members
|
||||
|
||||
public void CopyTo(Array ak_Array, int ai_Index)
|
||||
{
|
||||
for (k_Iterator lk_Iter = mk_Items.Begin.Clone(); lk_Iter != mk_Items.End; lk_Iter.Next())
|
||||
ak_Array.SetValue(lk_Iter.Current, ai_Index++);
|
||||
}
|
||||
|
||||
public int Count
|
||||
{
|
||||
get { return mk_Items.Count; }
|
||||
}
|
||||
|
||||
public bool IsSynchronized
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public object SyncRoot
|
||||
{
|
||||
get { return this; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEnumerable Members
|
||||
|
||||
public IEnumerator GetEnumerator()
|
||||
{
|
||||
return new k_IteratorEnumerator(mk_Items.Begin, mk_Items.End);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
830
iTechSharp/System/util/collections/Tree.cs
Normal file
830
iTechSharp/System/util/collections/Tree.cs
Normal file
@ -0,0 +1,830 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace System.util.collections
|
||||
{
|
||||
/// <summary>
|
||||
/// k_Tree is a red-black balanced search tree (BST) implementation.
|
||||
/// Complexity of find, insert and erase operations is near O(lg n).
|
||||
/// </summary>
|
||||
public class k_Tree : ISortedMap
|
||||
{
|
||||
#region k_Node Implementation
|
||||
|
||||
private class k_Node
|
||||
{
|
||||
private object mk_Key;
|
||||
private object mk_Value;
|
||||
private bool mb_Red;
|
||||
public k_Node mk_Left, mk_Right, mk_Parent; // public to simplify fixup & clone (passing by ref)
|
||||
|
||||
public k_Node(object ak_Key, object ak_Value, k_Node ak_Parent)
|
||||
{
|
||||
mk_Key = ak_Key;
|
||||
mk_Value = ak_Value;
|
||||
mk_Parent = ak_Parent;
|
||||
mb_Red = true;
|
||||
}
|
||||
|
||||
public object Key
|
||||
{
|
||||
get { return mk_Key; }
|
||||
}
|
||||
|
||||
public object Value
|
||||
{
|
||||
get { return mk_Value; }
|
||||
set { mk_Value = value; }
|
||||
}
|
||||
|
||||
public DictionaryEntry Item
|
||||
{
|
||||
get { return new DictionaryEntry(mk_Key, mk_Value); }
|
||||
}
|
||||
|
||||
public bool Red
|
||||
{
|
||||
get { return mb_Red; }
|
||||
set { mb_Red = value; }
|
||||
}
|
||||
|
||||
public static void SwapItems(k_Node ak_A, k_Node ak_B)
|
||||
{
|
||||
object lk_Tmp = ak_A.mk_Key;
|
||||
ak_A.mk_Key = ak_B.mk_Key;
|
||||
ak_B.mk_Key = lk_Tmp;
|
||||
|
||||
lk_Tmp = ak_A.mk_Value;
|
||||
ak_A.mk_Value = ak_B.mk_Value;
|
||||
ak_B.mk_Value = lk_Tmp;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region k_NodeIterator Implementation
|
||||
|
||||
private class k_NodeIterator : k_Iterator
|
||||
{
|
||||
private readonly k_Tree mk_Tree;
|
||||
private k_Node mk_Current;
|
||||
|
||||
public k_NodeIterator(k_Tree ak_Tree, k_Node ak_Node)
|
||||
{
|
||||
mk_Tree = ak_Tree;
|
||||
mk_Current = ak_Node;
|
||||
}
|
||||
|
||||
public override object Current
|
||||
{
|
||||
get
|
||||
{
|
||||
if (mk_Current == null)
|
||||
throw new k_InvalidPositionException();
|
||||
return mk_Current.Item;
|
||||
}
|
||||
set
|
||||
{
|
||||
DictionaryEntry lr_Entry = (DictionaryEntry)value;
|
||||
if (mk_Tree.mk_Comparer.Compare(lr_Entry.Key, mk_Current.Key) != 0)
|
||||
throw new ArgumentException("Key values must not be changed.");
|
||||
mk_Current.Value = lr_Entry.Value;
|
||||
}
|
||||
}
|
||||
|
||||
public override object Collection
|
||||
{
|
||||
get { return mk_Tree; }
|
||||
}
|
||||
|
||||
public override void Move(int ai_Count)
|
||||
{
|
||||
k_Node lk_NewPos = mk_Current;
|
||||
|
||||
if (ai_Count > 0)
|
||||
{
|
||||
while (ai_Count-- > 0)
|
||||
{
|
||||
if (lk_NewPos == null)
|
||||
throw new InvalidOperationException("Tried to moved beyond end element.");
|
||||
|
||||
lk_NewPos = k_Tree.Next(lk_NewPos);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (ai_Count++ < 0)
|
||||
{
|
||||
if (lk_NewPos == null)
|
||||
lk_NewPos = mk_Tree.mk_Right;
|
||||
else
|
||||
lk_NewPos = k_Tree.Previous(lk_NewPos);
|
||||
|
||||
if (lk_NewPos == null)
|
||||
throw new InvalidOperationException("Tried to move before first element.");
|
||||
}
|
||||
}
|
||||
|
||||
mk_Current = lk_NewPos;
|
||||
}
|
||||
|
||||
public override int Distance(k_Iterator ak_Iter)
|
||||
{
|
||||
k_NodeIterator lk_Iter = ak_Iter as k_NodeIterator;
|
||||
if (lk_Iter == null || !object.ReferenceEquals(lk_Iter.Collection, this.Collection))
|
||||
throw new ArgumentException("Cannot determine distance of iterators belonging to different collections.");
|
||||
|
||||
k_Iterator lk_End = mk_Tree.End;
|
||||
|
||||
int li_KeyDiff;
|
||||
if (this == lk_End || ak_Iter == lk_End)
|
||||
li_KeyDiff = (this == lk_End && this != ak_Iter) ? 1 : 0;
|
||||
else
|
||||
li_KeyDiff = mk_Tree.mk_Comparer.Compare(mk_Current.Key, lk_Iter.mk_Current.Key);
|
||||
|
||||
if (li_KeyDiff <= 0)
|
||||
{
|
||||
int li_Diff = 0;
|
||||
k_Iterator lk_Bck = this.Clone();
|
||||
for (; lk_Bck != ak_Iter && lk_Bck != lk_End; lk_Bck.Next())
|
||||
--li_Diff;
|
||||
|
||||
if (lk_Bck == ak_Iter)
|
||||
return li_Diff;
|
||||
}
|
||||
|
||||
if (li_KeyDiff >= 0)
|
||||
{
|
||||
int li_Diff = 0;
|
||||
k_Iterator lk_Fwd = ak_Iter.Clone();
|
||||
for (; lk_Fwd != this && lk_Fwd != lk_End; lk_Fwd.Next())
|
||||
++li_Diff;
|
||||
|
||||
if (lk_Fwd == this)
|
||||
return li_Diff;
|
||||
}
|
||||
|
||||
throw new Exception("Inconsistent state. Concurrency?");
|
||||
}
|
||||
|
||||
public override bool Equals(object ak_Obj)
|
||||
{
|
||||
k_NodeIterator lk_Iter = ak_Obj as k_NodeIterator;
|
||||
if (lk_Iter == null)
|
||||
return false;
|
||||
return object.ReferenceEquals(mk_Current, lk_Iter.mk_Current);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
if (mk_Current == null)
|
||||
return mk_Tree.GetHashCode();
|
||||
return mk_Current.GetHashCode();
|
||||
}
|
||||
|
||||
public override k_Iterator Clone()
|
||||
{
|
||||
return new k_NodeIterator(mk_Tree, mk_Current);
|
||||
}
|
||||
|
||||
internal k_Node Node
|
||||
{
|
||||
get { return mk_Current; }
|
||||
}
|
||||
}
|
||||
|
||||
private class k_PinnedNodeIterator : k_NodeIterator
|
||||
{
|
||||
public k_PinnedNodeIterator(k_Tree ak_Tree, k_Node ak_Node)
|
||||
: base(ak_Tree, ak_Node)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Move(int ai_Count)
|
||||
{
|
||||
throw new k_IteratorPinnedException();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private k_Node mk_Head, mk_Left, mk_Right;
|
||||
private k_Iterator mk_End;
|
||||
private int mi_Count;
|
||||
private IComparer mk_Comparer;
|
||||
private bool mb_AllowDuplicateKeys;
|
||||
|
||||
public k_Tree()
|
||||
: this(false)
|
||||
{
|
||||
}
|
||||
|
||||
public k_Tree(bool ab_AllowDuplicateKeys)
|
||||
: this(ab_AllowDuplicateKeys, System.Collections.Comparer.Default)
|
||||
{
|
||||
}
|
||||
|
||||
public k_Tree(bool ab_AllowDuplicateKeys, IComparer ak_Comparer)
|
||||
{
|
||||
mb_AllowDuplicateKeys = ab_AllowDuplicateKeys;
|
||||
mk_Comparer = ak_Comparer;
|
||||
mk_End = new k_PinnedNodeIterator(this, null);
|
||||
}
|
||||
|
||||
// IContainer Members
|
||||
public k_Iterator Begin
|
||||
{
|
||||
get
|
||||
{
|
||||
if (mi_Count == 0)
|
||||
return this.End;
|
||||
return new k_NodeIterator(this, mk_Left);
|
||||
}
|
||||
}
|
||||
|
||||
public k_Iterator End
|
||||
{
|
||||
get { return mk_End; }
|
||||
}
|
||||
|
||||
public bool IsEmpty
|
||||
{
|
||||
get { return (mi_Count == 0); }
|
||||
}
|
||||
|
||||
public k_Iterator Find(object ak_Value)
|
||||
{
|
||||
DictionaryEntry lr_Item = (DictionaryEntry)ak_Value;
|
||||
k_Node lk_Found = FindInternal(mk_Head, lr_Item.Key);
|
||||
if (lk_Found != null && mk_Comparer.Compare(lk_Found.Value, lr_Item.Value) == 0)
|
||||
return new k_NodeIterator(this, lk_Found);
|
||||
return this.End;
|
||||
}
|
||||
|
||||
public k_Iterator Erase(k_Iterator ak_Where)
|
||||
{
|
||||
//System.Diagnostics.Debug.Assert(object.ReferenceEquals(this, ak_Where.Collection), "Iterator does not belong to this tree.");
|
||||
k_Iterator lk_Successor = ak_Where + 1;
|
||||
RemoveNode(((k_NodeIterator)ak_Where).Node);
|
||||
return lk_Successor;
|
||||
}
|
||||
|
||||
public k_Iterator Erase(k_Iterator ak_First, k_Iterator ak_Last)
|
||||
{
|
||||
if (ak_First == this.Begin && ak_Last == this.End)
|
||||
{
|
||||
Clear();
|
||||
return ak_Last.Clone();
|
||||
}
|
||||
|
||||
k_Iterator lk_Current = ak_First;
|
||||
while (lk_Current != ak_Last)
|
||||
lk_Current = Erase(lk_Current);
|
||||
return lk_Current;
|
||||
}
|
||||
|
||||
// IMap Members
|
||||
public void Add(DictionaryEntry ar_Item)
|
||||
{
|
||||
Add(ar_Item.Key, ar_Item.Value);
|
||||
}
|
||||
|
||||
public k_Iterator FindKey(object ak_Key)
|
||||
{
|
||||
return new k_NodeIterator(this, FindInternal(mk_Head, ak_Key));
|
||||
}
|
||||
|
||||
public void Insert(k_Iterator ak_SrcBegin, k_Iterator ak_SrcEnd)
|
||||
{
|
||||
for (k_Iterator lk_Iter = ak_SrcBegin.Clone(); lk_Iter != ak_SrcEnd; lk_Iter.Next())
|
||||
Add((DictionaryEntry)lk_Iter.Current);
|
||||
}
|
||||
|
||||
// ISortedMap Members
|
||||
public IComparer Comparer
|
||||
{
|
||||
get { return mk_Comparer; }
|
||||
}
|
||||
|
||||
public k_Iterator LowerBound(object ak_Key)
|
||||
{
|
||||
k_Node lk_Node = mk_Head;
|
||||
k_Node lk_Found = null;
|
||||
while (lk_Node != null)
|
||||
{
|
||||
if (mk_Comparer.Compare(lk_Node.Key, ak_Key) < 0)
|
||||
lk_Node = lk_Node.mk_Right;
|
||||
else
|
||||
{
|
||||
lk_Found = lk_Node;
|
||||
lk_Node = lk_Node.mk_Left;
|
||||
}
|
||||
}
|
||||
return new k_NodeIterator(this, lk_Found);
|
||||
}
|
||||
|
||||
public k_Iterator UpperBound(object ak_Key)
|
||||
{
|
||||
k_Node lk_Node = mk_Head;
|
||||
k_Node lk_Found = null;
|
||||
while (lk_Node != null)
|
||||
{
|
||||
if (mk_Comparer.Compare(lk_Node.Key, ak_Key) > 0)
|
||||
{
|
||||
lk_Found = lk_Node;
|
||||
lk_Node = lk_Node.mk_Left;
|
||||
}
|
||||
else
|
||||
lk_Node = lk_Node.mk_Right;
|
||||
}
|
||||
return new k_NodeIterator(this, lk_Found);
|
||||
}
|
||||
|
||||
#region IDictionary Members
|
||||
|
||||
public void Add(object ak_Key, object ak_Value)
|
||||
{
|
||||
Insert(ref mk_Head, null, ak_Key, ak_Value, false);
|
||||
mk_Head.Red = false;
|
||||
++mi_Count;
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
mi_Count = 0;
|
||||
mk_Head = null;
|
||||
mk_Left = null;
|
||||
mk_Right = null;
|
||||
}
|
||||
|
||||
public bool Contains(object ak_Key)
|
||||
{
|
||||
return (FindInternal(mk_Head, ak_Key) != null);
|
||||
}
|
||||
|
||||
public IDictionaryEnumerator GetEnumerator()
|
||||
{
|
||||
return new k_IteratorDictEnumerator(this.Begin, this.End);
|
||||
}
|
||||
|
||||
public void Remove(object ak_Key)
|
||||
{
|
||||
RemoveNode(FindInternal(mk_Head, ak_Key));
|
||||
}
|
||||
|
||||
public bool IsFixedSize
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public bool IsReadOnly
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public object this[object ak_Key]
|
||||
{
|
||||
get
|
||||
{
|
||||
k_Node lk_Node = FindInternal(mk_Head, ak_Key);
|
||||
if (lk_Node == null)
|
||||
return null;
|
||||
return lk_Node.Value;
|
||||
}
|
||||
set
|
||||
{
|
||||
k_Node lk_Node = FindInternal(mk_Head, ak_Key);
|
||||
if (lk_Node == null)
|
||||
Add(new DictionaryEntry(ak_Key, value));
|
||||
else
|
||||
lk_Node.Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public ICollection Keys
|
||||
{
|
||||
get
|
||||
{
|
||||
int i=0;
|
||||
object[] lk_Keys = new object[mi_Count];
|
||||
foreach (DictionaryEntry lr_Entry in this)
|
||||
lk_Keys[i++] = lr_Entry.Key;
|
||||
return lk_Keys;
|
||||
}
|
||||
}
|
||||
|
||||
public ICollection Values
|
||||
{
|
||||
get
|
||||
{
|
||||
int i=0;
|
||||
object[] lk_Values = new object[mi_Count];
|
||||
foreach (DictionaryEntry lr_Entry in this)
|
||||
lk_Values[i++] = lr_Entry.Value;
|
||||
return lk_Values;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ICollection Members
|
||||
|
||||
public void CopyTo(Array ak_Array, int ai_Index)
|
||||
{
|
||||
foreach (DictionaryEntry lr_Entry in this)
|
||||
ak_Array.SetValue(lr_Entry, ai_Index++);
|
||||
}
|
||||
|
||||
public int Count
|
||||
{
|
||||
get { return mi_Count; }
|
||||
}
|
||||
|
||||
public bool IsSynchronized
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public object SyncRoot
|
||||
{
|
||||
get { return this; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEnumerable Members
|
||||
|
||||
IEnumerator System.Collections.IEnumerable.GetEnumerator()
|
||||
{
|
||||
return new k_IteratorEnumerator(this.Begin, this.End);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ICloneable Members
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
k_Tree lk_Clone = new k_Tree(mb_AllowDuplicateKeys, mk_Comparer);
|
||||
lk_Clone.mi_Count = mi_Count;
|
||||
CloneRecursive(mk_Head, null, ref lk_Clone.mk_Head);
|
||||
lk_Clone.mk_Left = k_Tree.LeftMost(lk_Clone.mk_Head);
|
||||
lk_Clone.mk_Right = k_Tree.RightMost(lk_Clone.mk_Head);
|
||||
|
||||
return lk_Clone;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void CloneRecursive(k_Node ak_Node, k_Node ak_Parent, ref k_Node ak_Link)
|
||||
{
|
||||
if (ak_Node == null)
|
||||
return;
|
||||
|
||||
ak_Link = new k_Node(ak_Node.Key, ak_Node.Value, ak_Parent);
|
||||
ak_Link.Red = ak_Node.Red;
|
||||
|
||||
CloneRecursive(ak_Node.mk_Left, ak_Link, ref ak_Link.mk_Left);
|
||||
CloneRecursive(ak_Node.mk_Right, ak_Link, ref ak_Link.mk_Right);
|
||||
}
|
||||
|
||||
private bool IsRed(k_Node ak_Node)
|
||||
{
|
||||
return (ak_Node != null && ak_Node.Red);
|
||||
}
|
||||
|
||||
private k_Node FindInternal(k_Node ak_Node, object ak_Key)
|
||||
{
|
||||
while (ak_Node != null)
|
||||
{
|
||||
int li_Diff = mk_Comparer.Compare(ak_Key, ak_Node.Key);
|
||||
if (li_Diff == 0)
|
||||
return ak_Node;
|
||||
ak_Node = (li_Diff < 0) ? ak_Node.mk_Left : ak_Node.mk_Right;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return leftmost node in subtree.
|
||||
/// </summary>
|
||||
/// <param name="ak_Node">Node where to start search</param>
|
||||
/// <returns>Found node</returns>
|
||||
private static k_Node LeftMost(k_Node ak_Node)
|
||||
{
|
||||
if (ak_Node == null)
|
||||
return null;
|
||||
while (ak_Node.mk_Left != null)
|
||||
ak_Node = ak_Node.mk_Left;
|
||||
return ak_Node;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return rightmost node in subtree.
|
||||
/// </summary>
|
||||
/// <param name="ak_Node">Node where to start search</param>
|
||||
/// <returns>Found node</returns>
|
||||
private static k_Node RightMost(k_Node ak_Node)
|
||||
{
|
||||
if (ak_Node == null)
|
||||
return null;
|
||||
while (ak_Node.mk_Right != null)
|
||||
ak_Node = ak_Node.mk_Right;
|
||||
return ak_Node;
|
||||
}
|
||||
|
||||
private static k_Node Previous(k_Node ak_Node) // the next smaller
|
||||
{
|
||||
if (ak_Node.mk_Left != null)
|
||||
return RightMost(ak_Node.mk_Left);
|
||||
|
||||
k_Node lk_Parent = ak_Node.mk_Parent;
|
||||
while (lk_Parent != null && lk_Parent.mk_Left == ak_Node)
|
||||
{
|
||||
ak_Node = lk_Parent;
|
||||
lk_Parent = lk_Parent.mk_Parent;
|
||||
}
|
||||
return lk_Parent;
|
||||
}
|
||||
|
||||
private static k_Node Next(k_Node ak_Node)
|
||||
{
|
||||
if (ak_Node.mk_Right != null)
|
||||
return LeftMost(ak_Node.mk_Right);
|
||||
|
||||
k_Node lk_Parent = ak_Node.mk_Parent;
|
||||
while (lk_Parent != null && lk_Parent.mk_Right == ak_Node)
|
||||
{
|
||||
ak_Node = lk_Parent;
|
||||
lk_Parent = lk_Parent.mk_Parent;
|
||||
}
|
||||
return lk_Parent;
|
||||
}
|
||||
|
||||
private void RemoveNode(k_Node ak_Node)
|
||||
{
|
||||
if (ak_Node == null)
|
||||
return;
|
||||
if (ak_Node == mk_Head)
|
||||
UnlinkNode(ref mk_Head);
|
||||
else if (ak_Node == ak_Node.mk_Parent.mk_Right)
|
||||
UnlinkNode(ref ak_Node.mk_Parent.mk_Right);
|
||||
else
|
||||
UnlinkNode(ref ak_Node.mk_Parent.mk_Left);
|
||||
}
|
||||
|
||||
private void UnlinkNode(ref k_Node ak_Node)
|
||||
{
|
||||
bool lb_Red = ak_Node.Red;
|
||||
k_Node lk_Erased = ak_Node;
|
||||
|
||||
k_Node lk_PatchNode = null;
|
||||
if (ak_Node.mk_Right == null)
|
||||
lk_PatchNode = ak_Node.mk_Left;
|
||||
else if (ak_Node.mk_Left == null)
|
||||
lk_PatchNode = ak_Node.mk_Right;
|
||||
else
|
||||
lk_PatchNode = ak_Node;
|
||||
|
||||
k_Node lk_PatchParent = null, lk_FixNode = null;
|
||||
if (lk_PatchNode == null)
|
||||
{
|
||||
lk_PatchParent = ak_Node.mk_Parent;
|
||||
ak_Node = null;
|
||||
}
|
||||
else if (lk_PatchNode != ak_Node)
|
||||
{
|
||||
lk_PatchNode.mk_Parent = ak_Node.mk_Parent;
|
||||
ak_Node = lk_PatchNode;
|
||||
lk_PatchParent = lk_PatchNode.mk_Parent;
|
||||
}
|
||||
else
|
||||
{
|
||||
// two subtrees
|
||||
lk_PatchNode = RightMost(ak_Node.mk_Left);
|
||||
if (lk_PatchNode.mk_Parent.mk_Right == lk_PatchNode)
|
||||
lk_PatchNode.mk_Parent.mk_Right = lk_PatchNode.mk_Left;
|
||||
else
|
||||
lk_PatchNode.mk_Parent.mk_Left = lk_PatchNode.mk_Left;
|
||||
|
||||
lb_Red = lk_PatchNode.Red;
|
||||
if (lk_PatchNode.mk_Left != null)
|
||||
lk_PatchNode.mk_Left.mk_Parent = lk_PatchNode.mk_Parent;
|
||||
|
||||
lk_PatchParent = lk_PatchNode.mk_Parent;
|
||||
lk_FixNode = lk_PatchNode.mk_Left;
|
||||
|
||||
k_Node.SwapItems(ak_Node, lk_PatchNode);
|
||||
|
||||
// ensure that mk_Left and/or mk_Right are corrected after unlink
|
||||
lk_Erased = lk_PatchNode;
|
||||
}
|
||||
|
||||
if (!lb_Red && lk_PatchParent != null)
|
||||
{
|
||||
// erased node was black link - rebalance the tree
|
||||
while (!IsRed(lk_FixNode) && lk_FixNode != mk_Head)
|
||||
{
|
||||
if (lk_PatchParent.mk_Left != null || lk_PatchParent.mk_Right != null)
|
||||
{
|
||||
if (lk_PatchParent.mk_Left == lk_FixNode)
|
||||
{
|
||||
// fixup right subtree
|
||||
k_Node lk_Node = lk_PatchParent.mk_Right;
|
||||
|
||||
if (IsRed(lk_Node))
|
||||
{
|
||||
lk_Node.Red = false;
|
||||
lk_PatchParent.Red = true;
|
||||
RotateLeft(lk_PatchParent);
|
||||
lk_Node = lk_PatchParent.mk_Right;
|
||||
}
|
||||
|
||||
if (lk_Node != null)
|
||||
{
|
||||
if (!IsRed(lk_Node.mk_Left) && !IsRed(lk_Node.mk_Right))
|
||||
lk_Node.Red = true;
|
||||
else
|
||||
{
|
||||
if (!IsRed(lk_Node.mk_Right))
|
||||
{
|
||||
lk_Node.Red = true;
|
||||
lk_Node.mk_Left.Red = false;
|
||||
RotateRight(lk_Node);
|
||||
lk_Node = lk_PatchParent.mk_Right;
|
||||
}
|
||||
|
||||
lk_Node.Red = lk_PatchParent.Red;
|
||||
lk_PatchParent.Red = false;
|
||||
lk_Node.mk_Right.Red = false;
|
||||
RotateLeft(lk_PatchParent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// fixup leftsubtree
|
||||
k_Node lk_Node = lk_PatchParent.mk_Left;
|
||||
|
||||
if (IsRed(lk_Node))
|
||||
{
|
||||
lk_Node.Red = false;
|
||||
lk_PatchParent.Red = true;
|
||||
RotateRight(lk_PatchParent);
|
||||
lk_Node = lk_PatchParent.mk_Left;
|
||||
}
|
||||
|
||||
if (lk_Node != null)
|
||||
{
|
||||
if (!IsRed(lk_Node.mk_Left) && !IsRed(lk_Node.mk_Right))
|
||||
lk_Node.Red = true;
|
||||
else
|
||||
{
|
||||
if (!IsRed(lk_Node.mk_Left))
|
||||
{
|
||||
lk_Node.Red = true;
|
||||
lk_Node.mk_Right.Red = false;
|
||||
RotateLeft(lk_Node);
|
||||
lk_Node = lk_PatchParent.mk_Left;
|
||||
}
|
||||
|
||||
lk_Node.Red = lk_PatchParent.Red;
|
||||
lk_PatchParent.Red = false;
|
||||
lk_Node.mk_Left.Red = false;
|
||||
RotateRight(lk_PatchParent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
lk_FixNode = lk_PatchParent;
|
||||
lk_PatchParent = lk_PatchParent.mk_Parent;
|
||||
}
|
||||
|
||||
if (lk_FixNode != null)
|
||||
lk_FixNode.Red = false;
|
||||
}
|
||||
|
||||
--mi_Count;
|
||||
|
||||
if (object.ReferenceEquals(lk_Erased, mk_Right))
|
||||
mk_Right = k_Tree.RightMost(mk_Head);
|
||||
if (object.ReferenceEquals(lk_Erased, mk_Left))
|
||||
mk_Left = k_Tree.LeftMost(mk_Head);
|
||||
}
|
||||
|
||||
private void Insert(ref k_Node ak_Node, k_Node ak_Parent, object ak_Key, object ak_Value, bool ab_RightMove)
|
||||
{
|
||||
if (ak_Node == null)
|
||||
{
|
||||
ak_Node = new k_Node(ak_Key, ak_Value, ak_Parent);
|
||||
if (object.ReferenceEquals(ak_Parent, mk_Right) && (ak_Parent == null || ab_RightMove))
|
||||
mk_Right = ak_Node;
|
||||
if (object.ReferenceEquals(ak_Parent, mk_Left) && (ak_Parent == null || !ab_RightMove))
|
||||
mk_Left = ak_Node;
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsRed(ak_Node.mk_Left) && IsRed(ak_Node.mk_Right))
|
||||
{
|
||||
ak_Node.Red = true;
|
||||
ak_Node.mk_Left.Red = false;
|
||||
ak_Node.mk_Right.Red = false;
|
||||
}
|
||||
|
||||
int li_Diff = mk_Comparer.Compare(ak_Key, ak_Node.Key);
|
||||
if (!mb_AllowDuplicateKeys && li_Diff == 0)
|
||||
throw new ArgumentException("An element with the same key already exists in the tree.");
|
||||
|
||||
if (li_Diff < 0)
|
||||
{
|
||||
Insert(ref ak_Node.mk_Left, ak_Node, ak_Key, ak_Value, false);
|
||||
if (IsRed(ak_Node) && IsRed(ak_Node.mk_Left) && ab_RightMove)
|
||||
ak_Node = RotateRight(ak_Node);
|
||||
if (IsRed(ak_Node.mk_Left) && IsRed(ak_Node.mk_Left.mk_Left))
|
||||
{
|
||||
ak_Node = RotateRight(ak_Node);
|
||||
ak_Node.Red = false;
|
||||
ak_Node.mk_Right.Red = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Insert(ref ak_Node.mk_Right, ak_Node, ak_Key, ak_Value, true);
|
||||
if (IsRed(ak_Node) && IsRed(ak_Node.mk_Right) && !ab_RightMove)
|
||||
ak_Node = RotateLeft(ak_Node);
|
||||
if (IsRed(ak_Node.mk_Right) && IsRed(ak_Node.mk_Right.mk_Right))
|
||||
{
|
||||
ak_Node = RotateLeft(ak_Node);
|
||||
ak_Node.Red = false;
|
||||
ak_Node.mk_Left.Red = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
A right rotation: ak_Node.Left takes old position of ak_Node.
|
||||
Makes the old root the right subtree of the new root.
|
||||
|
||||
5 2
|
||||
2 7 -> 1 5
|
||||
1 3 6 8 3 7
|
||||
6 8
|
||||
*/
|
||||
private k_Node RotateRight(k_Node ak_Node)
|
||||
{
|
||||
k_Node lk_Tmp = ak_Node.mk_Left;
|
||||
|
||||
lk_Tmp.mk_Parent = ak_Node.mk_Parent;
|
||||
ak_Node.mk_Parent = lk_Tmp;
|
||||
|
||||
ak_Node.mk_Left = lk_Tmp.mk_Right;
|
||||
if (ak_Node.mk_Left != null)
|
||||
ak_Node.mk_Left.mk_Parent = ak_Node;
|
||||
lk_Tmp.mk_Right = ak_Node;
|
||||
|
||||
// correct parent
|
||||
if (lk_Tmp.mk_Parent == null)
|
||||
mk_Head = lk_Tmp;
|
||||
else if (lk_Tmp.mk_Parent.mk_Right == ak_Node)
|
||||
lk_Tmp.mk_Parent.mk_Right = lk_Tmp;
|
||||
else
|
||||
lk_Tmp.mk_Parent.mk_Left = lk_Tmp;
|
||||
|
||||
return lk_Tmp;
|
||||
}
|
||||
|
||||
/*
|
||||
A left rotation: ak_Node.Right takes old position of ak_Node.
|
||||
Makes the old root the left subtree of the new root.
|
||||
|
||||
5 7
|
||||
2 7 -> 5 8
|
||||
1 3 6 8 2 6
|
||||
1 3
|
||||
*/
|
||||
private k_Node RotateLeft(k_Node ak_Node)
|
||||
{
|
||||
k_Node lk_Tmp = ak_Node.mk_Right;
|
||||
|
||||
lk_Tmp.mk_Parent = ak_Node.mk_Parent;
|
||||
ak_Node.mk_Parent = lk_Tmp;
|
||||
|
||||
ak_Node.mk_Right = lk_Tmp.mk_Left;
|
||||
if (ak_Node.mk_Right != null)
|
||||
ak_Node.mk_Right.mk_Parent = ak_Node;
|
||||
lk_Tmp.mk_Left = ak_Node;
|
||||
|
||||
// correct parent
|
||||
if (lk_Tmp.mk_Parent == null)
|
||||
mk_Head = lk_Tmp;
|
||||
else if (lk_Tmp.mk_Parent.mk_Right == ak_Node)
|
||||
lk_Tmp.mk_Parent.mk_Right = lk_Tmp;
|
||||
else
|
||||
lk_Tmp.mk_Parent.mk_Left = lk_Tmp;
|
||||
|
||||
return lk_Tmp;
|
||||
}
|
||||
}
|
||||
}
|
143
iTechSharp/System/util/collections/Vector.cs
Normal file
143
iTechSharp/System/util/collections/Vector.cs
Normal file
@ -0,0 +1,143 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace System.util.collections
|
||||
{
|
||||
/// <summary>
|
||||
/// One dimensional array of variable size
|
||||
/// </summary>
|
||||
public class k_Vector : ArrayList, ISequence
|
||||
{
|
||||
public k_Vector()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
public k_Vector(int ai_Capacity)
|
||||
: base(ai_Capacity)
|
||||
{
|
||||
}
|
||||
|
||||
public k_Vector(ICollection ak_Collection)
|
||||
: base(ak_Collection)
|
||||
{
|
||||
}
|
||||
|
||||
// IContainer Members
|
||||
public k_Iterator Begin
|
||||
{
|
||||
get { return k_IListIterator.CreateBegin(this); }
|
||||
}
|
||||
|
||||
public k_Iterator End
|
||||
{
|
||||
get { return k_IListIterator.CreateEnd(this); }
|
||||
}
|
||||
|
||||
public bool IsEmpty
|
||||
{
|
||||
get { return (this.Count == 0); }
|
||||
}
|
||||
|
||||
public k_Iterator Find(object ak_Value)
|
||||
{
|
||||
int li_Index = this.IndexOf(ak_Value);
|
||||
if (li_Index < 0)
|
||||
return this.End;
|
||||
return new k_IListIterator(this, li_Index);
|
||||
}
|
||||
|
||||
public k_Iterator Erase(k_Iterator ak_Where)
|
||||
{
|
||||
//System.Diagnostics.Debug.Assert(object.ReferenceEquals(this, ak_Where.Collection), "Iterator does not belong to this collection.");
|
||||
int li_Index = ((k_IListIterator)ak_Where).Index;
|
||||
if (li_Index < this.Count)
|
||||
base.RemoveAt(li_Index);
|
||||
return new k_IListIterator(this, li_Index);
|
||||
}
|
||||
|
||||
public k_Iterator Erase(k_Iterator ak_First, k_Iterator ak_Last)
|
||||
{
|
||||
//System.Diagnostics.Debug.Assert(object.ReferenceEquals(this, ak_First.Collection) && object.ReferenceEquals(this, ak_Last.Collection), "Iterators do not belong to this collection.");
|
||||
int li_FirstIndex = ((k_IListIterator)ak_First).Index;
|
||||
int li_Count = ak_Last - ak_First;
|
||||
|
||||
base.RemoveRange(li_FirstIndex, li_Count);
|
||||
|
||||
return new k_IListIterator(this, li_FirstIndex);
|
||||
}
|
||||
|
||||
// ISequence Members
|
||||
public object Front
|
||||
{
|
||||
get { return this.Begin.Current; }
|
||||
set { this.Begin.Current = value; }
|
||||
}
|
||||
|
||||
public object Back
|
||||
{
|
||||
get { return (this.End-1).Current; }
|
||||
set { (this.End-1).Current = value; }
|
||||
}
|
||||
|
||||
public void PushFront(object ak_Value)
|
||||
{
|
||||
Insert(this.Begin, ak_Value);
|
||||
}
|
||||
|
||||
public void PopFront()
|
||||
{
|
||||
Erase(this.Begin);
|
||||
}
|
||||
|
||||
public void PushBack(object ak_Value)
|
||||
{
|
||||
Insert(this.End, ak_Value);
|
||||
}
|
||||
|
||||
public void PopBack()
|
||||
{
|
||||
Erase(this.End-1);
|
||||
}
|
||||
|
||||
public void Assign(k_Iterator ak_SrcBegin, k_Iterator ak_SrcEnd)
|
||||
{
|
||||
Clear();
|
||||
Insert(this.End, ak_SrcBegin, ak_SrcEnd);
|
||||
}
|
||||
|
||||
public void Assign(object ak_Value, int ai_Count)
|
||||
{
|
||||
Clear();
|
||||
Insert(this.End, ak_Value, ai_Count);
|
||||
}
|
||||
|
||||
public void Insert(k_Iterator ak_Where, object ak_Value)
|
||||
{
|
||||
//System.Diagnostics.Debug.Assert(object.ReferenceEquals(this, ak_Where.Collection), "Iterator does not belong to this collection.");
|
||||
this.Insert(((k_IListIterator)ak_Where).Index, ak_Value);
|
||||
}
|
||||
|
||||
public void Insert(k_Iterator ak_Where, k_Iterator ak_SrcBegin, k_Iterator ak_SrcEnd)
|
||||
{
|
||||
//System.Diagnostics.Debug.Assert(object.ReferenceEquals(this, ak_Where.Collection), "Iterator does not belong to this collection.");
|
||||
InsertRange(((k_IListIterator)ak_Where).Index, new k_CollectionOnIterators(ak_SrcBegin, ak_SrcEnd));
|
||||
}
|
||||
|
||||
public void Insert(k_Iterator ak_Where, object ak_Value, int ai_Count)
|
||||
{
|
||||
int li_Pos = ((k_IListIterator)ak_Where).Index;
|
||||
for (int i=0; i<ai_Count; ++i)
|
||||
base.Insert(li_Pos+i, ak_Value);
|
||||
}
|
||||
|
||||
#region ICloneable Members
|
||||
|
||||
public override object Clone()
|
||||
{
|
||||
return new k_Vector(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
88
iTechSharp/System/util/zlib/Adler32.cs
Normal file
88
iTechSharp/System/util/zlib/Adler32.cs
Normal file
@ -0,0 +1,88 @@
|
||||
using System;
|
||||
/*
|
||||
* $Id: Adler32.cs,v 1.1 2006/06/16 10:56:20 psoares33 Exp $
|
||||
*
|
||||
Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. The names of the authors may not be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* This program is based on zlib-1.1.3, so all credit should go authors
|
||||
* Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
|
||||
* and contributors of zlib.
|
||||
*/
|
||||
|
||||
namespace System.util.zlib {
|
||||
|
||||
internal sealed class Adler32{
|
||||
|
||||
// largest prime smaller than 65536
|
||||
private const int BASE=65521;
|
||||
// NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1
|
||||
private const int NMAX=5552;
|
||||
|
||||
internal long adler32(long adler, byte[] buf, int index, int len){
|
||||
if(buf == null){ return 1L; }
|
||||
|
||||
long s1=adler&0xffff;
|
||||
long s2=(adler>>16)&0xffff;
|
||||
int k;
|
||||
|
||||
while(len > 0) {
|
||||
k=len<NMAX?len:NMAX;
|
||||
len-=k;
|
||||
while(k>=16){
|
||||
s1+=buf[index++]&0xff; s2+=s1;
|
||||
s1+=buf[index++]&0xff; s2+=s1;
|
||||
s1+=buf[index++]&0xff; s2+=s1;
|
||||
s1+=buf[index++]&0xff; s2+=s1;
|
||||
s1+=buf[index++]&0xff; s2+=s1;
|
||||
s1+=buf[index++]&0xff; s2+=s1;
|
||||
s1+=buf[index++]&0xff; s2+=s1;
|
||||
s1+=buf[index++]&0xff; s2+=s1;
|
||||
s1+=buf[index++]&0xff; s2+=s1;
|
||||
s1+=buf[index++]&0xff; s2+=s1;
|
||||
s1+=buf[index++]&0xff; s2+=s1;
|
||||
s1+=buf[index++]&0xff; s2+=s1;
|
||||
s1+=buf[index++]&0xff; s2+=s1;
|
||||
s1+=buf[index++]&0xff; s2+=s1;
|
||||
s1+=buf[index++]&0xff; s2+=s1;
|
||||
s1+=buf[index++]&0xff; s2+=s1;
|
||||
k-=16;
|
||||
}
|
||||
if(k!=0){
|
||||
do{
|
||||
s1+=buf[index++]&0xff; s2+=s1;
|
||||
}
|
||||
while(--k!=0);
|
||||
}
|
||||
s1%=BASE;
|
||||
s2%=BASE;
|
||||
}
|
||||
return (s2<<16)|s1;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
1639
iTechSharp/System/util/zlib/Deflate.cs
Normal file
1639
iTechSharp/System/util/zlib/Deflate.cs
Normal file
File diff suppressed because it is too large
Load Diff
618
iTechSharp/System/util/zlib/InfBlocks.cs
Normal file
618
iTechSharp/System/util/zlib/InfBlocks.cs
Normal file
@ -0,0 +1,618 @@
|
||||
using System;
|
||||
/*
|
||||
* $Id: InfBlocks.cs,v 1.1 2006/06/16 10:56:20 psoares33 Exp $
|
||||
*
|
||||
Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. The names of the authors may not be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* This program is based on zlib-1.1.3, so all credit should go authors
|
||||
* Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
|
||||
* and contributors of zlib.
|
||||
*/
|
||||
|
||||
namespace System.util.zlib {
|
||||
|
||||
internal sealed class InfBlocks{
|
||||
private const int MANY=1440;
|
||||
|
||||
// And'ing with mask[n] masks the lower n bits
|
||||
static private int[] inflate_mask = {
|
||||
0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000f,
|
||||
0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff, 0x000001ff,
|
||||
0x000003ff, 0x000007ff, 0x00000fff, 0x00001fff, 0x00003fff,
|
||||
0x00007fff, 0x0000ffff
|
||||
};
|
||||
|
||||
// Table for deflate from PKZIP's appnote.txt.
|
||||
static int[] border = { // Order of the bit length code lengths
|
||||
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
|
||||
};
|
||||
|
||||
private const int Z_OK=0;
|
||||
private const int Z_STREAM_END=1;
|
||||
private const int Z_NEED_DICT=2;
|
||||
private const int Z_ERRNO=-1;
|
||||
private const int Z_STREAM_ERROR=-2;
|
||||
private const int Z_DATA_ERROR=-3;
|
||||
private const int Z_MEM_ERROR=-4;
|
||||
private const int Z_BUF_ERROR=-5;
|
||||
private const int Z_VERSION_ERROR=-6;
|
||||
|
||||
private const int TYPE=0; // get type bits (3, including end bit)
|
||||
private const int LENS=1; // get lengths for stored
|
||||
private const int STORED=2;// processing stored block
|
||||
private const int TABLE=3; // get table lengths
|
||||
private const int BTREE=4; // get bit lengths tree for a dynamic block
|
||||
private const int DTREE=5; // get length, distance trees for a dynamic block
|
||||
private const int CODES=6; // processing fixed or dynamic block
|
||||
private const int DRY=7; // output remaining window bytes
|
||||
private const int DONE=8; // finished last block, done
|
||||
private const int BAD=9; // ot a data error--stuck here
|
||||
|
||||
internal int mode; // current inflate_block mode
|
||||
|
||||
internal int left; // if STORED, bytes left to copy
|
||||
|
||||
internal int table; // table lengths (14 bits)
|
||||
internal int index; // index into blens (or border)
|
||||
internal int[] blens; // bit lengths of codes
|
||||
internal int[] bb=new int[1]; // bit length tree depth
|
||||
internal int[] tb=new int[1]; // bit length decoding tree
|
||||
|
||||
internal InfCodes codes=new InfCodes(); // if CODES, current state
|
||||
|
||||
int last; // true if this block is the last block
|
||||
|
||||
// mode independent information
|
||||
internal int bitk; // bits in bit buffer
|
||||
internal int bitb; // bit buffer
|
||||
internal int[] hufts; // single malloc for tree space
|
||||
internal byte[] window; // sliding window
|
||||
internal int end; // one byte after sliding window
|
||||
internal int read; // window read pointer
|
||||
internal int write; // window write pointer
|
||||
internal Object checkfn; // check function
|
||||
internal long check; // check on output
|
||||
|
||||
internal InfTree inftree=new InfTree();
|
||||
|
||||
internal InfBlocks(ZStream z, Object checkfn, int w){
|
||||
hufts=new int[MANY*3];
|
||||
window=new byte[w];
|
||||
end=w;
|
||||
this.checkfn = checkfn;
|
||||
mode = TYPE;
|
||||
reset(z, null);
|
||||
}
|
||||
|
||||
internal void reset(ZStream z, long[] c){
|
||||
if(c!=null) c[0]=check;
|
||||
if(mode==BTREE || mode==DTREE){
|
||||
}
|
||||
if(mode==CODES){
|
||||
codes.free(z);
|
||||
}
|
||||
mode=TYPE;
|
||||
bitk=0;
|
||||
bitb=0;
|
||||
read=write=0;
|
||||
|
||||
if(checkfn != null)
|
||||
z.adler=check=z._adler.adler32(0L, null, 0, 0);
|
||||
}
|
||||
|
||||
internal int proc(ZStream z, int r){
|
||||
int t; // temporary storage
|
||||
int b; // bit buffer
|
||||
int k; // bits in bit buffer
|
||||
int p; // input data pointer
|
||||
int n; // bytes available there
|
||||
int q; // output window write pointer
|
||||
int m; { // bytes to end of window or read pointer
|
||||
|
||||
// copy input/output information to locals (UPDATE macro restores)
|
||||
p=z.next_in_index;n=z.avail_in;b=bitb;k=bitk;} {
|
||||
q=write;m=(int)(q<read?read-q-1:end-q);}
|
||||
|
||||
// process input based on current state
|
||||
while(true){
|
||||
switch (mode){
|
||||
case TYPE:
|
||||
|
||||
while(k<(3)){
|
||||
if(n!=0){
|
||||
r=Z_OK;
|
||||
}
|
||||
else{
|
||||
bitb=b; bitk=k;
|
||||
z.avail_in=n;
|
||||
z.total_in+=p-z.next_in_index;z.next_in_index=p;
|
||||
write=q;
|
||||
return inflate_flush(z,r);
|
||||
};
|
||||
n--;
|
||||
b|=(z.next_in[p++]&0xff)<<k;
|
||||
k+=8;
|
||||
}
|
||||
t = (int)(b & 7);
|
||||
last = t & 1;
|
||||
|
||||
switch (t >> 1){
|
||||
case 0: { // stored
|
||||
b>>=(3);k-=(3);}
|
||||
t = k & 7; { // go to byte boundary
|
||||
|
||||
b>>=(t);k-=(t);}
|
||||
mode = LENS; // get length of stored block
|
||||
break;
|
||||
case 1: { // fixed
|
||||
int[] bl=new int[1];
|
||||
int[] bd=new int[1];
|
||||
int[][] tl=new int[1][];
|
||||
int[][] td=new int[1][];
|
||||
|
||||
InfTree.inflate_trees_fixed(bl, bd, tl, td, z);
|
||||
codes.init(bl[0], bd[0], tl[0], 0, td[0], 0, z);
|
||||
} {
|
||||
|
||||
b>>=(3);k-=(3);}
|
||||
|
||||
mode = CODES;
|
||||
break;
|
||||
case 2: { // dynamic
|
||||
|
||||
b>>=(3);k-=(3);}
|
||||
|
||||
mode = TABLE;
|
||||
break;
|
||||
case 3: { // illegal
|
||||
|
||||
b>>=(3);k-=(3);}
|
||||
mode = BAD;
|
||||
z.msg = "invalid block type";
|
||||
r = Z_DATA_ERROR;
|
||||
|
||||
bitb=b; bitk=k;
|
||||
z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
|
||||
write=q;
|
||||
return inflate_flush(z,r);
|
||||
}
|
||||
break;
|
||||
case LENS:
|
||||
|
||||
while(k<(32)){
|
||||
if(n!=0){
|
||||
r=Z_OK;
|
||||
}
|
||||
else{
|
||||
bitb=b; bitk=k;
|
||||
z.avail_in=n;
|
||||
z.total_in+=p-z.next_in_index;z.next_in_index=p;
|
||||
write=q;
|
||||
return inflate_flush(z,r);
|
||||
};
|
||||
n--;
|
||||
b|=(z.next_in[p++]&0xff)<<k;
|
||||
k+=8;
|
||||
}
|
||||
|
||||
if ((((~b) >> 16) & 0xffff) != (b & 0xffff)){
|
||||
mode = BAD;
|
||||
z.msg = "invalid stored block lengths";
|
||||
r = Z_DATA_ERROR;
|
||||
|
||||
bitb=b; bitk=k;
|
||||
z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
|
||||
write=q;
|
||||
return inflate_flush(z,r);
|
||||
}
|
||||
left = (b & 0xffff);
|
||||
b = k = 0; // dump bits
|
||||
mode = left!=0 ? STORED : (last!=0 ? DRY : TYPE);
|
||||
break;
|
||||
case STORED:
|
||||
if (n == 0){
|
||||
bitb=b; bitk=k;
|
||||
z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
|
||||
write=q;
|
||||
return inflate_flush(z,r);
|
||||
}
|
||||
|
||||
if(m==0){
|
||||
if(q==end&&read!=0){
|
||||
q=0; m=(int)(q<read?read-q-1:end-q);
|
||||
}
|
||||
if(m==0){
|
||||
write=q;
|
||||
r=inflate_flush(z,r);
|
||||
q=write;m=(int)(q<read?read-q-1:end-q);
|
||||
if(q==end&&read!=0){
|
||||
q=0; m=(int)(q<read?read-q-1:end-q);
|
||||
}
|
||||
if(m==0){
|
||||
bitb=b; bitk=k;
|
||||
z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
|
||||
write=q;
|
||||
return inflate_flush(z,r);
|
||||
}
|
||||
}
|
||||
}
|
||||
r=Z_OK;
|
||||
|
||||
t = left;
|
||||
if(t>n) t = n;
|
||||
if(t>m) t = m;
|
||||
System.Array.Copy(z.next_in, p, window, q, t);
|
||||
p += t; n -= t;
|
||||
q += t; m -= t;
|
||||
if ((left -= t) != 0)
|
||||
break;
|
||||
mode = last!=0 ? DRY : TYPE;
|
||||
break;
|
||||
case TABLE:
|
||||
|
||||
while(k<(14)){
|
||||
if(n!=0){
|
||||
r=Z_OK;
|
||||
}
|
||||
else{
|
||||
bitb=b; bitk=k;
|
||||
z.avail_in=n;
|
||||
z.total_in+=p-z.next_in_index;z.next_in_index=p;
|
||||
write=q;
|
||||
return inflate_flush(z,r);
|
||||
};
|
||||
n--;
|
||||
b|=(z.next_in[p++]&0xff)<<k;
|
||||
k+=8;
|
||||
}
|
||||
|
||||
table = t = (b & 0x3fff);
|
||||
if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29) {
|
||||
mode = BAD;
|
||||
z.msg = "too many length or distance symbols";
|
||||
r = Z_DATA_ERROR;
|
||||
|
||||
bitb=b; bitk=k;
|
||||
z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
|
||||
write=q;
|
||||
return inflate_flush(z,r);
|
||||
}
|
||||
t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
|
||||
if(blens==null || blens.Length<t){
|
||||
blens=new int[t];
|
||||
}
|
||||
else{
|
||||
for(int i=0; i<t; i++){blens[i]=0;}
|
||||
} {
|
||||
|
||||
b>>=(14);k-=(14);}
|
||||
|
||||
index = 0;
|
||||
mode = BTREE;
|
||||
goto case BTREE;
|
||||
case BTREE:
|
||||
while (index < 4 + (table >> 10)){
|
||||
while(k<(3)){
|
||||
if(n!=0){
|
||||
r=Z_OK;
|
||||
}
|
||||
else{
|
||||
bitb=b; bitk=k;
|
||||
z.avail_in=n;
|
||||
z.total_in+=p-z.next_in_index;z.next_in_index=p;
|
||||
write=q;
|
||||
return inflate_flush(z,r);
|
||||
};
|
||||
n--;
|
||||
b|=(z.next_in[p++]&0xff)<<k;
|
||||
k+=8;
|
||||
}
|
||||
|
||||
blens[border[index++]] = b&7; {
|
||||
|
||||
b>>=(3);k-=(3);}
|
||||
}
|
||||
|
||||
while(index < 19){
|
||||
blens[border[index++]] = 0;
|
||||
}
|
||||
|
||||
bb[0] = 7;
|
||||
t = inftree.inflate_trees_bits(blens, bb, tb, hufts, z);
|
||||
if (t != Z_OK){
|
||||
r = t;
|
||||
if (r == Z_DATA_ERROR){
|
||||
blens=null;
|
||||
mode = BAD;
|
||||
}
|
||||
|
||||
bitb=b; bitk=k;
|
||||
z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
|
||||
write=q;
|
||||
return inflate_flush(z,r);
|
||||
}
|
||||
|
||||
index = 0;
|
||||
mode = DTREE;
|
||||
goto case DTREE;
|
||||
case DTREE:
|
||||
while (true){
|
||||
t = table;
|
||||
if(!(index < 258 + (t & 0x1f) + ((t >> 5) & 0x1f))){
|
||||
break;
|
||||
}
|
||||
|
||||
int i, j, c;
|
||||
|
||||
t = bb[0];
|
||||
|
||||
while(k<(t)){
|
||||
if(n!=0){
|
||||
r=Z_OK;
|
||||
}
|
||||
else{
|
||||
bitb=b; bitk=k;
|
||||
z.avail_in=n;
|
||||
z.total_in+=p-z.next_in_index;z.next_in_index=p;
|
||||
write=q;
|
||||
return inflate_flush(z,r);
|
||||
};
|
||||
n--;
|
||||
b|=(z.next_in[p++]&0xff)<<k;
|
||||
k+=8;
|
||||
}
|
||||
|
||||
if(tb[0]==-1){
|
||||
//System.err.println("null...");
|
||||
}
|
||||
|
||||
t=hufts[(tb[0]+(b&inflate_mask[t]))*3+1];
|
||||
c=hufts[(tb[0]+(b&inflate_mask[t]))*3+2];
|
||||
|
||||
if (c < 16){
|
||||
b>>=(t);k-=(t);
|
||||
blens[index++] = c;
|
||||
}
|
||||
else { // c == 16..18
|
||||
i = c == 18 ? 7 : c - 14;
|
||||
j = c == 18 ? 11 : 3;
|
||||
|
||||
while(k<(t+i)){
|
||||
if(n!=0){
|
||||
r=Z_OK;
|
||||
}
|
||||
else{
|
||||
bitb=b; bitk=k;
|
||||
z.avail_in=n;
|
||||
z.total_in+=p-z.next_in_index;z.next_in_index=p;
|
||||
write=q;
|
||||
return inflate_flush(z,r);
|
||||
};
|
||||
n--;
|
||||
b|=(z.next_in[p++]&0xff)<<k;
|
||||
k+=8;
|
||||
}
|
||||
|
||||
b>>=(t);k-=(t);
|
||||
|
||||
j += (b & inflate_mask[i]);
|
||||
|
||||
b>>=(i);k-=(i);
|
||||
|
||||
i = index;
|
||||
t = table;
|
||||
if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) ||
|
||||
(c == 16 && i < 1)){
|
||||
blens=null;
|
||||
mode = BAD;
|
||||
z.msg = "invalid bit length repeat";
|
||||
r = Z_DATA_ERROR;
|
||||
|
||||
bitb=b; bitk=k;
|
||||
z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
|
||||
write=q;
|
||||
return inflate_flush(z,r);
|
||||
}
|
||||
|
||||
c = c == 16 ? blens[i-1] : 0;
|
||||
do{
|
||||
blens[i++] = c;
|
||||
}
|
||||
while (--j!=0);
|
||||
index = i;
|
||||
}
|
||||
}
|
||||
|
||||
tb[0]=-1; {
|
||||
int[] bl=new int[1];
|
||||
int[] bd=new int[1];
|
||||
int[] tl=new int[1];
|
||||
int[] td=new int[1];
|
||||
bl[0] = 9; // must be <= 9 for lookahead assumptions
|
||||
bd[0] = 6; // must be <= 9 for lookahead assumptions
|
||||
|
||||
t = table;
|
||||
t = inftree.inflate_trees_dynamic(257 + (t & 0x1f),
|
||||
1 + ((t >> 5) & 0x1f),
|
||||
blens, bl, bd, tl, td, hufts, z);
|
||||
|
||||
if (t != Z_OK){
|
||||
if (t == Z_DATA_ERROR){
|
||||
blens=null;
|
||||
mode = BAD;
|
||||
}
|
||||
r = t;
|
||||
|
||||
bitb=b; bitk=k;
|
||||
z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
|
||||
write=q;
|
||||
return inflate_flush(z,r);
|
||||
}
|
||||
codes.init(bl[0], bd[0], hufts, tl[0], hufts, td[0], z);
|
||||
}
|
||||
mode = CODES;
|
||||
goto case CODES;
|
||||
case CODES:
|
||||
bitb=b; bitk=k;
|
||||
z.avail_in=n; z.total_in+=p-z.next_in_index;z.next_in_index=p;
|
||||
write=q;
|
||||
|
||||
if ((r = codes.proc(this, z, r)) != Z_STREAM_END){
|
||||
return inflate_flush(z, r);
|
||||
}
|
||||
r = Z_OK;
|
||||
codes.free(z);
|
||||
|
||||
p=z.next_in_index; n=z.avail_in;b=bitb;k=bitk;
|
||||
q=write;m=(int)(q<read?read-q-1:end-q);
|
||||
|
||||
if (last==0){
|
||||
mode = TYPE;
|
||||
break;
|
||||
}
|
||||
mode = DRY;
|
||||
goto case DRY;
|
||||
case DRY:
|
||||
write=q;
|
||||
r=inflate_flush(z, r);
|
||||
q=write; m=(int)(q<read?read-q-1:end-q);
|
||||
if (read != write){
|
||||
bitb=b; bitk=k;
|
||||
z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
|
||||
write=q;
|
||||
return inflate_flush(z, r);
|
||||
}
|
||||
mode = DONE;
|
||||
goto case DONE;
|
||||
case DONE:
|
||||
r = Z_STREAM_END;
|
||||
|
||||
bitb=b; bitk=k;
|
||||
z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
|
||||
write=q;
|
||||
return inflate_flush(z, r);
|
||||
case BAD:
|
||||
r = Z_DATA_ERROR;
|
||||
|
||||
bitb=b; bitk=k;
|
||||
z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
|
||||
write=q;
|
||||
return inflate_flush(z, r);
|
||||
|
||||
default:
|
||||
r = Z_STREAM_ERROR;
|
||||
|
||||
bitb=b; bitk=k;
|
||||
z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
|
||||
write=q;
|
||||
return inflate_flush(z, r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void free(ZStream z){
|
||||
reset(z, null);
|
||||
window=null;
|
||||
hufts=null;
|
||||
//ZFREE(z, s);
|
||||
}
|
||||
|
||||
internal void set_dictionary(byte[] d, int start, int n){
|
||||
System.Array.Copy(d, start, window, 0, n);
|
||||
read = write = n;
|
||||
}
|
||||
|
||||
// Returns true if inflate is currently at the end of a block generated
|
||||
// by Z_SYNC_FLUSH or Z_FULL_FLUSH.
|
||||
internal int sync_point(){
|
||||
return mode == LENS ? 1 : 0;
|
||||
}
|
||||
|
||||
// copy as much as possible from the sliding window to the output area
|
||||
internal int inflate_flush(ZStream z, int r){
|
||||
int n;
|
||||
int p;
|
||||
int q;
|
||||
|
||||
// local copies of source and destination pointers
|
||||
p = z.next_out_index;
|
||||
q = read;
|
||||
|
||||
// compute number of bytes to copy as far as end of window
|
||||
n = (int)((q <= write ? write : end) - q);
|
||||
if (n > z.avail_out) n = z.avail_out;
|
||||
if (n!=0 && r == Z_BUF_ERROR) r = Z_OK;
|
||||
|
||||
// update counters
|
||||
z.avail_out -= n;
|
||||
z.total_out += n;
|
||||
|
||||
// update check information
|
||||
if(checkfn != null)
|
||||
z.adler=check=z._adler.adler32(check, window, q, n);
|
||||
|
||||
// copy as far as end of window
|
||||
System.Array.Copy(window, q, z.next_out, p, n);
|
||||
p += n;
|
||||
q += n;
|
||||
|
||||
// see if more to copy at beginning of window
|
||||
if (q == end){
|
||||
// wrap pointers
|
||||
q = 0;
|
||||
if (write == end)
|
||||
write = 0;
|
||||
|
||||
// compute bytes to copy
|
||||
n = write - q;
|
||||
if (n > z.avail_out) n = z.avail_out;
|
||||
if (n!=0 && r == Z_BUF_ERROR) r = Z_OK;
|
||||
|
||||
// update counters
|
||||
z.avail_out -= n;
|
||||
z.total_out += n;
|
||||
|
||||
// update check information
|
||||
if(checkfn != null)
|
||||
z.adler=check=z._adler.adler32(check, window, q, n);
|
||||
|
||||
// copy
|
||||
System.Array.Copy(window, q, z.next_out, p, n);
|
||||
p += n;
|
||||
q += n;
|
||||
}
|
||||
|
||||
// update pointers
|
||||
z.next_out_index = p;
|
||||
read = q;
|
||||
|
||||
// done
|
||||
return r;
|
||||
}
|
||||
}
|
||||
}
|
611
iTechSharp/System/util/zlib/InfCodes.cs
Normal file
611
iTechSharp/System/util/zlib/InfCodes.cs
Normal file
@ -0,0 +1,611 @@
|
||||
using System;
|
||||
/*
|
||||
* $Id: InfCodes.cs,v 1.1 2006/06/16 10:56:20 psoares33 Exp $
|
||||
*
|
||||
Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. The names of the authors may not be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* This program is based on zlib-1.1.3, so all credit should go authors
|
||||
* Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
|
||||
* and contributors of zlib.
|
||||
*/
|
||||
|
||||
namespace System.util.zlib {
|
||||
|
||||
internal sealed class InfCodes{
|
||||
|
||||
static private int[] inflate_mask = {
|
||||
0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000f,
|
||||
0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff, 0x000001ff,
|
||||
0x000003ff, 0x000007ff, 0x00000fff, 0x00001fff, 0x00003fff,
|
||||
0x00007fff, 0x0000ffff
|
||||
};
|
||||
|
||||
private const int Z_OK=0;
|
||||
private const int Z_STREAM_END=1;
|
||||
private const int Z_NEED_DICT=2;
|
||||
private const int Z_ERRNO=-1;
|
||||
private const int Z_STREAM_ERROR=-2;
|
||||
private const int Z_DATA_ERROR=-3;
|
||||
private const int Z_MEM_ERROR=-4;
|
||||
private const int Z_BUF_ERROR=-5;
|
||||
private const int Z_VERSION_ERROR=-6;
|
||||
|
||||
// waiting for "i:"=input,
|
||||
// "o:"=output,
|
||||
// "x:"=nothing
|
||||
private const int START=0; // x: set up for LEN
|
||||
private const int LEN=1; // i: get length/literal/eob next
|
||||
private const int LENEXT=2; // i: getting length extra (have base)
|
||||
private const int DIST=3; // i: get distance next
|
||||
private const int DISTEXT=4;// i: getting distance extra
|
||||
private const int COPY=5; // o: copying bytes in window, waiting for space
|
||||
private const int LIT=6; // o: got literal, waiting for output space
|
||||
private const int WASH=7; // o: got eob, possibly still output waiting
|
||||
private const int END=8; // x: got eob and all data flushed
|
||||
private const int BADCODE=9;// x: got error
|
||||
|
||||
int mode; // current inflate_codes mode
|
||||
|
||||
// mode dependent information
|
||||
int len;
|
||||
|
||||
int[] tree; // pointer into tree
|
||||
int tree_index=0;
|
||||
int need; // bits needed
|
||||
|
||||
int lit;
|
||||
|
||||
// if EXT or COPY, where and how much
|
||||
int get; // bits to get for extra
|
||||
int dist; // distance back to copy from
|
||||
|
||||
byte lbits; // ltree bits decoded per branch
|
||||
byte dbits; // dtree bits decoder per branch
|
||||
int[] ltree; // literal/length/eob tree
|
||||
int ltree_index; // literal/length/eob tree
|
||||
int[] dtree; // distance tree
|
||||
int dtree_index; // distance tree
|
||||
|
||||
internal InfCodes(){
|
||||
}
|
||||
internal void init(int bl, int bd,
|
||||
int[] tl, int tl_index,
|
||||
int[] td, int td_index, ZStream z){
|
||||
mode=START;
|
||||
lbits=(byte)bl;
|
||||
dbits=(byte)bd;
|
||||
ltree=tl;
|
||||
ltree_index=tl_index;
|
||||
dtree = td;
|
||||
dtree_index=td_index;
|
||||
tree=null;
|
||||
}
|
||||
|
||||
internal int proc(InfBlocks s, ZStream z, int r){
|
||||
int j; // temporary storage
|
||||
int tindex; // temporary pointer
|
||||
int e; // extra bits or operation
|
||||
int b=0; // bit buffer
|
||||
int k=0; // bits in bit buffer
|
||||
int p=0; // input data pointer
|
||||
int n; // bytes available there
|
||||
int q; // output window write pointer
|
||||
int m; // bytes to end of window or read pointer
|
||||
int f; // pointer to copy strings from
|
||||
|
||||
// copy input/output information to locals (UPDATE macro restores)
|
||||
p=z.next_in_index;n=z.avail_in;b=s.bitb;k=s.bitk;
|
||||
q=s.write;m=q<s.read?s.read-q-1:s.end-q;
|
||||
|
||||
// process input and output based on current state
|
||||
while (true){
|
||||
switch (mode){
|
||||
// waiting for "i:"=input, "o:"=output, "x:"=nothing
|
||||
case START: // x: set up for LEN
|
||||
if (m >= 258 && n >= 10){
|
||||
|
||||
s.bitb=b;s.bitk=k;
|
||||
z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
|
||||
s.write=q;
|
||||
r = inflate_fast(lbits, dbits,
|
||||
ltree, ltree_index,
|
||||
dtree, dtree_index,
|
||||
s, z);
|
||||
|
||||
p=z.next_in_index;n=z.avail_in;b=s.bitb;k=s.bitk;
|
||||
q=s.write;m=q<s.read?s.read-q-1:s.end-q;
|
||||
|
||||
if (r != Z_OK){
|
||||
mode = r == Z_STREAM_END ? WASH : BADCODE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
need = lbits;
|
||||
tree = ltree;
|
||||
tree_index=ltree_index;
|
||||
|
||||
mode = LEN;
|
||||
goto case LEN;
|
||||
case LEN: // i: get length/literal/eob next
|
||||
j = need;
|
||||
|
||||
while(k<(j)){
|
||||
if(n!=0)r=Z_OK;
|
||||
else{
|
||||
|
||||
s.bitb=b;s.bitk=k;
|
||||
z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
|
||||
s.write=q;
|
||||
return s.inflate_flush(z,r);
|
||||
}
|
||||
n--;
|
||||
b|=(z.next_in[p++]&0xff)<<k;
|
||||
k+=8;
|
||||
}
|
||||
|
||||
tindex=(tree_index+(b&inflate_mask[j]))*3;
|
||||
|
||||
b>>=(tree[tindex+1]);
|
||||
k-=(tree[tindex+1]);
|
||||
|
||||
e=tree[tindex];
|
||||
|
||||
if(e == 0){ // literal
|
||||
lit = tree[tindex+2];
|
||||
mode = LIT;
|
||||
break;
|
||||
}
|
||||
if((e & 16)!=0 ){ // length
|
||||
get = e & 15;
|
||||
len = tree[tindex+2];
|
||||
mode = LENEXT;
|
||||
break;
|
||||
}
|
||||
if ((e & 64) == 0){ // next table
|
||||
need = e;
|
||||
tree_index = tindex/3+tree[tindex+2];
|
||||
break;
|
||||
}
|
||||
if ((e & 32)!=0){ // end of block
|
||||
mode = WASH;
|
||||
break;
|
||||
}
|
||||
mode = BADCODE; // invalid code
|
||||
z.msg = "invalid literal/length code";
|
||||
r = Z_DATA_ERROR;
|
||||
|
||||
s.bitb=b;s.bitk=k;
|
||||
z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
|
||||
s.write=q;
|
||||
return s.inflate_flush(z,r);
|
||||
|
||||
case LENEXT: // i: getting length extra (have base)
|
||||
j = get;
|
||||
|
||||
while(k<(j)){
|
||||
if(n!=0)r=Z_OK;
|
||||
else{
|
||||
|
||||
s.bitb=b;s.bitk=k;
|
||||
z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
|
||||
s.write=q;
|
||||
return s.inflate_flush(z,r);
|
||||
}
|
||||
n--; b|=(z.next_in[p++]&0xff)<<k;
|
||||
k+=8;
|
||||
}
|
||||
|
||||
len += (b & inflate_mask[j]);
|
||||
|
||||
b>>=j;
|
||||
k-=j;
|
||||
|
||||
need = dbits;
|
||||
tree = dtree;
|
||||
tree_index=dtree_index;
|
||||
mode = DIST;
|
||||
goto case DIST;
|
||||
case DIST: // i: get distance next
|
||||
j = need;
|
||||
|
||||
while(k<(j)){
|
||||
if(n!=0)r=Z_OK;
|
||||
else{
|
||||
|
||||
s.bitb=b;s.bitk=k;
|
||||
z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
|
||||
s.write=q;
|
||||
return s.inflate_flush(z,r);
|
||||
}
|
||||
n--; b|=(z.next_in[p++]&0xff)<<k;
|
||||
k+=8;
|
||||
}
|
||||
|
||||
tindex=(tree_index+(b & inflate_mask[j]))*3;
|
||||
|
||||
b>>=tree[tindex+1];
|
||||
k-=tree[tindex+1];
|
||||
|
||||
e = (tree[tindex]);
|
||||
if((e & 16)!=0){ // distance
|
||||
get = e & 15;
|
||||
dist = tree[tindex+2];
|
||||
mode = DISTEXT;
|
||||
break;
|
||||
}
|
||||
if ((e & 64) == 0){ // next table
|
||||
need = e;
|
||||
tree_index = tindex/3 + tree[tindex+2];
|
||||
break;
|
||||
}
|
||||
mode = BADCODE; // invalid code
|
||||
z.msg = "invalid distance code";
|
||||
r = Z_DATA_ERROR;
|
||||
|
||||
s.bitb=b;s.bitk=k;
|
||||
z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
|
||||
s.write=q;
|
||||
return s.inflate_flush(z,r);
|
||||
|
||||
case DISTEXT: // i: getting distance extra
|
||||
j = get;
|
||||
|
||||
while(k<(j)){
|
||||
if(n!=0)r=Z_OK;
|
||||
else{
|
||||
|
||||
s.bitb=b;s.bitk=k;
|
||||
z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
|
||||
s.write=q;
|
||||
return s.inflate_flush(z,r);
|
||||
}
|
||||
n--; b|=(z.next_in[p++]&0xff)<<k;
|
||||
k+=8;
|
||||
}
|
||||
|
||||
dist += (b & inflate_mask[j]);
|
||||
|
||||
b>>=j;
|
||||
k-=j;
|
||||
|
||||
mode = COPY;
|
||||
goto case COPY;
|
||||
case COPY: // o: copying bytes in window, waiting for space
|
||||
f = q - dist;
|
||||
while(f < 0){ // modulo window size-"while" instead
|
||||
f += s.end; // of "if" handles invalid distances
|
||||
}
|
||||
while (len!=0){
|
||||
|
||||
if(m==0){
|
||||
if(q==s.end&&s.read!=0){q=0;m=q<s.read?s.read-q-1:s.end-q;}
|
||||
if(m==0){
|
||||
s.write=q; r=s.inflate_flush(z,r);
|
||||
q=s.write;m=q<s.read?s.read-q-1:s.end-q;
|
||||
|
||||
if(q==s.end&&s.read!=0){q=0;m=q<s.read?s.read-q-1:s.end-q;}
|
||||
|
||||
if(m==0){
|
||||
s.bitb=b;s.bitk=k;
|
||||
z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
|
||||
s.write=q;
|
||||
return s.inflate_flush(z,r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
s.window[q++]=s.window[f++]; m--;
|
||||
|
||||
if (f == s.end)
|
||||
f = 0;
|
||||
len--;
|
||||
}
|
||||
mode = START;
|
||||
break;
|
||||
case LIT: // o: got literal, waiting for output space
|
||||
if(m==0){
|
||||
if(q==s.end&&s.read!=0){q=0;m=q<s.read?s.read-q-1:s.end-q;}
|
||||
if(m==0){
|
||||
s.write=q; r=s.inflate_flush(z,r);
|
||||
q=s.write;m=q<s.read?s.read-q-1:s.end-q;
|
||||
|
||||
if(q==s.end&&s.read!=0){q=0;m=q<s.read?s.read-q-1:s.end-q;}
|
||||
if(m==0){
|
||||
s.bitb=b;s.bitk=k;
|
||||
z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
|
||||
s.write=q;
|
||||
return s.inflate_flush(z,r);
|
||||
}
|
||||
}
|
||||
}
|
||||
r=Z_OK;
|
||||
|
||||
s.window[q++]=(byte)lit; m--;
|
||||
|
||||
mode = START;
|
||||
break;
|
||||
case WASH: // o: got eob, possibly more output
|
||||
if (k > 7){ // return unused byte, if any
|
||||
k -= 8;
|
||||
n++;
|
||||
p--; // can always return one
|
||||
}
|
||||
|
||||
s.write=q; r=s.inflate_flush(z,r);
|
||||
q=s.write;m=q<s.read?s.read-q-1:s.end-q;
|
||||
|
||||
if (s.read != s.write){
|
||||
s.bitb=b;s.bitk=k;
|
||||
z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
|
||||
s.write=q;
|
||||
return s.inflate_flush(z,r);
|
||||
}
|
||||
mode = END;
|
||||
goto case END;
|
||||
case END:
|
||||
r = Z_STREAM_END;
|
||||
s.bitb=b;s.bitk=k;
|
||||
z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
|
||||
s.write=q;
|
||||
return s.inflate_flush(z,r);
|
||||
|
||||
case BADCODE: // x: got error
|
||||
|
||||
r = Z_DATA_ERROR;
|
||||
|
||||
s.bitb=b;s.bitk=k;
|
||||
z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
|
||||
s.write=q;
|
||||
return s.inflate_flush(z,r);
|
||||
|
||||
default:
|
||||
r = Z_STREAM_ERROR;
|
||||
|
||||
s.bitb=b;s.bitk=k;
|
||||
z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
|
||||
s.write=q;
|
||||
return s.inflate_flush(z,r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void free(ZStream z){
|
||||
// ZFREE(z, c);
|
||||
}
|
||||
|
||||
// Called with number of bytes left to write in window at least 258
|
||||
// (the maximum string length) and number of input bytes available
|
||||
// at least ten. The ten bytes are six bytes for the longest length/
|
||||
// distance pair plus four bytes for overloading the bit buffer.
|
||||
|
||||
internal int inflate_fast(int bl, int bd,
|
||||
int[] tl, int tl_index,
|
||||
int[] td, int td_index,
|
||||
InfBlocks s, ZStream z){
|
||||
int t; // temporary pointer
|
||||
int[] tp; // temporary pointer
|
||||
int tp_index; // temporary pointer
|
||||
int e; // extra bits or operation
|
||||
int b; // bit buffer
|
||||
int k; // bits in bit buffer
|
||||
int p; // input data pointer
|
||||
int n; // bytes available there
|
||||
int q; // output window write pointer
|
||||
int m; // bytes to end of window or read pointer
|
||||
int ml; // mask for literal/length tree
|
||||
int md; // mask for distance tree
|
||||
int c; // bytes to copy
|
||||
int d; // distance back to copy from
|
||||
int r; // copy source pointer
|
||||
|
||||
int tp_index_t_3; // (tp_index+t)*3
|
||||
|
||||
// load input, output, bit values
|
||||
p=z.next_in_index;n=z.avail_in;b=s.bitb;k=s.bitk;
|
||||
q=s.write;m=q<s.read?s.read-q-1:s.end-q;
|
||||
|
||||
// initialize masks
|
||||
ml = inflate_mask[bl];
|
||||
md = inflate_mask[bd];
|
||||
|
||||
// do until not enough input or output space for fast loop
|
||||
do { // assume called with m >= 258 && n >= 10
|
||||
// get literal/length code
|
||||
while(k<(20)){ // max bits for literal/length code
|
||||
n--;
|
||||
b|=(z.next_in[p++]&0xff)<<k;k+=8;
|
||||
}
|
||||
|
||||
t= b&ml;
|
||||
tp=tl;
|
||||
tp_index=tl_index;
|
||||
tp_index_t_3=(tp_index+t)*3;
|
||||
if ((e = tp[tp_index_t_3]) == 0){
|
||||
b>>=(tp[tp_index_t_3+1]); k-=(tp[tp_index_t_3+1]);
|
||||
|
||||
s.window[q++] = (byte)tp[tp_index_t_3+2];
|
||||
m--;
|
||||
continue;
|
||||
}
|
||||
do {
|
||||
|
||||
b>>=(tp[tp_index_t_3+1]); k-=(tp[tp_index_t_3+1]);
|
||||
|
||||
if((e&16)!=0){
|
||||
e &= 15;
|
||||
c = tp[tp_index_t_3+2] + ((int)b & inflate_mask[e]);
|
||||
|
||||
b>>=e; k-=e;
|
||||
|
||||
// decode distance base of block to copy
|
||||
while(k<(15)){ // max bits for distance code
|
||||
n--;
|
||||
b|=(z.next_in[p++]&0xff)<<k;k+=8;
|
||||
}
|
||||
|
||||
t= b&md;
|
||||
tp=td;
|
||||
tp_index=td_index;
|
||||
tp_index_t_3=(tp_index+t)*3;
|
||||
e = tp[tp_index_t_3];
|
||||
|
||||
do {
|
||||
|
||||
b>>=(tp[tp_index_t_3+1]); k-=(tp[tp_index_t_3+1]);
|
||||
|
||||
if((e&16)!=0){
|
||||
// get extra bits to add to distance base
|
||||
e &= 15;
|
||||
while(k<(e)){ // get extra bits (up to 13)
|
||||
n--;
|
||||
b|=(z.next_in[p++]&0xff)<<k;k+=8;
|
||||
}
|
||||
|
||||
d = tp[tp_index_t_3+2] + (b&inflate_mask[e]);
|
||||
|
||||
b>>=(e); k-=(e);
|
||||
|
||||
// do the copy
|
||||
m -= c;
|
||||
if (q >= d){ // offset before dest
|
||||
// just copy
|
||||
r=q-d;
|
||||
if(q-r>0 && 2>(q-r)){
|
||||
s.window[q++]=s.window[r++]; // minimum count is three,
|
||||
s.window[q++]=s.window[r++]; // so unroll loop a little
|
||||
c-=2;
|
||||
}
|
||||
else{
|
||||
System.Array.Copy(s.window, r, s.window, q, 2);
|
||||
q+=2; r+=2; c-=2;
|
||||
}
|
||||
}
|
||||
else{ // else offset after destination
|
||||
r=q-d;
|
||||
do{
|
||||
r+=s.end; // force pointer in window
|
||||
}while(r<0); // covers invalid distances
|
||||
e=s.end-r;
|
||||
if(c>e){ // if source crosses,
|
||||
c-=e; // wrapped copy
|
||||
if(q-r>0 && e>(q-r)){
|
||||
do{s.window[q++] = s.window[r++];}
|
||||
while(--e!=0);
|
||||
}
|
||||
else{
|
||||
System.Array.Copy(s.window, r, s.window, q, e);
|
||||
q+=e; r+=e; e=0;
|
||||
}
|
||||
r = 0; // copy rest from start of window
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// copy all or what's left
|
||||
if(q-r>0 && c>(q-r)){
|
||||
do{s.window[q++] = s.window[r++];}
|
||||
while(--c!=0);
|
||||
}
|
||||
else{
|
||||
System.Array.Copy(s.window, r, s.window, q, c);
|
||||
q+=c; r+=c; c=0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
else if((e&64)==0){
|
||||
t+=tp[tp_index_t_3+2];
|
||||
t+=(b&inflate_mask[e]);
|
||||
tp_index_t_3=(tp_index+t)*3;
|
||||
e=tp[tp_index_t_3];
|
||||
}
|
||||
else{
|
||||
z.msg = "invalid distance code";
|
||||
|
||||
c=z.avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;
|
||||
|
||||
s.bitb=b;s.bitk=k;
|
||||
z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
|
||||
s.write=q;
|
||||
|
||||
return Z_DATA_ERROR;
|
||||
}
|
||||
}
|
||||
while(true);
|
||||
break;
|
||||
}
|
||||
|
||||
if((e&64)==0){
|
||||
t+=tp[tp_index_t_3+2];
|
||||
t+=(b&inflate_mask[e]);
|
||||
tp_index_t_3=(tp_index+t)*3;
|
||||
if((e=tp[tp_index_t_3])==0){
|
||||
|
||||
b>>=(tp[tp_index_t_3+1]); k-=(tp[tp_index_t_3+1]);
|
||||
|
||||
s.window[q++]=(byte)tp[tp_index_t_3+2];
|
||||
m--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if((e&32)!=0){
|
||||
|
||||
c=z.avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;
|
||||
|
||||
s.bitb=b;s.bitk=k;
|
||||
z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
|
||||
s.write=q;
|
||||
|
||||
return Z_STREAM_END;
|
||||
}
|
||||
else{
|
||||
z.msg="invalid literal/length code";
|
||||
|
||||
c=z.avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;
|
||||
|
||||
s.bitb=b;s.bitk=k;
|
||||
z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
|
||||
s.write=q;
|
||||
|
||||
return Z_DATA_ERROR;
|
||||
}
|
||||
}
|
||||
while(true);
|
||||
}
|
||||
while(m>=258 && n>= 10);
|
||||
|
||||
// not enough input or output--restore pointers and return
|
||||
c=z.avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;
|
||||
|
||||
s.bitb=b;s.bitk=k;
|
||||
z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
|
||||
s.write=q;
|
||||
|
||||
return Z_OK;
|
||||
}
|
||||
}
|
||||
}
|
523
iTechSharp/System/util/zlib/InfTree.cs
Normal file
523
iTechSharp/System/util/zlib/InfTree.cs
Normal file
@ -0,0 +1,523 @@
|
||||
using System;
|
||||
/*
|
||||
* $Id: InfTree.cs,v 1.1 2006/06/16 10:56:20 psoares33 Exp $
|
||||
*
|
||||
Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. The names of the authors may not be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* This program is based on zlib-1.1.3, so all credit should go authors
|
||||
* Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
|
||||
* and contributors of zlib.
|
||||
*/
|
||||
|
||||
namespace System.util.zlib {
|
||||
|
||||
internal sealed class InfTree{
|
||||
|
||||
private const int MANY=1440;
|
||||
|
||||
private const int Z_OK=0;
|
||||
private const int Z_STREAM_END=1;
|
||||
private const int Z_NEED_DICT=2;
|
||||
private const int Z_ERRNO=-1;
|
||||
private const int Z_STREAM_ERROR=-2;
|
||||
private const int Z_DATA_ERROR=-3;
|
||||
private const int Z_MEM_ERROR=-4;
|
||||
private const int Z_BUF_ERROR=-5;
|
||||
private const int Z_VERSION_ERROR=-6;
|
||||
|
||||
private const int fixed_bl = 9;
|
||||
private const int fixed_bd = 5;
|
||||
|
||||
static int[] fixed_tl = {
|
||||
96,7,256, 0,8,80, 0,8,16, 84,8,115,
|
||||
82,7,31, 0,8,112, 0,8,48, 0,9,192,
|
||||
80,7,10, 0,8,96, 0,8,32, 0,9,160,
|
||||
0,8,0, 0,8,128, 0,8,64, 0,9,224,
|
||||
80,7,6, 0,8,88, 0,8,24, 0,9,144,
|
||||
83,7,59, 0,8,120, 0,8,56, 0,9,208,
|
||||
81,7,17, 0,8,104, 0,8,40, 0,9,176,
|
||||
0,8,8, 0,8,136, 0,8,72, 0,9,240,
|
||||
80,7,4, 0,8,84, 0,8,20, 85,8,227,
|
||||
83,7,43, 0,8,116, 0,8,52, 0,9,200,
|
||||
81,7,13, 0,8,100, 0,8,36, 0,9,168,
|
||||
0,8,4, 0,8,132, 0,8,68, 0,9,232,
|
||||
80,7,8, 0,8,92, 0,8,28, 0,9,152,
|
||||
84,7,83, 0,8,124, 0,8,60, 0,9,216,
|
||||
82,7,23, 0,8,108, 0,8,44, 0,9,184,
|
||||
0,8,12, 0,8,140, 0,8,76, 0,9,248,
|
||||
80,7,3, 0,8,82, 0,8,18, 85,8,163,
|
||||
83,7,35, 0,8,114, 0,8,50, 0,9,196,
|
||||
81,7,11, 0,8,98, 0,8,34, 0,9,164,
|
||||
0,8,2, 0,8,130, 0,8,66, 0,9,228,
|
||||
80,7,7, 0,8,90, 0,8,26, 0,9,148,
|
||||
84,7,67, 0,8,122, 0,8,58, 0,9,212,
|
||||
82,7,19, 0,8,106, 0,8,42, 0,9,180,
|
||||
0,8,10, 0,8,138, 0,8,74, 0,9,244,
|
||||
80,7,5, 0,8,86, 0,8,22, 192,8,0,
|
||||
83,7,51, 0,8,118, 0,8,54, 0,9,204,
|
||||
81,7,15, 0,8,102, 0,8,38, 0,9,172,
|
||||
0,8,6, 0,8,134, 0,8,70, 0,9,236,
|
||||
80,7,9, 0,8,94, 0,8,30, 0,9,156,
|
||||
84,7,99, 0,8,126, 0,8,62, 0,9,220,
|
||||
82,7,27, 0,8,110, 0,8,46, 0,9,188,
|
||||
0,8,14, 0,8,142, 0,8,78, 0,9,252,
|
||||
96,7,256, 0,8,81, 0,8,17, 85,8,131,
|
||||
82,7,31, 0,8,113, 0,8,49, 0,9,194,
|
||||
80,7,10, 0,8,97, 0,8,33, 0,9,162,
|
||||
0,8,1, 0,8,129, 0,8,65, 0,9,226,
|
||||
80,7,6, 0,8,89, 0,8,25, 0,9,146,
|
||||
83,7,59, 0,8,121, 0,8,57, 0,9,210,
|
||||
81,7,17, 0,8,105, 0,8,41, 0,9,178,
|
||||
0,8,9, 0,8,137, 0,8,73, 0,9,242,
|
||||
80,7,4, 0,8,85, 0,8,21, 80,8,258,
|
||||
83,7,43, 0,8,117, 0,8,53, 0,9,202,
|
||||
81,7,13, 0,8,101, 0,8,37, 0,9,170,
|
||||
0,8,5, 0,8,133, 0,8,69, 0,9,234,
|
||||
80,7,8, 0,8,93, 0,8,29, 0,9,154,
|
||||
84,7,83, 0,8,125, 0,8,61, 0,9,218,
|
||||
82,7,23, 0,8,109, 0,8,45, 0,9,186,
|
||||
0,8,13, 0,8,141, 0,8,77, 0,9,250,
|
||||
80,7,3, 0,8,83, 0,8,19, 85,8,195,
|
||||
83,7,35, 0,8,115, 0,8,51, 0,9,198,
|
||||
81,7,11, 0,8,99, 0,8,35, 0,9,166,
|
||||
0,8,3, 0,8,131, 0,8,67, 0,9,230,
|
||||
80,7,7, 0,8,91, 0,8,27, 0,9,150,
|
||||
84,7,67, 0,8,123, 0,8,59, 0,9,214,
|
||||
82,7,19, 0,8,107, 0,8,43, 0,9,182,
|
||||
0,8,11, 0,8,139, 0,8,75, 0,9,246,
|
||||
80,7,5, 0,8,87, 0,8,23, 192,8,0,
|
||||
83,7,51, 0,8,119, 0,8,55, 0,9,206,
|
||||
81,7,15, 0,8,103, 0,8,39, 0,9,174,
|
||||
0,8,7, 0,8,135, 0,8,71, 0,9,238,
|
||||
80,7,9, 0,8,95, 0,8,31, 0,9,158,
|
||||
84,7,99, 0,8,127, 0,8,63, 0,9,222,
|
||||
82,7,27, 0,8,111, 0,8,47, 0,9,190,
|
||||
0,8,15, 0,8,143, 0,8,79, 0,9,254,
|
||||
96,7,256, 0,8,80, 0,8,16, 84,8,115,
|
||||
82,7,31, 0,8,112, 0,8,48, 0,9,193,
|
||||
|
||||
80,7,10, 0,8,96, 0,8,32, 0,9,161,
|
||||
0,8,0, 0,8,128, 0,8,64, 0,9,225,
|
||||
80,7,6, 0,8,88, 0,8,24, 0,9,145,
|
||||
83,7,59, 0,8,120, 0,8,56, 0,9,209,
|
||||
81,7,17, 0,8,104, 0,8,40, 0,9,177,
|
||||
0,8,8, 0,8,136, 0,8,72, 0,9,241,
|
||||
80,7,4, 0,8,84, 0,8,20, 85,8,227,
|
||||
83,7,43, 0,8,116, 0,8,52, 0,9,201,
|
||||
81,7,13, 0,8,100, 0,8,36, 0,9,169,
|
||||
0,8,4, 0,8,132, 0,8,68, 0,9,233,
|
||||
80,7,8, 0,8,92, 0,8,28, 0,9,153,
|
||||
84,7,83, 0,8,124, 0,8,60, 0,9,217,
|
||||
82,7,23, 0,8,108, 0,8,44, 0,9,185,
|
||||
0,8,12, 0,8,140, 0,8,76, 0,9,249,
|
||||
80,7,3, 0,8,82, 0,8,18, 85,8,163,
|
||||
83,7,35, 0,8,114, 0,8,50, 0,9,197,
|
||||
81,7,11, 0,8,98, 0,8,34, 0,9,165,
|
||||
0,8,2, 0,8,130, 0,8,66, 0,9,229,
|
||||
80,7,7, 0,8,90, 0,8,26, 0,9,149,
|
||||
84,7,67, 0,8,122, 0,8,58, 0,9,213,
|
||||
82,7,19, 0,8,106, 0,8,42, 0,9,181,
|
||||
0,8,10, 0,8,138, 0,8,74, 0,9,245,
|
||||
80,7,5, 0,8,86, 0,8,22, 192,8,0,
|
||||
83,7,51, 0,8,118, 0,8,54, 0,9,205,
|
||||
81,7,15, 0,8,102, 0,8,38, 0,9,173,
|
||||
0,8,6, 0,8,134, 0,8,70, 0,9,237,
|
||||
80,7,9, 0,8,94, 0,8,30, 0,9,157,
|
||||
84,7,99, 0,8,126, 0,8,62, 0,9,221,
|
||||
82,7,27, 0,8,110, 0,8,46, 0,9,189,
|
||||
0,8,14, 0,8,142, 0,8,78, 0,9,253,
|
||||
96,7,256, 0,8,81, 0,8,17, 85,8,131,
|
||||
82,7,31, 0,8,113, 0,8,49, 0,9,195,
|
||||
80,7,10, 0,8,97, 0,8,33, 0,9,163,
|
||||
0,8,1, 0,8,129, 0,8,65, 0,9,227,
|
||||
80,7,6, 0,8,89, 0,8,25, 0,9,147,
|
||||
83,7,59, 0,8,121, 0,8,57, 0,9,211,
|
||||
81,7,17, 0,8,105, 0,8,41, 0,9,179,
|
||||
0,8,9, 0,8,137, 0,8,73, 0,9,243,
|
||||
80,7,4, 0,8,85, 0,8,21, 80,8,258,
|
||||
83,7,43, 0,8,117, 0,8,53, 0,9,203,
|
||||
81,7,13, 0,8,101, 0,8,37, 0,9,171,
|
||||
0,8,5, 0,8,133, 0,8,69, 0,9,235,
|
||||
80,7,8, 0,8,93, 0,8,29, 0,9,155,
|
||||
84,7,83, 0,8,125, 0,8,61, 0,9,219,
|
||||
82,7,23, 0,8,109, 0,8,45, 0,9,187,
|
||||
0,8,13, 0,8,141, 0,8,77, 0,9,251,
|
||||
80,7,3, 0,8,83, 0,8,19, 85,8,195,
|
||||
83,7,35, 0,8,115, 0,8,51, 0,9,199,
|
||||
81,7,11, 0,8,99, 0,8,35, 0,9,167,
|
||||
0,8,3, 0,8,131, 0,8,67, 0,9,231,
|
||||
80,7,7, 0,8,91, 0,8,27, 0,9,151,
|
||||
84,7,67, 0,8,123, 0,8,59, 0,9,215,
|
||||
82,7,19, 0,8,107, 0,8,43, 0,9,183,
|
||||
0,8,11, 0,8,139, 0,8,75, 0,9,247,
|
||||
80,7,5, 0,8,87, 0,8,23, 192,8,0,
|
||||
83,7,51, 0,8,119, 0,8,55, 0,9,207,
|
||||
81,7,15, 0,8,103, 0,8,39, 0,9,175,
|
||||
0,8,7, 0,8,135, 0,8,71, 0,9,239,
|
||||
80,7,9, 0,8,95, 0,8,31, 0,9,159,
|
||||
84,7,99, 0,8,127, 0,8,63, 0,9,223,
|
||||
82,7,27, 0,8,111, 0,8,47, 0,9,191,
|
||||
0,8,15, 0,8,143, 0,8,79, 0,9,255
|
||||
};
|
||||
static int[] fixed_td = {
|
||||
80,5,1, 87,5,257, 83,5,17, 91,5,4097,
|
||||
81,5,5, 89,5,1025, 85,5,65, 93,5,16385,
|
||||
80,5,3, 88,5,513, 84,5,33, 92,5,8193,
|
||||
82,5,9, 90,5,2049, 86,5,129, 192,5,24577,
|
||||
80,5,2, 87,5,385, 83,5,25, 91,5,6145,
|
||||
81,5,7, 89,5,1537, 85,5,97, 93,5,24577,
|
||||
80,5,4, 88,5,769, 84,5,49, 92,5,12289,
|
||||
82,5,13, 90,5,3073, 86,5,193, 192,5,24577
|
||||
};
|
||||
|
||||
// Tables for deflate from PKZIP's appnote.txt.
|
||||
static int[] cplens = { // Copy lengths for literal codes 257..285
|
||||
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
|
||||
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
|
||||
};
|
||||
|
||||
// see note #13 above about 258
|
||||
static int[] cplext = { // Extra bits for literal codes 257..285
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
|
||||
3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112 // 112==invalid
|
||||
};
|
||||
|
||||
static int[] cpdist = { // Copy offsets for distance codes 0..29
|
||||
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
|
||||
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
|
||||
8193, 12289, 16385, 24577
|
||||
};
|
||||
|
||||
static int[] cpdext = { // Extra bits for distance codes
|
||||
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
|
||||
7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
|
||||
12, 12, 13, 13};
|
||||
|
||||
// If BMAX needs to be larger than 16, then h and x[] should be uLong.
|
||||
const int BMAX=15; // maximum bit length of any code
|
||||
|
||||
int[] hn = null; // hufts used in space
|
||||
int[] v = null; // work area for huft_build
|
||||
int[] c = null; // bit length count table
|
||||
int[] r = null; // table entry for structure assignment
|
||||
int[] u = null; // table stack
|
||||
int[] x = null; // bit offsets, then code stack
|
||||
|
||||
private int huft_build(int[] b, // code lengths in bits (all assumed <= BMAX)
|
||||
int bindex,
|
||||
int n, // number of codes (assumed <= 288)
|
||||
int s, // number of simple-valued codes (0..s-1)
|
||||
int[] d, // list of base values for non-simple codes
|
||||
int[] e, // list of extra bits for non-simple codes
|
||||
int[] t, // result: starting table
|
||||
int[] m, // maximum lookup bits, returns actual
|
||||
int[] hp,// space for trees
|
||||
int[] hn,// hufts used in space
|
||||
int[] v // working area: values in order of bit length
|
||||
){
|
||||
// Given a list of code lengths and a maximum table size, make a set of
|
||||
// tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR
|
||||
// if the given code set is incomplete (the tables are still built in this
|
||||
// case), Z_DATA_ERROR if the input is invalid (an over-subscribed set of
|
||||
// lengths), or Z_MEM_ERROR if not enough memory.
|
||||
|
||||
int a; // counter for codes of length k
|
||||
int f; // i repeats in table every f entries
|
||||
int g; // maximum code length
|
||||
int h; // table level
|
||||
int i; // counter, current code
|
||||
int j; // counter
|
||||
int k; // number of bits in current code
|
||||
int l; // bits per table (returned in m)
|
||||
int mask; // (1 << w) - 1, to avoid cc -O bug on HP
|
||||
int p; // pointer into c[], b[], or v[]
|
||||
int q; // points to current table
|
||||
int w; // bits before this table == (l * h)
|
||||
int xp; // pointer into x
|
||||
int y; // number of dummy codes added
|
||||
int z; // number of entries in current table
|
||||
|
||||
// Generate counts for each bit length
|
||||
|
||||
p = 0; i = n;
|
||||
do {
|
||||
c[b[bindex+p]]++; p++; i--; // assume all entries <= BMAX
|
||||
}while(i!=0);
|
||||
|
||||
if(c[0] == n){ // null input--all zero length codes
|
||||
t[0] = -1;
|
||||
m[0] = 0;
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
// Find minimum and maximum length, bound *m by those
|
||||
l = m[0];
|
||||
for (j = 1; j <= BMAX; j++)
|
||||
if(c[j]!=0) break;
|
||||
k = j; // minimum code length
|
||||
if(l < j){
|
||||
l = j;
|
||||
}
|
||||
for (i = BMAX; i!=0; i--){
|
||||
if(c[i]!=0) break;
|
||||
}
|
||||
g = i; // maximum code length
|
||||
if(l > i){
|
||||
l = i;
|
||||
}
|
||||
m[0] = l;
|
||||
|
||||
// Adjust last length count to fill out codes, if needed
|
||||
for (y = 1 << j; j < i; j++, y <<= 1){
|
||||
if ((y -= c[j]) < 0){
|
||||
return Z_DATA_ERROR;
|
||||
}
|
||||
}
|
||||
if ((y -= c[i]) < 0){
|
||||
return Z_DATA_ERROR;
|
||||
}
|
||||
c[i] += y;
|
||||
|
||||
// Generate starting offsets into the value table for each length
|
||||
x[1] = j = 0;
|
||||
p = 1; xp = 2;
|
||||
while (--i!=0) { // note that i == g from above
|
||||
x[xp] = (j += c[p]);
|
||||
xp++;
|
||||
p++;
|
||||
}
|
||||
|
||||
// Make a table of values in order of bit lengths
|
||||
i = 0; p = 0;
|
||||
do {
|
||||
if ((j = b[bindex+p]) != 0){
|
||||
v[x[j]++] = i;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
while (++i < n);
|
||||
n = x[g]; // set n to length of v
|
||||
|
||||
// Generate the Huffman codes and for each, make the table entries
|
||||
x[0] = i = 0; // first Huffman code is zero
|
||||
p = 0; // grab values in bit order
|
||||
h = -1; // no tables yet--level -1
|
||||
w = -l; // bits decoded == (l * h)
|
||||
u[0] = 0; // just to keep compilers happy
|
||||
q = 0; // ditto
|
||||
z = 0; // ditto
|
||||
|
||||
// go through the bit lengths (k already is bits in shortest code)
|
||||
for (; k <= g; k++){
|
||||
a = c[k];
|
||||
while (a--!=0){
|
||||
// here i is the Huffman code of length k bits for value *p
|
||||
// make tables up to required level
|
||||
while (k > w + l){
|
||||
h++;
|
||||
w += l; // previous table always l bits
|
||||
// compute minimum size table less than or equal to l bits
|
||||
z = g - w;
|
||||
z = (z > l) ? l : z; // table size upper limit
|
||||
if((f=1<<(j=k-w))>a+1){ // try a k-w bit table
|
||||
// too few codes for k-w bit table
|
||||
f -= a + 1; // deduct codes from patterns left
|
||||
xp = k;
|
||||
if(j < z){
|
||||
while (++j < z){ // try smaller tables up to z bits
|
||||
if((f <<= 1) <= c[++xp])
|
||||
break; // enough codes to use up j bits
|
||||
f -= c[xp]; // else deduct codes from patterns
|
||||
}
|
||||
}
|
||||
}
|
||||
z = 1 << j; // table entries for j-bit table
|
||||
|
||||
// allocate new table
|
||||
if (hn[0] + z > MANY){ // (note: doesn't matter for fixed)
|
||||
return Z_DATA_ERROR; // overflow of MANY
|
||||
}
|
||||
u[h] = q = /*hp+*/ hn[0]; // DEBUG
|
||||
hn[0] += z;
|
||||
|
||||
// connect to last table, if there is one
|
||||
if(h!=0){
|
||||
x[h]=i; // save pattern for backing up
|
||||
r[0]=(byte)j; // bits in this table
|
||||
r[1]=(byte)l; // bits to dump before this table
|
||||
j=i>>(w - l);
|
||||
r[2] = (int)(q - u[h-1] - j); // offset to this table
|
||||
System.Array.Copy(r, 0, hp, (u[h-1]+j)*3, 3); // connect to last table
|
||||
}
|
||||
else{
|
||||
t[0] = q; // first table is returned result
|
||||
}
|
||||
}
|
||||
|
||||
// set up table entry in r
|
||||
r[1] = (byte)(k - w);
|
||||
if (p >= n){
|
||||
r[0] = 128 + 64; // out of values--invalid code
|
||||
}
|
||||
else if (v[p] < s){
|
||||
r[0] = (byte)(v[p] < 256 ? 0 : 32 + 64); // 256 is end-of-block
|
||||
r[2] = v[p++]; // simple code is just the value
|
||||
}
|
||||
else{
|
||||
r[0]=(byte)(e[v[p]-s]+16+64); // non-simple--look up in lists
|
||||
r[2]=d[v[p++] - s];
|
||||
}
|
||||
|
||||
// fill code-like entries with r
|
||||
f=1<<(k-w);
|
||||
for (j=i>>w;j<z;j+=f){
|
||||
System.Array.Copy(r, 0, hp, (q+j)*3, 3);
|
||||
}
|
||||
|
||||
// backwards increment the k-bit code i
|
||||
for (j = 1 << (k - 1); (i & j)!=0; j >>= 1){
|
||||
i ^= j;
|
||||
}
|
||||
i ^= j;
|
||||
|
||||
// backup over finished tables
|
||||
mask = (1 << w) - 1; // needed on HP, cc -O bug
|
||||
while ((i & mask) != x[h]){
|
||||
h--; // don't need to update q
|
||||
w -= l;
|
||||
mask = (1 << w) - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Return Z_BUF_ERROR if we were given an incomplete table
|
||||
return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
|
||||
}
|
||||
|
||||
internal int inflate_trees_bits(int[] c, // 19 code lengths
|
||||
int[] bb, // bits tree desired/actual depth
|
||||
int[] tb, // bits tree result
|
||||
int[] hp, // space for trees
|
||||
ZStream z // for messages
|
||||
){
|
||||
int result;
|
||||
initWorkArea(19);
|
||||
hn[0]=0;
|
||||
result = huft_build(c, 0, 19, 19, null, null, tb, bb, hp, hn, v);
|
||||
|
||||
if(result == Z_DATA_ERROR){
|
||||
z.msg = "oversubscribed dynamic bit lengths tree";
|
||||
}
|
||||
else if(result == Z_BUF_ERROR || bb[0] == 0){
|
||||
z.msg = "incomplete dynamic bit lengths tree";
|
||||
result = Z_DATA_ERROR;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
internal int inflate_trees_dynamic(int nl, // number of literal/length codes
|
||||
int nd, // number of distance codes
|
||||
int[] c, // that many (total) code lengths
|
||||
int[] bl, // literal desired/actual bit depth
|
||||
int[] bd, // distance desired/actual bit depth
|
||||
int[] tl, // literal/length tree result
|
||||
int[] td, // distance tree result
|
||||
int[] hp, // space for trees
|
||||
ZStream z // for messages
|
||||
){
|
||||
int result;
|
||||
|
||||
// build literal/length tree
|
||||
initWorkArea(288);
|
||||
hn[0]=0;
|
||||
result = huft_build(c, 0, nl, 257, cplens, cplext, tl, bl, hp, hn, v);
|
||||
if (result != Z_OK || bl[0] == 0){
|
||||
if(result == Z_DATA_ERROR){
|
||||
z.msg = "oversubscribed literal/length tree";
|
||||
}
|
||||
else if (result != Z_MEM_ERROR){
|
||||
z.msg = "incomplete literal/length tree";
|
||||
result = Z_DATA_ERROR;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// build distance tree
|
||||
initWorkArea(288);
|
||||
result = huft_build(c, nl, nd, 0, cpdist, cpdext, td, bd, hp, hn, v);
|
||||
|
||||
if (result != Z_OK || (bd[0] == 0 && nl > 257)){
|
||||
if (result == Z_DATA_ERROR){
|
||||
z.msg = "oversubscribed distance tree";
|
||||
}
|
||||
else if (result == Z_BUF_ERROR) {
|
||||
z.msg = "incomplete distance tree";
|
||||
result = Z_DATA_ERROR;
|
||||
}
|
||||
else if (result != Z_MEM_ERROR){
|
||||
z.msg = "empty distance tree with lengths";
|
||||
result = Z_DATA_ERROR;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
internal static int inflate_trees_fixed(int[] bl, //literal desired/actual bit depth
|
||||
int[] bd, //distance desired/actual bit depth
|
||||
int[][] tl,//literal/length tree result
|
||||
int[][] td,//distance tree result
|
||||
ZStream z //for memory allocation
|
||||
){
|
||||
bl[0]=fixed_bl;
|
||||
bd[0]=fixed_bd;
|
||||
tl[0]=fixed_tl;
|
||||
td[0]=fixed_td;
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
private void initWorkArea(int vsize){
|
||||
if(hn==null){
|
||||
hn=new int[1];
|
||||
v=new int[vsize];
|
||||
c=new int[BMAX+1];
|
||||
r=new int[3];
|
||||
u=new int[BMAX];
|
||||
x=new int[BMAX+1];
|
||||
}
|
||||
if(v.Length<vsize){ v=new int[vsize]; }
|
||||
for(int i=0; i<vsize; i++){v[i]=0;}
|
||||
for(int i=0; i<BMAX+1; i++){c[i]=0;}
|
||||
for(int i=0; i<3; i++){r[i]=0;}
|
||||
// for(int i=0; i<BMAX; i++){u[i]=0;}
|
||||
System.Array.Copy(c, 0, u, 0, BMAX);
|
||||
// for(int i=0; i<BMAX+1; i++){x[i]=0;}
|
||||
System.Array.Copy(c, 0, x, 0, BMAX+1);
|
||||
}
|
||||
}
|
||||
}
|
387
iTechSharp/System/util/zlib/Inflate.cs
Normal file
387
iTechSharp/System/util/zlib/Inflate.cs
Normal file
@ -0,0 +1,387 @@
|
||||
using System;
|
||||
/*
|
||||
* $Id: Inflate.cs,v 1.1 2006/06/16 10:56:20 psoares33 Exp $
|
||||
*
|
||||
Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. The names of the authors may not be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* This program is based on zlib-1.1.3, so all credit should go authors
|
||||
* Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
|
||||
* and contributors of zlib.
|
||||
*/
|
||||
|
||||
namespace System.util.zlib {
|
||||
|
||||
internal sealed class Inflate{
|
||||
|
||||
private const int MAX_WBITS=15; // 32K LZ77 window
|
||||
|
||||
// preset dictionary flag in zlib header
|
||||
private const int PRESET_DICT=0x20;
|
||||
|
||||
internal const int Z_NO_FLUSH=0;
|
||||
internal const int Z_PARTIAL_FLUSH=1;
|
||||
internal const int Z_SYNC_FLUSH=2;
|
||||
internal const int Z_FULL_FLUSH=3;
|
||||
internal const int Z_FINISH=4;
|
||||
|
||||
private const int Z_DEFLATED=8;
|
||||
|
||||
private const int Z_OK=0;
|
||||
private const int Z_STREAM_END=1;
|
||||
private const int Z_NEED_DICT=2;
|
||||
private const int Z_ERRNO=-1;
|
||||
private const int Z_STREAM_ERROR=-2;
|
||||
private const int Z_DATA_ERROR=-3;
|
||||
private const int Z_MEM_ERROR=-4;
|
||||
private const int Z_BUF_ERROR=-5;
|
||||
private const int Z_VERSION_ERROR=-6;
|
||||
|
||||
private const int METHOD=0; // waiting for method byte
|
||||
private const int FLAG=1; // waiting for flag byte
|
||||
private const int DICT4=2; // four dictionary check bytes to go
|
||||
private const int DICT3=3; // three dictionary check bytes to go
|
||||
private const int DICT2=4; // two dictionary check bytes to go
|
||||
private const int DICT1=5; // one dictionary check byte to go
|
||||
private const int DICT0=6; // waiting for inflateSetDictionary
|
||||
private const int BLOCKS=7; // decompressing blocks
|
||||
private const int CHECK4=8; // four check bytes to go
|
||||
private const int CHECK3=9; // three check bytes to go
|
||||
private const int CHECK2=10; // two check bytes to go
|
||||
private const int CHECK1=11; // one check byte to go
|
||||
private const int DONE=12; // finished check, done
|
||||
private const int BAD=13; // got an error--stay here
|
||||
|
||||
internal int mode; // current inflate mode
|
||||
|
||||
// mode dependent information
|
||||
internal int method; // if FLAGS, method byte
|
||||
|
||||
// if CHECK, check values to compare
|
||||
internal long[] was=new long[1] ; // computed check value
|
||||
internal long need; // stream check value
|
||||
|
||||
// if BAD, inflateSync's marker bytes count
|
||||
internal int marker;
|
||||
|
||||
// mode independent information
|
||||
internal int nowrap; // flag for no wrapper
|
||||
internal int wbits; // log2(window size) (8..15, defaults to 15)
|
||||
|
||||
internal InfBlocks blocks; // current inflate_blocks state
|
||||
|
||||
internal int inflateReset(ZStream z){
|
||||
if(z == null || z.istate == null) return Z_STREAM_ERROR;
|
||||
|
||||
z.total_in = z.total_out = 0;
|
||||
z.msg = null;
|
||||
z.istate.mode = z.istate.nowrap!=0 ? BLOCKS : METHOD;
|
||||
z.istate.blocks.reset(z, null);
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
internal int inflateEnd(ZStream z){
|
||||
if(blocks != null)
|
||||
blocks.free(z);
|
||||
blocks=null;
|
||||
// ZFREE(z, z->state);
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
internal int inflateInit(ZStream z, int w){
|
||||
z.msg = null;
|
||||
blocks = null;
|
||||
|
||||
// handle undocumented nowrap option (no zlib header or check)
|
||||
nowrap = 0;
|
||||
if(w < 0){
|
||||
w = - w;
|
||||
nowrap = 1;
|
||||
}
|
||||
|
||||
// set window size
|
||||
if(w<8 ||w>15){
|
||||
inflateEnd(z);
|
||||
return Z_STREAM_ERROR;
|
||||
}
|
||||
wbits=w;
|
||||
|
||||
z.istate.blocks=new InfBlocks(z,
|
||||
z.istate.nowrap!=0 ? null : this,
|
||||
1<<w);
|
||||
|
||||
// reset state
|
||||
inflateReset(z);
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
internal int inflate(ZStream z, int f){
|
||||
int r;
|
||||
int b;
|
||||
|
||||
if(z == null || z.istate == null || z.next_in == null)
|
||||
return Z_STREAM_ERROR;
|
||||
f = f == Z_FINISH ? Z_BUF_ERROR : Z_OK;
|
||||
r = Z_BUF_ERROR;
|
||||
while (true){
|
||||
//System.out.println("mode: "+z.istate.mode);
|
||||
switch (z.istate.mode){
|
||||
case METHOD:
|
||||
|
||||
if(z.avail_in==0)return r;r=f;
|
||||
|
||||
z.avail_in--; z.total_in++;
|
||||
if(((z.istate.method = z.next_in[z.next_in_index++])&0xf)!=Z_DEFLATED){
|
||||
z.istate.mode = BAD;
|
||||
z.msg="unknown compression method";
|
||||
z.istate.marker = 5; // can't try inflateSync
|
||||
break;
|
||||
}
|
||||
if((z.istate.method>>4)+8>z.istate.wbits){
|
||||
z.istate.mode = BAD;
|
||||
z.msg="invalid window size";
|
||||
z.istate.marker = 5; // can't try inflateSync
|
||||
break;
|
||||
}
|
||||
z.istate.mode=FLAG;
|
||||
goto case FLAG;
|
||||
case FLAG:
|
||||
|
||||
if(z.avail_in==0)return r;r=f;
|
||||
|
||||
z.avail_in--; z.total_in++;
|
||||
b = (z.next_in[z.next_in_index++])&0xff;
|
||||
|
||||
if((((z.istate.method << 8)+b) % 31)!=0){
|
||||
z.istate.mode = BAD;
|
||||
z.msg = "incorrect header check";
|
||||
z.istate.marker = 5; // can't try inflateSync
|
||||
break;
|
||||
}
|
||||
|
||||
if((b&PRESET_DICT)==0){
|
||||
z.istate.mode = BLOCKS;
|
||||
break;
|
||||
}
|
||||
z.istate.mode = DICT4;
|
||||
goto case DICT4;
|
||||
case DICT4:
|
||||
|
||||
if(z.avail_in==0)return r;r=f;
|
||||
|
||||
z.avail_in--; z.total_in++;
|
||||
z.istate.need=((z.next_in[z.next_in_index++]&0xff)<<24)&0xff000000L;
|
||||
z.istate.mode=DICT3;
|
||||
goto case DICT3;
|
||||
case DICT3:
|
||||
|
||||
if(z.avail_in==0)return r;r=f;
|
||||
|
||||
z.avail_in--; z.total_in++;
|
||||
z.istate.need+=((z.next_in[z.next_in_index++]&0xff)<<16)&0xff0000L;
|
||||
z.istate.mode=DICT2;
|
||||
goto case DICT2;
|
||||
case DICT2:
|
||||
|
||||
if(z.avail_in==0)return r;r=f;
|
||||
|
||||
z.avail_in--; z.total_in++;
|
||||
z.istate.need+=((z.next_in[z.next_in_index++]&0xff)<<8)&0xff00L;
|
||||
z.istate.mode=DICT1;
|
||||
goto case DICT1;
|
||||
case DICT1:
|
||||
|
||||
if(z.avail_in==0)return r;r=f;
|
||||
|
||||
z.avail_in--; z.total_in++;
|
||||
z.istate.need += (z.next_in[z.next_in_index++]&0xffL);
|
||||
z.adler = z.istate.need;
|
||||
z.istate.mode = DICT0;
|
||||
return Z_NEED_DICT;
|
||||
case DICT0:
|
||||
z.istate.mode = BAD;
|
||||
z.msg = "need dictionary";
|
||||
z.istate.marker = 0; // can try inflateSync
|
||||
return Z_STREAM_ERROR;
|
||||
case BLOCKS:
|
||||
|
||||
r = z.istate.blocks.proc(z, r);
|
||||
if(r == Z_DATA_ERROR){
|
||||
z.istate.mode = BAD;
|
||||
z.istate.marker = 0; // can try inflateSync
|
||||
break;
|
||||
}
|
||||
if(r == Z_OK){
|
||||
r = f;
|
||||
}
|
||||
if(r != Z_STREAM_END){
|
||||
return r;
|
||||
}
|
||||
r = f;
|
||||
z.istate.blocks.reset(z, z.istate.was);
|
||||
if(z.istate.nowrap!=0){
|
||||
z.istate.mode=DONE;
|
||||
break;
|
||||
}
|
||||
z.istate.mode=CHECK4;
|
||||
goto case CHECK4;
|
||||
case CHECK4:
|
||||
|
||||
if(z.avail_in==0)return r;r=f;
|
||||
|
||||
z.avail_in--; z.total_in++;
|
||||
z.istate.need=((z.next_in[z.next_in_index++]&0xff)<<24)&0xff000000L;
|
||||
z.istate.mode=CHECK3;
|
||||
goto case CHECK3;
|
||||
case CHECK3:
|
||||
|
||||
if(z.avail_in==0)return r;r=f;
|
||||
|
||||
z.avail_in--; z.total_in++;
|
||||
z.istate.need+=((z.next_in[z.next_in_index++]&0xff)<<16)&0xff0000L;
|
||||
z.istate.mode = CHECK2;
|
||||
goto case CHECK2;
|
||||
case CHECK2:
|
||||
|
||||
if(z.avail_in==0)return r;r=f;
|
||||
|
||||
z.avail_in--; z.total_in++;
|
||||
z.istate.need+=((z.next_in[z.next_in_index++]&0xff)<<8)&0xff00L;
|
||||
z.istate.mode = CHECK1;
|
||||
goto case CHECK1;
|
||||
case CHECK1:
|
||||
|
||||
if(z.avail_in==0)return r;r=f;
|
||||
|
||||
z.avail_in--; z.total_in++;
|
||||
z.istate.need+=(z.next_in[z.next_in_index++]&0xffL);
|
||||
|
||||
if(((int)(z.istate.was[0])) != ((int)(z.istate.need))){
|
||||
z.istate.mode = BAD;
|
||||
z.msg = "incorrect data check";
|
||||
z.istate.marker = 5; // can't try inflateSync
|
||||
break;
|
||||
}
|
||||
|
||||
z.istate.mode = DONE;
|
||||
goto case DONE;
|
||||
case DONE:
|
||||
return Z_STREAM_END;
|
||||
case BAD:
|
||||
return Z_DATA_ERROR;
|
||||
default:
|
||||
return Z_STREAM_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
internal int inflateSetDictionary(ZStream z, byte[] dictionary, int dictLength){
|
||||
int index=0;
|
||||
int length = dictLength;
|
||||
if(z==null || z.istate == null|| z.istate.mode != DICT0)
|
||||
return Z_STREAM_ERROR;
|
||||
|
||||
if(z._adler.adler32(1L, dictionary, 0, dictLength)!=z.adler){
|
||||
return Z_DATA_ERROR;
|
||||
}
|
||||
|
||||
z.adler = z._adler.adler32(0, null, 0, 0);
|
||||
|
||||
if(length >= (1<<z.istate.wbits)){
|
||||
length = (1<<z.istate.wbits)-1;
|
||||
index=dictLength - length;
|
||||
}
|
||||
z.istate.blocks.set_dictionary(dictionary, index, length);
|
||||
z.istate.mode = BLOCKS;
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
static private byte[] mark = {(byte)0, (byte)0, (byte)0xff, (byte)0xff};
|
||||
|
||||
internal int inflateSync(ZStream z){
|
||||
int n; // number of bytes to look at
|
||||
int p; // pointer to bytes
|
||||
int m; // number of marker bytes found in a row
|
||||
long r, w; // temporaries to save total_in and total_out
|
||||
|
||||
// set up
|
||||
if(z == null || z.istate == null)
|
||||
return Z_STREAM_ERROR;
|
||||
if(z.istate.mode != BAD){
|
||||
z.istate.mode = BAD;
|
||||
z.istate.marker = 0;
|
||||
}
|
||||
if((n=z.avail_in)==0)
|
||||
return Z_BUF_ERROR;
|
||||
p=z.next_in_index;
|
||||
m=z.istate.marker;
|
||||
|
||||
// search
|
||||
while (n!=0 && m < 4){
|
||||
if(z.next_in[p] == mark[m]){
|
||||
m++;
|
||||
}
|
||||
else if(z.next_in[p]!=0){
|
||||
m = 0;
|
||||
}
|
||||
else{
|
||||
m = 4 - m;
|
||||
}
|
||||
p++; n--;
|
||||
}
|
||||
|
||||
// restore
|
||||
z.total_in += p-z.next_in_index;
|
||||
z.next_in_index = p;
|
||||
z.avail_in = n;
|
||||
z.istate.marker = m;
|
||||
|
||||
// return no joy or set up to restart on a new block
|
||||
if(m != 4){
|
||||
return Z_DATA_ERROR;
|
||||
}
|
||||
r=z.total_in; w=z.total_out;
|
||||
inflateReset(z);
|
||||
z.total_in=r; z.total_out = w;
|
||||
z.istate.mode = BLOCKS;
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
// Returns true if inflate is currently at the end of a block generated
|
||||
// by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
|
||||
// implementation to provide an additional safety check. PPP uses Z_SYNC_FLUSH
|
||||
// but removes the length bytes of the resulting empty stored block. When
|
||||
// decompressing, PPP checks that at the end of input packet, inflate is
|
||||
// waiting for these length bytes.
|
||||
internal int inflateSyncPoint(ZStream z){
|
||||
if(z == null || z.istate == null || z.istate.blocks == null)
|
||||
return Z_STREAM_ERROR;
|
||||
return z.istate.blocks.sync_point();
|
||||
}
|
||||
}
|
||||
}
|
70
iTechSharp/System/util/zlib/JZlib.cs
Normal file
70
iTechSharp/System/util/zlib/JZlib.cs
Normal file
@ -0,0 +1,70 @@
|
||||
using System;
|
||||
/*
|
||||
* $Id: JZlib.cs,v 1.1 2006/06/16 10:56:20 psoares33 Exp $
|
||||
*
|
||||
Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. The names of the authors may not be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* This program is based on zlib-1.1.3, so all credit should go authors
|
||||
* Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
|
||||
* and contributors of zlib.
|
||||
*/
|
||||
|
||||
namespace System.util.zlib {
|
||||
|
||||
public sealed class JZlib{
|
||||
private const String version_="1.0.2";
|
||||
public static String version(){return version_;}
|
||||
|
||||
// compression levels
|
||||
public const int Z_NO_COMPRESSION=0;
|
||||
public const int Z_BEST_SPEED=1;
|
||||
public const int Z_BEST_COMPRESSION=9;
|
||||
public const int Z_DEFAULT_COMPRESSION=(-1);
|
||||
|
||||
// compression strategy
|
||||
public const int Z_FILTERED=1;
|
||||
public const int Z_HUFFMAN_ONLY=2;
|
||||
public const int Z_DEFAULT_STRATEGY=0;
|
||||
|
||||
public const int Z_NO_FLUSH=0;
|
||||
public const int Z_PARTIAL_FLUSH=1;
|
||||
public const int Z_SYNC_FLUSH=2;
|
||||
public const int Z_FULL_FLUSH=3;
|
||||
public const int Z_FINISH=4;
|
||||
|
||||
public const int Z_OK=0;
|
||||
public const int Z_STREAM_END=1;
|
||||
public const int Z_NEED_DICT=2;
|
||||
public const int Z_ERRNO=-1;
|
||||
public const int Z_STREAM_ERROR=-2;
|
||||
public const int Z_DATA_ERROR=-3;
|
||||
public const int Z_MEM_ERROR=-4;
|
||||
public const int Z_BUF_ERROR=-5;
|
||||
public const int Z_VERSION_ERROR=-6;
|
||||
}
|
||||
}
|
152
iTechSharp/System/util/zlib/StaticTree.cs
Normal file
152
iTechSharp/System/util/zlib/StaticTree.cs
Normal file
@ -0,0 +1,152 @@
|
||||
using System;
|
||||
/*
|
||||
* $Id: StaticTree.cs,v 1.1 2006/06/16 10:56:20 psoares33 Exp $
|
||||
*
|
||||
Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. The names of the authors may not be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* This program is based on zlib-1.1.3, so all credit should go authors
|
||||
* Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
|
||||
* and contributors of zlib.
|
||||
*/
|
||||
|
||||
namespace System.util.zlib {
|
||||
|
||||
internal sealed class StaticTree{
|
||||
private const int MAX_BITS=15;
|
||||
|
||||
private const int BL_CODES=19;
|
||||
private const int D_CODES=30;
|
||||
private const int LITERALS=256;
|
||||
private const int LENGTH_CODES=29;
|
||||
private const int L_CODES=(LITERALS+1+LENGTH_CODES);
|
||||
|
||||
// Bit length codes must not exceed MAX_BL_BITS bits
|
||||
internal const int MAX_BL_BITS=7;
|
||||
|
||||
internal static short[] static_ltree = {
|
||||
12, 8, 140, 8, 76, 8, 204, 8, 44, 8,
|
||||
172, 8, 108, 8, 236, 8, 28, 8, 156, 8,
|
||||
92, 8, 220, 8, 60, 8, 188, 8, 124, 8,
|
||||
252, 8, 2, 8, 130, 8, 66, 8, 194, 8,
|
||||
34, 8, 162, 8, 98, 8, 226, 8, 18, 8,
|
||||
146, 8, 82, 8, 210, 8, 50, 8, 178, 8,
|
||||
114, 8, 242, 8, 10, 8, 138, 8, 74, 8,
|
||||
202, 8, 42, 8, 170, 8, 106, 8, 234, 8,
|
||||
26, 8, 154, 8, 90, 8, 218, 8, 58, 8,
|
||||
186, 8, 122, 8, 250, 8, 6, 8, 134, 8,
|
||||
70, 8, 198, 8, 38, 8, 166, 8, 102, 8,
|
||||
230, 8, 22, 8, 150, 8, 86, 8, 214, 8,
|
||||
54, 8, 182, 8, 118, 8, 246, 8, 14, 8,
|
||||
142, 8, 78, 8, 206, 8, 46, 8, 174, 8,
|
||||
110, 8, 238, 8, 30, 8, 158, 8, 94, 8,
|
||||
222, 8, 62, 8, 190, 8, 126, 8, 254, 8,
|
||||
1, 8, 129, 8, 65, 8, 193, 8, 33, 8,
|
||||
161, 8, 97, 8, 225, 8, 17, 8, 145, 8,
|
||||
81, 8, 209, 8, 49, 8, 177, 8, 113, 8,
|
||||
241, 8, 9, 8, 137, 8, 73, 8, 201, 8,
|
||||
41, 8, 169, 8, 105, 8, 233, 8, 25, 8,
|
||||
153, 8, 89, 8, 217, 8, 57, 8, 185, 8,
|
||||
121, 8, 249, 8, 5, 8, 133, 8, 69, 8,
|
||||
197, 8, 37, 8, 165, 8, 101, 8, 229, 8,
|
||||
21, 8, 149, 8, 85, 8, 213, 8, 53, 8,
|
||||
181, 8, 117, 8, 245, 8, 13, 8, 141, 8,
|
||||
77, 8, 205, 8, 45, 8, 173, 8, 109, 8,
|
||||
237, 8, 29, 8, 157, 8, 93, 8, 221, 8,
|
||||
61, 8, 189, 8, 125, 8, 253, 8, 19, 9,
|
||||
275, 9, 147, 9, 403, 9, 83, 9, 339, 9,
|
||||
211, 9, 467, 9, 51, 9, 307, 9, 179, 9,
|
||||
435, 9, 115, 9, 371, 9, 243, 9, 499, 9,
|
||||
11, 9, 267, 9, 139, 9, 395, 9, 75, 9,
|
||||
331, 9, 203, 9, 459, 9, 43, 9, 299, 9,
|
||||
171, 9, 427, 9, 107, 9, 363, 9, 235, 9,
|
||||
491, 9, 27, 9, 283, 9, 155, 9, 411, 9,
|
||||
91, 9, 347, 9, 219, 9, 475, 9, 59, 9,
|
||||
315, 9, 187, 9, 443, 9, 123, 9, 379, 9,
|
||||
251, 9, 507, 9, 7, 9, 263, 9, 135, 9,
|
||||
391, 9, 71, 9, 327, 9, 199, 9, 455, 9,
|
||||
39, 9, 295, 9, 167, 9, 423, 9, 103, 9,
|
||||
359, 9, 231, 9, 487, 9, 23, 9, 279, 9,
|
||||
151, 9, 407, 9, 87, 9, 343, 9, 215, 9,
|
||||
471, 9, 55, 9, 311, 9, 183, 9, 439, 9,
|
||||
119, 9, 375, 9, 247, 9, 503, 9, 15, 9,
|
||||
271, 9, 143, 9, 399, 9, 79, 9, 335, 9,
|
||||
207, 9, 463, 9, 47, 9, 303, 9, 175, 9,
|
||||
431, 9, 111, 9, 367, 9, 239, 9, 495, 9,
|
||||
31, 9, 287, 9, 159, 9, 415, 9, 95, 9,
|
||||
351, 9, 223, 9, 479, 9, 63, 9, 319, 9,
|
||||
191, 9, 447, 9, 127, 9, 383, 9, 255, 9,
|
||||
511, 9, 0, 7, 64, 7, 32, 7, 96, 7,
|
||||
16, 7, 80, 7, 48, 7, 112, 7, 8, 7,
|
||||
72, 7, 40, 7, 104, 7, 24, 7, 88, 7,
|
||||
56, 7, 120, 7, 4, 7, 68, 7, 36, 7,
|
||||
100, 7, 20, 7, 84, 7, 52, 7, 116, 7,
|
||||
3, 8, 131, 8, 67, 8, 195, 8, 35, 8,
|
||||
163, 8, 99, 8, 227, 8
|
||||
};
|
||||
|
||||
internal static short[] static_dtree = {
|
||||
0, 5, 16, 5, 8, 5, 24, 5, 4, 5,
|
||||
20, 5, 12, 5, 28, 5, 2, 5, 18, 5,
|
||||
10, 5, 26, 5, 6, 5, 22, 5, 14, 5,
|
||||
30, 5, 1, 5, 17, 5, 9, 5, 25, 5,
|
||||
5, 5, 21, 5, 13, 5, 29, 5, 3, 5,
|
||||
19, 5, 11, 5, 27, 5, 7, 5, 23, 5
|
||||
};
|
||||
|
||||
internal static StaticTree static_l_desc =
|
||||
new StaticTree(static_ltree, Tree.extra_lbits,
|
||||
LITERALS+1, L_CODES, MAX_BITS);
|
||||
|
||||
internal static StaticTree static_d_desc =
|
||||
new StaticTree(static_dtree, Tree.extra_dbits,
|
||||
0, D_CODES, MAX_BITS);
|
||||
|
||||
internal static StaticTree static_bl_desc =
|
||||
new StaticTree(null, Tree.extra_blbits,
|
||||
0, BL_CODES, MAX_BL_BITS);
|
||||
|
||||
internal short[] static_tree; // static tree or null
|
||||
internal int[] extra_bits; // extra bits for each code or null
|
||||
internal int extra_base; // base index for extra_bits
|
||||
internal int elems; // max number of elements in the tree
|
||||
internal int max_length; // max bit length for the codes
|
||||
|
||||
internal StaticTree(short[] static_tree,
|
||||
int[] extra_bits,
|
||||
int extra_base,
|
||||
int elems,
|
||||
int max_length
|
||||
){
|
||||
this.static_tree=static_tree;
|
||||
this.extra_bits=extra_bits;
|
||||
this.extra_base=extra_base;
|
||||
this.elems=elems;
|
||||
this.max_length=max_length;
|
||||
}
|
||||
}
|
||||
}
|
367
iTechSharp/System/util/zlib/Tree.cs
Normal file
367
iTechSharp/System/util/zlib/Tree.cs
Normal file
@ -0,0 +1,367 @@
|
||||
using System;
|
||||
/*
|
||||
* $Id: Tree.cs,v 1.2 2006/07/31 14:30:59 psoares33 Exp $
|
||||
*
|
||||
Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. The names of the authors may not be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* This program is based on zlib-1.1.3, so all credit should go authors
|
||||
* Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
|
||||
* and contributors of zlib.
|
||||
*/
|
||||
|
||||
namespace System.util.zlib {
|
||||
|
||||
internal sealed class Tree{
|
||||
private const int MAX_BITS=15;
|
||||
private const int BL_CODES=19;
|
||||
private const int D_CODES=30;
|
||||
private const int LITERALS=256;
|
||||
private const int LENGTH_CODES=29;
|
||||
private const int L_CODES=(LITERALS+1+LENGTH_CODES);
|
||||
private const int HEAP_SIZE=(2*L_CODES+1);
|
||||
|
||||
// Bit length codes must not exceed MAX_BL_BITS bits
|
||||
internal const int MAX_BL_BITS=7;
|
||||
|
||||
// end of block literal code
|
||||
internal const int END_BLOCK=256;
|
||||
|
||||
// repeat previous bit length 3-6 times (2 bits of repeat count)
|
||||
internal const int REP_3_6=16;
|
||||
|
||||
// repeat a zero length 3-10 times (3 bits of repeat count)
|
||||
internal const int REPZ_3_10=17;
|
||||
|
||||
// repeat a zero length 11-138 times (7 bits of repeat count)
|
||||
internal const int REPZ_11_138=18;
|
||||
|
||||
// extra bits for each length code
|
||||
internal static int[] extra_lbits={
|
||||
0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0
|
||||
};
|
||||
|
||||
// extra bits for each distance code
|
||||
internal static int[] extra_dbits={
|
||||
0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13
|
||||
};
|
||||
|
||||
// extra bits for each bit length code
|
||||
internal static int[] extra_blbits={
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7
|
||||
};
|
||||
|
||||
internal static byte[] bl_order={
|
||||
16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
|
||||
|
||||
|
||||
// The lengths of the bit length codes are sent in order of decreasing
|
||||
// probability, to avoid transmitting the lengths for unused bit
|
||||
// length codes.
|
||||
|
||||
internal const int Buf_size=8*2;
|
||||
|
||||
// see definition of array dist_code below
|
||||
internal const int DIST_CODE_LEN=512;
|
||||
|
||||
internal static byte[] _dist_code = {
|
||||
0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
|
||||
8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
|
||||
10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
|
||||
11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
|
||||
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
|
||||
13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
|
||||
13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17,
|
||||
18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
|
||||
23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
|
||||
24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
|
||||
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
|
||||
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
|
||||
27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
|
||||
27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
|
||||
28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
|
||||
28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
|
||||
28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
|
||||
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
|
||||
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
|
||||
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
|
||||
};
|
||||
|
||||
internal static byte[] _length_code={
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
|
||||
13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
|
||||
17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
|
||||
21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
|
||||
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
|
||||
23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
|
||||
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
|
||||
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
|
||||
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
|
||||
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
|
||||
26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
|
||||
27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
|
||||
};
|
||||
|
||||
internal static int[] base_length = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
|
||||
64, 80, 96, 112, 128, 160, 192, 224, 0
|
||||
};
|
||||
|
||||
internal static int[] base_dist = {
|
||||
0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
|
||||
32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
|
||||
1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
|
||||
};
|
||||
|
||||
// Mapping from a distance to a distance code. dist is the distance - 1 and
|
||||
// must not have side effects. _dist_code[256] and _dist_code[257] are never
|
||||
// used.
|
||||
internal static int d_code(int dist){
|
||||
return ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]);
|
||||
}
|
||||
|
||||
internal short[] dyn_tree; // the dynamic tree
|
||||
internal int max_code; // largest code with non zero frequency
|
||||
internal StaticTree stat_desc; // the corresponding static tree
|
||||
|
||||
// Compute the optimal bit lengths for a tree and update the total bit length
|
||||
// for the current block.
|
||||
// IN assertion: the fields freq and dad are set, heap[heap_max] and
|
||||
// above are the tree nodes sorted by increasing frequency.
|
||||
// OUT assertions: the field len is set to the optimal bit length, the
|
||||
// array bl_count contains the frequencies for each bit length.
|
||||
// The length opt_len is updated; static_len is also updated if stree is
|
||||
// not null.
|
||||
internal void gen_bitlen(Deflate s){
|
||||
short[] tree = dyn_tree;
|
||||
short[] stree = stat_desc.static_tree;
|
||||
int[] extra = stat_desc.extra_bits;
|
||||
int based = stat_desc.extra_base;
|
||||
int max_length = stat_desc.max_length;
|
||||
int h; // heap index
|
||||
int n, m; // iterate over the tree elements
|
||||
int bits; // bit length
|
||||
int xbits; // extra bits
|
||||
short f; // frequency
|
||||
int overflow = 0; // number of elements with bit length too large
|
||||
|
||||
for (bits = 0; bits <= MAX_BITS; bits++) s.bl_count[bits] = 0;
|
||||
|
||||
// In a first pass, compute the optimal bit lengths (which may
|
||||
// overflow in the case of the bit length tree).
|
||||
tree[s.heap[s.heap_max]*2+1] = 0; // root of the heap
|
||||
|
||||
for(h=s.heap_max+1; h<HEAP_SIZE; h++){
|
||||
n = s.heap[h];
|
||||
bits = tree[tree[n*2+1]*2+1] + 1;
|
||||
if (bits > max_length){ bits = max_length; overflow++; }
|
||||
tree[n*2+1] = (short)bits;
|
||||
// We overwrite tree[n*2+1] which is no longer needed
|
||||
|
||||
if (n > max_code) continue; // not a leaf node
|
||||
|
||||
s.bl_count[bits]++;
|
||||
xbits = 0;
|
||||
if (n >= based) xbits = extra[n-based];
|
||||
f = tree[n*2];
|
||||
s.opt_len += f * (bits + xbits);
|
||||
if (stree!=null) s.static_len += f * (stree[n*2+1] + xbits);
|
||||
}
|
||||
if (overflow == 0) return;
|
||||
|
||||
// This happens for example on obj2 and pic of the Calgary corpus
|
||||
// Find the first bit length which could increase:
|
||||
do {
|
||||
bits = max_length-1;
|
||||
while(s.bl_count[bits]==0) bits--;
|
||||
s.bl_count[bits]--; // move one leaf down the tree
|
||||
s.bl_count[bits+1]+=2; // move one overflow item as its brother
|
||||
s.bl_count[max_length]--;
|
||||
// The brother of the overflow item also moves one step up,
|
||||
// but this does not affect bl_count[max_length]
|
||||
overflow -= 2;
|
||||
}
|
||||
while (overflow > 0);
|
||||
|
||||
for (bits = max_length; bits != 0; bits--) {
|
||||
n = s.bl_count[bits];
|
||||
while (n != 0) {
|
||||
m = s.heap[--h];
|
||||
if (m > max_code) continue;
|
||||
if (tree[m*2+1] != bits) {
|
||||
s.opt_len += (int)(((long)bits - (long)tree[m*2+1])*(long)tree[m*2]);
|
||||
tree[m*2+1] = (short)bits;
|
||||
}
|
||||
n--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Construct one Huffman tree and assigns the code bit strings and lengths.
|
||||
// Update the total bit length for the current block.
|
||||
// IN assertion: the field freq is set for all tree elements.
|
||||
// OUT assertions: the fields len and code are set to the optimal bit length
|
||||
// and corresponding code. The length opt_len is updated; static_len is
|
||||
// also updated if stree is not null. The field max_code is set.
|
||||
internal void build_tree(Deflate s){
|
||||
short[] tree=dyn_tree;
|
||||
short[] stree=stat_desc.static_tree;
|
||||
int elems=stat_desc.elems;
|
||||
int n, m; // iterate over heap elements
|
||||
int max_code=-1; // largest code with non zero frequency
|
||||
int node; // new node being created
|
||||
|
||||
// Construct the initial heap, with least frequent element in
|
||||
// heap[1]. The sons of heap[n] are heap[2*n] and heap[2*n+1].
|
||||
// heap[0] is not used.
|
||||
s.heap_len = 0;
|
||||
s.heap_max = HEAP_SIZE;
|
||||
|
||||
for(n=0; n<elems; n++) {
|
||||
if(tree[n*2] != 0) {
|
||||
s.heap[++s.heap_len] = max_code = n;
|
||||
s.depth[n] = 0;
|
||||
}
|
||||
else{
|
||||
tree[n*2+1] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// The pkzip format requires that at least one distance code exists,
|
||||
// and that at least one bit should be sent even if there is only one
|
||||
// possible code. So to avoid special checks later on we force at least
|
||||
// two codes of non zero frequency.
|
||||
while (s.heap_len < 2) {
|
||||
node = s.heap[++s.heap_len] = (max_code < 2 ? ++max_code : 0);
|
||||
tree[node*2] = 1;
|
||||
s.depth[node] = 0;
|
||||
s.opt_len--; if (stree!=null) s.static_len -= stree[node*2+1];
|
||||
// node is 0 or 1 so it does not have extra bits
|
||||
}
|
||||
this.max_code = max_code;
|
||||
|
||||
// The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
|
||||
// establish sub-heaps of increasing lengths:
|
||||
|
||||
for(n=s.heap_len/2;n>=1; n--)
|
||||
s.pqdownheap(tree, n);
|
||||
|
||||
// Construct the Huffman tree by repeatedly combining the least two
|
||||
// frequent nodes.
|
||||
|
||||
node=elems; // next internal node of the tree
|
||||
do{
|
||||
// n = node of least frequency
|
||||
n=s.heap[1];
|
||||
s.heap[1]=s.heap[s.heap_len--];
|
||||
s.pqdownheap(tree, 1);
|
||||
m=s.heap[1]; // m = node of next least frequency
|
||||
|
||||
s.heap[--s.heap_max] = n; // keep the nodes sorted by frequency
|
||||
s.heap[--s.heap_max] = m;
|
||||
|
||||
// Create a new node father of n and m
|
||||
tree[node*2] = (short)(tree[n*2] + tree[m*2]);
|
||||
s.depth[node] = (byte)(System.Math.Max(s.depth[n],s.depth[m])+1);
|
||||
tree[n*2+1] = tree[m*2+1] = (short)node;
|
||||
|
||||
// and insert the new node in the heap
|
||||
s.heap[1] = node++;
|
||||
s.pqdownheap(tree, 1);
|
||||
}
|
||||
while(s.heap_len>=2);
|
||||
|
||||
s.heap[--s.heap_max] = s.heap[1];
|
||||
|
||||
// At this point, the fields freq and dad are set. We can now
|
||||
// generate the bit lengths.
|
||||
|
||||
gen_bitlen(s);
|
||||
|
||||
// The field len is now set, we can generate the bit codes
|
||||
gen_codes(tree, max_code, s.bl_count);
|
||||
}
|
||||
|
||||
// Generate the codes for a given tree and bit counts (which need not be
|
||||
// optimal).
|
||||
// IN assertion: the array bl_count contains the bit length statistics for
|
||||
// the given tree and the field len is set for all tree elements.
|
||||
// OUT assertion: the field code is set for all tree elements of non
|
||||
// zero code length.
|
||||
internal static void gen_codes(short[] tree, // the tree to decorate
|
||||
int max_code, // largest code with non zero frequency
|
||||
short[] bl_count // number of codes at each bit length
|
||||
){
|
||||
short[] next_code=new short[MAX_BITS+1]; // next code value for each bit length
|
||||
short code = 0; // running code value
|
||||
int bits; // bit index
|
||||
int n; // code index
|
||||
|
||||
// The distribution counts are first used to generate the code values
|
||||
// without bit reversal.
|
||||
for (bits = 1; bits <= MAX_BITS; bits++) {
|
||||
next_code[bits] = code = (short)((code + bl_count[bits-1]) << 1);
|
||||
}
|
||||
|
||||
// Check that the bit counts in bl_count are consistent. The last code
|
||||
// must be all ones.
|
||||
//Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
|
||||
// "inconsistent bit counts");
|
||||
//Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
|
||||
|
||||
for (n = 0; n <= max_code; n++) {
|
||||
int len = tree[n*2+1];
|
||||
if (len == 0) continue;
|
||||
// Now reverse the bits
|
||||
tree[n*2] = (short)(bi_reverse(next_code[len]++, len));
|
||||
}
|
||||
}
|
||||
|
||||
// Reverse the first len bits of a code, using straightforward code (a faster
|
||||
// method would use a table)
|
||||
// IN assertion: 1 <= len <= 15
|
||||
internal static int bi_reverse(int code, // the value to invert
|
||||
int len // its bit length
|
||||
){
|
||||
int res = 0;
|
||||
do{
|
||||
res|=code&1;
|
||||
code>>=1;
|
||||
res<<=1;
|
||||
}
|
||||
while(--len>0);
|
||||
return res>>1;
|
||||
}
|
||||
}
|
||||
}
|
196
iTechSharp/System/util/zlib/ZDeflaterOutputStream.cs
Normal file
196
iTechSharp/System/util/zlib/ZDeflaterOutputStream.cs
Normal file
@ -0,0 +1,196 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
/*
|
||||
* $Id: ZDeflaterOutputStream.cs,v 1.3 2007/06/22 14:14:13 psoares33 Exp $
|
||||
*
|
||||
* Copyright 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 isp 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 isp 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code isp 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 isp 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 isp 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 isp 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 System.util.zlib {
|
||||
/// <summary>
|
||||
/// Summary description for DeflaterOutputStream.
|
||||
/// </summary>
|
||||
public class ZDeflaterOutputStream : Stream {
|
||||
protected ZStream z=new ZStream();
|
||||
protected int flushLevel=JZlib.Z_NO_FLUSH;
|
||||
private const int BUFSIZE = 4192;
|
||||
protected byte[] buf=new byte[BUFSIZE];
|
||||
private byte[] buf1=new byte[1];
|
||||
|
||||
protected Stream outp;
|
||||
|
||||
public ZDeflaterOutputStream(Stream outp) : this(outp, 6, false) {
|
||||
}
|
||||
|
||||
public ZDeflaterOutputStream(Stream outp, int level) : this(outp, level, false) {
|
||||
}
|
||||
|
||||
public ZDeflaterOutputStream(Stream outp, int level, bool nowrap) {
|
||||
this.outp=outp;
|
||||
z.deflateInit(level, nowrap);
|
||||
}
|
||||
|
||||
|
||||
public override bool CanRead {
|
||||
get {
|
||||
// TODO: Add DeflaterOutputStream.CanRead getter implementation
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanSeek {
|
||||
get {
|
||||
// TODO: Add DeflaterOutputStream.CanSeek getter implementation
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanWrite {
|
||||
get {
|
||||
// TODO: Add DeflaterOutputStream.CanWrite getter implementation
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public override long Length {
|
||||
get {
|
||||
// TODO: Add DeflaterOutputStream.Length getter implementation
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public override long Position {
|
||||
get {
|
||||
// TODO: Add DeflaterOutputStream.Position getter implementation
|
||||
return 0;
|
||||
}
|
||||
set {
|
||||
// TODO: Add DeflaterOutputStream.Position setter implementation
|
||||
}
|
||||
}
|
||||
|
||||
public override void Write(byte[] b, int off, int len) {
|
||||
if(len==0)
|
||||
return;
|
||||
int err;
|
||||
z.next_in=b;
|
||||
z.next_in_index=off;
|
||||
z.avail_in=len;
|
||||
do{
|
||||
z.next_out=buf;
|
||||
z.next_out_index=0;
|
||||
z.avail_out=BUFSIZE;
|
||||
err=z.deflate(flushLevel);
|
||||
if(err!=JZlib.Z_OK)
|
||||
throw new IOException("deflating: "+z.msg);
|
||||
if (z.avail_out < BUFSIZE)
|
||||
outp.Write(buf, 0, BUFSIZE-z.avail_out);
|
||||
}
|
||||
while(z.avail_in>0 || z.avail_out==0);
|
||||
}
|
||||
|
||||
public override long Seek(long offset, SeekOrigin origin) {
|
||||
// TODO: Add DeflaterOutputStream.Seek implementation
|
||||
return 0;
|
||||
}
|
||||
|
||||
public override void SetLength(long value) {
|
||||
// TODO: Add DeflaterOutputStream.SetLength implementation
|
||||
|
||||
}
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count) {
|
||||
// TODO: Add DeflaterOutputStream.Read implementation
|
||||
return 0;
|
||||
}
|
||||
|
||||
public override void Flush() {
|
||||
outp.Flush();
|
||||
}
|
||||
|
||||
public override void WriteByte(byte b) {
|
||||
buf1[0]=(byte)b;
|
||||
Write(buf1, 0, 1);
|
||||
}
|
||||
|
||||
public void Finish() {
|
||||
int err;
|
||||
do{
|
||||
z.next_out=buf;
|
||||
z.next_out_index=0;
|
||||
z.avail_out=BUFSIZE;
|
||||
err=z.deflate(JZlib.Z_FINISH);
|
||||
if(err!=JZlib.Z_STREAM_END && err != JZlib.Z_OK)
|
||||
throw new IOException("deflating: "+z.msg);
|
||||
if(BUFSIZE-z.avail_out>0){
|
||||
outp.Write(buf, 0, BUFSIZE-z.avail_out);
|
||||
}
|
||||
}
|
||||
while(z.avail_in>0 || z.avail_out==0);
|
||||
Flush();
|
||||
}
|
||||
|
||||
public void End() {
|
||||
if(z==null)
|
||||
return;
|
||||
z.deflateEnd();
|
||||
z.free();
|
||||
z=null;
|
||||
}
|
||||
|
||||
public override void Close() {
|
||||
try{
|
||||
try{Finish();}
|
||||
catch (IOException) {}
|
||||
}
|
||||
finally{
|
||||
End();
|
||||
outp.Close();
|
||||
outp=null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
174
iTechSharp/System/util/zlib/ZInflaterInputStream.cs
Normal file
174
iTechSharp/System/util/zlib/ZInflaterInputStream.cs
Normal file
@ -0,0 +1,174 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
/*
|
||||
* $Id: ZInflaterInputStream.cs,v 1.4 2007/06/22 14:14:16 psoares33 Exp $
|
||||
*
|
||||
* Copyright 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 isp 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 isp 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code isp 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 isp 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 isp 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 isp 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 System.util.zlib {
|
||||
/// <summary>
|
||||
/// Summary description for DeflaterOutputStream.
|
||||
/// </summary>
|
||||
public class ZInflaterInputStream : Stream {
|
||||
protected ZStream z=new ZStream();
|
||||
protected int flushLevel=JZlib.Z_NO_FLUSH;
|
||||
private const int BUFSIZE = 4192;
|
||||
protected byte[] buf=new byte[BUFSIZE];
|
||||
private byte[] buf1=new byte[1];
|
||||
|
||||
protected Stream inp=null;
|
||||
private bool nomoreinput=false;
|
||||
|
||||
public ZInflaterInputStream(Stream inp) : this(inp, false) {
|
||||
}
|
||||
|
||||
public ZInflaterInputStream(Stream inp, bool nowrap) {
|
||||
this.inp=inp;
|
||||
z.inflateInit(nowrap);
|
||||
z.next_in=buf;
|
||||
z.next_in_index=0;
|
||||
z.avail_in=0;
|
||||
}
|
||||
|
||||
public override bool CanRead {
|
||||
get {
|
||||
// TODO: Add DeflaterOutputStream.CanRead getter implementation
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanSeek {
|
||||
get {
|
||||
// TODO: Add DeflaterOutputStream.CanSeek getter implementation
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanWrite {
|
||||
get {
|
||||
// TODO: Add DeflaterOutputStream.CanWrite getter implementation
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override long Length {
|
||||
get {
|
||||
// TODO: Add DeflaterOutputStream.Length getter implementation
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public override long Position {
|
||||
get {
|
||||
// TODO: Add DeflaterOutputStream.Position getter implementation
|
||||
return 0;
|
||||
}
|
||||
set {
|
||||
// TODO: Add DeflaterOutputStream.Position setter implementation
|
||||
}
|
||||
}
|
||||
|
||||
public override void Write(byte[] b, int off, int len) {
|
||||
}
|
||||
|
||||
public override long Seek(long offset, SeekOrigin origin) {
|
||||
// TODO: Add DeflaterOutputStream.Seek implementation
|
||||
return 0;
|
||||
}
|
||||
|
||||
public override void SetLength(long value) {
|
||||
// TODO: Add DeflaterOutputStream.SetLength implementation
|
||||
|
||||
}
|
||||
|
||||
public override int Read(byte[] b, int off, int len) {
|
||||
if(len==0)
|
||||
return(0);
|
||||
int err;
|
||||
z.next_out=b;
|
||||
z.next_out_index=off;
|
||||
z.avail_out=len;
|
||||
do {
|
||||
if((z.avail_in==0)&&(!nomoreinput)) { // if buffer is empty and more input is avaiable, refill it
|
||||
z.next_in_index=0;
|
||||
z.avail_in=inp.Read(buf, 0, BUFSIZE);//(BUFSIZE<z.avail_out ? BUFSIZE : z.avail_out));
|
||||
if(z.avail_in==0) {
|
||||
z.avail_in=0;
|
||||
nomoreinput=true;
|
||||
}
|
||||
}
|
||||
err=z.inflate(flushLevel);
|
||||
if(nomoreinput&&(err==JZlib.Z_BUF_ERROR))
|
||||
return(-1);
|
||||
if(err!=JZlib.Z_OK && err!=JZlib.Z_STREAM_END)
|
||||
throw new IOException("inflating: "+z.msg);
|
||||
if((nomoreinput||err==JZlib.Z_STREAM_END)&&(z.avail_out==len))
|
||||
return(0);
|
||||
}
|
||||
while(z.avail_out==len&&err==JZlib.Z_OK);
|
||||
//System.err.print("("+(len-z.avail_out)+")");
|
||||
return(len-z.avail_out);
|
||||
}
|
||||
|
||||
public override void Flush() {
|
||||
inp.Flush();
|
||||
}
|
||||
|
||||
public override void WriteByte(byte b) {
|
||||
}
|
||||
|
||||
public override void Close() {
|
||||
inp.Close();
|
||||
}
|
||||
|
||||
public override int ReadByte() {
|
||||
if(Read(buf1, 0, 1)<=0)
|
||||
return -1;
|
||||
return(buf1[0]&0xFF);
|
||||
}
|
||||
}
|
||||
}
|
214
iTechSharp/System/util/zlib/ZStream.cs
Normal file
214
iTechSharp/System/util/zlib/ZStream.cs
Normal file
@ -0,0 +1,214 @@
|
||||
using System;
|
||||
/*
|
||||
* $Id: ZStream.cs,v 1.1 2006/06/16 10:56:20 psoares33 Exp $
|
||||
*
|
||||
Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. The names of the authors may not be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* This program is based on zlib-1.1.3, so all credit should go authors
|
||||
* Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
|
||||
* and contributors of zlib.
|
||||
*/
|
||||
|
||||
namespace System.util.zlib {
|
||||
|
||||
public sealed class ZStream{
|
||||
|
||||
private const int MAX_WBITS=15; // 32K LZ77 window
|
||||
private const int DEF_WBITS=MAX_WBITS;
|
||||
|
||||
private const int Z_NO_FLUSH=0;
|
||||
private const int Z_PARTIAL_FLUSH=1;
|
||||
private const int Z_SYNC_FLUSH=2;
|
||||
private const int Z_FULL_FLUSH=3;
|
||||
private const int Z_FINISH=4;
|
||||
|
||||
private const int MAX_MEM_LEVEL=9;
|
||||
|
||||
private const int Z_OK=0;
|
||||
private const int Z_STREAM_END=1;
|
||||
private const int Z_NEED_DICT=2;
|
||||
private const int Z_ERRNO=-1;
|
||||
private const int Z_STREAM_ERROR=-2;
|
||||
private const int Z_DATA_ERROR=-3;
|
||||
private const int Z_MEM_ERROR=-4;
|
||||
private const int Z_BUF_ERROR=-5;
|
||||
private const int Z_VERSION_ERROR=-6;
|
||||
|
||||
public byte[] next_in; // next input byte
|
||||
public int next_in_index;
|
||||
public int avail_in; // number of bytes available at next_in
|
||||
public long total_in; // total nb of input bytes read so far
|
||||
|
||||
public byte[] next_out; // next output byte should be put there
|
||||
public int next_out_index;
|
||||
public int avail_out; // remaining free space at next_out
|
||||
public long total_out; // total nb of bytes output so far
|
||||
|
||||
public String msg;
|
||||
|
||||
internal Deflate dstate;
|
||||
internal Inflate istate;
|
||||
|
||||
internal int data_type; // best guess about the data type: ascii or binary
|
||||
|
||||
public long adler;
|
||||
internal Adler32 _adler=new Adler32();
|
||||
|
||||
public int inflateInit(){
|
||||
return inflateInit(DEF_WBITS);
|
||||
}
|
||||
public int inflateInit(bool nowrap){
|
||||
return inflateInit(DEF_WBITS, nowrap);
|
||||
}
|
||||
public int inflateInit(int w){
|
||||
return inflateInit(w, false);
|
||||
}
|
||||
|
||||
public int inflateInit(int w, bool nowrap){
|
||||
istate=new Inflate();
|
||||
return istate.inflateInit(this, nowrap?-w:w);
|
||||
}
|
||||
|
||||
public int inflate(int f){
|
||||
if(istate==null) return Z_STREAM_ERROR;
|
||||
return istate.inflate(this, f);
|
||||
}
|
||||
public int inflateEnd(){
|
||||
if(istate==null) return Z_STREAM_ERROR;
|
||||
int ret=istate.inflateEnd(this);
|
||||
istate = null;
|
||||
return ret;
|
||||
}
|
||||
public int inflateSync(){
|
||||
if(istate == null)
|
||||
return Z_STREAM_ERROR;
|
||||
return istate.inflateSync(this);
|
||||
}
|
||||
public int inflateSetDictionary(byte[] dictionary, int dictLength){
|
||||
if(istate == null)
|
||||
return Z_STREAM_ERROR;
|
||||
return istate.inflateSetDictionary(this, dictionary, dictLength);
|
||||
}
|
||||
|
||||
public int deflateInit(int level){
|
||||
return deflateInit(level, MAX_WBITS);
|
||||
}
|
||||
public int deflateInit(int level, bool nowrap){
|
||||
return deflateInit(level, MAX_WBITS, nowrap);
|
||||
}
|
||||
public int deflateInit(int level, int bits){
|
||||
return deflateInit(level, bits, false);
|
||||
}
|
||||
public int deflateInit(int level, int bits, bool nowrap){
|
||||
dstate=new Deflate();
|
||||
return dstate.deflateInit(this, level, nowrap?-bits:bits);
|
||||
}
|
||||
public int deflate(int flush){
|
||||
if(dstate==null){
|
||||
return Z_STREAM_ERROR;
|
||||
}
|
||||
return dstate.deflate(this, flush);
|
||||
}
|
||||
public int deflateEnd(){
|
||||
if(dstate==null) return Z_STREAM_ERROR;
|
||||
int ret=dstate.deflateEnd();
|
||||
dstate=null;
|
||||
return ret;
|
||||
}
|
||||
public int deflateParams(int level, int strategy){
|
||||
if(dstate==null) return Z_STREAM_ERROR;
|
||||
return dstate.deflateParams(this, level, strategy);
|
||||
}
|
||||
public int deflateSetDictionary (byte[] dictionary, int dictLength){
|
||||
if(dstate == null)
|
||||
return Z_STREAM_ERROR;
|
||||
return dstate.deflateSetDictionary(this, dictionary, dictLength);
|
||||
}
|
||||
|
||||
// Flush as much pending output as possible. All deflate() output goes
|
||||
// through this function so some applications may wish to modify it
|
||||
// to avoid allocating a large strm->next_out buffer and copying into it.
|
||||
// (See also read_buf()).
|
||||
internal void flush_pending(){
|
||||
int len=dstate.pending;
|
||||
|
||||
if(len>avail_out) len=avail_out;
|
||||
if(len==0) return;
|
||||
|
||||
if(dstate.pending_buf.Length<=dstate.pending_out ||
|
||||
next_out.Length<=next_out_index ||
|
||||
dstate.pending_buf.Length<(dstate.pending_out+len) ||
|
||||
next_out.Length<(next_out_index+len)){
|
||||
// System.out.println(dstate.pending_buf.length+", "+dstate.pending_out+
|
||||
// ", "+next_out.length+", "+next_out_index+", "+len);
|
||||
// System.out.println("avail_out="+avail_out);
|
||||
}
|
||||
|
||||
System.Array.Copy(dstate.pending_buf, dstate.pending_out,
|
||||
next_out, next_out_index, len);
|
||||
|
||||
next_out_index+=len;
|
||||
dstate.pending_out+=len;
|
||||
total_out+=len;
|
||||
avail_out-=len;
|
||||
dstate.pending-=len;
|
||||
if(dstate.pending==0){
|
||||
dstate.pending_out=0;
|
||||
}
|
||||
}
|
||||
|
||||
// Read a new buffer from the current input stream, update the adler32
|
||||
// and total number of bytes read. All deflate() input goes through
|
||||
// this function so some applications may wish to modify it to avoid
|
||||
// allocating a large strm->next_in buffer and copying from it.
|
||||
// (See also flush_pending()).
|
||||
internal int read_buf(byte[] buf, int start, int size) {
|
||||
int len=avail_in;
|
||||
|
||||
if(len>size) len=size;
|
||||
if(len==0) return 0;
|
||||
|
||||
avail_in-=len;
|
||||
|
||||
if(dstate.noheader==0) {
|
||||
adler=_adler.adler32(adler, next_in, next_in_index, len);
|
||||
}
|
||||
System.Array.Copy(next_in, next_in_index, buf, start, len);
|
||||
next_in_index += len;
|
||||
total_in += len;
|
||||
return len;
|
||||
}
|
||||
|
||||
public void free(){
|
||||
next_in=null;
|
||||
next_out=null;
|
||||
msg=null;
|
||||
_adler=null;
|
||||
}
|
||||
}
|
||||
}
|
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";
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user