Forum Topic - PDF reader for Photon GUI: Page 2 of 2 (33 Items)
   
Re: PDF reader for Photon GUI  
Hi Mike,

After debugging phmupdf on our QNX system , we found that the call PhCreateImage() in phpdf_load_page() was failing and 
returning NULL.due to which phmupdf crashed.
This was happening during continous zoom operations.

As a solution to this , can I put a check in phpdf_load_page() to check for PhCreateImage() to return NULL and in this 
case I may revert back to the previous zoom level.What all structures I may have to clear and handle.Attaching the 
conditional statement : 

if(NULL != app->page_image[slotno].page_image_phi)
            {
            	printf("pointer not null\n");
            
        	temp_ptr=app->page_image[slotno].page_image_phi->image;
                 w=app->page_image[slotno].page_image_phi->size.w;
                 h=app->page_image[slotno].page_image_phi->size.h;
                 pitch=app->page_image[slotno].page_image_phi->bpl;
            }
            else
            {
            	printf("NULL Image!!!!! Cannot allocate memory\n");
                  //Return to previous zoom level
            }

Also in some cases of scrolling and zoom I observed the fitz library function fz_malloc_array() throwing an exception 
for not enough memory(). Can you pinpoint me the exact scenario when the memory is allocated using this function.
Re: PDF reader for Photon GUI  
> As a solution to this , can I put a check in phpdf_load_page() to check for 
> PhCreateImage() to return NULL and in this case I may revert back to the 
> previous zoom level.What all structures I may have to clear and handle.
> Attaching the conditional statement : 

What video card and what graphics driver you using? Maybe it would be a good solution to use offscreen video memory 
instead of system shared memory? It will be much faster and will leave system memory almost untouched.

> Also in some cases of scrolling and zoom I observed the fitz library function 
> fz_malloc_array() throwing an exception for not enough memory(). Can you 
> pinpoint me the exact scenario when the memory is allocated using this 
> function.

fz_malloc_*() is used everywhere in the fitz library. Each page rendering operation calls numerous fz_malloc_*() 
functions.
Re: PDF reader for Photon GUI  
Hi Mike,

I tried enabling offscreen memory context and I do see an improvement in memory usage.
However the horizontal scroll functionality which I implemented using PtScrollContainer stopped working.

Only the PtPane gets scrolled instead of the whole drawing area.Following is the code I used to create scroll container.


app->phwindow=PtCreateWidget(PtWindow, Pt_NO_PARENT, winargc, winargs);
 /* Create PtOSContainer widget for flicker-free updating */
   PtSetArg(&winargs[winargc++], Pt_ARG_DIM, &app->window.dimension, 0);

    app->phoscontainer=PtCreateWidget(PtOSContainer, app->phwindow, winargc, winargs);
   
  /*Create ScrollContainer for Horizontal Scroll in This Application*/
    winargc=0;
    PtSetArg(&winargs[winargc++], Pt_ARG_DIM, &app->window.dimension, 0);
    PtSetArg(&winargs[winargc++], Pt_ARG_SCROLLBAR_Y_DISPLAY, Pt_NEVER, 0);//Vertical Scroll bar is not displayed as it 
is already implemented.
  
app->scrollarea=PtCreateWidget(PtScrollContainer,  app->phoscontainer, winargc, winargs);   
   
   
    /* Create PtRaw widget for drawings */
      winargc=0;   
	PtSetArg(&winargs[winargc++], Pt_ARG_DIM, &app->window.dimension, 0);
    PtSetArg(&winargs[winargc++], Pt_ARG_FILL_COLOR, PgRGB(0x70, 0x70, 0x70), 0);
    PtSetArg(&winargs[winargc++], Pt_ARG_RAW_DRAW_F, phmupdf_draw_content, 0);
    PtSetArg(&winargs[winargc++], Pt_ARG_POINTER, (void*)app, 0);
    raw_cb.event_mask=Ph_EV_BUT_PRESS | Ph_EV_PTR_MOTION_BUTTON |
        Ph_EV_PTR_MOTION_NOBUTTON | Ph_EV_BOUNDARY;
    raw_cb.event_f=phmupdf_content_callback_raw;
    raw_cb.data=(void*)app;
    PtSetArg(&winargs[winargc++], Pt_CB_RAW, &raw_cb, 0);

    /* Create the PtRaw widget */
    app->phcontent=PtCreateWidget(PtRaw, app->scrollarea, winargc, winargs);

Does it have any relation of scroll container created on PtOSContainer and offscreen-memory context enabled at the same 
time? 
Re: PDF reader for Photon GUI  
> Does it have any relation of scroll container created on PtOSContainer and 
> offscreen-memory context enabled at the same time? 

No, PtOSContainer is used just for non-flickering graphics update. I think problem could be in blitting from offscreen 
memory to PtOSContainer, since I have not implemented horizontal scrolling, it can be an issue.
Re: PDF reader for Photon GUI  
Hi Mike,

Thanks for the comments.However to avoid PtScrollContainer I was trying to implement the horizontal scroll bar itself. 
Can you give me the pointers as to how I can target it.

Thanks
Re: PDF reader for Photon GUI  
> Thanks for the comments.However to avoid PtScrollContainer I was trying to 
> implement the horizontal scroll bar itself. Can you give me the pointers as to
>  how I can target it.

I planned to add text selection/copying and horizontal scrolling using mupdf 1.2 engine, which must come out soon. It is
 a matter of one/two weekends to do this :)

If you like to do this yourself, take a look into the phmupdf_draw_content() function, there one variable called offset,
 it is y-offset of the page, you have to implement x-offset using the same algorithms. And also you have to unlock zoom 
levels, currently maximum zoom level is calculated using fitting page to the window dimensions.
Re: PDF reader for Photon GUI  
Hi Mike,

Thanks for the inputs.I'll try implementing it.Also it would be great if you could upload the code soon.

Thanks..
Re: PDF reader for Photon GUI  
Hi Mike,

Did you get a chance to work on horizontal scrolling.
It would be great if you could upload the code soon.

Thanks