1
#region PDFsharp - A .NET library for processing PDF
4
// Stefan Lange (mailto:Stefan.Lange@pdfsharp.com)
6
// Copyright (c) 2005-2008 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.TrueType
43
/// Base class for all TrueType fonts.
45
internal class TrueTypeFontTable : ICloneable
48
///// Initializes a new instance of the <see cref="TrueTypeFontTable"/> class.
50
//public TrueTypeFontTable(FontData fontData)
52
// this.fontData = fontData;
55
public TrueTypeFontTable(FontData fontData, string tag)
57
this.fontData = fontData;
58
if (fontData != null && fontData.tableDictionary.ContainsKey(tag))
59
this.DirectoryEntry = fontData.tableDictionary[tag];
61
this.DirectoryEntry = new TableDirectoryEntry(tag);
62
this.DirectoryEntry.FontTable = this;
66
/// Creates a deep copy of the current instance.
73
protected virtual TrueTypeFontTable DeepCopy()
75
TrueTypeFontTable fontTable = (TrueTypeFontTable)MemberwiseClone();
76
fontTable.DirectoryEntry.Offset = 0;
77
fontTable.DirectoryEntry.FontTable = fontTable;
82
/// Gets the font image the table belongs to.
84
public FontData FontData
86
get { return this.fontData; }
88
internal FontData fontData;
90
public TableDirectoryEntry DirectoryEntry;
93
/// When overridden in a derived class, prepares the font table to be compiled into its binary representation.
95
public virtual void PrepareForCompilation()
100
/// When overridden in a derived class, converts the font into its binary representation.
102
public virtual void Write(TrueTypeFontWriter writer)
107
/// Calculates the checksum of a table represented by its bytes.
109
public static uint CalcChecksum(byte[] bytes)
111
Debug.Assert((bytes.Length & 3) == 0);
112
// Cannot use Buffer.BlockCopy because 32-bit values are Big-endian
113
uint byte3, byte2, byte1, byte0;
114
byte3 = byte2 = byte1 = byte0 = 0;
115
int length = bytes.Length;
116
for (int idx = 0; idx < length;)
118
byte3 += bytes[idx++];
119
byte2 += bytes[idx++];
120
byte1 += bytes[idx++];
121
byte0 += bytes[idx++];
123
return (byte3 << 24) + (byte2 << 16) + (byte1 << 8) + byte0;