-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(packages): Add watermark package and trigger from build variable
Closes #154
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
local base = require("packages.base") | ||
|
||
local package = pl.class(base) | ||
package._name = "watermark" | ||
|
||
local text = os.getenv("CASILE_WATERMARK") or "DRAFT" | ||
|
||
function package:_init(options) | ||
if options.text then text = options.text end | ||
base._init(self, options) | ||
self:loadPackage("rotate") | ||
self.class:registerHook("newpage", self.addWatermark) | ||
self:addWatermark() | ||
end | ||
|
||
function package:addWatermark () | ||
local page = SILE.getFrame("page") | ||
local frame = SILE.newFrame({ | ||
id = "watermark", | ||
left = "left(page)+20", | ||
right = "right(page)-20", | ||
top = "top(page)+20", | ||
bottom = "bottom(page)-20" | ||
}) | ||
SILE.documentState.thisPageTemplate.frames.watermark = frame | ||
SILE.typesetNaturally(frame, SILE.Commands["watermark:content"]) | ||
end | ||
|
||
function package:registerCommands () | ||
|
||
SILE.registerCommand("watermark:content", function (_, _) | ||
SILE.call("hbox") | ||
SILE.call("skip", { height = "20%fh" }) | ||
SILE.call("center", {}, function () | ||
SILE.call("color", { color = "#fafafa" }, function () | ||
SILE.call("rotate", { angle = -35 }, function () | ||
SILE.call("font", { family = "TeX Gyre Heros", weight = 900, size = "8%fw" }, { text }) | ||
end) | ||
SILE.call("skip", { height = "20%fh" }) | ||
SILE.call("rotate", { angle = -35 }, function () | ||
SILE.call("font", { family = "TeX Gyre Heros", weight = 900, size = "8%fw" }, { text }) | ||
end) | ||
end) | ||
end) | ||
end) | ||
|
||
end | ||
|
||
return package |
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