-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimum fit line breaking and hyphenation
This updates to the newest version of boxes and glue and has some documentation. Now implemented the optimum line breaking algorithm from Donald E. Knuth and Michael F. Plass and the hyphenation algorithm by Frank Liang.
- Loading branch information
Showing
10 changed files
with
363 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# ETS Experimental typesetting system | ||
# ets Experimental typesetting system | ||
|
||
This software repository contains a Lua frontend for the typesetting library [“Boxes and Glue”](https://github.com/speedata/boxesandglue) which is an algorithmic typesetting machine in the spirits of TeX. | ||
|
||
|
@@ -36,62 +36,64 @@ Contact: Patrick Gundlach <[email protected]> | |
## Sample code | ||
|
||
```lua | ||
-- The document d is the central point for all | ||
function CreateFontVlist(d) | ||
local face, msg = d.loadFace("fonts/CrimsonPro-Regular.ttf") | ||
if not face then | ||
print(msg) | ||
os.exit(-1) | ||
end | ||
local fnt = d.createFont(face,document.sp("12pt")) | ||
-- This is still a very vey early preview and will probably not work when | ||
-- you experiment with the code. | ||
-- | ||
-- Two functions for fonts and for images just to show how to | ||
-- create objects and output them. | ||
|
||
local lang_en, msg = d.loadpattern("hyphenationpatterns/hyph-en-us.pat.txt") | ||
if not lang_en then | ||
print(msg) | ||
os.exit(-1) | ||
end | ||
document.info("Reading myfile.lua") | ||
|
||
lang_en.name = "en" | ||
local ok, face, msg, fnt, lang_en, imgfile, image | ||
|
||
function CreateFontVlist(d) | ||
local lang = node.new("lang") | ||
lang.lang = lang_en | ||
|
||
local tbl = fnt.shape("the quick brown fox jumps over the lazy dog") | ||
local tbl = fnt.shape([[In olden times when wishing still helped one, there lived a king whose daughters | ||
were all beautiful; and the youngest was so beautiful that the sun itself, which | ||
has seen so much, was astonished whenever it shone in her face. | ||
Close by the king's castle lay a great dark forest, and under an old lime-tree in the forest | ||
was a well, and when the day was very warm, the king's child went out into the | ||
forest and sat down by the side of the cool fountain; and when she was bored she | ||
took a golden ball, and threw it up on high and caught it; and this ball was her | ||
favorite plaything.]]) | ||
|
||
|
||
local head, cur = lang, lang | ||
for _, glyph in ipairs(tbl) do | ||
if glyph.glyph == 32 then | ||
local glu = node.new("glue") | ||
glu.width = fnt.space | ||
glu.stretch = fnt.stretch | ||
glu.shrink = fnt.shrink | ||
head = node.insertafter(head,cur,glu) | ||
cur = glu | ||
else | ||
local g = node.new("glyph") | ||
g.width = glyph.advance | ||
g.codepoint = glyph.codepoint | ||
g.components = glyph.components | ||
g.font = glyph.font | ||
g.hyphenate = glyph.hyphenate | ||
head = node.insertafter(head,cur,g) | ||
cur = g | ||
end | ||
end | ||
|
||
local hlist = node.hpack(head) | ||
d.hyphenate(head) | ||
node.append_lineend(cur) | ||
|
||
local param = { | ||
hsize = document.sp("200pt"), | ||
hsize = document.sp("134pt"), | ||
lineheight = document.sp("12pt"), | ||
} | ||
|
||
local vl = node.simplelinebreak(hlist,param) | ||
local vl = node.linebreak(head,param) | ||
return vl | ||
end | ||
|
||
local function CreateImageVlist(d) | ||
local imgfile = d.loadimagefile("img/ocean.pdf") | ||
local image = d.createimage(imgfile) | ||
|
||
|
||
image = d.createimage(imgfile) | ||
local imagenode = node.new("image") | ||
imagenode.img = image | ||
imagenode.width = document.sp("4cm") | ||
|
@@ -101,21 +103,38 @@ local function CreateImageVlist(d) | |
return vlist | ||
end | ||
|
||
|
||
-- The document d is the most important item here. | ||
local d = document.new("out.pdf") | ||
|
||
face, msg = d.loadFace("fonts/CrimsonPro-Regular.ttf") | ||
if not face then | ||
print(msg) | ||
os.exit(-1) | ||
end | ||
|
||
fnt = d.createFont(face,document.sp("12pt")) | ||
|
||
lang_en, msg = d.loadpattern("hyphenationpatterns/hyph-en-us.pat.txt") | ||
if not lang_en then | ||
print(msg) | ||
os.exit(-1) | ||
end | ||
|
||
lang_en.name = "en" | ||
imgfile = d.loadimagefile("img/ocean.pdf") | ||
|
||
local fontVL = CreateFontVlist(d) | ||
local imageVL = CreateImageVlist(d) | ||
|
||
d.outputat(document.sp("4cm"),document.sp("27cm"),fontVL) | ||
d.outputat(document.sp("4cm"),document.sp("26cm"),imageVL) | ||
d.outputat(document.sp("12cm"),document.sp("27cm"),imageVL) | ||
d.currentpage().shipout() | ||
|
||
|
||
local ok, msg = d.finish() | ||
ok, msg = d.finish() | ||
if not ok then | ||
print(msg) | ||
os.exit(-1) | ||
end | ||
|
||
document.info("Reading myfile.lua...done") | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.