aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/freetype/main_2.c135
-rw-r--r--tests/freetype/ref_2.txt33
-rwxr-xr-xtests/runner.py9
3 files changed, 177 insertions, 0 deletions
diff --git a/tests/freetype/main_2.c b/tests/freetype/main_2.c
new file mode 100644
index 00000000..85e5609d
--- /dev/null
+++ b/tests/freetype/main_2.c
@@ -0,0 +1,135 @@
+/* example1.c */
+/* */
+/* This small program shows how to print a rotated string with the */
+/* FreeType 2 library. */
+
+
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include <stdlib.h>
+
+#include <ft2build.h>
+#include FT_FREETYPE_H
+
+int WIDTH = 0;
+int HEIGHT = 0;
+
+/* origin is the upper left corner */
+unsigned char *image;
+
+
+/* Replace this function with something useful. */
+
+void
+draw_bitmap( FT_Bitmap* bitmap,
+ FT_Int x,
+ FT_Int y)
+{
+ FT_Int i, j, p, q;
+ FT_Int x_max = x + bitmap->width;
+ FT_Int y_max = y + bitmap->rows;
+
+ for ( i = x, p = 0; i < x_max; i++, p++ )
+ {
+ for ( j = y, q = 0; j < y_max; j++, q++ )
+ {
+ if ( i < 0 || j < 0 ||
+ i >= WIDTH || j >= HEIGHT )
+ continue;
+
+ image[j*WIDTH + i] |= bitmap->buffer[q * bitmap->width + p];
+ }
+ }
+}
+
+
+void
+show_image( void )
+{
+ int i, j;
+ int count = 0;
+
+ for ( i = 0; i < HEIGHT; i++ )
+ {
+ for ( j = 0; j < WIDTH; j++ )
+ {
+ if (image[i*WIDTH + j]) count++;
+ putchar(image[i*WIDTH + j] == 0? ' '
+ : image[i*WIDTH + j] < 128 ? '+'
+ : '*' );
+ }
+ putchar( '\n' );
+ }
+ printf("Non-0s: %d\n", count);
+}
+
+
+int
+main( int argc,
+ char** argv )
+{
+ FT_Library library;
+ FT_Face face;
+
+ FT_GlyphSlot slot;
+ FT_Error error;
+
+ FT_UInt glyphIndex;
+
+ char* filename;
+ char* text;
+
+ int target_height;
+
+ if ( argc != 6 )
+ {
+ fprintf ( stderr, "usage: %s font sample-text width height angle\n", argv[0] );
+ exit( 1 );
+ }
+
+ // Only test the character 'w'
+ text = "w";
+
+ filename = argv[1]; /* first argument */
+ WIDTH = atoi(argv[3]);
+ HEIGHT = atoi(argv[4]);
+ target_height = HEIGHT;
+
+ image = (unsigned char*)malloc(WIDTH*HEIGHT);
+ for (int x = 0; x < WIDTH; x++)
+ for (int y = 0; y < HEIGHT; y++)
+ image[y*WIDTH + x] = 0;
+
+ error = FT_Init_FreeType( &library ); /* initialize library */
+ if (error) printf("Init Error! %d\n", error);
+
+ error = FT_New_Face( library, argv[1], 0, &face ); /* create face object */
+ if (error) printf("New_Face Error! %d\n", error);
+
+ /* use 50pt at 100dpi */
+ error = FT_Set_Char_Size( face, 0, 32 * 64, 0, 0 ); /* set character size */
+ if (error) printf("Set_Cshar_Size Error! %d\n", error);
+
+ slot = face->glyph;
+
+ glyphIndex = FT_Get_Char_Index(face, text[0]);
+
+ /* load glyph image into the slot (erase previous one) */
+ error = FT_Load_Glyph(face, glyphIndex, FT_LOAD_NO_BITMAP);
+ if(error) printf("FT_Load_Glyph Error! %d\n", error);
+
+ error = FT_Render_Glyph(slot, FT_RENDER_MODE_NORMAL);
+ if(error) printf("FT_Render_Glyph Error! %d\n", error);
+
+ /* now, draw to our target surface (convert position) */
+ draw_bitmap(&slot->bitmap, slot->bitmap_left, target_height - slot->bitmap_top);
+
+ show_image();
+
+ FT_Done_Face(face);
+ FT_Done_FreeType(library);
+ return 0;
+}
+
+/* EOF */ \ No newline at end of file
diff --git a/tests/freetype/ref_2.txt b/tests/freetype/ref_2.txt
new file mode 100644
index 00000000..c15bb415
--- /dev/null
+++ b/tests/freetype/ref_2.txt
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+****+ +***** +****
+****+ +*****+ +****
++**** ******+ ****+
++**** ******* ****+
++****+ +***+*** +****
+ ****+ +***+***+ +***+
+ +***+ **** ***+ ****+
+ +**** ***+ +*** ****+
+ +**** +***+ +*** +****
+ ****++*** +***++***+
+ +***+**** ***++***+
+ +***+***+ +*******+
+ *******+ +*******
+ ******* +******+
+ +*****+ ******+
+ +*****+ +*****
+ *****+ +*****
+Non-0s: 285
diff --git a/tests/runner.py b/tests/runner.py
index 41a2a2dc..95c892f8 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -4711,6 +4711,15 @@ def process(filename):
post_build=post)
#build_ll_hook=self.do_autodebug)
+ # Second testcase, github issue 324
+ print '[issue 324]'
+ self.do_run(open(path_from_root('tests', 'freetype', 'main_2.c'), 'r').read(),
+ open(path_from_root('tests', 'freetype', 'ref_2.txt'), 'r').read(),
+ ['font.ttf', 'w', '32', '32', '25'],
+ libraries=self.get_freetype(),
+ includes=[path_from_root('tests', 'freetype', 'include')],
+ post_build=post)
+
def test_sqlite(self):
# gcc -O3 -I/home/alon/Dev/emscripten/tests/sqlite -ldl src.c
if self.emcc_args is None: return self.skip('Very slow without ta2, and we would also need to include dlmalloc manually without emcc')