generate internal font from glyph data on demand

This commit is contained in:
Vincent Sanders 2014-08-17 23:49:06 +01:00
parent ea1e68feba
commit 98a4985b30
4 changed files with 174 additions and 6252 deletions

File diff suppressed because it is too large Load Diff

View File

@ -70,11 +70,6 @@ endif
# built-in resource setup
# ----------------------------------------------------------------------------
# We make convert_image depend on fb_bitmap.h so that if we change
# that header, we get new images built just in case.
$(TOOLROOT)/convert_image: $(TOOLROOT)/created framebuffer/convert_image.c framebuffer/fbtk.h
$(VQ)echo " HOST CC: $@"
$(Q)$(HOST_CC) -o $@ framebuffer/convert_image.c -lpng
FB_IMAGE_left_arrow := framebuffer/res/icons/back.png
FB_IMAGE_right_arrow := framebuffer/res/icons/forward.png
@ -112,6 +107,14 @@ FB_IMAGE_throbber6 := framebuffer/res/throbber/throbber6.png
FB_IMAGE_throbber7 := framebuffer/res/throbber/throbber7.png
FB_IMAGE_throbber8 := framebuffer/res/throbber/throbber8.png
# Host tool to convert image bitmaps to source code.
#
# convert_image dependd on fb_bitmap.h so that if we change that
# header, we get new images built.
$(TOOLROOT)/convert_image: $(TOOLROOT)/created framebuffer/convert_image.c framebuffer/fbtk.h
$(VQ)echo " HOST CC: $@"
$(Q)$(HOST_CC) -o $@ framebuffer/convert_image.c -lpng
# 1: input file
# 2: output file
# 3: bitmap name
@ -126,7 +129,34 @@ endef
S_IMAGES :=
$(eval $(foreach V,$(filter FB_IMAGE_%,$(.VARIABLES)),$(call convert_image,$($(V)),$(OBJROOT)/$(patsubst FB_IMAGE_%,%,$(V)).c,$(patsubst FB_IMAGE_%,%,$(V)))))
$(eval $(foreach V,$(filter FB_IMAGE_%,$(.VARIABLES)),$(call convert_image,$($(V)),$(OBJROOT)/image-$(patsubst FB_IMAGE_%,%,$(V)).c,$(patsubst FB_IMAGE_%,%,$(V)))))
# Internal fonts to generate
FB_FONT_internal_core := framebuffer/res/fonts/glyph_data
# Internal font conversion
$(TOOLROOT)/convert_font: $(TOOLROOT)/created framebuffer/convert_font.c
$(VQ)echo " HOST CC: $@"
$(Q)$(HOST_CC) -o $@ framebuffer/convert_font.c
# 1: input file
# 2: output source code file
# 3: output header file
# 4: font name
define convert_font
S_FONTS += $(2)
$(2): $(1) $(TOOLROOT)/convert_font
$(VQ)echo " FONT: $(1) ($(4))"
$(Q)$(TOOLROOT)/convert_font -H $(3) $(1) $(2)
endef
S_FONTS :=
$(eval $(foreach V,$(filter FB_FONT_$(NETSURF_FB_FONTLIB)_%,$(.VARIABLES)),$(call convert_font,$($(V)),$(OBJROOT)/font-$(patsubst FB_FONT_$(NETSURF_FB_FONTLIB)_%,%,$(V)).c,$(OBJROOT)/font-$(patsubst FB_FONT_$(NETSURF_FB_FONTLIB)_%,%,$(V)).h,$(patsubst FB_FONT_$(NETSURF_FB_FONTLIB)_%,%,$(V)))))
# ----------------------------------------------------------------------------
# Source file setup
@ -147,7 +177,7 @@ S_FRAMEBUFFER := $(addprefix framebuffer/,$(S_FRAMEBUFFER)) $(addprefix framebuf
# This is the final source build list
# Note this is deliberately *not* expanded here as common and image
# are not yet available
SOURCES = $(S_COMMON) $(S_IMAGE) $(S_BROWSER) $(S_FRAMEBUFFER) $(S_IMAGES)
SOURCES = $(S_COMMON) $(S_IMAGE) $(S_BROWSER) $(S_FRAMEBUFFER) $(S_IMAGES) $(S_FONTS)
EXETARGET := nsfb
# ----------------------------------------------------------------------------

View File

@ -1,9 +1,30 @@
/*
* Copyright 2014 Michael Drake <tlsa@netsurf-browser.org>
* Copyright 2014 Vincent Sanders <vince@netsurf-browser.org>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
* NetSurf 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; version 2 of the License.
*
* NetSurf 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/>.
*/
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <unistd.h>
#include <getopt.h>
#define GLYPH_LEN 16
#define BUCKETS 512
@ -250,6 +271,41 @@ struct font_data {
int glyphs;
};
bool generate_font_header(const char *path, struct font_data *data)
{
FILE *fp;
int s;
fp = fopen(path, "wb");
if (fp == NULL) {
LOG(LOG_ERROR, "Couldn't open header file \"%s\"\n", path);
return false;
}
fprintf(fp, "/*\n");
fwrite(data->header, 1, data->header_len, fp);
fprintf(fp, " */\n\n");
fprintf(fp, "/* Don't edit this file, it was generated from the "
"plain text source data. */\n\n");
for (s = 0; s < 4; s++) {
fprintf(fp, "const uint8_t *%s_section_table;\n",
var_lables[s]);
fprintf(fp, "const uint16_t *%s_sections;\n",
var_lables[s]);
}
fprintf(fp, "const uint8_t *font_glyph_data;\n");
fprintf(fp, "\n\n");
fclose(fp);
return true;
}
bool generate_font_source(const char *path, struct font_data *data)
{
@ -335,7 +391,6 @@ bool generate_font_source(const char *path, struct font_data *data)
fprintf(fp, "};\n\n");
fclose(fp);
return true;
@ -1049,24 +1104,11 @@ bool load_font(const char *path, struct font_data **data)
return true;
}
int main(int argc, char** argv)
static void log_usage(const char *argv0)
{
const char *in_path = NULL;
const char *out_path = NULL;
struct font_data *data;
bool ok;
int i;
level = LOG_RESULT;
/* Handle program arguments */
for (i = 1; i < argc; i++) {
if (argv[i][0] == '-') {
if (strcmp(argv[i], "-h") == 0 ||
strcmp(argv[i], "--help") == 0) {
level = LOG_INFO;
LOG(LOG_INFO, "Usage:\n"
LOG(LOG_INFO,
"Usage:\n"
"\t%s [options] <in_file> <out_file>\n"
"\n"
"Options:\n"
@ -1074,34 +1116,65 @@ int main(int argc, char** argv)
"\t--quiet -q Don't show warnings\n"
"\t--verbose -v Verbose output\n"
"\t--debug -d Full debug output\n",
argv[0]);
return EXIT_SUCCESS;
} if (argc >= 3 && (strcmp(argv[i], "-v") == 0 ||
strcmp(argv[i], "--verbose") == 0)) {
level = LOG_INFO;
} else if (argc >= 3 && (strcmp(argv[i], "-d") == 0 ||
strcmp(argv[i], "--debug") == 0)) {
level = LOG_DEBUG;
} else if (argc >= 3 && (strcmp(argv[i], "-q") == 0 ||
strcmp(argv[i], "--quiet") == 0)) {
argv0);
}
int main(int argc, char** argv)
{
const char *in_path = NULL;
const char *out_path = NULL;
char *header_path = NULL;
struct font_data *data;
bool ok;
int i;
int opt;
level = LOG_RESULT;
/* Handle program arguments */
struct option long_options[] = {
{ "help", no_argument, NULL, 'h' },
{ "quiet", no_argument, NULL, 'q' },
{ "verbose", no_argument, NULL, 'v' },
{ "debug", no_argument, NULL, 'd' },
{ "header", required_argument, NULL, 'H' },
};
while ((opt = getopt_long(argc, argv, "hqvdH:", long_options, NULL)) != -1) {
switch (opt) {
case 'q':
level = LOG_WARNING;
}
break;
continue;
}
case 'v':
level = LOG_INFO;
break;
if (in_path == NULL)
in_path = argv[i];
else
out_path = argv[i];
}
case 'd':
level = LOG_DEBUG;
break;
if (in_path == NULL || out_path == NULL) {
LOG(LOG_ERROR, "Usage:\n"
"\t%s [options] <in_file> <out_file>\n",
argv[0]);
case 'H':
header_path = strdup(optarg);
break;
case 'h':
log_usage(argv[0]);
return EXIT_SUCCESS;
default:
log_usage(argv[0]);
return EXIT_FAILURE;
}
}
if ((argc - optind) < 2) {
log_usage(argv[0]);
return EXIT_FAILURE;
}
in_path = argv[optind];
out_path = argv[optind + 1];
LOG(LOG_DEBUG, "Using input path: \"%s\"\n", in_path);
LOG(LOG_DEBUG, "Using output path: \"%s\"\n", out_path);
@ -1113,6 +1186,9 @@ int main(int argc, char** argv)
}
ok = generate_font_source(out_path, data);
if (ok && (header_path != NULL)) {
ok = generate_font_header(header_path, data);
}
free_table();
for (i = 0; i < 4; i++) {
free(data->sections[i]);
@ -1124,4 +1200,3 @@ int main(int argc, char** argv)
return EXIT_SUCCESS;
}

View File

@ -30,8 +30,7 @@
#include "framebuffer/gui.h"
#include "framebuffer/font.h"
#include "framebuffer/GEN_font_internal.c"
#include <font-core.h>
#define GLYPH_LEN 16