2020-01-05 12:08:01 +00:00
|
|
|
|
namespace UglyToad.PdfPig.Fonts.CompactFontFormat.Dictionaries
|
2018-04-29 14:42:54 +01:00
|
|
|
|
{
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using Core;
|
|
|
|
|
|
|
2018-11-17 22:16:27 +00:00
|
|
|
|
internal class CompactFontFormatTopLevelDictionaryReader : CompactFontFormatDictionaryReader<CompactFontFormatTopLevelDictionary, CompactFontFormatTopLevelDictionary>
|
2018-04-29 14:42:54 +01:00
|
|
|
|
{
|
2024-04-18 11:58:40 -07:00
|
|
|
|
public override CompactFontFormatTopLevelDictionary Read(CompactFontFormatData data, ReadOnlySpan<string> stringIndex)
|
2018-04-29 14:42:54 +01:00
|
|
|
|
{
|
|
|
|
|
|
var dictionary = new CompactFontFormatTopLevelDictionary();
|
|
|
|
|
|
|
|
|
|
|
|
ReadDictionary(dictionary, data, stringIndex);
|
|
|
|
|
|
|
|
|
|
|
|
return dictionary;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-18 11:58:40 -07:00
|
|
|
|
protected override void ApplyOperation(CompactFontFormatTopLevelDictionary dictionary, List<Operand> operands, OperandKey key, ReadOnlySpan<string> stringIndex)
|
2018-04-29 14:42:54 +01:00
|
|
|
|
{
|
|
|
|
|
|
switch (key.Byte0)
|
|
|
|
|
|
{
|
|
|
|
|
|
case 0:
|
|
|
|
|
|
dictionary.Version = GetString(operands, stringIndex);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
dictionary.Notice = GetString(operands, stringIndex);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
dictionary.FullName = GetString(operands, stringIndex);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
dictionary.FamilyName = GetString(operands, stringIndex);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 4:
|
|
|
|
|
|
dictionary.Weight = GetString(operands, stringIndex);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 5:
|
|
|
|
|
|
dictionary.FontBoundingBox = GetBoundingBox(operands);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 12:
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!key.Byte1.HasValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new InvalidOperationException("A single byte sequence beginning with 12 was found.");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch (key.Byte1.Value)
|
|
|
|
|
|
{
|
|
|
|
|
|
case 0:
|
|
|
|
|
|
dictionary.Copyright = GetString(operands, stringIndex);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 1:
|
2024-03-03 21:59:35 +00:00
|
|
|
|
dictionary.IsFixedPitch = operands[0].Double == 1;
|
2018-04-29 14:42:54 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case 2:
|
2024-03-03 21:59:35 +00:00
|
|
|
|
dictionary.ItalicAngle = operands[0].Double;
|
2018-04-29 14:42:54 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case 3:
|
2024-03-03 21:59:35 +00:00
|
|
|
|
dictionary.UnderlinePosition = operands[0].Double;
|
2018-04-29 14:42:54 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case 4:
|
2024-03-03 21:59:35 +00:00
|
|
|
|
dictionary.UnderlineThickness = operands[0].Double;
|
2018-04-29 14:42:54 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case 5:
|
2024-03-03 21:59:35 +00:00
|
|
|
|
dictionary.PaintType = operands[0].Double;
|
2018-04-29 14:42:54 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case 6:
|
2018-11-16 21:30:59 +00:00
|
|
|
|
dictionary.CharStringType = (CompactFontFormatCharStringType)GetIntOrDefault(operands, 2);
|
2018-04-29 14:42:54 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case 7:
|
|
|
|
|
|
{
|
|
|
|
|
|
var array = ToArray(operands);
|
|
|
|
|
|
|
2019-05-10 20:02:29 +01:00
|
|
|
|
if (array.Length == 4)
|
|
|
|
|
|
{
|
|
|
|
|
|
dictionary.FontMatrix = TransformationMatrix.FromArray(array);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (array.Length == 6)
|
|
|
|
|
|
{
|
|
|
|
|
|
dictionary.FontMatrix = TransformationMatrix.FromArray(array);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
2018-04-29 14:42:54 +01:00
|
|
|
|
{
|
2023-09-12 16:56:13 +02:00
|
|
|
|
throw new InvalidOperationException($"Expected four values for the font matrix, instead got: {array.Length}.");
|
2018-04-29 14:42:54 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 8:
|
2024-03-03 21:59:35 +00:00
|
|
|
|
dictionary.StrokeWidth = operands[0].Double;
|
2018-04-29 14:42:54 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case 20:
|
|
|
|
|
|
dictionary.SyntheticBaseFontIndex = GetIntOrDefault(operands);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 21:
|
|
|
|
|
|
dictionary.PostScript = GetString(operands, stringIndex);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 22:
|
|
|
|
|
|
dictionary.BaseFontName = GetString(operands, stringIndex);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 23:
|
|
|
|
|
|
dictionary.BaseFontBlend = ReadDeltaToArray(operands);
|
|
|
|
|
|
break;
|
|
|
|
|
|
// TODO: CID Font Stuff
|
|
|
|
|
|
case 30:
|
2018-12-28 22:34:47 +00:00
|
|
|
|
var registry = GetString(operands, stringIndex);
|
|
|
|
|
|
operands.RemoveAt(0);
|
|
|
|
|
|
var ordering = GetString(operands, stringIndex);
|
|
|
|
|
|
operands.RemoveAt(0);
|
|
|
|
|
|
var supplement = GetIntOrDefault(operands);
|
|
|
|
|
|
dictionary.CidFontOperators.Ros = new RegistryOrderingSupplement
|
|
|
|
|
|
{
|
|
|
|
|
|
Registry = registry,
|
|
|
|
|
|
Ordering = ordering,
|
|
|
|
|
|
Supplement = supplement
|
|
|
|
|
|
};
|
|
|
|
|
|
dictionary.IsCidFont = true;
|
2018-04-29 14:42:54 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case 31:
|
2018-12-28 22:34:47 +00:00
|
|
|
|
dictionary.CidFontOperators.Version = GetIntOrDefault(operands);
|
2018-04-29 14:42:54 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case 32:
|
2018-12-28 22:34:47 +00:00
|
|
|
|
dictionary.CidFontOperators.Revision = GetIntOrDefault(operands);
|
2018-04-29 14:42:54 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case 33:
|
2018-12-28 22:34:47 +00:00
|
|
|
|
dictionary.CidFontOperators.Type = GetIntOrDefault(operands);
|
2018-04-29 14:42:54 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case 34:
|
2018-12-28 22:34:47 +00:00
|
|
|
|
dictionary.CidFontOperators.Count = GetIntOrDefault(operands);
|
2018-04-29 14:42:54 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case 35:
|
2018-12-28 22:34:47 +00:00
|
|
|
|
dictionary.CidFontOperators.UidBase = GetIntOrDefault(operands);
|
2018-04-29 14:42:54 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case 36:
|
2018-12-28 22:34:47 +00:00
|
|
|
|
dictionary.CidFontOperators.FontDictionaryArray = GetIntOrDefault(operands);
|
2018-04-29 14:42:54 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case 37:
|
2018-12-29 11:41:46 +00:00
|
|
|
|
dictionary.CidFontOperators.FontDictionarySelect = GetIntOrDefault(operands);
|
2018-04-29 14:42:54 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case 38:
|
2018-12-28 22:34:47 +00:00
|
|
|
|
dictionary.CidFontOperators.FontName = GetString(operands, stringIndex);
|
2018-04-29 14:42:54 +01:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 13:
|
2024-03-03 21:59:35 +00:00
|
|
|
|
dictionary.UniqueId = operands.Count > 0 ? operands[0].Double : 0;
|
2018-04-29 14:42:54 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case 14:
|
|
|
|
|
|
dictionary.Xuid = ToArray(operands);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 15:
|
|
|
|
|
|
dictionary.CharSetOffset = GetIntOrDefault(operands);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 16:
|
|
|
|
|
|
dictionary.EncodingOffset = GetIntOrDefault(operands);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 17:
|
|
|
|
|
|
dictionary.CharStringsOffset = GetIntOrDefault(operands);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 18:
|
|
|
|
|
|
{
|
|
|
|
|
|
var size = GetIntOrDefault(operands);
|
|
|
|
|
|
operands.RemoveAt(0);
|
|
|
|
|
|
var offset = GetIntOrDefault(operands);
|
2018-11-18 13:53:43 +00:00
|
|
|
|
dictionary.PrivateDictionaryLocation = new CompactFontFormatTopLevelDictionary.SizeAndOffset(size, offset);
|
2018-04-29 14:42:54 +01:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|