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)  

hmtx.c
Go to the documentation of this file.
1 #include "hmtx.h"
2 
3 #include "support/util.h"
4 
6  if (table->metrics != NULL) FREE(table->metrics);
7  if (table->leftSideBearing != NULL) FREE(table->leftSideBearing);
8 }
9 
11 
13  table_hhea *hhea, table_maxp *maxp) {
14  if (!hhea || !maxp || !hhea->numberOfMetrics || maxp->numGlyphs < hhea->numberOfMetrics) {
15  return NULL;
16  }
17  FOR_TABLE(OTFCC_CHR('h','m','t','x'), table) {
19  uint32_t length = table.length;
20 
21  table_hmtx *hmtx = NULL;
22 
23  glyphid_t count_a = hhea->numberOfMetrics;
24  glyphid_t count_k = maxp->numGlyphs - hhea->numberOfMetrics;
25  if (length < count_a * 4 + count_k * 2) goto HMTX_CORRUPTED;
26 
27  NEW(hmtx);
28  NEW(hmtx->metrics, count_a);
29  NEW(hmtx->leftSideBearing, count_k);
30 
31  for (glyphid_t ia = 0; ia < count_a; ia++) {
32  hmtx->metrics[ia].advanceWidth = read_16u(data + ia * 4);
33  hmtx->metrics[ia].lsb = read_16s(data + ia * 4 + 2);
34  }
35 
36  for (glyphid_t ik = 0; ik < count_k; ik++) {
37  hmtx->leftSideBearing[ik] = read_16s(data + count_a * 4 + ik * 2);
38  }
39 
40  return hmtx;
41  HMTX_CORRUPTED:
42  logWarning("Table 'hmtx' corrupted.\n");
43  if (hmtx) { table_iHmtx.free(hmtx), hmtx = NULL; }
44  }
45  return NULL;
46 }
47 
49  const otfcc_Options *options) {
51  if (!hmtx) return buf;
52  if (hmtx->metrics) {
53  for (glyphid_t j = 0; j < count_a; j++) {
54  bufwrite16b(buf, hmtx->metrics[j].advanceWidth);
55  bufwrite16b(buf, hmtx->metrics[j].lsb);
56  }
57  }
58  if (hmtx->leftSideBearing) {
59  for (glyphid_t j = 0; j < count_k; j++) {
60  bufwrite16b(buf, hmtx->leftSideBearing[j]);
61  }
62  }
63  return buf;
64 }
static uint16_t read_16u(const uint8_t *src)
Definition: bin-io.h:121
static int16_t read_16s(const uint8_t *src)
Definition: bin-io.h:153
#define OTFCC_CHR(a, b, c, d)
Definition: caryll-font.c:7
struct rect data
Definition: dvipdfm.c:64
const unsigned char FREE
Definition: image.cpp:34
#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 logWarning(...)
Definition: aliases.h:14
uint8_t * font_file_pointer
Definition: aliases.h:41
#define FOR_TABLE(name, table)
Definition: aliases.h:33
@ MOVE
Definition: pl-parser.h:87
uint16_t glyphid_t
Definition: primitives.h:14
void bufwrite16b(caryll_Buffer *buf, uint16_t x)
Definition: buffer.c:58
caryll_Buffer * bufnew(void)
Definition: buffer.c:4
table_hmtx * otfcc_readHmtx(const otfcc_Packet packet, const otfcc_Options *options, table_hhea *hhea, table_maxp *maxp)
Definition: hmtx.c:12
caryll_Buffer * otfcc_buildHmtx(const table_hmtx *hmtx, glyphid_t count_a, glyphid_t count_k, const otfcc_Options *options)
Definition: hmtx.c:48
static INLINE void disposeHmtx(MOVE table_hmtx *table)
Definition: hmtx.c:5
caryll_standardRefType(table_hmtx, table_iHmtx, disposeHmtx)
Definition: ttf.h:315
int16 lsb
Definition: ttf.h:317
Definition: ttf.h:413
uint16 numGlyphs
Definition: ttf.h:415
Definition: hhea.h:6
uint16_t numberOfMetrics
Definition: hhea.h:21
Definition: maxp.h:6
Definition: table.h:30
int j
Definition: t4ht.c:1589