| | 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 | } |
| | 190 | void |
| | 191 | PrintPter::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 | |