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
3 // found in the LICENSE file.
9 // VORG - Vertical Origin Table
10 // http://www.microsoft.com/typography/otspec/vorg.htm
12 #define TABLE_NAME "VORG"
14 #define DROP_THIS_TABLE(...) \
16 OTS_FAILURE_MSG_(font->file, TABLE_NAME ": " __VA_ARGS__); \
17 OTS_FAILURE_MSG("Table discarded"); \
24 bool ots_vorg_parse(Font
*font
, const uint8_t *data
, size_t length
) {
25 Buffer
table(data
, length
);
26 font
->vorg
= new OpenTypeVORG
;
27 OpenTypeVORG
* const vorg
= font
->vorg
;
30 if (!table
.ReadU16(&vorg
->major_version
) ||
31 !table
.ReadU16(&vorg
->minor_version
) ||
32 !table
.ReadS16(&vorg
->default_vert_origin_y
) ||
33 !table
.ReadU16(&num_recs
)) {
34 return OTS_FAILURE_MSG("Failed to read header");
36 if (vorg
->major_version
!= 1) {
37 DROP_THIS_TABLE("bad major version: %u", vorg
->major_version
);
40 if (vorg
->minor_version
!= 0) {
41 DROP_THIS_TABLE("bad minor version: %u", vorg
->minor_version
);
45 // num_recs might be zero (e.g., DFHSMinchoPro5-W3-Demo.otf).
50 uint16_t last_glyph_index
= 0;
51 vorg
->metrics
.reserve(num_recs
);
52 for (unsigned i
= 0; i
< num_recs
; ++i
) {
53 OpenTypeVORGMetrics rec
;
55 if (!table
.ReadU16(&rec
.glyph_index
) ||
56 !table
.ReadS16(&rec
.vert_origin_y
)) {
57 return OTS_FAILURE_MSG("Failed to read record %d", i
);
59 if ((i
!= 0) && (rec
.glyph_index
<= last_glyph_index
)) {
60 DROP_THIS_TABLE("the table is not sorted");
63 last_glyph_index
= rec
.glyph_index
;
65 vorg
->metrics
.push_back(rec
);
71 bool ots_vorg_should_serialise(Font
*font
) {
72 if (!font
->cff
) return false; // this table is not for fonts with TT glyphs.
73 return font
->vorg
!= NULL
;
76 bool ots_vorg_serialise(OTSStream
*out
, Font
*font
) {
77 OpenTypeVORG
* const vorg
= font
->vorg
;
79 const uint16_t num_metrics
= static_cast<uint16_t>(vorg
->metrics
.size());
80 if (num_metrics
!= vorg
->metrics
.size() ||
81 !out
->WriteU16(vorg
->major_version
) ||
82 !out
->WriteU16(vorg
->minor_version
) ||
83 !out
->WriteS16(vorg
->default_vert_origin_y
) ||
84 !out
->WriteU16(num_metrics
)) {
85 return OTS_FAILURE_MSG("Failed to write table header");
88 for (uint16_t i
= 0; i
< num_metrics
; ++i
) {
89 const OpenTypeVORGMetrics
& rec
= vorg
->metrics
[i
];
90 if (!out
->WriteU16(rec
.glyph_index
) ||
91 !out
->WriteS16(rec
.vert_origin_y
)) {
92 return OTS_FAILURE_MSG("Failed to write record %d", i
);
99 void ots_vorg_reuse(Font
*font
, Font
*other
) {
100 font
->vorg
= other
->vorg
;
101 font
->vorg_reused
= true;
104 void ots_vorg_free(Font
*font
) {
111 #undef DROP_THIS_TABLE