This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project gfxprim.git.
The branch, master has been updated via 9743963133809d6610a4986dbe1514e333e87589 (commit) via d9e3b063bae380e838bf4ae99ddc5ca387b73877 (commit) from 25e3933b27e047c26e4eefd3024d51bd44fca741 (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- http://repo.or.cz/w/gfxprim.git/commit/9743963133809d6610a4986dbe1514e333e87...
commit 9743963133809d6610a4986dbe1514e333e87589 Merge: d9e3b06 25e3933 Author: Cyril Hrubis metan@ucw.cz Date: Tue Dec 13 20:35:44 2011 +0100
Merge ssh://repo.or.cz/srv/git/gfxprim
http://repo.or.cz/w/gfxprim.git/commit/d9e3b063bae380e838bf4ae99ddc5ca387b73...
commit d9e3b063bae380e838bf4ae99ddc5ca387b73877 Author: Cyril Hrubis metan@ucw.cz Date: Tue Dec 13 18:39:46 2011 +0100
text: First badly hacked support for freetype.
* The text is rendered in 1bpp mode and not really nice
* Changes to gfxprim font rendering would be needed before we got anything better.
diff --git a/configure b/configure index 36b0418..bb7c7cb 100755 --- a/configure +++ b/configure @@ -167,7 +167,7 @@ if __name__ == '__main__': [header_exists, "jpeglib.h"], "", "-ljpeg"], ["freetype", "A high-quality and portable font engine", - [header_exists, "ft2build.h"], "", ""]], cfg) + [header_exists, "ft2build.h"], "", "`freetype-config --libs`"]], cfg) parser = OptionParser(); diff --git a/include/text/GP_FreeType.h b/include/text/GP_FreeType.h new file mode 100644 index 0000000..954096f --- /dev/null +++ b/include/text/GP_FreeType.h @@ -0,0 +1,30 @@ +/***************************************************************************** + * This file is part of gfxprim library. * + * * + * Gfxprim 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. * + * * + * Gfxprim 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 gfxprim; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, * + * Boston, MA 02110-1301 USA * + * * + * Copyright (C) 2009-2011 Cyril Hrubis metan@ucw.cz * + * * + *****************************************************************************/ + +#ifndef TEXT_GP_FREE_TYPE_H +#define TEXT_GP_FREE_TYPE_H + +#include "GP_TextStyle.h" +#include "GP_TextMetric.h" + + +#endif /* TEXT_GP_FREE_TYPE_H */ diff --git a/libs/text/GP_Font.c b/libs/text/GP_Font.c index 8778ce3..b3b8681 100644 --- a/libs/text/GP_Font.c +++ b/libs/text/GP_Font.c @@ -126,13 +126,12 @@ GP_RetCode GP_FontLoad(GP_Font **pfont, const char *filename) if (pfont == NULL || filename == NULL) return GP_ENULLPTR;
- /* allocate the font metadata structure */ - GP_Font *font = (GP_Font *) calloc(1, sizeof(*font)); + GP_Font *font = malloc(sizeof(*font)); if (font == NULL) return GP_ENOMEM;
- /* open the font file */ FILE *f = fopen(filename, "r"); + if (f == NULL) { result = GP_ENOENT; goto bad; diff --git a/libs/text/GP_FreeType.c b/libs/text/GP_FreeType.c new file mode 100644 index 0000000..35b98e1 --- /dev/null +++ b/libs/text/GP_FreeType.c @@ -0,0 +1,190 @@ +/***************************************************************************** + * This file is part of gfxprim library. * + * * + * Gfxprim 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. * + * * + * Gfxprim 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 gfxprim; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, * + * Boston, MA 02110-1301 USA * + * * + * Copyright (C) 2009-2011 Cyril Hrubis metan@ucw.cz * + * * + *****************************************************************************/ + +#include <ft2build.h> +#include FT_FREETYPE_H + +#include "core/GP_Debug.h" +#include "GP_FreeType.h" + +GP_Font *GP_FontFreeTypeLoad(const char *path, uint32_t width, uint32_t height) +{ + int err; + + FT_Library library; + FT_Face face; + + err = FT_Init_FreeType(&library); + + if (err) { + GP_DEBUG(1, "Failed to initalize Free Type"); + return NULL; + } + + err = FT_New_Face(library, path, 0, &face); + + if (err) { + //TODO: FT_Exit_FreeType() ? + GP_DEBUG(1, "Failed to open font '%s'", path); + return NULL; + } + + GP_DEBUG(1, "Opened font '%s'", path); + GP_DEBUG(2, "Font family_name='%s' style_name='%s' num_glyphs=%li", + face->family_name, face->style_name, + (long)face->num_glyphs); + GP_DEBUG(2, "Font ascender=%i descender=%i height=%i", + (int)face->ascender, (int)face->descender, (int)face->height); + + //TODO: not scalable fonts? + err = FT_Set_Pixel_Sizes(face, width, height); + + if (err) { + GP_DEBUG(1, "Failed to set pixel size"); + return NULL; + } + + GP_Font *font = malloc(sizeof(GP_Font)); + + if (font == NULL) { + GP_DEBUG(1, "Malloc failed :("); + goto err1; + } + + strncpy(font->family, face->family_name, sizeof(font->family)); + font->family[GP_FONT_NAME_MAX] = '0'; + strncpy(font->name, face->style_name, sizeof(font->name)); + font->name[GP_FONT_NAME_MAX] = '0'; + strcpy(font->author, "Unknown"); + strcpy(font->license, "Unknown"); + + font->charset = GP_CHARSET_7BIT; + font->version = 0; + + unsigned int i; + + font->height = 0; + font->bytes_per_line = 0; + font->max_bounding_width = 0; + font->baseline = 0; + + int32_t baseline = 0; + + for (i = 0x21; i < 0x7f; i++) { + FT_UInt glyph_idx = FT_Get_Char_Index(face, i); + + err = FT_Load_Glyph(face, glyph_idx, FT_LOAD_DEFAULT); + + if (err) { + GP_DEBUG(1, "Failed to load glyph '%c'", i); + goto err2; + } + + err = FT_Render_Glyph(face->glyph, FT_RENDER_MODE_MONO); + + if (err) { + GP_DEBUG(1, "Failed to render glyph '%c'", i); + goto err2; + } + + FT_Bitmap *bitmap = &face->glyph->bitmap; + + GP_DEBUG(2, "Glyph '%c' bitmap rows=%i width=%i pitch=%i", + i, bitmap->rows, bitmap->width, bitmap->pitch); + + GP_DEBUG(2, " bitmap top=%i left=%i", + face->glyph->bitmap_top, face->glyph->bitmap_left); + + width = (face->glyph->metrics.width>>6); + + if (font->max_bounding_width < width) + font->max_bounding_width = width; + + if (font->bytes_per_line < bitmap->pitch) + font->bytes_per_line = bitmap->pitch; + + height = face->glyph->metrics.height>>6; + + if (font->height < height) + font->height = height; + + baseline = bitmap->rows - face->glyph->bitmap_top; + + if (font->baseline < baseline) + font->baseline = baseline; + } + + size_t font_data_size = GP_GetFontDataSize(font); + font->data = malloc(font_data_size); + + if (font->data == NULL) { + GP_DEBUG(1, "Malloc failed :("); + goto err2; + } + + memset(font->data, 0, font_data_size); + + for (i = 0x21; i < 0x7f; i++) { + FT_UInt glyph_idx = FT_Get_Char_Index(face, i); + + err = FT_Load_Glyph(face, glyph_idx, FT_LOAD_DEFAULT); + + if (err) { + GP_DEBUG(1, "Failed to load glyph '%c'", i); + goto err2; + } + + err = FT_Render_Glyph(face->glyph, FT_RENDER_MODE_MONO); + + if (err) { + GP_DEBUG(1, "Failed to render glyph '%c'", i); + goto err2; + } + + FT_Bitmap *bitmap = &face->glyph->bitmap; + + GP_CharData *char_data = (GP_CharData*)GP_GetCharData(font, i); + + char_data->pre_offset = face->glyph->bitmap_left; + char_data->post_offset = face->glyph->advance.x>>6; + + char_data->char_width = bitmap->width; + + int x, y; + + for (y = 0; y < bitmap->rows; y++) { + for (x = 0; x < bitmap->pitch; x++) { + uint8_t trans_y = y + font->height - font->baseline - face->glyph->bitmap_top; + uint8_t addr = font->bytes_per_line * trans_y + x; + + char_data->bitmap[addr] = bitmap->buffer[y*bitmap->pitch + x]; + } + } + } + + return font; +err2: + free(font); +err1: + //TODO FREETYPE CLEANUP + return NULL; +} diff --git a/libs/text/Makefile b/libs/text/Makefile index 300ad6e..448c8fb 100644 --- a/libs/text/Makefile +++ b/libs/text/Makefile @@ -1,5 +1,9 @@ TOPDIR=../.. CSOURCES=$(shell ls *.c) LIBNAME=text + include $(TOPDIR)/include.mk include $(TOPDIR)/lib.mk + +GP_FreeType.dep: CFLAGS+=`freetype-config --cflags` +GP_FreeType.o: CFLAGS+=`freetype-config --cflags` diff --git a/pylib/templates/common.c.t b/pylib/templates/common.c.t index b4af2f8..d3fcbd8 100644 --- a/pylib/templates/common.c.t +++ b/pylib/templates/common.c.t @@ -9,3 +9,8 @@ * Maybe opts, adds comma on the right side. */ {% macro maybe_opts_r(opts) %}{% if opts %}{{ opts }}, {% endif %}{% endmacro %} + +/* + * Converts channels to params + */ +{% macro expand_chanslist(chlist) %} {{ chlist[0][0] }}{% for i in chlist %}, {{ i[0] }}{% endfor %}{% endmacro %} diff --git a/tests/SDL/fonttest.c b/tests/SDL/fonttest.c index 4bfa945..4dd232c 100644 --- a/tests/SDL/fonttest.c +++ b/tests/SDL/fonttest.c @@ -197,9 +197,9 @@ int main(int argc, char *argv[]) if (argc > 1) { GP_RetCode err; fprintf(stderr, "nLoading font '%s'n", argv[1]); - err = GP_FontLoad(&font, argv[1]); + font = GP_FontFreeTypeLoad(argv[1], 17, 20);
- if (err) { + if (font == NULL) { fprintf(stderr, "Error: %sn", GP_RetCodeName(err)); return 1; }
-----------------------------------------------------------------------
Summary of changes: configure | 2 +- .../histogram.h => include/text/GP_FreeType.h | 10 +- libs/text/GP_Font.c | 5 +- libs/text/GP_FreeType.c | 190 ++++++++++++++++++++ libs/text/Makefile | 4 + pylib/templates/common.c.t | 5 + tests/SDL/fonttest.c | 4 +- 7 files changed, 209 insertions(+), 11 deletions(-) copy demos/grinder/histogram.h => include/text/GP_FreeType.h (91%) create mode 100644 libs/text/GP_FreeType.c
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.