From 86d7e9fe80893156d52b766a4f645aaf3a638f44 Mon Sep 17 00:00:00 2001 From: Rebekah Rowe Date: Tue, 5 Apr 2022 11:49:44 -0400 Subject: [PATCH] Removed useless headers --- ftgl/CMakeLists.txt | 4 - ftgl/README.md | 87 ------- ftgl/font-manager.h | 162 ------------- ftgl/markup.h | 164 -------------- ftgl/opengl.h | 28 --- ftgl/platform.c | 31 --- ftgl/platform.h | 31 --- ftgl/text-buffer.c | 536 -------------------------------------------- ftgl/text-buffer.h | 289 ------------------------ 9 files changed, 1332 deletions(-) delete mode 100644 ftgl/README.md delete mode 100644 ftgl/font-manager.h delete mode 100644 ftgl/markup.h delete mode 100644 ftgl/opengl.h delete mode 100644 ftgl/platform.c delete mode 100644 ftgl/platform.h delete mode 100644 ftgl/text-buffer.c delete mode 100644 ftgl/text-buffer.h diff --git a/ftgl/CMakeLists.txt b/ftgl/CMakeLists.txt index 018b75f..2e6a5b0 100644 --- a/ftgl/CMakeLists.txt +++ b/ftgl/CMakeLists.txt @@ -1,10 +1,6 @@ target_sources(glez PRIVATE "${CMAKE_CURRENT_LIST_DIR}/freetype-gl.h" - "${CMAKE_CURRENT_LIST_DIR}/markup.h" "${CMAKE_CURRENT_LIST_DIR}/mat4.h" - "${CMAKE_CURRENT_LIST_DIR}/opengl.h" - "${CMAKE_CURRENT_LIST_DIR}/platform.h" - "${CMAKE_CURRENT_LIST_DIR}/text-buffer.h" "${CMAKE_CURRENT_LIST_DIR}/texture-atlas.h" "${CMAKE_CURRENT_LIST_DIR}/texture-font.h" "${CMAKE_CURRENT_LIST_DIR}/utf8-utils.h" diff --git a/ftgl/README.md b/ftgl/README.md deleted file mode 100644 index adba2e5..0000000 --- a/ftgl/README.md +++ /dev/null @@ -1,87 +0,0 @@ -# Freetype GL - A C OpenGL Freetype engine - -[![Build Status Travis](https://travis-ci.org/rougier/freetype-gl.png?branch=master)](https://travis-ci.org/rougier/freetype-gl) -[![Build Status Appveyor](https://ci.appveyor.com/api/projects/status/github/rougier/freetype-gl?branch=master)](https://ci.appveyor.com/project/rougier/freetype-gl) - -A small library for displaying Unicode in OpenGL using a single texture and -a single vertex buffer. - -![Screenshot](http://raw.github.com/rougier/freetype-gl/master/doc/images/markup.png) - -[Installation instructions](INSTALL.md). - -## Code organization - -### Mandatory files - -* **texture-font**: The texture-font structure is in charge of creating bitmap - glyphs and to upload them to the texture atlas. - -* **texture-atlas**: This structure is responsible for the packing of small - regions into a bigger texture. It is based on the skyline - bottom left algorithm which appear to be well suited for - storing glyphs. More information at: - http://clb.demon.fi/files/RectangleBinPack.pdf - -* **vector**: This structure loosely mimics the std::vector class from - c++. It is used by texture-atlas (for storing nodes), - texture-font (for storing glyphs) and font-manager (for - storing fonts). More information at: - http://www.cppreference.com/wiki/container/vector/start - - -### Optional files - -* **markup**: Simple structure that describes text properties (font - family, font size, colors, underline, etc.) - -* **font-manager**: Structure in charge of caching fonts. - -* **vertex-buffer**: Generic vertex buffer structure inspired by pyglet - (python). (more information at http://www.pyglet.org) - -* **edtaa3func**: Distance field computation by Stefan Gustavson - (more information at http://contourtextures.wikidot.com/) - -* **makefont**: Allow to generate header file with font information - (texture + glyphs) such that it can be used without - freetype. - - -## Contributors - -* Ryan.H.Kawicki (Initial CMake project) -* Julian Mayer (Several bugfixes and code for demo-opengl-4.cc) -* Sylvain Duclos (Android port) -* Wang Yongcong (Improvements on the windows build and code review) -* Jonas Wielicki (Bug report & fix on the CMakefile) -* whatmannerofburgeristhis (Bug report in makefont) -* Andrei Petrovici (Fine analysis of the whole code and report of potential problems) -* Cristi Caloghera (Report on bad vertex buffer usage) -* Andrei Petrovici (Code review) -* Kim Jacobsen (Bug report & fix) -* bsoddd (Bug report & fix) -* Greg Douglas (Bug report & fix) -* Jim Teeuwen (Bug report & fix) -* quarnster (Bug report & fix) -* Per Inge Mathisen (Bug report & fix) -* Wojciech Mamrak (Code review, bug report & fix) -* Wael Eloraiby (Put code to the C89 norm and fix CMakefile) -* Christian Forfang (Code review, fix & patch for 3.2 core profile) -* Lukas Murmann (Code review & fix for 3.2 core profile) -* Jérémie Roy (Code review, fix and new ideas) -* dsewtz (Bug report & fix) -* jcgamestoy (Bug report & fix) -* Behdad Esfahbod (Bug fix on harfbuzz demo) -* Marcel Metz (Bug report & fix, CMmake no demo option, makefont parameters) -* PJ O'Halloran (svn to git migration) -* William Light (Face creation from memory) -* Jan Niklas Hasse (Bug report & fix + README.md) -* Pierre-Emmanuel Lallemant (Bug report & fix + travis setup) -* Robert Conde (Bug report & fix) -* Mikołaj Siedlarek (Build system bug fix) -* Preet Desai (Bug report & fix) -* Andy Staton (CMake fix and added namespace safeguard (avoiding glm collisions)) -* Daniel Burke (Removed GLEW dependency and fix problems with font licences) -* Bob Kocisko (Added horizontal text alignment and text bounds calculation) -* Ciro Santilli (Improve markdown documentation) diff --git a/ftgl/font-manager.h b/ftgl/font-manager.h deleted file mode 100644 index 4155e55..0000000 --- a/ftgl/font-manager.h +++ /dev/null @@ -1,162 +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. - */ -#ifndef __FONT_MANAGER_H__ -#define __FONT_MANAGER_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "vector.h" -#include "markup.h" -#include "texture-font.h" -#include "texture-atlas.h" - -#ifdef __cplusplus -namespace ftgl -{ -#endif - -/** - * @file font-manager.h - * @author Nicolas Rougier (Nicolas.Rougier@inria.fr) - * - * @defgroup font-manager Font manager - * - * Structure in charge of caching fonts. - * - * Example Usage: - * @code - * #include "font-manager.h" - * - * int main( int arrgc, char *argv[] ) - * { - * font_manager_t * manager = manager_new( 512, 512, 1 ); - * texture_font_t * font = font_manager_get( manager, "Mono", 12, 0, 0 ); - * - * return 0; - * } - * @endcode - * - * @{ - */ - -/** - * Structure in charge of caching fonts. - */ -typedef struct font_manager_t -{ - /** - * Texture atlas to hold font glyphs. - */ - texture_atlas_t *atlas; - - /** - * Cached textures. - */ - vector_t *fonts; - - /** - * Default glyphs to be loaded when loading a new font. - */ - char *cache; - -} font_manager_t; - -/** - * Creates a new empty font manager. - * - * @param width width of the underlying atlas - * @param height height of the underlying atlas - * @param depth bit depth of the underlying atlas - * - * @return a new font manager. - * - */ -font_manager_t *font_manager_new(size_t width, size_t height, size_t depth); - -/** - * Deletes a font manager. - * - * @param self a font manager. - */ -void font_manager_delete(font_manager_t *self); - -/** - * Deletes a font from the font manager. - * - * Note that font glyphs are not removed from the atlas. - * - * @param self a font manager. - * @param font font to be deleted - * - */ -void font_manager_delete_font(font_manager_t *self, texture_font_t *font); - -/** - * Request for a font based on a filename. - * - * @param self a font manager. - * @param filename font filename - * @param size font size - * - * @return Requested font - */ -texture_font_t *font_manager_get_from_filename(font_manager_t *self, - const char *filename, - const float size); - -/** - * Request for a font based on a description - * - * @param self a font manager - * @param family font family - * @param size font size - * @param bold whether font is bold - * @param italic whether font is italic - * - * @return Requested font - */ -texture_font_t *font_manager_get_from_description(font_manager_t *self, - const char *family, - const float size, - const int bold, - const int italic); - -/** - * Request for a font based on a markup - * - * @param self a font manager - * @param markup Markup describing a font - * - * @return Requested font - */ -texture_font_t *font_manager_get_from_markup(font_manager_t *self, - const markup_t *markup); - -/** - * Search for a font filename that match description. - * - * @param self a font manager - * @param family font family - * @param size font size - * @param bold whether font is bold - * @param italic whether font is italic - * - * @return Requested font filename - */ -char *font_manager_match_description(font_manager_t *self, const char *family, - const float size, const int bold, - const int italic); - -/** @} */ - -#ifdef __cplusplus -} -} -#endif // ifdef __cplusplus - -#endif /* __FONT_MANAGER_H__ */ diff --git a/ftgl/markup.h b/ftgl/markup.h deleted file mode 100644 index d986dbf..0000000 --- a/ftgl/markup.h +++ /dev/null @@ -1,164 +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. - */ -#ifndef __MARKUP_H__ -#define __MARKUP_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "texture-font.h" -#include "vec234.h" - -#ifdef __cplusplus -namespace ftgl -{ -#endif - -/** - * @file markup.h - * @author Nicolas Rougier (Nicolas.Rougier@inria.fr) - * - * @defgroup markup Markup - * - * Simple structure that describes text properties. - * - * Example Usage: - * @code - * #include "markup.h" - * - * ... - * - * vec4 black = {{0.0, 0.0, 0.0, 1.0}}; - * vec4 white = {{1.0, 1.0, 1.0, 1.0}}; - * vec4 none = {{1.0, 1.0, 1.0, 0.0}}; - * - * markup_t normal = { - * .family = "Droid Serif", - * .size = 24.0, - * .bold = 0, - * .italic = 0, - * .spacing = 1.0, - * .gamma = 1.0, - * .foreground_color = black, .background_color = none, - * .underline = 0, .underline_color = black, - * .overline = 0, .overline_color = black, - * .strikethrough = 0, .strikethrough_color = black, - * .font = 0, - * }; - * - * ... - * - * @endcode - * - * @{ - */ - -/** - * Simple structure that describes text properties. - */ -typedef struct markup_t -{ - /** - * A font family name such as "normal", "sans", "serif" or "monospace". - */ - char *family; - - /** - * Font size. - */ - float size; - - /** - * Whether text is bold. - */ - int bold; - - /** - * Whether text is italic. - */ - int italic; - - /** - * Spacing between letters. - */ - float spacing; - - /** - * Gamma correction. - */ - float gamma; - - /** - * Text color. - */ - vec4 foreground_color; - - /** - * Background color. - */ - vec4 background_color; - - /** - * Whether outline is active. - */ - int outline; - - /** - * Outline color. - */ - vec4 outline_color; - - /** - * Whether underline is active. - */ - int underline; - - /** - * Underline color. - */ - vec4 underline_color; - - /** - * Whether overline is active. - */ - int overline; - - /** - * Overline color. - */ - vec4 overline_color; - - /** - * Whether strikethrough is active. - */ - int strikethrough; - - /** - * Strikethrough color. - */ - vec4 strikethrough_color; - - /** - * Pointer on the corresponding font (family/size/bold/italic) - */ - texture_font_t *font; - -} markup_t; - -/** - * Default markup - */ -extern markup_t default_markup; - -/** @} */ - -#ifdef __cplusplus -} -} -#endif - -#endif /* __MARKUP_H__ */ diff --git a/ftgl/opengl.h b/ftgl/opengl.h deleted file mode 100644 index fa5a455..0000000 --- a/ftgl/opengl.h +++ /dev/null @@ -1,28 +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. - */ -#ifndef __OPEN_GL_H__ -#define __OPEN_GL_H__ - -#if defined(__APPLE__) -#include "TargetConditionals.h" -#if TARGET_OS_SIMULATOR || TARGET_OS_IPHONE -#if defined(FREETYPE_GL_ES_VERSION_3_0) -#include -#else -#include -#endif -#else -#include -#endif -#elif defined(_WIN32) || defined(_WIN64) -#include -#include -#else -#include -#include -#endif - -#endif /* OPEN_GL_H */ diff --git a/ftgl/platform.c b/ftgl/platform.c deleted file mode 100644 index 3d609df..0000000 --- a/ftgl/platform.c +++ /dev/null @@ -1,31 +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. - */ -#include -#include "platform.h" - -#if defined(_WIN32) || defined(_WIN64) - -#include - -// strndup() is not available on Windows -char *strndup(const char *s1, size_t n) -{ - char *copy = (char *) malloc(n + 1); - memcpy(copy, s1, n); - copy[n] = 0; - return copy; -}; -#endif - -// strndup() was only added in OSX lion -#if defined(__APPLE__) -char *strndup(const char *s1, size_t n) -{ - char *copy = calloc(n + 1, sizeof(char)); - memcpy(copy, s1, n); - return copy; -}; -#endif diff --git a/ftgl/platform.h b/ftgl/platform.h deleted file mode 100644 index 33eac5b..0000000 --- a/ftgl/platform.h +++ /dev/null @@ -1,31 +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. - */ -#ifndef __PLATFORM_H__ -#define __PLATFORM_H__ - -#include - -#ifdef __cplusplus -extern "C" { -namespace ftgl -{ -#endif - -#ifdef __APPLE__ -/* strndup() was only added in OSX lion */ -char *strndup(const char *s1, size_t n); -#elif defined(_WIN32) || defined(_WIN64) -/* does not exist on windows */ -char *strndup(const char *s1, size_t n); -#pragma warning(disable : 4244) // suspend warnings -#endif // _WIN32 || _WIN64 - -#ifdef __cplusplus -} -} -#endif // __cplusplus - -#endif /* __PLATFORM_H__ */ diff --git a/ftgl/text-buffer.c b/ftgl/text-buffer.c deleted file mode 100644 index 428c715..0000000 --- a/ftgl/text-buffer.c +++ /dev/null @@ -1,536 +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. - */ -#include -#include -#include -#include -#include -#include -#include "opengl.h" -#include "text-buffer.h" -#include "utf8-utils.h" - -#define SET_GLYPH_VERTEX(value, x0, y0, z0, s0, t0, r, g, b, a, sh, gm) \ - { \ - glyph_vertex_t *gv = &value; \ - gv->x = x0; \ - gv->y = y0; \ - gv->z = z0; \ - gv->u = s0; \ - gv->v = t0; \ - gv->r = r; \ - gv->g = g; \ - gv->b = b; \ - gv->a = a; \ - gv->shift = sh; \ - gv->gamma = gm; \ - } - -// ---------------------------------------------------------------------------- - -text_buffer_t *text_buffer_new() -{ - text_buffer_t *self = (text_buffer_t *) malloc(sizeof(text_buffer_t)); - self->buffer = vertex_buffer_new( - "vertex:3f,tex_coord:2f,color:4f,ashift:1f,agamma:1f"); - self->line_start = 0; - self->line_ascender = 0; - self->base_color.r = 0.0; - self->base_color.g = 0.0; - self->base_color.b = 0.0; - self->base_color.a = 1.0; - self->line_descender = 0; - self->lines = vector_new(sizeof(line_info_t)); - self->bounds.left = 0.0; - self->bounds.top = 0.0; - self->bounds.width = 0.0; - self->bounds.height = 0.0; - return self; -} - -// ---------------------------------------------------------------------------- -void text_buffer_delete(text_buffer_t *self) -{ - vector_delete(self->lines); - vertex_buffer_delete(self->buffer); - free(self); -} - -// ---------------------------------------------------------------------------- -void text_buffer_clear(text_buffer_t *self) -{ - assert(self); - - vertex_buffer_clear(self->buffer); - self->line_start = 0; - self->line_ascender = 0; - self->line_descender = 0; - vector_clear(self->lines); - self->bounds.left = 0.0; - self->bounds.top = 0.0; - self->bounds.width = 0.0; - self->bounds.height = 0.0; -} - -// ---------------------------------------------------------------------------- -void text_buffer_printf(text_buffer_t *self, vec2 *pen, ...) -{ - markup_t *markup; - char *text; - va_list args; - - if (vertex_buffer_size(self->buffer) == 0) - { - self->origin = *pen; - } - - va_start(args, pen); - do - { - markup = va_arg(args, markup_t *); - if (markup == NULL) - { - va_end(args); - return; - } - text = va_arg(args, char *); - text_buffer_add_text(self, pen, markup, text, 0); - } while (markup != 0); - va_end(args); -} - -// ---------------------------------------------------------------------------- -void text_buffer_move_last_line(text_buffer_t *self, float dy) -{ - size_t i; - int j; - for (i = self->line_start; i < vector_size(self->buffer->items); ++i) - { - ivec4 *item = (ivec4 *) vector_get(self->buffer->items, i); - for (j = item->vstart; j < item->vstart + item->vcount; ++j) - { - glyph_vertex_t *vertex = - (glyph_vertex_t *) vector_get(self->buffer->vertices, j); - vertex->y -= dy; - } - } -} - -// ---------------------------------------------------------------------------- -// text_buffer_finish_line (internal use only) -// -// Performs calculations needed at the end of each line of text -// and prepares for the next line if necessary -// -// advancePen: if true, advance the pen to the next line -// -static void text_buffer_finish_line(text_buffer_t *self, vec2 *pen, - bool advancePen) -{ - float line_left = self->line_left; - float line_right = pen->x; - float line_width = line_right - line_left; - float line_top = pen->y + self->line_ascender; - float line_height = self->line_ascender - self->line_descender; - float line_bottom = line_top - line_height; - - line_info_t line_info; - line_info.line_start = self->line_start; - line_info.bounds.left = line_left; - line_info.bounds.top = line_top; - line_info.bounds.width = line_width; - line_info.bounds.height = line_height; - - vector_push_back(self->lines, &line_info); - - if (line_left < self->bounds.left) - { - self->bounds.left = line_left; - } - if (line_top > self->bounds.top) - { - self->bounds.top = line_top; - } - - float self_right = self->bounds.left + self->bounds.width; - float self_bottom = self->bounds.top - self->bounds.height; - - if (line_right > self_right) - { - self->bounds.width = line_right - self->bounds.left; - } - if (line_bottom < self_bottom) - { - self->bounds.height = self->bounds.top - line_bottom; - } - - if (advancePen) - { - pen->x = self->origin.x; - pen->y += (int) (self->line_descender); - } - - self->line_descender = 0; - self->line_ascender = 0; - self->line_start = vector_size(self->buffer->items); - self->line_left = pen->x; -} - -// ---------------------------------------------------------------------------- -void text_buffer_add_text(text_buffer_t *self, vec2 *pen, markup_t *markup, - const char *text, size_t length) -{ - size_t i; - const char *prev_character = NULL; - - if (markup == NULL) - { - return; - } - - if (!markup->font) - { - fprintf(stderr, "Houston, we've got a problem !\n"); - return; - } - - if (length == 0) - { - length = utf8_strlen(text); - } - if (vertex_buffer_size(self->buffer) == 0) - { - self->origin = *pen; - self->line_left = pen->x; - self->bounds.left = pen->x; - self->bounds.top = pen->y; - } - else - { - if (pen->x < self->origin.x) - { - self->origin.x = pen->x; - } - if (pen->y != self->last_pen_y) - { - text_buffer_finish_line(self, pen, false); - } - } - - for (i = 0; length; i += utf8_surrogate_len(text + i)) - { - text_buffer_add_char(self, pen, markup, text + i, prev_character); - prev_character = text + i; - length--; - } - - self->last_pen_y = pen->y; -} - -// ---------------------------------------------------------------------------- -void text_buffer_add_char(text_buffer_t *self, vec2 *pen, markup_t *markup, - const char *current, const char *previous) -{ - size_t vcount = 0; - size_t icount = 0; - vertex_buffer_t *buffer = self->buffer; - texture_font_t *font = markup->font; - float gamma = markup->gamma; - - // Maximum number of vertices is 20 (= 5x2 triangles) per glyph: - // - 2 triangles for background - // - 2 triangles for overline - // - 2 triangles for underline - // - 2 triangles for strikethrough - // - 2 triangles for glyph - glyph_vertex_t vertices[4 * 5]; - GLuint indices[6 * 5]; - texture_glyph_t *glyph; - texture_glyph_t *black; - float kerning = 0.0f; - - if (markup->font->ascender > self->line_ascender) - { - float y = pen->y; - pen->y -= (markup->font->ascender - self->line_ascender); - text_buffer_move_last_line(self, (float) (int) (y - pen->y)); - self->line_ascender = markup->font->ascender; - } - if (markup->font->descender < self->line_descender) - { - self->line_descender = markup->font->descender; - } - - if (*current == '\n') - { - text_buffer_finish_line(self, pen, true); - return; - } - - glyph = texture_font_get_glyph(font, current); - black = texture_font_get_glyph(font, NULL); - - if (glyph == NULL) - { - return; - } - - if (previous && markup->font->kerning) - { - kerning = texture_glyph_get_kerning(glyph, previous); - } - pen->x += kerning; - - // Background - if (markup->background_color.alpha > 0) - { - float r = markup->background_color.r; - float g = markup->background_color.g; - float b = markup->background_color.b; - float a = markup->background_color.a; - float x0 = (pen->x - kerning); - float y0 = (float) (int) (pen->y + font->descender); - float x1 = (x0 + glyph->advance_x); - float y1 = (float) (int) (y0 + font->height + font->linegap); - float s0 = black->s0; - float t0 = black->t0; - float s1 = black->s1; - float t1 = black->t1; - - SET_GLYPH_VERTEX(vertices[vcount + 0], (float) (int) x0, y0, 0, s0, t0, - r, g, b, a, x0 - ((int) x0), gamma); - SET_GLYPH_VERTEX(vertices[vcount + 1], (float) (int) x0, y1, 0, s0, t1, - r, g, b, a, x0 - ((int) x0), gamma); - SET_GLYPH_VERTEX(vertices[vcount + 2], (float) (int) x1, y1, 0, s1, t1, - r, g, b, a, x1 - ((int) x1), gamma); - SET_GLYPH_VERTEX(vertices[vcount + 3], (float) (int) x1, y0, 0, s1, t0, - r, g, b, a, x1 - ((int) x1), gamma); - indices[icount + 0] = vcount + 0; - indices[icount + 1] = vcount + 1; - indices[icount + 2] = vcount + 2; - indices[icount + 3] = vcount + 0; - indices[icount + 4] = vcount + 2; - indices[icount + 5] = vcount + 3; - vcount += 4; - icount += 6; - } - - // Underline - if (markup->underline) - { - float r = markup->underline_color.r; - float g = markup->underline_color.g; - float b = markup->underline_color.b; - float a = markup->underline_color.a; - float x0 = (pen->x - kerning); - float y0 = (float) (int) (pen->y + font->underline_position); - float x1 = (x0 + glyph->advance_x); - float y1 = (float) (int) (y0 + font->underline_thickness); - float s0 = black->s0; - float t0 = black->t0; - float s1 = black->s1; - float t1 = black->t1; - - SET_GLYPH_VERTEX(vertices[vcount + 0], (float) (int) x0, y0, 0, s0, t0, - r, g, b, a, x0 - ((int) x0), gamma); - SET_GLYPH_VERTEX(vertices[vcount + 1], (float) (int) x0, y1, 0, s0, t1, - r, g, b, a, x0 - ((int) x0), gamma); - SET_GLYPH_VERTEX(vertices[vcount + 2], (float) (int) x1, y1, 0, s1, t1, - r, g, b, a, x1 - ((int) x1), gamma); - SET_GLYPH_VERTEX(vertices[vcount + 3], (float) (int) x1, y0, 0, s1, t0, - r, g, b, a, x1 - ((int) x1), gamma); - indices[icount + 0] = vcount + 0; - indices[icount + 1] = vcount + 1; - indices[icount + 2] = vcount + 2; - indices[icount + 3] = vcount + 0; - indices[icount + 4] = vcount + 2; - indices[icount + 5] = vcount + 3; - vcount += 4; - icount += 6; - } - - // Overline - if (markup->overline) - { - float r = markup->overline_color.r; - float g = markup->overline_color.g; - float b = markup->overline_color.b; - float a = markup->overline_color.a; - float x0 = (pen->x - kerning); - float y0 = (float) (int) (pen->y + (int) font->ascender); - float x1 = (x0 + glyph->advance_x); - float y1 = (float) (int) (y0 + (int) font->underline_thickness); - float s0 = black->s0; - float t0 = black->t0; - float s1 = black->s1; - float t1 = black->t1; - SET_GLYPH_VERTEX(vertices[vcount + 0], (float) (int) x0, y0, 0, s0, t0, - r, g, b, a, x0 - ((int) x0), gamma); - SET_GLYPH_VERTEX(vertices[vcount + 1], (float) (int) x0, y1, 0, s0, t1, - r, g, b, a, x0 - ((int) x0), gamma); - SET_GLYPH_VERTEX(vertices[vcount + 2], (float) (int) x1, y1, 0, s1, t1, - r, g, b, a, x1 - ((int) x1), gamma); - SET_GLYPH_VERTEX(vertices[vcount + 3], (float) (int) x1, y0, 0, s1, t0, - r, g, b, a, x1 - ((int) x1), gamma); - indices[icount + 0] = vcount + 0; - indices[icount + 1] = vcount + 1; - indices[icount + 2] = vcount + 2; - indices[icount + 3] = vcount + 0; - indices[icount + 4] = vcount + 2; - indices[icount + 5] = vcount + 3; - vcount += 4; - icount += 6; - } - - /* Strikethrough */ - if (markup->strikethrough) - { - float r = markup->strikethrough_color.r; - float g = markup->strikethrough_color.g; - float b = markup->strikethrough_color.b; - float a = markup->strikethrough_color.a; - float x0 = (pen->x - kerning); - float y0 = (float) (int) (pen->y + (int) font->ascender * .33f); - float x1 = (x0 + glyph->advance_x); - float y1 = (float) (int) (y0 + (int) font->underline_thickness); - float s0 = black->s0; - float t0 = black->t0; - float s1 = black->s1; - float t1 = black->t1; - SET_GLYPH_VERTEX(vertices[vcount + 0], (float) (int) x0, y0, 0, s0, t0, - r, g, b, a, x0 - ((int) x0), gamma); - SET_GLYPH_VERTEX(vertices[vcount + 1], (float) (int) x0, y1, 0, s0, t1, - r, g, b, a, x0 - ((int) x0), gamma); - SET_GLYPH_VERTEX(vertices[vcount + 2], (float) (int) x1, y1, 0, s1, t1, - r, g, b, a, x1 - ((int) x1), gamma); - SET_GLYPH_VERTEX(vertices[vcount + 3], (float) (int) x1, y0, 0, s1, t0, - r, g, b, a, x1 - ((int) x1), gamma); - indices[icount + 0] = vcount + 0; - indices[icount + 1] = vcount + 1; - indices[icount + 2] = vcount + 2; - indices[icount + 3] = vcount + 0; - indices[icount + 4] = vcount + 2; - indices[icount + 5] = vcount + 3; - vcount += 4; - icount += 6; - } - { - // Actual glyph - float r = markup->foreground_color.red; - float g = markup->foreground_color.green; - float b = markup->foreground_color.blue; - float a = markup->foreground_color.alpha; - float x0 = (pen->x + glyph->offset_x); - float y0 = (float) (int) (pen->y + glyph->offset_y); - float x1 = (x0 + glyph->width); - float y1 = (float) (int) (y0 - glyph->height); - float s0 = glyph->s0; - float t0 = glyph->t0; - float s1 = glyph->s1; - float t1 = glyph->t1; - - SET_GLYPH_VERTEX(vertices[vcount + 0], (float) (int) x0, y0, 0, s0, t0, - r, g, b, a, x0 - ((int) x0), gamma); - SET_GLYPH_VERTEX(vertices[vcount + 1], (float) (int) x0, y1, 0, s0, t1, - r, g, b, a, x0 - ((int) x0), gamma); - SET_GLYPH_VERTEX(vertices[vcount + 2], (float) (int) x1, y1, 0, s1, t1, - r, g, b, a, x1 - ((int) x1), gamma); - SET_GLYPH_VERTEX(vertices[vcount + 3], (float) (int) x1, y0, 0, s1, t0, - r, g, b, a, x1 - ((int) x1), gamma); - indices[icount + 0] = vcount + 0; - indices[icount + 1] = vcount + 1; - indices[icount + 2] = vcount + 2; - indices[icount + 3] = vcount + 0; - indices[icount + 4] = vcount + 2; - indices[icount + 5] = vcount + 3; - vcount += 4; - icount += 6; - - vertex_buffer_push_back(buffer, vertices, vcount, indices, icount); - pen->x += glyph->advance_x * (1.0f + markup->spacing); - } -} - -// ---------------------------------------------------------------------------- -void text_buffer_align(text_buffer_t *self, vec2 *pen, enum Align alignment) -{ - if (ALIGN_LEFT == alignment) - { - return; - } - - size_t total_items = vector_size(self->buffer->items); - if (self->line_start != total_items) - { - text_buffer_finish_line(self, pen, false); - } - - size_t i, j; - int k; - float self_left, self_right, self_center; - float line_left, line_right, line_center; - float dx; - - self_left = self->bounds.left; - self_right = self->bounds.left + self->bounds.width; - self_center = (self_left + self_right) / 2; - - line_info_t *line_info; - size_t lines_count, line_end; - - lines_count = vector_size(self->lines); - for (i = 0; i < lines_count; ++i) - { - line_info = (line_info_t *) vector_get(self->lines, i); - - if (i + 1 < lines_count) - { - line_end = - ((line_info_t *) vector_get(self->lines, i + 1))->line_start; - } - else - { - line_end = vector_size(self->buffer->items); - } - - line_right = line_info->bounds.left + line_info->bounds.width; - - if (ALIGN_RIGHT == alignment) - { - dx = self_right - line_right; - } - else // ALIGN_CENTER - { - line_left = line_info->bounds.left; - line_center = (line_left + line_right) / 2; - dx = self_center - line_center; - } - - dx = roundf(dx); - - for (j = line_info->line_start; j < line_end; ++j) - { - ivec4 *item = (ivec4 *) vector_get(self->buffer->items, j); - for (k = item->vstart; k < item->vstart + item->vcount; ++k) - { - glyph_vertex_t *vertex = - (glyph_vertex_t *) vector_get(self->buffer->vertices, k); - vertex->x += dx; - } - } - } -} - -vec4 text_buffer_get_bounds(text_buffer_t *self, vec2 *pen) -{ - size_t total_items = vector_size(self->buffer->items); - if (self->line_start != total_items) - { - text_buffer_finish_line(self, pen, false); - } - - return self->bounds; -} diff --git a/ftgl/text-buffer.h b/ftgl/text-buffer.h deleted file mode 100644 index e81f6af..0000000 --- a/ftgl/text-buffer.h +++ /dev/null @@ -1,289 +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. - */ -#ifndef __TEXT_BUFFER_H__ -#define __TEXT_BUFFER_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "vertex-buffer.h" -#include "markup.h" - -#ifdef __cplusplus -namespace ftgl -{ -#endif - -/** - * Use LCD filtering - */ -#define LCD_FILTERING_ON 3 - -/** - * Do not use LCD filtering - */ -#define LCD_FILTERING_OFF 1 - -/** - * @file text-buffer.h - * @author Nicolas Rougier (Nicolas.Rougier@inria.fr) - * - * @defgroup text-buffer Text buffer - * - * - * Example Usage: - * @code - * - * int main( int arrgc, char *argv[] ) - * { - * - * return 0; - * } - * @endcode - * - * @{ - */ - -/** - * Text buffer structure - */ -typedef struct text_buffer_t -{ - /** - * Vertex buffer - */ - vertex_buffer_t *buffer; - - /** - * Base color for text - */ - vec4 base_color; - - /** - * Pen origin - */ - vec2 origin; - - /** - * Last pen y location - */ - float last_pen_y; - - /** - * Total bounds - */ - vec4 bounds; - - /** - * Index (in the vertex buffer) of the current line start - */ - size_t line_start; - - /** - * Location of the start of the line - */ - float line_left; - - /** - * Vector of line information - */ - vector_t *lines; - - /** - * Current line ascender - */ - float line_ascender; - - /** - * Current line decender - */ - float line_descender; -} text_buffer_t; - -/** - * Glyph vertex structure - */ -typedef struct glyph_vertex_t -{ - /** - * Vertex x coordinates - */ - float x; - - /** - * Vertex y coordinates - */ - float y; - - /** - * Vertex z coordinates - */ - float z; - - /** - * Texture first coordinate - */ - float u; - - /** - * Texture second coordinate - */ - float v; - - /** - * Color red component - */ - float r; - - /** - * Color green component - */ - float g; - - /** - * Color blue component - */ - float b; - - /** - * Color alpha component - */ - float a; - - /** - * Shift along x - */ - float shift; - - /** - * Color gamma correction - */ - float gamma; - -} glyph_vertex_t; - -/** - * Line structure - */ -typedef struct line_info_t -{ - /** - * Index (in the vertex buffer) where this line starts - */ - size_t line_start; - - /** - * bounds of this line - */ - vec4 bounds; - -} line_info_t; - -/** - * Align enumeration - */ -typedef enum Align { - /** - * Align text to the left hand side - */ - ALIGN_LEFT, - - /** - * Align text to the center - */ - ALIGN_CENTER, - - /** - * Align text to the right hand side - */ - ALIGN_RIGHT -} Align; - -/** - * Creates a new empty text buffer. - * - * @return a new empty text buffer. - * - */ -text_buffer_t *text_buffer_new(); - -/** - * Deletes texture buffer and its associated vertex buffer. - * - * @param self texture buffer to delete - * - */ -void text_buffer_delete(text_buffer_t *self); - -/** - * Print some text to the text buffer - * - * @param self a text buffer - * @param pen position of text start - * @param ... a series of markup_t *, char * ended by NULL - * - */ -void text_buffer_printf(text_buffer_t *self, vec2 *pen, ...); - -/** - * Add some text to the text buffer - * - * @param self a text buffer - * @param pen position of text start - * @param markup Markup to be used to add text - * @param text Text to be added - * @param length Length of text to be added - */ -void text_buffer_add_text(text_buffer_t *self, vec2 *pen, markup_t *markup, - const char *text, size_t length); - -/** - * Add a char to the text buffer - * - * @param self a text buffer - * @param pen position of text start - * @param markup markup to be used to add text - * @param current charactr to be added - * @param previous previous character (if any) - */ -void text_buffer_add_char(text_buffer_t *self, vec2 *pen, markup_t *markup, - const char *current, const char *previous); - -/** - * Align all the lines of text already added to the buffer - * This alignment will be relative to the overall bounds of the - * text which can be queried by text_buffer_get_bounds - * - * @param self a text buffer - * @param pen pen used in last call (must be unmodified) - * @param alignment desired alignment of text - */ -void text_buffer_align(text_buffer_t *self, vec2 *pen, enum Align alignment); - -/** - * Get the rectangle surrounding the text - * - * @param self a text buffer - * @param pen pen used in last call (must be unmodified) - */ -vec4 text_buffer_get_bounds(text_buffer_t *self, vec2 *pen); - -/** - * Clear text buffer - * - * @param self a text buffer - */ -void text_buffer_clear(text_buffer_t *self); - -/** @} */ - -#ifdef __cplusplus -} -} -#endif - -#endif /* #define __TEXT_BUFFER_H__ */