1
#region PDFsharp - A .NET library for processing PDF
4
// Stefan Lange (mailto:Stefan.Lange@pdfsharp.com)
6
// Copyright (c) 2005-2009 empira Software GmbH, Cologne (Germany)
8
// http://www.pdfsharp.com
9
// http://sourceforge.net/projects/pdfsharp
11
// Permission is hereby granted, free of charge, to any person obtaining a
12
// copy of this software and associated documentation files (the "Software"),
13
// to deal in the Software without restriction, including without limitation
14
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
15
// and/or sell copies of the Software, and to permit persons to whom the
16
// Software is furnished to do so, subject to the following conditions:
18
// The above copyright notice and this permission notice shall be included
19
// in all copies or substantial portions of the Software.
21
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27
// DEALINGS IN THE SOFTWARE.
31
using System.Diagnostics;
32
using System.Runtime.InteropServices;
33
using PdfSharp.Drawing;
34
using PdfSharp.Internal;
36
using Fixed = System.Int32;
37
using FWord = System.Int16;
38
using UFWord = System.UInt16;
40
namespace PdfSharp.Fonts.OpenType
43
/// Base class for all OpenType fonts.
45
internal class OpenTypeFontTable : ICloneable
47
public OpenTypeFontTable(FontData fontData, string tag)
49
this.fontData = fontData;
50
if (fontData != null && fontData.tableDictionary.ContainsKey(tag))
51
this.DirectoryEntry = fontData.tableDictionary[tag];
53
this.DirectoryEntry = new TableDirectoryEntry(tag);
54
this.DirectoryEntry.FontTable = this;
58
/// Creates a deep copy of the current instance.
65
protected virtual OpenTypeFontTable DeepCopy()
67
OpenTypeFontTable fontTable = (OpenTypeFontTable)MemberwiseClone();
68
fontTable.DirectoryEntry.Offset = 0;
69
fontTable.DirectoryEntry.FontTable = fontTable;
74
/// Gets the font image the table belongs to.
76
public FontData FontData
78
get { return this.fontData; }
80
internal FontData fontData;
82
public TableDirectoryEntry DirectoryEntry;
85
/// When overridden in a derived class, prepares the font table to be compiled into its binary representation.
87
public virtual void PrepareForCompilation()
92
/// When overridden in a derived class, converts the font into its binary representation.
94
public virtual void Write(OpenTypeFontWriter writer)
99
/// Calculates the checksum of a table represented by its bytes.
101
public static uint CalcChecksum(byte[] bytes)
103
Debug.Assert((bytes.Length & 3) == 0);
104
// Cannot use Buffer.BlockCopy because 32-bit values are Big-endian
105
uint byte3, byte2, byte1, byte0;
106
byte3 = byte2 = byte1 = byte0 = 0;
107
int length = bytes.Length;
108
for (int idx = 0; idx < length;)
110
byte3 += bytes[idx++];
111
byte2 += bytes[idx++];
112
byte1 += bytes[idx++];
113
byte0 += bytes[idx++];
115
return (byte3 << 24) + (byte2 << 16) + (byte1 << 8) + byte0;