Skip to content

Commit 2c112bb

Browse files
committed
591: minor update on variable fonts (work-in-progress)
1 parent c9e1370 commit 2c112bb

10 files changed

Lines changed: 442 additions & 55 deletions

File tree

145 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SIL , https://github.com/TypeNetwork/Amstelvar/blob/master/COPYRIGHT.md
225 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
OFL, https://fonts.google.com/specimen/Comfortaa#standard-styles

LICENSE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ The FreeType Project LICENSE (3-clauses BSD style),2003-2016, David Turner, Robe
2020

2121
Apache2, 2018, Apache/PDFBox Authors, https://github.com/apache/pdfbox
2222

23+
Apache2, 2020, Adobe Font Development Kit for OpenType (AFDKO), https://github.com/adobe-type-tools/afdko
24+
2325
**Text Processing**
2426

2527
Unicode (BSD style), 2020, _UNICODE, INC_, https://www.unicode.org/license.html

Typography.OpenFont/Tables.Variations/CVar.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ namespace Typography.OpenFont.Tables
1212
class CVar : TableEntry
1313
{
1414
public const string _N = "cvar";
15-
public override string Name => _N;
15+
public override string Name => _N;
1616
public CVar()
1717
{
18+
//The control value table (CVT) variations table is used in variable fonts to provide variation data for CVT values.
19+
//For a general overview of OpenType Font Variations
20+
1821

1922
}
2023
protected override void ReadContentFrom(BinaryReader reader)

Typography.OpenFont/Tables.Variations/Common.TupleVariationStore.cs

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ namespace Typography.OpenFont.Tables
8686

8787
//The tupleVariationCount field contains a packed value that includes flags and the number of logical tuple variation tables — which is also the number of physical tuple variation headers.The format of the tupleVariationCount value is as follows:
8888
//Mask Name Description
89-
//0x8000 SHARED_POINT_NUMBERS Flag indicating that some or all tuple variation tables reference a shared set of “point” numbers.These shared numbers are represented as packed point number data at the start of the serialized data.
89+
//0x8000 SHARED_POINT_NUMBERS Flag indicating that some or all tuple variation tables reference a shared set of “point” numbers.
90+
// These shared numbers are represented as packed point number data at the start of the serialized data.
9091
//0x7000 Reserved Reserved for future use — set to 0.
9192
//0x0FFF COUNT_MASK Mask for the low bits to give the number of tuple variation tables.
9293

@@ -109,22 +110,58 @@ class TupleVariationHeader
109110
{
110111
//TupleVariationHeader:
111112
//Type Name Description
112-
//int16 variationDataSize The size in bytes of the serialized data for this tuple variation table.
113+
//uint16 variationDataSize The size in bytes of the serialized data for this tuple variation table.
113114
//uint16 tupleIndex A packed field.
114115
// The high 4 bits are flags(see below).
115116
// The low 12 bits are an index into a shared tuple records array.
116-
//Tuple peakTuple Peak tuple record for this tuple variation table — optional,
117-
// determined by flags in the tupleIndex value.
117+
//Tuple peakTuple Peak tuple record for this tuple variation table — optional, determined by flags in the tupleIndex value.
118118
// Note that this must always be included in the 'cvar' table.
119119
//Tuple intermediateStartTuple Intermediate start tuple record for this tuple variation table — optional, determined by flags in the tupleIndex value.
120120
//Tuple intermediateEndTuple Intermediate end tuple record for this tuple variation table — optional, determined by flags in the tupleIndex value.
121121

122-
public short variableDataSize;
123-
public ushort tupleIndex;
122+
public ushort variableDataSize;
123+
124+
public int flags;
125+
public ushort indexToSharedTupleRecArray;
126+
124127
public TupleRecord peakTuple;
125128
public TupleRecord intermediateStartTuple;
126129
public TupleRecord intermediateEndTuple;
127130

131+
132+
public static TupleVariationHeader Read(BinaryReader reader, int axisCount)
133+
{
134+
TupleVariationHeader header = new TupleVariationHeader();
135+
136+
header.variableDataSize = reader.ReadUInt16();
137+
ushort tupleIndex = reader.ReadUInt16();
138+
int flags = (tupleIndex >> 12) & 0xF; //The high 4 bits are flags(see below).
139+
header.flags = flags; //The high 4 bits are flags(see below).
140+
header.indexToSharedTupleRecArray = (ushort)(tupleIndex & 0x0FFF); // The low 12 bits are an index into a shared tuple records array.
141+
142+
143+
if ((flags & ((int)TupleIndexFormat.EMBEDDED_PEAK_TUPLE >> 12)) == ((int)TupleIndexFormat.EMBEDDED_PEAK_TUPLE >> 12))
144+
{
145+
//TODO:...
146+
header.peakTuple = TupleRecord.ReadTupleRecord(reader, axisCount);
147+
}
148+
if ((flags & ((int)TupleIndexFormat.INTERMEDIATE_REGION >> 12)) == ((int)TupleIndexFormat.INTERMEDIATE_REGION >> 12))
149+
{
150+
//TODO:...
151+
header.intermediateStartTuple = TupleRecord.ReadTupleRecord(reader, axisCount);
152+
header.intermediateEndTuple = TupleRecord.ReadTupleRecord(reader, axisCount);
153+
}
154+
155+
return header;
156+
}
157+
158+
159+
160+
//---------
161+
public ushort[] PrivatePoints;
162+
public short[] PackedDeltasXY;
163+
164+
128165
//Note that the size of the TupleVariationHeader is variable,
129166
//depending on whether peak or intermediate tuple records are included. (See below for more information.)
130167

@@ -208,9 +245,22 @@ enum TupleIndexFormat
208245
// }
209246
}
210247

211-
struct TupleRecord
248+
readonly struct TupleRecord
212249
{
213-
public float[] coords;
250+
public readonly float[] coords;
251+
public TupleRecord(float[] coords) => this.coords = coords;
252+
#if DEBUG
253+
public override string ToString() => coords?.Length.ToString() ?? "0";
254+
#endif
255+
public static TupleRecord ReadTupleRecord(BinaryReader reader, int count)
256+
{
257+
float[] coords = new float[count];
258+
for (int n = 0; n < coords.Length; ++n)
259+
{
260+
coords[n] = reader.ReadF2Dot14();
261+
}
262+
return new TupleRecord(coords);
263+
}
214264
}
215265

216266
//----------------------------------------------------------------

Typography.OpenFont/Tables.Variations/FVar.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ public void ReadContent(BinaryReader reader)
145145

146146
}
147147
}
148+
148149
public class InstanceRecord
149150
{
150151
//InstanceRecord
@@ -166,23 +167,24 @@ public class InstanceRecord
166167
//Tuple coordinates The coordinates array for this instance.
167168
//uint16 postScriptNameID Optional.The name ID for entries in the 'name' table that provide PostScript names for this instance.
168169

169-
public ushort subfamilyNameID;
170+
public ushort subfamilyNameID;//point to name table, will be resolved later
170171
public ushort flags;
171-
public float[] coordinates; //tuple record
172-
public ushort postScriptNameID;
172+
public TupleRecord coordinates;
173+
public ushort postScriptNameID;//point to name table, will be resolved later
174+
173175
public void ReadContent(BinaryReader reader, int axisCount, int instanceRecordSize)
174176
{
175177
long expectedEndPos = reader.BaseStream.Position + instanceRecordSize;
176178
subfamilyNameID = reader.ReadUInt16();
177179
flags = reader.ReadUInt16();
178-
coordinates = new float[axisCount];
180+
float[] coords = new float[axisCount];
179181
for (int i = 0; i < axisCount; ++i)
180182
{
181-
coordinates[i] = reader.ReadFixed();
183+
coords[i] = reader.ReadFixed();
182184
}
185+
coordinates = new TupleRecord(coords);
183186

184-
185-
if (reader.BaseStream.Position < instanceRecordSize)
187+
if (reader.BaseStream.Position < expectedEndPos)
186188
{
187189
//optional field
188190
postScriptNameID = reader.ReadUInt16();

0 commit comments

Comments
 (0)