Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed May 10, 2024
2 parents 0da75b8 + ee18a0c commit 3de470d
Show file tree
Hide file tree
Showing 20 changed files with 622 additions and 355 deletions.
309 changes: 170 additions & 139 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ futures = "0.3"
itertools = "0.12"
lazy_static = "1.4"
num_cpus = "1.16"
rayon = "1.8"
rayon = "1.10"
rust-embed = "8.3"
rustc-hash = "1.1"
subprocess = "0.2"
Expand Down
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ nobase_data_DATA = rules/casile.mk $(reverse_lang_key_files)
nobase_dist_data_DATA = rules/rules.mk rules/functions.mk rules/translation.mk rules/utilities.mk $(lang_key_files)
nobase_dist_data_DATA += rules/ebooks.mk rules/mdbook.mk rules/renderings.mk rules/zola.mk
nobase_dist_pkgdata_DATA = $(LUALIBRARIES)
_casile_libs = src/lib.rs src/cli.rs src/config.rs src/i18n.rs src/tui.rs
_casile_libs = src/lib.rs src/cli.rs src/config.rs src/i18n.rs src/ui.rs src/ui_indicatif.rs src/ui_ascii.rs
_casile_modules = src/make/mod.rs src/run/mod.rs src/setup/mod.rs src/status/mod.rs
_casile_assets = assets/en-US/cli.ftl assets/tr-TR/cli.ftl
bin_PROGRAMS = casile
Expand Down
2 changes: 1 addition & 1 deletion classes/cabinding.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function class:declareOptions ()
if size then
self.papersize = size
local parsed = SILE.papersize(size)
if binding == "print" or CASILE.layout == "print" then
if binding == "print" or CASILE.binding == "print" then
self.defaultFrameset = posterFrameset
SILE.documentState.paperSize = { parsed[1], parsed[2] }
else
Expand Down
12 changes: 7 additions & 5 deletions classes/cabook.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,19 @@ function class:declareOptions ()
end

function class:setOptions (options)
options.binding = options.binding or "print" -- print, paperback, hardcover, coil, stapled
options.binding = options.binding or CASILE.binding or "print" -- print, paperback, hardcover, coil, stapled
-- Set binding first if we have it so that the layout can adapt the papersize based on the binding
self.options.binding = options.binding
options.crop = options.crop or (options.binding ~= "print")
options.background = options.background or true
options.verseindex = options.verseindex or false
options.layout = options.layout or CASILE.layout or "a4"
-- Set layout first because it resets paper size. If we don't a random race
-- Set layout next because it resets paper size. If we don't a random race
-- condition picks the default papersize *or* our layout to be set first.
options.layout = options.layout or CASILE.layout or "a4"
self.options.layout = options.layout
-- Now set the rest but with the papersize reset to whatever layout wanted
options.papersize = self.options.papersize
options.layout = nil
options.background = options.background or true
options.verseindex = options.verseindex or false
book.setOptions(self, options)
end

Expand Down
2 changes: 1 addition & 1 deletion cover.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<sile class="cabinding" crop="false" background="false">
<sile class="cabinding" binding="print" crop="false" background="false">
<nofolios />
<frontcover />
</sile>
33 changes: 20 additions & 13 deletions layouts/cep.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,39 @@ return function (class)

if class._name == "cabook" then

class:loadPackage("masters", {{
id = "right",
firstContentFrame = "content",
frames = {
content = {
class.defaultFrameset = {
content = {
left = "left(page) + 20mm",
right = "right(page) - 10mm",
top = "top(page) + 20mm",
bottom = "top(footnotes)"
},
runningHead = {
},
runningHead = {
left = "left(content)",
right = "right(content)",
top = "top(content) - 10mm",
bottom = "top(content) - 2mm"
},
footnotes = {
},
footnotes = {
left = "left(content)",
right = "right(content)",
height = "0",
bottom = "bottom(page) - 15mm"
}
}
}})
},
}

SILE.setCommandDefaults("imprint:font", { size = "7pt" })
class:registerPostinit(function (_)
SILE.setCommandDefaults("imprint:font", { size = "7pt" })
end)

-- Hack to avoid SILE bug in print editions
-- See https://github.com/simoncozens/sile/issues/355
class:registerCommand("href", function (options, content)
if class.options.verseindex then
SILE.call("markverse", options, content)
end
SILE.process(content)
end)

end

Expand Down
1 change: 1 addition & 0 deletions layouts/square.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
return function (class)

