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

View File

@ -11,28 +11,6 @@
private readonly IReadOnlyList<double> rangeArray;
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>
/// Constructor assumes a starting index of 0.
/// </summary>

View File

@ -362,14 +362,6 @@
public static TransformationMatrix FromValues(double a, double b, double c, double d)
=> 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>
/// Create a new <see cref="TransformationMatrix"/> from the values.
/// </summary>

View File

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

View File

@ -1,13 +1,12 @@
namespace UglyToad.PdfPig.Fonts.AdobeFontMetrics
{
using Core;
using System.Collections.Generic;
using System.Linq;
using Core;
using Standard14Fonts;
internal class AdobeFontMetricsBuilder
{
public decimal AfmVersion { get; }
public double AfmVersion { get; }
public List<string> Comments { get; }
@ -37,7 +36,7 @@
/// <summary>
/// Angle in degrees counter-clockwise from vertical of vertical strokes of the font.
/// </summary>
public decimal ItalicAngle { get; set; }
public double ItalicAngle { get; set; }
/// <summary>
/// Whether the font is monospaced or not.
@ -52,12 +51,12 @@
/// <summary>
/// Distance from the baseline for underlining.
/// </summary>
public decimal UnderlinePosition { get; set; }
public double UnderlinePosition { get; set; }
/// <summary>
/// The stroke width for underlining.
/// </summary>
public decimal UnderlineThickness { get; set; }
public double UnderlineThickness { get; set; }
/// <summary>
/// Version identifier for the font program.
@ -86,32 +85,32 @@
/// <summary>
/// The y-value of the top of a capital H.
/// </summary>
public decimal CapHeight { get; set; }
public double CapHeight { get; set; }
/// <summary>
/// The y-value of the top of lowercase x.
/// </summary>
public decimal XHeight { get; set; }
public double XHeight { get; set; }
/// <summary>
/// Generally the y-value of the top of lowercase d.
/// </summary>
public decimal Ascender { get; set; }
public double Ascender { get; set; }
/// <summary>
/// The y-value of the bottom of lowercase p.
/// </summary>
public decimal Descender { get; set; }
public double Descender { get; set; }
/// <summary>
/// Width of horizontal stems.
/// </summary>
public decimal StdHw { get; set; }
public double StdHw { get; set; }
/// <summary>
/// Width of vertical stems.
/// </summary>
public decimal StdVw { get; set; }
public double StdVw { get; set; }
public int EscapeCharacter { get; set; }
@ -123,7 +122,7 @@
public bool IsFixedV { get; set; }
public AdobeFontMetricsBuilder(decimal afmVersion)
public AdobeFontMetricsBuilder(double afmVersion)
{
AfmVersion = afmVersion;
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}.");
}
var version = ReadDecimal(bytes, stringBuilder);
var version = ReadDouble(bytes, stringBuilder);
var builder = new AdobeFontMetricsBuilder(version);
@ -368,7 +368,7 @@ namespace UglyToad.PdfPig.Fonts.AdobeFontMetrics
builder.Weight = ReadLine(bytes, stringBuilder);
break;
case ItalicAngle:
builder.ItalicAngle = ReadDecimal(bytes, stringBuilder);
builder.ItalicAngle = ReadDouble(bytes, stringBuilder);
break;
case IsFixedPitch:
builder.IsFixedPitch = ReadBool(bytes, stringBuilder);
@ -378,10 +378,10 @@ namespace UglyToad.PdfPig.Fonts.AdobeFontMetrics
ReadDouble(bytes, stringBuilder), ReadDouble(bytes, stringBuilder));
break;
case UnderlinePosition:
builder.UnderlinePosition = ReadDecimal(bytes, stringBuilder);
builder.UnderlinePosition = ReadDouble(bytes, stringBuilder);
break;
case UnderlineThickness:
builder.UnderlineThickness = ReadDecimal(bytes, stringBuilder);
builder.UnderlineThickness = ReadDouble(bytes, stringBuilder);
break;
case Version:
builder.Version = ReadLine(bytes, stringBuilder);
@ -393,37 +393,37 @@ namespace UglyToad.PdfPig.Fonts.AdobeFontMetrics
builder.EncodingScheme = ReadLine(bytes, stringBuilder);
break;
case MappingScheme:
builder.MappingScheme = (int)ReadDecimal(bytes, stringBuilder);
builder.MappingScheme = (int)ReadDouble(bytes, stringBuilder);
break;
case CharacterSet:
builder.CharacterSet = ReadLine(bytes, stringBuilder);
break;
case EscChar:
builder.EscapeCharacter = (int) ReadDecimal(bytes, stringBuilder);
builder.EscapeCharacter = (int)ReadDouble(bytes, stringBuilder);
break;
case Characters:
builder.Characters = (int) ReadDecimal(bytes, stringBuilder);
builder.Characters = (int)ReadDouble(bytes, stringBuilder);
break;
case IsBaseFont:
builder.IsBaseFont = ReadBool(bytes, stringBuilder);
break;
case CapHeight:
builder.CapHeight = ReadDecimal(bytes, stringBuilder);
builder.CapHeight = ReadDouble(bytes, stringBuilder);
break;
case XHeight:
builder.XHeight = ReadDecimal(bytes, stringBuilder);
builder.XHeight = ReadDouble(bytes, stringBuilder);
break;
case Ascender:
builder.Ascender = ReadDecimal(bytes, stringBuilder);
builder.Ascender = ReadDouble(bytes, stringBuilder);
break;
case Descender:
builder.Descender = ReadDecimal(bytes, stringBuilder);
builder.Descender = ReadDouble(bytes, stringBuilder);
break;
case StdHw:
builder.StdHw = ReadDecimal(bytes, stringBuilder);
builder.StdHw = ReadDouble(bytes, stringBuilder);
break;
case StdVw:
builder.StdVw = ReadDecimal(bytes, stringBuilder);
builder.StdVw = ReadDouble(bytes, stringBuilder);
break;
case CharWidth:
builder.SetCharacterWidth(ReadDouble(bytes, stringBuilder), ReadDouble(bytes, stringBuilder));
@ -435,7 +435,7 @@ namespace UglyToad.PdfPig.Fonts.AdobeFontMetrics
builder.IsFixedV = ReadBool(bytes, stringBuilder);
break;
case StartCharMetrics:
var count = (int)ReadDecimal(bytes, stringBuilder);
var count = (int)ReadDouble(bytes, stringBuilder);
for (var i = 0; i < count; i++)
{
var metric = ReadCharacterMetric(bytes, stringBuilder);
@ -457,17 +457,9 @@ namespace UglyToad.PdfPig.Fonts.AdobeFontMetrics
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)
{
var dec = ReadDecimal(input, stringBuilder);
return (double) dec;
return double.Parse(ReadString(input, stringBuilder), CultureInfo.InvariantCulture);
}
private static bool ReadBool(IInputBytes input, StringBuilder stringBuilder)

