1 : // Copyright (c) 2010 Mozilla Foundation. All rights reserved.
2 : // Use of this source code is governed by a BSD-style license that can be
3 : // found in the LICENSE file.
4 :
5 : #include "graphite.h"
6 :
7 : // Support for preserving (NOT sanitizing) the Graphite tables
8 :
9 : namespace ots {
10 :
11 : // 'Silf'
12 0 : bool ots_silf_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
13 0 : Buffer table(data, length);
14 :
15 0 : OpenTypeSILF *silf = new OpenTypeSILF;
16 0 : file->silf = silf;
17 :
18 0 : if (!table.Skip(length)) {
19 0 : return OTS_FAILURE();
20 : }
21 :
22 0 : silf->data = data;
23 0 : silf->length = length;
24 0 : return true;
25 : }
26 :
27 0 : bool ots_silf_should_serialise(OpenTypeFile *file) {
28 0 : return file->preserve_graphite && file->silf;
29 : }
30 :
31 0 : bool ots_silf_serialise(OTSStream *out, OpenTypeFile *file) {
32 0 : const OpenTypeSILF *silf = file->silf;
33 :
34 0 : if (!out->Write(silf->data, silf->length)) {
35 0 : return OTS_FAILURE();
36 : }
37 :
38 0 : return true;
39 : }
40 :
41 0 : void ots_silf_free(OpenTypeFile *file) {
42 0 : delete file->silf;
43 0 : }
44 :
45 : // 'Sill'
46 0 : bool ots_sill_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
47 0 : Buffer table(data, length);
48 :
49 0 : OpenTypeSILL *sill = new OpenTypeSILL;
50 0 : file->sill = sill;
51 :
52 0 : if (!table.Skip(length)) {
53 0 : return OTS_FAILURE();
54 : }
55 :
56 0 : sill->data = data;
57 0 : sill->length = length;
58 0 : return true;
59 : }
60 :
61 0 : bool ots_sill_should_serialise(OpenTypeFile *file) {
62 0 : return file->preserve_graphite && file->sill;
63 : }
64 :
65 0 : bool ots_sill_serialise(OTSStream *out, OpenTypeFile *file) {
66 0 : const OpenTypeSILL *sill = file->sill;
67 :
68 0 : if (!out->Write(sill->data, sill->length)) {
69 0 : return OTS_FAILURE();
70 : }
71 :
72 0 : return true;
73 : }
74 :
75 0 : void ots_sill_free(OpenTypeFile *file) {
76 0 : delete file->sill;
77 0 : }
78 :
79 : // 'Gloc'
80 0 : bool ots_gloc_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
81 0 : Buffer table(data, length);
82 :
83 0 : OpenTypeGLOC *gloc = new OpenTypeGLOC;
84 0 : file->gloc = gloc;
85 :
86 0 : if (!table.Skip(length)) {
87 0 : return OTS_FAILURE();
88 : }
89 :
90 0 : gloc->data = data;
91 0 : gloc->length = length;
92 0 : return true;
93 : }
94 :
95 0 : bool ots_gloc_should_serialise(OpenTypeFile *file) {
96 0 : return file->preserve_graphite && file->gloc;
97 : }
98 :
99 0 : bool ots_gloc_serialise(OTSStream *out, OpenTypeFile *file) {
100 0 : const OpenTypeGLOC *gloc = file->gloc;
101 :
102 0 : if (!out->Write(gloc->data, gloc->length)) {
103 0 : return OTS_FAILURE();
104 : }
105 :
106 0 : return true;
107 : }
108 :
109 0 : void ots_gloc_free(OpenTypeFile *file) {
110 0 : delete file->gloc;
111 0 : }
112 :
113 : // 'Glat'
114 0 : bool ots_glat_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
115 0 : Buffer table(data, length);
116 :
117 0 : OpenTypeGLAT *glat = new OpenTypeGLAT;
118 0 : file->glat = glat;
119 :
120 0 : if (!table.Skip(length)) {
121 0 : return OTS_FAILURE();
122 : }
123 :
124 0 : glat->data = data;
125 0 : glat->length = length;
126 0 : return true;
127 : }
128 :
129 0 : bool ots_glat_should_serialise(OpenTypeFile *file) {
130 0 : return file->preserve_graphite && file->glat;
131 : }
132 :
133 0 : bool ots_glat_serialise(OTSStream *out, OpenTypeFile *file) {
134 0 : const OpenTypeGLAT *glat = file->glat;
135 :
136 0 : if (!out->Write(glat->data, glat->length)) {
137 0 : return OTS_FAILURE();
138 : }
139 :
140 0 : return true;
141 : }
142 :
143 0 : void ots_glat_free(OpenTypeFile *file) {
144 0 : delete file->glat;
145 0 : }
146 :
147 : // 'Feat'
148 0 : bool ots_feat_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
149 0 : Buffer table(data, length);
150 :
151 0 : OpenTypeFEAT *feat = new OpenTypeFEAT;
152 0 : file->feat = feat;
153 :
154 0 : if (!table.Skip(length)) {
155 0 : return OTS_FAILURE();
156 : }
157 :
158 0 : feat->data = data;
159 0 : feat->length = length;
160 0 : return true;
161 : }
162 :
163 0 : bool ots_feat_should_serialise(OpenTypeFile *file) {
164 0 : return file->preserve_graphite && file->feat;
165 : }
166 :
167 0 : bool ots_feat_serialise(OTSStream *out, OpenTypeFile *file) {
168 0 : const OpenTypeFEAT *feat = file->feat;
169 :
170 0 : if (!out->Write(feat->data, feat->length)) {
171 0 : return OTS_FAILURE();
172 : }
173 :
174 0 : return true;
175 : }
176 :
177 0 : void ots_feat_free(OpenTypeFile *file) {
178 0 : delete file->feat;
179 0 : }
180 :
181 : } // namespace ots
|