[Scummvm-git-logs] scummvm master -> accd508b9cbffc136c07088d2309ac8b84db6f06
dreammaster
noreply at scummvm.org
Tue Mar 29 03:30:38 UTC 2022
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
accd508b9c GRAPHICS: Create set of wrapper functions for accessing FreeType directly
Commit: accd508b9cbffc136c07088d2309ac8b84db6f06
https://github.com/scummvm/scummvm/commit/accd508b9cbffc136c07088d2309ac8b84db6f06
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-28T20:29:36-07:00
Commit Message:
GRAPHICS: Create set of wrapper functions for accessing FreeType directly
Changed paths:
A graphics/fonts/freetype.cpp
A graphics/fonts/freetype.h
engines/ags/lib/alfont/alfont.cpp
graphics/module.mk
diff --git a/engines/ags/lib/alfont/alfont.cpp b/engines/ags/lib/alfont/alfont.cpp
index a3c6930cae3..2efb425df3c 100644
--- a/engines/ags/lib/alfont/alfont.cpp
+++ b/engines/ags/lib/alfont/alfont.cpp
@@ -29,13 +29,25 @@
#include "ags/lib/allegro/draw.h"
#include "ags/lib/allegro/gfx.h"
#include "ags/lib/allegro/unicode.h"
-#include <ft2build.h>
-#include <wchar.h>
-#include FT_FREETYPE_H
-#include FT_GLYPH_H
+#include "graphics/fonts/freetype.h"
namespace AGS3 {
+using Graphics::FreeType::Init_FreeType;
+using Graphics::FreeType::Done_FreeType;
+using Graphics::FreeType::Load_Glyph;
+using Graphics::FreeType::Get_Glyph;
+using Graphics::FreeType::Glyph_Copy;
+using Graphics::FreeType::Glyph_To_Bitmap;
+using Graphics::FreeType::Done_Glyph;
+using Graphics::FreeType::Set_Pixel_Sizes;
+using Graphics::FreeType::New_Face;
+using Graphics::FreeType::New_Memory_Face;
+using Graphics::FreeType::Done_Face;
+using Graphics::FreeType::Get_Char_Index;
+using Graphics::FreeType::Get_Kerning;
+
+
#undef TRUE
#undef FALSE
#define TRUE -1
@@ -239,8 +251,8 @@ static void _alfont_cache_glyph(ALFONT_FONT *f, int glyph_number) {
if (!f->cached_glyphs[glyph_number].is_cached) {
FT_Glyph new_glyph;
/* load the font glyph */
- FT_Load_Glyph(f->face, glyph_number, FT_LOAD_DEFAULT);
- FT_Get_Glyph(f->face->glyph, &new_glyph);
+ Load_Glyph(f->face, glyph_number, FT_LOAD_DEFAULT);
+ Get_Glyph(f->face->glyph, &new_glyph);
/* ok, this glyph is now cached */
f->cached_glyphs[glyph_number].is_cached = 1;
@@ -253,11 +265,11 @@ static void _alfont_cache_glyph(ALFONT_FONT *f, int glyph_number) {
FT_Glyph glyph;
FT_BitmapGlyph bmp_glyph;
- FT_Glyph_Copy(new_glyph, &glyph);
+ Glyph_Copy(new_glyph, &glyph);
/* only render glyph if it is not already a bitmap */
if (glyph->format != ft_glyph_format_bitmap)
- FT_Glyph_To_Bitmap(&glyph, ft_render_mode_mono, NULL, 1);
+ Glyph_To_Bitmap(&glyph, ft_render_mode_mono, NULL, 1);
/* the FT rendered bitmap */
bmp_glyph = (FT_BitmapGlyph)glyph;
@@ -309,7 +321,7 @@ static void _alfont_cache_glyph(ALFONT_FONT *f, int glyph_number) {
}
}
- FT_Done_Glyph(glyph);
+ Done_Glyph(glyph);
}
@@ -319,11 +331,11 @@ static void _alfont_cache_glyph(ALFONT_FONT *f, int glyph_number) {
FT_Glyph glyph;
FT_BitmapGlyph bmp_glyph;
- FT_Glyph_Copy(new_glyph, &glyph);
+ Glyph_Copy(new_glyph, &glyph);
/* only render glyph if it is not already a bitmap */
if (glyph->format != ft_glyph_format_bitmap)
- FT_Glyph_To_Bitmap(&glyph, ft_render_mode_normal, NULL, 1);
+ Glyph_To_Bitmap(&glyph, ft_render_mode_normal, NULL, 1);
/* the FT rendered bitmap */
bmp_glyph = (FT_BitmapGlyph)glyph;
@@ -379,14 +391,14 @@ static void _alfont_cache_glyph(ALFONT_FONT *f, int glyph_number) {
}
}
- FT_Done_Glyph(glyph);
+ Done_Glyph(glyph);
}
f->cached_glyphs[glyph_number].advancex = f->face->glyph->advance.x >> 6;
f->cached_glyphs[glyph_number].advancey = f->face->glyph->advance.y >> 6;
/* delete the glyph */
- FT_Done_Glyph(new_glyph);
+ Done_Glyph(new_glyph);
}
}
@@ -425,7 +437,7 @@ int alfont_set_font_size_ex(ALFONT_FONT *f, int h, int flags) {
test_h = h;
direction = 0;
while (1) {
- error = FT_Set_Pixel_Sizes(f->face, 0, test_h);
+ error = Set_Pixel_Sizes(f->face, 0, test_h);
if (error)
break;
@@ -454,7 +466,7 @@ int alfont_set_font_size_ex(ALFONT_FONT *f, int h, int flags) {
else if ((direction > 0) && (real_height > h)) {
/* decrease one and found */
test_h--;
- FT_Set_Pixel_Sizes(f->face, 0, test_h);
+ Set_Pixel_Sizes(f->face, 0, test_h);
break;
}
@@ -486,7 +498,7 @@ int alfont_set_font_size_ex(ALFONT_FONT *f, int h, int flags) {
return ALFONT_OK;
} else {
- FT_Set_Pixel_Sizes(f->face, 0, f->real_face_h);
+ Set_Pixel_Sizes(f->face, 0, f->real_face_h);
return ALFONT_ERROR;
}
}
@@ -504,7 +516,7 @@ int alfont_get_font_real_height(ALFONT_FONT *f) {
void alfont_exit(void) {
if (alfont_inited) {
alfont_inited = 0;
- FT_Done_FreeType(ft_library);
+ Done_FreeType(ft_library);
memset(&ft_library, 0, sizeof(ft_library));
}
}
@@ -516,7 +528,7 @@ int alfont_init(void) {
else {
int error;
memset(&ft_library, 0, sizeof(ft_library));
- error = FT_Init_FreeType(&ft_library);
+ error = Init_FreeType(&ft_library);
if (!error)
alfont_inited = 1;
@@ -544,7 +556,7 @@ ALFONT_FONT *alfont_load_font(const char *filepathname) {
font->data_size = 0;
/* load the font */
- error = FT_New_Face(ft_library, filepathname, 0, &font->face);
+ error = New_Face(ft_library, filepathname, 0, &font->face);
if (error) {
free(font);
@@ -622,7 +634,7 @@ ALFONT_FONT *alfont_load_font_from_mem(const char *data, int data_len) {
memcpy((void *)font->data, (void *)data, data_len);
/* load the font */
- error = FT_New_Memory_Face(ft_library, (const FT_Byte *)font->data, font->data_size, 0, &font->face);
+ error = New_Memory_Face(ft_library, (const FT_Byte *)font->data, font->data_size, 0, &font->face);
if (error) {
free(font->data);
@@ -690,7 +702,7 @@ void alfont_destroy_font(ALFONT_FONT *f) {
_alfont_delete_glyphs(f);
/* delete the face */
- FT_Done_Face(f->face);
+ Done_Face(f->face);
if (f->fixed_sizes)
free(f->fixed_sizes);
@@ -1020,7 +1032,7 @@ void alfont_textout_aa_ex(BITMAP *bmp, ALFONT_FONT *f, const char *s, int x, int
/* get the character out of the font */
if (f->face->charmap)
- glyph_index_tmp = FT_Get_Char_Index(f->face, character);
+ glyph_index_tmp = Get_Char_Index(f->face, character);
else
glyph_index_tmp = character;
@@ -1058,7 +1070,7 @@ void alfont_textout_aa_ex(BITMAP *bmp, ALFONT_FONT *f, const char *s, int x, int
/* get the character out of the font */
if (f->face->charmap)
- glyph_index = FT_Get_Char_Index(f->face, character);
+ glyph_index = Get_Char_Index(f->face, character);
else
glyph_index = character;
@@ -1077,7 +1089,7 @@ void alfont_textout_aa_ex(BITMAP *bmp, ALFONT_FONT *f, const char *s, int x, int
#ifdef APPLY_FONT_KERNING
if (last_glyph_index) {
FT_Vector v;
- FT_Get_Kerning(f->face, last_glyph_index, glyph_index, ft_kerning_default, &v);
+ Get_Kerning(f->face, last_glyph_index, glyph_index, ft_kerning_default, &v);
real_x += v.x >> 6;
real_y += v.y >> 6;
}
@@ -2091,7 +2103,7 @@ void alfont_textout_ex(BITMAP * bmp, ALFONT_FONT * f, const char *s, int x, int
/* get the character out of the font */
if (f->face->charmap)
- glyph_index_tmp = FT_Get_Char_Index(f->face, character);
+ glyph_index_tmp = Get_Char_Index(f->face, character);
else
glyph_index_tmp = character;
@@ -2128,7 +2140,7 @@ void alfont_textout_ex(BITMAP * bmp, ALFONT_FONT * f, const char *s, int x, int
/* get the character out of the font */
if (f->face->charmap)
- glyph_index = FT_Get_Char_Index(f->face, character);
+ glyph_index = Get_Char_Index(f->face, character);
else
glyph_index = character;
@@ -2147,7 +2159,7 @@ void alfont_textout_ex(BITMAP * bmp, ALFONT_FONT * f, const char *s, int x, int
#ifdef APPLY_FONT_KERNING
if (last_glyph_index) {
FT_Vector v;
- FT_Get_Kerning(f->face, last_glyph_index, glyph_index, ft_kerning_default, &v);
+ Get_Kerning(f->face, last_glyph_index, glyph_index, ft_kerning_default, &v);
real_x += v.x >> 6;
real_y += v.y >> 6;
}
@@ -2873,7 +2885,7 @@ int alfont_text_length(ALFONT_FONT * f, const char *str) {
/* get the character out of the font */
if (f->face->charmap)
- glyph_index_tmp = FT_Get_Char_Index(f->face, character);
+ glyph_index_tmp = Get_Char_Index(f->face, character);
else
glyph_index_tmp = character;
@@ -2898,14 +2910,14 @@ int alfont_text_length(ALFONT_FONT * f, const char *str) {
#endif
if (f->face->charmap)
- glyph_index = FT_Get_Char_Index(f->face, character);
+ glyph_index = Get_Char_Index(f->face, character);
else
glyph_index = character;
/* apply kerning */
/*if (last_glyph_index) {
FT_Vector v;
- FT_Get_Kerning(f->face, last_glyph_index, glyph_index, ft_kerning_default, &v);
+ Get_Kerning(f->face, last_glyph_index, glyph_index, ft_kerning_default, &v);
total_length += v.x >> 6;
}*/
last_glyph_index = glyph_index;
@@ -2977,14 +2989,14 @@ int alfont_char_length(ALFONT_FONT * f, int character) {
/* get the character out of the font */
if (f->face->charmap)
- glyph_index = FT_Get_Char_Index(f->face, character);
+ glyph_index = Get_Char_Index(f->face, character);
else
glyph_index = character;
/* apply kerning */
/*if (last_glyph_index) {
FT_Vector v;
- FT_Get_Kerning(f->face, last_glyph_index, glyph_index, ft_kerning_default, &v);
+ Get_Kerning(f->face, last_glyph_index, glyph_index, ft_kerning_default, &v);
total_length += v.x >> 6;
}*/
last_glyph_index = glyph_index;
diff --git a/graphics/fonts/freetype.cpp b/graphics/fonts/freetype.cpp
new file mode 100644
index 00000000000..38bbe286c95
--- /dev/null
+++ b/graphics/fonts/freetype.cpp
@@ -0,0 +1,97 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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/>.
+ *
+ */
+
+#ifdef USE_FREETYPE2
+
+// Since FreeType2 includes files, which contain forbidden symbols, we need to
+// allow all symbols here.
+#define FORBIDDEN_SYMBOL_ALLOW_ALL
+
+#include "common/scummsys.h"
+#include <wchar.h>
+#include <ft2build.h>
+#include FT_FREETYPE_H
+#include FT_GLYPH_H
+
+namespace Graphics {
+namespace FreeType {
+
+FT_Error Init_FreeType(FT_Library *alibrary) {
+ return FT_Init_FreeType(alibrary);
+}
+
+FT_Error Done_FreeType(FT_Library library) {
+ return FT_Done_FreeType(library);
+}
+
+FT_Error Load_Glyph(FT_Face face, FT_UInt glyph_index, FT_Int32 load_flags) {
+ return FT_Load_Glyph(face, glyph_index, load_flags);
+}
+
+FT_Error Get_Glyph(FT_GlyphSlot slot, FT_Glyph *aglyph) {
+ return FT_Get_Glyph(slot, aglyph);
+}
+
+FT_Error Glyph_Copy(FT_Glyph source, FT_Glyph *target) {
+ return FT_Glyph_Copy(source, target);
+}
+
+FT_Error Glyph_To_Bitmap(FT_Glyph *the_glyph, FT_Render_Mode render_mode,
+ FT_Vector *origin, FT_Bool destroy) {
+ return FT_Glyph_To_Bitmap(the_glyph, render_mode, origin, destroy);
+}
+
+void Done_Glyph(FT_Glyph glyph) {
+ return FT_Done_Glyph(glyph);
+}
+
+FT_Error Set_Pixel_Sizes(FT_Face face, FT_UInt pixel_width,
+ FT_UInt pixel_height) {
+ return FT_Set_Pixel_Sizes(face, pixel_width, pixel_height);
+}
+
+FT_Error New_Face(FT_Library library, const char *pathname,
+ FT_Long face_index, FT_Face *aface) {
+ return FT_New_Face(library, pathname, face_index, aface);
+}
+
+FT_Error New_Memory_Face(FT_Library library, const FT_Byte *file_base,
+ FT_Long file_size, FT_Long face_index, FT_Face *aface) {
+ return FT_New_Memory_Face(library, file_base, file_size, face_index, aface);
+}
+
+FT_Error Done_Face(FT_Face face) {
+ return FT_Done_Face(face);
+}
+
+FT_UInt Get_Char_Index(FT_Face face, FT_ULong charcode) {
+ return FT_Get_Char_Index(face, charcode);
+}
+
+FT_Error Get_Kerning(FT_Face face, FT_UInt left_glyph,
+ FT_UInt right_glyph, FT_UInt kern_mode, FT_Vector *akerning) {
+ return FT_Get_Kerning(face, left_glyph, right_glyph, kern_mode, akerning);
+}
+
+} // End of namespace FreeType
+} // End of namespace Graphics
+
+#endif
diff --git a/graphics/fonts/freetype.h b/graphics/fonts/freetype.h
new file mode 100644
index 00000000000..2d588256980
--- /dev/null
+++ b/graphics/fonts/freetype.h
@@ -0,0 +1,60 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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/>.
+ *
+ */
+
+#ifndef GRAPHICS_FONTS_FREETYPE_H
+#define GRAPHICS_FONTS_FREETYPE_H
+
+#ifdef USE_FREETYPE2
+
+#include "common/scummsys.h"
+#include <ft2build.h>
+#include FT_FREETYPE_H
+#include FT_GLYPH_H
+
+namespace Graphics {
+namespace FreeType {
+
+extern FT_Error Init_FreeType(FT_Library *alibrary);
+extern FT_Error Done_FreeType(FT_Library library);
+extern FT_Error Load_Glyph(FT_Face face, FT_UInt glyph_index, FT_Int32 load_flags);
+extern FT_Error Get_Glyph(FT_GlyphSlot slot, FT_Glyph *aglyph);
+extern FT_Error Glyph_Copy(FT_Glyph source, FT_Glyph *target);
+extern FT_Error Glyph_To_Bitmap(FT_Glyph *the_glyph, FT_Render_Mode render_mode,
+ FT_Vector *origin, FT_Bool destroy);
+extern void Done_Glyph(FT_Glyph glyph);
+extern FT_Error Set_Pixel_Sizes(FT_Face face, FT_UInt pixel_width,
+ FT_UInt pixel_height);
+extern FT_Error New_Face(FT_Library library, const char *pathname,
+ FT_Long face_index, FT_Face *aface);
+extern FT_Error New_Memory_Face(FT_Library library, const FT_Byte *file_base,
+ FT_Long file_size, FT_Long face_index, FT_Face *aface);
+extern FT_Error Done_Face(FT_Face face);
+extern FT_UInt Get_Char_Index(FT_Face face, FT_ULong charcode);
+extern FT_Error Get_Kerning(FT_Face face, FT_UInt left_glyph,
+ FT_UInt right_glyph, FT_UInt kern_mode, FT_Vector *akerning);
+
+} // End of namespace FreeType
+} // End of namespace Graphics
+
+#endif
+
+#endif
+
diff --git a/graphics/module.mk b/graphics/module.mk
index 70ec14520ca..5fdeb840398 100644
--- a/graphics/module.mk
+++ b/graphics/module.mk
@@ -8,6 +8,7 @@ MODULE_OBJS := \
fonts/amigafont.o \
fonts/bdf.o \
fonts/consolefont.o \
+ fonts/freetype.o \
fonts/macfont.o \
fonts/newfont_big.o \
fonts/newfont.o \
More information about the Scummvm-git-logs
mailing list