Use double in fonts instead of decimals and tidy up remaining decimals

This commit is contained in:
BobLd 2024-03-03 21:59:35 +00:00
parent c25368e5ab
commit ac0276f1bf
32 changed files with 184 additions and 277 deletions

View File

@ -16,7 +16,7 @@
/// <summary> /// <summary>
/// The origin of the coordinates system. /// The origin of the coordinates system.
/// </summary> /// </summary>
public static PdfPoint Origin { get; } = new PdfPoint(0m, 0m); public static PdfPoint Origin { get; } = new PdfPoint(0.0, 0.0);
/// <summary> /// <summary>
/// The X coordinate for this point. (Horizontal axis). /// The X coordinate for this point. (Horizontal axis).
@ -28,16 +28,6 @@
/// </summary> /// </summary>
public double Y { get; } public double Y { get; }
/// <summary>
/// Create a new <see cref="PdfPoint"/> at this position.
/// </summary>
[DebuggerStepThrough]
public PdfPoint(decimal x, decimal y)
{
X = (double)x;
Y = (double)y;
}
/// <summary> /// <summary>
/// Create a new <see cref="PdfPoint"/> at this position. /// Create a new <see cref="PdfPoint"/> at this position.
/// </summary> /// </summary>

View File

@ -11,28 +11,6 @@
private readonly IReadOnlyList<double> rangeArray; private readonly IReadOnlyList<double> rangeArray;
private readonly int startingIndex; private readonly int startingIndex;
/// <summary>
/// Constructor assumes a starting index of 0.
/// </summary>
/// <param name="range">The array that describes the range.</param>
public PdfRange(IEnumerable<decimal> range)
: this(range.Select(v => (double)v), 0)
{
}
/// <summary>
/// Constructor with an index into an array. Because some arrays specify
/// multiple ranges ie [0, 1, 0, 2, 2, 3]. It is convenient for this
/// class to take an index into an array. So if you want this range to
/// represent 0, 2 in the above example then you would say <c>new PDRange(array, 1)</c>.
/// </summary>
/// <param name="range">The array that describes the index</param>
/// <param name="index">The range index into the array for the start of the range.</param>
public PdfRange(IEnumerable<decimal> range, int index)
: this(range.Select(v => (double)v), index)
{
}
/// <summary> /// <summary>
/// Constructor assumes a starting index of 0. /// Constructor assumes a starting index of 0.
/// </summary> /// </summary>

View File

@ -362,14 +362,6 @@
public static TransformationMatrix FromValues(double a, double b, double c, double d) public static TransformationMatrix FromValues(double a, double b, double c, double d)
=> new TransformationMatrix(a, b, 0, c, d, 0, 0, 0, 1); => new TransformationMatrix(a, b, 0, c, d, 0, 0, 0, 1);
/// <summary>
/// Create a new <see cref="TransformationMatrix"/> from the values.
/// </summary>
/// <param name="values">Either all 9 values of the matrix, 6 values in the default PDF order or the 4 values of the top left square.</param>
/// <returns></returns>
public static TransformationMatrix FromArray(decimal[] values)
=> FromArray(values.Select(x => (double)x).ToArray());
/// <summary> /// <summary>
/// Create a new <see cref="TransformationMatrix"/> from the values. /// Create a new <see cref="TransformationMatrix"/> from the values.
/// </summary> /// </summary>

View File

