void
EDFBFont::ForceFontAliasing(bool enable)
{
	if(fEngine == NULL) return;
	EAutolock <EDFBGraphicsEngine> autolock(fEngine);
	if(autolock.IsLocked() == false || fEngine->InitCheck() != E_OK) return;

	if(fForceFontAliasing != enable)
	{
		fForceFontAliasing = enable;

		DFBFontDescription fontdesc;
		fontdesc.flags = (DFBFontDescriptionFlags)(DFDESC_ATTRIBUTES | DFDESC_HEIGHT);
		fontdesc.attributes = (fForceFontAliasing ? DFFA_MONOCHROME : DFFA_NONE);
		fontdesc.height = ETK_DIRECTFONT_DEFAULT_SIZE;

		IDirectFBFont *newFont = NULL;
		fEngine->dfbDisplay->CreateFont(fEngine->dfbDisplay, fFilename, &fontdesc, &newFont);
		if(newFont)
		{
			fDFBFont->Release(fDFBFont);
			fDFBFont = newFont;

			int height = 0;
			fDFBFont->GetHeight(fDFBFont, &height);
			float sizes = (float)height;
			SetFixedSize(&sizes, 1);
		}
	}
}
void font_test(LANG lang)
{
    DFBFontDescription fontdesc;
    IDirectFBFont *font;
    DFBResult ret;

    fontdesc.flags = (DFBFontDescriptionFlags)(DFDESC_HEIGHT | DFDESC_HEIGHT);
    fontdesc.height = 70;
    fontdesc.width = 70;

    //ret = dfb->CreateFont(dfb, NULL, &fontdesc, &font);
    ret = dfb->CreateFont(dfb, FONTDIR"/FZCCHK.TTF", &fontdesc, &font);
    if (ret != DFB_OK) {
        cout<<"failed to create  font"<<endl;
        return;
    }
    font->EnumEncodings(font,  TextEncodingCallback, NULL);

    screen->SetFont(screen, font);

    screen->SetColor(screen, 0xFF, 0, 0, 0xFF);
    screen->DrawString(screen, msg[lang][0], -1, 20, 240, DSTF_LEFT);
    cout<<"msg["<<lang<<"][0]: "<<msg[lang][0]<<endl;

    font->Release(font);
}
void font_test()
{
    DFBFontDescription fontdesc;
    IDirectFBFont *font;
    DFBResult ret;

    fontdesc.flags = (DFBFontDescriptionFlags)(DFDESC_HEIGHT | DFDESC_HEIGHT);
    fontdesc.height = 72;
    fontdesc.width = 72;

    //ret = dfb->CreateFont(dfb, NULL, &fontdesc, &font);
    ret = dfb->CreateFont(dfb, FONTDIR"/maozedong.ttf", &fontdesc, &font);
    if (ret != DFB_OK) {
        cout<<"failed to create fix font"<<endl;
        return;
    }

    screen->SetFont(screen, font);

    screen->SetColor(screen, 0xFF, 0, 0, 0xFF);
    screen->DrawString(screen, "DirectFB字体测试", -1, 20, 240, DSTF_LEFT);

    font->Release(font);
}
int
main( int argc, char *argv[] )
{
     int                    i;
     DFBResult              ret;
     DFBSurfaceDescription  desc;
     IDirectFB             *dfb;
     IDirectFBSurface      *dest            = NULL;
     const char            *url             = NULL;
     DFBFontAttributes      attributes      = DFFA_NONE;
     DFBSurfaceTextFlags    text_flags      = DSTF_TOPLEFT;
     int                    outline_width   = 0x10000;
     int                    outline_opacity = 255;
     const DFBColorID       color_ids[2]    = { DCID_PRIMARY, DCID_OUTLINE };
     const DFBColor         colors[2]       = { { 0xff, 0xff, 0xff, 0xff },
                                                { 0xff, 0x00, 0x80, 0xff } };

     /* Initialize DirectFB. */
     ret = DirectFBInit( &argc, &argv );
     if (ret) {
          D_DERROR( ret, "DFBTest/Font: DirectFBInit() failed!\n" );
          return ret;
     }

     /* Parse arguments. */
     for (i=1; i<argc; i++) {
          const char *arg = argv[i];

          if (strcmp( arg, "-h" ) == 0 || strcmp (arg, "--help") == 0)
               return print_usage( argv[0] );
          else if (strcmp (arg, "-v") == 0 || strcmp (arg, "--version") == 0) {
               fprintf (stderr, "dfbtest_blit version %s\n", DIRECTFB_VERSION);
               return false;
          }
          else if (strcmp (arg, "-o") == 0 || strcmp (arg, "--outline") == 0) {
               attributes |= DFFA_OUTLINED;
               text_flags |= DSTF_OUTLINE;
          }
          else if (strcmp (arg, "-ow") == 0 || strcmp (arg, "--outline-width") == 0) {
               if (++i == argc)
                    return print_usage( argv[0] );

               if (sscanf( argv[i], "%d", &outline_width ) != 1)
                    return print_usage( argv[0] );

               outline_width <<= 16;
          }
          else if (strcmp (arg, "-oo") == 0 || strcmp (arg, "--outline-opacity") == 0) {
               if (++i == argc)
                    return print_usage( argv[0] );

               if (sscanf( argv[i], "%d", &outline_opacity ) != 1)
                    return print_usage( argv[0] );
          }
          else if (!url)
               url = arg;
          else
               return print_usage( argv[0] );
     }

     /* Check if we got an URL. */
     if (!url)
          return print_usage( argv[0] );

     /* Create super interface. */
     ret = DirectFBCreate( &dfb );
     if (ret) {
          D_DERROR( ret, "DFBTest/Font: DirectFBCreate() failed!\n" );
          return ret;
     }

     /* Fill description for a primary surface. */
     desc.flags = DSDESC_CAPS;
     desc.caps  = DSCAPS_PRIMARY | DSCAPS_FLIPPING;

     dfb->SetCooperativeLevel( dfb, DFSCL_FULLSCREEN );

     /* Create a primary surface. */
     ret = dfb->CreateSurface( dfb, &desc, &dest );
     if (ret) {
          D_DERROR( ret, "DFBTest/Font: IDirectFB::CreateSurface() failed!\n" );
          goto out;
     }

     dest->GetSize( dest, &desc.width, &desc.height );
     dest->GetPixelFormat( dest, &desc.pixelformat );

     D_INFO( "DFBTest/Font: Destination is %dx%d using %s\n",
             desc.width, desc.height, dfb_pixelformat_name(desc.pixelformat) );

     for (i=10; i<50; i++) {
          IDirectFBFont *font;

          font = CreateFont( dfb, url, i, attributes, outline_width, outline_opacity );

          RenderChecker( dest, 64, 64 );

          dest->SetColors( dest, color_ids, colors, 2 );

          dest->SetFont( dest, font );
          dest->DrawString( dest, "Test String AVAWA", -1, 100, 100, text_flags );

          dest->Flip( dest, NULL, DSFLIP_NONE );

          font->Release( font );

          usleep( 500000 );
     }


out:
     if (dest)
          dest->Release( dest );

     /* Shutdown DirectFB. */
     dfb->Release( dfb );

     return ret;
}
Exemple #5
0
int main(int argc, char *argv[])
{
	IDirectFBDisplayLayer 	*layer;
	DFBWindowDescription	dwsc;
	DFBSurfaceDescription 	dsc;
	DFBDisplayLayerConfig	config;
	IDirectFBWindow 	*window_mic, *window_camera, *window_case, *window_tp;
	IDirectFBSurface 	*surface_case, *surface_tp, *surface_camera;
	IDirectFBSurface 	*surface_mic, *primary, *surface_button;
	IDirectFBFont 		*font;
	DFBRectangle		rect;
	DFBFontDescription 	font_desc;
	DirectThread     *thread_camera, *thread_music, *thread_mic, *thread_tp, *thread_flashlight, *thread_case[case_num];
	DirectThread 	*thread_button;
	 

//	int font_size = 24;
//	int camera_frame = 0;

	int i;
	char font_file[50] = "/misc/font/wqy-zenhei.ttc";
	char conf_file[50] = "/misc/pcba.conf";

	
	bool overflow = false;
	
	case_t *case_x;
	case_x = malloc((case_num + 3) * sizeof(case_t));
	
	//20 case,11 auto case,gps is the last autocase
	init_case(case_x, case_num + 3, gps + 1);
	
	if(parser_config_file(conf_file, case_x))
	{
		printf("config file open error, use default\n");
	}
	
	parse_global_config(case_x);

	printf("camera_frame = %d\n", camera_frame);
	printf("font_size = %d\n", font_size);
	printf("camera pixel [%d*%d]\n", camera_pixel_width, camera_pixel_height);

#ifndef __GS900A__
	ion_open_alc();
#endif
	//define window size
	int screen_width, screen_height;
	int mic_width, camera_window_width, camera_window_height;
	int case_width, case_name_align, case_result_align;
	int font_height;
	
	//change env
	char event_path[100];
	char env_gsensor[256];
	
	//enable gsensor
	i = get_input_event_name(case_x[gsensor].dev_name, event_path);
	if(i != -1)
	{
		sprintf(env_gsensor, "echo 1 > /sys/class/input/input%d/enable", i);
		system(env_gsensor);
	}
	else
	{
		printf("----error! gsensor not found\n");
	}
	
	//vibrate test for 3 second
	test_vibrate(3);
	
	//dfb init
	DFBCHECK(DirectFBInit(&argc, &argv));
	DFBCHECK(DirectFBCreate(&dfb));
	
	font_desc.flags = DFDESC_HEIGHT;
	font_desc.height = font_size;
	DFBCHECK(dfb->CreateFont( dfb, font_file,  &font_desc, &font));
	DFBCHECK(font->GetHeight(font, &font_height));
	DFBCHECK(dfb->GetDisplayLayer(dfb, DLID_PRIMARY, &layer));
	DFBCHECK(layer->GetConfiguration( layer, &config ));
	// DFBCHECK(layer->SetRotation( layer, 180 ));
	//set window size
	screen_width = config.width;
	screen_height = config.height;
	mic_width = screen_width / 20;
	camera_window_width = (screen_width - mic_width) / 2;
	camera_window_height = screen_height / 2;
	case_width = screen_width - mic_width - camera_window_width;
	case_name_align = font_size;
	case_result_align = 7 * font_size;
	
	//create tp window
	dwsc.flags = DWDESC_POSX | DWDESC_POSY | DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_CAPS;
	dwsc.posx = 0;
	dwsc.posy = 0;
	dwsc.width = screen_width;
	dwsc.height = screen_height;
	dwsc.caps = DWCAPS_ALPHACHANNEL;
	
	DFBCHECK(layer->CreateWindow(layer, &dwsc, &window_tp));
	DFBCHECK(window_tp->GetSurface(window_tp, &surface_tp));
	DFBCHECK(window_tp->SetOptions(window_tp, DWOP_ALPHACHANNEL));
	DFBCHECK(window_tp->SetStackingClass(window_tp, DWSC_UPPER));
	DFBCHECK(window_tp->RaiseToTop(window_tp));
	DFBCHECK(surface_tp->Clear(surface_tp, 0, 0, 0, 0));
	DFBCHECK(surface_tp->SetColor(surface_tp, 0, 0xff, 0, 0xff));
	DFBCHECK(window_tp->SetOpacity(window_tp, 0xff));
	
	//config camera window
	dwsc.flags = DWDESC_POSX | DWDESC_POSY | DWDESC_WIDTH | DWDESC_HEIGHT;
	dwsc.posx = case_width + mic_width;
	dwsc.posy = 0;
	dwsc.width = camera_window_width;
	dwsc.height = screen_height;
	
	DFBCHECK(layer->CreateWindow( layer, &dwsc, &window_camera ));
	DFBCHECK(window_camera->GetSurface(window_camera, &windowsurface));
	DFBCHECK(windowsurface->SetColor(windowsurface, 0, 0, 0, 0xff));
	DFBCHECK(windowsurface->FillRectangle(windowsurface, 0, 0, camera_window_width , screen_height));
	DFBCHECK(windowsurface->Flip(windowsurface, NULL, 0));
	DFBCHECK(window_camera->SetOpacity( window_camera, 0xff ));
	
	drawRGB(windowsurface, 0, screen_height / 2, camera_window_width, screen_height /2);
	
	rect.x = 0;
	rect.y = 0;
	rect.w = camera_window_width;
	rect.h = camera_window_height;
	DFBCHECK(windowsurface->GetSubSurface(windowsurface, &rect, &surface_camera));
	
	rect.x = 0;
	rect.y = screen_height / 4 * 3;
	rect.w = camera_window_width;
	rect.h = screen_height - rect.y;
	DFBCHECK(windowsurface->GetSubSurface(windowsurface, &rect, &surface_button));
	
	//create camera surface
	dsc.flags       = DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT;
    dsc.pixelformat = DSPF_NV12;
	dsc.width = camera_pixel_width;
	dsc.height = camera_pixel_height;
	DFBCHECK(dfb->CreateSurface(dfb, &dsc, &camera_source));
	
	//config mic window
	dwsc.flags = DWDESC_POSX | DWDESC_POSY | DWDESC_WIDTH | DWDESC_HEIGHT;
	dwsc.posx = case_width;
	dwsc.posy = 0;
	dwsc.width = mic_width;
	dwsc.height = screen_height;
	
	DFBCHECK(layer->CreateWindow(layer, &dwsc, &window_mic));
	DFBCHECK(window_mic->GetSurface(window_mic, &surface_mic));
	DFBCHECK(surface_mic->SetColor(surface_mic, 0, 0, 0, 0xff));
	DFBCHECK(surface_mic->FillRectangle(surface_mic, 0, 0, mic_width , screen_height));
	DFBCHECK(surface_mic->Flip(surface_mic, NULL, 0));
	DFBCHECK(window_mic->SetOpacity( window_mic, 0xff));
	
	//config case window
	dwsc.posx = 0;
	dwsc.posy = 0;
	dwsc.width = case_width;
	dwsc.height = screen_height;
	
	DFBCHECK(layer->CreateWindow(layer, &dwsc, &window_case));
	DFBCHECK(window_case->GetSurface(window_case, &surface_case));
	DFBCHECK(surface_case->SetColor(surface_case, 0xff, 0xff, 0xff, 0xff));
	DFBCHECK(surface_case->SetFont(surface_case, font));
	DFBCHECK(surface_case->FillRectangle(surface_case, 0, 0, case_width, screen_height));
	
	//draw headline
	DFBCHECK(surface_case->SetColor(surface_case, 0xff, 0xff, 0, 0xff));
	DFBCHECK(surface_case->FillRectangle(surface_case, 0, 0, case_width, font_size + 2));
	DFBCHECK(surface_case->FillRectangle(surface_case, 0, screen_height / 2, case_width, font_size + 2));
	DFBCHECK(surface_case->SetColor(surface_case, 0, 0, 0, 0xff));
	DFBCHECK(surface_case->DrawString(surface_case, "自动测试选项", -1, case_width / 2, 0, DSTF_TOPCENTER));
	DFBCHECK(surface_case->DrawString(surface_case, "手动测试选项", -1, case_width / 2, screen_height / 2, DSTF_TOPCENTER));
	
	int auto_skip = 0;
	int manu_skip = 0;
	int skip_height = 0;
	bool double_line = false;
	//draw string
	for(i = 0; i < case_num; i++)
	{
		double_line = false;
		if(overflow)
		{
			case_x[i].enable = 0;
			continue;
		}
		if(!case_x[i].enable)
		{
			if(case_x[i].type)
				manu_skip++;
			else
				auto_skip++;
				
			//case_x[i].position = -1;
			continue;
		}
		if(case_x[i].doubleline == 1)
		{
			double_line = true;
		}
		if(case_x[i].type)
			skip_height = manu_skip * (font_height);
		else
			skip_height = auto_skip * (font_height);
		
		case_x[i].position = case_x[i].type * screen_height / 2 + (case_x[i].index + 1) * (font_height);
		case_x[i].position -= skip_height;
		
		// printf("name_h = %d\n", case_x[i].position);
		DFBCHECK(surface_case->SetColor(surface_case, 0, 0, 0, 0xff));
		DFBCHECK(surface_case->DrawString(surface_case, case_x[i].name, -1, case_name_align, case_x[i].position, DSTF_TOPLEFT));
		DFBCHECK(surface_case->SetColor(surface_case, 0xc0, 0xc0, 0xc0, 0xff));
		DFBCHECK(surface_case->DrawString(surface_case, case_x[i].init_string, -1, case_result_align, case_x[i].position, DSTF_TOPLEFT));
		
		rect.x = case_result_align;
		rect.y = case_x[i].position;
		rect.w = case_width - case_result_align;
		rect.h = font_height;
		if((rect.y + rect.h) > screen_height)
		{
			overflow = true;
			case_x[i].enable = 0;
			printf("case %d overflow, disable all case after it\n", i);
			continue;
		}
		if(double_line)
		{
			// case_x[i].position = -2;
			rect.h *= 2;
			if(case_x[i].type)
				manu_skip--;
			else
				auto_skip--;
		}
		DFBCHECK(surface_case->GetSubSurface(surface_case, &rect, &case_x[i].surface));
		DFBCHECK(case_x[i].surface->SetFont(case_x[i].surface, font));
	}
	
	DFBCHECK(window_case->SetOpacity(window_case, 0xff ));

#ifdef __GS900A__
	system("echo 1 > /sys/devices/e0250000.hdmi/enable");
#endif
	//start case thread
	for(i = 0; i < case_num; i++)
	{
		char thread_name[10];
		sprintf(thread_name,"thread_%d", i);
		if(case_x[i].enable)
		{
			thread_case[i] = direct_thread_create(DTT_DEFAULT, case_thread, &case_x[i], thread_name);
		}
	}
	
	case_x[tp].surface = surface_tp;
	
	//start thread
#ifdef __GS702C__
	thread_music = direct_thread_create(DTT_DEFAULT, music_thread, NULL, "music");
	thread_mic = direct_thread_create(DTT_DEFAULT, mic_thread, surface_mic, "mic");
#else
	thread_music  = direct_thread_create(DTT_DEFAULT, tinyalsa_music_thread, NULL, "tinyalsa_music");
	thread_mic = direct_thread_create(DTT_DEFAULT, tinyalsa_mic_thread, surface_mic, "tinyalsa_mic");
#endif

	thread_tp = direct_thread_create(DTT_DEFAULT, tp_thread, &case_x[tp], "tp");
	thread_flashlight = direct_thread_create(DTT_DEFAULT, flashlight_thread, &case_x[flashlight], "flashlight");
	thread_camera = direct_thread_create(DTT_DEFAULT, camera_thread, &camera_frame, "camera" );
	//thread_mic = direct_thread_create(DTT_DEFAULT, mic_thread, surface_mic, "mic");
	thread_button = direct_thread_create(DTT_DEFAULT, handle_record_button, surface_button, "button");
	sleep(1);
	
	DFBCHECK(surface_case->Flip(surface_case, NULL, 0));
	
	if(iio_read(info, case_x[gsensor].enable, case_x[gyro].enable, case_x[comp].enable) == -1)
		printf("get iio device error\n");
		
	//block in iio_read
	//useless statement
	for(i = 0; i < case_num; i++)
	{
		if(case_x[i].enable)
		{
			direct_thread_join(thread_case[i]);
			case_x[i].surface->Release(case_x[i].surface);
			direct_thread_destroy(thread_case[i]);
			printf("thread %d destroyed\n", i);
		}
	}

	direct_thread_join(thread_camera);
	direct_thread_destroy(thread_camera);
	direct_thread_join(thread_music);
	direct_thread_destroy(thread_music);
	direct_thread_join(thread_mic);
	direct_thread_destroy(thread_mic);

	surface_button->Release(surface_button);
	surface_camera->Release(surface_camera);
	camera_source->Release(camera_source);
	windowsurface->Release(windowsurface);
	window_camera->Release(window_camera);
	
	surface_case->Release(surface_case);
	window_case->Release(window_case);
	layer->Release(layer);
	font->Release(font);
	dfb->Release(dfb);
	
#ifndef __GS900A__
	ion_close_alc();
#endif
}