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

Unified Diff: src/ots.cc

Issue 8896006: Remove all 51 static initializers from ots.cc. (Closed) Base URL: http://ots.googlecode.com/svn/trunk/
Patch Set: Created 9 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ots.cc
===================================================================
--- src/ots.cc (revision 74)
+++ src/ots.cc (working copy)
@@ -34,12 +34,6 @@
return (value + 3) & ~3;
}
-uint32_t Tag(const char *tag_str) {
- uint32_t ret;
- std::memcpy(&ret, tag_str, 4);
- return ret;
-}
-
bool CheckTag(uint32_t tag_value) {
for (unsigned i = 0; i < 4; ++i) {
const uint32_t check = tag_value & 0xff;
@@ -83,6 +77,10 @@
std::vector<uint8_t*> hunks_;
};
+// Use a macro instead of a function because gcc 4.4.3 creates static
+// initializers in that case. Note this macro assumes a little-endian system.
+#define TAG(a, b, c, d) (a | (b << 8) | (c << 16) | (d << 24))
+
const struct {
uint32_t tag;
bool (*parse)(ots::OpenTypeFile *otf, const uint8_t *data, size_t length);
@@ -91,69 +89,69 @@
void (*free)(ots::OpenTypeFile *file);
bool required;
} table_parsers[] = {
- { Tag("maxp"), ots::ots_maxp_parse, ots::ots_maxp_serialise,
+ { TAG('m', 'a', 'x', 'p'), ots::ots_maxp_parse, ots::ots_maxp_serialise,
ots::ots_maxp_should_serialise, ots::ots_maxp_free, true },
- { Tag("head"), ots::ots_head_parse, ots::ots_head_serialise,
+ { TAG('h', 'e', 'a', 'd'), ots::ots_head_parse, ots::ots_head_serialise,
ots::ots_head_should_serialise, ots::ots_head_free, true },
- { Tag("OS/2"), ots::ots_os2_parse, ots::ots_os2_serialise,
+ { TAG('O', 'S', '/', '2'), ots::ots_os2_parse, ots::ots_os2_serialise,
ots::ots_os2_should_serialise, ots::ots_os2_free, true },
- { Tag("cmap"), ots::ots_cmap_parse, ots::ots_cmap_serialise,
+ { TAG('c', 'm', 'a', 'p'), ots::ots_cmap_parse, ots::ots_cmap_serialise,
ots::ots_cmap_should_serialise, ots::ots_cmap_free, true },
- { Tag("hhea"), ots::ots_hhea_parse, ots::ots_hhea_serialise,
+ { TAG('h', 'h', 'e', 'a'), ots::ots_hhea_parse, ots::ots_hhea_serialise,
ots::ots_hhea_should_serialise, ots::ots_hhea_free, true },
- { Tag("hmtx"), ots::ots_hmtx_parse, ots::ots_hmtx_serialise,
+ { TAG('h', 'm', 't', 'x'), ots::ots_hmtx_parse, ots::ots_hmtx_serialise,
ots::ots_hmtx_should_serialise, ots::ots_hmtx_free, true },
- { Tag("name"), ots::ots_name_parse, ots::ots_name_serialise,
+ { TAG('n', 'a', 'm', 'e'), ots::ots_name_parse, ots::ots_name_serialise,
ots::ots_name_should_serialise, ots::ots_name_free, true },
- { Tag("post"), ots::ots_post_parse, ots::ots_post_serialise,
+ { TAG('p', 'o', 's', 't'), ots::ots_post_parse, ots::ots_post_serialise,
ots::ots_post_should_serialise, ots::ots_post_free, true },
- { Tag("loca"), ots::ots_loca_parse, ots::ots_loca_serialise,
+ { TAG('l', 'o', 'c', 'a'), ots::ots_loca_parse, ots::ots_loca_serialise,
ots::ots_loca_should_serialise, ots::ots_loca_free, false },
- { Tag("glyf"), ots::ots_glyf_parse, ots::ots_glyf_serialise,
+ { TAG('g', 'l', 'y', 'f'), ots::ots_glyf_parse, ots::ots_glyf_serialise,
ots::ots_glyf_should_serialise, ots::ots_glyf_free, false },
- { Tag("CFF "), ots::ots_cff_parse, ots::ots_cff_serialise,
+ { TAG('C', 'F', 'F', ' '), ots::ots_cff_parse, ots::ots_cff_serialise,
ots::ots_cff_should_serialise, ots::ots_cff_free, false },
- { Tag("VDMX"), ots::ots_vdmx_parse, ots::ots_vdmx_serialise,
+ { TAG('V', 'D', 'M', 'X'), ots::ots_vdmx_parse, ots::ots_vdmx_serialise,
ots::ots_vdmx_should_serialise, ots::ots_vdmx_free, false },
- { Tag("hdmx"), ots::ots_hdmx_parse, ots::ots_hdmx_serialise,
+ { TAG('h', 'd', 'm', 'x'), ots::ots_hdmx_parse, ots::ots_hdmx_serialise,
ots::ots_hdmx_should_serialise, ots::ots_hdmx_free, false },
- { Tag("gasp"), ots::ots_gasp_parse, ots::ots_gasp_serialise,
+ { TAG('g', 'a', 's', 'p'), ots::ots_gasp_parse, ots::ots_gasp_serialise,
ots::ots_gasp_should_serialise, ots::ots_gasp_free, false },
- { Tag("cvt "), ots::ots_cvt_parse, ots::ots_cvt_serialise,
+ { TAG('c', 'v', 't', ' '), ots::ots_cvt_parse, ots::ots_cvt_serialise,
ots::ots_cvt_should_serialise, ots::ots_cvt_free, false },
- { Tag("fpgm"), ots::ots_fpgm_parse, ots::ots_fpgm_serialise,
+ { TAG('f', 'p', 'g', 'm'), ots::ots_fpgm_parse, ots::ots_fpgm_serialise,
ots::ots_fpgm_should_serialise, ots::ots_fpgm_free, false },
- { Tag("prep"), ots::ots_prep_parse, ots::ots_prep_serialise,
+ { TAG('p', 'r', 'e', 'p'), ots::ots_prep_parse, ots::ots_prep_serialise,
ots::ots_prep_should_serialise, ots::ots_prep_free, false },
- { Tag("LTSH"), ots::ots_ltsh_parse, ots::ots_ltsh_serialise,
+ { TAG('L', 'T', 'S', 'H'), ots::ots_ltsh_parse, ots::ots_ltsh_serialise,
ots::ots_ltsh_should_serialise, ots::ots_ltsh_free, false },
- { Tag("VORG"), ots::ots_vorg_parse, ots::ots_vorg_serialise,
+ { TAG('V', 'O', 'R', 'G'), ots::ots_vorg_parse, ots::ots_vorg_serialise,
ots::ots_vorg_should_serialise, ots::ots_vorg_free, false },
- { Tag("kern"), ots::ots_kern_parse, ots::ots_kern_serialise,
+ { TAG('k', 'e', 'r', 'n'), ots::ots_kern_parse, ots::ots_kern_serialise,
ots::ots_kern_should_serialise, ots::ots_kern_free, false },
// We need to parse GDEF table in advance of parsing GSUB/GPOS tables
// because they could refer GDEF table.
- { Tag("GDEF"), ots::ots_gdef_parse, ots::ots_gdef_serialise,
+ { TAG('G', 'D', 'E', 'F'), ots::ots_gdef_parse, ots::ots_gdef_serialise,
ots::ots_gdef_should_serialise, ots::ots_gdef_free, false },
- { Tag("GPOS"), ots::ots_gpos_parse, ots::ots_gpos_serialise,
+ { TAG('G', 'P', 'O', 'S'), ots::ots_gpos_parse, ots::ots_gpos_serialise,
ots::ots_gpos_should_serialise, ots::ots_gpos_free, false },
- { Tag("GSUB"), ots::ots_gsub_parse, ots::ots_gsub_serialise,
+ { TAG('G', 'S', 'U', 'B'), ots::ots_gsub_parse, ots::ots_gsub_serialise,
ots::ots_gsub_should_serialise, ots::ots_gsub_free, false },
- { Tag("vhea"), ots::ots_vhea_parse, ots::ots_vhea_serialise,
+ { TAG('v', 'h', 'e', 'a'), ots::ots_vhea_parse, ots::ots_vhea_serialise,
ots::ots_vhea_should_serialise, ots::ots_vhea_free, false },
- { Tag("vmtx"), ots::ots_vmtx_parse, ots::ots_vmtx_serialise,
+ { TAG('v', 'm', 't', 'x'), ots::ots_vmtx_parse, ots::ots_vmtx_serialise,
ots::ots_vmtx_should_serialise, ots::ots_vmtx_free, false },
// TODO(bashi): Support mort, base, and jstf tables.
{ 0, NULL, NULL, NULL, NULL, false },
};
bool IsValidVersionTag(uint32_t tag) {
- return tag == Tag("\x00\x01\x00\x00") ||
+ return tag == TAG('\x00', '\x01', '\x00', '\x00') ||
Nico 2011/12/09 19:13:30 The function-local Tag() calls didn't matter, but
// OpenType fonts with CFF data have 'OTTO' tag.
- tag == Tag("OTTO") ||
+ tag == TAG('O', 'T', 'T', 'O') ||
// Older Mac fonts might have 'true' or 'typ1' tag.
- tag == Tag("true") ||
- tag == Tag("typ1");
+ tag == TAG('t', 'r', 'u', 'e') ||
+ tag == TAG('t', 'y', 'p', '1');
}
bool ProcessGeneric(ots::OpenTypeFile *header, ots::OTSStream *output,
@@ -251,7 +249,7 @@
return OTS_FAILURE();
}
- if (woff_tag != Tag("wOFF")) {
+ if (woff_tag != TAG('w', 'O', 'F', 'F')) {
return OTS_FAILURE();
}
@@ -447,7 +445,7 @@
if (header->cff) {
// font with PostScript glyph
- if (header->version != Tag("OTTO")) {
+ if (header->version != TAG('O', 'T', 'T', 'O')) {
return OTS_FAILURE();
}
if (header->glyf || header->loca) {
@@ -511,7 +509,7 @@
out.offset = output->Tell();
output->ResetChecksum();
- if (table_parsers[i].tag == Tag("head")) {
+ if (table_parsers[i].tag == TAG('h', 'e', 'a', 'd')) {
head_table_offset = out.offset;
}
if (!table_parsers[i].serialise(output, header)) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698