class.options.binding = "print"
class.options.papersize = 1024 / 300 .. "in x " .. 1024 / 300 .. "in"

end
14 changes: 12 additions & 2 deletions packages/cabook-commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ local spreadHook = function ()
spread_counter = spread_counter + 1
end

local _requireSpaceSamePage
local function _abortRequireSpace ()
_requireSpaceSamePage = false
end

function package:_init ()
base._init(self)
self.class:registerHook("newpage", spreadHook)
self.class:registerHook("newpage", _abortRequireSpace)
end

function package:registerCommands ()
Expand Down Expand Up @@ -599,14 +605,18 @@ function package:registerCommands ()
end, "Output publication dates in proper format for imprint page")

self:registerCommand("requireSpace", function (options, content)
_requireSpaceSamePage = true
local required = SILE.length(options.height or 0)
SILE.typesetter:leaveHmode()
SILE.call("hbox", {}, content) -- push content we want to fit
local heightOfPageSoFar = SILE.pagebuilder:collateVboxes(SILE.typesetter.state.outputQueue).height
local heightOfFrame = SU.cast("length", SILE.typesetter.frame:height())
local heightOfPageSoFar = SILE.pagebuilder:collateVboxes(SILE.typesetter.state.outputQueue).height
table.remove(SILE.typesetter.state.nodes) -- steal it back
SILE.typesetter:leaveHmode()
if heightOfFrame - heightOfPageSoFar < required then
SILE.call("supereject")
if _requireSpaceSamePage then
SILE.call("supereject")
end
end
end)

Expand Down
2 changes: 1 addition & 1 deletion rules/functions.mk
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ define magick_crease ?=
-blur 0x$(call scale,$(call mmtopx,0.2)) \
-level "0x40%!" \
\) \
-compose Divide -composite
-compose Difference -composite
endef

define magick_fray ?=
Expand Down
20 changes: 18 additions & 2 deletions rules/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ MOCKUPFACTOR ?= 1
FIGURES ?=

# Default output formats and parameters (often overridden)
FORMATS ?= pdfs epub mobi odt docx mdbook zola $(and $(ISBNS),play) app html
FORMATS ?= manifest pdfs epub mobi odt docx mdbook zola $(and $(ISBNS),play) app html
BLEED ?= 3
TRIM ?= 10
NOBLEED ?= 0
Expand Down Expand Up @@ -275,12 +275,18 @@ endef

$(foreach FORMAT,$(FORMATS),$(eval $(call format_template,$(FORMAT),$(TARGETS))))

VIRTUALMANIFESTS := $(call pattern_list,$(SOURCES),.manifest)
.PHONY: $(VIRTUALMANIFESTS)
$(VIRTUALMANIFESTS): %.manifest: %-manifest.yml

VIRTUALPDFS := $(call pattern_list,$(SOURCES),.pdfs)
VIRTUALEDITPDFS := $(and $(EDITS),$(call pattern_list,$(SOURCES),$(EDITS),.pdfs))
.PHONY: $(VIRTUALPDFS) $(VIRTUALEDITPDFS)
$(VIRTUALPDFS) $(VIRTUALEDITPDFS): %.pdfs: $(call pattern_list,$$*,$(LAYOUTS),.pdf)
$(VIRTUALPDFS): %.pdfs: $(and $(EDITIONS),$(call pattern_list,$$*,$(EDITIONS),$(LAYOUTS),.pdf))
$(VIRTUALEDITPDFS): %.pdfs: $$(and $(EDITIONS),$(EDITS),$$(call pattern_list,$$(call parse_bookid,$$*),$(EDITIONS),$(EDITS),$(LAYOUTS),.pdf))
ACTIVEBOUNDLAYOUTS = $(filter $(BOUNDLAYOUTS),$(LAYOUTS))
$(VIRTUALPDFS): %.pdfs: $(and $(ACTIVEBOUNDLAYOUTS),$(call pattern_list,$$*,$(ACTIVEBOUNDLAYOUTS),$(_cropped),.pdf))

