diff --git a/configure.ac b/configure.ac index aa6d424b..ca70965d 100644 --- a/configure.ac +++ b/configure.ac @@ -636,6 +636,10 @@ AC_ARG_ENABLE(unicodesupport, [ --enable-unicodesupport include UNICODE (ISO-10646-1 and UTF-8 encoding) support ], build_unicode_support=$enableval) +AC_ARG_ENABLE(fullunicode, +[ --enable-fullunicode include support for full UNICODE code points ], +build_full_unicode=$enableval) + AC_ARG_ENABLE(kbdhebrewpc, [ --enable-kbdhebrewpc include keyboard layout for Hebrew PC keyboard ], use_kbd_hebrewpc=$enableval) @@ -2217,6 +2221,11 @@ if test "x$build_unicode_support" = "xyes"; then [Define if support UNICODE]) fi +if test "x$build_full_unicode" = "xyes"; then + AC_DEFINE(_MGCHARSET_UNICODE_FULL, 1, + [Define if support full UNICODE code points]) +fi + if test "x$use_kbd_hebrewpc" = "xyes"; then AC_DEFINE(_MGKBDLAYOUT_HEBREWPC, 1, [Define if use the Hebrew PC keyboard layout]) diff --git a/src/font/Makefile.am b/src/font/Makefile.am index 78797897..a5925f10 100644 --- a/src/font/Makefile.am +++ b/src/font/Makefile.am @@ -2,7 +2,7 @@ SUBDIRS = in-core noinst_LTLIBRARIES = libfont.la -SRC_FILES = charset.c charset-arabic.c general-bidi.c \ +SRC_FILES = charset.c charset-arabic.c mgbidi.c \ unicode-comp.c unicode-script.c language-code.c \ sysfont.c logfont.c devfont.c fontname.c \ rawbitmap.c varbitmap.c qpf.c upf.c \ @@ -16,7 +16,7 @@ SRC_FILES = charset.c charset-arabic.c general-bidi.c \ HDR_FILES = charset.h rawbitmap.h varbitmap.h freetype2.h qpf.h se_minigui.h \ upf.h bitmapfont.h unicode-bidi-tables.h \ unicode-tables.h unicode-break-tables.h unicode-script-table.h \ - unicode-decomp.h unicode-comp.h general-bidi.h \ + unicode-decomp.h unicode-comp.h mgbidi.h \ unicode-emoji-tables.h unicode-arabic-shaping-tables.h EXTRA_DIST = convgbmap.c jisunimap.c $(SRC_FILES) $(HDR_FILES) \ diff --git a/src/font/general-bidi.c b/src/font/mgbidi.c similarity index 99% rename from src/font/general-bidi.c rename to src/font/mgbidi.c index 36cddc4b..79f88786 100644 --- a/src/font/general-bidi.c +++ b/src/font/mgbidi.c @@ -33,17 +33,17 @@ */ /* -** general-bidi.c: +** mgbidi.c: ** -** A general implementation of UNICODE BIDIRECTIONAL ALGORITHM +** A general implementation of UNICODE BIDIRECTIONAL ALGORITHM for MiniGUI ** ** https://www.unicode.org/reports/tr9/ ** ** Created by WEI Yongming at 2019/03/08 ** -** This implementation is based on LGPL'd Bidi: +** This implementation is based on LGPL'd FriBidi: ** -** https://github.com/gbidi/gbidi +** https://github.com/fribidi/fribidi ** ** Authors: ** Behdad Esfahbod, 2001, 2002, 2004 @@ -69,7 +69,7 @@ #include "devfont.h" #include "bidi.h" -#include "general-bidi.h" +#include "mgbidi.h" #ifdef DEBUG diff --git a/src/font/general-bidi.h b/src/font/mgbidi.h similarity index 95% rename from src/font/general-bidi.h rename to src/font/mgbidi.h index 0a747afa..b6225b54 100644 --- a/src/font/general-bidi.h +++ b/src/font/mgbidi.h @@ -3,7 +3,7 @@ * and Graphics User Interface (GUI) support system for embedded systems * and smart IoT devices. * - * Copyright (C) 2002~2018, Beijing FMSoft Technologies Co., Ltd. + * Copyright (C) 2002~2019, Beijing FMSoft Technologies Co., Ltd. * Copyright (C) 1998~2002, WEI Yongming * * This program is free software: you can redistribute it and/or modify @@ -33,30 +33,31 @@ */ /* -** general-bidi.h: +** mgbidi.h: ** -** A general implementation of UNICODE BIDIRECTIONAL ALGORITHM +** A general implementation of UNICODE BIDIRECTIONAL ALGORITHM for MiniGUI ** ** https://www.unicode.org/reports/tr9/ ** ** Created by WEI Yongming at 2019/03/08 ** -** This implementation is based on LGPL'd Bidi: +** This implementation is based on LGPL'd FriBidi: ** -** https://github.com/gbidi/gbidi -** -** Authors: -** Behdad Esfahbod, 2001, 2002, 2004 -** Dov Grobgeld, 1999, 2000, 2017 -** -** Copyright (C) 2004 Sharif FarsiWeb, Inc -** Copyright (C) 2001,2002 Behdad Esfahbod -** Copyright (C) 1999,2000,2017 Dov Grobgeld +** https://github.com/fribidi/fribidi */ #ifndef _MGFONT_GENERAL_BIDI_H #define _MGFONT_GENERAL_BIDI_H +#ifdef _MGCHARSET_UNICODE_FULL +#define MGBIDI_UNICODE_CHARS 0x110000 +#else +#define MGBIDI_UNICODE_CHARS 0xFFFE +#endif + +/* some general macros */ +#define STRINGIZE(symbol) #symbol + /* A few macros for working with bits */ #define BIDI_TEST_BITS(x, mask) (((x) & (mask)) ? 1 : 0) diff --git a/src/font/utils/Makefile b/src/font/utils/Makefile index 1412ef11..20a77824 100644 --- a/src/font/utils/Makefile +++ b/src/font/utils/Makefile @@ -1,28 +1,35 @@ -CC=gcc -CFLAGS=-Wall -g +CC=gcc +CFLAGS=-Wall -Werror -g -D__MINIGUI_LIB__ -I../../../include/ -all:bin2c qpf2c vbf2c upgradevbf bdf2vbf dumpupf qpf2upf upf2c +all:mkmap-ucs-gb18030 mkmap-ucs-gb2312 \ + gen-unicode-version \ + gen-bidi-type-tab \ + gen-joining-type-tab \ + gen-arabic-shaping-tab \ + gen-mirroring-tab \ + gen-brackets-tab \ + gen-brackets-type-tab -bin2c:bin2c.o +mkmap-ucs-gb2312:mkmap-ucs-gb2312.o -qpf2c:qpf2c.o +mkmap-ucs-gb18030:mkmap-ucs-gb18030.o -qpf2upf:qpf2upf.o +gen-unicode-version:gen-unicode-version.o -upf2c:upf2c.c - -vbf2c:vbf2c.o - -makegbrbf:makegbrbf.o - -makeucs2gbtable:makeucs2gbtable.o - -upgradevbf:upgradevbf.o - -bdf2vbf:bdf2vbf.c - -dumpupf: - gcc -lminigui_ths -lttf -ljpeg -lpng -lpthread -lm -lz -o dumpupf dumpupf.c +gen-bidi-type-tab:gen-bidi-type-tab.o packtab.o +gen-joining-type-tab:gen-joining-type-tab.o packtab.o +gen-arabic-shaping-tab:gen-arabic-shaping-tab.o packtab.o +gen-mirroring-tab:gen-mirroring-tab.o packtab.o +gen-brackets-tab:gen-brackets-tab.o packtab.o +gen-brackets-type-tab:gen-brackets-type-tab.o packtab.o clean: - rm -f qpf2c qpf2upf upf2c vbf2c bin2c dumpqpf dumpupf dumpqpf2 upgradevbf bdf2vbf *.o + rm -f *.o mkmap-ucs-gb2312 mkmap-gb18030-ucs.c mkmap-ucs-gb18030 \ + gen-unicode-version \ + gen-bidi-type-tab \ + gen-joining-type-tab \ + gen-arabic-shaping-tab \ + gen-mirroring-tab \ + gen-brackets-tab \ + gen-brackets-type-tab + diff --git a/src/font/utils/bdf2vbf.c b/src/font/utils/bdf2vbf.c deleted file mode 100644 index 42199e7b..00000000 --- a/src/font/utils/bdf2vbf.c +++ /dev/null @@ -1,706 +0,0 @@ -/* - * This file is part of MiniGUI, a mature cross-platform windowing - * and Graphics User Interface (GUI) support system for embedded systems - * and smart IoT devices. - * - * Copyright (C) 2002~2018, Beijing FMSoft Technologies Co., Ltd. - * Copyright (C) 1998~2002, WEI Yongming - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * Or, - * - * As this program is a library, any link to this program must follow - * GNU General Public License version 3 (GPLv3). If you cannot accept - * GPLv3, you need to be licensed from FMSoft. - * - * If you have got a commercial license of this program, please use it - * under the terms and conditions of the commercial license. - * - * For more information about the commercial license, please refer to - * . - */ -#include -#include -#include -#include -#include -#include - -#include "../varbitmap.h" - -#define VAL_DEBUG -//#define INFO_DEBUG -#include "my_debug.h" - -#define SET_WEIGHT_POS 0 -#define SET_SLANT_POS 1 -#define SET_SETWIDTH_POS 2 - -#define LINE_BUF_LEN 256 -#define INV_METRICS 0xFFFF -#define UPTO_MUTI_FOUR(i) (((i)+3)>>2<<2) -#define ARCHSWAP32_SELF(i) ((i) = ArchSwap32(i)) - - -/*get one line and*/ -static char* getline (char* buf, FILE* fp) -{ - int len; - fgets(buf, LINE_BUF_LEN, fp); - len = strlen (buf); - - if (buf[len-1] == '\n') - buf[len-1] = '\0'; - - /*void line*/ - if (!*buf) - return NULL; - - while (*buf && !isspace(*buf)) - buf++; - *buf++ = '\0'; - - while (*buf && isspace(*buf)) - buf++; - if (*buf == '\"') - { - buf++; - *(strchr(buf, '\"')) = '\0'; - } - - return (*buf) ? buf : NULL; -} - -static void set_rrncnn (char* rrncnn, int set_pos, char* value) -{ - switch (set_pos) - { - case SET_WEIGHT_POS: - if (strcasecmp(value, "black") == 0) - rrncnn[SET_WEIGHT_POS] = 'c'; - else if (strcasecmp(value, "bold") == 0) - rrncnn[SET_WEIGHT_POS] = 'b'; - else if (strcasecmp(value, "book") == 0) - rrncnn[SET_WEIGHT_POS] = 'k'; - else if (strcasecmp(value, "black") == 0) - rrncnn[SET_WEIGHT_POS] = 'c'; - else if (strcasecmp(value, "demibold") == 0) - rrncnn[SET_WEIGHT_POS] = 'd'; - else if (strcasecmp(value, "light") == 0) - rrncnn[SET_WEIGHT_POS] = 'l'; - else if (strcasecmp(value, "medium") == 0) - rrncnn[SET_WEIGHT_POS] = 'm'; - else if (strcasecmp(value, "regular") == 0) - rrncnn[SET_WEIGHT_POS] = 'r'; - break; - - case SET_SLANT_POS: - if (strcasecmp(value, "italic") == 0) - rrncnn[SET_SLANT_POS] = 'i'; - else if (strcasecmp(value, "oblique") == 0) - rrncnn[SET_SLANT_POS] = 'o'; - else if (strcasecmp(value, "roman") == 0) - rrncnn[SET_SLANT_POS] = 'r'; - break; - case SET_SETWIDTH_POS: - if (strcasecmp(value, "bold") == 0) - rrncnn[SET_SETWIDTH_POS] = 'b'; - else if (strcasecmp(value, "condensed") == 0) - rrncnn[SET_SETWIDTH_POS] = 'c'; - else if (strcasecmp(value, "semicondensed") == 0) - rrncnn[SET_SETWIDTH_POS] = 's'; - else if (strcasecmp(value, "normal") == 0) - rrncnn[SET_SETWIDTH_POS] = 'n'; - break; - } - -} - -#define FIND_LINE(line_buf, fp, header, body)\ - do \ - {\ - body = getline (line_buf, fp);\ - } while (strcmp (line_buf, header) != 0) - -static void get_propt_from_name (char* name, char* family, char* charset, int* height) -{ - int num; - TEST_VAL (name, %s); - num = sscanf (name, - "%*[-]%*[^-]" /*vender, not needed*/ - "%*[-]%[^-]" /*family*/ - "%*[-]%*[^-]" /*weight, not needed*/ - "%*[-]%*[^-]" /*slant, not needed*/ - "%*[-]%*[^-]" /*setwidth, not needed*/ - "%*[-]%d" /*height*/ - "%*[-]%*d" /*unkown*/ - "%*[-]%*d" /*unkown*/ - "%*[-]%*d" /*unkown*/ - "%*[-]%*[^-]" /*unkdown*/ - "%*[-]%*d" /*unkown*/ - "%*[-]%s",/*charset*/ - family, - height, - charset); - - TEST_VAL (family, %s); - TEST_VAL (*height, %d); - TEST_VAL (charset, %s); - -} - -static BOOL get_font_propt(FILE* fp, char* family, char* font_rrncnn, char* charset, - int* height, int* descent, int* def_glyph) -{ - char* line_buf; - char* body; - int ascent = 0; - - *height = 0; - *descent = 0; - - line_buf = (char*)malloc(LINE_BUF_LEN); - -#if 1 - FIND_LINE (line_buf, fp, "FONT", body); - get_propt_from_name (body, family, charset, height); -#endif - - FIND_LINE (line_buf, fp , "FONTBOUNDINGBOX", body); - sscanf(body, "%*d%d", height); - TEST_VAL (*height, %d); - - FIND_LINE (line_buf, fp, "STARTPROPERTIES", body); - - while (1) - { - body = getline (line_buf, fp); - TEST_VAL(line_buf, %s); - TEST_VAL(body, %s); - TEST_INFO(""); - - if (strcmp (line_buf, "ENDPROPERTIES") == 0) - break; - - /*FAMILY_NAME*/ - if (strcmp (line_buf, "FAMILY_NAME") == 0) - { - if (strlen(body) > LEN_LOGFONT_NAME_FIELD) - { - fprintf(stderr, "the FAMILY_NAME is too long, " - "please truncation it to less than %d\n", LEN_LOGFONT_NAME_FIELD-2); - return FALSE; - } - strncpy (family, body, LEN_LOGFONT_NAME_FIELD); - } - else if (strcmp (line_buf, "WEIGHT_NAME") == 0) - set_rrncnn (font_rrncnn, SET_WEIGHT_POS, body); - - /*FIXME SLANT_NAME? ? ?*/ - else if (strcmp (line_buf, "SLANT_NAME") == 0) - set_rrncnn (font_rrncnn, SET_SLANT_POS, body); - else if (strcmp (line_buf, "SETWIDTH_NAME") == 0) - set_rrncnn (font_rrncnn, SET_SETWIDTH_POS, body); - - /*FIXME must inorder*/ - else if (strcmp (line_buf, "CHARSET_REGISTRY") == 0) - strncpy (charset, body, LEN_LOGFONT_NAME_FIELD); - else if (strcmp (line_buf, "CHARSET_ENCODING") == 0) - { - if (body[0] != '-') - strcat (charset, "-"); - strcat (charset, body); - } - - else if (strcmp (line_buf, "PIXEL_SIZE") == 0) - *height = atoi (body); - else if (strcmp (line_buf, "FONT_DESCENT") == 0) - *descent = atoi (body); - else if (strcmp (line_buf, "FONT_ASCENT") == 0) - ascent = atoi (body); - - else if (strcmp (line_buf, "DEFAULT_CHAR") == 0) - { - *def_glyph = atoi (body); - TEST_VAL(*def_glyph, %d); - } - } - - /*calc descent*/ - if (*descent == 0) - { - if (ascent != 0) - *descent = *height - ascent; - else - *descent = 0; - } - else - { - /*adjust height*/ - if (ascent!=0 && height < descent + ascent) - height = descent + ascent; - } - free(line_buf); - return TRUE; -} - -static void -print_bitmap(FILE* file, char* bits, int width, int height) -{ - int y = 0; - int x = 0; - char* p_line_head; - char* p_cur_char; - int pitch = (width +7) >>3; - - for (y = 0, p_line_head = bits; y < height; y++) - { - for (x = 0; x < width; x++) - { - p_cur_char = (x >> 3) + p_line_head; - if (*p_cur_char & (128 >> (x%8))) - fprintf(file, "@ "); - else - fprintf(file, ". "); - } - fprintf(file, "\n"); - - p_line_head += pitch; - } -} - -#define HEX_CHAR_VAL(ch)\ - do {\ - if (ch & 0x40) /*'a'--'f'*/\ - ch = (ch & 0x0F) + 9;\ - else /*'0'--'9'*/\ - ch &= 0x0F;\ - }while (0) - -static int realloc_font(char** advx, char** advy, VBF_BBOX** bbox, - Uint32** offsets, int char_num) -{ - int old_len_advx = UPTO_MUTI_FOUR (char_num); - int old_len_advy = UPTO_MUTI_FOUR (char_num); - int old_len_bbox = UPTO_MUTI_FOUR (char_num * sizeof(VBF_BBOX)); - int old_len_offsets = UPTO_MUTI_FOUR (char_num * sizeof(Uint32)); - - int new_len_advx = UPTO_MUTI_FOUR (char_num<<1); - int new_len_advy = UPTO_MUTI_FOUR (char_num<<1); - int new_len_bbox = UPTO_MUTI_FOUR ((char_num<<1) * sizeof(VBF_BBOX)); - int new_len_offsets = UPTO_MUTI_FOUR ((char_num<<1) * sizeof(Uint32)); - - *advx = (char*)realloc (*advx, new_len_advx); - *advy = (char*)realloc (*advy, new_len_advy); - *bbox = (VBF_BBOX*)realloc (*bbox, new_len_bbox); - *offsets = (Uint32*) realloc (*offsets, new_len_offsets); - - memset(((char*)*advx)+old_len_advx, 0, (new_len_advx-old_len_advx)); - memset(((char*)*advy)+old_len_advy, 0, (new_len_advy-old_len_advy)); - memset(((char*)*bbox)+old_len_bbox, 0, (new_len_bbox-old_len_bbox)); - memset(((char*)*offsets)+old_len_offsets, 0, - (new_len_offsets-old_len_offsets)); - - return char_num<<1; -} - -static int get_all_glyph(FILE* fp, int glyph_num, - VBF_BBOX** bbox, char** advx, char** advy, Uint32** offsets, - char* glyph_bits, int* first_glyph, int* last_glyph, - int* max_width, int* ave_width, int* char_num) -{ - char* line_buf; - char* body; - - int bbox_x = 0; - int bbox_y = 0; - int bbox_w = 0; - int bbox_h = 0; - int total_width = 0; - - int advance_x = 0; - int advance_y = 0; - - int glyph_val = 0; - - int next_offset = 0; - int i; - - char* cp; - char ch_left; - char ch_right; - char* cur_bits = glyph_bits; - int font_size = 0; - int intend_char_num, glyph_bitmap_len, padding_len; - - *char_num = glyph_num; - intend_char_num = glyph_num; - *max_width = 0; - - line_buf = (char*)malloc (LINE_BUF_LEN); - - for (i=0; i *last_glyph) - *last_glyph = glyph_val; - - if (glyph_val - *first_glyph + 1 >= *char_num) - { - *char_num = glyph_val - *first_glyph + 1; - if (*char_num >= intend_char_num) - intend_char_num = realloc_font(advx, advy, - bbox, offsets, intend_char_num); - } - - (*offsets)[glyph_val-*first_glyph] = next_offset; - } - - if (strcmp (line_buf, "DWIDTH") == 0) - { - sscanf (body, "%d %d", &advance_x, &advance_y); - *max_width = (advance_x > *max_width)? - advance_x : *max_width; - total_width += advance_x; - (*advx)[glyph_val-*first_glyph] = advance_x; - (*advy)[glyph_val-*first_glyph] = advance_y; - } - - else if (strcmp (line_buf, "BBX") == 0) - { - sscanf (body, "%d %d %d %d", &bbox_w, &bbox_h, - &bbox_x, &bbox_y); - bbox_y += bbox_h; - (*bbox)[glyph_val-*first_glyph].x = bbox_x; - (*bbox)[glyph_val-*first_glyph].y = bbox_y; - (*bbox)[glyph_val-*first_glyph].w = bbox_w; - (*bbox)[glyph_val-*first_glyph].h = bbox_h; - } - - if (strcmp (line_buf, "BITMAP") == 0) - { - glyph_bitmap_len =0; - while (1) - { - getline (line_buf, fp); - if (strcmp (line_buf, "ENDCHAR") == 0) - goto end_one_glyph; - - cp = line_buf; - TEST_VAL(cp, %s); - - ch_left = *cp++; - ch_right = *cp++; - - while(ch_left) - { - HEX_CHAR_VAL(ch_left); - HEX_CHAR_VAL(ch_right); - ch_right |= ch_left << 4; - - *cur_bits++ = ch_right; - font_size ++; - - ch_left = *cp++; - ch_right = *cp++; - } - next_offset += (cp - line_buf - 2) >> 1; - glyph_bitmap_len += (cp - line_buf - 2) >> 1; - } - } - } -end_one_glyph: - padding_len = (glyph_bitmap_len %4 ? (4 - (glyph_bitmap_len % 4)) : 0); - next_offset += padding_len; - while(padding_len){ - *cur_bits++ = 0x00; - padding_len --; - } - TEST_INFO(""); - TEST_VAL (bbox_w, %d); - TEST_VAL (bbox_h, %d); - TEST_VAL (next_offset, %d); - fprintf(stderr, "glyph_val = 0x%x\n", glyph_val); - print_bitmap(stderr, glyph_bits+(*offsets)[glyph_val-*first_glyph], bbox_w, bbox_h); - fprintf(stderr, "\n"); - } - - *ave_width = total_width / glyph_num; - free (line_buf); - return font_size; -} - -typedef struct _FILE_HEADER { - char ver_info [LEN_VERSION_INFO]; - char vender_name [LEN_VENDER_INFO]; - - Uint16 len_header; - - Uint32 off_bboxs; - Uint32 len_bboxs; - - Uint32 off_advxs; - Uint32 len_advxs; - - Uint32 off_advys; - Uint32 len_advys; - - Uint32 off_bit_offs; - Uint32 len_bit_offs; - - Uint32 off_bits; - Uint32 len_bits; - - Uint32 font_size; - int align[0]; -} FILE_HEADER; - -typedef struct _FONT_PROPT { - char font_name [LEN_DEVFONT_NAME + 1]; - - char max_width; - char ave_width; - char height; - char descent; - - int first_glyph; - int last_glyph; - int def_glyph; - - int align[0]; -} FONT_PROPT; - -char font_name [LEN_UNIDEVFONT_NAME]; -char family [LEN_LOGFONT_NAME_FIELD]; -char charset [LEN_LOGFONT_NAME_FIELD]; -char new_file_name [LEN_UNIDEVFONT_NAME+5]; - -#define MAKE_HEADER(header, glyph_num)\ - do {\ - header.len_header = sizeof(FILE_HEADER);\ - header.len_advxs = UPTO_MUTI_FOUR (glyph_num);\ - header.len_advys = header.len_advxs;\ - header.len_bboxs = UPTO_MUTI_FOUR (glyph_num * sizeof(VBF_BBOX));\ - header.len_bit_offs = UPTO_MUTI_FOUR (glyph_num * sizeof(Uint32));\ - }while (0) - -int bdf2vbf(char* file_name) -{ - char font_rrncnn [7] = "rrncnn"; - - char* advx; - char* advy; - VBF_BBOX* bbox; - Uint32* offsets; - char* glyph_bits; - - int max_width; - int ave_width; - - int height; - int descent; - - int first_glyph = 0x7FFFFFFF; - int last_glyph = -1; - int def_glyph = 0; - int glyph_num; - - char* line_buf; - char* body; - FILE* fp; - int file_size; - int char_num; - int i; - - FILE_HEADER header; - FONT_PROPT font_propt; - - fp = fopen (file_name, "rb"); - - fseek(fp, 0, SEEK_END); - file_size = ftell (fp); - fseek(fp, 0, SEEK_SET); - - if (!fp) - { - fprintf(stderr, "open bdf file error\n"); - return -1; - } - - line_buf = (char*)malloc(LINE_BUF_LEN); - if (!get_font_propt(fp, family, font_rrncnn, charset, - &height, &descent, &def_glyph)) - return -1; - - if (height > 128) - { - fprintf(stderr, "error: %s is too big %d,\n vbf height is less than 128\n", file_name, height); - return -1; - } - - FIND_LINE (line_buf, fp, "CHARS", body); - glyph_num = atoi (body); - font_rrncnn[6] = '\0'; - - TEST_VAL (family, %s); - TEST_VAL (font_rrncnn, %s); - TEST_VAL (charset, %s); - - TEST_VAL (height, %d); - TEST_VAL (descent, %d); - - TEST_VAL (glyph_num, %d); - - strcpy (header.ver_info, "vbf-3.0**"); - strcpy (header.vender_name, "FMSoft"); - - MAKE_HEADER (header, glyph_num); - - advx = (char*)malloc (header.len_advxs); - advy = (char*)malloc (header.len_advys); - bbox = (VBF_BBOX*)malloc (header.len_bboxs); - offsets = (Uint32*) malloc (header.len_bit_offs); - - memset (advx, 0, header.len_advxs); - memset (advy, 0, header.len_advys); - memset (bbox, 0, header.len_bboxs); - memset (offsets, 0, header.len_bit_offs); - - /*size of bdf is larger than sizeof glyph_bits*/ - glyph_bits = (char*) malloc (file_size); - - header.len_bits = get_all_glyph(fp, glyph_num, &bbox, &advx, &advy, &offsets, - glyph_bits, &first_glyph, &last_glyph, - &max_width, &ave_width, &char_num); - - for (i=0; i. - * - * Or, - * - * As this program is a library, any link to this program must follow - * GNU General Public License version 3 (GPLv3). If you cannot accept - * GPLv3, you need to be licensed from FMSoft. - * - * If you have got a commercial license of this program, please use it - * under the terms and conditions of the commercial license. - * - * For more information about the commercial license, please refer to - * . - */ -/* -** $Id: dumpqpf.c 8944 2007-12-29 08:29:16Z xwyan $ -** -** vi: tabstop=4:expandtab -** -** dumpqpf.c: Dump in-core QPF font. -** -** Create date: 2005/07/19 -*/ - -/* -** This program is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation; either version 2 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software -** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -/* -** TODO: -*/ - -#include -#include -#include - -#include -#include -#include -#include -#include - -#define FM_SMOOTH 1 - -#define BOOL int -#define TRUE 1 -#define FALSE 0 - -typedef unsigned char uchar; -typedef unsigned char Uint8; -typedef char Sint8; - -typedef struct __attribute__ ((packed)) _GLYPHMETRICS { - Uint8 linestep; - Uint8 width; - Uint8 height; - Uint8 padding; - - Sint8 bearingx; /* Difference from pen position to glyph's left bbox */ - Uint8 advance; /* Difference between pen positions */ - Sint8 bearingy; /* Used for putting characters on baseline */ - - Sint8 reserved; /* Do not use */ -} GLYPHMETRICS; - -typedef struct _GLYPH -{ - GLYPHMETRICS* metrics; - unsigned char* data; -} GLYPH; - -typedef struct _GLYPHTREE -{ - unsigned int min, max; - struct _GLYPHTREE* less; - struct _GLYPHTREE* more; - GLYPH* glyph; - - unsigned int idx_node; -} GLYPHTREE; - -typedef struct __attribute__ ((packed)) _QPFMETRICS -{ - Sint8 ascent, descent; - Sint8 leftbearing, rightbearing; - Uint8 maxwidth; - Sint8 leading; - Uint8 flags; - Uint8 underlinepos; - Uint8 underlinewidth; - Uint8 reserved3; -} QPFMETRICS; - -typedef struct -{ - char* font_name; - unsigned int height; - unsigned int width; - - unsigned int file_size; - QPFMETRICS* fm; - - GLYPHTREE* tree; - - int max_bmp_size; - unsigned char* std_bmp; -} QPFINFO; - -#define HAVE_MMAP 1 - -/********************** Load/Unload of QPF font ***********************/ - -static void readNode (GLYPHTREE* tree, uchar** data) -{ - uchar rw, cl; - int flags, n; - - rw = **data; (*data)++; - cl = **data; (*data)++; - tree->min = (rw << 8) | cl; - - rw = **data; (*data)++; - cl = **data; (*data)++; - tree->max = (rw << 8) | cl; - - flags = **data; (*data)++; - if (flags & 1) - tree->less = calloc (1, sizeof (GLYPHTREE)); - else - tree->less = NULL; - - if (flags & 2) - tree->more = calloc (1, sizeof (GLYPHTREE)); - else - tree->more = NULL; - - n = tree->max - tree->min + 1; - tree->glyph = calloc (n, sizeof (GLYPH)); - - if (tree->less) - readNode (tree->less, data); - if (tree->more) - readNode (tree->more, data); -} - -static void readMetrics (GLYPHTREE* tree, uchar** data) -{ - int i; - int n = tree->max - tree->min + 1; - - for (i = 0; i < n; i++) { - tree->glyph[i].metrics = (GLYPHMETRICS*) *data; - - *data += sizeof (GLYPHMETRICS); - } - - if (tree->less) - readMetrics (tree->less, data); - if (tree->more) - readMetrics (tree->more, data); -} - -static void readData (GLYPHTREE* tree, uchar** data) -{ - int i; - int n = tree->max - tree->min + 1; - - for (i = 0; i < n; i++) { - int datasize; - - datasize = tree->glyph[i].metrics->linestep * tree->glyph[i].metrics->height; - tree->glyph[i].data = *data; *data += datasize; - } - - if (tree->less) - readData (tree->less, data); - if (tree->more) - readData (tree->more, data); -} - -static void BuildGlyphTree (GLYPHTREE* tree, uchar** data) -{ - readNode (tree, data); - readMetrics (tree, data); - readData (tree, data); -} - -BOOL LoadQPFont (const char* file, QPFINFO* QPFInfo) -{ - int fd; - struct stat st; - uchar* data; - - if ((fd = open (file, O_RDONLY)) < 0) return FALSE; - if (fstat (fd, &st)) return FALSE; - QPFInfo->file_size = st.st_size; - -#ifdef HAVE_MMAP - - QPFInfo->fm = (QPFMETRICS*) mmap( 0, st.st_size, - PROT_READ, MAP_PRIVATE, fd, 0 ); - - if (!QPFInfo->fm || QPFInfo->fm == (QPFMETRICS *)MAP_FAILED) - goto error; - -#else - - QPFInfo->fm = calloc (1, st.st_size); - if (QPFInfo->fm == NULL) - goto error; - - read (fd, QPFInfo->fm, st.st_size); - -#endif - - QPFInfo->tree = calloc (1, sizeof (GLYPHTREE)); - - data = (uchar*)QPFInfo->fm; - data += sizeof (QPFMETRICS); - BuildGlyphTree (QPFInfo->tree, &data); - - close (fd); - return TRUE; - -error: - close (fd); - return FALSE; -} - -static void ClearGlyphTree (GLYPHTREE* tree) -{ - if (tree->less) { - ClearGlyphTree (tree->less); - } - if (tree->more) { - ClearGlyphTree (tree->more); - } - - free (tree->glyph); - free (tree->less); - free (tree->more); -} - -void UnloadQPFont (QPFINFO* QPFInfo) -{ - if (QPFInfo->file_size == 0) - return; - - ClearGlyphTree (QPFInfo->tree); - free (QPFInfo->tree); -#if 0 - free (QPFInfo->std_bmp); -#endif - -#ifdef HAVE_MMAP - munmap (QPFInfo->fm, QPFInfo->file_size); -#else - free (QPFInfo->fm); -#endif -} - -unsigned int idx_node = 0; - -static void make_incore_glyph_tree (GLYPHTREE* tree) -{ - int i, j, n; - int datasize, dataoffset; - - if (tree->less) { - make_incore_glyph_tree (tree->less); - } - if (tree->more) { - make_incore_glyph_tree (tree->more); - } - - n = tree->max - tree->min + 1; - - printf ("static GLYPHMETRICS glyph_metrics_%d [] = {\n", idx_node); - for (i = 0; i < n; i++) { - //printf ("\t{0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x}, \n", - printf ("\t{%d, %d, %d, %d, %d, %d, %d, %d}, \n", - tree->glyph[i].metrics->linestep, - tree->glyph[i].metrics->width, - tree->glyph[i].metrics->height, - tree->glyph[i].metrics->padding, - tree->glyph[i].metrics->bearingx, - tree->glyph[i].metrics->advance, - tree->glyph[i].metrics->bearingy, - tree->glyph[i].metrics->reserved); - } - printf ("};\n\n"); - - printf ("static unsigned char glyph_data_%d [] = {", idx_node); - for (i = 0; i < n; i++) { - - datasize = tree->glyph[i].metrics->linestep * tree->glyph[i].metrics->height; - for (j = 0; j < datasize; j++) { - if (j % 8 == 0) - printf ("\n\t"); - printf ("0x%02x, ", tree->glyph[i].data [j]); - } - - } - printf ("\n};\n\n"); - - dataoffset = 0; - printf ("static GLYPH glyph_%d [] = {\n", idx_node); - for (i = 0; i < n; i++) { - printf ("\t{glyph_metrics_%d + %d, glyph_data_%d + %d}, \n", idx_node, i, idx_node, dataoffset); - dataoffset += tree->glyph[i].metrics->linestep * tree->glyph[i].metrics->height; - } - printf ("};\n\n"); - - printf ("static GLYPHTREE glyph_tree_%d = {\n", idx_node); - printf ("\t0x%04x, 0x%04x, ", tree->min, tree->max); - if (tree->less) - printf ("&glyph_tree_%d, ", tree->less->idx_node); - else - printf ("NULL, "); - if (tree->more) - printf ("&glyph_tree_%d, ", tree->more->idx_node); - else - printf ("NULL, "); - - printf ("glyph_%d\n", idx_node); - printf ("};\n\n"); - - tree->idx_node = idx_node; - idx_node ++; -} - -static int dump_qpf (const char* name, const QPFINFO* QPFInfo, const char* font_name) -{ - printf ("/*\n"); - printf ("** This file is created by 'dumpqpf' by FMSoft (http://www.fmsoft.cn).\n"); - printf ("** Please do not modify it manually.\n"); - printf ("*/\n"); - - printf ("#include \n"); - printf ("#include \n"); - printf ("\n"); - printf ("#include \"common.h\"\n"); - printf ("#include \"minigui.h\"\n"); - printf ("#include \"gdi.h\"\n"); - printf ("\n"); - printf ("#ifdef _MGFONT_QPF\n"); - printf ("#ifdef _MGINCORE_RES\n"); - printf ("\n"); - printf ("#include \"qpf.h\"\n"); - printf ("\n"); - - make_incore_glyph_tree (QPFInfo->tree); - - printf ("static QPFMETRICS fm = {\n"); - printf ("\t%d, %d, %d, %d, %d, %d, %d, %d, %d, %d\n", - QPFInfo->fm->ascent, - QPFInfo->fm->descent, - QPFInfo->fm->leftbearing, - QPFInfo->fm->rightbearing, - QPFInfo->fm->maxwidth, - QPFInfo->fm->leading, - QPFInfo->fm->flags, - QPFInfo->fm->underlinepos, - QPFInfo->fm->underlinewidth, - QPFInfo->fm->reserved3); - - printf ("};\n\n"); - - printf ("QPFINFO %s = {\n", name); - printf ("\t\"%s\", \n", font_name); - printf ("\t0, 0, 0, &fm, \n"); - printf ("\t&glyph_tree_%d, \n", idx_node - 1); - printf ("};\n\n"); - - printf ("#endif /* _MGINCORE_RES */\n"); - printf ("#endif /* _MGFONT_QPF */\n"); - return 0; -} - -int main (int argc, char **argv) -{ - char name [256]; - QPFINFO QPFInfo; - - if (argc < 4) { - fprintf (stderr, "Usage: dumpqpf \n"); - return 1; - } - - if (!LoadQPFont (argv[1], &QPFInfo)) { - fprintf (stderr, "dumpqpf: can't load QPF file: %s\n", argv[2]); - return 3; - } - - strcpy (name, "__mgif_qpf_"); - strcat (name, argv[2]); - - dump_qpf (name, &QPFInfo, argv[3]); - - UnloadQPFont (&QPFInfo); - - return 0; -} - diff --git a/src/font/utils/dumpupf.c b/src/font/utils/dumpupf.c deleted file mode 100644 index 470bdfce..00000000 --- a/src/font/utils/dumpupf.c +++ /dev/null @@ -1,317 +0,0 @@ -/* - * This file is part of MiniGUI, a mature cross-platform windowing - * and Graphics User Interface (GUI) support system for embedded systems - * and smart IoT devices. - * - * Copyright (C) 2002~2018, Beijing FMSoft Technologies Co., Ltd. - * Copyright (C) 1998~2002, WEI Yongming - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * Or, - * - * As this program is a library, any link to this program must follow - * GNU General Public License version 3 (GPLv3). If you cannot accept - * GPLv3, you need to be licensed from FMSoft. - * - * If you have got a commercial license of this program, please use it - * under the terms and conditions of the commercial license. - * - * For more information about the commercial license, please refer to - * . - */ - -#include -#include -#include - -#include -#include -#include -#include - -#include "../../include/devfont.h" - -#define PATH_LEN 128 - -static LOGFONT *_logfont; - -#ifdef _DEF_DYNAMIC_LOAD_DEVFONT_ -static DEVFONT *_devfont; -#endif - -const char * _usage = - "\n" - "Usage: dumpupf " - " [big_unicode]\n" - " Dump font data between small unicode and big unicode.\n" - " The font data list below.\n" - " ---font property \n" - " ave width \n" - " max width \n" - " font heigh \n" - " font size \n" - " font ascent \n" - " font descent \n" - " ---glyph property \n" - " glyph exist \n" - " glyph bbox \n" - " glyph advance \n" - " glyph monobitmap \n" - " glyph greybitmap \n" - "\n" - "Example: \n" - " $ ./dumpupf qpf-unifont-rrncnn-16-16-ISO8859-1 unifont_160_50.qpf 0 1618\n" - " $ ./dumpupf qpf-micro-rrncnn-4-4-ISO8859-1 micro_40_50.qpf 100 > tmp\n\n"; - -void dumpupf (DEVFONT * devfont, int glyph) -{ - int index; - int bbox_x, bbox_y, bbox_w, bbox_h; - int advance_x, advance_y; - unsigned short scale; - unsigned short scale_greybmp, scale_monobmp; - int pitch; - unsigned char * monobitmap; - unsigned char * bmp_grey; - unsigned char * bmp_mono; - BITMAP bmp_glyph = {0}; - - printf ("------------- glyph : %i ------------- \n", glyph); - - if (devfont->font_ops->is_glyph_existed(_logfont, devfont, glyph)) - { - printf ("glyph exist = TRUE\n"); - } - else - { - printf ("glyph exist = FALSE\n"); - } - - if (devfont->font_ops->get_glyph_bbox) - { - devfont->font_ops->get_glyph_bbox - (_logfont, devfont, glyph, &bbox_x, &bbox_y, &bbox_w, &bbox_h); - printf ("glyph bbox = (%i, %i, %i , %i)\n", - bbox_x, bbox_y, bbox_w, bbox_h); - } - else - { - printf ("glyph bbox = NULL function\n"); - } - - if (devfont->font_ops->get_glyph_advance) - { - - devfont->font_ops->get_glyph_advance - (_logfont, devfont, glyph, &advance_x, &advance_y); - - printf ("glyph advance = (%i, %i)\n", - advance_x, advance_y); - } - else - { - printf ("glyph advance = NULL function\n"); - } - - if (devfont->font_ops->get_glyph_monobitmap) - { - bmp_grey = (unsigned char *)devfont->font_ops->get_glyph_monobitmap - (_logfont, devfont, glyph, &scale_greybmp); - - printf ("glyph monobitmap = (scale=%i; ", scale_greybmp); - if (!bmp_grey) - { - printf ("bmp = NULL)\n"); - } - else - { - printf ("bmp = {"); - - printf ("0x%x", bmp_grey [0]); - - for (index = 1; - index < sizeof (bmp_grey) / sizeof (unsigned char); - ++index) - { - printf (", 0x%x", bmp_grey [index]); - } - - printf ("} )\n"); - } - - } - else - { - printf ("glyph monobitmap = NULL function\n"); - } - - if (devfont->font_ops->get_glyph_greybitmap) - { - bmp_mono = (unsigned char *)devfont->font_ops->get_glyph_greybitmap - (_logfont, devfont, glyph, &pitch, &scale_monobmp); - - printf ("glyph greybitmap = (scale=%i, pitch=%i, ", - scale_monobmp, pitch); - - if (!bmp_mono) - { - printf ("bmp=NULL)\n"); - } - else - { - printf ("glyph greybitmap = (bmp = {"); - - printf ("0x%x", bmp_mono [0]); - - for (index = 1; - index < sizeof (bmp_mono) / sizeof (unsigned char) - 1; - ++index) - { - printf (", 0x%x", bmp_mono [index]); - } - - printf ("} )\n"); - } - } - else - { - printf ("glyph greybitmap = NULL function\n"); - } - -} - -void dump_common_data (DEVFONT * devfont) -{ - int ave_width; - int max_width; - int font_height; - int font_size; - int font_ascent; - int font_descent; - - ave_width = devfont->font_ops->get_ave_width(_logfont, devfont); - max_width = devfont->font_ops->get_max_width(_logfont, devfont); - font_height = devfont->font_ops->get_font_height(_logfont, devfont); - font_size = devfont->font_ops->get_font_size(_logfont, devfont, 1); - font_ascent = devfont->font_ops->get_font_ascent(_logfont, devfont); - font_descent = devfont->font_ops->get_font_descent(_logfont, devfont); - - printf ( - "\n font name : [%s] \n \n" - "======================================\n", - devfont->name); - - printf ( - "ave_width = %i\n" - "max_width = %i\n" - "font_height = %i\n" - "font_size = %i\n" - "font_ascent = %i\n" - "font_descent = %i\n" - "======================================\n", - ave_width, max_width, font_height, - font_size, font_ascent, font_descent); -} - -int MiniGUIMain (int argc, const char* argv[]) -{ -#ifdef _MGRM_PROCESSES - JoinLayer(NAME_DEF_LAYER , "dumpupf", 0, 0); -#endif - - int i; - int unicode_value_min; - int unicode_value_max; - - char font_file[PATH_LEN] = {0}; - - DEVFONT *mydevfont; - - if (argc != 4 && argc != 5) - { - printf (_usage); - exit (0); - } - - /** get unicode value */ - unicode_value_min = atoi (argv[3]); - if (argc == 5) - { - unicode_value_max = atoi (argv[4]); - if (unicode_value_max < unicode_value_min) - { - printf ( _usage); - exit (0); - } - } - else - { - unicode_value_max = unicode_value_min; - } - - /** get font file name */ - strcpy (font_file, "/usr/local/lib/minigui/res/font/"); - strcat (font_file, argv[2]); - font_file[PATH_LEN] = '\0'; - -#ifdef _DEF_DYNAMIC_LOAD_DEVFONT_ - _devfont == LoadDevFontFromFile (argv[1], font_file); - if (!_devfont) - { - printf ("ERROR: LoadDevFontFromFile fail. \n"); - exit (0); - } -#endif - - /** create logfont according device font name */ - _logfont = CreateLogFontByName (argv[1]); - if (!_logfont) - { - printf ("ERROR: CreateLogFontByName fail. \n"); - exit (0); - } - -#ifdef _DEBUG - dbg_dumpDevFonts(); -#endif - - if (_logfont->sbc_devfont) - mydevfont = _logfont->sbc_devfont; - else - mydevfont = _logfont->mbc_devfont; - - if (!mydevfont) - { - printf ("ERROR: Invalid LogFont.\n"); - exit (0); - } - - dump_common_data (mydevfont); - - for (i = unicode_value_min; i <= unicode_value_max; ++i) - { - dumpupf(mydevfont, i); - } - -#ifdef _DEF_DYNAMIC_LOAD_DEVFONT_ - DestroyDynamicDevFont (_devfont); -#endif - - exit (0); -} - -#ifdef _MGRM_THREADS -#include -#endif diff --git a/src/font/utils/dumpvbf.c b/src/font/utils/dumpvbf.c deleted file mode 100644 index b35cd6c2..00000000 --- a/src/font/utils/dumpvbf.c +++ /dev/null @@ -1,120 +0,0 @@ -/* - * This file is part of MiniGUI, a mature cross-platform windowing - * and Graphics User Interface (GUI) support system for embedded systems - * and smart IoT devices. - * - * Copyright (C) 2002~2018, Beijing FMSoft Technologies Co., Ltd. - * Copyright (C) 1998~2002, WEI Yongming - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * Or, - * - * As this program is a library, any link to this program must follow - * GNU General Public License version 3 (GPLv3). If you cannot accept - * GPLv3, you need to be licensed from FMSoft. - * - * If you have got a commercial license of this program, please use it - * under the terms and conditions of the commercial license. - * - * For more information about the commercial license, please refer to - * . - */ -/* - * Usage: - * 1) Define your VBFINFO name as extern_vbfinfo in a C file. - * 2) Please link this file with the C file defining your VBF file to compile an executable. - * 3) Run the executable. - * - * Limitation: - * Only VBF V1.0 is supported. - */ - -#include -#include - -#include "vbf.h" - -#define LEN_VERSION_INFO 10 - -#define VBF_VERSION "vbf-1.0**" - -typedef int BOOL; -#define TRUE 1 -#define FALSE 0 - -#define LEN_LOGFONT_NAME_FIELD 23 -#define LEN_DEVFONT_NAME 79 - -extern VBFINFO extern_vbfinfo; - -#define vbf_to_dump extern_vbfinfo - -BOOL dumpVBF (VBFINFO* vbf, char* file) -{ - FILE* fp; - char family [LEN_LOGFONT_NAME_FIELD + 1]; - char style [LEN_LOGFONT_NAME_FIELD + 1]; - int len_offsets; - int len_widths; - int len_header; - int len_bits = vbf->len_bits; - int len_file; - int num_chars = (vbf->last_char - vbf->first_char + 1); - - len_header = 4 + 2 + 8 + 3 + 12 + 4 + LEN_VERSION_INFO; - len_offsets = num_chars * sizeof (unsigned short); - len_widths = num_chars * sizeof (unsigned char); - - len_file = len_header + LEN_DEVFONT_NAME + 1 + len_offsets + len_widths + len_bits; - sprintf (file, "%s.vbf", vbf->name); - - if ((fp = fopen (file, "w+")) == NULL) - return FALSE; - - fwrite (VBF_VERSION, sizeof (char), LEN_VERSION_INFO, fp); - fwrite (&len_header, sizeof (int), 1, fp); - fwrite (&vbf->max_width, sizeof (char), 1, fp); - fwrite (&vbf->ave_width, sizeof (char), 1, fp); - fwrite (&vbf->height, sizeof (int), 1, fp); - fwrite (&vbf->descent, sizeof (int), 1, fp); - fwrite (&vbf->first_char, sizeof (unsigned char), 1, fp); - fwrite (&vbf->last_char, sizeof (unsigned char), 1, fp); - fwrite (&vbf->def_char, sizeof (unsigned char), 1, fp); - - fwrite (&len_offsets, sizeof (int), 1, fp); - fwrite (&len_widths, sizeof (int), 1, fp); - fwrite (&len_bits, sizeof (int), 1, fp); - fwrite (&len_file, sizeof (int), 1, fp); - - fwrite (vbf->name, sizeof (char), LEN_DEVFONT_NAME + 1, fp); - fwrite (vbf->offset, sizeof (unsigned short), num_chars, fp); - fwrite (vbf->width, sizeof (unsigned char), num_chars, fp); - - fwrite (vbf->bits, sizeof (unsigned char), len_bits, fp); - - fclose (fp); - return TRUE; -} - -int main (void) -{ - char file [256]; - - dumpVBF (&vbf_to_dump, file); - printf ("The vbf font name: '%s'\n", vbf_to_dump.name); - printf ("The VBF dump to file: '%s'\n", file); - return 0; -} - diff --git a/src/font/utils/fetch-ucd.sh b/src/font/utils/fetch-ucd.sh index 0b436b41..89cb8774 100755 --- a/src/font/utils/fetch-ucd.sh +++ b/src/font/utils/fetch-ucd.sh @@ -1,7 +1,7 @@ #!/bin/bash url='https://www.unicode.org/Public/12.0.0/ucd/' -files='Scripts.txt UnicodeData.txt LineBreak.txt SpecialCasing.txt CaseFolding.txt CompositionExclusions.txt IndicPositionalCategory.txt IndicSyllabicCategory.txt ArabicShaping.txt BidiBrackets.txt BidiMirroring.txt Blocks.txt extracted/DerivedEastAsianWidth.txt extracted/DerivedBidiClass.txt' +files='ReadMe.txt Scripts.txt UnicodeData.txt LineBreak.txt SpecialCasing.txt CaseFolding.txt CompositionExclusions.txt IndicPositionalCategory.txt IndicSyllabicCategory.txt ArabicShaping.txt BidiBrackets.txt BidiMirroring.txt Blocks.txt extracted/DerivedEastAsianWidth.txt extracted/DerivedBidiClass.txt' if test ! -d ucd/extracted; then mkdir -p ucd/extracted diff --git a/src/font/utils/gen-arabic-shaping-tab.c b/src/font/utils/gen-arabic-shaping-tab.c new file mode 100644 index 00000000..78d8b4b6 --- /dev/null +++ b/src/font/utils/gen-arabic-shaping-tab.c @@ -0,0 +1,291 @@ +/* MGBidi + * gen-arabic-shaping-tab.c - generate mgbidi-arabic-shaping-table.h + * + * Revised from FriBidi by Vincent Wei for MiniGUI 3.4.0 + * + * Authors of FriBidi: + * Behdad Esfahbod, 2004, 2005 + * + * Copyright (C) 2004 Sharif FarsiWeb, Inc + * Copyright (C) 2004, 2005 Behdad Esfahbod + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library, in a file named COPYING; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + * + * For licensing issues, contact . + */ + +#include +#include +#include + +#include "common.h" +#include "minigui.h" +#include "gdi.h" + +#include "packtab.h" + +#include "../mgbidi.h" +#include "mgbidi-unicode-version.h" + +#define appname "gen-arabic-shaping-tab" +#define outputname "mgbidi-arabic-shaping-table.h" + +static void +die ( + const char *msg +) +{ + fprintf (stderr, appname ": %s\n", msg); + exit (1); +} + +static void +die2 ( + const char *fmt, + const char *p +) +{ + fprintf (stderr, appname ": "); + fprintf (stderr, fmt, p); + fprintf (stderr, "\n"); + exit (1); +} + +static void +die3 ( + const char *fmt, + const char *p, + const char *q +) +{ + fprintf (stderr, appname ": "); + fprintf (stderr, fmt, p, q); + fprintf (stderr, "\n"); + exit (1); +} + +static void +die3l ( + const char *fmt, + unsigned long l, + const char *p +) +{ + fprintf (stderr, appname ": "); + fprintf (stderr, fmt, l, p); + fprintf (stderr, "\n"); + exit (1); +} + +static const char *arabic_shaping_tags[] = { + "isolated", + "final", + "initial", + "medial", + NULL +}; + +static int +shape_is ( + const char *s, + const char *type_list[] +) +{ + const char **p = type_list; + for (; *p; p++) + if (!strcmp (s, p[0])) + return p - type_list; + return -1; +} + +#define table_name "ArShap" +#define macro_name "MGBIDI_GET_ARABIC_SHAPE_PRES" + +#define START_CHAR 0x600 +#define END_CHAR 0x700 + +static Uchar32 table[MGBIDI_UNICODE_CHARS][4]; +static char buf[4000]; +static char tag[sizeof (buf)], buf2[sizeof (buf)]; +static Uchar32 minshaped, maxshaped; + +static void +clear_tab ( + void +) +{ + register Uchar32 c; + register int shape; + + for (c = 0; c < MGBIDI_UNICODE_CHARS; c++) + for (shape = 0; shape < 4; shape++) + table[c][shape] = c; +} + +static void +init ( + void +) +{ + minshaped = MGBIDI_UNICODE_CHARS; + maxshaped = 0; + + clear_tab (); +} + +static void +read_unicode_data_txt ( + FILE *f +) +{ + unsigned long c, unshaped, l; + + l = 0; + while (fgets (buf, sizeof buf, f)) + { + int i, shape; + const char *s = buf; + + l++; + + while (*s == ' ') + s++; + + if (*s == '#' || *s == '\0' || *s == '\n') + continue; + + i = sscanf (s, "%lx;%*[^;];%*[^;];%*[^;];%*[^;];<%[^;> ]> %lx %[^; ]", &c, tag, &unshaped, buf2); + + if (i != 3) + continue; + + if (i != 3 || c >= MGBIDI_UNICODE_CHARS || unshaped >= MGBIDI_UNICODE_CHARS) + die3l ("UnicodeData.txt: invalid input at line %ld: %s", l, s); + + shape = shape_is (tag, arabic_shaping_tags); + if (shape >= 0) + { + table[unshaped][shape] = c; + if (unshaped < minshaped) + minshaped = unshaped; + if (unshaped > maxshaped) + maxshaped = unshaped; + } + } +} + +static void +read_data ( + const char *data_file_type[], + const char *data_file_name[] +) +{ + FILE *f; + + for (; data_file_name[0] && data_file_type[0]; + data_file_name++, data_file_type++) + { + if (!(f = fopen (data_file_name[0], "rt"))) + die2 ("error: cannot open `%s' for reading", data_file_name[0]); + + if (!strcmp (data_file_type[0], "UnicodeData.txt")) + read_unicode_data_txt (f); + else + die2 ("error: unknown data-file type %s", data_file_type[0]); + + fclose (f); + } + +} + +static void +gen_arabic_shaping_tab ( + int max_depth /* currently unused */, + const char *data_file_type[] +) +{ + register Uchar32 c; + register int shape; + + if (maxshaped < minshaped) + die ("error: no shaping pair found, something wrong with reading input"); + + printf ("/* " outputname "\n * generated by " appname "\n" + " * from the files %s, %s of Unicode version " + MGBIDI_UNICODE_VERSION ". */\n\n", data_file_type[0], + data_file_type[1]); + + printf ("/*\n" + " use %s(key,shape) to access your table\n\n" + " required memory: %ld\n" + " */\n\n", + macro_name, (long)(maxshaped - minshaped + 1) * 4 * sizeof (Uchar32)); + + printf ("\n" "/* *IND" "ENT-OFF* */\n\n"); + + printf ("static const Uchar32 %s[%d][%d] = {\n", table_name, maxshaped - minshaped + 1, 4); + for (c = minshaped; c <= maxshaped; c++) + { + printf (" {"); + for (shape = 0; shape < 4; shape++) + printf ("0x%04lx,", (unsigned long)table[c][shape]); + printf ("},\n"); + } + + + printf ("};\n\n"); + + printf ("/* *IND" "ENT-ON* */\n\n"); + + printf ("#ifndef MGBIDI_ACCESS_SHAPE_TABLE\n" + "# define MGBIDI_ACCESS_SHAPE_TABLE(table,min,max,x,shape) \\\n" + " (((x)<(min)||(x)>(max))?(x):(table)[(x)-(min)][(shape)])\n" + "#endif\n\n"); + printf ("#define %s(x,shape) " + "MGBIDI_ACCESS_SHAPE_TABLE(%s, 0x%04lx, 0x%04lx, (x), (shape))\n\n", + macro_name, table_name, (unsigned long)minshaped, (unsigned long)maxshaped); + + printf ("/* End of generated " outputname " */\n"); +} + +int +main ( + int argc, + const char **argv +) +{ + const char *data_file_type[] = + { "UnicodeData.txt", NULL }; + + if (argc < 3) + die3 ("usage:\n " appname " max-depth /path/to/%s /path/to/%s [junk...]", + data_file_type[0], data_file_type[1]); + + { + int max_depth = atoi (argv[1]); + const char *data_file_name[] = { NULL, NULL }; + data_file_name[0] = argv[2]; + + if (max_depth < 2) + die ("invalid depth"); + + init (); + read_data (data_file_type, data_file_name); + gen_arabic_shaping_tab (max_depth, data_file_type); + } + + return 0; +} diff --git a/src/font/utils/gen-bidi-type-tab.c b/src/font/utils/gen-bidi-type-tab.c new file mode 100644 index 00000000..9ce50340 --- /dev/null +++ b/src/font/utils/gen-bidi-type-tab.c @@ -0,0 +1,348 @@ +/* MGBidi + * gen-bidi-type-tab.c - generate mgbidi-bidi-type-table.h + * + * Revised from FriBidi by Vincent Wei for MiniGUI 3.4.0 + * + * Authors of FriBidi: + * Behdad Esfahbod, 2001, 2002, 2004 + * + * Copyright (C) 2004 Sharif FarsiWeb, Inc + * Copyright (C) 2001,2002,2004 Behdad Esfahbod + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library, in a file named COPYING; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + * + * For licensing issues, contact . + */ + +#include +#include +#include + +#include "common.h" +#include "minigui.h" +#include "gdi.h" + +#include "packtab.h" + +#include "../mgbidi.h" +#include "mgbidi-unicode-version.h" + +#define appname "gen-bidi-type-tab" +#define outputname "mgbidi-bidi-type-table.h" + +static void +die ( + const char *msg +) +{ + fprintf (stderr, appname ": %s\n", msg); + exit (1); +} + +static void +die2 ( + const char *fmt, + const char *p +) +{ + fprintf (stderr, appname ": "); + fprintf (stderr, fmt, p); + fprintf (stderr, "\n"); + exit (1); +} + +static void +die3 ( + const char *fmt, + unsigned long l, + const char *p +) +{ + fprintf (stderr, appname ": "); + fprintf (stderr, fmt, l, p); + fprintf (stderr, "\n"); + exit (1); +} + +enum Char32TypeLinearEnumOffsetOne +{ +# define _MGBIDI_ADD_TYPE(TYPE,SYMBOL) TYPE, +# define _MGBIDI_ADD_ALIAS(TYPE1,TYPE2) TYPE1 = TYPE2, +# include "../mgbidi-bidi-types-list.h" +# undef _MGBIDI_ADD_ALIAS +# undef _MGBIDI_ADD_TYPE + NUM_TYPES +}; + +struct +{ + const char *name; + int key; +} +type_names[] = +{ +# define _MGBIDI_ADD_TYPE(TYPE,SYMBOL) {STRINGIZE(TYPE), TYPE}, +# define _MGBIDI_ADD_ALIAS(TYPE1,TYPE2) _MGBIDI_ADD_TYPE(TYPE1, SYMBOL) +# include "../mgbidi-bidi-types-list.h" +# undef _MGBIDI_ADD_ALIAS +# undef _MGBIDI_ADD_TYPE +}; + +#define type_names_count (sizeof (type_names) / sizeof (type_names[0])) + +static const char *names[type_names_count]; + +static char +get_type ( + const char *s +) +{ + unsigned int i; + + for (i = 0; i < type_names_count; i++) + if (!strcmp (s, type_names[i].name)) + return type_names[i].key; + die2 ("bidi type name `%s' not found", s); + return 0; +} + +#define table_name "Bid" +#define macro_name "MGBIDI_GET_BIDI_TYPE" + +static signed int table[MGBIDI_UNICODE_CHARS]; +static char buf[4000]; +static char tp[sizeof (buf)]; + +static void +init ( + void +) +{ + register int i; + + for (i = 0; i < type_names_count; i++) + names[i] = 0; + for (i = type_names_count - 1; i >= 0; i--) + names[type_names[i].key] = type_names[i].name; +} + +static void +clear_tab ( + void +) +{ + register Uchar32 c; + + for (c = 0; c < MGBIDI_UNICODE_CHARS; c++) + table[c] = LTR; +} + +static void +init_tab_unicode_data_txt ( + void +) +{ + register Uchar32 c; + + clear_tab (); + + for (c = 0x0590; c < 0x0600; c++) + table[c] = RTL; + for (c = 0x07C0; c < 0x0900; c++) + table[c] = RTL; + for (c = 0xFB1D; c < 0xFB50; c++) + table[c] = RTL; + + for (c = 0x0600; c < 0x07C0; c++) + table[c] = AL; + for (c = 0xFB50; c < 0xFDD0; c++) + table[c] = AL; + for (c = 0xFDF0; c < 0xFE00; c++) + table[c] = AL; + for (c = 0xFE70; c < 0xFF00; c++) + table[c] = AL; + + for (c = 0x2060; c < 0x2070; c++) + table[c] = BN; + for (c = 0xFDD0; c < 0xFDF0; c++) + table[c] = BN; + for (c = 0xFFF0; c < 0xFFF9; c++) + table[c] = BN; + for (c = 0xFFFF; c < MGBIDI_UNICODE_CHARS; c += 0x10000) + table[c - 1] = table[c] = BN; + + if (MGBIDI_UNICODE_CHARS > 0x10000) + { + for (c = 0x10800; c < 0x11000; c++) + table[c] = RTL; + + for (c = 0xE0000; c < 0xE1000; c++) + table[c] = BN; + } +} + +static void +init_tab_derived_bidi_class_txt ( + void +) +{ + clear_tab (); +} + +static void +read_unicode_data_txt ( + FILE *f +) +{ + unsigned long c, l; + + init_tab_unicode_data_txt (); + + l = 0; + while (fgets (buf, sizeof buf, f)) + { + int i; + const char *s = buf; + + l++; + + while (*s == ' ') + s++; + + if (s[0] == '#' || s[0] == '\0' || s[0] == '\n') + continue; + + i = sscanf (s, "%lx;%*[^;];%*[^;];%*[^;];%[^; ]", &c, tp); + if (i != 2 || c >= MGBIDI_UNICODE_CHARS) + die3 ("invalid input at line %ld: %s", l, s); + + /* FIXME: We don't handle First..Last parts of UnicodeData.txt, + * but it works, since all those are LTR. */ + table[c] = get_type (tp); + } +} + +static void +read_derived_bidi_class_txt ( + FILE *f +) +{ + unsigned long c, c2, l; + + init_tab_derived_bidi_class_txt (); + + l = 0; + while (fgets (buf, sizeof buf, f)) + { + int i; + register char typ; + const char *s = buf; + + l++; + + while (*s == ' ') + s++; + + if (s[0] == '#' || s[0] == '\0' || s[0] == '\n') + continue; + + i = sscanf (s, "%lx ; %[^; ]", &c, tp); + if (i == 2) + c2 = c; + else + i = sscanf (s, "%lx..%lx ; %[^; ]", &c, &c2, tp) - 1; + + if (i != 2 || c > c2 || c2 >= MGBIDI_UNICODE_CHARS) + die3 ("invalid input at line %ld: %s", l, s); + + typ = get_type (tp); + for (; c <= c2; c++) + table[c] = typ; + } +} + +static void +read_data ( + const char *data_file_type, + const char *data_file_name +) +{ + FILE *f; + + if (!(f = fopen (data_file_name, "rt"))) + die2 ("error: cannot open `%s' for reading", data_file_name); + + if (!strcmp (data_file_type, "UnicodeData.txt")) + read_unicode_data_txt (f); + else if (!strcmp (data_file_type, "DerivedBidiClass.txt")) + read_derived_bidi_class_txt (f); + else + die2 ("error: unknown data-file type %s", data_file_type); + + fclose (f); +} + +static void +gen_bidi_type_tab ( + int max_depth, + const char *data_file_type +) +{ + printf ("/* " outputname "\n * generated by " appname "\n" + " * from the file %s of Unicode version " + MGBIDI_UNICODE_VERSION ". */\n\n", data_file_type); + + printf ("#define PACKTAB_UINT8 uint8_t\n" + "#define PACKTAB_UINT16 uint16_t\n" + "#define PACKTAB_UINT32 uint32_t\n\n"); + + if (!pack_table + (table, MGBIDI_UNICODE_CHARS, 1, LTR, max_depth, 3, names, + "unsigned char", table_name, macro_name, stdout)) + die ("error: insufficient memory, decrease max_depth"); + + printf ("#undef PACKTAB_UINT8\n" + "#undef PACKTAB_UINT16\n" "#undef PACKTAB_UINT32\n\n"); + + printf ("/* End of generated " outputname " */\n"); +} + +int +main ( + int argc, + const char **argv +) +{ + const char *data_file_type = "UnicodeData.txt"; + + if (argc < 3) + die2 ("usage:\n " appname " max-depth /path/to/%s [junk...]", + data_file_type); + + { + int max_depth = atoi (argv[1]); + const char *data_file_name = argv[2]; + + if (max_depth < 2) + die ("invalid depth"); + + init (); + read_data (data_file_type, data_file_name); + gen_bidi_type_tab (max_depth, data_file_type); + } + + return 0; +} diff --git a/src/font/utils/gen-brackets-tab.c b/src/font/utils/gen-brackets-tab.c new file mode 100644 index 00000000..a7bd2024 --- /dev/null +++ b/src/font/utils/gen-brackets-tab.c @@ -0,0 +1,335 @@ +/* MGBidi + * gen-brackets-tab.c - generate mgbidi-brackets-tables.h + * + * Revised from FriBidi by Vincent Wei for MiniGUI 3.4.0 + * + * Authors of FriBidi: + * Behdad Esfahbod, 2001, 2002, 2004 + * Dov Grobgeld 2017 + * + * Copyright (C) 2004 Sharif FarsiWeb, Inc + * Copyright (C) 2001,2002,2004 Behdad Esfahbod + * Copyright (C) 2017 Dov Grobgeld + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library, in a file named COPYING; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + * + * For licensing issues, contact . + */ + +#include +#include +#include +#include + +#include "common.h" +#include "minigui.h" +#include "gdi.h" + +#include "packtab.h" + +#include "../mgbidi.h" +#include "mgbidi-unicode-version.h" + +#define appname "gen-brackets-tab" +#define outputname "mgbidi-brackets-table.h" + +static void +die ( + const char *msg +) +{ + fprintf (stderr, appname ": %s\n", msg); + exit (1); +} + +static void +die2 ( + const char *fmt, + const char *p +) +{ + fprintf (stderr, appname ": "); + fprintf (stderr, fmt, p); + fprintf (stderr, "\n"); + exit (1); +} + +static void +die3 ( + const char *fmt, + const char *p, + const char *q +) +{ + fprintf (stderr, appname ": "); + fprintf (stderr, fmt, p, q); + fprintf (stderr, "\n"); + exit (1); +} + +static void +die4 ( + const char *fmt, + unsigned long l, + unsigned long p, + unsigned long q +) +{ + fprintf (stderr, appname ": "); + fprintf (stderr, fmt, l, p, q); + fprintf (stderr, "\n"); + exit (1); +} + +#define table_name "Brk" +#define macro_name "MGBIDI_GET_BRACKETS" + +static signed int table[MGBIDI_UNICODE_CHARS]; +static signed int equiv_table[MGBIDI_UNICODE_CHARS]; +static char buf[4000]; +static signed long max_dist; + +static void +init ( + void +) +{ + max_dist = 0; +} + +static void +clear_tabs ( + void +) +{ + register Uchar32 c; + + for (c = 0; c < MGBIDI_UNICODE_CHARS; c++) + { + table[c] = 0; + equiv_table[c] = 0; + } +} + +static signed int table[MGBIDI_UNICODE_CHARS]; +static char buf[4000]; + +/* Read the canonical mapping of unicode characters and store them in the + equiv_table array. */ +static void +read_unicode_data_txt_equivalence ( + FILE *f +) +{ + unsigned long c, l; + + l = 0; + while (fgets (buf, sizeof buf, f)) + { + int i; + const char *s = buf; + char ce_string[256]; /* For parsing the equivalence */ + char *p = NULL; + int ce, in_tag; + + l++; + + while (*s == ' ') + s++; + + if (s[0] == '#' || s[0] == '\0' || s[0] == '\n') + continue; + /* Field: 0 ; 1 ; 2 ; 3 ; 4 ; 5 */ + i = sscanf (s, "%lx;%*[^;];%*[^;];%*[^;];%*[^;];%[^;]", &c, ce_string); + if (c >= MGBIDI_UNICODE_CHARS) + { + fprintf (stderr, "invalid input at line %ld: %s", l, s); + exit(1); + } + if (i==1) + continue; + + /* split and parse ce */ + p = ce_string; + ce = -1; + in_tag = 0; + while(*p) + { + if (*p==';') + break; + else if (*p=='<') + in_tag = 1; + else if (*p=='>') + in_tag = 0; + else if (!in_tag && isalnum(*p)) + { + /* Assume we got a hexa decimal */ + ce = strtol(p,NULL,16); + break; + } + p++; + } + + /* FIXME: We don't handle First..Last parts of UnicodeData.txt, + * but it works, since all those are LTR. */ + equiv_table[c] = ce; + } +} + +static void +read_bidi_brackets_txt ( + FILE *f +) +{ + unsigned long l; + + l = 0; + while (fgets (buf, sizeof buf, f)) + { + unsigned long i, j; + signed long dist; + int k; + const char *s = buf; + char open_close; + + l++; + + while (*s == ' ') + s++; + + if (s[0] == '#' || s[0] == '\0' || s[0] == '\n') + continue; + + k = sscanf (s, "%lx; %lx; %c", &i, &j, &open_close); + if (k != 3 || i >= MGBIDI_UNICODE_CHARS || j >= MGBIDI_UNICODE_CHARS) + die4 ("invalid pair in input at line %ld: %04lX, %04lX", l, i, j); + + /* Open braces map to themself */ + if (open_close=='o') + j = i; + + /* Turn j into the unicode equivalence if it exists */ + if (equiv_table[j]) + { + /* printf("Found match for %04x->%04x\n", j, equiv_table[j]); */ + j = equiv_table[j]; + } + + dist = ((signed long) j - (signed long) i); + table[i] = dist; + if (dist > max_dist) + max_dist = dist; + else if (-dist > max_dist) + max_dist = -dist; + } +} + +static void +read_data ( + const char *bracket_datafile_type, + const char *bracket_datafile_name, + const char *uni_datafile_type, + const char *uni_datafile_name +) +{ + FILE *f; + + clear_tabs (); + + if (!(f = fopen (uni_datafile_name, "rt"))) + die2 ("error: cannot open `%s' for reading", bracket_datafile_name); + + if (!strcmp (uni_datafile_type, "UnicodeData.txt")) + read_unicode_data_txt_equivalence (f); + else + die2 ("error: unknown data-file-type %s", uni_datafile_type); + + fprintf (stderr, "Reading `%s'\n", bracket_datafile_name); + if (!(f = fopen (bracket_datafile_name, "rt"))) + die2 ("error: cannot open `%s' for reading", bracket_datafile_name); + + if (!strcmp (bracket_datafile_type, "BidiBrackets.txt")) + read_bidi_brackets_txt (f); + else + die2 ("error: unknown data-file-type %s", bracket_datafile_type); + + fclose (f); +} + +static void +gen_brackets_tab ( + int max_depth, + const char *data_file_type +) +{ + int key_bytes; + const char *key_type; + + printf ("/* " outputname "\n * generated by " appname "\n" + " * from the file %s of Unicode version " + MGBIDI_UNICODE_VERSION ". */\n\n", data_file_type); + + printf ("#define PACKTAB_UINT8 uint8_t\n" + "#define PACKTAB_UINT16 uint16_t\n" + "#define PACKTAB_UINT32 uint32_t\n\n"); + + key_bytes = max_dist <= 0x7f ? 1 : max_dist < 0x7fff ? 2 : 4; + key_type = key_bytes == 1 ? "int8_t" : key_bytes == 2 ? + "int16_t" : "int32_t"; + + if (!pack_table + (table, MGBIDI_UNICODE_CHARS, key_bytes, 0, max_depth, 1, NULL, + key_type, table_name, macro_name "_DELTA", stdout)) + die ("error: insufficient memory, decrease max_depth"); + + printf ("#undef PACKTAB_UINT8\n" + "#undef PACKTAB_UINT16\n" "#undef PACKTAB_UINT32\n\n"); + + printf ("#define " macro_name "(x) ((x) + " macro_name "_DELTA(x))\n\n"); + + printf ("/* End of generated " outputname " */\n"); +} + +int +main ( + int argc, + const char **argv +) +{ + const char *bracket_datafile_type = "BidiBrackets.txt"; + const char *uni_datafile_type = "UnicodeData.txt"; + + if (argc < 4) + die3 ("usage:\n " appname " max-depth /path/to/%s /path/to/%s [junk...]", + bracket_datafile_type, + uni_datafile_type); + + { + int max_depth = atoi (argv[1]); + const char *bracket_datafile_name = argv[2]; + const char *uni_datafile_name = argv[3]; + + if (max_depth < 2) + die ("invalid depth"); + + init (); + read_data (bracket_datafile_type, bracket_datafile_name, + uni_datafile_type, uni_datafile_name); + gen_brackets_tab (max_depth, bracket_datafile_type); + } + + return 0; +} diff --git a/src/font/utils/gen-brackets-type-tab.c b/src/font/utils/gen-brackets-type-tab.c new file mode 100644 index 00000000..d73f5971 --- /dev/null +++ b/src/font/utils/gen-brackets-type-tab.c @@ -0,0 +1,225 @@ +/* MGBidi + * gen-brackets-type-tab.c - generate mgbidi-brackets-type-table.h + * + * Revised from FriBidi by Vincent Wei for MiniGUI 3.4.0 + * + * Authors of FriBidi: + * Behdad Esfahbod, 2001, 2002, 2004 + * Dov Grobgeld 2017 + * + * Copyright (C) 2004 Sharif FarsiWeb, Inc + * Copyright (C) 2001,2002,2004 Behdad Esfahbod + * Copyright (C) 2017 Dov Grobgeld + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library, in a file named COPYING; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + * + * For licensing issues, contact . + */ + +#include +#include +#include + +#include "common.h" +#include "minigui.h" +#include "gdi.h" + +#include "packtab.h" + +#include "../mgbidi.h" +#include "mgbidi-unicode-version.h" + +#define appname "gen-brackets-type-tab" +#define outputname "mgbidi-brackets-type-tablel.h" + +static void +die ( + const char *msg +) +{ + fprintf (stderr, appname ": %s\n", msg); + exit (1); +} + +static void +die2 ( + const char *fmt, + const char *p +) +{ + fprintf (stderr, appname ": "); + fprintf (stderr, fmt, p); + fprintf (stderr, "\n"); + exit (1); +} + +static void +die4 ( + const char *fmt, + unsigned long l, + unsigned long p, + unsigned long q +) +{ + fprintf (stderr, appname ": "); + fprintf (stderr, fmt, l, p, q); + fprintf (stderr, "\n"); + exit (1); +} + +#define table_name "Brt" +#define macro_name "MGBIDI_GET_BRACKET_TYPE" + +static signed int table[MGBIDI_UNICODE_CHARS]; +static char buf[4000]; +static signed long max_dist; + +static void +init ( + void +) +{ + max_dist = 0; +} + +static void +clear_tab ( + void +) +{ + register Uchar32 c; + + for (c = 0; c < MGBIDI_UNICODE_CHARS; c++) + table[c] = 0; +} + +static void +init_tab_brackets_type_txt ( + void +) +{ + clear_tab (); +} + +static void +read_bidi_brackets_type_txt ( + FILE *f +) +{ + unsigned long l; + + init_tab_brackets_type_txt (); + + l = 0; + while (fgets (buf, sizeof buf, f)) + { + unsigned long i, j; + int k; + const char *s = buf; + char open_close; + + l++; + + while (*s == ' ') + s++; + + if (s[0] == '#' || s[0] == '\0' || s[0] == '\n') + continue; + + k = sscanf (s, "%lx; %lx; %c", &i, &j, &open_close); + if (k != 3 || i >= MGBIDI_UNICODE_CHARS || j >= MGBIDI_UNICODE_CHARS) + die4 ("invalid pair in input at line %ld: %04lX, %04lX", l, i, j); + table[i] = 1 + (0x2 * (open_close=='o')); + } +} + +static void +read_data ( + const char *data_file_type, + const char *data_file_name +) +{ + FILE *f; + + if (!(f = fopen (data_file_name, "rt"))) + die2 ("error: cannot open `%s' for reading", data_file_name); + + if (!strcmp (data_file_type, "BidiBrackets.txt")) + read_bidi_brackets_type_txt (f); + else + die2 ("error: unknown data-file-type %s", data_file_type); + + fclose (f); +} + +static void +gen_brackets_tab ( + int max_depth, + const char *data_file_type +) +{ + int key_bytes; + const char *key_type; + + printf ("/* " outputname "\n * generated by " appname "\n" + " * from the file %s of Unicode version " + MGBIDI_UNICODE_VERSION ". */\n\n", data_file_type); + + printf ("#define PACKTAB_UINT8 uint8_t\n" + "#define PACKTAB_UINT16 uint16_t\n" + "#define PACKTAB_UINT32 uint32_t\n\n"); + + key_bytes = 1; + key_type = key_bytes == 1 ? "int8_t" : key_bytes == 2 ? + "int16_t" : "int32_t"; + + if (!pack_table + (table, MGBIDI_UNICODE_CHARS, key_bytes, 0, max_depth, 1, NULL, + key_type, table_name, macro_name, stdout)) + die ("error: insufficient memory, decrease max_depth"); + + printf ("#undef PACKTAB_UINT8\n" + "#undef PACKTAB_UINT16\n" "#undef PACKTAB_UINT32\n\n"); + + printf ("/* End of generated " outputname " */\n"); +} + +int +main ( + int argc, + const char **argv +) +{ + const char *data_file_type = "BidiBrackets.txt"; + + if (argc < 3) + die2 ("usage:\n " appname " max-depth /path/to/%s [junk...]", + data_file_type); + + { + int max_depth = atoi (argv[1]); + const char *data_file_name = argv[2]; + + if (max_depth < 2) + die ("invalid depth"); + + init (); + read_data (data_file_type, data_file_name); + gen_brackets_tab (max_depth, data_file_type); + } + + return 0; +} diff --git a/src/font/utils/gen-joining-type-tab.c b/src/font/utils/gen-joining-type-tab.c new file mode 100644 index 00000000..f627ac83 --- /dev/null +++ b/src/font/utils/gen-joining-type-tab.c @@ -0,0 +1,346 @@ +/* MGBidi + * gen-joining-type-tab.c - generate mgbidi-joining-type-table.h + * + * Revised from FriBidi by Vincent Wei for MiniGUI 3.4.0 + * + * Authors of FriBidi: + * Behdad Esfahbod, 2004 + * + * Copyright (C) 2004 Sharif FarsiWeb, Inc + * Copyright (C) 2004 Behdad Esfahbod + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library, in a file named COPYING; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + * + * For licensing issues, contact . + */ + +#include +#include +#include + +#include "common.h" +#include "minigui.h" +#include "gdi.h" + +#include "packtab.h" + +#include "../mgbidi.h" +#include "mgbidi-unicode-version.h" + +#define appname "gen-joining-type-tab" +#define outputname "mgbidi-joining-type-table.h" + +static void +die ( + const char *msg +) +{ + fprintf (stderr, appname ": %s\n", msg); + exit (1); +} + +static void +die2 ( + const char *fmt, + const char *p +) +{ + fprintf (stderr, appname ": "); + fprintf (stderr, fmt, p); + fprintf (stderr, "\n"); + exit (1); +} + +static void +die3 ( + const char *fmt, + const char *p, + const char *q +) +{ + fprintf (stderr, appname ": "); + fprintf (stderr, fmt, p, q); + fprintf (stderr, "\n"); + exit (1); +} + +static void +die3l ( + const char *fmt, + unsigned long l, + const char *p +) +{ + fprintf (stderr, appname ": "); + fprintf (stderr, fmt, l, p); + fprintf (stderr, "\n"); + exit (1); +} + +enum FriBidiJoiningLinearEnumOffsetOne +{ +# define _MGBIDI_ADD_TYPE(TYPE,SYMBOL) TYPE, +# include "../mgbidi-joining-types-list.h" +# undef _MGBIDI_ADD_TYPE + NUM_TYPES +}; + +struct +{ + const char *name; + int key; +} +type_names[] = +{ +# define _MGBIDI_ADD_TYPE(TYPE,SYMBOL) {STRINGIZE(TYPE), TYPE}, +# include "../mgbidi-joining-types-list.h" +# undef _MGBIDI_ADD_TYPE +}; + +#define type_names_count (sizeof (type_names) / sizeof (type_names[0])) + +static const char *names[type_names_count]; + +static char +get_type ( + const char *s +) +{ + unsigned int i; + + for (i = 0; i < type_names_count; i++) + if (!strcmp (s, type_names[i].name)) + return type_names[i].key; + die2 ("joining type name `%s' not found", s); + return -1; +} + +static const char *ignored_bidi_types[] = { + "BN", + "LRE", + "RLE", + "LRO", + "RLO", + "PDF", + "LRI", + "RLI", + "FSI", + "PDI", + NULL +}; + +static const char *transparent_general_categories[] = { + "Mn", + "Mn", + "Cf", + NULL +}; + +static const char * +type_is ( + const char *s, + const char *type_list[] +) +{ + for (; type_list[0]; type_list++) + if (!strcmp (s, type_list[0])) + return type_list[0]; + return NULL; +} + +#define table_name "Joi" +#define macro_name "MGBIDI_GET_JOINING_TYPE" + +static signed int table[MGBIDI_UNICODE_CHARS]; +static char buf[4000]; +static char tp[sizeof (buf)], tp_gen[sizeof (buf)], tp_bidi[sizeof (buf)]; + +static void +clear_tab ( + void +) +{ + register Uchar32 c; + + for (c = 0; c < MGBIDI_UNICODE_CHARS; c++) + table[c] = U; +} + +static void +init ( + void +) +{ + register int i; + + for (i = 0; i < type_names_count; i++) + names[i] = 0; + for (i = type_names_count - 1; i >= 0; i--) + names[type_names[i].key] = type_names[i].name; + + clear_tab (); +} + +static void +read_unicode_data_txt ( + FILE *f +) +{ + unsigned long c, l; + + l = 0; + while (fgets (buf, sizeof buf, f)) + { + int i; + const char *s = buf; + + l++; + + while (*s == ' ') + s++; + + if (*s == '#' || *s == '\0' || *s == '\n') + continue; + + i = sscanf (s, "%lx;%*[^;];%[^; ];%*[^;];%[^; ]", &c, tp_gen, tp_bidi); + if (i != 3 || c >= MGBIDI_UNICODE_CHARS) + die3l ("UnicodeData.txt: invalid input at line %ld: %s", l, s); + + if (type_is (tp_bidi, ignored_bidi_types)) + table[c] = G; + if (type_is (tp_gen, transparent_general_categories)) + table[c] = T; + } +} + +static void +read_arabic_shaping_txt ( + FILE *f +) +{ + unsigned long c, c2, l; + + l = 0; + while (fgets (buf, sizeof buf, f)) + { + int i; + register char typ; + const char *s = buf; + + l++; + + while (*s == ' ') + s++; + + if (*s == '#' || *s == '\0' || *s == '\n') + continue; + + i = sscanf (s, "%lx ; %*[^;]; %[^; ]", &c, tp); + if (i == 2) + c2 = c; + else + i = sscanf (s, "%lx..%lx ; %*[^;]; %[^; ]", &c, &c2, tp) - 1; + + if (i != 2 || c > c2 || c2 >= MGBIDI_UNICODE_CHARS) + die3l ("ArabicShaping.txt: invalid input at line %ld: %s", l, s); + + typ = get_type (tp); + for (; c <= c2; c++) + table[c] = typ; + } +} + +static void +read_data ( + const char *data_file_type[], + const char *data_file_name[] +) +{ + FILE *f; + + for (; data_file_name[0] && data_file_type[0]; + data_file_name++, data_file_type++) + { + if (!(f = fopen (data_file_name[0], "rt"))) + die2 ("error: cannot open `%s' for reading", data_file_name[0]); + + if (!strcmp (data_file_type[0], "UnicodeData.txt")) + read_unicode_data_txt (f); + else if (!strcmp (data_file_type[0], "ArabicShaping.txt")) + read_arabic_shaping_txt (f); + else + die2 ("error: unknown data-file type %s", data_file_type[0]); + + fclose (f); + } + +} + +static void +gen_joining_type_tab ( + int max_depth, + const char *data_file_type[] +) +{ + printf ("/* " outputname "\n * generated by " appname "\n" + " * from the files %s, %s of Unicode version " + MGBIDI_UNICODE_VERSION ". */\n\n", data_file_type[0], + data_file_type[1]); + + printf ("#define PACKTAB_UINT8 uint8_t\n" + "#define PACKTAB_UINT16 uint16_t\n" + "#define PACKTAB_UINT32 uint32_t\n\n"); + + if (!pack_table + (table, MGBIDI_UNICODE_CHARS, 1, U, max_depth, 1, names, + "unsigned char", table_name, macro_name, stdout)) + die ("error: insufficient memory, decrease max_depth"); + + printf ("#undef PACKTAB_UINT8\n" + "#undef PACKTAB_UINT16\n" "#undef PACKTAB_UINT32\n\n"); + + printf ("/* End of generated " outputname " */\n"); +} + +int +main ( + int argc, + const char **argv +) +{ + const char *data_file_type[] = + { "UnicodeData.txt", "ArabicShaping.txt", NULL }; + + if (argc < 4) + die3 ("usage:\n " appname " max-depth /path/to/%s /path/to/%s [junk...]", + data_file_type[0], data_file_type[1]); + + { + int max_depth = atoi (argv[1]); + const char *data_file_name[] = { NULL, NULL, NULL }; + data_file_name[0] = argv[2]; + data_file_name[1] = argv[3]; + + if (max_depth < 2) + die ("invalid depth"); + + init (); + read_data (data_file_type, data_file_name); + gen_joining_type_tab (max_depth, data_file_type); + } + + return 0; +} diff --git a/src/font/utils/gen-mirroring-tab.c b/src/font/utils/gen-mirroring-tab.c new file mode 100644 index 00000000..bccbbf76 --- /dev/null +++ b/src/font/utils/gen-mirroring-tab.c @@ -0,0 +1,230 @@ +/* MGBidi + * gen-mirroring-tab.c - generate mgbidi-mirroring-table.h + * + * Revised from FriBidi by Vincent Wei for MiniGUI 3.4.0 + * + * Authors of FriBidi: + * Behdad Esfahbod, 2001, 2002, 2004 + * + * Copyright (C) 2004 Sharif FarsiWeb, Inc + * Copyright (C) 2001,2002,2004 Behdad Esfahbod + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library, in a file named COPYING; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + * + * For licensing issues, contact . + */ + +#include +#include +#include + +#include "common.h" +#include "minigui.h" +#include "gdi.h" + +#include "packtab.h" + +#include "../mgbidi.h" +#include "mgbidi-unicode-version.h" + +#define appname "gen-mirroring-tab" +#define outputname "mgbidi-mirroring-table.h" + +static void +die ( + const char *msg +) +{ + fprintf (stderr, appname ": %s\n", msg); + exit (1); +} + +static void +die2 ( + const char *fmt, + const char *p +) +{ + fprintf (stderr, appname ": "); + fprintf (stderr, fmt, p); + fprintf (stderr, "\n"); + exit (1); +} + +static void +die4 ( + const char *fmt, + unsigned long l, + unsigned long p, + unsigned long q +) +{ + fprintf (stderr, appname ": "); + fprintf (stderr, fmt, l, p, q); + fprintf (stderr, "\n"); + exit (1); +} + +#define table_name "Mir" +#define macro_name "MGBIDI_GET_MIRRORING" + +static signed int table[MGBIDI_UNICODE_CHARS]; +static char buf[4000]; +static signed long max_dist; + +static void +init ( + void +) +{ + max_dist = 0; +} + +static void +clear_tab ( + void +) +{ + register Uchar32 c; + + for (c = 0; c < MGBIDI_UNICODE_CHARS; c++) + table[c] = 0; +} + +static void +init_tab_mirroring_txt ( + void +) +{ + clear_tab (); +} + +static void +read_bidi_mirroring_txt ( + FILE *f +) +{ + unsigned long l; + + init_tab_mirroring_txt (); + + l = 0; + while (fgets (buf, sizeof buf, f)) + { + unsigned long i, j; + signed long dist; + int k; + const char *s = buf; + + l++; + + while (*s == ' ') + s++; + + if (s[0] == '#' || s[0] == '\0' || s[0] == '\n') + continue; + + k = sscanf (s, "%lx; %lx", &i, &j); + if (k != 2 || i >= MGBIDI_UNICODE_CHARS || j >= MGBIDI_UNICODE_CHARS) + die4 ("invalid pair in input at line %ld: %04lX, %04lX", l, i, j); + dist = ((signed long) j - (signed long) i); + table[i] = dist; + if (dist > max_dist) + max_dist = dist; + else if (-dist > max_dist) + max_dist = -dist; + } +} + +static void +read_data ( + const char *data_file_type, + const char *data_file_name +) +{ + FILE *f; + + if (!(f = fopen (data_file_name, "rt"))) + die2 ("error: cannot open `%s' for reading", data_file_name); + + if (!strcmp (data_file_type, "BidiMirroring.txt")) + read_bidi_mirroring_txt (f); + else + die2 ("error: unknown data-file-type %s", data_file_type); + + fclose (f); +} + +static void +gen_mirroring_tab ( + int max_depth, + const char *data_file_type +) +{ + int key_bytes; + const char *key_type; + + printf ("/* " outputname "\n * generated by " appname "\n" + " * from the file %s of Unicode version " + MGBIDI_UNICODE_VERSION ". */\n\n", data_file_type); + + printf ("#define PACKTAB_UINT8 uint8_t\n" + "#define PACKTAB_UINT16 uint16_t\n" + "#define PACKTAB_UINT32 uint32_t\n\n"); + + key_bytes = max_dist <= 0x7f ? 1 : max_dist < 0x7fff ? 2 : 4; + key_type = key_bytes == 1 ? "int8_t" : key_bytes == 2 ? + "int16_t" : "int32_t"; + + if (!pack_table + (table, MGBIDI_UNICODE_CHARS, key_bytes, 0, max_depth, 1, NULL, + key_type, table_name, macro_name "_DELTA", stdout)) + die ("error: insufficient memory, decrease max_depth"); + + printf ("#undef PACKTAB_UINT8\n" + "#undef PACKTAB_UINT16\n" "#undef PACKTAB_UINT32\n\n"); + + printf ("#define " macro_name "(x) ((x) + " macro_name "_DELTA(x))\n\n"); + + printf ("/* End of generated " outputname " */\n"); +} + +int +main ( + int argc, + const char **argv +) +{ + const char *data_file_type = "BidiMirroring.txt"; + + if (argc < 3) + die2 ("usage:\n " appname " max-depth /path/to/%s [junk...]", + data_file_type); + + { + int max_depth = atoi (argv[1]); + const char *data_file_name = argv[2]; + + if (max_depth < 2) + die ("invalid depth"); + + init (); + read_data (data_file_type, data_file_name); + gen_mirroring_tab (max_depth, data_file_type); + } + + return 0; +} diff --git a/src/font/utils/gen-unicode-version.c b/src/font/utils/gen-unicode-version.c new file mode 100644 index 00000000..2b2cfd31 --- /dev/null +++ b/src/font/utils/gen-unicode-version.c @@ -0,0 +1,181 @@ +/* MGBidi + * gen-unicode-version.c - generate mgbidi-unicode-version.h + * + * Revised from FriBidi by Vincent Wei for MiniGUI 3.4.0 + * + * Authors of FriBidi: + * Behdad Esfahbod, 2001, 2002, 2004 + * + * Copyright (C) 2004 Sharif FarsiWeb, Inc + * Copyright (C) 2004 Behdad Esfahbod + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library, in a file named COPYING; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + * + * For licensing issues, contact . + */ + +#include + +#include + +#include +#include +#include +#include + +#include "packtab.h" + +#define appname "gen-unicode-version" +#define outputname "mgbidi-unicode-version.h" + +static void +die ( + const char *msg +) +{ + fprintf (stderr, appname ": %s\n", msg); + exit (1); +} + +static void +die2 ( + const char *fmt, + const char *p +) +{ + fprintf (stderr, appname ": "); + fprintf (stderr, fmt, p); + fprintf (stderr, "\n"); + exit (1); +} + +int version_major, version_minor, version_micro; +char unicode_version[100]; +char buf[4000]; + +static void +init ( + void +) +{ + version_major = version_minor = version_micro = 0; + strcpy (unicode_version, "(unknown)"); +} + +#define READ_VERSION(prefix) ((where = strstr(buf, prefix)) && \ + (3 == sscanf (where, \ + prefix"%d.%d.%d", &version_major, &version_minor, &version_micro))) + +static int +read_file ( + FILE *f +) +{ + int found = 0; + + version_micro = 0; + + while (fgets (buf, sizeof buf, f)) + { + const char *where; + + if (READ_VERSION ("Version ") || READ_VERSION ("Unicode ")) + { + found = 1; + break; + } + } + + if (!found) + return 0; + + sprintf (unicode_version, "%d.%d.%d", version_major, version_minor, + version_micro); + return 1; +} + +static int +read_data ( + const char *data_file_type, + const char *data_file_name +) +{ + FILE *f; + int status; + + if (!(f = fopen (data_file_name, "rt"))) + die2 ("error: cannot open `%s' for reading", data_file_name); + + status = read_file (f); + + fclose (f); + + return status; +} + +static void +gen_unicode_version ( + const char *data_file_type +) +{ + printf ("/* " outputname "\n * generated by " appname "\n" " * from the file %s */\n\n", data_file_type); + + printf ("#define MGBIDI_UNICODE_VERSION \"%s\"\n" + "#define MGBIDI_UNICODE_MAJOR_VERSION %d\n" + "#define MGBIDI_UNICODE_MINOR_VERSION %d\n" + "#define MGBIDI_UNICODE_MICRO_VERSION %d\n" + "\n", + unicode_version, + version_major, version_minor, version_micro); + + printf ("/* End of generated " outputname " */\n"); +} + +int +main ( + int argc, + const char **argv +) +{ + const char *data_file_type; + int i; + int found = 0; + + if (argc < 2) + die ("usage:\n " appname + " /path/to/a/UCD/file [/path/to/more/UCD/files ...]"); + + { + const char *data_file_name; + + init (); + for (i = 1; i < argc && !found; i++) + { + data_file_name = argv[i]; + data_file_type = strrchr (data_file_name, '/'); + if (data_file_type) + data_file_type++; + else + data_file_type = data_file_name; + found = read_data (data_file_type, data_file_name); + } + if (!found) + die ("error: version not found"); + gen_unicode_version (data_file_type); + } + + return 0; +} diff --git a/src/font/utils/makegbkrbf.c b/src/font/utils/makegbkrbf.c deleted file mode 100644 index 6964d2b7..00000000 --- a/src/font/utils/makegbkrbf.c +++ /dev/null @@ -1,157 +0,0 @@ -/* - * This file is part of MiniGUI, a mature cross-platform windowing - * and Graphics User Interface (GUI) support system for embedded systems - * and smart IoT devices. - * - * Copyright (C) 2002~2018, Beijing FMSoft Technologies Co., Ltd. - * Copyright (C) 1998~2002, WEI Yongming - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * Or, - * - * As this program is a library, any link to this program must follow - * GNU General Public License version 3 (GPLv3). If you cannot accept - * GPLv3, you need to be licensed from FMSoft. - * - * If you have got a commercial license of this program, please use it - * under the terms and conditions of the commercial license. - * - * For more information about the commercial license, please refer to - * . - */ -#include -#include -#include - -static int gbk_index (unsigned short encoding) -{ - unsigned char ch1, ch2; - - ch1 = encoding >> 8; - ch2 = (unsigned char)encoding; - - if (ch2 > 0x7F) - return (ch1 - 0x81) * 190 + (ch2 - 0x41); - else - return (ch1 - 0x81) * 190 + (ch2 - 0x40); -} - -static struct _font_info { - char name [256]; - int def_char; - int pixel; - int ascent; - int descent; - int nr_chars; -} font_info; - -typedef struct _glyph { - int encoding; - int dwidth; - int bbw; - int bbh; - int bbx; - int bby; - unsigned char bitmap [72]; -} glyph_t; - -int main (int argc, char* argv[]) -{ - FILE* fp; - int i; - int width, height; - int bmp_pitch, bmp_size, bmp_pos; - - if (argc < 2) { - printf ("usage: ./makegbkrbf < \n"); - return 1; - } - - scanf ("%s\n", font_info.name); - scanf ("%d\n", &font_info.def_char); - scanf ("%d\n", &font_info.pixel); - scanf ("%d\n", &font_info.ascent); - scanf ("%d\n", &font_info.descent); - scanf ("%d\n", &font_info.nr_chars); - - width = font_info.pixel; - height = font_info.ascent + font_info.descent; - bmp_pitch = (width + 7)/8; - bmp_size = bmp_pitch * height; - - if ((fp = fopen (argv[1], "w+")) == NULL) - return 1; - - printf ("font: %s (%dx%d)\n", font_info.name, width, height); - - fseek (fp, (0xFF - 0x80) * 190 * bmp_size - 1, SEEK_SET); - fwrite (" ", 1, 1, fp); - - for (i = 0; i < font_info.nr_chars; i++) { - glyph_t glyph; - int n, j, k, skip_lines, skip_bytes; - int bb_pitch; - unsigned char bb_bmp [72]; - unsigned int bb_lines [24]; - - scanf ("%d\n", &glyph.encoding); - scanf ("%d\n", &glyph.dwidth); - scanf ("%d\n", &glyph.bbw); - scanf ("%d\n", &glyph.bbh); - scanf ("%d\n", &glyph.bbx); - scanf ("%d\n", &glyph.bby); - - printf ("enconding: %d (%d, %d, %d, %d)\n", - glyph.encoding, glyph.bbw, glyph.bbh, glyph.bbx, glyph.bby); - - bb_pitch = (glyph.bbw + 7)/8; - n = bb_pitch * glyph.bbh; - - /* read bounding box bitmap */ - for (j = 0; j < n; j++) { - int tmp; - scanf ("%d\n", &tmp); - bb_bmp [j] = (unsigned char)tmp; - } - - for (j = 0; j < glyph.bbh; j++) { - bb_lines [j] = 0; - for (k = 0; k < bb_pitch; k++) - bb_lines [j] |= bb_bmp [j*bb_pitch + k] << ((bb_pitch - k - 1) * 8); - - bb_lines [j] <<= (bmp_pitch - bb_pitch) * 8; - bb_lines [j] >>= glyph.bbx; - } - - skip_lines = height - (glyph.bbh + glyph.bby) - font_info.descent; - skip_bytes = skip_lines * bmp_pitch; - - memset (glyph.bitmap, 0, 72); - for (j = 0; j < glyph.bbh; j++) { - unsigned char* bmp = &glyph.bitmap [skip_bytes + j*bmp_pitch]; - for (k = 0; k < bmp_pitch; k++) - bmp [k] = (unsigned char)(bb_lines [j] >> ((bmp_pitch - k - 1) * 8)); - } - - bmp_pos = bmp_size * gbk_index (glyph.encoding); - - fseek (fp, bmp_pos, SEEK_SET); - fwrite (glyph.bitmap, bmp_size, 1, fp); - } - - fclose (fp); - return 0; -} - diff --git a/src/font/utils/makegbksong24rbf.c b/src/font/utils/makegbksong24rbf.c deleted file mode 100644 index fcc4adc4..00000000 --- a/src/font/utils/makegbksong24rbf.c +++ /dev/null @@ -1,151 +0,0 @@ -/* - * This file is part of MiniGUI, a mature cross-platform windowing - * and Graphics User Interface (GUI) support system for embedded systems - * and smart IoT devices. - * - * Copyright (C) 2002~2018, Beijing FMSoft Technologies Co., Ltd. - * Copyright (C) 1998~2002, WEI Yongming - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * Or, - * - * As this program is a library, any link to this program must follow - * GNU General Public License version 3 (GPLv3). If you cannot accept - * GPLv3, you need to be licensed from FMSoft. - * - * If you have got a commercial license of this program, please use it - * under the terms and conditions of the commercial license. - * - * For more information about the commercial license, please refer to - * . - */ -#include -#include -#include - -static int gbk_index (unsigned short encoding) -{ - unsigned char ch1, ch2; - - ch1 = encoding >> 8; - ch2 = (unsigned char)encoding; - - return (ch1 - 0x81) * 192 + (ch2 - 0x40); -} - -static struct _font_info { - char name [256]; - int def_char; - int pixel; - int ascent; - int descent; - int nr_chars; -} font_info; - -typedef struct _glyph { - int encoding; - int dwidth; - int bbw; - int bbh; - int bbx; - int bby; - unsigned char bitmap [72]; -} glyph_t; - -int main (void) -{ - FILE* fp; - int i; - int width, height; - int bmp_pitch, bmp_size, bmp_pos; - - scanf ("%s\n", font_info.name); - scanf ("%d\n", &font_info.def_char); - scanf ("%d\n", &font_info.pixel); - scanf ("%d\n", &font_info.ascent); - scanf ("%d\n", &font_info.descent); - scanf ("%d\n", &font_info.nr_chars); - - width = font_info.pixel; - height = font_info.ascent + font_info.descent; - bmp_pitch = (width + 7)/8; - bmp_size = bmp_pitch * height; - - if ((fp = fopen ("gbk24song.bin", "w+")) == NULL) - return 1; - - printf ("font: %s (%dx%d)\n", font_info.name, width, height); - - fseek (fp, (0xFF-0x80)*(0xFF-0x40)*bmp_size - 1, SEEK_SET); - fwrite (" ", 1, 1, fp); - - for (i = 0; i < font_info.nr_chars; i++) { - glyph_t glyph; - int n, j, k, skip_lines, skip_bytes; - int bb_pitch; - unsigned char bb_bmp [72]; - unsigned int bb_lines [24]; - - scanf ("%d\n", &glyph.encoding); - scanf ("%d\n", &glyph.dwidth); - scanf ("%d\n", &glyph.bbw); - scanf ("%d\n", &glyph.bbh); - scanf ("%d\n", &glyph.bbx); - scanf ("%d\n", &glyph.bby); - - printf ("enconding: %d (%d, %d, %d, %d)\n", - glyph.encoding, glyph.bbw, glyph.bbh, glyph.bbx, glyph.bby); - - bb_pitch = (glyph.bbw + 7)/8; - n = bb_pitch * glyph.bbh; - - /* read bounding box bitmap */ - for (j = 0; j < n; j++) { - int tmp; - scanf ("%d\n", &tmp); - bb_bmp [j] = (unsigned char)tmp; - } - - for (j = 0; j < glyph.bbh; j++) { - bb_lines [j] = 0; - for (k = 0; k < bb_pitch; k++) - bb_lines [j] |= bb_bmp [j*bb_pitch + k] << ((bb_pitch - k - 1) * 8); - - bb_lines [j] <<= (bmp_pitch - bb_pitch) * 8; - bb_lines [j] >>= glyph.bbx; - } - - skip_lines = height - (glyph.bbh + glyph.bby) - font_info.descent; - skip_bytes = skip_lines * bmp_pitch; - - memset (glyph.bitmap, 0, 72); - for (j = 0; j < glyph.bbh; j++) { - unsigned char* bmp = &glyph.bitmap [skip_bytes + j*bmp_pitch]; - for (k = 0; k < bmp_pitch; k++) - bmp [k] = (unsigned char)(bb_lines [j] >> ((bmp_pitch - k - 1) * 8)); - } - - bmp_pos = bmp_size * gbk_index (glyph.encoding); - - // printf ("bmp_pos: %d\n", bmp_pos); - - fseek (fp, bmp_pos, SEEK_SET); - fwrite (glyph.bitmap, bmp_size, 1, fp); - } - - fclose (fp); - return 0; -} - diff --git a/src/font/utils/makegbrbf.c b/src/font/utils/makegbrbf.c deleted file mode 100644 index e3174fa6..00000000 --- a/src/font/utils/makegbrbf.c +++ /dev/null @@ -1,171 +0,0 @@ -/* - * This file is part of MiniGUI, a mature cross-platform windowing - * and Graphics User Interface (GUI) support system for embedded systems - * and smart IoT devices. - * - * Copyright (C) 2002~2018, Beijing FMSoft Technologies Co., Ltd. - * Copyright (C) 1998~2002, WEI Yongming - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * Or, - * - * As this program is a library, any link to this program must follow - * GNU General Public License version 3 (GPLv3). If you cannot accept - * GPLv3, you need to be licensed from FMSoft. - * - * If you have got a commercial license of this program, please use it - * under the terms and conditions of the commercial license. - * - * For more information about the commercial license, please refer to - * . - */ -#include -#include -#include - -#define IS_GB2312_CHAR(ch1, ch2) \ - if (((ch1 >= 0xA1 && ch1 <= 0xA9) || (ch1 >= 0xB0 && ch1 <= 0xF7)) \ - && ch2 >= 0xA1 && ch2 <= 0xFE) - -static int gb_index (unsigned short encoding) -{ - unsigned char ch1, ch2; - int area; - - ch1 = encoding >> 8; - ch2 = (unsigned char)encoding; - - area = ch1 - 0xA1; - IS_GB2312_CHAR(ch1, ch2) { - if (area < 9) { - return (area * 94 + ch2 - 0xA1); - } - else if (area >= 15) - return ((area - 6)* 94 + ch2 - 0xA1); - } - - return -1; -} - -static struct _font_info { - char name [256]; - int def_char; - int pixel; - int ascent; - int descent; - int nr_chars; -} font_info; - -typedef struct _glyph { - int encoding; - int dwidth; - int bbw; - int bbh; - int bbx; - int bby; - unsigned char bitmap [72]; -} glyph_t; - -int main (int argc, char* argv[]) -{ - FILE* fp; - int i; - int width, height; - int bmp_pitch, bmp_size, bmp_pos; - - if (argc < 2) { - printf ("usage: ./makegbrbf < \n"); - return 1; - } - - scanf ("%s\n", font_info.name); - scanf ("%d\n", &font_info.def_char); - scanf ("%d\n", &font_info.pixel); - scanf ("%d\n", &font_info.ascent); - scanf ("%d\n", &font_info.descent); - scanf ("%d\n", &font_info.nr_chars); - - width = font_info.pixel; - height = font_info.ascent + font_info.descent; - bmp_pitch = (width + 7)/8; - bmp_size = bmp_pitch * height; - - if ((fp = fopen (argv[1], "w+")) == NULL) - return 1; - - printf ("font: %s (%dx%d) %d\n", font_info.name, width, height, bmp_size); - - fseek (fp, 94 * 81 * bmp_size - 1, SEEK_SET); - fwrite (" ", 1, 1, fp); - - for (i = 0; i < font_info.nr_chars; i++) { - glyph_t glyph; - int n, j, k, skip_lines, skip_bytes; - int bb_pitch; - unsigned char bb_bmp [72]; - unsigned int bb_lines [24]; - unsigned int index; - - scanf ("%d\n", &glyph.encoding); - scanf ("%d\n", &glyph.dwidth); - scanf ("%d\n", &glyph.bbw); - scanf ("%d\n", &glyph.bbh); - scanf ("%d\n", &glyph.bbx); - scanf ("%d\n", &glyph.bby); - - printf ("enconding: %d (%d, %d, %d, %d)\n", - glyph.encoding, glyph.bbw, glyph.bbh, glyph.bbx, glyph.bby); - - bb_pitch = (glyph.bbw + 7)/8; - n = bb_pitch * glyph.bbh; - - /* read bounding box bitmap */ - for (j = 0; j < n; j++) { - int tmp; - scanf ("%d\n", &tmp); - bb_bmp [j] = (unsigned char)tmp; - } - - for (j = 0; j < glyph.bbh; j++) { - bb_lines [j] = 0; - for (k = 0; k < bb_pitch; k++) - bb_lines [j] |= bb_bmp [j*bb_pitch + k] << ((bb_pitch - k - 1) * 8); - - bb_lines [j] <<= (bmp_pitch - bb_pitch) * 8; - bb_lines [j] >>= glyph.bbx; - } - - skip_lines = height - (glyph.bbh + glyph.bby) - font_info.descent; - skip_bytes = skip_lines * bmp_pitch; - - memset (glyph.bitmap, 0, 72); - for (j = 0; j < glyph.bbh; j++) { - unsigned char* bmp = &glyph.bitmap [skip_bytes + j*bmp_pitch]; - for (k = 0; k < bmp_pitch; k++) - bmp [k] = (unsigned char)(bb_lines [j] >> ((bmp_pitch - k - 1) * 8)); - } - - index = gb_index (glyph.encoding); - if (index >= 0 && index < 7614) { - bmp_pos = bmp_size * index; - fseek (fp, bmp_pos, SEEK_SET); - fwrite (glyph.bitmap, bmp_size, 1, fp); - } - } - - fclose (fp); - return 0; -} - diff --git a/src/font/utils/makepytab.c b/src/font/utils/makepytab.c deleted file mode 100644 index 2821209f..00000000 --- a/src/font/utils/makepytab.c +++ /dev/null @@ -1,205 +0,0 @@ -/* - * This file is part of MiniGUI, a mature cross-platform windowing - * and Graphics User Interface (GUI) support system for embedded systems - * and smart IoT devices. - * - * Copyright (C) 2002~2018, Beijing FMSoft Technologies Co., Ltd. - * Copyright (C) 1998~2002, WEI Yongming - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * Or, - * - * As this program is a library, any link to this program must follow - * GNU General Public License version 3 (GPLv3). If you cannot accept - * GPLv3, you need to be licensed from FMSoft. - * - * If you have got a commercial license of this program, please use it - * under the terms and conditions of the commercial license. - * - * For more information about the commercial license, please refer to - * . - */ -#include -#include -#include -#include - -#include - -#define MAX_NR_PINYIN 10 - -typedef struct _gbhz_pinyin -{ - unsigned short encoding; - unsigned long pinyin [MAX_NR_PINYIN]; -} GBHZ_PINYIN; - -#define MAX_LEN_PINYIN 10 - -typedef struct _pinyin -{ - char pinyin [MAX_LEN_PINYIN]; -} PINYIN; - -#define NR_GBHZ ((0xFF-0xB0) * (0xFF-0xA1)) - -static int max_index; -static GBHZ_PINYIN gbhz_py_tab [NR_GBHZ]; - -static int nr_py; -static PINYIN py_tab [1024]; - -static void output_py_tab (void) -{ - int i; - - printf ("static int nr_pinyin = %d;\n" - "static const char* py_tab [] = {\n", nr_py); - - for (i = 0; i < nr_py; i++) { - printf ("\t\"%s\",\n", py_tab[i].pinyin); - } - - printf ("};\n\n"); -} - -static void output_gbhz_py_tab (void) -{ - int i; - - printf ("#define MAX_NR_PINYIN\t10\n\n"); - - printf ("typedef struct _gbhz_pinyin\n"); - printf ("{\n"); - printf ("\tunsigned short encoding;\n"); - printf ("\tunsigned short def_py;\n"); - printf ("\tunsigned long pinyin [MAX_NR_PINYIN];\n"); - printf ("} GBHZ_PINYIN;\n\n"); - - printf ("static int max_index = %d;\n", max_index); - printf ("static GBHZ_PINYIN gbhz_py_tab [NR_GBHZ] = {\n"); - - for (i = 0; i <= max_index; i++) { - int j; - GBHZ_PINYIN* p = gbhz_py_tab + i; - - printf ("\t{0x%04X /* %c%c */, 0, {", p->encoding, HIBYTE_WORD16 (p->encoding), LOBYTE_WORD16 (p->encoding)); - for (j = 0; j < MAX_NR_PINYIN; j++) { - int no_py, tone; - if (p->pinyin [j] == 0) - break; - printf ("%lu", (p->pinyin [j] << 16) | p->encoding); - no_py = p->pinyin [j] >> 6; - tone = p->pinyin [j] & 0x003F; - printf (" /* %s%d */, ", py_tab [no_py].pinyin, tone); - } - printf ("}},\n"); - } - - printf ("};\n\n"); -} - -static void output_funcs (void) -{ - printf ("\n"); - - printf ("#define NR_GBHZ ((0xFF-0xB0) * (0xFF-0xA1))\n"); - printf ("#define PINYIN_NO(pinyin) (pinyin >> 6)\n"); - printf ("#define PINYIN_TONE(pinyin) (pinyin & 0x003F)\n"); - printf ("\n"); - - printf ("static int gbhz_index (unsigned char ch1, unsigned char ch2)\n"); - printf ("{\n"); - printf ("\treturn ((ch1 - 0xB0) * 94 + ch2 - 0xA1);\n"); - printf ("}\n\n"); -} - -static int gbhz_index (unsigned char ch1, unsigned char ch2) -{ - return ((ch1 - 0xB0) * 94 + ch2 - 0xA1); -} - -static int set_gbhz_pinyin (unsigned char ch1, unsigned char ch2, unsigned short no_py, int tone) -{ - int i, index; - GBHZ_PINYIN* p; - - index = gbhz_index (ch1, ch2); - - if (index < 0 || index >= NR_GBHZ) - return -1; - - if (index > max_index) - max_index = index; - - p = gbhz_py_tab + index; - - p->encoding = MAKEWORD16 (ch2, ch1); - for (i = 0; i < MAX_NR_PINYIN; i++) { - if (p->pinyin [i] == 0) { - p->pinyin [i] = no_py; - p->pinyin [i] <<= 6; - p->pinyin [i] |= (tone & 0x03F); - break; - } - } - - return 0; -} - -int main (int argc, char* argv[]) -{ - FILE* fp; - char c, *tmp; - char line [1024]; - - if ((fp = fopen ("pinyin.gb", "r")) == NULL) - return 1; - - while (feof (fp) == 0) { - fscanf (fp, "%c", &c); - if (isalpha (c)) { - fgets (line + 1, 1023, fp); - line [0] = c; - - tmp = index (line, ','); - *tmp = '\0'; - strcpy (py_tab [nr_py].pinyin, line); - nr_py ++; - } - else if (isdigit (c)) { - fgets (line, 1023, fp); - - tmp = line; - while (*tmp && *tmp != '\n') { - int tone = c - '0'; - - set_gbhz_pinyin (tmp [0], tmp[1], nr_py - 1, tone); - - tmp += 2; - } - } - else - break; - } - - output_funcs (); - output_py_tab (); - output_gbhz_py_tab (); - - fclose (fp); - return 0; -} - diff --git a/src/font/utils/mgbidi-unicode-version.h b/src/font/utils/mgbidi-unicode-version.h new file mode 100644 index 00000000..cc623507 --- /dev/null +++ b/src/font/utils/mgbidi-unicode-version.h @@ -0,0 +1,10 @@ +/* mgbidi-unicode-version.h + * generated by gen-unicode-version + * from the file ReadMe.txt */ + +#define MGBIDI_UNICODE_VERSION "12.0.0" +#define MGBIDI_UNICODE_MAJOR_VERSION 12 +#define MGBIDI_UNICODE_MINOR_VERSION 0 +#define MGBIDI_UNICODE_MICRO_VERSION 0 + +/* End of generated mgbidi-unicode-version.h */ diff --git a/src/font/utils/mkmap-gb18030-ucs.c b/src/font/utils/mkmap-gb18030-ucs.c deleted file mode 100644 index ff5e4657..00000000 --- a/src/font/utils/mkmap-gb18030-ucs.c +++ /dev/null @@ -1,159 +0,0 @@ -/* - * This file is part of MiniGUI, a mature cross-platform windowing - * and Graphics User Interface (GUI) support system for embedded systems - * and smart IoT devices. - * - * Copyright (C) 2002~2018, Beijing FMSoft Technologies Co., Ltd. - * Copyright (C) 1998~2002, WEI Yongming - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * Or, - * - * As this program is a library, any link to this program must follow - * GNU General Public License version 3 (GPLv3). If you cannot accept - * GPLv3, you need to be licensed from FMSoft. - * - * If you have got a commercial license of this program, please use it - * under the terms and conditions of the commercial license. - * - * For more information about the commercial license, please refer to - * . - */ -#include -#include -#include - -static struct _local_to_ucs -{ - unsigned int local; - unsigned int ucs; -} local_to_ucs [65536]; - -static unsigned short* gb18030_ucs_map; - -static int gb18030_index (unsigned int encoding) -{ - unsigned char ch1; - unsigned char ch2; - unsigned char ch3; - unsigned char ch4; - - if (encoding < 0xFFFF) { - ch1 = encoding >> 8; - ch2 = encoding; - if (ch1 >= 0x81 && ch1 <= 0xFE && ch2 >= 0x40 && ch2 <= 0xFE && ch2 != 0x7F) - return ((ch1 - 0x81) * 192 + (ch2 - 0x40)); - else - return -1; - } - else { - ch1 = encoding >> 24; - ch2 = encoding >> 16; - ch3 = encoding >> 8; - ch4 = encoding; - if (ch2 >= 0x30 && ch2 <= 0x39 && ch4 >= 0x30 && ch4 <= 0x39 - && ch1 >= 0x81 && ch1 <= 0xFE && ch3 >= 0x81 && ch3 <= 0xFE) { - return ((126 * 192) + - ((ch1 - 0x81) * 12600 + (ch2 - 0x30) * 1260 + - (ch3 - 0x81) * 10 + (ch4 - 0x30))); - } - else { - fprintf (stderr, "bad char: %x, %x, %x, %x\n", ch1, ch2, ch3, ch4); - return -1; - } - } -} - -int main (void) -{ - int i, count; - int max_index, index; - FILE* fp; - - fp = fopen ("gb18030-unicode.txt", "r"); - if (fp == NULL) { - fprintf (stderr, "mkmap-gb18030-ucs: can not open 'gb18030-unicode.txt' for reading.\n"); - return 1; - } - - max_index = 0; - count = 0; - do { - if (fscanf (fp, "%x %x\n", &local_to_ucs[count].local, &local_to_ucs[count].ucs) == EOF) - break; - - index = gb18030_index (local_to_ucs[count].local); - if (index < 0) { - fprintf (stderr, "mkmap-gb18030-ucs: bad local char: %x\n", local_to_ucs[count].local); - } - - if (index > max_index) - max_index = index; - - count ++; - } while (1); - - fclose (fp); - - printf ("mkmap-gb18030-ucs: read total %d local characters, max index: %d\n", count, max_index); - - gb18030_ucs_map = calloc (max_index, sizeof (unsigned short)); - if (gb18030_ucs_map == NULL) { - fprintf (stderr, "mkmap-gb18030-ucs: insufficiant memory\n"); - return 2; - } - - for (i = 0; i < count; i++) { - index = gb18030_index (local_to_ucs[i].local); - if (index >= 0) { - if (gb18030_ucs_map [index] == 0) - gb18030_ucs_map [index] = local_to_ucs[i].ucs; - else - fprintf (stderr, "mkmap-gb18030-ucs: duplicated index of local char: %x (%d)\n", - local_to_ucs[i].local, index); - } - } - - count = 0; - for (i = 0; i < max_index; i++) { - if (gb18030_ucs_map [i] == 0) { - gb18030_ucs_map [i] = 0x3000; - count ++; - } - } - printf ("mkmap-gb18030-ucs: there are %d empty slots in the map.\n", count); - - if ((fp = fopen ("gb18030unimap.c", "w+")) == NULL) { - fprintf (stderr, "mkmap-gb18030-ucs: can not open 'gb18030unimap.c' for writing.\n"); - return 3; - } - - fprintf (fp, "const unsigned short __mg_gb18030_0_unicode_map [] = {"); - - for (i = 0; i <= max_index; i++) { - if (i % 3 == 0) - fprintf (fp, "\n "); - fprintf (fp, "0x%x, ", gb18030_ucs_map [i]); - } - - fprintf (fp, "\n};\n"); - - fclose (fp); - - free (gb18030_ucs_map); - - return 0; -} - diff --git a/src/font/utils/mkmap-ucs-gb2312.c b/src/font/utils/mkmap-ucs-gb2312.c index a57931e4..dbcf216f 100644 --- a/src/font/utils/mkmap-ucs-gb2312.c +++ b/src/font/utils/mkmap-ucs-gb2312.c @@ -76,7 +76,7 @@ int main (int argc, char* argv[]) for (ch2 = 0xA1; ch2 < 0xFF; ch2++) { index = gb_index (ch1, ch2); if (index >= 0) { - uc16 = gbunicode_map [index]; + uc16 = __mg_gbunicode_map [index]; if (gb_char [uc16].ch1 || gb_char [uc16].ch2) { fprintf (stderr, "WARNING: duplicated value 0x%04X.\n", uc16); @@ -130,7 +130,7 @@ int main (int argc, char* argv[]) } printf ("0x%02x, 0x%02x, ", gb_char [uc16].ch1, gb_char [uc16].ch2); } - printf ("\n};\n", index); + printf ("\n};\n"); } printf ("\n"); @@ -146,7 +146,7 @@ int main (int argc, char* argv[]) } printf ("};\n"); - printf ("#define NR_BYTES_PER_CHAR %d\n", sizeof (struct _gb_char)); + printf ("#define NR_BYTES_PER_CHAR %lu\n", sizeof (struct _gb_char)); printf ("\n"); printf ("/* using binary search */\n"); printf ("const unsigned char* __mg_map_uc16_to_gb (unsigned short uc16)\n"); diff --git a/src/font/utils/packtab.c b/src/font/utils/packtab.c new file mode 100644 index 00000000..4729e089 --- /dev/null +++ b/src/font/utils/packtab.c @@ -0,0 +1,427 @@ +/* PackTab - Pack a static table + * Copyright (C) 2001 Behdad Esfahbod. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library, in a file named COPYING; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + * + * For licensing issues, contact . + */ + +/* + 8 <= N <= 2^21 + int key + 1 <= max_depth <= 21 +*/ + +#include +#include +#include + +#include +#include + +#include "packtab.h" + +typedef signed int uni_table[1024 * 1024 * 2]; +static int n, a, max_depth, digits, tab_width, per_row; +static long N; +signed int def_key; +static uni_table temp, x, perm, *tab; +static long packtab_pow[22], cluster, cmpcluster; +static const char *const *name, *key_type_name, *table_name, *macro_name; +static FILE *f; + +static long +most_binary ( + long min, + long max +) +{ + /* min should be less than max */ + register int i, ii; + + if (min == max) + return max; + + for (i = 21; max < packtab_pow[i]; i--) + ; + ii = i; + while (i && !((min ^ max) & packtab_pow[i])) + i--; + + if (ii == i) + { + /* min is less than half of max */ + for (i = 21 - 1; min < packtab_pow[i]; i--) + ; + i++; + return packtab_pow[i]; + } + + return max & (packtab_pow[i] - 1); +} + +static void +init ( + const signed int *table +) +{ + register int i; + + /* initialize powers of two */ + packtab_pow[0] = 1; + for (i = 1; i <= 21; i++) + packtab_pow[i] = packtab_pow[i - 1] << 1; + + /* reduce number of elements to get a more binary number */ + { + long essen; + + /* find number of essential items */ + essen = N - 1; + while (essen && table[essen] == def_key) + essen--; + essen++; + + N = most_binary (essen, N); + } + + for (n = 21; N % packtab_pow[n]; n--) + ; + digits = (n + 3) / 4; + for (i = 6; i; i--) + if (packtab_pow[i] * (tab_width + 1) < 80) + break; + per_row = packtab_pow[i]; +} + +static int +compare ( + const void *r, + const void *s +) +{ + int i; + for (i = 0; i < cmpcluster; i++) + if (((int *) r)[i] != ((int *) s)[i]) + return ((int *) r)[i] - ((int *) s)[i]; + return 0; +} + +static int lev, best_lev, p[22], best_p[22], nn; +static long c[22], best_c[22], s, best_s; +static long t[22], best_t[22], clusters[22], best_cluster[22]; + +static void +found ( + void +) +{ + int i; + + if (s < best_s) + { + best_s = s; + best_lev = lev; + for (i = 0; i <= lev; i++) + { + best_p[i] = p[i]; + best_c[i] = c[i]; + best_t[i] = t[i]; + best_cluster[i] = clusters[i]; + } + } +} + +static void +bt ( + int node_size +) +{ + long i, j, k, y, sbak; + long key_bytes; + + if (t[lev] == 1) + { + found (); + return; + } + if (lev == max_depth) + return; + + for (i = 1 - t[lev] % 2; i <= nn + (t[lev] >> nn) % 2; i++) + { + nn -= (p[lev] = i); + clusters[lev] = cluster = (i && nn >= 0) ? packtab_pow[i] : t[lev]; + cmpcluster = cluster + 1; + + t[lev + 1] = (t[lev] - 1) / cluster + 1; + for (j = 0; j < t[lev + 1]; j++) + { + memmove (temp + j * cmpcluster, tab[lev] + j * cluster, + cluster * sizeof (tab[lev][0])); + temp[j * cmpcluster + cluster] = j; + } + qsort (temp, t[lev + 1], cmpcluster * sizeof (temp[0]), compare); + for (j = 0; j < t[lev + 1]; j++) + { + perm[j] = temp[j * cmpcluster + cluster]; + temp[j * cmpcluster + cluster] = 0; + } + k = 1; + y = 0; + tab[lev + 1][perm[0]] = perm[0]; + for (j = 1; j < t[lev + 1]; j++) + { + if (compare (temp + y, temp + y + cmpcluster)) + { + k++; + tab[lev + 1][perm[j]] = perm[j]; + } + else + tab[lev + 1][perm[j]] = tab[lev + 1][perm[j - 1]]; + y += cmpcluster; + } + sbak = s; + s += k * node_size * cluster; + c[lev] = k; + + if (s >= best_s) + { + s = sbak; + nn += i; + return; + } + + key_bytes = k * cluster; + key_bytes = key_bytes < 0xff ? 1 : key_bytes < 0xffff ? 2 : 4; + lev++; + bt (key_bytes); + lev--; + + s = sbak; + nn += i; + } +} + +static void +solve ( + void +) +{ + best_lev = max_depth + 2; + best_s = N * a * 2; + lev = 0; + s = 0; + nn = n; + t[0] = N; + bt (a); +} + +static void +write_array ( + long max_key +) +{ + int i, j, k, y, ii, ofs; + const char *key_type; + + if (best_t[lev] == 1) + return; + + nn -= (i = best_p[lev]); + cluster = best_cluster[lev]; + cmpcluster = cluster + 1; + + t[lev + 1] = best_t[lev + 1]; + for (j = 0; j < t[lev + 1]; j++) + { + memmove (temp + j * cmpcluster, tab[lev] + j * cluster, + cluster * sizeof (tab[lev][0])); + temp[j * cmpcluster + cluster] = j; + } + qsort (temp, t[lev + 1], cmpcluster * sizeof (temp[0]), compare); + for (j = 0; j < t[lev + 1]; j++) + { + perm[j] = temp[j * cmpcluster + cluster]; + temp[j * cmpcluster + cluster] = 0; + } + k = 1; + y = 0; + tab[lev + 1][perm[0]] = x[0] = perm[0]; + for (j = 1; j < t[lev + 1]; j++) + { + if (compare (temp + y, temp + y + cmpcluster)) + { + x[k] = perm[j]; + tab[lev + 1][perm[j]] = x[k]; + k++; + } + else + tab[lev + 1][perm[j]] = tab[lev + 1][perm[j - 1]]; + y += cmpcluster; + } + + i = 0; + for (ii = 1; ii < k; ii++) + if (x[ii] < x[i]) + i = ii; + + key_type = !lev ? key_type_name : + max_key <= 0xff ? "PACKTAB_UINT8" : + max_key <= 0xffff ? "PACKTAB_UINT16" : "PACKTAB_UINT32"; + fprintf (f, "static const %s %sLev%d[%ld*%d] = {", key_type, table_name, + best_lev - lev - 1, cluster, k); + ofs = 0; + for (ii = 0; ii < k; ii++) + { + int kk, jj; + fprintf (f, "\n#define %sLev%d_%0*lX 0x%0X", table_name, + best_lev - lev - 1, digits, x[i] * packtab_pow[n - nn], ofs); + kk = x[i] * cluster; + if (!lev) + if (name) + for (j = 0; j < cluster; j++) + { + if (!(j % per_row) && j != cluster - 1) + fprintf (f, "\n "); + fprintf (f, "%*s,", tab_width, name[tab[lev][kk++]]); + } + else + for (j = 0; j < cluster; j++) + { + if (!(j % per_row) && j != cluster - 1) + fprintf (f, "\n "); + fprintf (f, "%*d,", tab_width, tab[lev][kk++]); + } + else + for (j = 0; j < cluster; j++, kk++) + fprintf (f, "\n %sLev%d_%0*lX, /* %0*lX..%0*lX */", table_name, + best_lev - lev, digits, + tab[lev][kk] * packtab_pow[n - nn - best_p[lev]], digits, + x[i] * packtab_pow[n - nn] + j * packtab_pow[n - nn - best_p[lev]], digits, + x[i] * packtab_pow[n - nn] + (j + 1) * packtab_pow[n - nn - best_p[lev]] - + 1); + ofs += cluster; + jj = i; + for (j = 0; j < k; j++) + if (x[j] > x[i] && (x[j] < x[jj] || jj == i)) + jj = j; + i = jj; + } + fprintf (f, "\n};\n\n"); + lev++; + write_array (cluster * k); + lev--; +} + +static void +write_source ( + void +) +{ + int i, j; + + lev = 0; + s = 0; + nn = n; + t[0] = N; + fprintf (f, "\n" "/* *IND" "ENT-OFF* */\n\n"); + write_array (0); + fprintf (f, "/* *IND" "ENT-ON* */\n\n"); + + fprintf (f, "#define %s(x) \\\n", macro_name); + fprintf (f, "\t((x) >= 0x%lx ? ", N); + if (name) + fprintf (f, "%s", name[def_key]); + else + fprintf (f, "%d", def_key); + fprintf (f, " : "); + j = 0; + for (i = best_lev - 1; i >= 0; i--) + { + fprintf (f, " \\\n\t%sLev%d[((x)", table_name, i); + if (j != 0) + fprintf (f, " >> %d", j); + if (i) + fprintf (f, " & 0x%02lx) +", packtab_pow[best_p[best_lev - 1 - i]] - 1); + j += best_p[best_lev - 1 - i]; + } + fprintf (f, ")"); + for (i = 0; i < best_lev; i++) + fprintf (f, "]"); + fprintf (f, ")\n\n"); +} + +static void +write_out ( + void +) +{ + int i; + fprintf (f, "/*\n" + " generated by packtab.c version %d\n\n" + " use %s(key) to access your table\n\n" + " assumed sizeof(%s): %d\n" + " required memory: %ld\n" + " lookups: %d\n" + " partition shape: %s", + packtab_version, macro_name, key_type_name, a, best_s, best_lev, + table_name); + for (i = best_lev - 1; i >= 0; i--) + fprintf (f, "[%ld]", best_cluster[i]); + fprintf (f, "\n" " different table entries:"); + for (i = best_lev - 1; i >= 0; i--) + fprintf (f, " %ld", best_c[i]); + fprintf (f, "\n*/\n"); + write_source (); +} + +int +pack_table ( + const signed int *base, + long key_num, + int key_size, + signed int default_key, + int p_max_depth, + int p_tab_width, + const char *const *p_name, + const char *p_key_type_name, + const char *p_table_name, + const char *p_macro_name, + FILE *out +) +{ + N = key_num; + a = key_size; + def_key = default_key; + max_depth = p_max_depth; + tab_width = p_tab_width; + name = p_name; + key_type_name = p_key_type_name; + table_name = p_table_name; + macro_name = p_macro_name; + f = out; + init (base); + if (!(tab = malloc ((n + 1) * sizeof (tab[0])))) + return 0; + memmove (tab[0], base, N * sizeof (base[0])); + solve (); + write_out (); + free (tab); + return 1; +} + +/* End of packtab.c */ diff --git a/src/font/utils/packtab.h b/src/font/utils/packtab.h new file mode 100644 index 00000000..7ae80f01 --- /dev/null +++ b/src/font/utils/packtab.h @@ -0,0 +1,52 @@ +/* PackTab - Pack a static table + * Copyright (C) 2001 Behdad Esfahbod. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library, in a file named COPYING; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + * + * For licensing issues, contact . + */ + +#ifndef PACKTAB_H +#define PACKTAB_H + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +#define packtab_version 3 + + int pack_table ( + const signed int *base, + long key_num, + int key_size, + signed int default_key, + int max_depth, + int tab_width, + const char *const *name, + const char *key_type_name, + const char *table_name, + const char *macro_name, + FILE *out + ); + +#ifdef __cplusplus +} +#endif + +#endif /* PACKTAB_H */ diff --git a/src/font/utils/qpf2c.c b/src/font/utils/qpf2c.c deleted file mode 100644 index 4607072e..00000000 --- a/src/font/utils/qpf2c.c +++ /dev/null @@ -1,377 +0,0 @@ -/* - * This file is part of MiniGUI, a mature cross-platform windowing - * and Graphics User Interface (GUI) support system for embedded systems - * and smart IoT devices. - * - * Copyright (C) 2002~2018, Beijing FMSoft Technologies Co., Ltd. - * Copyright (C) 1998~2002, WEI Yongming - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * Or, - * - * As this program is a library, any link to this program must follow - * GNU General Public License version 3 (GPLv3). If you cannot accept - * GPLv3, you need to be licensed from FMSoft. - * - * If you have got a commercial license of this program, please use it - * under the terms and conditions of the commercial license. - * - * For more information about the commercial license, please refer to - * . - */ -#include -#include -#include -#include - -#include "qpf2c.h" - -#define LINE_BYTE_NUM 8 -static inline long get_file_size (char* filename) -{ - FILE* fp = fopen (filename, "rb"); - if (fp == NULL) - return 0; - - fseek (fp, 0, SEEK_END); - return ftell (fp); -} - -static inline BOOL init_array (ARRAY* array, int item_size, int item_num) -{ - array->array = malloc (item_size * item_num); - if (! array->array) - return FALSE; - - array->item_size = item_size; - array->item_num = item_num; - array->alloced_num = 0; - return TRUE; -} - -static inline BOOL reinit_array (ARRAY* array, int item_num) -{ - array->array = realloc (array->array, array->item_size * item_num); - if (! array->array) - return FALSE; - - array->item_num = item_num; - return TRUE; -} - -static inline void destroy_array (ARRAY* array) -{ - free (array->array); - array->array = NULL; - array->item_num = 0; - array->alloced_num = 0; -} - -static inline int alloc_from_array (ARRAY* array, int num) -{ - int tmp; - if (array->alloced_num == array->item_num) { - array->item_num = array->item_size * 2 + num; - if (reinit_array (array, array->item_size) == FALSE) - return -1; - } - - tmp = array->alloced_num; - array->alloced_num += num; - return tmp; -} - -static inline void* get_item (ARRAY* array, int index) -{ - if (index >= array->alloced_num) - return NULL; - - return array->array + array->item_size * index; -} - -static int read_node (ARRAY* a_node, ARRAY* a_glyph, uchar** data) -{ - uchar rw, cl; - int flags; - QPF_GLYPHTREE* root; - int root_index; - - root_index = alloc_from_array (a_node, 1); - root = get_item (a_node, root_index); - - rw = **data; (*data)++; - cl = **data; (*data)++; - root->min = (rw << 8) | cl; - - rw = **data; (*data)++; - cl = **data; (*data)++; - root->max = (rw << 8) | cl; - - root->glyph_index = alloc_from_array (a_glyph, root->max-root->min+1); - - flags = **data; (*data)++; - - if (flags & 1) - root->less_tree_index = read_node (a_node, a_glyph, data); - else - root->less_tree_index = -1; - - if (flags & 2) - root->more_tree_index = read_node (a_node, a_glyph, data); - else - root->more_tree_index = -1; - - return root_index; -} - -static void read_metrics (ARRAY* a_node, int node_index, - ARRAY* a_glyph, uchar** data) -{ - int i; - int n; - int glyph_index; - QPF_GLYPHTREE* node; - QPF_GLYPH* glyph; - - if (node_index == -1) - return; - - node = (QPF_GLYPHTREE* ) get_item (a_node, node_index); - n = node->max - node->min + 1; - glyph_index = node->glyph_index; - - for (i = 0; i < n; i++) { - glyph = (QPF_GLYPH*) get_item (a_glyph, glyph_index+i); - glyph->metrics = (QPF_GLYPHMETRICS*) *data; - - *data += sizeof (QPF_GLYPHMETRICS); - } - - read_metrics (a_node, node->less_tree_index, a_glyph, data); - read_metrics (a_node, node->more_tree_index, a_glyph, data); -} - -static void read_data (ARRAY* a_node, int node_index, - ARRAY* a_glyph, uchar** data) -{ - int i; - int n; - int glyph_index; - QPF_GLYPHTREE* node; - QPF_GLYPH* glyph; - - if (node_index == -1) - return; - - node = (QPF_GLYPHTREE* ) get_item (a_node, node_index); - n = node->max - node->min + 1; - glyph_index = node->glyph_index; - - for (i = 0; i < n; i++) { - glyph = (QPF_GLYPH*) get_item (a_glyph, glyph_index+i); - glyph->data = *data; - - *data += glyph->metrics->linestep * glyph->metrics->height; - } - - read_data (a_node, node->less_tree_index, a_glyph, data); - read_data (a_node, node->more_tree_index, a_glyph, data); -} - - -static void build_glyph_tree (ARRAY* a_node, ARRAY* a_glyph, - unsigned char** data) -{ - read_node (a_node, a_glyph, data); - read_metrics (a_node, 0, a_glyph, data); - read_data (a_node, 0, a_glyph, data); -} - -static void printf_data_array (FILE* fp_c, char* prefix, uchar* data, int data_size) -{ - int i; - int j; - int left; - fprintf (fp_c, "static unsigned char %s_data [ ] = {\n", prefix); - for (i=0; ialloced_num; i++) - { - glyph = (QPF_GLYPH*) get_item (a_glyph, i); - - fprintf (fp_c, "\t{(QPF_GLYPHMETRICS*)(%s_data + %d), %s_data + %d},\n", - prefix, ((uchar*)glyph->metrics) - data, - prefix, glyph->data - data); - - } - fprintf (fp_c, "};\n\n"); -} - -static void printf_node_array (FILE* fp_c, char* prefix, ARRAY* a_node) -{ - int i; - QPF_GLYPHTREE* node; - fprintf (fp_c, "static QPF_GLYPHTREE %s_tree [ ] = {\n", prefix); - - for (i=0; ialloced_num; i++) - { - node = (QPF_GLYPHTREE*) get_item (a_node, i); - - fprintf (fp_c, "\t{%d, %d, ", node->min, node->max); - - if (node->less_tree_index == -1 ) - fprintf (fp_c, "NULL, "); - else - fprintf (fp_c, "%s_tree + %d, ", prefix, node->less_tree_index); - - if (node->more_tree_index == -1 ) - fprintf (fp_c, "NULL, "); - else - fprintf (fp_c, "%s_tree + %d, ", prefix, node->more_tree_index); - - fprintf (fp_c, "%s_glyph + %d},\n", prefix, node->glyph_index); - } - - fprintf (fp_c, "};\n\n"); -} - -static void printf_qpfinfo (FILE* fp_c, char* prefix, int height, int width) -{ - fprintf (fp_c, "static QPFINFO %s_info = {\n", prefix); - fprintf (fp_c, "\t%d,\n" - "\t%d,\n" - "\t%d,\n" - "\t(QPFMETRICS*) %s_data,\n" - "\t%s_tree,\n", - width, height, 0, - prefix, prefix); - fprintf (fp_c, "};\n"); - -} - -static BOOL get_c_file_and_array_prefix (char* file_name, - char* c_file_name, char* prefix) -{ - char* cp; - char* point; - - point = strrchr (file_name, '.'); - if (!point || strcmp (point+1, "qpf") != 0) { - fprintf (stderr, "%s --not qpf font\n", file_name); - return FALSE; - } - - strcpy (prefix, "__mgif_qpf_"); - strncpy (prefix+strlen(prefix), file_name, point-file_name); - - for (cp=prefix; *cp; cp++) - { - if (isalnum(*cp) || *cp == '_') - continue; - - *cp = '_'; - } - - strcpy (c_file_name, "qpf_"); - strncpy (c_file_name+strlen(c_file_name), file_name, point-file_name); - strcat (c_file_name, ".c"); - - return TRUE; -} - -BOOL static qpf2c_for_minigui_v3 (char* file_name) -{ - int file_size; - FILE* fp; - FILE* fp_c; - ARRAY a_glyph; - ARRAY a_node; - unsigned char* data; - unsigned char* real_data; - QPFMETRICS* font_metrics; - static char prefix [128]; - static char c_file_name [128]; - - bzero (prefix, 128); - bzero (c_file_name, 128); - if (get_c_file_and_array_prefix (file_name, c_file_name, prefix) - == FALSE) - return FALSE; - - file_size = get_file_size (file_name); - if (file_size <=0) - return FALSE; - - - data = (unsigned char*) malloc (file_size); - init_array (&a_glyph, sizeof(QPF_GLYPH), file_size/sizeof(QPF_GLYPH)); - init_array (&a_node, sizeof(QPF_GLYPHTREE), file_size/sizeof(QPF_GLYPHTREE)); - - fp = fopen (file_name, "rb"); - fp_c = fopen (c_file_name, "w+"); - - fread (data, 1, file_size, fp); - font_metrics = (QPFMETRICS*)data; - real_data = data + sizeof(QPFMETRICS); - - build_glyph_tree (&a_node, &a_glyph, &real_data); - - printf_data_array (fp_c, prefix, data, file_size); - - printf_glyph_array (fp_c, prefix, &a_glyph, data); - printf_node_array (fp_c, prefix, &a_node); - printf_qpfinfo (fp_c, prefix, font_metrics->maxwidth, - font_metrics->ascent + font_metrics->descent); - fclose (fp_c); - printf ("%s -----> %s\n", file_name, c_file_name); - - return TRUE; -} - -int main (int argc, char* argv[]) -{ - int i = 1; - for (i=1; i. - * - * Or, - * - * As this program is a library, any link to this program must follow - * GNU General Public License version 3 (GPLv3). If you cannot accept - * GPLv3, you need to be licensed from FMSoft. - * - * If you have got a commercial license of this program, please use it - * under the terms and conditions of the commercial license. - * - * For more information about the commercial license, please refer to - * . - */ -#ifndef QPF2C_FOR_MINIGUI3_H -#define QPF2C_FOR_MINIGUI3_H - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - - typedef unsigned char Uint8; - typedef signed char Sint8; - typedef int BOOL; - typedef unsigned char uchar; - -#define FALSE 0 -#define TRUE 1 - - -#ifdef __NOUNIX__ - typedef struct _QPF_GLYPHMETRICS -#else - typedef struct __attribute__ ((packed)) _QPF_GLYPHMETRICS -#endif - { - Uint8 linestep; - Uint8 width; - Uint8 height; - Uint8 padding; - - Sint8 bearingx; /* Difference from pen position to glyph's left bbox */ - Uint8 advance; /* Difference between pen positions */ - Sint8 bearingy; /* Used for putting characters on baseline */ - - Sint8 reserved; /* Do not use */ - } QPF_GLYPHMETRICS; - - typedef struct _QPF_GLYPH - { - const QPF_GLYPHMETRICS* metrics; - const unsigned char* data; - } QPF_GLYPH; - - typedef struct _QPF_GLYPHTREE - { - unsigned int min, max; - int less_tree_index; - int more_tree_index; - int glyph_index; - } QPF_GLYPHTREE; - -#ifdef __NOUNIX__ - typedef struct _QPFMETRICS -#else - typedef struct __attribute__ ((packed)) _QPFMETRICS -#endif - { - Sint8 ascent, descent; - Sint8 leftbearing, rightbearing; - Uint8 maxwidth; - Sint8 leading; - Uint8 flags; - Uint8 underlinepos; - Uint8 underlinewidth; - Uint8 reserved3; - } QPFMETRICS; - - typedef struct - { - unsigned int height; - unsigned int width; - - unsigned int file_size; - QPFMETRICS* fm; - - QPF_GLYPHTREE* tree; - } QPFINFO; - - typedef struct _ARRAY{ - void* array; - int item_size; - int item_num; - int alloced_num; - } ARRAY; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif diff --git a/src/font/utils/qpf2upf.c b/src/font/utils/qpf2upf.c deleted file mode 100644 index 95097fff..00000000 --- a/src/font/utils/qpf2upf.c +++ /dev/null @@ -1,707 +0,0 @@ -/* - * This file is part of MiniGUI, a mature cross-platform windowing - * and Graphics User Interface (GUI) support system for embedded systems - * and smart IoT devices. - * - * Copyright (C) 2002~2018, Beijing FMSoft Technologies Co., Ltd. - * Copyright (C) 1998~2002, WEI Yongming - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * Or, - * - * As this program is a library, any link to this program must follow - * GNU General Public License version 3 (GPLv3). If you cannot accept - * GPLv3, you need to be licensed from FMSoft. - * - * If you have got a commercial license of this program, please use it - * under the terms and conditions of the commercial license. - * - * For more information about the commercial license, please refer to - * . - */ -/* -** $Id: qpf2upf.c 8944 2008-1-29 08:29:16Z hejian $ -** -** vi: tabstop=4:expandtab -** -** qpf2c.c: Dump QPF font to in-core C file. -** -** Create date: 2008/01/22 -*/ - - -#include -#include -#include -#include -#include - -#include -#include -#include - - -#define TRUE 1 -#define FALSE 0 -#define LEN_UNIDEVFONT_NAME 127 -#define LEN_VERSION_INFO 16 -#define LEN_VENDER_NAME 16 -#define LEN_DEVFONT_NAME 127 - -#define QPF_FLAG_MODE_SMOOTH 1 - - -typedef int BOOL ; -typedef unsigned char Uint8 ; -typedef signed char Sint8 ; -typedef unsigned short Uint16 ; -typedef unsigned int Uint32 ; - - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/**********************************************/ - -#define FM_SMOOTH 1 - -#ifdef __NOUNIX__ -typedef struct _GLYPHMETRICS { -#else -typedef struct __attribute__ ((packed)) _GLYPHMETRICS { -#endif - Uint8 linestep; - Uint8 width; - Uint8 height; - Uint8 padding; - - Sint8 bearingx; /* Difference from pen position to glyph's left bbox */ - Uint8 advance; /* Difference between pen positions */ - Sint8 bearingy; /* Used for putting characters on baseline */ - - Sint8 reserved; /* Do not use */ -} GLYPHMETRICS; - -typedef struct _GLYPH -{ - const GLYPHMETRICS* metrics; - const unsigned char* data; -} GLYPH; - -typedef struct _GLYPHTREE -{ - unsigned int min, max; - struct _GLYPHTREE* less; - struct _GLYPHTREE* more; - GLYPH* glyph; -} GLYPHTREE; - - -#ifdef __NOUNIX__ -typedef struct _QPFMETRICS -#else -typedef struct __attribute__ ((packed)) _QPFMETRICS -{ -#endif - Sint8 ascent, descent; - Sint8 leftbearing, rightbearing; - Uint8 maxwidth; - Sint8 leading; - Uint8 flags; - Uint8 underlinepos; - Uint8 underlinewidth; - Uint8 reserved3; -} QPFMETRICS; - -typedef struct -{ - char font_name [LEN_UNIDEVFONT_NAME + 1]; - unsigned int height; - unsigned int width; - - unsigned int file_size; - QPFMETRICS* fm; - - GLYPHTREE* tree; -} QPFINFO; - - -BOOL LoadQPFont (const char* file, int fd, QPFINFO* QPFInfo); -void UnloadQPFont (QPFINFO* QPFInfo, int fd); - -/****************upf.h*****************/ - -#ifdef __NOUNIX__ -typedef struct _UPFGLYPH { -#else -typedef struct __attribute__ ((packed)) _UPFGLYPH -{ -#endif - /* BBOX information of the glyph */ - Sint8 bearingx; - Sint8 bearingy; - Uint8 width; - Uint8 height; - /* advance value of the glyph */ - Uint8 pitch; - /* Paddings for alignment */ - Uint8 padding1; - Uint8 advance; - /* The pitch of the bitmap (bytes of one scan line) */ - Uint8 padding2; - /* the index of the glyph bitmap in the bitmap section of this font file. */ - Uint32 bitmap_offset; -}UPFGLYPH; - - -typedef struct _UPFNODE -{ - Uint32 min; - Uint32 max; - Uint32 less_offset; - Uint32 more_offset; - Uint32 glyph_offset; -}UPFNODE; - - -#ifdef __NOUNIX__ -typedef struct _UPFINFO { -#else -typedef struct __attribute__ ((packed)) _UPFINFO -{ -#endif - char font_name [LEN_UNIDEVFONT_NAME + 1]; - - Uint8 width; - Uint8 height; - Sint8 ascent; - Sint8 descent; - Uint8 max_width; - Uint8 underline_pos; - Uint8 underline_width; - Sint8 leading; - Uint8 mono_bitmap; - Uint8 reserved[3]; - Uint32 root_dir; - Uint32 file_size; -}UPFINFO; - -#ifdef __NOUNIX__ -typedef struct _UPFV1_FILE_HEADER{ -#else -typedef struct __attribute__ ((packed)) _UPFV1_FILE_HEADER -{ -#endif - char ver_info [LEN_VERSION_INFO]; - char vender_name [LEN_VENDER_NAME]; - char font_name [LEN_DEVFONT_NAME + 1]; - Uint8 width; - Uint8 height; - Sint8 ascent; - Sint8 descent; - Uint8 max_width; - Uint8 min_width; - Sint8 left_bearing; - Sint8 right_bearing; - Uint8 underline_pos; - Uint8 underline_width; - Sint8 leading; - Uint8 mono_bitmap; - Uint16 endian; - Uint32 off_nodes; - Uint32 off_glyphs; - Uint32 off_bitmaps; - Uint32 len_nodes; - Uint32 len_glyphs; - Uint32 len_bitmaps; - Uint32 nr_glyph; - Uint32 nr_zones; - Uint32 font_size; -} UPFV1_FILE_HEADER; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -/***********************************************************************/ - - -static unsigned off_nodes =0; -static unsigned off_glyphs =0; -static unsigned off_bitmaps =0; - - -//static unsigned len_nodes =0; -//static unsigned len_glyphs =0; -static unsigned len_bitmaps =0; - - -static unsigned nr_nodes =0; -static unsigned nr_glyphs =0; - - -/** ===================================================================== - ** Usage of the tool. - ** ===================================================================== - */ -void help (void) -{ - printf ("################USAGE######################\n"); - printf ("COMMANDLINE :qpf2upf filename fontname \n"); - printf ("EXAMPLE:\n"); - printf ("\t qpf2upf unifont_160_50.qpf upf-unifont-rrncnn-16-16-ISO8859-1,ISO8859-15,GB2312-0,GBK,BIG5,UTF-8\n"); -} - - -/** ===================================================================== - ** Read glyph node of qpf. - ** ===================================================================== - */ -static void readNode (GLYPHTREE* tree, Uint8** data) -{ - Uint8 rw, cl; - int flags, n; - - rw = **data; (*data)++; - cl = **data; (*data)++; - tree->min = (rw << 8) | cl; - - rw = **data; (*data)++; - cl = **data; (*data)++; - tree->max = (rw << 8) | cl; - - flags = **data; (*data)++; - if (flags & 1) - tree->less = (GLYPHTREE*)calloc (1, sizeof (GLYPHTREE)); - else - tree->less = NULL; - - if (flags & 2) - tree->more = (GLYPHTREE*)calloc (1, sizeof (GLYPHTREE)); - else - tree->more = NULL; - - n = tree->max - tree->min + 1; - tree->glyph = calloc (n, sizeof (GLYPH)); - - if (tree->less) - readNode (tree->less, data); - if (tree->more) - readNode (tree->more, data); -} - - -/** ===================================================================== - ** Read glyph metrics of qpf. - ** ===================================================================== - */ - -static void readMetrics (GLYPHTREE* tree, Uint8** data) -{ - int i; - int n = tree->max - tree->min + 1; - - for (i = 0; i < n; i++) { - tree->glyph[i].metrics = (GLYPHMETRICS*) *data; - - *data += sizeof (GLYPHMETRICS); - } - - if (tree->less) - readMetrics (tree->less, data); - if (tree->more) - readMetrics (tree->more, data); -} - - -/** ===================================================================== - ** Read glyph bitmap data of qpf - ** ===================================================================== - */ - -static void readData (GLYPHTREE* tree, Uint8** data) -{ - int i; - int n = tree->max - tree->min + 1; - - for (i = 0; i < n; i++) { - int datasize; - - datasize = tree->glyph[i].metrics->linestep * - tree->glyph[i].metrics->height; - tree->glyph[i].data = *data; *data += datasize; - } - - if (tree->less) - readData (tree->less, data); - if (tree->more) - readData (tree->more, data); -} - - -/** ===================================================================== - ** To build a glyph tree of qpf - ** ===================================================================== - */ - -static void BuildGlyphTree (GLYPHTREE* tree, Uint8** data) -{ - readNode (tree, data); - readMetrics (tree, data); - readData (tree, data); -} - - -/** ===================================================================== - ** Load qpf font from the file name - ** ===================================================================== - */ - -BOOL LoadQPFont (const char* file, int fd, QPFINFO* QPFInfo) -{ - struct stat st; - Uint8* data; - - if ((fd = open (file, O_RDONLY)) < 0) return FALSE; - if (fstat (fd, &st)) return FALSE; - QPFInfo->file_size = st.st_size; - - - QPFInfo->fm = (QPFMETRICS*) mmap( 0, st.st_size, - PROT_READ, MAP_PRIVATE, fd, 0 ); - - if (!QPFInfo->fm || QPFInfo->fm == (QPFMETRICS *)MAP_FAILED) - goto error; - - - QPFInfo->tree = (GLYPHTREE*)calloc (1, sizeof (GLYPHTREE)); - - data = (Uint8*)QPFInfo->fm; - data += sizeof (QPFMETRICS); - BuildGlyphTree (QPFInfo->tree, &data); - - return TRUE; - -error: - munmap (QPFInfo->fm, QPFInfo->file_size); - close (fd); - return FALSE; -} - - - -/** ===================================================================== - ** Clear glyph tree of qpf - ** ===================================================================== - */ - -static void ClearGlyphTree (GLYPHTREE* tree) -{ - if (tree->less) { - ClearGlyphTree (tree->less); - } - if (tree->more) { - ClearGlyphTree (tree->more); - } - - free (tree->glyph); - free (tree->less); - free (tree->more); -} - - -/** ===================================================================== - ** Unload qpf font - ** ===================================================================== - */ - -void UnloadQPFont (QPFINFO* QPFInfo, int fd) -{ - if (QPFInfo->file_size == 0) - return; - - ClearGlyphTree (QPFInfo->tree); - free (QPFInfo->tree); - munmap (QPFInfo->fm, QPFInfo->file_size); - close (fd); -} - - - -/** ===================================================================== - ** Add glyph bitmap data to upf font file - ** ===================================================================== - */ - -static void AddDate (GLYPHTREE* tree, FILE *upfile) -{ - UPFNODE upfnode; - UPFGLYPH upfglyph; - int n, i; - - fread (&upfnode, sizeof (UPFNODE), 1, upfile); - - n = upfnode.max - upfnode.min + 1; - - for (i =0; iglyph[i].data), (upfglyph.height * upfglyph.pitch), 1, upfile ); - } - - if (upfnode.less_offset) - { - fseek (upfile, upfnode.less_offset, SEEK_SET); - AddDate (tree->less, upfile); - } - if (upfnode.more_offset) - { - fseek (upfile, upfnode.more_offset, SEEK_SET); - AddDate (tree->more, upfile); - } - - -} - - -/** ===================================================================== - ** Add glyph information to upf font file - ** ===================================================================== - */ - -static void CreatGlyph (GLYPHTREE* tree, FILE *upfile) -{ - UPFNODE upfnode; - static UPFGLYPH upfglyph; - unsigned int curr_pos; - int n, i; - - curr_pos = ftell (upfile); - fread (&upfnode, sizeof (UPFNODE), 1, upfile); - n = upfnode.max - upfnode.min + 1; - - - fseek (upfile, 0L, SEEK_END ); - upfnode.glyph_offset = ftell (upfile); - - if (off_glyphs== 0) - off_glyphs = ftell (upfile); - - for (i = 0; iglyph[i].metrics->bearingx; - upfglyph.bearingy = tree->glyph[i].metrics->bearingy; - upfglyph.width = tree->glyph[i].metrics->width; - upfglyph.height = tree->glyph[i].metrics->height; - upfglyph.pitch = tree->glyph[i].metrics->linestep; - upfglyph.padding1 = tree->glyph[i].metrics->padding; - upfglyph.advance = tree->glyph[i].metrics->advance; - upfglyph.padding2 = tree->glyph[i].metrics->reserved; - upfglyph.bitmap_offset = 0; - - fwrite ((const void*)&upfglyph, sizeof (UPFGLYPH), 1, upfile ); - } - - fseek (upfile, curr_pos, SEEK_SET); - fwrite ((const void*)&upfnode, sizeof (UPFNODE), 1, upfile); - - if (upfnode.less_offset) - { - fseek (upfile, upfnode.less_offset, SEEK_SET); - CreatGlyph (tree->less, upfile); - } - if (upfnode.more_offset) - { - fseek (upfile, upfnode.more_offset, SEEK_SET); - CreatGlyph (tree->more, upfile); - } - -} - - - -/** ===================================================================== - ** Add glyph UNICODE value area node to upf font file - ** ===================================================================== - */ - -static void CreateNodes (GLYPHTREE* tree, FILE *upfile ) -{ - UPFNODE upfnode; - unsigned int curr_pos; - - curr_pos = ftell (upfile); - upfnode.min = tree->min; - upfnode.max = tree->max; - upfnode.less_offset = 0; - upfnode.more_offset = 0; - - nr_nodes ++; - - if (off_nodes==0) - off_nodes = curr_pos; - - fwrite ((const void*)&upfnode, sizeof (UPFNODE), 1, upfile); - - if (tree->less) - { - upfnode.less_offset = ftell (upfile) ; - fseek (upfile, curr_pos, SEEK_SET ); - fwrite ((const void*)&upfnode, sizeof (UPFNODE), 1, upfile); - fseek (upfile, 0L, SEEK_END); - CreateNodes (tree->less, upfile); - } - - if (tree->more) - { - fseek (upfile, 0L, SEEK_END); - upfnode.more_offset = ftell (upfile); - fseek (upfile, curr_pos, SEEK_SET ); - fwrite ((const void*)&upfnode, sizeof (UPFNODE), 1, upfile); - fseek (upfile, 0L, SEEK_END); - CreateNodes (tree->more, upfile); - } - -} - - - -/** ===================================================================== - ** To Create a upf font file from a qpf font file, use the parameter font_name - ** as the device font name - ** ===================================================================== - */ - -static void CreatUpfFile (QPFINFO *qpfinfo, FILE *upfile ,const char *font_name) -{ - UPFV1_FILE_HEADER upfheade={0}; - Uint32 curr_pos, start_pos; - - sprintf (upfheade.ver_info, "upf-1.0"); - sprintf (upfheade.vender_name, "FMSoft"); - if(font_name) - snprintf (upfheade.font_name, LEN_DEVFONT_NAME, "%s", font_name); - - upfheade.endian = 0x1234 ; - - upfheade.width = qpfinfo->fm->maxwidth; - upfheade.height = qpfinfo->fm->ascent +qpfinfo->fm->descent + qpfinfo->fm->leading; - upfheade.ascent = qpfinfo->fm->ascent; - upfheade.descent = qpfinfo->fm->descent; - upfheade.max_width = qpfinfo->fm->maxwidth ; - upfheade.underline_pos = qpfinfo->fm->underlinepos; - upfheade.underline_width = qpfinfo->fm->underlinewidth; - upfheade.leading = qpfinfo->fm->leading; - upfheade.mono_bitmap = !(qpfinfo->fm->flags & QPF_FLAG_MODE_SMOOTH); - upfheade.off_nodes = sizeof (UPFV1_FILE_HEADER); - - start_pos = ftell (upfile); - fwrite((const void*)&upfheade, sizeof (UPFV1_FILE_HEADER), 1, upfile); - curr_pos = ftell (upfile); - - CreateNodes (qpfinfo->tree, upfile); - fseek (upfile, curr_pos, SEEK_SET); - CreatGlyph (qpfinfo->tree, upfile); - fseek (upfile, curr_pos, SEEK_SET); - AddDate (qpfinfo->tree, upfile); - - fseek (upfile, 0, SEEK_END); - upfheade.font_size = ftell (upfile); - - fseek (upfile, start_pos, SEEK_SET); - - upfheade.off_nodes = off_nodes; - upfheade.off_glyphs = off_glyphs; - upfheade.off_bitmaps = off_bitmaps; - upfheade.len_bitmaps = len_bitmaps; - upfheade.len_nodes = nr_nodes * sizeof (UPFNODE); - upfheade.len_glyphs = nr_glyphs * sizeof (UPFGLYPH); - - fwrite((const void*)&upfheade, sizeof (UPFV1_FILE_HEADER), 1, upfile); - - -} - - -/******************************main*************************************/ - -/** ===================================================================== - ** Main function - ** ===================================================================== - */ - -int main (int args, char *arg[]) -{ - QPFINFO qpfinfo; - char upf_name [128]; - FILE *upf_file; - int fd =0; - char *s,*filename; - - if (args <3) - { - help (); - printf ("Please specify the 'qpf' file and the fontname\n"); - return 1; - } - - filename =strrchr((const char *)arg[1], '/'); - sprintf (upf_name, "%s", filename?(filename+1):arg[1]); - s = strrchr ((const char *)upf_name, '.'); - - if (s==NULL) - { - help (); - printf ("Please specify the 'qpf' file\n"); - return 1; - } - - *s ='\0'; - sprintf (s, "%s", ".upf"); - - if (!LoadQPFont (arg[1], fd, &qpfinfo)) - { - help (); - printf ("Load %s faile !\n", arg[1]); - return 2; - } - - /*****************create upf file********************************/ - upf_file = fopen ((const char *)upf_name, "w+"); - CreatUpfFile (&qpfinfo, upf_file, arg[2]); - fclose (upf_file); - /****************************************************************/ - UnloadQPFont (&qpfinfo, fd); - - - return 0; -} diff --git a/src/font/utils/upf2c.c b/src/font/utils/upf2c.c deleted file mode 100644 index 2b6024e6..00000000 --- a/src/font/utils/upf2c.c +++ /dev/null @@ -1,178 +0,0 @@ -/* - * This file is part of MiniGUI, a mature cross-platform windowing - * and Graphics User Interface (GUI) support system for embedded systems - * and smart IoT devices. - * - * Copyright (C) 2002~2018, Beijing FMSoft Technologies Co., Ltd. - * Copyright (C) 1998~2002, WEI Yongming - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * Or, - * - * As this program is a library, any link to this program must follow - * GNU General Public License version 3 (GPLv3). If you cannot accept - * GPLv3, you need to be licensed from FMSoft. - * - * If you have got a commercial license of this program, please use it - * under the terms and conditions of the commercial license. - * - * For more information about the commercial license, please refer to - * . - */ -/* - * ** vi: tabstop=4:expandtab - * ** - * ** Create date: 2008/01/26 - * */ -#include -#include - - -#define LEN_UNIDEVFONT_NAME 127 -typedef unsigned char Uint8; -typedef char Sint8; -typedef unsigned int Uint32; - -#ifdef __NOUNIX__ -typedef struct -#else -typedef struct __attribute__ ((packed)) -#endif -{ - char font_name [LEN_UNIDEVFONT_NAME + 1]; - - Uint8 width; - Uint8 height; - Sint8 ascent; - Sint8 descent; - Uint8 max_width; - Uint8 underline_pos; - Uint8 underline_width; - Sint8 leading; - Uint8 mono_bitmap; - Uint8 reserved[3]; - Uint32 root_dir; - Uint32 file_size; -} UPFINFO; - - -int main (int arg, char *argv[]) -{ - FILE * tab_file =NULL; - FILE * c_file =NULL; - unsigned int cha; - unsigned int n =0; - char upf_cfile[128],name[256]={0}; - char *s; - - if (arg<4) - { - fprintf (stderr, "Usage: upf2c \n"); - fprintf (stderr, "upf2c unifont_160_50.upf unifont_160_50 upf-unifont-rrncnn-16-16-ISO8859-1,ISO8859-15,GB2312-0,GBK,BIG5,UTF-8 \n"); - return 1; - } - - strcpy(name,"__mgif_upf_"); - strcat(name,argv[2]); - strcpy(upf_cfile,"upf_"); - strcat(upf_cfile,argv[1]); - s = strrchr ((const char *)upf_cfile, '.'); - - if (s==NULL) - { - printf ("Please specify the 'upf' file\n"); - return 1; - } - - *s ='\0'; - sprintf (s, "%s", ".c"); - - tab_file =fopen (argv[1],"rb"); - - if (tab_file==NULL) - { - printf ("Cant open the table file!\n"); - return 2; - } - - c_file =fopen (upf_cfile,"w+"); - s = strrchr ((const char *)upf_cfile, '.'); - *s ='\0'; - fprintf (c_file, "/*\n"); - fprintf (c_file, "** In-core UPF file for %s.\n", name); - fprintf (c_file, "**\n"); - fprintf (c_file, "** This file is created by 'upf2c' by FMSoft (http://www.fmsoft.cn).\n"); - fprintf (c_file, "** Please do not modify it manually.\n"); - fprintf (c_file, "**\n"); - fprintf (c_file, "** Copyright (C) 2018 FMSoft\n"); - fprintf (c_file, "**\n"); - fprintf (c_file, "*/\n"); - - fprintf (c_file, "#include \n"); - fprintf (c_file, "#include \n"); - fprintf (c_file, "\n"); - fprintf (c_file, "#include \"common.h\"\n"); - fprintf (c_file, "#include \"minigui.h\"\n"); - fprintf (c_file, "#include \"gdi.h\"\n"); - fprintf (c_file, "\n"); - fprintf (c_file, "#ifdef _MGFONT_UPF\n"); - fprintf (c_file, "#ifdef _MGINCORE_RES\n"); - fprintf (c_file, "\n"); - fprintf (c_file, "#include \"upf.h\"\n"); - fprintf (c_file, "\n"); - - fprintf (c_file, "static unsigned char %s[] = {\n",upf_cfile ); - cha =0; - - while (1) - { - - if (fread (&cha,1,1,tab_file)!=1) - { - fprintf (c_file, "0x%02x", 0 ); - break; - } - - fprintf (c_file, "0x%02x",cha ); - fprintf (c_file, ", " ); - - if (++n%10==0) - fprintf (c_file, "\n"); - - cha =0; - } - fprintf (c_file, "};\n\n" ); - - fprintf (c_file,"UPFINFO %s = {\n", name); - fprintf (c_file,"\t\"%s\", \n", argv[3]); - fprintf (c_file,"\t0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0},\n"); - fprintf (c_file,"\t%s,%d \n", upf_cfile,n); - fprintf (c_file,"};\n\n"); - - - fprintf (c_file,"#endif /* _MGINCORE_RES */\n"); - fprintf (c_file,"#endif /* _MGFONT_UPF */\n"); - - - printf ("OK! translation is successful! there are %d bytes in the %s.c\n", n, upf_cfile); - - - fclose (tab_file); - fclose (c_file); - return 0; -} - - - diff --git a/src/font/utils/upgradevbf.c b/src/font/utils/upgradevbf.c deleted file mode 100644 index 638e86fc..00000000 --- a/src/font/utils/upgradevbf.c +++ /dev/null @@ -1,532 +0,0 @@ -/* - * This file is part of MiniGUI, a mature cross-platform windowing - * and Graphics User Interface (GUI) support system for embedded systems - * and smart IoT devices. - * - * Copyright (C) 2002~2018, Beijing FMSoft Technologies Co., Ltd. - * Copyright (C) 1998~2002, WEI Yongming - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * Or, - * - * As this program is a library, any link to this program must follow - * GNU General Public License version 3 (GPLv3). If you cannot accept - * GPLv3, you need to be licensed from FMSoft. - * - * If you have got a commercial license of this program, please use it - * under the terms and conditions of the commercial license. - * - * For more information about the commercial license, please refer to - * . - */ -#include -#include -#include -#include "../varbitmap.h" - -#define INFO_DEBUG -#define VAL_DEBUG -#include "my_debug.h" - -typedef int BOOL; -typedef unsigned int Uint32; -typedef unsigned short Uint16; - -#define TRUE 1 -#define FALSE 0 - -#define MGUI_LIL_ENDIAN 1234 -#define MGUI_BIG_ENDIAN 4321 - -/* Assume that the host is little endian */ -#define MGUI_BYTEORDER MGUI_LIL_ENDIAN - -#define VBF_VERSION "vbf-1.0**" -#define VBF_VERSION2 "vbf-2.0**" - -#define LEN_VERSION_INFO 10 -#define LEN_DEVFONT_NAME 79 - -#define LEN_VENDER_INFO 12 - -typedef struct -{ - unsigned char version; /* font version */ - const char* name; /* font name */ - unsigned char max_width; /* max width in pixels */ - unsigned char ave_width; /* average width in pixels */ - int height; /* height in pixels */ - int descent; /* pixels below the base line */ - unsigned char first_char; /* first character in this font */ - unsigned char last_char; /* last character in this font */ - unsigned char def_char; /* default character in this font */ - const unsigned short* offset; /* character glyph offsets into bitmap data or NULL */ - const unsigned char* width; /* character widths or NULL */ - const unsigned char* bits; /* 8-bit right-padded bitmap data */ - unsigned int font_size; /* used by mmap. It should be zero for in-core vbfs. */ - int* bbox_x; - int* bbox_y; - int* bbox_w; - int* bbox_h; -} OLD_VBFINFO; - -typedef struct _NEW_PROPT -{ - char font_name [LEN_DEVFONT_NAME + 1]; - - char max_width; - char ave_width; - char height; - char descent; - - int first_glyph; - int last_glyph; - int def_glyph; -}NEW_PROPT; - -typedef struct _PART_LAYOUT { - Uint32 offset; - Uint32 len; - Uint32 padding; -}PART_LAYOUT; - - -/********************** Load/Unload of var bitmap font ***********************/ -static int LoadVarBitmapFont (const char* file, OLD_VBFINFO* info) -{ -#ifdef HAVE_MMAP - int fd; -#else - FILE* fp; -#endif - char* temp = NULL; - int header_len, len_offsets, len_widths, bits_len, len_bboxs = 0; - int font_size; - char version[LEN_VERSION_INFO + 1]; - -#ifdef HAVE_MMAP - if ((fd = open (file, O_RDONLY)) < 0) - return 0; - - if (read (fd, version, LEN_VERSION_INFO) == -1) - goto error; - version[LEN_VERSION_INFO] = '\0'; - - if (!strcmp (version, VBF_VERSION2)) - info->version = 2; - else - { - info->version = 1; - if (strcmp (version, VBF_VERSION)) - fprintf (stderr, "Error on loading vbf: %s, version: %s, invalid version.\n", file, version); - } - - if (read (fd, &header_len, sizeof (int)) == -1) - goto error; -#if MGUI_BYTEORDER == MGUI_BIG_ENDIAN - header_len = ArchSwap32 (header_len); -#endif - - if (read (fd, &info->max_width, sizeof (char) * 2) == -1) goto error; - if (read (fd, &info->height, sizeof (int) * 2) == -1) goto error; - -#if MGUI_BYTEORDER == MGUI_BIG_ENDIAN - info->height = ArchSwap32 (info->height); - info->descent = ArchSwap32 (info->descent); -#endif - - if (read (fd, &info->first_char, sizeof (char) * 3) == -1) goto error; - - if (lseek (fd, header_len - (((info->version == 2)?5:4) * sizeof (int)), SEEK_SET) == -1) - goto error; - - if (read (fd, &len_offsets, sizeof (int)) == -1 - || read (fd, &len_widths, sizeof (int)) == -1 - || (info->version == 2 && read (fd, &len_bboxs, sizeof (int)) == -1) - || read (fd, &bits_len, sizeof (int)) == -1 - || read (fd, &font_size, sizeof (int)) == -1) - goto error; - -#if MGUI_BYTEORDER == MGUI_BIG_ENDIAN - len_offsets = ArchSwap32 (len_offsets); - len_widths = ArchSwap32 (len_widths); - if (info->version == 2) - len_bboxs = ArchSwap32 (len_bboxs); - bits_len = ArchSwap32 (bits_len); - font_size = ArchSwap32 (font_size); -#endif - - if ((temp = mmap (NULL, font_size, PROT_READ, MAP_SHARED, - fd, 0)) == MAP_FAILED) - goto error; - - temp += header_len; - close (fd); -#else - // Open font file and read information of font. - if (!(fp = fopen (file, "rb"))) - return 0; - - if (fread (version, sizeof (char), LEN_VERSION_INFO, fp) < LEN_VERSION_INFO) - goto error; - version [LEN_VERSION_INFO] = '\0'; - - if (!strcmp (version, VBF_VERSION2)) - info->version = 2; - else - { - info->version = 1; - if (strcmp (version, VBF_VERSION)) - fprintf (stderr, "Error on loading vbf: %s, version: %s, invalid version.\n", file, version); - } - - if (fread (&header_len, sizeof (int), 1, fp) < 1) - goto error; -#if MGUI_BYTEORDER == MGUI_BIG_ENDIAN - header_len = ArchSwap32 (header_len); -#endif - - if (fread (&info->max_width, sizeof (char), 2, fp) < 2) goto error; - if (fread (&info->height, sizeof (int), 2, fp) < 2) goto error; -#if MGUI_BYTEORDER == MGUI_BIG_ENDIAN - info->height = ArchSwap32 (info->height); - info->descent = ArchSwap32 (info->descent); -#endif - if (fread (&info->first_char, sizeof (char), 3, fp) < 3) goto error; - - if (fseek (fp, header_len - (((info->version == 2)?5:4)*sizeof (int)), SEEK_SET) != 0) - goto error; - - if (fread (&len_offsets, sizeof (int), 1, fp) < 1 - || fread (&len_widths, sizeof (int), 1, fp) < 1 - || (info->version == 2 && fread (&len_bboxs, sizeof (int), 1, fp) < 1) - || fread (&bits_len, sizeof (int), 1, fp) < 1 - || fread (&font_size, sizeof (int), 1, fp) < 1) - goto error; -#if MGUI_BYTEORDER == MGUI_BIG_ENDIAN - len_offsets = ArchSwap32 (len_offsets); - len_widths = ArchSwap32 (len_widths); - if (info->version == 2) - len_bboxs = ArchSwap32 (len_bboxs); - bits_len = ArchSwap32 (bits_len); - font_size = ArchSwap32 (font_size); -#endif - - // Allocate memory for font data. - font_size -= header_len; - if ((temp = (char *)malloc (font_size)) == NULL) - goto error; - - if (fseek (fp, header_len, SEEK_SET) != 0) - goto error; - - if (fread (temp, sizeof (char), font_size, fp) < font_size) - goto error; - - fclose (fp); -#endif - info->name = temp; - info->offset = (unsigned short*) (temp + LEN_DEVFONT_NAME + 1); - info->width = (unsigned char*) (temp + LEN_DEVFONT_NAME + 1 + len_offsets); - if (info->version == 2) - { - info->bbox_x = (int*) (temp + LEN_DEVFONT_NAME + 1 + len_offsets + len_widths); - info->bbox_y = (int*) (temp + LEN_DEVFONT_NAME + 1 + len_offsets + len_widths + len_bboxs); - info->bbox_w = (int*) (temp + LEN_DEVFONT_NAME + 1 + len_offsets + len_widths + 2*len_bboxs); - info->bbox_h = (int*) (temp + LEN_DEVFONT_NAME + 1 + len_offsets + len_widths + 3*len_bboxs); - info->bits = (unsigned char*) (temp + LEN_DEVFONT_NAME + 1 + len_offsets + len_widths + 4*len_bboxs); - } - else - info->bits = (unsigned char*) (temp + LEN_DEVFONT_NAME + 1 + len_offsets + len_widths); - info->font_size = font_size; - - return bits_len; - -error: -#ifdef HAVE_MMAP - if (temp) - munmap (temp, font_size); - close (fd); -#else - free (temp); - fclose (fp); -#endif - - return 0; -} - -static void UnloadVarBitmapFont (OLD_VBFINFO* info) -{ -#ifdef HAVE_MMAP - if (info->name) - munmap ((void*)(info->name), info->font_size); -#else - free ((void*)info->name); -#endif -} - -#define LAYOUT_STEP(cur, cur_len, pre)\ - do{\ - (cur).offset = (pre).offset + (pre).len + (pre).padding;\ - (cur).len = (cur_len);\ - (cur).padding = (4 - ((cur).len & 3)) & 3;\ - }while (0) - -#define TEST_LAYOUT(layout)\ - do {\ - TEST_VAL(layout.offset, %x);\ - TEST_VAL(layout.len, %x);\ - TEST_VAL(layout.padding, %x);\ - }while (0) - -static void write_layout (FILE* fp, Uint32 offset, Uint32 len) -{ -#if MGUI_BYTEORDER == MGUI_BIG_ENDIAN - len = ArchSwap32 (len); - offset = ArchSwap32 (offset); -#endif - - fwrite (&offset, sizeof(Uint32), 1, fp); - fwrite (&len, sizeof(Uint32), 1, fp); -} - -static void write_propt (FILE* fp, OLD_VBFINFO* old_info) -{ - NEW_PROPT new_propt; - strncpy (new_propt.font_name, old_info->name, LEN_DEVFONT_NAME); - new_propt.font_name [LEN_DEVFONT_NAME] = '\0'; - - new_propt.max_width = old_info->max_width; - new_propt.ave_width = old_info->ave_width; - new_propt.height = old_info->height; - new_propt.descent = old_info->descent; - - new_propt.first_glyph = old_info->first_char; - new_propt.last_glyph = old_info->last_char; - new_propt.def_glyph = old_info->def_char; -#if MGUI_BYTEORDER == MGUI_BIG_ENDIAN - new_propt.first_glyph = ArchSwap32 (new_propt.first_glyph); - new_propt.last_glyph = ArchSwap32 (new_propt.last_glyph); - new_propt.def_glyph = ArchSwap32 (new_propt.def_glyph); -#endif - - fwrite (&new_propt, sizeof(new_propt), 1, fp); -} - -static void write_bbox (FILE* fp, int* x, int* y, int* w, int* h, int char_num) -{ - VBF_BBOX bbox; - int i; - - for (i=0; i>3; - - for (y = 0, p_line_head = bits; y < height; y++) - { - for (x = 0; x < width; x++) - { - p_cur_char = (x >> 3) + p_line_head; - if (*p_cur_char & (128 >> (x%8))) - printf("@ "); - else - printf(". "); - } - printf("\n"); - - p_line_head += pitch; - } -} - -static int upgrade (char *old_file, char* new_file) -{ - PART_LAYOUT header_layout; - PART_LAYOUT prop_layout; - PART_LAYOUT bbox_layout; - PART_LAYOUT advx_layout; - PART_LAYOUT advy_layout; - PART_LAYOUT bits_off_layout; - PART_LAYOUT glyph_bits_layout; - - char vender_name [LEN_VENDER_INFO]; - char ver_info [LEN_VERSION_INFO]; - - char padding_ch = '\0'; - - Uint32 glyph_bits_len; - Uint16 header_len; - Uint32 font_size; - - FILE* fp; - int tmp; - - OLD_VBFINFO old_info; - Uint32 glyph_num; - - memset (&old_info, 0, sizeof(old_info)); - memset (vender_name, 0, sizeof(vender_name)); - memset (ver_info, 0, sizeof(ver_info)); - - strcpy (vender_name, "FMSoft"); - strcpy (ver_info, "vbf-3.0**"); - - - if ((glyph_bits_len = LoadVarBitmapFont (old_file, &old_info)) == 0) { - fprintf (stderr, "vbf2c: can't load VBF file: %s\n", old_file); - return 2; - } - - print_bitmap (old_info.bits + old_info.offset['A'-old_info.first_char], - old_info.width['A'-old_info.first_char], - old_info.height); - - glyph_num = old_info.last_char - old_info.first_char + 1; - - header_layout.offset = 0; - header_layout.len = 5*sizeof(PART_LAYOUT) - 5*sizeof(int) + - sizeof(int) + sizeof(short) + sizeof(vender_name) + sizeof(ver_info); - TEST_VAL (header_layout.len, %d); - - header_layout.padding = (4 - (header_layout.len & 3)) & 3; - TEST_LAYOUT (header_layout); - - LAYOUT_STEP (prop_layout, sizeof(NEW_PROPT), header_layout); - TEST_LAYOUT (prop_layout); - - /*if old vbf have bbox*/ - tmp = (old_info.bbox_x) ? glyph_num*sizeof(VBF_BBOX) : 0; - LAYOUT_STEP (bbox_layout, tmp, prop_layout); - TEST_LAYOUT (bbox_layout); - /*if old vbf have different width*/ - - tmp = (old_info.offset) ? glyph_num * sizeof(char) : 0; - LAYOUT_STEP (advx_layout, tmp, bbox_layout); - TEST_LAYOUT (advx_layout); - - /*old vfb has not advance_y*/ - LAYOUT_STEP (advy_layout, 0, advx_layout); - TEST_LAYOUT (advy_layout); - - tmp = (old_info.offset) ? glyph_num * sizeof(Uint32) : 0; - LAYOUT_STEP (bits_off_layout, tmp, advy_layout); - TEST_LAYOUT (bits_off_layout); - - LAYOUT_STEP (glyph_bits_layout, glyph_bits_len, bits_off_layout); - TEST_LAYOUT (glyph_bits_layout); - - font_size = glyph_bits_layout.offset + glyph_bits_layout.len; - - fp = fopen (new_file, "wb"); - - fwrite (ver_info, sizeof(ver_info), 1, fp); - fwrite (vender_name, sizeof(vender_name), 1, fp); - - header_len = header_layout.len; -#if MGUI_BYTEORDER == MGUI_BIG_ENDIAN - header_len = ArchSwap16 (header_len); - font_size = ArchSwap32 (font_size); -#endif - fwrite (&(header_len), sizeof(Uint16), 1, fp); - - write_layout (fp, bbox_layout.offset, bbox_layout.len); - write_layout (fp, advx_layout.offset, advx_layout.len); - write_layout (fp, advy_layout.offset, advy_layout.len); - write_layout (fp, bits_off_layout.offset, bits_off_layout.len); - write_layout (fp, glyph_bits_layout.offset, glyph_bits_layout.len); - - fwrite (&font_size, sizeof(Uint32), 1, fp); - fwrite (&padding_ch, 1, header_layout.padding, fp); - - write_propt (fp, &old_info); - fwrite (&padding_ch, 1, prop_layout.padding, fp); - - if (old_info.bbox_x) - { - write_bbox (fp, old_info.bbox_x, old_info.bbox_y, - old_info.bbox_w, old_info.bbox_h, glyph_num); - fwrite (&padding_ch, 1, bbox_layout.padding, fp); - } - - if (old_info.offset) - { - fwrite (old_info.width, 1, glyph_num, fp); - fwrite (&padding_ch, 1, advx_layout.padding, fp); - } - - if (old_info.offset) - { - write_bits_off (fp, old_info.offset, glyph_num); - fwrite (&padding_ch, 1, bits_off_layout.padding, fp); - } - - print_bitmap (old_info.bits + old_info.offset['A'-old_info.first_char], - old_info.width['A'-old_info.first_char], - old_info.height); - - fwrite (old_info.bits, glyph_bits_len, 1, fp); - fclose (fp); - - UnloadVarBitmapFont (&old_info); - - return 0; -} - -int main (int argc, char **argv) -{ - - int i; - if (argc < 1) { - fprintf (stderr, "Usage: upgradevbf \n"); - return 1; - } - - for (i=1; i. - * - * Or, - * - * As this program is a library, any link to this program must follow - * GNU General Public License version 3 (GPLv3). If you cannot accept - * GPLv3, you need to be licensed from FMSoft. - * - * If you have got a commercial license of this program, please use it - * under the terms and conditions of the commercial license. - * - * For more information about the commercial license, please refer to - * . - */ - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -typedef struct -{ - const char* name; /* font name */ - char max_width; /* max width in pixels */ - char ave_width; /* average width in pixels */ - int height; /* height in pixels */ - int descent; /* pixels below the base line */ - unsigned char first_char; /* first character in this font */ - unsigned char last_char; /* last character in this font */ - unsigned char def_char; /* default character in this font */ - unsigned short* offset; /* glyph offsets into bitmap data or NULL */ - unsigned char* width; /* character widths or NULL */ - unsigned char* bits; /* 8-bit right-padded bitmap data */ - int len_bits; /* lenght of bits */ -} VBFINFO; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - diff --git a/src/font/utils/vbf2c.c b/src/font/utils/vbf2c.c deleted file mode 100644 index e217e575..00000000 --- a/src/font/utils/vbf2c.c +++ /dev/null @@ -1,436 +0,0 @@ -/* - * This file is part of MiniGUI, a mature cross-platform windowing - * and Graphics User Interface (GUI) support system for embedded systems - * and smart IoT devices. - * - * Copyright (C) 2002~2018, Beijing FMSoft Technologies Co., Ltd. - * Copyright (C) 1998~2002, WEI Yongming - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * Or, - * - * As this program is a library, any link to this program must follow - * GNU General Public License version 3 (GPLv3). If you cannot accept - * GPLv3, you need to be licensed from FMSoft. - * - * If you have got a commercial license of this program, please use it - * under the terms and conditions of the commercial license. - * - * For more information about the commercial license, please refer to - * . - */ -/* -** vi: tabstop=4:expandtab -** -** vbf2c.c: Dump VBF font to in-core C file. -** -** Create date: 2007/04/24 -*/ - -/* -** TODO: -*/ - -#include -#include -#include - -typedef struct -{ - unsigned char version; /* font version */ - const char* name; /* font name */ - unsigned char max_width; /* max width in pixels */ - unsigned char ave_width; /* average width in pixels */ - int height; /* height in pixels */ - int descent; /* pixels below the base line */ - unsigned char first_char; /* first character in this font */ - unsigned char last_char; /* last character in this font */ - unsigned char def_char; /* default character in this font */ - const unsigned short* offset; /* character glyph offsets into bitmap data or NULL */ - const unsigned char* width; /* character widths or NULL */ - const unsigned char* bits; /* 8-bit right-padded bitmap data */ - unsigned int font_size; /* used by mmap. It should be zero for in-core vbfs. */ - int* bbox_x; - int* bbox_y; - int* bbox_w; - int* bbox_h; -} OLD_VBFINFO; - -#define LEN_VERSION_INFO 10 - -#define VBF_VERSION "vbf-1.0**" -#define VBF_VERSION2 "vbf-2.0**" - -typedef int BOOL; -#define TRUE 1 -#define FALSE 0 - -#define MGUI_LIL_ENDIAN 1234 -#define MGUI_BIG_ENDIAN 4321 - -/* Assume that the host is little endian */ -#define MGUI_BYTEORDER MGUI_LIL_ENDIAN - -#define LEN_DEVFONT_NAME 79 - -/********************** Load/Unload of var bitmap font ***********************/ -static int LoadVarBitmapFont (const char* file, OLD_VBFINFO* info) -{ -#ifdef HAVE_MMAP - int fd; -#else - FILE* fp; -#endif - char* temp = NULL; - int len_header, len_offsets, len_widths, len_bits, len_bboxs = 0; - int font_size; - char version[LEN_VERSION_INFO + 1]; - -#ifdef HAVE_MMAP - if ((fd = open (file, O_RDONLY)) < 0) - return FALSE; - - if (read (fd, version, LEN_VERSION_INFO) == -1) - goto error; - version[LEN_VERSION_INFO] = '\0'; - - if (!strcmp (version, VBF_VERSION2)) - info->version = 2; - else - { - info->version = 1; - if (strcmp (version, VBF_VERSION)) - fprintf (stderr, "Error on loading vbf: %s, version: %s, invalid version.\n", file, version); - } - - if (read (fd, &len_header, sizeof (int)) == -1) - goto error; -#if MGUI_BYTEORDER == MGUI_BIG_ENDIAN - len_header = ArchSwap32 (len_header); -#endif - - if (read (fd, &info->max_width, sizeof (char) * 2) == -1) goto error; - if (read (fd, &info->height, sizeof (int) * 2) == -1) goto error; - -#if MGUI_BYTEORDER == MGUI_BIG_ENDIAN - info->height = ArchSwap32 (info->height); - info->descent = ArchSwap32 (info->descent); -#endif - - if (read (fd, &info->first_char, sizeof (char) * 3) == -1) goto error; - - if (lseek (fd, len_header - (((info->version == 2)?5:4) * sizeof (int)), SEEK_SET) == -1) - goto error; - - if (read (fd, &len_offsets, sizeof (int)) == -1 - || read (fd, &len_widths, sizeof (int)) == -1 - || (info->version == 2 && read (fd, &len_bboxs, sizeof (int)) == -1) - || read (fd, &len_bits, sizeof (int)) == -1 - || read (fd, &font_size, sizeof (int)) == -1) - goto error; -#if MGUI_BYTEORDER == MGUI_BIG_ENDIAN - len_offsets = ArchSwap32 (len_offsets); - len_widths = ArchSwap32 (len_widths); - if (info->version == 2) - len_bboxs = ArchSwap32 (len_bboxs); - len_bits = ArchSwap32 (len_bits); - font_size = ArchSwap32 (font_size); -#endif - - if ((temp = mmap (NULL, font_size, PROT_READ, MAP_SHARED, - fd, 0)) == MAP_FAILED) - goto error; - - temp += len_header; - close (fd); -#else - // Open font file and read information of font. - if (!(fp = fopen (file, "rb"))) - return FALSE; - - if (fread (version, sizeof (char), LEN_VERSION_INFO, fp) < LEN_VERSION_INFO) - goto error; - version [LEN_VERSION_INFO] = '\0'; - - if (!strcmp (version, VBF_VERSION2)) - info->version = 2; - else - { - info->version = 1; - if (strcmp (version, VBF_VERSION)) - fprintf (stderr, "Error on loading vbf: %s, version: %s, invalid version.\n", file, version); - } - - if (fread (&len_header, sizeof (int), 1, fp) < 1) - goto error; -#if MGUI_BYTEORDER == MGUI_BIG_ENDIAN - len_header = ArchSwap32 (len_header); -#endif - - if (fread (&info->max_width, sizeof (char), 2, fp) < 2) goto error; - if (fread (&info->height, sizeof (int), 2, fp) < 2) goto error; -#if MGUI_BYTEORDER == MGUI_BIG_ENDIAN - info->height = ArchSwap32 (info->height); - info->descent = ArchSwap32 (info->descent); -#endif - if (fread (&info->first_char, sizeof (char), 3, fp) < 3) goto error; - - if (fseek (fp, len_header - (((info->version == 2)?5:4)*sizeof (int)), SEEK_SET) != 0) - goto error; - - if (fread (&len_offsets, sizeof (int), 1, fp) < 1 - || fread (&len_widths, sizeof (int), 1, fp) < 1 - || (info->version == 2 && fread (&len_bboxs, sizeof (int), 1, fp) < 1) - || fread (&len_bits, sizeof (int), 1, fp) < 1 - || fread (&font_size, sizeof (int), 1, fp) < 1) - goto error; -#if MGUI_BYTEORDER == MGUI_BIG_ENDIAN - len_offsets = ArchSwap32 (len_offsets); - len_widths = ArchSwap32 (len_widths); - if (info->version == 2) - len_bboxs = ArchSwap32 (len_bboxs); - len_bits = ArchSwap32 (len_bits); - font_size = ArchSwap32 (font_size); -#endif - - // Allocate memory for font data. - font_size -= len_header; - if ((temp = (char *)malloc (font_size)) == NULL) - goto error; - - if (fseek (fp, len_header, SEEK_SET) != 0) - goto error; - - if (fread (temp, sizeof (char), font_size, fp) < font_size) - goto error; - - fclose (fp); -#endif - info->name = temp; - info->offset = (unsigned short*) (temp + LEN_DEVFONT_NAME + 1); - info->width = (unsigned char*) (temp + LEN_DEVFONT_NAME + 1 + len_offsets); - if (info->version == 2) - { - info->bbox_x = (int*) (temp + LEN_DEVFONT_NAME + 1 + len_offsets + len_widths); - info->bbox_y = (int*) (temp + LEN_DEVFONT_NAME + 1 + len_offsets + len_widths + len_bboxs); - info->bbox_w = (int*) (temp + LEN_DEVFONT_NAME + 1 + len_offsets + len_widths + 2*len_bboxs); - info->bbox_h = (int*) (temp + LEN_DEVFONT_NAME + 1 + len_offsets + len_widths + 3*len_bboxs); - info->bits = (unsigned char*) (temp + LEN_DEVFONT_NAME + 1 + len_offsets + len_widths + 4*len_bboxs); - } - else - info->bits = (unsigned char*) (temp + LEN_DEVFONT_NAME + 1 + len_offsets + len_widths); - info->font_size = font_size; - -#if 0 - fprintf (stderr, "VBF: %s-%dx%d-%d (%d~%d:%d).\n", - info->name, info->max_width, info->height, info->descent, - info->first_char, info->last_char, info->def_char); -#endif - - return len_bits; - -error: -#ifdef HAVE_MMAP - if (temp) - munmap (temp, font_size); - close (fd); -#else - free (temp); - fclose (fp); -#endif - - return 0; -} - -static void UnloadVarBitmapFont (OLD_VBFINFO* info) -{ -#ifdef HAVE_MMAP - if (info->name) - munmap ((void*)(info->name), info->font_size); -#else - free ((void*)info->name); -#endif -} - -static void dump_incore_offset (const OLD_VBFINFO* vbf_info) -{ - int ch; - for (ch = vbf_info->first_char; ch <= vbf_info->last_char; ch++) { - printf ("%d, \n", vbf_info->offset[ch]); - } -} - -static void dump_incore_width (const OLD_VBFINFO* vbf_info) -{ - int ch; - for (ch = vbf_info->first_char; ch <= vbf_info->last_char; ch++) { - printf ("%d, \n", vbf_info->width[ch]); - } -} - -static void dump_incore_bits (const OLD_VBFINFO* vbf_info, int len_bits) -{ - int i; - - for (i = 0; i < len_bits; i++) { - if (i % 8 == 0) - printf ("\n\t"); - printf ("0x%02x, ", vbf_info->bits [i]); - } -} - -static void dump_incore_bbox (const OLD_VBFINFO* vbf_info, int which) -{ - int ch; - for (ch = vbf_info->first_char; ch <= vbf_info->last_char; ch++) { - switch (which) { - case 1: - printf ("%d, \n", vbf_info->bbox_x[ch]); - break; - case 2: - printf ("%d, \n", vbf_info->bbox_y[ch]); - break; - case 3: - printf ("%d, \n", vbf_info->bbox_w[ch]); - break; - case 4: - printf ("%d, \n", vbf_info->bbox_h[ch]); - break; - } - } -} - -static void dumpVBF2C (const char* name, const OLD_VBFINFO* vbf_info, int len_bits) -{ - printf ("/*\n"); - printf ("** In-core VBF file for %s.\n", name); - printf ("**\n"); - printf ("** This file is created by 'vbf2c' by FMSoft (http://www.fmsoft.cn).\n"); - printf ("** Please do not modify it manually.\n"); - printf ("**\n"); - printf ("** Copyright (C) 2007 FMSoft\n"); - printf ("**\n"); - printf ("*/\n"); - - printf ("#include \n"); - printf ("#include \n"); - printf ("\n"); - printf ("#include \"common.h\"\n"); - printf ("#include \"minigui.h\"\n"); - printf ("#include \"gdi.h\"\n"); - printf ("\n"); - printf ("#ifdef _VBF_SUPPORT\n"); - printf ("\n"); - printf ("#include \"varbitmap.h\"\n"); - printf ("\n"); - - if (vbf_info->offset) { - printf ("static const unsigned short offset [] = {\n"); - dump_incore_offset (vbf_info); - printf ("};\n\n"); - } - - if (vbf_info->width) { - printf ("static const unsigned char width [] = {\n"); - dump_incore_width (vbf_info); - printf ("};\n\n"); - } - - printf ("static const unsigned char bits [] = {"); - dump_incore_bits (vbf_info, len_bits); - printf ("\n};\n\n"); - - if (vbf_info->version == 2) { - printf ("static const unsigned char bbox_x [] = {\n"); - dump_incore_bbox (vbf_info, 1); - printf ("};\n\n"); - - printf ("static const unsigned char bbox_y [] = {\n"); - dump_incore_bbox (vbf_info, 2); - printf ("};\n\n"); - - printf ("static const unsigned char bbox_w [] = {\n"); - dump_incore_bbox (vbf_info, 3); - printf ("};\n\n"); - - printf ("static const unsigned char bbox_h [] = {\n"); - dump_incore_bbox (vbf_info, 4); - printf ("};\n\n"); - } - - printf ("OLD_VBFINFO %s = {\n", name); - printf ("\t%d, \n", vbf_info->version); - printf ("\t\"%s\", \n", vbf_info->name); - printf ("\t%d, \n", vbf_info->max_width); - printf ("\t%d, \n", vbf_info->ave_width); - printf ("\t%d, \n", vbf_info->height); - printf ("\t%d, \n", vbf_info->descent); - printf ("\t%d, \n", vbf_info->first_char); - printf ("\t%d, \n", vbf_info->last_char); - printf ("\t%d, \n", vbf_info->def_char); - - if (vbf_info->offset) - printf ("\toffset, \n"); - else - printf ("\tNULL, \n"); - - if (vbf_info->width) - printf ("\twidth, \n"); - else - printf ("\tNULL, \n"); - - printf ("\tbits, \n"); - printf ("\t0, \n"); - - if (vbf_info->version == 2) { - printf ("\tbbox_x, \n"); - printf ("\tbbox_x, \n"); - printf ("\tbbox_w, \n"); - printf ("\tbbox_h, \n"); - } - else { - printf ("\tNULL, NULL, NULL, NULL, \n"); - } - printf ("};\n\n"); - - printf ("#endif /* _VBF_SUPPORT */\n"); -} - -int main (int argc, char **argv) -{ - int len_bits; - char name [256]; - OLD_VBFINFO vbf_info; - - if (argc < 3) { - fprintf (stderr, "Usage: vbf2c \n"); - return 1; - } - - if ((len_bits = LoadVarBitmapFont (argv[1], &vbf_info)) == 0) { - fprintf (stderr, "vbf2c: can't load VBF file: %s\n", argv[1]); - return 2; - } - - strcpy (name, "__mgif_vbf_"); - strcat (name, argv[2]); - - dumpVBF2C (name, &vbf_info, len_bits); - - UnloadVarBitmapFont (&vbf_info); - - return 0; -} -