*/
#include <common.h>
+#include <charset.h>
#include <dm.h>
#include <video.h>
#include <video_console.h>
return 0;
}
-static int console_putc_xy(struct udevice *dev, uint x_frac, uint y, char ch)
+static int console_putc_xy(struct udevice *dev, uint x_frac, uint y, int cp)
{
struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
struct udevice *vid = dev->parent;
int pbytes = VNBYTES(vid_priv->bpix);
int x, linenum, ret;
void *start, *line;
+ u8 ch = console_utf_to_cp437(cp);
uchar *pfont = fontdata->video_fontdata +
- (u8)ch * fontdata->char_pixel_bytes;
+ ch * fontdata->char_pixel_bytes;
if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
return -EAGAIN;
*/
#include <common.h>
+#include <charset.h>
#include <dm.h>
#include <video.h>
#include <video_console.h>
return 0;
}
-static int console_putc_xy_1(struct udevice *dev, uint x_frac, uint y, char ch)
+static int console_putc_xy_1(struct udevice *dev, uint x_frac, uint y, int cp)
{
struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
struct udevice *vid = dev->parent;
int pbytes = VNBYTES(vid_priv->bpix);
int x, linenum, ret;
void *start, *line;
+ u8 ch = console_utf_to_cp437(cp);
uchar *pfont = fontdata->video_fontdata +
- (u8)ch * fontdata->char_pixel_bytes;
+ ch * fontdata->char_pixel_bytes;
if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
return -EAGAIN;
return 0;
}
-static int console_putc_xy_2(struct udevice *dev, uint x_frac, uint y, char ch)
+static int console_putc_xy_2(struct udevice *dev, uint x_frac, uint y, int cp)
{
struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
struct udevice *vid = dev->parent;
int pbytes = VNBYTES(vid_priv->bpix);
int linenum, x, ret;
void *start, *line;
+ u8 ch = console_utf_to_cp437(cp);
uchar *pfont = fontdata->video_fontdata +
- (u8)ch * fontdata->char_pixel_bytes;
+ ch * fontdata->char_pixel_bytes;
if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
return -EAGAIN;
return 0;
}
-static int console_putc_xy_3(struct udevice *dev, uint x_frac, uint y, char ch)
+static int console_putc_xy_3(struct udevice *dev, uint x_frac, uint y, int cp)
{
struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
struct udevice *vid = dev->parent;
int pbytes = VNBYTES(vid_priv->bpix);
int linenum, x, ret;
void *start, *line;
+ u8 ch = console_utf_to_cp437(cp);
uchar *pfont = fontdata->video_fontdata +
- (u8)ch * fontdata->char_pixel_bytes;
+ ch * fontdata->char_pixel_bytes;
if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
return -EAGAIN;
}
static int console_truetype_putc_xy(struct udevice *dev, uint x, uint y,
- char ch)
+ int cp)
{
struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
struct udevice *vid = dev->parent;
int row, ret;
/* First get some basic metrics about this character */
- stbtt_GetCodepointHMetrics(font, ch, &advance, &lsb);
+ stbtt_GetCodepointHMetrics(font, cp, &advance, &lsb);
/*
* First out our current X position in fractional pixels. If we wrote
xpos = frac(VID_TO_PIXEL((double)x));
if (vc_priv->last_ch) {
xpos += met->scale * stbtt_GetCodepointKernAdvance(font,
- vc_priv->last_ch, ch);
+ vc_priv->last_ch, cp);
}
/*
* return NULL;
*/
data = stbtt_GetCodepointBitmapSubpixel(font, met->scale, met->scale,
- x_shift, 0, ch, &width, &height,
+ x_shift, 0, cp, &width, &height,
&xoff, &yoff);
if (!data)
return width_frac;
#include <common.h>
#include <abuf.h>
+#include <charset.h>
#include <command.h>
#include <console.h>
#include <log.h>
#include <video_font.h> /* Bitmap font for code page 437 */
#include <linux/ctype.h>
-int vidconsole_putc_xy(struct udevice *dev, uint x, uint y, char ch)
+int vidconsole_putc_xy(struct udevice *dev, uint x, uint y, int ch)
{
struct vidconsole_ops *ops = vidconsole_get_ops(dev);
priv->escape = 0;
}
-/* Put that actual character on the screen (using the CP437 code page). */
-static int vidconsole_output_glyph(struct udevice *dev, char ch)
+/* Put that actual character on the screen (using the UTF-32 code points). */
+static int vidconsole_output_glyph(struct udevice *dev, int ch)
{
struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
int ret;
int vidconsole_put_char(struct udevice *dev, char ch)
{
struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
- int ret;
+ int cp, ret;
if (priv->escape) {
vidconsole_escape_char(dev, ch);
priv->last_ch = 0;
break;
default:
- ret = vidconsole_output_glyph(dev, ch);
+ if (CONFIG_IS_ENABLED(CHARSET)) {
+ cp = utf8_to_utf32_stream(ch, priv->utf8_buf);
+ if (cp == 0)
+ return 0;
+ } else {
+ cp = ch;
+ }
+ ret = vidconsole_output_glyph(dev, cp);
if (ret < 0)
return ret;
break;
* (C) Copyright 2023 Dzmitry Sankouski <dsankouski@gmail.com>
*/
+#include <charset.h>
+#include <config.h>
+
#define FLIPPED_DIRECTION 1
#define NORMAL_DIRECTION 0
* See details in video_console.h select_font function
**/
int console_simple_select_font(struct udevice *dev, const char *name, uint size);
+
+/**
+ * Internal function to convert Unicode code points to code page 437.
+ * Used by video consoles using bitmap fonts.
+ *
+ * @param codepoint Unicode code point
+ * @returns code page 437 character.
+ */
+static inline u8 console_utf_to_cp437(int codepoint)
+{
+ if (CONFIG_IS_ENABLED(CHARSET)) {
+ utf_to_cp(&codepoint, codepage_437);
+ return codepoint;
+ }
+ return codepoint;
+}
* @col_saved: Saved X position, in fractional units (VID_TO_POS(x))
* @row_saved: Saved Y position in pixels (0=top)
* @escape_buf: Buffer to accumulate escape sequence
+ * @utf8_buf: Buffer to accumulate UTF-8 byte sequence
*/
struct vidconsole_priv {
struct stdio_dev sdev;
int row_saved;
int col_saved;
char escape_buf[32];
+ char utf8_buf[5];
};
/**
* @x_frac: Fractional pixel X position (0=left-most pixel) which
* is the X position multipled by VID_FRAC_DIV.
* @y: Pixel Y position (0=top-most pixel)
- * @ch: Character to write
+ * @cp: UTF-32 code point to write
* @return number of fractional pixels that the cursor should move,
* if all is OK, -EAGAIN if we ran out of space on this line, other -ve
* on error
*/
- int (*putc_xy)(struct udevice *dev, uint x_frac, uint y, char ch);
+ int (*putc_xy)(struct udevice *dev, uint x_frac, uint y, int cp);
/**
* move_rows() - Move text rows from one place to another
* @x_frac: Fractional pixel X position (0=left-most pixel) which
* is the X position multipled by VID_FRAC_DIV.
* @y: Pixel Y position (0=top-most pixel)
- * @ch: Character to write
+ * @cp: UTF-32 code point to write
* Return: number of fractional pixels that the cursor should move,
* if all is OK, -EAGAIN if we ran out of space on this line, other -ve
* on error
*/
-int vidconsole_putc_xy(struct udevice *dev, uint x, uint y, char ch);
+int vidconsole_putc_xy(struct udevice *dev, uint x, uint y, int cp);
/**
* vidconsole_move_rows() - Move text rows from one place to another