Recent

Author Topic: Synedit + Syntax Highlighting => how to print after ?  (Read 10321 times)

candide

  • New Member
  • *
  • Posts: 14
Synedit + Syntax Highlighting => how to print after ?
« on: December 10, 2010, 09:43:03 pm »
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 ?


Laksen

  • Hero Member
  • *****
  • Posts: 743
    • J-Software
Re: Synedit + Syntax Highlighting => how to print after ?
« Reply #1 on: December 10, 2010, 09:49:33 pm »
This page says that there exists an example of printing in a demo in the source dir
http://sourceforge.net/apps/mediawiki/synedit/index.php?title=FAQ#How_do_I_print_the_contents_of_a_TSynEdit.3F

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

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9867
  • Debugger - SynEdit - and more
    • wiki
Re: Synedit + Syntax Highlighting => how to print after ?
« Reply #2 on: December 10, 2010, 10:14:13 pm »
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: [Select]
 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);
      FormatToken(Token);
      Highlighter.Next;
    end;
    FormatNewLine;
  end;

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

Code: [Select]
   // 0 base line number
        fHighlighter.StartAtLineIndex(CurTextIndex);
        while not fHighlighter.GetEol do begin
    // pchar and len to next text segment
          fHighlighter.GetTokenEx(sToken,nTokenLen);
    // color of next text segment
          attr := fHighlighter.GetTokenAttribute;
    // output it
          DrawHiLightMarkupToken(attr,sToken,nTokenLen);
          // Let the highlighter scan the next token.
          fHighlighter.Next;
        end;
      end;

- 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: http://wiki.lazarus.freepascal.org/SynEdit_Highlighter
 [It does not (yet?) have anything on printing, but other re-occurring questions...]
« Last Edit: December 10, 2010, 10:18:44 pm by Martin_fr »

 

TinyPortal © 2005-2018