WYSIWYG

Is it possible to have a text area with exactly the same layout as the printer-output ?

Maybe this can help : http://www.bkeeney.com/formatted-text-control

Otherwise, you may want to ask yourself the question the other way : “is it possible to print exactly as it appears in a textarea” ? The method used to print can stick to what is displayed, therefore Wysiwyg…

Michel, es tu Dupond ou Dupont? :slight_smile:

John bowen : ???!!!
Michel : Ok with your remark but do you have an answer for that other question : “is it possible to print exactly as it appears in a textarea” ? The method used to print can stick to what is displayed, therefore Wysiwyg…

Your question cannot be “can the textarea look like the printer”… because what is on a printed page cannot be imported to a text area (disregarding OCR scan).

Since you enter text into the text area and then print from there… what Michel said above is more approprite.

“Can the printed output look exactly like the content of a Text Area”… and to that the answer is yes. Read about styled text in the XOJO documents.

I have a control that goes beyond what FTC does and is precisely WYSIWYG. You can even print everything by calling a single function…scale…fit to page. …whatever you want with a single function call… The control comes with a module that also extends the graphics class, so you could use the function g.DrawStyledText (even if you don’t use the control itself) to handle all the (tedious) manipulation you’ll have to do just to send StyledText to the printer… You can download and try it using the link below… printing styledtext involves looping through style runs and accounting for styles (and every possible combination) yourself. My single function Handles all of that for you :slight_smile:

https://forum.xojo.com/11355-simdesignercanvas-control-v1-5-beta-available

[quote=87316:@Antoon Verleysen]
Michel : Ok with your remark but do you have an answer for that other question : “is it possible to print exactly as it appears in a textarea” ? The method used to print can stick to what is displayed, therefore Wysiwyg…[/quote]

To print you basically Graphics.DrawString lines one after the other on a printer graphics object, like so :

dim pr as printersetup g = OpenPrinterDialog(pr) if g = nil then return False // if it's not nil If not(g=Nil) Then g.TextSize = TextArea1.TextSize g.TextFont=TextArea1.TextFont g.DrawString "this is my first line" ,left, top end if

As you can see in this short sample, you can control the print attributes : font size, font, color, bold or not, etc.

To make the print the same as the TextArea, you need to detect the stylerun in the styled text. See the example project in the Xojo folder : Text/StyledText.xojo_binary_project. Then use the stylerun on the printed material.

The tricky part is to figure the soft wrap ; that is, the way lines are cut in the TextArea within a paragraph. DrawString does that with the wrap option and it works fine when a paragraph contains only one style, but you have to manage line ends when for instance a line contains a word in bold or italic. Usually, you will need to use the Graphics.Stringwidth to evaluate the length of the line and use a loop until you get to a space where you can wrap the line.

These are the general principles you can use to print a TextArea by copying text style.

Just noticed Matthew’s post. Antoon, you may want to follow his advice, save you the need to perfect a print routine and use his control.

The work of Matthew really looks great !
I’ll study it very carefully.
Ones again, guys, tx for your help.