Changeset 150

Show
Ignore:
Timestamp:
05/07/06 06:45:49 (2 years ago)
Author:
jordi
Message:

When IDocument has not image of the page requested by PagePter?, PagePter? asks for an empty page and gives it to the IPageView. Then it requests to the IPageView to show the "Loading..." text to let know the user that the page is loading, instead of just showing nothing or the previously shown page. For now this empty page with the loading notice is also shown when the page is resized.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/DocumentPage.cxx

    r148 r150  
    176176    if ( NULL != m_Data ) 
    177177    { 
    178         memset (m_Data, 0, dataSize); 
     178        memset (m_Data, 0xff, dataSize); 
    179179    } 
    180180     
  • trunk/src/IDocument.cxx

    r148 r150  
    870870 
    871871/// 
     872/// @brief Gets an empty page of the same size than the current page. 
     873/// 
     874/// This is used when the page is now ready on the cache and the presenter 
     875/// wants to show something to the user. This function just will create  
     876/// an empty document (i.e., no text or image) using the size that the 
     877/// page would have it it was rendered. 
     878/// 
     879/// @return An DocumentPage whose image is just a blank page. The caller 
     880///         must delete this DocumentPage object. 
     881/// 
     882DocumentPage * 
     883IDocument::getEmptyPage () 
     884{ 
     885    gdouble pageWidth; 
     886    gdouble pageHeight; 
     887    getPageSizeForPage (getCurrentPageNum (), &pageWidth, &pageHeight); 
     888    gint width = MAX((gint) ((pageWidth * getZoom ()) + 0.5), 1); 
     889    gint height = MAX((gint) ((pageHeight * getZoom ()) + 0.5) , 1); 
     890    DocumentPage *emptyPage = new DocumentPage (); 
     891    emptyPage->newPage (width, height); 
     892 
     893    return emptyPage; 
     894} 
     895 
     896/// 
    872897/// @brief Get the document's current page number. 
    873898/// 
  • trunk/src/IDocument.h

    r148 r150  
    233233            void setNumPages (gint numPages); 
    234234            DocumentPage *getCurrentPage (void); 
     235            DocumentPage *getEmptyPage (void); 
    235236            gint getCurrentPageNum (void); 
    236237            DocumentOutline *getOutline (void); 
  • trunk/src/IPageView.h

    r148 r150  
    150150            /// 
    151151            virtual void showPage (DocumentPage *page, PageScroll scroll) = 0; 
     152 
     153            /// 
     154            /// @brief Shows text on the page. 
     155            /// 
     156            /// This is only used when the page is still loading but the 
     157            /// presenter wants to show something on the user. The presenter 
     158            /// passes a text string to show during the rendering of the 
     159            /// current page. The view should put this string at the middle 
     160            /// of the currently shown page. 
     161            /// 
     162            /// @param text The text to show on the middle of the page. 
     163            /// 
     164            virtual void showText (const gchar *text) = 0; 
     165             
    152166             
    153167        protected: 
  • trunk/src/PagePter.cxx

    r148 r150  
    192192PagePter::notifyLoad () 
    193193{ 
     194    g_WaitingForPage = FALSE; 
    194195    refreshPage (PAGE_SCROLL_START); 
    195196} 
     
    198199PagePter::notifyPageChanged (gint pageNum) 
    199200{ 
     201    g_WaitingForPage = FALSE; 
    200202    refreshPage (m_NextPageScroll); 
    201203} 
     
    204206PagePter::notifyPageRotated (gint rotation) 
    205207{ 
     208    g_WaitingForPage = FALSE; 
    206209    refreshPage (PAGE_SCROLL_START); 
    207210} 
     
    210213PagePter::notifyPageZoomed (gdouble zoom) 
    211214{ 
     215    g_WaitingForPage = FALSE; 
    212216    refreshPage (PAGE_SCROLL_NONE); 
    213217} 
     
    216220PagePter::notifyReload () 
    217221{ 
     222    g_WaitingForPage = FALSE; 
    218223    refreshPage (PAGE_SCROLL_NONE); 
    219224} 
     
    252257    if ( m_Document->isLoaded () ) 
    253258    { 
     259        IPageView &view = getView (); 
    254260        DocumentPage *documentPage = m_Document->getCurrentPage (); 
    255261        if ( NULL != documentPage ) 
    256262        { 
    257263            g_WaitingForPage = FALSE; 
    258             getView ().showPage (documentPage, pageScroll); 
     264            view.showPage (documentPage, pageScroll); 
    259265        } 
    260266        else 
    261267        { 
    262 #if defined DEBUG 
    263             // I just emulate as if the document has already the page, 
    264             // because during debug (i.e., test) we don't actually care 
    265             // about the page's content. 
    266             getView ().showPage ((DocumentPage *)0xdeadbeef, pageScroll); 
    267 #else // !DEBUG 
    268268            if ( !g_WaitingForPage ) 
    269269            { 
     270                documentPage = m_Document->getEmptyPage (); 
     271                view.showPage (documentPage, pageScroll); 
     272                delete documentPage; 
     273                view.showText (_("Loading...")); 
     274 
    270275                g_WaitingForPage = TRUE; 
    271276                PageNotAvailableData *data = new PageNotAvailableData; 
     
    274279                g_idle_add (PagePter::pageNotAvailable, data); 
    275280            } 
    276 #endif // !DEBUG 
    277281        } 
    278282    } 
  • trunk/src/gtk/PageView.cxx

    r147 r150  
    205205} 
    206206 
     207void 
     208PageView::showText (const gchar *text) 
     209{ 
     210    // I need to make the changes to the original Pixbuf that the GtkImage 
     211    // controls shows. 
     212    // Since a Pixbuf is a client-side buffer, it's not drawable and the 
     213    // gdk functions to draw using pango won't accept it. 
     214    // The solution I found is to render the pixbuf to a pixmap, which is 
     215    // server-side and therefore drawable, make the modifications 
     216    // and set the modified pixbuf again to the GtkImage control. 
     217    //  
     218    GdkPixbuf *originalPage = gtk_image_get_pixbuf (GTK_IMAGE (m_PageImage)); 
     219    if ( NULL != originalPage ) 
     220    { 
     221        gint width = gdk_pixbuf_get_width (originalPage); 
     222        gint height = gdk_pixbuf_get_height (originalPage); 
     223        
     224        PangoLayout *layout =  
     225            gtk_widget_create_pango_layout (m_PageImage, text); 
     226 
     227        // I want the text to be half the page's width. 
     228        // Since I don't know the font's size I just set the font 
     229        // size to 1pt. 
     230        PangoFontDescription *fontDescription = pango_font_description_new (); 
     231        pango_font_description_set_size (fontDescription, PANGO_SCALE); 
     232        pango_layout_set_font_description (layout, fontDescription); 
     233        // The I get the logical rectangle that this text would 
     234        // extent to if it was rendered using 1pt and calculate the 
     235        // size in points it would take to make the width fill the 
     236        // page's half width. 
     237        PangoRectangle logicalRectangle; 
     238        pango_layout_get_pixel_extents (layout, NULL, &logicalRectangle); 
     239        gint targetWidth = MAX (width / 2, 1); 
     240        gdouble realSize =  
     241            (gdouble)targetWidth / (gdouble)logicalRectangle.width; 
     242        pango_font_description_set_size (fontDescription, 
     243                                         (gint)realSize * PANGO_SCALE);         
     244        pango_layout_set_font_description (layout, fontDescription); 
     245        pango_layout_get_pixel_extents (layout, NULL, &logicalRectangle); 
     246         
     247        // Once the font are set up, I just need to render  
     248        // the pixbuf to the pixmap (copying from client-side to  
     249        // server size) and draw the layout. 
     250        GdkPixmap *pixmap; 
     251        GdkBitmap *mask; 
     252        gdk_pixbuf_render_pixmap_and_mask (originalPage, 
     253                                           &pixmap, &mask, 0); 
     254        gdk_draw_layout (pixmap,  
     255                         m_PageImage->style->black_gc,  
     256                         (width - logicalRectangle.width) / 2,  
     257                         height / 4 - logicalRectangle.height / 2, 
     258                         layout); 
     259        pango_font_description_free (fontDescription); 
     260        g_object_unref (layout); 
     261        // Then I just copy back the image to a client-size pixbuf. 
     262        GdkPixbuf *modifiedPage =  
     263            gdk_pixbuf_get_from_drawable (NULL, 
     264                                          pixmap, 
     265                                          NULL, 
     266                                          0, 0, 
     267                                          0, 0, 
     268                                          width, height); 
     269        g_object_unref (pixmap); 
     270        if ( NULL != mask ) 
     271        { 
     272            g_object_unref (mask); 
     273        } 
     274         
     275        gtk_image_set_from_pixbuf (GTK_IMAGE (m_PageImage), modifiedPage); 
     276        gdk_pixbuf_unref (modifiedPage); 
     277    }  
     278} 
     279 
    207280//////////////////////////////////////////////////////////////// 
    208281// GTK+ Functions. 
  • trunk/src/gtk/PageView.h

    r147 r150  
    3838            void setPresenter (PagePter *pter); 
    3939            void showPage (DocumentPage *page, PageScroll scroll); 
     40            void showText (const gchar *text); 
    4041 
    4142        protected: 
  • trunk/tests/DumbPageView.cxx

    r147 r150  
    6767{ 
    6868} 
     69 
     70void 
     71DumbPageView::showText (const gchar *text) 
     72{ 
     73} 
  • trunk/tests/DumbPageView.h

    r147 r150  
    3434            void setCursor (PageCursor cursorType); 
    3535            void showPage (DocumentPage *page, PageScroll scroll); 
     36            void showText (const gchar *text); 
    3637 
    3738