rpms/paps/devel paps-0.6.3-formfeed.patch, NONE, 1.1 paps-0.6.3-goption.patch, NONE, 1.1 paps-0.6.3-header.patch, NONE, 1.1 paps.spec, 1.7, 1.8
Akira Tagoh (tagoh)
fedora-extras-commits at redhat.com
Fri Mar 31 05:21:07 UTC 2006
Author: tagoh
Update of /cvs/extras/rpms/paps/devel
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv16134
Modified Files:
paps.spec
Added Files:
paps-0.6.3-formfeed.patch paps-0.6.3-goption.patch
paps-0.6.3-header.patch
Log Message:
* Fri Mar 31 2006 Akira TAGOH <tagoh at redhat.com> - 0.6.3-4
- paps-0.6.3-formfeed.patch: applied to deal with the formfeed mark properly.
- paps-0.6.3-goption.patch: rewritten option parser using GOption. and segfault
gone as well. (#187205)
- paps-0.6.3-header.patch: applied to support the output of the page header.
paps-0.6.3-formfeed.patch:
--- NEW FILE paps-0.6.3-formfeed.patch ---
diff -ruN paps-0.6.3.orig/src/paps.c paps-0.6.3/src/paps.c
--- paps-0.6.3.orig/src/paps.c 2006-03-28 12:10:36.000000000 +0900
+++ paps-0.6.3/src/paps.c 2006-03-28 15:54:21.000000000 +0900
@@ -83,6 +83,7 @@
PangoLayoutLine *pango_line;
PangoRectangle logical_rect;
PangoRectangle ink_rect;
+ int formfeed;
} LineLink;
typedef struct _Paragraph Paragraph;
@@ -93,6 +94,7 @@
char *text;
int length;
int height; /* Height, in pixels */
+ int formfeed;
PangoLayout *layout;
};
@@ -431,7 +433,7 @@
fprintf (stderr, "%s: Invalid character in input\n", g_get_prgname ());
wc = 0;
}
- if (!*p || !wc || wc == '\n')
+ if (!*p || !wc || wc == '\n' || wc == '\f')
{
Paragraph *para = g_new (Paragraph, 1);
para->text = last_para;
@@ -445,6 +447,11 @@
pango_layout_set_width (para->layout, paint_width * PANGO_SCALE);
para->height = 0;
+ if (wc == '\f')
+ para->formfeed = 1;
+ else
+ para->formfeed = 0;
+
last_para = next;
result = g_list_prepend (result, para);
@@ -472,6 +479,7 @@
while(par_list)
{
int para_num_lines, i;
+ LineLink *line_link;
Paragraph *para = par_list->data;
para_num_lines = pango_layout_get_line_count(para->layout);
@@ -479,12 +487,15 @@
for (i=0; i<para_num_lines; i++)
{
PangoRectangle logical_rect, ink_rect;
- LineLink *line_link = g_new(LineLink, 1);
+ line_link = g_new(LineLink, 1);
+ line_link->formfeed = 0;
line_link->pango_line = pango_layout_get_line(para->layout, i);
pango_layout_line_get_extents(line_link->pango_line,
&ink_rect, &logical_rect);
line_link->logical_rect = logical_rect;
+ if (para->formfeed && i == (para_num_lines - 1))
+ line_link->formfeed = 1;
line_link->ink_rect = ink_rect;
line_list = g_list_prepend(line_list, line_link);
}
@@ -513,8 +524,8 @@
PangoLayoutLine *line = line_link->pango_line;
/* Check if we need to move to next column */
- if (column_y_pos + line_link->logical_rect.height
- >= pango_column_height)
+ if ((column_y_pos + line_link->logical_rect.height
+ >= pango_column_height) || line_link->formfeed)
{
column_idx++;
column_y_pos = 0;
paps-0.6.3-goption.patch:
--- NEW FILE paps-0.6.3-goption.patch ---
diff -ruN paps-0.6.3.orig/src/paps.c paps-0.6.3/src/paps.c
--- paps-0.6.3.orig/src/paps.c 2006-03-29 15:21:53.000000000 +0900
+++ paps-0.6.3/src/paps.c 2006-03-29 16:22:59.000000000 +0900
@@ -138,12 +138,58 @@
double last_pos_y = -1;
double last_pos_x = -1;
paps_t *paps;
+paper_type_t paper_type = PAPER_TYPE_A4;
#define CASE(s) if (strcmp(S_, s) == 0)
+static gboolean
+_paps_arg_paper_cb(const char *option_name,
+ const char *value,
+ gpointer data)
+{
+ gboolean retval = TRUE;
+
+ if (value && *value) {
+ if (g_ascii_strcasecmp(value, "legal") == 0)
+ paper_type = PAPER_TYPE_US_LEGAL;
+ else if (g_ascii_strcasecmp(value, "letter") == 0)
+ paper_type = PAPER_TYPE_US_LETTER;
+ else if (g_ascii_strcasecmp(value, "a4") == 0)
+ paper_type = PAPER_TYPE_A4;
+ else {
+ retval = FALSE;
+ fprintf(stderr, "Unknown page size %s.\n", value);
+ }
+ } else {
+ fprintf(stderr, "You must specify page size.\n");
+ retval = FALSE;
+ }
+
+ return retval;
+}
+
int main(int argc, char *argv[])
{
- int argp=1;
+ gboolean do_landscape = FALSE, do_rtl = FALSE, do_justify = FALSE;
+ int num_columns = 1, font_scale = 12;
+ int top_margin = 36, bottom_margin = 36, right_margin = 36, left_margin = 36;
+ char *font_family = "Monospace";
+ GOptionContext *ctxt = g_option_context_new("[text file]");
+ GOptionEntry entries[] = {
+ {"landscape", 0, 0, G_OPTION_ARG_NONE, &do_landscape, "Landscape output. (Default: portrait)", NULL},
+ {"columns", 0, 0, G_OPTION_ARG_INT, &num_columns, "Number of columns output. (Default: 1)", "NUM"},
+ {"font_scale", 0, 0, G_OPTION_ARG_INT, &font_scale, "Font scaling. (Default: 12)", "NUM"},
+ {"family", 0, 0, G_OPTION_ARG_STRING, &font_family, "Pango FT2 font family. (Default: Monospace)", "FAMILY"},
+ {"rtl", 0, 0, G_OPTION_ARG_NONE, &do_rtl, "Do rtl layout.", NULL},
+ {"justify", 0, 0, G_OPTION_ARG_NONE, &do_justify, "Do justify the lines.", NULL},
+ {"paper", 0, 0, G_OPTION_ARG_CALLBACK, _paps_arg_paper_cb, "Choose paper size. Known paper sizes are legal, letter, a4. (Default: a4)", "PAPER"},
+ {"bottom-margin", 0, 0, G_OPTION_ARG_INT, &bottom_margin, "Set bottom margin. (Default: 36)", "NUM"},
+ {"top-margin", 0, 0, G_OPTION_ARG_INT, &top_margin, "Set top margin. (Default: 36)", "NUM"},
+ {"right-margin", 0, 0, G_OPTION_ARG_INT, &right_margin, "Set right margin. (Default: 36)", "NUM"},
+ {"left-margin", 0, 0, G_OPTION_ARG_INT, &left_margin, "Set left margin. (Default: 36)", "NUM"},
+ {NULL}
+ };
+ GError *error = NULL;
char *filename_in;
char *title;
FILE *IN, *OUT = NULL;
@@ -154,108 +200,32 @@
PangoContext *pango_context;
PangoFontDescription *font_description;
PangoDirection pango_dir = PANGO_DIRECTION_LTR;
- char *font_family = "Monospace";
- int font_scale = 12;
int num_pages = 1;
- int num_columns = 1;
int gutter_width = 40;
int total_gutter_width;
- paper_type_t paper_type = PAPER_TYPE_A4;
int page_width = paper_sizes[0].width;
int page_height = paper_sizes[0].height;
- gboolean do_landscape = FALSE;
int do_tumble = -1; /* -1 means not initialized */
int do_duplex = -1;
gboolean do_draw_header = FALSE;
- gboolean do_justify = FALSE;
gchar *paps_header = NULL;
- int top_margin = 36;
- int bottom_margin = 36;
- int left_margin = 36;
- int right_margin = 36;
/* Prerequisite when using glib. */
g_type_init();
+ g_option_context_add_main_entries(ctxt, entries, NULL);
/* Parse command line */
- while(argp < argc && argv[argp][0] == '-')
+ if (!g_option_context_parse(ctxt, &argc, &argv, &error))
{
- char *S_ = argv[argp++];
- CASE("--help")
- {
- printf("paps - A postscript generating program using pango.\n"
- "\n"
- "Syntax:\n"
- " paps [--landscape] [--columns cl] [--font_scale fs]\n"
- " [--family f] [--rtl] [--paper type]\n"
- " [--bottom-margin bm] [--top-margin tm] [--left-margin lm]\n"
- " [--right-margin rm]\n"
- "\n"
- "Description:\n"
- " paps reads a UTF-8 encoded file and generates a PostScript\n"
- " rendering of the file. The rendering is done by creating\n"
- " outline curves through the pango FT2 backend.\n"
- "\n"
- "Options:\n"
- " --landscape Landscape output. Default is portrait.\n"
- " --columns cl Number of columns output. Default is 1.\n"
- " --font_scale fs Font scaling. Default is 12.\n"
- " --family f Pango ft2 font family. Default is sans.\n"
- " --rtl Do rtl layout.\n"
- " --paper ps Choose paper size. Known paper sizes are legal, letter, a4.\n"
- " Default is A4.\n"
- " --bottom-margin bm Set bottom margin. Default is 36."
- " --top-margin tm Set top margin. Default is 36."
- " --left-margin lm Set left margin. Default is 36."
- " --right-margin rm Set right margin. Default is 36."
-
- );
-
- exit(0);
- }
- CASE("--landscape") { do_landscape = TRUE; continue; }
- CASE("--columns") { num_columns = atoi(argv[argp++]); continue; }
- CASE("--font_scale") { font_scale = atoi(argv[argp++]); continue; }
- CASE("--family") { font_family = argv[argp++]; continue; }
- CASE("--rtl") { pango_dir = PANGO_DIRECTION_RTL; continue; }
- CASE("--justify") { do_justify = TRUE; continue; }
- CASE("--paper")
- {
- char *S_ = argv[argp++];
- while(1) /* So that I can break */
- {
- CASE("legal") { paper_type=PAPER_TYPE_US_LEGAL; break; }
- CASE("letter") { paper_type=PAPER_TYPE_US_LETTER; break; }
- CASE("a4") { paper_type=PAPER_TYPE_A4; break; }
-
- fprintf(stderr, "Unknown page size %s!\n", S_);
- exit(1);
- }
- continue;
- }
- CASE("--bottom-margin")
- {
- bottom_margin = atoi(argv[argp++]); continue;
- }
- CASE("--top-margin")
- {
- top_margin = atoi(argv[argp++]); continue;
- }
- CASE("--right-margin")
- {
- right_margin = atoi(argv[argp++]); continue;
- }
- CASE("--left-margin")
- {
- left_margin = atoi(argv[argp++]); continue;
- }
- fprintf(stderr, "Unknown option %s!\n", S_);
+ fprintf(stderr, "Failed to parse the given options. maybe unknown options or missing extra argument.\n");
exit(1);
}
+ if (do_rtl)
+ pango_dir = PANGO_DIRECTION_RTL;
- if (argp < argc)
+ if (argc > 1)
{
- filename_in = argv[argp++];
+ filename_in = argv[1];
IN = fopen(filename_in, "rb");
if (!IN)
{
@@ -368,6 +338,7 @@
// Cleanup
g_string_free(ps_pages_string, TRUE);
+ g_option_context_free(ctxt);
return 0;
}
paps-0.6.3-header.patch:
--- NEW FILE paps-0.6.3-header.patch ---
diff -ruN -x Makefile -x autom4te.cache -x 'config*' -x doc -x libtool -x '*o' -x '*~' -x 'stamp*' -x 'test*' -x paps -x '*a' paps-0.6.3.orig/src/paps.c paps-0.6.3/src/paps.c
--- paps-0.6.3.orig/src/paps.c 2006-03-29 17:26:44.000000000 +0900
+++ paps-0.6.3/src/paps.c 2006-03-30 22:42:36.000000000 +0900
@@ -63,6 +63,8 @@
int page_height;
int header_ypos;
int header_sep;
+ int header_height;
+ int footer_height;
gboolean do_draw_header;
gboolean do_draw_footer;
gboolean do_duplex;
@@ -72,6 +74,7 @@
gboolean do_separation_line;
gboolean do_draw_contour;
PangoDirection pango_dir;
+ gchar *filename;
} page_layout_t;
typedef struct {
@@ -99,32 +102,39 @@
};
/* Information passed in user data when drawing outlines */
-GList *split_paragraphs_into_lines(GList *paragraphs);
-static char *read_file (FILE *file);
-static GList *
-split_text_into_paragraphs (PangoContext *pango_context,
- page_layout_t *page_layout,
- int paint_width,
- char *text);
+GList *split_paragraphs_into_lines (GList *paragraphs);
+static char *read_file (FILE *file);
+static GList *split_text_into_paragraphs (PangoContext *pango_context,
+ page_layout_t *page_layout,
+ int paint_width,
+ char *text);
+static int output_pages (FILE *OUT,
+ GList *pango_lines,
+ page_layout_t *page_layout,
+ gboolean need_header,
+ PangoContext *pango_context);
+static void print_postscript_header (FILE *OUT,
+ const char *title,
+ page_layout_t *page_layout);
+static void print_postscript_trailer (FILE *OUT,
+ int num_pages);
+static void eject_column (FILE *OUT,
+ page_layout_t *page_layout,
+ int column_idx);
+static void eject_page (FILE *OUT);
+static void start_page (FILE *OUT,
+ int page_idx);
+static void draw_line_to_page (FILE *OUT,
+ int column_idx,
+ int column_pos,
+ page_layout_t *page_layout,
+ PangoLayoutLine *line);
+static int draw_page_header_line_to_page(FILE *OUT,
+ gboolean is_footer,
+ page_layout_t *page_layout,
+ PangoContext *ctx,
+ int page);
-int output_pages(FILE *OUT,
- GList *pango_lines,
- page_layout_t *page_layout);
-void print_postscript_header(FILE *OUT,
- const char *title,
- page_layout_t *page_layout);
-void print_postscript_trailer(FILE *OUT, int num_pages);
-void print_svg_trailer(FILE *OUT, int num_pages);
-void eject_column(FILE *OUT,
- page_layout_t *page_layout,
- int column_idx);
-void eject_page(FILE *OUT);
-void start_page(FILE *OUT, int page_idx);
-void draw_line_to_page(FILE *OUT,
- int column_idx,
- int column_pos,
- page_layout_t *page_layout,
- PangoLayoutLine *line);
// Fonts are three character symbols in an alphabet composing of
// the following characters:
//
@@ -170,7 +180,7 @@
int main(int argc, char *argv[])
{
- gboolean do_landscape = FALSE, do_rtl = FALSE, do_justify;
+ gboolean do_landscape = FALSE, do_rtl = FALSE, do_justify = FALSE, do_draw_header = FALSE;
int num_columns = 1, font_scale = 12;
int top_margin = 36, bottom_margin = 36, right_margin = 36, left_margin = 36;
char *font_family = "Monospace";
@@ -187,6 +197,7 @@
{"top-margin", 0, 0, G_OPTION_ARG_INT, &top_margin, "Set top margin. (Default: 36)", "NUM"},
{"right-margin", 0, 0, G_OPTION_ARG_INT, &right_margin, "Set right margin. (Default: 36)", "NUM"},
{"left-margin", 0, 0, G_OPTION_ARG_INT, &left_margin, "Set left margin. (Default: 36)", "NUM"},
+ {"header", 0, 0, G_OPTION_ARG_NONE, &do_draw_header, "Draw page header for each page.", NULL},
{NULL}
};
GError *error = NULL;
@@ -207,7 +218,6 @@
int page_height = paper_sizes[0].height;
int do_tumble = -1; /* -1 means not initialized */
int do_duplex = -1;
- gboolean do_draw_header = FALSE;
gchar *paps_header = NULL;
/* Prerequisite when using glib. */
@@ -292,6 +302,8 @@
page_layout.top_margin = top_margin;
page_layout.bottom_margin = bottom_margin;
page_layout.header_ypos = page_layout.top_margin;
+ page_layout.header_height = 0;
+ page_layout.footer_height = 0;
if (do_draw_header)
page_layout.header_sep = font_scale * 2.5;
else
@@ -312,6 +324,7 @@
page_layout.do_tumble = do_tumble;
page_layout.do_duplex = do_duplex;
page_layout.pango_dir = pango_dir;
+ page_layout.filename = filename_in;
text = read_file(IN);
paragraphs = split_text_into_paragraphs(pango_context,
@@ -326,7 +339,7 @@
print_postscript_header(OUT, title, &page_layout);
ps_pages_string = g_string_new("");
- num_pages = output_pages(OUT, pango_lines, &page_layout);
+ num_pages = output_pages(OUT, pango_lines, &page_layout, do_draw_header, pango_context);
paps_header = paps_get_postscript_header_strdup(paps);
fprintf(OUT, "%s", paps_header);
@@ -478,9 +491,12 @@
}
-int output_pages(FILE *OUT,
- GList *pango_lines,
- page_layout_t *page_layout)
+int
+output_pages(FILE *OUT,
+ GList *pango_lines,
+ page_layout_t *page_layout,
+ gboolean need_header,
+ PangoContext *pango_context)
{
int column_idx = 0;
int column_y_pos = 0;
@@ -489,6 +505,9 @@
start_page(OUT, page_idx);
+ if (need_header)
+ column_y_pos += draw_page_header_line_to_page(OUT, FALSE, page_layout, pango_context, page_idx);
+
while(pango_lines)
{
LineLink *line_link = pango_lines->data;
@@ -506,12 +525,17 @@
eject_page(OUT);
page_idx++;
start_page(OUT, page_idx);
+
+ if (need_header)
+ column_y_pos += draw_page_header_line_to_page(OUT, FALSE, page_layout, pango_context, page_idx);
}
else
- eject_column(OUT,
- page_layout,
- column_idx
- );
+ {
+ eject_column(OUT,
+ page_layout,
+ column_idx
+ );
+ }
}
draw_line_to_page(OUT,
column_idx,
@@ -706,8 +730,8 @@
+ page_layout->column_width * column_idx
+ total_gutter;
- y_top = page_layout->page_height - page_layout->top_margin;
- y_bot = page_layout->bottom_margin;
+ y_top = page_layout->page_height - page_layout->top_margin - page_layout->header_height - page_layout->header_sep / 2;
+ y_bot = page_layout->bottom_margin - page_layout->footer_height;
g_string_append_printf(ps_pages_string,
"%f %f moveto %f %f lineto 0 setlinewidth stroke\n",
@@ -778,3 +802,89 @@
g_free(ps_layout);
}
+int
+draw_page_header_line_to_page(FILE *OUT,
+ gboolean is_footer,
+ page_layout_t *page_layout,
+ PangoContext *ctx,
+ int page)
+{
+ PangoLayout *layout = pango_layout_new(ctx);
+ PangoLayoutLine *line;
+ PangoRectangle ink_rect, logical_rect;
+ /* Assume square aspect ratio for now */
+ double x_pos, y_pos;
+ gchar *ps_layout, *header, date[256];
+ time_t t;
+ struct tm tm;
+ int height;
+ gdouble line_pos;
+
+ t = time(NULL);
+ tm = *localtime(&t);
+ strftime(date, 255, "%c", &tm);
+ header = g_strdup_printf("<span weight=\"bold\">%s</span>\n<span weight=\"bold\">%s</span>\n<span weight=\"bold\">Page %d</span>", date, page_layout->filename, page);
+ pango_layout_set_markup(layout, header, -1);
+ g_free(header);
+
+ /* output a left edge of header/footer */
+ line = pango_layout_get_line(layout, 0);
+ pango_layout_line_get_extents(line,
+ &ink_rect,
+ &logical_rect);
+ x_pos = page_layout->left_margin;
+ height = logical_rect.height / PANGO_SCALE * page_layout->pixel_to_pt;
+ if (is_footer)
+ {
+ y_pos = page_layout->top_margin + height;
+ page_layout->footer_height = height;
+ }
+ else
+ {
+ y_pos = page_layout->page_height - page_layout->bottom_margin - height;
+ page_layout->header_height = height;
+ }
+ ps_layout = paps_layout_line_to_postscript_strdup(paps,
+ x_pos, y_pos,
+ line);
+ g_string_append(ps_pages_string,
+ ps_layout);
+ g_free(ps_layout);
+
+ /* 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 - (logical_rect.width / PANGO_SCALE * page_layout->pixel_to_pt)) / 2;
+ ps_layout = paps_layout_line_to_postscript_strdup(paps,
+ x_pos, y_pos,
+ line);
+ g_string_append(ps_pages_string,
+ ps_layout);
+ g_free(ps_layout);
+
+ /* output a right edge of header/footer */
+ line = pango_layout_get_line(layout, 2);
+ pango_layout_line_get_extents(line,
+ &ink_rect,
+ &logical_rect);
+ x_pos = page_layout->page_width - page_layout->right_margin - (logical_rect.width / PANGO_SCALE * page_layout->pixel_to_pt);
+ ps_layout = paps_layout_line_to_postscript_strdup(paps,
+ x_pos, y_pos,
+ line);
+ g_string_append(ps_pages_string,
+ ps_layout);
+ g_free(ps_layout);
+
+ g_object_unref(layout);
+
+ /* header separator */
+ line_pos = page_layout->page_height - page_layout->top_margin - page_layout->header_height - page_layout->header_sep / 2;
+ g_string_append_printf(ps_pages_string,
+ "%d %f moveto %d %f lineto 0 setlinewidth stroke\n",
+ page_layout->left_margin, line_pos,
+ page_layout->page_width - page_layout->right_margin, line_pos);
+
+ return logical_rect.height;
+}
Index: paps.spec
===================================================================
RCS file: /cvs/extras/rpms/paps/devel/paps.spec,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- paps.spec 24 Mar 2006 09:35:23 -0000 1.7
+++ paps.spec 31 Mar 2006 05:21:07 -0000 1.8
@@ -1,6 +1,6 @@
Name: paps
Version: 0.6.3
-Release: 3%{?dist}
+Release: 4%{?dist}
License: LGPL
URL: http://paps.sourceforge.net/
@@ -9,6 +9,9 @@
BuildRequires: pango-devel
Patch0: paps-0.6.1-makefile.patch
Patch1: paps-0.6.3-fix-pagesize.patch
+Patch2: paps-0.6.3-formfeed.patch
+Patch3: paps-0.6.3-goption.patch
+Patch4: paps-0.6.3-header.patch
Summary: Plain Text to PostScript converter
Group: Applications/Publishing
@@ -20,6 +23,9 @@
%setup -q
%patch0 -p1 -b .makefile
%patch1 -p1 -b .pagesize
+%patch2 -p1 -b .formfeed
+%patch3 -p1 -b .goption
+%patch4 -p1 -b .header
aclocal
automake
autoconf
@@ -46,6 +52,12 @@
%changelog
+* Fri Mar 31 2006 Akira TAGOH <tagoh at redhat.com> - 0.6.3-4
+- paps-0.6.3-formfeed.patch: applied to deal with the formfeed mark properly.
+- paps-0.6.3-goption.patch: rewritten option parser using GOption. and segfault
+ gone as well. (#187205)
+- paps-0.6.3-header.patch: applied to support the output of the page header.
+
* Fri Mar 24 2006 Akira TAGOH <tagoh at redhat.com> - 0.6.3-3
- paps-0.6.3-fix-pagesize.patch: fixed displaying the beginning of line at out of page. (#176207)
More information about the fedora-extras-commits
mailing list