@ -11,7 +11,7 @@
/// <summary> /// <summary>
/// Version of the Adobe Font Metrics specification used to generate this file. /// Version of the Adobe Font Metrics specification used to generate this file.
/// </summary> /// </summary>
public decimal AfmVersion { get; } public double AfmVersion { get; }
/// <summary> /// <summary>
/// Any comments in the file. /// Any comments in the file.
@ -103,38 +103,38 @@
/// <summary> /// <summary>
/// Usually the y-value of the top of capital 'H'. /// Usually the y-value of the top of capital 'H'.
/// </summary> /// </summary>
public decimal CapHeight { get; } public double CapHeight { get; }
/// <summary> /// <summary>
/// Usually the y-value of the top of lowercase 'x'. /// Usually the y-value of the top of lowercase 'x'.
/// </summary> /// </summary>
public decimal XHeight { get; } public double XHeight { get; }
/// <summary> /// <summary>
/// Usually the y-value of the top of lowercase 'd'. /// Usually the y-value of the top of lowercase 'd'.
/// </summary> /// </summary>
public decimal Ascender { get; } public double Ascender { get; }
/// <summary> /// <summary>
/// Usually the y-value of the bottom of lowercase 'p'. /// Usually the y-value of the bottom of lowercase 'p'.
/// </summary> /// </summary>
public decimal Descender { get; } public double Descender { get; }
/// <summary> /// <summary>
/// Distance from the baseline for underlining. /// Distance from the baseline for underlining.
/// </summary> /// </summary>
public decimal UnderlinePosition { get; } public double UnderlinePosition { get; }
/// <summary> /// <summary>
/// Width of the line for underlining. /// Width of the line for underlining.
/// </summary> /// </summary>
public decimal UnderlineThickness { get; } public double UnderlineThickness { get; }
/// <summary> /// <summary>
/// Angle in degrees counter-clockwise from the vertical of the vertical linea. /// Angle in degrees counter-clockwise from the vertical of the vertical linea.
/// Zero for non-italic fonts. /// Zero for non-italic fonts.
/// </summary> /// </summary>
public decimal ItalicAngle { get; } public double ItalicAngle { get; }
/// <summary> /// <summary>
/// If present all characters have this width and height. /// If present all characters have this width and height.
@ -144,12 +144,12 @@
/// <summary> /// <summary>
/// Horizontal stem width. /// Horizontal stem width.
/// </summary> /// </summary>
public decimal HorizontalStemWidth { get; } public double HorizontalStemWidth { get; }
/// <summary> /// <summary>
/// Vertical stem width. /// Vertical stem width.
/// </summary> /// </summary>
public decimal VerticalStemWidth { get; } public double VerticalStemWidth { get; }
/// <summary> /// <summary>
/// Metrics for the individual characters. /// Metrics for the individual characters.
@ -159,7 +159,7 @@
/// <summary> /// <summary>
/// Create a new <see cref="AdobeFontMetrics"/>. /// Create a new <see cref="AdobeFontMetrics"/>.
/// </summary> /// </summary>
public AdobeFontMetrics(decimal afmVersion, IReadOnlyList<string> comments, int metricSets, string fontName, public AdobeFontMetrics(double afmVersion, IReadOnlyList<string> comments, int metricSets, string fontName,
string fullName, string fullName,
string familyName, string familyName,
string weight, string weight,
@ -174,16 +174,16 @@
bool isBaseFont, bool isBaseFont,
AdobeFontMetricsVector vVector, AdobeFontMetricsVector vVector,
bool isFixedV, bool isFixedV,
decimal capHeight, double capHeight,
decimal xHeight, double xHeight,
decimal ascender, double ascender,
decimal descender, double descender,
decimal underlinePosition, double underlinePosition,
decimal underlineThickness, double underlineThickness,
decimal italicAngle, double italicAngle,
AdobeFontMetricsCharacterSize characterWidth, AdobeFontMetricsCharacterSize characterWidth,
decimal horizontalStemWidth, double horizontalStemWidth,
decimal verticalStemWidth, double verticalStemWidth,
IReadOnlyDictionary<string, AdobeFontMetricsIndividualCharacterMetric> characterMetrics) IReadOnlyDictionary<string, AdobeFontMetricsIndividualCharacterMetric> characterMetrics)
{ {
AfmVersion = afmVersion; AfmVersion = afmVersion;

View File

@ -1,13 +1,12 @@
namespace UglyToad.PdfPig.Fonts.AdobeFontMetrics namespace UglyToad.PdfPig.Fonts.AdobeFontMetrics
{ {
using Core;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Core;
using Standard14Fonts;
internal class AdobeFontMetricsBuilder internal class AdobeFontMetricsBuilder
{ {
public decimal AfmVersion { get; } public double AfmVersion { get; }
public List<string> Comments { get; } public List<string> Comments { get; }
@ -37,7 +36,7 @@
/// <summary> /// <summary>
/// Angle in degrees counter-clockwise from vertical of vertical strokes of the font. /// Angle in degrees counter-clockwise from vertical of vertical strokes of the font.
/// </summary> /// </summary>
public decimal ItalicAngle { get; set; } public double ItalicAngle { get; set; }
/// <summary> /// <summary>
/// Whether the font is monospaced or not. /// Whether the font is monospaced or not.
@ -52,12 +51,12 @@
/// <summary> /// <summary>
/// Distance from the baseline for underlining. /// Distance from the baseline for underlining.
/// </summary> /// </summary>
public decimal UnderlinePosition { get; set; } public double UnderlinePosition { get; set; }
/// <summary> /// <summary>
/// The stroke width for underlining. /// The stroke width for underlining.
/// </summary> /// </summary>
public decimal UnderlineThickness { get; set; } public double UnderlineThickness { get; set; }
/// <summary> /// <summary>
/// Version identifier for the font program. /// Version identifier for the font program.
@ -86,32 +85,32 @@
/// <summary> /// <summary>
/// The y-value of the top of a capital H. /// The y-value of the top of a capital H.
/// </summary> /// </summary>
public decimal CapHeight { get; set; } public double CapHeight { get; set; }
/// <summary> /// <summary>
/// The y-value of the top of lowercase x. /// The y-value of the top of lowercase x.
/// </summary> /// </summary>
public decimal XHeight { get; set; } public double XHeight { get; set; }
/// <summary> /// <summary>
/// Generally the y-value of the top of lowercase d. /// Generally the y-value of the top of lowercase d.
/// </summary> /// </summary>
public decimal Ascender { get; set; } public double Ascender { get; set; }
/// <summary> /// <summary>
/// The y-value of the bottom of lowercase p. /// The y-value of the bottom of lowercase p.
/// </summary> /// </summary>
public decimal Descender { get; set; } public double Descender { get; set; }
/// <summary> /// <summary>
/// Width of horizontal stems. /// Width of horizontal stems.
/// </summary> /// </summary>
public decimal StdHw { get; set; } public double StdHw { get; set; }
/// <summary> /// <summary>
/// Width of vertical stems. /// Width of vertical stems.
/// </summary> /// </summary>
public decimal StdVw { get; set; } public double StdVw { get; set; }
public int EscapeCharacter { get; set; } public int EscapeCharacter { get; set; }
@ -123,7 +122,7 @@
public bool IsFixedV { get; set; } public bool IsFixedV { get; set; }
public AdobeFontMetricsBuilder(decimal afmVersion) public AdobeFontMetricsBuilder(double afmVersion)
{ {
AfmVersion = afmVersion; AfmVersion = afmVersion;
Comments = new List<string>(); Comments = new List<string>();

View File

@ -344,7 +344,7 @@ namespace UglyToad.PdfPig.Fonts.AdobeFontMetrics
throw new InvalidFontFormatException($"The AFM file was not valid, it did not start with {StartFontMetrics}."); throw new InvalidFontFormatException($"The AFM file was not valid, it did not start with {StartFontMetrics}.");
} }
var version = ReadDecimal(bytes, stringBuilder); var version = ReadDouble(bytes, stringBuilder);
var builder = new AdobeFontMetricsBuilder(version); var builder = new AdobeFontMetricsBuilder(version);
@ -368,7 +368,7 @@ namespace UglyToad.PdfPig.Fonts.AdobeFontMetrics
builder.Weight = ReadLine(bytes, stringBuilder); builder.Weight = ReadLine(bytes, stringBuilder);
break; break;
case ItalicAngle: case ItalicAngle:
builder.ItalicAngle = ReadDecimal(bytes, stringBuilder); builder.ItalicAngle = ReadDouble(bytes, stringBuilder);
break; break;
case IsFixedPitch: case IsFixedPitch:
builder.IsFixedPitch = ReadBool(bytes, stringBuilder); builder.IsFixedPitch = ReadBool(bytes, stringBuilder);
@ -378,10 +378,10 @@ namespace UglyToad.PdfPig.Fonts.AdobeFontMetrics
ReadDouble(bytes, stringBuilder), ReadDouble(bytes, stringBuilder)); ReadDouble(bytes, stringBuilder), ReadDouble(bytes, stringBuilder));
break; break;
case UnderlinePosition: case UnderlinePosition:
builder.UnderlinePosition = ReadDecimal(bytes, stringBuilder); builder.UnderlinePosition = ReadDouble(bytes, stringBuilder);
break; break;
case UnderlineThickness: case UnderlineThickness:
builder.UnderlineThickness = ReadDecimal(bytes, stringBuilder); builder.UnderlineThickness = ReadDouble(bytes, stringBuilder);
break; break;
case Version: case Version:
builder.Version = ReadLine(bytes, stringBuilder); builder.Version = ReadLine(bytes, stringBuilder);
@ -393,37 +393,37 @@ namespace UglyToad.PdfPig.Fonts.AdobeFontMetrics
builder.EncodingScheme = ReadLine(bytes, stringBuilder); builder.EncodingScheme = ReadLine(bytes, stringBuilder);
break; break;
case MappingScheme: case MappingScheme:
builder.MappingScheme = (int)ReadDecimal(bytes, stringBuilder); builder.MappingScheme = (int)ReadDouble(bytes, stringBuilder);
break; break;
case CharacterSet: case CharacterSet:
builder.CharacterSet = ReadLine(bytes, stringBuilder); builder.CharacterSet = ReadLine(bytes, stringBuilder);
break; break;
case EscChar: case EscChar:
builder.EscapeCharacter = (int) ReadDecimal(bytes, stringBuilder); builder.EscapeCharacter = (int)ReadDouble(bytes, stringBuilder);
break; break;
case Characters: case Characters:
builder.Characters = (int) ReadDecimal(bytes, stringBuilder); builder.Characters = (int)ReadDouble(bytes, stringBuilder);
break; break;
case IsBaseFont: case IsBaseFont:
builder.IsBaseFont = ReadBool(bytes, stringBuilder); builder.IsBaseFont = ReadBool(bytes, stringBuilder);
break; break;
case CapHeight: case CapHeight:
builder.CapHeight = ReadDecimal(bytes, stringBuilder); builder.CapHeight = ReadDouble(bytes, stringBuilder);
break; break;
case XHeight: case XHeight:
builder.XHeight = ReadDecimal(bytes, stringBuilder); builder.XHeight = ReadDouble(bytes, stringBuilder);
break; break;
case Ascender: case Ascender:
builder.Ascender = ReadDecimal(bytes, stringBuilder); builder.Ascender = ReadDouble(bytes, stringBuilder);
break; break;
case Descender: case Descender:
builder.Descender = ReadDecimal(bytes, stringBuilder); builder.Descender = ReadDouble(bytes, stringBuilder);
break; break;
case StdHw: case StdHw:
builder.StdHw = ReadDecimal(bytes, stringBuilder); builder.StdHw = ReadDouble(bytes, stringBuilder);
break; break;
case StdVw: case StdVw:
builder.StdVw = ReadDecimal(bytes, stringBuilder); builder.StdVw = ReadDouble(bytes, stringBuilder);
break; break;
case CharWidth: case CharWidth:
builder.SetCharacterWidth(ReadDouble(bytes, stringBuilder), ReadDouble(bytes, stringBuilder)); builder.SetCharacterWidth(ReadDouble(bytes, stringBuilder), ReadDouble(bytes, stringBuilder));
@ -435,7 +435,7 @@ namespace UglyToad.PdfPig.Fonts.AdobeFontMetrics
builder.IsFixedV = ReadBool(bytes, stringBuilder); builder.IsFixedV = ReadBool(bytes, stringBuilder);
break; break;
case StartCharMetrics: case StartCharMetrics:
var count = (int)ReadDecimal(bytes, stringBuilder); var count = (int)ReadDouble(bytes, stringBuilder);
for (var i = 0; i < count; i++) for (var i = 0; i < count; i++)
{ {
var metric = ReadCharacterMetric(bytes, stringBuilder); var metric = ReadCharacterMetric(bytes, stringBuilder);
@ -457,17 +457,9 @@ namespace UglyToad.PdfPig.Fonts.AdobeFontMetrics
return builder.Build(); return builder.Build();
} }
private static decimal ReadDecimal(IInputBytes input, StringBuilder stringBuilder)
{
var str = ReadString(input, stringBuilder);
return decimal.Parse(str, CultureInfo.InvariantCulture);
}
private static double ReadDouble(IInputBytes input, StringBuilder stringBuilder) private static double ReadDouble(IInputBytes input, StringBuilder stringBuilder)
{ {
var dec = ReadDecimal(input, stringBuilder); return double.Parse(ReadString(input, stringBuilder), CultureInfo.InvariantCulture);
return (double) dec;
} }
private static bool ReadBool(IInputBytes input, StringBuilder stringBuilder) private static bool ReadBool(IInputBytes input, StringBuilder stringBuilder)
@ -484,7 +476,7 @@ namespace UglyToad.PdfPig.Fonts.AdobeFontMetrics
throw new InvalidFontFormatException($"The AFM should have contained a boolean but instead contained: {boolean}."); throw new InvalidFontFormatException($"The AFM should have contained a boolean but instead contained: {boolean}.");
} }
} }
private static string ReadString(IInputBytes input, StringBuilder stringBuilder) private static string ReadString(IInputBytes input, StringBuilder stringBuilder)
{ {
stringBuilder.Clear(); stringBuilder.Clear();

View File

@ -12,12 +12,12 @@
/// <summary> /// <summary>
/// Default value of <see cref="BlueScale"/>. /// Default value of <see cref="BlueScale"/>.
/// </summary> /// </summary>
public static readonly decimal DefaultBlueScale = 0.039625m; public static readonly double DefaultBlueScale = 0.039625;
/// <summary> /// <summary>
/// Default value of <see cref="ExpansionFactor"/>. /// Default value of <see cref="ExpansionFactor"/>.
/// </summary> /// </summary>
public static readonly decimal DefaultExpansionFactor = 0.06m; public static readonly double DefaultExpansionFactor = 0.06;
/// <summary> /// <summary>
/// Default value of <see cref="BlueFuzz"/>. /// Default value of <see cref="BlueFuzz"/>.
@ -76,7 +76,7 @@
/// points on a 300-dpi device, you should set BlueScale to /// points on a 300-dpi device, you should set BlueScale to
/// (11 0.49) ÷ 240 or 0.04379 /// (11 0.49) ÷ 240 or 0.04379
/// </example> /// </example>
public decimal BlueScale { get; } public double BlueScale { get; }
/// <summary> /// <summary>
/// Optional: The character space distance beyond the flat position of alignment zones /// Optional: The character space distance beyond the flat position of alignment zones
@ -97,22 +97,22 @@
/// <summary> /// <summary>
/// Optional: The dominant width of horizontal stems vertically in character space units. /// Optional: The dominant width of horizontal stems vertically in character space units.
/// </summary> /// </summary>
public decimal? StandardHorizontalWidth { get; } public double? StandardHorizontalWidth { get; }
/// <summary> /// <summary>
/// Optional: The dominant width of vertical stems horizontally in character space units. /// Optional: The dominant width of vertical stems horizontally in character space units.
/// </summary> /// </summary>
public decimal? StandardVerticalWidth { get; } public double? StandardVerticalWidth { get; }
/// <summary> /// <summary>
/// Optional: Up to 12 numbers with the most common widths for horizontal stems vertically in character space units. /// Optional: Up to 12 numbers with the most common widths for horizontal stems vertically in character space units.
/// </summary> /// </summary>
public IReadOnlyList<decimal> StemSnapHorizontalWidths { get; } public IReadOnlyList<double> StemSnapHorizontalWidths { get; }
/// <summary> /// <summary>
/// Optional: Up to 12 numbers with the most common widths for vertical stems horizontally in character space units. /// Optional: Up to 12 numbers with the most common widths for vertical stems horizontally in character space units.
/// </summary> /// </summary>
public IReadOnlyList<decimal> StemSnapVerticalWidths { get; } public IReadOnlyList<double> StemSnapVerticalWidths { get; }
/// <summary> /// <summary>
/// Optional: At small sizes at low resolutions this controls whether bold characters should appear thicker using /// Optional: At small sizes at low resolutions this controls whether bold characters should appear thicker using
@ -131,8 +131,8 @@
/// Optional: The limit for changing the size of a character bounding box for /// Optional: The limit for changing the size of a character bounding box for
/// <see cref="LanguageGroup"/> 1 counters during font processing. /// <see cref="LanguageGroup"/> 1 counters during font processing.
/// </summary> /// </summary>
public decimal ExpansionFactor { get; } public double ExpansionFactor { get; }
/// <summary> /// <summary>
/// Creates a new <see cref="AdobeStylePrivateDictionary"/>. /// Creates a new <see cref="AdobeStylePrivateDictionary"/>.
/// </summary> /// </summary>
@ -153,8 +153,8 @@
BlueShift = builder.BlueShift ?? DefaultBlueShift; BlueShift = builder.BlueShift ?? DefaultBlueShift;
StandardHorizontalWidth = builder.StandardHorizontalWidth; StandardHorizontalWidth = builder.StandardHorizontalWidth;
StandardVerticalWidth = builder.StandardVerticalWidth; StandardVerticalWidth = builder.StandardVerticalWidth;
StemSnapHorizontalWidths = builder.StemSnapHorizontalWidths ?? EmptyArray<decimal>.Instance; StemSnapHorizontalWidths = builder.StemSnapHorizontalWidths ?? EmptyArray<double>.Instance;
StemSnapVerticalWidths = builder.StemSnapVerticalWidths ?? EmptyArray<decimal>.Instance; StemSnapVerticalWidths = builder.StemSnapVerticalWidths ?? EmptyArray<double>.Instance;
ForceBold = builder.ForceBold ?? false; ForceBold = builder.ForceBold ?? false;
LanguageGroup = builder.LanguageGroup ?? DefaultLanguageGroup; LanguageGroup = builder.LanguageGroup ?? DefaultLanguageGroup;
ExpansionFactor = builder.ExpansionFactor ?? DefaultExpansionFactor; ExpansionFactor = builder.ExpansionFactor ?? DefaultExpansionFactor;
@ -188,7 +188,7 @@
/// <summary> /// <summary>
/// <see cref="AdobeStylePrivateDictionary.BlueScale"/>. /// <see cref="AdobeStylePrivateDictionary.BlueScale"/>.
/// </summary> /// </summary>
public decimal? BlueScale { get; set; } public double? BlueScale { get; set; }
/// <summary> /// <summary>
/// <see cref="AdobeStylePrivateDictionary.BlueShift"/>. /// <see cref="AdobeStylePrivateDictionary.BlueShift"/>.
@ -203,22 +203,22 @@
/// <summary> /// <summary>
/// <see cref="AdobeStylePrivateDictionary.StandardVerticalWidth"/>. /// <see cref="AdobeStylePrivateDictionary.StandardVerticalWidth"/>.
/// </summary> /// </summary>
public decimal? StandardHorizontalWidth { get; set; } public double? StandardHorizontalWidth { get; set; }
/// <summary> /// <summary>
/// <see cref="AdobeStylePrivateDictionary.StandardVerticalWidth"/>. /// <see cref="AdobeStylePrivateDictionary.StandardVerticalWidth"/>.
/// </summary> /// </summary>
public decimal? StandardVerticalWidth { get; set; } public double? StandardVerticalWidth { get; set; }
/// <summary> /// <summary>
/// <see cref="AdobeStylePrivateDictionary.StemSnapHorizontalWidths"/>. /// <see cref="AdobeStylePrivateDictionary.StemSnapHorizontalWidths"/>.
/// </summary> /// </summary>
public IReadOnlyList<decimal> StemSnapHorizontalWidths { get; set; } public IReadOnlyList<double> StemSnapHorizontalWidths { get; set; }
/// <summary> /// <summary>
/// <see cref="AdobeStylePrivateDictionary.StemSnapVerticalWidths"/>. /// <see cref="AdobeStylePrivateDictionary.StemSnapVerticalWidths"/>.
/// </summary> /// </summary>
public IReadOnlyList<decimal> StemSnapVerticalWidths { get; set; } public IReadOnlyList<double> StemSnapVerticalWidths { get; set; }
/// <summary> /// <summary>
/// <see cref="AdobeStylePrivateDictionary.ForceBold"/>. /// <see cref="AdobeStylePrivateDictionary.ForceBold"/>.
@ -229,11 +229,11 @@
/// <see cref="AdobeStylePrivateDictionary.LanguageGroup"/>. /// <see cref="AdobeStylePrivateDictionary.LanguageGroup"/>.
/// </summary> /// </summary>
public int? LanguageGroup { get; set; } public int? LanguageGroup { get; set; }
/// <summary> /// <summary>
/// <see cref="AdobeStylePrivateDictionary.ExpansionFactor"/>. /// <see cref="AdobeStylePrivateDictionary.ExpansionFactor"/>.
/// </summary> /// </summary>
public decimal? ExpansionFactor { get; set; } public double? ExpansionFactor { get; set; }
} }
} }
} }

