Changeset 150
- Timestamp:
- 05/07/06 06:45:49 (2 years ago)
- Files:
-
- trunk/src/DocumentPage.cxx (modified) (1 diff)
- trunk/src/IDocument.cxx (modified) (1 diff)
- trunk/src/IDocument.h (modified) (1 diff)
- trunk/src/IPageView.h (modified) (1 diff)
- trunk/src/PagePter.cxx (modified) (7 diffs)
- trunk/src/gtk/PageView.cxx (modified) (1 diff)
- trunk/src/gtk/PageView.h (modified) (1 diff)
- trunk/tests/DumbPageView.cxx (modified) (1 diff)
- trunk/tests/DumbPageView.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/DocumentPage.cxx
r148 r150 176 176 if ( NULL != m_Data ) 177 177 { 178 memset (m_Data, 0 , dataSize);178 memset (m_Data, 0xff, dataSize); 179 179 } 180 180 trunk/src/IDocument.cxx
r148 r150 870 870 871 871 /// 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 /// 882 DocumentPage * 883 IDocument::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 /// 872 897 /// @brief Get the document's current page number. 873 898 /// trunk/src/IDocument.h
r148 r150 233 233 void setNumPages (gint numPages); 234 234 DocumentPage *getCurrentPage (void); 235 DocumentPage *getEmptyPage (void); 235 236 gint getCurrentPageNum (void); 236 237 DocumentOutline *getOutline (void); trunk/src/IPageView.h
r148 r150 150 150 /// 151 151 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 152 166 153 167 protected: trunk/src/PagePter.cxx
r148 r150 192 192 PagePter::notifyLoad () 193 193 { 194 g_WaitingForPage = FALSE; 194 195 refreshPage (PAGE_SCROLL_START); 195 196 } … … 198 199 PagePter::notifyPageChanged (gint pageNum) 199 200 { 201 g_WaitingForPage = FALSE; 200 202 refreshPage (m_NextPageScroll); 201 203 } … … 204 206 PagePter::notifyPageRotated (gint rotation) 205 207 { 208 g_WaitingForPage = FALSE; 206 209 refreshPage (PAGE_SCROLL_START); 207 210 } … … 210 213 PagePter::notifyPageZoomed (gdouble zoom) 211 214 { 215 g_WaitingForPage = FALSE; 212 216 refreshPage (PAGE_SCROLL_NONE); 213 217 } … … 216 220 PagePter::notifyReload () 217 221 { 222 g_WaitingForPage = FALSE; 218 223 refreshPage (PAGE_SCROLL_NONE); 219 224 } … … 252 257 if ( m_Document->isLoaded () ) 253 258 { 259 IPageView &view = getView (); 254 260 DocumentPage *documentPage = m_Document->getCurrentPage (); 255 261 if ( NULL != documentPage ) 256 262 { 257 263 g_WaitingForPage = FALSE; 258 getView ().showPage (documentPage, pageScroll);264 view.showPage (documentPage, pageScroll); 259 265 } 260 266 else 261 267 { 262 #if defined DEBUG263 // I just emulate as if the document has already the page,264 // because during debug (i.e., test) we don't actually care265 // about the page's content.266 getView ().showPage ((DocumentPage *)0xdeadbeef, pageScroll);267 #else // !DEBUG268 268 if ( !g_WaitingForPage ) 269 269 { 270 documentPage = m_Document->getEmptyPage (); 271 view.showPage (documentPage, pageScroll); 272 delete documentPage; 273 view.showText (_("Loading...")); 274 270 275 g_WaitingForPage = TRUE; 271 276 PageNotAvailableData *data = new PageNotAvailableData; … … 274 279 g_idle_add (PagePter::pageNotAvailable, data); 275 280 } 276 #endif // !DEBUG277 281 } 278 282 } trunk/src/gtk/PageView.cxx
r147 r150 205 205 } 206 206 207 void 208 PageView::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 207 280 //////////////////////////////////////////////////////////////// 208 281 // GTK+ Functions. trunk/src/gtk/PageView.h
r147 r150 38 38 void setPresenter (PagePter *pter); 39 39 void showPage (DocumentPage *page, PageScroll scroll); 40 void showText (const gchar *text); 40 41 41 42 protected: trunk/tests/DumbPageView.cxx
r147 r150 67 67 { 68 68 } 69 70 void 71 DumbPageView::showText (const gchar *text) 72 { 73 } trunk/tests/DumbPageView.h
r147 r150 34 34 void setCursor (PageCursor cursorType); 35 35 void showPage (DocumentPage *page, PageScroll scroll); 36 void showText (const gchar *text); 36 37 37 38
