w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

head.c
Go to the documentation of this file.
1 #include "head.h"
2 
3 #include "support/util.h"
4 
5 static INLINE void initHead(table_head *head) {
6  memset(head, 0, sizeof(*head));
7  head->magicNumber = 0x5f0f3cf5;
8  head->unitsPerEm = 1000;
9 }
11  // trivial
12 }
14 
16  FOR_TABLE(OTFCC_CHR('h','e','a','d'), table) {
18  uint32_t length = table.length;
19 
20  if (length < 54) {
21  logWarning("table 'head' corrupted.\n");
22  } else {
24  NEW(head);
26  head->fontRevision = read_32u(data + 4);
27  head->checkSumAdjustment = read_32u(data + 8);
28  head->magicNumber = read_32u(data + 12);
29  head->flags = read_16u(data + 16);
30  head->unitsPerEm = read_16u(data + 18);
31  head->created = read_64u(data + 20);
32  head->modified = read_64u(data + 28);
33  head->xMin = read_16u(data + 36);
34  head->yMin = read_16u(data + 38);
35  head->xMax = read_16u(data + 40);
36  head->yMax = read_16u(data + 42);
37  head->macStyle = read_16u(data + 44);
38  head->lowestRecPPEM = read_16u(data + 46);
39  head->fontDirectoryHint = read_16u(data + 48);
40  head->indexToLocFormat = read_16u(data + 50);
41  head->glyphDataFormat = read_16u(data + 52);
42  return head;
43  }
44  }
45  return NULL;
46 }
47 
48 static const char *headFlagsLabels[] = {"baselineAtY_0",
49  "lsbAtX_0",
50  "instrMayDependOnPointSize",
51  "alwaysUseIntegerSize",
52  "instrMayAlterAdvanceWidth",
53  "designedForVertical",
54  "_reserved1",
55  "designedForComplexScript",
56  "hasMetamorphosisEffects",
57  "containsStrongRTL",
58  "containsIndicRearrangement",
59  "fontIsLossless",
60  "fontIsConverted",
61  "optimizedForCleartype",
62  "lastResortFont",
63  NULL};
64 static const char *macStyleLabels[] = {"bold", "italic", "underline", "outline",
65  "shadow", "condensed", "extended", NULL};
66 
68  if (!table) return;
69  loggedStep("head") {
72  json_object_push(head, "fontRevision",
73  json_double_new(otfcc_from_fixed(table->fontRevision)));
75  json_object_push(head, "unitsPerEm", json_integer_new(table->unitsPerEm));
76  json_object_push(head, "created", json_integer_new(table->created));
77  json_object_push(head, "modified", json_integer_new(table->modified));
82  json_object_push(head, "macStyle", otfcc_dump_flags(table->macStyle, macStyleLabels));
83  json_object_push(head, "lowestRecPPEM", json_integer_new(table->lowestRecPPEM));
84  json_object_push(head, "fontDirectoryHint", json_integer_new(table->fontDirectoryHint));
85  json_object_push(head, "indexToLocFormat", json_integer_new(table->indexToLocFormat));
86  json_object_push(head, "glyphDataFormat", json_integer_new(table->glyphDataFormat));
87  json_object_push(root, "head", head);
88  }
89 }
90 
92  table_head *head = table_iHead.create();
94  if ((table = json_obj_get_type(root, "head", json_object))) {
95  loggedStep("head") {
97  head->fontRevision = otfcc_to_fixed(json_obj_getnum_fallback(table, "fontRevision", 0));
99  head->unitsPerEm = json_obj_getnum_fallback(table, "unitsPerEm", 0);
100  head->created = json_obj_getnum_fallback(table, "created", 0);
101  head->modified = json_obj_getnum_fallback(table, "modified", 0);
102  head->xMin = json_obj_getnum_fallback(table, "xMin", 0);
103  head->xMax = json_obj_getnum_fallback(table, "xMax", 0);
104  head->yMin = json_obj_getnum_fallback(table, "yMin", 0);
105  head->yMax = json_obj_getnum_fallback(table, "yMax", 0);
106  head->macStyle = otfcc_parse_flags(json_obj_get(table, "macStyle"), macStyleLabels);
107  head->lowestRecPPEM = json_obj_getnum_fallback(table, "lowestRecPPEM", 0);
108  head->fontDirectoryHint = json_obj_getnum_fallback(table, "fontDirectoryHint", 0);
109  head->indexToLocFormat = json_obj_getnum_fallback(table, "indexToLocFormat", 0);
110  head->glyphDataFormat = json_obj_getnum_fallback(table, "glyphDataFormat", 0);
111  }
112  }
113  return head;
114 }
115 
117  if (!head) return NULL;
118  caryll_Buffer *buf = bufnew();
120  bufwrite32b(buf, head->fontRevision);
121  bufwrite32b(buf, head->checkSumAdjustment);
122  bufwrite32b(buf, head->magicNumber);
124  bufwrite16b(buf, head->unitsPerEm);
125  bufwrite64b(buf, head->created);
126  bufwrite64b(buf, head->modified);
127  bufwrite16b(buf, head->xMin);
128  bufwrite16b(buf, head->yMin);
129  bufwrite16b(buf, head->xMax);
130  bufwrite16b(buf, head->yMax);
131  bufwrite16b(buf, head->macStyle);
132  bufwrite16b(buf, head->lowestRecPPEM);
133  bufwrite16b(buf, head->fontDirectoryHint);
134  bufwrite16b(buf, head->indexToLocFormat);
135  bufwrite16b(buf, head->glyphDataFormat);
136  return buf;
137 }
#define head
Definition: aptex-macros.h:513
static uint32_t read_32u(const uint8_t *src)
Definition: bin-io.h:132
static uint16_t read_16u(const uint8_t *src)
Definition: bin-io.h:121
static uint64_t read_64u(const uint8_t *src)
Definition: bin-io.h:139
static int32_t read_32s(const uint8_t *src)
Definition: bin-io.h:156
#define OTFCC_CHR(a, b, c, d)
Definition: caryll-font.c:7
struct rect data
Definition: dvipdfm.c:64
table_iHead
Definition: glyf.d:17902
json_value * json_object_push(json_value *object, const char *name, json_value *)
json_value * json_integer_new(int64_t)
json_value * json_object_new(size_t length)
json_value * json_double_new(double)
static json_value * json_obj_get(const json_value *obj, const char *key)
Definition: json-funcs.h:26
static json_value * json_obj_get_type(const json_value *obj, const char *key, const json_type type)
Definition: json-funcs.h:34
static json_value * otfcc_dump_flags(int flags, const char *labels[])
Definition: json-funcs.h:164
static uint32_t otfcc_parse_flags(const json_value *v, const char *labels[])
Definition: json-funcs.h:170
static double json_obj_getnum_fallback(const json_value *obj, const char *key, double fallback)
Definition: json-funcs.h:105
#define NULL
Definition: ftobjs.h:61
#define NEW
Definition: gdkanji.c:77
unsigned int uint32_t
Definition: stdint.h:80
#define INLINE
Definition: port.h:26
#define buf
#define length(c)
Definition: ctangleboot.c:65
#define root
Definition: ctangleboot.c:69
#define logWarning(...)
Definition: aliases.h:14
uint8_t * font_file_pointer
Definition: aliases.h:41
#define FOR_TABLE(name, table)
Definition: aliases.h:33
#define loggedStep(...)
Definition: aliases.h:6
double otfcc_from_fixed(const f16dot16 x)
Definition: primitives.c:14
f16dot16 otfcc_to_fixed(const double x)
Definition: primitives.c:17
bstring c int memset(void *s, int c, int length)
void bufwrite32b(caryll_Buffer *buf, uint32_t x)
Definition: buffer.c:82
void bufwrite64b(caryll_Buffer *buf, uint64_t x)
Definition: buffer.c:100
void bufwrite16b(caryll_Buffer *buf, uint16_t x)
Definition: buffer.c:58
caryll_Buffer * bufnew(void)
Definition: buffer.c:4
@ json_object
Definition: json.h:85
void otfcc_dumpHead(const table_head *table, json_value *root, const otfcc_Options *options)
Definition: head.c:67
caryll_Buffer * otfcc_buildHead(const table_head *head, const otfcc_Options *options)
Definition: head.c:116
static INLINE void initHead(table_head *head)
Definition: head.c:5
static const char * headFlagsLabels[]
Definition: head.c:48
table_head * otfcc_parseHead(const json_value *root, const otfcc_Options *options)
Definition: head.c:91
static const char * macStyleLabels[]
Definition: head.c:64
table_head * otfcc_readHead(const otfcc_Packet packet, const otfcc_Options *options)
Definition: head.c:15
caryll_standardRefType(table_head, table_iHead, initHead, disposeHead)
static INLINE void disposeHead(table_head *head)
Definition: head.c:10
Definition: ttf.h:354
uint16 flags
Definition: ttf.h:359
int32 version
Definition: ttf.h:355
Definition: head.h:6
Definition: table.h:30