public override byte[] GetData(ushort[] glyfIndexes) { System.IO.MemoryStream ms = new System.IO.MemoryStream(); int hMetricsCount = calculateNumOfLongHorMetrics(glyfIndexes); for (int i = 0; i < hMetricsCount; ++i) { if (i >= _hMetrics.Count) { break; } LongHorMetric tmp = _hMetrics[i]; ms.Write(BinaryUtility.UInt16ToBytes((ushort)tmp.AdvanceWidth), 0, 2); ms.Write(BinaryUtility.UInt16ToBytes((ushort)tmp.Lsb), 0, 2); } int glyfsCount = glyfIndexes[glyfIndexes.Length - 1] + 1; int leftSideBearingCount = glyfsCount - hMetricsCount; if (leftSideBearingCount > 0 && _leftSideBearing.Count > 0) { int start = calculateStartLeftSideBearing(glyfIndexes); for (int i = 0; i < leftSideBearingCount; ++i) { if (i >= _leftSideBearing.Count + start) { break; } ms.Write(BinaryUtility.UInt16ToBytes((ushort)_leftSideBearing[start + i]), 0, 2); } } byte[] tempFontData = new byte[ms.Length]; ms.Position = 0; ms.Read(tempFontData, 0, tempFontData.Length); return(tempFontData); }
public override void Read(Reader reader, int offset, int length) { if (length < 0 || offset <= 0 || offset >= reader.Length) { throw new PDFWrongFontFileException(); } reader.Position = offset; for (int i = 0; i < _numberOfHMetrics; ++i) { LongHorMetric tmp = new LongHorMetric(); tmp.AdvanceWidth = (ushort)reader.ReadUint16(); tmp.Lsb = (short)reader.ReadUint16(); _hMetrics.Add(tmp); } int count = _numGlyphs - _numberOfHMetrics; for (int i = 0; i < count; ++i) { _leftSideBearing.Add((short)reader.ReadUint16()); } }