Yet another source code viewer plugin based on Scintilla control

Issues:
In standalone viewer, The first line is obscured by the toolbar.

another:
the background/foreground color of line number cannot be modified, can this be improved?

the color defined in <Line number margin (global)> is not designated as all styles's line number color in dosrcvwr.config.xml

Alucard theme (light).xml

<GlobalStyles>

        <WidgetStyle name="Line number margin" styleID="33" fgColor="5A5643" bgColor="FFFBEB" fontName="" fontSize=""></WidgetStyle>

for example, in dosrcvwr.config.xml, "Line number margin" fgColor is always "81969A" .

<Style name="perl" ext="pl pm plx" desc="Perl" lexer="6">

        <WordStyle name="Line number margin" styleID="33" fgColor="81969A" bgColor="3F4B4E" fontStyle="0" eolFill="0"/>

1、删除配置文件中所有的 <WordStyle name="Line number margin"\N+ (正则匹配)
2、在 <Style name="default" ext="*" lexer="1"> 节中添加新的

这是我的配色:<WordStyle name="Line number margin" styleID="33" fgColor="FAFEFF" bgColor="2D2F32" eolFill="0"/>

行号的配色确实是有问题的 我重新编辑了上面的帖子
说的更详细了

Alucard theme (light).xml 中有定义行号颜色
没有被正确引入 dosrcvwr.config.xml
当你切换主题xml时,行号颜色不会改变,你需要再次编辑 dosrcvwr.config.xml
这肯定是不科学的

dosrcvwr.config.xml 里的配置 在切换另一个主题后再切回来 基本上都会重新还原为 Alucard theme (light).xml 里的定义,所以直接修改 dosrcvwr.config.xml 不是个好方案

There was an issue with the order in which the settings were applied. I've already fixed it. The new version is in the first post of this thread.

Regarding this situation: For some reason, my contlol isn’t receiving all notifications about resizing. If we resize the window manually, everything returns to normal. I need a little time to figure this out.

@alexeydott

默认的XML配置文件中XML部分有错误,使用默认配置文件不能正确渲染。

There are errors in the XML part of the default XML configuration file, and the default configuration file cannot be rendered correctly.

CPP部分我修改了一下,把默认的INSTRUCTION WORD 和 TYPE WORD 合并了,参考SciTE的配置文件增加了非活动状态的着色:

