Skip to content

Commit

Permalink
feat(packages): Add watermark package and trigger from build variable
Browse files Browse the repository at this point in the history
Closes #154
  • Loading branch information
alerque committed Mar 16, 2024
1 parent cd3e3d0 commit 5cc8b60
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
49 changes: 49 additions & 0 deletions packages/watermark.lua
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
5 changes: 5 additions & 0 deletions rules/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,11 @@ $(FULLPDFS): %.pdf: $(BUILDDIR)/%.sil $$(call coverpreq,$$@) $$(call onpaperlibs
rm $*.tmp.pdf
fi

ifneq ($(WATERMARK),)
export CASILE_WATERMARK = $(WATERMARK)
$(FULLPDFS): SILEFLAGS += --use packages.watermark
endif

DISTFILES += $(FULLPDFS)

PANDOCTEMPLATE ?= $(CASILEDIR)/template.sil
Expand Down

0 comments on commit 5cc8b60

Please sign in to comment.