diff options
author | Mattias Andrée <m@maandree.se> | 2024-10-13 11:17:48 +0200 |
---|---|---|
committer | Mattias Andrée <m@maandree.se> | 2024-10-13 11:17:48 +0200 |
commit | a81c96c0348af8caf6ae45e2d942a676792a2a31 (patch) | |
tree | 24cc725efa3eba381c98ebed7cb2cbf7e0e34f0c /libparsepcf_get_metrics.c | |
parent | Update e-mail (diff) | |
download | libparsepcf-a81c96c0348af8caf6ae45e2d942a676792a2a31.tar.gz libparsepcf-a81c96c0348af8caf6ae45e2d942a676792a2a31.tar.bz2 libparsepcf-a81c96c0348af8caf6ae45e2d942a676792a2a31.tar.xz |
Documentation and minor improvements
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'libparsepcf_get_metrics.c')
-rw-r--r-- | libparsepcf_get_metrics.c | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/libparsepcf_get_metrics.c b/libparsepcf_get_metrics.c index 5e2fbe0..8994405 100644 --- a/libparsepcf_get_metrics.c +++ b/libparsepcf_get_metrics.c @@ -2,11 +2,16 @@ #include "common.h" +#define PARSE_INT8(TEXT) ((int16_t)((int)*(const uint8_t *)(TEXT) - 128)) + + int -libparsepcf_get_metrics(const char *file, size_t size, +libparsepcf_get_metrics(const void *file, size_t size, const struct libparsepcf_table *table, - struct libparsepcf_metrics *out, size_t first, size_t count) + struct libparsepcf_metrics *metrics, + size_t first, size_t count) { + const char *text = file; size_t pos, i; int msb = table->format & LIBPARSEPCF_BYTE; int compressed = table->format & LIBPARSEPCF_COMPRESSED_METRICS; @@ -18,30 +23,30 @@ libparsepcf_get_metrics(const char *file, size_t size, if (compressed) { for (i = 0; i < count; i++, pos += 5) { - out[i].left_side_bearing = (int16_t)((int)((const uint8_t *)file)[pos + 0] - 128); - out[i].right_side_bearing = (int16_t)((int)((const uint8_t *)file)[pos + 1] - 128); - out[i].character_width = (int16_t)((int)((const uint8_t *)file)[pos + 2] - 128); - out[i].character_ascent = (int16_t)((int)((const uint8_t *)file)[pos + 3] - 128); - out[i].character_descent = (int16_t)((int)((const uint8_t *)file)[pos + 4] - 128); - out[i].character_attributes = 0; - if (out[i].left_side_bearing > out[i].right_side_bearing || - (int32_t)out[i].character_ascent < -(int32_t)out[i].character_descent) - goto ebfont; + metrics[i].left_side_bearing = PARSE_INT8(&text[pos + 0]); + metrics[i].right_side_bearing = PARSE_INT8(&text[pos + 1]); + metrics[i].character_width = PARSE_INT8(&text[pos + 2]); + metrics[i].character_ascent = PARSE_INT8(&text[pos + 3]); + metrics[i].character_descent = PARSE_INT8(&text[pos + 4]); + metrics[i].character_attributes = 0; } } else { for (i = 0; i < count; i++, pos += 12) { - out[i].left_side_bearing = PARSE_INT16(&file[pos + 0], msb); - out[i].right_side_bearing = PARSE_INT16(&file[pos + 2], msb); - out[i].character_width = PARSE_INT16(&file[pos + 4], msb); - out[i].character_ascent = PARSE_INT16(&file[pos + 6], msb); - out[i].character_descent = PARSE_INT16(&file[pos + 8], msb); - out[i].character_attributes = PARSE_UINT16(&file[pos + 10], msb); - if (out[i].left_side_bearing > out[i].right_side_bearing || - (int32_t)out[i].character_ascent < -(int32_t)out[i].character_descent) - goto ebfont; + metrics[i].left_side_bearing = PARSE_INT16(&text[pos + 0], msb); + metrics[i].right_side_bearing = PARSE_INT16(&text[pos + 2], msb); + metrics[i].character_width = PARSE_INT16(&text[pos + 4], msb); + metrics[i].character_ascent = PARSE_INT16(&text[pos + 6], msb); + metrics[i].character_descent = PARSE_INT16(&text[pos + 8], msb); + metrics[i].character_attributes = PARSE_UINT16(&text[pos + 10], msb); } } + for (i = 0; i < count; i++) { + if (metrics[i].left_side_bearing > metrics[i].right_side_bearing || + (int32_t)metrics[i].character_ascent < -(int32_t)metrics[i].character_descent) + goto ebfont; + } + return 0; ebfont: |