do not consider division safe for |0 removal, and add testcase 2 from issue 324
This commit is contained in:
Родитель
f0427fc434
Коммит
231b619286
|
@ -0,0 +1,184 @@
|
|||
/* 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;
|
||||
|
||||
unsigned char pixelData[32 * 32];
|
||||
|
||||
/* 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;
|
||||
int xbyte;
|
||||
int xbit;
|
||||
unsigned char* pcur;
|
||||
|
||||
unsigned char* src = bitmap->buffer;
|
||||
unsigned char* dest = pixelData;
|
||||
|
||||
// Note: FT_RENDER_MONO_MODE render characater's one pixel by a single bit,
|
||||
// translate the single bit to a single char for displaying image.
|
||||
for(int _y = 0; _y < bitmap->rows; ++_y)
|
||||
{
|
||||
for(int _x = 0; _x < bitmap->width; ++_x)
|
||||
{
|
||||
xbyte = _x / 8;
|
||||
xbit = _x - xbyte * 8;
|
||||
pcur = dest + _x;
|
||||
|
||||
// test if the pixel bit be set
|
||||
if(src[xbyte] & (0x80 >> xbit))
|
||||
{
|
||||
*pcur = 0xFF;
|
||||
}
|
||||
else
|
||||
{
|
||||
*pcur = 0;
|
||||
}
|
||||
}
|
||||
src += bitmap->pitch;
|
||||
dest += bitmap->width;
|
||||
}
|
||||
|
||||
// display the character to ref txt file
|
||||
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] |= pixelData[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_Vector pen; /* untransformed origin */
|
||||
|
||||
char* filename;
|
||||
char* text;
|
||||
|
||||
double angle;
|
||||
int target_height;
|
||||
int n, num_chars;
|
||||
FT_UInt glyphIndex;
|
||||
|
||||
if ( argc != 6 )
|
||||
{
|
||||
fprintf ( stderr, "usage: %s font sample-text width height angle\n", argv[0] );
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
filename = argv[1]; /* first argument */
|
||||
text = argv[2]; /* second argument */
|
||||
num_chars = strlen( text );
|
||||
WIDTH = atoi(argv[3]);
|
||||
HEIGHT = atoi(argv[4]);
|
||||
angle = ( ((float)atoi(argv[5])) / 360 ) * 3.14159 * 2; /* use 25 degrees */
|
||||
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, 32 * 64, 0,
|
||||
0, 0 ); /* set character size */
|
||||
if (error) printf("Set_Char_Size Error! %d\n", error);
|
||||
|
||||
slot = face->glyph;
|
||||
pen.x = 0;
|
||||
pen.y = 0;
|
||||
for ( n = 0; n < num_chars; n++ )
|
||||
{
|
||||
/* set transformation */
|
||||
FT_Set_Transform( face, 0, &pen );
|
||||
|
||||
/* load glyph image into the slot (erase previous one) */
|
||||
glyphIndex = FT_Get_Char_Index(face, text[n]);
|
||||
|
||||
/* load glyph image into the slot (erase previous one) */
|
||||
error = FT_Load_Glyph(face, glyphIndex, FT_LOAD_DEFAULT);
|
||||
if(error) printf("FT_Load_Glyph Error! %d\n", error);
|
||||
|
||||
error = FT_Render_Glyph(slot, FT_RENDER_MODE_MONO);
|
||||
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 );
|
||||
|
||||
/* increment pen position */
|
||||
pen.x += slot->advance.x;
|
||||
pen.y += slot->advance.y;
|
||||
}
|
||||
|
||||
show_image();
|
||||
|
||||
FT_Done_Face ( face );
|
||||
FT_Done_FreeType( library );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* EOF */
|
|
@ -0,0 +1,33 @@
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
***** ***** ****
|
||||
***** ****** *****
|
||||
***** ******* *****
|
||||
***** ******* ****
|
||||
***** ******* ****
|
||||
***** *** **** *****
|
||||
***** **** **** ****
|
||||
**** **** **** ****
|
||||
***** **** **** ****
|
||||
***** **** ***** ****
|
||||
***** **** **** ****
|
||||
**** **** **** ****
|
||||
**** **** **** ****
|
||||
***** *** **** ****
|
||||
**** **** **** ****
|
||||
**** **** **** ****
|
||||
**** **** **** ***
|
||||
******* ********
|
||||
******* *******
|
||||
******* *******
|
||||
******* ******
|
||||
***** *****
|
||||
Non-0s: 342
|
|
@ -4724,6 +4724,10 @@ def process(filename):
|
|||
)
|
||||
open(filename, 'w').write(src)
|
||||
'''
|
||||
|
||||
# Not needed for js, but useful for debugging
|
||||
shutil.copyfile(path_from_root('tests', 'freetype', 'LiberationSansBold.ttf'), os.path.join(self.get_dir(), 'font.ttf'))
|
||||
|
||||
# Main
|
||||
self.do_run(open(path_from_root('tests', 'freetype', 'main.c'), 'r').read(),
|
||||
open(path_from_root('tests', 'freetype', 'ref.txt'), 'r').read(),
|
||||
|
@ -4733,7 +4737,7 @@ def process(filename):
|
|||
post_build=post)
|
||||
#build_ll_hook=self.do_autodebug)
|
||||
|
||||
# Second testcase, github issue 324
|
||||
# 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(),
|
||||
|
@ -4742,6 +4746,14 @@ def process(filename):
|
|||
includes=[path_from_root('tests', 'freetype', 'include')],
|
||||
post_build=post)
|
||||
|
||||
print '[issue 324 case 2]'
|
||||
self.do_run(open(path_from_root('tests', 'freetype', 'main_3.c'), 'r').read(),
|
||||
open(path_from_root('tests', 'freetype', 'ref_3.txt'), 'r').read(),
|
||||
['font.ttf', 'W', '32', '32', '0'],
|
||||
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')
|
||||
|
|
|
@ -388,7 +388,7 @@ function simplifyExpressionsPre(ast) {
|
|||
|
||||
function simplifyBitops(ast) {
|
||||
var USEFUL_BINARY_OPS = set('<<', '>>', '|', '&', '^');
|
||||
var SAFE_BINARY_OPS = set('+', '-', '*', '/', '%');
|
||||
var SAFE_BINARY_OPS = set('+', '-', '*', '%'); // division is unsafe as it creates non-ints in JS
|
||||
var ZERO = ['num', 0];
|
||||
var rerun = true;
|
||||
while (rerun) {
|
||||
|
|
|
@ -86,7 +86,7 @@ function bits() {
|
|||
z($f << 2);
|
||||
z($f * 100 << 2);
|
||||
z($f % 2 | 255);
|
||||
z($f / 55 & 255);
|
||||
z(($f | 0) / 55 & 255);
|
||||
z($f - 22 ^ 1);
|
||||
z($f + 15 << 2);
|
||||
}
|
||||
|
@ -312,6 +312,6 @@ function notComps() {
|
|||
}
|
||||
}
|
||||
function tricky() {
|
||||
var $conv642 = $conv6374 - (($132 << 16 >> 16) / 2 & -1) & 65535;
|
||||
var $conv642 = $conv6374 - (($132 << 16 >> 16 | 0) / 2 & -1) & 65535;
|
||||
}
|
||||
// EMSCRIPTEN_GENERATED_FUNCTIONS: ["abc", "xyz", "xyz2", "expr", "loopy", "bits", "maths", "hoisting", "demangle", "lua", "moreLabels", "notComps", "tricky"]
|
||||
|
|
Загрузка…
Ссылка в новой задаче