AviSynth / AviSynthPlus

AviSynth with improvements
http://avs-plus.net
977 stars 75 forks source link

Inconsistent alignment with Text(align=5) #368

Closed flossy83 closed 11 months ago

flossy83 commented 1 year ago

There is a small issue which is making it difficult for me to align my debug text vertically on screen due to some quirk of Text(align=5) where if I concatenate another "\n" to the string being displayed, it shifts the whole string up by 1 line.

SubTitle() doesn't exhibit this behaviour, but is too CPU intensive for my needs. Example below:

ColorBars().KillAudio()

ScriptClip(last, 
\ """
    string = "\n\n" + "Line 1"

    # add line 2 every other frame
    if (Fmod(current_frame, 2) == 0){ string = string + "\n" + "Line 2" }

    # works as expected - line 1 retains its vertical position for all frames
    SubTitle(string, align=5, lsp=0) 

    # doesn't work as expected - line 1 gets shifted up a line for frames when line 2 is added 
    # Text(string, align=5, lsp=0)  

\ """ , after_frame=true, local=false)

The workaround I'm using currently is to add another "\n" to the beginning of line 1, but I have no idea why that works.

flossy83 commented 1 year ago

It appears the issue is that SubTitle(align=5) doesn't try to align the whole string vertically whereas Text(align=5) does.

Perhaps it could be argued that SubTitle should behave like Text instead of vice versa, if the intention of align=5 is to align the entire string in the center of the screen. Although the documentation says "Note there is no Y-center alignment setting".

https://avisynthplus.readthedocs.io/en/latest/avisynthdoc/corefilters/subtitle.html

pinterf commented 1 year ago

Text is a totally different filter from the existing SubTitle and was written to somehow mimic some SubTitle functionality on Linux, where no Windows GDI exists. But yes, it should work in a consistent way. As for the documentation, I don't get it either: "Note there is no Y-center alignment setting.". (Subtitle's documentation must be rewritten, there are many additions and fixes there)

pinterf commented 1 year ago

edit: The multiline (lsp is defined) vertical alignment in Text was intended to do a proper and fine vertical alignment: it would center the whole text block vertically. E.g. for 3 lines it would position at the 1.5 line position. But due to rounding issues it did not perform this task properly. In this regard it is (and was) different from SubTitle, which seems to ignore the multilineness of the text and calculates the vertical center position as if it was a one line text. Second, third, etc.. lines are displayed below the center positioned first line.

kedaitinh12 commented 1 year ago

Check fix ver: https://forum.doom9.org/showthread.php?p=1993152#post1993152

pinterf commented 11 months ago

I'm closing this as the feature was partly fixed and the rest is (hopefully) consistently implemented.