Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(466)

Side by Side Diff: third_party/ots/src/post.cc

Issue 1252363005: Update OTS to revision a7a3b94 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/ots/src/ots.cc ('k') | third_party/ots/src/prep.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "post.h" 5 #include "post.h"
6 6
7 #include "maxp.h" 7 #include "maxp.h"
8 8
9 // post - PostScript 9 // post - PostScript
10 // http://www.microsoft.com/typography/otspec/post.htm 10 // http://www.microsoft.com/typography/otspec/post.htm
11 11
12 #define TABLE_NAME "post" 12 #define TABLE_NAME "post"
13 13
14 namespace ots { 14 namespace ots {
15 15
16 bool ots_post_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { 16 bool ots_post_parse(Font *font, const uint8_t *data, size_t length) {
17 Buffer table(data, length); 17 Buffer table(data, length);
18 18
19 OpenTypePOST *post = new OpenTypePOST; 19 OpenTypePOST *post = new OpenTypePOST;
20 file->post = post; 20 font->post = post;
21 21
22 if (!table.ReadU32(&post->version) || 22 if (!table.ReadU32(&post->version) ||
23 !table.ReadU32(&post->italic_angle) || 23 !table.ReadU32(&post->italic_angle) ||
24 !table.ReadS16(&post->underline) || 24 !table.ReadS16(&post->underline) ||
25 !table.ReadS16(&post->underline_thickness) || 25 !table.ReadS16(&post->underline_thickness) ||
26 !table.ReadU32(&post->is_fixed_pitch)) { 26 !table.ReadU32(&post->is_fixed_pitch)) {
27 return OTS_FAILURE_MSG("Failed to read post header"); 27 return OTS_FAILURE_MSG("Failed to read post header");
28 } 28 }
29 29
30 if (post->underline_thickness < 0) { 30 if (post->underline_thickness < 0) {
(...skipping 15 matching lines...) Expand all
46 // when serialising 46 // when serialising
47 if (!table.Skip(16)) { 47 if (!table.Skip(16)) {
48 return OTS_FAILURE_MSG("Failed to skip memory usage in post table"); 48 return OTS_FAILURE_MSG("Failed to skip memory usage in post table");
49 } 49 }
50 50
51 uint16_t num_glyphs = 0; 51 uint16_t num_glyphs = 0;
52 if (!table.ReadU16(&num_glyphs)) { 52 if (!table.ReadU16(&num_glyphs)) {
53 return OTS_FAILURE_MSG("Failed to read number of glyphs"); 53 return OTS_FAILURE_MSG("Failed to read number of glyphs");
54 } 54 }
55 55
56 if (!file->maxp) { 56 if (!font->maxp) {
57 return OTS_FAILURE_MSG("No maxp table required by post table"); 57 return OTS_FAILURE_MSG("No maxp table required by post table");
58 } 58 }
59 59
60 if (num_glyphs == 0) { 60 if (num_glyphs == 0) {
61 if (file->maxp->num_glyphs > 258) { 61 if (font->maxp->num_glyphs > 258) {
62 return OTS_FAILURE_MSG("Can't have no glyphs in the post table if there ar e more than 256 glyphs in the font"); 62 return OTS_FAILURE_MSG("Can't have no glyphs in the post table if there ar e more than 256 glyphs in the font");
63 } 63 }
64 OTS_WARNING("table version is 1, but no glyf names are found"); 64 OTS_WARNING("table version is 1, but no glyf names are found");
65 // workaround for fonts in http://www.fontsquirrel.com/fontface 65 // workaround for fonts in http://www.fontsquirrel.com/fontface
66 // (e.g., yataghan.ttf). 66 // (e.g., yataghan.ttf).
67 post->version = 0x00010000; 67 post->version = 0x00010000;
68 return true; 68 return true;
69 } 69 }
70 70
71 if (num_glyphs != file->maxp->num_glyphs) { 71 if (num_glyphs != font->maxp->num_glyphs) {
72 // Note: Fixedsys500c.ttf seems to have inconsistent num_glyphs values. 72 // Note: Fixedsys500c.ttf seems to have inconsistent num_glyphs values.
73 return OTS_FAILURE_MSG("Bad number of glyphs in post table %d", num_glyphs); 73 return OTS_FAILURE_MSG("Bad number of glyphs in post table %d", num_glyphs);
74 } 74 }
75 75
76 post->glyph_name_index.resize(num_glyphs); 76 post->glyph_name_index.resize(num_glyphs);
77 for (unsigned i = 0; i < num_glyphs; ++i) { 77 for (unsigned i = 0; i < num_glyphs; ++i) {
78 if (!table.ReadU16(&post->glyph_name_index[i])) { 78 if (!table.ReadU16(&post->glyph_name_index[i])) {
79 return OTS_FAILURE_MSG("Failed to read post information for glyph %d", i); 79 return OTS_FAILURE_MSG("Failed to read post information for glyph %d", i);
80 } 80 }
81 // Note: A strict interpretation of the specification requires name indexes 81 // Note: A strict interpretation of the specification requires name indexes
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 113
114 offset -= 258; 114 offset -= 258;
115 if (offset >= num_strings) { 115 if (offset >= num_strings) {
116 return OTS_FAILURE_MSG("Bad string index %d", offset); 116 return OTS_FAILURE_MSG("Bad string index %d", offset);
117 } 117 }
118 } 118 }
119 119
120 return true; 120 return true;
121 } 121 }
122 122
123 bool ots_post_should_serialise(OpenTypeFile *file) { 123 bool ots_post_should_serialise(Font *font) {
124 return file->post != NULL; 124 return font->post != NULL;
125 } 125 }
126 126
127 bool ots_post_serialise(OTSStream *out, OpenTypeFile *file) { 127 bool ots_post_serialise(OTSStream *out, Font *font) {
128 const OpenTypePOST *post = file->post; 128 const OpenTypePOST *post = font->post;
129 129
130 // OpenType with CFF glyphs must have v3 post table. 130 // OpenType with CFF glyphs must have v3 post table.
131 if (file->post && file->cff && file->post->version != 0x00030000) { 131 if (font->post && font->cff && font->post->version != 0x00030000) {
132 return OTS_FAILURE_MSG("Bad post version %x", post->version); 132 return OTS_FAILURE_MSG("Bad post version %x", post->version);
133 } 133 }
134 134
135 if (!out->WriteU32(post->version) || 135 if (!out->WriteU32(post->version) ||
136 !out->WriteU32(post->italic_angle) || 136 !out->WriteU32(post->italic_angle) ||
137 !out->WriteS16(post->underline) || 137 !out->WriteS16(post->underline) ||
138 !out->WriteS16(post->underline_thickness) || 138 !out->WriteS16(post->underline_thickness) ||
139 !out->WriteU32(post->is_fixed_pitch) || 139 !out->WriteU32(post->is_fixed_pitch) ||
140 !out->WriteU32(0) || 140 !out->WriteU32(0) ||
141 !out->WriteU32(0) || 141 !out->WriteU32(0) ||
(...skipping 30 matching lines...) Expand all
172 // Some ttf fonts (e.g., frank.ttf on Windows Vista) have zero-length name. 172 // Some ttf fonts (e.g., frank.ttf on Windows Vista) have zero-length name.
173 // We allow them. 173 // We allow them.
174 if (string_length > 0 && !out->Write(s.data(), string_length)) { 174 if (string_length > 0 && !out->Write(s.data(), string_length)) {
175 return OTS_FAILURE_MSG("Failed to write string length for string %d", i); 175 return OTS_FAILURE_MSG("Failed to write string length for string %d", i);
176 } 176 }
177 } 177 }
178 178
179 return true; 179 return true;
180 } 180 }
181 181
182 void ots_post_free(OpenTypeFile *file) { 182 void ots_post_reuse(Font *font, Font *other) {
183 delete file->post; 183 font->post = other->post;
184 font->post_reused = true;
185 }
186
187 void ots_post_free(Font *font) {
188 delete font->post;
184 } 189 }
185 190
186 } // namespace ots 191 } // namespace ots
187 192
188 #undef TABLE_NAME 193 #undef TABLE_NAME
OLDNEW
« no previous file with comments | « third_party/ots/src/ots.cc ('k') | third_party/ots/src/prep.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698