Example #1
0
File: clip.c Project: kai4785/LM
int main(int argc, char** argv)
{
    SYSLOG(LOG_INFO, "***** plugin started");
    PDL_Init(0);
    SYSLOG(LOG_INFO, "***** plugin initialized PDL");
    atexit(PDL_Quit);

    SDL_Init(SDL_INIT_VIDEO);
    SYSLOG(LOG_INFO, "***** plugin initialized SDL");
    atexit(SDL_Quit);
    SYSLOG(LOG_INFO, "***** plugin initialized");
    
    // register the js callback
    PDL_RegisterJSHandler("hello_world", hello_world);
    PDL_RegisterJSHandler("acl_license", PDL_acl_license);
    PDL_JSRegistrationComplete();
    PDL_CallJS("ready", NULL, 0);

    while(1)
        loop();

    // Cleanup
    PDL_Quit();
    SYSLOG(LOG_INFO, "***** plugin exiting");
}
Example #2
0
void FinishIndex()
{
#if USE_PDL

	const char *params[1];
	params[0] = 0;

	PDL_Err mjErr = PDL_CallJS("FinishIndex", params, 0);
	if ( mjErr != PDL_NOERROR )
	{
		ReportError1("error: %s\n", PDL_GetError());
	}
#endif
	ReportError("Finish Index");

}
Example #3
0
void AddToIndex(const char *path, int32_t iLastMod)
{
	const char *params[2];
	params[0] = path;

	char cstrIndex[15];
	sprintf(cstrIndex,"%i",iLastMod);
	params[1] = cstrIndex;
#if USE_PDL
	PDL_Err mjErr = PDL_CallJS("AddToIndex", params, 2);
	if ( mjErr != PDL_NOERROR )
	{
		ReportError1("error: %s\n", PDL_GetError());
	}
#endif
	ReportError2("Callback Val: %s : %s", params[0], params[1]);

}
Example #4
0
    PDL_bool service::do_render(PDL_JSParameters* params)
    {
        boost::format my_formatter(filename_format);

        int from = PDL_GetJSParamInt(params, 1);
        int count = PDL_GetJSParamInt(params, 2);
        int zoom = PDL_GetJSParamInt(params, 3);
        std::string directory = PDL_GetJSParamString(params, 4);
        std::string prefix = PDL_GetJSParamString(params, 5);
        std::string suffix = PDL_GetJSParamString(params, 6);

        my_formatter % directory % prefix % zoom % suffix;

//        if (!ctx_.is_open())
//            throw std::runtime_error("Document has not been opened yet");

        int err = ::mkdir(directory.c_str(), 0755);
        if (err != 0 && errno != EEXIST)
            throw std::runtime_error("could not create directory");

        LECTOR_LOG("Rendering call: from %d, count %d", from, count);
        for (int i = from; i < from + count; ++i)
        {
            std::string filename = (boost::format(my_formatter) % i).str();

            if (::access(filename.c_str(), R_OK) == -1 && errno == ENOENT)
            {
                LECTOR_LOG("Starting rendering of page %d", i);
                queue_.push(std::make_tuple(zoom / 100.f, i, filename));
            }
            else
            {
                LECTOR_LOG("Reusing cached image of page %d", i);
                std::string response_json =
                    (boost::format(render_response) % i % filename).str();

                const char* response = response_json.c_str();
                PDL_CallJS("RenderCallback", &response, 1);
            }
        }

        return PDL_TRUE;
    }
