move files

git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@537 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
Nishi 2025-10-31 21:09:30 +00:00
commit 8d75f58958
13 changed files with 57 additions and 44 deletions

View file

@ -1,137 +0,0 @@
/* $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 */
};

File diff suppressed because it is too large Load diff

View file

@ -1,360 +0,0 @@
/* $Id$ */
#include <Mw/Milsko.h>
#if defined(USE_FREETYPE2)
#include <ft2build.h>
#include FT_FREETYPE_H
typedef struct ttf {
FT_Library library;
FT_Face face;
void* data;
} ttf_t;
#define TTF
#elif defined(USE_STB_TRUETYPE)
#include "../../external/stb_truetype.h"
typedef struct ttf {
stbtt_fontinfo font;
void* data;
float scale;
int ascent;
int descent;
} ttf_t;
#define TTF
#endif
#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;
int tw, th;
unsigned char* px;
MwRect r;
MwLLPixmap p;
if(strlen(text) == 0) text = " ";
tw = MwTextWidth(handle, text);
th = MwTextHeight(handle, text);
px = malloc(tw * th * 4);
memset(px, 0, tw * th * 4);
sx = 0;
sy = 0;
while(text[i] != 0) {
int out;
i += MwUTF8ToUTF32(text + i, &out);
if(out >= 0x80) out = 0;
if(out == '\n') {
sx = 0;
sy += FontHeight;
} else {
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 << ((FontWidth - 1) - x))) {
ppx[0] = color->red;
ppx[1] = color->green;
ppx[2] = color->blue;
ppx[3] = 255;
} else {
ppx[0] = 0;
ppx[1] = 0;
ppx[2] = 0;
ppx[3] = 0;
}
}
}
sx += FontWidth;
}
}
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);
}
#if defined(USE_STB_TRUETYPE)
static int ttf_MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color) {
ttf_t* ttf = MwGetVoid(handle, bold ? MwNboldFont : MwNfont);
unsigned char* px;
int tw, th;
MwRect r;
MwLLPixmap p;
int ax, lsb;
int x = 0;
if(ttf == NULL) return 1;
tw = MwTextWidth(handle, text);
th = MwTextHeight(handle, text);
px = malloc(tw * th * 4);
memset(px, 0, tw * th * 4);
while(text[0] != 0) {
int c;
int x0, y0, x1, y1, cx, cy;
int ow, oh;
unsigned char* out;
text += MwUTF8ToUTF32(text, &c);
stbtt_GetCodepointHMetrics(&ttf->font, c, &ax, &lsb);
stbtt_GetCodepointBitmapBox(&ttf->font, c, ttf->scale, ttf->scale, &x0, &y0, &x1, &y1);
ow = x1 - x0;
oh = y1 - y0;
out = malloc(ow * oh);
stbtt_MakeCodepointBitmap(&ttf->font, out, ow, oh, ow, ttf->scale, ttf->scale, c);
for(cy = 0; cy < oh; cy++) {
for(cx = 0; cx < ow; cx++) {
int ox = x + (lsb * ttf->scale) + cx;
int oy = (ttf->ascent * ttf->scale) + y0 + cy;
unsigned char* opx = &px[(oy * tw + ox) * 4];
opx[0] = color->red;
opx[1] = color->green;
opx[2] = color->blue;
opx[3] = out[cy * ow + cx];
}
}
x += ax * ttf->scale;
free(out);
}
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);
return 0;
}
static int ttf_MwTextWidth(MwWidget handle, const char* text) {
ttf_t* ttf = MwGetVoid(handle, MwNfont);
int ax, lsb;
int tw = 0;
if(ttf == NULL) return -1;
while(text[0] != 0) {
int c;
text += MwUTF8ToUTF32(text, &c);
stbtt_GetCodepointHMetrics(&ttf->font, c, &ax, &lsb);
tw += ax * ttf->scale;
}
return tw;
}
static int ttf_MwTextHeight(MwWidget handle, int count) {
ttf_t* ttf = MwGetVoid(handle, MwNfont);
if(ttf == NULL) return -1;
return (ttf->ascent - ttf->descent) * ttf->scale * count;
}
#elif defined(USE_FREETYPE2)
static int ttf_MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color) {
ttf_t* ttf = MwGetVoid(handle, bold ? MwNboldFont : MwNfont);
int tw, th;
unsigned char* px;
MwLLPixmap p;
MwRect r;
int x = 0;
if(ttf == NULL) return 1;
tw = MwTextWidth(handle, text);
th = MwTextHeight(handle, text);
px = malloc(tw * th * 4);
memset(px, 0, tw * th * 4);
while(text[0] != 0) {
int c;
FT_Bitmap* bmp;
int cy, cx;
text += MwUTF8ToUTF32(text, &c);
FT_Load_Char(ttf->face, c, FT_LOAD_RENDER);
bmp = &ttf->face->glyph->bitmap;
for(cy = 0; cy < bmp->rows; cy++) {
for(cx = 0; cx < bmp->width; cx++) {
int ox = x + cx + ttf->face->glyph->bitmap_left;
int oy = th - ttf->face->glyph->bitmap_top + cy + (ttf->face->descender * 14 / ttf->face->units_per_EM);
unsigned char* opx = &px[(oy * tw + ox) * 4];
opx[0] = color->red;
opx[1] = color->green;
opx[2] = color->blue;
opx[3] = bmp->buffer[cy * bmp->pitch + cx];
}
}
x += ttf->face->glyph->metrics.horiAdvance / 64;
}
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);
return 0;
}
static int ttf_MwTextWidth(MwWidget handle, const char* text) {
ttf_t* ttf = MwGetVoid(handle, MwNfont);
int tw = 0;
if(ttf == NULL) return -1;
while(text[0] != 0) {
int c;
text += MwUTF8ToUTF32(text, &c);
FT_Load_Char(ttf->face, c, FT_LOAD_RENDER);
tw += ttf->face->glyph->metrics.horiAdvance / 64;
}
return tw;
}
static int ttf_MwTextHeight(MwWidget handle, int count) {
ttf_t* ttf = MwGetVoid(handle, MwNfont);
if(ttf == NULL) return -1;
return (ttf->face->height * 14 / ttf->face->units_per_EM) * count;
}
#endif
void MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color) {
#ifdef TTF
if(ttf_MwDrawText(handle, point, text, bold, align, color))
#endif
bitmap_MwDrawText(handle, point, text, bold, align, color);
}
int MwTextWidth(MwWidget handle, const char* text) {
/* TODO: check newline */
#ifdef TTF
int st;
if((st = ttf_MwTextWidth(handle, text)) != -1) return st;
#else
(void)handle;
#endif
return strlen(text) * FontWidth;
}
int MwTextHeight(MwWidget handle, const char* text) {
int c = 1;
int i = 0;
#ifdef TTF
int st;
#endif
(void)handle;
(void)text;
while(text[i] != 0) {
int out;
i += MwUTF8ToUTF32(text + i, &out);
if(out == '\n') c++;
}
#ifdef TTF
if((st = ttf_MwTextHeight(handle, c)) != -1) return st;
#endif
return FontHeight * c;
}
void* MwFontLoad(unsigned char* data, unsigned int size) {
#if defined(USE_FREETYPE2)
ttf_t* ttf = malloc(sizeof(*ttf));
ttf->data = malloc(size);
memcpy(ttf->data, data, size);
FT_Init_FreeType(&ttf->library);
FT_New_Memory_Face(ttf->library, ttf->data, size, 0, &ttf->face);
FT_Set_Pixel_Sizes(ttf->face, 0, 14);
return ttf;
#elif defined(USE_STB_TRUETYPE)
ttf_t* ttf = malloc(sizeof(*ttf));
ttf->data = malloc(size);
memcpy(ttf->data, data, size);
stbtt_InitFont(&ttf->font, ttf->data, 0);
ttf->scale = stbtt_ScaleForPixelHeight(&ttf->font, 16);
stbtt_GetFontVMetrics(&ttf->font, &ttf->ascent, &ttf->descent, 0);
return ttf;
#else
(void)data;
(void)size;
return NULL;
#endif
}
void MwFontFree(void* handle) {
#if defined(USE_FREETYPE2)
ttf_t* ttf = handle;
FT_Done_Face(ttf->face);
FT_Done_FreeType(ttf->library);
free(ttf->data);
free(ttf);
#elif defined(USE_STB_TRUETYPE)
ttf_t* ttf = handle;
free(ttf->data);
free(ttf);
#else
(void)handle;
#endif
}

View file

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

File diff suppressed because it is too large Load diff