This project is read-only.

GetStyleAt() Always returns 0

Mar 5, 2008 at 5:48 PM
What I'm basically doing is making an Html Exporter for ScintillaNET. I do this by first looping through all the scintilla.Styles and writing them out in a big <style></style> tag, giving them names. This part works fine, albeit there's about 126 different styles when I use c# as my lexer. Next, I'm trying to loop through each character in the scintilla.Text property, and call GetStyleAt(curPos) on it. Now, for whatever reason, this always returns 0 (DOCUMENT_DEFAULT style), even though I do see some appropriate styles when I go through all the scintilla.Styles, so I know the lexer loaded them (and the control on a windows form has the sample code I'm processing all highlighted nicely).

I'm pretty much following the same method in my approach as in Scite's Exporters.cxx file where they do the HTML Export. Anyways, I'm not sure why, but no matter what, GetStyleAt always returns 0.

Note: I checked out the source today, so I should have whatever the latest committed changes were!

Any Ideas?
Mar 5, 2008 at 7:50 PM
Send me a zipped up example project and I can play with it. (
Mar 5, 2008 at 10:47 PM
I'll send you something tomorrow (left my code on another machine)

Anyways, I'm basically interested in making ScintillaNET support some sort of Export interface. So, to do this, I have three options: 1) Be lazy and wait until someone else does it (if that happens). 2) Create my own Exporter project that works with ScintillaNET. 3) Change ScintillaNET source and either submit it to you to get merged, or get access to commit to the repository

I'd prefer option 3, and that's what I started working on. I've got an IExporter interface drawn up (it's extremely simple, basically has only void Export(Scintilla sc, System.IO.Stream output);
I'm working primarily on an HTML Exporter (which will be used whenever I redesign instead of the ActiPro software I'm using), but using an interface would allow other future exporters of course (as with Scite, RTF, PDF might also be useful). As far as modifying the actual Scintilla code, all I've needed to do so far is add two methods to the Scintilla control file: Export(IExporter exporter, System.IO.Stream output) and Export(IExporter, string filename). Both are basically just stubs which would instantiate a new Exporter class that will handle the actual work (this again, is to minimize the need to change the actual guts of ScintillaNET).

So, let me know what you think. Again, I'll make up a quick example project to demonstrate my issue (hopefully I'm just missing something).
Mar 6, 2008 at 4:10 AM
That actually is something that is a "someday" item. If you can provide a working source I'll merge it into the project.. HTML and RTF are probably the most desired. PDF would be a more difficult item.

I'm curious though, why are you not using ActiPro (SyntaxEdit?) assuming you are already fully licensed?
Mar 6, 2008 at 2:41 PM
I have a license for ActiPro based on an agreement with the company with certain advertising clauses (we worked out a deal since the project I use it for is a 'free' project). While It's been pretty good to use, my license is always for a specific version and whenever I want to update that, I need to contact the vendor and it's a bit of a hassle. Besides that, I don't have very much control over how it works, and that's been somewhat limiting. I like the idea of using scintilla and supporting something open source. So far, it's been a lot easier dealing with it then the actipro stuff (though I really don't use the windows forms portion of either that much, it's more for just getting code highlighted and getting the result out).

Mostly it boils down to having more control over my projects, and supporting open source. So far you've done a great job with the .net wrapper and I want to contribute back to it if possible. :)
Mar 6, 2008 at 3:45 PM
Ok, so a bit more info into my 'problem'. It seems the latest posted works fine (build 31025), so it seems something has changed in the repository since that build since the latest source i've checked out does not work :s. At least I can confirm I'm doing it properly!
Mar 6, 2008 at 3:58 PM
Duh... 31025 IS the latest revision in the repository...

Anyways, more on the problem. Hopefully this can be worked around... I was trying to use my code in the form_load event of the form i had the control on. If I let the form load, and THEN perform the export (eg: with a button click event), it works fine. Much the same, if I create a new instance of the control without displaying it on a form (eg: if I wanted to use the lexer from an ASP.NET app and export the highlighted code to html, and display the html), the same problems happen. So, something is happening when the control is displayed that isn't happening when it's not. I'm going to dig a bit deeper, but my guess is that this problem stems from Scintialla itself and probably not the wrapper :s. I'm hoping there's a way to work around this!
Mar 6, 2008 at 7:27 PM
I always get double posts when I post with FireFox.

Anyway when I have time I'll look into this some more. ScintillaNET's initialization should happen before its parent form's Load event happens. However it won't work outside of a Windows GUI context because both Scintilla and ScintillaNET are both tightly coupled with Windows Messages. It you just want to do syntax highlighting export to HTML another library would be more appropriate.
Mar 7, 2008 at 1:17 AM
Yeah, as I'm looking further into the code, I see that.... Though, I don't see why it still shouldn't work for what I'm trying to do if you say that it should all be working before the form_load happens. It would be nice if there were a way to get this to do what I am looking for. It's so close as it is!

Basically, the other options for doing this are not spectacular. There's a decent python based one, a php one, but neither seem to have any sort of support for code folding or anything beyond the utmost basic syntax colouring...

The trick here is, yes I'm looking to export to html, but I'm also interested in using it in a windows app client for the service that will be just exporting to html. So this would kill both birds with one stone.... I'd love to get this to work...
Mar 31, 2008 at 3:16 PM
Any updates on this? I did a fair bit more research on highlighters and none of the options are that appealing. I know since it's tightly coupled with windows messages, this isn't the best idea for a highlighting engine, but as I mentioned, I already want to use ScintillaNET for the windows.forms aspect of the service, so it would make sense to utilize the same syntax definitions in both places.