Recent

Author Topic: How to create a 'virtual' receipt (in a window/dialog)?  (Read 11277 times)

zrocker

  • New Member
  • *
  • Posts: 11
How to create a 'virtual' receipt (in a window/dialog)?
« on: February 25, 2014, 08:34:45 pm »
I need to generate a simulation of a printed paper receipt to the screen (in a window or dialog box).
Specific needs: mono-spaced font(s) (varying sizes for each line), possible different fonts per line (same on any single line), maximum 42 chars per line; bold, underline, italic support, varying receipt length (# of lines) with vertical scroll bar, each lines' text could be left/center/right justified and, finally, an option to print the receipt data as seen on the screen to a printer (such that it looks like what is seen on screen).

This is probably pretty easy, but I can't figure what control(s) to use.  SynEdit and TMemo don't seem to be good for this.  Again, the window (dialog) would be something simple like a TMemo with white background and black text... and scroll bar on the right... and, each line could have a different font and font style.  Then, printing that text would be nice (if user clicks Print button).

I hope someone has a great solution for this and/or some sample code that shows how to get started on this.  Thanks :)
« Last Edit: February 25, 2014, 09:35:18 pm by zrocker »

Windsurfer

  • Sr. Member
  • ****
  • Posts: 368
    • Windsurfer
Re: How to create a 'virtual' receipt (in a window/dialog)?
« Reply #1 on: February 25, 2014, 09:24:08 pm »
You can create an Image and use the canvas textout function to write the text.

eg Image1.Canvas.TextOut(X, Y, string);

Take a look at http://wiki.freepascal.org/Using_the_printer for ideas about using the printer.

zrocker

  • New Member
  • *
  • Posts: 11
Re: How to create a 'virtual' receipt (in a window/dialog)?
« Reply #2 on: February 25, 2014, 09:34:54 pm »
Awesome... and, so... if I set the image alignment to client or put it in a TScrollBox, it'll automatically get a vertical scroll bar?

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: How to create a 'virtual' receipt (in a window/dialog)?
« Reply #3 on: February 25, 2014, 09:35:46 pm »
You are correct in deducing that TMemo and TSynedit do not handle multiple fonts at all.
You want what is termed a 'richtext' component. Lazarus CCR has RichView and RichMemo, but fpvectorial
  http://wiki.lazarus.freepascal.org/fpvectorial_-_Text_Document_Support
may be your best bet.
No open source richtext component has so far been deemed good enough to find a permanent place on the Lazarus component palette, which should indicate to you that most of the current solutions have shortcomings of one sort or another.
It is clear from recent postings here that fpvectorial is under active current development. I don't know about the maintained status of the others.

zrocker

  • New Member
  • *
  • Posts: 11
Re: How to create a 'virtual' receipt (in a window/dialog)?
« Reply #4 on: February 25, 2014, 10:30:44 pm »
I think I found a good/great solution.  I'll turn the receipt text into an HTML format and use the THtmlViewer component (THtmlPort package) to display this receipt text.  Printing support is built-in as well.  :)

zrocker

  • New Member
  • *
  • Posts: 11
