commit 106bc40b9421b8976bb6c17754c10b351ad4332c
parent e5b1be97b07df3f5bbee4a7b516c8b92540abe80
Author: Frederic Cambus <fred@statdns.com>
Date: Fri, 7 Feb 2020 15:27:56 +0100
Use floats for polygon position and sizes, avoids problems with rounding.
Diffstat:
3 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/src/bdf2sfd.c b/src/bdf2sfd.c
@@ -4,7 +4,7 @@
* https://github.com/fcambus/bdf2sfd
*
* Created: 2019-11-21
- * Last Updated: 2020-02-06
+ * Last Updated: 2020-02-07
*
* bdf2sfd is released under the BSD 2-Clause license
* See LICENSE file for details
@@ -69,9 +69,9 @@ main(int argc, char *argv[])
uint32_t ascent = 0, descent = 0;
int key;
- int32_t x = 0, y = 0;
+ float x = 0.0, y = 0.0;
uint32_t mask = 0;
- uint32_t xlength = 64, ylength = 64; /* Default values for 8x16 fonts */
+ float xlength = 64.0, ylength = 64.0; /* Default values for 8x16 fonts */
struct fontinfo font;
memset(&font, 0, sizeof(struct fontinfo));
@@ -172,8 +172,8 @@ main(int argc, char *argv[])
if (!width || !height)
errx(EXIT_FAILURE, "Invalid value for FONTBOUNDINGBOX.");
- xlength = 512 / width;
- ylength = 1024 / height;
+ xlength = 512.0 / width;
+ ylength = 1024.0 / height;
mask = 1 << (stride[width] * 8 - 1);
diff --git a/src/polygon.c b/src/polygon.c
@@ -4,7 +4,7 @@
* https://github.com/fcambus/bdf2sfd
*
* Created: 2019-11-21
- * Last Updated: 2020-02-06
+ * Last Updated: 2020-02-07
*
* bdf2sfd is released under the BSD 2-Clause license
* See LICENSE file for details
@@ -14,15 +14,15 @@
#include <stdio.h>
void
-polygon(uint32_t row, uint32_t mask, uint32_t width, int32_t x, int32_t y, uint32_t xlength, uint32_t ylength) {
+polygon(uint32_t row, uint32_t mask, uint32_t width, float x, float y, float xlength, float ylength) {
for (size_t column = 0; column < width; column++) {
if ((row & (mask >> column)) != 0) {
x = column * xlength;
- fprintf(stdout, "%d %d m 1\n"
- " %d %d l 1\n"
- " %d %d l 1\n"
- " %d %d l 1\n"
- " %d %d l 1\n",
+ fprintf(stdout, "%f %f m 1\n"
+ " %f %f l 1\n"
+ " %f %f l 1\n"
+ " %f %f l 1\n"
+ " %f %f l 1\n",
x, y,
x, y - ylength,
x + xlength, y - ylength,
diff --git a/src/polygon.h b/src/polygon.h
@@ -4,7 +4,7 @@
* https://github.com/fcambus/bdf2sfd
*
* Created: 2019-11-21
- * Last Updated: 2020-02-06
+ * Last Updated: 2020-02-07
*
* bdf2sfd is released under the BSD 2-Clause license
* See LICENSE file for details
@@ -13,6 +13,6 @@
#ifndef POLYGON_H
#define POLYGON_H
-void polygon(uint32_t, uint32_t, uint32_t, int32_t, int32_t, uint32_t, uint32_t);
+void polygon(uint32_t, uint32_t, uint32_t, float, float, float, float);
#endif /* POLYGON_H */