Forum > SynEdit

Synedit + Syntax Highlighting => how to print after ?


with Lazarus it is easy to create an editor with synedit, Syntax Highlight is working well, but after how to print ?

We don't have synedit component to print... 

do we have exemple of application based  on synedit with printing feature ?

This page says that there exists an example of printing in a demo in the source dir

Btw. It was the first result when searching for: synedit print ;)

That page is not about the SynEdit in Lazarus.

SynEdit is an independent open-source (GPL/MPL) project currently in Version 2.x
And originally based on a project called mwedit.

Lazarus forked it's own SynEdit of the original project, when the original project was at Version 1.1 or 1.2.

Since then both projects have added many features. However the Lazarus fork is no longer compatible with the original (and there are no plans to get it back there)

A printer component for SynEdit has been long on my list, but unfortunately not yet been started.

One of the issues is, that when printing, you must wrap long lines (which you do not do on screen (another feature...))

If you want to look at doing something, I guess your best bet is TSynCustomExporter in Syneditexport.pas

There also is a html exporter (but I have no idea how well it works...). SynExporter may need maintenance itself (all i know is it compiles, but that says nothing, sorry)

Look at the methods ExportAll, ExportRange.

The main part as to how to get the higghlight info is:
(I removed some code, that did cut the 1st and last line. Using partial lines may give very unexpected results)

--- Code: ---  Highlighter.ResetRange; // important for very first line
  for i := Start.Y to Stop.Y do begin
    Line := ALines[i - 1];
    Highlighter.SetLine(Line, i);
    while not Highlighter.GetEOL do begin
      Attri := Highlighter.GetTokenAttribute;
      Token := ReplaceReservedChars(Highlighter.GetToken, IsSpace);
      SetTokenAttribute(IsSpace, Attri);

--- End code ---

A better approach may be to copy the code from SynEdit.PaintLines

--- Code: ---    // 0 base line number
        while not fHighlighter.GetEol do begin
    // pchar and len to next text segment
    // color of next text segment
          attr := fHighlighter.GetTokenAttribute;
    // output it
          // Let the highlighter scan the next token.

--- End code ---

- loop through all lines
- replace DrawHiLightMarkupToken with your code to output text to the printer

attr contains Fore/Back/Frame-color, as well as TextStyle (ignore stylemask)

Note: the highlighter only returns the highlights for pascal.

all editing attributes (such as block selection, highlight of current word, etc) are not included in this. And should not, since you do not highlight the selection in print.

Maybe i find some more time...

For SynEdit/Highlighter related stuff also see here:
 [It does not (yet?) have anything on printing, but other re-occurring questions...]


[0] Message Index

Go to full version