Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
.net core port of HtmlRenderer and HtmlRenderer.PdfSharp
  • Loading branch information
karel-hajek-absa committed Mar 4, 2020
commit 30d37c13020f536652a9f3612390783e77fcbcc4
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,5 @@ _UpgradeReport_Files/
Backup*/
UpgradeLog*.XML

*.DotSettings
*.DotSettings
/Source/.vs/
Binary file modified Build/NuGet.exe
Binary file not shown.
30 changes: 30 additions & 0 deletions Build/NuGet/HtmlRenderer.PdfSharp.Core.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>Polybioz.HtmlRenderer.PdfSharp.Core</id>
<version>1.0.0</version>
<title>HTML Renderer for PDF using PdfSharp</title>
<authors>Karel Hajek</authors>
<owners>Karel Hajek</owners>
<license type="file">LICENSE.txt</license>
<projectUrl>https://github.com/polybioz/HTML-Renderer-Core</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<summary>
HtmlRenderer.PdfSharp for .NET Core
</summary>
<description>
HtmlRenderer.PdfSharp.Core is a partial port of HtmlRenderer.PdfSharp for .NET Core
</description>
<copyright>José Manuel Menéndez Poo, Arthur Teplitzki</copyright>
<tags>html render renderer draw pdfsharp .NETCore</tags>
<repository url="https://github.com/polybioz/HTML-Renderer-Core" />
<dependencies>
<dependency id="PdfSharpCore" version="1.1.21"/>
</dependencies>
</metadata>
<files>
<file src="LICENSE.txt" />
<file src="..\Release\PdfSharpCore\netcoreapp2.1\HtmlRenderer.Core.dll" target="lib\netcoreapp2.1" />
<file src="..\Release\PdfSharpCore\netcoreapp2.1\HtmlRenderer.PdfSharp.Core.dll" target="lib\netcoreapp2.1" />
</files>
</package>
28 changes: 28 additions & 0 deletions Build/NuGet/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Copyright (c) 2009, José Manuel Menéndez Poo
Copyright (c) 2013, Arthur Teplitzki
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

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.

Neither the name of the menendezpoo.com, ArthurHub nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS 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 THE COPYRIGHT HOLDER OR CONTRIBUTORS 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.
273 changes: 273 additions & 0 deletions Source/HtmlRenderer.Core/Adapters/Entities/RColor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
// Type: System.Drawing.Color
// Assembly: System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// Assembly location: C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll

using System;
using System.Text;