I modified the CPP part and merged the default INSTRUCTION WORD and TYPE WORD. I added inactive coloring by referring to the SciTE configuration file.

        <WordStyle name="Default" styleID="32" fgColor="FAFEFF" bgColor="2D2F32" fontStyle="0" eolFill="0"/>
        <WordStyle name="White Space" styleID="0" fgColor="FAFEFF" bgColor="2D2F32" fontStyle="0" eolFill="0"/>
        <WordStyle name="Comment" styleID="1" fgColor="BCE784" bgColor="2D2F32" fontStyle="0"  eolFill="0"/>
        <WordStyle name="Comment Line" styleID="2" fgColor="BCE784" bgColor="2D2F32" fontStyle="0"  eolFill="0"/>
        <WordStyle name="Comment Doc" styleID="3" fgColor="BCE784" bgColor="2D2F32" fontStyle="0"  eolFill="0"/>
        <WordStyle name="Number" styleID="4" fgColor="FFB86C" bgColor="2D2F32" fontStyle="0" eolFill="0"/>
        <WordStyle name="Keywords" styleID="5" fgColor="FFE0BC" bgColor="2D2F32" fontStyle="1"  eolFill="0" keywordClass="instre1">
          <Keywords id="0">alignas alignof and and_eq asm audit auto axiom bitand bitor bool break case catch char char8_t char16_t char32_t class compl concept const consteval constexpr const_cast continue co_await co_return co_yield decltype default delete do double dynamic_cast else enum explicit export extern false final float for friend goto if import inline int long module mutable namespace new noexcept not not_eq nullptr operator or or_eq override private protected public register reinterpret_cast requires return short signed sizeof static static_assert static_cast struct switch template this thread_local throw true try typedef typeid typename union unsigned using virtual void volatile wchar_t while xor xor_eq</Keywords>
        </WordStyle>
        <WordStyle name="Double Quoted String" styleID="6" fgColor="F1FA8C" bgColor="2D2F32" fontStyle="0" eolFill="0"/>
        <WordStyle name="Single Quoted String" styleID="7" fgColor="F1FA8C" bgColor="2D2F32" fontStyle="0" eolFill="0"/>
        <WordStyle name="UUIDs (Only In IDL)" styleID="8" fgColor="FAFEFF" bgColor="2D2F32" fontStyle="0" eolFill="0"/>
        <WordStyle name="Preprocessor" styleID="9" fgColor="66CDFF" bgColor="2D2F32" fontStyle="0"  eolFill="0"/>
        <WordStyle name="Operators" styleID="10" fgColor="FAFEFF" bgColor="2D2F32" fontStyle="0" eolFill="0"/>
        <WordStyle name="Identifiers" styleID="11" fgColor="FAFEFF" bgColor="2D2F32" fontStyle="0" eolFill="0"/>
        <WordStyle name="End of line where string is not closed" styleID="12" fgColor="F1FA8C" bgColor="2D2F32" fontStyle="0" eolFill="0"/>
        <WordStyle name="Verbatim strings" styleID="13" fgColor="FAFEFF" bgColor="2D2F32" fontStyle="0" eolFill="0"/>
        <WordStyle name="Regular expressions" styleID="14" fgColor="8BE9FD" bgColor="2D2F32" fontStyle="0" eolFill="0"/>
        <WordStyle name="Comment Line Doc" styleID="15" fgColor="BCE784" bgColor="2D2F32" fontStyle="0"  eolFill="0"/>
        <WordStyle name="Keywords2" styleID="16" fgColor="4EC999" bgColor="2D2F32" fontStyle="0" eolFill="0" keywordClass="type1">
          <!-- 用户自定义数据类型 -->
          <Keywords id="1">BOOL INT UINT</Keywords>
        </WordStyle>
        <WordStyle name="Comment Doc Keyword" styleID="17" fgColor="BCE784" bgColor="2D2F32" fontStyle="0"  eolFill="0"/>
        <WordStyle name="Comment Doc Keyword Error" styleID="18" fgColor="BCE784" bgColor="2D2F32" fontStyle="0"  eolFill="0"/>
        <WordStyle name="Global class" styleID="19" fgColor="FAFEFF" bgColor="2D2F32" fontStyle="0" eolFill="0"/>
        <WordStyle name="Raw strings for C++0x" styleID="20" fgColor="FAFEFF" bgColor="2D2F32" fontStyle="0" eolFill="0"/>
        <WordStyle name="Triple-Quoted Strings For Vala" styleID="21" fgColor="F1FA8C" bgColor="2D2F32" fontStyle="0" eolFill="0"/>
        <WordStyle name="Hash-quoted strings for Pike" styleID="22" fgColor="F1FA8C" bgColor="2D2F32" fontStyle="0" eolFill="0"/>
        <WordStyle name="Preprocessor Stream Comment" styleID="23" fgColor="BCE784" bgColor="2D2F32" fontStyle="0" />
        <WordStyle name="Preprocessor Stream Doc Comment" styleID="24" fgColor="BCE784" bgColor="2D2F32" fontStyle="0" />
        <WordStyle name="User Defined Literals" styleID="25" fgColor="BEB7FF" bgColor="2D2F32" fontStyle="0" eolFill="0" />
        <WordStyle name="Task Marker" styleID="26" fgColor="FAFEFF" bgColor="2D2F32" fontStyle="0" eolFill="0"/>
        <WordStyle name="Escape Sequence" styleID="27" fgColor="FAFEFF" bgColor="2D2F32" fontStyle="0" eolFill="0"/>
        <!-- Inactive states are 64 greater than their active counterparts -->
        <WordStyle name="Comment Inactive" styleID="65" fgColor="7D9A58" bgColor="2D2F32" fontStyle="0"  eolFill="0"/>
        <WordStyle name="Line Comment Inactive" styleID="66" fgColor="7D9A58" bgColor="2D2F32" fontStyle="0"  eolFill="0"/>
        <WordStyle name="Doc Comment Inactive" styleID="67" fgColor="7D9A58" bgColor="2D2F32" fontStyle="0"  eolFill="0"/>
        <WordStyle name="Number Inactive" styleID="68" fgColor="C0C0C0" bgColor="2D2F32" fontStyle="0"  eolFill="0"/>
        <WordStyle name="Keyword Inactive" styleID="69" fgColor="C0C0C0" bgColor="2D2F32" fontStyle="0"  eolFill="0"/>
        <WordStyle name="Double quoted string Inactive" styleID="70" fgColor="C0C0C0" bgColor="2D2F32" fontStyle="0"  eolFill="0"/>
        <WordStyle name="Single quoted string Inactive" styleID="71" fgColor="C0C0C0" bgColor="2D2F32" fontStyle="0"  eolFill="0"/>
        <WordStyle name="UUIDs  Inactive" styleID="72" fgColor="C0C0C0" bgColor="2D2F32" fontStyle="0"  eolFill="0"/>
        <WordStyle name="Preprocessor Inactive" styleID="73" fgColor="C0C0C0" bgColor="2D2F32" fontStyle="0"  eolFill="0"/>
        <WordStyle name="Operators Inactive" styleID="74" fgColor="C0C0C0" bgColor="2D2F32" fontStyle="0"  eolFill="0"/>
        <WordStyle name="Identifiers Inactive" styleID="75" fgColor="C0C0C0" bgColor="2D2F32" fontStyle="0"  eolFill="0"/>
        <WordStyle name="Keywords2 Inactive" styleID="80" fgColor="C0C0C0" bgColor="2D2F32" fontStyle="0"  eolFill="0"/>
        <WordStyle name="Comment keyword Inactive" styleID="81" fgColor="C0C0C0" bgColor="2D2F32" fontStyle="0"  eolFill="0"/>
        <WordStyle name=" Comment keyword error Inactive" styleID="82" fgColor="C0C0C0" bgColor="2D2F32" fontStyle="0"  eolFill="0"/>
        <WordStyle name="Raw strings for C++0x Inactive" styleID="84" fgColor="C0C0C0" bgColor="2D2F32" fontStyle="0"  eolFill="0"/>
        <WordStyle name="Triple-quoted strings for Vala Inactive" styleID="85" fgColor="C0C0C0" bgColor="2D2F32" fontStyle="0"  eolFill="0"/>
        <WordStyle name="Hash-quoted strings for Pike Inactive" styleID="86" fgColor="C0C0C0" bgColor="2D2F32" fontStyle="0"  eolFill="0"/>
        <WordStyle name="Preprocessor stream comment Inactive" styleID="87" fgColor="C0C0C0" bgColor="2D2F32" fontStyle="0"  eolFill="0"/>
        <WordStyle name="Preprocessor stream doc comment Inactive" styleID="88" fgColor="C0C0C0" bgColor="2D2F32" fontStyle="0"  eolFill="0"/>
        <WordStyle name="User defined literals Inactive" styleID="89" fgColor="C0C0C0" bgColor="2D2F32" fontStyle="0"  eolFill="0"/>
        <WordStyle name="Task Marker Inactive" styleID="90" fgColor="C0C0C0" bgColor="2D2F32" fontStyle="0"  eolFill="0"/>
        <WordStyle name="Escape sequence Inactive" styleID="91" fgColor="C0C0C0" bgColor="2D2F32" fontStyle="0"  eolFill="0"/>
