diff --git a/include/nanosvg.h b/include/nanosvg.h index 2fca86a..de19c78 100644 --- a/include/nanosvg.h +++ b/include/nanosvg.h @@ -103,6 +103,8 @@ typedef struct NSVGimage { float height; // Height of the image. int fontAscent; int fontDescent; + int fontUnitsPerEm; + int fontHeight; int defaultHorizAdv; NSVGshape *shapes; // Linked list of shapes in the image. } NSVGimage; diff --git a/meson.build b/meson.build index 96b1cfd..ca2fbad 100644 --- a/meson.build +++ b/meson.build @@ -3,7 +3,8 @@ cc = meson.get_compiler('c') deps = [ cc.find_library('m', required : false), - dependency('libdrm', required : true), + dependency('libdrm'), + dependency('libudev'), ] inc = [ diff --git a/src/drawing.c b/src/drawing.c index 6f001cf..c00a9e6 100644 --- a/src/drawing.c +++ b/src/drawing.c @@ -11,6 +11,8 @@ #include "framebuffer.h" #include "tfblib.h" +#define DEBUGRENDER 0 + extern inline uint32_t tfb_make_color(uint8_t red, uint8_t green, uint8_t blue); extern inline void tfb_draw_pixel(int x, int y, uint32_t color); extern inline uint32_t tfb_screen_width(void); @@ -137,22 +139,14 @@ void tfb_fill_rect(int x, int y, int w, int h, uint32_t color) if (w < 0 || h < 0) return; - /* - for (uint32_t cy = y; cy < yend; cy++) { - //memset(dest, color, w); - for (uint32_t cx = x; cx < x + w; cx++) - tfb_draw_pixel(cx, cy, color); - } - */ - w = MIN(w, MAX(0, (int)__fb_win_end_x - x)); yend = MIN(y + h, __fb_win_end_y); dest = __fb_buffer + y * __fb_pitch + (x * 4); /* drm alignment weirdness */ - //if (drm) - w *= 4; + if (drm) + w *= 4; for (uint32_t cy = y; cy < yend; cy++, dest += __fb_pitch) memset(dest, color, w); @@ -259,8 +253,6 @@ void tfb_fill_circle(int cx, int cy, int r, uint32_t color) tfb_draw_pixel(cx + x, cy + y, color); } -#define DEBUGRENDER 0 - /* x and y are expected to be relative to the screen rotation, however the buffer * width and height won't be, we need to handle rotating the buffer here. */ diff --git a/src/pbsplash.c b/src/pbsplash.c index 0f32fe8..2f39fe1 100644 --- a/src/pbsplash.c +++ b/src/pbsplash.c @@ -108,6 +108,7 @@ static inline float getShapeWidth(const NSVGimage *font, const NSVGshape *shape) if (shape) { return shape->horizAdvX; } else { + //printf("WARNING: Shape for '%s' is NULL!\n", shape->unicode ?: ""); return font->defaultHorizAdv; } } @@ -120,7 +121,7 @@ static const char *getTextDimensions(const NSVGimage *font, const char *text, fl int *width, int *height) { int i, j; - int fontHeight = (font->fontAscent - font->fontDescent) * scale; + int fontHeight = font->fontHeight * scale; int maxWidth = 0; if (text == NULL) @@ -129,7 +130,7 @@ static const char *getTextDimensions(const NSVGimage *font, const char *text, fl // Pre-allocate 3x the size to account for any word splitting char *out_text = zalloc(strlen(text) * 3 + 1); - *width = 2; // font->defaultHorizAdv * scale; + *width = font->defaultHorizAdv * scale; // The height is simply the height of the font * the scale factor *height = fontHeight; @@ -174,7 +175,7 @@ static const char *getTextDimensions(const NSVGimage *font, const char *text, fl line_has_space = true; } - *width += round(getShapeWidth(font, shape) * scale); + *width += ceil(getShapeWidth(font, shape) * scale); } *width = *width > maxWidth ? *width : maxWidth;