lib/fonts: Add font_glyph_cursor() helper

The new helper font_glyph_cursor() fills a glyph with a cursor pattern.
As with the font_glyph_rotate_*() helpers, the caller has to provide the
output memory.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Helge Deller <deller@gmx.de>
Signed-off-by: Helge Deller <deller@gmx.de>
This commit is contained in:
Thomas Zimmermann 2026-10-05 15:31:02 +02:00 committed by Helge Deller
parent 5c02696d15
commit a88cef9206
3 changed files with 62 additions and 1 deletions

View File

@ -109,6 +109,10 @@ const unsigned char *font_data_glyph_buf(font_data_t *fd,
bool font_data_is_equal(font_data_t *lhs, font_data_t *rhs);
int font_data_export(font_data_t *fd, struct console_font *font, unsigned int vpitch);
/* font_cursor.c */
void font_glyph_cursor(unsigned int width, unsigned int height,
unsigned int from, unsigned int to, unsigned char *out);
/* font_rotate.c */
void font_glyph_rotate_90(const unsigned char *glyph, unsigned int width, unsigned int height,
unsigned char *out);

View File

@ -1,7 +1,8 @@
# SPDX-License-Identifier: GPL-2.0
# Font handling
font-y := fonts.o
font-y := fonts.o \
font_cursor.o
font-$(CONFIG_FRAMEBUFFER_CONSOLE_ROTATION) += font_rotate.o
# Built-in fonts; sorted by Family-Size in ascending order

56
lib/fonts/font_cursor.c Normal file
View File

@ -0,0 +1,56 @@
// SPDX-License-Identifier: GPL-2.0-only
#include <linux/bug.h>
#include <linux/export.h>
#include <linux/string.h>
#include "font.h"
/**
* font_glyph_cursor - Create a cursor glyph
* @width: The glyph width in bits per scanline
* @height: The number of scanlines in the glyph
* @start: The first scanline of the cursor block
* @end: The first scanline after the cursor block
* @out: The cursor-glyph bitmap
*
* The parameters @width and @height refer to the glyph size. The caller
* has to provide the output buffer @out of sufficient size to hold the
* cursor glyph. The arguments in @start and @end describe the number of
* scanlines occupied by the cursor block; counting from the top of the
* glyph. The helper fills these scanlines with a pattern and clears the
* remaining scanlines.
*/
void font_glyph_cursor(unsigned int width, unsigned int height,
unsigned int start, unsigned int end, unsigned char *out)
{
unsigned int pitch = font_glyph_pitch(width);
const unsigned char *out_end = out + height * pitch;
unsigned int size;
if (WARN_ON_ONCE(start > height))
start = height;
if (WARN_ON_ONCE(end > height))
end = height;
if (end < start)
end = start;
/* clear scanlines before cursor block */
size = start * pitch;
memset(out, 0x00, size);
out += size;
/* set cursor block */
size = (end - start) * pitch;
memset(out, 0xff, size);
out += size;
/* clear scanlines below cursor block */
size = (height - end) * pitch;
memset(out, 0x00, size);
out += size;
WARN_ON_ONCE(out != out_end);
}
EXPORT_SYMBOL_GPL(font_glyph_cursor);