1 Like

I usually don't touch the lexer configuration files. I'm content to provide notepad++) it would be great if you issued a pull request on github. there is a special tool for creating default config resources.

1 Like

缩进线与行高可以在各个语法高亮中控制是否显示么?

Can indentation lines and line heights be controlled to display in various syntax highlights?

可以增加CP437编码么?NFO文件载入乱码。

Can I add CP437 encoding?The NFO file is loaded with garbled characters.

Folders below ConfigFiles\Plugins aren't backed up, no. Plugins shouldn't make subdirs there, but could put the same files directly into ConfigFiles\Plugins with a prefix/suffix on the filenames to separate them and allow the plugin to find them by listing the directory (e.g. for a list of user-installed themes as in the example).

The User Data config folder (sibling of ConfigFiles) can also be used if needed. That is backed up and restored recursively.

Therefore, if I save the plugin settings in %DOPUSUserData%\dosrcvwr\ directory, their backup will be created automatically?
How do I access it through the DO api? This way is reliable?
%DOPUSUserData% = GetConfigPath(OPUSPATH_CONFIG) + '\..\..\User Data\'

The file encoding is determined using the chsdet library. I have added basic support for recognizing pseudographics there.
first post has been updated.

Scintilla doesn't have a separate LineSpacing property as a coefficient. The line spacing is set by adding an extra value to the ascent/descent of the line.

