[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Beaver-devel] [beaver] pretty print patch
From: |
Higor Eurípedes |
Subject: |
Re: [Beaver-devel] [beaver] pretty print patch |
Date: |
Sun, 25 Jan 2009 17:51:31 +0000 |
Looks good :-)
Commit! :D
bye
2009/1/23 Tobias Heinzen <address@hidden>:
> i'm proud to announce a pretty print patch ^^
>
> Greets
> Tobias
>
> ### Eclipse Workspace Patch 1.0
> #P beaver0.4.0
> Index: src/interface.c
> ===================================================================
> RCS file: /sources/beaver/beaver0.4.0/src/interface.c,v
> retrieving revision 1.46
> diff -u -r1.46 interface.c
> --- src/interface.c 12 Jan 2009 16:28:06 -0000 1.46
> +++ src/interface.c 23 Jan 2009 11:07:34 -0000
> @@ -249,32 +249,81 @@
> /* get some contexes */
> cr = gtk_print_context_get_cairo_context (context);
> layout = gtk_print_context_create_pango_layout (context);
> -
> +
> + /* get width and height of the print plane */
> + gint width = gtk_print_context_get_width (context);
> + gint height = gtk_print_context_get_height (context);
> +
> + /* draw a rectangle all around the text */
> + cairo_set_line_width (cr, 0.7);
> + cairo_new_sub_path (cr);
> + cairo_rectangle (cr, 0, 0, width, height);
> + cairo_close_path (cr);
> + cairo_stroke (cr);
> +
> + /* draw a small rectangle on top of the page (header) */
> + cairo_new_sub_path (cr);
> + cairo_rectangle (cr, 0, 0, width, 17);
> + cairo_close_path (cr);
> + cairo_set_source_rgb (cr, 0.9, 0.9, 0.9);
> + cairo_fill_preserve (cr);
> + cairo_set_source_rgba (cr, 0, 0, 0, 1);
> + cairo_stroke (cr);
> +
> + /* draw the header. the header contains of the filename and the page
> + * number. the filename is truncated to the basename and is centered
> + * in the header. it also get's printed bold and with a different
> + * font face. */
> + cairo_text_extents_t extents;
> + cairo_select_font_face (cr, "Sans", CAIRO_FONT_SLANT_NORMAL,
> + CAIRO_FONT_WEIGHT_BOLD);
> + cairo_set_font_size (cr, 12.0);
> + cairo_text_extents (cr, doc->name, &extents);
> +
> + double x = (width/2)-(extents.width/2 + extents.x_bearing);
> +
> + cairo_move_to (cr, x, 12.0);
> + cairo_show_text (cr, doc->name);
> + cairo_stroke (cr);
> +
> + /* now draw the page number on the right handside */
> + gchar* page = g_strdup_printf ("Page %d/%d", page_nr+1, doc->n_pages);
> + cairo_select_font_face (cr, "Sans", CAIRO_FONT_SLANT_NORMAL,
> + CAIRO_FONT_WEIGHT_NORMAL);
> + cairo_set_font_size (cr, 12.0);
> + cairo_text_extents (cr, doc->name, &extents);
> +
> + x = width-extents.width-3.0;
> +
> + cairo_move_to (cr, x, 12.0);
> + cairo_show_text (cr, page);
> + cairo_stroke (cr);
> +
> + g_free (page);
> +
> /* count the number of characters until 75 lines are full. */
> - gint chars = 0; gint lines = 0;
> + gint chars = 0; gint lines = 0; gint length = 0;
> gchar* text = doc->content+doc->chars_printed;
> while (*text && lines < LINES_PER_PAGE) {
> if (*text == '\n') {
> + cairo_select_font_face (cr, "Courier New",
> CAIRO_FONT_SLANT_NORMAL,
> + CAIRO_FONT_WEIGHT_NORMAL);
> + cairo_set_font_size (cr, 12.0);
> + cairo_move_to (cr, 3.0, (lines+2)*15.0);
> + *text = '\0';
> + cairo_show_text (cr, text-length);
> + *text = '\n';
> + cairo_stroke (cr);
> +
> + length=-1;
> lines++;
> }
>
> + length++;
> text++;
> chars++;
> }
> -
> - /* create the header line and get the text to print */
> - gchar* header_line = g_strdup_printf ("page %d/%d of
> %s\n______________________"
> -
> "________________________________________________________________________\n\n",
> - page_nr+1, doc->n_pages, doc->name);
> - gchar* body = g_strconcat (header_line,
> doc->content+doc->chars_printed, NULL);
> -
> - /* set the text to print */
> - pango_layout_set_text (layout, body, chars+strlen((const
> char*)header_line));
> -
> - /* free unused space */
> - g_free (header_line);
> - g_free (body);
> -
> +
> /* increase the number of printed chars */
> doc->chars_printed += chars;
>
> @@ -284,6 +333,7 @@
>
> /* free up space */
> g_object_unref (layout);
> +
> }
>
> /**
> @@ -310,7 +360,7 @@
> GtkWidget* textview = FPROPS(current_page, Text);
> doc->textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
> doc->content = get_text(gtk_text_view_get_buffer
> (GTK_TEXT_VIEW(textview)));
> - doc->name = FPROPS(current_page, Name);
> + doc->name = FPROPS(current_page, BaseName);
>
> /* create new GTKPrintOperation */
> GtkPrintOperation *print;
>
> _______________________________________________
> Beaver-devel mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/beaver-devel
>
>
--
Higor Euripedes (enygmata)