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

Side by Side Diff: third_party/ots/src/loca.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/layout.cc ('k') | third_party/ots/src/ltsh.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 "loca.h" 5 #include "loca.h"
6 6
7 #include "head.h" 7 #include "head.h"
8 #include "maxp.h" 8 #include "maxp.h"
9 9
10 // loca - Index to Location 10 // loca - Index to Location
11 // http://www.microsoft.com/typography/otspec/loca.htm 11 // http://www.microsoft.com/typography/otspec/loca.htm
12 12
13 #define TABLE_NAME "loca" 13 #define TABLE_NAME "loca"
14 14
15 namespace ots { 15 namespace ots {
16 16
17 bool ots_loca_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { 17 bool ots_loca_parse(Font *font, const uint8_t *data, size_t length) {
18 Buffer table(data, length); 18 Buffer table(data, length);
19 19
20 // We can't do anything useful in validating this data except to ensure that 20 // We can't do anything useful in validating this data except to ensure that
21 // the values are monotonically increasing. 21 // the values are monotonically increasing.
22 22
23 OpenTypeLOCA *loca = new OpenTypeLOCA; 23 OpenTypeLOCA *loca = new OpenTypeLOCA;
24 file->loca = loca; 24 font->loca = loca;
25 25
26 if (!file->maxp || !file->head) { 26 if (!font->maxp || !font->head) {
27 return OTS_FAILURE_MSG("maxp or head tables missing from font, needed by loc a"); 27 return OTS_FAILURE_MSG("maxp or head tables missing from font, needed by loc a");
28 } 28 }
29 29
30 const unsigned num_glyphs = file->maxp->num_glyphs; 30 const unsigned num_glyphs = font->maxp->num_glyphs;
31 unsigned last_offset = 0; 31 unsigned last_offset = 0;
32 loca->offsets.resize(num_glyphs + 1); 32 loca->offsets.resize(num_glyphs + 1);
33 // maxp->num_glyphs is uint16_t, thus the addition never overflows. 33 // maxp->num_glyphs is uint16_t, thus the addition never overflows.
34 34
35 if (file->head->index_to_loc_format == 0) { 35 if (font->head->index_to_loc_format == 0) {
36 // Note that the <= here (and below) is correct. There is one more offset 36 // Note that the <= here (and below) is correct. There is one more offset
37 // than the number of glyphs in order to give the length of the final 37 // than the number of glyphs in order to give the length of the final
38 // glyph. 38 // glyph.
39 for (unsigned i = 0; i <= num_glyphs; ++i) { 39 for (unsigned i = 0; i <= num_glyphs; ++i) {
40 uint16_t offset = 0; 40 uint16_t offset = 0;
41 if (!table.ReadU16(&offset)) { 41 if (!table.ReadU16(&offset)) {
42 return OTS_FAILURE_MSG("Failed to read offset for glyph %d", i); 42 return OTS_FAILURE_MSG("Failed to read offset for glyph %d", i);
43 } 43 }
44 if (offset < last_offset) { 44 if (offset < last_offset) {
45 return OTS_FAILURE_MSG("Out of order offset %d < %d for glyph %d", offse t, last_offset, i); 45 return OTS_FAILURE_MSG("Out of order offset %d < %d for glyph %d", offse t, last_offset, i);
(...skipping 11 matching lines...) Expand all
57 return OTS_FAILURE_MSG("Out of order offset %d < %d for glyph %d", offse t, last_offset, i); 57 return OTS_FAILURE_MSG("Out of order offset %d < %d for glyph %d", offse t, last_offset, i);
58 } 58 }
59 last_offset = offset; 59 last_offset = offset;
60 loca->offsets[i] = offset; 60 loca->offsets[i] = offset;
61 } 61 }
62 } 62 }
63 63
64 return true; 64 return true;
65 } 65 }
66 66
67 bool ots_loca_should_serialise(OpenTypeFile *file) { 67 bool ots_loca_should_serialise(Font *font) {
68 return file->loca != NULL; 68 return font->loca != NULL;
69 } 69 }
70 70
71 bool ots_loca_serialise(OTSStream *out, OpenTypeFile *file) { 71 bool ots_loca_serialise(OTSStream *out, Font *font) {
72 const OpenTypeLOCA *loca = file->loca; 72 const OpenTypeLOCA *loca = font->loca;
73 const OpenTypeHEAD *head = file->head; 73 const OpenTypeHEAD *head = font->head;
74 74
75 if (!head) { 75 if (!head) {
76 return OTS_FAILURE_MSG("Missing head table in font needed by loca"); 76 return OTS_FAILURE_MSG("Missing head table in font needed by loca");
77 } 77 }
78 78
79 if (head->index_to_loc_format == 0) { 79 if (head->index_to_loc_format == 0) {
80 for (unsigned i = 0; i < loca->offsets.size(); ++i) { 80 for (unsigned i = 0; i < loca->offsets.size(); ++i) {
81 const uint16_t offset = static_cast<uint16_t>(loca->offsets[i] >> 1); 81 const uint16_t offset = static_cast<uint16_t>(loca->offsets[i] >> 1);
82 if ((offset != (loca->offsets[i] >> 1)) || 82 if ((offset != (loca->offsets[i] >> 1)) ||
83 !out->WriteU16(offset)) { 83 !out->WriteU16(offset)) {
84 return OTS_FAILURE_MSG("Failed to write glyph offset for glyph %d", i); 84 return OTS_FAILURE_MSG("Failed to write glyph offset for glyph %d", i);
85 } 85 }
86 } 86 }
87 } else { 87 } else {
88 for (unsigned i = 0; i < loca->offsets.size(); ++i) { 88 for (unsigned i = 0; i < loca->offsets.size(); ++i) {
89 if (!out->WriteU32(loca->offsets[i])) { 89 if (!out->WriteU32(loca->offsets[i])) {
90 return OTS_FAILURE_MSG("Failed to write glyph offset for glyph %d", i); 90 return OTS_FAILURE_MSG("Failed to write glyph offset for glyph %d", i);
91 } 91 }
92 } 92 }
93 } 93 }
94 94
95 return true; 95 return true;
96 } 96 }
97 97
98 void ots_loca_free(OpenTypeFile *file) { 98 void ots_loca_reuse(Font *font, Font *other) {
99 delete file->loca; 99 font->loca = other->loca;
100 font->loca_reused = true;
101 }
102
103 void ots_loca_free(Font *font) {
104 delete font->loca;
100 } 105 }
101 106
102 } // namespace ots 107 } // namespace ots
103 108
104 #undef TABLE_NAME 109 #undef TABLE_NAME
OLDNEW
« no previous file with comments | « third_party/ots/src/layout.cc ('k') | third_party/ots/src/ltsh.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698