| 1 | ///////////////////////////////////////////////////////////////////////////// |
| 2 | // Name: src/gtk/gnome/gprint.cpp |
| 3 | // Author: Robert Roebling |
| 4 | // Purpose: Implement GNOME printing support |
| 5 | // Created: 09/20/04 |
| 6 | // Copyright: Robert Roebling |
| 7 | // Licence: wxWindows Licence |
| 8 | ///////////////////////////////////////////////////////////////////////////// |
| 9 | |
| 10 | // For compilers that support precompilation, includes "wx/wx.h". |
| 11 | #include "wx/wxprec.h" |
| 12 | |
| 13 | #ifdef __BORLANDC__ |
| 14 | #pragma hdrstop |
| 15 | #endif |
| 16 | |
| 17 | #if wxUSE_LIBGNOMEPRINT |
| 18 | |
| 19 | #include "wx/gtk/gnome/gprint.h" |
| 20 | |
| 21 | #ifndef WX_PRECOMP |
| 22 | #include "wx/log.h" |
| 23 | #include "wx/dcmemory.h" |
| 24 | #include "wx/icon.h" |
| 25 | #include "wx/math.h" |
| 26 | #include "wx/image.h" |
| 27 | #include "wx/module.h" |
| 28 | #include "wx/crt.h" |
| 29 | #endif |
| 30 | |
| 31 | #include "wx/fontutil.h" |
| 32 | #include "wx/gtk/private.h" |
| 33 | #include "wx/dynlib.h" |
| 34 | #include "wx/paper.h" |
| 35 | #include "wx/dcprint.h" |
| 36 | #include "wx/modalhook.h" |
| 37 | |
| 38 | #include <libgnomeprint/gnome-print.h> |
| 39 | #include <libgnomeprint/gnome-print-pango.h> |
| 40 | #include <libgnomeprint/gnome-print-config.h> |
| 41 | #include <libgnomeprintui/gnome-print-dialog.h> |
| 42 | #include <libgnomeprintui/gnome-print-job-preview.h> |
| 43 | #include <libgnomeprintui/gnome-print-paper-selector.h> |
| 44 | |
| 45 | #include "wx/link.h" |
| 46 | wxFORCE_LINK_THIS_MODULE(gnome_print) |
| 47 | |
| 48 | //---------------------------------------------------------------------------- |
| 49 | // wxGnomePrintLibrary |
| 50 | //---------------------------------------------------------------------------- |
| 51 | |
| 52 | class wxGnomePrintLibrary |
| 53 | { |
| 54 | public: |
| 55 | wxGnomePrintLibrary(); |
| 56 | ~wxGnomePrintLibrary(); |
| 57 | |
| 58 | bool IsOk(); |
| 59 | private: |
| 60 | bool InitializeMethods(); |
| 61 | |
| 62 | wxDynamicLibrary m_libGnomePrint; |
| 63 | wxDynamicLibrary m_libGnomePrintUI; |
| 64 | |
| 65 | // only true if we successfully loaded both libraries |
| 66 | // |
| 67 | // don't rename this field, it's used by wxDL_XXX macros internally |
| 68 | bool m_ok; |
| 69 | |
| 70 | public: |
| 71 | wxDL_METHOD_DEFINE( gint, gnome_print_newpath, |
| 72 | (GnomePrintContext *pc), (pc), 0 ) |
| 73 | wxDL_METHOD_DEFINE( gint, gnome_print_moveto, |
| 74 | (GnomePrintContext *pc, gdouble x, gdouble y), (pc, x, y), 0 ) |
| 75 | wxDL_METHOD_DEFINE( gint, gnome_print_lineto, |
| 76 | (GnomePrintContext *pc, gdouble x, gdouble y), (pc, x, y), 0 ) |
| 77 | wxDL_METHOD_DEFINE( gint, gnome_print_arcto, |
| 78 | (GnomePrintContext *pc, gdouble x, gdouble y, gdouble radius, gdouble angle1, gdouble angle2, gint direction ), (pc, x, y, radius, angle1, angle2, direction), 0 ) |
| 79 | wxDL_METHOD_DEFINE( gint, gnome_print_curveto, |
| 80 | (GnomePrintContext *pc, gdouble x1, gdouble y1, gdouble x2, gdouble y2, gdouble x3, gdouble y3), (pc, x1, y1, x2, y2, x3, y3), 0 ) |
| 81 | wxDL_METHOD_DEFINE( gint, gnome_print_closepath, |
| 82 | (GnomePrintContext *pc), (pc), 0 ) |
| 83 | wxDL_METHOD_DEFINE( gint, gnome_print_stroke, |
| 84 | (GnomePrintContext *pc), (pc), 0 ) |
| 85 | wxDL_METHOD_DEFINE( gint, gnome_print_fill, |
| 86 | (GnomePrintContext *pc), (pc), 0 ) |
| 87 | wxDL_METHOD_DEFINE( gint, gnome_print_setrgbcolor, |
| 88 | (GnomePrintContext *pc, gdouble r, gdouble g, gdouble b), (pc, r, g, b), 0 ) |
| 89 | wxDL_METHOD_DEFINE( gint, gnome_print_setlinewidth, |
| 90 | (GnomePrintContext *pc, gdouble width), (pc, width), 0 ) |
| 91 | wxDL_METHOD_DEFINE( gint, gnome_print_setdash, |
| 92 | (GnomePrintContext *pc, gint n_values, const gdouble *values, gdouble offset), (pc, n_values, values, offset), 0 ) |
| 93 | |
| 94 | wxDL_METHOD_DEFINE( gint, gnome_print_rgbimage, |
| 95 | (GnomePrintContext *pc, const guchar *data, gint width, gint height, gint rowstride), (pc, data, width, height, rowstride ), 0 ) |
| 96 | wxDL_METHOD_DEFINE( gint, gnome_print_rgbaimage, |
| 97 | (GnomePrintContext *pc, const guchar *data, gint width, gint height, gint rowstride), (pc, data, width, height, rowstride ), 0 ) |
| 98 | |
| 99 | wxDL_METHOD_DEFINE( gint, gnome_print_concat, |
| 100 | (GnomePrintContext *pc, const gdouble *matrix), (pc, matrix), 0 ) |
| 101 | wxDL_METHOD_DEFINE( gint, gnome_print_scale, |
| 102 | (GnomePrintContext *pc, gdouble sx, gdouble sy), (pc, sx, sy), 0 ) |
| 103 | wxDL_METHOD_DEFINE( gint, gnome_print_rotate, |
| 104 | (GnomePrintContext *pc, gdouble theta), (pc, theta), 0 ) |
| 105 | wxDL_METHOD_DEFINE( gint, gnome_print_translate, |
| 106 | (GnomePrintContext *pc, gdouble x, gdouble y), (pc, x, y), 0 ) |
| 107 | |
| 108 | wxDL_METHOD_DEFINE( gint, gnome_print_gsave, |
| 109 | (GnomePrintContext *pc), (pc), 0 ) |
| 110 | wxDL_METHOD_DEFINE( gint, gnome_print_grestore, |
| 111 | (GnomePrintContext *pc), (pc), 0 ) |
| 112 | |
| 113 | wxDL_METHOD_DEFINE( gint, gnome_print_clip, |
| 114 | (GnomePrintContext *pc), (pc), 0 ) |
| 115 | wxDL_METHOD_DEFINE( gint, gnome_print_eoclip, |
| 116 | (GnomePrintContext *pc), (pc), 0 ) |
| 117 | |
| 118 | wxDL_METHOD_DEFINE( gint, gnome_print_beginpage, |
| 119 | (GnomePrintContext *pc, const guchar* name), (pc, name), 0 ) |
| 120 | wxDL_METHOD_DEFINE( gint, gnome_print_showpage, |
| 121 | (GnomePrintContext *pc), (pc), 0 ) |
| 122 | wxDL_METHOD_DEFINE( gint, gnome_print_end_doc, |
| 123 | (GnomePrintContext *pc), (pc), 0 ) |
| 124 | |
| 125 | wxDL_METHOD_DEFINE( PangoLayout*, gnome_print_pango_create_layout, |
| 126 | (GnomePrintContext *gpc), (gpc), NULL ) |
| 127 | wxDL_VOIDMETHOD_DEFINE( gnome_print_pango_layout, |
| 128 | (GnomePrintContext *gpc, PangoLayout *layout), (gpc, layout) ) |
| 129 | |
| 130 | wxDL_METHOD_DEFINE( GnomePrintJob*, gnome_print_job_new, |
| 131 | (GnomePrintConfig *config), (config), NULL ) |
| 132 | wxDL_METHOD_DEFINE( GnomePrintContext*, gnome_print_job_get_context, |
| 133 | (GnomePrintJob *job), (job), NULL ) |
| 134 | wxDL_METHOD_DEFINE( gint, gnome_print_job_close, |
| 135 | (GnomePrintJob *job), (job), 0 ) |
| 136 | wxDL_METHOD_DEFINE( gint, gnome_print_job_print, |
| 137 | (GnomePrintJob *job), (job), 0 ) |
| 138 | wxDL_METHOD_DEFINE( gboolean, gnome_print_job_get_page_size, |
| 139 | (GnomePrintJob *job, gdouble *width, gdouble *height), (job, width, height), 0 ) |
| 140 | |
| 141 | wxDL_METHOD_DEFINE( GnomePrintUnit*, gnome_print_unit_get_by_abbreviation, |
| 142 | (const guchar *abbreviation), (abbreviation), NULL ) |
| 143 | wxDL_METHOD_DEFINE( gboolean, gnome_print_convert_distance, |
| 144 | (gdouble *distance, const GnomePrintUnit *from, const GnomePrintUnit *to), (distance, from, to), false ) |
| 145 | |
| 146 | wxDL_METHOD_DEFINE( GnomePrintConfig*, gnome_print_config_default, |
| 147 | (void), (), NULL ) |
| 148 | wxDL_METHOD_DEFINE( gboolean, gnome_print_config_set, |
| 149 | (GnomePrintConfig *config, const guchar *key, const guchar *value), (config, key, value), false ) |
| 150 | wxDL_METHOD_DEFINE( gboolean, gnome_print_config_set_double, |
| 151 | (GnomePrintConfig *config, const guchar *key, gdouble value), (config, key, value), false ) |
| 152 | wxDL_METHOD_DEFINE( gboolean, gnome_print_config_set_int, |
| 153 | (GnomePrintConfig *config, const guchar *key, gint value), (config, key, value), false ) |
| 154 | wxDL_METHOD_DEFINE( gboolean, gnome_print_config_set_boolean, |
| 155 | (GnomePrintConfig *config, const guchar *key, gboolean value), (config, key, value), false ) |
| 156 | wxDL_METHOD_DEFINE( gboolean, gnome_print_config_set_length, |
| 157 | (GnomePrintConfig *config, const guchar *key, gdouble value, const GnomePrintUnit *unit), (config, key, value, unit), false ) |
| 158 | |
| 159 | wxDL_METHOD_DEFINE( guchar*, gnome_print_config_get, |
| 160 | (GnomePrintConfig *config, const guchar *key), (config, key), NULL ) |
| 161 | wxDL_METHOD_DEFINE( gboolean, gnome_print_config_get_length, |
| 162 | (GnomePrintConfig *config, const guchar *key, gdouble *val, const GnomePrintUnit **unit), (config, key, val, unit), false ) |
| 163 | wxDL_METHOD_DEFINE( gboolean, gnome_print_config_get_boolean, |
| 164 | (GnomePrintConfig *config, const guchar *key, gboolean *val), (config, key, val), false ) |
| 165 | |
| 166 | wxDL_METHOD_DEFINE( GtkWidget*, gnome_print_dialog_new, |
| 167 | (GnomePrintJob *gpj, const guchar *title, gint flags), (gpj, title, flags), NULL ) |
| 168 | wxDL_VOIDMETHOD_DEFINE( gnome_print_dialog_construct_range_page, |
| 169 | (GnomePrintDialog *gpd, gint flags, gint start, gint end, |
| 170 | const guchar *currentlabel, const guchar *rangelabel), |
| 171 | (gpd, flags, start, end, currentlabel, rangelabel) ) |
| 172 | wxDL_VOIDMETHOD_DEFINE( gnome_print_dialog_get_copies, |
| 173 | (GnomePrintDialog *gpd, gint *copies, gboolean *collate), (gpd, copies, collate) ) |
| 174 | wxDL_VOIDMETHOD_DEFINE( gnome_print_dialog_set_copies, |
| 175 | (GnomePrintDialog *gpd, gint copies, gint collate), (gpd, copies, collate) ) |
| 176 | wxDL_METHOD_DEFINE( GnomePrintRangeType, gnome_print_dialog_get_range, |
| 177 | (GnomePrintDialog *gpd), (gpd), GNOME_PRINT_RANGETYPE_NONE ) |
| 178 | wxDL_METHOD_DEFINE( int, gnome_print_dialog_get_range_page, |
| 179 | (GnomePrintDialog *gpd, gint *start, gint *end), (gpd, start, end), 0 ) |
| 180 | |
| 181 | wxDL_METHOD_DEFINE( GtkWidget*, gnome_paper_selector_new_with_flags, |
| 182 | (GnomePrintConfig *config, gint flags), (config, flags), NULL ) |
| 183 | |
| 184 | wxDL_METHOD_DEFINE( GtkWidget*, gnome_print_job_preview_new, |
| 185 | (GnomePrintJob *gpm, const guchar *title), (gpm, title), NULL ) |
| 186 | |
| 187 | wxDECLARE_NO_COPY_CLASS(wxGnomePrintLibrary); |
| 188 | }; |
| 189 | |
| 190 | wxGnomePrintLibrary::wxGnomePrintLibrary() |
| 191 | { |
| 192 | wxLogNull log; |
| 193 | |
| 194 | m_libGnomePrint.Load("libgnomeprint-2-2.so.0"); |
| 195 | m_ok = m_libGnomePrint.IsLoaded(); |
| 196 | if ( !m_ok ) |
| 197 | return; |
| 198 | |
| 199 | m_libGnomePrintUI.Load("libgnomeprintui-2-2.so.0"); |
| 200 | m_ok = m_libGnomePrintUI.IsLoaded(); |
| 201 | if ( !m_ok ) |
| 202 | { |
| 203 | m_libGnomePrint.Unload(); |
| 204 | return; |
| 205 | } |
| 206 | |
| 207 | m_ok = InitializeMethods(); |
| 208 | } |
| 209 | |
| 210 | wxGnomePrintLibrary::~wxGnomePrintLibrary() |
| 211 | { |
| 212 | } |
| 213 | |
| 214 | bool wxGnomePrintLibrary::IsOk() |
| 215 | { |
| 216 | return m_ok; |
| 217 | } |
| 218 | |
| 219 | bool wxGnomePrintLibrary::InitializeMethods() |
| 220 | { |
| 221 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_newpath ); |
| 222 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_moveto ); |
| 223 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_lineto ); |
| 224 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_curveto ); |
| 225 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_arcto ); |
| 226 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_closepath ); |
| 227 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_stroke ); |
| 228 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_fill ); |
| 229 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_setrgbcolor ); |
| 230 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_setlinewidth ); |
| 231 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_setdash ); |
| 232 | |
| 233 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_rgbimage ); |
| 234 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_rgbaimage ); |
| 235 | |
| 236 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_concat ); |
| 237 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_scale ); |
| 238 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_rotate ); |
| 239 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_translate ); |
| 240 | |
| 241 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_gsave ); |
| 242 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_grestore ); |
| 243 | |
| 244 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_clip ); |
| 245 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_eoclip ); |
| 246 | |
| 247 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_beginpage ); |
| 248 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_showpage ); |
| 249 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_end_doc ); |
| 250 | |
| 251 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_pango_create_layout ); |
| 252 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_pango_layout ); |
| 253 | |
| 254 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_job_new ); |
| 255 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_job_get_context ); |
| 256 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_job_close ); |
| 257 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_job_print ); |
| 258 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_job_get_page_size ); |
| 259 | |
| 260 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_unit_get_by_abbreviation ); |
| 261 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_convert_distance ); |
| 262 | |
| 263 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_config_default ); |
| 264 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_config_set ); |
| 265 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_config_set_boolean ); |
| 266 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_config_set_double ); |
| 267 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_config_set_int ); |
| 268 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_config_set_length ); |
| 269 | |
| 270 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_config_get ); |
| 271 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_config_get_length ); |
| 272 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_config_get_boolean ); |
| 273 | |
| 274 | wxDL_METHOD_LOAD( m_libGnomePrintUI, gnome_print_dialog_new ); |
| 275 | wxDL_METHOD_LOAD( m_libGnomePrintUI, gnome_print_dialog_construct_range_page ); |
| 276 | wxDL_METHOD_LOAD( m_libGnomePrintUI, gnome_print_dialog_get_copies ); |
| 277 | wxDL_METHOD_LOAD( m_libGnomePrintUI, gnome_print_dialog_set_copies ); |
| 278 | wxDL_METHOD_LOAD( m_libGnomePrintUI, gnome_print_dialog_get_range ); |
| 279 | wxDL_METHOD_LOAD( m_libGnomePrintUI, gnome_print_dialog_get_range_page ); |
| 280 | |
| 281 | wxDL_METHOD_LOAD( m_libGnomePrintUI, gnome_paper_selector_new_with_flags ); |
| 282 | |
| 283 | wxDL_METHOD_LOAD( m_libGnomePrintUI, gnome_print_job_preview_new ); |
| 284 | |
| 285 | return true; |
| 286 | } |
| 287 | |
| 288 | static wxGnomePrintLibrary* gs_libGnomePrint = NULL; |
| 289 | |
| 290 | //---------------------------------------------------------------------------- |
| 291 | // wxGnomePrintNativeData |
| 292 | //---------------------------------------------------------------------------- |
| 293 | |
| 294 | IMPLEMENT_CLASS(wxGnomePrintNativeData, wxPrintNativeDataBase) |
| 295 | |
| 296 | wxGnomePrintNativeData::wxGnomePrintNativeData() |
| 297 | { |
| 298 | m_config = gs_libGnomePrint->gnome_print_config_default(); |
| 299 | m_job = gs_libGnomePrint->gnome_print_job_new( m_config ); |
| 300 | } |
| 301 | |
| 302 | wxGnomePrintNativeData::~wxGnomePrintNativeData() |
| 303 | { |
| 304 | g_object_unref (m_config); |
| 305 | } |
| 306 | |
| 307 | bool wxGnomePrintNativeData::TransferTo( wxPrintData &data ) |
| 308 | { |
| 309 | guchar *res = gs_libGnomePrint->gnome_print_config_get( m_config, |
| 310 | (guchar*)(char*)GNOME_PRINT_KEY_PAGE_ORIENTATION ); |
| 311 | if (g_ascii_strcasecmp((const gchar *)res,"R90") == 0) |
| 312 | data.SetOrientation( wxLANDSCAPE ); |
| 313 | else |
| 314 | data.SetOrientation( wxPORTRAIT ); |
| 315 | g_free( res ); |
| 316 | |
| 317 | res = gs_libGnomePrint->gnome_print_config_get( m_config, |
| 318 | (guchar*)(char*)GNOME_PRINT_KEY_OUTPUT_FILENAME ); |
| 319 | if (res) |
| 320 | { |
| 321 | data.SetFilename( wxConvFile.cMB2WX( (const char*) res ) ); |
| 322 | wxPrintf( "filename %s\n", data.GetFilename() ); |
| 323 | g_free( res ); |
| 324 | } |
| 325 | else |
| 326 | { |
| 327 | data.SetFilename( wxEmptyString ); |
| 328 | } |
| 329 | |
| 330 | gboolean ret; |
| 331 | if (gs_libGnomePrint->gnome_print_config_get_boolean( m_config, |
| 332 | (guchar*)(char*)GNOME_PRINT_KEY_COLLATE, &ret)) |
| 333 | { |
| 334 | data.SetCollate( ret ); |
| 335 | } |
| 336 | |
| 337 | // gnome_print_v |
| 338 | |
| 339 | return true; |
| 340 | } |
| 341 | |
| 342 | bool wxGnomePrintNativeData::TransferFrom( const wxPrintData &data ) |
| 343 | { |
| 344 | if (data.GetOrientation() == wxLANDSCAPE) |
| 345 | { |
| 346 | gs_libGnomePrint->gnome_print_config_set( m_config, |
| 347 | (guchar*)(char*)GNOME_PRINT_KEY_PAGE_ORIENTATION, |
| 348 | (guchar*)(char*)"R90" ); |
| 349 | } |
| 350 | else |
| 351 | { |
| 352 | gs_libGnomePrint->gnome_print_config_set( m_config, |
| 353 | (guchar*)(char*)GNOME_PRINT_KEY_PAGE_ORIENTATION, |
| 354 | (guchar*)(char*)"R0" ); |
| 355 | } |
| 356 | |
| 357 | if (data.GetCollate()) |
| 358 | { |
| 359 | gs_libGnomePrint->gnome_print_config_set_boolean( m_config, |
| 360 | (guchar*)(char*)GNOME_PRINT_KEY_COLLATE, |
| 361 | TRUE ); |
| 362 | } |
| 363 | else |
| 364 | { |
| 365 | gs_libGnomePrint->gnome_print_config_set_boolean( m_config, |
| 366 | (guchar*)(char*)GNOME_PRINT_KEY_COLLATE, |
| 367 | FALSE ); |
| 368 | } |
| 369 | |
| 370 | switch (data.GetPaperId()) |
| 371 | { |
| 372 | case wxPAPER_A3: gs_libGnomePrint->gnome_print_config_set( m_config, |
| 373 | (guchar*)(char*)GNOME_PRINT_KEY_PAPER_SIZE, |
| 374 | (guchar*)(char*)"A3" ); |
| 375 | break; |
| 376 | case wxPAPER_A5: gs_libGnomePrint->gnome_print_config_set( m_config, |
| 377 | (guchar*)(char*)GNOME_PRINT_KEY_PAPER_SIZE, |
| 378 | (guchar*)(char*)"A5" ); |
| 379 | break; |
| 380 | case wxPAPER_B4: gs_libGnomePrint->gnome_print_config_set( m_config, |
| 381 | (guchar*)(char*)GNOME_PRINT_KEY_PAPER_SIZE, |
| 382 | (guchar*)(char*)"B4" ); |
| 383 | break; |
| 384 | case wxPAPER_B5: gs_libGnomePrint->gnome_print_config_set( m_config, |
| 385 | (guchar*)(char*)GNOME_PRINT_KEY_PAPER_SIZE, |
| 386 | (guchar*)(char*)"B5" ); |
| 387 | break; |
| 388 | case wxPAPER_LETTER: gs_libGnomePrint->gnome_print_config_set( m_config, |
| 389 | (guchar*)(char*)GNOME_PRINT_KEY_PAPER_SIZE, |
| 390 | (guchar*)(char*)"USLetter" ); |
| 391 | break; |
| 392 | case wxPAPER_LEGAL: gs_libGnomePrint->gnome_print_config_set( m_config, |
| 393 | (guchar*)(char*)GNOME_PRINT_KEY_PAPER_SIZE, |
| 394 | (guchar*)(char*)"USLegal" ); |
| 395 | break; |
| 396 | case wxPAPER_EXECUTIVE: gs_libGnomePrint->gnome_print_config_set( m_config, |
| 397 | (guchar*)(char*)GNOME_PRINT_KEY_PAPER_SIZE, |
| 398 | (guchar*)(char*)"Executive" ); |
| 399 | break; |
| 400 | case wxPAPER_ENV_C5: gs_libGnomePrint->gnome_print_config_set( m_config, |
| 401 | (guchar*)(char*)GNOME_PRINT_KEY_PAPER_SIZE, |
| 402 | (guchar*)(char*)"C5" ); |
| 403 | break; |
| 404 | case wxPAPER_ENV_C6: gs_libGnomePrint->gnome_print_config_set( m_config, |
| 405 | (guchar*)(char*)GNOME_PRINT_KEY_PAPER_SIZE, |
| 406 | (guchar*)(char*)"C6" ); |
| 407 | break; |
| 408 | case wxPAPER_NONE: break; |
| 409 | |
| 410 | default: |
| 411 | case wxPAPER_A4: gs_libGnomePrint->gnome_print_config_set( m_config, |
| 412 | (guchar*)(char*)GNOME_PRINT_KEY_PAPER_SIZE, |
| 413 | (guchar*)(char*)"A4" ); |
| 414 | break; |
| 415 | } |
| 416 | |
| 417 | return true; |
| 418 | } |
| 419 | |
| 420 | //---------------------------------------------------------------------------- |
| 421 | // wxGnomePrintFactory |
| 422 | //---------------------------------------------------------------------------- |
| 423 | |
| 424 | wxPrinterBase* wxGnomePrintFactory::CreatePrinter( wxPrintDialogData *data ) |
| 425 | { |
| 426 | return new wxGnomePrinter( data ); |
| 427 | } |
| 428 | |
| 429 | wxPrintPreviewBase *wxGnomePrintFactory::CreatePrintPreview( wxPrintout *preview, |
| 430 | wxPrintout *printout, |
| 431 | wxPrintDialogData *data ) |
| 432 | { |
| 433 | return new wxGnomePrintPreview( preview, printout, data ); |
| 434 | } |
| 435 | |
| 436 | wxPrintPreviewBase *wxGnomePrintFactory::CreatePrintPreview( wxPrintout *preview, |
| 437 | wxPrintout *printout, |
| 438 | wxPrintData *data ) |
| 439 | { |
| 440 | return new wxGnomePrintPreview( preview, printout, data ); |
| 441 | } |
| 442 | |
| 443 | wxPrintDialogBase *wxGnomePrintFactory::CreatePrintDialog( wxWindow *parent, |
| 444 | wxPrintDialogData *data ) |
| 445 | { |
| 446 | return new wxGnomePrintDialog( parent, data ); |
| 447 | } |
| 448 | |
| 449 | wxPrintDialogBase *wxGnomePrintFactory::CreatePrintDialog( wxWindow *parent, |
| 450 | wxPrintData *data ) |
| 451 | { |
| 452 | return new wxGnomePrintDialog( parent, data ); |
| 453 | } |
| 454 | |
| 455 | wxPageSetupDialogBase *wxGnomePrintFactory::CreatePageSetupDialog( wxWindow *parent, |
| 456 | wxPageSetupDialogData * data ) |
| 457 | { |
| 458 | // The native page setup dialog is broken. It |
| 459 | // miscalculates newly entered values for the |
| 460 | // margins if you have not chose "points" but |
| 461 | // e.g. centimerters. |
| 462 | // This has been fixed in GNOME CVS (maybe |
| 463 | // fixed in libgnomeprintui 2.8.1) |
| 464 | |
| 465 | return new wxGnomePageSetupDialog( parent, data ); |
| 466 | } |
| 467 | |
| 468 | bool wxGnomePrintFactory::HasPrintSetupDialog() |
| 469 | { |
| 470 | return false; |
| 471 | } |
| 472 | |
| 473 | wxDialog * |
| 474 | wxGnomePrintFactory::CreatePrintSetupDialog(wxWindow * WXUNUSED(parent), |
| 475 | wxPrintData * WXUNUSED(data)) |
| 476 | { |
| 477 | return NULL; |
| 478 | } |
| 479 | |
| 480 | |
| 481 | #if wxUSE_NEW_DC |
| 482 | |
| 483 | wxDCImpl* wxGnomePrintFactory::CreatePrinterDCImpl( wxPrinterDC *owner, const wxPrintData& data ) |
| 484 | { |
| 485 | return new wxGnomePrinterDCImpl( owner, data ); |
| 486 | } |
| 487 | |
| 488 | #else |
| 489 | |
| 490 | wxDC* wxGnomePrintFactory::CreatePrinterDC( const wxPrintData& data ) |
| 491 | { |
| 492 | return new wxGnomePrinterDC(data); |
| 493 | } |
| 494 | |
| 495 | #endif |
| 496 | |
| 497 | bool wxGnomePrintFactory::HasOwnPrintToFile() |
| 498 | { |
| 499 | return true; |
| 500 | } |
| 501 | |
| 502 | bool wxGnomePrintFactory::HasPrinterLine() |
| 503 | { |
| 504 | return true; |
| 505 | } |
| 506 | |
| 507 | wxString wxGnomePrintFactory::CreatePrinterLine() |
| 508 | { |
| 509 | // redundant now |
| 510 | return wxEmptyString; |
| 511 | } |
| 512 | |
| 513 | bool wxGnomePrintFactory::HasStatusLine() |
| 514 | { |
| 515 | // redundant now |
| 516 | return true; |
| 517 | } |
| 518 | |
| 519 | wxString wxGnomePrintFactory::CreateStatusLine() |
| 520 | { |
| 521 | // redundant now |
| 522 | return wxEmptyString; |
| 523 | } |
| 524 | |
| 525 | wxPrintNativeDataBase *wxGnomePrintFactory::CreatePrintNativeData() |
| 526 | { |
| 527 | return new wxGnomePrintNativeData; |
| 528 | } |
| 529 | |
| 530 | //---------------------------------------------------------------------------- |
| 531 | // wxGnomePrintSetupDialog |
| 532 | //---------------------------------------------------------------------------- |
| 533 | |
| 534 | IMPLEMENT_CLASS(wxGnomePrintDialog, wxPrintDialogBase) |
| 535 | |
| 536 | wxGnomePrintDialog::wxGnomePrintDialog( wxWindow *parent, wxPrintDialogData *data ) |
| 537 | : wxPrintDialogBase(parent, wxID_ANY, _("Print"), |
| 538 | wxPoint(0, 0), wxSize(600, 600), |
| 539 | wxDEFAULT_DIALOG_STYLE | |
| 540 | wxTAB_TRAVERSAL) |
| 541 | { |
| 542 | if (data) |
| 543 | m_printDialogData = *data; |
| 544 | |
| 545 | Init(); |
| 546 | } |
| 547 | |
| 548 | wxGnomePrintDialog::wxGnomePrintDialog( wxWindow *parent, wxPrintData *data ) |
| 549 | : wxPrintDialogBase(parent, wxID_ANY, _("Print"), |
| 550 | wxPoint(0, 0), wxSize(600, 600), |
| 551 | wxDEFAULT_DIALOG_STYLE | |
| 552 | wxTAB_TRAVERSAL) |
| 553 | { |
| 554 | if (data) |
| 555 | m_printDialogData = *data; |
| 556 | |
| 557 | Init(); |
| 558 | } |
| 559 | |
| 560 | void wxGnomePrintDialog::Init() |
| 561 | { |
| 562 | wxPrintData data = m_printDialogData.GetPrintData(); |
| 563 | |
| 564 | data.ConvertToNative(); |
| 565 | |
| 566 | wxGnomePrintNativeData *native = |
| 567 | (wxGnomePrintNativeData*) data.GetNativeData(); |
| 568 | |
| 569 | m_widget = gs_libGnomePrint->gnome_print_dialog_new( native->GetPrintJob(), |
| 570 | (guchar*)"Print", |
| 571 | GNOME_PRINT_DIALOG_RANGE|GNOME_PRINT_DIALOG_COPIES ); |
| 572 | |
| 573 | int flag = 0; |
| 574 | if (m_printDialogData.GetEnableSelection()) |
| 575 | flag |= GNOME_PRINT_RANGE_SELECTION; |
| 576 | if (m_printDialogData.GetEnablePageNumbers()) |
| 577 | flag |= GNOME_PRINT_RANGE_ALL|GNOME_PRINT_RANGE_RANGE; |
| 578 | |
| 579 | gs_libGnomePrint->gnome_print_dialog_construct_range_page( (GnomePrintDialog*) m_widget, |
| 580 | flag, |
| 581 | m_printDialogData.GetMinPage(), |
| 582 | m_printDialogData.GetMaxPage(), |
| 583 | NULL, |
| 584 | NULL ); |
| 585 | } |
| 586 | |
| 587 | wxGnomePrintDialog::~wxGnomePrintDialog() |
| 588 | { |
| 589 | m_widget = NULL; |
| 590 | } |
| 591 | |
| 592 | int wxGnomePrintDialog::ShowModal() |
| 593 | { |
| 594 | WX_HOOK_MODAL_DIALOG(); |
| 595 | |
| 596 | int response = gtk_dialog_run (GTK_DIALOG (m_widget)); |
| 597 | |
| 598 | if (response == GNOME_PRINT_DIALOG_RESPONSE_CANCEL) |
| 599 | { |
| 600 | gtk_widget_destroy(m_widget); |
| 601 | m_widget = NULL; |
| 602 | |
| 603 | return wxID_CANCEL; |
| 604 | } |
| 605 | |
| 606 | m_printDialogData.GetPrintData().ConvertFromNative(); |
| 607 | |
| 608 | gint copies = 1; |
| 609 | gboolean collate = false; |
| 610 | gs_libGnomePrint->gnome_print_dialog_get_copies( (GnomePrintDialog*) m_widget, &copies, &collate ); |
| 611 | m_printDialogData.SetNoCopies( copies ); |
| 612 | m_printDialogData.SetCollate( collate ); |
| 613 | |
| 614 | // Cast needed to avoid warnings because the gnome_print_dialog_get_range() |
| 615 | // is declared as returning a wrong enum type. |
| 616 | switch ( static_cast<int>( gs_libGnomePrint->gnome_print_dialog_get_range( (GnomePrintDialog*) m_widget ))) |
| 617 | { |
| 618 | case GNOME_PRINT_RANGE_SELECTION: |
| 619 | m_printDialogData.SetSelection( true ); |
| 620 | break; |
| 621 | case GNOME_PRINT_RANGE_ALL: |
| 622 | m_printDialogData.SetAllPages( true ); |
| 623 | m_printDialogData.SetFromPage( 0 ); |
| 624 | m_printDialogData.SetToPage( 9999 ); |
| 625 | break; |
| 626 | case GNOME_PRINT_RANGE_RANGE: |
| 627 | default: |
| 628 | gint start,end; |
| 629 | gs_libGnomePrint->gnome_print_dialog_get_range_page( (GnomePrintDialog*) m_widget, &start, &end ); |
| 630 | m_printDialogData.SetFromPage( start ); |
| 631 | m_printDialogData.SetToPage( end ); |
| 632 | break; |
| 633 | } |
| 634 | |
| 635 | gtk_widget_destroy(m_widget); |
| 636 | m_widget = NULL; |
| 637 | |
| 638 | if (response == GNOME_PRINT_DIALOG_RESPONSE_PREVIEW) |
| 639 | return wxID_PREVIEW; |
| 640 | |
| 641 | return wxID_OK; |
| 642 | } |
| 643 | |
| 644 | wxDC *wxGnomePrintDialog::GetPrintDC() |
| 645 | { |
| 646 | // Later |
| 647 | return NULL; |
| 648 | } |
| 649 | |
| 650 | bool wxGnomePrintDialog::Validate() |
| 651 | { |
| 652 | return true; |
| 653 | } |
| 654 | |
| 655 | bool wxGnomePrintDialog::TransferDataToWindow() |
| 656 | { |
| 657 | return true; |
| 658 | } |
| 659 | |
| 660 | bool wxGnomePrintDialog::TransferDataFromWindow() |
| 661 | { |
| 662 | return true; |
| 663 | } |
| 664 | |
| 665 | //---------------------------------------------------------------------------- |
| 666 | // wxGnomePageSetupDialog |
| 667 | //---------------------------------------------------------------------------- |
| 668 | |
| 669 | IMPLEMENT_CLASS(wxGnomePageSetupDialog, wxPageSetupDialogBase) |
| 670 | |
| 671 | wxGnomePageSetupDialog::wxGnomePageSetupDialog(wxWindow * WXUNUSED(parent), |
| 672 | wxPageSetupDialogData *data) |
| 673 | { |
| 674 | if (data) |
| 675 | m_pageDialogData = *data; |
| 676 | |
| 677 | m_pageDialogData.GetPrintData().ConvertToNative(); |
| 678 | |
| 679 | wxGnomePrintNativeData *native = |
| 680 | (wxGnomePrintNativeData*) m_pageDialogData.GetPrintData().GetNativeData(); |
| 681 | |
| 682 | // This *was* required as the page setup dialog |
| 683 | // calculates wrong values otherwise. |
| 684 | #if 0 |
| 685 | gs_libGnomePrint->gnome_print_config_set( native->GetPrintConfig(), |
| 686 | (const guchar*) GNOME_PRINT_KEY_PREFERED_UNIT, |
| 687 | (const guchar*) "Pts" ); |
| 688 | #endif |
| 689 | |
| 690 | GnomePrintConfig *config = native->GetPrintConfig(); |
| 691 | |
| 692 | const GnomePrintUnit *mm_unit = gs_libGnomePrint->gnome_print_unit_get_by_abbreviation( (const guchar*) "mm" ); |
| 693 | |
| 694 | double ml = (double) m_pageDialogData.GetMarginTopLeft().x; |
| 695 | double mt = (double) m_pageDialogData.GetMarginTopLeft().y; |
| 696 | double mr = (double) m_pageDialogData.GetMarginBottomRight().x; |
| 697 | double mb = (double) m_pageDialogData.GetMarginBottomRight().y; |
| 698 | |
| 699 | gs_libGnomePrint->gnome_print_config_set_length (config, |
| 700 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT, ml, mm_unit ); |
| 701 | gs_libGnomePrint->gnome_print_config_set_length (config, |
| 702 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT, mr, mm_unit ); |
| 703 | gs_libGnomePrint->gnome_print_config_set_length (config, |
| 704 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP, mt, mm_unit ); |
| 705 | gs_libGnomePrint->gnome_print_config_set_length (config, |
| 706 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM, mb, mm_unit ); |
| 707 | |
| 708 | m_widget = gtk_dialog_new(); |
| 709 | |
| 710 | gtk_window_set_title( GTK_WINDOW(m_widget), wxGTK_CONV( _("Page setup") ) ); |
| 711 | |
| 712 | GtkWidget *main = gs_libGnomePrint->gnome_paper_selector_new_with_flags( native->GetPrintConfig(), |
| 713 | GNOME_PAPER_SELECTOR_MARGINS|GNOME_PAPER_SELECTOR_FEED_ORIENTATION ); |
| 714 | gtk_container_set_border_width (GTK_CONTAINER (main), 8); |
| 715 | gtk_widget_show (main); |
| 716 | |
| 717 | gtk_container_add( GTK_CONTAINER (GTK_DIALOG (m_widget)->vbox), main ); |
| 718 | |
| 719 | gtk_dialog_set_has_separator (GTK_DIALOG (m_widget), TRUE); |
| 720 | |
| 721 | gtk_dialog_add_buttons (GTK_DIALOG (m_widget), |
| 722 | GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
| 723 | GTK_STOCK_OK, GTK_RESPONSE_OK, |
| 724 | NULL); |
| 725 | |
| 726 | gtk_dialog_set_default_response (GTK_DIALOG (m_widget), |
| 727 | GTK_RESPONSE_OK); |
| 728 | } |
| 729 | |
| 730 | wxGnomePageSetupDialog::~wxGnomePageSetupDialog() |
| 731 | { |
| 732 | } |
| 733 | |
| 734 | wxPageSetupDialogData& wxGnomePageSetupDialog::GetPageSetupDialogData() |
| 735 | { |
| 736 | return m_pageDialogData; |
| 737 | } |
| 738 | |
| 739 | int wxGnomePageSetupDialog::ShowModal() |
| 740 | { |
| 741 | WX_HOOK_MODAL_DIALOG(); |
| 742 | |
| 743 | wxGnomePrintNativeData *native = |
| 744 | (wxGnomePrintNativeData*) m_pageDialogData.GetPrintData().GetNativeData(); |
| 745 | |
| 746 | GnomePrintConfig *config = native->GetPrintConfig(); |
| 747 | |
| 748 | |
| 749 | int ret = gtk_dialog_run( GTK_DIALOG(m_widget) ); |
| 750 | |
| 751 | if (ret == GTK_RESPONSE_OK) |
| 752 | { |
| 753 | // Transfer data back to m_pageDialogData |
| 754 | m_pageDialogData.GetPrintData().ConvertFromNative(); |
| 755 | |
| 756 | // I don't know how querying the last parameter works |
| 757 | double ml,mr,mt,mb,pw,ph; |
| 758 | gs_libGnomePrint->gnome_print_config_get_length (config, |
| 759 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT, &ml, NULL); |
| 760 | gs_libGnomePrint->gnome_print_config_get_length (config, |
| 761 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT, &mr, NULL); |
| 762 | gs_libGnomePrint->gnome_print_config_get_length (config, |
| 763 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP, &mt, NULL); |
| 764 | gs_libGnomePrint->gnome_print_config_get_length (config, |
| 765 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM, &mb, NULL); |
| 766 | gs_libGnomePrint->gnome_print_config_get_length (config, |
| 767 | (const guchar*) GNOME_PRINT_KEY_PAPER_WIDTH, &pw, NULL); |
| 768 | gs_libGnomePrint->gnome_print_config_get_length (config, |
| 769 | (const guchar*) GNOME_PRINT_KEY_PAPER_HEIGHT, &ph, NULL); |
| 770 | |
| 771 | // This code converts correctly from what the user chose |
| 772 | // as the unit although I query Pts here |
| 773 | const GnomePrintUnit *mm_unit = gs_libGnomePrint->gnome_print_unit_get_by_abbreviation( (const guchar*) "mm" ); |
| 774 | const GnomePrintUnit *pts_unit = gs_libGnomePrint->gnome_print_unit_get_by_abbreviation( (const guchar*) "Pts" ); |
| 775 | gs_libGnomePrint->gnome_print_convert_distance( &ml, pts_unit, mm_unit ); |
| 776 | gs_libGnomePrint->gnome_print_convert_distance( &mr, pts_unit, mm_unit ); |
| 777 | gs_libGnomePrint->gnome_print_convert_distance( &mt, pts_unit, mm_unit ); |
| 778 | gs_libGnomePrint->gnome_print_convert_distance( &mb, pts_unit, mm_unit ); |
| 779 | gs_libGnomePrint->gnome_print_convert_distance( &pw, pts_unit, mm_unit ); |
| 780 | gs_libGnomePrint->gnome_print_convert_distance( &ph, pts_unit, mm_unit ); |
| 781 | |
| 782 | m_pageDialogData.SetMarginTopLeft( wxPoint( (int)(ml+0.5), (int)(mt+0.5)) ); |
| 783 | m_pageDialogData.SetMarginBottomRight( wxPoint( (int)(mr+0.5), (int)(mb+0.5)) ); |
| 784 | |
| 785 | m_pageDialogData.SetPaperSize( wxSize( (int)(pw+0.5), (int)(ph+0.5) ) ); |
| 786 | |
| 787 | ret = wxID_OK; |
| 788 | } |
| 789 | else |
| 790 | { |
| 791 | ret = wxID_CANCEL; |
| 792 | } |
| 793 | |
| 794 | gtk_widget_destroy( m_widget ); |
| 795 | m_widget = NULL; |
| 796 | |
| 797 | return ret; |
| 798 | } |
| 799 | |
| 800 | bool wxGnomePageSetupDialog::Validate() |
| 801 | { |
| 802 | return true; |
| 803 | } |
| 804 | |
| 805 | bool wxGnomePageSetupDialog::TransferDataToWindow() |
| 806 | { |
| 807 | return true; |
| 808 | } |
| 809 | |
| 810 | bool wxGnomePageSetupDialog::TransferDataFromWindow() |
| 811 | { |
| 812 | return true; |
| 813 | } |
| 814 | |
| 815 | //---------------------------------------------------------------------------- |
| 816 | // wxGnomePrinter |
| 817 | //---------------------------------------------------------------------------- |
| 818 | |
| 819 | IMPLEMENT_CLASS(wxGnomePrinter, wxPrinterBase) |
| 820 | |
| 821 | wxGnomePrinter::wxGnomePrinter( wxPrintDialogData *data ) : |
| 822 | wxPrinterBase( data ) |
| 823 | { |
| 824 | m_native_preview = false; |
| 825 | } |
| 826 | |
| 827 | wxGnomePrinter::~wxGnomePrinter() |
| 828 | { |
| 829 | } |
| 830 | |
| 831 | bool wxGnomePrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt ) |
| 832 | { |
| 833 | if (!printout) |
| 834 | { |
| 835 | sm_lastError = wxPRINTER_ERROR; |
| 836 | return false; |
| 837 | } |
| 838 | |
| 839 | wxPrintData printdata = GetPrintDialogData().GetPrintData(); |
| 840 | |
| 841 | wxGnomePrintNativeData *native = |
| 842 | (wxGnomePrintNativeData*) printdata.GetNativeData(); |
| 843 | |
| 844 | GnomePrintJob *job = gs_libGnomePrint->gnome_print_job_new( native->GetPrintConfig() ); |
| 845 | |
| 846 | // The GnomePrintJob is temporarily stored in the |
| 847 | // native print data as the native print dialog |
| 848 | // needs to access it. |
| 849 | native->SetPrintJob( job ); |
| 850 | |
| 851 | |
| 852 | if (m_printDialogData.GetMinPage() < 1) |
| 853 | m_printDialogData.SetMinPage(1); |
| 854 | if (m_printDialogData.GetMaxPage() < 1) |
| 855 | m_printDialogData.SetMaxPage(9999); |
| 856 | |
| 857 | wxDC *dc; |
| 858 | if (prompt) |
| 859 | dc = PrintDialog( parent ); |
| 860 | else |
| 861 | #if wxUSE_NEW_DC |
| 862 | dc = new wxPrinterDC( printdata ); // TODO: check that this works |
| 863 | #else |
| 864 | dc = new wxGnomePrinterDC( printdata ); // TODO: check that this works |
| 865 | #endif |
| 866 | |
| 867 | if (!dc) |
| 868 | { |
| 869 | gs_libGnomePrint->gnome_print_job_close( job ); |
| 870 | g_object_unref (job); |
| 871 | if (sm_lastError != wxPRINTER_CANCELLED) |
| 872 | sm_lastError = wxPRINTER_ERROR; |
| 873 | return false; |
| 874 | } |
| 875 | |
| 876 | printout->SetPPIScreen(wxGetDisplayPPI()); |
| 877 | printout->SetPPIPrinter( dc->GetResolution(), |
| 878 | dc->GetResolution() ); |
| 879 | |
| 880 | printout->SetDC(dc); |
| 881 | |
| 882 | int w, h; |
| 883 | dc->GetSize(&w, &h); |
| 884 | printout->SetPageSizePixels((int)w, (int)h); |
| 885 | printout->SetPaperRectPixels(wxRect(0, 0, w, h)); |
| 886 | int mw, mh; |
| 887 | dc->GetSizeMM(&mw, &mh); |
| 888 | printout->SetPageSizeMM((int)mw, (int)mh); |
| 889 | printout->OnPreparePrinting(); |
| 890 | |
| 891 | // Get some parameters from the printout, if defined |
| 892 | int fromPage, toPage; |
| 893 | int minPage, maxPage; |
| 894 | printout->GetPageInfo(&minPage, &maxPage, &fromPage, &toPage); |
| 895 | |
| 896 | if (maxPage == 0) |
| 897 | { |
| 898 | gs_libGnomePrint->gnome_print_job_close( job ); |
| 899 | g_object_unref (job); |
| 900 | sm_lastError = wxPRINTER_ERROR; |
| 901 | return false; |
| 902 | } |
| 903 | |
| 904 | printout->OnBeginPrinting(); |
| 905 | |
| 906 | int minPageNum = minPage, maxPageNum = maxPage; |
| 907 | |
| 908 | if ( !m_printDialogData.GetAllPages() ) |
| 909 | { |
| 910 | minPageNum = m_printDialogData.GetFromPage(); |
| 911 | maxPageNum = m_printDialogData.GetToPage(); |
| 912 | } |
| 913 | |
| 914 | |
| 915 | int copyCount; |
| 916 | for ( copyCount = 1; |
| 917 | copyCount <= m_printDialogData.GetNoCopies(); |
| 918 | copyCount++ ) |
| 919 | { |
| 920 | if (!printout->OnBeginDocument(minPageNum, maxPageNum)) |
| 921 | { |
| 922 | wxLogError(_("Could not start printing.")); |
| 923 | sm_lastError = wxPRINTER_ERROR; |
| 924 | break; |
| 925 | } |
| 926 | |
| 927 | int pn; |
| 928 | for ( pn = minPageNum; |
| 929 | pn <= maxPageNum && printout->HasPage(pn); |
| 930 | pn++ ) |
| 931 | { |
| 932 | dc->StartPage(); |
| 933 | printout->OnPrintPage(pn); |
| 934 | dc->EndPage(); |
| 935 | } |
| 936 | |
| 937 | printout->OnEndDocument(); |
| 938 | printout->OnEndPrinting(); |
| 939 | } |
| 940 | |
| 941 | gs_libGnomePrint->gnome_print_job_close( job ); |
| 942 | if (m_native_preview) |
| 943 | { |
| 944 | const wxCharBuffer title(wxGTK_CONV_SYS(_("Print preview"))); |
| 945 | GtkWidget *preview = gs_libGnomePrint->gnome_print_job_preview_new |
| 946 | ( |
| 947 | job, |
| 948 | (const guchar *)title.data() |
| 949 | ); |
| 950 | gtk_widget_show(preview); |
| 951 | } |
| 952 | else |
| 953 | { |
| 954 | gs_libGnomePrint->gnome_print_job_print( job ); |
| 955 | } |
| 956 | |
| 957 | g_object_unref (job); |
| 958 | delete dc; |
| 959 | |
| 960 | return (sm_lastError == wxPRINTER_NO_ERROR); |
| 961 | } |
| 962 | |
| 963 | wxDC* wxGnomePrinter::PrintDialog( wxWindow *parent ) |
| 964 | { |
| 965 | wxGnomePrintDialog dialog( parent, &m_printDialogData ); |
| 966 | int ret = dialog.ShowModal(); |
| 967 | if (ret == wxID_CANCEL) |
| 968 | { |
| 969 | sm_lastError = wxPRINTER_CANCELLED; |
| 970 | return NULL; |
| 971 | } |
| 972 | |
| 973 | m_native_preview = ret == wxID_PREVIEW; |
| 974 | |
| 975 | m_printDialogData = dialog.GetPrintDialogData(); |
| 976 | #if wxUSE_NEW_DC |
| 977 | return new wxPrinterDC( m_printDialogData.GetPrintData() ); |
| 978 | #else |
| 979 | return new wxGnomePrinterDC( m_printDialogData.GetPrintData() ); |
| 980 | #endif |
| 981 | } |
| 982 | |
| 983 | bool wxGnomePrinter::Setup(wxWindow * WXUNUSED(parent)) |
| 984 | { |
| 985 | return false; |
| 986 | } |
| 987 | |
| 988 | //----------------------------------------------------------------------------- |
| 989 | // wxGnomePrinterDC |
| 990 | //----------------------------------------------------------------------------- |
| 991 | |
| 992 | // conversion |
| 993 | static const double RAD2DEG = 180.0 / M_PI; |
| 994 | |
| 995 | // we don't want to use only 72 dpi from GNOME print |
| 996 | static const int DPI = 600; |
| 997 | static const double PS2DEV = 600.0 / 72.0; |
| 998 | static const double DEV2PS = 72.0 / 600.0; |
| 999 | |
| 1000 | #define XLOG2DEV(x) ((double)(LogicalToDeviceX(x)) * DEV2PS) |
| 1001 | #define XLOG2DEVREL(x) ((double)(LogicalToDeviceXRel(x)) * DEV2PS) |
| 1002 | #define YLOG2DEV(x) ((m_pageHeight - (double)LogicalToDeviceY(x)) * DEV2PS) |
| 1003 | #define YLOG2DEVREL(x) ((double)(LogicalToDeviceYRel(x)) * DEV2PS) |
| 1004 | |
| 1005 | #if wxUSE_NEW_DC |
| 1006 | IMPLEMENT_ABSTRACT_CLASS(wxGnomePrinterDCImpl, wxDCImpl) |
| 1007 | #else |
| 1008 | IMPLEMENT_ABSTRACT_CLASS(wxGnomePrinterDC, wxDC) |
| 1009 | #endif |
| 1010 | |
| 1011 | #if wxUSE_NEW_DC |
| 1012 | wxGnomePrinterDCImpl::wxGnomePrinterDCImpl( wxPrinterDC *owner, const wxPrintData& data ) : |
| 1013 | wxDCImpl( owner ) |
| 1014 | #else |
| 1015 | wxGnomePrinterDC::wxGnomePrinterDC( const wxPrintData& data ) |
| 1016 | #endif |
| 1017 | { |
| 1018 | m_printData = data; |
| 1019 | |
| 1020 | wxGnomePrintNativeData *native = |
| 1021 | (wxGnomePrintNativeData*) m_printData.GetNativeData(); |
| 1022 | |
| 1023 | m_job = native->GetPrintJob(); |
| 1024 | m_gpc = gs_libGnomePrint->gnome_print_job_get_context (m_job); |
| 1025 | |
| 1026 | m_layout = gs_libGnomePrint->gnome_print_pango_create_layout( m_gpc ); |
| 1027 | m_fontdesc = pango_font_description_from_string( "Sans 12" ); |
| 1028 | m_context = NULL; |
| 1029 | |
| 1030 | m_currentRed = 0; |
| 1031 | m_currentBlue = 0; |
| 1032 | m_currentGreen = 0; |
| 1033 | |
| 1034 | // Query page size. This seems to omit the margins |
| 1035 | double pw,ph; |
| 1036 | gs_libGnomePrint->gnome_print_job_get_page_size( native->GetPrintJob(), &pw, &ph ); |
| 1037 | |
| 1038 | m_pageHeight = ph * PS2DEV; |
| 1039 | } |
| 1040 | |
| 1041 | wxGnomePrinterDCImpl::~wxGnomePrinterDCImpl() |
| 1042 | { |
| 1043 | } |
| 1044 | |
| 1045 | bool wxGnomePrinterDCImpl::IsOk() const |
| 1046 | { |
| 1047 | return true; |
| 1048 | } |
| 1049 | |
| 1050 | bool |
| 1051 | wxGnomePrinterDCImpl::DoFloodFill(wxCoord WXUNUSED(x1), |
| 1052 | wxCoord WXUNUSED(y1), |
| 1053 | const wxColour& WXUNUSED(col), |
| 1054 | wxFloodFillStyle WXUNUSED(style)) |
| 1055 | { |
| 1056 | return false; |
| 1057 | } |
| 1058 | |
| 1059 | bool |
| 1060 | wxGnomePrinterDCImpl::DoGetPixel(wxCoord WXUNUSED(x1), |
| 1061 | wxCoord WXUNUSED(y1), |
| 1062 | wxColour * WXUNUSED(col)) const |
| 1063 | { |
| 1064 | return false; |
| 1065 | } |
| 1066 | |
| 1067 | void wxGnomePrinterDCImpl::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) |
| 1068 | { |
| 1069 | if ( m_pen.IsTransparent() ) |
| 1070 | return; |
| 1071 | |
| 1072 | SetPen( m_pen ); |
| 1073 | |
| 1074 | gs_libGnomePrint->gnome_print_moveto ( m_gpc, XLOG2DEV(x1), YLOG2DEV(y1) ); |
| 1075 | gs_libGnomePrint->gnome_print_lineto ( m_gpc, XLOG2DEV(x2), YLOG2DEV(y2) ); |
| 1076 | gs_libGnomePrint->gnome_print_stroke ( m_gpc); |
| 1077 | |
| 1078 | CalcBoundingBox( x1, y1 ); |
| 1079 | CalcBoundingBox( x2, y2 ); |
| 1080 | } |
| 1081 | |
| 1082 | void wxGnomePrinterDCImpl::DoCrossHair(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y)) |
| 1083 | { |
| 1084 | } |
| 1085 | |
| 1086 | void wxGnomePrinterDCImpl::DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2,wxCoord xc,wxCoord yc) |
| 1087 | { |
| 1088 | double dx = x1 - xc; |
| 1089 | double dy = y1 - yc; |
| 1090 | double radius = sqrt((double)(dx*dx+dy*dy)); |
| 1091 | double alpha1, alpha2; |
| 1092 | if (x1 == x2 && y1 == y2) |
| 1093 | { |
| 1094 | alpha1 = 0.0; |
| 1095 | alpha2 = 360.0; |
| 1096 | } |
| 1097 | else if ( wxIsNullDouble(radius) ) |
| 1098 | { |
| 1099 | alpha1 = |
| 1100 | alpha2 = 0.0; |
| 1101 | } |
| 1102 | else |
| 1103 | { |
| 1104 | alpha1 = (x1 - xc == 0) ? |
| 1105 | (y1 - yc < 0) ? 90.0 : -90.0 : |
| 1106 | -atan2(double(y1-yc), double(x1-xc)) * RAD2DEG; |
| 1107 | alpha2 = (x2 - xc == 0) ? |
| 1108 | (y2 - yc < 0) ? 90.0 : -90.0 : |
| 1109 | -atan2(double(y2-yc), double(x2-xc)) * RAD2DEG; |
| 1110 | |
| 1111 | while (alpha1 <= 0) alpha1 += 360; |
| 1112 | while (alpha2 <= 0) alpha2 += 360; // adjust angles to be between |
| 1113 | while (alpha1 > 360) alpha1 -= 360; // 0 and 360 degree |
| 1114 | while (alpha2 > 360) alpha2 -= 360; |
| 1115 | } |
| 1116 | |
| 1117 | if ( m_brush.IsNonTransparent() ) |
| 1118 | { |
| 1119 | SetBrush( m_brush ); |
| 1120 | gs_libGnomePrint->gnome_print_moveto ( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc) ); |
| 1121 | gs_libGnomePrint->gnome_print_arcto( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc), XLOG2DEVREL((int)radius), alpha1, alpha2, 0 ); |
| 1122 | |
| 1123 | gs_libGnomePrint->gnome_print_fill( m_gpc ); |
| 1124 | } |
| 1125 | |
| 1126 | if ( m_pen.IsNonTransparent() ) |
| 1127 | { |
| 1128 | SetPen (m_pen); |
| 1129 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); |
| 1130 | gs_libGnomePrint->gnome_print_moveto ( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc) ); |
| 1131 | gs_libGnomePrint->gnome_print_arcto( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc), XLOG2DEVREL((int)radius), alpha1, alpha2, 0 ); |
| 1132 | gs_libGnomePrint->gnome_print_closepath( m_gpc ); |
| 1133 | |
| 1134 | gs_libGnomePrint->gnome_print_stroke( m_gpc ); |
| 1135 | } |
| 1136 | |
| 1137 | CalcBoundingBox (x1, y1); |
| 1138 | CalcBoundingBox (x2, y2); |
| 1139 | CalcBoundingBox (xc, yc); |
| 1140 | } |
| 1141 | |
| 1142 | void wxGnomePrinterDCImpl::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea) |
| 1143 | { |
| 1144 | x += w/2; |
| 1145 | y += h/2; |
| 1146 | |
| 1147 | double xx = XLOG2DEV(x); |
| 1148 | double yy = YLOG2DEV(y); |
| 1149 | |
| 1150 | gs_libGnomePrint->gnome_print_gsave( m_gpc ); |
| 1151 | |
| 1152 | gs_libGnomePrint->gnome_print_translate( m_gpc, xx, yy ); |
| 1153 | double scale = (double)YLOG2DEVREL(h) / (double) XLOG2DEVREL(w); |
| 1154 | gs_libGnomePrint->gnome_print_scale( m_gpc, 1.0, scale ); |
| 1155 | |
| 1156 | xx = 0.0; |
| 1157 | yy = 0.0; |
| 1158 | |
| 1159 | if ( m_brush.IsNonTransparent() ) |
| 1160 | { |
| 1161 | SetBrush( m_brush ); |
| 1162 | |
| 1163 | gs_libGnomePrint->gnome_print_moveto ( m_gpc, xx, yy ); |
| 1164 | gs_libGnomePrint->gnome_print_arcto( m_gpc, xx, yy, |
| 1165 | XLOG2DEVREL(w)/2, sa, ea, 0 ); |
| 1166 | gs_libGnomePrint->gnome_print_moveto ( m_gpc, xx, yy ); |
| 1167 | |
| 1168 | gs_libGnomePrint->gnome_print_fill( m_gpc ); |
| 1169 | } |
| 1170 | |
| 1171 | if ( m_pen.IsNonTransparent() ) |
| 1172 | { |
| 1173 | SetPen (m_pen); |
| 1174 | |
| 1175 | gs_libGnomePrint->gnome_print_arcto( m_gpc, xx, yy, |
| 1176 | XLOG2DEVREL(w)/2, sa, ea, 0 ); |
| 1177 | |
| 1178 | gs_libGnomePrint->gnome_print_stroke( m_gpc ); |
| 1179 | } |
| 1180 | |
| 1181 | gs_libGnomePrint->gnome_print_grestore( m_gpc ); |
| 1182 | |
| 1183 | CalcBoundingBox( x, y ); |
| 1184 | CalcBoundingBox( x+w, y+h ); |
| 1185 | } |
| 1186 | |
| 1187 | void wxGnomePrinterDCImpl::DoDrawPoint(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y)) |
| 1188 | { |
| 1189 | } |
| 1190 | |
| 1191 | void wxGnomePrinterDCImpl::DoDrawLines(int n, const wxPoint points[], wxCoord xoffset, wxCoord yoffset) |
| 1192 | { |
| 1193 | if (n <= 0) return; |
| 1194 | |
| 1195 | if ( m_pen.IsTransparent() ) |
| 1196 | return; |
| 1197 | |
| 1198 | SetPen (m_pen); |
| 1199 | |
| 1200 | int i; |
| 1201 | for ( i =0; i<n ; i++ ) |
| 1202 | CalcBoundingBox( points[i].x+xoffset, points[i].y+yoffset); |
| 1203 | |
| 1204 | gs_libGnomePrint->gnome_print_moveto ( m_gpc, XLOG2DEV(points[0].x+xoffset), YLOG2DEV(points[0].y+yoffset) ); |
| 1205 | |
| 1206 | for (i = 1; i < n; i++) |
| 1207 | gs_libGnomePrint->gnome_print_lineto ( m_gpc, XLOG2DEV(points[i].x+xoffset), YLOG2DEV(points[i].y+yoffset) ); |
| 1208 | |
| 1209 | gs_libGnomePrint->gnome_print_stroke ( m_gpc); |
| 1210 | } |
| 1211 | |
| 1212 | void wxGnomePrinterDCImpl::DoDrawPolygon(int n, const wxPoint points[], |
| 1213 | wxCoord xoffset, wxCoord yoffset, |
| 1214 | wxPolygonFillMode WXUNUSED(fillStyle)) |
| 1215 | { |
| 1216 | if (n==0) return; |
| 1217 | |
| 1218 | if ( m_brush.IsNonTransparent() ) |
| 1219 | { |
| 1220 | SetBrush( m_brush ); |
| 1221 | |
| 1222 | int x = points[0].x + xoffset; |
| 1223 | int y = points[0].y + yoffset; |
| 1224 | CalcBoundingBox( x, y ); |
| 1225 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); |
| 1226 | gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); |
| 1227 | int i; |
| 1228 | for (i = 1; i < n; i++) |
| 1229 | { |
| 1230 | x = points[i].x + xoffset; |
| 1231 | y = points[i].y + yoffset; |
| 1232 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); |
| 1233 | CalcBoundingBox( x, y ); |
| 1234 | } |
| 1235 | gs_libGnomePrint->gnome_print_closepath( m_gpc ); |
| 1236 | gs_libGnomePrint->gnome_print_fill( m_gpc ); |
| 1237 | } |
| 1238 | |
| 1239 | if ( m_pen.IsNonTransparent() ) |
| 1240 | { |
| 1241 | SetPen (m_pen); |
| 1242 | |
| 1243 | int x = points[0].x + xoffset; |
| 1244 | int y = points[0].y + yoffset; |
| 1245 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); |
| 1246 | gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); |
| 1247 | int i; |
| 1248 | for (i = 1; i < n; i++) |
| 1249 | { |
| 1250 | x = points[i].x + xoffset; |
| 1251 | y = points[i].y + yoffset; |
| 1252 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); |
| 1253 | CalcBoundingBox( x, y ); |
| 1254 | } |
| 1255 | gs_libGnomePrint->gnome_print_closepath( m_gpc ); |
| 1256 | gs_libGnomePrint->gnome_print_stroke( m_gpc ); |
| 1257 | } |
| 1258 | } |
| 1259 | |
| 1260 | void wxGnomePrinterDCImpl::DoDrawPolyPolygon(int n, const int count[], const wxPoint points[], wxCoord xoffset, wxCoord yoffset, wxPolygonFillMode fillStyle) |
| 1261 | { |
| 1262 | #if wxUSE_NEW_DC |
| 1263 | wxDCImpl::DoDrawPolyPolygon( n, count, points, xoffset, yoffset, fillStyle ); |
| 1264 | #else |
| 1265 | wxDC::DoDrawPolyPolygon( n, count, points, xoffset, yoffset, fillStyle ); |
| 1266 | #endif |
| 1267 | } |
| 1268 | |
| 1269 | void wxGnomePrinterDCImpl::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) |
| 1270 | { |
| 1271 | width--; |
| 1272 | height--; |
| 1273 | |
| 1274 | if ( m_brush.IsNonTransparent() ) |
| 1275 | { |
| 1276 | SetBrush( m_brush ); |
| 1277 | |
| 1278 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); |
| 1279 | gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); |
| 1280 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y) ); |
| 1281 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y + height) ); |
| 1282 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y + height) ); |
| 1283 | gs_libGnomePrint->gnome_print_closepath( m_gpc ); |
| 1284 | gs_libGnomePrint->gnome_print_fill( m_gpc ); |
| 1285 | |
| 1286 | CalcBoundingBox( x, y ); |
| 1287 | CalcBoundingBox( x + width, y + height ); |
| 1288 | } |
| 1289 | |
| 1290 | if ( m_pen.IsNonTransparent() ) |
| 1291 | { |
| 1292 | SetPen (m_pen); |
| 1293 | |
| 1294 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); |
| 1295 | gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); |
| 1296 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y) ); |
| 1297 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y + height) ); |
| 1298 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y + height) ); |
| 1299 | gs_libGnomePrint->gnome_print_closepath( m_gpc ); |
| 1300 | gs_libGnomePrint->gnome_print_stroke( m_gpc ); |
| 1301 | |
| 1302 | CalcBoundingBox( x, y ); |
| 1303 | CalcBoundingBox( x + width, y + height ); |
| 1304 | } |
| 1305 | } |
| 1306 | |
| 1307 | void wxGnomePrinterDCImpl::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius) |
| 1308 | { |
| 1309 | width--; |
| 1310 | height--; |
| 1311 | |
| 1312 | wxCoord rad = wxRound( radius ); |
| 1313 | |
| 1314 | if ( m_brush.IsNonTransparent() ) |
| 1315 | { |
| 1316 | SetBrush(m_brush); |
| 1317 | gs_libGnomePrint->gnome_print_newpath(m_gpc); |
| 1318 | gs_libGnomePrint->gnome_print_moveto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y)); |
| 1319 | gs_libGnomePrint->gnome_print_curveto(m_gpc, |
| 1320 | XLOG2DEV(x + rad),YLOG2DEV(y), |
| 1321 | XLOG2DEV(x),YLOG2DEV(y), |
| 1322 | XLOG2DEV(x),YLOG2DEV(y + rad)); |
| 1323 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x),YLOG2DEV(y + height - rad)); |
| 1324 | gs_libGnomePrint->gnome_print_curveto(m_gpc, |
| 1325 | XLOG2DEV(x),YLOG2DEV(y + height - rad), |
| 1326 | XLOG2DEV(x),YLOG2DEV(y + height), |
| 1327 | XLOG2DEV(x + rad),YLOG2DEV(y + height)); |
| 1328 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + width - rad),YLOG2DEV(y + height)); |
| 1329 | gs_libGnomePrint->gnome_print_curveto(m_gpc, |
| 1330 | XLOG2DEV(x + width - rad),YLOG2DEV(y + height), |
| 1331 | XLOG2DEV(x + width),YLOG2DEV(y + height), |
| 1332 | XLOG2DEV(x + width),YLOG2DEV(y + height - rad)); |
| 1333 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + width),YLOG2DEV(y + rad)); |
| 1334 | gs_libGnomePrint->gnome_print_curveto(m_gpc, |
| 1335 | XLOG2DEV(x + width),YLOG2DEV(y + rad), |
| 1336 | XLOG2DEV(x + width),YLOG2DEV(y), |
| 1337 | XLOG2DEV(x + width - rad),YLOG2DEV(y)); |
| 1338 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y)); |
| 1339 | gs_libGnomePrint->gnome_print_closepath(m_gpc); |
| 1340 | gs_libGnomePrint->gnome_print_fill(m_gpc); |
| 1341 | |
| 1342 | CalcBoundingBox(x,y); |
| 1343 | CalcBoundingBox(x+width,y+height); |
| 1344 | } |
| 1345 | |
| 1346 | if ( m_pen.IsNonTransparent() ) |
| 1347 | { |
| 1348 | SetPen(m_pen); |
| 1349 | gs_libGnomePrint->gnome_print_newpath(m_gpc); |
| 1350 | gs_libGnomePrint->gnome_print_moveto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y)); |
| 1351 | gs_libGnomePrint->gnome_print_curveto(m_gpc, |
| 1352 | XLOG2DEV(x + rad),YLOG2DEV(y), |
| 1353 | XLOG2DEV(x),YLOG2DEV(y), |
| 1354 | XLOG2DEV(x),YLOG2DEV(y + rad)); |
| 1355 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x),YLOG2DEV(y + height - rad)); |
| 1356 | gs_libGnomePrint->gnome_print_curveto(m_gpc, |
| 1357 | XLOG2DEV(x),YLOG2DEV(y + height - rad), |
| 1358 | XLOG2DEV(x),YLOG2DEV(y + height), |
| 1359 | XLOG2DEV(x + rad),YLOG2DEV(y + height)); |
| 1360 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + width - rad),YLOG2DEV(y + height)); |
| 1361 | gs_libGnomePrint->gnome_print_curveto(m_gpc, |
| 1362 | XLOG2DEV(x + width - rad),YLOG2DEV(y + height), |
| 1363 | XLOG2DEV(x + width),YLOG2DEV(y + height), |
| 1364 | XLOG2DEV(x + width),YLOG2DEV(y + height - rad)); |
| 1365 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + width),YLOG2DEV(y + rad)); |
| 1366 | gs_libGnomePrint->gnome_print_curveto(m_gpc, |
| 1367 | XLOG2DEV(x + width),YLOG2DEV(y + rad), |
| 1368 | XLOG2DEV(x + width),YLOG2DEV(y), |
| 1369 | XLOG2DEV(x + width - rad),YLOG2DEV(y)); |
| 1370 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y)); |
| 1371 | gs_libGnomePrint->gnome_print_closepath(m_gpc); |
| 1372 | gs_libGnomePrint->gnome_print_stroke(m_gpc); |
| 1373 | |
| 1374 | CalcBoundingBox(x,y); |
| 1375 | CalcBoundingBox(x+width,y+height); |
| 1376 | } |
| 1377 | } |
| 1378 | |
| 1379 | void wxGnomePrinterDCImpl::makeEllipticalPath(wxCoord x, wxCoord y, |
| 1380 | wxCoord width, wxCoord height) |
| 1381 | { |
| 1382 | double r = 4 * (sqrt(2.) - 1) / 3; |
| 1383 | double halfW = 0.5 * width, |
| 1384 | halfH = 0.5 * height, |
| 1385 | halfWR = r * halfW, |
| 1386 | halfHR = r * halfH; |
| 1387 | wxCoord halfWI = (wxCoord) halfW, |
| 1388 | halfHI = (wxCoord) halfH; |
| 1389 | |
| 1390 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); |
| 1391 | |
| 1392 | // Approximate an ellipse using four cubic splines, clockwise from 0 deg */ |
| 1393 | gs_libGnomePrint->gnome_print_moveto( m_gpc, |
| 1394 | XLOG2DEV(x + width), |
| 1395 | YLOG2DEV(y + halfHI) ); |
| 1396 | gs_libGnomePrint->gnome_print_curveto( m_gpc, |
| 1397 | XLOG2DEV(x + width), |
| 1398 | YLOG2DEV(y + (wxCoord) rint (halfH + halfHR)), |
| 1399 | XLOG2DEV(x + (wxCoord) rint(halfW + halfWR)), |
| 1400 | YLOG2DEV(y + height), |
| 1401 | XLOG2DEV(x + halfWI), |
| 1402 | YLOG2DEV(y + height) ); |
| 1403 | gs_libGnomePrint->gnome_print_curveto( m_gpc, |
| 1404 | XLOG2DEV(x + (wxCoord) rint(halfW - halfWR)), |
| 1405 | YLOG2DEV(y + height), |
| 1406 | XLOG2DEV(x), |
| 1407 | YLOG2DEV(y + (wxCoord) rint (halfH + halfHR)), |
| 1408 | XLOG2DEV(x), YLOG2DEV(y+halfHI) ); |
| 1409 | gs_libGnomePrint->gnome_print_curveto( m_gpc, |
| 1410 | XLOG2DEV(x), |
| 1411 | YLOG2DEV(y + (wxCoord) rint (halfH - halfHR)), |
| 1412 | XLOG2DEV(x + (wxCoord) rint (halfW - halfWR)), |
| 1413 | YLOG2DEV(y), |
| 1414 | XLOG2DEV(x+halfWI), YLOG2DEV(y) ); |
| 1415 | gs_libGnomePrint->gnome_print_curveto( m_gpc, |
| 1416 | XLOG2DEV(x + (wxCoord) rint(halfW + halfWR)), |
| 1417 | YLOG2DEV(y), |
| 1418 | XLOG2DEV(x + width), |
| 1419 | YLOG2DEV(y + (wxCoord) rint(halfH - halfHR)), |
| 1420 | XLOG2DEV(x + width), YLOG2DEV(y + halfHI) ); |
| 1421 | |
| 1422 | gs_libGnomePrint->gnome_print_closepath(m_gpc); |
| 1423 | } |
| 1424 | |
| 1425 | void wxGnomePrinterDCImpl::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) |
| 1426 | { |
| 1427 | width--; |
| 1428 | height--; |
| 1429 | |
| 1430 | if ( m_brush.IsNonTransparent() ) |
| 1431 | { |
| 1432 | SetBrush( m_brush ); |
| 1433 | makeEllipticalPath( x, y, width, height ); |
| 1434 | gs_libGnomePrint->gnome_print_fill( m_gpc ); |
| 1435 | CalcBoundingBox( x, y ); |
| 1436 | CalcBoundingBox( x + width, y + height ); |
| 1437 | } |
| 1438 | |
| 1439 | if ( m_pen.IsNonTransparent() ) |
| 1440 | { |
| 1441 | SetPen (m_pen); |
| 1442 | makeEllipticalPath( x, y, width, height ); |
| 1443 | gs_libGnomePrint->gnome_print_stroke( m_gpc ); |
| 1444 | CalcBoundingBox( x, y ); |
| 1445 | CalcBoundingBox( x + width, y + height ); |
| 1446 | } |
| 1447 | } |
| 1448 | |
| 1449 | #if wxUSE_SPLINES |
| 1450 | void wxGnomePrinterDCImpl::DoDrawSpline(const wxPointList *points) |
| 1451 | { |
| 1452 | SetPen (m_pen); |
| 1453 | |
| 1454 | double c, d, x1, y1, x2, y2, x3, y3; |
| 1455 | wxPoint *p, *q; |
| 1456 | |
| 1457 | wxPointList::compatibility_iterator node = points->GetFirst(); |
| 1458 | p = node->GetData(); |
| 1459 | x1 = p->x; |
| 1460 | y1 = p->y; |
| 1461 | |
| 1462 | node = node->GetNext(); |
| 1463 | p = node->GetData(); |
| 1464 | c = p->x; |
| 1465 | d = p->y; |
| 1466 | x3 = |
| 1467 | (double)(x1 + c) / 2; |
| 1468 | y3 = |
| 1469 | (double)(y1 + d) / 2; |
| 1470 | |
| 1471 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); |
| 1472 | gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV((wxCoord)x1), YLOG2DEV((wxCoord)y1) ); |
| 1473 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV((wxCoord)x3), YLOG2DEV((wxCoord)y3) ); |
| 1474 | |
| 1475 | CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 ); |
| 1476 | CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 ); |
| 1477 | |
| 1478 | node = node->GetNext(); |
| 1479 | while (node) |
| 1480 | { |
| 1481 | q = node->GetData(); |
| 1482 | |
| 1483 | x1 = x3; |
| 1484 | y1 = y3; |
| 1485 | x2 = c; |
| 1486 | y2 = d; |
| 1487 | c = q->x; |
| 1488 | d = q->y; |
| 1489 | x3 = (double)(x2 + c) / 2; |
| 1490 | y3 = (double)(y2 + d) / 2; |
| 1491 | |
| 1492 | gs_libGnomePrint->gnome_print_curveto(m_gpc, |
| 1493 | XLOG2DEV((wxCoord)x1), YLOG2DEV((wxCoord)y1), |
| 1494 | XLOG2DEV((wxCoord)x2), YLOG2DEV((wxCoord)y2), |
| 1495 | XLOG2DEV((wxCoord)x3), YLOG2DEV((wxCoord)y3) ); |
| 1496 | |
| 1497 | CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 ); |
| 1498 | CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 ); |
| 1499 | |
| 1500 | node = node->GetNext(); |
| 1501 | } |
| 1502 | |
| 1503 | gs_libGnomePrint->gnome_print_lineto ( m_gpc, XLOG2DEV((wxCoord)c), YLOG2DEV((wxCoord)d) ); |
| 1504 | |
| 1505 | gs_libGnomePrint->gnome_print_stroke( m_gpc ); |
| 1506 | } |
| 1507 | #endif // wxUSE_SPLINES |
| 1508 | |
| 1509 | bool |
| 1510 | wxGnomePrinterDCImpl::DoBlit(wxCoord xdest, wxCoord ydest, |
| 1511 | wxCoord width, wxCoord height, |
| 1512 | wxDC *source, |
| 1513 | wxCoord xsrc, wxCoord ysrc, |
| 1514 | wxRasterOperationMode rop, |
| 1515 | bool WXUNUSED(useMask), |
| 1516 | wxCoord WXUNUSED(xsrcMask), wxCoord WXUNUSED(ysrcMask)) |
| 1517 | { |
| 1518 | wxCHECK_MSG( source, false, wxT("invalid source dc") ); |
| 1519 | |
| 1520 | // blit into a bitmap |
| 1521 | wxBitmap bitmap( width, height ); |
| 1522 | wxMemoryDC memDC; |
| 1523 | memDC.SelectObject(bitmap); |
| 1524 | memDC.Blit(0, 0, width, height, source, xsrc, ysrc, rop); /* TODO: Blit transparently? */ |
| 1525 | memDC.SelectObject(wxNullBitmap); |
| 1526 | |
| 1527 | // draw bitmap. scaling and positioning is done there |
| 1528 | GetOwner()->DrawBitmap( bitmap, xdest, ydest ); |
| 1529 | |
| 1530 | return true; |
| 1531 | } |
| 1532 | |
| 1533 | void wxGnomePrinterDCImpl::DoDrawIcon( const wxIcon& icon, wxCoord x, wxCoord y ) |
| 1534 | { |
| 1535 | DoDrawBitmap( icon, x, y, true ); |
| 1536 | } |
| 1537 | |
| 1538 | void |
| 1539 | wxGnomePrinterDCImpl::DoDrawBitmap(const wxBitmap& bitmap, |
| 1540 | wxCoord x, wxCoord y, |
| 1541 | bool WXUNUSED(useMask)) |
| 1542 | { |
| 1543 | if (!bitmap.IsOk()) return; |
| 1544 | |
| 1545 | if (bitmap.HasPixbuf()) |
| 1546 | { |
| 1547 | GdkPixbuf *pixbuf = bitmap.GetPixbuf(); |
| 1548 | guchar *raw_image = gdk_pixbuf_get_pixels( pixbuf ); |
| 1549 | bool has_alpha = gdk_pixbuf_get_has_alpha( pixbuf ); |
| 1550 | int rowstride = gdk_pixbuf_get_rowstride( pixbuf ); |
| 1551 | int height = gdk_pixbuf_get_height( pixbuf ); |
| 1552 | int width = gdk_pixbuf_get_width( pixbuf ); |
| 1553 | |
| 1554 | gs_libGnomePrint->gnome_print_gsave( m_gpc ); |
| 1555 | double matrix[6]; |
| 1556 | matrix[0] = XLOG2DEVREL(width); |
| 1557 | matrix[1] = 0; |
| 1558 | matrix[2] = 0; |
| 1559 | matrix[3] = YLOG2DEVREL(height); |
| 1560 | matrix[4] = XLOG2DEV(x); |
| 1561 | matrix[5] = YLOG2DEV(y+height); |
| 1562 | gs_libGnomePrint->gnome_print_concat( m_gpc, matrix ); |
| 1563 | gs_libGnomePrint->gnome_print_moveto( m_gpc, 0, 0 ); |
| 1564 | if (has_alpha) |
| 1565 | gs_libGnomePrint->gnome_print_rgbaimage( m_gpc, (guchar *)raw_image, width, height, rowstride ); |
| 1566 | else |
| 1567 | gs_libGnomePrint->gnome_print_rgbimage( m_gpc, (guchar *)raw_image, width, height, rowstride ); |
| 1568 | gs_libGnomePrint->gnome_print_grestore( m_gpc ); |
| 1569 | } |
| 1570 | else |
| 1571 | { |
| 1572 | wxImage image = bitmap.ConvertToImage(); |
| 1573 | |
| 1574 | if (!image.IsOk()) return; |
| 1575 | |
| 1576 | gs_libGnomePrint->gnome_print_gsave( m_gpc ); |
| 1577 | double matrix[6]; |
| 1578 | matrix[0] = XLOG2DEVREL(image.GetWidth()); |
| 1579 | matrix[1] = 0; |
| 1580 | matrix[2] = 0; |
| 1581 | matrix[3] = YLOG2DEVREL(image.GetHeight()); |
| 1582 | matrix[4] = XLOG2DEV(x); |
| 1583 | matrix[5] = YLOG2DEV(y+image.GetHeight()); |
| 1584 | gs_libGnomePrint->gnome_print_concat( m_gpc, matrix ); |
| 1585 | gs_libGnomePrint->gnome_print_moveto( m_gpc, 0, 0 ); |
| 1586 | gs_libGnomePrint->gnome_print_rgbimage( m_gpc, (guchar*) image.GetData(), image.GetWidth(), image.GetHeight(), image.GetWidth()*3 ); |
| 1587 | gs_libGnomePrint->gnome_print_grestore( m_gpc ); |
| 1588 | } |
| 1589 | } |
| 1590 | |
| 1591 | void wxGnomePrinterDCImpl::DoDrawText(const wxString& text, wxCoord x, wxCoord y ) |
| 1592 | { |
| 1593 | DoDrawRotatedText( text, x, y, 0.0 ); |
| 1594 | } |
| 1595 | |
| 1596 | void wxGnomePrinterDCImpl::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle) |
| 1597 | { |
| 1598 | double xx = XLOG2DEV(x); |
| 1599 | double yy = YLOG2DEV(y); |
| 1600 | |
| 1601 | const wxScopedCharBuffer data(text.utf8_str()); |
| 1602 | |
| 1603 | pango_layout_set_text(m_layout, data, data.length()); |
| 1604 | const bool setAttrs = m_font.GTKSetPangoAttrs(m_layout); |
| 1605 | |
| 1606 | if (m_textForegroundColour.IsOk()) |
| 1607 | { |
| 1608 | unsigned char red = m_textForegroundColour.Red(); |
| 1609 | unsigned char blue = m_textForegroundColour.Blue(); |
| 1610 | unsigned char green = m_textForegroundColour.Green(); |
| 1611 | |
| 1612 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) |
| 1613 | { |
| 1614 | double redPS = (double)(red) / 255.0; |
| 1615 | double bluePS = (double)(blue) / 255.0; |
| 1616 | double greenPS = (double)(green) / 255.0; |
| 1617 | |
| 1618 | gs_libGnomePrint->gnome_print_setrgbcolor( m_gpc, redPS, greenPS, bluePS ); |
| 1619 | |
| 1620 | m_currentRed = red; |
| 1621 | m_currentBlue = blue; |
| 1622 | m_currentGreen = green; |
| 1623 | } |
| 1624 | } |
| 1625 | |
| 1626 | #if 0 |
| 1627 | if ( m_backgroundMode == wxSOLID ) |
| 1628 | { |
| 1629 | gdk_gc_set_foreground(m_textGC, m_textBackgroundColour.GetColor()); |
| 1630 | gdk_draw_rectangle(m_window, m_textGC, TRUE, xx, yy, w, h); |
| 1631 | gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor()); |
| 1632 | } |
| 1633 | #endif |
| 1634 | |
| 1635 | // Draw layout. |
| 1636 | gs_libGnomePrint->gnome_print_moveto (m_gpc, xx, yy); |
| 1637 | |
| 1638 | gs_libGnomePrint->gnome_print_gsave( m_gpc ); |
| 1639 | |
| 1640 | gs_libGnomePrint->gnome_print_scale( m_gpc, m_scaleX * DEV2PS, m_scaleY * DEV2PS ); |
| 1641 | |
| 1642 | if (fabs(angle) > 0.00001) |
| 1643 | gs_libGnomePrint->gnome_print_rotate( m_gpc, angle ); |
| 1644 | |
| 1645 | gs_libGnomePrint->gnome_print_pango_layout( m_gpc, m_layout ); |
| 1646 | |
| 1647 | int w,h; |
| 1648 | pango_layout_get_pixel_size( m_layout, &w, &h ); |
| 1649 | |
| 1650 | gs_libGnomePrint->gnome_print_grestore( m_gpc ); |
| 1651 | |
| 1652 | if (setAttrs) |
| 1653 | { |
| 1654 | // undo underline attributes setting: |
| 1655 | pango_layout_set_attributes(m_layout, NULL); |
| 1656 | } |
| 1657 | |
| 1658 | CalcBoundingBox(x, y); |
| 1659 | CalcBoundingBox(x + w, y + h); |
| 1660 | } |
| 1661 | |
| 1662 | void wxGnomePrinterDCImpl::Clear() |
| 1663 | { |
| 1664 | } |
| 1665 | |
| 1666 | void wxGnomePrinterDCImpl::SetFont( const wxFont& font ) |
| 1667 | { |
| 1668 | m_font = font; |
| 1669 | |
| 1670 | if (m_font.IsOk()) |
| 1671 | { |
| 1672 | if (m_fontdesc) |
| 1673 | pango_font_description_free( m_fontdesc ); |
| 1674 | |
| 1675 | m_fontdesc = pango_font_description_copy( m_font.GetNativeFontInfo()->description ); |
| 1676 | |
| 1677 | float size = pango_font_description_get_size( m_fontdesc ); |
| 1678 | size = size * GetFontPointSizeAdjustment(72.0); |
| 1679 | pango_font_description_set_size( m_fontdesc, (gint)size ); |
| 1680 | |
| 1681 | pango_layout_set_font_description( m_layout, m_fontdesc ); |
| 1682 | } |
| 1683 | } |
| 1684 | |
| 1685 | void wxGnomePrinterDCImpl::SetPen( const wxPen& pen ) |
| 1686 | { |
| 1687 | if (!pen.IsOk()) return; |
| 1688 | |
| 1689 | m_pen = pen; |
| 1690 | |
| 1691 | double width; |
| 1692 | |
| 1693 | if (m_pen.GetWidth() <= 0) |
| 1694 | width = 0.1; |
| 1695 | else |
| 1696 | width = (double) m_pen.GetWidth(); |
| 1697 | |
| 1698 | gs_libGnomePrint->gnome_print_setlinewidth( m_gpc, width * DEV2PS * m_scaleX ); |
| 1699 | |
| 1700 | static const double dotted[] = {2.0, 5.0}; |
| 1701 | static const double short_dashed[] = {4.0, 4.0}; |
| 1702 | static const double wxCoord_dashed[] = {4.0, 8.0}; |
| 1703 | static const double dotted_dashed[] = {6.0, 6.0, 2.0, 6.0}; |
| 1704 | |
| 1705 | switch (m_pen.GetStyle()) |
| 1706 | { |
| 1707 | case wxPENSTYLE_DOT: gs_libGnomePrint->gnome_print_setdash( m_gpc, 2, dotted, 0 ); break; |
| 1708 | case wxPENSTYLE_SHORT_DASH: gs_libGnomePrint->gnome_print_setdash( m_gpc, 2, short_dashed, 0 ); break; |
| 1709 | case wxPENSTYLE_LONG_DASH: gs_libGnomePrint->gnome_print_setdash( m_gpc, 2, wxCoord_dashed, 0 ); break; |
| 1710 | case wxPENSTYLE_DOT_DASH: gs_libGnomePrint->gnome_print_setdash( m_gpc, 4, dotted_dashed, 0 ); break; |
| 1711 | case wxPENSTYLE_USER_DASH: |
| 1712 | { |
| 1713 | // It may be noted that libgnomeprint between at least |
| 1714 | // versions 2.8.0 and 2.12.1 makes a copy of the dashes |
| 1715 | // and then leak the memory since it doesn't set the |
| 1716 | // internal flag "privatedash" to 0. |
| 1717 | wxDash *wx_dashes; |
| 1718 | int num = m_pen.GetDashes (&wx_dashes); |
| 1719 | gdouble *g_dashes = g_new( gdouble, num ); |
| 1720 | int i; |
| 1721 | for (i = 0; i < num; ++i) |
| 1722 | g_dashes[i] = (gdouble) wx_dashes[i]; |
| 1723 | gs_libGnomePrint -> gnome_print_setdash( m_gpc, num, g_dashes, 0); |
| 1724 | g_free( g_dashes ); |
| 1725 | } |
| 1726 | break; |
| 1727 | case wxPENSTYLE_SOLID: |
| 1728 | case wxPENSTYLE_TRANSPARENT: |
| 1729 | default: gs_libGnomePrint->gnome_print_setdash( m_gpc, 0, NULL, 0 ); break; |
| 1730 | } |
| 1731 | |
| 1732 | |
| 1733 | unsigned char red = m_pen.GetColour().Red(); |
| 1734 | unsigned char blue = m_pen.GetColour().Blue(); |
| 1735 | unsigned char green = m_pen.GetColour().Green(); |
| 1736 | |
| 1737 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) |
| 1738 | { |
| 1739 | double redPS = (double)(red) / 255.0; |
| 1740 | double bluePS = (double)(blue) / 255.0; |
| 1741 | double greenPS = (double)(green) / 255.0; |
| 1742 | |
| 1743 | gs_libGnomePrint->gnome_print_setrgbcolor( m_gpc, redPS, greenPS, bluePS ); |
| 1744 | |
| 1745 | m_currentRed = red; |
| 1746 | m_currentBlue = blue; |
| 1747 | m_currentGreen = green; |
| 1748 | } |
| 1749 | } |
| 1750 | |
| 1751 | void wxGnomePrinterDCImpl::SetBrush( const wxBrush& brush ) |
| 1752 | { |
| 1753 | if (!brush.IsOk()) return; |
| 1754 | |
| 1755 | m_brush = brush; |
| 1756 | |
| 1757 | // Brush colour |
| 1758 | unsigned char red = m_brush.GetColour().Red(); |
| 1759 | unsigned char blue = m_brush.GetColour().Blue(); |
| 1760 | unsigned char green = m_brush.GetColour().Green(); |
| 1761 | |
| 1762 | if (!m_colour) |
| 1763 | { |
| 1764 | // Anything not white is black |
| 1765 | if (! (red == (unsigned char) 255 && |
| 1766 | blue == (unsigned char) 255 && |
| 1767 | green == (unsigned char) 255) ) |
| 1768 | { |
| 1769 | red = (unsigned char) 0; |
| 1770 | green = (unsigned char) 0; |
| 1771 | blue = (unsigned char) 0; |
| 1772 | } |
| 1773 | // setgray here ? |
| 1774 | } |
| 1775 | |
| 1776 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) |
| 1777 | { |
| 1778 | double redPS = (double)(red) / 255.0; |
| 1779 | double bluePS = (double)(blue) / 255.0; |
| 1780 | double greenPS = (double)(green) / 255.0; |
| 1781 | |
| 1782 | gs_libGnomePrint->gnome_print_setrgbcolor( m_gpc, redPS, greenPS, bluePS ); |
| 1783 | |
| 1784 | m_currentRed = red; |
| 1785 | m_currentBlue = blue; |
| 1786 | m_currentGreen = green; |
| 1787 | } |
| 1788 | } |
| 1789 | |
| 1790 | void wxGnomePrinterDCImpl::SetLogicalFunction(wxRasterOperationMode WXUNUSED(function)) |
| 1791 | { |
| 1792 | } |
| 1793 | |
| 1794 | void wxGnomePrinterDCImpl::SetBackground(const wxBrush& WXUNUSED(brush)) |
| 1795 | { |
| 1796 | } |
| 1797 | |
| 1798 | void wxGnomePrinterDCImpl::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height) |
| 1799 | { |
| 1800 | #if wxUSE_NEW_DC |
| 1801 | m_clipping = TRUE; // TODO move somewhere else |
| 1802 | m_clipX1 = x; |
| 1803 | m_clipY1 = y; |
| 1804 | m_clipX2 = x + width; |
| 1805 | m_clipY2 = y + height; |
| 1806 | #else |
| 1807 | wxDC::DoSetClippingRegion( x, y, width, height ); |
| 1808 | #endif |
| 1809 | |
| 1810 | gs_libGnomePrint->gnome_print_gsave( m_gpc ); |
| 1811 | |
| 1812 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); |
| 1813 | gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); |
| 1814 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y) ); |
| 1815 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y + height) ); |
| 1816 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y + height) ); |
| 1817 | gs_libGnomePrint->gnome_print_closepath( m_gpc ); |
| 1818 | gs_libGnomePrint->gnome_print_clip( m_gpc ); |
| 1819 | } |
| 1820 | |
| 1821 | void wxGnomePrinterDCImpl::DestroyClippingRegion() |
| 1822 | { |
| 1823 | #if wxUSE_NEW_DC |
| 1824 | wxDCImpl::DestroyClippingRegion(); |
| 1825 | #else |
| 1826 | wxDC::DestroyClippingRegion(); |
| 1827 | #endif |
| 1828 | |
| 1829 | gs_libGnomePrint->gnome_print_grestore( m_gpc ); |
| 1830 | |
| 1831 | #if 0 |
| 1832 | // not needed, we set the values in each |
| 1833 | // drawing method anyways |
| 1834 | SetPen( m_pen ); |
| 1835 | SetBrush( m_brush ); |
| 1836 | SetFont( m_font ); |
| 1837 | #endif |
| 1838 | } |
| 1839 | |
| 1840 | bool wxGnomePrinterDCImpl::StartDoc(const wxString& WXUNUSED(message)) |
| 1841 | { |
| 1842 | return true; |
| 1843 | } |
| 1844 | |
| 1845 | void wxGnomePrinterDCImpl::EndDoc() |
| 1846 | { |
| 1847 | gs_libGnomePrint->gnome_print_end_doc( m_gpc ); |
| 1848 | } |
| 1849 | |
| 1850 | void wxGnomePrinterDCImpl::StartPage() |
| 1851 | { |
| 1852 | gs_libGnomePrint->gnome_print_beginpage( m_gpc, (const guchar*) "page" ); |
| 1853 | } |
| 1854 | |
| 1855 | void wxGnomePrinterDCImpl::EndPage() |
| 1856 | { |
| 1857 | gs_libGnomePrint->gnome_print_showpage( m_gpc ); |
| 1858 | } |
| 1859 | |
| 1860 | wxCoord wxGnomePrinterDCImpl::GetCharHeight() const |
| 1861 | { |
| 1862 | pango_layout_set_text( m_layout, "H", 1 ); |
| 1863 | |
| 1864 | int w,h; |
| 1865 | pango_layout_get_pixel_size( m_layout, &w, &h ); |
| 1866 | |
| 1867 | return h; |
| 1868 | } |
| 1869 | |
| 1870 | wxCoord wxGnomePrinterDCImpl::GetCharWidth() const |
| 1871 | { |
| 1872 | pango_layout_set_text( m_layout, "H", 1 ); |
| 1873 | |
| 1874 | int w,h; |
| 1875 | pango_layout_get_pixel_size( m_layout, &w, &h ); |
| 1876 | |
| 1877 | return w; |
| 1878 | } |
| 1879 | |
| 1880 | void wxGnomePrinterDCImpl::DoGetTextExtent(const wxString& string, wxCoord *width, wxCoord *height, |
| 1881 | wxCoord *descent, |
| 1882 | wxCoord *externalLeading, |
| 1883 | const wxFont *theFont ) const |
| 1884 | { |
| 1885 | if ( width ) |
| 1886 | *width = 0; |
| 1887 | if ( height ) |
| 1888 | *height = 0; |
| 1889 | if ( descent ) |
| 1890 | *descent = 0; |
| 1891 | if ( externalLeading ) |
| 1892 | *externalLeading = 0; |
| 1893 | |
| 1894 | if (string.empty()) |
| 1895 | { |
| 1896 | return; |
| 1897 | } |
| 1898 | |
| 1899 | // Set layout's text |
| 1900 | |
| 1901 | const wxScopedCharBuffer dataUTF8(string.utf8_str()); |
| 1902 | |
| 1903 | gint oldSize = 0; |
| 1904 | if ( theFont ) |
| 1905 | { |
| 1906 | // scale the font and apply it |
| 1907 | PangoFontDescription *desc = theFont->GetNativeFontInfo()->description; |
| 1908 | oldSize = pango_font_description_get_size(desc); |
| 1909 | float size = oldSize * GetFontPointSizeAdjustment(72.0); |
| 1910 | pango_font_description_set_size(desc, (gint)size); |
| 1911 | |
| 1912 | pango_layout_set_font_description(m_layout, desc); |
| 1913 | } |
| 1914 | |
| 1915 | pango_layout_set_text( m_layout, dataUTF8, strlen(dataUTF8) ); |
| 1916 | |
| 1917 | int h; |
| 1918 | pango_layout_get_pixel_size( m_layout, width, &h ); |
| 1919 | if ( height ) |
| 1920 | *height = h; |
| 1921 | |
| 1922 | if (descent) |
| 1923 | { |
| 1924 | PangoLayoutIter *iter = pango_layout_get_iter(m_layout); |
| 1925 | int baseline = pango_layout_iter_get_baseline(iter); |
| 1926 | pango_layout_iter_free(iter); |
| 1927 | *descent = h - PANGO_PIXELS(baseline); |
| 1928 | } |
| 1929 | |
| 1930 | if ( theFont ) |
| 1931 | { |
| 1932 | // restore font and reset font's size back |
| 1933 | pango_layout_set_font_description(m_layout, m_fontdesc); |
| 1934 | |
| 1935 | PangoFontDescription *desc = theFont->GetNativeFontInfo()->description; |
| 1936 | pango_font_description_set_size(desc, oldSize); |
| 1937 | } |
| 1938 | } |
| 1939 | |
| 1940 | void wxGnomePrinterDCImpl::DoGetSize(int* width, int* height) const |
| 1941 | { |
| 1942 | wxGnomePrintNativeData *native = |
| 1943 | (wxGnomePrintNativeData*) m_printData.GetNativeData(); |
| 1944 | |
| 1945 | // Query page size. This seems to omit the margins |
| 1946 | double pw,ph; |
| 1947 | gs_libGnomePrint->gnome_print_job_get_page_size( native->GetPrintJob(), &pw, &ph ); |
| 1948 | |
| 1949 | if (width) |
| 1950 | *width = wxRound( pw * PS2DEV ); |
| 1951 | |
| 1952 | if (height) |
| 1953 | *height = wxRound( ph * PS2DEV ); |
| 1954 | } |
| 1955 | |
| 1956 | void wxGnomePrinterDCImpl::DoGetSizeMM(int *width, int *height) const |
| 1957 | { |
| 1958 | wxGnomePrintNativeData *native = |
| 1959 | (wxGnomePrintNativeData*) m_printData.GetNativeData(); |
| 1960 | |
| 1961 | // This code assumes values in Pts. |
| 1962 | |
| 1963 | double pw,ph; |
| 1964 | gs_libGnomePrint->gnome_print_job_get_page_size( native->GetPrintJob(), &pw, &ph ); |
| 1965 | |
| 1966 | // Convert to mm. |
| 1967 | |
| 1968 | const GnomePrintUnit *mm_unit = gs_libGnomePrint->gnome_print_unit_get_by_abbreviation( (const guchar*) "mm" ); |
| 1969 | const GnomePrintUnit *pts_unit = gs_libGnomePrint->gnome_print_unit_get_by_abbreviation( (const guchar*) "Pts" ); |
| 1970 | gs_libGnomePrint->gnome_print_convert_distance( &pw, pts_unit, mm_unit ); |
| 1971 | gs_libGnomePrint->gnome_print_convert_distance( &ph, pts_unit, mm_unit ); |
| 1972 | |
| 1973 | if (width) |
| 1974 | *width = (int) (pw + 0.5); |
| 1975 | if (height) |
| 1976 | *height = (int) (ph + 0.5); |
| 1977 | } |
| 1978 | |
| 1979 | wxSize wxGnomePrinterDCImpl::GetPPI() const |
| 1980 | { |
| 1981 | return wxSize(DPI,DPI); |
| 1982 | } |
| 1983 | |
| 1984 | void wxGnomePrinterDCImpl::SetPrintData(const wxPrintData& data) |
| 1985 | { |
| 1986 | m_printData = data; |
| 1987 | |
| 1988 | int height; |
| 1989 | if (m_printData.GetOrientation() == wxPORTRAIT) |
| 1990 | GetOwner()->GetSize( NULL, &height ); |
| 1991 | else |
| 1992 | GetOwner()->GetSize( &height, NULL ); |
| 1993 | m_deviceLocalOriginY = height; |
| 1994 | } |
| 1995 | |
| 1996 | // overridden for wxPrinterDC Impl |
| 1997 | |
| 1998 | int wxGnomePrinterDCImpl::GetResolution() const |
| 1999 | { |
| 2000 | return DPI; |
| 2001 | } |
| 2002 | |
| 2003 | wxRect wxGnomePrinterDCImpl::GetPaperRect() const |
| 2004 | { |
| 2005 | // GNOME print doesn't support printer margins |
| 2006 | int w = 0; |
| 2007 | int h = 0; |
| 2008 | DoGetSize( &w, &h ); |
| 2009 | return wxRect( 0, 0, w, h ); |
| 2010 | } |
| 2011 | |
| 2012 | // ---------------------------------------------------------------------------- |
| 2013 | // wxGnomePrintModule |
| 2014 | // ---------------------------------------------------------------------------- |
| 2015 | |
| 2016 | bool wxGnomePrintModule::OnInit() |
| 2017 | { |
| 2018 | gs_libGnomePrint = new wxGnomePrintLibrary; |
| 2019 | if (gs_libGnomePrint->IsOk()) |
| 2020 | wxPrintFactory::SetPrintFactory( new wxGnomePrintFactory ); |
| 2021 | return true; |
| 2022 | } |
| 2023 | |
| 2024 | void wxGnomePrintModule::OnExit() |
| 2025 | { |
| 2026 | wxDELETE(gs_libGnomePrint); |
| 2027 | } |
| 2028 | |
| 2029 | IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule, wxModule) |
| 2030 | |
| 2031 | // ---------------------------------------------------------------------------- |
| 2032 | // Print preview |
| 2033 | // ---------------------------------------------------------------------------- |
| 2034 | |
| 2035 | IMPLEMENT_CLASS(wxGnomePrintPreview, wxPrintPreviewBase) |
| 2036 | |
| 2037 | void wxGnomePrintPreview::Init(wxPrintout * WXUNUSED(printout), |
| 2038 | wxPrintout * WXUNUSED(printoutForPrinting)) |
| 2039 | { |
| 2040 | DetermineScaling(); |
| 2041 | } |
| 2042 | |
| 2043 | wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout *printout, |
| 2044 | wxPrintout *printoutForPrinting, |
| 2045 | wxPrintDialogData *data) |
| 2046 | : wxPrintPreviewBase(printout, printoutForPrinting, data) |
| 2047 | { |
| 2048 | Init(printout, printoutForPrinting); |
| 2049 | } |
| 2050 | |
| 2051 | wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout *printout, |
| 2052 | wxPrintout *printoutForPrinting, |
| 2053 | wxPrintData *data) |
| 2054 | : wxPrintPreviewBase(printout, printoutForPrinting, data) |
| 2055 | { |
| 2056 | Init(printout, printoutForPrinting); |
| 2057 | } |
| 2058 | |
| 2059 | wxGnomePrintPreview::~wxGnomePrintPreview() |
| 2060 | { |
| 2061 | } |
| 2062 | |
| 2063 | bool wxGnomePrintPreview::Print(bool interactive) |
| 2064 | { |
| 2065 | if (!m_printPrintout) |
| 2066 | return false; |
| 2067 | |
| 2068 | wxPrinter printer(& m_printDialogData); |
| 2069 | return printer.Print(m_previewFrame, m_printPrintout, interactive); |
| 2070 | } |
| 2071 | |
| 2072 | void wxGnomePrintPreview::DetermineScaling() |
| 2073 | { |
| 2074 | wxPaperSize paperType = m_printDialogData.GetPrintData().GetPaperId(); |
| 2075 | if (paperType == wxPAPER_NONE) |
| 2076 | paperType = wxPAPER_NONE; |
| 2077 | |
| 2078 | wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(paperType); |
| 2079 | if (!paper) |
| 2080 | paper = wxThePrintPaperDatabase->FindPaperType(wxPAPER_A4); |
| 2081 | |
| 2082 | if (paper) |
| 2083 | { |
| 2084 | m_previewPrintout->SetPPIScreen(wxGetDisplayPPI()); |
| 2085 | |
| 2086 | int resolution = DPI; |
| 2087 | m_previewPrintout->SetPPIPrinter( resolution, resolution ); |
| 2088 | |
| 2089 | wxSize sizeDevUnits(paper->GetSizeDeviceUnits()); |
| 2090 | |
| 2091 | // TODO: get better resolution information from wxGnomePrinterDCImpl, if possible. |
| 2092 | |
| 2093 | sizeDevUnits.x = (wxCoord)((float)sizeDevUnits.x * resolution / 72.0); |
| 2094 | sizeDevUnits.y = (wxCoord)((float)sizeDevUnits.y * resolution / 72.0); |
| 2095 | wxSize sizeTenthsMM(paper->GetSize()); |
| 2096 | wxSize sizeMM(sizeTenthsMM.x / 10, sizeTenthsMM.y / 10); |
| 2097 | |
| 2098 | // If in landscape mode, we need to swap the width and height. |
| 2099 | if ( m_printDialogData.GetPrintData().GetOrientation() == wxLANDSCAPE ) |
| 2100 | { |
| 2101 | m_pageWidth = sizeDevUnits.y; |
| 2102 | m_pageHeight = sizeDevUnits.x; |
| 2103 | m_previewPrintout->SetPageSizeMM(sizeMM.y, sizeMM.x); |
| 2104 | } |
| 2105 | else |
| 2106 | { |
| 2107 | m_pageWidth = sizeDevUnits.x; |
| 2108 | m_pageHeight = sizeDevUnits.y; |
| 2109 | m_previewPrintout->SetPageSizeMM(sizeMM.x, sizeMM.y); |
| 2110 | } |
| 2111 | m_previewPrintout->SetPageSizePixels(m_pageWidth, m_pageHeight); |
| 2112 | m_previewPrintout->SetPaperRectPixels(wxRect(0, 0, m_pageWidth, m_pageHeight)); |
| 2113 | |
| 2114 | // At 100%, the page should look about page-size on the screen. |
| 2115 | m_previewScaleX = (double)0.8 * 72.0 / (double)resolution; |
| 2116 | m_previewScaleY = m_previewScaleX; |
| 2117 | } |
| 2118 | } |
| 2119 | |
| 2120 | #endif |
| 2121 | // wxUSE_LIBGNOMEPRINT |