View File

@ -37,7 +37,7 @@
/// <summary> /// <summary>
/// The value of Italic Angle from the top dictionary or 0. /// The value of Italic Angle from the top dictionary or 0.
/// </summary> /// </summary>
public decimal ItalicAngle => TopDictionary?.ItalicAngle ?? 0; public double ItalicAngle => TopDictionary?.ItalicAngle ?? 0.0;
internal CompactFontFormatFont(CompactFontFormatTopLevelDictionary topDictionary, CompactFontFormatPrivateDictionary privateDictionary, internal CompactFontFormatFont(CompactFontFormatTopLevelDictionary topDictionary, CompactFontFormatPrivateDictionary privateDictionary,
ICompactFontFormatCharset charset, ICompactFontFormatCharset charset,
@ -157,7 +157,7 @@
/// <summary> /// <summary>
/// Get the default width of x for the character. /// Get the default width of x for the character.
/// </summary> /// </summary>
protected virtual decimal GetDefaultWidthX(string characterName) protected virtual double GetDefaultWidthX(string characterName)
{ {
return PrivateDictionary.DefaultWidthX; return PrivateDictionary.DefaultWidthX;
} }
@ -165,7 +165,7 @@
/// <summary> /// <summary>
/// Get the nominal width of x for the character. /// Get the nominal width of x for the character.
/// </summary> /// </summary>
protected virtual decimal GetNominalWidthX(string characterName) protected virtual double GetNominalWidthX(string characterName)
{ {
return PrivateDictionary.NominalWidthX; return PrivateDictionary.NominalWidthX;
} }
@ -197,7 +197,7 @@
FdSelect = fdSelect; FdSelect = fdSelect;
} }
protected override decimal GetDefaultWidthX(string characterName) protected override double GetDefaultWidthX(string characterName)
{ {
if (!TryGetPrivateDictionaryForCharacter(characterName, out var dictionary)) if (!TryGetPrivateDictionaryForCharacter(characterName, out var dictionary))
{ {
@ -207,7 +207,7 @@
return dictionary.DefaultWidthX; return dictionary.DefaultWidthX;
} }
protected override decimal GetNominalWidthX(string characterName) protected override double GetNominalWidthX(string characterName)
{ {
if (!TryGetPrivateDictionaryForCharacter(characterName, out var dictionary)) if (!TryGetPrivateDictionaryForCharacter(characterName, out var dictionary))
{ {

View File

@ -91,7 +91,7 @@
return builder; return builder;
} }
private static decimal ReadRealNumber(CompactFontFormatData data) private static double ReadRealNumber(CompactFontFormatData data)
{ {
var sb = new StringBuilder(); var sb = new StringBuilder();
var done = false; var done = false;
@ -170,10 +170,10 @@
if (sb.Length == 0) if (sb.Length == 0)
{ {
return 0m; return 0.0;
} }
return hasExponent ? decimal.Parse(sb.ToString(), NumberStyles.Float, CultureInfo.InvariantCulture) : decimal.Parse(sb.ToString(), CultureInfo.InvariantCulture); return hasExponent ? double.Parse(sb.ToString(), NumberStyles.Float, CultureInfo.InvariantCulture) : double.Parse(sb.ToString(), CultureInfo.InvariantCulture);
} }
protected abstract void ApplyOperation(TBuilder builder, List<Operand> operands, OperandKey operandKey, IReadOnlyList<string> stringIndex); protected abstract void ApplyOperation(TBuilder builder, List<Operand> operands, OperandKey operandKey, IReadOnlyList<string> stringIndex);
@ -187,7 +187,7 @@
if (!operands[0].Int.HasValue) if (!operands[0].Int.HasValue)
{ {
throw new InvalidOperationException($"The first operand for reading a string was not an integer. Got: {operands[0].Decimal}"); throw new InvalidOperationException($"The first operand for reading a string was not an integer. Got: {operands[0].Double}");
} }
var index = operands[0].Int.Value; var index = operands[0].Int.Value;
@ -213,17 +213,17 @@
return new PdfRectangle(); return new PdfRectangle();
} }
return new PdfRectangle((double)operands[0].Decimal, (double)operands[1].Decimal, return new PdfRectangle(operands[0].Double, operands[1].Double,
(double)operands[2].Decimal, (double)operands[3].Decimal); operands[2].Double, operands[3].Double);
} }
protected static decimal[] ToArray(List<Operand> operands) protected static double[] ToArray(List<Operand> operands)
{ {
var result = new decimal[operands.Count]; var result = new double[operands.Count];
for (int i = 0; i < result.Length; i++) for (int i = 0; i < result.Length; i++)
{ {
result[i] = operands[i].Decimal; result[i] = operands[i].Double;
} }
return result; return result;
@ -255,12 +255,12 @@
return results; return results;
} }
results[0] = (int)operands[0].Decimal; results[0] = (int)operands[0].Double;
for (var i = 1; i < operands.Count; i++) for (var i = 1; i < operands.Count; i++)
{ {
var previous = results[i - 1]; var previous = results[i - 1];
var current = operands[i].Decimal; var current = operands[i].Double;
results[i] = (int)(previous + current); results[i] = (int)(previous + current);
} }
@ -268,21 +268,21 @@
return results; return results;
} }
protected static decimal[] ReadDeltaToArray(List<Operand> operands) protected static double[] ReadDeltaToArray(List<Operand> operands)
{ {
var results = new decimal[operands.Count]; var results = new double[operands.Count];
if (operands.Count == 0) if (operands.Count == 0)
{ {
return results; return results;
} }
results[0] = operands[0].Decimal; results[0] = operands[0].Double;
for (var i = 1; i < operands.Count; i++) for (var i = 1; i < operands.Count; i++)
{ {
var previous = results[i - 1]; var previous = results[i - 1];
var current = operands[i].Decimal; var current = operands[i].Double;
results[i] = previous + current; results[i] = previous + current;
} }
@ -294,18 +294,18 @@
{ {
public int? Int { get; } public int? Int { get; }
public decimal Decimal { get; } public double Double { get; }
public Operand(int integer) public Operand(int integer)
{ {
Int = integer; Int = integer;
Decimal = integer; Double = integer;
} }
public Operand(decimal d) public Operand(double d)
{ {
Int = null; Int = null;
Decimal = d; Double = d;
} }
} }

View File

@ -7,7 +7,7 @@
/// <summary> /// <summary>
/// Compatibility entry. /// Compatibility entry.
/// </summary> /// </summary>
public decimal InitialRandomSeed { get; } public double InitialRandomSeed { get; }
/// <summary> /// <summary>
/// The offset in bytes for the local subroutine index in this font. The value is relative to this private dictionary. /// The offset in bytes for the local subroutine index in this font. The value is relative to this private dictionary.
@ -17,12 +17,12 @@
/// <summary> /// <summary>
/// If a glyph's width equals the default width X it can be omitted from the charstring. /// If a glyph's width equals the default width X it can be omitted from the charstring.
/// </summary> /// </summary>
public decimal DefaultWidthX { get; } public double DefaultWidthX { get; }
/// <summary> /// <summary>
/// If not equal to <see cref="DefaultWidthX"/>, Glyph width is computed by adding the charstring width to the nominal width X value. /// If not equal to <see cref="DefaultWidthX"/>, Glyph width is computed by adding the charstring width to the nominal width X value.
/// </summary> /// </summary>
public decimal NominalWidthX { get; } public double NominalWidthX { get; }
/// <inheritdoc /> /// <inheritdoc />
/// <summary> /// <summary>
@ -44,19 +44,19 @@
public class Builder : BaseBuilder public class Builder : BaseBuilder
{ {
public decimal InitialRandomSeed { get; set; } public double InitialRandomSeed { get; set; }
public int? LocalSubroutineOffset { get; set; } public int? LocalSubroutineOffset { get; set; }
/// <summary> /// <summary>
/// If a glyph's width equals the default width X it can be omitted from the charstring. /// If a glyph's width equals the default width X it can be omitted from the charstring.
/// </summary> /// </summary>
public decimal DefaultWidthX { get; set; } public double DefaultWidthX { get; set; }
/// <summary> /// <summary>
/// If not equal to <see cref="DefaultWidthX"/>, Glyph width is computed by adding the charstring width to the nominal width X value. /// If not equal to <see cref="DefaultWidthX"/>, Glyph width is computed by adding the charstring width to the nominal width X value.
/// </summary> /// </summary>
public decimal NominalWidthX { get; set; } public double NominalWidthX { get; set; }
public CompactFontFormatPrivateDictionary Build() public CompactFontFormatPrivateDictionary Build()
{ {

View File

@ -31,10 +31,10 @@
dictionary.FamilyOtherBlues = ReadDeltaToIntArray(operands); dictionary.FamilyOtherBlues = ReadDeltaToIntArray(operands);
break; break;
case 10: case 10:
dictionary.StandardHorizontalWidth = operands[0].Decimal; dictionary.StandardHorizontalWidth = operands[0].Double;
break; break;
case 11: case 11:
dictionary.StandardVerticalWidth = operands[0].Decimal; dictionary.StandardVerticalWidth = operands[0].Double;
break; break;
case 12: case 12:
{ {
@ -46,7 +46,7 @@
switch (operandKey.Byte1.Value) switch (operandKey.Byte1.Value)
{ {
case 9: case 9:
dictionary.BlueScale = operands[0].Decimal; dictionary.BlueScale = operands[0].Double;
break; break;
case 10: case 10:
dictionary.BlueShift = operands[0].Int; dictionary.BlueShift = operands[0].Int;
@ -61,16 +61,16 @@
dictionary.StemSnapVerticalWidths = ReadDeltaToArray(operands); dictionary.StemSnapVerticalWidths = ReadDeltaToArray(operands);
break; break;
case 14: case 14:
dictionary.ForceBold = operands[0].Decimal == 1; dictionary.ForceBold = operands[0].Double == 1;
break; break;
case 17: case 17:
dictionary.LanguageGroup = operands[0].Int; dictionary.LanguageGroup = operands[0].Int;
break; break;
case 18: case 18:
dictionary.ExpansionFactor = operands[0].Decimal; dictionary.ExpansionFactor = operands[0].Double;
break; break;
case 19: case 19:
dictionary.InitialRandomSeed = operands[0].Decimal; dictionary.InitialRandomSeed = operands[0].Double;
break; break;
} }
} }
@ -79,10 +79,10 @@
dictionary.LocalSubroutineOffset = GetIntOrDefault(operands, -1); dictionary.LocalSubroutineOffset = GetIntOrDefault(operands, -1);
break; break;
case 20: case 20:
dictionary.DefaultWidthX = operands[0].Decimal; dictionary.DefaultWidthX = operands[0].Double;
break; break;
case 21: case 21:
dictionary.NominalWidthX = operands[0].Decimal; dictionary.NominalWidthX = operands[0].Double;
break; break;
} }
} }

View File

@ -20,25 +20,25 @@
public bool IsFixedPitch { get; set; } public bool IsFixedPitch { get; set; }
public decimal ItalicAngle { get; set; } public double ItalicAngle { get; set; }
public decimal UnderlinePosition { get; set; } = -100; public double UnderlinePosition { get; set; } = -100;
public decimal UnderlineThickness { get; set; } = 50; public double UnderlineThickness { get; set; } = 50;
public decimal PaintType { get; set; } public double PaintType { get; set; }
public CompactFontFormatCharStringType CharStringType { get; set; } = CompactFontFormatCharStringType.Type2; public CompactFontFormatCharStringType CharStringType { get; set; } = CompactFontFormatCharStringType.Type2;
public TransformationMatrix? FontMatrix { get; set; } public TransformationMatrix? FontMatrix { get; set; }
public decimal StrokeWidth { get; set; } public double StrokeWidth { get; set; }
public decimal UniqueId { get; set; } public double UniqueId { get; set; }
public PdfRectangle FontBoundingBox { get; set; } = new PdfRectangle(0, 0, 0, 0); public PdfRectangle FontBoundingBox { get; set; } = new PdfRectangle(0, 0, 0, 0);
public decimal[] Xuid { get; set; } public double[] Xuid { get; set; }
public int CharSetOffset { get; set; } = UnsetOffset; public int CharSetOffset { get; set; } = UnsetOffset;
@ -54,7 +54,7 @@
public string BaseFontName { get; set; } public string BaseFontName { get; set; }
public decimal[] BaseFontBlend { get; set; } public double[] BaseFontBlend { get; set; }
public bool IsCidFont { get; set; } public bool IsCidFont { get; set; }
@ -91,7 +91,7 @@
public int Count { get; set; } = 8720; public int Count { get; set; } = 8720;
public decimal UidBase { get; set; } public double UidBase { get; set; }
public int FontDictionaryArray { get; set; } public int FontDictionaryArray { get; set; }
@ -106,13 +106,13 @@
public string Ordering { get; set; } public string Ordering { get; set; }
public decimal Supplement { get; set; } public double Supplement { get; set; }
} }
/// <summary> /// <summary>
/// Defines the format of the CharString data contained within a Compact Font Format font. /// Defines the format of the CharString data contained within a Compact Font Format font.
/// </summary> /// </summary>
internal enum CompactFontFormatCharStringType internal enum CompactFontFormatCharStringType : byte
{ {
/// <summary> /// <summary>
/// The Type 1 CharString format as defined by the Adobe Type 1 Font Format. /// The Type 1 CharString format as defined by the Adobe Type 1 Font Format.

View File

@ -50,19 +50,19 @@
dictionary.Copyright = GetString(operands, stringIndex); dictionary.Copyright = GetString(operands, stringIndex);
break; break;
case 1: case 1:
dictionary.IsFixedPitch = operands[0].Decimal == 1; dictionary.IsFixedPitch = operands[0].Double == 1;
break; break;
case 2: case 2:
dictionary.ItalicAngle = operands[0].Decimal; dictionary.ItalicAngle = operands[0].Double;
break; break;
case 3: case 3:
dictionary.UnderlinePosition = operands[0].Decimal; dictionary.UnderlinePosition = operands[0].Double;
break; break;
case 4: case 4:
dictionary.UnderlineThickness = operands[0].Decimal; dictionary.UnderlineThickness = operands[0].Double;
break; break;
case 5: case 5:
dictionary.PaintType = operands[0].Decimal; dictionary.PaintType = operands[0].Double;
break; break;
case 6: case 6:
dictionary.CharStringType = (CompactFontFormatCharStringType)GetIntOrDefault(operands, 2); dictionary.CharStringType = (CompactFontFormatCharStringType)GetIntOrDefault(operands, 2);
@ -86,7 +86,7 @@
} }
break; break;
case 8: case 8:
dictionary.StrokeWidth = operands[0].Decimal; dictionary.StrokeWidth = operands[0].Double;
break; break;
case 20: case 20:
dictionary.SyntheticBaseFontIndex = GetIntOrDefault(operands); dictionary.SyntheticBaseFontIndex = GetIntOrDefault(operands);
@ -143,7 +143,7 @@
} }
break; break;
case 13: case 13:
dictionary.UniqueId = operands.Count > 0 ? operands[0].Decimal : 0; dictionary.UniqueId = operands.Count > 0 ? operands[0].Double : 0;
break; break;
case 14: case 14:
dictionary.Xuid = ToArray(operands); dictionary.Xuid = ToArray(operands);

