bdf2sfd

BDF to SFD converter, allowing to vectorize bitmap fonts
Log | Files | Refs | README | LICENSE

commit c521ef43856695c3321402edf4d8419fc2765f5e
parent d01659aacdcc639bf40f7d4dc741d9480d0232a3
Author: Frederic Cambus <fred@statdns.com>
Date:   Thu,  6 Feb 2020 15:16:58 +0100

Introduce a polygon() function to draw polygons, makes things cleaner.

Diffstat:
MCMakeLists.txt | 2+-
Msrc/bdftosfd.c | 19+++----------------
Asrc/polygon.c | 33+++++++++++++++++++++++++++++++++
Asrc/polygon.h | 18++++++++++++++++++
4 files changed, 55 insertions(+), 17 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt @@ -26,7 +26,7 @@ check_function_exists(strtonum HAVE_STRTONUM) include_directories("compat") set(CMAKE_BUILD_TYPE Release) -set(SRC src/bdftosfd.c src/header.c src/parse.c) +set(SRC src/bdftosfd.c src/header.c src/parse.c src/polygon.c) if(NOT HAVE_PLEDGE) set (SRC ${SRC} compat/pledge.c) diff --git a/src/bdftosfd.c b/src/bdftosfd.c @@ -31,6 +31,7 @@ #include "config.h" #include "header.h" #include "parse.h" +#include "polygon.h" struct timespec begin, end, elapsed; @@ -295,22 +296,8 @@ main(int argc, char *argv[]) if (readglyph) { uint32_t row = strtoul(lineBuffer, NULL, 16); - 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", - x, y, - x, y - ylength, - x + xlength, y - ylength, - x + xlength, y, - x, y); - } - } - + polygon(row, mask, width, x, y, xlength, ylength); + y -= ylength; } } diff --git a/src/polygon.c b/src/polygon.c @@ -0,0 +1,33 @@ +/* + * bdftosfd + * Copyright (c) 2019-2020, Frederic Cambus + * https://github.com/fcambus/bdftosfd + * + * Created: 2019-11-21 + * Last Updated: 2020-02-06 + * + * bdftosfd is released under the BSD 2-Clause license + * See LICENSE file for details + */ + +#include <inttypes.h> +#include <stdio.h> + +void +polygon(uint32_t row, uint32_t mask, int32_t width, int32_t x, int32_t y, int32_t xlength, int32_t 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", + x, y, + x, y - ylength, + x + xlength, y - ylength, + x + xlength, y, + x, y); + } + } +} diff --git a/src/polygon.h b/src/polygon.h @@ -0,0 +1,18 @@ +/* + * bdftosfd + * Copyright (c) 2019-2020, Frederic Cambus + * https://github.com/fcambus/bdftosfd + * + * Created: 2019-11-21 + * Last Updated: 2020-02-06 + * + * bdftosfd is released under the BSD 2-Clause license + * See LICENSE file for details + */ + +#ifndef POLYGON_H +#define POLYGON_H + +void polygon(uint32_t, uint32_t, int32_t, int32_t, int32_t, int32_t, int32_t); + +#endif /* POLYGON_H */