Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Backports:SLE-15:Update
paps
paps-layout.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File paps-layout.patch of Package paps
Try to get page layout to something useful --- src/paps.1 | 6 ++ src/paps.c | 162 +++++++++++++++++++++++++++++++++++++++++-------------------- 2 files changed, 116 insertions(+), 52 deletions(-) --- src/paps.1 +++ src/paps.1 2017-12-06 12:02:16.293502145 +0000 @@ -272,6 +272,12 @@ Set gutter width. Default is 40 postscri .TP .B \-\-header Draw page header with document name, date and page number for each page. Header +is not printed by default. Page numbers are only done without +.B \-\-footer +option. +.TP +.B \-\-footer +Draw page footer page number for each page. Footer is not printed by default. .TP .B \-\-title="text" --- src/paps.c +++ src/paps.c 2017-12-06 12:02:16.297502070 +0000 @@ -169,7 +169,6 @@ static int output_pages cairo_t *cr, GList *pango_lines, page_layout_t *page_layout, - gboolean need_header, PangoContext *pango_context); static void eject_column (cairo_t *cr, page_layout_t *page_layout, @@ -185,7 +184,10 @@ static void draw_line_to_page PangoLayoutLine *line, gboolean draw_wrap_character); static int draw_page_header_line_to_page(cairo_t *cr, - gboolean is_footer, + page_layout_t *page_layout, + PangoContext *ctx, + int page); +static int draw_page_footer_line_to_page(cairo_t *cr, page_layout_t *page_layout, PangoContext *ctx, int page); @@ -699,6 +701,8 @@ int main(int argc, char *argv[]) do_duplex = TRUE; } + page_layout.do_draw_header = do_draw_header; + page_layout.do_draw_footer = do_draw_footer; page_layout.page_width = page_width; page_layout.page_height = page_height; page_layout.paper_type = paper_type; @@ -715,9 +719,9 @@ int main(int argc, char *argv[]) page_layout.scale_x = 1.0L; page_layout.scale_y = 1.0L; if (do_draw_header) - page_layout.header_sep = 0; // header_sep; + page_layout.header_sep = header_sep; else - page_layout.header_sep = 0; + page_layout.header_sep = 0; page_layout.column_height = (int)page_height - page_layout.top_margin @@ -782,7 +786,7 @@ int main(int argc, char *argv[]) cairo_scale(cr, page_layout.scale_x, page_layout.scale_y); - output_pages(surface, cr, pango_lines, &page_layout, do_draw_header, pango_context); + output_pages(surface, cr, pango_lines, &page_layout, pango_context); cairo_destroy (cr); cairo_surface_finish (surface); @@ -1184,7 +1188,6 @@ output_pages(cairo_surface_t *surface, cairo_t *cr, GList *pango_lines, page_layout_t *page_layout, - gboolean need_header, PangoContext *pango_context) { int column_idx = 0; @@ -1196,8 +1199,10 @@ output_pages(cairo_surface_t *surface, start_page(surface, cr, page_layout); - if (need_header) - draw_page_header_line_to_page(cr, TRUE, page_layout, pango_context, page_idx); + if (page_layout->do_draw_header) + draw_page_header_line_to_page(cr, page_layout, pango_context, page_idx); + if (page_layout->do_draw_footer) + draw_page_footer_line_to_page(cr, page_layout, pango_context, page_idx); while(pango_lines) { @@ -1219,8 +1224,10 @@ output_pages(cairo_surface_t *surface, page_idx++; start_page(surface, cr, page_layout); - if (need_header) - draw_page_header_line_to_page(cr, TRUE, page_layout, pango_context, page_idx); + if (page_layout->do_draw_header) + draw_page_header_line_to_page(cr, page_layout, pango_context, page_idx); + if (page_layout->do_draw_footer) + draw_page_footer_line_to_page(cr, page_layout, pango_context, page_idx); } else { @@ -1438,7 +1445,6 @@ get_date(char *date, int maxlen) int draw_page_header_line_to_page(cairo_t *cr, - gboolean is_footer, page_layout_t *page_layout, PangoContext *ctx, int page) @@ -1449,24 +1455,29 @@ draw_page_header_line_to_page(cairo_t /* Assume square aspect ratio for now */ double x_pos, y_pos; gchar *header, date[256]; - int height; + int height, title_len; gdouble line_pos; /* Reset gravity?? */ -#if 0 - header = g_strdup_printf("<span font_desc=\"%s\">%s</span>\n" - "<span font_desc=\"%s\">%s</span>\n" - "<span font_desc=\"%s\">%d</span>", - page_layout->header_font_desc, - page_layout->title, - page_layout->header_font_desc, - get_date(date, 255), - page_layout->header_font_desc, - page); -#endif - header = g_strdup_printf("<span font_desc=\"%s\">%d</span>\n", - page_layout->header_font_desc, - page); + if (page_layout->do_draw_footer) + header = g_strdup_printf("<span font_desc=\"%s\">%s</span>\n" + "<span font_desc=\"%s\">%s</span>\n", + page_layout->header_font_desc, + page_layout->title, + page_layout->header_font_desc, + get_date(date, 255)); + else + header = g_strdup_printf("<span font_desc=\"%s\">%s</span>\n" + "<span font_desc=\"%s\">%s</span>\n" + "<span font_desc=\"%s\">%d</span>", + page_layout->header_font_desc, + page_layout->title, + page_layout->header_font_desc, + get_date(date, 255), + page_layout->header_font_desc, + page); + + title_len = strlen(page_layout->title); pango_layout_set_markup(layout, header, -1); g_free(header); @@ -1476,54 +1487,101 @@ draw_page_header_line_to_page(cairo_t pango_layout_line_get_extents(line, &ink_rect, &logical_rect); - x_pos = page_layout->left_margin + (page_layout->page_width-page_layout->left_margin-page_layout->right_margin)*0.5 - 0.5*logical_rect.width/PANGO_SCALE; + x_pos = page_layout->left_margin; + x_pos += 0.5*(page_layout->page_width - page_layout->left_margin-page_layout->right_margin); + x_pos -= 0.7*(logical_rect.width / PANGO_SCALE); height = logical_rect.height / PANGO_SCALE /3.0; /* The header is placed right after the margin */ - if (is_footer) - { - y_pos = page_layout->page_height - page_layout->bottom_margin*0.5; - page_layout->footer_height = height; - } - else - { - y_pos = page_layout->top_margin + height; - page_layout->header_height = height; - } + y_pos = page_layout->top_margin + height; + page_layout->header_height = height; cairo_move_to(cr, x_pos,y_pos); pango_cairo_show_layout_line(cr,line); - /* output a right edge of header/footer */ - line = pango_layout_get_line(layout, 2); - pango_layout_line_get_extents(line, - &ink_rect, - &logical_rect); - pagenum_rect = logical_rect; - x_pos = page_layout->page_width - page_layout->right_margin - (logical_rect.width / PANGO_SCALE ); - cairo_move_to(cr, x_pos,y_pos); - pango_cairo_show_layout_line(cr,line); + if (!page_layout->do_draw_footer) + { + line = pango_layout_get_line(layout, 1); + pango_layout_line_get_extents(line, + &ink_rect, + &logical_rect); + x_pos = page_layout->page_width; + x_pos -= page_layout->right_margin; + x_pos -= (logical_rect.width + pagenum_rect.width) / PANGO_SCALE; + x_pos -= page_layout->gutter_width; + cairo_move_to(cr, x_pos,y_pos); + pango_cairo_show_layout_line(cr,line); + } + + /* output a right edge of header */ + if (!page_layout->do_draw_footer) + line = pango_layout_get_line(layout, 2); + else + line = pango_layout_get_line(layout, 1); - /* output a "center" of header/footer */ - line = pango_layout_get_line(layout, 1); pango_layout_line_get_extents(line, &ink_rect, &logical_rect); - x_pos = page_layout->page_width - page_layout->right_margin - - ((logical_rect.width + pagenum_rect.width) / PANGO_SCALE + page_layout->gutter_width); + pagenum_rect = logical_rect; + x_pos = page_layout->page_width; + x_pos -= page_layout->right_margin; + x_pos -= logical_rect.width / PANGO_SCALE; cairo_move_to(cr, x_pos,y_pos); pango_cairo_show_layout_line(cr,line); g_object_unref(layout); /* header separator */ -#if 0 line_pos = page_layout->top_margin + page_layout->header_height + page_layout->header_sep / 2; cairo_move_to(cr, page_layout->left_margin, line_pos); cairo_line_to(cr,page_layout->page_width - page_layout->right_margin, line_pos); cairo_set_line_width(cr,0.1); // TBD cairo_stroke(cr); -#endif + + return logical_rect.height; +} + +int +draw_page_footer_line_to_page(cairo_t *cr, + page_layout_t *page_layout, + PangoContext *ctx, + int page) +{ + PangoLayout *layout = pango_layout_new(ctx); + PangoLayoutLine *line; + PangoRectangle ink_rect, logical_rect, pagenum_rect; + /* Assume square aspect ratio for now */ + double x_pos, y_pos; + gchar *footer; + int height; + gdouble line_pos; + + /* Reset gravity?? */ + footer = g_strdup_printf("<span font_desc=\"%s\">%d</span>\n", + page_layout->header_font_desc, + page); + + pango_layout_set_markup(layout, footer, -1); + g_free(footer); + + /* output footer */ + line = pango_layout_get_line(layout, 0); + pango_layout_line_get_extents(line, + &ink_rect, + &logical_rect); + + x_pos = page_layout->left_margin; + x_pos += 0.5*(page_layout->page_width - page_layout->left_margin-page_layout->right_margin); + x_pos -= 0.5*(logical_rect.width / PANGO_SCALE); + height = logical_rect.height / PANGO_SCALE /3.0; + + y_pos = page_layout->page_height - page_layout->bottom_margin*0.5; + page_layout->footer_height = height; + + cairo_move_to(cr, x_pos,y_pos); + pango_cairo_show_layout_line(cr,line); + + g_object_unref(layout); return logical_rect.height; }
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor