public void ChecksumAdjustment(byte[] headersBuffer, uint headerOffset, uint headerLength, uint tablesChecksum = 0) { Debug.Assert(_headIndex != -1); if (_headIndex == -1) { return; } var headTable = _woffTables[_headIndex] as WoffTableHead; Debug.Assert(headTable != null); if (headTable == null) { return; } // Compute the checksum of the font's header Debug.Assert(headerLength != 0); Debug.Assert(headersBuffer != null && headersBuffer.Length != 0); var headerPadding = (uint)WoffBuffer.CalcPadBytes((int)headerLength, 4); var buffer = headersBuffer; if (headerPadding > 0) { var paddedLength = headerLength + headerPadding; buffer = new byte[paddedLength]; Buffer.BlockCopy(headersBuffer, 0, buffer, 0, headersBuffer.Length); } uint nLongs = (headerLength + 3) / 4; uint headerChecksum = 0; for (uint i = 0; i < nLongs; i += 4) { headerChecksum += WoffBuffer.GetUIntBE(buffer, i); } // Compute the checksum of the font by summing the checksum of the header and tables var fontChecksum = headerChecksum; if (tablesChecksum == 0) { tablesChecksum = headerChecksum; for (ushort i = 0; i < _woffDirs.Count; i++) { tablesChecksum += _woffDirs[i].OrigChecksum; } } fontChecksum += headerChecksum; // Finally, update the 'head' table's checkSumAdjustment. headTable.CheckSumAdjustment = 0xB1B0AFBA - fontChecksum; }
public uint CalculateChecksum() { Debug.Assert(_origLength != 0); Debug.Assert(_origTable != null && _origTable.Length != 0); var padBytesLength = (uint)WoffBuffer.CalcPadBytes((int)_origLength, 4); if (padBytesLength != 0) { _padding = padBytesLength; } var origLength = _origLength; var buffer = _origTable; if (_padding > 0) { origLength = _origLength + _padding; buffer = new byte[origLength]; Buffer.BlockCopy(_origTable, 0, buffer, 0, _origTable.Length); } uint nLongs = (_origLength + 3) / 4; uint sum = 0; //for (uint i = 0; i < nLongs; i++) //{ // sum += WoffBuffer.GetUIntBE(buffer, i * 4); //} for (uint i = 0; i < nLongs; i += 4) { sum += WoffBuffer.GetUIntBE(buffer, i); } return(sum); }