View File

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

View File

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

View File

@ -91,7 +91,7 @@
return builder;
}
private static decimal ReadRealNumber(CompactFontFormatData data)
private static double ReadRealNumber(CompactFontFormatData data)
{
var sb = new StringBuilder();
var done = false;
@ -170,10 +170,10 @@
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);
@ -187,7 +187,7 @@
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;
@ -213,17 +213,17 @@
return new PdfRectangle();
}
return new PdfRectangle((double)operands[0].Decimal, (double)operands[1].Decimal,
(double)operands[2].Decimal, (double)operands[3].Decimal);
return new PdfRectangle(operands[0].Double, operands[1].Double,
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++)
{
result[i] = operands[i].Decimal;
result[i] = operands[i].Double;
}
return result;
@ -255,12 +255,12 @@
return results;
}
results[0] = (int)operands[0].Decimal;
results[0] = (int)operands[0].Double;
for (var i = 1; i < operands.Count; i++)
{
var previous = results[i - 1];
var current = operands[i].Decimal;
var current = operands[i].Double;
results[i] = (int)(previous + current);
}
@ -268,21 +268,21 @@
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)
{
return results;
}
results[0] = operands[0].Decimal;
results[0] = operands[0].Double;
for (var i = 1; i < operands.Count; i++)
{
var previous = results[i - 1];
var current = operands[i].Decimal;
var current = operands[i].Double;
results[i] = previous + current;
}
@ -294,18 +294,18 @@
{
public int? Int { get; }
public decimal Decimal { get; }
public double Double { get; }
public Operand(int integer)
{
Int = integer;
Decimal = integer;
Double = integer;
}
public Operand(decimal d)
public Operand(double d)
{
Int = null;
Decimal = d;
Double = d;
}
}

View File