Example #5
0
File: clip.c Project: kai4785/LM
static void loop()
{
    SDL_Event event;
    {
        // fire off the js
        const char *params[2];
        params[0] = "foo";
        params[1] = "bar";
        PDL_Err mjErr = PDL_CallJS("testFunc", params, 2);
        if ( mjErr != PDL_NOERROR )
        {
            printf("PDL_CallJS failed. %s\n", PDL_GetError());
        }
    }
    if (SDL_WaitEvent(&event)) {
        SYSLOG(LOG_INFO, "***** plugin event");
        if (event.type == SDL_QUIT) {
            exit(0);
        }
    }
}
Example #6
0
void StartSong(const char *cstrPath,
				const char *cstrArtist,
				const char *cstrTitle,
				int32_t iTrack)
{
	if (!cstrPath)
		cstrPath = "0";
	if (!cstrArtist)
		cstrArtist = "0";
	if (!cstrTitle)
		cstrTitle = "0";
		

	const char *params[4];
	params[0] = cstrPath;
	params[1] = cstrArtist;
	params[2] = cstrTitle;
	
	char cstrIndex[15];
	sprintf(cstrIndex,"%i",iTrack);
	
	params[3] = cstrIndex;

#if USE_PDL
	PDL_Err mjErr = PDL_CallJS("StartSong", params, 4);

	if ( mjErr != PDL_NOERROR )
	{
	  printf("error: %s\n", PDL_GetError());
	}

#endif
	ReportError4("*****Callback Val: %s, %s, %s, %s", params[0], 
													  params[1],
													  params[2],
													  params[3]);


}
Example #7
0
std::vector<Funambol::WString>& BlockingServiceCall(const char* method, const Funambol::WString& parameters,const Funambol::WString& param2)
{
	pthread_mutex_lock(&callbackMutex);
	globalResults.clear();
	partlyResult = "";
	const char* params[2];
	params[0] = fromWString(parameters);
	params[1] = fromWString(param2);
	PDL_Err error = PDL_CallJS(method,params,2);
	if(error == PDL_NOERROR)
	{
		Funambol::LOG.debug("Set of callback, now blocking till result received.");
		pthread_cond_wait(&callbackReady,&callbackMutex);
		Funambol::LOG.debug("Callback succeeded.");
	}
	else
	{
		Funambol::LOG.error("Could not start callback. Error: %s (%d).",PDL_GetError(),error);
	}
	pthread_mutex_unlock(&callbackMutex);
	return globalResults;
}
Example #8
0
void FinishSeek(const char *cstrVal, int32_t iTrack)
{
#if USE_PDL

	ReportError("Entering FinishSeek");

	const char *params[2];
	params[0] = cstrVal;

	char cstrIndex[15];
	sprintf(cstrIndex,"%i",iTrack);

	params[1] = cstrIndex;

	PDL_Err mjErr = PDL_CallJS("FinishSeek", params, 2);
	if ( mjErr != PDL_NOERROR )
	{
		ReportError1("error: %s\n", PDL_GetError());
	}
#endif
	ReportError1("Callback Val From FinishSeek: %s", cstrVal);

}
Example #9
0
    void service::render_thread()
    {
        LECTOR_LOG("Started thread");
        context ctx(ctx_);
        LECTOR_LOG("Copied");

        std::tuple<float, int, std::string> elem;

        while(running_)
        {
            LECTOR_LOG("Rendering task");
            queue_.pop(elem);

            float const& zoom = std::get<0>(elem);
            int const& page = std::get<1>(elem);
            std::string const& filename = std::get<2>(elem);
            LECTOR_LOG("Got item");
            try
            {
                pixmap pix = ctx.render_full(zoom, page);
                pix.write_png(filename);
            }
            catch (std::runtime_error const& exc)
            {
                LECTOR_LOG_ERROR("Exception: %s", exc.what());
            }
            LECTOR_LOG("Rendered successfully");

            std::string response_json =
                (boost::format(render_response) % page
                                                % filename).str();

            const char* response = response_json.c_str();
            PDL_CallJS("RenderCallback", &response, 1);
            LECTOR_LOG("Done rendering page %d", page);
        }
    }
