• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2011 Google Inc. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef SFNTLY_CPP_SRC_SFNTLY_TABLE_HEADER_H_
18 #define SFNTLY_CPP_SRC_SFNTLY_TABLE_HEADER_H_
19 
20 #include "sfntly/port/refcount.h"
21 
22 namespace sfntly {
23 
24 class Header : public RefCounted<Header> {
25  public:
26   // Make a partial header with only the basic info for an empty new table.
27   explicit Header(int32_t tag);
28 
29   // Make a partial header with only the basic info for a new table.
30   Header(int32_t tag, int32_t length);
31 
32   // Make a full header as read from an existing font.
33   Header(int32_t tag, int64_t checksum, int32_t offset, int32_t length);
34   virtual ~Header();
35 
36   // Get the table tag.
tag()37   int32_t tag() const { return tag_; }
38 
39   // Get the table offset. The offset is from the start of the font file.  This
40   // offset value is what was read from the font file during construction of the
41   // font. It may not be meaningful if the font was maninpulated through the
42   // builders.
offset()43   int32_t offset() const { return offset_; }
44 
45   // Is the offset in the header valid. The offset will not be valid if the
46   // table was constructed during building and has no physical location in a
47   // font file.
offset_valid()48   bool offset_valid() const { return offset_valid_; }
49 
50   // Get the length of the table as recorded in the table record header.  During
51   // building the header length will reflect the length that was initially read
52   // from the font file. This may not be consistent with the current state of
53   // the data.
length()54   int32_t length() const { return length_; }
55 
56   // Is the length in the header valid. The length will not be valid if the
57   // table was constructed during building and has no physical location in a
58   // font file until the table is built from the builder.
length_valid()59   bool length_valid() const { return length_valid_; }
60 
61   // Get the checksum for the table as recorded in the table record header.
checksum()62   int64_t checksum() const { return checksum_; }
63 
64   // Is the checksum valid. The checksum will not be valid if the table was
65   // constructed during building and has no physical location in a font file.
66   // Note that this does *NOT* check the validity of the checksum against
67   // the calculated checksum for the table data.
checksum_valid()68   bool checksum_valid() const { return checksum_valid_; }
69 
70   // UNIMPLEMENTED: boolean equals(Object obj)
71   //                int hashCode()
72   //                string toString()
73 
74  private:
75   const int32_t tag_;
76   const int32_t offset_;
77   const bool offset_valid_;
78   const int32_t length_;
79   const bool length_valid_;
80   const int64_t checksum_;
81   const bool checksum_valid_;
82 
83   friend class HeaderComparatorByOffset;
84   friend class HeaderComparatorByTag;
85 };
86 typedef Ptr<Header> HeaderPtr;
87 
88 class HeaderComparator {
89  public:
~HeaderComparator()90   virtual ~HeaderComparator() {}
91   virtual bool operator()(const HeaderPtr h1,
92                           const HeaderPtr h2) const = 0;
93 };
94 
95 class HeaderComparatorByOffset : public HeaderComparator {
96  public:
~HeaderComparatorByOffset()97   virtual ~HeaderComparatorByOffset() {}
98   virtual bool operator()(const HeaderPtr h1,
99                           const HeaderPtr h2) const;
100 };
101 
102 class HeaderComparatorByTag : public HeaderComparator {
103  public:
~HeaderComparatorByTag()104   virtual ~HeaderComparatorByTag() {}
105   virtual bool operator()(const HeaderPtr h1,
106                           const HeaderPtr h2) const;
107 };
108 
109 typedef std::set<HeaderPtr, HeaderComparatorByOffset> HeaderOffsetSortedSet;
110 typedef std::set<HeaderPtr, HeaderComparatorByTag> HeaderTagSortedSet;
111 
112 }  // namespace sfntly
113 
114 #endif  // SFNTLY_CPP_SRC_SFNTLY_TABLE_HEADER_H_
115