There is no separate property for this in Notepad++ themes format (specifically in dracula, I have not looked at others). Notepad++ theme format sets colors and style parameters through WordsStyle / WidgetStyle: fgColor, bgColor, fontName, fontStyle, fontSize, colorStyle, keywordClass; there is no separate field for SCI_SETEXTRAASCENT / SCI_SETEXTRADESCENT.

In the DScintilla control visual settings, you need to set the Upper line spacing / Lower line spacing:

怎么增加新的语法高亮?如何操作?

How to add new syntax highlighting? How to operate?

The text encoding detection seems to need improvement.
this bat should be codepage 936. but shown as 852.

test.bat (6.2 KB)

Other text editors can detect the encoding correctly.
such as notepad++ / emeditor / everedit / notepad4. etc.

But here's what's interesting. for example, in my notepad++ and notepad4, distorted characters are displayed when opening your example. I think it all depends on the current system locale.


To be honest, I haven't tested chsdet in situations where a multibyte structured stream contains bytes with OEM/legacy signatures. It turns out that these signatures overlap, which leads to incorrect encoding detection.

Fixed.
first post has been updated.

1 Like

@alexeydott
可以在xml配置文件中增加一个控制每种语法高亮的行距、缩进线的设置项么?
Can we add a setting item in the XML configuration file to control the line spacing and indentation of each syntax highlight?

1 Like

Unfortunately, no.
The UpperLineSpacing / LowerLineSpacing parameters currently relate to the editor configuration, not to Lexer (). Theoretically, if they are in the node, they can be read and changed Editor`s UpperLineSpacing / LowerLineSpacing parameters. but it's ugly.

Have I understood correctly what you want me to do: if the theme attributes include UpperLineSpacing and LowerLineSpacing, we simply apply them to the control. The same applies to the global and default attributes, with the former overriding the global setting and the latter applying to all.
Since NPP should ignore this, the result is an extension to the NPP theme format that ensures backwards compatibility. I right?

I tried adding support for additional ascents/descents as I mentioned.


But unfortunately it turns out badly. in the scintilla control architecture, it is not possible to depict lines of different heights. All lines must be the same height

All lines of text in Scintilla are the same height, and this height is calculated from the largest font in any current style. This restriction is for performance; if lines differed in height then calculations involving positioning of text would require the text to be styled first.

DOSrcVwr-test.zip (2.2 MB)
I'm attaching a version, but I don't think I'll leave this code. to maintain lineSpacings by style, we need to modify scintilla control itself by adding extraAscent/extraDescent to the Style class
Something like:

class Style : public FontSpecification, public FontMeasurements {
public:
    ColourRGBA fore;
    ColourRGBA back;
    bool eolFilled;
    bool underline;
    ...
    int extraAscent = 0;
    int extraDescent = 0;
};

But it affects too much. I don't think the higher-level Scintilla will accept such a patch without much discussion: the changes affect the layout model and change the API.

Can you add .txt to the preview list?
Because the default common text previewer cannot show line numbers,and its encoding detection is not very comprehensive.

such as :
CMakeLists.txt
xxx.js.txt

try adding “txt” to the desired lexers and restart dopus for the settings to take effect.
txt to cmake


and
"js.txt" as extention to javascript / js

1 Like

thank you!
I try this:
Associate txt to batch,
Associate js.txt to javascript,
the batch takes priority in taking effect.