Example #10
0
int main(int argc, char** argv)
{
	int result;
	int fd;
	fz_context *ctx;
	char buf[10];
	int c; 
	int pagewidth, pageheight;
	
	result = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);

	if(result !=  0) {
		printf("Could not init SDL: %s\n", SDL_GetError());
		exit(1);
	}

	PDL_Init(0);
	PDL_SetOrientation(PDL_ORIENTATION_0);
    
    PDL_RegisterJSHandler("flipPage",flip_page);
    PDL_RegisterJSHandler("panPage",pan_page);	
 //   PDL_RegisterJSHandler("pause", pause);																																																									
 //	PDL_RegisterJSHandler("resume", resume);
	
    PDL_JSRegistrationComplete();
    PDL_CallJS("ready", NULL, 0);

	memset(&pitch_action, 0, sizeof(PDF_Pitch_t));

	//gesture_data = (Gesture_Event *)malloc(sizeof(Gesture_Event));
	memset(&gesture_data, 0, sizeof(Gesture_Event));
	pitch_action.scale = 1.0;
	
	Surface = SDL_SetVideoMode(0, 0, 0, SDL_SWSURFACE);

	SDL_FillRect(Surface, NULL, 0xF0F0F);
	SDL_Flip(Surface);

	ctx = fz_new_context(NULL, FZ_STORE_DEFAULT);

	pdfapp_init(ctx, &app);

	app.scrw = 1024;
	app.scrh = 768;
	app.pageno = 10;
	
	src.x = 20;
	src.y = 20;
	src.w = 1024;
	src.h = 768;

	dest.x = 0;
	dest.y = 0;
	
	fd = open(argv[1], O_RDONLY, 0666);
	if (fd < 0)	{
		printf("cannot open file\n");
		fz_throw(app.ctx, "cannot open file '%s'", argv[1]);
	}
	pdfapp_open(&app,argv[1],fd,0);
	
	//app.rotate = 90 * 3;
	pdfapp_showpage(&app,1,1,1);
	draw_pdf();
	
#if 0
	content = SDL_CreateRGBSurfaceFrom(app.image->samples, app.image->w, app.image->h,
		32, app.image->w * 4, 0x00, 0x00, 0x00, 0x00);
	

	SDL_BlitSurface(content,NULL, Surface, NULL);
	SDL_Flip(Surface);
