public void LoadFontDescription_CultureNamePriority_FirstWindows() { var usCulture = new CultureInfo(0x0409); var c1 = new CultureInfo(1034); // spanish - international var c2 = new CultureInfo(3082); // spanish - traditional var writer = new BigEndianBinaryWriter(); writer.WriteTrueTypeFileHeader(1, 0, 0, 0); writer.WriteTableHeader("name", 0, 28, 999); writer.WriteNameTable( (KnownNameIds.FullFontName, "name_c1", c1), (KnownNameIds.FontSubfamilyName, "sub_c1", c1), (KnownNameIds.FontFamilyName, "fam_c1", c1), (KnownNameIds.FullFontName, "name_c2", c2), (KnownNameIds.FontSubfamilyName, "sub_c2", c2), (KnownNameIds.FontFamilyName, "fam_c2", c2)); var description = FontDescription.LoadDescription(writer.GetStream()); // unknown culture should prioritise US, but missing so will return first Assert.Equal("name_c1", description.FontNameInvariantCulture); Assert.Equal("sub_c1", description.FontSubFamilyNameInvariantCulture); Assert.Equal("fam_c1", description.FontFamilyInvariantCulture); }
public void LoadFontDescription_GetNameById() { var c1 = new CultureInfo(1034); // spanish - international var c2 = new CultureInfo(3082); // spanish - traditional var writer = new BigEndianBinaryWriter(); writer.WriteTrueTypeFileHeader(1, 0, 0, 0); writer.WriteTableHeader("name", 0, 28, 999); writer.WriteNameTable( (KnownNameIds.FullFontName, "name_c1", c1), (KnownNameIds.FontSubfamilyName, "sub_c1", c1), (KnownNameIds.FontFamilyName, "fam_c1", c1), (KnownNameIds.FullFontName, "name_c2", c2), (KnownNameIds.FontSubfamilyName, "sub_c2", c2), (KnownNameIds.FontFamilyName, "fam_c2", c2)); var description = FontDescription.LoadDescription(writer.GetStream()); Assert.Equal("name_c1", description.GetNameById(c1, KnownNameIds.FullFontName)); Assert.Equal("sub_c1", description.GetNameById(c1, KnownNameIds.FontSubfamilyName)); Assert.Equal("fam_c1", description.GetNameById(c1, KnownNameIds.FontFamilyName)); Assert.Equal("name_c2", description.GetNameById(c2, KnownNameIds.FullFontName)); Assert.Equal("sub_c2", description.GetNameById(c2, KnownNameIds.FontSubfamilyName)); Assert.Equal("fam_c2", description.GetNameById(c2, KnownNameIds.FontFamilyName)); }
public static void WriteCffFileHeader( this BigEndianBinaryWriter writer, ushort tableCount, ushort searchRange, ushort entrySelector, ushort rangeShift) // uint32 | sfntVersion 0x00010000 or 0x4F54544F('OTTO') — see below. => writer.WriteFileHeader(0x4F54544F, tableCount, searchRange, entrySelector, rangeShift);
public void ReadTrueTypeOutlineType() { var writer = new BigEndianBinaryWriter(); writer.WriteTrueTypeFileHeader(0, 0, 0, 0); var reader = new FontReader(writer.GetStream()); Assert.Equal(FontReader.OutlineTypes.TrueType, reader.OutlineType); }
public void ReadCcfOutlineType() { var writer = new BigEndianBinaryWriter(); writer.WriteCffFileHeader(0, 0, 0, 0); Assert.Throws <Exceptions.InvalidFontFileException>( () => { var reader = new FontReader(writer.GetStream()); }); }
public void ReadTableHeaders() { var writer = new BigEndianBinaryWriter(); writer.WriteTrueTypeFileHeader(2, 0, 0, 0); writer.WriteTableHeader("name", 0, 10, 0); writer.WriteTableHeader("cmap", 0, 1, 0); var reader = new FontReader(writer.GetStream()); Assert.Equal(2, reader.Headers.Count); }
public static void WriteTableHeader(this BigEndianBinaryWriter writer, string tag, uint checksum, uint?offset, uint length) { // table header // Record Type | Name | Description // ------------|----------|--------------------------------------------------- // uint32 | tag | 4 - byte identifier. // uint32 | checkSum | CheckSum for this table. // Offset32 | offset | Offset from beginning of TrueType font file. // uint32 | length | Length of this table. writer.WriteUInt32(tag); writer.WriteUInt32(checksum); writer.WriteOffset32(offset); writer.WriteUInt32(length); }
private static void WriteFileHeader(this BigEndianBinaryWriter writer, uint version, ushort tableCount, ushort searchRange, ushort entrySelector, ushort rangeShift) { // file header // Type Name | name | Description // ----------|---------------|------------------------------ // uint32 | sfntVersion | 0x00010000 or 0x4F54544F('OTTO') — see below. // uint16 | numTables | Number of tables. // uint16 | searchRange | (Maximum power of 2 <= numTables) x 16. // uint16 | entrySelector | Log2(maximum power of 2 <= numTables). // uint16 | rangeShift | NumTables x 16 - searchRange. writer.WriteUInt32(version); writer.WriteUInt16(tableCount); writer.WriteUInt16(searchRange); writer.WriteUInt16(entrySelector); writer.WriteUInt16(rangeShift); }
public void LoadFontDescription() { var writer = new BigEndianBinaryWriter(); writer.WriteTrueTypeFileHeader(1, 0, 0, 0); writer.WriteTableHeader("name", 0, 28, 999); writer.WriteNameTable( new Dictionary <WellKnownIds.NameIds, string> { { WellKnownIds.NameIds.FullFontName, "name" }, { WellKnownIds.NameIds.FontSubfamilyName, "sub" }, { WellKnownIds.NameIds.FontFamilyName, "fam" } }); var description = FontDescription.LoadDescription(writer.GetStream()); Assert.Equal("name", description.FontNameInvariantCulture); Assert.Equal("sub", description.FontSubFamilyNameInvariantCulture); Assert.Equal("fam", description.FontFamilyInvariantCulture); }
public void ReadCMapTable() { var writer = new BigEndianBinaryWriter(); writer.WriteTrueTypeFileHeader(new TableHeader("cmap", 0, 0, 20)); writer.WriteCMapTable( new[] { new Fonts.Tables.General.CMap.Format0SubTable( 0, WellKnownIds.PlatformIDs.Macintosh, 1, new byte[] { 2, 9 }) }); var reader = new FontReader(writer.GetStream()); CMapTable cmap = reader.GetTable <CMapTable>(); Assert.NotNull(cmap); }
private static void WriteFileHeader(this BigEndianBinaryWriter writer, uint version, params TableHeader[] headers) { // file header // Type Name | name | Description // ----------|---------------|------------------------------ // uint32 | sfntVersion | 0x00010000 or 0x4F54544F('OTTO') — see below. // uint16 | numTables | Number of tables. // uint16 | searchRange | (Maximum power of 2 <= numTables) x 16. // uint16 | entrySelector | Log2(maximum power of 2 <= numTables). // uint16 | rangeShift | NumTables x 16 - searchRange. writer.WriteUInt32(version); writer.WriteUInt16((ushort)headers.Length); writer.WriteUInt16(0); writer.WriteUInt16(0); writer.WriteUInt16(0); int offset = 12; offset += headers.Length * 16; foreach (TableHeader h in headers) { writer.WriteTableHeader(h.Tag, h.CheckSum, (uint)offset, h.Length); offset += (int)h.Length; } }
public static void WriteNameTable(this BigEndianBinaryWriter writer, Dictionary <KnownNameIds, string> names, List <string> languages = null) => writer.WriteNameTable(names.Select(x => (x.Key, x.Value, CultureInfo.InvariantCulture)).ToList(), languages);
public static void WriteTrueTypeFileHeader(this BigEndianBinaryWriter writer, params TableHeader[] headers) // uint32 | sfntVersion 0x00010000 or 0x4F54544F('OTTO') — see below. => writer.WriteFileHeader(0x00010000, headers);