Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » LineEdit, EditFields, DocEdit » How to Print a file inside LineEdit
How to Print a file inside LineEdit [message #3227] Sun, 14 May 2006 19:34 Go to next message
forlano is currently offline  forlano
Messages: 1182
Registered: March 2006
Location: Italy
Senior Contributor
Hello,

I've a file in a LineEdit widget and I desire to send it to the Printer. I've found with Assist the Print() function but it seems to work with RichText while I've a simple text file. So I wonder if it works or there is a U++ Print method that can do the job. (At the moment I've not a printer so I cannot test if the Print() method RichTest based works in my case).

BTW, this question is more general because in principle I could want to print a text file bypassing any widget and sending it directly to the printer.

Thank you,

Luigi

PS: The class RichEdit has the Print() method, why LineEdit has not the same?
Re: How to Print a file inside LineEdit [message #3230 is a reply to message #3227] Sun, 14 May 2006 21:44 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
forlano wrote on Sun, 14 May 2006 13:34

Hello,

I've a file in a LineEdit widget and I desire to send it to the Printer. I've found with Assist the Print() function but it seems to work with RichText while I've a simple text file. So I wonder if it works or there is a U++ Print method that can do the job. (At the moment I've not a printer so I cannot test if the Print() method RichTest based works in my case).

BTW, this question is more general because in principle I could want to print a text file bypassing any widget and sending it directly to the printer.

Thank you,

Luigi

PS: The class RichEdit has the Print() method, why LineEdit has not the same?


There is no direct support for printing of LineEdit.

The simplest way to print is to use Report. Simply, instead to sending your stuff to "Draw", you use Report (which implements Draw interface), just add some calls to perform pagination. Alternatively, use Qtf, which you can send to Report as well.

Mirek

