add stuff

git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@471 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
Nishi 2025-10-23 06:20:50 +00:00
commit 397c26ca89
6 changed files with 5102 additions and 285 deletions

137
src/text/boldfont.c Normal file
View file

@ -0,0 +1,137 @@
/* $Id$ */
#include <Mw/Milsko.h>
/**
* Copyright notice:
* "Public domain font. Share and enjoy."
*/
MwFont MwBoldFontData[] = {
{0, 12, {0, 90, 66, 0, 66, 66, 0, 66, 66, 0, 66, 90, 0, 0}}, /* 0 */
{0, 12, {0, 90, 66, 0, 66, 66, 0, 66, 66, 0, 66, 90, 0, 0}}, /* 1 */
{0, 12, {0, 90, 66, 0, 66, 66, 0, 66, 66, 0, 66, 90, 0, 0}}, /* 2 */
{0, 12, {0, 90, 66, 0, 66, 66, 0, 66, 66, 0, 66, 90, 0, 0}}, /* 3 */
{0, 12, {0, 90, 66, 0, 66, 66, 0, 66, 66, 0, 66, 90, 0, 0}}, /* 4 */
{0, 12, {0, 90, 66, 0, 66, 66, 0, 66, 66, 0, 66, 90, 0, 0}}, /* 5 */
{0, 12, {0, 90, 66, 0, 66, 66, 0, 66, 66, 0, 66, 90, 0, 0}}, /* 6 */
{0, 12, {0, 90, 66, 0, 66, 66, 0, 66, 66, 0, 66, 90, 0, 0}}, /* 7 */
{0, 12, {0, 90, 66, 0, 66, 66, 0, 66, 66, 0, 66, 90, 0, 0}}, /* 8 */
{0, 12, {0, 90, 66, 0, 66, 66, 0, 66, 66, 0, 66, 90, 0, 0}}, /* 9 */
{0, 12, {0, 90, 66, 0, 66, 66, 0, 66, 66, 0, 66, 90, 0, 0}}, /* 10 */
{0, 12, {0, 90, 66, 0, 66, 66, 0, 66, 66, 0, 66, 90, 0, 0}}, /* 11 */
{0, 12, {0, 90, 66, 0, 66, 66, 0, 66, 66, 0, 66, 90, 0, 0}}, /* 12 */
{0, 12, {0, 90, 66, 0, 66, 66, 0, 66, 66, 0, 66, 90, 0, 0}}, /* 13 */
{0, 12, {0, 90, 66, 0, 66, 66, 0, 66, 66, 0, 66, 90, 0, 0}}, /* 14 */
{0, 12, {0, 90, 66, 0, 66, 66, 0, 66, 66, 0, 66, 90, 0, 0}}, /* 15 */
{0, 12, {0, 90, 66, 0, 66, 66, 0, 66, 66, 0, 66, 90, 0, 0}}, /* 16 */
{0, 12, {0, 90, 66, 0, 66, 66, 0, 66, 66, 0, 66, 90, 0, 0}}, /* 17 */
{0, 12, {0, 90, 66, 0, 66, 66, 0, 66, 66, 0, 66, 90, 0, 0}}, /* 18 */
{0, 12, {0, 90, 66, 0, 66, 66, 0, 66, 66, 0, 66, 90, 0, 0}}, /* 19 */
{0, 12, {0, 90, 66, 0, 66, 66, 0, 66, 66, 0, 66, 90, 0, 0}}, /* 20 */
{0, 12, {0, 90, 66, 0, 66, 66, 0, 66, 66, 0, 66, 90, 0, 0}}, /* 21 */
{0, 12, {0, 90, 66, 0, 66, 66, 0, 66, 66, 0, 66, 90, 0, 0}}, /* 22 */
{0, 12, {0, 90, 66, 0, 66, 66, 0, 66, 66, 0, 66, 90, 0, 0}}, /* 23 */
{0, 12, {0, 90, 66, 0, 66, 66, 0, 66, 66, 0, 66, 90, 0, 0}}, /* 24 */
{0, 12, {0, 90, 66, 0, 66, 66, 0, 66, 66, 0, 66, 90, 0, 0}}, /* 25 */
{0, 12, {0, 90, 66, 0, 66, 66, 0, 66, 66, 0, 66, 90, 0, 0}}, /* 26 */
{0, 12, {0, 90, 66, 0, 66, 66, 0, 66, 66, 0, 66, 90, 0, 0}}, /* 27 */
{0, 12, {0, 90, 66, 0, 66, 66, 0, 66, 66, 0, 66, 90, 0, 0}}, /* 28 */
{0, 12, {0, 90, 66, 0, 66, 66, 0, 66, 66, 0, 66, 90, 0, 0}}, /* 29 */
{0, 12, {0, 90, 66, 0, 66, 66, 0, 66, 66, 0, 66, 90, 0, 0}}, /* 30 */
{0, 12, {0, 90, 66, 0, 66, 66, 0, 66, 66, 0, 66, 90, 0, 0}}, /* 31 */
{0, 12, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 32 */
{0, 12, {0, 0, 24, 24, 24, 24, 24, 24, 24, 0, 24, 24, 0, 0}}, /* 33 */
{0, 12, {0, 54, 54, 54, 54, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 34 */
{0, 12, {0, 0, 60, 60, 60, 126, 60, 60, 126, 60, 60, 60, 0, 0}}, /* 35 */
{0, 12, {0, 0, 24, 60, 90, 90, 56, 28, 26, 90, 90, 60, 24, 0}}, /* 36 */
{0, 12, {0, 0, 54, 110, 108, 56, 8, 16, 28, 54, 118, 108, 0, 0}}, /* 37 */
{0, 12, {0, 0, 28, 54, 54, 54, 28, 54, 110, 108, 108, 54, 0, 0}}, /* 38 */
{0, 12, {0, 24, 24, 24, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 39 */
{0, 12, {0, 6, 12, 24, 24, 48, 48, 48, 48, 48, 24, 24, 12, 6}}, /* 40 */
{0, 12, {0, 48, 24, 12, 12, 6, 6, 6, 6, 6, 12, 12, 24, 48}}, /* 41 */
{0, 12, {0, 0, 90, 90, 60, 24, 60, 90, 90, 0, 0, 0, 0, 0}}, /* 42 */
{0, 12, {0, 0, 0, 0, 24, 24, 24, 126, 24, 24, 24, 0, 0, 0}}, /* 43 */
{0, 12, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28, 12, 12, 24}}, /* 44 */
{0, 12, {0, 0, 0, 0, 0, 0, 0, 126, 0, 0, 0, 0, 0, 0}}, /* 45 */
{0, 12, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 24, 0, 0}}, /* 46 */
{0, 12, {0, 6, 6, 6, 12, 12, 24, 24, 24, 48, 48, 96, 96, 96}}, /* 47 */
{0, 12, {0, 0, 60, 102, 102, 102, 102, 102, 102, 102, 102, 60, 0, 0}}, /* 48 */
{0, 12, {0, 0, 24, 56, 120, 24, 24, 24, 24, 24, 24, 126, 0, 0}}, /* 49 */
{0, 12, {0, 0, 60, 102, 102, 6, 12, 12, 24, 48, 96, 126, 0, 0}}, /* 50 */
{0, 12, {0, 0, 60, 102, 102, 6, 28, 6, 6, 102, 102, 60, 0, 0}}, /* 51 */
{0, 12, {0, 0, 4, 12, 12, 28, 60, 108, 108, 126, 12, 12, 0, 0}}, /* 52 */
{0, 12, {0, 0, 126, 96, 96, 124, 102, 6, 6, 102, 102, 60, 0, 0}}, /* 53 */
{0, 12, {0, 0, 28, 54, 102, 96, 124, 102, 102, 102, 102, 60, 0, 0}}, /* 54 */
{0, 12, {0, 0, 126, 102, 108, 12, 24, 24, 24, 24, 24, 24, 0, 0}}, /* 55 */
{0, 12, {0, 0, 60, 102, 102, 102, 60, 60, 102, 102, 102, 60, 0, 0}}, /* 56 */
{0, 12, {0, 0, 60, 102, 102, 102, 102, 62, 6, 102, 108, 56, 0, 0}}, /* 57 */
{0, 12, {0, 0, 0, 0, 24, 24, 0, 0, 0, 24, 24, 0, 0, 0}}, /* 58 */
{0, 12, {0, 0, 0, 0, 12, 12, 0, 0, 0, 28, 12, 12, 24, 0}}, /* 59 */
{0, 12, {0, 0, 0, 6, 12, 24, 48, 96, 48, 24, 12, 6, 0, 0}}, /* 60 */
{0, 12, {0, 0, 0, 0, 0, 0, 126, 0, 0, 126, 0, 0, 0, 0}}, /* 61 */
{0, 12, {0, 0, 0, 96, 48, 24, 12, 6, 12, 24, 48, 96, 0, 0}}, /* 62 */
{0, 12, {0, 0, 60, 102, 102, 12, 24, 24, 24, 0, 24, 24, 0, 0}}, /* 63 */
{0, 12, {0, 0, 28, 54, 110, 122, 122, 122, 122, 110, 48, 30, 0, 0}}, /* 64 */
{0, 12, {0, 0, 60, 126, 102, 102, 102, 102, 126, 102, 102, 102, 0, 0}}, /* 65 */
{0, 12, {0, 0, 124, 102, 102, 100, 124, 102, 102, 102, 102, 124, 0, 0}}, /* 66 */
{0, 12, {0, 0, 60, 102, 102, 96, 96, 96, 96, 102, 102, 60, 0, 0}}, /* 67 */
{0, 12, {0, 0, 120, 108, 102, 102, 102, 102, 102, 102, 108, 120, 0, 0}}, /* 68 */
{0, 12, {0, 0, 126, 96, 96, 96, 124, 96, 96, 96, 96, 126, 0, 0}}, /* 69 */
{0, 12, {0, 0, 126, 96, 96, 96, 124, 96, 96, 96, 96, 96, 0, 0}}, /* 70 */
{0, 12, {0, 0, 60, 102, 102, 96, 96, 110, 102, 102, 102, 60, 0, 0}}, /* 71 */
{0, 12, {0, 0, 102, 102, 102, 102, 126, 102, 102, 102, 102, 102, 0, 0}}, /* 72 */
{0, 12, {0, 0, 126, 24, 24, 24, 24, 24, 24, 24, 24, 126, 0, 0}}, /* 73 */
{0, 12, {0, 0, 6, 6, 6, 6, 6, 6, 6, 102, 108, 56, 0, 0}}, /* 74 */
{0, 12, {0, 0, 102, 108, 120, 112, 112, 120, 120, 108, 102, 102, 0, 0}}, /* 75 */
{0, 12, {0, 0, 96, 96, 96, 96, 96, 96, 96, 96, 96, 126, 0, 0}}, /* 76 */
{0, 12, {0, 0, 66, 102, 102, 126, 126, 102, 102, 102, 102, 102, 0, 0}}, /* 77 */
{0, 12, {0, 0, 102, 102, 118, 118, 118, 110, 110, 110, 102, 102, 0, 0}}, /* 78 */
{0, 12, {0, 0, 60, 102, 102, 102, 102, 102, 102, 102, 102, 60, 0, 0}}, /* 79 */
{0, 12, {0, 0, 124, 102, 102, 102, 102, 124, 96, 96, 96, 96, 0, 0}}, /* 80 */
{0, 12, {0, 0, 60, 102, 102, 102, 102, 102, 118, 110, 102, 60, 6, 2}}, /* 81 */
{0, 12, {0, 0, 124, 102, 102, 102, 124, 108, 102, 102, 102, 102, 0, 0}}, /* 82 */
{0, 12, {0, 0, 60, 102, 102, 48, 24, 24, 12, 102, 102, 60, 0, 0}}, /* 83 */
{0, 12, {0, 0, 126, 24, 24, 24, 24, 24, 24, 24, 24, 24, 0, 0}}, /* 84 */
{0, 12, {0, 0, 102, 102, 102, 102, 102, 102, 102, 102, 102, 60, 0, 0}}, /* 85 */
{0, 12, {0, 0, 102, 102, 102, 102, 102, 102, 102, 60, 60, 24, 0, 0}}, /* 86 */
{0, 12, {0, 0, 102, 102, 102, 102, 102, 126, 126, 126, 126, 36, 0, 0}}, /* 87 */
{0, 12, {0, 0, 102, 102, 60, 60, 24, 24, 60, 60, 102, 102, 0, 0}}, /* 88 */
{0, 12, {0, 0, 102, 102, 102, 60, 60, 24, 24, 24, 24, 24, 0, 0}}, /* 89 */
{0, 12, {0, 0, 126, 6, 12, 12, 24, 24, 48, 48, 96, 126, 0, 0}}, /* 90 */
{0, 12, {0, 62, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 62}}, /* 91 */
{0, 12, {0, 96, 96, 96, 48, 48, 24, 24, 24, 12, 12, 6, 6, 6}}, /* 92 */
{0, 12, {0, 62, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 62}}, /* 93 */
{0, 12, {24, 60, 102, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 94 */
{0, 12, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 126, 126}}, /* 95 */
{0, 12, {0, 48, 24, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 96 */
{0, 12, {0, 0, 0, 0, 0, 60, 102, 14, 54, 102, 102, 62, 0, 0}}, /* 97 */
{0, 12, {0, 0, 96, 96, 96, 124, 102, 102, 102, 102, 102, 124, 0, 0}}, /* 98 */
{0, 12, {0, 0, 0, 0, 0, 60, 102, 96, 96, 96, 102, 60, 0, 0}}, /* 99 */
{0, 12, {0, 0, 6, 6, 6, 62, 102, 102, 102, 102, 102, 62, 0, 0}}, /* 100 */
{0, 12, {0, 0, 0, 0, 0, 60, 102, 102, 126, 96, 102, 60, 0, 0}}, /* 101 */
{0, 12, {0, 0, 12, 30, 24, 24, 126, 24, 24, 24, 24, 24, 0, 0}}, /* 102 */
{0, 12, {0, 0, 0, 0, 0, 58, 110, 108, 108, 56, 32, 124, 102, 60}}, /* 103 */
{0, 12, {0, 0, 96, 96, 96, 124, 102, 102, 102, 102, 102, 102, 0, 0}}, /* 104 */
{0, 12, {0, 0, 24, 24, 0, 24, 24, 24, 24, 24, 24, 24, 0, 0}}, /* 105 */
{0, 12, {0, 0, 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 54, 28}}, /* 106 */
{0, 12, {0, 0, 96, 96, 96, 100, 108, 120, 120, 108, 102, 98, 0, 0}}, /* 107 */
{0, 12, {0, 0, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 0, 0}}, /* 108 */
{0, 12, {0, 0, 0, 0, 0, 108, 126, 126, 126, 126, 126, 102, 0, 0}}, /* 109 */
{0, 12, {0, 0, 0, 0, 0, 124, 102, 102, 102, 102, 102, 102, 0, 0}}, /* 110 */
{0, 12, {0, 0, 0, 0, 0, 60, 102, 102, 102, 102, 102, 60, 0, 0}}, /* 111 */
{0, 12, {0, 0, 0, 0, 0, 124, 102, 102, 102, 102, 102, 124, 96, 96}}, /* 112 */
{0, 12, {0, 0, 0, 0, 0, 62, 102, 102, 102, 102, 102, 62, 6, 6}}, /* 113 */
{0, 12, {0, 0, 0, 0, 0, 124, 102, 102, 96, 96, 96, 96, 0, 0}}, /* 114 */
{0, 12, {0, 0, 0, 0, 0, 60, 102, 48, 24, 12, 102, 60, 0, 0}}, /* 115 */
{0, 12, {0, 0, 24, 24, 24, 126, 24, 24, 24, 24, 24, 14, 0, 0}}, /* 116 */
{0, 12, {0, 0, 0, 0, 0, 102, 102, 102, 102, 102, 102, 62, 0, 0}}, /* 117 */
{0, 12, {0, 0, 0, 0, 0, 102, 102, 102, 60, 60, 24, 24, 0, 0}}, /* 118 */
{0, 12, {0, 0, 0, 0, 0, 102, 102, 126, 126, 126, 126, 36, 0, 0}}, /* 119 */
{0, 12, {0, 0, 0, 0, 0, 102, 102, 60, 24, 60, 102, 102, 0, 0}}, /* 120 */
{0, 12, {0, 0, 0, 0, 0, 102, 102, 54, 54, 28, 28, 12, 108, 56}}, /* 121 */
{0, 12, {0, 0, 0, 0, 0, 126, 6, 12, 24, 48, 96, 126, 0, 0}}, /* 122 */
{0, 12, {0, 14, 24, 24, 24, 24, 24, 48, 24, 24, 24, 24, 24, 14}}, /* 123 */
{0, 12, {0, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24}}, /* 124 */
{0, 12, {0, 56, 12, 12, 12, 12, 12, 6, 12, 12, 12, 12, 12, 56}}, /* 125 */
{0, 12, {0, 34, 122, 94, 68, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 126 */
{0, 12, {0, 90, 66, 0, 66, 66, 0, 66, 66, 0, 66, 90, 0, 0}} /* 127 */
};

View file

@ -1,16 +1,8 @@
/* $Id$ */
#include <Mw/Milsko.h>
#ifdef HAS_FREETYPE
#include <ft2build.h>
#include FT_FREETYPE_H
#endif
#define bitmap_FontWidth 7
#define bitmap_FontHeight 14
#define ft_FontWidth 14
#define ft_FontHeight 14
#define FontWidth 7
#define FontHeight 14
static void bitmap_MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color) {
int i = 0, x, y, sx, sy;
@ -38,12 +30,12 @@ static void bitmap_MwDrawText(MwWidget handle, MwPoint* point, const char* text,
if(out == '\n') {
sx = 0;
sy += bitmap_FontHeight;
sy += FontHeight;
} else {
for(y = 0; y < bitmap_FontHeight; y++) {
for(x = 0; x < bitmap_FontWidth; x++) {
for(y = 0; y < FontHeight; y++) {
for(x = 0; x < FontWidth; x++) {
unsigned char* ppx = &px[((sy + y) * tw + sx + x) * 4];
if((bold ? MwBoldFontData : MwFontData)[out].data[y] & (1 << ((bitmap_FontWidth - 1) - x))) {
if((bold ? MwBoldFontData : MwFontData)[out].data[y] & (1 << ((FontWidth - 1) - x))) {
ppx[0] = color->red;
ppx[1] = color->green;
ppx[2] = color->blue;
@ -56,7 +48,7 @@ static void bitmap_MwDrawText(MwWidget handle, MwPoint* point, const char* text,
}
}
}
sx += bitmap_FontWidth;
sx += FontWidth;
}
}
@ -77,117 +69,6 @@ static void bitmap_MwDrawText(MwWidget handle, MwPoint* point, const char* text,
free(px);
}
#ifdef HAS_FREETYPE
static void ft_MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color) {
FT_Error err;
FT_Error (*_FT_Load_Char)(FT_Face face,
FT_ULong char_code,
FT_Int32 load_flags);
FT_Error (*_FT_Set_Pixel_Sizes)(FT_Face face,
FT_UInt pixel_width,
FT_UInt pixel_height);
MwLL l = handle->lowlevel;
int i = 0, x, y, sx, sy;
int tw;
int th;
unsigned char* px;
MwRect r;
MwLLPixmap p;
if(strlen(text) == 0) text = " ";
tw = MwTextWidth(handle, text);
th = MwTextHeight(handle, text);
// allocate 4x memory then what we need to account for spacing, italics, etc.
px = malloc(tw * th * 16);
memset(px, 0, tw * th * 16);
sx = 0;
sy = 0;
FT_WITH_FUNC(l, FT_Set_Pixel_Sizes, {
if((err = _FT_Set_Pixel_Sizes(l->ftFace, ft_FontWidth, ft_FontHeight)) != 0) {
if(r.width == 0 || r.height == 0) {
printf("failed to set pixel sizes");
print_ft_error(l->ftLib, err);
return;
}
}
});
FT_WITH_FUNC(l, FT_Load_Char, {
while(text[i] != 0) {
int out;
i += MwUTF8ToUTF32(text + i, &out);
if(out >= 0x80) out = 0;
if((err = _FT_Load_Char(l->ftFace, out, FT_LOAD_RENDER)) != 0) {
printf("[WARNING] Failed to render %c. ", out);
print_ft_error(l->ftLib, err);
continue;
}
FT_GlyphSlot glyph = l->ftFace->glyph;
FT_Bitmap bitmap = glyph->bitmap;
r.width = bitmap.width;
r.height = bitmap.rows;
if(sy == 0) {
sy = r.height;
}
if(r.width == 0 || r.height == 0) {
sx += ft_FontWidth;
continue;
}
if(out == '\n') {
sx = 0;
sy += r.height;
} else {
// printf("%ld\n", (glyph->advance.x / r.width));
int gsx = sx + glyph->bitmap_left;
int gsy = (sy - glyph->bitmap_top);
for(y = 0; y < r.height; y++) {
for(x = 0; x < r.width; x++) {
unsigned char* ppx = &px[((gsy + y) * tw + gsx + x) * 4];
unsigned char gray = bitmap.buffer[(y * r.width) + x];
ppx[0] = color->red - gray;
ppx[1] = color->green - gray;
ppx[2] = color->blue - gray;
ppx[3] = gray;
}
}
sx += r.width;
// sx += glyph->advance.x;
}
}
});
p = MwLoadRaw(handle, px, tw, th);
r.x = point->x;
r.y = point->y - th / 2;
r.width = tw;
r.height = th;
if(align == MwALIGNMENT_CENTER) {
r.x -= tw / 2;
} else if(align == MwALIGNMENT_END) {
r.x -= tw;
}
MwLLDrawPixmap(handle->lowlevel, &r, p);
MwLLDestroyPixmap(p);
free(px);
}
#endif
void MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color) {
bitmap_MwDrawText(handle, point, text, bold, align, color);
}
@ -195,16 +76,8 @@ void MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, int
int MwTextWidth(MwWidget handle, const char* text) {
(void)handle;
/* TODO: check newline */
#ifdef HAS_FREETYPE
if(handle->lowlevel->ftLib != NULL) {
return strlen(text) * ft_FontWidth;
} else {
#endif
return strlen(text) * bitmap_FontWidth;
#ifdef HAS_FREETYPE
}
#endif
/* TODO: check newline */
return strlen(text) * FontWidth;
}
int MwTextHeight(MwWidget handle, const char* text) {
@ -220,13 +93,5 @@ int MwTextHeight(MwWidget handle, const char* text) {
if(out == '\n') c++;
}
#ifdef HAS_FREETYPE
if(handle->lowlevel->ftLib != NULL) {
return ft_FontHeight * c;
} else {
#endif
return bitmap_FontHeight * c;
#ifdef HAS_FREETYPE
}
#endif
return FontHeight * c;
}