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.
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.
When the render height is not a whole number of pixels, for example a
600x500 design at 800 px wide (666.67 px) or 1080x1920 (1422.2 px), the
last row of the full render is only partly covered and its alpha is
below 250. The "background has see-through parts" note was then
printed for fully opaque designs, and contrast was also measured on
black for no reason.
Look for see-through pixels only in the rows that lie wholly inside
the canvas. Verified on o600x500.svg and a 1080x1920 poster (note
gone, with rsvg and cairosvg) and on a design with no background and
the mismatch.svg letterbox (note still printed).
The canvas was taken from the viewBox alone, or from width and height
when there was no viewBox. Three things went wrong:
- When width/height and the viewBox have different shapes, the
renderer fits the viewBox into the viewport (preserveAspectRatio,
meet by default), but the per-text renders used the viewBox shape.
mismatch.svg (viewBox 400x600, width 400, height 400) and a
400x600 poster shown in a 600x600 viewport had every text called
"covered" or "runs off the bottom edge".
- width="100%" (or "auto", or missing) with no viewBox was read as
100x100 (nowh.svg), and width="auto" with no viewBox crashed with
AttributeError.
- A viewBox with only one of width/height renders as 800x600 under
cairosvg instead of 800x1200, so the renders did not line up.
Work out the viewport size in px (width/height with their units, or
from the viewBox aspect when one is missing or a percentage), then the
part of the user space it shows, following preserveAspectRatio
(xMin/Mid/Max, meet, slice, none). The per-text renders map that
region to the same pixels with preserveAspectRatio="none", so the
scale may differ per axis. When the renderers would disagree on the
size, render a copy with explicit width and height. After the full
render, stop with a one-line message if its size is not the expected
one (for example CSS width on the svg element). An SVG with no viewBox
and no fixed width and height has no defined canvas, so ask for a
viewBox instead of guessing. A viewBox with zero or negative size
draws nothing; say so instead of dividing by zero.
Text size is now measured against the rendered image side, which is
the same number as before for files whose shapes agree.
Each text is rendered on its own with a margin of a quarter of the
image side, then compared pixel by pixel with the full render. The
margin was pad * scale pixels, a fraction, but the comparison cut the
render at round(pad * scale). On portrait canvases such as 1080x1920,
360x640, 390x844, 333x517 and 357x499 at the default 800 px width the
two images were half a pixel apart, and every text on a plain white
ground was reported 14-17% covered.
Choose the margin as a whole number of pixels first and derive the
user-unit margin from it, so the solo render sits exactly p pixels
in from the full render.
rough.py now leaves any element marked data-rough="off", and everything
inside it, untouched. This keeps chart marks, numbers and must-read text
exact while the rest of the piece is roughened.
check.py now reports a problem when the SVG contains Japanese text but
fontconfig lists no Japanese font, since rsvg/cairo would render it as
empty boxes and the other checks would not catch that.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NCDY4KVLusg6S2pAP3Fi4C
When stdout is a pipe, as it is when an agent runs the script, Python
on Windows writes with the ANSI code page. A problem line quoting text
such as "POD WIEŻĄ" raised UnicodeEncodeError, so the report was lost.
Write stdout as UTF-8 instead.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
rsvg-convert is rarely installed on Windows, and cairocffi finds
libcairo-2.dll only through PATH, so check.py stopped at the cairosvg
import. Setting CAIROCFFI_DLL_DIRECTORIES did not help: the load still
failed with error 0x7e (Python 3.14, cairocffi 1.7.1).
When no folder on PATH holds libcairo-2.dll, look in the folders from
CAIROCFFI_DLL_DIRECTORIES and in the bin folders of common GTK installs
(MSYS2, GTK3 runtime, Inkscape, Siril, GIMP), and put the first match
on PATH for this process. Other systems are unchanged.
Co-Authored-By: Claude Opus 5.5 <[email protected]>