utilities for generating Bidi tables

This commit is contained in:
Vincent Wei
2019-03-10 13:17:52 +08:00
parent 27e508848d
commit fdc449335d
33 changed files with 2507 additions and 4874 deletions
+9
View File
@@ -636,6 +636,10 @@ AC_ARG_ENABLE(unicodesupport,
[ --enable-unicodesupport include UNICODE (ISO-10646-1 and UTF-8 encoding) support <default=yes>],
build_unicode_support=$enableval)
AC_ARG_ENABLE(fullunicode,
[ --enable-fullunicode include support for full UNICODE code points <default=yes>],
build_full_unicode=$enableval)
AC_ARG_ENABLE(kbdhebrewpc,
[ --enable-kbdhebrewpc include keyboard layout for Hebrew PC keyboard <default=no>],
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])
+2 -2
View File
@@ -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) \
@@ -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
+14 -13
View File
@@ -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)
+28 -21
View File
@@ -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
File diff suppressed because it is too large Load Diff
-435
View File
@@ -1,435 +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 <http://www.gnu.org/licenses/>.
*
* 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
* <http://www.minigui.com/en/about/licensing-policy/>.
*/
/*
** $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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#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 <stdio.h>\n");
printf ("#include <stdlib.h>\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 <qpffile> <name> <dev-font-name>\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;
}
-317
View File
@@ -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 <http://www.gnu.org/licenses/>.
*
* 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
* <http://www.minigui.com/en/about/licensing-policy/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <minigui/common.h>
#include <minigui/minigui.h>
#include <minigui/gdi.h>
#include <minigui/window.h>
#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 <dev-font-name> <font-file-name> "
"<small_unicode> [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 <minigui/dti.c>
#endif
-120
View File
@@ -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 <http://www.gnu.org/licenses/>.
*
* 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
* <http://www.minigui.com/en/about/licensing-policy/>.
*/
/*
* 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 <stdio.h>
#include <string.h>
#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;
}
+1 -1
View File
@@ -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
+291
View File
@@ -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 <fribidi.license@gmail.com>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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;
}
+348
View File
@@ -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 <fribidi.license@gmail.com>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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;
}
+335
View File
@@ -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 <fribidi.license@gmail.com>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#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;
}
+225
View File
@@ -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 <fribidi.license@gmail.com>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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;
}
+346
View File
@@ -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 <fribidi.license@gmail.com>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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;
}
+230
View File
@@ -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 <fribidi.license@gmail.com>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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;
}
+181
View File
@@ -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 <fribidi.license@gmail.com>.
*/
#include <common.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#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;
}
-157
View File
@@ -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 <http://www.gnu.org/licenses/>.
*
* 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
* <http://www.minigui.com/en/about/licensing-policy/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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 <rbfname> < <dumpedbdf.txt>\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;
}
-151
View File
@@ -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 <http://www.gnu.org/licenses/>.
*
* 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
* <http://www.minigui.com/en/about/licensing-policy/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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;
}
-171
View File
@@ -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 <http://www.gnu.org/licenses/>.
*
* 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
* <http://www.minigui.com/en/about/licensing-policy/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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 <rbfname> < <dumpedbdf.txt>\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;
}
-205
View File
@@ -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 <http://www.gnu.org/licenses/>.
*
* 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
* <http://www.minigui.com/en/about/licensing-policy/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <minigui/common.h>
#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;
}
+10
View File
@@ -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 */
-159
View File
@@ -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 <http://www.gnu.org/licenses/>.
*
* 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
* <http://www.minigui.com/en/about/licensing-policy/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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;
}
+3 -3
View File
@@ -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");
+427
View File
@@ -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 <fribidi.license@gmail.com>.
*/
/*
8 <= N <= 2^21
int key
1 <= max_depth <= 21
*/
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <memory.h>
#include <string.h>
#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 */
+52
View File
@@ -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 <fribidi.license@gmail.com>.
*/
#ifndef PACKTAB_H
#define PACKTAB_H
#include <stdio.h>
#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 */
-377
View File
@@ -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 <http://www.gnu.org/licenses/>.
*
* 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
* <http://www.minigui.com/en/about/licensing-policy/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#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; i<data_size; i+=LINE_BYTE_NUM)
{
fprintf (fp_c, "\t");
for (j=0; j<LINE_BYTE_NUM; j++)
{
fprintf (fp_c, "0x%.2x, ", *data);
data++;
}
fprintf (fp_c, "\n");
}
left = data_size % LINE_BYTE_NUM;
fprintf (fp_c, "\t");
for (i=0; i<left; i++)
{
fprintf (fp_c, "0x%x, ", *data);
data++;
}
fprintf (fp_c, "};\n\n");
}
static void printf_glyph_array (FILE* fp_c, char* prefix, ARRAY* a_glyph, uchar* data)
{
int i;
QPF_GLYPH* glyph;
fprintf (fp_c, "static QPF_GLYPH %s_glyph [ ] = {\n", prefix);
for (i=0; i<a_glyph->alloced_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; i<a_node->alloced_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<argc; i++)
qpf2c_for_minigui_v3 (argv[i]);
return 0;
}
-120
View File
@@ -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 <http://www.gnu.org/licenses/>.
*
* 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
* <http://www.minigui.com/en/about/licensing-policy/>.
*/
#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
File diff suppressed because it is too large Load Diff
-178
View File
@@ -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 <http://www.gnu.org/licenses/>.
*
* 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
* <http://www.minigui.com/en/about/licensing-policy/>.
*/
/*
* ** vi: tabstop=4:expandtab
* **
* ** Create date: 2008/01/26
* */
#include <stdio.h>
#include <string.h>
#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 <upffile> <name> <dev-font-name>\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 <stdio.h>\n");
fprintf (c_file, "#include <stdlib.h>\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;
}
File diff suppressed because it is too large Load Diff
-58
View File
@@ -1,58 +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 <http://www.gnu.org/licenses/>.
*
* 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
* <http://www.minigui.com/en/about/licensing-policy/>.
*/
#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 */
-436
View File
@@ -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 <http://www.gnu.org/licenses/>.
*
* 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
* <http://www.minigui.com/en/about/licensing-policy/>.
*/
/*
** vi: tabstop=4:expandtab
**
** vbf2c.c: Dump VBF font to in-core C file.
**
** Create date: 2007/04/24
*/
/*
** TODO:
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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 <stdio.h>\n");
printf ("#include <stdlib.h>\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 <vbffile> <name>\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;
}