/// <summary> /// This will parse a kern pair from the data stream. /// </summary> /// <returns>The kern pair that was parsed from the stream.</returns> /// <exception cref="IOException">If there is an error reading from the stream.</exception> private KernPair ParseKernPair() { KernPair kernPair = null; string cmd = ReadString(); if (KERN_PAIR_KP.Equals(cmd)) { kernPair = new KernPair { FirstKernCharacter = ReadString(), SecondKernCharacter = ReadString(), X = ReadFloat(), Y = ReadFloat() }; } else if (KERN_PAIR_KPH.Equals(cmd)) { kernPair = new KernPair { FirstKernCharacter = HexToString(ReadString()), SecondKernCharacter = HexToString(ReadString()), X = ReadFloat(), Y = ReadFloat() }; } else if (KERN_PAIR_KPX.Equals(cmd)) { kernPair = new KernPair { FirstKernCharacter = ReadString(), SecondKernCharacter = ReadString(), X = ReadFloat(), Y = 0 }; } else if (KERN_PAIR_KPY.Equals(cmd)) { kernPair = new KernPair { FirstKernCharacter = ReadString(), SecondKernCharacter = ReadString(), X = 0, Y = ReadFloat() }; } else { throw new IOException("Error expected kern pair command actual='" + cmd + "'"); } return(kernPair); }
/// <summary> /// This will parse the kern data. /// </summary> /// <param name="fontMetrics">The metrics class to put the parsed data into.</param> /// <exception cref="IOException">If there is an error parsing the data.</exception> private void ParseKernData(FontMetrics fontMetrics) { string nextCommand; while (!(nextCommand = ReadString()).Equals(END_KERN_DATA)) { if (START_TRACK_KERN.Equals(nextCommand)) { int count = ReadInt(); for (int i = 0; i < count; i++) { fontMetrics.AddTrackKern(new TrackKern { Degree = ReadInt(), MinPointSize = ReadFloat(), MinKern = ReadFloat(), MaxPointSize = ReadFloat(), MaxKern = ReadFloat() }); } string end = ReadString(); if (!end.Equals(END_TRACK_KERN)) { throw new IOException("Error: Expected '" + END_TRACK_KERN + "' actual '" + end + "'"); } } else if (START_KERN_PAIRS.Equals(nextCommand)) { int count = ReadInt(); for (int i = 0; i < count; i++) { KernPair pair = ParseKernPair(); fontMetrics.AddKernPair(pair); } String end = ReadString(); if (!end.Equals(END_KERN_PAIRS)) { throw new IOException("Error: Expected '" + END_KERN_PAIRS + "' actual '" + end + "'"); } } else if (START_KERN_PAIRS0.Equals(nextCommand)) { int count = ReadInt(); for (int i = 0; i < count; i++) { KernPair pair = ParseKernPair(); fontMetrics.AddKernPair0(pair); } string end = ReadString(); if (!end.Equals(END_KERN_PAIRS)) { throw new IOException("Error: Expected '" + END_KERN_PAIRS + "' actual '" + end + "'"); } } else if (START_KERN_PAIRS1.Equals(nextCommand)) { int count = ReadInt(); for (int i = 0; i < count; i++) { KernPair pair = ParseKernPair(); fontMetrics.AddKernPair1(pair); } string end = ReadString(); if (!end.Equals(END_KERN_PAIRS)) { throw new IOException("Error: Expected '" + END_KERN_PAIRS + "' actual '" + end + "'"); } } else { throw new IOException("Unknown kerning data type '" + nextCommand + "'"); } } }