25 #include <glibmm/i18n.h> 61 Pango::FontDescription header_font(
"sans 16");
63 retval->set_font_description(header_font);
64 retval->set_markup(Glib::ustring::compose(
"<b>%1</b>",
m_page_title));
65 retval->set_alignment(Pango::ALIGN_CENTER);
66 retval->set_width(static_cast<int>(context->get_width() * Pango::SCALE));
77 Pango::FontDescription font_desc(
"sans 12");
79 retval->set_font_description(font_desc);
81 retval->set_text(footer);
82 retval->set_alignment(Pango::ALIGN_CENTER);
83 retval->set_width(static_cast<int>(context->get_width() * Pango::SCALE));
94 Pango::FontDescription font_desc(
"sans 12");
98 const double width = context->get_width();
99 double height = context->get_height();
100 m_ref_layout->set_width(static_cast<int>(width * Pango::SCALE));
105 ref_header->get_size(w, h);
106 height -=
static_cast<int>(h / Pango::SCALE);
107 ref_footer->get_size(w, h);
108 height -=
static_cast<int>(h / Pango::SCALE);
113 Glib::ustring page_text;
121 Glib::RefPtr<Pango::LayoutLine> layout_line;
122 double page_height = 0;
123 for (
int line = 0; line < line_count; ++line) {
124 Pango::Rectangle ink_rect, logical_rect;
126 layout_line->get_extents(ink_rect, logical_rect);
127 const double line_height = logical_rect.get_height() / Pango::SCALE;
129 if (page_height + line_height > height) {
137 page_height += line_height;
141 set_n_pages(n_pages);
144 for (
int page_number = 0; page_number < n_pages; page_number++) {
146 Glib::ustring footer = Glib::ustring::compose(
FOOTER_TEXT,
160 int start_page_line = 0;
161 int end_page_line = 0;
163 if (page_number == 0) {
176 Cairo::RefPtr<Cairo::Context> cairo_ctx = context->get_cairo_context();
177 cairo_ctx->set_source_rgb(0, 0, 0);
179 Pango::LayoutIter iter;
180 double start_pos = 0;
182 double header_height = 0;
186 ref_header->get_iter(iter);
188 Glib::RefPtr<Pango::LayoutLine> header_line = iter.get_line();
189 Pango::Rectangle hr = iter.get_line_logical_extents();
190 int bl = iter.get_baseline();
191 double hx = hr.get_x() / Pango::SCALE;
192 double hy = bl / Pango::SCALE;
194 cairo_ctx->move_to(hx, hy);
195 header_line->show_in_cairo_context(cairo_ctx);
196 }
while (iter.next_line());
199 cairo_ctx->set_line_width(0.5);
200 cairo_ctx->set_line_cap(Cairo::LINE_CAP_SQUARE);
201 cairo_ctx->set_line_join(Cairo::LINE_JOIN_MITER);
203 cairo_ctx->move_to(0.0, header_height);
204 cairo_ctx->line_to(context->get_width(), header_height);
211 if (line_index >= start_page_line) {
212 Glib::RefPtr<Pango::LayoutLine> layout_line = iter.get_line();
213 Pango::Rectangle logical_rect = iter.get_line_logical_extents();
214 int baseline = iter.get_baseline();
215 if (line_index == start_page_line) {
216 start_pos = logical_rect.get_y() / Pango::SCALE;
218 double x = logical_rect.get_x() / Pango::SCALE;
219 double y = baseline / Pango::SCALE - start_pos + header_height;
220 cairo_ctx->move_to(x, y);
221 layout_line->show_in_cairo_context(cairo_ctx);
224 }
while (line_index < end_page_line && iter.next_line());
230 ref_footer->get_size(w, h);
231 start_pos = context->get_height() - h / Pango::SCALE -
BORDER_SPACING;
234 cairo_ctx->set_source_rgb(0, 0, 0);
235 cairo_ctx->set_line_width(0.5);
236 cairo_ctx->set_line_cap(Cairo::LINE_CAP_SQUARE);
237 cairo_ctx->set_line_join(Cairo::LINE_JOIN_MITER);
238 cairo_ctx->move_to(0.0, start_pos);
239 cairo_ctx->line_to(context->get_width(), start_pos);
243 ref_footer->get_iter(iter);
245 Glib::RefPtr<Pango::LayoutLine> footer_line = iter.get_line();
246 Pango::Rectangle fr = iter.get_line_logical_extents();
247 int bl = iter.get_baseline();
248 double fx = fr.get_x() / Pango::SCALE;
249 double fy = bl / Pango::SCALE + start_pos;
250 cairo_ctx->move_to(fx, fy);
251 footer_line->show_in_cairo_context(cairo_ctx);
252 }
while (iter.next_line());
virtual void on_begin_print(const Glib::RefPtr< Gtk::PrintContext > &context)
ItemContainer::iterator ItemIter
layout_refptr new_header(const Glib::RefPtr< Gtk::PrintContext > &context)
std::vector< int > m_page_breaks
A list of line numbers where a page break is required.
std::vector< layout_refptr > m_ref_footers
A list of footers, one for each page.
const int FOOTER_SPACING
The spacing between the footer and the body.
layout_refptr new_footer(const Glib::RefPtr< Gtk::PrintContext > &context)
std::vector< layout_refptr > m_ref_headers
A list of headers, one for each page.
const int PAGE_TOLERANCE
Seems calculating page body height is inaccurate.
virtual void on_draw_page(const Glib::RefPtr< Gtk::PrintContext > &context, int page_number)
std::string get_description()
static Glib::RefPtr< KitPrintOperation > create()
Factory to create instances.
Glib::RefPtr< Pango::Layout > layout_refptr
const Glib::ustring FOOTER_TEXT
Text used to print page number in footer - Page x of n.
layout_refptr m_ref_layout
A layout to hold the body of the entire kitlist to be printed.
const int BORDER_SPACING
The space above and below the horizontal lines at the top and bottom of each page.
Glib::ustring m_page_title
const int HEADER_SPACING
The spacing between the header and the body.
~KitPrintOperation()
Destructor.