Page 1 sur 1

Imprimer sous Linux Ubuntu

Publié : sam. 13/déc./2008 12:57
par cnormal
Bonjour,
J'aimerais pouvoir imprimer simplement des graphiques avec PureBasic sous Linux Ubuntu, mais les commandes Printer de la démo ci-dessous fonctionne pas sous Linux !
Si il faut utiliser une autre procédure, un membre du forum pourrait-il m'expliquer la conversion et le code qu'il faudrait faire avec l'exemple ci-desous.
Merci d'avance
;
; ------------------------------------------------------------
;
; PureBasic - Printer example file
;
; (c) Fantaisie Software
;
; ------------------------------------------------------------
;

If PrintRequester()

If StartPrinting("PureBasic Test")

LoadFont(0, "Arial", 30)
LoadFont(1, "Arial", 100)

If StartDrawing(PrinterOutput())

DrawingFont(FontID(0))

DrawText(100, 100, "PureBasic Printer Test")

DrawingFont(FontID(1))

DrawText(100, 400, "PureBasic Printer Test 2")

If LoadImage(0, "Data\PureBasic.bmp")
DrawImage(ImageID(0), 200, 600)
Else
MessageRequester("Error","Can't load the image")
EndIf

FrontColor(RGB(100,100,100))
Box(200, 600, 100, 100)

StopDrawing()
EndIf

StopPrinting()
EndIf
EndIf
[/list][/code]

Publié : dim. 21/déc./2008 14:32
par Anonyme
As tu un message d'erreur du deboggeur ? car comme ca difficile de dire pourquoi cela ne fonctionne pas .

Publié : sam. 03/janv./2009 15:14
par cnormal
J'ai trouvé, il faut ajouter le paquet libgnomeprint2.2-dev. Mais, la résolution DPI me parait bien faible !

Publié : sam. 03/janv./2009 15:27
par Anonyme
en tout cas , chez moi pas de soucis. donne du code pour voir.

Après une longue absence je reviens sur le problème

Publié : ven. 14/août/2009 21:25
par cnormal
Dans le code ci-dessus par exemple, en imprimant Box(200, 600, 100, 100) avec Ubuntu le carré a environ 35 mm de côté, avec Windows le même carré a environ 7 mm de côté.
Le texte est 4 fois plus long avec Ubuntu par rapport à Windows.
Pourtant mon imprimantes une jet d'encre Epson Stylus D92 a un règlage identique sur les deux systèmes d'exploitation.
Il y a le même problème avec mon autre imprimante, une laser Brother HL-1440.
Comment paramètrer mon imprimante avec PB pour avoir à peu près les mêmes valeurs d'impression de Windows avec Ubuntu sans modifier les valeurs graphiques PB.

Publié : dim. 16/août/2009 8:28
par kernadec
bonjour cnormal
je pense que tes drivers sont a jours.
mais au cas ou regarde ici http://www.openprinting.org/printer_list.cgi et tu auras peut etre le pilote qu'il est préférable d'utiliser.
tu fais un test en créant une nouvelle imprimante avec ton navigateur à l'adresse http://localhost:631

cordialement

Publié : dim. 16/août/2009 14:20
par cnormal
Bonjour kernadec,
Merci pour avoir répondu si vite.
Le pilote que j'ai installé est:
Epson Stylus D92 - CUPS+Gutenprint (OpenPrinting LSB 3.2) v5.2.3
Les règlages de la résolution au maximum avec le gestionnaire d'imprimante est 2880 ppp x 1440 ppp

Lorsque je fais le test suivant:

PrintRequester()

If StartPrinting("PureBasic Test")

Result = PrinterPageWidth()
Debug "horizontale"
Debug Result

Result = PrinterPageHeight()
Debug "verticale"
Debug Result

StopPrinting()
EndIf

Sauf erreur:
Avec PB Ubuntu les réponses sont 695 et 842 ce qui fait environ sans les marges de l'imprimante que la résolution est 72 ou 75 DPI. (Digne des premières imprimantes matricielles).

(Pour le même test avec Windows les réponses peuvent aller au maximum 5784 et 8250 !)

Je pense que la solution serait de programmer la résolution de l'imprimante avec du code PB mais, je ne sais pas comment faire !

Publié : lun. 17/août/2009 13:01
par kernadec
bonjour cnormal
je n'utilise pas tres souvent linux
mais sous Windows l'API GetDeviceCaps sert très généralement à interroger
le pilote d'un périphérique: marges, résolution, taille physique, taille logique, aspect des pixels...

pour cela voila un lien vers une doc API lib gnome print , qui a des fonctions API equivalentes
http://library.gnome.org/devel/libgnomeprint/stable/

Cordialement

Publié : lun. 17/août/2009 13:11
par Progi1984
Un Import ou ImportC du fichier .so devrait fonctionner.

