Removed extra files for transition to upstream

This commit is contained in:
Rebekah 2022-04-05 11:27:31 -04:00
parent 7132d84fa2
commit c3c3678aa6
Signed by: oneechanhax
GPG Key ID: 183EB7902964DAE5
6 changed files with 55 additions and 867 deletions

View File

@ -1,7 +1,6 @@
target_sources(glez PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/distance-field.h"
"${CMAKE_CURRENT_LIST_DIR}/distance-field.c"
"${CMAKE_CURRENT_LIST_DIR}/edtaa3func.h"
"${CMAKE_CURRENT_LIST_DIR}/font-manager.h"
"${CMAKE_CURRENT_LIST_DIR}/freetype-gl.h"
"${CMAKE_CURRENT_LIST_DIR}/markup.h"
"${CMAKE_CURRENT_LIST_DIR}/mat4.h"
@ -17,13 +16,9 @@ target_sources(glez PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/vertex-buffer.h")
target_sources(glez PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/distance-field.c"
"${CMAKE_CURRENT_LIST_DIR}/edtaa3func.c"
"${CMAKE_CURRENT_LIST_DIR}/font-manager.c"
"${CMAKE_CURRENT_LIST_DIR}/makefont.c"
"${CMAKE_CURRENT_LIST_DIR}/edtaa3func.c"
"${CMAKE_CURRENT_LIST_DIR}/distance-field.c"
"${CMAKE_CURRENT_LIST_DIR}/mat4.c"
"${CMAKE_CURRENT_LIST_DIR}/platform.c"
"${CMAKE_CURRENT_LIST_DIR}/text-buffer.c"
"${CMAKE_CURRENT_LIST_DIR}/texture-atlas.c"
"${CMAKE_CURRENT_LIST_DIR}/texture-font.c"
"${CMAKE_CURRENT_LIST_DIR}/utf8-utils.c"

View File

@ -1,28 +0,0 @@
Copyright 2011-2016 Nicolas P. Rougier
Copyright 2013-2016 Marcel Metz
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are
those of the authors and should not be interpreted as representing official
policies, either expressed or implied, of the freetype-gl project.

View File

@ -9,81 +9,80 @@
#include <string.h>
#include "edtaa3func.h"
double *make_distance_mapd(double *data, unsigned int width,
unsigned int height)
double *
make_distance_mapd( double *data, unsigned int width, unsigned int height )
{
short *xdist = (short *) malloc(width * height * sizeof(short));
short *ydist = (short *) malloc(width * height * sizeof(short));
double *gx = (double *) calloc(width * height, sizeof(double));
double *gy = (double *) calloc(width * height, sizeof(double));
double *outside = (double *) calloc(width * height, sizeof(double));
double *inside = (double *) calloc(width * height, sizeof(double));
double vmin = DBL_MAX;
short * xdist = (short *) malloc( width * height * sizeof(short) );
short * ydist = (short *) malloc( width * height * sizeof(short) );
double * gx = (double *) calloc( width * height, sizeof(double) );
double * gy = (double *) calloc( width * height, sizeof(double) );
double * outside = (double *) calloc( width * height, sizeof(double) );
double * inside = (double *) calloc( width * height, sizeof(double) );
double vmin = DBL_MAX;
unsigned int i;
// Compute outside = edtaa3(bitmap); % Transform background (0's)
computegradient(data, width, height, gx, gy);
computegradient( data, width, height, gx, gy);
edtaa3(data, gx, gy, width, height, xdist, ydist, outside);
for (i = 0; i < width * height; ++i)
if (outside[i] < 0.0)
for( i=0; i<width*height; ++i)
if( outside[i] < 0.0 )
outside[i] = 0.0;
// Compute inside = edtaa3(1-bitmap); % Transform foreground (1's)
memset(gx, 0, sizeof(double) * width * height);
memset(gy, 0, sizeof(double) * width * height);
for (i = 0; i < width * height; ++i)
memset( gx, 0, sizeof(double)*width*height );
memset( gy, 0, sizeof(double)*width*height );
for( i=0; i<width*height; ++i)
data[i] = 1 - data[i];
computegradient(data, width, height, gx, gy);
edtaa3(data, gx, gy, width, height, xdist, ydist, inside);
for (i = 0; i < width * height; ++i)
if (inside[i] < 0)
computegradient( data, width, height, gx, gy );
edtaa3( data, gx, gy, width, height, xdist, ydist, inside );
for( i=0; i<width*height; ++i )
if( inside[i] < 0 )
inside[i] = 0.0;
// distmap = outside - inside; % Bipolar distance field
for (i = 0; i < width * height; ++i)
for( i=0; i<width*height; ++i)
{
outside[i] -= inside[i];
if (outside[i] < vmin)
if( outside[i] < vmin )
vmin = outside[i];
}
vmin = fabs(vmin);
for (i = 0; i < width * height; ++i)
for( i=0; i<width*height; ++i)
{
double v = outside[i];
if (v < -vmin)
outside[i] = -vmin;
else if (v > +vmin)
outside[i] = +vmin;
data[i] = (outside[i] + vmin) / (2 * vmin);
if ( v < -vmin) outside[i] = -vmin;
else if( v > +vmin) outside[i] = +vmin;
data[i] = (outside[i]+vmin)/(2*vmin);
}
free(xdist);
free(ydist);
free(gx);
free(gy);
free(outside);
free(inside);
free( xdist );
free( ydist );
free( gx );
free( gy );
free( outside );
free( inside );
return data;
}
unsigned char *make_distance_mapb(unsigned char *img, unsigned int width,
unsigned int height)
unsigned char *
make_distance_mapb( unsigned char *img,
unsigned int width, unsigned int height )
{
double *data = (double *) calloc(width * height, sizeof(double));
unsigned char *out =
(unsigned char *) malloc(width * height * sizeof(unsigned char));
double * data = (double *) calloc( width * height, sizeof(double) );
unsigned char *out = (unsigned char *) malloc( width * height * sizeof(unsigned char) );
unsigned int i;
// find minimimum and maximum values
// find minimum and maximum values
double img_min = DBL_MAX;
double img_max = DBL_MIN;
for (i = 0; i < width * height; ++i)
for( i=0; i<width*height; ++i)
{
double v = img[i];
data[i] = v;
data[i] = v;
if (v > img_max)
img_max = v;
if (v < img_min)
@ -91,16 +90,16 @@ unsigned char *make_distance_mapb(unsigned char *img, unsigned int width,
}
// Map values from 0 - 255 to 0.0 - 1.0
for (i = 0; i < width * height; ++i)
data[i] = (img[i] - img_min) / img_max;
for( i=0; i<width*height; ++i)
data[i] = (img[i]-img_min)/img_max;
data = make_distance_mapd(data, width, height);
// map values from 0.0 - 1.0 to 0 - 255
for (i = 0; i < width * height; ++i)
out[i] = (unsigned char) (255 * (1 - data[i]));
for( i=0; i<width*height; ++i)
out[i] = (unsigned char)(255*(1-data[i]));
free(data);
free( data );
return out;
}

View File

@ -8,8 +8,7 @@
#ifdef __cplusplus
extern "C" {
namespace ftgl
{
namespace ftgl {
#endif
/**
@ -50,11 +49,13 @@ namespace ftgl
* be freed after usage.
*
*/
double *make_distance_mapd(double *img, unsigned int width,
unsigned int height);
double *
make_distance_mapd( double *img,
unsigned int width, unsigned int height );
unsigned char *make_distance_mapb(unsigned char *img, unsigned int width,
unsigned int height);
unsigned char *
make_distance_mapb( unsigned char *img,
unsigned int width, unsigned int height );
/** @} */

View File

@ -1,232 +0,0 @@
/* Freetype GL - A C OpenGL Freetype engine
*
* Distributed under the OSI-approved BSD 2-Clause License. See accompanying
* file `LICENSE` for more details.
*/
#if 0
#if !defined(_WIN32) && !defined(_WIN64)
#include <fontconfig/fontconfig.h>
#endif
#endif
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "font-manager.h"
// ------------------------------------------------------------ file_exists ---
static int file_exists(const char *filename)
{
FILE *file = fopen(filename, "r");
if (file)
{
fclose(file);
return 1;
}
return 0;
}
// ------------------------------------------------------- font_manager_new ---
font_manager_t *font_manager_new(size_t width, size_t height, size_t depth)
{
font_manager_t *self;
texture_atlas_t *atlas = texture_atlas_new(width, height, depth);
self = (font_manager_t *) malloc(sizeof(font_manager_t));
if (!self)
{
fprintf(stderr, "line %d: No more memory for allocating data\n",
__LINE__);
exit(EXIT_FAILURE);
}
self->atlas = atlas;
self->fonts = vector_new(sizeof(texture_font_t *));
self->cache = strdup(" ");
return self;
}
// ---------------------------------------------------- font_manager_delete ---
void font_manager_delete(font_manager_t *self)
{
if (self)
{
size_t i;
texture_font_t *font;
for (i = 0; i < vector_size(self->fonts); ++i)
{
font = *(texture_font_t **) vector_get(self->fonts, i);
texture_font_delete(font);
}
vector_delete(self->fonts);
texture_atlas_delete(self->atlas);
if (self->cache)
{
free(self->cache);
}
free(self);
}
}
// ----------------------------------------------- font_manager_delete_font ---
void font_manager_delete_font(font_manager_t *self, texture_font_t *font)
{
size_t i;
texture_font_t *other;
assert(self);
assert(font);
for (i = 0; i < self->fonts->size; ++i)
{
other = (texture_font_t *) vector_get(self->fonts, i);
if ((strcmp(font->filename, other->filename) == 0) &&
(font->size == other->size))
{
vector_erase(self->fonts, i);
break;
}
}
texture_font_delete(font);
}
// ----------------------------------------- font_manager_get_from_filename ---
texture_font_t *font_manager_get_from_filename(font_manager_t *self,
const char *filename,
const float size)
{
size_t i;
texture_font_t *font;
assert(self);
for (i = 0; i < vector_size(self->fonts); ++i)
{
font = *(texture_font_t **) vector_get(self->fonts, i);
if ((strcmp(font->filename, filename) == 0) && (font->size == size))
{
return font;
}
}
font = texture_font_new_from_file(self->atlas, size, filename);
if (font)
{
vector_push_back(self->fonts, &font);
texture_font_load_glyphs(font, self->cache);
return font;
}
fprintf(stderr, "Unable to load \"%s\" (size=%.1f)\n", filename, size);
return 0;
}
// ----------------------------------------- font_manager_get_from_description
// ---
texture_font_t *font_manager_get_from_description(font_manager_t *self,
const char *family,
const float size,
const int bold,
const int italic)
{
texture_font_t *font;
char *filename = 0;
assert(self);
if (file_exists(family))
{
filename = strdup(family);
}
else
{
#if defined(_WIN32) || defined(_WIN64)
fprintf(stderr,
"\"font_manager_get_from_description\" not implemented yet.\n");
return 0;
#endif
filename =
font_manager_match_description(self, family, size, bold, italic);
if (!filename)
{
fprintf(
stderr,
"No \"%s (size=%.1f, bold=%d, italic=%d)\" font available.\n",
family, size, bold, italic);
return 0;
}
}
font = font_manager_get_from_filename(self, filename, size);
free(filename);
return font;
}
// ------------------------------------------- font_manager_get_from_markup ---
texture_font_t *font_manager_get_from_markup(font_manager_t *self,
const markup_t *markup)
{
assert(self);
assert(markup);
return font_manager_get_from_description(self, markup->family, markup->size,
markup->bold, markup->italic);
}
// ----------------------------------------- font_manager_match_description ---
char *font_manager_match_description(font_manager_t *self, const char *family,
const float size, const int bold,
const int italic)
{
// Use of fontconfig is disabled by default.
#if 1
return 0;
#else
#if defined _WIN32 || defined _WIN64
fprintf(
stderr,
"\"font_manager_match_description\" not implemented for windows.\n");
return 0;
#endif
char *filename = 0;
int weight = FC_WEIGHT_REGULAR;
int slant = FC_SLANT_ROMAN;
if (bold)
{
weight = FC_WEIGHT_BOLD;
}
if (italic)
{
slant = FC_SLANT_ITALIC;
}
FcInit();
FcPattern *pattern = FcPatternCreate();
FcPatternAddDouble(pattern, FC_SIZE, size);
FcPatternAddInteger(pattern, FC_WEIGHT, weight);
FcPatternAddInteger(pattern, FC_SLANT, slant);
FcPatternAddString(pattern, FC_FAMILY, (FcChar8 *) family);
FcConfigSubstitute(0, pattern, FcMatchPattern);
FcDefaultSubstitute(pattern);
FcResult result;
FcPattern *match = FcFontMatch(0, pattern, &result);
FcPatternDestroy(pattern);
if (!match)
{
fprintf(stderr, "fontconfig error: could not match family '%s'",
family);
return 0;
}
else
{
FcValue value;
FcResult result = FcPatternGet(match, FC_FILE, 0, &value);
if (result)
{
fprintf(stderr, "fontconfig error: could not match family '%s'",
family);
}
else
{
filename = strdup((char *) (value.u.s));
}
}
FcPatternDestroy(match);
return filename;
#endif
}

View File

@ -1,547 +0,0 @@
/* Freetype GL - A C OpenGL Freetype engine
*
* Distributed under the OSI-approved BSD 2-Clause License. See accompanying
* file `LICENSE` for more details.
*/
#pragma GCC diagnostic ignored "-Wformat"
#include "opengl.h"
#include "vec234.h"
#include "vector.h"
#include "freetype-gl.h"
#include <errno.h>
#include <stdio.h>
#include <string.h>
#ifndef WIN32
#define PRIzu "zu"
#else
#define PRIzu "Iu"
#endif
// ------------------------------------------------------------- print help ---
void print_help()
{
fprintf(stderr, "Usage: makefont [--help] --font <font file> "
"--header <header file> --size <font size> "
"--variable <variable name> --texture <texture size>"
"--rendermode <one of 'normal', 'outline_edge', "
"'outline_positive', 'outline_negative' or 'sdf'>\n");
}
// ------------------------------------------------------------------- main ---
int main(int argc, char **argv)
{
FILE *test;
size_t i, j;
int arg;
char *font_cache = " !\"#$%&'()*+,-./0123456789:;<=>?"
"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
"`abcdefghijklmnopqrstuvwxyz{|}~";
float font_size = 0.0;
const char *font_filename = NULL;
const char *header_filename = NULL;
const char *variable_name = "font";
int show_help = 0;
size_t texture_width = 128;
rendermode_t rendermode = RENDER_NORMAL;
const char *rendermodes[5];
rendermodes[RENDER_NORMAL] = "normal";
rendermodes[RENDER_OUTLINE_EDGE] = "outline edge";
rendermodes[RENDER_OUTLINE_POSITIVE] = "outline added";
rendermodes[RENDER_OUTLINE_NEGATIVE] = "outline removed";
rendermodes[RENDER_SIGNED_DISTANCE_FIELD] = "signed distance field";
for (arg = 1; arg < argc; ++arg)
{
if (0 == strcmp("--font", argv[arg]) || 0 == strcmp("-f", argv[arg]))
{
++arg;
if (font_filename)
{
fprintf(stderr, "Multiple --font parameters.\n");
print_help();
exit(1);
}
if (arg >= argc)
{
fprintf(stderr, "No font file given.\n");
print_help();
exit(1);
}
font_filename = argv[arg];
continue;
}
if (0 == strcmp("--header", argv[arg]) || 0 == strcmp("-o", argv[arg]))
{
++arg;
if (header_filename)
{
fprintf(stderr, "Multiple --header parameters.\n");
print_help();
exit(1);
}
if (arg >= argc)
{
fprintf(stderr, "No header file given.\n");
print_help();
exit(1);
}
header_filename = argv[arg];
continue;
}
if (0 == strcmp("--help", argv[arg]) || 0 == strcmp("-h", argv[arg]))
{
show_help = 1;
break;
}
if (0 == strcmp("--size", argv[arg]) || 0 == strcmp("-s", argv[arg]))
{
++arg;
if (0.0 != font_size)
{
fprintf(stderr, "Multiple --size parameters.\n");
print_help();
exit(1);
}
if (arg >= argc)
{
fprintf(stderr, "No font size given.\n");
print_help();
exit(1);
}
errno = 0;
font_size = atof(argv[arg]);
if (errno)
{
fprintf(stderr, "No valid font size given.\n");
print_help();
exit(1);
}
continue;
}
if (0 == strcmp("--variable", argv[arg]) ||
0 == strcmp("-a", argv[arg]))
{
++arg;
if (0 != strcmp("font", variable_name))
{
fprintf(stderr, "Multiple --variable parameters.\n");
print_help();
exit(1);
}
if (arg >= argc)
{
fprintf(stderr, "No variable name given.\n");
print_help();
exit(1);
}
variable_name = argv[arg];
continue;
}
if (0 == strcmp("--texture", argv[arg]) || 0 == strcmp("-t", argv[arg]))
{
++arg;
if (128.0 != texture_width)
{
fprintf(stderr, "Multiple --texture parameters.\n");
print_help();
exit(1);
}
if (arg >= argc)
{
fprintf(stderr, "No texture size given.\n");
print_help();
exit(1);
}
errno = 0;
texture_width = atof(argv[arg]);
if (errno)
{
fprintf(stderr, "No valid texture size given.\n");
print_help();
exit(1);
}
continue;
}
if (0 == strcmp("--rendermode", argv[arg]) ||
0 == strcmp("-r", argv[arg]))
{
++arg;
if (128.0 != texture_width)
{
fprintf(stderr, "Multiple --texture parameters.\n");
print_help();
exit(1);
}
if (arg >= argc)
{
fprintf(stderr, "No texture size given.\n");
print_help();
exit(1);
}
errno = 0;
if (0 == strcmp("normal", argv[arg]))
{
rendermode = RENDER_NORMAL;
}
else if (0 == strcmp("outline_edge", argv[arg]))
{
rendermode = RENDER_OUTLINE_EDGE;
}
else if (0 == strcmp("outline_positive", argv[arg]))
{
rendermode = RENDER_OUTLINE_POSITIVE;
}
else if (0 == strcmp("outline_negative", argv[arg]))
{
rendermode = RENDER_OUTLINE_NEGATIVE;
}
else if (0 == strcmp("sdf", argv[arg]))
{
rendermode = RENDER_SIGNED_DISTANCE_FIELD;
}
else
{
fprintf(stderr, "No valid render mode given.\n");
print_help();
exit(1);
}
continue;
}
fprintf(stderr, "Unknown parameter %s\n", argv[arg]);
print_help();
exit(1);
}
if (show_help)
{
print_help();
exit(1);
}
if (!font_filename)
{
fprintf(stderr, "No font file given.\n");
print_help();
exit(1);
}
if (!(test = fopen(font_filename, "r")))
{
fprintf(stderr, "Font file \"%s\" does not exist.\n", font_filename);
}
fclose(test);
if (4.0 > font_size)
{
fprintf(stderr, "Font size too small, expected at least 4 pt.\n");
print_help();
exit(1);
}
if (!header_filename)
{
fprintf(stderr, "No header file given.\n");
print_help();
exit(1);
}
texture_atlas_t *atlas = texture_atlas_new(texture_width, texture_width, 1);
texture_font_t *font =
texture_font_new_from_file(atlas, font_size, font_filename);
font->rendermode = rendermode;
size_t missed = texture_font_load_glyphs(font, font_cache);
printf("Font filename : %s\n"
"Font size : %.1f\n"
"Number of glyphs : %ld\n"
"Number of missed glyphs : %ld\n"
"Texture size : %ldx%ldx%ld\n"
"Texture occupancy : %.2f%%\n"
"\n"
"Header filename : %s\n"
"Variable name : %s\n"
"Render mode : %s\n",
font_filename, font_size, strlen(font_cache), missed, atlas->width,
atlas->height, atlas->depth,
100.0 * atlas->used / (float) (atlas->width * atlas->height),
header_filename, variable_name, rendermodes[rendermode]);
size_t texture_size = atlas->width * atlas->height * atlas->depth;
size_t glyph_count = font->glyphs->size;
size_t max_kerning_count = 1;
for (i = 0; i < glyph_count; ++i)
{
texture_glyph_t *glyph =
*(texture_glyph_t **) vector_get(font->glyphs, i);
if (vector_size(glyph->kerning) > max_kerning_count)
{
max_kerning_count = vector_size(glyph->kerning);
}
}
FILE *file = fopen(header_filename, "w");
// -------------
// Header
// -------------
fprintf(
file,
"/* "
"======================================================================"
"======\n"
" * Freetype GL - A C OpenGL Freetype engine\n"
" * Platform: Any\n"
" * WWW: https://github.com/rougier/freetype-gl\n"
" * "
"----------------------------------------------------------------------"
"------\n"
" * Copyright 2011,2012 Nicolas P. Rougier. All rights reserved.\n"
" *\n"
" * Redistribution and use in source and binary forms, with or "
"without\n"
" * modification, are permitted provided that the following conditions "
"are met:\n"
" *\n"
" * 1. Redistributions of source code must retain the above copyright "
"notice,\n"
" * this list of conditions and the following disclaimer.\n"
" *\n"
" * 2. Redistributions in binary form must reproduce the above "
"copyright\n"
" * notice, this list of conditions and the following disclaimer "
"in the\n"
" * documentation and/or other materials provided with the "
"distribution.\n"
" *\n"
" * THIS SOFTWARE IS PROVIDED BY NICOLAS P. ROUGIER ''AS IS'' AND ANY "
"EXPRESS OR\n"
" * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED "
"WARRANTIES OF\n"
" * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE "
"DISCLAIMED. IN NO\n"
" * EVENT SHALL NICOLAS P. ROUGIER OR CONTRIBUTORS BE LIABLE FOR ANY "
"DIRECT,\n"
" * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL "
"DAMAGES\n"
" * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR "
"SERVICES;\n"
" * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER "
"CAUSED AND\n"
" * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, "
"OR TORT\n"
" * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE "
"USE OF\n"
" * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
" *\n"
" * The views and conclusions contained in the software and "
"documentation are\n"
" * those of the authors and should not be interpreted as representing "
"official\n"
" * policies, either expressed or implied, of Nicolas P. Rougier.\n"
" * "
"======================================================================"
"======\n"
" */\n");
// ----------------------
// Structure declarations
// ----------------------
fprintf(file, "#include <stddef.h>\n"
"#include <stdint.h>\n"
"#ifdef __cplusplus\n"
"extern \"C\" {\n"
"#endif\n"
"\n"
"typedef struct\n"
"{\n"
" uint32_t codepoint;\n"
" float kerning;\n"
"} kerning_t;\n\n");
fprintf(file,
"typedef struct\n"
"{\n"
" uint32_t codepoint;\n"
" int width, height;\n"
" int offset_x, offset_y;\n"
" float advance_x, advance_y;\n"
" float s0, t0, s1, t1;\n"
" size_t kerning_count;\n"
" kerning_t kerning[%" PRIzu "];\n"
"} texture_glyph_t;\n\n",
max_kerning_count);
fprintf(file,
"typedef struct\n"
"{\n"
" size_t tex_width;\n"
" size_t tex_height;\n"
" size_t tex_depth;\n"
" char tex_data[%" PRIzu "];\n"
" float size;\n"
" float height;\n"
" float linegap;\n"
" float ascender;\n"
" float descender;\n"
" size_t glyphs_count;\n"
" texture_glyph_t glyphs[%" PRIzu "];\n"
"} texture_font_t;\n\n",
texture_size, glyph_count);
fprintf(file, "texture_font_t %s = {\n", variable_name);
// ------------
// Texture data
// ------------
fprintf(file, " %" PRIzu ", %" PRIzu ", %" PRIzu ", \n", atlas->width,
atlas->height, atlas->depth);
fprintf(file, " {");
for (i = 0; i < texture_size; i += 32)
{
for (j = 0; j < 32 && (j + i) < texture_size; ++j)
{
if ((j + i) < (texture_size - 1))
{
fprintf(file, "%d,", atlas->data[i + j]);
}
else
{
fprintf(file, "%d", atlas->data[i + j]);
}
}
if ((j + i) < texture_size)
{
fprintf(file, "\n ");
}
}
fprintf(file, "}, \n");
// -------------------
// Texture information
// -------------------
fprintf(file, " %ff, %ff, %ff, %ff, %ff, %" PRIzu ", \n", font->size,
font->height, font->linegap, font->ascender, font->descender,
glyph_count);
// --------------
// Texture glyphs
// --------------
fprintf(file, " {\n");
for (i = 0; i < glyph_count; ++i)
{
texture_glyph_t *glyph =
*(texture_glyph_t **) vector_get(font->glyphs, i);
/*
// Debugging information
printf( "glyph : '%lc'\n",
glyph->codepoint );
printf( " size : %dx%d\n",
glyph->width, glyph->height );
printf( " offset : %+d%+d\n",
glyph->offset_x, glyph->offset_y );
printf( " advance : %ff, %ff\n",
glyph->advance_x, glyph->advance_y );
printf( " tex coords.: %ff, %ff, %ff, %ff\n",
glyph->u0, glyph->v0, glyph->u1, glyph->v1 );
printf( " kerning : " );
if( glyph->kerning_count )
{
for( j=0; j < glyph->kerning_count; ++j )
{
printf( "('%lc', %ff)",
glyph->kerning[j].codepoint,
glyph->kerning[j].kerning ); if( j < (glyph->kerning_count-1) )
{
printf( ", " );
}
}
}
else
{
printf( "None" );
}
printf( "\n\n" );
*/
// TextureFont
fprintf(file, " {%u, ", glyph->codepoint);
fprintf(file, "%" PRIzu ", %" PRIzu ", ", glyph->width, glyph->height);
fprintf(file, "%d, %d, ", glyph->offset_x, glyph->offset_y);
fprintf(file, "%ff, %ff, ", glyph->advance_x, glyph->advance_y);
fprintf(file, "%ff, %ff, %ff, %ff, ", glyph->s0, glyph->t0, glyph->s1,
glyph->t1);
fprintf(file, "%" PRIzu ", ", vector_size(glyph->kerning));
if (vector_size(glyph->kerning) == 0)
{
fprintf(file, "0");
}
else
{
fprintf(file, "{ ");
for (j = 0; j < vector_size(glyph->kerning); ++j)
{
kerning_t *kerning =
(kerning_t *) vector_get(glyph->kerning, j);
fprintf(file, "{%u, %ff}", kerning->codepoint,
kerning->kerning);
if (j < (vector_size(glyph->kerning) - 1))
{
fprintf(file, ", ");
}
}
fprintf(file, "}");
}
fprintf(file, " },\n");
}
fprintf(file, " }\n};\n");
fprintf(file, "#ifdef __cplusplus\n"
"}\n"
"#endif\n");
fclose(file);
return 0;
}