-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMetafileDescriptor.cs
87 lines (78 loc) · 3.82 KB
/
MetafileDescriptor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using CgmInfo.Commands.Attributes;
using CgmInfo.Commands.Enums;
using CgmInfo.Utilities;
namespace CgmInfo
{
public class MetafileDescriptor
{
public MetafileDescriptor()
{
// ISO/IEC 8632-3 9
// also ISO/IEC 8632-1 8
ColorModel = ColorModel.RGB;
ColorPrecision = 8;
ColorIndexPrecision = 8;
RealPrecision = RealPrecisionSpecification.FixedPoint32Bit;
IntegerPrecision = 16;
IndexPrecision = 16;
NamePrecision = 16;
VdcType = VdcTypeSpecification.Integer;
VdcIntegerPrecision = 16;
VdcRealPrecision = RealPrecisionSpecification.FixedPoint32Bit;
ColorSelectionMode = ColorModeType.Indexed;
DeviceViewportSpecificationMode = DeviceViewportSpecificationModeType.FractionOfDrawingSurface;
LineWidthSpecificationMode = WidthSpecificationModeType.Scaled;
MarkerSizeSpecificationMode = WidthSpecificationModeType.Scaled;
EdgeWidthSpecificationMode = WidthSpecificationModeType.Scaled;
InteriorStyleSpecificationMode = WidthSpecificationModeType.Absolute;
}
internal void UpdateColorTable(ColorTable colorTable)
{
// easiest case first: whole color table is updated, and it's larger than the current one
if (colorTable.StartIndex == 0 && colorTable.Colors.Length >= ColorTable.Length)
{
_colorTable = colorTable.Colors;
}
else
{
// partial update; make sure we can fit the whole changes
if (ColorTable.Length < colorTable.StartIndex + colorTable.Colors.Length)
Array.Resize(ref _colorTable, colorTable.StartIndex + colorTable.Colors.Length);
// update the fields specified by COLOUR TABLE; leave everything else as-is
colorTable.Colors.CopyTo(_colorTable, colorTable.StartIndex);
}
}
public MetafileColor GetIndexedColor(int colorIndex)
{
if (colorIndex < 0 || colorIndex >= ColorTable.Length)
return null!;
return ColorTable[colorIndex];
}
public int GetColorIndex(MetafileColor value)
{
int foundIndex = Array.IndexOf(ColorTable, value);
if (foundIndex == -1)
throw new ArgumentException($"Could not find color '{value}' in color table", nameof(value));
return foundIndex;
}
private MetafileColor[] _colorTable = new MetafileColor[0];
public MetafileColor[] ColorTable => _colorTable;
public ColorModel ColorModel { get; internal set; }
public int ColorPrecision { get; internal set; }
public int ColorIndexPrecision { get; internal set; }
public RealPrecisionSpecification RealPrecision { get; internal set; }
public int IntegerPrecision { get; internal set; }
public int IndexPrecision { get; internal set; }
public int NamePrecision { get; internal set; }
public ColorModeType ColorSelectionMode { get; internal set; }
public DeviceViewportSpecificationModeType DeviceViewportSpecificationMode { get; internal set; }
public VdcTypeSpecification VdcType { get; internal set; }
public int VdcIntegerPrecision { get; internal set; }
public RealPrecisionSpecification VdcRealPrecision { get; internal set; }
public WidthSpecificationModeType LineWidthSpecificationMode { get; internal set; }
public WidthSpecificationModeType MarkerSizeSpecificationMode { get; internal set; }
public WidthSpecificationModeType EdgeWidthSpecificationMode { get; internal set; }
public WidthSpecificationModeType InteriorStyleSpecificationMode { get; internal set; }
}
}