Re: How to create a 'virtual' receipt (in a window/dialog)?
« Reply #5 on: March 04, 2014, 02:05:28 pm »
All - Using THtmlViewer (latest code 11.4 from https://code.google.com/p/thtmlviewer/) worked perfectly for displaying the receipt data.  For printing, the support for FPC was IFDEF-ed out (not supported yet), but I looked at the portion commented out and added a just a couple of lines (in vwPrint.pas) to obtain the printer canvas handle from Printer.Canvas.Handle and printing worked.  I also had to turn off range checking it 2 places because of false 'range check errors' on some TMap Put/Remove calls.  NOTE: I tried the Print Preview (really I tried the Number of Pages feature prior to printing) feature, but that was causing some exception [bad things] so I just didn't use that feature.

OrphanCat

  • Newbie
  • Posts: 4
    • Htmlviewer Components
Re: How to create a 'virtual' receipt (in a window/dialog)?
« Reply #6 on: March 30, 2014, 03:11:50 pm »
Hi,

I'm maintaining the HtmlViewer components.

It would be great, if you could post your changes as an "issue" to the above link or push them to a clone of the HtmlViewer11 branch of the  GitHub project.
I will then try to fix the exceptions.

Thanks in advance
OprhanCat

zeljko

  • Hero Member
  • *****
  • Posts: 1770
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: How to create a 'virtual' receipt (in a window/dialog)?
« Reply #7 on: March 30, 2014, 04:20:19 pm »
I need to generate a simulation of a printed paper receipt to the screen (in a window or dialog box).
Specific needs: mono-spaced font(s) (varying sizes for each line), possible different fonts per line (same on any single line), maximum 42 chars per line; bold, underline, italic support, varying receipt length (# of lines) with vertical scroll bar, each lines' text could be left/center/right justified and, finally, an option to print the receipt data as seen on the screen to a printer (such that it looks like what is seen on screen).

This is probably pretty easy, but I can't figure what control(s) to use.  SynEdit and TMemo don't seem to be good for this.  Again, the window (dialog) would be something simple like a TMemo with white background and black text... and scroll bar on the right... and, each line could have a different font and font style.  Then, printing that text would be nice (if user clicks Print button).

I hope someone has a great solution for this and/or some sample code that shows how to get started on this.  Thanks :)

I'm interested also in component to test pos printer output (ESC/POS only).
As I can see you already setted up html viewer as such test, but I don't think it's perfect for such scenario.
Best would be paintBox in TScrollBox, and then render each command into paintBox canvas (with monospaced font , like it is with ESC/POS printer).
So in that case, such form can contain various settings like column number (different printers can print different num of cols with it's default font 32..42) and maybe printer driver (samsung,epson,escpos,starmode etc).





zrocker

  • New Member
  • *
  • Posts: 11
Re: How to create a 'virtual' receipt (in a window/dialog)?
« Reply #8 on: March 31, 2014, 02:17:57 am »
I'm interested also in component to test pos printer output (ESC/POS only).
As I can see you already setted up html viewer as such test, but I don't think it's perfect for such scenario.
Best would be paintBox in TScrollBox, and then render each command into paintBox canvas (with monospaced font , like it is with ESC/POS printer).
So in that case, such form can contain various settings like column number (different printers can print different num of cols with it's default font 32..42) and maybe printer driver (samsung,epson,escpos,starmode etc).

I was able to emulate all this using the HTML component and converting/interpreting the ESC/POS to html code and formatting the receipt.  Looks great (my receipts were pretty easy and I'm no HTML expert).

zrocker

  • New Member
  • *
  • Posts: 11
Re: How to create a 'virtual' receipt (in a window/dialog)?
« Reply #9 on: March 31, 2014, 02:23:24 am »
Hi,

I'm maintaining the HtmlViewer components.

It would be great, if you could post your changes as an "issue" to the above link or push them to a clone of the HtmlViewer11 branch of the  GitHub project.
I will then try to fix the exceptions.

Thanks in advance
OprhanCat

Awesome... will do (soon... today or tomorrow).  If I remember, it/they were pretty simple.  Still, the call to the 'preview' function (or whatever it was) that provides the # of pages in advance of display the print dialog was still crash things.  So, in the end, I did not implement/use that feature (when printing an HTML page).

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12321
  • FPC developer.
Re: How to create a 'virtual' receipt (in a window/dialog)?
« Reply #10 on: March 31, 2014, 09:11:54 am »
Awesome... will do (soon... today or tomorrow).  If I remember, it/they were pretty simple.  Still, the call to the 'preview' function (or whatever it was) that provides the # of pages in advance of display the print dialog was still crash things.  So, in the end, I did not implement/use that feature (when printing an HTML page).

Do you use Windows 8 (and probably 64-bit) ? I've seen that behavior often on systems that use Vista printer drivers. Something changed there.

zrocker

  • New Member
  • *
  • Posts: 11
Re: How to create a 'virtual' receipt (in a window/dialog)?
« Reply #11 on: March 31, 2014, 02:12:11 pm »
Awesome... will do (soon... today or tomorrow).  If I remember, it/they were pretty simple.  Still, the call to the 'preview' function (or whatever it was) that provides the # of pages in advance of display the print dialog was still crash things.  So, in the end, I did not implement/use that feature (when printing an HTML page).

Do you use Windows 8 (and probably 64-bit) ? I've seen that behavior often on systems that use Vista printer drivers. Something changed there.

No.  That testing (for # of print pages) was done on Win XP 32-bit (believe it our not).  I did NOT think to try it out on another Windows platform (Win 7 or Win 8, 64 or 32-bit).... maybe, I can someday.  Thanks.

 

TinyPortal © 2005-2018