vendor: import KillerPDF 1.7.5 source (GPL-3.0) as the base for MMD PDF

This commit is contained in:
2026-08-27 06:58:22 +02:00
commit 532485a830
577 changed files with 149058 additions and 0 deletions
+302
View File
@@ -0,0 +1,302 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.Collections.Generic;
using System.Diagnostics;
using PdfSharpCore.Internal;
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Represents a graphics path that uses the same notation as GDI+.
/// </summary>
internal class CoreGraphicsPath
{
// Same values as GDI+ uses.
const byte PathPointTypeStart = 0; // move
const byte PathPointTypeLine = 1; // line
const byte PathPointTypeBezier = 3; // default Bezier (= cubic Bezier)
const byte PathPointTypePathTypeMask = 0x07; // type mask (lowest 3 bits).
const byte PathPointTypeCloseSubpath = 0x80; // closed flag
public CoreGraphicsPath()
{ }
public CoreGraphicsPath(CoreGraphicsPath path)
{
_points = new List<XPoint>(path._points);
_types = new List<byte>(path._types);
}
public void MoveOrLineTo(double x, double y)
{
// Make a MoveTo if there is no previous subpath or the previous subpath was closed.
// Otherwise make a LineTo.
if (_types.Count == 0 || (_types[_types.Count - 1] & PathPointTypeCloseSubpath) == PathPointTypeCloseSubpath)
MoveTo(x, y);
else
LineTo(x, y, false);
}
public void MoveTo(double x, double y)
{
_points.Add(new XPoint(x, y));
_types.Add(PathPointTypeStart);
}
public void LineTo(double x, double y, bool closeSubpath)
{
if (_points.Count > 0 && _points[_points.Count - 1].Equals(new XPoint(x, y)))
return;
_points.Add(new XPoint(x, y));
_types.Add((byte)(PathPointTypeLine | (closeSubpath ? PathPointTypeCloseSubpath : 0)));
}
public void BezierTo(double x1, double y1, double x2, double y2, double x3, double y3, bool closeSubpath)
{
_points.Add(new XPoint(x1, y1));
_types.Add(PathPointTypeBezier);
_points.Add(new XPoint(x2, y2));
_types.Add(PathPointTypeBezier);
_points.Add(new XPoint(x3, y3));
_types.Add((byte)(PathPointTypeBezier | (closeSubpath ? PathPointTypeCloseSubpath : 0)));
}
/// <summary>
/// Adds an arc that fills exactly one quadrant (quarter) of an ellipse.
/// Just a quick hack to draw rounded rectangles before AddArc is fully implemented.
/// </summary>
public void QuadrantArcTo(double x, double y, double width, double height, int quadrant, bool clockwise)
{
if (width < 0)
throw new ArgumentOutOfRangeException("width");
if (height < 0)
throw new ArgumentOutOfRangeException("height");
double w = Const.κ * width;
double h = Const.κ * height;
double x1, y1, x2, y2, x3, y3;
switch (quadrant)
{
case 1:
if (clockwise)
{
x1 = x + w;
y1 = y - height;
x2 = x + width;
y2 = y - h;
x3 = x + width;
y3 = y;
}
else
{
x1 = x + width;
y1 = y - h;
x2 = x + w;
y2 = y - height;
x3 = x;
y3 = y - height;
}
break;
case 2:
if (clockwise)
{
x1 = x - width;
y1 = y - h;
x2 = x - w;
y2 = y - height;
x3 = x;
y3 = y - height;
}
else
{
x1 = x - w;
y1 = y - height;
x2 = x - width;
y2 = y - h;
x3 = x - width;
y3 = y;
}
break;
case 3:
if (clockwise)
{
x1 = x - w;
y1 = y + height;
x2 = x - width;
y2 = y + h;
x3 = x - width;
y3 = y;
}
else
{
x1 = x - width;
y1 = y + h;
x2 = x - w;
y2 = y + height;
x3 = x;
y3 = y + height;
}
break;
case 4:
if (clockwise)
{
x1 = x + width;
y1 = y + h;
x2 = x + w;
y2 = y + height;
x3 = x;
y3 = y + height;
}
else
{
x1 = x + w;
y1 = y + height;
x2 = x + width;
y2 = y + h;
x3 = x + width;
y3 = y;
}
break;
default:
throw new ArgumentOutOfRangeException("quadrant");
}
BezierTo(x1, y1, x2, y2, x3, y3, false);
}
/// <summary>
/// Closes the current subpath.
/// </summary>
public void CloseSubpath()
{
int count = _types.Count;
if (count > 0)
_types[count - 1] |= PathPointTypeCloseSubpath;
}
/// <summary>
/// Gets or sets the current fill mode (alternate or winding).
/// </summary>
XFillMode FillMode
{
get { return _fillMode; }
set { _fillMode = value; }
}
XFillMode _fillMode;
public void AddArc(double x, double y, double width, double height, double startAngle, double sweepAngle)
{
XMatrix matrix = XMatrix.Identity;
List<XPoint> points = GeometryHelper.BezierCurveFromArc(x, y, width, height, startAngle, sweepAngle, PathStart.MoveTo1st, ref matrix);
int count = points.Count;
Debug.Assert((count + 2) % 3 == 0);
MoveOrLineTo(points[0].X, points[0].Y);
for (int idx = 1; idx < count; idx += 3)
BezierTo(points[idx].X, points[idx].Y, points[idx + 1].X, points[idx + 1].Y, points[idx + 2].X, points[idx + 2].Y, false);
}
public void AddArc(XPoint point1, XPoint point2, XSize size, double rotationAngle, bool isLargeArg, XSweepDirection sweepDirection)
{
List<XPoint> points = GeometryHelper.BezierCurveFromArc(point1, point2, size, rotationAngle, isLargeArg,
sweepDirection == XSweepDirection.Clockwise, PathStart.MoveTo1st);
int count = points.Count;
Debug.Assert((count + 2) % 3 == 0);
MoveOrLineTo(points[0].X, points[0].Y);
for (int idx = 1; idx < count; idx += 3)
BezierTo(points[idx].X, points[idx].Y, points[idx + 1].X, points[idx + 1].Y, points[idx + 2].X, points[idx + 2].Y, false);
}
public void AddCurve(XPoint[] points, double tension)
{
int count = points.Length;
if (count < 2)
throw new ArgumentException("AddCurve requires two or more points.", "points");
tension /= 3;
MoveOrLineTo(points[0].X, points[0].Y);
if (count == 2)
{
//figure.Segments.Add(GeometryHelper.CreateCurveSegment(points[0], points[0], points[1], points[1], tension));
ToCurveSegment(points[0], points[0], points[1], points[1], tension);
}
else
{
//figure.Segments.Add(GeometryHelper.CreateCurveSegment(points[0], points[0], points[1], points[2], tension));
ToCurveSegment(points[0], points[0], points[1], points[2], tension);
for (int idx = 1; idx < count - 2; idx++)
{
//figure.Segments.Add(GeometryHelper.CreateCurveSegment(points[idx - 1], points[idx], points[idx + 1], points[idx + 2], tension));
ToCurveSegment(points[idx - 1], points[idx], points[idx + 1], points[idx + 2], tension);
}
//figure.Segments.Add(GeometryHelper.CreateCurveSegment(points[count - 3], points[count - 2], points[count - 1], points[count - 1], tension));
ToCurveSegment(points[count - 3], points[count - 2], points[count - 1], points[count - 1], tension);
}
}
///// <summary>
///// Appends a Bézier curve for a cardinal spline through pt1 and pt2.
///// </summary>
//void ToCurveSegment(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3, double tension3, bool closeSubpath)
//{
// BezierTo(
// x1 + tension3 * (x2 - x0), y1 + tension3 * (y2 - y0),
// x2 - tension3 * (x3 - x1), y2 - tension3 * (y3 - y1),
// x2, y2, closeSubpath);
//}
void ToCurveSegment(XPoint pt0, XPoint pt1, XPoint pt2, XPoint pt3, double tension3)
{
BezierTo(
pt1.X + tension3 * (pt2.X - pt0.X), pt1.Y + tension3 * (pt2.Y - pt0.Y),
pt2.X - tension3 * (pt3.X - pt1.X), pt2.Y - tension3 * (pt3.Y - pt1.Y),
pt2.X, pt2.Y,
false);
}
/// <summary>
/// Gets the path points in GDI+ style.
/// </summary>
public XPoint[] PathPoints { get { return _points.ToArray(); } }
/// <summary>
/// Gets the path types in GDI+ style.
/// </summary>
public byte[] PathTypes { get { return _types.ToArray(); } }
readonly List<XPoint> _points = new List<XPoint>();
readonly List<byte> _types = new List<byte>();
}
}
+133
View File
@@ -0,0 +1,133 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text;
using PdfSharpCore.Fonts;
using PdfSharpCore.Fonts.OpenType;
using PdfSharpCore.Internal;
using PdfSharpCore.Pdf;
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Global cache of all internal font family objects.
/// </summary>
internal sealed class FontFamilyCache
{
FontFamilyCache()
{
_familiesByName = new Dictionary<string, FontFamilyInternal>(StringComparer.OrdinalIgnoreCase);
}
public static FontFamilyInternal GetFamilyByName(string familyName)
{
try
{
Lock.EnterFontFactory();
FontFamilyInternal family;
Singleton._familiesByName.TryGetValue(familyName, out family);
return family;
}
finally { Lock.ExitFontFactory(); }
}
/// <summary>
/// Caches the font family or returns a previously cached one.
/// </summary>
public static FontFamilyInternal CacheOrGetFontFamily(FontFamilyInternal fontFamily)
{
try
{
Lock.EnterFontFactory();
// Recall that a font family is uniquely identified by its case insensitive name.
FontFamilyInternal existingFontFamily;
if (Singleton._familiesByName.TryGetValue(fontFamily.Name, out existingFontFamily))
{
#if DEBUG_
if (fontFamily.Name == "xxx")
fontFamily.GetType();
#endif
return existingFontFamily;
}
Singleton._familiesByName.Add(fontFamily.Name, fontFamily);
return fontFamily;
}
finally { Lock.ExitFontFactory(); }
}
/// <summary>
/// Gets the singleton.
/// </summary>
static FontFamilyCache Singleton
{
get
{
// ReSharper disable once InvertIf
if (_singleton == null)
{
try
{
Lock.EnterFontFactory();
if (_singleton == null)
_singleton = new FontFamilyCache();
}
finally { Lock.ExitFontFactory(); }
}
return _singleton;
}
}
static volatile FontFamilyCache _singleton;
internal static string GetCacheState()
{
StringBuilder state = new StringBuilder();
state.Append("====================\n");
state.Append("Font families by name\n");
Dictionary<string, FontFamilyInternal>.KeyCollection familyKeys = Singleton._familiesByName.Keys;
int count = familyKeys.Count;
string[] keys = new string[count];
familyKeys.CopyTo(keys, 0);
Array.Sort(keys, StringComparer.OrdinalIgnoreCase);
foreach (string key in keys)
state.AppendFormat(" {0}: {1}\n", key, Singleton._familiesByName[key].DebuggerDisplay);
state.Append("\n");
return state.ToString();
}
/// <summary>
/// Maps family name to internal font family.
/// </summary>
readonly Dictionary<string, FontFamilyInternal> _familiesByName;
}
}
+101
View File
@@ -0,0 +1,101 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
using System.Diagnostics;
using System.Globalization;
using PdfSharpCore.Internal;
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Internal implementation class of XFontFamily.
/// </summary>
[DebuggerDisplay("{DebuggerDisplay}")]
internal class FontFamilyInternal
{
// Implementation Notes
// FontFamilyInternal implements an XFontFamily.
//
// * Each XFontFamily object is just a handle to its FontFamilyInternal singleton.
//
// * A FontFamilyInternal is is uniquely identified by its name. It
// is not possible to use two different fonts that have the same
// family name.
FontFamilyInternal(string familyName, bool createPlatformObjects)
{
_sourceName = _name = familyName;
}
internal static FontFamilyInternal GetOrCreateFromName(string familyName, bool createPlatformObject)
{
try
{
Lock.EnterFontFactory();
FontFamilyInternal family = FontFamilyCache.GetFamilyByName(familyName);
if (family == null)
{
family = new FontFamilyInternal(familyName, createPlatformObject);
family = FontFamilyCache.CacheOrGetFontFamily(family);
}
return family;
}
finally { Lock.ExitFontFactory(); }
}
/// <summary>
/// Gets the family name this family was originally created with.
/// </summary>
public string SourceName
{
get { return _sourceName; }
}
readonly string _sourceName;
/// <summary>
/// Gets the name that uniquely identifies this font family.
/// </summary>
public string Name
{
// In WPF this is the Win32FamilyName, not the WPF family name.
get { return _name; }
}
readonly string _name;
/// <summary>
/// Gets the DebuggerDisplayAttribute text.
/// </summary>
// ReSha rper disable UnusedMember.Local
internal string DebuggerDisplay
// ReShar per restore UnusedMember.Local
{
get { return string.Format(CultureInfo.InvariantCulture, "FontFamiliy: '{0}'", Name); }
}
}
}
+165
View File
@@ -0,0 +1,165 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using PdfSharpCore.Fonts;
using PdfSharpCore.Fonts.OpenType;
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Bunch of functions that do not have a better place.
/// </summary>
static class FontHelper
{
/// <summary>
/// Measure string directly from font data.
/// </summary>
public static XSize MeasureString(string text, XFont font, XStringFormat stringFormat)
{
XSize size = new XSize();
OpenTypeDescriptor descriptor = FontDescriptorCache.GetOrCreateDescriptorFor(font) as OpenTypeDescriptor;
if (descriptor != null)
{
// Height is the sum of ascender and descender.
var singleLineHeight = (descriptor.Ascender + descriptor.Descender) * font.Size / font.UnitsPerEm;
var lineGapHeight = (descriptor.LineSpacing - descriptor.Ascender - descriptor.Descender) * font.Size / font.UnitsPerEm;
Debug.Assert(descriptor.Ascender > 0);
bool symbol = descriptor.FontFace.cmap.symbol;
int length = text.Length;
int adjustedLength = length;
var height = singleLineHeight;
int maxWidth = 0;
int width = 0;
for (int idx = 0; idx < length; idx++)
{
char ch = text[idx];
// Handle line feed ( \n)
if (ch == 10)
{
adjustedLength--;
if (idx < (length - 1))
{
maxWidth = Math.Max(maxWidth, width);
width = 0;
height += lineGapHeight + singleLineHeight;
}
continue;
}
// HACK: Handle tabulator sign as space (\t)
if (ch == 9)
{
ch = ' ';
}
// HACK: Unclear what to do here.
if (ch < 32)
{
adjustedLength--;
continue;
}
if (symbol)
{
// Remap ch for symbol fonts.
ch = (char)(ch | (descriptor.FontFace.os2.usFirstCharIndex & 0xFF00)); // @@@ refactor
// Used | instead of + because of: http://PdfSharpCore.codeplex.com/workitem/15954
}
int glyphIndex = descriptor.CharCodeToGlyphIndex(ch);
width += descriptor.GlyphIndexToWidth(glyphIndex);
}
maxWidth = Math.Max(maxWidth, width);
// What? size.Width = maxWidth * font.Size * (font.Italic ? 1 : 1) / descriptor.UnitsPerEm;
size.Width = maxWidth * font.Size / descriptor.UnitsPerEm;
size.Height = height;
// Adjust bold simulation.
if ((font.GlyphTypeface.StyleSimulations & XStyleSimulations.BoldSimulation) == XStyleSimulations.BoldSimulation)
{
// Add 2% of the em-size for each character.
// Unsure how to deal with white space. Currently count as regular character.
size.Width += adjustedLength * font.Size * Const.BoldEmphasis;
}
}
Debug.Assert(descriptor != null, "No OpenTypeDescriptor.");
return size;
}
/// <summary>
/// Calculates an Adler32 checksum combined with the buffer length
/// in a 64 bit unsigned integer.
/// </summary>
public static ulong CalcChecksum(byte[] buffer)
{
if (buffer == null)
throw new ArgumentNullException("buffer");
const uint prime = 65521; // largest prime smaller than 65536
uint s1 = 0;
uint s2 = 0;
int length = buffer.Length;
int offset = 0;
while (length > 0)
{
int n = 3800;
if (n > length)
n = length;
length -= n;
while (--n >= 0)
{
s1 += buffer[offset++];
s2 = s2 + s1;
}
s1 %= prime;
s2 %= prime;
}
ulong ul1 = (ulong)s2 << 16;
ul1 = ul1 | s1;
ulong ul2 = (ulong)buffer.Length;
return (ul1 << 32) | ul2;
}
public static XFontStyle CreateStyle(bool isBold, bool isItalic)
{
return (isBold ? XFontStyle.Bold : 0) | (isItalic ? XFontStyle.Italic : 0);
}
}
}
+317
View File
@@ -0,0 +1,317 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.Diagnostics;
using System.Collections.Generic;
using PdfSharpCore.Internal;
// ReSharper disable RedundantNameQualifier
// ReSharper disable CompareOfFloatsByEqualityOperator
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Helper class for Geometry paths.
/// </summary>
static class GeometryHelper
{
/// <summary>
/// Creates between 1 and 5 Béziers curves from parameters specified like in GDI+.
/// </summary>
public static List<XPoint> BezierCurveFromArc(double x, double y, double width, double height, double startAngle, double sweepAngle,
PathStart pathStart, ref XMatrix matrix)
{
List<XPoint> points = new List<XPoint>();
// Normalize the angles.
double α = startAngle;
if (α < 0)
α = α + (1 + Math.Floor((Math.Abs(α) / 360))) * 360;
else if (α > 360)
α = α - Math.Floor(α / 360) * 360;
Debug.Assert(α >= 0 && α <= 360);
double β = sweepAngle;
if (β < -360)
β = -360;
else if (β > 360)
β = 360;
if (α == 0 && β < 0)
α = 360;
else if (α == 360 && β > 0)
α = 0;
// Is it possible that the arc is small starts and ends in same quadrant?
bool smallAngle = Math.Abs(β) <= 90;
β = α + β;
if (β < 0)
β = β + (1 + Math.Floor((Math.Abs(β) / 360))) * 360;
bool clockwise = sweepAngle > 0;
int startQuadrant = Quadrant(α, true, clockwise);
int endQuadrant = Quadrant(β, false, clockwise);
if (startQuadrant == endQuadrant && smallAngle)
AppendPartialArcQuadrant(points, x, y, width, height, α, β, pathStart, matrix);
else
{
int currentQuadrant = startQuadrant;
bool firstLoop = true;
do
{
if (currentQuadrant == startQuadrant && firstLoop)
{
double ξ = currentQuadrant * 90 + (clockwise ? 90 : 0);
AppendPartialArcQuadrant(points, x, y, width, height, α, ξ, pathStart, matrix);
}
else if (currentQuadrant == endQuadrant)
{
double ξ = currentQuadrant * 90 + (clockwise ? 0 : 90);
AppendPartialArcQuadrant(points, x, y, width, height, ξ, β, PathStart.Ignore1st, matrix);
}
else
{
double ξ1 = currentQuadrant * 90 + (clockwise ? 0 : 90);
double ξ2 = currentQuadrant * 90 + (clockwise ? 90 : 0);
AppendPartialArcQuadrant(points, x, y, width, height, ξ1, ξ2, PathStart.Ignore1st, matrix);
}
// Don't stop immediately if arc is greater than 270 degrees.
if (currentQuadrant == endQuadrant && smallAngle)
break;
smallAngle = true;
if (clockwise)
currentQuadrant = currentQuadrant == 3 ? 0 : currentQuadrant + 1;
else
currentQuadrant = currentQuadrant == 0 ? 3 : currentQuadrant - 1;
firstLoop = false;
} while (true);
}
return points;
}
/// <summary>
/// Calculates the quadrant (0 through 3) of the specified angle. If the angle lies on an edge
/// (0, 90, 180, etc.) the result depends on the details how the angle is used.
/// </summary>
static int Quadrant(double φ, bool start, bool clockwise)
{
Debug.Assert(φ >= 0);
if (φ > 360)
φ = φ - Math.Floor(φ / 360) * 360;
int quadrant = (int)(φ / 90);
if (quadrant * 90 == φ)
{
if ((start && !clockwise) || (!start && clockwise))
quadrant = quadrant == 0 ? 3 : quadrant - 1;
}
else
quadrant = clockwise ? ((int)Math.Floor(φ / 90)) % 4 : (int)Math.Floor(φ / 90);
return quadrant;
}
/// <summary>
/// Appends a Bézier curve for an arc within a full quadrant.
/// </summary>
static void AppendPartialArcQuadrant(List<XPoint> points, double x, double y, double width, double height, double α, double β, PathStart pathStart, XMatrix matrix)
{
Debug.Assert(α >= 0 && α <= 360);
Debug.Assert(β >= 0);
if (β > 360)
β = β - Math.Floor(β / 360) * 360;
Debug.Assert(Math.Abs(α - β) <= 90);
// Scanling factor.
double δx = width / 2;
double δy = height / 2;
// Center of ellipse.
double x0 = x + δx;
double y0 = y + δy;
// We have the following quarters:
// |
// 2 | 3
// ----+-----
// 1 | 0
// |
// If the angles lie in quarter 2 or 3, their values are subtracted by 180 and the
// resulting curve is reflected at the center. This algorithm works as expected (simply tried out).
// There may be a mathematically more elegant solution...
bool reflect = false;
if (α >= 180 && β >= 180)
{
α -= 180;
β -= 180;
reflect = true;
}
double cosα, cosβ, sinα, sinβ;
if (width == height)
{
// Circular arc needs no correction.
α = α * Calc.Deg2Rad;
β = β * Calc.Deg2Rad;
}
else
{
// Elliptic arc needs the angles to be adjusted such that the scaling transformation is compensated.
α = α * Calc.Deg2Rad;
sinα = Math.Sin(α);
if (Math.Abs(sinα) > 1E-10)
α = Math.PI / 2 - Math.Atan(δy * Math.Cos(α) / (δx * sinα));
β = β * Calc.Deg2Rad;
sinβ = Math.Sin(β);
if (Math.Abs(sinβ) > 1E-10)
β = Math.PI / 2 - Math.Atan(δy * Math.Cos(β) / (δx * sinβ));
}
double κ = 4 * (1 - Math.Cos((α - β) / 2)) / (3 * Math.Sin((β - α) / 2));
sinα = Math.Sin(α);
cosα = Math.Cos(α);
sinβ = Math.Sin(β);
cosβ = Math.Cos(β);
//XPoint pt1, pt2, pt3;
if (!reflect)
{
// Calculation for quarter 0 and 1.
switch (pathStart)
{
case PathStart.MoveTo1st:
points.Add(matrix.Transform(new XPoint(x0 + δx * cosα, y0 + δy * sinα)));
break;
case PathStart.LineTo1st:
points.Add(matrix.Transform(new XPoint(x0 + δx * cosα, y0 + δy * sinα)));
break;
case PathStart.Ignore1st:
break;
}
points.Add(matrix.Transform(new XPoint(x0 + δx * (cosα - κ * sinα), y0 + δy * (sinα + κ * cosα))));
points.Add(matrix.Transform(new XPoint(x0 + δx * (cosβ + κ * sinβ), y0 + δy * (sinβ - κ * cosβ))));
points.Add(matrix.Transform(new XPoint(x0 + δx * cosβ, y0 + δy * sinβ)));
}
else
{
// Calculation for quarter 2 and 3.
switch (pathStart)
{
case PathStart.MoveTo1st:
points.Add(matrix.Transform(new XPoint(x0 - δx * cosα, y0 - δy * sinα)));
break;
case PathStart.LineTo1st:
points.Add(matrix.Transform(new XPoint(x0 - δx * cosα, y0 - δy * sinα)));
break;
case PathStart.Ignore1st:
break;
}
points.Add(matrix.Transform(new XPoint(x0 - δx * (cosα - κ * sinα), y0 - δy * (sinα + κ * cosα))));
points.Add(matrix.Transform(new XPoint(x0 - δx * (cosβ + κ * sinβ), y0 - δy * (sinβ - κ * cosβ))));
points.Add(matrix.Transform(new XPoint(x0 - δx * cosβ, y0 - δy * sinβ)));
}
}
/// <summary>
/// Creates between 1 and 5 Béziers curves from parameters specified like in WPF.
/// </summary>
public static List<XPoint> BezierCurveFromArc(XPoint point1, XPoint point2, XSize size,
double rotationAngle, bool isLargeArc, bool clockwise, PathStart pathStart)
{
// See also http://www.charlespetzold.com/blog/blog.xml from January 2, 2008:
// http://www.charlespetzold.com/blog/2008/01/Mathematics-of-ArcSegment.html
double δx = size.Width;
double δy = size.Height;
Debug.Assert(δx * δy > 0);
double factor = δy / δx;
bool isCounterclockwise = !clockwise;
// Adjust for different radii and rotation angle.
XMatrix matrix = new XMatrix();
matrix.RotateAppend(-rotationAngle);
matrix.ScaleAppend(δy / δx, 1);
XPoint pt1 = matrix.Transform(point1);
XPoint pt2 = matrix.Transform(point2);
// Get info about chord that connects both points.
XPoint midPoint = new XPoint((pt1.X + pt2.X) / 2, (pt1.Y + pt2.Y) / 2);
XVector vect = pt2 - pt1;
double halfChord = vect.Length / 2;
// Get vector from chord to center.
XVector vectRotated;
// (comparing two Booleans here!)
if (isLargeArc == isCounterclockwise)
vectRotated = new XVector(-vect.Y, vect.X);
else
vectRotated = new XVector(vect.Y, -vect.X);
vectRotated.Normalize();
// Distance from chord to center.
double centerDistance = Math.Sqrt(δy * δy - halfChord * halfChord);
if (double.IsNaN(centerDistance))
centerDistance = 0;
// Calculate center point.
XPoint center = midPoint + centerDistance * vectRotated;
// Get angles from center to the two points.
double α = Math.Atan2(pt1.Y - center.Y, pt1.X - center.X);
double β = Math.Atan2(pt2.Y - center.Y, pt2.X - center.X);
// (another comparison of two Booleans!)
if (isLargeArc == (Math.Abs(β - α) < Math.PI))
{
if (α < β)
α += 2 * Math.PI;
else
β += 2 * Math.PI;
}
// Invert matrix for final point calculation.
matrix.Invert();
double sweepAngle = β - α;
// Let the algorithm of GDI+ DrawArc to Bézier curves do the rest of the job
return BezierCurveFromArc(center.X - δx * factor, center.Y - δy, 2 * δx * factor, 2 * δy,
α / Calc.Deg2Rad, sweepAngle / Calc.Deg2Rad, pathStart, ref matrix);
}
}
}
+91
View File
@@ -0,0 +1,91 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.Collections.Generic;
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Represents a stack of XGraphicsState and XGraphicsContainer objects.
/// </summary>
internal class GraphicsStateStack
{
public GraphicsStateStack(XGraphics gfx)
{
_current = new InternalGraphicsState(gfx);
}
public int Count
{
get { return _stack.Count; }
}
public void Push(InternalGraphicsState state)
{
_stack.Push(state);
state.Pushed();
}
public int Restore(InternalGraphicsState state)
{
if (!_stack.Contains(state))
throw new ArgumentException("State not on stack.", "state");
if (state.Invalid)
throw new ArgumentException("State already restored.", "state");
int count = 1;
InternalGraphicsState top = _stack.Pop();
top.Popped();
while (top != state)
{
count++;
state.Invalid = true;
top = _stack.Pop();
top.Popped();
}
state.Invalid = true;
return count;
}
public InternalGraphicsState Current
{
get
{
if (_stack.Count == 0)
return _current;
return _stack.Peek();
}
}
readonly InternalGraphicsState _current;
readonly Stack<InternalGraphicsState> _stack = new Stack<InternalGraphicsState>();
}
}
+176
View File
@@ -0,0 +1,176 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Represents an abstract drawing surface for PdfPages.
/// </summary>
public interface IXGraphicsRenderer
{
void Close();
#region Drawing
/// <summary>
/// Draws a straight line.
/// </summary>
void DrawLine(XPen pen, double x1, double y1, double x2, double y2);
/// <summary>
/// Draws a series of straight lines.
/// </summary>
void DrawLines(XPen pen, XPoint[] points);
/// <summary>
/// Draws a Bézier spline.
/// </summary>
void DrawBezier(XPen pen, double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4);
/// <summary>
/// Draws a series of Bézier splines.
/// </summary>
void DrawBeziers(XPen pen, XPoint[] points);
/// <summary>
/// Draws a cardinal spline.
/// </summary>
void DrawCurve(XPen pen, XPoint[] points, double tension);
/// <summary>
/// Draws an arc.
/// </summary>
void DrawArc(XPen pen, double x, double y, double width, double height, double startAngle, double sweepAngle);
/// <summary>
/// Draws a rectangle.
/// </summary>
void DrawRectangle(XPen pen, XBrush brush, double x, double y, double width, double height);
/// <summary>
/// Draws a series of rectangles.
/// </summary>
void DrawRectangles(XPen pen, XBrush brush, XRect[] rects);
/// <summary>
/// Draws a rectangle with rounded corners.
/// </summary>
void DrawRoundedRectangle(XPen pen, XBrush brush, double x, double y, double width, double height, double ellipseWidth, double ellipseHeight);
/// <summary>
/// Draws an ellipse.
/// </summary>
void DrawEllipse(XPen pen, XBrush brush, double x, double y, double width, double height);
/// <summary>
/// Draws a polygon.
/// </summary>
void DrawPolygon(XPen pen, XBrush brush, XPoint[] points, XFillMode fillmode);
/// <summary>
/// Draws a pie.
/// </summary>
void DrawPie(XPen pen, XBrush brush, double x, double y, double width, double height, double startAngle, double sweepAngle);
/// <summary>
/// Draws a cardinal spline.
/// </summary>
void DrawClosedCurve(XPen pen, XBrush brush, XPoint[] points, double tension, XFillMode fillmode);
/// <summary>
/// Draws a graphical path.
/// </summary>
void DrawPath(XPen pen, XBrush brush, XGraphicsPath path);
/// <summary>
/// Draws a series of glyphs identified by the specified text and font.
/// </summary>
void DrawString(string s, XFont font, XBrush brush, XRect layoutRectangle, XStringFormat format);
/// <summary>
/// Draws an image.
/// </summary>
void DrawImage(XImage image, double x, double y, double width, double height);
void DrawImage(XImage image, XRect destRect, XRect srcRect, XGraphicsUnit srcUnit);
#endregion
#region Save and Restore
/// <summary>
/// Saves the current graphics state without changing it.
/// </summary>
void Save(XGraphicsState state);
/// <summary>
/// Restores the specified graphics state.
/// </summary>
void Restore(XGraphicsState state);
/// <summary>
///
/// </summary>
void BeginContainer(XGraphicsContainer container, XRect dstrect, XRect srcrect, XGraphicsUnit unit);
/// <summary>
///
/// </summary>
void EndContainer(XGraphicsContainer container);
#endregion
#region Transformation
/// <summary>
/// Gets or sets the transformation matrix.
/// </summary>
//XMatrix Transform {get; set;}
void AddTransform(XMatrix transform, XMatrixOrder matrixOrder);
#endregion
#region Clipping
void SetClip(XGraphicsPath path, XCombineMode combineMode);
void ResetClip();
#endregion
#region Miscellaneous
/// <summary>
/// Writes a comment to the output stream. Comments have no effect on the rendering of the output.
/// </summary>
void WriteComment(string comment);
#endregion
}
}
+50
View File
@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace MigraDocCore.DocumentObjectModel.MigraDoc.DocumentObjectModel.Shapes
{
public abstract class ImageSource
{
/// <summary>
/// Gets or sets the image source implementation to use for reading images.
/// </summary>
/// <value>The image source impl.</value>
public static ImageSource ImageSourceImpl { get; set; }
public interface IImageSource
{
int Width { get; }
int Height { get; }
string Name { get; }
void SaveAsJpeg(MemoryStream ms);
bool Transparent { get; }
void SaveAsPdfBitmap(MemoryStream ms);
}
protected abstract IImageSource FromFileImpl(string path, int? quality = 75);
protected abstract IImageSource FromBinaryImpl(string name, Func<byte[]> imageSource, int? quality = 75);
protected abstract IImageSource FromStreamImpl(string name, Func<Stream> imageStream, int? quality = 75);
public static IImageSource FromFile(string path, int? quality = 75)
{
return ImageSourceImpl.FromFileImpl(path, quality);
}
public static IImageSource FromBinary(string name, Func<byte[]> imageSource, int? quality = 75)
{
return ImageSourceImpl.FromBinaryImpl(name, imageSource, quality);
}
public static IImageSource FromStream(string name, Func<Stream> imageStream, int? quality = 75)
{
return ImageSourceImpl.FromStreamImpl(name, imageStream, quality);
}
}
}
@@ -0,0 +1,116 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
namespace PdfSharpCore.Drawing
{
// In GDI+ the functions Save/Restore, BeginContainer/EndContainer, Transform, SetClip and ResetClip
// can be combined in any order. E.g. you can set a clip region, save the graphics state, empty the
// clip region and draw without clipping. Then you can restore to the previous clip region. With PDF
// this behavior is hard to implement. To solve this problem I first an automaton that keeps track
// of all clipping paths and the current transformation when the clip path was set. The automation
// manages a PDF graphics state stack to calculate the desired bahaviour. It also takes into consideration
// not to multiply with inverse matrixes when the user sets a new transformation matrix.
// After the design works on pager I decided not to implement it because it is much to large-scale.
// Instead I lay down some rules how to use the XGraphics class.
//
// * Before you set a transformation matrix save the graphics state (Save) or begin a new container
// (BeginContainer).
//
// * Instead of resetting the transformation matrix, call Restore or EndContainer. If you reset the
// transformation, in PDF must be multiplied with the inverse matrix. That leads to round off errors
// because in PDF file only 3 digits are used and Acrobat internally uses fixed point numbers (until
// versioin 6 or 7 I think).
//
// * When no clip path is defined, you can set or intersect a new path.
//
// * When a clip path is already defined, you can always intersect with a new one (wich leads in general
// to a smaller clip region).
//
// * When a clip path is already defined, you can only reset it to the empty region (ResetClip) when
// the graphics state stack is at the same position as it had when the clip path was defined. Otherwise
// an error occurs.
//
// Keeping these rules leads to easy to read code and best results in PDF output.
/// <summary>
/// Represents the internal state of an XGraphics object.
/// Used when the state is saved and restored.
/// </summary>
internal class InternalGraphicsState
{
public InternalGraphicsState(XGraphics gfx)
{
_gfx = gfx;
}
public InternalGraphicsState(XGraphics gfx, XGraphicsState state)
{
_gfx = gfx;
State = state;
State.InternalState = this;
}
public InternalGraphicsState(XGraphics gfx, XGraphicsContainer container)
{
_gfx = gfx;
container.InternalState = this;
}
/// <summary>
/// Gets or sets the current transformation matrix.
/// </summary>
public XMatrix Transform
{
get { return _transform; }
set { _transform = value; }
}
XMatrix _transform;
/// <summary>
/// Called after this instanced was pushed on the internal graphics stack.
/// </summary>
public void Pushed()
{
}
/// <summary>
/// Called after this instanced was popped from the internal graphics stack.
/// </summary>
public void Popped()
{
Invalid = true;
}
public bool Invalid;
readonly XGraphics _gfx;
internal XGraphicsState State;
}
}
+75
View File
@@ -0,0 +1,75 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
using System;
using PdfSharpCore.Pdf;
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Specifies details about how the font is used in PDF creation.
/// </summary>
public class XPdfFontOptions
{
internal XPdfFontOptions() { }
/// <summary>
/// Initializes a new instance of the <see cref="XPdfFontOptions"/> class.
/// </summary>
public XPdfFontOptions(PdfFontEncoding encoding)
{
_fontEncoding = encoding;
}
/// <summary>
/// Gets a value indicating how the font is encoded.
/// </summary>
public PdfFontEncoding FontEncoding
{
get { return _fontEncoding; }
}
readonly PdfFontEncoding _fontEncoding;
/// <summary>
/// Gets the default options with WinAnsi encoding and always font embedding.
/// </summary>
public static XPdfFontOptions WinAnsiDefault
{
get { return new XPdfFontOptions(PdfFontEncoding.WinAnsi); }
}
/// <summary>
/// Gets the default options with Unicode encoding and always font embedding.
/// </summary>
public static XPdfFontOptions UnicodeDefault
{
get { return new XPdfFontOptions(PdfFontEncoding.Unicode); }
}
}
}
+146
View File
@@ -0,0 +1,146 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Ben Askren
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.ComponentModel;
using PdfSharpCore.Internal;
// ReSharper disable RedundantNameQualifier because it is required for hybrid build
namespace PdfSharpCore.Drawing
{
public class XBaseGradientBrush : XBrush
{
protected XBaseGradientBrush(XColor color1, XColor color2)
{
_color1 = color1;
_color2 = color2;
}
/// <summary>
/// Gets or sets an XMatrix that defines a local geometric transform for this LinearGradientBrush.
/// </summary>
public XMatrix Transform
{
get { return _matrix; }
set { _matrix = value; }
}
/// <summary>
/// Translates the brush with the specified offset.
/// </summary>
public void TranslateTransform(double dx, double dy)
{
_matrix.TranslatePrepend(dx, dy);
}
/// <summary>
/// Translates the brush with the specified offset.
/// </summary>
public void TranslateTransform(double dx, double dy, XMatrixOrder order)
{
_matrix.Translate(dx, dy, order);
}
/// <summary>
/// Scales the brush with the specified scalars.
/// </summary>
public void ScaleTransform(double sx, double sy)
{
_matrix.ScalePrepend(sx, sy);
}
/// <summary>
/// Scales the brush with the specified scalars.
/// </summary>
public void ScaleTransform(double sx, double sy, XMatrixOrder order)
{
_matrix.Scale(sx, sy, order);
}
/// <summary>
/// Rotates the brush with the specified angle.
/// </summary>
public void RotateTransform(double angle)
{
_matrix.RotatePrepend(angle);
}
/// <summary>
/// Rotates the brush with the specified angle.
/// </summary>
public void RotateTransform(double angle, XMatrixOrder order)
{
_matrix.Rotate(angle, order);
}
/// <summary>
/// Multiply the brush transformation matrix with the specified matrix.
/// </summary>
public void MultiplyTransform(XMatrix matrix)
{
_matrix.Prepend(matrix);
}
/// <summary>
/// Multiply the brush transformation matrix with the specified matrix.
/// </summary>
public void MultiplyTransform(XMatrix matrix, XMatrixOrder order)
{
_matrix.Multiply(matrix, order);
}
/// <summary>
/// Resets the brush transformation matrix with identity matrix.
/// </summary>
public void ResetTransform()
{
_matrix = new XMatrix();
}
//public void SetBlendTriangularShape(double focus);
//public void SetBlendTriangularShape(double focus, double scale);
//public void SetSigmaBellShape(double focus);
//public void SetSigmaBellShape(double focus, double scale);
//public Blend Blend { get; set; }
//public bool GammaCorrection { get; set; }
//public ColorBlend InterpolationColors { get; set; }
//public XColor[] LinearColors { get; set; }
//public RectangleF Rectangle { get; }
//public WrapMode WrapMode { get; set; }
//private bool interpolationColorsWasSet;
internal XColor _color1, _color2;
internal XMatrix _matrix;
}
}
+54
View File
@@ -0,0 +1,54 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Provides functionality to load a bitmap image encoded in a specific format.
/// </summary>
public class XBitmapDecoder
{
internal XBitmapDecoder()
{ }
/// <summary>
/// Gets a new instance of the PNG image decoder.
/// </summary>
public static XBitmapDecoder GetPngDecoder()
{
return new XPngBitmapDecoder();
}
}
internal sealed class XPngBitmapDecoder : XBitmapDecoder
{
internal XPngBitmapDecoder()
{ }
}
}
+84
View File
@@ -0,0 +1,84 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.IO;
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Provides functionality to save a bitmap image in a specific format.
/// </summary>
public abstract class XBitmapEncoder
{
internal XBitmapEncoder()
{
// Prevent external deriving.
}
/// <summary>
/// Gets a new instance of the PNG image encoder.
/// </summary>
public static XBitmapEncoder GetPngEncoder()
{
return new XPngBitmapEncoder();
}
/// <summary>
/// Gets or sets the bitmap source to be encoded.
/// </summary>
public XBitmapSource Source
{
get { return _source; }
set { _source = value; }
}
XBitmapSource _source;
/// <summary>
/// When overridden in a derived class saves the image on the specified stream
/// in the respective format.
/// </summary>
public abstract void Save(Stream stream);
}
internal sealed class XPngBitmapEncoder : XBitmapEncoder
{
internal XPngBitmapEncoder()
{ }
/// <summary>
/// Saves the image on the specified stream in PNG format.
/// </summary>
public override void Save(Stream stream)
{
if (Source == null)
throw new InvalidOperationException("No image source.");
}
}
}
+55
View File
@@ -0,0 +1,55 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Defines a pixel based bitmap image.
/// </summary>
public sealed class XBitmapImage : XBitmapSource
{
// TODO: Move code from XImage to this class.
/// <summary>
/// Initializes a new instance of the <see cref="XBitmapImage"/> class.
/// </summary>
internal XBitmapImage(int width, int height)
{
}
/// <summary>
/// Creates a default 24 bit ARGB bitmap with the specified pixel size.
/// </summary>
public static XBitmapSource CreateBitmap(int width, int height)
{
// Create a default 24 bit ARGB bitmap.
return new XBitmapImage(width, height);
}
}
}
+62
View File
@@ -0,0 +1,62 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Defines an abstract base class for pixel based images.
/// </summary>
public abstract class XBitmapSource : XImage
{
// TODO: Move code from XImage to this class.
/// <summary>
/// Gets the width of the image in pixels.
/// </summary>
public override int PixelWidth
{
get
{
return PixelWidth;
}
}
/// <summary>
/// Gets the height of the image in pixels.
/// </summary>
public override int PixelHeight
{
get
{
return PixelHeight;
}
}
}
}
+39
View File
@@ -0,0 +1,39 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Classes derived from this abstract base class define objects used to fill the
/// interiors of paths.
/// </summary>
public abstract class XBrush
{
}
}
File diff suppressed because it is too large Load Diff
+662
View File
@@ -0,0 +1,662 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.Diagnostics;
using System.Globalization;
using System.ComponentModel;
// ReSharper disable RedundantNameQualifier
namespace PdfSharpCore.Drawing
{
///<summary>
/// Represents a RGB, CMYK, or gray scale color.
/// </summary>
[DebuggerDisplay("clr=(A={A}, R={R}, G={G}, B={B} C={C}, M={M}, Y={Y}, K={K})")]
public struct XColor
{
XColor(uint argb)
{
_cs = XColorSpace.Rgb;
_a = (byte)((argb >> 24) & 0xff) / 255f;
_r = (byte)((argb >> 16) & 0xff);
_g = (byte)((argb >> 8) & 0xff);
_b = (byte)(argb & 0xff);
_c = 0;
_m = 0;
_y = 0;
_k = 0;
_gs = 0;
RgbChanged();
//_cs.GetType(); // Suppress warning
}
XColor(byte alpha, byte red, byte green, byte blue)
{
_cs = XColorSpace.Rgb;
_a = alpha / 255f;
_r = red;
_g = green;
_b = blue;
_c = 0;
_m = 0;
_y = 0;
_k = 0;
_gs = 0;
RgbChanged();
//_cs.GetType(); // Suppress warning
}
XColor(double alpha, double cyan, double magenta, double yellow, double black)
{
_cs = XColorSpace.Cmyk;
_a = (float)(alpha > 1 ? 1 : (alpha < 0 ? 0 : alpha));
_c = (float)(cyan > 1 ? 1 : (cyan < 0 ? 0 : cyan));
_m = (float)(magenta > 1 ? 1 : (magenta < 0 ? 0 : magenta));
_y = (float)(yellow > 1 ? 1 : (yellow < 0 ? 0 : yellow));
_k = (float)(black > 1 ? 1 : (black < 0 ? 0 : black));
_r = 0;
_g = 0;
_b = 0;
_gs = 0f;
CmykChanged();
}
XColor(double cyan, double magenta, double yellow, double black)
: this(1.0, cyan, magenta, yellow, black)
{ }
XColor(double gray)
{
_cs = XColorSpace.GrayScale;
if (gray < 0)
_gs = 0;
else if (gray > 1)
_gs = 1;
_gs = (float)gray;
_a = 1;
_r = 0;
_g = 0;
_b = 0;
_c = 0;
_m = 0;
_y = 0;
_k = 0;
GrayChanged();
}
internal XColor(XKnownColor knownColor)
: this(XKnownColorTable.KnownColorToArgb(knownColor))
{ }
/// <summary>
/// Creates an XColor structure from a 32-bit ARGB value.
/// </summary>
public static XColor FromArgb(int argb)
{
return new XColor((byte)(argb >> 24), (byte)(argb >> 16), (byte)(argb >> 8), (byte)(argb));
}
/// <summary>
/// Creates an XColor structure from a 32-bit ARGB value.
/// </summary>
public static XColor FromArgb(uint argb)
{
return new XColor((byte)(argb >> 24), (byte)(argb >> 16), (byte)(argb >> 8), (byte)(argb));
}
// from System.Drawing.Color
//public static XColor FromArgb(int alpha, Color baseColor);
//public static XColor FromArgb(int red, int green, int blue);
//public static XColor FromArgb(int alpha, int red, int green, int blue);
//public static XColor FromKnownColor(KnownColor color);
//public static XColor FromName(string name);
/// <summary>
/// Creates an XColor structure from the specified 8-bit color values (red, green, and blue).
/// The alpha value is implicitly 255 (fully opaque).
/// </summary>
public static XColor FromArgb(int red, int green, int blue)
{
CheckByte(red, "red");
CheckByte(green, "green");
CheckByte(blue, "blue");
return new XColor(255, (byte)red, (byte)green, (byte)blue);
}
/// <summary>
/// Creates an XColor structure from the four ARGB component (alpha, red, green, and blue) values.
/// </summary>
public static XColor FromArgb(int alpha, int red, int green, int blue)
{
CheckByte(alpha, "alpha");
CheckByte(red, "red");
CheckByte(green, "green");
CheckByte(blue, "blue");
return new XColor((byte)alpha, (byte)red, (byte)green, (byte)blue);
}
/// <summary>
/// Creates an XColor structure from the specified alpha value and color.
/// </summary>
public static XColor FromArgb(int alpha, XColor color)
{
color.A = ((byte)alpha) / 255.0;
return color;
}
/// <summary>
/// Creates an XColor structure from the specified CMYK values.
/// </summary>
public static XColor FromCmyk(double cyan, double magenta, double yellow, double black)
{
return new XColor(cyan, magenta, yellow, black);
}
/// <summary>
/// Creates an XColor structure from the specified CMYK values.
/// </summary>
public static XColor FromCmyk(double alpha, double cyan, double magenta, double yellow, double black)
{
return new XColor(alpha, cyan, magenta, yellow, black);
}
/// <summary>
/// Creates an XColor structure from the specified gray value.
/// </summary>
public static XColor FromGrayScale(double grayScale)
{
return new XColor(grayScale);
}
/// <summary>
/// Creates an XColor from the specified pre-defined color.
/// </summary>
public static XColor FromKnownColor(XKnownColor color)
{
return new XColor(color);
}
/// <summary>
/// Creates an XColor from the specified name of a pre-defined color.
/// </summary>
public static XColor FromName(string name)
{
return Empty;
}
/// <summary>
/// Gets or sets the color space to be used for PDF generation.
/// </summary>
public XColorSpace ColorSpace
{
get { return _cs; }
set
{
if (!Enum.IsDefined(typeof(XColorSpace), value))
throw new InvalidEnumArgumentException("value", (int)value, typeof(XColorSpace));
_cs = value;
}
}
/// <summary>
/// Indicates whether this XColor structure is uninitialized.
/// </summary>
public bool IsEmpty
{
get { return this == Empty; }
}
/// <summary>
/// Determines whether the specified object is a Color structure and is equivalent to this
/// Color structure.
/// </summary>
public override bool Equals(object obj)
{
// ReSharper disable CompareOfFloatsByEqualityOperator
if (obj is XColor)
{
XColor color = (XColor)obj;
if (_r == color._r && _g == color._g && _b == color._b &&
_c == color._c && _m == color._m && _y == color._y && _k == color._k &&
_gs == color._gs)
{
return _a == color._a;
}
}
return false;
// ReSharper restore CompareOfFloatsByEqualityOperator
}
/// <summary>
/// Returns the hash code for this instance.
/// </summary>
public override int GetHashCode()
{
// ReSharper disable NonReadonlyFieldInGetHashCode
return ((byte)(_a * 255)) ^ _r ^ _g ^ _b;
// ReSharper restore NonReadonlyFieldInGetHashCode
}
/// <summary>
/// Determines whether two colors are equal.
/// </summary>
public static bool operator ==(XColor left, XColor right)
{
// ReSharper disable CompareOfFloatsByEqualityOperator
if (left._r == right._r && left._g == right._g && left._b == right._b &&
left._c == right._c && left._m == right._m && left._y == right._y && left._k == right._k &&
left._gs == right._gs)
{
return left._a == right._a;
}
return false;
// ReSharper restore CompareOfFloatsByEqualityOperator
}
/// <summary>
/// Determines whether two colors are not equal.
/// </summary>
public static bool operator !=(XColor left, XColor right)
{
return !(left == right);
}
/// <summary>
/// Gets a value indicating whether this color is a known color.
/// </summary>
public bool IsKnownColor
{
get { return XKnownColorTable.IsKnownColor(Argb); }
}
/// <summary>
/// Gets the hue-saturation-brightness (HSB) hue value, in degrees, for this color.
/// </summary>
/// <returns>The hue, in degrees, of this color. The hue is measured in degrees, ranging from 0 through 360, in HSB color space.</returns>
public double GetHue()
{
// ReSharper disable CompareOfFloatsByEqualityOperator
if ((_r == _g) && (_g == _b))
return 0;
double value1 = _r / 255.0;
double value2 = _g / 255.0;
double value3 = _b / 255.0;
double value7 = 0;
double value4 = value1;
double value5 = value1;
if (value2 > value4)
value4 = value2;
if (value3 > value4)
value4 = value3;
if (value2 < value5)
value5 = value2;
if (value3 < value5)
value5 = value3;
double value6 = value4 - value5;
if (value1 == value4)
value7 = (value2 - value3) / value6;
else if (value2 == value4)
value7 = 2f + ((value3 - value1) / value6);
else if (value3 == value4)
value7 = 4f + ((value1 - value2) / value6);
value7 *= 60;
if (value7 < 0)
value7 += 360;
return value7;
// ReSharper restore CompareOfFloatsByEqualityOperator
}
/// <summary>
/// Gets the hue-saturation-brightness (HSB) saturation value for this color.
/// </summary>
/// <returns>The saturation of this color. The saturation ranges from 0 through 1, where 0 is grayscale and 1 is the most saturated.</returns>
public double GetSaturation()
{
// ReSharper disable CompareOfFloatsByEqualityOperator
double value1 = _r / 255.0;
double value2 = _g / 255.0;
double value3 = _b / 255.0;
double value7 = 0;
double value4 = value1;
double value5 = value1;
if (value2 > value4)
value4 = value2;
if (value3 > value4)
value4 = value3;
if (value2 < value5)
value5 = value2;
if (value3 < value5)
value5 = value3;
if (value4 == value5)
return value7;
double value6 = (value4 + value5) / 2;
if (value6 <= 0.5)
return (value4 - value5) / (value4 + value5);
return (value4 - value5) / ((2f - value4) - value5);
// ReSharper restore CompareOfFloatsByEqualityOperator
}
/// <summary>
/// Gets the hue-saturation-brightness (HSB) brightness value for this color.
/// </summary>
/// <returns>The brightness of this color. The brightness ranges from 0 through 1, where 0 represents black and 1 represents white.</returns>
public double GetBrightness()
{
double value1 = _r / 255.0;
double value2 = _g / 255.0;
double value3 = _b / 255.0;
double value4 = value1;
double value5 = value1;
if (value2 > value4)
value4 = value2;
if (value3 > value4)
value4 = value3;
if (value2 < value5)
value5 = value2;
if (value3 < value5)
value5 = value3;
return (value4 + value5) / 2;
}
///<summary>
/// One of the RGB values changed; recalculate other color representations.
/// </summary>
void RgbChanged()
{
// ReSharper disable LocalVariableHidesMember
_cs = XColorSpace.Rgb;
int c = 255 - _r;
int m = 255 - _g;
int y = 255 - _b;
int k = Math.Min(c, Math.Min(m, y));
if (k == 255)
_c = _m = _y = 0;
else
{
float black = 255f - k;
_c = (c - k) / black;
_m = (m - k) / black;
_y = (y - k) / black;
}
_k = _gs = k / 255f;
// ReSharper restore LocalVariableHidesMember
}
///<summary>
/// One of the CMYK values changed; recalculate other color representations.
/// </summary>
void CmykChanged()
{
_cs = XColorSpace.Cmyk;
float black = _k * 255;
float factor = 255f - black;
_r = (byte)(255 - Math.Min(255f, _c * factor + black));
_g = (byte)(255 - Math.Min(255f, _m * factor + black));
_b = (byte)(255 - Math.Min(255f, _y * factor + black));
_gs = (float)(1 - Math.Min(1.0, 0.3f * _c + 0.59f * _m + 0.11 * _y + _k));
}
///<summary>
/// The gray scale value changed; recalculate other color representations.
/// </summary>
void GrayChanged()
{
_cs = XColorSpace.GrayScale;
_r = (byte)(_gs * 255);
_g = (byte)(_gs * 255);
_b = (byte)(_gs * 255);
_c = 0;
_m = 0;
_y = 0;
_k = 1 - _gs;
}
// Properties
/// <summary>
/// Gets or sets the alpha value the specifies the transparency.
/// The value is in the range from 1 (opaque) to 0 (completely transparent).
/// </summary>
public double A
{
get { return _a; }
set
{
if (value < 0)
_a = 0;
else if (value > 1)
_a = 1;
else
_a = (float)value;
}
}
/// <summary>
/// Gets or sets the red value.
/// </summary>
public byte R
{
get { return _r; }
set { _r = value; RgbChanged(); }
}
/// <summary>
/// Gets or sets the green value.
/// </summary>
public byte G
{
get { return _g; }
set { _g = value; RgbChanged(); }
}
/// <summary>
/// Gets or sets the blue value.
/// </summary>
public byte B
{
get { return _b; }
set { _b = value; RgbChanged(); }
}
/// <summary>
/// Gets the RGB part value of the color. Internal helper function.
/// </summary>
internal uint Rgb
{
get { return ((uint)_r << 16) | ((uint)_g << 8) | _b; }
}
/// <summary>
/// Gets the ARGB part value of the color. Internal helper function.
/// </summary>
internal uint Argb
{
get { return ((uint)(_a * 255) << 24) | ((uint)_r << 16) | ((uint)_g << 8) | _b; }
}
/// <summary>
/// Gets or sets the cyan value.
/// </summary>
public double C
{
get { return _c; }
set
{
if (value < 0)
_c = 0;
else if (value > 1)
_c = 1;
else
_c = (float)value;
CmykChanged();
}
}
/// <summary>
/// Gets or sets the magenta value.
/// </summary>
public double M
{
get { return _m; }
set
{
if (value < 0)
_m = 0;
else if (value > 1)
_m = 1;
else
_m = (float)value;
CmykChanged();
}
}
/// <summary>
/// Gets or sets the yellow value.
/// </summary>
public double Y
{
get { return _y; }
set
{
if (value < 0)
_y = 0;
else if (value > 1)
_y = 1;
else
_y = (float)value;
CmykChanged();
}
}
/// <summary>
/// Gets or sets the black (or key) value.
/// </summary>
public double K
{
get { return _k; }
set
{
if (value < 0)
_k = 0;
else if (value > 1)
_k = 1;
else
_k = (float)value;
CmykChanged();
}
}
/// <summary>
/// Gets or sets the gray scale value.
/// </summary>
// ReSharper disable InconsistentNaming
public double GS
// ReSharper restore InconsistentNaming
{
get { return _gs; }
set
{
if (value < 0)
_gs = 0;
else if (value > 1)
_gs = 1;
else
_gs = (float)value;
GrayChanged();
}
}
/// <summary>
/// Represents the null color.
/// </summary>
public static XColor Empty;
///<summary>
/// Special property for XmlSerializer only.
/// </summary>
public string RgbCmykG
{
get
{
return String.Format(CultureInfo.InvariantCulture,
"{0};{1};{2};{3};{4};{5};{6};{7};{8}", _r, _g, _b, _c, _m, _y, _k, _gs, _a);
}
set
{
string[] values = value.Split(';');
_r = byte.Parse(values[0], CultureInfo.InvariantCulture);
_g = byte.Parse(values[1], CultureInfo.InvariantCulture);
_b = byte.Parse(values[2], CultureInfo.InvariantCulture);
_c = float.Parse(values[3], CultureInfo.InvariantCulture);
_m = float.Parse(values[4], CultureInfo.InvariantCulture);
_y = float.Parse(values[5], CultureInfo.InvariantCulture);
_k = float.Parse(values[6], CultureInfo.InvariantCulture);
_gs = float.Parse(values[7], CultureInfo.InvariantCulture);
_a = float.Parse(values[8], CultureInfo.InvariantCulture);
}
}
static void CheckByte(int val, string name)
{
if (val < 0 || val > 0xFF)
throw new ArgumentException(PSSR.InvalidValue(val, name, 0, 255));
}
XColorSpace _cs;
float _a; // alpha
byte _r; // \
byte _g; // |--- RGB
byte _b; // /
float _c; // \
float _m; // |--- CMYK
float _y; // |
float _k; // /
float _gs; // >--- gray scale
}
}
@@ -0,0 +1,351 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.Globalization;
using System.ComponentModel;
using System.Threading;
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Manages the localization of the color class.
/// </summary>
public class XColorResourceManager
{
/// <summary>
/// Initializes a new instance of the <see cref="XColorResourceManager"/> class.
/// </summary>
public XColorResourceManager()
: this(CultureInfo.CurrentUICulture)
{ }
/// <summary>
/// Initializes a new instance of the <see cref="XColorResourceManager"/> class.
/// </summary>
/// <param name="cultureInfo">The culture info.</param>
public XColorResourceManager(CultureInfo cultureInfo)
{
_cultureInfo = cultureInfo;
}
readonly CultureInfo _cultureInfo;
#if DEBUG_
static public void Test()
{
int kcc = XKnownColorTable.colorTable.Length;
for (int idx = 0; idx < kcc; idx++)
{
uint argb = XKnownColorTable.colorTable[idx];
ColorResourceInfo info = GetColorInfo((XKnownColor)idx);
if ((int)info.KnownColor == -1)
{
kcc.GetType();
}
else
{
if (argb != info.Argb)
{
kcc.GetType();
}
}
}
for (int idx = 0; idx < colorInfos.Length; idx++)
{
ColorResourceInfo c2 = colorInfos[idx];
if (c2.Argb != c2.Color.Rgb)
c2.GetType();
}
}
#endif
/// <summary>
/// Gets a known color from an ARGB value. Throws an ArgumentException if the value is not a known color.
/// </summary>
public static XKnownColor GetKnownColor(uint argb)
{
XKnownColor knownColor = XKnownColorTable.GetKnownColor(argb);
if ((int)knownColor == -1)
throw new ArgumentException("The argument is not a known color", "argb");
return knownColor;
}
/// <summary>
/// Gets all known colors.
/// </summary>
/// <param name="includeTransparent">Indicates whether to include the color Transparent.</param>
public static XKnownColor[] GetKnownColors(bool includeTransparent)
{
int count = colorInfos.Length;
XKnownColor[] knownColor = new XKnownColor[count - (includeTransparent ? 0 : 1)];
for (int idxIn = includeTransparent ? 0 : 1, idxOut = 0; idxIn < count; idxIn++, idxOut++)
knownColor[idxOut] = colorInfos[idxIn].KnownColor;
return knownColor;
}
/// <summary>
/// Converts a known color to a localized color name.
/// </summary>
public string ToColorName(XKnownColor knownColor)
{
ColorResourceInfo colorInfo = GetColorInfo(knownColor);
// Currently German only
if (_cultureInfo.TwoLetterISOLanguageName == "de")
return colorInfo.NameDE;
return colorInfo.Name;
}
/// <summary>
/// Converts a color to a localized color name or an ARGB value.
/// </summary>
public string ToColorName(XColor color)
{
string name;
if (color.IsKnownColor)
name = ToColorName(XKnownColorTable.GetKnownColor(color.Argb));
else
name = String.Format("{0}, {1}, {2}, {3}", (int)(255 * color.A), color.R, color.G, color.B);
return name;
}
static ColorResourceInfo GetColorInfo(XKnownColor knownColor)
{
for (int idx = 0; idx < colorInfos.Length; idx++)
{
ColorResourceInfo colorInfo = colorInfos[idx];
if (colorInfo.KnownColor == knownColor)
return colorInfo;
}
throw new InvalidEnumArgumentException("Enum is not an XKnownColor.");
}
// I found no official translation for the 140 pre-defined colors. Some folks made their own translations.
// http://unnecessary.de/wuest/farbtab/farbtabelle-w.html
// http://blog.patrickkempf.de/archives/2004/04/10/html-farben/
// http://www.grafikwunder.de/Grafikecke/Farbtabelle/farbtabelle-006.php
// Silke changed some German translations (women know more colors than men :-)
internal static ColorResourceInfo[] colorInfos = new ColorResourceInfo[]
{
new ColorResourceInfo(XKnownColor.Transparent, XColors.Transparent, 0x00FFFFFF, "Transparent", "Transparent"),
new ColorResourceInfo(XKnownColor.Black, XColors.Black, 0xFF000000, "Black", "Schwarz"),
new ColorResourceInfo(XKnownColor.DarkSlateGray, XColors.DarkSlateGray, 0xFF8FBC8F, "Darkslategray", "Dunkles Schiefergrau"),
new ColorResourceInfo(XKnownColor.SlateGray, XColors.SlateGray, 0xFF708090, "Slategray", "Schiefergrau"),
new ColorResourceInfo(XKnownColor.LightSlateGray, XColors.LightSlateGray, 0xFF778899, "Lightslategray", "Helles Schiefergrau"),
new ColorResourceInfo(XKnownColor.LightSteelBlue, XColors.LightSteelBlue, 0xFFB0C4DE, "Lightsteelblue", "Helles Stahlblau"),
//new ColorResourceInfo(XKnownColor.DimGray, XColors.DimGray, 0xFF696969, "Dimgray", "Mattes Grau"),
new ColorResourceInfo(XKnownColor.DimGray, XColors.DimGray, 0xFF696969, "Dimgray", "Gedecktes Grau"),
new ColorResourceInfo(XKnownColor.Gray, XColors.Gray, 0xFF808080, "Gray", "Grau"),
new ColorResourceInfo(XKnownColor.DarkGray, XColors.DarkGray, 0xFFA9A9A9, "Darkgray", "Dunkelgrau"),
new ColorResourceInfo(XKnownColor.Silver, XColors.Silver, 0xFFC0C0C0, "Silver", "Silber"),
//new ColorResourceInfo(XKnownColor.Gainsboro, XColors.Gainsboro, 0xFFDCDCDC, "Gainsboro", "Gainsboro"),
new ColorResourceInfo(XKnownColor.Gainsboro, XColors.Gainsboro, 0xFFDCDCDC, "Gainsboro", "Helles Blaugrau"),
//new ColorResourceInfo(XKnownColor.WhiteSmoke, XColors.WhiteSmoke, 0xFFF5F5F5, "Whitesmoke", "Rauchiges Weiß"),
new ColorResourceInfo(XKnownColor.WhiteSmoke, XColors.WhiteSmoke, 0xFFF5F5F5, "Whitesmoke", "Rauchweiß"),
//new ColorResourceInfo(XKnownColor.GhostWhite, XColors.GhostWhite, 0xFFF8F8FF, "Ghostwhite", "Geisterweiß"),
new ColorResourceInfo(XKnownColor.GhostWhite, XColors.GhostWhite, 0xFFF8F8FF, "Ghostwhite", "Schattenweiß"),
new ColorResourceInfo(XKnownColor.White, XColors.White, 0xFFFFFFFF, "White", "Weiß"),
new ColorResourceInfo(XKnownColor.Snow, XColors.Snow, 0xFFFFFAFA, "Snow", "Schneeweiß"),
new ColorResourceInfo(XKnownColor.Ivory, XColors.Ivory, 0xFFFFFFF0, "Ivory", "Elfenbein"),
new ColorResourceInfo(XKnownColor.FloralWhite, XColors.FloralWhite, 0xFFFFFAF0, "Floralwhite", "Blütenweiß"),
new ColorResourceInfo(XKnownColor.SeaShell, XColors.SeaShell, 0xFFFFF5EE, "Seashell", "Muschel"),
//new ColorResourceInfo(XKnownColor.OldLace, XColors.OldLace, 0xFFFDF5E6, "Oldlace", "Altgold"),
new ColorResourceInfo(XKnownColor.OldLace, XColors.OldLace, 0xFFFDF5E6, "Oldlace", "Altweiß"),
//new ColorResourceInfo(XKnownColor.Linen, XColors.Linen, 0xFFFAF0E6, "Linen", "Leinenfarbe"),
new ColorResourceInfo(XKnownColor.Linen, XColors.Linen, 0xFFFAF0E6, "Linen", "Leinen"),
new ColorResourceInfo(XKnownColor.AntiqueWhite, XColors.AntiqueWhite, 0xFFFAEBD7, "Antiquewhite", "Antikes Weiß"),
new ColorResourceInfo(XKnownColor.BlanchedAlmond, XColors.BlanchedAlmond, 0xFFFFEBCD, "Blanchedalmond", "Mandelweiß"),
//new ColorResourceInfo(XKnownColor.PapayaWhip, XColors.PapayaWhip, 0xFFFFEFD5, "Papayawhip", "Cremiges Papaya"),
new ColorResourceInfo(XKnownColor.PapayaWhip, XColors.PapayaWhip, 0xFFFFEFD5, "Papayawhip", "Papayacreme"),
new ColorResourceInfo(XKnownColor.Beige, XColors.Beige, 0xFFF5F5DC, "Beige", "Beige"),
new ColorResourceInfo(XKnownColor.Cornsilk, XColors.Cornsilk, 0xFFFFF8DC, "Cornsilk", "Mais"),
//new ColorResourceInfo(XKnownColor.LightGoldenrodYellow, XColors.LightGoldenrodYellow, 0xFFFAFAD2, "Lightgoldenrodyellow", "Helles Goldrutengelb"),
new ColorResourceInfo(XKnownColor.LightGoldenrodYellow, XColors.LightGoldenrodYellow, 0xFFFAFAD2, "Lightgoldenrodyellow", "Helles Goldgelb"),
new ColorResourceInfo(XKnownColor.LightYellow, XColors.LightYellow, 0xFFFFFFE0, "Lightyellow", "Hellgelb"),
new ColorResourceInfo(XKnownColor.LemonChiffon, XColors.LemonChiffon, 0xFFFFFACD, "Lemonchiffon", "Pastellgelb"),
//new ColorResourceInfo(XKnownColor.PaleGoldenrod, XColors.PaleGoldenrod, 0xFFEEE8AA, "Palegoldenrod", "Blasse Goldrutenfarbe"),
new ColorResourceInfo(XKnownColor.PaleGoldenrod, XColors.PaleGoldenrod, 0xFFEEE8AA, "Palegoldenrod", "Blasses Goldgelb"),
new ColorResourceInfo(XKnownColor.Khaki, XColors.Khaki, 0xFFF0E68C, "Khaki", "Khaki"),
new ColorResourceInfo(XKnownColor.Yellow, XColors.Yellow, 0xFFFFFF00, "Yellow", "Gelb"),
new ColorResourceInfo(XKnownColor.Gold, XColors.Gold, 0xFFFFD700, "Gold", "Gold"),
new ColorResourceInfo(XKnownColor.Orange, XColors.Orange, 0xFFFFA500, "Orange", "Orange"),
new ColorResourceInfo(XKnownColor.DarkOrange, XColors.DarkOrange, 0xFFFF8C00, "Darkorange", "Dunkles Orange"),
//new ColorResourceInfo(XKnownColor.Goldenrod, XColors.Goldenrod, 0xFFDAA520, "Goldenrod", "Goldrute"),
new ColorResourceInfo(XKnownColor.Goldenrod, XColors.Goldenrod, 0xFFDAA520, "Goldenrod", "Goldgelb"),
//new ColorResourceInfo(XKnownColor.DarkGoldenrod, XColors.DarkGoldenrod, 0xFFB8860B, "Darkgoldenrod", "Dunkle Goldrutenfarbe"),
new ColorResourceInfo(XKnownColor.DarkGoldenrod, XColors.DarkGoldenrod, 0xFFB8860B, "Darkgoldenrod", "Dunkles Goldgelb"),
new ColorResourceInfo(XKnownColor.Peru, XColors.Peru, 0xFFCD853F, "Peru", "Peru"),
new ColorResourceInfo(XKnownColor.Chocolate, XColors.Chocolate, 0xFFD2691E, "Chocolate", "Schokolade"),
new ColorResourceInfo(XKnownColor.SaddleBrown, XColors.SaddleBrown, 0xFF8B4513, "Saddlebrown", "Sattelbraun"),
new ColorResourceInfo(XKnownColor.Sienna, XColors.Sienna, 0xFFA0522D, "Sienna", "Ocker"),
new ColorResourceInfo(XKnownColor.Brown, XColors.Brown, 0xFFA52A2A, "Brown", "Braun"),
new ColorResourceInfo(XKnownColor.DarkRed, XColors.DarkRed, 0xFF8B0000, "Darkred", "Dunkelrot"),
new ColorResourceInfo(XKnownColor.Maroon, XColors.Maroon, 0xFF800000, "Maroon", "Kastanienbraun"),
new ColorResourceInfo(XKnownColor.PaleTurquoise, XColors.PaleTurquoise, 0xFFAFEEEE, "Paleturquoise", "Blasses Türkis"),
//new ColorResourceInfo(XKnownColor.Firebrick, XColors.Firebrick, 0xFFB22222, "Firebrick", "Ziegelfarbe"),
new ColorResourceInfo(XKnownColor.Firebrick, XColors.Firebrick, 0xFFB22222, "Firebrick", "Ziegel"),
new ColorResourceInfo(XKnownColor.IndianRed, XColors.IndianRed, 0xFFCD5C5C, "Indianred", "Indischrot"),
new ColorResourceInfo(XKnownColor.Crimson, XColors.Crimson, 0xFFDC143C, "Crimson", "Karmesinrot"),
new ColorResourceInfo(XKnownColor.Red, XColors.Red, 0xFFFF0000, "Red", "Rot"),
//new ColorResourceInfo(XKnownColor.OrangeRed, XColors.OrangeRed, 0xFFFF4500, "Orangered", "Orangenrot"),
new ColorResourceInfo(XKnownColor.OrangeRed, XColors.OrangeRed, 0xFFFF4500, "Orangered", "Orangerot"),
//new ColorResourceInfo(XKnownColor.Tomato, XColors.Tomato, 0xFFFF6347, "Tomato", "Tomatenrot"),
new ColorResourceInfo(XKnownColor.Tomato, XColors.Tomato, 0xFFFF6347, "Tomato", "Tomate"),
new ColorResourceInfo(XKnownColor.Coral, XColors.Coral, 0xFFFF7F50, "Coral", "Koralle"),
new ColorResourceInfo(XKnownColor.Salmon, XColors.Salmon, 0xFFFA8072, "Salmon", "Lachs"),
new ColorResourceInfo(XKnownColor.LightCoral, XColors.LightCoral, 0xFFF08080, "Lightcoral", "Helles Korallenrot"),
//new ColorResourceInfo(XKnownColor.DarkSalmon, XColors.DarkSalmon, 0xFFE9967A, "Darksalmon", "Dunkle Lachsfarbe"),
new ColorResourceInfo(XKnownColor.DarkSalmon, XColors.DarkSalmon, 0xFFE9967A, "Darksalmon", "Dunkles Lachs"),
//new ColorResourceInfo(XKnownColor.LightSalmon, XColors.LightSalmon, 0xFFFFA07A, "Lightsalmon", "Helle Lachsfarbe"),
new ColorResourceInfo(XKnownColor.LightSalmon, XColors.LightSalmon, 0xFFFFA07A, "Lightsalmon", "Helles Lachs"),
new ColorResourceInfo(XKnownColor.SandyBrown, XColors.SandyBrown, 0xFFF4A460, "Sandybrown", "Sandbraun"),
//new ColorResourceInfo(XKnownColor.RosyBrown, XColors.RosyBrown, 0xFFBC8F8F, "Rosybrown", "Rosiges Braun"),
new ColorResourceInfo(XKnownColor.RosyBrown, XColors.RosyBrown, 0xFFBC8F8F, "Rosybrown", "Rotbraun"),
new ColorResourceInfo(XKnownColor.Tan, XColors.Tan, 0xFFD2B48C, "Tan", "Gelbbraun"),
//new ColorResourceInfo(XKnownColor.BurlyWood, XColors.BurlyWood, 0xFFDEB887, "Burlywood", "Grobes Braun"),
new ColorResourceInfo(XKnownColor.BurlyWood, XColors.BurlyWood, 0xFFDEB887, "Burlywood", "Kräftiges Sandbraun"),
new ColorResourceInfo(XKnownColor.Wheat, XColors.Wheat, 0xFFF5DEB3, "Wheat", "Weizen"),
new ColorResourceInfo(XKnownColor.PeachPuff, XColors.PeachPuff, 0xFFFFDAB9, "Peachpuff", "Pfirsich"),
//new ColorResourceInfo(XKnownColor.NavajoWhite, XColors.NavajoWhite, 0xFFFFDEAD, "Navajowhite", "Navajoweiß"),
new ColorResourceInfo(XKnownColor.NavajoWhite, XColors.NavajoWhite, 0xFFFFDEAD, "Navajowhite", "Orangeweiß"),
//new ColorResourceInfo(XKnownColor.Bisque, XColors.Bisque, 0xFFFFE4C4, "Bisque", "Tomatencreme"),
new ColorResourceInfo(XKnownColor.Bisque, XColors.Bisque, 0xFFFFE4C4, "Bisque", "Blasses Rotbraun"),
//new ColorResourceInfo(XKnownColor.Moccasin, XColors.Moccasin, 0xFFFFE4B5, "Moccasin", "Moccasin"),
new ColorResourceInfo(XKnownColor.Moccasin, XColors.Moccasin, 0xFFFFE4B5, "Moccasin", "Mokassin"),
//new ColorResourceInfo(XKnownColor.LavenderBlush, XColors.LavenderBlush, 0xFFFFF0F5, "Lavenderblush", "Rosige Lavenderfarbe"),
new ColorResourceInfo(XKnownColor.LavenderBlush, XColors.LavenderBlush, 0xFFFFF0F5, "Lavenderblush", "Roter Lavendel"),
new ColorResourceInfo(XKnownColor.MistyRose, XColors.MistyRose, 0xFFFFE4E1, "Mistyrose", "Altrosa"),
new ColorResourceInfo(XKnownColor.Pink, XColors.Pink, 0xFFFFC0CB, "Pink", "Rosa"),
new ColorResourceInfo(XKnownColor.LightPink, XColors.LightPink, 0xFFFFB6C1, "Lightpink", "Hellrosa"),
new ColorResourceInfo(XKnownColor.HotPink, XColors.HotPink, 0xFFFF69B4, "Hotpink", "Leuchtendes Rosa"),
//// XKnownColor.Fuchsia removed because the same as XKnownColor.Magenta
////new ColorResourceInfo(XKnownColor.Fuchsia, XColors.Fuchsia, 0xFFFF00FF, "Fuchsia", "Fuchsie"),
new ColorResourceInfo(XKnownColor.Magenta, XColors.Magenta, 0xFFFF00FF, "Magenta", "Magentarot"),
new ColorResourceInfo(XKnownColor.DeepPink, XColors.DeepPink, 0xFFFF1493, "Deeppink", "Tiefrosa"),
new ColorResourceInfo(XKnownColor.MediumVioletRed, XColors.MediumVioletRed, 0xFFC71585, "Mediumvioletred", "Mittleres Violettrot"),
new ColorResourceInfo(XKnownColor.PaleVioletRed, XColors.PaleVioletRed, 0xFFDB7093, "Palevioletred", "Blasses Violettrot"),
new ColorResourceInfo(XKnownColor.Plum, XColors.Plum, 0xFFDDA0DD, "Plum", "Pflaume"),
new ColorResourceInfo(XKnownColor.Thistle, XColors.Thistle, 0xFFD8BFD8, "Thistle", "Distel"),
//new ColorResourceInfo(XKnownColor.Lavender, XColors.Lavender, 0xFFE6E6FA, "Lavender", "Lavendelfarbe"),
new ColorResourceInfo(XKnownColor.Lavender, XColors.Lavender, 0xFFE6E6FA, "Lavender", "Lavendel"),
new ColorResourceInfo(XKnownColor.Violet, XColors.Violet, 0xFFEE82EE, "Violet", "Violett"),
new ColorResourceInfo(XKnownColor.Orchid, XColors.Orchid, 0xFFDA70D6, "Orchid", "Orchidee"),
new ColorResourceInfo(XKnownColor.DarkMagenta, XColors.DarkMagenta, 0xFF8B008B, "Darkmagenta", "Dunkles Magentarot"),
new ColorResourceInfo(XKnownColor.Purple, XColors.Purple, 0xFF800080, "Purple", "Violett"),
new ColorResourceInfo(XKnownColor.Indigo, XColors.Indigo, 0xFF4B0082, "Indigo", "Indigo"),
new ColorResourceInfo(XKnownColor.BlueViolet, XColors.BlueViolet, 0xFF8A2BE2, "Blueviolet", "Blauviolett"),
new ColorResourceInfo(XKnownColor.DarkViolet, XColors.DarkViolet, 0xFF9400D3, "Darkviolet", "Dunkles Violett"),
//new ColorResourceInfo(XKnownColor.DarkOrchid, XColors.DarkOrchid, 0xFF9932CC, "Darkorchid", "Dunkle Orchideenfarbe"),
new ColorResourceInfo(XKnownColor.DarkOrchid, XColors.DarkOrchid, 0xFF9932CC, "Darkorchid", "Dunkle Orchidee"),
new ColorResourceInfo(XKnownColor.MediumPurple, XColors.MediumPurple, 0xFF9370DB, "Mediumpurple", "Mittleres Violett"),
//new ColorResourceInfo(XKnownColor.MediumOrchid, XColors.MediumOrchid, 0xFFBA55D3, "Mediumorchid", "Mittlere Orchideenfarbe"),
new ColorResourceInfo(XKnownColor.MediumOrchid, XColors.MediumOrchid, 0xFFBA55D3, "Mediumorchid", "Mittlere Orchidee"),
new ColorResourceInfo(XKnownColor.MediumSlateBlue, XColors.MediumSlateBlue, 0xFF7B68EE, "Mediumslateblue", "Mittleres Schieferblau"),
new ColorResourceInfo(XKnownColor.SlateBlue, XColors.SlateBlue, 0xFF6A5ACD, "Slateblue", "Schieferblau"),
new ColorResourceInfo(XKnownColor.DarkSlateBlue, XColors.DarkSlateBlue, 0xFF483D8B, "Darkslateblue", "Dunkles Schiefergrau"),
new ColorResourceInfo(XKnownColor.MidnightBlue, XColors.MidnightBlue, 0xFF191970, "Midnightblue", "Mitternachtsblau"),
new ColorResourceInfo(XKnownColor.Navy, XColors.Navy, 0xFF000080, "Navy", "Marineblau"),
new ColorResourceInfo(XKnownColor.DarkBlue, XColors.DarkBlue, 0xFF00008B, "Darkblue", "Dunkelblau"),
new ColorResourceInfo(XKnownColor.LightGray, XColors.LightGray, 0xFFD3D3D3, "Lightgray", "Hellgrau"),
new ColorResourceInfo(XKnownColor.MediumBlue, XColors.MediumBlue, 0xFF0000CD, "Mediumblue", "Mittelblau"),
new ColorResourceInfo(XKnownColor.Blue, XColors.Blue, 0xFF0000FF, "Blue", "Blau"),
new ColorResourceInfo(XKnownColor.RoyalBlue, XColors.RoyalBlue, 0xFF4169E1, "Royalblue", "Königsblau"),
new ColorResourceInfo(XKnownColor.SteelBlue, XColors.SteelBlue, 0xFF4682B4, "Steelblue", "Stahlblau"),
new ColorResourceInfo(XKnownColor.CornflowerBlue, XColors.CornflowerBlue, 0xFF6495ED, "Cornflowerblue", "Kornblumenblau"),
new ColorResourceInfo(XKnownColor.DodgerBlue, XColors.DodgerBlue, 0xFF1E90FF, "Dodgerblue", "Dodger-Blau"),
new ColorResourceInfo(XKnownColor.DeepSkyBlue, XColors.DeepSkyBlue, 0xFF00BFFF, "Deepskyblue", "Tiefes Himmelblau"),
new ColorResourceInfo(XKnownColor.LightSkyBlue, XColors.LightSkyBlue, 0xFF87CEFA, "Lightskyblue", "Helles Himmelblau"),
new ColorResourceInfo(XKnownColor.SkyBlue, XColors.SkyBlue, 0xFF87CEEB, "Skyblue", "Himmelblau"),
new ColorResourceInfo(XKnownColor.LightBlue, XColors.LightBlue, 0xFFADD8E6, "Lightblue", "Hellblau"),
//// XKnownColor.Aqua removed because the same as XKnownColor.Cyan
////new ColorResourceInfo(XKnownColor.Aqua, XColors.Aqua, 0xFF00FFFF, "Aqua", "Blaugrün"),
new ColorResourceInfo(XKnownColor.Cyan, XColors.Cyan, 0xFF00FFFF, "Cyan", "Zyan"),
new ColorResourceInfo(XKnownColor.PowderBlue, XColors.PowderBlue, 0xFFB0E0E6, "Powderblue", "Taubenblau"),
new ColorResourceInfo(XKnownColor.LightCyan, XColors.LightCyan, 0xFFE0FFFF, "Lightcyan", "Helles Cyanblau"),
new ColorResourceInfo(XKnownColor.AliceBlue, XColors.AliceBlue, 0xFFA0CE00, "Aliceblue", "Aliceblau"),
new ColorResourceInfo(XKnownColor.Azure, XColors.Azure, 0xFFF0FFFF, "Azure", "Himmelblau"),
//new ColorResourceInfo(XKnownColor.MintCream, XColors.MintCream, 0xFFF5FFFA, "Mintcream", "Cremige Pfefferminzfarbe"),
new ColorResourceInfo(XKnownColor.MintCream, XColors.MintCream, 0xFFF5FFFA, "Mintcream", "Helles Pfefferminzgrün"),
new ColorResourceInfo(XKnownColor.Honeydew, XColors.Honeydew, 0xFFF0FFF0, "Honeydew", "Honigmelone"),
new ColorResourceInfo(XKnownColor.Aquamarine, XColors.Aquamarine, 0xFF7FFFD4, "Aquamarine", "Aquamarinblau"),
new ColorResourceInfo(XKnownColor.Turquoise, XColors.Turquoise, 0xFF40E0D0, "Turquoise", "Türkis"),
new ColorResourceInfo(XKnownColor.MediumTurquoise, XColors.MediumTurquoise, 0xFF48D1CC, "Mediumturqoise", "Mittleres Türkis"),
new ColorResourceInfo(XKnownColor.DarkTurquoise, XColors.DarkTurquoise, 0xFF00CED1, "Darkturquoise", "Dunkles Türkis"),
new ColorResourceInfo(XKnownColor.MediumAquamarine, XColors.MediumAquamarine, 0xFF66CDAA, "Mediumaquamarine", "Mittleres Aquamarinblau"),
new ColorResourceInfo(XKnownColor.LightSeaGreen, XColors.LightSeaGreen, 0xFF20B2AA, "Lightseagreen", "Helles Seegrün"),
new ColorResourceInfo(XKnownColor.DarkCyan, XColors.DarkCyan, 0xFF008B8B, "Darkcyan", "Dunkles Zyanblau"),
//new ColorResourceInfo(XKnownColor.Teal, XColors.Teal, 0xFF008080, "Teal", "Entenbraun"),
new ColorResourceInfo(XKnownColor.Teal, XColors.Teal, 0xFF008080, "Teal", "Entenblau"),
new ColorResourceInfo(XKnownColor.CadetBlue, XColors.CadetBlue, 0xFF5F9EA0, "Cadetblue", "Kadettblau"),
new ColorResourceInfo(XKnownColor.MediumSeaGreen, XColors.MediumSeaGreen, 0xFF3CB371, "Mediumseagreen", "Mittleres Seegrün"),
new ColorResourceInfo(XKnownColor.DarkSeaGreen, XColors.DarkSeaGreen, 0xFF8FBC8F, "Darkseagreen", "Dunkles Seegrün"),
new ColorResourceInfo(XKnownColor.LightGreen, XColors.LightGreen, 0xFF90EE90, "Lightgreen", "Hellgrün"),
new ColorResourceInfo(XKnownColor.PaleGreen, XColors.PaleGreen, 0xFF98FB98, "Palegreen", "Blassgrün"),
new ColorResourceInfo(XKnownColor.MediumSpringGreen, XColors.MediumSpringGreen, 0xFF00FA9A, "Mediumspringgreen", "Mittleres Frühlingsgrün"),
new ColorResourceInfo(XKnownColor.SpringGreen, XColors.SpringGreen, 0xFF00FF7F, "Springgreen", "Frühlingsgrün"),
new ColorResourceInfo(XKnownColor.Lime, XColors.Lime, 0xFF00FF00, "Lime", "Zitronengrün"),
new ColorResourceInfo(XKnownColor.LimeGreen, XColors.LimeGreen, 0xFF32CD32, "Limegreen", "Gelbgrün"),
new ColorResourceInfo(XKnownColor.SeaGreen, XColors.SeaGreen, 0xFF2E8B57, "Seagreen", "Seegrün"),
new ColorResourceInfo(XKnownColor.ForestGreen, XColors.ForestGreen, 0xFF228B22, "Forestgreen", "Waldgrün"),
new ColorResourceInfo(XKnownColor.Green, XColors.Green, 0xFF008000, "Green", "Grün"),
new ColorResourceInfo(XKnownColor.LawnGreen, XColors.LawnGreen, 0xFF008000, "LawnGreen", "Grasgrün"),
new ColorResourceInfo(XKnownColor.DarkGreen, XColors.DarkGreen, 0xFF006400, "Darkgreen", "Dunkelgrün"),
//new ColorResourceInfo(XKnownColor.OliveDrab, XColors.OliveDrab, 0xFF6B8E23, "Olivedrab", "Olivfarbiges Graubraun"),
new ColorResourceInfo(XKnownColor.OliveDrab, XColors.OliveDrab, 0xFF6B8E23, "Olivedrab", "Reife Olive"),
new ColorResourceInfo(XKnownColor.DarkOliveGreen, XColors.DarkOliveGreen, 0xFF556B2F, "Darkolivegreen", "Dunkles Olivgrün"),
new ColorResourceInfo(XKnownColor.Olive, XColors.Olive, 0xFF808000, "Olive", "Olivgrün"),
new ColorResourceInfo(XKnownColor.DarkKhaki, XColors.DarkKhaki, 0xFFBDB76B, "Darkkhaki", "Dunkles Khaki"),
new ColorResourceInfo(XKnownColor.YellowGreen, XColors.YellowGreen, 0xFF9ACD32, "Yellowgreen", "Gelbgrün"),
new ColorResourceInfo(XKnownColor.Chartreuse, XColors.Chartreuse, 0xFF7FFF00, "Chartreuse", "Hellgrün"),
new ColorResourceInfo(XKnownColor.GreenYellow, XColors.GreenYellow, 0xFFADFF2F, "Greenyellow", "Grüngelb"),
};
internal struct ColorResourceInfo
{
public ColorResourceInfo(XKnownColor knownColor, XColor color, uint argb, string name, string nameDE)
{
KnownColor = knownColor;
Color = color;
Argb = argb;
Name = name;
NameDE = nameDE;
}
public XKnownColor KnownColor;
public XColor Color;
public uint Argb;
public string Name;
// ReSharper disable once InconsistentNaming
public string NameDE;
}
}
}
+461
View File
@@ -0,0 +1,461 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
namespace PdfSharpCore.Drawing
{
///<summary>
/// Represents a set of 141 pre-defined RGB colors. Incidentally the values are the same
/// as in System.Drawing.Color.
/// </summary>
public static class XColors
{
///<summary>Gets a predefined color.</summary>
public static XColor AliceBlue { get { return new XColor(XKnownColor.AliceBlue); } }
///<summary>Gets a predefined color.</summary>
public static XColor AntiqueWhite { get { return new XColor(XKnownColor.AntiqueWhite); } }
///<summary>Gets a predefined color.</summary>
public static XColor Aqua { get { return new XColor(XKnownColor.Aqua); } }
///<summary>Gets a predefined color.</summary>
public static XColor Aquamarine { get { return new XColor(XKnownColor.Aquamarine); } }
///<summary>Gets a predefined color.</summary>
public static XColor Azure { get { return new XColor(XKnownColor.Azure); } }
///<summary>Gets a predefined color.</summary>
public static XColor Beige { get { return new XColor(XKnownColor.Beige); } }
///<summary>Gets a predefined color.</summary>
public static XColor Bisque { get { return new XColor(XKnownColor.Bisque); } }
///<summary>Gets a predefined color.</summary>
public static XColor Black { get { return new XColor(XKnownColor.Black); } }
///<summary>Gets a predefined color.</summary>
public static XColor BlanchedAlmond { get { return new XColor(XKnownColor.BlanchedAlmond); } }
///<summary>Gets a predefined color.</summary>
public static XColor Blue { get { return new XColor(XKnownColor.Blue); } }
///<summary>Gets a predefined color.</summary>
public static XColor BlueViolet { get { return new XColor(XKnownColor.BlueViolet); } }
///<summary>Gets a predefined color.</summary>
public static XColor Brown { get { return new XColor(XKnownColor.Brown); } }
///<summary>Gets a predefined color.</summary>
public static XColor BurlyWood { get { return new XColor(XKnownColor.BurlyWood); } }
///<summary>Gets a predefined color.</summary>
public static XColor CadetBlue { get { return new XColor(XKnownColor.CadetBlue); } }
///<summary>Gets a predefined color.</summary>
public static XColor Chartreuse { get { return new XColor(XKnownColor.Chartreuse); } }
///<summary>Gets a predefined color.</summary>
public static XColor Chocolate { get { return new XColor(XKnownColor.Chocolate); } }
///<summary>Gets a predefined color.</summary>
public static XColor Coral { get { return new XColor(XKnownColor.Coral); } }
///<summary>Gets a predefined color.</summary>
public static XColor CornflowerBlue { get { return new XColor(XKnownColor.CornflowerBlue); } }
///<summary>Gets a predefined color.</summary>
public static XColor Cornsilk { get { return new XColor(XKnownColor.Cornsilk); } }
///<summary>Gets a predefined color.</summary>
public static XColor Crimson { get { return new XColor(XKnownColor.Crimson); } }
///<summary>Gets a predefined color.</summary>
public static XColor Cyan { get { return new XColor(XKnownColor.Cyan); } }
///<summary>Gets a predefined color.</summary>
public static XColor DarkBlue { get { return new XColor(XKnownColor.DarkBlue); } }
///<summary>Gets a predefined color.</summary>
public static XColor DarkCyan { get { return new XColor(XKnownColor.DarkCyan); } }
///<summary>Gets a predefined color.</summary>
public static XColor DarkGoldenrod { get { return new XColor(XKnownColor.DarkGoldenrod); } }
///<summary>Gets a predefined color.</summary>
public static XColor DarkGray { get { return new XColor(XKnownColor.DarkGray); } }
///<summary>Gets a predefined color.</summary>
public static XColor DarkGreen { get { return new XColor(XKnownColor.DarkGreen); } }
///<summary>Gets a predefined color.</summary>
public static XColor DarkKhaki { get { return new XColor(XKnownColor.DarkKhaki); } }
///<summary>Gets a predefined color.</summary>
public static XColor DarkMagenta { get { return new XColor(XKnownColor.DarkMagenta); } }
///<summary>Gets a predefined color.</summary>
public static XColor DarkOliveGreen { get { return new XColor(XKnownColor.DarkOliveGreen); } }
///<summary>Gets a predefined color.</summary>
public static XColor DarkOrange { get { return new XColor(XKnownColor.DarkOrange); } }
///<summary>Gets a predefined color.</summary>
public static XColor DarkOrchid { get { return new XColor(XKnownColor.DarkOrchid); } }
///<summary>Gets a predefined color.</summary>
public static XColor DarkRed { get { return new XColor(XKnownColor.DarkRed); } }
///<summary>Gets a predefined color.</summary>
public static XColor DarkSalmon { get { return new XColor(XKnownColor.DarkSalmon); } }
///<summary>Gets a predefined color.</summary>
public static XColor DarkSeaGreen { get { return new XColor(XKnownColor.DarkSeaGreen); } }
///<summary>Gets a predefined color.</summary>
public static XColor DarkSlateBlue { get { return new XColor(XKnownColor.DarkSlateBlue); } }
///<summary>Gets a predefined color.</summary>
public static XColor DarkSlateGray { get { return new XColor(XKnownColor.DarkSlateGray); } }
///<summary>Gets a predefined color.</summary>
public static XColor DarkTurquoise { get { return new XColor(XKnownColor.DarkTurquoise); } }
///<summary>Gets a predefined color.</summary>
public static XColor DarkViolet { get { return new XColor(XKnownColor.DarkViolet); } }
///<summary>Gets a predefined color.</summary>
public static XColor DeepPink { get { return new XColor(XKnownColor.DeepPink); } }
///<summary>Gets a predefined color.</summary>
public static XColor DeepSkyBlue { get { return new XColor(XKnownColor.DeepSkyBlue); } }
///<summary>Gets a predefined color.</summary>
public static XColor DimGray { get { return new XColor(XKnownColor.DimGray); } }
///<summary>Gets a predefined color.</summary>
public static XColor DodgerBlue { get { return new XColor(XKnownColor.DodgerBlue); } }
///<summary>Gets a predefined color.</summary>
public static XColor Firebrick { get { return new XColor(XKnownColor.Firebrick); } }
///<summary>Gets a predefined color.</summary>
public static XColor FloralWhite { get { return new XColor(XKnownColor.FloralWhite); } }
///<summary>Gets a predefined color.</summary>
public static XColor ForestGreen { get { return new XColor(XKnownColor.ForestGreen); } }
///<summary>Gets a predefined color.</summary>
public static XColor Fuchsia { get { return new XColor(XKnownColor.Fuchsia); } }
///<summary>Gets a predefined color.</summary>
public static XColor Gainsboro { get { return new XColor(XKnownColor.Gainsboro); } }
///<summary>Gets a predefined color.</summary>
public static XColor GhostWhite { get { return new XColor(XKnownColor.GhostWhite); } }
///<summary>Gets a predefined color.</summary>
public static XColor Gold { get { return new XColor(XKnownColor.Gold); } }
///<summary>Gets a predefined color.</summary>
public static XColor Goldenrod { get { return new XColor(XKnownColor.Goldenrod); } }
///<summary>Gets a predefined color.</summary>
public static XColor Gray { get { return new XColor(XKnownColor.Gray); } }
///<summary>Gets a predefined color.</summary>
public static XColor Green { get { return new XColor(XKnownColor.Green); } }
///<summary>Gets a predefined color.</summary>
public static XColor GreenYellow { get { return new XColor(XKnownColor.GreenYellow); } }
///<summary>Gets a predefined color.</summary>
public static XColor Honeydew { get { return new XColor(XKnownColor.Honeydew); } }
///<summary>Gets a predefined color.</summary>
public static XColor HotPink { get { return new XColor(XKnownColor.HotPink); } }
///<summary>Gets a predefined color.</summary>
public static XColor IndianRed { get { return new XColor(XKnownColor.IndianRed); } }
///<summary>Gets a predefined color.</summary>
public static XColor Indigo { get { return new XColor(XKnownColor.Indigo); } }
///<summary>Gets a predefined color.</summary>
public static XColor Ivory { get { return new XColor(XKnownColor.Ivory); } }
///<summary>Gets a predefined color.</summary>
public static XColor Khaki { get { return new XColor(XKnownColor.Khaki); } }
///<summary>Gets a predefined color.</summary>
public static XColor Lavender { get { return new XColor(XKnownColor.Lavender); } }
///<summary>Gets a predefined color.</summary>
public static XColor LavenderBlush { get { return new XColor(XKnownColor.LavenderBlush); } }
///<summary>Gets a predefined color.</summary>
public static XColor LawnGreen { get { return new XColor(XKnownColor.LawnGreen); } }
///<summary>Gets a predefined color.</summary>
public static XColor LemonChiffon { get { return new XColor(XKnownColor.LemonChiffon); } }
///<summary>Gets a predefined color.</summary>
public static XColor LightBlue { get { return new XColor(XKnownColor.LightBlue); } }
///<summary>Gets a predefined color.</summary>
public static XColor LightCoral { get { return new XColor(XKnownColor.LightCoral); } }
///<summary>Gets a predefined color.</summary>
public static XColor LightCyan { get { return new XColor(XKnownColor.LightCyan); } }
///<summary>Gets a predefined color.</summary>
public static XColor LightGoldenrodYellow { get { return new XColor(XKnownColor.LightGoldenrodYellow); } }
///<summary>Gets a predefined color.</summary>
public static XColor LightGray { get { return new XColor(XKnownColor.LightGray); } }
///<summary>Gets a predefined color.</summary>
public static XColor LightGreen { get { return new XColor(XKnownColor.LightGreen); } }
///<summary>Gets a predefined color.</summary>
public static XColor LightPink { get { return new XColor(XKnownColor.LightPink); } }
///<summary>Gets a predefined color.</summary>
public static XColor LightSalmon { get { return new XColor(XKnownColor.LightSalmon); } }
///<summary>Gets a predefined color.</summary>
public static XColor LightSeaGreen { get { return new XColor(XKnownColor.LightSeaGreen); } }
///<summary>Gets a predefined color.</summary>
public static XColor LightSkyBlue { get { return new XColor(XKnownColor.LightSkyBlue); } }
///<summary>Gets a predefined color.</summary>
public static XColor LightSlateGray { get { return new XColor(XKnownColor.LightSlateGray); } }
///<summary>Gets a predefined color.</summary>
public static XColor LightSteelBlue { get { return new XColor(XKnownColor.LightSteelBlue); } }
///<summary>Gets a predefined color.</summary>
public static XColor LightYellow { get { return new XColor(XKnownColor.LightYellow); } }
///<summary>Gets a predefined color.</summary>
public static XColor Lime { get { return new XColor(XKnownColor.Lime); } }
///<summary>Gets a predefined color.</summary>
public static XColor LimeGreen { get { return new XColor(XKnownColor.LimeGreen); } }
///<summary>Gets a predefined color.</summary>
public static XColor Linen { get { return new XColor(XKnownColor.Linen); } }
///<summary>Gets a predefined color.</summary>
public static XColor Magenta { get { return new XColor(XKnownColor.Magenta); } }
///<summary>Gets a predefined color.</summary>
public static XColor Maroon { get { return new XColor(XKnownColor.Maroon); } }
///<summary>Gets a predefined color.</summary>
public static XColor MediumAquamarine { get { return new XColor(XKnownColor.MediumAquamarine); } }
///<summary>Gets a predefined color.</summary>
public static XColor MediumBlue { get { return new XColor(XKnownColor.MediumBlue); } }
///<summary>Gets a predefined color.</summary>
public static XColor MediumOrchid { get { return new XColor(XKnownColor.MediumOrchid); } }
///<summary>Gets a predefined color.</summary>
public static XColor MediumPurple { get { return new XColor(XKnownColor.MediumPurple); } }
///<summary>Gets a predefined color.</summary>
public static XColor MediumSeaGreen { get { return new XColor(XKnownColor.MediumSeaGreen); } }
///<summary>Gets a predefined color.</summary>
public static XColor MediumSlateBlue { get { return new XColor(XKnownColor.MediumSlateBlue); } }
///<summary>Gets a predefined color.</summary>
public static XColor MediumSpringGreen { get { return new XColor(XKnownColor.MediumSpringGreen); } }
///<summary>Gets a predefined color.</summary>
public static XColor MediumTurquoise { get { return new XColor(XKnownColor.MediumTurquoise); } }
///<summary>Gets a predefined color.</summary>
public static XColor MediumVioletRed { get { return new XColor(XKnownColor.MediumVioletRed); } }
///<summary>Gets a predefined color.</summary>
public static XColor MidnightBlue { get { return new XColor(XKnownColor.MidnightBlue); } }
///<summary>Gets a predefined color.</summary>
public static XColor MintCream { get { return new XColor(XKnownColor.MintCream); } }
///<summary>Gets a predefined color.</summary>
public static XColor MistyRose { get { return new XColor(XKnownColor.MistyRose); } }
///<summary>Gets a predefined color.</summary>
public static XColor Moccasin { get { return new XColor(XKnownColor.Moccasin); } }
///<summary>Gets a predefined color.</summary>
public static XColor NavajoWhite { get { return new XColor(XKnownColor.NavajoWhite); } }
///<summary>Gets a predefined color.</summary>
public static XColor Navy { get { return new XColor(XKnownColor.Navy); } }
///<summary>Gets a predefined color.</summary>
public static XColor OldLace { get { return new XColor(XKnownColor.OldLace); } }
///<summary>Gets a predefined color.</summary>
public static XColor Olive { get { return new XColor(XKnownColor.Olive); } }
///<summary>Gets a predefined color.</summary>
public static XColor OliveDrab { get { return new XColor(XKnownColor.OliveDrab); } }
///<summary>Gets a predefined color.</summary>
public static XColor Orange { get { return new XColor(XKnownColor.Orange); } }
///<summary>Gets a predefined color.</summary>
public static XColor OrangeRed { get { return new XColor(XKnownColor.OrangeRed); } }
///<summary>Gets a predefined color.</summary>
public static XColor Orchid { get { return new XColor(XKnownColor.Orchid); } }
///<summary>Gets a predefined color.</summary>
public static XColor PaleGoldenrod { get { return new XColor(XKnownColor.PaleGoldenrod); } }
///<summary>Gets a predefined color.</summary>
public static XColor PaleGreen { get { return new XColor(XKnownColor.PaleGreen); } }
///<summary>Gets a predefined color.</summary>
public static XColor PaleTurquoise { get { return new XColor(XKnownColor.PaleTurquoise); } }
///<summary>Gets a predefined color.</summary>
public static XColor PaleVioletRed { get { return new XColor(XKnownColor.PaleVioletRed); } }
///<summary>Gets a predefined color.</summary>
public static XColor PapayaWhip { get { return new XColor(XKnownColor.PapayaWhip); } }
///<summary>Gets a predefined color.</summary>
public static XColor PeachPuff { get { return new XColor(XKnownColor.PeachPuff); } }
///<summary>Gets a predefined color.</summary>
public static XColor Peru { get { return new XColor(XKnownColor.Peru); } }
///<summary>Gets a predefined color.</summary>
public static XColor Pink { get { return new XColor(XKnownColor.Pink); } }
///<summary>Gets a predefined color.</summary>
public static XColor Plum { get { return new XColor(XKnownColor.Plum); } }
///<summary>Gets a predefined color.</summary>
public static XColor PowderBlue { get { return new XColor(XKnownColor.PowderBlue); } }
///<summary>Gets a predefined color.</summary>
public static XColor Purple { get { return new XColor(XKnownColor.Purple); } }
///<summary>Gets a predefined color.</summary>
public static XColor Red { get { return new XColor(XKnownColor.Red); } }
///<summary>Gets a predefined color.</summary>
public static XColor RosyBrown { get { return new XColor(XKnownColor.RosyBrown); } }
///<summary>Gets a predefined color.</summary>
public static XColor RoyalBlue { get { return new XColor(XKnownColor.RoyalBlue); } }
///<summary>Gets a predefined color.</summary>
public static XColor SaddleBrown { get { return new XColor(XKnownColor.SaddleBrown); } }
///<summary>Gets a predefined color.</summary>
public static XColor Salmon { get { return new XColor(XKnownColor.Salmon); } }
///<summary>Gets a predefined color.</summary>
public static XColor SandyBrown { get { return new XColor(XKnownColor.SandyBrown); } }
///<summary>Gets a predefined color.</summary>
public static XColor SeaGreen { get { return new XColor(XKnownColor.SeaGreen); } }
///<summary>Gets a predefined color.</summary>
public static XColor SeaShell { get { return new XColor(XKnownColor.SeaShell); } }
///<summary>Gets a predefined color.</summary>
public static XColor Sienna { get { return new XColor(XKnownColor.Sienna); } }
///<summary>Gets a predefined color.</summary>
public static XColor Silver { get { return new XColor(XKnownColor.Silver); } }
///<summary>Gets a predefined color.</summary>
public static XColor SkyBlue { get { return new XColor(XKnownColor.SkyBlue); } }
///<summary>Gets a predefined color.</summary>
public static XColor SlateBlue { get { return new XColor(XKnownColor.SlateBlue); } }
///<summary>Gets a predefined color.</summary>
public static XColor SlateGray { get { return new XColor(XKnownColor.SlateGray); } }
///<summary>Gets a predefined color.</summary>
public static XColor Snow { get { return new XColor(XKnownColor.Snow); } }
///<summary>Gets a predefined color.</summary>
public static XColor SpringGreen { get { return new XColor(XKnownColor.SpringGreen); } }
///<summary>Gets a predefined color.</summary>
public static XColor SteelBlue { get { return new XColor(XKnownColor.SteelBlue); } }
///<summary>Gets a predefined color.</summary>
public static XColor Tan { get { return new XColor(XKnownColor.Tan); } }
///<summary>Gets a predefined color.</summary>
public static XColor Teal { get { return new XColor(XKnownColor.Teal); } }
///<summary>Gets a predefined color.</summary>
public static XColor Thistle { get { return new XColor(XKnownColor.Thistle); } }
///<summary>Gets a predefined color.</summary>
public static XColor Tomato { get { return new XColor(XKnownColor.Tomato); } }
///<summary>Gets a predefined color.</summary>
public static XColor Transparent { get { return new XColor(XKnownColor.Transparent); } }
///<summary>Gets a predefined color.</summary>
public static XColor Turquoise { get { return new XColor(XKnownColor.Turquoise); } }
///<summary>Gets a predefined color.</summary>
public static XColor Violet { get { return new XColor(XKnownColor.Violet); } }
///<summary>Gets a predefined color.</summary>
public static XColor Wheat { get { return new XColor(XKnownColor.Wheat); } }
///<summary>Gets a predefined color.</summary>
public static XColor White { get { return new XColor(XKnownColor.White); } }
///<summary>Gets a predefined color.</summary>
public static XColor WhiteSmoke { get { return new XColor(XKnownColor.WhiteSmoke); } }
///<summary>Gets a predefined color.</summary>
public static XColor Yellow { get { return new XColor(XKnownColor.Yellow); } }
///<summary>Gets a predefined color.</summary>
public static XColor YellowGreen { get { return new XColor(XKnownColor.YellowGreen); } }
}
}
+38
View File
@@ -0,0 +1,38 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Converts XGraphics enums to GDI+ enums.
/// </summary>
internal static class XConvert
{
}
}
+387
View File
@@ -0,0 +1,387 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
// #??? Clean up
using System;
using System.Diagnostics;
using System.Globalization;
using System.ComponentModel;
using PdfSharpCore.Fonts;
using PdfSharpCore.Fonts.OpenType;
using PdfSharpCore.Pdf;
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Defines an object used to draw text.
/// </summary>
[DebuggerDisplay("{DebuggerDisplay}")]
public sealed class XFont
{
/// <summary>
/// Initializes a new instance of the <see cref="XFont"/> class.
/// </summary>
/// <param name="familyName">Name of the font family.</param>
/// <param name="emSize">The em size.</param>
public XFont(string familyName, double emSize)
: this(familyName, emSize, XFontStyle.Regular, new XPdfFontOptions(GlobalFontSettings.DefaultFontEncoding))
{ }
/// <summary>
/// Initializes a new instance of the <see cref="XFont"/> class.
/// </summary>
/// <param name="familyName">Name of the font family.</param>
/// <param name="emSize">The em size.</param>
/// <param name="style">The font style.</param>
public XFont(string familyName, double emSize, XFontStyle style)
: this(familyName, emSize, style, new XPdfFontOptions(GlobalFontSettings.DefaultFontEncoding))
{ }
/// <summary>
/// Initializes a new instance of the <see cref="XFont"/> class.
/// </summary>
/// <param name="familyName">Name of the font family.</param>
/// <param name="emSize">The em size.</param>
/// <param name="style">The font style.</param>
/// <param name="pdfOptions">Additional PDF options.</param>
public XFont(string familyName, double emSize, XFontStyle style, XPdfFontOptions pdfOptions)
{
_familyName = familyName;
_emSize = emSize;
_style = style;
_pdfOptions = pdfOptions;
Initialize();
}
internal XFont(string familyName, double emSize, XFontStyle style, XPdfFontOptions pdfOptions, XStyleSimulations styleSimulations)
{
_familyName = familyName;
_emSize = emSize;
_style = style;
_pdfOptions = pdfOptions;
OverrideStyleSimulations = true;
StyleSimulations = styleSimulations;
Initialize();
}
/// <summary>
/// Initializes this instance by computing the glyph typeface, font family, font source and TrueType fontface.
/// (PDFsharp currently only deals with TrueType fonts.)
/// </summary>
void Initialize()
{
#if DEBUG
if (_familyName == "Segoe UI Semilight" && (_style & XFontStyle.BoldItalic) == XFontStyle.Italic)
GetType();
#endif
FontResolvingOptions fontResolvingOptions = OverrideStyleSimulations
? new FontResolvingOptions(_style, StyleSimulations)
: new FontResolvingOptions(_style);
// HACK: 'PlatformDefault' is used in unit test code.
if (StringComparer.OrdinalIgnoreCase.Compare(_familyName, GlobalFontSettings.DefaultFontName) == 0)
{
}
// In principle an XFont is an XGlyphTypeface plus an em-size.
_glyphTypeface = XGlyphTypeface.GetOrCreateFrom(_familyName, fontResolvingOptions);
CreateDescriptorAndInitializeFontMetrics();
}
/// <summary>
/// Code separated from Metric getter to make code easier to debug.
/// (Setup properties in their getters caused side effects during debugging because Visual Studio calls a getter
/// to early to show its value in a debugger window.)
/// </summary>
void CreateDescriptorAndInitializeFontMetrics() // TODO: refactor
{
Debug.Assert(_fontMetrics == null, "InitializeFontMetrics() was already called.");
_descriptor = (OpenTypeDescriptor)FontDescriptorCache.GetOrCreateDescriptorFor(this); //_familyName, _style, _glyphTypeface.Fontface);
_fontMetrics = new XFontMetrics(_descriptor.FontName, _descriptor.UnitsPerEm, _descriptor.Ascender, _descriptor.Descender,
_descriptor.Leading, _descriptor.LineSpacing, _descriptor.CapHeight, _descriptor.XHeight, _descriptor.StemV, 0, 0, 0,
_descriptor.UnderlinePosition, _descriptor.UnderlineThickness, _descriptor.StrikeoutPosition, _descriptor.StrikeoutSize);
XFontMetrics fm = Metrics;
// Already done in CreateDescriptorAndInitializeFontMetrics.
//if (_descriptor == null)
// _descriptor = (OpenTypeDescriptor)FontDescriptorStock.Global.CreateDescriptor(this); //(Name, (XGdiFontStyle)Font.Style);
UnitsPerEm = _descriptor.UnitsPerEm;
CellAscent = _descriptor.Ascender;
CellDescent = _descriptor.Descender;
CellSpace = _descriptor.LineSpacing;
Debug.Assert(fm.UnitsPerEm == _descriptor.UnitsPerEm);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Gets the XFontFamily object associated with this XFont object.
/// </summary>
[Browsable(false)]
public XFontFamily FontFamily
{
get { return _glyphTypeface.FontFamily; }
}
/// <summary>
/// WRONG: Gets the face name of this Font object.
/// Indeed it returns the font family name.
/// </summary>
// [Obsolete("This function returns the font family name, not the face name. Use xxx.FontFamily.Name or xxx.FaceName")]
public string Name
{
get { return _glyphTypeface.FontFamily.Name; }
}
internal string FaceName
{
get { return _glyphTypeface.FaceName; }
}
/// <summary>
/// Gets the em-size of this font measured in the unit of this font object.
/// </summary>
public double Size
{
get { return _emSize; }
}
readonly double _emSize;
/// <summary>
/// Gets style information for this Font object.
/// </summary>
[Browsable(false)]
public XFontStyle Style
{
get { return _style; }
}
readonly XFontStyle _style;
/// <summary>
/// Indicates whether this XFont object is bold.
/// </summary>
public bool Bold
{
get { return (_style & XFontStyle.Bold) == XFontStyle.Bold; }
}
/// <summary>
/// Indicates whether this XFont object is italic.
/// </summary>
public bool Italic
{
get { return (_style & XFontStyle.Italic) == XFontStyle.Italic; }
}
/// <summary>
/// Indicates whether this XFont object is stroke out.
/// </summary>
public bool Strikeout
{
get { return (_style & XFontStyle.Strikeout) == XFontStyle.Strikeout; }
}
/// <summary>
/// Indicates whether this XFont object is underlined.
/// </summary>
public bool Underline
{
get { return (_style & XFontStyle.Underline) == XFontStyle.Underline; }
}
/// <summary>
/// Temporary HACK for XPS to PDF converter.
/// </summary>
internal bool IsVertical
{
get { return _isVertical; }
set { _isVertical = value; }
}
bool _isVertical;
/// <summary>
/// Gets the PDF options of the font.
/// </summary>
public XPdfFontOptions PdfOptions
{
get { return _pdfOptions ?? (_pdfOptions = new XPdfFontOptions()); }
}
XPdfFontOptions _pdfOptions;
/// <summary>
/// Indicates whether this XFont is encoded as Unicode.
/// </summary>
internal bool Unicode
{
get { return _pdfOptions != null && _pdfOptions.FontEncoding == PdfFontEncoding.Unicode; }
}
/// <summary>
/// Gets the cell space for the font. The CellSpace is the line spacing, the sum of CellAscent and CellDescent and optionally some extra space.
/// </summary>
public int CellSpace
{
get { return _cellSpace; }
internal set { _cellSpace = value; }
}
int _cellSpace;
/// <summary>
/// Gets the cell ascent, the area above the base line that is used by the font.
/// </summary>
public int CellAscent
{
get { return _cellAscent; }
internal set { _cellAscent = value; }
}
int _cellAscent;
/// <summary>
/// Gets the cell descent, the area below the base line that is used by the font.
/// </summary>
public int CellDescent
{
get { return _cellDescent; }
internal set { _cellDescent = value; }
}
int _cellDescent;
/// <summary>
/// Gets the font metrics.
/// </summary>
/// <value>The metrics.</value>
public XFontMetrics Metrics
{
get
{
// Code moved to InitializeFontMetrics().
//if (_fontMetrics == null)
//{
// FontDescriptor descriptor = FontDescriptorStock.Global.CreateDescriptor(this);
// _fontMetrics = new XFontMetrics(descriptor.FontName, descriptor.UnitsPerEm, descriptor.Ascender, descriptor.Descender,
// descriptor.Leading, descriptor.LineSpacing, descriptor.CapHeight, descriptor.XHeight, descriptor.StemV, 0, 0, 0);
//}
Debug.Assert(_fontMetrics != null, "InitializeFontMetrics() not yet called.");
return _fontMetrics;
}
}
XFontMetrics _fontMetrics;
/// <summary>
/// Returns the line spacing, in pixels, of this font. The line spacing is the vertical distance
/// between the base lines of two consecutive lines of text. Thus, the line spacing includes the
/// blank space between lines along with the height of the character itself.
/// </summary>
public double GetHeight()
{
double value = CellSpace * _emSize / UnitsPerEm;
return value;
}
/// <summary>
/// Gets the line spacing of this font.
/// </summary>
[Browsable(false)]
public int Height
{
// Implementation from System.Drawing.Font.cs
get { return (int)Math.Ceiling(GetHeight()); }
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
internal XGlyphTypeface GlyphTypeface
{
get { return _glyphTypeface; }
}
XGlyphTypeface _glyphTypeface;
internal OpenTypeDescriptor Descriptor
{
get { return _descriptor; }
private set { _descriptor = value; }
}
OpenTypeDescriptor _descriptor;
internal string FamilyName
{
get { return _familyName; }
}
string _familyName;
internal int UnitsPerEm
{
get { return _unitsPerEm; }
private set { _unitsPerEm = value; }
}
internal int _unitsPerEm;
/// <summary>
/// Override style simulations by using the value of StyleSimulations.
/// </summary>
internal bool OverrideStyleSimulations;
/// <summary>
/// Used to enforce style simulations by renderer. For development purposes only.
/// </summary>
internal XStyleSimulations StyleSimulations;
/// <summary>
/// Cache PdfFontTable.FontSelector to speed up finding the right PdfFont
/// if this font is used more than once.
/// </summary>
internal string Selector
{
get { return _selector; }
set { _selector = value; }
}
string _selector;
/// <summary>
/// Gets the DebuggerDisplayAttribute text.
/// </summary>
// ReSharper disable UnusedMember.Local
string DebuggerDisplay
// ReSharper restore UnusedMember.Local
{
get { return String.Format(CultureInfo.InvariantCulture, "font=('{0}' {1:0.##})", Name, Size); }
}
}
}
+178
View File
@@ -0,0 +1,178 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
using System;
using PdfSharpCore.Fonts;
using PdfSharpCore.Fonts.OpenType;
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Defines a group of typefaces having a similar basic design and certain variations in styles.
/// </summary>
public sealed class XFontFamily
{
/// <summary>
/// Initializes a new instance of the <see cref="XFontFamily"/> class.
/// </summary>
/// <param name="familyName">The family name of a font.</param>
public XFontFamily(string familyName)
{
FamilyInternal = FontFamilyInternal.GetOrCreateFromName(familyName, true);
}
internal XFontFamily(string familyName, bool createPlatformObjects)
{
FamilyInternal = FontFamilyInternal.GetOrCreateFromName(familyName, createPlatformObjects);
}
/// <summary>
/// Initializes a new instance of the <see cref="XFontFamily"/> class from FontFamilyInternal.
/// </summary>
XFontFamily(FontFamilyInternal fontFamilyInternal)
{
FamilyInternal = fontFamilyInternal;
}
internal static XFontFamily CreateFromName_not_used(string name, bool createPlatformFamily)
{
XFontFamily fontFamily = new XFontFamily(name);
return fontFamily;
}
/// <summary>
/// An XGlyphTypeface for a font souce that comes from a custom font resolver
/// creates a solitary font family exclusively for it.
/// </summary>
internal static XFontFamily CreateSolitary(string name)
{
// Custom font resolver face names must not clash with platform family names.
FontFamilyInternal fontFamilyInternal = FontFamilyCache.GetFamilyByName(name);
if (fontFamilyInternal == null)
{
fontFamilyInternal = FontFamilyInternal.GetOrCreateFromName(name, false);
fontFamilyInternal = FontFamilyCache.CacheOrGetFontFamily(fontFamilyInternal);
}
// Create font family and save it in cache. Do not try to create platform objects.
return new XFontFamily(fontFamilyInternal);
//// Custom font resolver face names must not clash with platform family names.
//if (FontFamilyCache.GetFamilyByName(name) != null)
//{
// // User must rename its font face to resolve naming confilict.
// throw new InvalidOperationException(String.Format("Font face name {0} clashs with existing family name.", name));
//}
//// Create font family and save it in cache. Do not try to create platform objects.
//FontFamilyInternal fontFamilyInternal = FontFamilyInternal.GetOrCreateFromName(name, false);
//fontFamilyInternal = FontFamilyCache.CacheFontFamily(fontFamilyInternal);
//return new XFontFamily(fontFamilyInternal);
}
/// <summary>
/// Gets the name of the font family.
/// </summary>
public string Name
{
get { return FamilyInternal.Name; }
}
#if true__
public double LineSpacing
{
get
{
WpfFamily.FamilyTypefaces[0].UnderlineThickness
}
}
#endif
/// <summary>
/// Returns the cell ascent, in design units, of the XFontFamily object of the specified style.
/// </summary>
public int GetCellAscent(XFontStyle style)
{
OpenTypeDescriptor descriptor = (OpenTypeDescriptor)FontDescriptorCache.GetOrCreateDescriptor(Name, style);
int result = descriptor.Ascender;
return result;
}
/// <summary>
/// Returns the cell descent, in design units, of the XFontFamily object of the specified style.
/// </summary>
public int GetCellDescent(XFontStyle style)
{
OpenTypeDescriptor descriptor = (OpenTypeDescriptor)FontDescriptorCache.GetOrCreateDescriptor(Name, style);
int result = descriptor.Descender;
return result;
}
/// <summary>
/// Gets the height, in font design units, of the em square for the specified style.
/// </summary>
public int GetEmHeight(XFontStyle style)
{
OpenTypeDescriptor descriptor = (OpenTypeDescriptor)FontDescriptorCache.GetOrCreateDescriptor(Name, style);
int result = descriptor.UnitsPerEm;
#if DEBUG_
int headValue = descriptor.FontFace.head.unitsPerEm;
Debug.Assert(headValue == result);
#endif
return result;
}
/// <summary>
/// Returns the line spacing, in design units, of the FontFamily object of the specified style.
/// The line spacing is the vertical distance between the base lines of two consecutive lines of text.
/// </summary>
public int GetLineSpacing(XFontStyle style)
{
OpenTypeDescriptor descriptor = (OpenTypeDescriptor)FontDescriptorCache.GetOrCreateDescriptor(Name, style);
int result = descriptor.LineSpacing;
return result;
}
//public string GetName(int language);
/// <summary>
/// Indicates whether the specified FontStyle enumeration is available.
/// </summary>
public bool IsStyleAvailable(XFontStyle style)
{
XGdiFontStyle xStyle = ((XGdiFontStyle)style) & XGdiFontStyle.BoldItalic;
return false;
}
/// <summary>
/// The implementation sigleton of font family;
/// </summary>
internal FontFamilyInternal FamilyInternal;
}
}
+203
View File
@@ -0,0 +1,203 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Collects information of a font.
/// </summary>
public sealed class XFontMetrics
{
internal XFontMetrics(string name, int unitsPerEm, int ascent, int descent, int leading, int lineSpacing,
int capHeight, int xHeight, int stemV, int stemH, int averageWidth, int maxWidth ,
int underlinePosition, int underlineThickness, int strikethroughPosition, int strikethroughThickness)
{
_name = name;
_unitsPerEm = unitsPerEm;
_ascent = ascent;
_descent = descent;
_leading = leading;
_lineSpacing = lineSpacing;
_capHeight = capHeight;
_xHeight = xHeight;
_stemV = stemV;
_stemH = stemH;
_averageWidth = averageWidth;
_maxWidth = maxWidth;
_underlinePosition = underlinePosition;
_underlineThickness = underlineThickness;
_strikethroughPosition = strikethroughPosition;
_strikethroughThickness = strikethroughThickness;
}
/// <summary>
/// Gets the font name.
/// </summary>
public string Name
{
get { return _name; }
}
readonly string _name;
/// <summary>
/// Gets the ascent value.
/// </summary>
public int UnitsPerEm
{
get { return _unitsPerEm; }
}
readonly int _unitsPerEm;
/// <summary>
/// Gets the ascent value.
/// </summary>
public int Ascent
{
get { return _ascent; }
}
readonly int _ascent;
/// <summary>
/// Gets the descent value.
/// </summary>
public int Descent
{
get { return _descent; }
}
readonly int _descent;
/// <summary>
/// Gets the average width.
/// </summary>
public int AverageWidth
{
get { return _averageWidth; }
}
readonly int _averageWidth;
/// <summary>
/// Gets the height of capital letters.
/// </summary>
public int CapHeight
{
get { return _capHeight; }
}
readonly int _capHeight;
/// <summary>
/// Gets the leading value.
/// </summary>
public int Leading
{
get { return _leading; }
}
readonly int _leading;
/// <summary>
/// Gets the line spacing value.
/// </summary>
public int LineSpacing
{
get { return _lineSpacing; }
}
readonly int _lineSpacing;
/// <summary>
/// Gets the maximum width of a character.
/// </summary>
public int MaxWidth
{
get { return _maxWidth; }
}
readonly int _maxWidth;
/// <summary>
/// Gets an internal value.
/// </summary>
public int StemH
{
get { return _stemH; }
}
readonly int _stemH;
/// <summary>
/// Gets an internal value.
/// </summary>
public int StemV
{
get { return _stemV; }
}
readonly int _stemV;
/// <summary>
/// Gets the height of a lower-case character.
/// </summary>
public int XHeight
{
get { return _xHeight; }
}
readonly int _xHeight;
/// <summary>
/// Gets the underline position.
/// </summary>
public int UnderlinePosition
{
get { return _underlinePosition; }
}
readonly int _underlinePosition;
/// <summary>
/// Gets the underline thicksness.
/// </summary>
public int UnderlineThickness
{
get { return _underlineThickness; }
}
readonly int _underlineThickness;
/// <summary>
/// Gets the strikethrough position.
/// </summary>
public int StrikethroughPosition
{
get { return _strikethroughPosition; }
}
readonly int _strikethroughPosition;
/// <summary>
/// Gets the strikethrough thicksness.
/// </summary>
public int StrikethroughThickness
{
get { return _strikethroughThickness; }
}
readonly int _strikethroughThickness;
}
}
+178
View File
@@ -0,0 +1,178 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.Diagnostics;
using System.Globalization;
using PdfSharpCore.Fonts;
using PdfSharpCore.Fonts.OpenType;
namespace PdfSharpCore.Drawing
{
/// <summary>
/// The bytes of a font file.
/// </summary>
[DebuggerDisplay("{DebuggerDisplay}")]
internal class XFontSource
{
// Implementation Notes
//
// * XFontSource represents a single font (file) in memory.
// * An XFontSource hold a reference to it OpenTypeFontface.
// * To prevent large heap fragmentation this class must exists only once.
// * TODO: ttcf
// Signature of a true type collection font.
const uint ttcf = 0x66637474;
XFontSource(byte[] bytes, ulong key)
{
_fontName = null;
_bytes = bytes;
_key = key;
}
/// <summary>
/// Gets an existing font source or creates a new one.
/// A new font source is cached in font factory.
/// </summary>
public static XFontSource GetOrCreateFrom(byte[] bytes)
{
ulong key = FontHelper.CalcChecksum(bytes);
XFontSource fontSource;
if (!FontFactory.TryGetFontSourceByKey(key, out fontSource))
{
fontSource = new XFontSource(bytes, key);
// Theoretically the font source could be created by a differend thread in the meantime.
fontSource = FontFactory.CacheFontSource(fontSource);
}
return fontSource;
}
public static XFontSource GetOrCreateFrom(string typefaceKey, byte[] fontBytes)
{
XFontSource fontSource;
ulong key = FontHelper.CalcChecksum(fontBytes);
if (FontFactory.TryGetFontSourceByKey(key, out fontSource))
{
// The font source already exists, but is not yet cached under the specified typeface key.
FontFactory.CacheExistingFontSourceWithNewTypefaceKey(typefaceKey, fontSource);
}
else
{
// No font source exists. Create new one and cache it.
fontSource = new XFontSource(fontBytes, key);
FontFactory.CacheNewFontSource(typefaceKey, fontSource);
}
return fontSource;
}
public static XFontSource CreateCompiledFont(byte[] bytes)
{
XFontSource fontSource = new XFontSource(bytes, 0);
return fontSource;
}
/// <summary>
/// Gets or sets the fontface.
/// </summary>
internal OpenTypeFontface Fontface
{
get { return _fontface; }
set
{
_fontface = value;
_fontName = value.name.FullFontName;
}
}
OpenTypeFontface _fontface;
/// <summary>
/// Gets the key that uniquely identifies this font source.
/// </summary>
internal ulong Key
{
get
{
if (_key == 0)
_key = FontHelper.CalcChecksum(Bytes);
return _key;
}
}
ulong _key;
public void IncrementKey()
{
// HACK: Depends on implementation of CalcChecksum.
// Increment check sum and keep length untouched.
_key += 1ul << 32;
}
/// <summary>
/// Gets the name of the font's name table.
/// </summary>
public string FontName
{
get { return _fontName; }
}
string _fontName;
/// <summary>
/// Gets the bytes of the font.
/// </summary>
public byte[] Bytes
{
get { return _bytes; }
}
readonly byte[] _bytes;
public override int GetHashCode()
{
return (int)((Key >> 32) ^ Key);
}
public override bool Equals(object obj)
{
XFontSource fontSource = obj as XFontSource;
if (fontSource == null)
return false;
return Key == fontSource.Key;
}
/// <summary>
/// Gets the DebuggerDisplayAttribute text.
/// </summary>
// ReSha rper disable UnusedMember.Local
internal string DebuggerDisplay
// ReShar per restore UnusedMember.Local
{
// The key is converted to a value a human can remember during debugging.
get { return String.Format(CultureInfo.InvariantCulture, "XFontSource: '{0}', keyhash={1}", FontName, Key % 99991 /* largest prime number less than 100000 */); }
}
}
}
+53
View File
@@ -0,0 +1,53 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
namespace PdfSharpCore.Drawing
{
#if PDFSHARP20
enum FontStretchValues
{
UltraCondensed = 1,
ExtraCondensed = 2,
Condensed = 3,
SemiCondensed = 4,
Normal = 5,
SemiExpanded = 6,
Expanded = 7,
ExtraExpanded = 8,
UltraExpanded = 9,
}
/// <summary>
/// NYI. Reserved for future extensions of PdfSharpCore.
/// </summary>
// [DebuggerDisplay("'{Name}', {Size}")]
public class XFontStretch
{ }
#endif
}
+163
View File
@@ -0,0 +1,163 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
namespace PdfSharpCore.Drawing
{
#if true_ // PDFSHARP20
/// <summary>
/// Defines the density of a typeface, in terms of the lightness or heaviness of the strokes.
/// </summary>
[DebuggerDisplay("'{Weight}'")]
public class XFontWeight : IFormattable
{
internal XFontWeight(int weight)
{
_weight = weight;
}
/// <summary>
/// Gets the weight of the font, a value between 1 and 999.
/// </summary>
public int Weight
{
get { return (_weight); }
}
private readonly int _weight;
//public static XFontWeight FromOpenTypeWeight(int weightValue)
//{
// if (weightValue < 1 || weightValue > 999)
// throw new ArgumentOutOfRangeException("weightValue", "Parameter must be between 1 and 999.");
// return new XFontWeight(weightValue);
//}
/// <summary>
/// Compares the specified font weights.
/// </summary>
public static int Compare(XFontWeight left, XFontWeight right)
{
return left._weight - right._weight;
}
/// <summary>
/// Implements the operator &lt;.
/// </summary>
public static bool operator <(XFontWeight left, XFontWeight right)
{
return Compare(left, right) < 0;
}
/// <summary>
/// Implements the operator &lt;=.
/// </summary>
public static bool operator <=(XFontWeight left, XFontWeight right)
{
return Compare(left, right) <= 0;
}
/// <summary>
/// Implements the operator &gt;.
/// </summary>
public static bool operator >(XFontWeight left, XFontWeight right)
{
return Compare(left, right) > 0;
}
/// <summary>
/// Implements the operator &gt;=.
/// </summary>
public static bool operator >=(XFontWeight left, XFontWeight right)
{
return Compare(left, right) >= 0;
}
/// <summary>
/// Implements the operator ==.
/// </summary>
public static bool operator ==(XFontWeight left, XFontWeight right)
{
return Compare(left, right) == 0;
}
/// <summary>
/// Implements the operator !=.
/// </summary>
public static bool operator !=(XFontWeight left, XFontWeight right)
{
return !(left == right);
}
/// <summary>
/// Determines whether the specified <see cref="XFontWeight"/> is equal to the current <see cref="XFontWeight"/>.
/// </summary>
public bool Equals(XFontWeight obj)
{
return this == obj;
}
/// <summary>
/// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>.
/// </summary>
public override bool Equals(object obj)
{
return (obj is XFontWeight) && this == ((XFontWeight)obj);
}
/// <summary>
/// Serves as a hash function for this type.
/// </summary>
public override int GetHashCode()
{
return Weight;
}
/// <summary>
/// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
/// </summary>
public override string ToString()
{
return ConvertToString(null, null);
}
string IFormattable.ToString(string format, IFormatProvider provider)
{
return ConvertToString(format, provider);
}
internal string ConvertToString(string format, IFormatProvider provider)
{
provider = provider ?? CultureInfo.InvariantCulture;
string str;
if (!XFontWeights.FontWeightToString(Weight, out str))
return Weight.ToString(format, provider);
return str;
}
}
#endif
}
+309
View File
@@ -0,0 +1,309 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
// Not used in PDFsharp 1.x.
namespace PdfSharpCore.Drawing
{
enum FontWeightValues
{
Thin = 100,
ExtraLight = 200,
Light = 300,
Normal = 400,
Medium = 500,
SemiBold = 600,
Bold = 700,
ExtraBold = 800,
Black = 900,
ExtraBlack = 950,
}
#if true_ // PDFSHARP20
/// <summary>
/// Defines a set of static predefined XFontWeight values.
/// </summary>
public static class XFontWeights
{
internal static bool FontWeightStringToKnownWeight(string s, IFormatProvider provider, ref XFontWeight fontWeight)
{
int num;
switch (s.ToLower())
{
case "thin":
fontWeight = Thin;
return true;
case "extralight":
fontWeight = ExtraLight;
return true;
case "ultralight":
fontWeight = UltraLight;
return true;
case "light":
fontWeight = Light;
return true;
case "normal":
fontWeight = Normal;
return true;
case "regular":
fontWeight = Regular;
return true;
case "medium":
fontWeight = Medium;
return true;
case "semibold":
fontWeight = SemiBold;
return true;
case "demibold":
fontWeight = DemiBold;
return true;
case "bold":
fontWeight = Bold;
return true;
case "extrabold":
fontWeight = ExtraBold;
return true;
case "ultrabold":
fontWeight = UltraBold;
return true;
case "heavy":
fontWeight = Heavy;
return true;
case "black":
fontWeight = Black;
return true;
case "extrablack":
fontWeight = ExtraBlack;
return true;
case "ultrablack":
fontWeight = UltraBlack;
return true;
}
if (Int32.TryParse(s, NumberStyles.Integer, provider, out num))
{
fontWeight = new XFontWeight(num);
return true;
}
return false;
}
internal static bool FontWeightToString(int weight, out string convertedValue)
{
switch (weight)
{
case 100:
convertedValue = "Thin";
return true;
case 200:
convertedValue = "ExtraLight";
return true;
case 300:
convertedValue = "Light";
return true;
case 400:
convertedValue = "Normal";
return true;
case 500:
convertedValue = "Medium";
return true;
case 600:
convertedValue = "SemiBold";
return true;
case 700:
convertedValue = "Bold";
return true;
case 800:
convertedValue = "ExtraBold";
return true;
case 900:
convertedValue = "Black";
return true;
case 950:
convertedValue = "ExtraBlack";
return true;
}
convertedValue = null;
return false;
}
/// <summary>
/// Specifies a "Thin" font weight.
/// </summary>
public static XFontWeight Thin
{
get { return new XFontWeight(100); }
}
/// <summary>
/// Specifies a "ExtraLight" font weight.
/// </summary>
public static XFontWeight ExtraLight
{
get { return new XFontWeight(200); }
}
/// <summary>
/// Specifies a "UltraLight" font weight.
/// </summary>
public static XFontWeight UltraLight
{
get { return new XFontWeight(200); }
}
/// <summary>
/// Specifies a "Light" font weight.
/// </summary>
public static XFontWeight Light
{
get { return new XFontWeight(300); }
}
/// <summary>
/// Specifies a "Normal" font weight.
/// </summary>
public static XFontWeight Normal
{
get { return new XFontWeight(400); }
}
/// <summary>
/// Specifies a "Regular" font weight.
/// </summary>
public static XFontWeight Regular
{
get { return new XFontWeight(400); }
}
/// <summary>
/// Specifies a "Medium" font weight.
/// </summary>
public static XFontWeight Medium
{
get { return new XFontWeight(500); }
}
/// <summary>
/// Specifies a "SemiBold" font weight.
/// </summary>
public static XFontWeight SemiBold
{
get { return new XFontWeight(600); }
}
/// <summary>
/// Specifies a "DemiBold" font weight.
/// </summary>
public static XFontWeight DemiBold
{
get { return new XFontWeight(600); }
}
/// <summary>
/// Specifies a "Bold" font weight.
/// </summary>
public static XFontWeight Bold
{
get { return new XFontWeight(700); }
}
/// <summary>
/// Specifies a "ExtraBold" font weight.
/// </summary>
public static XFontWeight ExtraBold
{
get { return new XFontWeight(800); }
}
/// <summary>
/// Specifies a "UltraBold" font weight.
/// </summary>
public static XFontWeight UltraBold
{
get { return new XFontWeight(800); }
}
/// <summary>
/// Specifies a "Heavy" font weight.
/// </summary>
public static XFontWeight Heavy
{
get { return new XFontWeight(900); }
}
/// <summary>
/// Specifies a "Black" font weight.
/// </summary>
public static XFontWeight Black
{
get { return new XFontWeight(900); }
}
/// <summary>
/// Specifies a "ExtraBlack" font weight.
/// </summary>
public static XFontWeight ExtraBlack
{
get { return new XFontWeight(950); }
}
/// <summary>
/// Specifies a "UltraBlack" font weight.
/// </summary>
public static XFontWeight UltraBlack
{
get { return new XFontWeight(950); }
}
}
#endif
}
+466
View File
@@ -0,0 +1,466 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.Diagnostics;
using PdfSharpCore.Drawing.Pdf;
using PdfSharpCore.Pdf;
using PdfSharpCore.Pdf.Advanced;
using PdfSharpCore.Pdf.Filters;
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Represents a graphical object that can be used to render retained graphics on it.
/// In GDI+ it is represented by a Metafile, in WPF by a DrawingVisual, and in PDF by a Form XObjects.
/// </summary>
public class XForm : XImage, IContentStream
{
internal enum FormState
{
/// <summary>
/// The form is an imported PDF page.
/// </summary>
NotATemplate,
/// <summary>
/// The template is just created.
/// </summary>
Created,
/// <summary>
/// XGraphics.FromForm() was called.
/// </summary>
UnderConstruction,
/// <summary>
/// The form was drawn at least once and is 'frozen' now.
/// </summary>
Finished,
}
/// <summary>
/// Initializes a new instance of the <see cref="XForm"/> class.
/// </summary>
protected XForm()
{ }
/// <summary>
/// Initializes a new instance of the <see cref="XForm"/> class that represents a page of a PDF document.
/// </summary>
/// <param name="document">The PDF document.</param>
/// <param name="viewBox">The view box of the page.</param>
public XForm(PdfDocument document, XRect viewBox)
{
if (viewBox.Width < 1 || viewBox.Height < 1)
throw new ArgumentNullException("viewBox", "The size of the XPdfForm is to small.");
// I must tie the XPdfForm to a document immediately, because otherwise I would have no place where
// to store the resources.
if (document == null)
throw new ArgumentNullException("document", "An XPdfForm template must be associated with a document at creation time.");
_formState = FormState.Created;
_document = document;
_pdfForm = new PdfFormXObject(document, this);
//_templateSize = size;
_viewBox = viewBox;
PdfRectangle rect = new PdfRectangle(viewBox);
_pdfForm.Elements.SetRectangle(PdfFormXObject.Keys.BBox, rect);
}
/// <summary>
/// Initializes a new instance of the <see cref="XForm"/> class that represents a page of a PDF document.
/// </summary>
/// <param name="document">The PDF document.</param>
/// <param name="size">The size of the page.</param>
public XForm(PdfDocument document, XSize size)
: this(document, new XRect(0, 0, size.Width, size.Height))
{
////if (size.width < 1 || size.height < 1)
//// throw new ArgumentNullException("size", "The size of the XPdfForm is to small.");
////// I must tie the XPdfForm to a document immediately, because otherwise I would have no place where
////// to store the resources.
////if (document == null)
//// throw new ArgumentNullException("document", "An XPdfForm template must be associated with a document.");
////_formState = FormState.Created;
////_document = document;
////pdfForm = new PdfFormXObject(document, this);
////templateSize = size;
////PdfRectangle rect = new PdfRectangle(new XPoint(), size);
////pdfForm.Elements.SetRectangle(PdfFormXObject.Keys.BBox, rect);
}
/// <summary>
/// Initializes a new instance of the <see cref="XForm"/> class that represents a page of a PDF document.
/// </summary>
/// <param name="document">The PDF document.</param>
/// <param name="width">The width of the page.</param>
/// <param name="height">The height of the page</param>
public XForm(PdfDocument document, XUnit width, XUnit height)
: this(document, new XRect(0, 0, width, height))
{ }
/// <summary>
/// This function should be called when drawing the content of this form is finished.
/// The XGraphics object used for drawing the content is disposed by this function and
/// cannot be used for any further drawing operations.
/// PDFsharp automatically calls this function when this form was used the first time
/// in a DrawImage function.
/// </summary>
public void DrawingFinished()
{
if (_formState == FormState.Finished)
return;
if (_formState == FormState.NotATemplate)
throw new InvalidOperationException("This object is an imported PDF page and you cannot finish drawing on it because you must not draw on it at all.");
Finish();
}
/// <summary>
/// Called from XGraphics constructor that creates an instance that work on this form.
/// </summary>
internal void AssociateGraphics(XGraphics gfx)
{
if (_formState == FormState.NotATemplate)
throw new NotImplementedException("The current version of PDFsharp cannot draw on an imported page.");
if (_formState == FormState.UnderConstruction)
throw new InvalidOperationException("An XGraphics object already exists for this form.");
if (_formState == FormState.Finished)
throw new InvalidOperationException("After drawing a form it cannot be modified anymore.");
Debug.Assert(_formState == FormState.Created);
_formState = FormState.UnderConstruction;
Gfx = gfx;
}
internal XGraphics Gfx;
/// <summary>
/// Disposes this instance.
/// </summary>
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}
/// <summary>
/// Sets the form in the state FormState.Finished.
/// </summary>
internal virtual void Finish()
{
if (_formState == FormState.NotATemplate || _formState == FormState.Finished)
return;
if (!(_formState == FormState.Created || _formState == FormState.UnderConstruction))
{
throw new InvalidOperationException("Expected the form to be Created or UnderConstruction");
}
_formState = FormState.Finished;
Gfx.Dispose();
Gfx = null;
if (PdfRenderer != null)
{
//pdfForm.CreateStream(PdfEncoders.RawEncoding.GetBytes(PdfRenderer.GetContent()));
PdfRenderer.Close();
if (_document.Options.CompressContentStreams)
{
_pdfForm.Stream.Value = Filtering.FlateDecode.Encode(_pdfForm.Stream.Value, _document.Options.FlateEncodeMode);
_pdfForm.Elements["/Filter"] = new PdfName("/FlateDecode");
}
int length = _pdfForm.Stream.Length;
_pdfForm.Elements.SetInteger("/Length", length);
}
}
/// <summary>
/// Gets the owning document.
/// </summary>
internal PdfDocument Owner
{
get { return _document; }
}
PdfDocument _document;
/// <summary>
/// Gets the color model used in the underlying PDF document.
/// </summary>
internal PdfColorMode ColorMode
{
get
{
if (_document == null)
return PdfColorMode.Undefined;
return _document.Options.ColorMode;
}
}
/// <summary>
/// Gets a value indicating whether this instance is a template.
/// </summary>
internal bool IsTemplate
{
get { return _formState != FormState.NotATemplate; }
}
internal FormState _formState;
/// <summary>
/// Get the width in point of this image.
/// </summary>
public override double PointWidth
{
//get { return templateSize.width; }
get { return _viewBox.Width; }
}
/// <summary>
/// Get the height in point of this image.
/// </summary>
public override double PointHeight
{
//get { return templateSize.height; }
get { return _viewBox.Height; }
}
/// <summary>
/// Get the width of the page identified by the property PageNumber.
/// </summary>
public override int PixelWidth
{
//get { return (int)templateSize.width; }
get { return (int)_viewBox.Width; }
}
/// <summary>
/// Get the height of the page identified by the property PageNumber.
/// </summary>
public override int PixelHeight
{
//get { return (int)templateSize.height; }
get { return (int)_viewBox.Height; }
}
/// <summary>
/// Get the size of the page identified by the property PageNumber.
/// </summary>
public override XSize Size
{
//get { return templateSize; }
get { return _viewBox.Size; }
}
//XSize templateSize;
/// <summary>
/// Gets the view box of the form.
/// </summary>
public XRect ViewBox
{
get { return _viewBox; }
}
XRect _viewBox;
/// <summary>
/// Gets 72, the horizontal resolution by design of a form object.
/// </summary>
public override double HorizontalResolution
{
get { return 72; }
}
/// <summary>
/// Gets 72 always, the vertical resolution by design of a form object.
/// </summary>
public override double VerticalResolution
{
get { return 72; }
}
/// <summary>
/// Gets or sets the bounding box.
/// </summary>
public XRect BoundingBox
{
get { return _boundingBox; }
set { _boundingBox = value; } // TODO: pdfForm = null
}
XRect _boundingBox;
/// <summary>
/// Gets or sets the transformation matrix.
/// </summary>
public virtual XMatrix Transform
{
get { return _transform; }
set
{
if (_formState == FormState.Finished)
throw new InvalidOperationException("After a XPdfForm was once drawn it must not be modified.");
_transform = value;
}
}
internal XMatrix _transform;
internal PdfResources Resources
{
get
{
Debug.Assert(IsTemplate, "This function is for form templates only.");
return PdfForm.Resources;
//if (resources == null)
// resources = (PdfResources)pdfForm.Elements.GetValue(PdfFormXObject.Keys.Resources, VCF.Create); // VCF.CreateIndirect
//return resources;
}
}
//PdfResources resources;
/// <summary>
/// Implements the interface because the primary function is internal.
/// </summary>
PdfResources IContentStream.Resources
{
get { return Resources; }
}
/// <summary>
/// Gets the resource name of the specified font within this form.
/// </summary>
internal string GetFontName(XFont font, out PdfFont pdfFont)
{
Debug.Assert(IsTemplate, "This function is for form templates only.");
pdfFont = _document.FontTable.GetFont(font);
Debug.Assert(pdfFont != null);
string name = Resources.AddFont(pdfFont);
return name;
}
string IContentStream.GetFontName(XFont font, out PdfFont pdfFont)
{
return GetFontName(font, out pdfFont);
}
/// <summary>
/// Tries to get the resource name of the specified font data within this form.
/// Returns null if no such font exists.
/// </summary>
internal string TryGetFontName(string idName, out PdfFont pdfFont)
{
Debug.Assert(IsTemplate, "This function is for form templates only.");
pdfFont = _document.FontTable.TryGetFont(idName);
string name = null;
if (pdfFont != null)
name = Resources.AddFont(pdfFont);
return name;
}
/// <summary>
/// Gets the resource name of the specified font data within this form.
/// </summary>
internal string GetFontName(string idName, byte[] fontData, out PdfFont pdfFont)
{
Debug.Assert(IsTemplate, "This function is for form templates only.");
pdfFont = _document.FontTable.GetFont(idName, fontData);
//pdfFont = new PdfType0Font(Owner, idName, fontData);
//pdfFont.Document = _document;
Debug.Assert(pdfFont != null);
string name = Resources.AddFont(pdfFont);
return name;
}
string IContentStream.GetFontName(string idName, byte[] fontData, out PdfFont pdfFont)
{
return GetFontName(idName, fontData, out pdfFont);
}
/// <summary>
/// Gets the resource name of the specified image within this form.
/// </summary>
internal string GetImageName(XImage image)
{
Debug.Assert(IsTemplate, "This function is for form templates only.");
PdfImage pdfImage = _document.ImageTable.GetImage(image);
Debug.Assert(pdfImage != null);
string name = Resources.AddImage(pdfImage);
return name;
}
/// <summary>
/// Implements the interface because the primary function is internal.
/// </summary>
string IContentStream.GetImageName(XImage image)
{
return GetImageName(image);
}
internal PdfFormXObject PdfForm
{
get
{
Debug.Assert(IsTemplate, "This function is for form templates only.");
if (_pdfForm.Reference == null)
_document._irefTable.Add(_pdfForm);
return _pdfForm;
}
}
/// <summary>
/// Gets the resource name of the specified form within this form.
/// </summary>
internal string GetFormName(XForm form)
{
Debug.Assert(IsTemplate, "This function is for form templates only.");
PdfFormXObject pdfForm = _document.FormTable.GetForm(form);
Debug.Assert(pdfForm != null);
string name = Resources.AddForm(pdfForm);
return name;
}
/// <summary>
/// Implements the interface because the primary function is internal.
/// </summary>
string IContentStream.GetFormName(XForm form)
{
return GetFormName(form);
}
/// <summary>
/// The PdfFormXObject gets invalid when PageNumber or transform changed. This is because a modification
/// of an XPdfForm must not change objects that are already been drawn.
/// </summary>
internal PdfFormXObject _pdfForm; // TODO: make private
internal XGraphicsPdfRenderer PdfRenderer;
}
}
+320
View File
@@ -0,0 +1,320 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.Diagnostics;
using System.Globalization;
using PdfSharpCore.Fonts;
using PdfSharpCore.Fonts.OpenType;
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Specifies a physical font face that corresponds to a font file on the disk or in memory.
/// </summary>
[DebuggerDisplay("{DebuggerDisplay}")]
internal sealed class XGlyphTypeface
{
// Implementation Notes
// XGlyphTypeface is the centerpiece for font management. There is a one to one relationship
// between XFont an XGlyphTypeface.
//
// * Each XGlyphTypeface can belong to one or more XFont objects.
// * An XGlyphTypeface hold an XFontFamily.
// * XGlyphTypeface hold a reference to an OpenTypeFontface.
// *
//
const string KeyPrefix = "tk:"; // "typeface key"
public XGlyphTypeface(string key, XFontSource fontSource)
{
string familyName = fontSource.Fontface.name.Name;
_fontFamily = new XFontFamily(familyName, false);
_fontface = fontSource.Fontface;
_isBold = _fontface.os2.IsBold;
_isItalic = _fontface.os2.IsItalic;
_key = key;
//_fontFamily =xfont FontFamilyCache.GetFamilyByName(familyName);
_fontSource = fontSource;
Initialize();
}
// ReSharper disable once UnusedMember.Global
public XGlyphTypeface(string key, XFontFamily fontFamily, XFontSource fontSource, XStyleSimulations styleSimulations)
{
_key = key;
_fontFamily = fontFamily;
_fontSource = fontSource;
_styleSimulations = styleSimulations;
_fontface = OpenTypeFontface.CetOrCreateFrom(fontSource);
Initialize();
}
public static XGlyphTypeface GetOrCreateFrom(string familyName, FontResolvingOptions fontResolvingOptions)
{
// Check cache for requested type face.
string typefaceKey = ComputeKey(familyName, fontResolvingOptions);
if (GlyphTypefaceCache.TryGetGlyphTypeface(typefaceKey, out var glyphTypeface))
{
// Just return existing one.
return glyphTypeface;
}
// Resolve typeface by FontFactory.
FontResolverInfo fontResolverInfo = FontFactory.ResolveTypeface(familyName, fontResolvingOptions, typefaceKey);
if (fontResolverInfo == null)
{
// No fallback - just stop.
throw new InvalidOperationException("No appropriate font found.");
}
// Now create the font family at the first.
XFontFamily fontFamily;
if (fontResolverInfo is PlatformFontResolverInfo platformFontResolverInfo)
{
}
else
{
// Create new and exclusively used font family for custom font resolver retrieved font source.
fontFamily = XFontFamily.CreateSolitary(fontResolverInfo.FaceName);
}
// We have a valid font resolver info. That means we also have an XFontSource object loaded in the cache.
////XFontSource fontSource = FontFactory.GetFontSourceByTypefaceKey(fontResolverInfo.FaceName);
XFontSource fontSource = FontFactory.GetFontSourceByFontName(fontResolverInfo.FaceName);
Debug.Assert(fontSource != null);
// Each font source already contains its OpenTypeFontface.
glyphTypeface = new XGlyphTypeface(typefaceKey, fontSource);
GlyphTypefaceCache.AddGlyphTypeface(glyphTypeface);
return glyphTypeface;
}
public XFontFamily FontFamily
{
get { return _fontFamily; }
}
readonly XFontFamily _fontFamily;
internal OpenTypeFontface Fontface
{
get { return _fontface; }
}
readonly OpenTypeFontface _fontface;
public XFontSource FontSource
{
get { return _fontSource; }
}
readonly XFontSource _fontSource;
void Initialize()
{
_familyName = _fontface.name.Name;
if (string.IsNullOrEmpty(_faceName) || _faceName.StartsWith("?"))
_faceName = _familyName;
_styleName = _fontface.name.Style;
_displayName = _fontface.name.FullFontName;
if (string.IsNullOrEmpty(_displayName))
{
_displayName = _familyName;
if (string.IsNullOrEmpty(_styleName))
_displayName += " (" + _styleName + ")";
}
// Bold, as defined in OS/2 table.
_isBold = _fontface.os2.IsBold;
// Debug.Assert(_isBold == (_fontface.os2.usWeightClass > 400), "Check font weight.");
// Italic, as defined in OS/2 table.
_isItalic = _fontface.os2.IsItalic;
}
/// <summary>
/// Gets the name of the font face. This can be a file name, an uri, or a GUID.
/// </summary>
internal string FaceName
{
get { return _faceName; }
}
string _faceName;
/// <summary>
/// Gets the English family name of the font, for example "Arial".
/// </summary>
public string FamilyName
{
get { return _familyName; }
}
string _familyName;
/// <summary>
/// Gets the English subfamily name of the font,
/// for example "Bold".
/// </summary>
public string StyleName
{
get { return _styleName; }
}
string _styleName;
/// <summary>
/// Gets the English display name of the font,
/// for example "Arial italic".
/// </summary>
public string DisplayName
{
get { return _displayName; }
}
string _displayName;
/// <summary>
/// Gets a value indicating whether the font weight is bold.
/// </summary>
public bool IsBold
{
get { return _isBold; }
}
bool _isBold;
/// <summary>
/// Gets a value indicating whether the font style is italic.
/// </summary>
public bool IsItalic
{
get { return _isItalic; }
}
bool _isItalic;
public XStyleSimulations StyleSimulations
{
get { return _styleSimulations; }
}
XStyleSimulations _styleSimulations;
/// <summary>
/// Gets the suffix of the face name in a PDF font and font descriptor.
/// The name based on the effective value of bold and italic from the OS/2 table.
/// </summary>
string GetFaceNameSuffix()
{
// Use naming of Microsoft Word.
if (IsBold)
return IsItalic ? ",BoldItalic" : ",Bold";
return IsItalic ? ",Italic" : "";
}
internal string GetBaseName()
{
string name = DisplayName;
int ich = name.IndexOf("bold", StringComparison.OrdinalIgnoreCase);
if (ich > 0)
name = name.Substring(0, ich) + name.Substring(ich + 4, name.Length - ich - 4);
ich = name.IndexOf("italic", StringComparison.OrdinalIgnoreCase);
if (ich > 0)
name = name.Substring(0, ich) + name.Substring(ich + 6, name.Length - ich - 6);
//name = name.Replace(" ", "");
name = name.Trim();
name += GetFaceNameSuffix();
return name;
}
/// <summary>
/// Computes the bijective key for a typeface.
/// </summary>
internal static string ComputeKey(string familyName, FontResolvingOptions fontResolvingOptions)
{
// Compute a human readable key.
string simulationSuffix = "";
if (fontResolvingOptions.OverrideStyleSimulations)
{
switch (fontResolvingOptions.StyleSimulations)
{
case XStyleSimulations.BoldSimulation: simulationSuffix = "|b+/i-"; break;
case XStyleSimulations.ItalicSimulation: simulationSuffix = "|b-/i+"; break;
case XStyleSimulations.BoldItalicSimulation: simulationSuffix = "|b+/i+"; break;
case XStyleSimulations.None: break;
default: throw new ArgumentOutOfRangeException();
}
}
string key = KeyPrefix + familyName.ToLowerInvariant()
+ (fontResolvingOptions.IsItalic ? "/i" : "/n") // normal / oblique / italic
+ (fontResolvingOptions.IsBold ? "/700" : "/400") + "/5" // Stretch.Normal
+ simulationSuffix;
return key;
}
/// <summary>
/// Computes the bijective key for a typeface.
/// </summary>
internal static string ComputeKey(string familyName, bool isBold, bool isItalic)
{
return ComputeKey(familyName, new FontResolvingOptions(FontHelper.CreateStyle(isBold, isItalic)));
}
public string Key
{
get { return _key; }
}
readonly string _key;
/// <summary>
/// Gets the DebuggerDisplayAttribute text.
/// </summary>
// ReSharper disable UnusedMember.Local
internal string DebuggerDisplay
// ReSharper restore UnusedMember.Local
{
get { return string.Format(CultureInfo.InvariantCulture, "{0} - {1} ({2})", FamilyName, StyleName, FaceName); }
}
}
}
File diff suppressed because it is too large Load Diff
+39
View File
@@ -0,0 +1,39 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Represents the internal state of an XGraphics object.
/// </summary>
public sealed class XGraphicsContainer
{
internal InternalGraphicsState InternalState;
}
}
+505
View File
@@ -0,0 +1,505 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
using System;
using PdfSharpCore.Internal;
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Represents a series of connected lines and curves.
/// </summary>
public sealed class XGraphicsPath
{
/// <summary>
/// Initializes a new instance of the <see cref="XGraphicsPath"/> class.
/// </summary>
public XGraphicsPath()
{
_corePath = new CoreGraphicsPath();
}
/// <summary>
/// Clones this instance.
/// </summary>
public XGraphicsPath Clone()
{
XGraphicsPath path = (XGraphicsPath)MemberwiseClone();
_corePath = new CoreGraphicsPath(_corePath);
return path;
}
// ----- AddLine ------------------------------------------------------------------------------
/// <summary>
/// Adds a line segment to current figure.
/// </summary>
public void AddLine(XPoint pt1, XPoint pt2)
{
AddLine(pt1.X, pt1.Y, pt2.X, pt2.Y);
}
public void AddMove(double x1, double y1)
=> _corePath.MoveTo(x1, y1);
/// <summary>
/// Adds a line segment to current figure.
/// </summary>
public void AddLine(double x1, double y1, double x2, double y2)
{
_corePath.MoveOrLineTo(x1, y1);
_corePath.LineTo(x2, y2, false);
}
// ----- AddLines -----------------------------------------------------------------------------
/// <summary>
/// Adds a series of connected line segments to current figure.
/// </summary>
public void AddLines(XPoint[] points)
{
if (points == null)
throw new ArgumentNullException("points");
int count = points.Length;
if (count == 0)
return;
_corePath.MoveOrLineTo(points[0].X, points[0].Y);
for (int idx = 1; idx < count; idx++)
_corePath.LineTo(points[idx].X, points[idx].Y, false);
}
// ----- AddBezier ----------------------------------------------------------------------------
/// <summary>
/// Adds a cubic Bézier curve to the current figure.
/// </summary>
public void AddBezier(XPoint pt1, XPoint pt2, XPoint pt3, XPoint pt4)
{
AddBezier(pt1.X, pt1.Y, pt2.X, pt2.Y, pt3.X, pt3.Y, pt4.X, pt4.Y);
}
/// <summary>
/// Adds a cubic Bézier curve to the current figure.
/// </summary>
public void AddBezier(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
{
_corePath.MoveOrLineTo(x1, y1);
_corePath.BezierTo(x2, y2, x3, y3, x4, y4, false);
}
// ----- AddBeziers ---------------------------------------------------------------------------
/// <summary>
/// Adds a sequence of connected cubic Bézier curves to the current figure.
/// </summary>
public void AddBeziers(XPoint[] points)
{
if (points == null)
throw new ArgumentNullException("points");
int count = points.Length;
if (count < 4)
throw new ArgumentException("At least four points required for bezier curve.", "points");
if ((count - 1) % 3 != 0)
throw new ArgumentException("Invalid number of points for bezier curve. Number must fulfil 4+3n.",
"points");
_corePath.MoveOrLineTo(points[0].X, points[0].Y);
for (int idx = 1; idx < count; idx += 3)
{
_corePath.BezierTo(points[idx].X, points[idx].Y, points[idx + 1].X, points[idx + 1].Y,
points[idx + 2].X, points[idx + 2].Y, false);
}
}
// ----- AddCurve -----------------------------------------------------------------------
/// <summary>
/// Adds a spline curve to the current figure.
/// </summary>
public void AddCurve(XPoint[] points)
{
AddCurve(points, 0.5);
}
/// <summary>
/// Adds a spline curve to the current figure.
/// </summary>
public void AddCurve(XPoint[] points, double tension)
{
int count = points.Length;
if (count < 2)
throw new ArgumentException("AddCurve requires two or more points.", "points");
_corePath.AddCurve(points, tension);
}
/// <summary>
/// Adds a spline curve to the current figure.
/// </summary>
public void AddCurve(XPoint[] points, int offset, int numberOfSegments, double tension)
{
throw new NotImplementedException("AddCurve not yet implemented.");
}
// ----- AddArc -------------------------------------------------------------------------------
/// <summary>
/// Adds an elliptical arc to the current figure.
/// </summary>
public void AddArc(XRect rect, double startAngle, double sweepAngle)
{
AddArc(rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
}
/// <summary>
/// Adds an elliptical arc to the current figure.
/// </summary>
public void AddArc(double x, double y, double width, double height, double startAngle, double sweepAngle)
{
_corePath.AddArc(x, y, width, height, startAngle, sweepAngle);
}
/// <summary>
/// Adds an elliptical arc to the current figure. The arc is specified WPF like.
/// </summary>
public void AddArc(XPoint point1, XPoint point2, XSize size, double rotationAngle, bool isLargeArg, XSweepDirection sweepDirection)
{
_corePath.AddArc(point1, point2, size, rotationAngle, isLargeArg, sweepDirection);
}
// ----- AddRectangle -------------------------------------------------------------------------
/// <summary>
/// Adds a rectangle to this path.
/// </summary>
public void AddRectangle(XRect rect)
{
_corePath.MoveTo(rect.X, rect.Y);
_corePath.LineTo(rect.X + rect.Width, rect.Y, false);
_corePath.LineTo(rect.X + rect.Width, rect.Y + rect.Height, false);
_corePath.LineTo(rect.X, rect.Y + rect.Height, true);
_corePath.CloseSubpath();
}
/// <summary>
/// Adds a rectangle to this path.
/// </summary>
public void AddRectangle(double x, double y, double width, double height)
{
AddRectangle(new XRect(x, y, width, height));
}
// ----- AddRectangles ------------------------------------------------------------------------
/// <summary>
/// Adds a series of rectangles to this path.
/// </summary>
public void AddRectangles(XRect[] rects)
{
int count = rects.Length;
for (int idx = 0; idx < count; idx++)
{
AddRectangle(rects[idx]);
}
}
// ----- AddRoundedRectangle ------------------------------------------------------------------
/// <summary>
/// Adds a rectangle with rounded corners to this path.
/// </summary>
public void AddRoundedRectangle(double x, double y, double width, double height, double ellipseWidth, double ellipseHeight)
{
double arcWidth = ellipseWidth / 2;
double arcHeight = ellipseHeight / 2;
_corePath.MoveTo(x + width - arcWidth, y);
_corePath.QuadrantArcTo(x + width - arcWidth, y + arcHeight, arcWidth, arcHeight, 1, true);
_corePath.LineTo(x + width, y + height - arcHeight, false);
_corePath.QuadrantArcTo(x + width - arcWidth, y + height - arcHeight, arcWidth, arcHeight, 4, true);
_corePath.LineTo(x + arcWidth, y + height, false);
_corePath.QuadrantArcTo(x + arcWidth, y + height - arcHeight, arcWidth, arcHeight, 3, true);
_corePath.LineTo(x, y + arcHeight, false);
_corePath.QuadrantArcTo(x + arcWidth, y + arcHeight, arcWidth, arcHeight, 2, true);
_corePath.CloseSubpath();
}
// ----- AddEllipse ---------------------------------------------------------------------------
/// <summary>
/// Adds an ellipse to the current path.
/// </summary>
public void AddEllipse(XRect rect)
{
AddEllipse(rect.X, rect.Y, rect.Width, rect.Height);
}
/// <summary>
/// Adds an ellipse to the current path.
/// </summary>
public void AddEllipse(double x, double y, double width, double height)
{
double w = width / 2;
double h = height / 2;
double xc = x + w;
double yc = y + h;
_corePath.MoveTo(x + w, y);
_corePath.QuadrantArcTo(xc, yc, w, h, 1, true);
_corePath.QuadrantArcTo(xc, yc, w, h, 4, true);
_corePath.QuadrantArcTo(xc, yc, w, h, 3, true);
_corePath.QuadrantArcTo(xc, yc, w, h, 2, true);
_corePath.CloseSubpath();
}
// ----- AddPolygon ---------------------------------------------------------------------------
/// <summary>
/// Adds a polygon to this path.
/// </summary>
public void AddPolygon(XPoint[] points)
{
int count = points.Length;
if (count == 0)
return;
_corePath.MoveTo(points[0].X, points[0].Y);
for (int idx = 0; idx < count - 1; idx++)
_corePath.LineTo(points[idx].X, points[idx].Y, false);
_corePath.LineTo(points[count - 1].X, points[count - 1].Y, true);
_corePath.CloseSubpath();
}
// ----- AddPie -------------------------------------------------------------------------------
/// <summary>
/// Adds the outline of a pie shape to this path.
/// </summary>
public void AddPie(XRect rect, double startAngle, double sweepAngle)
{
AddPie(rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
}
/// <summary>
/// Adds the outline of a pie shape to this path.
/// </summary>
public void AddPie(double x, double y, double width, double height, double startAngle, double sweepAngle)
{
DiagnosticsHelper.HandleNotImplemented("XGraphicsPath.AddPie");
}
// ----- AddClosedCurve ------------------------------------------------------------------------
/// <summary>
/// Adds a closed curve to this path.
/// </summary>
public void AddClosedCurve(XPoint[] points)
{
AddClosedCurve(points, 0.5);
}
/// <summary>
/// Adds a closed curve to this path.
/// </summary>
public void AddClosedCurve(XPoint[] points, double tension)
{
if (points == null)
throw new ArgumentNullException("points");
int count = points.Length;
if (count == 0)
return;
if (count < 2)
throw new ArgumentException("Not enough points.", "points");
DiagnosticsHelper.HandleNotImplemented("XGraphicsPath.AddClosedCurve");
}
// ----- AddPath ------------------------------------------------------------------------------
/// <summary>
/// Adds the specified path to this path.
/// </summary>
public void AddPath(XGraphicsPath path, bool connect)
{
DiagnosticsHelper.HandleNotImplemented("XGraphicsPath.AddPath");
}
// ----- AddString ----------------------------------------------------------------------------
/// <summary>
/// Adds a text string to this path.
/// </summary>
public void AddString(string s, XFontFamily family, XFontStyle style, double emSize, XPoint origin,
XStringFormat format)
{
try
{
DiagnosticsHelper.HandleNotImplemented("XGraphicsPath.AddString");
}
catch
{
throw;
}
}
/// <summary>
/// Adds a text string to this path.
/// </summary>
public void AddString(string s, XFontFamily family, XFontStyle style, double emSize, XRect layoutRect,
XStringFormat format)
{
if (s == null)
throw new ArgumentNullException("s");
if (family == null)
throw new ArgumentNullException("family");
if (format == null)
format = XStringFormats.Default;
if (format.LineAlignment == XLineAlignment.BaseLine && layoutRect.Height != 0)
throw new InvalidOperationException(
"DrawString: With XLineAlignment.BaseLine the height of the layout rectangle must be 0.");
if (s.Length == 0)
return;
XFont font = new XFont(family.Name, emSize, style);
DiagnosticsHelper.HandleNotImplemented("XGraphicsPath.AddString");
}
// --------------------------------------------------------------------------------------------
/// <summary>
/// Closes the current figure and starts a new figure.
/// </summary>
public void CloseFigure()
{
_corePath.CloseSubpath();
}
/// <summary>
/// Starts a new figure without closing the current figure.
/// </summary>
public void StartFigure()
{
// TODO: ???
}
// --------------------------------------------------------------------------------------------
/// <summary>
/// Gets or sets an XFillMode that determines how the interiors of shapes are filled.
/// </summary>
public XFillMode FillMode
{
get { return _fillMode; }
set
{
_fillMode = value;
// Nothing to do.
}
}
private XFillMode _fillMode;
// --------------------------------------------------------------------------------------------
/// <summary>
/// Converts each curve in this XGraphicsPath into a sequence of connected line segments.
/// </summary>
public void Flatten()
{
// Just do nothing.
}
/// <summary>
/// Converts each curve in this XGraphicsPath into a sequence of connected line segments.
/// </summary>
public void Flatten(XMatrix matrix)
{
// Just do nothing.
}
/// <summary>
/// Converts each curve in this XGraphicsPath into a sequence of connected line segments.
/// </summary>
public void Flatten(XMatrix matrix, double flatness)
{
// Just do nothing.
}
// --------------------------------------------------------------------------------------------
/// <summary>
/// Replaces this path with curves that enclose the area that is filled when this path is drawn
/// by the specified pen.
/// </summary>
public void Widen(XPen pen)
{
// Just do nothing.
}
/// <summary>
/// Replaces this path with curves that enclose the area that is filled when this path is drawn
/// by the specified pen.
/// </summary>
public void Widen(XPen pen, XMatrix matrix)
{
// Just do nothing.
}
/// <summary>
/// Replaces this path with curves that enclose the area that is filled when this path is drawn
/// by the specified pen.
/// </summary>
public void Widen(XPen pen, XMatrix matrix, double flatness)
{
// Just do nothing.
}
/// <summary>
/// Grants access to internal objects of this class.
/// </summary>
public XGraphicsPathInternals Internals
{
get { return new XGraphicsPathInternals(this); }
}
/// <summary>
/// Gets access to underlying Core graphics path.
/// </summary>
internal CoreGraphicsPath _corePath;
}
}
@@ -0,0 +1,56 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
#if GDI
using System.Drawing;
using System.Drawing.Drawing2D;
#endif
#if WPF
using System.Windows;
using System.Windows.Media;
#endif
#if NETFX_CORE
using Windows.UI.Xaml.Media;
#endif
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Provides access to the internal data structures of XGraphicsPath.
/// This class prevents the public interface from pollution with internal functions.
/// </summary>
public sealed class XGraphicsPathInternals
{
internal XGraphicsPathInternals(XGraphicsPath path)
{
_path = path;
}
XGraphicsPath _path;
}
}
+41
View File
@@ -0,0 +1,41 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Represents the internal state of an XGraphics object.
/// This class is used as a handle for restoring the context.
/// </summary>
public sealed class XGraphicsState
{
// This class is simply a wrapper of InternalGraphicsState.
internal InternalGraphicsState InternalState;
}
}
+361
View File
@@ -0,0 +1,361 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.Diagnostics;
using System.IO;
using PdfSharpCore.Pdf.IO;
using PdfSharpCore.Pdf.Advanced;
using MigraDocCore.DocumentObjectModel.MigraDoc.DocumentObjectModel.Shapes;
using PdfSharpCore.Pdf.IO.enums;
using static MigraDocCore.DocumentObjectModel.MigraDoc.DocumentObjectModel.Shapes.ImageSource;
using PdfSharpCore.Utils;
using SixLabors.ImageSharp.PixelFormats;
namespace PdfSharpCore.Drawing
{
[Flags]
internal enum XImageState
{
UsedInDrawingContext = 0x00000001,
StateMask = 0x0000FFFF,
}
/// <summary>
/// Defines an object used to draw image files (bmp, png, jpeg, gif) and PDF forms.
/// An abstract base class that provides functionality for the Bitmap and Metafile descended classes.
/// </summary>
public class XImage : IDisposable
{
// The hierarchy is adapted to WPF/Silverlight/WinRT
//
// XImage <-- ImageSource
// XForm
// PdfForm
// XBitmapSource <-- BitmapSource
// XBitmapImage <-- BitmapImage
// ???
//public bool Disposed
//{
// get { return _disposed; }
// set { _disposed = value; }
//}
/// <summary>
/// Initializes a new instance of the <see cref="XImage"/> class.
/// </summary>
protected XImage()
{ }
// Useful stuff here: http://stackoverflow.com/questions/350027/setting-wpf-image-source-in-code
XImage(string path)
{
if (ImageSource.ImageSourceImpl == null) ImageSource.ImageSourceImpl = new ImageSharpImageSource<Rgba32>();
_source = ImageSource.FromFile(path);
Initialize();
}
XImage(IImageSource imageSource)
{
_source = imageSource;
_path = _source.Name;
Initialize();
}
XImage(Func<Stream> stream)
{
// Create a dummy unique path.
_path = "*" + Guid.NewGuid().ToString("B");
if (ImageSource.ImageSourceImpl == null)
ImageSource.ImageSourceImpl = new ImageSharpImageSource<Rgba32>();
_source = ImageSource.FromStream(_path, stream);
Initialize();
}
XImage(Func<byte[]> data)
{
// Create a dummy unique path.
_path = "*" + Guid.NewGuid().ToString("B");
_source = ImageSource.FromBinary(_path, data);
Initialize();
}
/// <summary>
/// Creates an image from the specified file.
/// For non-pdf files, this requires that an instance of an implementation of <see cref="T:MigraDocCore.DocumentObjectModel.MigraDoc.DocumentObjectModel.Shapes.ImageSource"/> be set on the `ImageSource.ImageSourceImpl` property.
/// For .NetCore apps, if this property is null at this point, then <see cref="T:PdfSharpCore.Utils.ImageSharpImageSource"/> with <see cref="T:SixLabors.ImageSharp.PixelFormats.Rgba32"/> Pixel Type is used
/// </summary>
/// <param name="path">The path to a BMP, PNG, GIF, JPEG, TIFF, or PDF file.</param>
public static XImage FromFile(string path)
{
return FromFile(path, PdfReadAccuracy.Strict);
}
/// <summary>
/// Creates an image from the specified file.
/// For non-pdf files, this requires that an instance of an implementation of <see cref="T:MigraDocCore.DocumentObjectModel.MigraDoc.DocumentObjectModel.Shapes.ImageSource"/> be set on the `ImageSource.ImageSourceImpl` property.
/// For .NetCore apps, if this property is null at this point, then <see cref="T:PdfSharpCore.Utils.ImageSharpImageSource"/> with <see cref="T:SixLabors.ImageSharp.PixelFormats.Rgba32"/> Pixel Type is used
/// </summary>
/// <param name="path">The path to a BMP, PNG, GIF, JPEG, TIFF, or PDF file.</param>
/// <param name="accuracy">Moderate allows for broken references when using a PDF file.</param>
public static XImage FromFile(string path, PdfReadAccuracy accuracy)
{
if (PdfReader.TestPdfFile(path) > 0)
return new XPdfForm(path, accuracy);
return new XImage(path);
}
/// <summary>
/// Creates an image from the specified stream.<br/>
/// For non-pdf files, this requires that an instance of an implementation of <see cref="T:MigraDocCore.DocumentObjectModel.MigraDoc.DocumentObjectModel.Shapes.ImageSource"/> be set on the `ImageSource.ImageSourceImpl` property.
/// For .NetCore apps, if this property is null at this point, then <see cref="T:PdfSharpCore.Utils.ImageSharpImageSource"/> with <see cref="T:SixLabors.ImageSharp.PixelFormats.Rgba32"/> Pixel Type is used
/// Silverlight supports PNG and JPEF only.
/// </summary>
/// <param name="stream">The stream containing a BMP, PNG, GIF, JPEG, TIFF, or PDF file.</param>
public static XImage FromStream(Func<Stream> stream)
{
if (stream == null)
throw new ArgumentNullException("stream");
// TODO: Check PDF stream.
//if (PdfReader.TestPdfFile(path) > 0)
// return new XPdfForm(path);
return new XImage(stream);
}
public static XImage FromImageSource(IImageSource imageSouce)
{
return new XImage(imageSouce);
}
/// <summary>
/// Tests if a file exist. Supports PDF files with page number suffix.
/// </summary>
/// <param name="path">The path to a BMP, PNG, GIF, JPEG, TIFF, or PDF file.</param>
public static bool ExistsFile(string path)
{
// Support for "base64:" pseudo protocol is a MigraDoc feature, currently completely implemented in MigraDoc files. TODO: Does support for "base64:" make sense for PDFsharp? Probably not as PDFsharp can handle images from streams.
//if (path.StartsWith("base64:")) // The Image is stored in the string here, so the file exists.
// return true;
if (PdfReader.TestPdfFile(path) > 0)
return true;
return false;
}
internal XImageState XImageState
{
get { return _xImageState; }
set { _xImageState = value; }
}
XImageState _xImageState;
internal void Initialize()
{
if (_source != null)
{
//We always get a jpeg from an image source
_format = _source.Transparent ? XImageFormat.Png : XImageFormat.Jpeg;
}
}
public MemoryStream AsJpeg()
{
var ms = new MemoryStream();
_source.SaveAsJpeg(ms);
ms.Position = 0;
return ms;
}
public MemoryStream AsBitmap()
{
var ms = new MemoryStream();
_source.SaveAsPdfBitmap(ms);
ms.Position = 0;
return ms;
}
/// <summary>
/// Under construction
/// </summary>
public void Dispose()
{
Dispose(true);
//GC.SuppressFinalize(this);
}
/// <summary>
/// Disposes underlying GDI+ object.
/// </summary>
protected virtual void Dispose(bool disposing)
{
if (!_disposed)
_disposed = true;
}
bool _disposed;
/// <summary>
/// Gets the width of the image in point.
/// </summary>
public virtual double PointWidth
{
get
{
return _source.Width * 72 / 96.0;
}
}
/// <summary>
/// Gets the height of the image in point.
/// </summary>
public virtual double PointHeight
{
get
{
return _source.Height * 72 / 96.0;
}
}
/// <summary>
/// Gets the width of the image in pixels.
/// </summary>
public virtual int PixelWidth
{
get
{
return _source.Width;
}
}
/// <summary>
/// Gets the height of the image in pixels.
/// </summary>
public virtual int PixelHeight
{
get
{
return _source.Height;
}
}
/// <summary>
/// Gets the size in point of the image.
/// </summary>
public virtual XSize Size
{
get { return new XSize(PointWidth, PointHeight); }
}
/// <summary>
/// Gets the horizontal resolution of the image.
/// </summary>
public virtual double HorizontalResolution
{
get
{
return 96;
}
}
/// <summary>
/// Gets the vertical resolution of the image.
/// </summary>
public virtual double VerticalResolution
{
get
{
return 96;
}
}
/// <summary>
/// Gets or sets a flag indicating whether image interpolation is to be performed.
/// </summary>
public virtual bool Interpolate
{
get { return _interpolate; }
set { _interpolate = value; }
}
bool _interpolate = true;
/// <summary>
/// Gets the format of the image.
/// </summary>
public XImageFormat Format
{
get { return _format; }
}
XImageFormat _format;
internal void AssociateWithGraphics(XGraphics gfx)
{
if (_associatedGraphics != null)
throw new InvalidOperationException("XImage already associated with XGraphics.");
_associatedGraphics = null;
}
internal void DisassociateWithGraphics()
{
if (_associatedGraphics == null)
throw new InvalidOperationException("XImage not associated with XGraphics.");
_associatedGraphics.DisassociateImage();
Debug.Assert(_associatedGraphics == null);
}
internal void DisassociateWithGraphics(XGraphics gfx)
{
if (_associatedGraphics != gfx)
throw new InvalidOperationException("XImage not associated with XGraphics.");
_associatedGraphics = null;
}
internal XGraphics AssociatedGraphics
{
get { return _associatedGraphics; }
set { _associatedGraphics = value; }
}
XGraphics _associatedGraphics;
/// <summary>
/// If path starts with '*' the image is created from a stream and the path is a GUID.
/// </summary>
internal string _path;
/// <summary>
/// Cache PdfImageTable.ImageSelector to speed up finding the right PdfImage
/// if this image is used more than once.
/// </summary>
internal PdfImageTable.ImageSelector _selector;
private IImageSource _source;
}
}
+141
View File
@@ -0,0 +1,141 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
using System;
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Specifies the format of the image.
/// </summary>
public sealed class XImageFormat
{
XImageFormat(Guid guid)
{
_guid = guid;
}
internal Guid Guid
{
get { return _guid; }
}
/// <summary>
/// Determines whether the specified object is equal to the current object.
/// </summary>
public override bool Equals(object obj)
{
XImageFormat format = obj as XImageFormat;
if (format == null)
return false;
return _guid == format._guid;
}
/// <summary>
/// Returns the hash code for this instance.
/// </summary>
public override int GetHashCode()
{
return _guid.GetHashCode();
}
/// <summary>
/// Gets the Portable Network Graphics (PNG) image format.
/// </summary>
public static XImageFormat Png
{
get { return _png; }
}
/// <summary>
/// Gets the Graphics Interchange Format (GIF) image format.
/// </summary>
public static XImageFormat Gif
{
get { return _gif; }
}
/// <summary>
/// Gets the Joint Photographic Experts Group (JPEG) image format.
/// </summary>
public static XImageFormat Jpeg
{
get { return _jpeg; }
}
/// <summary>
/// Gets the Tag Image File Format (TIFF) image format.
/// </summary>
public static XImageFormat Tiff
{
get { return _tiff; }
}
/// <summary>
/// Gets the Portable Document Format (PDF) image format
/// </summary>
public static XImageFormat Pdf
{
get { return _pdf; }
}
/// <summary>
/// Gets the Windows icon image format.
/// </summary>
public static XImageFormat Icon
{
get { return _icon; }
}
readonly Guid _guid;
// Guids used in GDI+
//ImageFormat.memoryBMP = new ImageFormat(new Guid("{b96b3caa-0728-11d3-9d7b-0000f81ef32e}"));
//ImageFormat.bmp = new ImageFormat(new Guid("{b96b3cab-0728-11d3-9d7b-0000f81ef32e}"));
//ImageFormat.emf = new ImageFormat(new Guid("{b96b3cac-0728-11d3-9d7b-0000f81ef32e}"));
//ImageFormat.wmf = new ImageFormat(new Guid("{b96b3cad-0728-11d3-9d7b-0000f81ef32e}"));
//ImageFormat.jpeg = new ImageFormat(new Guid("{b96b3cae-0728-11d3-9d7b-0000f81ef32e}"));
//ImageFormat.png = new ImageFormat(new Guid("{b96b3caf-0728-11d3-9d7b-0000f81ef32e}"));
//ImageFormat.gif = new ImageFormat(new Guid("{b96b3cb0-0728-11d3-9d7b-0000f81ef32e}"));
//ImageFormat.tiff = new ImageFormat(new Guid("{b96b3cb1-0728-11d3-9d7b-0000f81ef32e}"));
//ImageFormat.exif = new ImageFormat(new Guid("{b96b3cb2-0728-11d3-9d7b-0000f81ef32e}"));
//ImageFormat.photoCD = new ImageFormat(new Guid("{b96b3cb3-0728-11d3-9d7b-0000f81ef32e}"));
//ImageFormat.flashPIX = new ImageFormat(new Guid("{b96b3cb4-0728-11d3-9d7b-0000f81ef32e}"));
//ImageFormat.icon = new ImageFormat(new Guid("{b96b3cb5-0728-11d3-9d7b-0000f81ef32e}"));
// #??? Why Guids?
private static readonly XImageFormat _png = new XImageFormat(new Guid("{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}"));
private static readonly XImageFormat _gif = new XImageFormat(new Guid("{B96B3CB0-0728-11D3-9D7B-0000F81EF32E}"));
private static readonly XImageFormat _jpeg = new XImageFormat(new Guid("{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}"));
private static readonly XImageFormat _tiff = new XImageFormat(new Guid("{B96B3CB1-0728-11D3-9D7B-0000F81EF32E}"));
private static readonly XImageFormat _icon = new XImageFormat(new Guid("{B96B3CB5-0728-11D3-9D7B-0000F81EF32E}"));
// not GDI+ conform
private static readonly XImageFormat _pdf = new XImageFormat(new Guid("{84570158-DBF0-4C6B-8368-62D6A3CA76E0}"));
}
}
+215
View File
@@ -0,0 +1,215 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
namespace PdfSharpCore.Drawing
{
internal class XKnownColorTable
{
internal static uint[] ColorTable;
public static uint KnownColorToArgb(XKnownColor color)
{
if (ColorTable == null)
InitColorTable();
if (color <= XKnownColor.YellowGreen)
return ColorTable[(int)color];
return 0;
}
public static bool IsKnownColor(uint argb)
{
for (int idx = 0; idx < ColorTable.Length; idx++)
{
if (ColorTable[idx] == argb)
return true;
}
return false;
}
public static XKnownColor GetKnownColor(uint argb)
{
for (int idx = 0; idx < ColorTable.Length; idx++)
{
if (ColorTable[idx] == argb)
return (XKnownColor)idx;
}
return (XKnownColor)(-1);
}
private static void InitColorTable()
{
// Same values as in GDI+ and System.Windows.Media.XColors
// Note that Magenta is the same as Fuchsia and Zyan is the same as Aqua.
uint[] colors = new uint[141];
colors[0] = 0xFFF0F8FF; // AliceBlue
colors[1] = 0xFFFAEBD7; // AntiqueWhite
colors[2] = 0xFF00FFFF; // Aqua
colors[3] = 0xFF7FFFD4; // Aquamarine
colors[4] = 0xFFF0FFFF; // Azure
colors[5] = 0xFFF5F5DC; // Beige
colors[6] = 0xFFFFE4C4; // Bisque
colors[7] = 0xFF000000; // Black
colors[8] = 0xFFFFEBCD; // BlanchedAlmond
colors[9] = 0xFF0000FF; // Blue
colors[10] = 0xFF8A2BE2; // BlueViolet
colors[11] = 0xFFA52A2A; // Brown
colors[12] = 0xFFDEB887; // BurlyWood
colors[13] = 0xFF5F9EA0; // CadetBlue
colors[14] = 0xFF7FFF00; // Chartreuse
colors[15] = 0xFFD2691E; // Chocolate
colors[16] = 0xFFFF7F50; // Coral
colors[17] = 0xFF6495ED; // CornflowerBlue
colors[18] = 0xFFFFF8DC; // Cornsilk
colors[19] = 0xFFDC143C; // Crimson
colors[20] = 0xFF00FFFF; // Cyan
colors[21] = 0xFF00008B; // DarkBlue
colors[22] = 0xFF008B8B; // DarkCyan
colors[23] = 0xFFB8860B; // DarkGoldenrod
colors[24] = 0xFFA9A9A9; // DarkGray
colors[25] = 0xFF006400; // DarkGreen
colors[26] = 0xFFBDB76B; // DarkKhaki
colors[27] = 0xFF8B008B; // DarkMagenta
colors[28] = 0xFF556B2F; // DarkOliveGreen
colors[29] = 0xFFFF8C00; // DarkOrange
colors[30] = 0xFF9932CC; // DarkOrchid
colors[31] = 0xFF8B0000; // DarkRed
colors[32] = 0xFFE9967A; // DarkSalmon
colors[33] = 0xFF8FBC8B; // DarkSeaGreen
colors[34] = 0xFF483D8B; // DarkSlateBlue
colors[35] = 0xFF2F4F4F; // DarkSlateGray
colors[36] = 0xFF00CED1; // DarkTurquoise
colors[37] = 0xFF9400D3; // DarkViolet
colors[38] = 0xFFFF1493; // DeepPink
colors[39] = 0xFF00BFFF; // DeepSkyBlue
colors[40] = 0xFF696969; // DimGray
colors[41] = 0xFF1E90FF; // DodgerBlue
colors[42] = 0xFFB22222; // Firebrick
colors[43] = 0xFFFFFAF0; // FloralWhite
colors[44] = 0xFF228B22; // ForestGreen
colors[45] = 0xFFFF00FF; // Fuchsia
colors[46] = 0xFFDCDCDC; // Gainsboro
colors[47] = 0xFFF8F8FF; // GhostWhite
colors[48] = 0xFFFFD700; // Gold
colors[49] = 0xFFDAA520; // Goldenrod
colors[50] = 0xFF808080; // Gray
colors[51] = 0xFF008000; // Green
colors[52] = 0xFFADFF2F; // GreenYellow
colors[53] = 0xFFF0FFF0; // Honeydew
colors[54] = 0xFFFF69B4; // HotPink
colors[55] = 0xFFCD5C5C; // IndianRed
colors[56] = 0xFF4B0082; // Indigo
colors[57] = 0xFFFFFFF0; // Ivory
colors[58] = 0xFFF0E68C; // Khaki
colors[59] = 0xFFE6E6FA; // Lavender
colors[60] = 0xFFFFF0F5; // LavenderBlush
colors[61] = 0xFF7CFC00; // LawnGreen
colors[62] = 0xFFFFFACD; // LemonChiffon
colors[63] = 0xFFADD8E6; // LightBlue
colors[64] = 0xFFF08080; // LightCoral
colors[65] = 0xFFE0FFFF; // LightCyan
colors[66] = 0xFFFAFAD2; // LightGoldenrodYellow
colors[67] = 0xFFD3D3D3; // LightGray
colors[68] = 0xFF90EE90; // LightGreen
colors[69] = 0xFFFFB6C1; // LightPink
colors[70] = 0xFFFFA07A; // LightSalmon
colors[71] = 0xFF20B2AA; // LightSeaGreen
colors[72] = 0xFF87CEFA; // LightSkyBlue
colors[73] = 0xFF778899; // LightSlateGray
colors[74] = 0xFFB0C4DE; // LightSteelBlue
colors[75] = 0xFFFFFFE0; // LightYellow
colors[76] = 0xFF00FF00; // Lime
colors[77] = 0xFF32CD32; // LimeGreen
colors[78] = 0xFFFAF0E6; // Linen
colors[79] = 0xFFFF00FF; // Magenta
colors[80] = 0xFF800000; // Maroon
colors[81] = 0xFF66CDAA; // MediumAquamarine
colors[82] = 0xFF0000CD; // MediumBlue
colors[83] = 0xFFBA55D3; // MediumOrchid
colors[84] = 0xFF9370DB; // MediumPurple
colors[85] = 0xFF3CB371; // MediumSeaGreen
colors[86] = 0xFF7B68EE; // MediumSlateBlue
colors[87] = 0xFF00FA9A; // MediumSpringGreen
colors[88] = 0xFF48D1CC; // MediumTurquoise
colors[89] = 0xFFC71585; // MediumVioletRed
colors[90] = 0xFF191970; // MidnightBlue
colors[91] = 0xFFF5FFFA; // MintCream
colors[92] = 0xFFFFE4E1; // MistyRose
colors[93] = 0xFFFFE4B5; // Moccasin
colors[94] = 0xFFFFDEAD; // NavajoWhite
colors[95] = 0xFF000080; // Navy
colors[96] = 0xFFFDF5E6; // OldLace
colors[97] = 0xFF808000; // Olive
colors[98] = 0xFF6B8E23; // OliveDrab
colors[99] = 0xFFFFA500; // Orange
colors[100] = 0xFFFF4500; // OrangeRed
colors[101] = 0xFFDA70D6; // Orchid
colors[102] = 0xFFEEE8AA; // PaleGoldenrod
colors[103] = 0xFF98FB98; // PaleGreen
colors[104] = 0xFFAFEEEE; // PaleTurquoise
colors[105] = 0xFFDB7093; // PaleVioletRed
colors[106] = 0xFFFFEFD5; // PapayaWhip
colors[107] = 0xFFFFDAB9; // PeachPuff
colors[108] = 0xFFCD853F; // Peru
colors[109] = 0xFFFFC0CB; // Pink
colors[110] = 0xFFDDA0DD; // Plum
colors[111] = 0xFFB0E0E6; // PowderBlue
colors[112] = 0xFF800080; // Purple
colors[113] = 0xFFFF0000; // Red
colors[114] = 0xFFBC8F8F; // RosyBrown
colors[115] = 0xFF4169E1; // RoyalBlue
colors[116] = 0xFF8B4513; // SaddleBrown
colors[117] = 0xFFFA8072; // Salmon
colors[118] = 0xFFF4A460; // SandyBrown
colors[119] = 0xFF2E8B57; // SeaGreen
colors[120] = 0xFFFFF5EE; // SeaShell
colors[121] = 0xFFA0522D; // Sienna
colors[122] = 0xFFC0C0C0; // Silver
colors[123] = 0xFF87CEEB; // SkyBlue
colors[124] = 0xFF6A5ACD; // SlateBlue
colors[125] = 0xFF708090; // SlateGray
colors[126] = 0xFFFFFAFA; // Snow
colors[127] = 0xFF00FF7F; // SpringGreen
colors[128] = 0xFF4682B4; // SteelBlue
colors[129] = 0xFFD2B48C; // Tan
colors[130] = 0xFF008080; // Teal
colors[131] = 0xFFD8BFD8; // Thistle
colors[132] = 0xFFFF6347; // Tomato
colors[133] = 0x00FFFFFF; // Transparent
colors[134] = 0xFF40E0D0; // Turquoise
colors[135] = 0xFFEE82EE; // Violet
colors[136] = 0xFFF5DEB3; // Wheat
colors[137] = 0xFFFFFFFF; // White
colors[138] = 0xFFF5F5F5; // WhiteSmoke
colors[139] = 0xFFFFFF00; // Yellow
colors[140] = 0xFF9ACD32; // YellowGreen
ColorTable = colors;
}
}
}
@@ -0,0 +1,82 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.ComponentModel;
using PdfSharpCore.Internal;
// ReSharper disable RedundantNameQualifier because it is required for hybrid build
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Defines a Brush with a linear gradient.
/// </summary>
public sealed class XLinearGradientBrush : XBaseGradientBrush
{
//internal XLinearGradientBrush();
/// <summary>
/// Initializes a new instance of the <see cref="XLinearGradientBrush"/> class.
/// </summary>
public XLinearGradientBrush(XPoint point1, XPoint point2, XColor color1, XColor color2) : base(color1, color2)
{
_point1 = point1;
_point2 = point2;
}
/// <summary>
/// Initializes a new instance of the <see cref="XLinearGradientBrush"/> class.
/// </summary>
public XLinearGradientBrush(XRect rect, XColor color1, XColor color2, XLinearGradientMode linearGradientMode) : base(color1, color2)
{
if (!Enum.IsDefined(typeof(XLinearGradientMode), linearGradientMode))
throw new InvalidEnumArgumentException("linearGradientMode", (int)linearGradientMode, typeof(XLinearGradientMode));
if (rect.Width == 0 || rect.Height == 0)
throw new ArgumentException("Invalid rectangle.", "rect");
_useRect = true;
_rect = rect;
_linearGradientMode = linearGradientMode;
}
// TODO:
//public XLinearGradientBrush(Rectangle rect, XColor color1, XColor color2, double angle);
//public XLinearGradientBrush(RectangleF rect, XColor color1, XColor color2, double angle);
//public XLinearGradientBrush(Rectangle rect, XColor color1, XColor color2, double angle, bool isAngleScaleable);
//public XLinearGradientBrush(RectangleF rect, XColor color1, XColor color2, double angle, bool isAngleScaleable);
//public XLinearGradientBrush(RectangleF rect, XColor color1, XColor color2, double angle, bool isAngleScaleable);
internal bool _useRect;
internal XPoint _point1, _point2;
internal XRect _rect;
internal XLinearGradientMode _linearGradientMode;
}
}
File diff suppressed because it is too large Load Diff
+430
View File
@@ -0,0 +1,430 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.IO;
using PdfSharpCore.Internal;
using PdfSharpCore.Pdf;
using PdfSharpCore.Pdf.IO;
using PdfSharpCore.Pdf.IO.enums;
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Represents a so called 'PDF form external object', which is typically an imported page of an external
/// PDF document. XPdfForm objects are used like images to draw an existing PDF page of an external
/// document in the current document. XPdfForm objects can only be placed in PDF documents. If you try
/// to draw them using a XGraphics based on an GDI+ context no action is taken if no placeholder image
/// is specified. Otherwise the place holder is drawn.
/// </summary>
public class XPdfForm : XForm
{
/// <summary>
/// Initializes a new instance of the XPdfForm class from the specified path to an external PDF document.
/// Although PDFsharp internally caches XPdfForm objects it is recommended to reuse XPdfForm objects
/// in your code and change the PageNumber property if more than one page is needed form the external
/// document. Furthermore, because XPdfForm can occupy very much memory, it is recommended to
/// dispose XPdfForm objects if not needed anymore.
/// </summary>
internal XPdfForm(string path, PdfReadAccuracy accuracy)
{
int pageNumber;
path = ExtractPageNumber(path, out pageNumber);
path = Path.GetFullPath(path);
if (!File.Exists(path))
throw new FileNotFoundException(PSSR.FileNotFound(path));
if (PdfReader.TestPdfFile(path) == 0)
throw new ArgumentException("The specified file has no valid PDF file header.", "path");
_path = path;
_pathReadAccuracy = accuracy;
if (pageNumber != 0)
PageNumber = pageNumber;
}
/// <summary>
/// Initializes a new instance of the <see cref="XPdfForm"/> class from a stream.
/// </summary>
/// <param name="stream">The stream.</param>
/// <param name="accuracy">Moderate allows for broken references.</param>
internal XPdfForm(Stream stream, PdfReadAccuracy accuracy)
{
// Create a dummy unique path
_path = "*" + Guid.NewGuid().ToString("B");
if (PdfReader.TestPdfFile(stream) == 0)
throw new ArgumentException("The specified stream has no valid PDF file header.", "stream");
_externalDocument = PdfReader.Open(stream, accuracy);
}
/// <summary>
/// Initializes a new instance of the <see cref="XPdfForm"/> class from a stream and password.
/// </summary>
/// <param name="stream">The stream.</param>
/// <param name="password">The password.</param>
/// <param name="accuracy">Moderate allows for broken references.</param>
internal XPdfForm(Stream stream, string password, PdfReadAccuracy accuracy) {
// Create a dummy unique path
_path = "*" + Guid.NewGuid().ToString("B");
if (PdfReader.TestPdfFile(stream) == 0)
throw new ArgumentException("The specified stream has no valid PDF file header.", "stream");
_externalDocument = PdfReader.Open(stream, password, PdfDocumentOpenMode.ReadOnly, accuracy);
}
/// <summary>
/// Creates an XPdfForm from a file.
/// </summary>
public static new XPdfForm FromFile(string path)
{
return FromFile(path, PdfReadAccuracy.Strict);
}
/// <summary>
/// Creates an XPdfForm from a file.
/// </summary>
public static new XPdfForm FromFile(string path, PdfReadAccuracy accuracy)
{
// TODO: Same file should return same object (that's why the function is static).
return new XPdfForm(path, accuracy);
}
/// <summary>
/// Creates an XPdfForm from a stream.
/// </summary>
public static XPdfForm FromStream(Stream stream)
{
return FromStream(stream, PdfReadAccuracy.Strict);
}
/// <summary>
/// Creates an XPdfForm from a stream.
/// </summary>
public static XPdfForm FromStream(Stream stream, PdfReadAccuracy accuracy)
{
return new XPdfForm(stream, accuracy);
}
/// <summary>
/// Creates an XPdfForm from a stream and a password.
/// </summary>
public static XPdfForm FromStream(Stream stream, string password) {
return FromStream(stream, password, PdfReadAccuracy.Strict);
}
/// <summary>
/// Creates an XPdfForm from a stream and a password.
/// </summary>
public static XPdfForm FromStream(Stream stream, string password, PdfReadAccuracy accuracy) {
return new XPdfForm(stream, password, accuracy);
}
/*
void Initialize()
{
// ImageFormat has no overridden Equals...
}
*/
/// <summary>
/// Sets the form in the state FormState.Finished.
/// </summary>
internal override void Finish()
{
if (_formState == FormState.NotATemplate || _formState == FormState.Finished)
return;
base.Finish();
//if (Gfx.metafile != null)
// image = Gfx.metafile;
//Debug.Assert(_fromState == FormState.Created || _fromState == FormState.UnderConstruction);
//_fromState = FormState.Finished;
//Gfx.Dispose();
//Gfx = null;
//if (_pdfRenderer != null)
//{
// _pdfForm.Stream = new PdfDictionary.PdfStream(PdfEncoders.RawEncoding.GetBytes(pdfRenderer.GetContent()), this.pdfForm);
// if (_document.Options.CompressContentStreams)
// {
// _pdfForm.Stream.Value = Filtering.FlateDecode.Encode(pdfForm.Stream.Value);
// _pdfForm.Elements["/Filter"] = new PdfName("/FlateDecode");
// }
// int length = _pdfForm.Stream.Length;
// _pdfForm.Elements.SetInteger("/Length", length);
//}
}
/// <summary>
/// Frees the memory occupied by the underlying imported PDF document, even if other XPdfForm objects
/// refer to this document. A reuse of this object doesn't fail, because the underlying PDF document
/// is re-imported if necessary.
/// </summary>
// TODO: NYI: Dispose
protected override void Dispose(bool disposing)
{
if (!_disposed)
{
_disposed = true;
try
{
if (disposing)
{
//...
}
if (_externalDocument != null)
PdfDocument.Tls.DetachDocument(_externalDocument.Handle);
//...
}
finally
{
base.Dispose(disposing);
}
}
}
bool _disposed;
/// <summary>
/// Gets or sets an image that is used for drawing if the current XGraphics object cannot handle
/// PDF forms. A place holder is useful for showing a preview of a page on the display, because
/// PDFsharp cannot render native PDF objects.
/// </summary>
public XImage PlaceHolder
{
get { return _placeHolder; }
set { _placeHolder = value; }
}
XImage _placeHolder;
/// <summary>
/// Gets the underlying PdfPage (if one exists).
/// </summary>
public PdfPage Page
{
get
{
if (IsTemplate)
return null;
PdfPage page = ExternalDocument.Pages[_pageNumber - 1];
return page;
}
}
/// <summary>
/// Gets the number of pages in the PDF form.
/// </summary>
public int PageCount
{
get
{
if (IsTemplate)
return 1;
if (_pageCount == -1)
_pageCount = ExternalDocument.Pages.Count;
return _pageCount;
}
}
int _pageCount = -1;
/// <summary>
/// Gets the width in point of the page identified by the property PageNumber.
/// </summary>
public override double PointWidth
{
get
{
PdfPage page = ExternalDocument.Pages[_pageNumber - 1];
return page.Width;
}
}
/// <summary>
/// Gets the height in point of the page identified by the property PageNumber.
/// </summary>
public override double PointHeight
{
get
{
PdfPage page = ExternalDocument.Pages[_pageNumber - 1];
return page.Height;
}
}
/// <summary>
/// Gets the width in point of the page identified by the property PageNumber.
/// </summary>
public override int PixelWidth
{
get
{
//PdfPage page = ExternalDocument.Pages[_pageNumber - 1];
//return (int)page.Width;
return DoubleUtil.DoubleToInt(PointWidth);
}
}
/// <summary>
/// Gets the height in point of the page identified by the property PageNumber.
/// </summary>
public override int PixelHeight
{
get
{
//PdfPage page = ExternalDocument.Pages[_pageNumber - 1];
//return (int)page.Height;
return DoubleUtil.DoubleToInt(PointHeight);
}
}
/// <summary>
/// Get the size of the page identified by the property PageNumber.
/// </summary>
public override XSize Size
{
get
{
PdfPage page = ExternalDocument.Pages[_pageNumber - 1];
return new XSize(page.Width, page.Height);
}
}
/// <summary>
/// Gets or sets the transformation matrix.
/// </summary>
public override XMatrix Transform
{
get { return _transform; }
set
{
if (_transform != value)
{
// discard PdfFromXObject when Transform changed
_pdfForm = null;
_transform = value;
}
}
}
/// <summary>
/// Gets or sets the page number in the external PDF document this object refers to. The page number
/// is one-based, i.e. it is in the range from 1 to PageCount. The default value is 1.
/// </summary>
public int PageNumber
{
get { return _pageNumber; }
set
{
if (IsTemplate)
throw new InvalidOperationException("The page number of an XPdfForm template cannot be modified.");
if (_pageNumber != value)
{
_pageNumber = value;
// dispose PdfFromXObject when number has changed
_pdfForm = null;
}
}
}
int _pageNumber = 1;
/// <summary>
/// Gets or sets the page index in the external PDF document this object refers to. The page index
/// is zero-based, i.e. it is in the range from 0 to PageCount - 1. The default value is 0.
/// </summary>
public int PageIndex
{
get { return PageNumber - 1; }
set { PageNumber = value + 1; }
}
/// <summary>
/// Gets the underlying document from which pages are imported.
/// </summary>
internal PdfDocument ExternalDocument
{
// The problem is that you can ask an XPdfForm about the number of its pages before it was
// drawn the first time. At this moment the XPdfForm doesn't know the document where it will
// be later draw on one of its pages. To prevent the import of the same document more than
// once, all imported documents of a thread are cached. The cache is local to the current
// thread and not to the appdomain, because I won't get problems in a multi-thread environment
// that I don't understand.
get
{
if (IsTemplate)
throw new InvalidOperationException("This XPdfForm is a template and not an imported PDF page; therefore it has no external document.");
if (_externalDocument == null)
_externalDocument = PdfDocument.Tls.GetDocument(_path, _pathReadAccuracy);
return _externalDocument;
}
}
internal PdfDocument _externalDocument;
private PdfReadAccuracy _pathReadAccuracy;
/// <summary>
/// Extracts the page number if the path has the form 'MyFile.pdf#123' and returns
/// the actual path without the number sign and the following digits.
/// </summary>
public static string ExtractPageNumber(string path, out int pageNumber)
{
if (path == null)
throw new ArgumentNullException("path");
pageNumber = 0;
int length = path.Length;
if (length != 0)
{
length--;
if (char.IsDigit(path, length))
{
while (char.IsDigit(path, length) && length >= 0)
length--;
if (length > 0 && path[length] == '#')
{
// Must have at least one dot left of colon to distinguish from e.g. '#123'
if (path.IndexOf('.') != -1)
{
pageNumber = int.Parse(path.Substring(length + 1));
path = path.Substring(0, length);
}
}
}
}
return path;
}
}
}
+293
View File
@@ -0,0 +1,293 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
using System;
using PdfSharpCore.Internal;
namespace PdfSharpCore.Drawing
{
// TODO Free GDI objects (pens, brushes, ...) automatically without IDisposable.
/// <summary>
/// Defines an object used to draw lines and curves.
/// </summary>
public sealed class XPen
{
/// <summary>
/// Initializes a new instance of the <see cref="XPen"/> class.
/// </summary>
public XPen(XColor color)
: this(color, 1, false)
{ }
/// <summary>
/// Initializes a new instance of the <see cref="XPen"/> class.
/// </summary>
public XPen(XColor color, double width)
: this(color, width, false)
{ }
internal XPen(XColor color, double width, bool immutable)
{
_color = color;
_width = width;
_lineJoin = XLineJoin.Miter;
_lineCap = XLineCap.Flat;
_dashStyle = XDashStyle.Solid;
_dashOffset = 0f;
_immutable = immutable;
}
/// <summary>
/// Initializes a new instance of the <see cref="XPen"/> class
/// </summary>
/// <param name="brush"></param>
public XPen(XBrush brush) : this(brush, 1, false) { }
/// <summary>
/// Initializes a new instance of the <see cref="XPen"/> class
/// </summary>
/// <param name="brush"></param>
/// <param name="width"></param>
public XPen(XBrush brush, double width) : this(brush, width, false) { }
internal XPen(XBrush brush, double width, bool immutable)
{
_brush = brush;
_width = width;
_lineJoin = XLineJoin.Miter;
_lineCap = XLineCap.Flat;
_dashStyle = XDashStyle.Solid;
_dashOffset = 0f;
_immutable = immutable;
}
/// <summary>
/// Initializes a new instance of the <see cref="XPen"/> class.
/// </summary>
public XPen(XPen pen)
{
_color = pen._color;
_width = pen._width;
_lineJoin = pen._lineJoin;
_lineCap = pen._lineCap;
_dashStyle = pen._dashStyle;
_dashOffset = pen._dashOffset;
_dashPattern = pen._dashPattern;
if (_dashPattern != null)
_dashPattern = (double[])_dashPattern.Clone();
}
/// <summary>
/// Clones this instance.
/// </summary>
public XPen Clone()
{
return new XPen(this);
}
public XBrush Brush
{
get => _brush;
set
{
if (_immutable)
throw new ArgumentException(PSSR.CannotChangeImmutableObject("XPen"));
_dirty = _dirty || _brush != value;
_brush = value;
_color = XColor.Empty;
}
}
internal XBrush _brush;
/// <summary>
/// Gets or sets the color.
/// </summary>
public XColor Color
{
get { return _color; }
set
{
if (_immutable)
throw new ArgumentException(PSSR.CannotChangeImmutableObject("XPen"));
_dirty = _dirty || _color != value;
_color = value;
_brush = null;
}
}
internal XColor _color;
/// <summary>
/// Gets or sets the width.
/// </summary>
public double Width
{
get { return _width; }
set
{
if (_immutable)
throw new ArgumentException(PSSR.CannotChangeImmutableObject("XPen"));
_dirty = _dirty || _width != value;
_width = value;
}
}
internal double _width;
/// <summary>
/// Gets or sets the line join.
/// </summary>
public XLineJoin LineJoin
{
get { return _lineJoin; }
set
{
if (_immutable)
throw new ArgumentException(PSSR.CannotChangeImmutableObject("XPen"));
_dirty = _dirty || _lineJoin != value;
_lineJoin = value;
}
}
internal XLineJoin _lineJoin;
/// <summary>
/// Gets or sets the line cap.
/// </summary>
public XLineCap LineCap
{
get { return _lineCap; }
set
{
if (_immutable)
throw new ArgumentException(PSSR.CannotChangeImmutableObject("XPen"));
_dirty = _dirty || _lineCap != value;
_lineCap = value;
}
}
internal XLineCap _lineCap;
/// <summary>
/// Gets or sets the miter limit.
/// </summary>
public double MiterLimit
{
get { return _miterLimit; }
set
{
if (_immutable)
throw new ArgumentException(PSSR.CannotChangeImmutableObject("XPen"));
_dirty = _dirty || _miterLimit != value;
_miterLimit = value;
}
}
internal double _miterLimit;
/// <summary>
/// Gets or sets the dash style.
/// </summary>
public XDashStyle DashStyle
{
get { return _dashStyle; }
set
{
if (_immutable)
throw new ArgumentException(PSSR.CannotChangeImmutableObject("XPen"));
_dirty = _dirty || _dashStyle != value;
_dashStyle = value;
}
}
internal XDashStyle _dashStyle;
/// <summary>
/// Gets or sets the dash offset.
/// </summary>
public double DashOffset
{
get { return _dashOffset; }
set
{
if (_immutable)
throw new ArgumentException(PSSR.CannotChangeImmutableObject("XPen"));
_dirty = _dirty || _dashOffset != value;
_dashOffset = value;
}
}
internal double _dashOffset;
/// <summary>
/// Gets or sets the dash pattern.
/// </summary>
public double[] DashPattern
{
get
{
if (_dashPattern == null)
_dashPattern = new double[0];
return _dashPattern;
}
set
{
if (_immutable)
throw new ArgumentException(PSSR.CannotChangeImmutableObject("XPen"));
int length = value.Length;
//if (length == 0)
// throw new ArgumentException("Dash pattern array must not be empty.");
for (int idx = 0; idx < length; idx++)
{
if (value[idx] <= 0)
throw new ArgumentException("Dash pattern value must greater than zero.");
}
_dirty = true;
_dashStyle = XDashStyle.Custom;
_dashPattern = (double[])value.Clone();
}
}
internal double[] _dashPattern;
/// <summary>
/// Gets or sets a value indicating whether the pen enables overprint when used in a PDF document.
/// Experimental, takes effect only on CMYK color mode.
/// </summary>
public bool Overprint
{
get { return _overprint; }
set
{
if (_immutable)
throw new ArgumentException(PSSR.CannotChangeImmutableObject("XPen"));
_overprint = value;
}
}
internal bool _overprint;
bool _dirty = true;
readonly bool _immutable;
}
}
File diff suppressed because it is too large Load Diff
+337
View File
@@ -0,0 +1,337 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.InteropServices;
using PdfSharpCore.Internal;
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Represents a pair of floating point x- and y-coordinates that defines a point
/// in a two-dimensional plane.
/// </summary>
[DebuggerDisplay("{DebuggerDisplay}")]
[Serializable]
[StructLayout(LayoutKind.Sequential)] // TypeConverter(typeof(PointConverter)), ValueSerializer(typeof(PointValueSerializer))]
public struct XPoint : IFormattable
{
/// <summary>
/// Initializes a new instance of the XPoint class with the specified coordinates.
/// </summary>
public XPoint(double x, double y)
{
_x = x;
_y = y;
}
/// <summary>
/// Determines whether two points are equal.
/// </summary>
public static bool operator ==(XPoint point1, XPoint point2)
{
// ReSharper disable CompareOfFloatsByEqualityOperator
return point1._x == point2._x && point1._y == point2._y;
// ReSharper restore CompareOfFloatsByEqualityOperator
}
/// <summary>
/// Determines whether two points are not equal.
/// </summary>
public static bool operator !=(XPoint point1, XPoint point2)
{
return !(point1 == point2);
}
/// <summary>
/// Indicates whether the specified points are equal.
/// </summary>
public static bool Equals(XPoint point1, XPoint point2)
{
return point1.X.Equals(point2.X) && point1.Y.Equals(point2.Y);
}
/// <summary>
/// Indicates whether this instance and a specified object are equal.
/// </summary>
public override bool Equals(object o)
{
if (!(o is XPoint))
return false;
return Equals(this, (XPoint)o);
}
/// <summary>
/// Indicates whether this instance and a specified point are equal.
/// </summary>
public bool Equals(XPoint value)
{
return Equals(this, value);
}
/// <summary>
/// Returns the hash code for this instance.
/// </summary>
public override int GetHashCode()
{
return X.GetHashCode() ^ Y.GetHashCode();
}
/// <summary>
/// Parses the point from a string.
/// </summary>
public static XPoint Parse(string source)
{
CultureInfo cultureInfo = CultureInfo.InvariantCulture;
TokenizerHelper helper = new TokenizerHelper(source, cultureInfo);
string str = helper.NextTokenRequired();
XPoint point = new XPoint(Convert.ToDouble(str, cultureInfo), Convert.ToDouble(helper.NextTokenRequired(), cultureInfo));
helper.LastTokenRequired();
return point;
}
/// <summary>
/// Parses an array of points from a string.
/// </summary>
public static XPoint[] ParsePoints(string value)
{
if (value == null)
throw new ArgumentNullException("value");
// TODO: Reflect reliabel implementation from Avalon
// TODOWPF
string[] values = value.Split(' ');
int count = values.Length;
XPoint[] points = new XPoint[count];
for (int idx = 0; idx < count; idx++)
points[idx] = Parse(values[idx]);
return points;
}
/// <summary>
/// Gets the x-coordinate of this XPoint.
/// </summary>
public double X
{
get { return _x; }
set { _x = value; }
}
double _x;
/// <summary>
/// Gets the x-coordinate of this XPoint.
/// </summary>
public double Y
{
get { return _y; }
set { _y = value; }
}
double _y;
/// <summary>
/// Converts this XPoint to a human readable string.
/// </summary>
public override string ToString()
{
return ConvertToString(null, null);
}
/// <summary>
/// Converts this XPoint to a human readable string.
/// </summary>
public string ToString(IFormatProvider provider)
{
return ConvertToString(null, provider);
}
/// <summary>
/// Converts this XPoint to a human readable string.
/// </summary>
string IFormattable.ToString(string format, IFormatProvider provider)
{
return ConvertToString(format, provider);
}
/// <summary>
/// Implements ToString.
/// </summary>
internal string ConvertToString(string format, IFormatProvider provider)
{
char numericListSeparator = TokenizerHelper.GetNumericListSeparator(provider);
provider = provider ?? CultureInfo.InvariantCulture;
return string.Format(provider, "{1:" + format + "}{0}{2:" + format + "}", new object[] { numericListSeparator, _x, _y });
}
/// <summary>
/// Offsets the x and y value of this point.
/// </summary>
public void Offset(double offsetX, double offsetY)
{
_x += offsetX;
_y += offsetY;
}
/// <summary>
/// Adds a point and a vector.
/// </summary>
public static XPoint operator +(XPoint point, XVector vector)
{
return new XPoint(point._x + vector.X, point._y + vector.Y);
}
/// <summary>
/// Adds a point and a size.
/// </summary>
public static XPoint operator +(XPoint point, XSize size) // TODO: make obsolete
{
return new XPoint(point._x + size.Width, point._y + size.Height);
}
/// <summary>
/// Adds a point and a vector.
/// </summary>
public static XPoint Add(XPoint point, XVector vector)
{
return new XPoint(point._x + vector.X, point._y + vector.Y);
}
/// <summary>
/// Subtracts a vector from a point.
/// </summary>
public static XPoint operator -(XPoint point, XVector vector)
{
return new XPoint(point._x - vector.X, point._y - vector.Y);
}
/// <summary>
/// Subtracts a vector from a point.
/// </summary>
public static XPoint Subtract(XPoint point, XVector vector)
{
return new XPoint(point._x - vector.X, point._y - vector.Y);
}
/// <summary>
/// Subtracts a point from a point.
/// </summary>
public static XVector operator -(XPoint point1, XPoint point2)
{
return new XVector(point1._x - point2._x, point1._y - point2._y);
}
/// <summary>
/// Subtracts a point from a point.
/// </summary>
public static XVector Subtract(XPoint point1, XPoint point2)
{
return new XVector(point1._x - point2._x, point1._y - point2._y);
}
/// <summary>
/// Multiplies a point with a matrix.
/// </summary>
public static XPoint operator *(XPoint point, XMatrix matrix)
{
return matrix.Transform(point);
}
/// <summary>
/// Multiplies a point with a matrix.
/// </summary>
public static XPoint Multiply(XPoint point, XMatrix matrix)
{
return matrix.Transform(point);
}
/// <summary>
/// Multiplies a point with a scalar value.
/// </summary>
public static XPoint operator *(XPoint point, double value)
{
return new XPoint(point._x * value, point._y * value);
}
/// <summary>
/// Multiplies a point with a scalar value.
/// </summary>
public static XPoint operator *(double value, XPoint point)
{
return new XPoint(value * point._x, value * point._y);
}
/// <summary>
/// Performs an explicit conversion from XPoint to XSize.
/// </summary>
public static explicit operator XSize(XPoint point)
{
return new XSize(Math.Abs(point._x), Math.Abs(point._y));
}
/// <summary>
/// Performs an explicit conversion from XPoint to XVector.
/// </summary>
public static explicit operator XVector(XPoint point)
{
return new XVector(point._x, point._y);
}
#if WPF || NETFX_CORE
/// <summary>
/// Performs an implicit conversion from XPoint to Point.
/// </summary>
public static implicit operator SysPoint(XPoint point)
{
return new SysPoint(point.X, point.Y);
}
/// <summary>
/// Performs an implicit conversion from Point to XPoint.
/// </summary>
public static implicit operator XPoint(SysPoint point)
{
return new XPoint(point.X, point.Y);
}
#endif
/// <summary>
/// Gets the DebuggerDisplayAttribute text.
/// </summary>
// ReSharper disable UnusedMember.Local
string DebuggerDisplay
// ReSharper restore UnusedMember.Local
{
get
{
const string format = Config.SignificantFigures10;
return String.Format(CultureInfo.InvariantCulture, "point=({0:" + format + "}, {1:" + format + "})", _x, _y);
}
}
}
}
@@ -0,0 +1,71 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
using System.Collections.Generic;
namespace PdfSharpCore.Drawing
{
///<summary>
/// Makes fonts that are not installed on the system available within the current application domain.<br/>
/// In Silverlight required for all fonts used in PDF documents.
/// </summary>
public sealed class XPrivateFontCollection
{
// This one is global and can only grow. It is not possible to remove fonts that have been added.
/// <summary>
/// Initializes a new instance of the <see cref="XPrivateFontCollection"/> class.
/// </summary>
XPrivateFontCollection()
{
// HACK: Use one global PrivateFontCollection in GDI+
}
/// <summary>
/// Gets the global font collection.
/// </summary>
internal static XPrivateFontCollection Singleton
{
get { return _singleton; }
}
internal static XPrivateFontCollection _singleton = new XPrivateFontCollection();
static string MakeKey(string familyName, XFontStyle style)
{
return MakeKey(familyName, (style & XFontStyle.Bold) != 0, (style & XFontStyle.Italic) != 0);
}
static string MakeKey(string familyName, bool bold, bool italic)
{
return familyName + "#" + (bold ? "b" : "") + (italic ? "i" : "");
}
readonly Dictionary<string, XGlyphTypeface> _typefaces = new Dictionary<string, XGlyphTypeface>();
}
}
@@ -0,0 +1,69 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Ben Askren
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.ComponentModel;
using PdfSharpCore.Internal;
// ReSharper disable RedundantNameQualifier because it is required for hybrid build
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Defines a Brush with a linear gradient.
/// </summary>
public sealed class XRadialGradientBrush : XBaseGradientBrush
{
//internal XRadialGradientBrush();
/// <summary>
/// Initializes a new instance of the <see cref="XRadialGradientBrush"/> class.
/// </summary>
public XRadialGradientBrush(XPoint center1, XPoint center2, double r1, double r2, XColor color1, XColor color2) : base(color1, color2)
{
_center1 = center1;
_center2 = center2;
_r1 = r1;
_r2 = r2;
}
/// <summary>
/// Initializes a new instance of the <see cref="XRadialGradientBrush"/> class.
/// </summary>
public XRadialGradientBrush(XPoint center, double r1, double r2, XColor color1, XColor color2) : base(color1, color2)
{
_center1 = center;
_center2 = center;
_r1 = r1;
_r2 = r2;
}
internal XPoint _center1, _center2;
internal double _r1, _r2;
}
}
+735
View File
@@ -0,0 +1,735 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.InteropServices;
using PdfSharpCore.Internal;
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Stores a set of four floating-point numbers that represent the location and size of a rectangle.
/// </summary>
[DebuggerDisplay("{DebuggerDisplay}")]
[Serializable, StructLayout(LayoutKind.Sequential)] // , ValueSerializer(typeof(RectValueSerializer)), TypeConverter(typeof(RectConverter))]
public struct XRect : IFormattable
{
/// <summary>
/// Initializes a new instance of the XRect class.
/// </summary>
public XRect(double x, double y, double width, double height)
{
if (width < 0 || height < 0)
throw new ArgumentException("WidthAndHeightCannotBeNegative"); //SR.Get(SRID.Size_WidthAndHeightCannotBeNegative, new object[0]));
_x = x;
_y = y;
_width = width;
_height = height;
}
/// <summary>
/// Initializes a new instance of the XRect class.
/// </summary>
public XRect(XPoint point1, XPoint point2)
{
_x = Math.Min(point1.X, point2.X);
_y = Math.Min(point1.Y, point2.Y);
_width = Math.Max(Math.Max(point1.X, point2.X) - _x, 0);
_height = Math.Max(Math.Max(point1.Y, point2.Y) - _y, 0);
}
/// <summary>
/// Initializes a new instance of the XRect class.
/// </summary>
public XRect(XPoint point, XVector vector)
: this(point, point + vector)
{ }
/// <summary>
/// Initializes a new instance of the XRect class.
/// </summary>
public XRect(XPoint location, XSize size)
{
if (size.IsEmpty)
this = s_empty;
else
{
_x = location.X;
_y = location.Y;
_width = size.Width;
_height = size.Height;
}
}
/// <summary>
/// Initializes a new instance of the XRect class.
/// </summary>
public XRect(XSize size)
{
if (size.IsEmpty)
this = s_empty;
else
{
_x = _y = 0;
_width = size.Width;
_height = size.Height;
}
}
/// <summary>
/// Creates a rectangle from for straight lines.
/// </summary>
// ReSharper disable InconsistentNaming
public static XRect FromLTRB(double left, double top, double right, double bottom)
// ReSharper restore InconsistentNaming
{
return new XRect(left, top, right - left, bottom - top);
}
/// <summary>
/// Determines whether the two rectangles are equal.
/// </summary>
public static bool operator ==(XRect rect1, XRect rect2)
{
// ReSharper disable CompareOfFloatsByEqualityOperator
return rect1.X == rect2.X && rect1.Y == rect2.Y && rect1.Width == rect2.Width && rect1.Height == rect2.Height;
// ReSharper restore CompareOfFloatsByEqualityOperator
}
/// <summary>
/// Determines whether the two rectangles are not equal.
/// </summary>
public static bool operator !=(XRect rect1, XRect rect2)
{
return !(rect1 == rect2);
}
/// <summary>
/// Determines whether the two rectangles are equal.
/// </summary>
public static bool Equals(XRect rect1, XRect rect2)
{
if (rect1.IsEmpty)
return rect2.IsEmpty;
return rect1.X.Equals(rect2.X) && rect1.Y.Equals(rect2.Y) && rect1.Width.Equals(rect2.Width) && rect1.Height.Equals(rect2.Height);
}
/// <summary>
/// Determines whether this instance and the specified object are equal.
/// </summary>
public override bool Equals(object o)
{
if (!(o is XRect))
return false;
return Equals(this, (XRect)o);
}
/// <summary>
/// Determines whether this instance and the specified rect are equal.
/// </summary>
public bool Equals(XRect value)
{
return Equals(this, value);
}
/// <summary>
/// Returns the hash code for this instance.
/// </summary>
public override int GetHashCode()
{
if (IsEmpty)
return 0;
return X.GetHashCode() ^ Y.GetHashCode() ^ Width.GetHashCode() ^ Height.GetHashCode();
}
/// <summary>
/// Parses the rectangle from a string.
/// </summary>
public static XRect Parse(string source)
{
XRect empty;
CultureInfo cultureInfo = CultureInfo.InvariantCulture;
TokenizerHelper helper = new TokenizerHelper(source, cultureInfo);
string str = helper.NextTokenRequired();
if (str == "Empty")
empty = Empty;
else
empty = new XRect(Convert.ToDouble(str, cultureInfo), Convert.ToDouble(helper.NextTokenRequired(), cultureInfo), Convert.ToDouble(helper.NextTokenRequired(), cultureInfo), Convert.ToDouble(helper.NextTokenRequired(), cultureInfo));
helper.LastTokenRequired();
return empty;
}
/// <summary>
/// Converts this XRect to a human readable string.
/// </summary>
public override string ToString()
{
return ConvertToString(null, null);
}
/// <summary>
/// Converts this XRect to a human readable string.
/// </summary>
public string ToString(IFormatProvider provider)
{
return ConvertToString(null, provider);
}
/// <summary>
/// Converts this XRect to a human readable string.
/// </summary>
string IFormattable.ToString(string format, IFormatProvider provider)
{
return ConvertToString(format, provider);
}
internal string ConvertToString(string format, IFormatProvider provider)
{
if (IsEmpty)
return "Empty";
char numericListSeparator = TokenizerHelper.GetNumericListSeparator(provider);
provider = provider ?? CultureInfo.InvariantCulture;
// ReSharper disable FormatStringProblem
return string.Format(provider, "{1:" + format + "}{0}{2:" + format + "}{0}{3:" + format + "}{0}{4:" + format + "}", new object[] { numericListSeparator, _x, _y, _width, _height });
// ReSharper restore FormatStringProblem
}
/// <summary>
/// Gets the empty rectangle.
/// </summary>
public static XRect Empty
{
get { return s_empty; }
}
/// <summary>
/// Gets a value indicating whether this instance is empty.
/// </summary>
public bool IsEmpty
{
get { return _width < 0; }
}
/// <summary>
/// Gets or sets the location of the rectangle.
/// </summary>
public XPoint Location
{
get { return new XPoint(_x, _y); }
set
{
if (IsEmpty)
throw new InvalidOperationException("CannotModifyEmptyRect"); //SR.Get(SRID.Rect_CannotModifyEmptyRect, new object[0]));
_x = value.X;
_y = value.Y;
}
}
/// <summary>
/// Gets or sets the size of the rectangle.
/// </summary>
//[Browsable(false)]
public XSize Size
{
get
{
if (IsEmpty)
return XSize.Empty;
return new XSize(_width, _height);
}
set
{
if (value.IsEmpty)
this = s_empty;
else
{
if (IsEmpty)
throw new InvalidOperationException("CannotModifyEmptyRect"); //SR.Get(SRID.Rect_CannotModifyEmptyRect, new object[0]));
_width = value.Width;
_height = value.Height;
}
}
}
/// <summary>
/// Gets or sets the X value of the rectangle.
/// </summary>
public double X
{
get { return _x; }
set
{
if (IsEmpty)
throw new InvalidOperationException("CannotModifyEmptyRect"); //SR.Get(SRID.Rect_CannotModifyEmptyRect, new object[0]));
_x = value;
}
}
double _x;
/// <summary>
/// Gets or sets the Y value of the rectangle.
/// </summary>
public double Y
{
get { return _y; }
set
{
if (IsEmpty)
throw new InvalidOperationException("CannotModifyEmptyRect"); //SR.Get(SRID.Rect_CannotModifyEmptyRect, new object[0]));
_y = value;
}
}
double _y;
/// <summary>
/// Gets or sets the width of the rectangle.
/// </summary>
public double Width
{
get { return _width; }
set
{
if (IsEmpty)
throw new InvalidOperationException("CannotModifyEmptyRect"); //SR.Get(SRID.Rect_CannotModifyEmptyRect, new object[0]));
if (value < 0)
throw new ArgumentException("WidthCannotBeNegative"); //SR.Get(SRID.Size_WidthCannotBeNegative, new object[0]));
_width = value;
}
}
double _width;
/// <summary>
/// Gets or sets the height of the rectangle.
/// </summary>
public double Height
{
get { return _height; }
set
{
if (IsEmpty)
throw new InvalidOperationException("CannotModifyEmptyRect"); //SR.Get(SRID.Rect_CannotModifyEmptyRect, new object[0]));
if (value < 0)
throw new ArgumentException("WidthCannotBeNegative"); //SR.Get(SRID.Size_WidthCannotBeNegative, new object[0]));
_height = value;
}
}
double _height;
/// <summary>
/// Gets the x-axis value of the left side of the rectangle.
/// </summary>
public double Left
{
get { return _x; }
}
/// <summary>
/// Gets the y-axis value of the top side of the rectangle.
/// </summary>
public double Top
{
get { return _y; }
}
/// <summary>
/// Gets the x-axis value of the right side of the rectangle.
/// </summary>
public double Right
{
get
{
if (IsEmpty)
return double.NegativeInfinity;
return _x + _width;
}
}
/// <summary>
/// Gets the y-axis value of the bottom side of the rectangle.
/// </summary>
public double Bottom
{
get
{
if (IsEmpty)
return double.NegativeInfinity;
return _y + _height;
}
}
/// <summary>
/// Gets the position of the top-left corner of the rectangle.
/// </summary>
public XPoint TopLeft
{
get { return new XPoint(Left, Top); }
}
/// <summary>
/// Gets the position of the top-right corner of the rectangle.
/// </summary>
public XPoint TopRight
{
get { return new XPoint(Right, Top); }
}
/// <summary>
/// Gets the position of the bottom-left corner of the rectangle.
/// </summary>
public XPoint BottomLeft
{
get { return new XPoint(Left, Bottom); }
}
/// <summary>
/// Gets the position of the bottom-right corner of the rectangle.
/// </summary>
public XPoint BottomRight
{
get { return new XPoint(Right, Bottom); }
}
/// <summary>
/// Gets the center of the rectangle.
/// </summary>
//[Browsable(false)]
public XPoint Center
{
get { return new XPoint(_x + _width / 2, _y + _height / 2); }
}
/// <summary>
/// Indicates whether the rectangle contains the specified point.
/// </summary>
public bool Contains(XPoint point)
{
return Contains(point.X, point.Y);
}
/// <summary>
/// Indicates whether the rectangle contains the specified point.
/// </summary>
public bool Contains(double x, double y)
{
if (IsEmpty)
return false;
return ContainsInternal(x, y);
}
/// <summary>
/// Indicates whether the rectangle contains the specified rectangle.
/// </summary>
public bool Contains(XRect rect)
{
return !IsEmpty && !rect.IsEmpty &&
_x <= rect._x && _y <= rect._y &&
_x + _width >= rect._x + rect._width && _y + _height >= rect._y + rect._height;
}
/// <summary>
/// Indicates whether the specified rectangle intersects with the current rectangle.
/// </summary>
public bool IntersectsWith(XRect rect)
{
return !IsEmpty && !rect.IsEmpty &&
rect.Left <= Right && rect.Right >= Left &&
rect.Top <= Bottom && rect.Bottom >= Top;
}
/// <summary>
/// Sets current rectangle to the intersection of the current rectangle and the specified rectangle.
/// </summary>
public void Intersect(XRect rect)
{
if (!IntersectsWith(rect))
this = Empty;
else
{
double left = Math.Max(Left, rect.Left);
double top = Math.Max(Top, rect.Top);
_width = Math.Max(Math.Min(Right, rect.Right) - left, 0.0);
_height = Math.Max(Math.Min(Bottom, rect.Bottom) - top, 0.0);
_x = left;
_y = top;
}
}
/// <summary>
/// Returns the intersection of two rectangles.
/// </summary>
public static XRect Intersect(XRect rect1, XRect rect2)
{
rect1.Intersect(rect2);
return rect1;
}
/// <summary>
/// Sets current rectangle to the union of the current rectangle and the specified rectangle.
/// </summary>
public void Union(XRect rect)
{
// ReSharper disable CompareOfFloatsByEqualityOperator
if (IsEmpty)
this = rect;
else if (!rect.IsEmpty)
{
double left = Math.Min(Left, rect.Left);
double top = Math.Min(Top, rect.Top);
if (rect.Width == Double.PositiveInfinity || Width == Double.PositiveInfinity)
_width = Double.PositiveInfinity;
else
{
double right = Math.Max(Right, rect.Right);
_width = Math.Max(right - left, 0.0);
}
if (rect.Height == Double.PositiveInfinity || _height == Double.PositiveInfinity)
_height = Double.PositiveInfinity;
else
{
double bottom = Math.Max(Bottom, rect.Bottom);
_height = Math.Max(bottom - top, 0.0);
}
_x = left;
_y = top;
}
// ReSharper restore CompareOfFloatsByEqualityOperator
}
/// <summary>
/// Returns the union of two rectangles.
/// </summary>
public static XRect Union(XRect rect1, XRect rect2)
{
rect1.Union(rect2);
return rect1;
}
/// <summary>
/// Sets current rectangle to the union of the current rectangle and the specified point.
/// </summary>
public void Union(XPoint point)
{
Union(new XRect(point, point));
}
/// <summary>
/// Returns the intersection of a rectangle and a point.
/// </summary>
public static XRect Union(XRect rect, XPoint point)
{
rect.Union(new XRect(point, point));
return rect;
}
/// <summary>
/// Moves a rectangle by the specified amount.
/// </summary>
public void Offset(XVector offsetVector)
{
if (IsEmpty)
throw new InvalidOperationException("CannotCallMethod"); //SR.Get(SRID.Rect_CannotCallMethod, new object[0]));
_x += offsetVector.X;
_y += offsetVector.Y;
}
/// <summary>
/// Moves a rectangle by the specified amount.
/// </summary>
public void Offset(double offsetX, double offsetY)
{
if (IsEmpty)
throw new InvalidOperationException("CannotCallMethod"); //SR.Get(SRID.Rect_CannotCallMethod, new object[0]));
_x += offsetX;
_y += offsetY;
}
/// <summary>
/// Returns a rectangle that is offset from the specified rectangle by using the specified vector.
/// </summary>
public static XRect Offset(XRect rect, XVector offsetVector)
{
rect.Offset(offsetVector.X, offsetVector.Y);
return rect;
}
/// <summary>
/// Returns a rectangle that is offset from the specified rectangle by using specified horizontal and vertical amounts.
/// </summary>
public static XRect Offset(XRect rect, double offsetX, double offsetY)
{
rect.Offset(offsetX, offsetY);
return rect;
}
/// <summary>
/// Translates the rectangle by adding the specified point.
/// </summary>
//[Obsolete("Use Offset.")]
public static XRect operator +(XRect rect, XPoint point)
{
return new XRect(rect._x + point.X, rect.Y + point.Y, rect._width, rect._height);
}
/// <summary>
/// Translates the rectangle by subtracting the specified point.
/// </summary>
//[Obsolete("Use Offset.")]
public static XRect operator -(XRect rect, XPoint point)
{
return new XRect(rect._x - point.X, rect.Y - point.Y, rect._width, rect._height);
}
/// <summary>
/// Expands the rectangle by using the specified Size, in all directions.
/// </summary>
public void Inflate(XSize size)
{
Inflate(size.Width, size.Height);
}
/// <summary>
/// Expands or shrinks the rectangle by using the specified width and height amounts, in all directions.
/// </summary>
public void Inflate(double width, double height)
{
if (IsEmpty)
throw new InvalidOperationException("CannotCallMethod"); //SR.Get(SRID.Rect_CannotCallMethod, new object[0]));
_x -= width;
_y -= height;
_width += width;
_width += width;
_height += height;
_height += height;
if (_width < 0 || _height < 0)
this = s_empty;
}
/// <summary>
/// Returns the rectangle that results from expanding the specified rectangle by the specified Size, in all directions.
/// </summary>
public static XRect Inflate(XRect rect, XSize size)
{
rect.Inflate(size.Width, size.Height);
return rect;
}
/// <summary>
/// Creates a rectangle that results from expanding or shrinking the specified rectangle by the specified width and height amounts, in all directions.
/// </summary>
public static XRect Inflate(XRect rect, double width, double height)
{
rect.Inflate(width, height);
return rect;
}
/// <summary>
/// Returns the rectangle that results from applying the specified matrix to the specified rectangle.
/// </summary>
public static XRect Transform(XRect rect, XMatrix matrix)
{
XMatrix.MatrixHelper.TransformRect(ref rect, ref matrix);
return rect;
}
/// <summary>
/// Transforms the rectangle by applying the specified matrix.
/// </summary>
public void Transform(XMatrix matrix)
{
XMatrix.MatrixHelper.TransformRect(ref this, ref matrix);
}
/// <summary>
/// Multiplies the size of the current rectangle by the specified x and y values.
/// </summary>
public void Scale(double scaleX, double scaleY)
{
if (!IsEmpty)
{
_x *= scaleX;
_y *= scaleY;
_width *= scaleX;
_height *= scaleY;
if (scaleX < 0)
{
_x += _width;
_width *= -1.0;
}
if (scaleY < 0)
{
_y += _height;
_height *= -1.0;
}
}
}
bool ContainsInternal(double x, double y)
{
return x >= _x && x - _width <= _x && y >= _y && y - _height <= _y;
}
static XRect CreateEmptyRect()
{
XRect rect = new XRect();
rect._x = double.PositiveInfinity;
rect._y = double.PositiveInfinity;
rect._width = double.NegativeInfinity;
rect._height = double.NegativeInfinity;
return rect;
}
static XRect()
{
s_empty = CreateEmptyRect();
}
private static readonly XRect s_empty;
/// <summary>
/// Gets the DebuggerDisplayAttribute text.
/// </summary>
/// <value>The debugger display.</value>
// ReSharper disable UnusedMember.Local
string DebuggerDisplay
// ReSharper restore UnusedMember.Local
{
get
{
const string format = Config.SignificantFigures10;
return String.Format(CultureInfo.InvariantCulture,
"rect=({0:" + format + "}, {1:" + format + "}, {2:" + format + "}, {3:" + format + "})",
_x, _y, _width, _height);
}
}
}
}
+280
View File
@@ -0,0 +1,280 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.InteropServices;
using PdfSharpCore.Internal;
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Represents a pair of floating-point numbers, typically the width and height of a
/// graphical object.
/// </summary>
[DebuggerDisplay("{DebuggerDisplay}")]
[Serializable, StructLayout(LayoutKind.Sequential)] //, ValueSerializer(typeof(SizeValueSerializer)), TypeConverter(typeof(SizeConverter))]
public struct XSize : IFormattable
{
/// <summary>
/// Initializes a new instance of the XPoint class with the specified values.
/// </summary>
public XSize(double width, double height)
{
if (width < 0 || height < 0)
throw new ArgumentException("WidthAndHeightCannotBeNegative"); //SR.Get(SRID.Size_WidthAndHeightCannotBeNegative, new object[0]));
_width = width;
_height = height;
}
/// <summary>
/// Determines whether two size objects are equal.
/// </summary>
public static bool operator ==(XSize size1, XSize size2)
{
// ReSharper disable CompareOfFloatsByEqualityOperator
return size1.Width == size2.Width && size1.Height == size2.Height;
// ReSharper restore CompareOfFloatsByEqualityOperator
}
/// <summary>
/// Determines whether two size objects are not equal.
/// </summary>
public static bool operator !=(XSize size1, XSize size2)
{
return !(size1 == size2);
}
/// <summary>
/// Indicates whether this two instance are equal.
/// </summary>
public static bool Equals(XSize size1, XSize size2)
{
if (size1.IsEmpty)
return size2.IsEmpty;
return size1.Width.Equals(size2.Width) && size1.Height.Equals(size2.Height);
}
/// <summary>
/// Indicates whether this instance and a specified object are equal.
/// </summary>
public override bool Equals(object o)
{
if (!(o is XSize))
return false;
return Equals(this, (XSize)o);
}
/// <summary>
/// Indicates whether this instance and a specified size are equal.
/// </summary>
public bool Equals(XSize value)
{
return Equals(this, value);
}
/// <summary>
/// Returns the hash code for this instance.
/// </summary>
public override int GetHashCode()
{
if (IsEmpty)
return 0;
return Width.GetHashCode() ^ Height.GetHashCode();
}
/// <summary>
/// Parses the size from a string.
/// </summary>
public static XSize Parse(string source)
{
XSize empty;
CultureInfo cultureInfo = CultureInfo.InvariantCulture;
TokenizerHelper helper = new TokenizerHelper(source, cultureInfo);
string str = helper.NextTokenRequired();
if (str == "Empty")
empty = Empty;
else
empty = new XSize(Convert.ToDouble(str, cultureInfo), Convert.ToDouble(helper.NextTokenRequired(), cultureInfo));
helper.LastTokenRequired();
return empty;
}
/// <summary>
/// Converts this XSize to an XPoint.
/// </summary>
public XPoint ToXPoint()
{
return new XPoint(_width, _height);
}
/// <summary>
/// Converts this XSize to an XVector.
/// </summary>
public XVector ToXVector()
{
return new XVector(_width, _height);
}
/// <summary>
/// Converts this XSize to a human readable string.
/// </summary>
public override string ToString()
{
return ConvertToString(null, null);
}
/// <summary>
/// Converts this XSize to a human readable string.
/// </summary>
public string ToString(IFormatProvider provider)
{
return ConvertToString(null, provider);
}
/// <summary>
/// Converts this XSize to a human readable string.
/// </summary>
string IFormattable.ToString(string format, IFormatProvider provider)
{
return ConvertToString(format, provider);
}
internal string ConvertToString(string format, IFormatProvider provider)
{
if (IsEmpty)
return "Empty";
char numericListSeparator = TokenizerHelper.GetNumericListSeparator(provider);
provider = provider ?? CultureInfo.InvariantCulture;
// ReSharper disable FormatStringProblem
return string.Format(provider, "{1:" + format + "}{0}{2:" + format + "}", new object[] { numericListSeparator, _width, _height });
// ReSharper restore FormatStringProblem
}
/// <summary>
/// Returns an empty size, i.e. a size with a width or height less than 0.
/// </summary>
public static XSize Empty
{
get { return s_empty; }
}
static readonly XSize s_empty;
/// <summary>
/// Gets a value indicating whether this instance is empty.
/// </summary>
public bool IsEmpty
{
get { return _width < 0; }
}
/// <summary>
/// Gets or sets the width.
/// </summary>
public double Width
{
get { return _width; }
set
{
if (IsEmpty)
throw new InvalidOperationException("CannotModifyEmptySize"); //SR.Get(SRID.Size_CannotModifyEmptySize, new object[0]));
if (value < 0)
throw new ArgumentException("WidthCannotBeNegative"); //SR.Get(SRID.Size_WidthCannotBeNegative, new object[0]));
_width = value;
}
}
double _width;
/// <summary>
/// Gets or sets the height.
/// </summary>
public double Height
{
get { return _height; }
set
{
if (IsEmpty)
throw new InvalidOperationException("CannotModifyEmptySize"); // SR.Get(SRID.Size_CannotModifyEmptySize, new object[0]));
if (value < 0)
throw new ArgumentException("HeightCannotBeNegative"); //SR.Get(SRID.Size_HeightCannotBeNegative, new object[0]));
_height = value;
}
}
double _height;
/// <summary>
/// Performs an explicit conversion from XSize to XVector.
/// </summary>
public static explicit operator XVector(XSize size)
{
return new XVector(size._width, size._height);
}
/// <summary>
/// Performs an explicit conversion from XSize to XPoint.
/// </summary>
public static explicit operator XPoint(XSize size)
{
return new XPoint(size._width, size._height);
}
private static XSize CreateEmptySize()
{
XSize size = new XSize();
size._width = double.NegativeInfinity;
size._height = double.NegativeInfinity;
return size;
}
static XSize()
{
s_empty = CreateEmptySize();
}
/// <summary>
/// Gets the DebuggerDisplayAttribute text.
/// </summary>
/// <value>The debugger display.</value>
// ReSharper disable UnusedMember.Local
string DebuggerDisplay
// ReSharper restore UnusedMember.Local
{
get
{
const string format = Config.SignificantFigures10;
return String.Format(CultureInfo.InvariantCulture,
"size=({2}{0:" + format + "}, {1:" + format + "})",
_width, _height, IsEmpty ? "Empty " : "");
}
}
}
}
+98
View File
@@ -0,0 +1,98 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
using System;
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Defines a single color object used to fill shapes and draw text.
/// </summary>
public sealed class XSolidBrush : XBrush
{
/// <summary>
/// Initializes a new instance of the <see cref="XSolidBrush"/> class.
/// </summary>
public XSolidBrush()
{ }
/// <summary>
/// Initializes a new instance of the <see cref="XSolidBrush"/> class.
/// </summary>
public XSolidBrush(XColor color)
: this(color, false)
{ }
internal XSolidBrush(XColor color, bool immutable)
{
_color = color;
_immutable = immutable;
}
/// <summary>
/// Initializes a new instance of the <see cref="XSolidBrush"/> class.
/// </summary>
public XSolidBrush(XSolidBrush brush)
{
_color = brush.Color;
}
/// <summary>
/// Gets or sets the color of this brush.
/// </summary>
public XColor Color
{
get { return _color; }
set
{
if (_immutable)
throw new ArgumentException(PSSR.CannotChangeImmutableObject("XSolidBrush"));
_color = value;
}
}
internal XColor _color;
/// <summary>
/// Gets or sets a value indicating whether the brush enables overprint when used in a PDF document.
/// Experimental, takes effect only on CMYK color mode.
/// </summary>
public bool Overprint
{
get { return _overprint; }
set
{
if (_immutable)
throw new ArgumentException(PSSR.CannotChangeImmutableObject("XSolidBrush"));
_overprint = value;
}
}
internal bool _overprint;
readonly bool _immutable;
}
}
+93
View File
@@ -0,0 +1,93 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
using System;
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Represents the text layout information.
/// </summary>
public class XStringFormat
{
/// <summary>
/// Initializes a new instance of the <see cref="XStringFormat"/> class.
/// </summary>
public XStringFormat()
{
}
//TODO public StringFormat(StringFormat format);
//public StringFormat(StringFormatFlags options);
//public StringFormat(StringFormatFlags options, int language);
//public object Clone();
//public void Dispose();
//private void Dispose(bool disposing);
//protected override void Finalize();
//public float[] GetTabStops(out float firstTabOffset);
//public void SetDigitSubstitution(int language, StringDigitSubstitute substitute);
//public void SetMeasurableCharacterRanges(CharacterRange[] ranges);
//public void SetTabStops(float firstTabOffset, float[] tabStops);
//public override string ToString();
/// <summary>
/// Gets or sets horizontal text alignment information.
/// </summary>
public XStringAlignment Alignment
{
get { return _alignment; }
set
{
_alignment = value;
}
}
XStringAlignment _alignment;
//public int DigitSubstitutionLanguage { get; }
//public StringDigitSubstitute DigitSubstitutionMethod { get; }
//public StringFormatFlags FormatFlags { get; set; }
//public static StringFormat GenericDefault { get; }
//public static StringFormat GenericTypographic { get; }
//public HotkeyPrefix HotkeyPrefix { get; set; }
/// <summary>
/// Gets or sets the line alignment.
/// </summary>
public XLineAlignment LineAlignment
{
get { return _lineAlignment; }
set
{
_lineAlignment = value;
}
}
XLineAlignment _lineAlignment;
}
}
+227
View File
@@ -0,0 +1,227 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Represents predefined text layouts.
/// </summary>
public static class XStringFormats
{
/// <summary>
/// Gets a new XStringFormat object that aligns the text left on the base line.
/// This is the same as BaseLineLeft.
/// </summary>
public static XStringFormat Default
{
get { return BaseLineLeft; }
}
/// <summary>
/// Gets a new XStringFormat object that aligns the text left on the base line.
/// This is the same as Default.
/// </summary>
public static XStringFormat BaseLineLeft
{
get
{
// Create new format to allow changes.
XStringFormat format = new XStringFormat();
format.Alignment = XStringAlignment.Near;
format.LineAlignment = XLineAlignment.BaseLine;
return format;
}
}
/// <summary>
/// Gets a new XStringFormat object that aligns the text top left of the layout rectangle.
/// </summary>
public static XStringFormat TopLeft
{
get
{
// Create new format to allow changes.
XStringFormat format = new XStringFormat();
format.Alignment = XStringAlignment.Near;
format.LineAlignment = XLineAlignment.Near;
return format;
}
}
/// <summary>
/// Gets a new XStringFormat object that aligns the text center left of the layout rectangle.
/// </summary>
public static XStringFormat CenterLeft
{
get
{
// Create new format to allow changes.
XStringFormat format = new XStringFormat();
format.Alignment = XStringAlignment.Near;
format.LineAlignment = XLineAlignment.Center;
return format;
}
}
/// <summary>
/// Gets a new XStringFormat object that aligns the text bottom left of the layout rectangle.
/// </summary>
public static XStringFormat BottomLeft
{
get
{
// Create new format to allow changes.
XStringFormat format = new XStringFormat();
format.Alignment = XStringAlignment.Near;
format.LineAlignment = XLineAlignment.Far;
return format;
}
}
/// <summary>
/// Gets a new XStringFormat object that centers the text in the middle of the base line.
/// </summary>
public static XStringFormat BaseLineCenter
{
get
{
// Create new format to allow changes.
XStringFormat format = new XStringFormat();
format.Alignment = XStringAlignment.Center;
format.LineAlignment = XLineAlignment.BaseLine;
return format;
}
}
/// <summary>
/// Gets a new XStringFormat object that centers the text at the top of the layout rectangle.
/// </summary>
public static XStringFormat TopCenter
{
get
{
// Create new format to allow changes.
XStringFormat format = new XStringFormat();
format.Alignment = XStringAlignment.Center;
format.LineAlignment = XLineAlignment.Near;
return format;
}
}
/// <summary>
/// Gets a new XStringFormat object that centers the text in the middle of the layout rectangle.
/// </summary>
public static XStringFormat Center
{
get
{
// Create new format to allow changes.
XStringFormat format = new XStringFormat();
format.Alignment = XStringAlignment.Center;
format.LineAlignment = XLineAlignment.Center;
return format;
}
}
/// <summary>
/// Gets a new XStringFormat object that centers the text at the bottom of the layout rectangle.
/// </summary>
public static XStringFormat BottomCenter
{
get
{
// Create new format to allow changes.
XStringFormat format = new XStringFormat();
format.Alignment = XStringAlignment.Center;
format.LineAlignment = XLineAlignment.Far;
return format;
}
}
/// <summary>
/// Gets a new XStringFormat object that aligns the text in right on the base line.
/// </summary>
public static XStringFormat BaseLineRight
{
get
{
// Create new format to allow changes.
XStringFormat format = new XStringFormat();
format.Alignment = XStringAlignment.Far;
format.LineAlignment = XLineAlignment.BaseLine;
return format;
}
}
/// <summary>
/// Gets a new XStringFormat object that aligns the text top right of the layout rectangle.
/// </summary>
public static XStringFormat TopRight
{
get
{
// Create new format to allow changes.
XStringFormat format = new XStringFormat();
format.Alignment = XStringAlignment.Far;
format.LineAlignment = XLineAlignment.Near;
return format;
}
}
/// <summary>
/// Gets a new XStringFormat object that aligns the text center right of the layout rectangle.
/// </summary>
public static XStringFormat CenterRight
{
get
{
// Create new format to allow changes.
XStringFormat format = new XStringFormat();
format.Alignment = XStringAlignment.Far;
format.LineAlignment = XLineAlignment.Center;
return format;
}
}
/// <summary>
/// Gets a new XStringFormat object that aligns the text at the bottom right of the layout rectangle.
/// </summary>
public static XStringFormat BottomRight
{
get
{
// Create new format to allow changes.
XStringFormat format = new XStringFormat();
format.Alignment = XStringAlignment.Far;
format.LineAlignment = XLineAlignment.Far;
return format;
}
}
}
}
+74
View File
@@ -0,0 +1,74 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
namespace PdfSharpCore.Drawing
{
#if true_ // Not yet used
/// <summary>
/// no: Specifies a physical font face that corresponds to a font file on the disk or in memory.
/// </summary>
[DebuggerDisplay("{DebuggerDisplay}")]
internal class XTypeface_not_yet_used
{
public XTypeface_not_yet_used(XFontFamily family, XFontStyle style)
{
_family = family;
_style = style;
}
public XFontFamily Family
{
get { return _family; }
}
XFontFamily _family;
public XFontStyle Style
{
get { return _style; }
}
XFontStyle _style;
public bool TryGetGlyphTypeface(out XGlyphTypeface glyphTypeface)
{
glyphTypeface = null;
return false;
}
/// <summary>
/// Gets the DebuggerDisplayAttribute text.
/// </summary>
// ReSharper disable UnusedMember.Local
string DebuggerDisplay
// ReSharper restore UnusedMember.Local
{
get { return string.Format(CultureInfo.InvariantCulture, "XTypeface"); }
}
}
#endif
}
+593
View File
@@ -0,0 +1,593 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.Diagnostics;
using System.Globalization;
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Represents a value and its unit of measure. The structure converts implicitly from and to
/// double with a value measured in point.
/// </summary>
[DebuggerDisplay("{DebuggerDisplay}")]
public struct XUnit : IFormattable
{
internal const double PointFactor = 1;
internal const double InchFactor = 72;
internal const double MillimeterFactor = 72 / 25.4;
internal const double CentimeterFactor = 72 / 2.54;
internal const double PresentationFactor = 72 / 96.0;
internal const double PointFactorWpf = 96 / 72.0;
internal const double InchFactorWpf = 96;
internal const double MillimeterFactorWpf = 96 / 25.4;
internal const double CentimeterFactorWpf = 96 / 2.54;
internal const double PresentationFactorWpf = 1;
/// <summary>
/// Initializes a new instance of the XUnit class with type set to point.
/// </summary>
public XUnit(double point)
{
_value = point;
_type = XGraphicsUnit.Point;
}
/// <summary>
/// Initializes a new instance of the XUnit class.
/// </summary>
public XUnit(double value, XGraphicsUnit type)
{
if (!Enum.IsDefined(typeof(XGraphicsUnit), type))
throw new ArgumentException("type");
_value = value;
_type = type;
}
/// <summary>
/// Gets the raw value of the object without any conversion.
/// To determine the XGraphicsUnit use property <code>Type</code>.
/// To get the value in point use the implicit conversion to double.
/// </summary>
public double Value
{
get { return _value; }
}
/// <summary>
/// Gets the unit of measure.
/// </summary>
public XGraphicsUnit Type
{
get { return _type; }
}
/// <summary>
/// Gets or sets the value in point.
/// </summary>
public double Point
{
get
{
switch (_type)
{
case XGraphicsUnit.Point:
return _value;
case XGraphicsUnit.Inch:
return _value * 72;
case XGraphicsUnit.Millimeter:
return _value * 72 / 25.4;
case XGraphicsUnit.Centimeter:
return _value * 72 / 2.54;
case XGraphicsUnit.Presentation:
return _value * 72 / 96;
default:
throw new InvalidCastException();
}
}
set
{
_value = value;
_type = XGraphicsUnit.Point;
}
}
/// <summary>
/// Gets or sets the value in inch.
/// </summary>
public double Inch
{
get
{
switch (_type)
{
case XGraphicsUnit.Point:
return _value / 72;
case XGraphicsUnit.Inch:
return _value;
case XGraphicsUnit.Millimeter:
return _value / 25.4;
case XGraphicsUnit.Centimeter:
return _value / 2.54;
case XGraphicsUnit.Presentation:
return _value / 96;
default:
throw new InvalidCastException();
}
}
set
{
_value = value;
_type = XGraphicsUnit.Inch;
}
}
/// <summary>
/// Gets or sets the value in millimeter.
/// </summary>
public double Millimeter
{
get
{
switch (_type)
{
case XGraphicsUnit.Point:
return _value * 25.4 / 72;
case XGraphicsUnit.Inch:
return _value * 25.4;
case XGraphicsUnit.Millimeter:
return _value;
case XGraphicsUnit.Centimeter:
return _value * 10;
case XGraphicsUnit.Presentation:
return _value * 25.4 / 96;
default:
throw new InvalidCastException();
}
}
set
{
_value = value;
_type = XGraphicsUnit.Millimeter;
}
}
/// <summary>
/// Gets or sets the value in centimeter.
/// </summary>
public double Centimeter
{
get
{
switch (_type)
{
case XGraphicsUnit.Point:
return _value * 2.54 / 72;
case XGraphicsUnit.Inch:
return _value * 2.54;
case XGraphicsUnit.Millimeter:
return _value / 10;
case XGraphicsUnit.Centimeter:
return _value;
case XGraphicsUnit.Presentation:
return _value * 2.54 / 96;
default:
throw new InvalidCastException();
}
}
set
{
_value = value;
_type = XGraphicsUnit.Centimeter;
}
}
/// <summary>
/// Gets or sets the value in presentation units (1/96 inch).
/// </summary>
public double Presentation
{
get
{
switch (_type)
{
case XGraphicsUnit.Point:
return _value * 96 / 72;
case XGraphicsUnit.Inch:
return _value * 96;
case XGraphicsUnit.Millimeter:
return _value * 96 / 25.4;
case XGraphicsUnit.Centimeter:
return _value * 96 / 2.54;
case XGraphicsUnit.Presentation:
return _value;
default:
throw new InvalidCastException();
}
}
set
{
_value = value;
_type = XGraphicsUnit.Point;
}
}
/// <summary>
/// Returns the object as string using the format information.
/// The unit of measure is appended to the end of the string.
/// </summary>
public string ToString(IFormatProvider formatProvider)
{
string valuestring = _value.ToString(formatProvider) + GetSuffix();
return valuestring;
}
/// <summary>
/// Returns the object as string using the specified format and format information.
/// The unit of measure is appended to the end of the string.
/// </summary>
string IFormattable.ToString(string format, IFormatProvider formatProvider)
{
string valuestring = _value.ToString(format, formatProvider) + GetSuffix();
return valuestring;
}
/// <summary>
/// Returns the object as string. The unit of measure is appended to the end of the string.
/// </summary>
public override string ToString()
{
string valuestring = _value.ToString(CultureInfo.InvariantCulture) + GetSuffix();
return valuestring;
}
/// <summary>
/// Returns the unit of measure of the object as a string like 'pt', 'cm', or 'in'.
/// </summary>
string GetSuffix()
{
switch (_type)
{
case XGraphicsUnit.Point:
return "pt";
case XGraphicsUnit.Inch:
return "in";
case XGraphicsUnit.Millimeter:
return "mm";
case XGraphicsUnit.Centimeter:
return "cm";
case XGraphicsUnit.Presentation:
return "pu";
//case XGraphicsUnit.Pica:
// return "pc";
//case XGraphicsUnit.Line:
// return "li";
default:
throw new InvalidCastException();
}
}
/// <summary>
/// Returns an XUnit object. Sets type to point.
/// </summary>
public static XUnit FromPoint(double value)
{
XUnit unit;
unit._value = value;
unit._type = XGraphicsUnit.Point;
return unit;
}
/// <summary>
/// Returns an XUnit object. Sets type to inch.
/// </summary>
public static XUnit FromInch(double value)
{
XUnit unit;
unit._value = value;
unit._type = XGraphicsUnit.Inch;
return unit;
}
/// <summary>
/// Returns an XUnit object. Sets type to millimeters.
/// </summary>
public static XUnit FromMillimeter(double value)
{
XUnit unit;
unit._value = value;
unit._type = XGraphicsUnit.Millimeter;
return unit;
}
/// <summary>
/// Returns an XUnit object. Sets type to centimeters.
/// </summary>
public static XUnit FromCentimeter(double value)
{
XUnit unit;
unit._value = value;
unit._type = XGraphicsUnit.Centimeter;
return unit;
}
/// <summary>
/// Returns an XUnit object. Sets type to Presentation.
/// </summary>
public static XUnit FromPresentation(double value)
{
XUnit unit;
unit._value = value;
unit._type = XGraphicsUnit.Presentation;
return unit;
}
/// <summary>
/// Converts a string to an XUnit object.
/// If the string contains a suffix like 'cm' or 'in' the object will be converted
/// to the appropriate type, otherwise point is assumed.
/// </summary>
public static implicit operator XUnit(string value)
{
XUnit unit;
value = value.Trim();
// HACK for Germans...
value = value.Replace(',', '.');
int count = value.Length;
int valLen = 0;
for (; valLen < count; )
{
char ch = value[valLen];
if (ch == '.' || ch == '-' || ch == '+' || char.IsNumber(ch))
valLen++;
else
break;
}
try
{
unit._value = Double.Parse(value.Substring(0, valLen).Trim(), CultureInfo.InvariantCulture);
}
catch (Exception ex)
{
unit._value = 1;
string message = String.Format("String '{0}' is not a valid value for structure 'XUnit'.", value);
throw new ArgumentException(message, ex);
}
string typeStr = value.Substring(valLen).Trim().ToLower();
unit._type = XGraphicsUnit.Point;
switch (typeStr)
{
case "cm":
unit._type = XGraphicsUnit.Centimeter;
break;
case "in":
unit._type = XGraphicsUnit.Inch;
break;
case "mm":
unit._type = XGraphicsUnit.Millimeter;
break;
case "":
case "pt":
unit._type = XGraphicsUnit.Point;
break;
case "pu": // presentation units
unit._type = XGraphicsUnit.Presentation;
break;
default:
throw new ArgumentException("Unknown unit type: '" + typeStr + "'");
}
return unit;
}
/// <summary>
/// Converts an int to an XUnit object with type set to point.
/// </summary>
public static implicit operator XUnit(int value)
{
XUnit unit;
unit._value = value;
unit._type = XGraphicsUnit.Point;
return unit;
}
/// <summary>
/// Converts a double to an XUnit object with type set to point.
/// </summary>
public static implicit operator XUnit(double value)
{
XUnit unit;
unit._value = value;
unit._type = XGraphicsUnit.Point;
return unit;
}
/// <summary>
/// Returns a double value as point.
/// </summary>
public static implicit operator double(XUnit value)
{
return value.Point;
}
/// <summary>
/// Memberwise comparison. To compare by value,
/// use code like Math.Abs(a.Pt - b.Pt) &lt; 1e-5.
/// </summary>
public static bool operator ==(XUnit value1, XUnit value2)
{
// ReSharper disable CompareOfFloatsByEqualityOperator
return value1._type == value2._type && value1._value == value2._value;
// ReSharper restore CompareOfFloatsByEqualityOperator
}
/// <summary>
/// Memberwise comparison. To compare by value,
/// use code like Math.Abs(a.Pt - b.Pt) &lt; 1e-5.
/// </summary>
public static bool operator !=(XUnit value1, XUnit value2)
{
return !(value1 == value2);
}
/// <summary>
/// Calls base class Equals.
/// </summary>
public override bool Equals(Object obj)
{
if (obj is XUnit)
return this == (XUnit)obj;
return false;
}
/// <summary>
/// Returns the hash code for this instance.
/// </summary>
public override int GetHashCode()
{
// ReSharper disable NonReadonlyFieldInGetHashCode
return _value.GetHashCode() ^ _type.GetHashCode();
// ReSharper restore NonReadonlyFieldInGetHashCode
}
/// <summary>
/// This member is intended to be used by XmlDomainObjectReader only.
/// </summary>
public static XUnit Parse(string value)
{
XUnit unit = value;
return unit;
}
/// <summary>
/// Converts an existing object from one unit into another unit type.
/// </summary>
public void ConvertType(XGraphicsUnit type)
{
if (_type == type)
return;
switch (type)
{
case XGraphicsUnit.Point:
_value = Point;
_type = XGraphicsUnit.Point;
break;
case XGraphicsUnit.Inch:
_value = Inch;
_type = XGraphicsUnit.Inch;
break;
case XGraphicsUnit.Centimeter:
_value = Centimeter;
_type = XGraphicsUnit.Centimeter;
break;
case XGraphicsUnit.Millimeter:
_value = Millimeter;
_type = XGraphicsUnit.Millimeter;
break;
case XGraphicsUnit.Presentation:
_value = Presentation;
_type = XGraphicsUnit.Presentation;
break;
default:
throw new ArgumentException("Unknown unit type: '" + type + "'");
}
}
/// <summary>
/// Represents a unit with all values zero.
/// </summary>
public static readonly XUnit Zero = new XUnit();
double _value;
XGraphicsUnit _type;
/// <summary>
/// Gets the DebuggerDisplayAttribute text.
/// </summary>
/// <value>The debugger display.</value>
// ReSharper disable UnusedMember.Local
string DebuggerDisplay
// ReSharper restore UnusedMember.Local
{
get
{
const string format = Config.SignificantFigures10;
return String.Format(CultureInfo.InvariantCulture, "unit=({0:" + format + "} {1})", _value, GetSuffix());
}
}
}
}
+286
View File
@@ -0,0 +1,286 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.InteropServices;
using PdfSharpCore.Internal;
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Represents a two-dimensional vector specified by x- and y-coordinates.
/// </summary>
[DebuggerDisplay("{DebuggerDisplay}")]
[Serializable]
[StructLayout(LayoutKind.Sequential)]
public struct XVector : IFormattable
{
public XVector(double x, double y)
{
_x = x;
_y = y;
}
public static bool operator ==(XVector vector1, XVector vector2)
{
// ReSharper disable CompareOfFloatsByEqualityOperator
return vector1._x == vector2._x && vector1._y == vector2._y;
// ReSharper restore CompareOfFloatsByEqualityOperator
}
public static bool operator !=(XVector vector1, XVector vector2)
{
// ReSharper disable CompareOfFloatsByEqualityOperator
return vector1._x != vector2._x || vector1._y != vector2._y;
// ReSharper restore CompareOfFloatsByEqualityOperator
}
public static bool Equals(XVector vector1, XVector vector2)
{
if (vector1.X.Equals(vector2.X))
return vector1.Y.Equals(vector2.Y);
return false;
}
public override bool Equals(object o)
{
if (!(o is XVector))
return false;
return Equals(this, (XVector)o);
}
public bool Equals(XVector value)
{
return Equals(this, value);
}
public override int GetHashCode()
{
// ReSharper disable NonReadonlyFieldInGetHashCode
return _x.GetHashCode() ^ _y.GetHashCode();
// ReSharper restore NonReadonlyFieldInGetHashCode
}
public static XVector Parse(string source)
{
TokenizerHelper helper = new TokenizerHelper(source, CultureInfo.InvariantCulture);
string str = helper.NextTokenRequired();
XVector vector = new XVector(Convert.ToDouble(str, CultureInfo.InvariantCulture), Convert.ToDouble(helper.NextTokenRequired(), CultureInfo.InvariantCulture));
helper.LastTokenRequired();
return vector;
}
public double X
{
get { return _x; }
set { _x = value; }
}
double _x;
public double Y
{
get { return _y; }
set { _y = value; }
}
double _y;
public override string ToString()
{
return ConvertToString(null, null);
}
public string ToString(IFormatProvider provider)
{
return ConvertToString(null, provider);
}
string IFormattable.ToString(string format, IFormatProvider provider)
{
return ConvertToString(format, provider);
}
internal string ConvertToString(string format, IFormatProvider provider)
{
const char numericListSeparator = ',';
provider = provider ?? CultureInfo.InvariantCulture;
// ReSharper disable once FormatStringProblem
return string.Format(provider, "{1:" + format + "}{0}{2:" + format + "}", numericListSeparator, _x, _y);
}
public double Length
{
get { return Math.Sqrt(_x * _x + _y * _y); }
}
public double LengthSquared
{
get { return _x * _x + _y * _y; }
}
public void Normalize()
{
this = this / Math.Max(Math.Abs(_x), Math.Abs(_y));
this = this / Length;
}
public static double CrossProduct(XVector vector1, XVector vector2)
{
return vector1._x * vector2._y - vector1._y * vector2._x;
}
public static double AngleBetween(XVector vector1, XVector vector2)
{
double y = vector1._x * vector2._y - vector2._x * vector1._y;
double x = vector1._x * vector2._x + vector1._y * vector2._y;
return (Math.Atan2(y, x) * 57.295779513082323);
}
public static XVector operator -(XVector vector)
{
return new XVector(-vector._x, -vector._y);
}
public void Negate()
{
_x = -_x;
_y = -_y;
}
public static XVector operator +(XVector vector1, XVector vector2)
{
return new XVector(vector1._x + vector2._x, vector1._y + vector2._y);
}
public static XVector Add(XVector vector1, XVector vector2)
{
return new XVector(vector1._x + vector2._x, vector1._y + vector2._y);
}
public static XVector operator -(XVector vector1, XVector vector2)
{
return new XVector(vector1._x - vector2._x, vector1._y - vector2._y);
}
public static XVector Subtract(XVector vector1, XVector vector2)
{
return new XVector(vector1._x - vector2._x, vector1._y - vector2._y);
}
public static XPoint operator +(XVector vector, XPoint point)
{
return new XPoint(point.X + vector._x, point.Y + vector._y);
}
public static XPoint Add(XVector vector, XPoint point)
{
return new XPoint(point.X + vector._x, point.Y + vector._y);
}
public static XVector operator *(XVector vector, double scalar)
{
return new XVector(vector._x * scalar, vector._y * scalar);
}
public static XVector Multiply(XVector vector, double scalar)
{
return new XVector(vector._x * scalar, vector._y * scalar);
}
public static XVector operator *(double scalar, XVector vector)
{
return new XVector(vector._x * scalar, vector._y * scalar);
}
public static XVector Multiply(double scalar, XVector vector)
{
return new XVector(vector._x * scalar, vector._y * scalar);
}
public static XVector operator /(XVector vector, double scalar)
{
return vector * (1.0 / scalar);
}
public static XVector Divide(XVector vector, double scalar)
{
return vector * (1.0 / scalar);
}
public static XVector operator *(XVector vector, XMatrix matrix)
{
return matrix.Transform(vector);
}
public static XVector Multiply(XVector vector, XMatrix matrix)
{
return matrix.Transform(vector);
}
public static double operator *(XVector vector1, XVector vector2)
{
return vector1._x * vector2._x + vector1._y * vector2._y;
}
public static double Multiply(XVector vector1, XVector vector2)
{
return vector1._x * vector2._x + vector1._y * vector2._y;
}
public static double Determinant(XVector vector1, XVector vector2)
{
return vector1._x * vector2._y - vector1._y * vector2._x;
}
public static explicit operator XSize(XVector vector)
{
return new XSize(Math.Abs(vector._x), Math.Abs(vector._y));
}
public static explicit operator XPoint(XVector vector)
{
return new XPoint(vector._x, vector._y);
}
/// <summary>
/// Gets the DebuggerDisplayAttribute text.
/// </summary>
/// <value>The debugger display.</value>
// ReSharper disable UnusedMember.Local
string DebuggerDisplay
// ReSharper restore UnusedMember.Local
{
get
{
const string format = Config.SignificantFigures10;
return string.Format(CultureInfo.InvariantCulture, "vector=({0:" + format + "}, {1:" + format + "})", _x, _y);
}
}
}
}
+54
View File
@@ -0,0 +1,54 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
// ReSharper disable InconsistentNaming
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Indicates how to handle the first point of a path.
/// </summary>
internal enum PathStart
{
/// <summary>
/// Set the current position to the first point.
/// </summary>
MoveTo1st,
/// <summary>
/// Draws a line to the first point.
/// </summary>
LineTo1st,
/// <summary>
/// Ignores the first point.
/// </summary>
Ignore1st,
}
}
+52
View File
@@ -0,0 +1,52 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
namespace PdfSharpCore.Drawing
{
///<summary>
/// Currently not used. Only DeviceRGB is rendered in PDF.
/// </summary>
public enum XColorSpace
{
/// <summary>
/// Identifies the RGB color space.
/// </summary>
Rgb,
/// <summary>
/// Identifies the CMYK color space.
/// </summary>
Cmyk,
/// <summary>
/// Identifies the gray scale color space.
/// </summary>
GrayScale,
}
}
+67
View File
@@ -0,0 +1,67 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Specifies how different clipping regions can be combined.
/// </summary>
public enum XCombineMode // Same values as System.Drawing.Drawing2D.CombineMode.
{
/// <summary>
/// One clipping region is replaced by another.
/// </summary>
Replace = 0,
/// <summary>
/// Two clipping regions are combined by taking their intersection.
/// </summary>
Intersect = 1,
/// <summary>
/// Not yet implemented in PdfSharpCore.
/// </summary>
Union = 2,
/// <summary>
/// Not yet implemented in PdfSharpCore.
/// </summary>
Xor = 3,
/// <summary>
/// Not yet implemented in PdfSharpCore.
/// </summary>
Exclude = 4,
/// <summary>
/// Not yet implemented in PdfSharpCore.
/// </summary>
Complement = 5,
}
}
+67
View File
@@ -0,0 +1,67 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Specifies the style of dashed lines drawn with an XPen object.
/// </summary>
public enum XDashStyle // Same values as System.Drawing.Drawing2D.DashStyle.
{
/// <summary>
/// Specifies a solid line.
/// </summary>
Solid = 0,
/// <summary>
/// Specifies a line consisting of dashes.
/// </summary>
Dash = 1,
/// <summary>
/// Specifies a line consisting of dots.
/// </summary>
Dot = 2,
/// <summary>
/// Specifies a line consisting of a repeating pattern of dash-dot.
/// </summary>
DashDot = 3,
/// <summary>
/// Specifies a line consisting of a repeating pattern of dash-dot-dot.
/// </summary>
DashDotDot = 4,
/// <summary>
/// Specifies a user-defined custom dash style.
/// </summary>
Custom = 5,
}
}
+47
View File
@@ -0,0 +1,47 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Specifies how the interior of a closed path is filled.
/// </summary>
public enum XFillMode // Same values as System.Drawing.FillMode.
{
/// <summary>
/// Specifies the alternate fill mode. Called the 'odd-even rule' in PDF terminology.
/// </summary>
Alternate = 0,
/// <summary>
/// Specifies the winding fill mode. Called the 'nonzero winding number rule' in PDF terminology.
/// </summary>
Winding = 1,
}
}
+74
View File
@@ -0,0 +1,74 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
using System;
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Specifies style information applied to text.
/// </summary>
[Flags]
public enum XFontStyle // Same values as System.Drawing.FontStyle.
{
/// <summary>
/// Normal text.
/// </summary>
Regular = XGdiFontStyle.Regular,
/// <summary>
/// Bold text.
/// </summary>
Bold = XGdiFontStyle.Bold,
/// <summary>
/// Italic text.
/// </summary>
Italic = XGdiFontStyle.Italic,
/// <summary>
/// Bold and italic text.
/// </summary>
BoldItalic = XGdiFontStyle.BoldItalic,
/// <summary>
/// Underlined text.
/// </summary>
Underline = XGdiFontStyle.Underline,
/// <summary>
/// Text with a line through the middle.
/// </summary>
Strikeout = XGdiFontStyle.Strikeout,
// Additional flags:
// BoldSimulation
// ItalicSimulation // It is not ObliqueSimulation, because oblique is what is what you get and this simulates italic.
}
}
+76
View File
@@ -0,0 +1,76 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.Collections.Generic;
using System.Text;
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Backward compatibility.
/// </summary>
[Flags]
internal enum XGdiFontStyle // Same values as System.Drawing.FontStyle.
{
// Must be identical to both:
// System.Drawing.FontStyle and
// PdfSharpCore.Drawing.FontStyle
/// <summary>
/// Normal text.
/// </summary>
Regular = 0,
/// <summary>
/// Bold text.
/// </summary>
Bold = 1,
/// <summary>
/// Italic text.
/// </summary>
Italic = 2,
/// <summary>
/// Bold and italic text.
/// </summary>
BoldItalic = 3,
/// <summary>
/// Underlined text.
/// </summary>
Underline = 4,
/// <summary>
/// Text with a line through the middle.
/// </summary>
Strikeout = 8,
}
}
@@ -0,0 +1,63 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
// ReSharper disable InconsistentNaming
namespace PdfSharpCore.Drawing
{
///<summary>
/// Determines whether rendering based on GDI+ or WPF.
/// For internal use in hybrid build only only.
/// </summary>
enum XGraphicTargetContext
{
// NETFX_CORE_TODO
NONE = 0,
/// <summary>
/// Rendering does not depent on a particular technology.
/// </summary>
CORE = 1,
/// <summary>
/// Renders using GDI+.
/// </summary>
GDI = 2,
/// <summary>
/// Renders using WPF (including Silverlight).
/// </summary>
WPF = 3,
/// <summary>
/// Universal Windows Platform.
/// </summary>
UWP = 10,
}
}
@@ -0,0 +1,48 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Type of the path data.
/// </summary>
internal enum XGraphicsPathItemType
{
Lines,
Beziers,
Curve,
Arc,
Rectangle,
RoundedRectangle,
Ellipse,
Polygon,
CloseFigure,
StartFigure,
}
}
@@ -0,0 +1,52 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Specifies how the content of an existing PDF page and new content is combined.
/// </summary>
public enum XGraphicsPdfPageOptions
{
/// <summary>
/// The new content is inserted behind the old content and any subsequent drawing in done above the existing graphic.
/// </summary>
Append,
/// <summary>
/// The new content is inserted before the old content and any subsequent drawing in done beneath the existing graphic.
/// </summary>
Prepend,
/// <summary>
/// The new content entirely replaces the old content and any subsequent drawing in done on a blank page.
/// </summary>
Replace,
}
}
+62
View File
@@ -0,0 +1,62 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Specifies the unit of measure.
/// </summary>
public enum XGraphicsUnit // NOT the same values as System.Drawing.GraphicsUnit
{
/// <summary>
/// Specifies a printer's point (1/72 inch) as the unit of measure.
/// </summary>
Point = 0, // Must be 0 to let a new XUnit be 0 point.
/// <summary>
/// Specifies the inch (2.54 cm) as the unit of measure.
/// </summary>
Inch = 1,
/// <summary>
/// Specifies the millimeter as the unit of measure.
/// </summary>
Millimeter = 2,
/// <summary>
/// Specifies the centimeter as the unit of measure.
/// </summary>
Centimeter = 3,
/// <summary>
/// Specifies a presentation point (1/96 inch) as the unit of measure.
/// </summary>
Presentation = 4,
}
}
+461
View File
@@ -0,0 +1,461 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
namespace PdfSharpCore.Drawing
{
///<summary>
/// Specifies all pre-defined colors. Used to identify the pre-defined colors and to
/// localize their names.
/// </summary>
public enum XKnownColor
{
/// <summary>A pre-defined color.</summary>
AliceBlue = 0,
/// <summary>A pre-defined color.</summary>
AntiqueWhite = 1,
/// <summary>A pre-defined color.</summary>
Aqua = 2,
/// <summary>A pre-defined color.</summary>
Aquamarine = 3,
/// <summary>A pre-defined color.</summary>
Azure = 4,
/// <summary>A pre-defined color.</summary>
Beige = 5,
/// <summary>A pre-defined color.</summary>
Bisque = 6,
/// <summary>A pre-defined color.</summary>
Black = 7,
/// <summary>A pre-defined color.</summary>
BlanchedAlmond = 8,
/// <summary>A pre-defined color.</summary>
Blue = 9,
/// <summary>A pre-defined color.</summary>
BlueViolet = 10,
/// <summary>A pre-defined color.</summary>
Brown = 11,
/// <summary>A pre-defined color.</summary>
BurlyWood = 12,
/// <summary>A pre-defined color.</summary>
CadetBlue = 13,
/// <summary>A pre-defined color.</summary>
Chartreuse = 14,
/// <summary>A pre-defined color.</summary>
Chocolate = 15,
/// <summary>A pre-defined color.</summary>
Coral = 16,
/// <summary>A pre-defined color.</summary>
CornflowerBlue = 17,
/// <summary>A pre-defined color.</summary>
Cornsilk = 18,
/// <summary>A pre-defined color.</summary>
Crimson = 19,
/// <summary>A pre-defined color.</summary>
Cyan = 20,
/// <summary>A pre-defined color.</summary>
DarkBlue = 21,
/// <summary>A pre-defined color.</summary>
DarkCyan = 22,
/// <summary>A pre-defined color.</summary>
DarkGoldenrod = 23,
/// <summary>A pre-defined color.</summary>
DarkGray = 24,
/// <summary>A pre-defined color.</summary>
DarkGreen = 25,
/// <summary>A pre-defined color.</summary>
DarkKhaki = 26,
/// <summary>A pre-defined color.</summary>
DarkMagenta = 27,
/// <summary>A pre-defined color.</summary>
DarkOliveGreen = 28,
/// <summary>A pre-defined color.</summary>
DarkOrange = 29,
/// <summary>A pre-defined color.</summary>
DarkOrchid = 30,
/// <summary>A pre-defined color.</summary>
DarkRed = 31,
/// <summary>A pre-defined color.</summary>
DarkSalmon = 32,
/// <summary>A pre-defined color.</summary>
DarkSeaGreen = 33,
/// <summary>A pre-defined color.</summary>
DarkSlateBlue = 34,
/// <summary>A pre-defined color.</summary>
DarkSlateGray = 35,
/// <summary>A pre-defined color.</summary>
DarkTurquoise = 36,
/// <summary>A pre-defined color.</summary>
DarkViolet = 37,
/// <summary>A pre-defined color.</summary>
DeepPink = 38,
/// <summary>A pre-defined color.</summary>
DeepSkyBlue = 39,
/// <summary>A pre-defined color.</summary>
DimGray = 40,
/// <summary>A pre-defined color.</summary>
DodgerBlue = 41,
/// <summary>A pre-defined color.</summary>
Firebrick = 42,
/// <summary>A pre-defined color.</summary>
FloralWhite = 43,
/// <summary>A pre-defined color.</summary>
ForestGreen = 44,
/// <summary>A pre-defined color.</summary>
Fuchsia = 45,
/// <summary>A pre-defined color.</summary>
Gainsboro = 46,
/// <summary>A pre-defined color.</summary>
GhostWhite = 47,
/// <summary>A pre-defined color.</summary>
Gold = 48,
/// <summary>A pre-defined color.</summary>
Goldenrod = 49,
/// <summary>A pre-defined color.</summary>
Gray = 50,
/// <summary>A pre-defined color.</summary>
Green = 51,
/// <summary>A pre-defined color.</summary>
GreenYellow = 52,
/// <summary>A pre-defined color.</summary>
Honeydew = 53,
/// <summary>A pre-defined color.</summary>
HotPink = 54,
/// <summary>A pre-defined color.</summary>
IndianRed = 55,
/// <summary>A pre-defined color.</summary>
Indigo = 56,
/// <summary>A pre-defined color.</summary>
Ivory = 57,
/// <summary>A pre-defined color.</summary>
Khaki = 58,
/// <summary>A pre-defined color.</summary>
Lavender = 59,
/// <summary>A pre-defined color.</summary>
LavenderBlush = 60,
/// <summary>A pre-defined color.</summary>
LawnGreen = 61,
/// <summary>A pre-defined color.</summary>
LemonChiffon = 62,
/// <summary>A pre-defined color.</summary>
LightBlue = 63,
/// <summary>A pre-defined color.</summary>
LightCoral = 64,
/// <summary>A pre-defined color.</summary>
LightCyan = 65,
/// <summary>A pre-defined color.</summary>
LightGoldenrodYellow = 66,
/// <summary>A pre-defined color.</summary>
LightGray = 67,
/// <summary>A pre-defined color.</summary>
LightGreen = 68,
/// <summary>A pre-defined color.</summary>
LightPink = 69,
/// <summary>A pre-defined color.</summary>
LightSalmon = 70,
/// <summary>A pre-defined color.</summary>
LightSeaGreen = 71,
/// <summary>A pre-defined color.</summary>
LightSkyBlue = 72,
/// <summary>A pre-defined color.</summary>
LightSlateGray = 73,
/// <summary>A pre-defined color.</summary>
LightSteelBlue = 74,
/// <summary>A pre-defined color.</summary>
LightYellow = 75,
/// <summary>A pre-defined color.</summary>
Lime = 76,
/// <summary>A pre-defined color.</summary>
LimeGreen = 77,
/// <summary>A pre-defined color.</summary>
Linen = 78,
/// <summary>A pre-defined color.</summary>
Magenta = 79,
/// <summary>A pre-defined color.</summary>
Maroon = 80,
/// <summary>A pre-defined color.</summary>
MediumAquamarine = 81,
/// <summary>A pre-defined color.</summary>
MediumBlue = 82,
/// <summary>A pre-defined color.</summary>
MediumOrchid = 83,
/// <summary>A pre-defined color.</summary>
MediumPurple = 84,
/// <summary>A pre-defined color.</summary>
MediumSeaGreen = 85,
/// <summary>A pre-defined color.</summary>
MediumSlateBlue = 86,
/// <summary>A pre-defined color.</summary>
MediumSpringGreen = 87,
/// <summary>A pre-defined color.</summary>
MediumTurquoise = 88,
/// <summary>A pre-defined color.</summary>
MediumVioletRed = 89,
/// <summary>A pre-defined color.</summary>
MidnightBlue = 90,
/// <summary>A pre-defined color.</summary>
MintCream = 91,
/// <summary>A pre-defined color.</summary>
MistyRose = 92,
/// <summary>A pre-defined color.</summary>
Moccasin = 93,
/// <summary>A pre-defined color.</summary>
NavajoWhite = 94,
/// <summary>A pre-defined color.</summary>
Navy = 95,
/// <summary>A pre-defined color.</summary>
OldLace = 96,
/// <summary>A pre-defined color.</summary>
Olive = 97,
/// <summary>A pre-defined color.</summary>
OliveDrab = 98,
/// <summary>A pre-defined color.</summary>
Orange = 99,
/// <summary>A pre-defined color.</summary>
OrangeRed = 100,
/// <summary>A pre-defined color.</summary>
Orchid = 101,
/// <summary>A pre-defined color.</summary>
PaleGoldenrod = 102,
/// <summary>A pre-defined color.</summary>
PaleGreen = 103,
/// <summary>A pre-defined color.</summary>
PaleTurquoise = 104,
/// <summary>A pre-defined color.</summary>
PaleVioletRed = 105,
/// <summary>A pre-defined color.</summary>
PapayaWhip = 106,
/// <summary>A pre-defined color.</summary>
PeachPuff = 107,
/// <summary>A pre-defined color.</summary>
Peru = 108,
/// <summary>A pre-defined color.</summary>
Pink = 109,
/// <summary>A pre-defined color.</summary>
Plum = 110,
/// <summary>A pre-defined color.</summary>
PowderBlue = 111,
/// <summary>A pre-defined color.</summary>
Purple = 112,
/// <summary>A pre-defined color.</summary>
Red = 113,
/// <summary>A pre-defined color.</summary>
RosyBrown = 114,
/// <summary>A pre-defined color.</summary>
RoyalBlue = 115,
/// <summary>A pre-defined color.</summary>
SaddleBrown = 116,
/// <summary>A pre-defined color.</summary>
Salmon = 117,
/// <summary>A pre-defined color.</summary>
SandyBrown = 118,
/// <summary>A pre-defined color.</summary>
SeaGreen = 119,
/// <summary>A pre-defined color.</summary>
SeaShell = 120,
/// <summary>A pre-defined color.</summary>
Sienna = 121,
/// <summary>A pre-defined color.</summary>
Silver = 122,
/// <summary>A pre-defined color.</summary>
SkyBlue = 123,
/// <summary>A pre-defined color.</summary>
SlateBlue = 124,
/// <summary>A pre-defined color.</summary>
SlateGray = 125,
/// <summary>A pre-defined color.</summary>
Snow = 126,
/// <summary>A pre-defined color.</summary>
SpringGreen = 127,
/// <summary>A pre-defined color.</summary>
SteelBlue = 128,
/// <summary>A pre-defined color.</summary>
Tan = 129,
/// <summary>A pre-defined color.</summary>
Teal = 130,
/// <summary>A pre-defined color.</summary>
Thistle = 131,
/// <summary>A pre-defined color.</summary>
Tomato = 132,
/// <summary>A pre-defined color.</summary>
Transparent = 133,
/// <summary>A pre-defined color.</summary>
Turquoise = 134,
/// <summary>A pre-defined color.</summary>
Violet = 135,
/// <summary>A pre-defined color.</summary>
Wheat = 136,
/// <summary>A pre-defined color.</summary>
White = 137,
/// <summary>A pre-defined color.</summary>
WhiteSmoke = 138,
/// <summary>A pre-defined color.</summary>
Yellow = 139,
/// <summary>A pre-defined color.</summary>
YellowGreen = 140,
}
}
@@ -0,0 +1,62 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Specifies the alignment of a text string relative to its layout rectangle
/// </summary>
public enum XLineAlignment // same values as System.Drawing.StringAlignment (except BaseLine)
{
/// <summary>
/// Specifies the text be aligned near the layout.
/// In a left-to-right layout, the near position is left. In a right-to-left layout, the near
/// position is right.
/// </summary>
Near = 0,
/// <summary>
/// Specifies that text is aligned in the center of the layout rectangle.
/// </summary>
Center = 1,
/// <summary>
/// Specifies that text is aligned far from the origin position of the layout rectangle.
/// In a left-to-right layout, the far position is right. In a right-to-left layout, the far
/// position is left.
/// </summary>
Far = 2,
/// <summary>
/// Specifies that text is aligned relative to its base line.
/// With this option the layout rectangle must have a height of 0.
/// </summary>
BaseLine = 3,
}
}
+52
View File
@@ -0,0 +1,52 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Specifies the available cap styles with which an XPen object can start and end a line.
/// </summary>
public enum XLineCap
{
/// <summary>
/// Specifies a flat line cap.
/// </summary>
Flat = 0,
/// <summary>
/// Specifies a round line cap.
/// </summary>
Round = 1,
/// <summary>
/// Specifies a square line cap.
/// </summary>
Square = 2
}
}
+53
View File
@@ -0,0 +1,53 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Specifies how to join consecutive line or curve segments in a figure or subpath.
/// </summary>
public enum XLineJoin
{
/// <summary>
/// Specifies a mitered join. This produces a sharp corner or a clipped corner,
/// depending on whether the length of the miter exceeds the miter limit
/// </summary>
Miter = 0,
/// <summary>
/// Specifies a circular join. This produces a smooth, circular arc between the lines.
/// </summary>
Round = 1,
/// <summary>
/// Specifies a beveled join. This produces a diagonal corner.
/// </summary>
Bevel = 2,
}
}
@@ -0,0 +1,57 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Specifies the direction of a linear gradient.
/// </summary>
public enum XLinearGradientMode // same values as System.Drawing.LinearGradientMode
{
/// <summary>
/// Specifies a gradient from left to right.
/// </summary>
Horizontal = 0,
/// <summary>
/// Specifies a gradient from top to bottom.
/// </summary>
Vertical = 1,
/// <summary>
/// Specifies a gradient from upper left to lower right.
/// </summary>
ForwardDiagonal = 2,
/// <summary>
/// Specifies a gradient from upper right to lower left.
/// </summary>
BackwardDiagonal = 3,
}
}
+47
View File
@@ -0,0 +1,47 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Specifies the order for matrix transform operations.
/// </summary>
public enum XMatrixOrder
{
/// <summary>
/// The new operation is applied before the old operation.
/// </summary>
Prepend = 0,
/// <summary>
/// The new operation is applied after the old operation.
/// </summary>
Append = 1,
}
}
@@ -0,0 +1,51 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
using System;
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Specifies the direction of the y-axis.
/// </summary>
public enum XPageDirection
{
/// <summary>
/// Increasing Y values go downwards. This is the default.
/// </summary>
Downwards = 0,
/// <summary>
/// Increasing Y values go upwards. This is only possible when drawing on a PDF page.
/// It is not implemented when drawing on a System.Drawing.Graphics object.
/// </summary>
[Obsolete("Not implemeted - yagni")]
Upwards = 1, // Possible, but needs a lot of case differentiation - postponed.
}
}
@@ -0,0 +1,73 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
using System;
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Specifies whether smoothing (or antialiasing) is applied to lines and curves
/// and the edges of filled areas.
/// </summary>
[Flags]
public enum XSmoothingMode // same values as System.Drawing.Drawing2D.SmoothingMode
{
// Not used in PDF rendering process.
/// <summary>
/// Specifies an invalid mode.
/// </summary>
Invalid = -1,
/// <summary>
/// Specifies the default mode.
/// </summary>
Default = 0,
/// <summary>
/// Specifies high speed, low quality rendering.
/// </summary>
HighSpeed = 1,
/// <summary>
/// Specifies high quality, low speed rendering.
/// </summary>
HighQuality = 2,
/// <summary>
/// Specifies no antialiasing.
/// </summary>
None = 3,
/// <summary>
/// Specifies antialiased rendering.
/// </summary>
AntiAlias = 4,
}
}
@@ -0,0 +1,56 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Specifies the alignment of a text string relative to its layout rectangle.
/// </summary>
public enum XStringAlignment // Same values as System.Drawing.StringAlignment.
{
/// <summary>
/// Specifies the text be aligned near the layout.
/// In a left-to-right layout, the near position is left. In a right-to-left layout, the near
/// position is right.
/// </summary>
Near = 0,
/// <summary>
/// Specifies that text is aligned in the center of the layout rectangle.
/// </summary>
Center = 1,
/// <summary>
/// Specifies that text is aligned far from the origin position of the layout rectangle.
/// In a left-to-right layout, the far position is right. In a right-to-left layout, the far
/// position is left.
/// </summary>
Far = 2,
}
}
@@ -0,0 +1,60 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
using System;
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Describes the simulation style of a font.
/// </summary>
[Flags]
public enum XStyleSimulations // Identical to WpfStyleSimulations.
{
/// <summary>
/// No font style simulation.
/// </summary>
None = 0,
/// <summary>
/// Bold style simulation.
/// </summary>
BoldSimulation = 1,
/// <summary>
/// Italic style simulation.
/// </summary>
ItalicSimulation = 2,
/// <summary>
/// Bold and Italic style simulation.
/// </summary>
BoldItalicSimulation = ItalicSimulation | BoldSimulation,
}
}
@@ -0,0 +1,47 @@
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
namespace PdfSharpCore.Drawing
{
/// <summary>
/// Defines the direction an elliptical arc is drawn.
/// </summary>
public enum XSweepDirection // Same values as System.Windows.Media.SweepDirection.
{
/// <summary>
/// Specifies that arcs are drawn in a counter clockwise (negative-angle) direction.
/// </summary>
Counterclockwise = 0,
/// <summary>
/// Specifies that arcs are drawn in a clockwise (positive-angle) direction.
/// </summary>
Clockwise = 1,
}
}