@ -7,7 +7,7 @@
/// <summary>
/// Compatibility entry.
/// </summary>
public decimal InitialRandomSeed { get; }
public double InitialRandomSeed { get; }
/// <summary>
/// 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>
/// If a glyph's width equals the default width X it can be omitted from the charstring.
/// </summary>
public decimal DefaultWidthX { get; }
public double DefaultWidthX { get; }
/// <summary>
/// If not equal to <see cref="DefaultWidthX"/>, Glyph width is computed by adding the charstring width to the nominal width X value.
/// </summary>
public decimal NominalWidthX { get; }
public double NominalWidthX { get; }
/// <inheritdoc />
/// <summary>
@ -44,19 +44,19 @@
public class Builder : BaseBuilder
{
public decimal InitialRandomSeed { get; set; }
public double InitialRandomSeed { get; set; }
public int? LocalSubroutineOffset { get; set; }
/// <summary>
/// If a glyph's width equals the default width X it can be omitted from the charstring.
/// </summary>
public decimal DefaultWidthX { get; set; }
public double DefaultWidthX { get; set; }
/// <summary>
/// If not equal to <see cref="DefaultWidthX"/>, Glyph width is computed by adding the charstring width to the nominal width X value.
/// </summary>
public decimal NominalWidthX { get; set; }
public double NominalWidthX { get; set; }
public CompactFontFormatPrivateDictionary Build()
{

View File

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

View File

@ -20,25 +20,25 @@
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 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 decimal[] Xuid { get; set; }
public double[] Xuid { get; set; }
public int CharSetOffset { get; set; } = UnsetOffset;
@ -54,7 +54,7 @@
public string BaseFontName { get; set; }
public decimal[] BaseFontBlend { get; set; }
public double[] BaseFontBlend { get; set; }
public bool IsCidFont { get; set; }
@ -91,7 +91,7 @@
public int Count { get; set; } = 8720;
public decimal UidBase { get; set; }
public double UidBase { get; set; }
public int FontDictionaryArray { get; set; }
@ -106,13 +106,13 @@
public string Ordering { get; set; }
public decimal Supplement { get; set; }
public double Supplement { get; set; }
}
/// <summary>
/// Defines the format of the CharString data contained within a Compact Font Format font.
/// </summary>
internal enum CompactFontFormatCharStringType
internal enum CompactFontFormatCharStringType : byte
{
/// <summary>
/// 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);
break;
case 1:
dictionary.IsFixedPitch = operands[0].Decimal == 1;
dictionary.IsFixedPitch = operands[0].Double == 1;
break;
case 2:
dictionary.ItalicAngle = operands[0].Decimal;
dictionary.ItalicAngle = operands[0].Double;
break;
case 3:
dictionary.UnderlinePosition = operands[0].Decimal;
dictionary.UnderlinePosition = operands[0].Double;
break;
case 4:
dictionary.UnderlineThickness = operands[0].Decimal;
dictionary.UnderlineThickness = operands[0].Double;
break;
case 5:
dictionary.PaintType = operands[0].Decimal;
dictionary.PaintType = operands[0].Double;
break;
case 6:
dictionary.CharStringType = (CompactFontFormatCharStringType)GetIntOrDefault(operands, 2);
@ -86,7 +86,7 @@
}
break;
case 8:
dictionary.StrokeWidth = operands[0].Decimal;
dictionary.StrokeWidth = operands[0].Double;
break;
case 20:
dictionary.SyntheticBaseFontIndex = GetIntOrDefault(operands);
@ -143,7 +143,7 @@
}
break;
case 13:
dictionary.UniqueId = operands.Count > 0 ? operands[0].Decimal : 0;
dictionary.UniqueId = operands.Count > 0 ? operands[0].Double : 0;
break;
case 14:
dictionary.Xuid = ToArray(operands);

View File

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

View File

@ -44,7 +44,7 @@
{
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));
}

View File

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

View File

@ -42,12 +42,12 @@
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()

View File