namespace TheArtOfDev.HtmlRenderer.Adapters.Entities
{
/// <summary>
/// Represents an ARGB (alpha, red, green, blue) color.
/// </summary>
public struct RColor
{
#region Fields and Consts

/// <summary>
/// Represents a color that is null.
/// </summary>
/// <filterpriority>1</filterpriority>
public static readonly RColor Empty = new RColor();

private readonly long _value;

#endregion


private RColor(long value)
{
_value = value;
}

/// <summary>
/// Gets a system-defined color.
/// </summary>
public static RColor Transparent
{
get { return new RColor(0); }
}

/// <summary>
/// Gets a system-defined color that has an ARGB value of #FF000000.
/// </summary>
public static RColor Black
{
get { return FromArgb(0, 0, 0); }
}

/// <summary>
/// Gets a system-defined color that has an ARGB value of #FFFFFFFF.
/// </summary>
public static RColor White
{
get { return FromArgb(255, 255, 255); }
}

/// <summary>
/// Gets a system-defined color that has an ARGB value of #FFF5F5F5.
/// </summary>
public static RColor WhiteSmoke
{
get { return FromArgb(245, 245, 245); }
}

/// <summary>
/// Gets a system-defined color that has an ARGB value of #FFD3D3D3.
/// </summary>
public static RColor LightGray
{
get { return FromArgb(211, 211, 211); }
}

/// <summary>
/// Gets the red component value of this <see cref="RColor" /> structure.
/// </summary>
public byte R
{
get { return (byte)((ulong)(_value >> 16) & byte.MaxValue); }
}

/// <summary>
/// Gets the green component value of this <see cref="RColor" /> structure.
/// </summary>
public byte G
{
get { return (byte)((ulong)(_value >> 8) & byte.MaxValue); }
}

/// <summary>
/// Gets the blue component value of this <see cref="RColor" /> structure.
/// </summary>
public byte B
{
get { return (byte)((ulong)_value & byte.MaxValue); }
}

/// <summary>
/// Gets the alpha component value of this <see cref="RColor" /> structure.
/// </summary>
public byte A
{
get { return (byte)((ulong)(_value >> 24) & byte.MaxValue); }
}

/// <summary>
/// Specifies whether this <see cref="RColor" /> structure is uninitialized.
/// </summary>
/// <returns>
/// This property returns true if this color is uninitialized; otherwise, false.
/// </returns>
/// <filterpriority>1</filterpriority>
public bool IsEmpty
{
get { return _value == 0; }
}

/// <summary>
/// Tests whether two specified <see cref="RColor" /> structures are equivalent.
/// </summary>
/// <returns>
/// true if the two <see cref="RColor" /> structures are equal; otherwise, false.
/// </returns>
/// <param name="left">
/// The <see cref="RColor" /> that is to the left of the equality operator.
/// </param>
/// <param name="right">
/// The <see cref="RColor" /> that is to the right of the equality operator.
/// </param>
/// <filterpriority>3</filterpriority>
public static bool operator ==(RColor left, RColor right)
{
return left._value == right._value;
}

/// <summary>
/// Tests whether two specified <see cref="RColor" /> structures are different.
/// </summary>
/// <returns>
/// true if the two <see cref="RColor" /> structures are different; otherwise, false.
/// </returns>
/// <param name="left">
/// The <see cref="RColor" /> that is to the left of the inequality operator.
/// </param>
/// <param name="right">
/// The <see cref="RColor" /> that is to the right of the inequality operator.
/// </param>
/// <filterpriority>3</filterpriority>
public static bool operator !=(RColor left, RColor right)
{
return !(left == right);
}

/// <summary>
/// Creates a <see cref="RColor" /> structure from the four ARGB component (alpha, red, green, and blue) values. Although this method allows a 32-bit value to be passed for each component, the value of each component is limited to 8 bits.
/// </summary>
/// <returns>
/// The <see cref="RColor" /> that this method creates.
/// </returns>
/// <param name="alpha">The alpha component. Valid values are 0 through 255. </param>
/// <param name="red">The red component. Valid values are 0 through 255. </param>
/// <param name="green">The green component. Valid values are 0 through 255. </param>
/// <param name="blue">The blue component. Valid values are 0 through 255. </param>
/// <exception cref="T:System.ArgumentException">
/// <paramref name="alpha" />, <paramref name="red" />, <paramref name="green" />, or <paramref name="blue" /> is less than 0 or greater than 255.
/// </exception>
/// <filterpriority>1</filterpriority>
public static RColor FromArgb(int alpha, int red, int green, int blue)
{
CheckByte(alpha);
CheckByte(red);
CheckByte(green);
CheckByte(blue);
return new RColor((uint)(red << 16 | green << 8 | blue | alpha << 24) & (long)uint.MaxValue);
}

/// <summary>
/// Creates a <see cref="RColor" /> structure from the specified 8-bit color values (red, green, and blue). The alpha value is implicitly 255 (fully opaque). Although this method allows a 32-bit value to be passed for each color component, the value of each component is limited to 8 bits.
/// </summary>
/// <returns>
/// The <see cref="RColor" /> that this method creates.
/// </returns>
/// <param name="red">
/// The red component value for the new <see cref="RColor" />. Valid values are 0 through 255.
/// </param>
/// <param name="green">
/// The green component value for the new <see cref="RColor" />. Valid values are 0 through 255.
/// </param>
/// <param name="blue">
/// The blue component value for the new <see cref="RColor" />. Valid values are 0 through 255.
/// </param>
/// <exception cref="T:System.ArgumentException">
/// <paramref name="red" />, <paramref name="green" />, or <paramref name="blue" /> is less than 0 or greater than 255.
/// </exception>
/// <filterpriority>1</filterpriority>
public static RColor FromArgb(int red, int green, int blue)
{
return FromArgb(byte.MaxValue, red, green, blue);
}

/// <summary>
/// Tests whether the specified object is a <see cref="RColor" /> structure and is equivalent to this
/// <see
/// cref="RColor" />
/// structure.
/// </summary>
/// <returns>
/// true if <paramref name="obj" /> is a <see cref="RColor" /> structure equivalent to this
/// <see
/// cref="RColor" />
/// structure; otherwise, false.
/// </returns>
/// <param name="obj">The object to test. </param>
/// <filterpriority>1</filterpriority>
public override bool Equals(object obj)
{
if (obj is RColor)
{
var color = (RColor)obj;
return _value == color._value;
}
return false;
}

/// <summary>
/// Returns a hash code for this <see cref="RColor" /> structure.
/// </summary>
/// <returns>
/// An integer value that specifies the hash code for this <see cref="RColor" />.
/// </returns>
/// <filterpriority>1</filterpriority>
public override int GetHashCode()
{
return _value.GetHashCode();
}

/// <summary>
/// Converts this <see cref="RColor" /> structure to a human-readable string.
/// </summary>
public override string ToString()
{
var stringBuilder = new StringBuilder(32);
stringBuilder.Append(GetType().Name);
stringBuilder.Append(" [");
if (_value != 0)
{
stringBuilder.Append("A=");
stringBuilder.Append(A);
stringBuilder.Append(", R=");
stringBuilder.Append(R);
stringBuilder.Append(", G=");
stringBuilder.Append(G);
stringBuilder.Append(", B=");
stringBuilder.Append(B);
}
else
stringBuilder.Append("Empty");
stringBuilder.Append("]");
return stringBuilder.ToString();
}


#region Private methods

private static void CheckByte(int value)
{
if (value >= 0 && value <= byte.MaxValue)
return;
throw new ArgumentException("InvalidEx2BoundArgument");
}

#endregion
}
}
27 changes: 27 additions & 0 deletions Source/HtmlRenderer.Core/Adapters/Entities/RDashStyle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// "Therefore those skilled at the unorthodox
// are infinite as heaven and earth,
// inexhaustible as the great rivers.
// When they come to an end,
// they begin again,
// like the days and months;
// they die and are reborn,
// like the four seasons."
//
// - Sun Tsu,
// "The Art of War"

namespace TheArtOfDev.HtmlRenderer.Adapters.Entities
{
/// <summary>
/// Specifies the style of dashed lines drawn with a <see cref="RPen"/> object.
/// </summary>
public enum RDashStyle
{
Solid,
Dash,
Dot,
DashDot,
DashDotDot,
Custom,
}
}
Loading