View File

@ -11,12 +11,12 @@
public TrueTypeHeaderTable DirectoryTable { get; } public TrueTypeHeaderTable DirectoryTable { get; }
public bool IsCompressedFontFormat => Version == 0.5m; public bool IsCompressedFontFormat => Version == 0.5;
/// <summary> /// <summary>
/// The table version number. CFF fonts must use version 0.5 and only set number of glyphs. TrueType must use version 1. /// The table version number. CFF fonts must use version 0.5 and only set number of glyphs. TrueType must use version 1.
/// </summary> /// </summary>
public decimal Version { get; } public double Version { get; }
/// <summary> /// <summary>
/// The number of glyphs in the font. /// The number of glyphs in the font.
@ -26,7 +26,7 @@
public BasicMaximumProfileTable(TrueTypeHeaderTable directoryTable, float version, int numberOfGlyphs) public BasicMaximumProfileTable(TrueTypeHeaderTable directoryTable, float version, int numberOfGlyphs)
{ {
DirectoryTable = directoryTable; DirectoryTable = directoryTable;
Version = (decimal)version; Version = version;
NumberOfGlyphs = numberOfGlyphs; NumberOfGlyphs = numberOfGlyphs;
} }

View File

@ -44,7 +44,7 @@
{ {
if (char.IsNumber(part[0]) || part[0] == '-') if (char.IsNumber(part[0]) || part[0] == '-')
{ {
if (decimal.TryParse(part, NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out var value)) if (double.TryParse(part, NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out var value))
{ {
tokens.Add(new NumericToken(value)); tokens.Add(new NumericToken(value));
} }

View File

@ -123,27 +123,27 @@
} }
case Type1Symbols.StdHorizontalStemWidth: case Type1Symbols.StdHorizontalStemWidth:
{ {
var widths = ReadArrayValues(tokenizer, x => x.AsDecimal()); var widths = ReadArrayValues(tokenizer, x => x.AsDouble());
var width = widths[0]; var width = widths[0];
builder.StandardHorizontalWidth = width; builder.StandardHorizontalWidth = width;
break; break;
} }
case Type1Symbols.StdVerticalStemWidth: case Type1Symbols.StdVerticalStemWidth:
{ {
var widths = ReadArrayValues(tokenizer, x => x.AsDecimal()); var widths = ReadArrayValues(tokenizer, x => x.AsDouble());
var width = widths[0]; var width = widths[0];
builder.StandardVerticalWidth = width; builder.StandardVerticalWidth = width;
break; break;
} }
case Type1Symbols.StemSnapHorizontalWidths: case Type1Symbols.StemSnapHorizontalWidths:
{ {
var widths = ReadArrayValues(tokenizer, x => x.AsDecimal()); var widths = ReadArrayValues(tokenizer, x => x.AsDouble());
builder.StemSnapHorizontalWidths = widths; builder.StemSnapHorizontalWidths = widths;
break; break;
} }
case Type1Symbols.StemSnapVerticalWidths: case Type1Symbols.StemSnapVerticalWidths:
{ {
var widths = ReadArrayValues(tokenizer, x => x.AsDecimal()); var widths = ReadArrayValues(tokenizer, x => x.AsDouble());
builder.StemSnapVerticalWidths = widths; builder.StemSnapVerticalWidths = widths;
break; break;
} }
@ -603,7 +603,7 @@
return results; return results;
} }
private static decimal ReadNumeric(Type1Tokenizer tokenizer) private static double ReadNumeric(Type1Tokenizer tokenizer)
{ {
var token = tokenizer.GetNext(); var token = tokenizer.GetNext();
@ -612,7 +612,7 @@
throw new InvalidOperationException($"Expected to read a numeric token, instead got: {token}."); throw new InvalidOperationException($"Expected to read a numeric token, instead got: {token}.");
} }
return token.AsDecimal(); return token.AsDouble();
} }
private static bool ReadBoolean(Type1Tokenizer tokenizer) private static bool ReadBoolean(Type1Tokenizer tokenizer)

