Typed arguments, calculated tables, spans, closed-world fonts, top-level fnt/ and env/
Sync with klammertext-dev through b90b0e09: - Argument types end to end: :python_cast values are applied (Python @eval receives real bools/numbers/lists), argument values are validated against their argtype patterns with the argtype's description as the error message, argtypes can declare :default (overridable per declaration), and parameterized type families are supported: rest(N) casts a rest argument to an N-dimensional list (bar-count = dimension). - Unified indexed_range syntax (selector with parenthesized subsets, composable mnemonic names) for table lines and spans. - Table klammer: caption fonts fixed in both targets, :column_width / :leading / :colsep wired, :colspan and :rowspan render (HTML attributes; \multicolumn / \multirow), calculated cell values (:calc) with prefix operators, display-precision semantics, :calc_format and :decimal period|comma. - Fonts: closed-world resolution on the Klammertext font store (infrastructure in mac/font_store; no Google Fonts links or fetch). Default fonts live in the top-level fnt/; additional fonts install into KLAMMERTEXT_FONTS directories via kdesc --font (list, samples, preview, install — classification by font metadata). CSS font family names are quoted (digit-initial families were silently lost). - Environment files moved from mac/env/ to the top-level env/; shell profiles source env/runtime.env. Dead per-host variants removed. - Container: fnt/ ships in the image; curl removed (no network use).
This commit is contained in:
@@ -1,19 +1,25 @@
|
||||
import re
|
||||
|
||||
import border
|
||||
import font
|
||||
import html_util
|
||||
from html_util import E
|
||||
|
||||
# A purely numeric cell value (either decimal-mark style, optional sign).
|
||||
number_rgx = re.compile(r"[-+]?[\d.,]+$")
|
||||
|
||||
class Cell:
|
||||
def __init__(self, text, font, hpos,
|
||||
top, right, bottom, left,
|
||||
left_all, right_all,
|
||||
rowspan, colspan):
|
||||
rowspan, colspan, first_column=False):
|
||||
self.text = text
|
||||
self.font = font
|
||||
self.hpos = hpos
|
||||
self.border = border.Border(top, right, bottom, left, left_all, right_all)
|
||||
self.rowspan = rowspan
|
||||
self.colspan = colspan
|
||||
self.first_column = first_column
|
||||
#print("Cell:", text, hpos)
|
||||
|
||||
def __str__(self):
|
||||
@@ -30,6 +36,10 @@ class Cell:
|
||||
def html(self):
|
||||
result = self.text
|
||||
result = E("td").body(font.html_fontify(result, self.font, 1.0))
|
||||
if self.rowspan > 1:
|
||||
result.attr("rowspan", self.rowspan)
|
||||
if self.colspan > 1:
|
||||
result.attr("colspan", self.colspan)
|
||||
for pred, cls_name in zip(self.border.has(), "Bt Br Bb Bl".split()):
|
||||
if pred:
|
||||
result.cls(cls_name)
|
||||
@@ -38,8 +48,26 @@ class Cell:
|
||||
|
||||
def tex(self, debug=False): # , left_line, right_line):
|
||||
result = self.text
|
||||
# A number must not line-break (LaTeX breaks after a minus sign
|
||||
# read as a hyphen in narrow fit-width columns).
|
||||
if number_rgx.match(result.strip()):
|
||||
result = f"\\mbox{{{result.strip()}}}"
|
||||
if self.font != "r":
|
||||
result = font.tex_fontify(result, self.font, 1.0)
|
||||
if self.rowspan > 1:
|
||||
result = f"\\multirow{{{self.rowspan}}}{{*}}{{{result}}}"
|
||||
if self.colspan > 1:
|
||||
# \multicolumn carries the merged cell's own column spec. A
|
||||
# left bar may only be given when the span starts at the
|
||||
# table's first column: elsewhere the bar to the left belongs
|
||||
# to the preceding column's preamble entry, and adding one
|
||||
# here draws a doubled line.
|
||||
pos = self.hpos
|
||||
if self.border.left and self.first_column:
|
||||
pos = "|" + pos
|
||||
if self.border.right:
|
||||
pos = pos + "|"
|
||||
return f"\\multicolumn{{{self.colspan}}}{{{pos}}}{{{result}}}"
|
||||
remove_left = self.border.left_all and not self.border.left
|
||||
remove_right = self.border.right_all and not self.border.right
|
||||
if debug:
|
||||
|
||||
Reference in New Issue
Block a user