1/* printcompositor.h 2 * 3 * Copyright (C) 2009, 2010, 2011 Krzesimir Nowak 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Library General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Library General Public License for more details. 14 * 15 * You should have received a copy of the GNU Library General Public 16 * License along with this library; if not, write to the Free 17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 */ 19 20#include <gtkmm/printcontext.h> 21 22#include <gtksourceviewmm/view.h> 23#include <gtksourceviewmm/buffer.h> 24 25_DEFS(gtksourceviewmm,gtksourceview) 26_PINCLUDE(glibmm/private/object_p.h) 27 28namespace Gsv 29{ 30 31/** Compose a Buffer for printing. 32 * 33 * @newin{2,10} 34 */ 35class PrintCompositor : public Glib::Object 36{ 37 _CLASS_GOBJECT(PrintCompositor, GtkSourcePrintCompositor, GTK_SOURCE_PRINT_COMPOSITOR, Glib::Object, GObject) 38 39protected: 40 _WRAP_CTOR(PrintCompositor(const Glib::RefPtr<Buffer>& buffer), gtk_source_print_compositor_new) 41 explicit PrintCompositor(const View& view); 42public: 43 /** Creates a new print compositor that can be used to print @a buffer. 44 * 45 * @param buffer the Buffer to print. 46 * 47 * @return A new print compositor object. 48 * 49 * @newin{2,10} 50 */ 51 _WRAP_CREATE(const Glib::RefPtr<Buffer>& buffer) 52 53 /** Creates a new print compositor that can be used to print the buffer 54 * associated with @a view. 55 * 56 * This constructor sets some configuration properties to make the 57 * printed output match @a view as much as possible. The properties set are 58 * PrintCompositor::property_tab_width(), 59 * PrintCompositor::property_highlight_syntax(), 60 * PrintCompositor::property_wrap_mode(), 61 * PrintCompositor::property_body_font_name() and 62 * PrintCompositor::property_print_line_numbers(). 63 * 64 * @param view A View to get configuration from. 65 * 66 * @return A new print compositor object. 67 * 68 * @newin{2,10} 69 */ 70 _WRAP_CREATE(const View& view) 71 72 /** Gets the Buffer associated with the compositor. 73 * 74 * @return The Buffer associated with the compositor. 75 * 76 * @newin{2,10} 77 */ 78 _WRAP_METHOD(Glib::RefPtr<Buffer> get_buffer(), gtk_source_print_compositor_get_buffer, refreturn) 79 80 /** Gets the Buffer associated with the compositor. 81 * 82 * @return The Buffer associated with the compositor. 83 * 84 * @newin{2,10} 85 */ 86 _WRAP_METHOD(Glib::RefPtr<const Buffer> get_buffer() const, gtk_source_print_compositor_get_buffer, refreturn, constversion) 87 88 /** Sets the width of tabulation in characters for printed text. 89 * 90 * This function cannot be called anymore after the first call to the 91 * paginate() function. 92 * 93 * @param width Width of tab in characters. 94 * 95 * @newin{2,10} 96 */ 97 _WRAP_METHOD(void set_tab_width(guint width), gtk_source_print_compositor_set_tab_width) 98 99 /** Returns the width of tabulation in characters for printed text. 100 * 101 * @return Width of tab. 102 * 103 * @newin{2,10} 104 */ 105 _WRAP_METHOD(guint get_tab_width() const, gtk_source_print_compositor_get_tab_width) 106 107 /** Sets the line wrapping mode for the printed text. 108 * 109 * This function cannot be called anymore after the first call to the 110 * paginate() function. 111 * 112 * @param wrap_mode A Gtk::WrapMode. 113 * 114 * @newin{2,10} 115 */ 116 _WRAP_METHOD(void set_wrap_mode(Gtk::WrapMode wrap_mode), gtk_source_print_compositor_set_wrap_mode) 117 118 /** Gets the line wrapping mode for the printed text. 119 * 120 * @return The line wrap mode. 121 * 122 * @newin{2,10} 123 */ 124 _WRAP_METHOD(Gtk::WrapMode get_wrap_mode() const, gtk_source_print_compositor_get_wrap_mode) 125 126 /** Sets whether the printed text will be highlighted according to the 127 * buffer rules. 128 * 129 * Both color and font style are applied. This function cannot be called 130 * anymore after the first call to the paginate() function. 131 * 132 * @param highlight Whether syntax should be highlighted. 133 * 134 * @newin{2,10} 135 */ 136 _WRAP_METHOD(void set_highlight_syntax(bool highlight = true), gtk_source_print_compositor_set_highlight_syntax) 137 138 /** Determines whether the printed text will be highlighted according to the 139 * buffer rules. 140 * 141 * Note that highlighting will happen only if the buffer to print has 142 * highlighting activated. 143 * 144 * @return @c true if the printed output will be highlighted. 145 * 146 * @newin{2,10} 147 */ 148 _WRAP_METHOD(bool get_highlight_syntax() const, gtk_source_print_compositor_get_highlight_syntax) 149 150 /** Sets the interval for printed line numbers. 151 * 152 * If @a interval is 0 no numbers will be printed. If greater than 0, 153 * a number will be printed every @a interval lines (i.e. 1 will print all 154 * line numbers). 155 * 156 * Maximum accepted value for @a interval is 100. 157 * 158 * This function cannot be called anymore after the first call to the 159 * paginate() function. 160 * 161 * @param interval Interval for printed line numbers. 162 * 163 * @newin{2,10} 164 */ 165 _WRAP_METHOD(void set_print_line_numbers(guint interval = 1), gtk_source_print_compositor_set_print_line_numbers) 166 167 /** Returns the interval used for line number printing. 168 * 169 * If the value is 0, no line numbers will be printed. The default value is 170 * 1 (i.e. numbers printed in all lines). 171 * 172 * @return The interval of printed line numbers. 173 * 174 * @newin{2,10} 175 **/ 176 _WRAP_METHOD(guint get_print_line_numbers() const, gtk_source_print_compositor_get_print_line_numbers) 177 178 /** Sets the default font for the printed text. 179 * 180 * @a font_name should be a string representation of a font description Pango 181 * can understand. (e.g. "Monospace 10"). 182 * See Pango::FontDescription() for a description of the format 183 * of the string representation. 184 * 185 * This function cannot be called anymore after the first call to the 186 * paginate() function. 187 * 188 * @param font_name The name of the default font for the body text. 189 * 190 * @newin{2,10} 191 */ 192 _WRAP_METHOD(void set_body_font_name(const Glib::ustring& font_name), gtk_source_print_compositor_set_body_font_name) 193 194 /** Returns the name of the font used to print the text body. 195 * 196 * @return A string containing the name of the font used to print the text 197 * body. 198 * 199 * @newin{2,10} 200 */ 201 _WRAP_METHOD(Glib::ustring get_body_font_name() const, gtk_source_print_compositor_get_body_font_name) 202 203 /** Sets the font for printing line numbers on the left margin. 204 * 205 * @a font_name should be a string representation of a font description Pango 206 * can understand (e.g. "Monospace 10"). See 207 * Pango::FontDescription() for a description of the format of 208 * the string representation. 209 * 210 * This function cannot be called anymore after the first call to the 211 * paginate() function. 212 * 213 * @param font_name The name of the font for line numbers. 214 * 215 * @newin{2,10} 216 */ 217 _WRAP_METHOD(void set_line_numbers_font_name(const Glib::ustring& font_name), gtk_source_print_compositor_set_line_numbers_font_name) 218 219 /** Sets the default font for printing line numbers on the left margin. 220 * 221 * The font to be used will be the same used as used for the text. 222 * 223 * This function cannot be called anymore after the first call to the 224 * paginate() function. 225 * 226 * @newin{2,10} 227 */ 228 void set_default_line_numbers_font_name(); 229 230 /** Returns the name of the font used to print line numbers on the left 231 * margin. 232 * 233 * @return A string containing the name of the font used to print line numbers 234 * on the left margin. 235 * 236 * @newin{2,10} 237 */ 238 _WRAP_METHOD(Glib::ustring get_line_numbers_font_name() const, gtk_source_print_compositor_get_line_numbers_font_name) 239 240 /** Sets the font for printing the page header. 241 * 242 * @a font_name should be a string representation of a font description Pango 243 * can understand (e.g. "Monospace 10"). See 244 * Pango::FontDescription() for a description of the format of 245 * the string representation. 246 * 247 * This function cannot be called anymore after the first call to the 248 * paginate() function. 249 * 250 * @param font_name The name of the font for the page header. 251 * 252 * @newin{2,10} 253 */ 254 _WRAP_METHOD(void set_header_font_name(const Glib::ustring& font_name), gtk_source_print_compositor_set_header_font_name) 255 256 /** Sets the default font for printing the page header. 257 * 258 * The font to be used will be the same used as used for the text. 259 * 260 * This function cannot be called anymore after the first call to the 261 * paginate() function. 262 * 263 * @newin{2,10} 264 */ 265 void set_default_header_font_name(); 266 267 /** Returns the name of the font used to print the page header. 268 * 269 * @return A string containing the name of the font used to print the page 270 * header. 271 * 272 * @newin{2,10} 273 */ 274 _WRAP_METHOD(Glib::ustring get_header_font_name() const, gtk_source_print_compositor_get_header_font_name) 275 276 /** Sets the font for printing the page footer. 277 * 278 * @a font_name should be a string representation of a font description Pango 279 * can understand (e.g. "Monospace 10"). See 280 * Pango::FontDescription() for a description of the format of 281 * the string representation. 282 * 283 * This function cannot be called anymore after the first call to the 284 * paginate() function. 285 * 286 * @param font_name The name of the font for the page footer. 287 * 288 * @newin{2,10} 289 */ 290 _WRAP_METHOD(void set_footer_font_name(const Glib::ustring& font_name), gtk_source_print_compositor_set_footer_font_name) 291 292 /** Sets the default font for printing the page footer. 293 * 294 * The font to be used will be the same used as used for the text. 295 * 296 * This function cannot be called anymore after the first call to the 297 * paginate() function. 298 * 299 * @newin{2,10} 300 */ 301 void set_default_footer_font_name(); 302 303 /** Returns the name of the font used to print the page footer. 304 * 305 * @return A string containing the name of the font used to print the page 306 * footer. 307 * 308 * @newin{2,10} 309 */ 310 _WRAP_METHOD(Glib::ustring get_footer_font_name() const, gtk_source_print_compositor_get_footer_font_name) 311 312#m4 _CONV_ENUM(Gtk,Unit) 313 /** Sets the top margin used by @a compositor. 314 * 315 * @param margin The new top margin in units of @a unit. 316 * @param unit The units for @a margin. 317 * 318 * @newin{2,10} 319 */ 320 _WRAP_METHOD(void set_top_margin(double margin, Gtk::Unit unit), gtk_source_print_compositor_set_top_margin) 321 322 /** Gets the top margin in units of @a unit. 323 * 324 * @param unit The unit for the return value. 325 * @return The top margin. 326 * 327 * @newin{2,10} 328 */ 329 _WRAP_METHOD(double get_top_margin(Gtk::Unit unit) const, gtk_source_print_compositor_get_top_margin) 330 331 /** Sets the bottom margin used by @a compositor. 332 * 333 * @param margin The new bottom margin in units of @a unit. 334 * @param unit The units for @a margin. 335 * 336 * @newin{2,10} 337 */ 338 _WRAP_METHOD(void set_bottom_margin(double margin, Gtk::Unit unit), gtk_source_print_compositor_set_bottom_margin) 339 340 /** Gets the bottom margin in units of @a unit. 341 * 342 * @param unit The unit for the return value. 343 * @return The top margin. 344 * 345 * @newin{2,10} 346 */ 347 _WRAP_METHOD(double get_bottom_margin(Gtk::Unit unit) const, gtk_source_print_compositor_get_bottom_margin) 348 349 /** Sets the left margin used by @a compositor. 350 * 351 * @param margin The new bottom margin in units of @a unit. 352 * @param unit The units for @a margin. 353 * 354 * @newin{2,10} 355 */ 356 _WRAP_METHOD(void set_left_margin(double margin, Gtk::Unit unit), gtk_source_print_compositor_set_left_margin) 357 358 /** Gets the left margin in units of @a unit. 359 * 360 * @param unit The unit for the return value. 361 * @return The top margin. 362 * 363 * @newin{2,10} 364 */ 365 _WRAP_METHOD(double get_left_margin(Gtk::Unit unit) const, gtk_source_print_compositor_get_left_margin) 366 367 /** Sets the right margin used by @a compositor. 368 * 369 * @param margin The new bottom margin in units of @a unit. 370 * @param unit The units for @a margin. 371 * 372 * @newin{2,10} 373 */ 374 _WRAP_METHOD(void set_right_margin(double margin, Gtk::Unit unit), gtk_source_print_compositor_set_right_margin) 375 376 /** Gets the right margin in units of @a unit. 377 * 378 * @param unit The unit for the return value. 379 * @return The top margin. 380 * 381 * @newin{2,10} 382 */ 383 _WRAP_METHOD(double get_right_margin(Gtk::Unit unit) const, gtk_source_print_compositor_get_right_margin) 384 385 /** Sets whether you want to print a header in each page. 386 * 387 * The header consists of three pieces of text and an optional line separator, 388 * configurable with set_header_format(). 389 * 390 * Note that by default the header format is unspecified, and if it's 391 * empty it will not be printed, regardless of this setting. 392 * 393 * This function cannot be called anymore after the first call to the 394 * paginate() function. 395 * 396 * @param print @c true if you want the header to be printed. 397 * 398 * @newin{2,10} 399 */ 400 _WRAP_METHOD(void set_print_header(bool print = true), gtk_source_print_compositor_set_print_header) 401 402 /** Determines if a header is set to be printed for each page. 403 * 404 * A header will be printed if this function returns @c true @e and some 405 * format strings have been specified with set_header_format(). 406 * 407 * @return @c true if the header is set to be printed. 408 * 409 * @newin{2,10} 410 */ 411 _WRAP_METHOD(bool get_print_header() const, gtk_source_print_compositor_get_print_header) 412 413 /** Sets whether you want to print a footer in each page. 414 * 415 * The footer consists of three pieces of text and an optional line separator, 416 * configurable with set_header_format(). 417 * 418 * Note that by default the footer format is unspecified, and if it's 419 * empty it will not be printed, regardless of this setting. 420 * 421 * This function cannot be called anymore after the first call to the 422 * paginate() function. 423 * 424 * @param print @c true if you want the footer to be printed. 425 * 426 * @newin{2,10} 427 */ 428 _WRAP_METHOD(void set_print_footer(bool print = true), gtk_source_print_compositor_set_print_footer) 429 430 /** Determines if a footer is set to be printed for each page. 431 * 432 * A footer will be printed if this function returns @c true @e and some 433 * format strings have been specified with set_footer_format(). 434 * 435 * @return @c true if the header is set to be printed. 436 * 437 * @newin{2,10} 438 */ 439 _WRAP_METHOD(bool get_print_footer() const, gtk_source_print_compositor_get_print_footer) 440 441 _IGNORE(gtk_source_print_compositor_set_header_format) 442 /** Sets strftime like header format strings, to be printed on the 443 * left, center and right of the top of each page. 444 * 445 * The strings may include strftime(3) codes which will be expanded at print 446 * time. All strftime(3) codes are accepted, with the addition of %N for the 447 * page number and %Q for the page count. 448 * 449 * @a separator specifies if a solid line should be drawn to separate 450 * the header from the document text. 451 * 452 * If empty string is given for any of the three arguments, that particular 453 * string will not be printed. 454 * 455 * For the header to be printed, in addition to specifying format strings, you 456 * need to enable header printing with set_print_header(). 457 * 458 * This function cannot be called anymore after the first call to the 459 * paginate() function. 460 * 461 * @param separator @c true if you want a separator line to be printed. 462 * @param left A format string to print on the left of the header. 463 * @param center A format string to print on the center of the header. 464 * @param right A format string to print on the right of the header. 465 * 466 * @newin{2,10} 467 */ 468 void set_header_format(bool separator, const Glib::ustring& left, const Glib::ustring& center, const Glib::ustring& right); 469 _IGNORE(gtk_source_print_compositor_set_footer_format) 470 /** Sets strftime like footer format strings, to be printed on the 471 * left, center and right of the top of each page. 472 * 473 * The strings may include strftime(3) codes which will be expanded at print 474 * time. All strftime(3) codes are accepted, with the addition of %N for the 475 * page number and %Q for the page count. 476 * 477 * @a separator specifies if a solid line should be drawn to separate 478 * the footer from the document text. 479 * 480 * If empty string is given for any of the three arguments, that particular 481 * string will not be printed. 482 * 483 * For the footer to be printed, in addition to specifying format strings, you 484 * need to enable footer printing with set_print_footer(). 485 * 486 * This function cannot be called anymore after the first call to the 487 * paginate() function. 488 * 489 * @param separator @c true if you want a separator line to be printed. 490 * @param left A format string to print on the left of the footer. 491 * @param center A format string to print on the center of the footer. 492 * @param right A format string to print on the right of the footer. 493 * 494 * @newin{2,10} 495 */ 496 void set_footer_format(bool separator, const Glib::ustring& left, const Glib::ustring& center, const Glib::ustring& right); 497 498 /** Returns the number of pages in the document or @c -1 if the 499 * document has not been completely paginated. 500 * 501 * @return The number of pages in the document or @c -1 if the document has 502 * not been completely paginated. 503 * 504 * @newin{2,10} 505 */ 506 _WRAP_METHOD(int get_n_pages() const, gtk_source_print_compositor_get_n_pages) 507 508#m4 _CONVERSION(`const Glib::RefPtr<Gtk::PrintContext>&',`GtkPrintContext*',`Glib::unwrap($3)') 509 /** Paginate the document associated with the @a compositor. 510 * 511 * In order to support non-blocking pagination, document is paginated in small 512 * chunks. Each time paginate() is invoked, a chunk of the document is 513 * paginated. To paginate the entire document, paginate() must be invoked 514 * multiple times. It returns @c true if the document has been completely 515 * paginated, otherwise it returns @c false. 516 * 517 * This method has been designed to be invoked in the handler of the 518 * Gtk::PrintOperation::paginate signal, as shown in the following example: 519 * 520 * @code 521 * // Signal handler for the GtkPrintOperation::paginate signal. 522 * // Extended with sigc::bind(). 523 * 524 * static bool 525 * paginate (Glib::RefPtr<Gtk::PrintOperation> operation, 526 * Glib::RefPtr<Gtk::PrintContext> context, 527 * Glib::RefPtr<Gsv::PrintCompositor> compositor) 528 * { 529 * if (compositor->paginate(context)) 530 * { 531 * int n_pages = compositor->get_n_pages(); 532 * operation->set_n_pages(n_pages); 533 * 534 * return true; 535 * } 536 * 537 * return false; 538 * } 539 * @endcode 540 * 541 * If you don't need to do pagination in chunks, you can simply do it all in 542 * the Gtk::PrintOperation::begin-print handler, and set the number of pages 543 * from there, like in the following example: 544 * 545 * @code 546 * // Signal handler for the Gtk::PrintOperation::begin-print signal 547 * // Extended with sigc::bind(). 548 * 549 * static void 550 * begin_print (Glib::RefPtr< Gtk::PrintOperation > operation, 551 * Glib::RefPtr< Gtk::PrintContext > context, 552 * Glib::RefPtr< Gsv::PrintCompositor > compositor) 553 * { 554 * while (!compositor->paginate(context)); 555 * 556 * int n_pages = compositor->get_n_pages(); 557 * operation->set_n_pages(n_pages); 558 * } 559 * @endcode 560 * 561 * @param context The Gtk::PrintContext whose parameters (e.g. paper size, 562 * print margins, etc.) are used by the the compositor to paginate the 563 * document. 564 * 565 * @return @c true if the document has been completely paginated, @c false 566 * otherwise. 567 * 568 * @newin{2,10} 569 */ 570 _WRAP_METHOD(bool paginate(const Glib::RefPtr<Gtk::PrintContext>& context), gtk_source_print_compositor_paginate) 571 572 /** Return value: a fraction from 0.0 to 1.0 inclusive 573 * @return A fraction from 0.0 to 1.0 inclusive 574 * 575 * @newin{2,10} 576 */ 577 _WRAP_METHOD(double get_pagination_process(), gtk_source_print_compositor_get_pagination_progress) 578 579 /** Draw page @a page_nr for printing on the the Cairo context encapsuled in @a context. 580 * 581 * This method has been designed to be called in the handler of the Gtk::PrintOperation::draw_page signal 582 * as shown in the following example: 583 * 584 * @code 585 * // Signal handler for the Gtk::PrintOperation::draw_page signal. 586 * // Extended with sigc::bind(). 587 * 588 * static void 589 * draw_page (Glib::RefPtr< Gtk::PrintOperation > operation, 590 * Glib::RefPtr< GtkPrintContext > context, 591 * int page_nr, 592 * Glib::RefPtr< Gsv::PrintCompositor > compositor) 593 * { 594 * compositor->draw_page(context, page_nr); 595 * } 596 * @endcode 597 * 598 * @param context The Gtk::PrintContext encapsulating the context information 599 * that is required when drawing the page for printing. 600 * @param page_nr The number of the page to print. 601 * 602 * newin{2,10} 603 */ 604 _WRAP_METHOD(void draw_page(const Glib::RefPtr<Gtk::PrintContext>& context, int page_nr), gtk_source_print_compositor_draw_page) 605 606 607 _WRAP_PROPERTY("body-font-name", Glib::ustring) 608 _WRAP_PROPERTY("buffer", Glib::RefPtr<Buffer>) 609 _WRAP_PROPERTY("footer-font-name", Glib::ustring) 610 _WRAP_PROPERTY("header-font-name", Glib::ustring) 611 _WRAP_PROPERTY("highlight-syntax", bool) 612 _WRAP_PROPERTY("line-numbers-font-name", Glib::ustring) 613 _WRAP_PROPERTY("n-pages", int) 614 _WRAP_PROPERTY("print-footer", bool) 615 _WRAP_PROPERTY("print-header", bool) 616 _WRAP_PROPERTY("print-line-numbers", guint) 617 _WRAP_PROPERTY("tab-width", guint) 618 _WRAP_PROPERTY("wrap-mode", Gtk::WrapMode) 619}; 620 621} /* namespace Gsv */ 622 623