[Gnome-print] gnome-print-fax
- From: Roberto Majadas <phoenix nova es>
- To: gnome-print helixcode com
- Subject: [Gnome-print] gnome-print-fax
- Date: Thu, 15 Feb 2001 04:02:40 +0100
Hello gnome-print hackers :
I've was working in a driver for gnome-print . This driver is gnome-print-fax
.. The funtion of gnome-print-fax is ... all gnome-print can print by printer
, can send by fax-modem .
This driver take a rgb-buffer a give a g3 file . The output.g3 file can be
visualited with gimp and viewfax without problems . And i think there aren't
any problem with mgetty+sendfax because this programs use g3 format .
It've only a developed-problem . This problem is that only acept dpi<=209
because if this number is bigger than 209 , the page weigth is bigger than
1728 , and with g3-format the weigth number must be 1728 (A4 paper) .
If you want to see the driver running , there is a testfax . You must write
output.g3 and not output.ps :o)
I hope you like it . And if someone have any comments .. mail me ,ok?
regards
Roberto Majadas
? tests/testfax
? tests/output.g3
Index: libgnomeprint/ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-print/libgnomeprint/ChangeLog,v
retrieving revision 1.250
diff -u -5 -r1.250 ChangeLog
--- libgnomeprint/ChangeLog 2001/02/13 01:57:18 1.250
+++ libgnomeprint/ChangeLog 2001/02/15 02:33:37
@@ -1,5 +1,37 @@
+2001-02-15 Roberto Majadas <phoenix@nova.es>
+
+ * gnome-print-private.h: change in gnome_print_context_write_file
+ prototipe const char *buf => const void *buf
+
+ * gnome-print.c (gnome_print_context_write_file): change
+ const char *buf => const void *buf
+
+ * gnome-print-fax.c
+ (gnome_print_fax_get_type): new function
+ (gnome_print_fax_new): new function
+ (gnome_print_fax_construct): new function
+ (fax_class_init): new function
+ (fax_close): new function
+ (fax_beginpage): new function
+ (fax_page_begin): new function
+ (fax_page_end): new function
+ (fax_print_band): new function
+ (fax_encode): new function
+ (fax_encode_rules_apply): new function
+ (fax_encode_finish_of_row): new function
+ (fax_ditering): new function
+ (fax_code): new function
+ (fax_code_eof): new function
+ (fax_code_eol): new function
+ (fax_code_write): new function
+
+ * gnome-print-fax.h
+ * gnomr-print-fax-g3.h
+
+ * Makefile.am (libgnomeprint_la_SOURCES): add gnome-print-fax(.c,.h,-g3.h)
+
2001-02-12 Thomas Hudson <thudson@gobe.com>
* gnome-print-meta.c (gnome_print_meta_access_buffer): Fixed offset for
writing size into buffer.
Index: libgnomeprint/Makefile.am
===================================================================
RCS file: /cvs/gnome/gnome-print/libgnomeprint/Makefile.am,v
retrieving revision 1.45
diff -u -5 -r1.45 Makefile.am
--- libgnomeprint/Makefile.am 2000/12/17 20:26:41 1.45
+++ libgnomeprint/Makefile.am 2001/02/15 02:33:38
@@ -77,10 +77,13 @@
gnome-print-dialog.c \
gnome-print-copies.c \
gnome-printer.c \
gnome-printer-private.h \
gnome-print.c \
+ gnome-print-fax.c \
+ gnome-print-fax.h \
+ gnome-print-fax-g3.h \
gnome-print-file.c \
gnome-print-file.h \
gnome-print-private.h \
gnome-print-meta.c \
gnome-print-multipage.c \
Index: libgnomeprint/gnome-print-fax-g3.h
===================================================================
RCS file: gnome-print-fax-g3.h
diff -N gnome-print-fax-g3.h
--- /dev/null Tue May 5 16:32:27 1998
+++ gnome-print-fax-g3.h Wed Feb 14 21:33:38 2001
@@ -0,0 +1,221 @@
+#ifndef __GNOME_PRINT_RGB2FAX_H__
+#define __GNOME_PRINT_RGB2FAX_H__
+
+
+BEGIN_GNOME_DECLS
+
+typedef struct g3table{
+ int code;
+ int length;
+} g3table;
+
+
+/* Terminating white code table*/
+
+struct g3table twtable[] = {
+ { 0x35 , 8 }, /* 0 */
+ { 0x7 , 6 }, /* 1 */
+ { 0x7 , 4 }, /* 2 */
+ { 0x8 , 4 }, /* 3 */
+ { 0xb , 4 }, /* 4 */
+ { 0xc , 4 }, /* 5 */
+ { 0xe , 4 }, /* 6 */
+ { 0xf , 4 }, /* 7 */
+ { 0x13 , 5 }, /* 8 */
+ { 0x14 , 5 }, /* 9 */
+ { 0x7 , 5 }, /* 10 */
+ { 0x8 , 5 }, /* 11 */
+ { 0x8 , 6 }, /* 12 */
+ { 0x3 , 6 }, /* 13 */
+ { 0x34 , 6 }, /* 14 */
+ { 0x35 , 6 }, /* 15 */
+ { 0x2a , 6 }, /* 16 */
+ { 0x2b , 6 }, /* 17 */
+ { 0x27 , 7 }, /* 18 */
+ { 0xc , 7 }, /* 19 */
+ { 0x8 , 7 }, /* 20 */
+ { 0x17 , 7 }, /* 21 */
+ { 0x3 , 7 }, /* 22 */
+ { 0x4 , 7 }, /* 23 */
+ { 0x28 , 7 }, /* 24 */
+ { 0x2b , 7 }, /* 25 */
+ { 0x13 , 7 }, /* 26 */
+ { 0x24 , 7 }, /* 27 */
+ { 0x18 , 7 }, /* 28 */
+ { 0x2 , 8 }, /* 29 */
+ { 0x3 , 8 }, /* 30 */
+ { 0x1a , 8 }, /* 31 */
+ { 0x1b , 8 }, /* 32 */
+ { 0x12 , 8 }, /* 33 */
+ { 0x13 , 8 }, /* 34 */
+ { 0x14 , 8 }, /* 35 */
+ { 0x15 , 8 }, /* 36 */
+ { 0x16 , 8 }, /* 37 */
+ { 0x17 , 8 }, /* 38 */
+ { 0x28 , 8 }, /* 39 */
+ { 0x29 , 8 }, /* 40 */
+ { 0x2a , 8 }, /* 41 */
+ { 0x2b , 8 }, /* 42 */
+ { 0x2c , 8 }, /* 43 */
+ { 0x2d , 8 }, /* 44 */
+ { 0x4 , 8 }, /* 45 */
+ { 0x5 , 8 }, /* 46 */
+ { 0xa , 8 }, /* 47 */
+ { 0xb , 8 }, /* 48 */
+ { 0x52 , 8 }, /* 49 */
+ { 0x53 , 8 }, /* 50 */
+ { 0x54 , 8 }, /* 51 */
+ { 0x55 , 8 }, /* 52 */
+ { 0x24 , 8 }, /* 53 */
+ { 0x25 , 8 }, /* 54 */
+ { 0x58 , 8 }, /* 55 */
+ { 0x59 , 8 }, /* 56 */
+ { 0x5a , 8 }, /* 57 */
+ { 0x5b , 8 }, /* 58 */
+ { 0x4a , 8 }, /* 59 */
+ { 0x4b , 8 }, /* 60 */
+ { 0x32 , 8 }, /* 61 */
+ { 0x33 , 8 }, /* 62 */
+ { 0x34 , 8 }, /* 63 */
+};
+
+/* Make up white code table */
+
+struct g3table mwtable[] = {
+ { 0x1b, 5 }, /* 64 */
+ { 0x12, 5 }, /* 128 */
+ { 0x17, 6 }, /* 192 */
+ { 0x37, 7 }, /* 256 */
+ { 0x36, 8 }, /* 320 */
+ { 0x37, 8 }, /* 384 */
+ { 0x64, 8 }, /* 448 */
+ { 0x65, 8 }, /* 512 */
+ { 0x68, 8 }, /* 576 */
+ { 0x67, 8 }, /* 640 */
+ { 0xcc, 9 }, /* 704 */
+ { 0xcd, 9 }, /* 768 */
+ { 0xd2, 9 }, /* 832 */
+ { 0xd3, 9 }, /* 896 */
+ { 0xd4, 9 }, /* 960 */
+ { 0xd5, 9 }, /* 1024 */
+ { 0xd6, 9 }, /* 1088 */
+ { 0xd7, 9 }, /* 1152 */
+ { 0xd8, 9 }, /* 1216 */
+ { 0xd9, 9 }, /* 1280 */
+ { 0xda, 9 }, /* 1344 */
+ { 0xdb, 9 }, /* 1408 */
+ { 0x98, 9 }, /* 1472 */
+ { 0x99, 9 }, /* 1536 */
+ { 0x9a, 9 }, /* 1600 */
+ { 0x18, 6 }, /* 1664 */
+ { 0x9b, 9 }, /* 1728 */
+ };
+
+/* terminating white code table */
+
+struct g3table tbtable[] = {
+ { 0x37 , 10 }, /* 0 */
+ { 0x2 , 3 }, /* 1 */
+ { 0x3 , 2 }, /* 2 */
+ { 0x2 , 2 }, /* 3 */
+ { 0x3 , 3 }, /* 4 */
+ { 0x3 , 4 }, /* 5 */
+ { 0x2 , 4 }, /* 6 */
+ { 0x3 , 5 }, /* 7 */
+ { 0x5 , 6 }, /* 8 */
+ { 0x4 , 6 }, /* 9 */
+ { 0x4 , 7 }, /* 10 */
+ { 0x5 , 7 }, /* 11 */
+ { 0x7 , 7 }, /* 12 */
+ { 0x4 , 8 }, /* 13 */
+ { 0x7 , 8 }, /* 14 */
+ { 0x18 , 9 }, /* 15 */
+ { 0x17 , 10 }, /* 16 */
+ { 0x18 , 10 }, /* 17 */
+ { 0x8 , 10 }, /* 18 */
+ { 0x67 , 11 }, /* 19 */
+ { 0x68 , 11 }, /* 20 */
+ { 0x6c , 11 }, /* 21 */
+ { 0x37 , 11 }, /* 22 */
+ { 0x28 , 11 }, /* 23 */
+ { 0x17 , 11 }, /* 24 */
+ { 0x18 , 11 }, /* 25 */
+ { 0xca , 12 }, /* 26 */
+ { 0xcb , 12 }, /* 27 */
+ { 0xcc , 12 }, /* 28 */
+ { 0xcd , 12 }, /* 29 */
+ { 0x68 , 12 }, /* 30 */
+ { 0x69 , 12 }, /* 31 */
+ { 0x6a , 12 }, /* 32 */
+ { 0x6b , 12 }, /* 33 */
+ { 0xd2 , 12 }, /* 34 */
+ { 0xd3 , 12 }, /* 35 */
+ { 0xd4 , 12 }, /* 36 */
+ { 0xd5 , 12 }, /* 37 */
+ { 0xd6 , 12 }, /* 38 */
+ { 0xd7 , 12 }, /* 39 */
+ { 0x6c , 12 }, /* 40 */
+ { 0x6d , 12 }, /* 41 */
+ { 0xda , 12 }, /* 42 */
+ { 0xdb , 12 }, /* 43 */
+ { 0x54 , 12 }, /* 44 */
+ { 0x55 , 12 }, /* 45 */
+ { 0x56 , 12 }, /* 46 */
+ { 0x57 , 12 }, /* 47 */
+ { 0x64 , 12 }, /* 48 */
+ { 0x65 , 12 }, /* 49 */
+ { 0x52 , 12 }, /* 50 */
+ { 0x53 , 12 }, /* 51 */
+ { 0x24 , 12 }, /* 52 */
+ { 0x37 , 12 }, /* 53 */
+ { 0x38 , 12 }, /* 54 */
+ { 0x27 , 12 }, /* 55 */
+ { 0x28 , 12 }, /* 56 */
+ { 0x58 , 12 }, /* 57 */
+ { 0x59 , 12 }, /* 58 */
+ { 0x2b , 12 }, /* 59 */
+ { 0x2c , 12 }, /* 60 */
+ { 0x5a , 12 }, /* 61 */
+ { 0x66 , 12 }, /* 62 */
+ { 0x67 , 12 }, /* 63 */
+ };
+
+/* Make up black code table */
+
+struct g3table mbtable[] = {
+ { 0xf , 10 }, /* 64 */
+ { 0xc8 , 12 }, /* 128 */
+ { 0xc9 , 12 }, /* 192 */
+ { 0x5b , 12 }, /* 256 */
+ { 0x33 , 12 }, /* 320 */
+ { 0x34 , 12 }, /* 384 */
+ { 0x35 , 12 }, /* 448 */
+ { 0x6c , 13 }, /* 512 */
+ { 0x6d , 13 }, /* 576 */
+ { 0x4a , 13 }, /* 640 */
+ { 0x4b , 13 }, /* 704 */
+ { 0x4c , 13 }, /* 768 */
+ { 0x4d , 13 }, /* 832 */
+ { 0x72 , 13 }, /* 896 */
+ { 0x73 , 13 }, /* 960 */
+ { 0x74 , 13 }, /* 1024 */
+ { 0x75 , 13 }, /* 1088 */
+ { 0x76 , 13 }, /* 1152 */
+ { 0x77 , 13 }, /* 1216 */
+ { 0x52 , 13 }, /* 1280 */
+ { 0x53 , 13 }, /* 1344 */
+ { 0x54 , 13 }, /* 1408 */
+ { 0x55 , 13 }, /* 1472 */
+ { 0x5a , 13 }, /* 1536 */
+ { 0x5b , 13 }, /* 1600 */
+ { 0x64 , 13 }, /* 1664 */
+ { 0x65 , 13 }, /* 1728 */
+ };
+
+/* End of line code */
+
+struct g3table g3eol = {0x1 , 12 };
+
+END_GNOME_DECLS
+
+#endif /* __GNOME_PRINT_RGB2FAX_H__ */
Index: libgnomeprint/gnome-print-fax.c
===================================================================
RCS file: gnome-print-fax.c
diff -N gnome-print-fax.c
--- /dev/null Tue May 5 16:32:27 1998
+++ gnome-print-fax.c Wed Feb 14 21:33:39 2001
@@ -0,0 +1,447 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+
+/*
+ * gnome-print-fax.c: A fax driver from buffer rgb to G3 archives
+ *
+ * This implementation uses the GnomePrintRGBP driver.
+ *
+ * Author:
+ * Roberto Majadas "telemaco" <phoenix@nova.es>
+ *
+ * References :
+ *
+ * [1] RFC 804 STANDARDIZATION OF GROUP 3 FACSIMILE APPARATUS FOR DOCUMENT
+ * TRANSMISSION
+ *
+ */
+
+
+#include <config.h>
+#include <stdio.h>
+#include <math.h>
+#include <string.h>
+#include <libgnomeprint/gnome-printer.h>
+#include <libgnomeprint/gnome-printer-private.h>
+#include <libgnomeprint/gnome-print-fax.h>
+#include <libgnomeprint/gnome-print-fax-g3.h>
+#include <libgnomeprint/gnome-print-encode.h>
+#include <libgnomeprint/gnome-print-preview.h>
+#include <libgnomeprint/gnome-print-preview.h>
+#include <libgnomeprint/gnome-print-preview-private.h>
+
+
+#define MAX_FAX_COLS 1728 /* 0 to 1728 cols of A4-paper */
+
+#define YES_IOL 1
+#define NO_IOL 0
+
+#define YES_LASTCODE 1
+#define NO_LASTCODE 0
+
+#define FAX_BLACK_COLOR 1
+#define FAX_WHITE_COLOR 0
+
+typedef struct _FaxEncodeInfo FaxEncodeInfo ;
+struct _FaxEncodeInfo{
+
+ gint run_length ;
+ gint run_length_color ;
+ gint actual_color;
+ gint first_code_of_row ;
+};
+
+/* Gnome-print-fax prototipes */
+
+static void fax_encode (GnomePrintContext *pc, FaxEncodeInfo *fei);
+static void fax_encode_finish_of_row (GnomePrintContext *pc, FaxEncodeInfo *fei,
+ gint cols);
+static void fax_encode_rules_apply (GnomePrintContext *pc, FaxEncodeInfo *fei);
+static void fax_code_write (GnomePrintContext *pc, struct g3table node, int lastcode);
+static void fax_code_eol (GnomePrintContext *pc);
+static void fax_code_eof (GnomePrintContext *pc);
+static void fax_code (GnomePrintContext *pc, int run_length, int color, int iol);
+static int fax_ditering (guchar *rgb_buffer, gint actual_col, gint offset);
+
+
+static GnomePrintRGBPClass *fax_parent_class;
+
+static int fax_encode_buffer ;
+static int fax_encode_buffer_pivot ;
+static int first_code_of_doc ;
+
+
+
+/*
+ * fax_code_write : This funtion write in the g3-file the respective code
+ *
+ * struct g3table node : the respective color table
+ * int lastcode : if this code is the last code of the row => YES_LASTCODE
+ * if not => NO_LASTCODE
+ */
+
+static void
+fax_code_write (GnomePrintContext *pc, struct g3table node, int lastcode){
+ int i,j;
+ int pow_of_2[] = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768};
+
+ for (i=node.length; i > 0; ){
+
+ if (fax_encode_buffer_pivot<0){
+ fax_encode_buffer_pivot = 7 ;
+ gnome_print_context_write_file (pc, &fax_encode_buffer, 1);
+ fax_encode_buffer = 0;
+ }
+ j = node.code&pow_of_2[i-1];
+
+ if (j!=0){
+ fax_encode_buffer |= pow_of_2[fax_encode_buffer_pivot];
+ }
+ fax_encode_buffer_pivot -= 1;
+ i -= 1;
+ }
+
+ if (lastcode){
+ gnome_print_context_write_file (pc, &fax_encode_buffer, 1);
+ }
+}
+
+/*
+ * fax_code_eol : this funtion write in the g3-file the EOL code
+ *
+ */
+
+static void
+fax_code_eol (GnomePrintContext *pc)
+{
+ fax_code_write (pc, g3eol, NO_LASTCODE);
+}
+
+/*
+ * fax_code_eof : this funtion write in the g3-file the EOF code
+ *
+ */
+
+static void
+fax_code_eof (GnomePrintContext *pc)
+{
+ fax_code_write (pc, g3eol, NO_LASTCODE);
+ fax_code_write (pc, g3eol, NO_LASTCODE);
+ fax_code_write (pc, g3eol, NO_LASTCODE);
+ fax_code_write (pc, g3eol, NO_LASTCODE);
+ fax_code_write (pc, g3eol, NO_LASTCODE);
+ fax_code_write (pc, g3eol, YES_LASTCODE);
+}
+
+/*
+ * fax_code : this funtion recive a run_length and the color of this
+ * run_length . And this funtion write the respective code
+ *
+ */
+
+static void
+fax_code (GnomePrintContext *pc, int run_length, int color, int iol)
+{
+
+ if (run_length < 64)
+ {
+ if ( color == FAX_BLACK_COLOR )
+ {
+ if (iol == YES_IOL)
+ {
+ fax_code_write (pc, twtable[0], NO_LASTCODE);
+ fax_code_write (pc, tbtable[run_length], NO_LASTCODE);
+ }
+ else
+ {
+ fax_code_write (pc, tbtable[run_length], NO_LASTCODE);
+ }
+ }
+ else
+ {
+ fax_code_write (pc, twtable[run_length], NO_LASTCODE);
+ }
+ }
+ else if (run_length <= 1728)
+ {
+ int x,y ;
+
+ x = run_length / 64 ;
+ y = run_length % 64 ;
+
+ if ( color == FAX_BLACK_COLOR )
+ {
+ if (iol == YES_IOL)
+ {
+ fax_code_write (pc, twtable[0], NO_LASTCODE);
+ fax_code_write (pc, mbtable[x-1], NO_LASTCODE);
+ fax_code_write (pc, tbtable[y], NO_LASTCODE);
+ }
+ else
+ {
+ fax_code_write (pc, mbtable[x-1], NO_LASTCODE);
+ fax_code_write (pc, tbtable[y], NO_LASTCODE);
+ }
+ }
+ else
+ {
+ fax_code_write (pc, mwtable[x-1], NO_LASTCODE);
+ fax_code_write (pc, twtable[y], NO_LASTCODE);
+ }
+ }
+}
+
+/*
+ * fax_ditering : this function decide if a white or black pixel
+ *
+ */
+
+
+static int
+fax_ditering (guchar *rgb_buffer, gint actual_col, gint offset)
+{
+ gint j = actual_col ;
+
+ if ( rgb_buffer [offset+j] + rgb_buffer [offset+j+1] + rgb_buffer [offset+j+2] < (200*3) )
+ {
+ return FAX_BLACK_COLOR ;
+ }
+ else
+ {
+ return FAX_WHITE_COLOR ;
+ }
+
+}
+
+/*
+ * fax_encode_rules_apply : this funtion apply de rules for encode to g3
+ *
+ */
+
+static void
+fax_encode_rules_apply (GnomePrintContext *pc, FaxEncodeInfo *fei)
+{
+ if (fei->first_code_of_row == TRUE)
+ {
+ fei->first_code_of_row = FALSE;
+ fax_code (pc, fei->run_length, fei->run_length_color, YES_IOL);
+ }
+ else
+ {
+ fax_code (pc, fei->run_length, fei->run_length_color, NO_IOL);
+ }
+}
+
+/*
+ * fax_encode_finish_of_row : finaliza la linea y rellena de blancos si es
+ * necesario
+ *
+ */
+
+static void
+fax_encode_finish_of_row (GnomePrintContext *pc, FaxEncodeInfo *fei, gint cols)
+{
+ if (fei->actual_color == FAX_WHITE_COLOR)
+ {
+ fei->run_length += MAX_FAX_COLS - cols ;
+ fax_encode_rules_apply (pc, fei);
+
+ }
+ else
+ {
+ fax_encode_rules_apply (pc, fei);
+ if (cols<MAX_FAX_COLS)
+ fax_code (pc, MAX_FAX_COLS-cols, FAX_WHITE_COLOR, NO_IOL);
+
+ }
+
+}
+
+/*
+ * fax_encode : proceso de coificacion de la linea
+ *
+ */
+
+static void
+fax_encode (GnomePrintContext *pc, FaxEncodeInfo *fei)
+{
+
+ if (fei->run_length_color == fei->actual_color)
+ {
+ (fei->run_length)++;
+
+ }
+ else
+ {
+ fax_encode_rules_apply (pc, fei);
+ fei->run_length_color = !fei->run_length_color ;
+ fei->run_length = 1 ;
+ }
+}
+
+static int
+fax_print_band (GnomePrintRGBP *rgbp, guchar *rgb_buffer, ArtIRect *rect)
+{
+ GnomePrintContext *pc = GNOME_PRINT_CONTEXT (rgbp);
+ gint rows, actual_row, cols, actual_col, offset;
+
+ FaxEncodeInfo *fei ;
+
+ fei = g_new0 (FaxEncodeInfo, 1);
+
+ rows = rect->y1 - rect->y0;
+ cols = rect->x1 - rect->x0;
+
+ g_return_val_if_fail (cols <= MAX_FAX_COLS, -1);
+
+ if (first_code_of_doc == TRUE)
+ {
+ fax_code_eol (pc) ;
+ first_code_of_doc = FALSE ;
+ }
+
+ for (actual_row=0; actual_row<rows; actual_row++)
+ {
+
+ actual_col = 0 ;
+ offset = actual_row * cols * 3 ;
+
+ fei->actual_color = fax_ditering (rgb_buffer, actual_col, offset) ;
+ fei->run_length_color = fei->actual_color ;
+ fei->run_length = 1;
+ fei->first_code_of_row = TRUE ;
+
+ for (actual_col=1; actual_col<cols; actual_col++)
+ {
+ fei->actual_color = fax_ditering (rgb_buffer, actual_col, offset) ;
+ fax_encode (pc, fei);
+ }
+
+ fax_encode_finish_of_row (pc, fei, cols);
+
+ fax_code_eol (pc) ;
+ }
+
+ g_free (fei);
+
+ return 1;
+}
+
+
+static int
+fax_page_end (GnomePrintRGBP *rgbp)
+{
+ GnomePrintContext *pc;
+
+ g_return_val_if_fail (GNOME_IS_PRINT_RGBP (rgbp), -1);
+ pc = GNOME_PRINT_CONTEXT (rgbp);
+ g_return_val_if_fail (GNOME_IS_PRINT_CONTEXT (pc), -1);
+
+ return 0;
+}
+
+#ifdef KILL_COMPILE_WARNING
+static int
+fax_page_begin (GnomePrintContext *pc)
+{
+ g_print ("Page begin\n");
+ return 0;
+}
+#endif
+
+static int
+fax_beginpage (GnomePrintContext *pc, const char *name_of_this_page)
+{
+ /* Nothing. */
+ return 0;
+}
+
+static int
+fax_close (GnomePrintContext *pc)
+{
+ fax_code_eof (pc);
+ return gnome_print_context_close_file (pc);
+}
+
+static void
+fax_class_init (GtkObjectClass *object_class)
+{
+ GnomePrintRGBPClass *rgbp_class = (GnomePrintRGBPClass *) object_class;
+ GnomePrintContextClass *pc_class = (GnomePrintContextClass *) object_class;
+
+ fax_parent_class = gtk_type_class (gnome_print_rgbp_get_type ());
+
+ rgbp_class->print_band = fax_print_band;
+ rgbp_class->page_end = fax_page_end;
+
+
+ pc_class->close = fax_close;
+ pc_class->beginpage = fax_beginpage;
+
+}
+
+GnomePrintFAX *
+gnome_print_fax_construct (GnomePrintFAX *fax, GnomePrinter *printer, const GnomePaper *paper_info, int dpi)
+{
+ g_return_val_if_fail (printer != NULL, NULL);
+ g_return_val_if_fail (GNOME_IS_PRINTER (printer), NULL);
+ g_return_val_if_fail (fax != NULL, NULL);
+ g_return_val_if_fail (GNOME_IS_PRINT_FAX (fax), NULL);
+ g_return_val_if_fail (paper_info != NULL, NULL);
+ g_return_val_if_fail (dpi >= 0, NULL);
+
+ fax_encode_buffer_pivot = 7;
+ first_code_of_doc = TRUE ;
+
+ if (gnome_print_rgbp_construct (GNOME_PRINT_RGBP (fax), paper_info, dpi)){
+ gnome_print_context_open_file (GNOME_PRINT_CONTEXT (fax), printer->filename);
+ return fax;
+ } else
+ return NULL;
+}
+
+GnomePrintContext *
+gnome_print_fax_new (GnomePrinter *printer, const char *paper_size, int dpi)
+{
+ GnomePrintFAX *fax;
+ const GnomePaper *paper_info;
+
+ g_return_val_if_fail (printer != NULL, NULL);
+ g_return_val_if_fail (GNOME_IS_PRINTER (printer), NULL);
+ g_return_val_if_fail (paper_size != NULL, NULL);
+ g_return_val_if_fail (dpi >= 0, NULL);
+
+ fax = gtk_type_new (gnome_print_fax_get_type ());
+
+ paper_info = gnome_paper_with_name (paper_size);
+ if (paper_info == NULL)
+ g_return_val_if_fail (FALSE, NULL);
+
+ if (!gnome_print_fax_construct (fax, printer, paper_info, dpi))
+ gtk_object_unref (GTK_OBJECT (fax));
+
+ return GNOME_PRINT_CONTEXT (fax);
+}
+
+GtkType
+gnome_print_fax_get_type (void)
+{
+ static GtkType type = 0;
+
+ if (!type){
+ GtkTypeInfo info = {
+ "GnomePrintFAX",
+ sizeof (GnomePrintFAX),
+ sizeof (GnomePrintFAXClass),
+ (GtkClassInitFunc) fax_class_init,
+ (GtkObjectInitFunc) NULL,
+ /* reserved_1 */ NULL,
+ /* reserved_2 */ NULL,
+ (GtkClassInitFunc) NULL,
+ };
+
+ type = gtk_type_unique (gnome_print_rgbp_get_type (), &info);
+ }
+
+ return type;
+}
Index: libgnomeprint/gnome-print-fax.h
===================================================================
RCS file: gnome-print-fax.h
diff -N gnome-print-fax.h
--- /dev/null Tue May 5 16:32:27 1998
+++ gnome-print-fax.h Wed Feb 14 21:33:39 2001
@@ -0,0 +1,47 @@
+#ifndef __GNOME_PRINT_FAX_H__
+#define __GNOME_PRINT_FAX_H__
+
+#include <libgnome/gnome-defs.h>
+#include <libgnome/gnome-paper.h>
+#include <libgnomeui/gnome-canvas.h>
+#include <libgnomeprint/gnome-print.h>
+#include <libgnomeprint/gnome-print-rgbp.h>
+
+BEGIN_GNOME_DECLS
+
+/*
+ * GnomePrintPixbuf printer context.
+ */
+#define GNOME_TYPE_PRINT_FAX (gnome_print_fax_get_type ())
+#define GNOME_PRINT_FAX(obj) (GTK_CHECK_CAST ((obj), GNOME_TYPE_PRINT_FAX, GnomePrintFAX))
+#define GNOME_PRINT_FAX_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GNOME_TYPE_PRINT_FAX, GnomePrintFAXClass))
+#define GNOME_IS_PRINT_FAX(obj) (GTK_CHECK_TYPE ((obj), GNOME_TYPE_PRINT_FAX))
+#define GNOME_IS_PRINT_FAX_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GNOME_TYPE_PRINT_FAX))
+
+typedef struct _GnomePrintFAX GnomePrintFAX;
+typedef struct _GnomePrintFAXPrivate GnomePrintFAXPrivate;
+typedef struct _GnomePrintFAXClass GnomePrintFAXClass;
+
+struct _GnomePrintFAX {
+ GnomePrintRGBP rgbp;
+
+ GnomePrintFAXPrivate *priv;
+};
+
+struct _GnomePrintFAXClass {
+ GnomePrintRGBPClass parent_class;
+};
+
+GtkType gnome_print_fax_get_type (void);
+GnomePrintContext *gnome_print_fax_new (GnomePrinter *printer,
+ const char *paper_size,
+ int dpi);
+GnomePrintFAX *gnome_print_fax_construct (GnomePrintFAX *fax,
+ GnomePrinter *printer,
+ const GnomePaper *paper_info,
+ int dpi);
+
+END_GNOME_DECLS
+
+#endif /* __GNOME_PRINT_PCLR_H__ */
+
Index: libgnomeprint/gnome-print-private.h
===================================================================
RCS file: /cvs/gnome/gnome-print/libgnomeprint/gnome-print-private.h,v
retrieving revision 1.6
diff -u -5 -r1.6 gnome-print-private.h
--- libgnomeprint/gnome-print-private.h 2000/09/24 16:14:23 1.6
+++ libgnomeprint/gnome-print-private.h 2001/02/15 02:33:39
@@ -101,11 +101,11 @@
/* These are functions for writing bytes to the printer - generally to a
file or piped to lpr. */
int gnome_print_context_open_file (GnomePrintContext *pc, const char *filename);
-int gnome_print_context_write_file (GnomePrintContext *pc, const char *buf, size_t size);
+int gnome_print_context_write_file (GnomePrintContext *pc, const void *buf, size_t size);
int gnome_print_context_fprintf (GnomePrintContext *pc, const char *fmt, ...);
int gnome_print_context_close_file (GnomePrintContext *pc);
END_GNOME_DECLS
Index: libgnomeprint/gnome-print.c
===================================================================
RCS file: /cvs/gnome/gnome-print/libgnomeprint/gnome-print.c,v
retrieving revision 1.62
diff -u -5 -r1.62 gnome-print.c
--- libgnomeprint/gnome-print.c 2000/12/18 21:38:50 1.62
+++ libgnomeprint/gnome-print.c 2001/02/15 02:33:41
@@ -895,11 +895,11 @@
return pc->f != NULL;
}
/* Return number of bytes written */
int
-gnome_print_context_write_file (GnomePrintContext *pc, const char *buf, size_t size)
+gnome_print_context_write_file (GnomePrintContext *pc, const void *buf, size_t size)
{
g_return_val_if_fail (pc != NULL, 0);
g_return_val_if_fail (GNOME_IS_PRINT_CONTEXT (pc), 0);
g_return_val_if_fail (pc->f != NULL, 0);
Index: tests/Makefile.am
===================================================================
RCS file: /cvs/gnome/gnome-print/tests/Makefile.am,v
retrieving revision 1.9
diff -u -5 -r1.9 Makefile.am
--- tests/Makefile.am 2000/11/26 05:19:45 1.9
+++ tests/Makefile.am 2001/02/15 02:33:42
@@ -3,10 +3,11 @@
testprint2 \
testprint3 \
testprint4 \
testprint5 \
testprint6 \
+ testfax \
testpdf \
testmetrics\
testembed \
testzip
@@ -72,10 +73,16 @@
testprint6_SOURCES = testprint6.c
testprint6_LDFLAGS =
testprint6_DEPENDENCIES = $(DEPS)
testprint6_LDADD = \
+ $(print_libs)
+
+testfax_SOURCES = testfax.c
+testfax_LDFLAGS =
+testfax_DEPENDENCIES = $(DEPS)
+testfax_LDADD = \
$(print_libs)
testpdf_SOURCES = testpdf.c
testpdf_LDFLAGS =
testpdf_DEPENDENCIES = $(DEPS)
Index: tests/testfax.c
===================================================================
RCS file: testfax.c
diff -N testfax.c
--- /dev/null Tue May 5 16:32:27 1998
+++ testfax.c Wed Feb 14 21:33:42 2001
@@ -0,0 +1,162 @@
+#include <config.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <gnome.h>
+
+#include <libgnomeprint/gnome-printer.h>
+#include <libgnomeprint/gnome-print.h>
+#include <libgnomeprint/gnome-print-meta.h>
+#include <libgnomeprint/gnome-print-preview.h>
+#include <libgnomeprint/gnome-print-pixbuf.h>
+#include <libgnomeprint/gnome-print-fax.h>
+#include <libgnomeprint/gnome-print-rgbp.h>
+#include <libgnomeprint/gnome-font.h>
+#include <libgnomeprint/gnome-printer-dialog.h>
+
+#define _GNOME_PRINT_FAX_CLEAR_TEST_NOT
+
+static int do_preview;
+static int do_rgb_dump;
+static int dpi = 209;
+
+static struct poptOption options [] = {
+ { "preview", 0, POPT_ARG_NONE, &do_preview },
+ { "dump", 0, POPT_ARG_NONE, &do_rgb_dump },
+ { "dpi", 0, POPT_ARG_INT, &dpi },
+ { NULL }
+};
+
+
+
+static void
+print_test_page (GnomePrintContext *pc)
+{
+ GnomeFont *font;
+ int i;
+
+
+ font = gnome_font_new ("Courier", 14);
+ gnome_print_setfont (pc, font);
+
+#ifdef _GNOME_PRINT_FAX_CLEAR_TEST_NOT
+ for (i = 0; i < 300; i += 50){
+ char buf [40];
+
+ gnome_print_setrgbcolor (pc, 0.3, 0.4, 0.5);
+
+ gnome_print_moveto (pc, 0, i);
+ gnome_print_lineto (pc, 400, i);
+ gnome_print_stroke (pc);
+
+ gnome_print_setrgbcolor (pc, 0.3, 0.4, 0.5);
+
+ sprintf (buf, "%d", i);
+ gnome_print_moveto (pc, 10, i + 3);
+ gnome_print_show (pc, buf);
+ }
+
+ gnome_print_setrgbcolor (pc, 0, 0, 0);
+
+ font = gnome_font_new_closest ("Times", GNOME_FONT_BOLD, 1, 10);
+
+ gnome_print_setfont (pc, font);
+
+ gnome_print_moveto (pc, 5, 600);
+ gnome_print_show (pc, "En un lugar de la mancha de cuyo nombre no quiero acordarme");
+
+#endif
+
+ gnome_print_showpage (pc);
+ gnome_print_context_close (pc);
+
+}
+
+static void
+show_pixbuf (GnomePrintPixbuf * gpb, GdkPixbuf * pb, gint pagenum, gpointer data)
+{
+ int fh;
+ gint y, w, h, rs;
+ guchar * px, * p;
+
+ g_print ("Showpixbuf called :)\n");
+
+ w = gdk_pixbuf_get_width (pb);
+ h = gdk_pixbuf_get_height (pb);
+ rs = gdk_pixbuf_get_rowstride (pb);
+ px = gdk_pixbuf_get_pixels (pb);
+
+ fh = creat ("output.dump", S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ g_return_if_fail (fh >= 0);
+
+ for (y = 0; y < h; y++) {
+ p = px + y * rs;
+ write (fh, p, w * 4);
+ }
+
+ close (fh);
+}
+
+static void
+test_fax (void)
+{
+ GnomePrinter *printer;
+ GnomePrintContext *pc;
+ GtkWidget *toplevel, *canvas, *sw;
+
+ if (do_preview){
+ gtk_widget_set_default_colormap (gdk_rgb_get_cmap ());
+ gtk_widget_set_default_visual (gdk_rgb_get_visual ());
+
+ toplevel = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_widget_set_usize (toplevel, 700, 700);
+ sw = gtk_scrolled_window_new (NULL, NULL);
+ canvas = gnome_canvas_new_aa ();
+ gnome_canvas_set_pixels_per_unit (GNOME_CANVAS (canvas), dpi);
+ gtk_container_add (GTK_CONTAINER (toplevel), sw);
+ gtk_container_add (GTK_CONTAINER (sw), canvas);
+
+ pc = gnome_print_preview_new (GNOME_CANVAS(canvas), "US-Letter");
+
+ gtk_widget_show_all (toplevel);
+ } else {
+ if (do_rgb_dump) {
+ const GnomePaper * gp;
+ gdouble w, h;
+
+ gp = gnome_paper_with_name ("US-Letter");
+ w = gnome_paper_pswidth (gp);
+ h = gnome_paper_psheight (gp);
+
+ pc = gnome_print_pixbuf_new (0.0, 0.0, w, h,
+ dpi, dpi, TRUE);
+
+ gtk_signal_connect (GTK_OBJECT (pc), "showpixbuf",
+ GTK_SIGNAL_FUNC (show_pixbuf), NULL);
+
+ } else {
+ printer = gnome_printer_dialog_new_modal ();
+
+ if (!printer)
+ return;
+
+ g_print ("Estoy donde el fax\n");
+ pc = gnome_print_fax_new (printer, "A4", dpi);
+
+ }
+ }
+
+ print_test_page (pc);
+}
+
+int
+main (int argc, char **argv)
+{
+ gnome_init_with_popt_table ("TestPrint", VERSION, argc, argv, options, 0, NULL);
+
+ test_fax ();
+
+ if (do_preview)
+ gtk_main ();
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]