View File

@ -42,12 +42,12 @@
public int AsInt() public int AsInt()
{ {
return (int)AsDecimal(); return (int)AsDouble();
} }
public decimal AsDecimal() public double AsDouble()
{ {
return decimal.Parse(Text, CultureInfo.InvariantCulture); return double.Parse(Text, CultureInfo.InvariantCulture);
} }
public bool AsBool() public bool AsBool()

View File

@ -10,19 +10,19 @@
{ {
new object[] new object[]
{ {
new decimal[] new double[]
{ {
1, 0, 0, 1, 0, 0,
0, 1, 0, 0, 1, 0,
0, 0, 1 0, 0, 1
}, },
new decimal[] new double[]
{ {
1, 0, 0, 1, 0, 0,
0, 1, 0, 0, 1, 0,
0, 0, 1 0, 0, 1
}, },
new decimal[] new double[]
{ {
1, 0, 0, 1, 0, 0,
0, 1, 0, 0, 1, 0,
@ -31,19 +31,19 @@
}, },
new object[] new object[]
{ {
new decimal[] new double[]
{ {
65, 9, 3, 65, 9, 3,
5, 2, 7, 5, 2, 7,
11, 1, 6 11, 1, 6
}, },
new decimal[] new double[]
{ {
1, 2, 3, 1, 2, 3,
4, 5, 6, 4, 5, 6,
7, 8, 9 7, 8, 9
}, },
new decimal[] new double[]
{ {
122, 199, 276, 122, 199, 276,
62, 76, 90, 62, 76, 90,
@ -52,19 +52,19 @@
}, },
new object[] new object[]
{ {
new decimal[] new double[]
{ {
3, 5, 7, 3, 5, 7,
11, 13, -3, 11, 13, -3,
17, -6, -9 17, -6, -9
}, },
new decimal[] new double[]
{ {
5, 4, 3, 5, 4, 3,
3, 7, 12, 3, 7, 12,
1, 0, 6 1, 0, 6
}, },
new decimal[] new double[]
{ {
37, 47, 111, 37, 47, 111,
91, 135, 171, 91, 135, 171,
@ -75,7 +75,7 @@
[Theory] [Theory]
[MemberData(nameof(MultiplicationData))] [MemberData(nameof(MultiplicationData))]
public void MultipliesCorrectly(decimal[] a, decimal[] b, decimal[] expected) public void MultipliesCorrectly(double[] a, double[] b, double[] expected)
{ {
var matrixA = TransformationMatrix.FromArray(a); var matrixA = TransformationMatrix.FromArray(a);
var matrixB = TransformationMatrix.FromArray(b); var matrixB = TransformationMatrix.FromArray(b);
@ -156,7 +156,7 @@
public void InversesCorrectly(double[] a, double[] expected) public void InversesCorrectly(double[] a, double[] expected)
{ {
var matrixA = TransformationMatrix.FromArray(a); var matrixA = TransformationMatrix.FromArray(a);
var expectedMatrix = TransformationMatrix.FromArray(expected); var expectedMatrix = TransformationMatrix.FromArray(expected);
var result = matrixA.Inverse(); var result = matrixA.Inverse();

View File

@ -16,7 +16,7 @@
private static ArrayToken GetArrayToken(params double[] data) private static ArrayToken GetArrayToken(params double[] data)
{ {
return new ArrayToken(data.Select(v => new NumericToken((decimal)v)).ToArray()); return new ArrayToken(data.Select(v => new NumericToken(v)).ToArray());
} }
[Fact] [Fact]

View File

@ -15,12 +15,12 @@
DictionaryToken dictionaryToken = new DictionaryToken(new Dictionary<NameToken, IToken>() DictionaryToken dictionaryToken = new DictionaryToken(new Dictionary<NameToken, IToken>()
{ {
{ NameToken.FunctionType, new NumericToken(2) }, { NameToken.FunctionType, new NumericToken(2) },
{ NameToken.Domain, new ArrayToken(domain.Select(v => new NumericToken((decimal)v)).ToArray()) }, { NameToken.Domain, new ArrayToken(domain.Select(v => new NumericToken(v)).ToArray()) },
{ NameToken.Range, new ArrayToken(range.Select(v => new NumericToken((decimal)v)).ToArray()) }, { NameToken.Range, new ArrayToken(range.Select(v => new NumericToken(v)).ToArray()) },
{ NameToken.C0, new ArrayToken(c0.Select(v => new NumericToken((decimal)v)).ToArray()) }, { NameToken.C0, new ArrayToken(c0.Select(v => new NumericToken(v)).ToArray()) },
{ NameToken.C1, new ArrayToken(c1.Select(v => new NumericToken((decimal)v)).ToArray()) }, { NameToken.C1, new ArrayToken(c1.Select(v => new NumericToken(v)).ToArray()) },
{ NameToken.N, new NumericToken((decimal)n) }, { NameToken.N, new NumericToken(n) },
}); });
var func = PdfFunctionParser.Create(dictionaryToken, new TestPdfTokenScanner(), new TestFilterProvider()); var func = PdfFunctionParser.Create(dictionaryToken, new TestPdfTokenScanner(), new TestFilterProvider());

View File

@ -16,8 +16,8 @@
DictionaryToken dictionaryToken = new DictionaryToken(new Dictionary<NameToken, IToken>() DictionaryToken dictionaryToken = new DictionaryToken(new Dictionary<NameToken, IToken>()
{ {
{ NameToken.FunctionType, new NumericToken(4) }, { NameToken.FunctionType, new NumericToken(4) },
{ NameToken.Domain, new ArrayToken(domain.Select(v => new NumericToken((decimal)v)).ToArray()) }, { NameToken.Domain, new ArrayToken(domain.Select(v => new NumericToken(v)).ToArray()) },
{ NameToken.Range, new ArrayToken(range.Select(v => new NumericToken((decimal)v)).ToArray()) }, { NameToken.Range, new ArrayToken(range.Select(v => new NumericToken(v)).ToArray()) },
}); });
var data = Encoding.ASCII.GetBytes(function); // OtherEncodings.Iso88591.GetBytes(function); var data = Encoding.ASCII.GetBytes(function); // OtherEncodings.Iso88591.GetBytes(function);

View File

@ -99,10 +99,6 @@
{ {
result[i] = 0.5; result[i] = 0.5;
} }
else if (type == typeof(decimal))
{
result[i] = 0.5m;
}
else if (type == typeof(int)) else if (type == typeof(int))
{ {
result[i] = 1; result[i] = 1;
@ -114,13 +110,6 @@
1, 0, 0, 1, 2, 5 1, 0, 0, 1, 2, 5
}; };
} }
else if (type == typeof(decimal[]) || type == typeof(IReadOnlyList<decimal>))
{
result[i] = new decimal[]
{
1, 0, 0, 1, 2, 5
};
}
else if (type == typeof(IReadOnlyList<IToken>)) else if (type == typeof(IReadOnlyList<IToken>))
{ {
result[i] = new IToken[] { new StringToken("Text") }; result[i] = new IToken[] { new StringToken("Text") };

View File

@ -158,16 +158,6 @@
/// </summary> /// </summary>
public double Double => Data; public double Double => Data;
/// <summary>
/// Create a <see cref="NumericToken"/>.
/// </summary>
/// <param name="value">The number to represent.</param>
//[Obsolete("Use double constructor instead.")]
public NumericToken(decimal value)
{
Data = (double)value;
}
/// <summary> /// <summary>
/// Create a <see cref="NumericToken"/>. /// Create a <see cref="NumericToken"/>.
/// </summary> /// </summary>

View File

@ -21,7 +21,7 @@
/// <summary> /// <summary>
/// Get the rotation expressed in radians (anti-clockwise). /// Get the rotation expressed in radians (anti-clockwise).
/// </summary> /// </summary>
public decimal Radians public double Radians
{ {
get get
{ {
@ -30,11 +30,11 @@
case 0: case 0:
return 0; return 0;
case 90: case 90:
return -(decimal)(0.5 * Math.PI); return -0.5 * Math.PI;
case 180: case 180:
return -(decimal) Math.PI; return -Math.PI;
case 270: case 270:
return -(decimal) (1.5 * Math.PI); return -1.5 * Math.PI;
default: default:
throw new InvalidOperationException($"Invalid value for rotation: {Value}."); throw new InvalidOperationException($"Invalid value for rotation: {Value}.");
} }

View File

@ -120,7 +120,7 @@ namespace UglyToad.PdfPig.Graphics
/// <summary> /// <summary>
/// The precision for rendering color gradients on the output device. /// The precision for rendering color gradients on the output device.
/// </summary> /// </summary>
public decimal Smoothness { get; set; } = 0; public double Smoothness { get; set; } = 0;
#endregion #endregion
/// <inheritdoc /> /// <inheritdoc />

View File

@ -36,37 +36,14 @@
stream.WriteByte(NewLine); stream.WriteByte(NewLine);
} }
public static void WriteDecimal(this Stream stream, decimal value)
{
stream.WriteText(value.ToString("G", CultureInfo.InvariantCulture));
}
public static void WriteDecimal(this Stream stream, double value)
{
stream.WriteText(value.ToString("G", CultureInfo.InvariantCulture));
}
public static void WriteDecimal(this Stream stream, int value)
{
stream.WriteText(value.ToString("G", CultureInfo.InvariantCulture));
}
public static void WriteDouble(this Stream stream, double value) public static void WriteDouble(this Stream stream, double value)
{ {
stream.WriteText(value.ToString("G", CultureInfo.InvariantCulture)); stream.WriteText(value.ToString("G", CultureInfo.InvariantCulture));
} }
public static void WriteNumberText(this Stream stream, decimal number, string text)
{
stream.WriteDecimal(number);
stream.WriteWhiteSpace();
stream.WriteText(text);
stream.WriteNewLine();
}
public static void WriteNumberText(this Stream stream, int number, string text) public static void WriteNumberText(this Stream stream, int number, string text)
{ {
stream.WriteDecimal(number); stream.WriteDouble(number);
stream.WriteWhiteSpace(); stream.WriteWhiteSpace();
stream.WriteText(text); stream.WriteText(text);
stream.WriteNewLine(); stream.WriteNewLine();

View File

@ -421,7 +421,7 @@ namespace UglyToad.PdfPig.Graphics
throw new InvalidOperationException($"Fewer operands {operands.Count} found than required ({offset + 1}) for operator: {op.Data}."); throw new InvalidOperationException($"Fewer operands {operands.Count} found than required ({offset + 1}) for operator: {op.Data}.");
} }
if (parameter.ParameterType == typeof(decimal)) if (parameter.ParameterType == typeof(double))
{ {
if (operands[offset] is NumericToken numeric) if (operands[offset] is NumericToken numeric)
{ {
@ -429,7 +429,7 @@ namespace UglyToad.PdfPig.Graphics
} }
else else
{ {
throw new InvalidOperationException($"Expected a decimal parameter for operation type {operationType.FullName}. Instead got: {operands[offset]}"); throw new InvalidOperationException($"Expected a double parameter for operation type {operationType.FullName}. Instead got: {operands[offset]}");
} }
offset++; offset++;
@ -477,7 +477,7 @@ namespace UglyToad.PdfPig.Graphics
} }
else else
{ {
throw new InvalidOperationException($"Expected a decimal array parameter for operation type {operationType.FullName}. Instead got: {operands[offset]}"); throw new InvalidOperationException($"Expected a NameToken parameter for operation type {operationType.FullName}. Instead got: {operands[offset]}");
} }
offset++; offset++;

View File

@ -47,7 +47,7 @@
else else
{ {
// optional - Default value: the identity matrix [1 0 0 1 0 0] // optional - Default value: the identity matrix [1 0 0 1 0 0]
matrix = TransformationMatrix.FromArray(new decimal[] { 1, 0, 0, 1, 0, 0 }); matrix = TransformationMatrix.FromArray(new double[] { 1, 0, 0, 1, 0, 0 });
} }
DictionaryToken patternExtGState = null; DictionaryToken patternExtGState = null;

View File

@ -151,7 +151,7 @@
else else
{ {
// Optional - Default value: the identity matrix [1 0 0 1 0 0] // Optional - Default value: the identity matrix [1 0 0 1 0 0]
matrix = TransformationMatrix.FromArray(new decimal[] { 1, 0, 0, 1, 0, 0 }); matrix = TransformationMatrix.FromArray(new double[] { 1, 0, 0, 1, 0, 0 });
} }
if (!shadingDictionary.ContainsKey(NameToken.Function)) if (!shadingDictionary.ContainsKey(NameToken.Function))

View File

@ -63,7 +63,7 @@
var bbox = font.TableRegister.HeaderTable.Bounds; var bbox = font.TableRegister.HeaderTable.Bounds;
var scaling = 1000m / font.TableRegister.HeaderTable.UnitsPerEm; var scaling = 1000.0 / font.TableRegister.HeaderTable.UnitsPerEm;
var descriptorDictionary = new Dictionary<NameToken, IToken> var descriptorDictionary = new Dictionary<NameToken, IToken>
{ {
{ NameToken.Type, NameToken.FontDescriptor }, { NameToken.Type, NameToken.FontDescriptor },
@ -71,7 +71,7 @@
// TODO: get flags TrueTypeEmbedder.java // TODO: get flags TrueTypeEmbedder.java
{ NameToken.Flags, new NumericToken((int)FontDescriptorFlags.Symbolic) }, { NameToken.Flags, new NumericToken((int)FontDescriptorFlags.Symbolic) },
{ NameToken.FontBbox, GetBoundingBox(bbox, scaling) }, { NameToken.FontBbox, GetBoundingBox(bbox, scaling) },
{ NameToken.ItalicAngle, new NumericToken((decimal)postscript.ItalicAngle) }, { NameToken.ItalicAngle, new NumericToken(postscript.ItalicAngle) },
{ NameToken.Ascent, new NumericToken(Math.Round(hhead.Ascent * scaling, 2)) }, { NameToken.Ascent, new NumericToken(Math.Round(hhead.Ascent * scaling, 2)) },
{ NameToken.Descent, new NumericToken(Math.Round(hhead.Descent * scaling, 2)) }, { NameToken.Descent, new NumericToken(Math.Round(hhead.Descent * scaling, 2)) },
{ NameToken.CapHeight, new NumericToken(90) }, { NameToken.CapHeight, new NumericToken(90) },
@ -91,7 +91,7 @@
descriptorDictionary[NameToken.Xheight] = new NumericToken(twoPlus.XHeight); descriptorDictionary[NameToken.Xheight] = new NumericToken(twoPlus.XHeight);
} }
descriptorDictionary[NameToken.StemV] = new NumericToken(((decimal)bbox.Width) * scaling * 0.13m); descriptorDictionary[NameToken.StemV] = new NumericToken(bbox.Width * scaling * 0.13);
var lastCharacter = 0; var lastCharacter = 0;
var widths = new List<NumericToken> { NumericToken.Zero }; var widths = new List<NumericToken> { NumericToken.Zero };
@ -103,7 +103,7 @@
} }
var glyphId = font.WindowsUnicodeCMap.CharacterCodeToGlyphIndex(kvp.Key); var glyphId = font.WindowsUnicodeCMap.CharacterCodeToGlyphIndex(kvp.Key);
var width = decimal.Round(font.TableRegister.HorizontalMetricsTable.GetAdvanceWidth(glyphId) * scaling, 2); var width = Math.Round(font.TableRegister.HorizontalMetricsTable.GetAdvanceWidth(glyphId) * scaling, 2);
widths.Add(new NumericToken(width)); widths.Add(new NumericToken(width));
} }
@ -162,14 +162,14 @@
} }
} }
private static ArrayToken GetBoundingBox(PdfRectangle boundingBox, decimal scaling) private static ArrayToken GetBoundingBox(PdfRectangle boundingBox, double scaling)
{ {
return new ArrayToken(new[] return new ArrayToken(new[]
{ {
new NumericToken(Math.Round((decimal)boundingBox.Left * scaling, 2)), new NumericToken(Math.Round(boundingBox.Left * scaling, 2)),
new NumericToken(Math.Round((decimal)boundingBox.Bottom * scaling, 2)), new NumericToken(Math.Round(boundingBox.Bottom * scaling, 2)),
new NumericToken(Math.Round((decimal)boundingBox.Right * scaling, 2)), new NumericToken(Math.Round(boundingBox.Right * scaling, 2)),
new NumericToken(Math.Round((decimal)boundingBox.Top * scaling, 2)) new NumericToken(Math.Round(boundingBox.Top * scaling, 2))
}); });
} }
} }

View File

@ -592,7 +592,7 @@ namespace UglyToad.PdfPig.Writer
} }
const int desiredLeafSize = 25; // allow customization at some point? const int desiredLeafSize = 25; // allow customization at some point?
var numLeafs = (int)Math.Ceiling(Decimal.Divide(Pages.Count, desiredLeafSize)); var numLeafs = (int)Math.Ceiling(Pages.Count / (double)desiredLeafSize);
var leafRefs = new List<IndirectReferenceToken>(); var leafRefs = new List<IndirectReferenceToken>();
var leafChildren = new List<List<IndirectReferenceToken>>(); var leafChildren = new List<List<IndirectReferenceToken>>();
@ -772,7 +772,7 @@ namespace UglyToad.PdfPig.Writer
{ {
var currentTreeDepth = (int)Math.Ceiling(Math.Log(pagesNodes.Count, desiredLeafSize)); var currentTreeDepth = (int)Math.Ceiling(Math.Log(pagesNodes.Count, desiredLeafSize));
var perBranch = (int)Math.Ceiling(Math.Pow(desiredLeafSize, currentTreeDepth - 1)); var perBranch = (int)Math.Ceiling(Math.Pow(desiredLeafSize, currentTreeDepth - 1));
var branches = (int)Math.Ceiling(decimal.Divide(pagesNodes.Count, (decimal)perBranch)); var branches = (int)Math.Ceiling(pagesNodes.Count / (double)perBranch);
for (var i = 0; i < branches; i++) for (var i = 0; i < branches; i++)
{ {
var part = pagesNodes.Skip(i * perBranch).Take(perBranch).ToList(); var part = pagesNodes.Skip(i * perBranch).Take(perBranch).ToList();
@ -837,10 +837,10 @@ namespace UglyToad.PdfPig.Writer
{ {
return new ArrayToken(new[] return new ArrayToken(new[]
{ {
new NumericToken((decimal)rectangle.BottomLeft.X), new NumericToken(rectangle.BottomLeft.X),
new NumericToken((decimal)rectangle.BottomLeft.Y), new NumericToken(rectangle.BottomLeft.Y),
new NumericToken((decimal)rectangle.TopRight.X), new NumericToken(rectangle.TopRight.X),
new NumericToken((decimal)rectangle.TopRight.Y) new NumericToken(rectangle.TopRight.Y)
}); });
} }

View File

@ -380,7 +380,7 @@
} }
/// <summary> /// <summary>
/// Sets the stroke color with the exact decimal value between 0 and 1 for any following operations to the RGB value. Use <see cref="ResetColor"/> to reset. /// Sets the stroke color with the exact value between 0 and 1 for any following operations to the RGB value. Use <see cref="ResetColor"/> to reset.
/// </summary> /// </summary>
/// <param name="r">Red - 0 to 1</param> /// <param name="r">Red - 0 to 1</param>
/// <param name="g">Green - 0 to 1</param> /// <param name="g">Green - 0 to 1</param>
@ -1063,12 +1063,12 @@
{ {
if (value < 0) if (value < 0)
{ {
throw new ArgumentOutOfRangeException(argument, $"Provided decimal for RGB color was less than zero: {value}."); throw new ArgumentOutOfRangeException(argument, $"Provided double for RGB color was less than zero: {value}.");
} }
if (value > 1) if (value > 1)
{ {
throw new ArgumentOutOfRangeException(argument, $"Provided decimal for RGB color was greater than one: {value}."); throw new ArgumentOutOfRangeException(argument, $"Provided double for RGB color was greater than one: {value}.");
} }
return value; return value;