#endif

	SDL_Event Event;
	Event.type = SDL_NOEVENT;
	int temp1, temp2;
	
	do {
		if (Paused)	{
			SDL_WaitEvent(&Event);
			if (Event.type == SDL_ACTIVEEVENT)
			{
				if ((Event.active.state & SDL_APPACTIVE) && (Event.active.gain == 1))
				{
					Paused = SDL_FALSE;
				}
			}
		}			
	else {
		while(SDL_PollEvent(&Event)) {
			handle_events(Event);
//			switch (Event.type) {
#if 0
				case SDL_MOUSEBUTTONDOWN:
						fingerNum = Event.button.which + 1;
                        mouse_state = SDL_MOUSEBUTTONDOWN;
						printf("%2d fingers touch down\n",Event.button.which);
					break;
					
				case SDL_MOUSEBUTTONUP:
						if(fingerNum == 2) { 
							memset(&pitch_action, 0, sizeof(PDF_Pitch_t)-sizeof(float32));
							pinch = SDL_FALSE;
							//pitch_action.scale = 1.0;
						}
						if(fingerNum == 1 && mouse_state == SDL_MOUSEBUTTONDOWN) {
                            if(Event.button.x > (app.image->h / 2)) {
								buf[0] = '.';
                            }
							else {
								buf[0] = ',';
							}
							pdfapp_onkey(&app,buf[0]);
							printf("Flip page\n");
					    	draw_pdf();
						}
					//	printf("%2d fingers touching\n",fingerNum);
                        mouse_state = NULL;	
						printf("%2d fingers touch up\n",Event.button.which);

						if(fingerNum > 0)
							fingerNum -= 1; 
					break;

				case SDL_MOUSEMOTION:
					if(fingerNum == 2) {
							if(Event.motion.which == 0) {
								pitch_action.x0 = Event.motion.x;
								pitch_action.y0 = Event.motion.y;
								}
							if(Event.motion.which == 1) {
								pitch_action.x1 = Event.motion.x;
								pitch_action.y1 = Event.motion.y;
								}
							pitch_action.cx = (pitch_action.x0 + pitch_action.x1)/2;
							pitch_action.cy = (pitch_action.y0 + pitch_action.y1)/2;
							temp1  = pow((pitch_action.x0 - pitch_action.x1),2);
							temp2  = pow((pitch_action.y0 - pitch_action.y1),2);
							pitch_action.distance1 = sqrt(temp1 + temp2);
							
							pitch_action.offset = pitch_action.distance1 - pitch_action.distance0;
							pitch_action.distance0 = pitch_action.distance1;

							pitch_action.offset = (int)pitch_action.offset;
						//	printf("cx:%4d, cy:%4d, offset:%4f \n",pitch_action.cx,
						//		pitch_action.cy, pitch_action.offset);

							#if 1
							if(pitch_action.offset > 0 && pitch_action.offset < 5) {
								#if 0
									app.resolution *= (Uint16)pitch_action.offset;
									if (app.resolution > MAXRES)
										app.resolution = MAXRES;
									pdfapp_showpage(&app, 0, 1, 0);									
									draw_pdf();
								#endif
								pinch = SDL_TRUE;
								pitch_action.scale += 0.008;
								if(pitch_action.scale > 2)
									pitch_action.scale = 2;
								printf("-------------------------------------pinch out\n");
									
							}
							else if(pitch_action.offset < 0) {
								#if 0
									app.resolution /=(Uint16)( abs(pitch_action.offset));
									if (app.resolution < MINRES)
										app.resolution = MINRES;
									pdfapp_showpage(&app, 0, 1, 0);
									draw_pdf();
								#endif
									pinch = SDL_TRUE;
									pitch_action.scale -= 0.008;
									if(pitch_action.scale < 0.9)
										pitch_action.scale = 0.9;

									printf("----------------------------------pinch in\n");
								}
							else {
								pinch = SDL_FALSE;
							}
							#endif
						}
					//printf("which: %d, x = %4d, y = %4d \n",Event.motion.which,
					//	Event.motion.x, Event.motion.y);
                    mouse_state =  SDL_MOUSEMOTION;
					printf("Finger move \n");
                    break;
#endif
/*
				// handle deactivation by pausing our animation
				case SDL_ACTIVEEVENT:
					if ((Event.active.state & SDL_APPACTIVE) &&	(Event.active.gain == 0))
					{
						Paused = SDL_TRUE;
					}
					break;
					
				default:
					break;
//				}
*/
		}

#if 1
		if(pinch) {
			#if 1			
			if(pitch_action.scale == 1.4) {
				app.resolution = 72 * 1.4;
				pdfapp_showpage(&app,0,1,1);
				draw_pdf();
				printf("----increase pdf resolution \n");
			}
			if(pitch_action.scale == 1) {
				app.resolution = 72;
				pdfapp_showpage(&app,0,1,1);
				draw_pdf();
			}
			content = zoomSurface(page_copy,pitch_action.scale,pitch_action.scale,SMOOTHING_OFF);

			SDL_FillRect(Surface, NULL, SDL_MapRGBA(Surface->format, 45, 45, 45, 0));

			SDL_BlitSurface(content,NULL, Surface, NULL);
			SDL_Flip(Surface);
			SDL_FreeSurface(content);
			#else 
			app.resolution *= pitch_action.scale;
			if(app.resolution > MAXRES)
				app.resolution = MAXRES;
			if (app.resolution < MINRES)
				app.resolution = MINRES;
			pdfapp_showpage(&app, 0, 1, 1);
			draw_pdf();
			#endif
		}
#endif
			SDL_Delay(0);
		}
	}while(Event.type != SDL_QUIT);
	//cleanup
	SDL_FreeSurface(content);
	SDL_FreeSurface(Surface);
	
	pdfapp_close(&app);

	PDL_Quit();
	SDL_Quit();
	
	return 0;
}