Publié : lun. 17/août/2009 13:44
par Anonyme
;http://www.purebasic.fr/english/viewtopic.php?t=29904
; ---------------------------------------------------------------------------------------
; using the GTK print dialog
; 2007 walker
; not fully functional yet but shows how to use this dialog
; BUT with a working preview ;-)
; ---------------------------------------------------------------------------------------
;---------------- Preparations ---------------------------------------------------
;import needed functions
ImportC "/usr/lib/libgtk-x11-2.0.so"
gtk_print_operation_new()
gtk_print_operation_run(*op, action, *parent, *error);the print dialog
gtk_print_settings_new()
gtk_print_operation_set_print_settings(*print,*settings)
gtk_print_context_create_pango_layout(*context)
pango_layout_set_text(layout,txt.p-utf8,length)
pango_font_description_from_string(font.p-utf8)
pango_font_description_free(desc)
pango_layout_set_font_description(layout,desc)
cairo_move_to(cr,x,y)
pango_cairo_show_layout(cr,layout)
gtk_print_context_get_cairo_context(context)
gtk_print_operation_set_n_pages(*op,n_pages)
gtk_print_operation_set_unit(*op,unit)
gtk_print_operation_get_status_string (*op); a (translated) string
gtk_print_operation_get_status (*op);the numer enumerated below
gtk_print_operation_is_finished (*op);returns true or false
EndImport

;print actions
Enumeration
#GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG
#GTK_PRINT_OPERATION_ACTION_PRINT
#GTK_PRINT_OPERATION_ACTION_PREVIEW
#GTK_PRINT_OPERATION_ACTION_EXPORT
EndEnumeration
;return values from printdialog
Enumeration
#GTK_PRINT_OPERATION_RESULT_ERROR
#GTK_PRINT_OPERATION_RESULT_APPLY
#GTK_PRINT_OPERATION_RESULT_CANCEL
#GTK_PRINT_OPERATION_RESULT_IN_PROGRESS
EndEnumeration
;status of printing
Enumeration
#GTK_PRINT_STATUS_INITIAL
#GTK_PRINT_STATUS_PREPARING
#GTK_PRINT_STATUS_GENERATING_DATA
#GTK_PRINT_STATUS_SENDING_DATA
#GTK_PRINT_STATUS_PENDING
#GTK_PRINT_STATUS_PENDING_ISSUE
#GTK_PRINT_STATUS_PRINTING
#GTK_PRINT_STATUS_FINISHED
#GTK_PRINT_STATUS_FINISHED_ABORTED
EndEnumeration
;layout units
Enumeration
#GTK_UNIT_PIXEL
#GTK_UNIT_POINTS
#GTK_UNIT_INCH
#GTK_UNIT_MM
EndEnumeration

ProcedureCDLL begin_print(*op,context, user_data)
;this procedure is called before rendering the pages...

;set number of pages.. ESSENTIAL!!!! never forget this! (or you'll wait forever)
gtk_print_operation_set_n_pages(*op,1);

EndProcedure

ProcedureCDLL draw_page(*op,context,page_nr,user_data)
;this Procedure is called for each page to print.... so a fixed text like this example isn't a good idea
gtk_print_operation_set_unit (*op, #GTK_UNIT_MM);
cr= gtk_print_context_get_cairo_context(context)
layout = gtk_print_context_create_pango_layout (context);
pango_layout_set_text (layout, "Hello World!", -1);
desc = pango_font_description_from_string ("sans 28");
pango_layout_set_font_description (layout, desc);
pango_font_description_free (desc);
pango_cairo_show_layout (cr, layout)
g_object_unref_(layout)

EndProcedure

ProcedureCDLL print_preview(*op,*preview, *context, *parent, user_data)
;for your own preview routine...

EndProcedure

ProcedureCDLL end_print(*op, *context, user_data)
;if printig is finished, you can add code here for some cleanups etc...

EndProcedure

;-------------------- DEMO -------------------------
OpenWindow(0,0,0,400,400,"printtest",#PB_Window_SystemMenu)
CreateGadgetList(WindowID(0))
ButtonGadget(0,10,50,100,30,"Print")

Repeat
event=WaitWindowEvent()

If event=#PB_Event_Gadget
If EventGadget()=0
;print button
;create a new printoperation
print=gtk_print_operation_new()
;connect teh actions to a procedure
g_signal_connect_(print, "begin-print", @begin_print(), user_data);
g_signal_connect_(print, "draw-page", @draw_page(), user_data);
;If you activate the following line, the built in preview is DISABLED
; g_signal_connect_(print, "preview", @print_preview(), d);
g_signal_connect_(print, "end-print", @end_print(), user_data);
;finally calling the GTK+ printrequester
res=gtk_print_operation_run(print,#GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,WindowID(0),*error)
;If res returns #GTK_PRINT_OPERATION_RESULT_CANCEL the user had clicked on cancel - else one of the callbacks is called
EndIf
EndIf

Until event=#PB_Event_CloseWindow