Retagging <line>, <rect>, <circle> and the other shapes as <path> broke
<style> rules that select by element name. In t2.svg, line.css{stroke:
#e33} and circle{fill:#3c6} stopped matching, so the red line vanished
and the green circle went black. Rules for path went the other way:
path{fill:none} began to empty every converted circle and rect.
Copying each rule to a selector that matches the converted path cannot
keep its specificity: :where() and :is() would, but librsvg 2.63 ignores
both. A copied rule path[data-rough-shape="circle"] (0,1,1) then beats a
class rule (0,1,0), so in
<style>circle{fill:#c00} .blue{fill:#06c}</style>
<circle cx="75" cy="75" r="50"/>
<circle class="blue" cx="225" cy="75" r="50"/>
both circles came out red. Rewriting path to path:not([data-rough-shape])
raised path rules from (0,0,1) to (0,1,1) in the same way, so with
path{fill:#c00} .x{fill:#06c}, a real <path class="x"> turned red as soon
as the drawing also had a shape to convert.
The stylesheet is now left as it is. Each element's matching rules are
found once before any shape changes and once after, and where they
differ, the value the original cascade gave each property those rules
declare is written back onto the element: the first circle above gets
fill="#c00", the blue one is left alone. If a rule the matcher sees
still sets the property on the path, the value goes into the style
attribute instead, with !important when such a rule is !important, so
path{stroke-dasharray:4} does not reach converted shapes. A property the
original did not get at all is written as inherit, or as its initial
value (opacity:1) if it is not inherited; unset and initial are not
used, because librsvg 2.63 ignores both and cairosvg reads unset as
initial. Values rough.py sets itself, fill:none on lines and marker:none
on shapes, are kept.
Writing the value as a presentation attribute where possible keeps it
below any rule the matcher does not see. A rule with another
pseudo-class that still matches the path, such as .a:nth-child(3) or
.a:not(.b), still wins over it. A rule that names the old tag with such a
pseudo-class, circle:nth-child(2){fill:#0a0}, is still lost, as before.
Rules inside @media blocks are not matched, as in librsvg and cairosvg,
so a type rule in one, such as circle{fill:#fff} in
@media (prefers-color-scheme: dark), stops reaching converted shapes in
a browser.
A size given with the font shorthand, as in .head { font: bold 40px/1
serif } or style="font: italic 36px serif", was not read, so both
headlines were handled as 16px text: calm shaking and no edge filter.
Worse, style="font: 12px sans-serif" next to font-size="40" was treated
as 40-unit text, although the shorthand in the style attribute wins and
the text renders at 12.
The shorthand now counts as a font-size declaration, in the style
attribute and in stylesheet rules alike: the first word that is a size
keyword (large, smaller and so on) or a length with a unit, with any
/line-height after it dropped.
The text, marker, fill and rem fixes only saw the style attribute,
presentation attributes and inheritance, so values set by a <style>
rule were missed:
- poster.svg sets font-size: 72px on its title through the .title class,
and the title was handled as 16px text: calm shaking and no edge
filter.
- In r11.svg a polyline gets its markers from .m { marker: url(#dot) },
and its 2 mid dots grew to 20 as the jitter cut its edges into
pieces.
- In f1.svg the straight paths without a fill came out with black
slivers along them, because any document with a stylesheet was left
without fill="none", in case a rule filled an ancestor.
- With :root { font-size: 40px }, rem still counted as 16 px, so tspans
with dy="1rem" stepped 16 units instead of 40 and overlapped.
Stylesheet rules are now matched against elements with a small engine
for type, class, id, attribute, :root, :first-child and :last-child with
any combinator. Each element is matched once, against the document as
it was read, so a shape that has already turned into a path does not
change what its siblings match. A property comes from the cascade:
!important in the style attribute, then !important rules by specificity
and order, then the style attribute, then the other rules, then the
presentation attribute, then the parent.
Not matched: rules with other pseudo-classes (:hover, :nth-child,
:not() and so on), and rules inside @media or any other at-rule block.
librsvg 2.63 and cairosvg both ignore @media blocks, even @media screen,
so leaving them out follows what they draw. With rules resolved, the
fill check sees a fill set by a stylesheet (f1.svg: the .blue class)
and leaves it, and only fills the matcher cannot see are left to the
renderer: a fill set only by a :hover rule, say, still overrides the
added attribute, as it should.
With LOCALAPPDATA unset, os.path.join('', 'Programs') made the GIMP folders relative, so cairo_dir() searched 'Programs\GIMP 3\bin' under the current folder and put a libcairo-2.dll planted there on PATH. A relative entry in CAIROCFFI_DLL_DIRECTORIES did the same. Skip any folder that is not absolute.
check.py needs numpy and Pillow, but a plain Python has neither (the usual case on Windows), and the import failed with a ModuleNotFoundError traceback. Stop with one line that names both packages instead, like the other setup errors.
shutil.which() finds rsvg-convert through PATHEXT, so on Windows it also finds an rsvg-convert.cmd or .bat wrapper. subprocess.run(['rsvg-convert', ...]) then looks only for an .exe and failed with FileNotFoundError [WinError 2], a long traceback, and never fell back to cairosvg. Pass the path which() returned, so the wrapper runs and its errors come back as the usual one-line message.
ElementTree opens the output in text mode, so on Windows every newline in the SVG became CRLF and the same input and seed gave different bytes than on Linux (209 of 242 test files differed only in line endings). Open the file ourselves as UTF-8 with newline='\n' and hand it to ElementTree.
On Windows, stdout through a pipe uses the ANSI code page. When the output path has a character outside it, such as 'Łódź.svg' under cp1252, the closing 'wrote ...' line raised UnicodeEncodeError and rough.py exited 1 after the file had already been written, so a caller trusting the exit code thought it failed. moves.py and check.py already write stdout as UTF-8; do the same here.
An earlier commit on this branch made a corrupt history readable by
decoding with errors="replace" and skipping lines that are not JSON
objects. But add() rewrote the file from the rows it had parsed, so the
next add destroyed whatever it could not read, where upstream crashed
and left the file alone:
- Windows PowerShell 5 writes UTF-16 LE by default (`$rows | Out-File`).
The whole file failed to parse, `moves.py` said "no moves saved yet",
and the next add left a file with only the new row, with no warning.
- A cp1252 file from `Set-Content` ("Łódź" saved as ANSI) was listed as
"L�dz", and the next add wrote U+FFFD into the file for good.
- Any line that was not a JSON object was dropped at the next add.
Now:
- A file that starts with a UTF-16 BOM (FF FE or FE FF) is decoded as
UTF-16, and the next add writes it back as UTF-8.
- Anything else is decoded as UTF-8 with errors="surrogateescape" and
written back the same way, so bytes that are not UTF-8 survive byte
for byte. The listing shows them as "?", since stdout already uses
errors="replace".
- add() keeps the existing lines as text and appends the new row,
instead of re-serialising parsed rows. Lines that are not JSON objects
stay in the file. They count toward the 300-row cap and are trimmed
oldest first like the rest. Blank lines are dropped, and a "\r" at the
end of a line is removed, so a CRLF file comes back with one line
ending per row.
- load() still returns only the lines that parse as JSON objects.
On Linux: the bytes of a cp1252 file were unchanged after an add, UTF-16
LE and BE files with CRLF kept all 3 rows and became UTF-8, junk lines
("not json at all", 5, null) were still there after an add, and a
300-line file with a junk first line dropped exactly that line when one
row was added.
Readers don't take the lock. On Windows, opening history.jsonl while a
writer's os.replace is swapping it in fails with PermissionError for a
moment. load() turned that into "could not read the history" and an
empty list, so `moves.py` printed "no moves saved yet" and seed.py
stopped avoiding recent values, even though nothing was wrong with the
file.
Opening and reading now go through the same short retry as the rename
in add(): PermissionError is retried every 20 ms, up to 50 times (about
1 s). On Linux and macOS a file that really can't be read now warns
after that second instead of at once.
On Windows (Python 3.14, NTFS), one process looping read() while 4
others did 40 adds each got PermissionError on 104, 90 and 78 of about
4400 to 5200 reads in three runs before, and on 0 of about 3500 to 4500
reads after.
The listing sliced rows[-args.last:], so `--last 0` became rows[-0:],
which is every move, and `--last -1` became rows[1:], every move but the
oldest. Neither is what the flag says. A count below 1 now stops with
"--last must be 1 or more" (argparse usage error, exit 2).
`--keep "method=X-ray image"` did not match "x-ray image" in the pool,
so it was taken as a new method and skipped the rule that a fixed-colour
method gets "the method's own colors": the seed came back with
"color: two colors that clash". `--keep "method="` was accepted and
printed "method: " with nothing after it.
A kept value that matches a pool value of that axis without regard to
case (casefold) is now replaced by the pool value, so every rule keyed
on it applies: X-ray image becomes x-ray image and gets its own colours,
Iceland, "A Plain List" and "The Method's Own Colors" match too. A value
that matches nothing is still kept as given, because --keep is how a
subject or a fact from the user's request is held fixed ("region=Łódź",
"anchor=a red tram", a method the pools don't list), and the skill wants
the start point to come from the request when it carries one. An empty
value, or one of spaces only, now stops with "--keep needs a value after
'='".
`seed.py visual --only method` never returned any of the 12 methods that
bring their own colours (x-ray image, thermal camera image, LED dot
matrix and so on): 0 in 300 rolls. With --only, roll_once() dropped
every axis that was not kept or rolled, so colour was missing, and
clashes() counts a fixed-colour method without "the method's own colors"
as a clash and rolls again.
The reverse case was wrong too. After a seed such as "method: x-ray
image, color: the method's own colors", the model rolls the method again
and does not keep the colour, since that colour belongs to the old
method. It got back only "method: woodcut" and was left with "the
method's own colors" for a woodcut, which means nothing.
The colour depends on the method, so when --only method is used without
--keep color, the colour is rolled with it and printed:
- a fixed-colour method prints "color: the method's own colors";
- any other method prints a fresh colour from the pool, checked by
clashes() like a full seed (so "the colors of a machine screen" comes
only with a screen method).
With --keep color the output is the method alone, as before, and it
fits the kept colour: "the method's own colors" gives a fixed-colour
method, any other colour gives a method that does not fix its own, and a
machine-screen colour gives a screen method. Either way the model's
seed stays consistent if it replaces exactly the lines it is shown.
The logged row holds the same lines as the output.
After, in 300 rolls each: --only method gave 60 fixed-colour methods,
all with "color: the method's own colors", and no machine-screen colour
on a non-screen method; with --keep "color=the method's own colors"
all 300 were fixed-colour methods; with --keep color=fluorescent none
were. Every --only method output without a kept colour had two lines,
and every one with a kept colour had one.
With an unwritable history location (ANTIALGORITHM_HISTORY under a
read-only folder), seed.py printed the seed and then exited 1 with a
PermissionError traceback, and `moves.py add` failed the same way. An
agent that sees a failed command may throw the seed away and pick a
start point from its own taste, which is what the skill forbids, so the
seed has to succeed whatever happens to the history.
Now:
- load() turns a read error (no permission, a folder in the way) into
one line on stderr and an empty history, so seeds are still rolled,
only without avoiding recent values.
- seed.py prints the seed, and if saving fails it prints one line on
stderr and still exits 0.
- `moves.py add` prints "could not save the move: <reason>" and exits 1,
since saving is its whole job, but without a traceback.
add() still reads the file itself and fails on a read error rather than
treating the history as empty, so a file it cannot read is never
overwritten with a single row. This is one finding across three files:
the history module decides what a failure is, and each script decides
what it means for its own exit status.
Agents can run several sessions at once, and each one rolls seeds and
saves moves. add() read the whole file, appended a row and wrote it back
through a shared PATH + ".tmp", so parallel writers broke it two ways:
- 40 parallel `seed.py idea` runs gave a FileNotFoundError traceback
when one writer renamed the shared tmp file away from under another,
and only 38 of 40 rows were saved;
- even with distinct tmp names, two writers that read the same file each
wrote back their own copy without the other's row: 20 parallel
`moves.py add` runs left 18 rows.
add() now holds a lock file (history.jsonl.lock) across its read and
write. The lock is taken with os.open(O_CREAT | O_EXCL), which is atomic
on Linux, macOS and Windows and needs only the standard library; fcntl
is Unix-only and msvcrt is Windows-only. A writer that finds the lock
retries every 20 ms for up to 15 s. A lock older than 10 s is taken to be
left by a crashed writer and removed, since a real holder keeps it for
milliseconds; so a leftover lock costs one wait at most, never a
permanently broken history. The tmp file name includes the pid, so a
writer that breaks a stale lock still can't clobber another's tmp file.
On Windows, os.open on a lock file that another process is deleting
fails with PermissionError (ERROR_ACCESS_DENIED), not FileExistsError,
so on Windows PermissionError is retried the same way. A first version
that did not saved 196 and 193 of 200 rows in two runs of 20 processes
x 10 adds on Windows (Python 3.14, NTFS), with every failure at
os.open; with the retry 7 runs saved 1400 of 1400. The cost is that on
Windows a lock that can never be created (a read-only folder) fails
after the 15 s wait, with "could not create the lock file <path>",
instead of at once. On Linux and macOS PermissionError there always
means the folder is not writable, so it still fails at once.
On Windows, os.replace fails with PermissionError while another process
has the target open, which a reader (seed.py, moves.py) may have for a
moment, so the rename is retried for up to 1 s. migrate() takes the same
lock and re-checks before copying, so two first runs can't both copy the
old repo-root file over a row that one of them has just added. The
300-row cap is unchanged.
After: 40 parallel seeds saved 40 rows and 20 parallel adds saved 20
distinct moves, with empty stderr, in each of 4 runs; 320 more seeds
from 8 parallel loops left exactly 300 rows.
rem lengths were always 16 px. With style="font-size: 40px" on the root
<svg>, a circle with r="1.5rem" should have radius 60 and tspans with
dy="1rem" should step 40 units; rough.py drew radius 24 and stepped 16,
and the two lines of text overlapped.
The root <svg>'s font-size is now read once, from its style attribute or
its font-size attribute, and every rem in coordinates, dy and font sizes
is resolved against it. Without one it stays 16 px. Checked: a
font-size="20" attribute gives 20, style="font-size:2rem" gives 32,
none gives 16.
librsvg 2.63 does not draw rem in geometry attributes at all (the
original renders without its circle and rect), so the converted output,
which has plain numbers, now shows them at the size a browser would.
shake() returned early when dy held more than one value, a check from
upstream 7f92b83, so text whose author had placed letters one by one
(dy.svg: dy="0 -10 -10 20 20 -20" on WAVE ON, dy="0,0.25em,..." on
STEPS AND) got no baseline jitter at all.
Each listed value is now resolved as a length (em against the element's
font-size, % against the canvas height) and the small offsets are added
on top of it. When the list is shorter than the text the missing entries
count as 0, as SVG says for dx/dy (the last value does not repeat);
values beyond the last character are kept as they are, since SVG ignores
them. x, y, dx and rotate lists are not changed; rotate is still only
added when the author has none.
Rendered with cairosvg, because librsvg ignores per-letter dy lists: the
author's wave and steps are unchanged and the letters get the same small
shake as single-valued text.
Bad input ended in a traceback: an empty file (empty.svg), an undefined
entity such as (nbsp.svg) or an external one (ext.svg), a
billion-laughs file (laughs.svg) and a gzip-compressed .svgz all died
with xml.etree.ElementTree.ParseError, and a missing input or an output
in a missing folder with FileNotFoundError.
The input is now read as bytes and parsed in read_svg(), which uses the
same wording check.py uses on branch fix/check: "cannot open <file>:
<reason>", "<file> is gzip-compressed (svgz); unzip it to a plain .svg
first" and "<file> is not valid SVG XML: <parser message>". Writing
the output reports "cannot write <file>: <reason>". Each message starts
with rough.py: like the script's other errors, and the exit code is 1.
Checked on Python 3.9 and 3.15 with the files above, a directory given
as input or output, a file without read permission and a read-only
output folder.
An open <path> or <polyline> with no fill set anywhere is filled black by
default, but draws nothing while its points lie on one line, because the
fill encloses no area. Once jitter moves the points off that line the
fill appears: M40 580 L360 580 in scaled.svg came out as a hairline with
black slivers along it.
Such an element now gets fill="none" before it is roughened, but only
when every subpath is open (no Z) and all its points, control points
included, lie on one straight line, and no fill comes from an attribute,
the style attribute or an ancestor.
Left alone on purpose: any fill that is set (a fill="#c33" attribute,
fill inherited from a group), because the author asked for it even if it
was invisible; open curves and bent polylines, which do enclose area and
already render filled; and closed subpaths. A document with a non-empty
<style> element is left alone entirely, f1.svg among them: a rule there
may fill an ancestor, and without reading the rules the added attribute
could override the fill the element inherits from it.
<use> elements were walked past without change, so marks repeated with
<use>, the usual way to stamp the same tick, dot or tile many times,
stayed on their exact even spacing (r13d.svg: twelve ticks every 20
units), although visuals.md says rough.py moves repeated marks off it.
Each <use> now gets the same small whole-shape offset that small circles
and lines get: a translate in its parent's coordinates, sized by the
parent's scale, put in front of any transform it already has. The
referenced content itself is shared by all copies, so the copies move
but do not change shape.
Circles and ellipses became closed polygons of 12 to 160 straight
segments. At full size the facets show (r13c.svg: the r=150 circle's
outline is a ring of visible corners and kinks), which reads as a
plotted polygon rather than a hand-drawn curve.
They are now 8 to 24 jittered points joined by a closed Catmull-Rom
spline written as cubic Beziers, so the outline stays round between the
points. The radial noise is the same as before; the three-lobe
distortion of 1.5% now grows with --amount, so --amount 0 leaves the
shape round (renders within 0.02% of the pixels of the original circle)
instead of keeping the lobes. The files stay about the same size.
rect() returned early whenever rx or ry was set, so every rounded rect,
a common shape in posters and cards, stayed perfectly clean (r13b.svg:
five rounded rects, none touched).
A rounded rect is now built as four straight sides and four quarter-
ellipse cubics, with rx and ry resolved as lengths, a missing or auto
radius taken from the other one, and both clamped to half the width and
height as SVG does. The outline then goes through the same jitter as a
path. At --amount 0 it renders the same as the original rect.
Two details found on the way: a side of zero length (a pill whose
straight part vanishes) is dropped, since jittering the same point twice
drew a spike; and in any path, a segment that ends exactly at the start
of its subpath now reuses the jittered start point, which removes the
small kink where a closed outline met itself.
Arc commands were copied through with only their end point moved, so
every A in a path stayed a perfect circular or elliptical arc, while
visuals.md says rough.py breaks curves. In r13a.svg the half circle, the
rotated ellipse and the chain of arcs came out machine smooth.
parse_path() now converts each arc to cubic Beziers of at most a quarter
turn, using the centre parameterisation from the SVG implementation
notes (radii scaled up when too small, zero radii drawn as a straight
segment). The cubics then go through the same jitter as other curves.
At --amount 0 the converted arcs render the same as the originals. An arc
with non-finite or absurd radii falls under the existing size check and
leaves the path unchanged.
Every point the jitter inserts is a vertex, and marker-mid draws a marker
at every vertex. In marker.svg the polyline with marker-mid="url(#dot)"
went from 2 mid dots to about 20, and in r11.svg the same happened to a
path whose marker-mid was inherited from its group. Circles and rects
inside that group, which never draw markers, sprouted a dot at every
point once they became paths.
A path, line, polyline or polygon whose marker-mid is set, directly, in
its style attribute (also through the marker shorthand) or inherited, now
keeps its own vertices: they are still jittered, but edges are not cut
into pieces and curves are not split. Rects, circles and ellipses that
inherit any marker get marker:none in their style when they become
paths, as they never showed markers before. Markers set by <style> rules
are not seen yet.
Text was sorted into calm, medium and strong shaking by fixed sizes (16
and 32 user units) and got the rough-edge filter from 28 units, with
baseFrequency fixed at 0.9 per user unit. So the same design drawn at
0.25x, 1x and 10x coordinates (sc025.svg, sc1.svg, sc10.svg) was treated
three ways: at 0.25x the 44-unit title shrank to 11 units, was kept calm
and got no edge filter.
Sizes are now measured against a 720-unit canvas diagonal in the text's
local units, so the thresholds keep their meaning on a 400x600 poster and
scale with everything else. The filter's baseFrequency and displacement
follow the same scale, with one filter per distinct scale. Font sizes
come from the style attribute, then the font-size attribute, then the
parent, through nested tspans as well; keywords such as large and smaller
count. After the change the three sc files get identical rotations and
the same filter relative to their size.
Points within 1 user unit of the canvas edge were pushed out by their
jitter plus 1 unit, and every coordinate was rounded to 2 decimals. Both
are absolute. In unit.svg (viewBox 0 0 1 1) the whole canvas counts as
the edge: the white line and the green square were pushed off the
canvas, and 0.01 rounding put visible steps in the circle. In icon24.svg
(viewBox 0 0 24 24) a 1-unit push is 4% of the icon.
The edge band is now 1/720 of the current viewport's diagonal (1 unit on
a 400x600 canvas, as before), and numbers keep enough decimals for
1/72000 of the canvas diagonal in the local units: 2 on 400x600, 5 on a
1x1 viewBox, 1 on a 10x canvas. The amp in the closing message is shown
to 3 significant digits instead of 2 decimals, so it no longer reads
0.00 on small canvases.
The amplitude came from the root viewBox only, in root user units, and
was applied unchanged in every local coordinate system. In scaled.svg a
24-unit icon drawn inside scale(6), and the same icon in a nested
<svg viewBox="0 0 24 24"> 240 wide, got 6 and 10 times the intended
shake: the square turned into a skewed quad and the circle into a blob.
The nested <svg> also kept the outer canvas for its edge rule and for
resolving %.
The walk now tracks how large one local unit is in root units. Each
transform list is multiplied out and its largest singular value taken,
so a non-uniform scale never shakes harder than intended in any
direction; a nested <svg> adds its viewBox scale (meet, slice or none),
becomes the box for % lengths and edge snapping, and counts as a free
canvas edge again since it clips. Jitter, the step floor and the size
limit are divided by that scale. The small whole-shape offset is a
translate in the parent's system, so it uses the parent's scale.
Groups with a singular transform such as scale(0) draw nothing and are
skipped.
line x1..y2, rect x/y/width/height and circle or ellipse cx/cy/r/rx/ry
were read with fnum(), which drops the unit. In r4.svg a line from 5% to
95% across a 400-wide canvas became a line from 5 to 95, and a circle
with r=10% shrank to radius 10. t2.svg had the same with x2="100%".
Rects with a % width were skipped outright.
These attributes now go through the same length resolver as dy: % against
the canvas width or height, or for r against the diagonal divided by
sqrt 2 as SVG defines it, em and ex against the element's font-size, and
the absolute units converted to user units. Full-canvas rects given as
100% are still recognised as the background and left alone.
shake() read a tspan's own dy with fnum(), which keeps only the number,
so dy="1.2em" in t1.svg (font-size 40) became 1.2 user units instead of
48. The three lines FIRST, SECOND and THIRD were drawn on top of each
other.
dy is now resolved as a length: em and ex against the element's own
font-size, % against the canvas height, and px, pt, pc, mm, cm, in, Q
and rem converted to user units. An unknown unit counts as 0, as SVG
does for an invalid length. Font sizes given in em or % are resolved
against the inherited size the same way, instead of being read as bare
numbers.
A <line> is never filled, but the <path> it was turned into is. With the
default black fill, or a fill inherited from a group or set in its own
style, the jittered line drew a filled sliver between its points (r2.svg
at --amount 2: black, red and blue wedges along three hairlines).
The converted line now gets fill:none in its style attribute. It goes in
the style attribute rather than a fill attribute, so that a stylesheet
rule such as path{fill:red} cannot fill it again.
The finding also named <polyline>, but a polyline is filled in SVG just
like the open path it becomes (the black wedge under the polyline in
r2.svg renders the same before and after), so it is left as it is.
to_path() called el.clear(), which also drops child elements, text and
tail. In t2.svg the <title>tooltip</title> inside a circle was lost, and
so were <desc>, <animate> and <set> children; the cleared tail also
pulled every following element onto one line.
Only the geometry attributes are now removed before the tag changes, so
children and whitespace stay. A shape whose geometry is animated (an
<animate> or <set> child whose attributeName is r, x1, width, points
and so on) is left as it is, because the animation would target an
attribute the path no longer has.
deep.svg, 3000 nested <g>, ended in a RecursionError traceback. Both
walk() and ElementTree's own writer recurse once per level, so anything
past about 1000 levels fails, and the writer cannot be made iterative
without replacing it.
The depth is now measured with a loop before any work, and a file nested
more than 500 levels deep stops with a message that says so. 500 leaves
room under Python's default limit of 1000 for both recursions on every
supported version; real drawings nest a few tens of levels at most.
Checked: 498 groups (500 levels with the root and the line) still runs on
Python 3.9 and 3.15, 499 and 3000 get the message.
A path with L1e300 1e300 (hugepath.svg) hung, a line to x2=1e9
(huge.svg) died with MemoryError and a rect with width=1e999 (inf.svg)
with OverflowError: the number of points per edge grew with the length,
and int() of an infinite count failed.
Shapes whose numbers are not finite or lie more than a million canvas
diagonals from the origin are now left as they are, since jitter means
nothing at that size and the output would be hundreds of KB of digits.
Each edge is also cut into at most 200 pieces, so a long line that does
fit (x2=1e7) stays small. A viewBox or width/height that is infinite or
not positive now stops the run with a message naming the size instead of
writing inf and nan coordinates.
steps() divided each edge length by amp*18 + 1e-6. With --amount 0 the
divisor was 1e-6, so a 400-unit line asked for 400 million points and
the run never finished (poster400.svg timed out after 10 s), and
--amount 0.001 turned a 1.3 KB poster into a 1.6 MB file.
The shortest piece an edge is cut into is now also at least 1/160 of the
canvas diagonal. At the default amount this floor is lower than amp*18,
so --amount 1 output is byte-identical to before; at 0 or tiny amounts
the poster now comes out at about 15 KB.
--amount was a plain float, so "--amount nan" crashed with "ValueError:
cannot convert float NaN to integer", "--amount inf" wrote paths such as
d="Minf,nan Linf,inf ..." that no renderer can draw, and "--amount -1"
was accepted with a negative amplitude. The value now goes through an
argparse type that stops with a usage error for anything that is not a
finite number of 0 or more.
The see-through text check rendered the design once more without the
text whenever the text never reached alpha 250. Thin opaque text
also stays below 250, so every 12-14 px label of a 1440x900 interface
at the default 800 px width got an extra render: 82 renders instead
of 42 for many40.svg, and the run took twice as long (3.7 s to 7.3 s),
in a check that visuals.md already says can take minutes.
Decide from the opacity and fill-opacity set on the text and its
ancestors (attribute or inline style) instead. For other text the
cover check compares only the pixels the text covers almost fully
(alpha above 200), as before the see-through change; comparing the
partly covered pixels of thin text without the backdrop called every
label of the 1440x900 test interface 53-100% covered. Contrast still
uses the letter mask scaled by the strongest alpha.
Text at opacity 0.6 (bad_covered_faint: 95% covered) and 0.1
(bad_faint: low contrast) is still checked against the blend, the
regression set gives the same output as before this commit, and
many40.svg is back to 42 renders. Opacity set from a <style> sheet is
not seen; such text is cover-checked as opaque, as it was upstream.
cairosvg ignores writing-mode and draws vertical text as one
horizontal line. A 30 px writing-mode="tb" word placed near the right
edge (TALL in good_rotated, VERTICALSMALLTEXT in feat.svg) was then
reported as running off the right edge, which it does not do in a
browser or in rsvg-convert. cairosvg is the usual renderer on Windows.
Under cairosvg, skip the edge, cover and contrast checks for text in a
vertical writing mode and print a note that the renders show it
sideways. Its letters keep their size when drawn sideways, so the size
check still runs on them (TINYVERTICALTEXTHERE at font-size 4 is still
reported).
The note for text on a textPath under rsvg-convert now uses the same
"note:" line.
The size check took the height of the text's bounding box. For text
turned by a transform the box height is the length of the line, so
5 px fine print rotated by -90 or -30 degrees (horiz.svg,
bad_small_rotated) passed while the same text set straight was
reported. Text with writing-mode="tb" (feat.svg, bad_small_vertical)
passed for the same reason. The visual seed axis "type set
vertically" makes both common.
Work out the direction of the line from the transforms of the text
and its ancestors (matrix, scale, rotate, skewX, skewY; translate does
not turn it) and the viewport scale, and measure the ink across that
direction. For vertical writing modes (tb, tb-rl, vertical-rl,
vertical-lr) the line runs down the page and the lines are counted by
x and dx. Horizontal, rotated (-90), diagonal (45) and nested-group
rotated 6 px text now all measure 1.0% of the side with rsvg-convert;
before, only the horizontal one was reported.
cairosvg ignores writing-mode and draws such text sideways, so under
cairosvg it is measured as the horizontal text it renders.
The size check divided the text height by the number of direct
<tspan> children. A single line split into styled tspans, such as
<tspan font-weight="bold">LIVE</tspan> <tspan>MUSIC</tspan>
<tspan>FRIDAY</tspan> at font-size 20 or 24 (c1.svg, good_tspans),
was taken as three lines and called "very small, about 0.9% of the
image side" though it is a normal 2.6% line.
Follow the baseline through the text instead: each character takes
its position from the y and dy lists of its element (with em and ex
resolved against the font size, which is read from the element and
its ancestors), the baseline carries on after a tspan as in SVG, and
lines are the groups of characters whose baselines are more than half
the font size apart. Styled runs, superscripts and the per-letter dy
jitter that rough.py adds stay one line; dy="1.2em" lines, absolute y
lines and a y list that stacks one letter per row count each line.
Not followed: positions set from a <style> sheet, font sizes in CSS
classes (16 px is assumed), and a parent's y or dy list continuing
past a child tspan.
Contrast was the difference of the mean gamma-encoded luma of the
letters and of the ring around them, on a 0-255 scale, with 30 as the
limit. That number depends on where on the grey scale the pair sits,
and it passed pairs that are close to invisible: #ddd on white (WCAG
ratio 1.36), #fff on #fc0 (1.51), #0a0 on #f00 (1.29) and #555 on
#333 (1.69) all measured 31-35 and passed (contrast.svg,
bad_lowcontrast*.svg).
Use the WCAG relative luminance (linear sRGB) and the ratio
(L1 + 0.05) / (L2 + 0.05). Limits: 2:1 for large text and 3:1 for
small text, where large means a line at least twice --min-text tall
(2.4% of the image side by default, 1.2% with --min-text 0.6, which
is about 17 px on a 1440 px screen, close to the WCAG large-text
size). These are below the WCAG AA values (3:1 and 4.5:1) on purpose:
posters use quiet, low-contrast type on purpose (white on orange
#f60 is 2.94:1, red on blue 2.07:1), and every report makes the model
change the design. 2:1 still catches every near-invisible pair above,
and 3:1 is the WCAG floor for anything that must be read.
Two measuring fixes make the ratio usable on small text. The ring
around the letters no longer includes the antialiased edge pixels of
the text itself, which pulled the background towards the text colour.
The letter colour is un-mixed from the background using the per-pixel
coverage of the text render, so a pixel 85% covered by white counts
as white. Thin text in a scaled-down render still reads a little low:
white 14 px labels on #2a5 (3.0:1) in a 1440x900 interface measure
2.7:1 at the default 800 px width and 3.0:1 at --width 1440.
The per-text render found the letters by alpha > 200, and its pixels
with alpha > 40. Text with opacity or fill-opacity below about 0.78
never reaches alpha 200, so the mask was empty and the cover and
contrast checks were silently skipped: in c2.svg, #eee text at
opacity 0.7 on white passed while the same colour at full opacity was
reported, and a red bar over text at opacity 0.6 (bad_covered_faint)
passed. Below opacity 0.16 the text was called "draws nothing" (FAINT
at 0.1 in bad_faint, FAINT GHOST TEXT at 0.06 in c1.svg), which sends
the model looking for a bug instead of a contrast problem.
Scale both thresholds by the strongest alpha the text reaches, and
keep "draws nothing" for text with no alpha at all (peak below 3 of
255). For see-through text, the full render shows the text blended
with what is behind it, so compare it with that blend: render the
design once more without this text (only for text whose peak alpha is
below 250) and mix it with the text by the text's alpha. Now c2.svg
reports both pale texts, bad_covered_faint is 95% covered, and the
faint texts report low contrast. Half-transparent white text over a
gradient, in a filtered group, with its own filter and on a
transparent ground all still pass, with rsvg-convert and cairosvg.
Text on a <textPath> was always reported as "draws nothing". The
per-text renders hide every shape, including the <path> the textPath
follows, so the text had no path to sit on (c1.svg, ALONG THE CURVE).
Make the referenced paths transparent instead of hiding them, so the
text keeps its geometry. With cairosvg the text is now checked like
any other.
rsvg-convert (2.63) does not draw textPath at all, not even in the
full render. There the old "draws nothing" sent the model to fix text
that browsers show fine. Under rsvg-convert, text on a textPath that
draws nothing is now listed as not checked, with a note that it is
also missing from the renders and has to be checked by eye. It is no
longer counted as a problem or in "texts checked".
The per-text renders kept clip-paths. Text inside a canvas-sized clip
(a common frame that keeps roughened shapes inside the image) was
clipped there too, so it never reached the margin and "runs off the
edge" was not reported: CUTOFF at x=250, font-size 60 in c1.svg and
bad_offedge_clip.svg passed, although half the word is cut away.
Drop clip-path (attribute and style) from every element in the
per-text renders, as filters already are. Text cut at the canvas edge
is now reported as running off; text cut by a smaller clip inside the
canvas is now reported by the cover check (WINDOWED clipped to a
150x80 window: 51% covered). Text inside a clip it fits in, and the
canvas-sized frame with text inside it, still pass.
Clip-paths set from a <style> sheet are not seen, as with filters.
Text whose parent group has a filter skipped the cover check. In
grpfilter2.svg a green bar drawn over PARTLY HID inside a grain-filtered
group went unreported (the same text outside the group: 67% covered),
and in grpfilter.svg a red box over COVERED came out as "low contrast
(0)" instead of covered.
The exclusion came in with 7f92b83, together with the no-filter render
for text that has its own filter. The per-text renders drop every
filter, so a displacement filter on a group moves the group's text in
the full render but not in the per-text render, and the edges no
longer match: removing the exclusion alone makes ROUGH in a
displacement-filtered group "6% covered".
Keep that purpose but restore the check: the no-filter render now
drops filters from every element, the same way the per-text renders
do, and any text with a filter on itself or an ancestor is compared
against it. Contrast is still measured on the real, filtered render.
Through cairosvg nearly every text was reported covered. cairo draws
text with subpixel (colour) antialiasing on this system. On the
transparent per-text render the edge pixels then carry per-channel
coverage, which becomes colours such as (243, 255, 5) after
un-premultiplying, while the full render shows the same pixels as near
white. vbonly.svg (white HELLO on #123) was 11% covered, and a
1440x900 interface had its title 38% covered.
cairosvg picks subpixel only for the default text-rendering; any
explicit value gives grey antialiasing. Set text-rendering to
optimizeSpeed on the svg element (unless it sets its own), which
changes only the antialiasing mode, for every cairosvg render, so the
full render and the per-text renders agree. full.png changes the same
way.
cairosvg also ignores paint-order, so text with paint-order="stroke"
had its outline drawn over the fill. A white OUTLINE with a 4 px black
stroke on a dark ground read as black on dark: "low contrast (7)".
Under cairosvg, draw such text as a stroke-only copy under a
fill-only original, which is what paint-order="stroke" means.
rsvg-convert supports both and is unchanged.
Regression set under cairosvg: 15 false "covered" reports and one
false "low contrast" gone; no report that was correct went away.
Not tested with cairo on Windows, where the default font antialiasing
comes from the Windows font backend.
The font check looked only for a Japanese font (fc-list :lang=ja) and
called any CJK text Japanese. With only Latin fonts installed, Korean
text (밤의 음악) passed without a warning although it renders as empty
boxes, and Chinese text (夜晚音乐) was reported as "Japanese text".
Find kana, hangul and Han characters separately and ask fontconfig
whether any installed font has one of them (fc-list :charset=<code>),
which is the question that decides whether boxes appear. Han
characters with kana are Japanese, with hangul Korean, otherwise
Chinese. Suggest the matching Noto Sans CJK font.
Checked with FONTCONFIG_FILE pointing at three font sets: Latin only
(Japanese, Korean and Chinese each reported, mixed text gives two
lines), Latin plus a Japanese font (only Korean reported) and Latin
plus a Korean font that also has kana and Han (nothing reported).
Also drop the docstring, which CONTRIBUTING.md does not allow.
Renders went to <tempdir>/antialgorithm_check/<file name>, so two
files called final.svg in different folders, or two runs at once (the
skill suggests running long checks in the background), wrote over each
other's full.png and small.png. Two final.svg files checked in
parallel both reported .../antialgorithm_check/final/full.png.
The per-text renders went to a mkdtemp folder that was removed only at
the very end, so any failure on the way left it behind (shown with an
rsvg-convert that fails on the second text: the tmpXXXX folder
stayed). The _nofilter render was written into the output folder.
Without --out, make a fresh <file name>-XXXXXXXX folder under
antialgorithm_check for each run; the script prints its paths, so
nothing else needs to know the name. Put all scratch files in one temp
folder that main() removes in a finally block. --out works as before.
Runs no longer overwrite earlier renders, so old folders stay in the
temp directory until the system clears it.
These inputs ended in a Python traceback, which tells the model nothing
it can act on:
- an empty file, malformed XML or a gzip-compressed .svgz (ParseError),
and a missing file (FileNotFoundError);
- --width 0, --width -5 or --small 0 (bare CalledProcessError, with
the rsvg-convert stderr thrown away);
- --width 20000 (Pillow DecompressionBombError) and a 100x3000 design
at --width 4000 (rsvg-convert refused the size);
- about 3000 nested <g> elements (RecursionError under cairosvg).
--min-text nan or -1 was accepted and turned the size check off.
Validate the options in argparse (--width 100 to 4000, --small 8 to
1024, --min-text 0 to 100; nan fails the range test), read the file
with a short message for each failure, name svgz files, keep the
stderr of rsvg-convert and the message of cairosvg when they fail,
refuse renders larger than the Pillow limit before making them, and
turn a RecursionError into a message. Each case now prints one line
and exits non-zero.
The cairosvg exceptions are listed by type rather than caught with a
bare Exception, so a programming error still shows its traceback.