Changeset 222

Show
Ignore:
Timestamp:
06/11/06 14:46:38 (2 years ago)
Author:
jordi
Message:

Added a new class named JobPrint? whose duty is to render the current document to PostScript? and print the resultant file. It already renders the requested pages (Note: the setUpPageRange is horrible) to PostScript?.

Location:
trunk/src
Files:
2 added
15 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/IDocument.cxx

    r206 r222  
    231231        IDocumentObserver *observer = (IDocumentObserver *)item->data; 
    232232        observer->notifyFindChanged (matchRect); 
    233     }  
     233    } 
    234234} 
    235235 
     
    903903/// 
    904904const gchar * 
    905 IDocument::getPassword () 
     905IDocument::getPassword () const 
    906906{ 
    907907    return m_Password; 
     
    939939/// 
    940940const gchar * 
    941 IDocument::getFileName () 
     941IDocument::getFileName () const 
    942942{ 
    943943    if ( NULL == m_FileName ) 
  • trunk/src/IDocument.h

    r200 r222  
    134134 
    135135            /// 
     136            /// @brief Makes a copy of the document. 
     137            /// 
     138            /// This function must make a deep copy of the current document 
     139            /// and return the result. 
     140            /// 
     141            /// @return A new document class with the same content than the 
     142            ///         caller document. 
     143            /// 
     144            virtual IDocument *copy (void) const = 0; 
     145 
     146            /// 
    136147            /// @brief Finds text on a single page. 
    137148            /// 
     
    190201            virtual void getPageSizeForPage (gint pageNum, gdouble *width, 
    191202                                             gdouble *height) = 0; 
     203 
     204            /// 
     205            /// @brief Starts the output to PostScript. 
     206            /// 
     207            /// This starts a new PostScript file with name @a fileName and 
     208            /// with @a numPages pages of @a width x @a height. 
     209            /// 
     210            /// @param fileName The file name to output the postscript code. 
     211            /// @param numOfPages The number of pages to output. 
     212            /// @param pageWidth The width of each page. 
     213            /// @param pageHeight The height of each page. 
     214            /// 
     215            virtual void outputPostscriptBegin (const gchar *fileName, 
     216                                                guint numOfPages, 
     217                                                gfloat pageWidth, 
     218                                                gfloat pageHeight) = 0; 
     219 
     220            /// 
     221            /// @brief Ends the output to PostScript. 
     222            /// 
     223            /// Ends any started output to PostScript by calling 
     224            /// outputPostscriptBegin (). 
     225            /// 
     226            virtual void outputPostscriptEnd (void) = 0; 
     227 
     228            /// 
     229            /// @brief Renders a single page to PostScript. 
     230            /// 
     231            /// Renders the page @a pageNum To the PostScript started 
     232            /// at outputPostscriptBegin (). 
     233            /// 
     234            /// @param pageNum The number of the page to render. 
     235            /// 
     236            virtual void outputPostscriptPage (guint pageNum) = 0; 
    192237 
    193238            /// 
     
    248293            const gchar *getCreator (void); 
    249294            void setCreator (gchar *creator); 
    250             const gchar *getPassword (void); 
     295            const gchar *getPassword (void) const; 
    251296            void setPassword (const gchar *password); 
    252297            const gchar *getProducer (void); 
    253298            void setProducer (gchar *producer); 
    254             const gchar *getFileName (void); 
     299            const gchar *getFileName (void) const; 
    255300            void setFileName (const gchar *fileName); 
    256301            const gchar *getFormat (void); 
  • trunk/src/IPrintView.h

    r221 r222  
    6868            ///              which page size is. 
    6969            /// 
    70             virtual void addPageSize (const gchar *name,  
     70            virtual void addPageSize (const gchar *name, 
    7171                                      const gchar *value) = 0; 
    7272 
     
    100100 
    101101            /// 
     102            /// @brief Gets the page layout. 
     103            /// 
     104            /// @return The selected page layout's value. 
     105            /// 
     106            virtual PrintPageLayout getPageLayout (void) = 0; 
     107 
     108            /// 
     109            /// @brief Gets the page orientation. 
     110            /// 
     111            /// @return The selected page orientation's value. 
     112            /// 
     113            virtual PrintPageOrientation getPageOrientation (void) = 0; 
     114 
     115            /// 
     116            /// @brief Gets the entred page range. 
     117            /// 
     118            /// @return The entered text in the page range entry. 
     119            /// 
     120            virtual const gchar *getPageRange (void) = 0; 
     121 
     122            /// 
     123            /// @brief Gets the currently selected page size. 
     124            /// 
     125            /// @return The name of the page size that is selected. This name 
     126            ///         is the @a value parameter of the addPageSize() 
     127            ///         function. 
     128            /// 
     129            virtual gchar *getPageSize (void) = 0; 
     130 
     131            /// 
    102132            /// @brief Gets the name of the currently selected printer. 
    103133            /// 
     
    109139 
    110140            /// 
    111             /// @brief Check is the "All Pages" range option is selected. 
     141            /// @brief Checks if the "Collate" option is checked. 
     142            /// 
     143            /// @return TRUE if the "Collate" option is checked. 
     144            ///         FALSE otherwise. 
     145            /// 
     146            virtual gboolean isCheckedCollate (void) = 0; 
     147 
     148            /// 
     149            /// @brief Checks if the "All Pages" range option is selected. 
    112150            /// 
    113151            /// @return TRUE if the range's "All Pages" option is selected. 
     
    115153            /// 
    116154            virtual gboolean isSelectedAllPagesRangeOption (void) = 0; 
     155 
     156            /// 
     157            /// @brief Checks if the "Even Page" set option is selected. 
     158            /// 
     159            /// @return TRUE if the set's "Even Page" option is selected. 
     160            ///         FALSE otherwise. 
     161            /// 
     162            virtual gboolean isSelectedEvenPageSet (void) = 0; 
     163 
     164            /// 
     165            /// @brief Checks if the "Odd Page" set option is selected. 
     166            /// 
     167            /// @return TRUE if the set's "Odd Page" option is selected. 
     168            ///         FALSE otherwise. 
     169            /// 
     170            virtual gboolean isSelectedOddPageSet (void) = 0; 
    117171 
    118172            /// 
  • trunk/src/JobFind.cxx

    r172 r222  
    227227        GList *result = getDocument ()->findTextInPage (currentPage, 
    228228                                                        getTextToFind ()); 
    229          
     229 
    230230        if ( FIND_DIRECTION_FORWARDS == getDirection () ) 
    231231        { 
     
    236236            setCurrentPage (currentPage - 1); 
    237237        } 
    238          
     238 
    239239        if ( NULL != result ) 
    240240        { 
    241241            setResults (currentPage, result); 
    242242            JOB_NOTIFIER (job_find_results, this); 
    243         }         
    244         else  
     243        } 
     244        else 
    245245        { 
    246246            JOB_NOTIFIER (job_find_end, this); 
  • trunk/src/JobLoad.cxx

    r200 r222  
    286286    job->getDocument ().notifyReload (); 
    287287    JOB_NOTIFIER_END(); 
    288      
    289     return FALSE; 
    290 } 
     288 
     289    return FALSE; 
     290} 
  • trunk/src/JobSave.h

    r200 r222  
    2323    // Forward declarations. 
    2424    class IDocument; 
    25     
     25 
    2626    /// 
    2727    /// @class JobSave 
  • trunk/src/MainPter.cxx

    r213 r222  
    453453MainPter::printActivated () 
    454454{ 
    455     PrintPter *print = new PrintPter (); 
     455    PrintPter *print = new PrintPter (m_Document); 
    456456    IPrintView *view = getView ().getPrintView (); 
    457457    if ( NULL != view ) 
  • trunk/src/Makefile.am

    r213 r222  
    7676libepdfview_a_SOURCES +=    \ 
    7777    IPrintView.h    \ 
     78    JobPrint.cxx    \ 
     79    JobPrint.h  \ 
    7880    PrintPter.cxx   \ 
    7981    PrintPter.h 
  • trunk/src/PDFDocument.cxx

    r209 r222  
    3939{ 
    4040    m_Document = NULL; 
     41    m_PostScript = NULL; 
    4142} 
    4243 
     
    4748{ 
    4849    clearCache (); 
     50    outputPostscriptEnd (); 
    4951    if ( NULL != m_Document ) 
    5052    { 
     
    5254        m_Document = NULL; 
    5355    } 
     56} 
     57 
     58IDocument * 
     59PDFDocument::copy () const 
     60{ 
     61    // Making a deep copy is just making a new document and loading the same 
     62    // file. 
     63    PDFDocument *newDocument = new PDFDocument (); 
     64    newDocument->loadFile (getFileName (), getPassword (), NULL); 
     65 
     66    return newDocument; 
    5467} 
    5568 
     
    474487} 
    475488 
     489void 
     490PDFDocument::outputPostscriptBegin (const gchar *fileName, guint numOfPages, 
     491                                    gfloat pageWidth, gfloat pageHeight) 
     492{ 
     493    if ( NULL != m_Document ) 
     494    { 
     495        if ( NULL != m_PostScript ) 
     496        { 
     497            outputPostscriptEnd (); 
     498        } 
     499        m_PostScript = 
     500            poppler_ps_file_new (m_Document, fileName, 0, numOfPages); 
     501        if ( NULL != m_PostScript ) 
     502        { 
     503            poppler_ps_file_set_paper_size (m_PostScript, 
     504                                            pageWidth, pageHeight); 
     505        } 
     506    } 
     507} 
     508 
     509void 
     510PDFDocument::outputPostscriptEnd () 
     511{ 
     512    if ( NULL != m_PostScript ) 
     513    { 
     514        poppler_ps_file_free (m_PostScript); 
     515        m_PostScript = NULL; 
     516    } 
     517} 
     518 
     519void 
     520PDFDocument::outputPostscriptPage (guint pageNum) 
     521{ 
     522    if ( NULL != m_Document && NULL != m_PostScript ) 
     523    { 
     524        PopplerPage *page = poppler_document_get_page (m_Document, pageNum - 1); 
     525        if ( NULL != page ) 
     526        { 
     527            poppler_page_render_to_ps (page, m_PostScript); 
     528        } 
     529    } 
     530} 
     531 
     532 
    476533/// 
    477534/// @brief Renders a document's page. 
  • trunk/src/PDFDocument.h

    r200 r222  
    2525typedef struct _PopplerLinkMapping PopplerLinkMapping; 
    2626typedef struct _PopplerPage PopplerPage; 
     27typedef struct _PopplerPSFile PopplerPSFile; 
    2728 
    2829namespace ePDFView  
     
    4041            ~PDFDocument (void); 
    4142 
     43            IDocument *copy (void) const; 
    4244            GList *findTextInPage (gint pageNum, const gchar *textToFind); 
    4345            gboolean isLoaded (void); 
    4446            gboolean loadFile (const gchar *filename, const gchar *password,  
    4547                           GError **error); 
    46             void getPageSizeForPage (gint pageNum, gdouble *width,  
     48            void getPageSizeForPage (gint pageNum, gdouble *width, 
    4749                                     gdouble *height); 
     50            void outputPostscriptBegin (const gchar *fileName, guint numOfPages, 
     51                                        gfloat pageWidth, gfloat pageHeight); 
     52            void outputPostscriptEnd (void); 
     53            void outputPostscriptPage (guint pageNum); 
     54 
    4855            DocumentPage *renderPage (gint pageNum); 
    4956            gboolean saveFile (const gchar *fileName, GError **error); 
     
    5259            /// The PDF document. 
    5360            PopplerDocument *m_Document; 
     61            /// The output to PostScript. 
     62            PopplerPSFile *m_PostScript; 
    5463 
    5564            IDocumentLink *createDocumentLink (const PopplerLinkMapping *link, 
  • trunk/src/PrintPter.cxx

    r221 r222  
    3232}; 
    3333 
    34 PrintPter::PrintPter () 
     34PrintPter::PrintPter (IDocument *document) 
    3535{ 
    3636    m_View = NULL; 
     37    m_Document = document; 
    3738} 
    3839 
     
    102103PrintPter::printActivated () 
    103104{ 
     105    IPrintView &view = getView (); 
     106    // Get the printer's name. 
     107    char *printerName = view.getSelectedPrinterName (); 
     108    if ( NULL != printerName ) 
     109    { 
     110        float pageWidth; 
     111        float pageHeight; 
     112        char *pageSizeName = view.getPageSize (); 
     113        getPageSizeForPrinter (printerName, pageSizeName, 
     114                               &pageWidth, &pageHeight); 
     115        g_free (pageSizeName); 
     116        // Create the new print job. 
     117        JobPrint *job = new JobPrint (); 
     118        job->setDocument (m_Document); 
     119        job->setPrinterName (printerName); 
     120 
     121        if ( view.isSelectedAllPagesRangeOption () ) 
     122        { 
     123            char *pageRange = g_strdup_printf ("1-%d", 
     124                                               m_Document->getNumPages ()); 
     125            job->setPageRange (pageRange); 
     126            g_free (pageRange); 
     127        } 
     128        else 
     129        { 
     130            job->setPageRange (view.getPageRange()); 
     131        } 
     132 
     133        if ( view.isSelectedOddPageSet () ) 
     134        { 
     135            job->setPageSet (PRINT_ODD_PAGE_SET); 
     136        } 
     137        else if ( view.isSelectedEvenPageSet () ) 
     138        { 
     139            job->setPageSet (PRINT_EVEN_PAGE_SET); 
     140        } 
     141        else 
     142        { 
     143            job->setPageSet (PRINT_ALL_PAGE_SET); 
     144        } 
     145        job->setNumberOfCopies (view.getNumberOfCopies ()); 
     146        job->setCollate (view.isCheckedCollate ()); 
     147        job->setPageSize (pageWidth, pageHeight); 
     148        job->setPageOrientation (view.getPageOrientation ()); 
     149        job->setPageLayout (view.getPageLayout ()); 
     150 
     151        IJob::enqueue (job); 
     152 
     153        g_free (printerName); 
     154    } 
    104155    // Once done, it's the same as canceled :-) 
    105156    cancelActivated (); 
     
    137188} 
    138189 
     190void 
     191PrintPter::getPageSizeForPrinter (const gchar *printerName, 
     192                                  const gchar *pageSizeName, 
     193                                  float *pageWidth, float *pageHeight) 
     194{ 
     195    g_assert (NULL != pageWidth && "Tried to save the page width to NULL."); 
     196    g_assert (NULL != pageHeight && "Tried to save the page height to NULL."); 
     197 
     198    // Set the initial value to an A4 page size (size is in 1/72 inches). 
     199    *pageWidth = 0.1147f; 
     200    *pageHeight = 0.1624f; 
     201 
     202    if ( NULL != printerName ) 
     203    { 
     204        const gchar *printerPPDName = cupsGetPPD (printerName); 
     205        if ( NULL != printerPPDName ) 
     206        { 
     207            ppd_file_t *printerPPD = ppdOpenFile (printerPPDName); 
     208            if ( NULL != printerPPD ) 
     209            { 
     210                for ( int currentSize = 0 ; 
     211                      currentSize < printerPPD->num_sizes ; 
     212                      ++currentSize ) 
     213                { 
     214                    ppd_size_t *size = &printerPPD->sizes[currentSize]; 
     215                    if ( 0 == g_ascii_strcasecmp (pageSizeName, size->name) ) 
     216                    { 
     217                        *pageWidth = size->width; 
     218                        *pageHeight = size->length; 
     219                        break; 
     220                    } 
     221                } 
     222                ppdClose (printerPPD); 
     223            } 
     224        } 
     225    } 
     226} 
     227 
    139228printerAttributes * 
    140229PrintPter::getPrinterAttributes (const gchar *printerName) 
  • trunk/src/PrintPter.h

    r221 r222  
    2525{ 
    2626    /// 
    27     /// @enum PrintPageOrientation. 
    28     /// 
    29     enum PrintPageOrientation 
    30     { 
    31         PRINT_PAGE_ORIENTATION_PORTRAIT, 
    32         PRINT_PAGE_ORIENTATION_LANDSCAPE 
    33     }; 
    34  
    35     /// 
    36     /// @enum PrintPageLayout 
    37     /// 
    38     enum PrintPageLayout 
    39     { 
    40         PRINT_PAGE_LAYOUT_PLAIN, 
    41         PRINT_PAGE_LAYOUT_2IN1, 
    42         PRINT_PAGE_LAYOUT_4IN1 
    43     }; 
    44  
    45     /// 
    4627    /// @class PrintPter 
    4728    /// @brief Print Presenter. 
     
    5031    { 
    5132        public: 
    52             PrintPter (void); 
     33            PrintPter (IDocument *document); 
    5334            ~PrintPter (void); 
    5435 
     
    6344 
    6445        protected: 
     46            IDocument *m_Document; 
    6547            IPrintView *m_View; 
    6648 
     49            void getPageSizeForPrinter (const gchar *printerName, 
     50                                        const gchar *sizeName, 
     51                                        float *pageWidth, float *pageHeight); 
    6752            printerAttributes *getPrinterAttributes (const gchar *printerName); 
    6853            void listPrinters (void); 
  • trunk/src/epdfview.h

    r213 r222  
    3838#include <JobFind.h> 
    3939#include <JobLoad.h> 
     40#include <JobPrint.h> 
    4041#include <JobRender.h> 
    4142#include <JobSave.h> 
  • trunk/src/gtk/PrintView.cxx

    r221 r222  
    172172} 
    173173 
     174PrintPageLayout 
     175PrintView::getPageLayout () 
     176{ 
     177    PrintPageLayout layout = PRINT_PAGE_LAYOUT_PLAIN; 
     178    GtkTreeIter layoutIter; 
     179    if ( gtk_combo_box_get_active_iter (GTK_COMBO_BOX (m_LayoutView), 
     180                                        &layoutIter) ) 
     181    { 
     182        gtk_tree_model_get (GTK_TREE_MODEL (m_Layout), &layoutIter, 
     183                            printLayoutValueColumn, &layout, 
     184                            -1); 
     185    } 
     186 
     187    return layout; 
     188} 
     189 
     190PrintPageOrientation 
     191PrintView::getPageOrientation () 
     192{ 
     193    PrintPageOrientation orientation = PRINT_PAGE_ORIENTATION_PORTRAIT; 
     194    GtkTreeIter orientationIter; 
     195    if ( gtk_combo_box_get_active_iter (GTK_COMBO_BOX (m_OrientationView), 
     196                                        &orientationIter) ) 
     197    { 
     198        gtk_tree_model_get (GTK_TREE_MODEL (m_Orientation), &orientationIter, 
     199                            printOrientationValueColumn, &orientation, 
     200                            -1); 
     201    } 
     202    return orientation; 
     203} 
     204 
     205const gchar * 
     206PrintView::getPageRange () 
     207{ 
     208    return gtk_entry_get_text (GTK_ENTRY (m_PageRange)); 
     209} 
     210 
     211gchar * 
     212PrintView::getPageSize () 
     213{ 
     214    gchar *pageSize = NULL; 
     215    GtkTreeIter pageSizeIter; 
     216    if ( gtk_combo_box_get_active_iter (GTK_COMBO_BOX (m_PageSizeView), 
     217                                        &pageSizeIter) ) 
     218    { 
     219        gtk_tree_model_get (GTK_TREE_MODEL (m_PageSize), &pageSizeIter, 
     220                            pageSizeValueColumn, &pageSize, 
     221                            -1); 
     222    } 
     223    return pageSize; 
     224} 
     225 
    174226gchar * 
    175227PrintView::getSelectedPrinterName () 
     
    192244 
    193245gboolean 
     246PrintView::isCheckedCollate () 
     247{ 
     248    return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (m_Collate)); 
     249} 
     250 
     251gboolean 
    194252PrintView::isSelectedAllPagesRangeOption () 
    195253{ 
    196254    return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (m_AllPagesRangeOption)); 
     255} 
     256 
     257gboolean 
     258PrintView::isSelectedEvenPageSet () 
     259{ 
     260    return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (m_EvenPageSet)); 
     261} 
     262 
     263gboolean 
     264PrintView::isSelectedOddPageSet () 
     265{ 
     266    return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (m_OddPageSet)); 
    197267} 
    198268 
     
    299369        gtk_radio_button_new_with_mnemonic (NULL, _("A_ll pages")); 
    300370    gtk_box_pack_start_defaults (GTK_BOX (pageSetBox), allPageSetRadio); 
    301     GtkWidget *oddPageSetRadio = 
     371    m_OddPageSet = 
    302372        gtk_radio_button_new_with_mnemonic_from_widget ( 
    303373                GTK_RADIO_BUTTON (allPageSetRadio), _("O_dd pages")); 
    304     gtk_box_pack_start_defaults (GTK_BOX (pageSetBox), oddPageSetRadio); 
    305     GtkWidget *evenPageSetRadio = 
     374    gtk_box_pack_start_defaults (GTK_BOX (pageSetBox), m_OddPageSet); 
     375    m_EvenPageSet = 
    306376        gtk_radio_button_new_with_mnemonic_from_widget ( 
    307377                GTK_RADIO_BUTTON (allPageSetRadio), _("_Even pages")); 
    308     gtk_box_pack_start_defaults (GTK_BOX (pageSetBox), evenPageSetRadio); 
     378    gtk_box_pack_start_defaults (GTK_BOX (pageSetBox), m_EvenPageSet); 
    309379 
    310380    // Copies frame