protected void ReadPrivate(BinaryReaderFont reader) { long start = reader.Position; //Console.WriteLine("private dict: {0}", topDict.Private); privateDict = CFFPrivateDict.Read(reader, (int)topDict.Private.values[0]); //Console.WriteLine("private dict: {0}", privateDict); //reader.Position = position + (int)topDict.Private.values[1]; //CFFIndex index = CFFIndex.Read(reader); //int[] offset = index.offset; //Console.WriteLine("local subr index: {0}", index); if (privateDict.Subrs > 0) { reader.Position = start + (int)privateDict.Subrs; CFFIndex index = CFFIndex.Read(reader); int[] offset = index.ReadAllOffsets(reader); //Console.WriteLine("local subr index: {0}", index); localSubr = new byte[index.count][]; for (int i = 0; i < offset.Length - 1; i++) { int length = offset[i + 1] - offset[i]; localSubr[i] = reader.ReadBytes(length); } } charString.localSubr = localSubr; }
protected void ReadTopDict(BinaryReaderFont reader) { CFFIndex index = CFFIndex.Read(reader); //Console.WriteLine("topDict: {0}", index); int[] offset = index.ReadAllOffsets(reader); int length = offset[1] - offset[0]; topDict = CFFTopDict.Read(reader, length); }
protected void ReadName(BinaryReaderFont reader) { CFFIndex index = CFFIndex.Read(reader); int[] offset = index.ReadAllOffsets(reader); names = new string[index.count]; int length = offset.Length - 1; for (int i = 0; i < length; i++) { int byteSize = offset[i + 1] - offset[i]; names[i] = reader.ReadString(byteSize); } }
protected void ReadGlobalSubr(BinaryReaderFont reader) { CFFIndex index = CFFIndex.Read(reader); int[] offset = index.ReadAllOffsets(reader); //Console.WriteLine("global subr index: {0}", index); globalSubr = new byte[index.count][]; int length = offset.Length - 1; for (int i = 0; i < length; i++) { int byteSize = offset[i + 1] - offset[i]; globalSubr[i] = reader.ReadBytes(byteSize); } charString.globalSubr = globalSubr; }
protected void ReadString(BinaryReaderFont reader) { CFFIndex index = CFFIndex.Read(reader); int[] offset = index.ReadAllOffsets(reader); //Console.WriteLine("string index: {0}", index); strings = new string[index.count]; int length = offset.Length - 1; for (int i = 0; i < length; i++) { int byteSize = offset[i + 1] - offset[i]; //value.strings[i] = value.ConvertString(reader.ReadBytes(length)); strings[i] = reader.ReadString(byteSize); } }
public static CFFIndex Read(BinaryReaderFont reader) { CFFIndex value = new CFFIndex(); value.count = reader.ReadUInt16(); if (value.count == 0) { //value.offset = new int[0]; return(value); } value.offSize = reader.ReadByte(); value.position = reader.Position; /* * switch (value.offSize) { * case 1: * value.offset = Array.ConvertAll( * reader.ReadBytes(value.count + 1), * new Converter<byte, int>((a) => { * return a; * }) * ); * break; * case 2: * value.offset = Array.ConvertAll( * reader.ReadUInt16Array(value.count + 1), * new Converter<ushort, int>((a) => { * return a; * }) * ); * break; * case 3: * value.offset = reader.ReadUInt24Array(value.count + 1); * break; * case 4: * value.offset = reader.ReadInt32Array(value.count + 1); * break; * } */ //value.offset = reader.ReadBytes(value.offSize + 1); //for (int i = 0; i < value.offset.Length; i += 2) { // int length = value.offset[i + 1] - value.offset[i]; // value.data = reader.ReadBytes(length); //} return(value); }
public GraphicsPath GetGlyph(int glyphId, bool hasWidth) { if (glyphId < 0) { return(null); } if (File.Exists(filePath) == false) { return(null); } byte[] cs = null; using (Stream stream = File.OpenRead(filePath)) using (BinaryReaderFont reader = new BinaryReaderFont(stream)) { reader.Position = position + topDict.CharStrings; CFFIndex index = CFFIndex.Read(reader); //Console.WriteLine("CharStrings index: {0}", index); long offsetStart = reader.Position; int offset0 = 0; int offset1 = 0; index.ReadOffset(reader, glyphId, out offset0, out offset1); int byteSize = offset1 - offset0; if (byteSize <= 0) { return(null); } //Console.WriteLine("offset0: {0}, {1}", offset0, offset1); //Console.WriteLine("lastItem: {0}", offsetStart); offsetStart += (index.count + 1) * index.offSize; //Console.WriteLine("lastItem: {0}", offsetStart); reader.Position = offsetStart + offset0 - 1; cs = reader.ReadBytes(byteSize); } if (cs == null) { return(null); } //Console.WriteLine("Docode: {0}", CFFCharString.Decode(charString)); return(charString.CreateGlyph(cs, hasWidth)); }