# Setup target dependencies to mimic stages of a CI pipeline
ifeq ($(MAKECMDGOALS),ci)
Expand Down Expand Up @@ -314,8 +320,12 @@ $(VIRTUALPROMOTIONALS): %.promotionals: $(call pattern_list,$$*,$(PLACARDS),-$(_
ifneq ($(words $(TARGETS)),1)
promotionals: series_promotionals
renderings: series_renderings
manifest: series_manifest
endif

.PHONY: series_manifest
series_manifest: $(call pattern_list,$(PROJECT),manifest,.yml)

.PHONY: series_promotionals
series_promotionals: $(PROJECT)-epub-$(_poster)-$(_montage).jpg $(PROJECT)-$(_square)-$(_poster)-$(_montage).jpg

Expand Down Expand Up @@ -712,7 +722,7 @@ $(COVERPDFS): $(BUILDDIR)/%-$(_cover).pdf: $(BUILDDIR)/%-$(_cover).png $(BUILDDI
+repage \
$$bg
$(PDFTK) $(filter %.pdf,$^) cat 1 output $$text
$(PDFTK) $$text background $$bg output $@
$(PDFTK) $$text stamp $$bg output $@

BINDINGFRAGMENTS := $(addprefix $(BUILDDIR)/,$(call pattern_list,$(EDITIONEDITSOURCES),$(BOUNDLAYOUTS),-$(_binding)-$(_text).pdf))
$(BINDINGFRAGMENTS): .EXTRA_PREREQS = $(LUAINCLUDES)
Expand All @@ -727,6 +737,7 @@ $(BINDINGFRAGMENTS): $(BUILDDIR)/%-$(_binding)-$(_text).pdf:
local metadatafile = "$(filter %-manifest.yml,$^)"
CASILE.metadata = require("readmeta").load(metadatafile)
CASILE.layout = "$(or $(__$(call parse_papersize,$@)),$(call parse_papersize,$@))"
CASILE.binding = "$(or $(__$(call parse_binding,$@)),$(call parse_binding,$@))"
CASILE.language = "$(LANGUAGE)"
CASILE.spine = "$(call spinemm,$(filter %.pdf,$^))mm"
return { _name = "$*", type = "casile" }
Expand Down Expand Up @@ -788,6 +799,7 @@ $(COVERFRAGMENTS): $(BUILDDIR)/%-$(_text).pdf:
local metadatafile = "$(filter %-manifest.yml,$^)"
CASILE.metadata = require("readmeta").load(metadatafile)
CASILE.layout = "$(or $(__$(call parse_papersize,$@)),$(call parse_papersize,$@))"
CASILE.binding = "$(or $(__$(call parse_binding,$@)),$(call parse_binding,$@))"
CASILE.language = "$(LANGUAGE)"
return { _name = "casile", type = "casile" }
EOF
Expand Down Expand Up @@ -899,6 +911,7 @@ $(EMPTYGEOMETRIES): $(BUILDDIR)/$(_geometry)-%.pdf: $(CASILEDIR)/geometry.xml |
cat <<- EOF > $(BUILDDIR)/$*.lua
CASILE.versioninfo = "$(call versioninfo,$@)"
CASILE.layout = "$(or $(__$(call parse_papersize,$@)),$(call parse_papersize,$@))"
CASILE.binding = "$(or $(__$(call parse_binding,$@)),$(call parse_binding,$@))"
CASILE.language = "$(LANGUAGE)"
return { _name = "$*", type = "casile" }
EOF
Expand Down Expand Up @@ -1110,9 +1123,12 @@ $(BUILDDIR)/%-$(_barcode).png: $(BUILDDIR)/%-$(_barcode).svg
$< \
-bordercolor white -border 10 \
-font Hack-Regular -pointsize 72 \
-fill black \
label:" ISBN $(shell $(_ENV) isbn_format.py $*-manifest.yml paperback mask)" +swap -gravity Center -append \
-bordercolor white -border 0x10 \
-resize $(call scale,1200)x \
-alpha off \
-fill '#fffffe' -draw 'point 2,2' \
$@
if [[ $(shell $(_ENV) isbn_format.py $*-manifest.yml paperback) == 9786056644504 ]]; then
$(MAGICK) \
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ use std::{error, fmt, path, result, str};
pub mod cli;
pub mod config;
pub mod i18n;
pub mod tui;
pub mod ui;
pub mod ui_ascii;
pub mod ui_indicatif;

// Subcommands
pub mod make;
Expand Down
7 changes: 3 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use clap::{Args, Command, FromArgMatches as _};

use casile::cli::{Cli, Commands};
use casile::config::CONF;
use casile::tui::*;
use casile::ui::{UserInterface, CASILEUI};
use casile::{make, run, setup, status};
use casile::{Result, VERSION};

Expand All @@ -15,15 +15,14 @@ fn main() -> Result<()> {
let matches = cli.get_matches();
let args = Cli::from_arg_matches(&matches).expect("Unable to parse arguments");
CONF.merge_args(&args)?;
let command_status = CommandStatus::new();
command_status.welcome();
CASILEUI.welcome();
let subcommand = Commands::from_arg_matches(&matches)?;
let ret = match subcommand {
Commands::Make { target } => make::run(target),
Commands::Run { name, arguments } => run::run(name, arguments),
Commands::Setup {} => setup::run(),
Commands::Status {} => status::run(),
};
command_status.farewell();
CASILEUI.farewell();
ret
}
40 changes: 10 additions & 30 deletions src/make/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::i18n::LocalText;
use crate::tui::*;
use crate::ui::*;
use crate::*;

use console::style;
use indicatif::{ProgressBar, ProgressStyle};
use regex::Regex;
use std::collections::HashMap;
use std::io::prelude::*;
Expand All @@ -13,9 +12,8 @@ use subprocess::{Exec, ExitStatus, Redirection};
// FTL: help-subcommand-make
/// Build specified target(s)
pub fn run(target: Vec<String>) -> Result<()> {
let subcommand_status = SubcommandStatus::new("status-header", "status-good", "status-bad");
setup::is_setup(subcommand_status)?;
let subcommand_status = SubcommandStatus::new("make-header", "make-good", "make-bad");
setup::is_setup()?;
let subcommand_status = CASILEUI.new_subcommand("make");
let mut makeflags: Vec<OsString> = Vec::new();
let cpus = &num_cpus::get().to_string();
makeflags.push(OsString::from(format!("--jobs={cpus}")));
Expand Down Expand Up @@ -96,7 +94,7 @@ pub fn run(target: Vec<String>) -> Result<()> {
"CASILE" => match fields[1] {
"PRE" => {
let target = fields[2].to_owned();
let target_status = MakeTargetStatus::new(target.clone());
let target_status = CASILEUI.new_target(target.clone());
target_statuses.insert(target, target_status);
}
"STDOUT" => {
Expand Down Expand Up @@ -182,27 +180,27 @@ pub fn run(target: Vec<String>) -> Result<()> {
|| targets.contains(&"debug".into())
|| targets.contains(&"-p".into())
{
dump_backlog(&backlog)
subcommand_status.dump(&backlog)
};
Ok(())
}
1 => {
dump_backlog(&backlog);
subcommand_status.dump(&backlog);
Err(Box::new(io::Error::new(
io::ErrorKind::InvalidInput,
LocalText::new("make-error-unfinished").fmt(),
)))
}
2 => {
dump_backlog(&backlog);
subcommand_status.dump(&backlog);
Err(Box::new(io::Error::new(
io::ErrorKind::InvalidInput,
LocalText::new("make-error-build").fmt(),
)))
}
3 => {
if !CONF.get_bool("verbose")? {
dump_backlog(&backlog);
subcommand_status.dump(&backlog);
}
Err(Box::new(io::Error::new(
io::ErrorKind::InvalidInput,
Expand All @@ -211,15 +209,15 @@ pub fn run(target: Vec<String>) -> Result<()> {
}
137 => {
if !CONF.get_bool("verbose")? {
dump_backlog(&backlog);
subcommand_status.dump(&backlog);
}
Err(Box::new(io::Error::new(
io::ErrorKind::InvalidInput,
LocalText::new("make-error-oom").fmt(),
)))
}
_ => {
dump_backlog(&backlog);
subcommand_status.dump(&backlog);
Err(Box::new(io::Error::new(
io::ErrorKind::InvalidInput,
LocalText::new("make-error-unknown").fmt(),
Expand All @@ -235,21 +233,3 @@ pub fn run(target: Vec<String>) -> Result<()> {
subcommand_status.end(ret.is_ok());
Ok(ret?)
}

fn dump_backlog(backlog: &[String]) {
let bar = ProgressBar::new_spinner().with_style(ProgressStyle::with_template("{msg}").unwrap());
let bar = TUI.add(bar);
let mut dump = String::new();
let start = LocalText::new("make-backlog-start").fmt();
let start = format!("{} {start}\n", style(style("┄┄┄┄┄┄").cyan()));
dump.push_str(start.as_str());
for line in backlog.iter() {
dump.push_str(line.as_str());
dump.push('\n');
}
let end = LocalText::new("make-backlog-end").fmt();
let end = format!("{} {end}", style(style("┄┄┄┄┄").cyan()));
dump.push_str(end.as_str());
bar.set_message(dump);
bar.finish();
}
Loading

0 comments on commit 3de470d

Please sign in to comment.