Re: How to Print a file inside LineEdit [message #3240 is a reply to message #3230] Mon, 15 May 2006 21:09 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1182
Registered: March 2006
Location: Italy
Senior Contributor
luzr wrote on Sun, 14 May 2006 21:44

The simplest way to print is to use Report. Simply, instead to sending your stuff to "Draw", you use Report (which implements Draw interface), just add some calls to perform pagination. Alternatively, use Qtf, which you can send to Report as well.

Mirek


I tried Report. Perhaps I do some mistake but doesn't seems so immediate. Let's neglect for the moment the pagination and let assume I've only one page to print. I tried the following code:
void  VegaTab4::PrintCB()
{ 	Report r;
//	r.Header("[A2> Page $$P");
	r << "Round 1";
    r << "===================================================================";
    r << "  1 =   4 Karpov, Igor         -   2 Karpov, Vadim         = 1 - 0";
    r << "-------------------------------------------------------------------";
    Print( r, 1, "Preview");
//	Perform(r); //same format error
}

When I run it appear the print panel. Then I click print and I observe the result attached below (I've printed with a pdf driver and then get a screenshot).
So it seems Report try to interpret the strings in qtf terms. This means that my text file is processed as a qtf file while it has no format command and I want to send to the printer each character the file contains.
Before to obtain this error I believed I could get the entire text file and pass via << to r and then print it. But now seems I cannot avoid to save the file in qtf format. Am I right?

Anyway I think could be very useful to have a very direct way to communicate with a printer without any inteference and control about font etc. With linux I could use a calling to system and print via 'lp', but with windows I would like to have the possibility to choose at least the printer.

Luigi
  • Attachment: swiss5.jpg
    (Size: 8.68KB, Downloaded 2051 times)
Re: How to Print a file inside LineEdit [message #3242 is a reply to message #3240] Mon, 15 May 2006 22:00 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
forlano wrote on Mon, 15 May 2006 15:09

luzr wrote on Sun, 14 May 2006 21:44

The simplest way to print is to use Report. Simply, instead to sending your stuff to "Draw", you use Report (which implements Draw interface), just add some calls to perform pagination. Alternatively, use Qtf, which you can send to Report as well.

Mirek


I tried Report. Perhaps I do some mistake but doesn't seems so immediate. Let's neglect for the moment the pagination and let assume I've only one page to print. I tried the following code:
void  VegaTab4::PrintCB()
{ 	Report r;
//	r.Header("[A2> Page $$P");
	r << "Round 1";
    r << "===================================================================";
    r << "  1 =   4 Karpov, Igor         -   2 Karpov, Vadim         = 1 - 0";
    r << "-------------------------------------------------------------------";
    Print( r, 1, "Preview");
//	Perform(r); //same format error
}

When I run it appear the print panel. Then I click print and I observe the result attached below (I've printed with a pdf driver and then get a screenshot).
So it seems Report try to interpret the strings in qtf terms. This means that my text file is processed as a qtf file while it has no format command and I want to send to the printer each character the file contains.
Before to obtain this error I believed I could get the entire text file and pass via << to r and then print it. But now seems I cannot avoid to save the file in qtf format. Am I right?

Anyway I think could be very useful to have a very direct way to communicate with a printer without any inteference and control about font etc. With linux I could use a calling to system and print via 'lp', but with windows I would like to have the possibility to choose at least the printer.

Luigi


You can "avoid" qtf by calling DeQtf for texts you pass... That will add escape characters that will "quote" original text in Qtf.

void  VegaTab4::PrintCB()
{ 	Report r;
//	r.Header("[A2> Page $$P");
	r << "Round 1";
    r << DeQtf("===================================================================");
    r << DeQtf("  1 =   4 Karpov, Igor         -   2 Karpov, Vadim         = 1 - 0");
    r << DeQtf("-------------------------------------------------------------------");
    Print( r, 1, "Preview");
//	Perform(r); //same format error
}


Mirek

[Updated on: Mon, 15 May 2006 22:01]

Report message to a moderator

Re: How to Print a file inside LineEdit [message #3244 is a reply to message #3242] Mon, 15 May 2006 23:13 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1182
Registered: March 2006
Location: Italy
Senior Contributor
luzr wrote on Mon, 15 May 2006 22:00


You can "avoid" qtf by calling DeQtf for texts you pass... That will add escape characters that will "quote" original text in Qtf.

void  VegaTab4::PrintCB()
{ 	Report r;
//	r.Header("[A2> Page $$P");
	r << "Round 1";
    r << DeQtf("===================================================================");
    r << DeQtf("  1 =   4 Karpov, Igor         -   2 Karpov, Vadim         = 1 - 0");
    r << DeQtf("-------------------------------------------------------------------");
    Print( r, 1, "Preview");
//	Perform(r); //same format error
}


Mirek

I tried and it works. Unfortunatly there is again one more problem Smile : by default it is set the proportional font. Instead i would like to print with courier font to preserve the vertical alignment present in the file. Using UWord I got the format command to print with courier, say 11. So I've tried to embed one text line in a formatted command line with courier font like this:
void  VegaTab4::PrintCB()
{ 	Report r;
    r << "[ $$0,0#00000000000000000000000000000000:Default]"
         "[{_}%EN-US" 
         "[s0;C+92 Round 1 ]";  //it's OK
 
    r << "[s0;C+92 " << DeQtf("Round 1") << " ]";  // doesn't work
    r << "[s0;C+92 " << DeQtf("=====================================================") <<" ]" ;
   Print( r, 1, "Preview");
}

This produce problem (see attached picture) because do not recognise the final " ]" and this seems strange to me.

I've even tried
    r.SetFont(Courier(12)); 

with no success. So, is there a way to set by default the Courier font?

Luigi
index.php?t=getfile&id=137&private=0
  • Attachment: swiss6.jpg
    (Size: 8.58KB, Downloaded 2970 times)
Re: How to Print a file inside LineEdit [message #3245 is a reply to message #3244] Tue, 16 May 2006 01:35 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
forlano wrote on Mon, 15 May 2006 17:13

luzr wrote on Mon, 15 May 2006 22:00


You can "avoid" qtf by calling DeQtf for texts you pass... That will add escape characters that will "quote" original text in Qtf.

void  VegaTab4::PrintCB()
{ 	Report r;
//	r.Header("[A2> Page $$P");
	r << "Round 1";
    r << DeQtf("===================================================================");
    r << DeQtf("  1 =   4 Karpov, Igor         -   2 Karpov, Vadim         = 1 - 0");
    r << DeQtf("-------------------------------------------------------------------");
    Print( r, 1, "Preview");
//	Perform(r); //same format error
}


Mirek

I tried and it works. Unfortunatly there is again one more problem Smile : by default it is set the proportional font. Instead i would like to print with courier font to preserve the vertical alignment present in the file. Using UWord I got the format command to print with courier, say 11. So I've tried to embed one
Quote:



What about reading QTF reference instead? Smile

http://upp.sourceforge.net/srcdoc$RichText$QTF$en-us.html



text line in a formatted command line with courier font like this:
void  VegaTab4::PrintCB()
{ 	Report r;
    r << "[ $$0,0#00000000000000000000000000000000:Default]"
         "[{_}%EN-US" 
         "[s0;C+92 Round 1 ]";  //it's OK
 
    r << "[s0;C+92 " << DeQtf("Round 1") << " ]";  // doesn't work
    r << "[s0;C+92 " << DeQtf("=====================================================") <<" ]" ;
   Print( r, 1, "Preview");
}

This produce problem (see attached picture) because do not recognise the final " ]" and this seems strange to me.

I've even tried
    r.SetFont(Courier(12)); 

with no success. So, is there a way to set by default the Courier font?

Luigi
index.php?t=getfile&id=137&private=0


There is one tricky thing about Report::operator<< - it takes each call as separate qtf text. So

r << "[s0;C+92 " << DeQtf("Round 1") << " ]";


makes for 3 separate texts.

To fix it, simply add texts together:

r << "[s0;C+92 " + DeQtf("Round 1") + " ]";


(Note that adding here is possible becase DeQtf returns String).


Mirek
Re: How to Print a file inside LineEdit [message #3250 is a reply to message #3245] Tue, 16 May 2006 18:10 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1182
Registered: March 2006
Location: Italy
Senior Contributor
luzr wrote on Tue, 16 May 2006 01:35

To fix it, simply add texts together:
r << "[s0;C+92 " + DeQtf("Round 1") + " ]";

(Note that adding here is possible becase DeQtf returns String).

Mirek


Thanks to your help now everything works as I wanted.
I think this way to print (knowing it) is superior to that to send directly the file to the printer. In fact the font size can be selected and the text can be rescaled and reoriented before to send it to the printer. This is of course more flexible. For this reason I've added a size font selector that rescale the image file when necessary.
Now I need few information to permit me to organize a good pagination. Report has too much option and I'm a bit lost.
I run the following commands regarding the dimension and I've obtained the following results:
1)	sz = r.GetSize();    //  3968 x 6074  => aspect ratio = 0.652)
2)	sz = r.GetPageMMs(); //  320 x 240 => aspect ratio = 0.75
3)	sz = r.GetPagePixels(); // 1024 x 768 => aspect ratio = 0.75

I guess GetPageMMs() returns the dimensions in millimeters.
Now 2) and 3) returns dimensions that produce the same aspect ratio. So I wonder what GetSize() returns to give a different aspect ratio.

In the row
    r << "[s0;C+92 " + DeQtf("=====================================") + " ]" ;

which are the unit of the font height indicated by '92'?

Last question. If I send my code example to the printer (actually a pdfdriver) I obtain the following attached picture.
In it you can see an offset both for vertical and horizontal in the top left page. But If I preview it with Perform(r) the offset is absent on the screen! So, is it present some offset or the pdfprinter do some bad joke?

Thank you.

Luigi

PS: I guess these information, knowing the the number of lines of the file (maybe even the longest row of the file), should be enough to produce an acceptable pagination. If I need some other parameter please let me know it.
index.php?t=getfile&id=139&private=0
  • Attachment: swiss5.jpg
    (Size: 16.62KB, Downloaded 3123 times)

[Updated on: Tue, 16 May 2006 18:10]

Report message to a moderator

Re: How to Print a file inside LineEdit [message #3260 is a reply to message #3250] Tue, 16 May 2006 22:11 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Well, there is one important thing to know about U++ "distances".

Basically said, if the output goes to the screen, they are in pixels.

However, if there is "physical representation" (paper from the printer, or e.g. PDF which is in fact paper from the printer again), U++ uses "dots", where dot is defined as "pixel in 600dpi resolution".

And that is what GetSize returns. Actually, those numbers are choosen for A4 page and are indeed quite conservative (in fact, most printers are capable printing in much wider area, but it is different for each printer). When Report prints the page out, it takes "printer" page dimension and centres report size whithin it.

Mirek
Re: How to Print a file inside LineEdit [message #3284 is a reply to message #3260] Wed, 17 May 2006 19:16 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1182
Registered: March 2006
Location: Italy
Senior Contributor
The following code snippet read a text file and print it via the Report control. The font used is Courier. The size font, hf, come from the widget "FontHeight edt". Each line of the file is sent to report with
        r << "[s0;C+" + sizefont + DeQtf(line) + " ]"; 


Luigi

void  VegaTab4::PrintCB()
{ 
    Report r;
    FileIn in(filename);
    String sizefont;
    r.SetPageSize(4500, 6300); // reduce the left margin

    double hf = StrDblValue(AsString(~edt)); 
    sizefont = AsString( (int)(59 + (hf - 7.) * 10.) ) ; 

    while(!in.IsEof()) {
	String line = in.GetLine();
        r << "[s0;C+" + sizefont + DeQtf(line) + " ]"; 
    }
    in.Close();

    // Print( r, 1, "Preview");
    Perform(r);
}
  • Attachment: swiss5.jpg
    (Size: 36.78KB, Downloaded 2068 times)
Re: How to Print a file inside LineEdit [message #3285 is a reply to message #3284] Wed, 17 May 2006 20:30 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
There should be a single space after sizefont to delimit/terminate qtf command sequence... And ending "]" is not necessary here:

r << "[C+" + sizefont + ' ' + DeQtf(line);


Mirek
Re: How to Print a file inside LineEdit [message #3288 is a reply to message #3285] Wed, 17 May 2006 20:45 Go to previous message
forlano is currently offline  forlano
Messages: 1182
Registered: March 2006
Location: Italy
Senior Contributor
luzr wrote on Wed, 17 May 2006 20:30

There should be a single space after sizefont to delimit/terminate qtf command sequence... And ending "]" is not necessary here:

r << "[C+" + sizefont + ' ' + DeQtf(line);


Mirek



ooops... Sad , you are right and in my code there is. In fact without it I couldn't print. In the original version the space was in size font
sizefont = AsString( (int)(59 + (hf - 7.) * 10.) ) + " ";

But I didn't like there. So I removed it from there to move in r <<... but I forgot to add ... Smile
About " ]" good to know.

Luigi
Previous Topic: How to let appear by default the bar in the LineEdit?
Next Topic: Append separate Strings to a DocEdit[SOLVED]
Goto Forum:
  


Current Time: Thu Mar 28 13:31:48 CET 2024

Total time taken to generate the page: 0.01608 seconds