Skip to content

Commit

Permalink
Merge af9cabf into 60b95d7
Browse files Browse the repository at this point in the history
  • Loading branch information
Omikhleia committed Jan 22, 2024
2 parents 60b95d7 + af9cabf commit d0c41cb
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
5 changes: 5 additions & 0 deletions documentation/c08-language.sil
Expand Up @@ -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.
Expand Down
29 changes: 29 additions & 0 deletions 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 =
{
Expand Down
23 changes: 23 additions & 0 deletions 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
13 changes: 13 additions & 0 deletions 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}

0 comments on commit d0c41cb

Please sign in to comment.