[scribus] Script for (french) thin typographic spaces
JLuc
jluc at no-log.org
Tue Jun 2 16:09:11 UTC 2020
Le 02/06/2020 à 14:57, Victor / tokiop a écrit :
> Utf8 and regex is a bit tricky, not sure it is optimal as is, but thin space is correctly replaced before "»", which is not the case if utf8/regex is messed up.
AMOF Autoquotes script also manages spaces around " and « and »
but it's interesting to read how you do so using regexps rather than parsing.
What misses is adding (or changing spaces into) thin non breakable spaces before ! ; ? :
and after some glyphs also.
JLuc
>
> It only replace existing spaces with thin spaces, does not add missing spaces. Also, formatting will probably be lost, maybe autoquote does things better to prevent this, didn't check yet.
>
> Hope it can help, will be interested in a solid function too !
>
> Victor
>
> ---- 8< ----
> #!/usr/bin/env python3
> # -*- coding: utf-8 -*-
>
> import re
>
> thin_space = u"\u2009"
> thin_nbsp = u"\u202F"
>
> thin_before = "!?;:%»)"
> re_thin_before = re.compile(ur'\s([%s])'%thin_before)
>
> thin_after = "«("
> re_thin_after = re.compile(ur'([%s])\s'%thin_after)
>
> def traitement_typo(text) :
> text = re_thin_before.sub(thin_nbsp+ur"\1", text)
> text = re_thin_after.sub(ur"\1"+thin_nbsp, text)
> return text
>
> def main() :
> frame = scribus.getSelectedObject(0)
> text = scribus.getAllText(frame).decode("utf-8")
> scribus.setText(traitement_typo(text), frame)
>
> main()
>
> ___
> Scribus Mailing List: scribus at lists.scribus.net
> Edit your options or unsubscribe:
> http://lists.scribus.net/mailman/listinfo/scribus
> See also:
> http://wiki.scribus.net
> http://forums.scribus.net
>
More information about the scribus
mailing list