@ -10,19 +10,19 @@
{
new object[]
{
new decimal[]
new double[]
{
1, 0, 0,
0, 1, 0,
0, 0, 1
},
new decimal[]
new double[]
{
1, 0, 0,
0, 1, 0,
0, 0, 1
},
new decimal[]
new double[]
{
1, 0, 0,
0, 1, 0,
@ -31,19 +31,19 @@
},
new object[]
{
new decimal[]
new double[]
{
65, 9, 3,
5, 2, 7,
11, 1, 6
},
new decimal[]
new double[]
{
1, 2, 3,
4, 5, 6,
7, 8, 9
},
new decimal[]
new double[]
{
122, 199, 276,
62, 76, 90,
@ -52,19 +52,19 @@
},
new object[]
{
new decimal[]
new double[]
{
3, 5, 7,
11, 13, -3,
17, -6, -9
},
new decimal[]
new double[]
{
5, 4, 3,
3, 7, 12,
1, 0, 6
},
new decimal[]
new double[]
{
37, 47, 111,
91, 135, 171,
@ -75,7 +75,7 @@
[Theory]
[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 matrixB = TransformationMatrix.FromArray(b);

View File

@ -16,7 +16,7 @@
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]

View File

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

View File

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

View File

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

View File

@ -158,16 +158,6 @@
/// </summary>
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>
/// Create a <see cref="NumericToken"/>.
/// </summary>

View File

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

View File

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

View File

@ -36,37 +36,14 @@
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)
{
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)
{
stream.WriteDecimal(number);
stream.WriteDouble(number);
stream.WriteWhiteSpace();
stream.WriteText(text);
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}.");
}
if (parameter.ParameterType == typeof(decimal))
if (parameter.ParameterType == typeof(double))
{
if (operands[offset] is NumericToken numeric)
{
@ -429,7 +429,7 @@ namespace UglyToad.PdfPig.Graphics
}
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++;
@ -477,7 +477,7 @@ namespace UglyToad.PdfPig.Graphics
}
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++;

View File

@ -47,7 +47,7 @@
else
{
// 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;

View File

@ -151,7 +151,7 @@
else
{
// 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))

View File

@ -63,7 +63,7 @@
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>
{
{ NameToken.Type, NameToken.FontDescriptor },
@ -71,7 +71,7 @@
// TODO: get flags TrueTypeEmbedder.java
{ NameToken.Flags, new NumericToken((int)FontDescriptorFlags.Symbolic) },
{ 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.Descent, new NumericToken(Math.Round(hhead.Descent * scaling, 2)) },
{ NameToken.CapHeight, new NumericToken(90) },
@ -91,7 +91,7 @@
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 widths = new List<NumericToken> { NumericToken.Zero };
@ -103,7 +103,7 @@
}
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));
}
@ -162,14 +162,14 @@
}
}
private static ArrayToken GetBoundingBox(PdfRectangle boundingBox, decimal scaling)
private static ArrayToken GetBoundingBox(PdfRectangle boundingBox, double scaling)
{
return new ArrayToken(new[]
{
new NumericToken(Math.Round((decimal)boundingBox.Left * scaling, 2)),
new NumericToken(Math.Round((decimal)boundingBox.Bottom * scaling, 2)),
new NumericToken(Math.Round((decimal)boundingBox.Right * scaling, 2)),
new NumericToken(Math.Round((decimal)boundingBox.Top * scaling, 2))
new NumericToken(Math.Round(boundingBox.Left * scaling, 2)),
new NumericToken(Math.Round(boundingBox.Bottom * scaling, 2)),
new NumericToken(Math.Round(boundingBox.Right * 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?
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 leafChildren = new List<List<IndirectReferenceToken>>();
@ -772,7 +772,7 @@ namespace UglyToad.PdfPig.Writer
{
var currentTreeDepth = (int)Math.Ceiling(Math.Log(pagesNodes.Count, desiredLeafSize));
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++)
{
var part = pagesNodes.Skip(i * perBranch).Take(perBranch).ToList();
@ -837,10 +837,10 @@ namespace UglyToad.PdfPig.Writer
{
return new ArrayToken(new[]
{
new NumericToken((decimal)rectangle.BottomLeft.X),
new NumericToken((decimal)rectangle.BottomLeft.Y),
new NumericToken((decimal)rectangle.TopRight.X),
new NumericToken((decimal)rectangle.TopRight.Y)
new NumericToken(rectangle.BottomLeft.X),
new NumericToken(rectangle.BottomLeft.Y),
new NumericToken(rectangle.TopRight.X),
new NumericToken(rectangle.TopRight.Y)
});
}

View File

@ -380,7 +380,7 @@
}
/// <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>
/// <param name="r">Red - 0 to 1</param>
/// <param name="g">Green - 0 to 1</param>
@ -1063,12 +1063,12 @@
{
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)
{
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;