commit 0353c3cf2470edc2d72a2fb2a4d01c6902b0f543
parent 30e3189b95903e3c0cce5e8485037ab82e6504bd
Author: Frederic Cambus <fred@statdns.com>
Date: Tue, 21 Jan 2020 13:50:31 +0100
Parse and process FONT_ASCENT and FONT_DESCENT instead of hardcoding values.
Diffstat:
3 files changed, 45 insertions(+), 4 deletions(-)
diff --git a/src/bdftosfd.c b/src/bdftosfd.c
@@ -4,7 +4,7 @@
* https://github.com/fcambus/bdftosfd
*
* Created: 2019-11-21
- * Last Updated: 2020-01-20
+ * Last Updated: 2020-01-21
*
* bdftosfd is released under the BSD 2-Clause license
* See LICENSE file for details
@@ -110,6 +110,9 @@ main(int argc, char *argv[])
char *token = NULL;
char *charname = NULL, *copyright = NULL, *name = NULL, *encoding = NULL, *version = NULL;
+ char *value;
+ int32_t ascent, descent;
+
int32_t x, y;
struct fontinfo font;
@@ -141,6 +144,40 @@ main(int argc, char *argv[])
continue;
}
+ if (!strncmp(lineBuffer, "FONT_ASCENT ", 12)) {
+ token = strtok(lineBuffer, " \t");
+
+ if (token)
+ value = strtok(NULL, "\n");
+
+ if (value)
+ ascent = strtonum(value, 0, 16, &errstr);
+
+ if (!errstr)
+ font.ascent = ascent * 64;
+ else
+ errx(EXIT_FAILURE, "Invalid value for FONT_ASCENT.");
+
+ continue;
+ }
+
+ if (!strncmp(lineBuffer, "FONT_DESCENT ", 12)) {
+ token = strtok(lineBuffer, " \t");
+
+ if (token)
+ value = strtok(NULL, "\n");
+
+ if (value)
+ descent = strtonum(value, 0, 16, &errstr);
+
+ if (!errstr)
+ font.descent = descent * 64;
+ else
+ errx(EXIT_FAILURE, "Invalid value for FONT_DESCENT.");
+
+ continue;
+ }
+
if (!strncmp(lineBuffer, "FONT_VERSION ", 13)) {
token = strtok(lineBuffer, " \t");
diff --git a/src/header.c b/src/header.c
@@ -31,8 +31,8 @@ header(FILE *stream, struct fontinfo *font)
fprintf(stream, "ItalicAngle: 0\n");
fprintf(stream, "UnderlinePosition: -100\n");
fprintf(stream, "UnderlineWidth: 40\n");
- fprintf(stream, "Ascent: 768\n");
- fprintf(stream, "Descent: 256\n");
+ fprintf(stream, "Ascent: %i\n", font->ascent);
+ fprintf(stream, "Descent: %i\n", font->descent);
fprintf(stream, "LayerCount: 2\n");
fprintf(stream, "Layer: 0 0 \"Back\" 1\n");
fprintf(stream, "Layer: 1 0 \"Fore\" 0\n");
diff --git a/src/header.h b/src/header.h
@@ -4,7 +4,7 @@
* https://github.com/fcambus/bdftosfd
*
* Created: 2019-11-21
- * Last Updated: 2020-01-20
+ * Last Updated: 2020-01-21
*
* bdftosfd is released under the BSD 2-Clause license
* See LICENSE file for details
@@ -13,11 +13,15 @@
#ifndef HEADER_H
#define HEADER_H
+#include <inttypes.h>
+
struct fontinfo {
char *name;
char *chars;
char *copyright;
char *version;
+ int32_t ascent;
+ int32_t descent;
};
void header(FILE *, struct fontinfo *);