Log in

View Full Version : Can AviSynth use/load/import a font file that isn't in Windows' Fonts folder?


Leo D9
15th March 2017, 01:29
Can AviSynth use/load/import a font file that isn't in Windows' Fonts folder?

I have the TTF file, which I would like to use for subtitles, but I would prefer other users of my script not to have to copy it into their Windows' Fonts folder. I don't want them to modify their system in any way other than installing AviSynth itself. Is there any way to load the font file in my script or by some other means?

Thanks.

sneaker_ger
15th March 2017, 01:38
https://forum.doom9.org/showthread.php?t=148926

Leo D9
17th March 2017, 13:31
Interesting to know about, and I guess it proves it could be done with an external plugin, but would I have to then write the text to a .ass file to be able to use this, rather than just passing it as a parameter? Also, I don't see how I can load a font file with this plugin, unless the ASS file itself can load the file or link to it. I've never used ASS.

I need to render title text that is generated within the script, with a specific font, rather than displaying normal subtitles from a file. It seems that assrender would be quite a laborious way to achieve this, or may not be able to load a font file at all. Also, it speaks about font caching - would that cache all the fonts on the user's system?

Basically I just want something that is equivalent to:

Subtitle("My text here", font_file="Font Name.ttf")

I may have to force the user to install the font on their system :/

Thanks.

Groucho2004
17th March 2017, 13:46
I may have to force the user to install the font on their systemCorrect.

For reference, documentation of "subtitle" parameters here (http://avisynth.nl/index.php/Subtitle).

There is a plugin called "SubtitleEx (http://avisynth.nl/index.php/External_filters#Subtitling)" but that just adds visual effects.

sneaker_ger
17th March 2017, 13:54
@Leo D9:
Read the assrender readme. srt with font from file instead of system is possible. Text directly in AviSynth script instead of subtitle file is not AFAIK. Maybe you can abuse some file writer plugin if you need that badly ...

ChaosKing
17th March 2017, 14:03
You can attach fonts with Aegi sub to .ass files. Tested with VSfiltermod.

Groucho2004
17th March 2017, 14:16
Maybe you can abuse some file writer plugin if you need that badly ...
Awkward but that would probably work. :cool:

pinterf
17th March 2017, 17:43
Interesting idea, and it was not was not much work to integrate it in Avisynth+, so it will appear in the next release. It will look like
Subtitle("Roboto Test", x=-1, y=50, font_width=0, font="Dancing Script1002", font_filename="DancingScript-Regular.ttf")
Subtitle("Roboto Test", x=-1, y=75, font_width=0, font="Dancing Script1002")
There was no need to load the font for the second SubTitle.

Leo D9
22nd March 2017, 03:23
Great that it is being included :) Thanks.

Any chance of text that can be centred vertically as well as horizontally? (e.g. if over several lines using \n )

StainlessS
22nd March 2017, 15:33
Perhaps this can be hacked, just add font_filename arg to func, and pass it on to the Subtitle call.


#Avisource("D:\avs\test.avi")
Colorbars.killaudio
Function Sub(clip c, string text, float "x", float "y", int "first_frame", int "last_frame", string "font", float "size", \
int "text_color", int "halo_color", int "align", int "spc", int "lsp", float "font_width", float "font_angle", bool "interlaced", \
bool "vcenter") {
c
GScript("""
size=Default(size,18)
vcenter=Default(vcenter,false)
if(vcenter && Defined(align) && Defined(lsp) && (align>=4 && align<=6)) {
s=RT_StrReplace(text,"\n",Chr(10),Sig=false) # Replace String case Insignificant
Lines = RT_TxtQueryLines(s) # Line count with/without final newline
y=(Height/2) - ((Lines-1) * size / 2.0)
}
""")
Subtitle(text,x,y,first_frame,last_frame,font,size,text_color,halo_color,align,spc,lsp,font_width,font_angle,interlaced)
}

VC=True
#VC=False

S="The\nQuick\nBrown\nfox\njumped\nover\nthe\nlazy\ndog.\nThe\nQuick\nBrown\nfox\njumped\nover\nthe\nlazy\ndog.\n"

Sub(S,lsp=0,align=4,vcenter=VC)
Sub(S,lsp=0,align=5,vcenter=VC)
Sub(S,lsp=0,align=6,vcenter=VC)