Commit 4fa0f4c
freetype2 validation
Changed files (3)
modifiedlibbirdfont/OpenFontFormatReader.valamodifiedlibbirdfont/TestCases.valamodifiedlibbirdfont/load_svg_font.c
Diff
@@ -18,6 +18,9 @@ [CCode (cname = "load_svg_font")] public extern static StringBuilder? load_svg_font (string file, out int error); +[CCode (cname = "validate_freetype_font")]+public extern static bool validate_freetype_font (string file);+ namespace BirdFont { [SimpleType]@@ -54,7 +54,8 @@ class TestCases { int error; File f = BirdFont.get_settings_directory (); Font font = BirdFont.get_current_font ();-+ bool valid;+ font.set_name ("TEST_FONT"); // draw some test glyphs@@ -67,14 +68,17 @@ class TestCases { warning ("TTF export failed."); } - f = f.get_child (font.get_name () + ".ttf");- + f = f.get_child (font.get_name () + ".ttf") if (!f.query_exists ()) { warning ("File does not exist."); } - data = load_svg_font ((!) f.get_path (), out error);+ valid = validate_freetype_font ((!) f.get_path ());+ if (!valid) {+ warning ("The font does not pass freetype validation.");+ } + data = load_svg_font ((!) f.get_path (), out error); if (error != 0) { warning ("Failed to load font."); return;@@ -249,7 +249,7 @@ GString* get_svg_font (FT_Face face, int* err) { *err = OK; g_string_append (svg, "<?xml version=\"1.0\" standalone=\"no\"?>\n");- g_string_append (svg, "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\" >\n");+ // g_string_append (svg, "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\" >\n"); g_string_append (svg, "<svg xmlns=\"http://www.w3.org/2000/svg\">\n"); g_string_append (svg, "<defs>\n"); g_string_append_printf (svg, "<font id=\"%s\" horiz-adv-x=\"250\">\n", face->family_name);@@ -355,12 +355,6 @@ GString* load_svg_font (char* file, int* err) { return svg; } - error = validate_font (face);- if (error) {- *err = error;- return svg;- }- error = FT_Set_Char_Size (face, 0, 800, 300, 300); if (error) { printf ("Freetype FT_Set_Char_Size failed, error: %d.\n", error);@@ -381,3 +375,29 @@ GString* load_svg_font (char* file, int* err) { *err = OK; return svg; }++guint validate_freetype_font (char* file) {+ FT_Library library;+ FT_Face face;+ int error;+ + error = FT_Init_FreeType (&library);+ if (error != OK) {+ printf ("Freetype init error %d\n", error);+ return FALSE;+ }++ error = FT_New_Face (library, file, 0, &face);+ if (error) {+ printf ("Freetype font face error %d\n", error);+ return FALSE;+ }+ + error = validate_font (face);+ if (error) {+ printf ("Validation failed.\n", error);+ return FALSE;+ }+ + return TRUE;+}