diff --git a/kuhy_credit/README.md b/kuhy_credit/README.md index 61fbb5b..87eb4c4 100644 --- a/kuhy_credit/README.md +++ b/kuhy_credit/README.md @@ -42,7 +42,7 @@ Nothing loads over the network and nothing opens without a click. ```jsonc // package.json -"@kuhyx/kuhy-credit": "github:kuhyx/utils#kuhy-credit-v0.2.0&path:kuhy_credit/web" +"@kuhyx/kuhy-credit": "github:kuhyx/utils#kuhy-credit-v0.3.0&path:kuhy_credit/web" ``` ```html @@ -68,7 +68,7 @@ dependencies: kuhy_credit: git: url: https://github.com/kuhyx/utils - ref: kuhy-credit-v0.2.0 + ref: kuhy-credit-v0.3.0 path: kuhy_credit/flutter ``` @@ -85,7 +85,7 @@ app on Android). Back closes an open panel. Demo: `flutter/example`. ```bash cache="$(mktemp -d)" -git clone --depth 1 --branch kuhy-credit-v0.2.0 https://github.com/kuhyx/utils "$cache" +git clone --depth 1 --branch kuhy-credit-v0.3.0 https://github.com/kuhyx/utils "$cache" cp -r "$cache/kuhy_credit/godot/addons/kuhy_credit" addons/ ``` @@ -101,7 +101,7 @@ The script opens the site with `OS.shell_open`. Demo: ## Python / Tkinter ```bash -pip install "kuhy-credit @ git+https://github.com/kuhyx/utils@kuhy-credit-v0.2.0#subdirectory=kuhy_credit" +pip install "kuhy-credit @ git+https://github.com/kuhyx/utils@kuhy-credit-v0.3.0#subdirectory=kuhy_credit" ``` ```python @@ -122,7 +122,7 @@ vector TikZ, no image file) and makes it a link to the site. No words appear. ```bash # vendor the generated package from the tag, like the Godot addon cache="$(mktemp -d)" -git clone --depth 1 --branch kuhy-credit-v0.2.0 https://github.com/kuhyx/utils "$cache" +git clone --depth 1 --branch kuhy-credit-v0.3.0 https://github.com/kuhyx/utils "$cache" cp "$cache/kuhy_credit/latex/kuhy-credit.sty" kuhy-credit/ TEXINPUTS="$PWD/kuhy-credit//:" pdflatex doc.tex ``` @@ -133,7 +133,9 @@ TEXINPUTS="$PWD/kuhy-credit//:" pdflatex doc.tex \fancyfoot[R]{\kuhycredit} % \kuhycredit[8mm] for another size ``` -`\kuhycreditlogo[]` draws the logo without a link. The default size is +`\kuhycreditcorner[]` (preamble, LaTeX 2020-10+) puts the linked logo +on every page, `` (default 4mm) from the paper's bottom-right corner, +which keeps it in the margin of a full page. `\kuhycreditlogo[]` draws the logo without a link. The default size is `\kuhycreditsize` (12mm). Demo: `latex/demo/demo.tex`. ## Terminal programs diff --git a/kuhy_credit/flutter/example/pubspec.lock b/kuhy_credit/flutter/example/pubspec.lock index 1af1715..6637121 100644 --- a/kuhy_credit/flutter/example/pubspec.lock +++ b/kuhy_credit/flutter/example/pubspec.lock @@ -70,7 +70,7 @@ packages: path: ".." relative: true source: path - version: "0.2.0" + version: "0.3.0" leak_tracker: dependency: transitive description: diff --git a/kuhy_credit/flutter/pubspec.yaml b/kuhy_credit/flutter/pubspec.yaml index 01fb5d5..897dcde 100644 --- a/kuhy_credit/flutter/pubspec.yaml +++ b/kuhy_credit/flutter/pubspec.yaml @@ -3,7 +3,7 @@ description: >- The shared "Created by kuhy" credit: an M1 logo button that opens a small panel, whose tap opens kuhy.duckdns.org. Android and Flutter web. publish_to: 'none' -version: 0.2.0 +version: 0.3.0 environment: sdk: ^3.12.2 diff --git a/kuhy_credit/generator/emit.py b/kuhy_credit/generator/emit.py index 0bf0910..158e31b 100644 --- a/kuhy_credit/generator/emit.py +++ b/kuhy_credit/generator/emit.py @@ -205,7 +205,7 @@ def latex(c: Credit) -> str: f"% The kuhy credit for LaTeX ({MARK}).\n" "% \\kuhycredit[] draws the logo linked to the site (needs hyperref);\n" "% \\kuhycreditlogo[] draws it without a link. Size defaults to\n" - "% \\kuhycreditsize (12mm, about the web stack's 48px).\n" + "% \\kuhycreditsize (12mm, about the web stack's 48px). Needs LaTeX 2020-10+.\n" "\\NeedsTeXFormat{LaTeX2e}\n" "\\ProvidesPackage{kuhy-credit}[kuhy credit]\n" "\\RequirePackage{tikz}\n" @@ -224,6 +224,11 @@ def latex(c: Credit) -> str: " \\ifdefined\\href{\\hypersetup{pdfborder={0 0 0}}%\n" " \\href{\\kuhycreditURL}{\\kuhycreditlogo[#1]}}%\n" " \\else\\kuhycreditlogo[#1]\\fi}\n" + "% \\kuhycreditcorner[] (preamble) puts \\kuhycredit on every page,\n" + "% (default 4mm) from the bottom-right corner of the paper.\n" + "\\newcommand\\kuhycreditcorner[1][4mm]{\\AddToHook{shipout/foreground}{%\n" + " \\put(\\strip@pt\\dimexpr\\paperwidth-#1-\\kuhycreditsize\\relax,\n" + " \\strip@pt\\dimexpr#1-\\paperheight\\relax){\\kuhycredit}}}\n" "\\AtBeginDocument{\\ifdefined\\href\\else\\PackageWarningNoLine{kuhy-credit}%\n" " {hyperref is not loaded: \\string\\kuhycredit\\space draws no link}\\fi}\n" "\\endinput\n" diff --git a/kuhy_credit/latex/demo/demo.tex b/kuhy_credit/latex/demo/demo.tex index 27b557e..40efc52 100644 --- a/kuhy_credit/latex/demo/demo.tex +++ b/kuhy_credit/latex/demo/demo.tex @@ -2,7 +2,7 @@ % TEXINPUTS=../: pdflatex demo.tex (from kuhy_credit/latex/demo) \pdfcompresslevel=0 \pdfobjcompresslevel=0 -\documentclass{article} +\documentclass[letterpaper]{article} \usepackage{fancyhdr} \usepackage{hyperref} \usepackage{kuhy-credit} @@ -11,6 +11,7 @@ \fancyhf{} \renewcommand{\headrulewidth}{0pt} \fancyfoot[R]{\kuhycredit} +\kuhycreditcorner[4mm] \begin{document} \centering \kuhycredit[40mm]\par\bigskip diff --git a/kuhy_credit/latex/kuhy-credit.sty b/kuhy_credit/latex/kuhy-credit.sty index 0bd9ab5..8f26fe7 100644 --- a/kuhy_credit/latex/kuhy-credit.sty +++ b/kuhy_credit/latex/kuhy-credit.sty @@ -1,7 +1,7 @@ % The kuhy credit for LaTeX (generated by kuhy_credit/generator/generate.py; DO NOT EDIT). % \kuhycredit[] draws the logo linked to the site (needs hyperref); % \kuhycreditlogo[] draws it without a link. Size defaults to -% \kuhycreditsize (12mm, about the web stack's 48px). +% \kuhycreditsize (12mm, about the web stack's 48px). Needs LaTeX 2020-10+. \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{kuhy-credit}[kuhy credit] \RequirePackage{tikz} @@ -136,6 +136,11 @@ \ifdefined\href{\hypersetup{pdfborder={0 0 0}}% \href{\kuhycreditURL}{\kuhycreditlogo[#1]}}% \else\kuhycreditlogo[#1]\fi} +% \kuhycreditcorner[] (preamble) puts \kuhycredit on every page, +% (default 4mm) from the bottom-right corner of the paper. +\newcommand\kuhycreditcorner[1][4mm]{\AddToHook{shipout/foreground}{% + \put(\strip@pt\dimexpr\paperwidth-#1-\kuhycreditsize\relax, + \strip@pt\dimexpr#1-\paperheight\relax){\kuhycredit}}} \AtBeginDocument{\ifdefined\href\else\PackageWarningNoLine{kuhy-credit}% {hyperref is not loaded: \string\kuhycredit\space draws no link}\fi} \endinput diff --git a/kuhy_credit/pyproject.toml b/kuhy_credit/pyproject.toml index 34e17a6..909935d 100644 --- a/kuhy_credit/pyproject.toml +++ b/kuhy_credit/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "kuhy-credit" -version = "0.2.0" +version = "0.3.0" description = "The shared 'Created by kuhy' logo credit: Tkinter widget and terminal line" requires-python = ">=3.14" dependencies = [] # pure stdlib: tkinter and webbrowser ship with Python diff --git a/kuhy_credit/tests/test_latex.py b/kuhy_credit/tests/test_latex.py index 3efdd0a..7964e67 100644 --- a/kuhy_credit/tests/test_latex.py +++ b/kuhy_credit/tests/test_latex.py @@ -41,8 +41,8 @@ def _compile(tmp_path: Path) -> bytes: def test_demo_pdf_links_the_logo_to_the_site(tmp_path: Path) -> None: pdf = _compile(tmp_path) url = json.loads((CREDIT_DIR / "credit.json").read_text())["url"] - # One link per \kuhycredit call in the demo, each with the shared URL. - assert pdf.count(f"/URI({url})".encode()) == 2 + # One link per \kuhycredit call in the demo (footer, body, page corner). + assert pdf.count(f"/URI({url})".encode()) == 3 # The field and both glyph colours are painted (non-stroking rgb fills). for rgb in (b"0.12941 0.11374 0.10588", b"0.72157 0.5255 0.18039", b"0.92549 0.91765 0.91374"): assert rgb + b" rg" in pdf @@ -64,3 +64,13 @@ def test_tex_special_characters_are_refused(value: str) -> None: with pytest.raises(ValueError, match="TeX-special"): emit._tex_safe(value) + + +def test_corner_logo_sits_in_the_bottom_right_margin(tmp_path: Path) -> None: + """\\kuhycreditcorner[4mm] puts a 12mm logo 4mm from the page's corner.""" + pdf = _compile(tmp_path) + rects = [tuple(float(v) for v in m.split()) for m in re.findall(rb"/Rect\s*\[([^\]]*)\]", pdf)] + mm = 72 / 25.4 + width = 8.5 * 72 # letterpaper in the demo + want = (width - 16 * mm, 4 * mm, width - 4 * mm, 16 * mm) + assert any(all(abs(a - b) < 1 for a, b in zip(r, want, strict=True)) for r in rects), rects diff --git a/kuhy_credit/web/package.json b/kuhy_credit/web/package.json index 171fcbc..6b498b9 100644 --- a/kuhy_credit/web/package.json +++ b/kuhy_credit/web/package.json @@ -1,6 +1,6 @@ { "name": "@kuhyx/kuhy-credit", - "version": "0.2.0", + "version": "0.3.0", "private": false, "type": "module", "description": ": the shared 'Created by kuhy' logo credit as a dependency-free custom element.",