diff --git a/documentation/c08-language.sil b/documentation/c08-language.sil index 0b40c6b3b..2519db3b5 100644 --- a/documentation/c08-language.sil +++ b/documentation/c08-language.sil @@ -186,6 +186,11 @@ The size of these spaces is determined by \autodoc:setting[check=false]{languages.fr.colonspace} and \autodoc:setting[check=false]{languages.fr.guillspace}. +\subsection{Polish} + +According to Polish typography conventions, when a break occurs at an explicit hyphen, the hyphen gets repeated at the beginning of the new line. +SILE automatically handles this. + \subsection{Japanese / Chinese} SILE aims to conform with the W3G document “Requirements for Japanese Text Layout”\footnote{\url{https://www.w3.org/TR/jlreq/}} which describes the typographic conventions for Japanese (and also Chinese) text. diff --git a/languages/pl.lua b/languages/pl.lua index 63cdc794a..7a09c768c 100644 --- a/languages/pl.lua +++ b/languages/pl.lua @@ -1,3 +1,32 @@ +SILE.nodeMakers.pl = pl.class(SILE.nodeMakers.unicode) + +function SILE.nodeMakers.pl:handleWordBreak (item) + -- According to Polish rules, when a break occurs at an explicit hyphen, + -- the hyphen gets repeated at the beginning of the new line + if item.text == "-" then + self:addToken(item.text, item) + self:makeToken() + if self.lastnode ~= "discretionary" then + coroutine.yield(SILE.nodefactory.discretionary({ + postbreak = SILE.shaper:createNnodes("-", self.options) + })) + self.lastnode = "discretionary" + end + else + self._base.handleWordBreak(self, item) + end +end + +function SILE.nodeMakers.pl:handleLineBreak (item, subtype) + if self.lastnode == "discretionary" then + -- Initial word boundary after a discretionary: + -- Bypass it and just deal with the token. + self:dealWith(item) + else + self._base.handleLineBreak(self, item, subtype) + end +end + SILE.hyphenator.languages["pl"] = {} SILE.hyphenator.languages["pl"].patterns = { diff --git a/tests/fix-polish-hyphen.expected b/tests/fix-polish-hyphen.expected new file mode 100644 index 000000000..428d1a7f1 --- /dev/null +++ b/tests/fix-polish-hyphen.expected @@ -0,0 +1,23 @@ +Set paper size 209.7637818 297.6377985 +Begin page +Mx 162.4882 +My 26.9913 +Set font Gentium Plus;16;400;;normal;;;LTR +T 69 76 68 1146 82 16 w=37.7344 (biało-) +Mx 10.4882 +My 46.1913 +T 16 w=5.3906 (-) +Mx 15.8788 +T 70 93 72 85 90 82 81 92 w=63.5703 (czerwony) +Mx 130.4882 +My 65.3913 +T 69 76 68 1146 82 16 w=37.7344 (biało-) +Mx 168.2226 +T 70 93 72 85 w=27.5078 (czer) +Mx 195.7304 +T 16 w=5.3906 (-) +Mx 10.4882 +My 84.5913 +T 90 82 81 92 w=36.0625 (wony) +End page +Finish diff --git a/tests/fix-polish-hyphen.sil b/tests/fix-polish-hyphen.sil new file mode 100644 index 000000000..de95f961b --- /dev/null +++ b/tests/fix-polish-hyphen.sil @@ -0,0 +1,13 @@ +\begin[papersize=a7]{document} +\neverindent +\nofolios +\language[main=pl] +\font[size=16pt] + +% Breaks at existing hyphens get a hyphen on the next line +\kern[width=152pt]biało-czerwony + +% Breaks at other places just chill as usual +\kern[width=120pt]biało-czerwony + +\end{document}