Skip to content

Commit

Permalink
Add all remaining test cases from resvg. (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurenzV authored Feb 12, 2024
1 parent 78d14ef commit 5dfd1fe
Show file tree
Hide file tree
Showing 198 changed files with 634 additions and 176 deletions.
7 changes: 7 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ that are part of the test suites. SVG files which don't have a corresponding ref
will be skipped. To regenerate this file, you can simply run `./scripts/gen-tests.py` and
it should work out of the box.

Note: The aim of the test cases it not necessarily to check whether the SVGs are rendered
correctly, but rather whether our SVGs output match the one from resvg. In most cases, if
it matches resvg it is also correct, because resvg is pretty good at rendering SVGs in general.
However, a couple of features are not implemented (e.g. `enableBackground` in filters), thus
they are not rendered correctly, but we consider the test case as passing anyway, because
it matches the output of resvg.

To run the tests, you can then just invoke `cargo test --release` (make sure to run it
in release mode, otherwise it will be very slow).

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/ref/resvg/filters/enable-background/new.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/ref/resvg/filters/feImage/with-x-y.png
Binary file added tests/ref/resvg/filters/filter/in=FillPaint.png
Binary file added tests/ref/resvg/filters/filter/in=StrokePaint.png
Binary file added tests/ref/resvg/filters/filter/on-a-thin-rect.png
Binary file added tests/ref/resvg/filters/filter/path-bbox.png
Binary file added tests/ref/resvg/filters/filter/with-mask.png
Binary file added tests/ref/resvg/masking/clip/simple-case.png
Binary file added tests/ref/resvg/masking/mask/mask-type-in-style.png
Binary file added tests/ref/resvg/paint-servers/stop/hsla-color.png
Binary file added tests/ref/resvg/painting/fill/#RGBA.png
Binary file added tests/ref/resvg/painting/fill/#RRGGBBAA.png
Binary file added tests/ref/resvg/painting/fill/icc-color.png
Binary file added tests/ref/resvg/painting/fill/rgb-int-int-int.png
Binary file added tests/ref/resvg/painting/marker/on-ArcTo.png
Binary file added tests/ref/resvg/painting/stroke-linejoin/arcs.png
Binary file added tests/ref/resvg/painting/stroke-width/negative.png
Binary file added tests/ref/resvg/shapes/rect/cap-values.png
Binary file added tests/ref/resvg/shapes/rect/ch-values.png
Binary file added tests/ref/resvg/shapes/rect/ic-values.png
Binary file added tests/ref/resvg/shapes/rect/lh-values.png
Binary file added tests/ref/resvg/shapes/rect/q-values.png
Binary file added tests/ref/resvg/shapes/rect/rem-values.png
Binary file added tests/ref/resvg/shapes/rect/rlh-values.png
Binary file added tests/ref/resvg/shapes/rect/vi-and-vb-values.png
Binary file added tests/ref/resvg/shapes/rect/vmin-and-vmax-values.png
Binary file added tests/ref/resvg/shapes/rect/vw-and-vh-values.png
Binary file added tests/ref/resvg/structure/image/url-to-png.png
Binary file added tests/ref/resvg/structure/image/url-to-svg.png
Binary file added tests/ref/resvg/structure/style/external-CSS.png
Binary file added tests/ref/resvg/structure/style/important.png
Binary file added tests/ref/resvg/text/font-family/font-list.png
Binary file added tests/ref/resvg/text/font-kerning/as-property.png
Binary file added tests/ref/resvg/text/font-size/named-value.png
Binary file added tests/ref/resvg/text/font-size/negative-size.png
Binary file added tests/ref/resvg/text/font-stretch/inherit.png
Binary file added tests/ref/resvg/text/font-stretch/narrower.png
Binary file added tests/ref/resvg/text/font-weight/650.png
Binary file added tests/ref/resvg/text/kerning/0.png
Binary file added tests/ref/resvg/text/lengthAdjust/vertical.png
Binary file added tests/ref/resvg/text/text-decoration/indirect.png
Binary file added tests/ref/resvg/text/text/filter-bbox.png
Binary file added tests/ref/resvg/text/text/real-text-height.png
Binary file added tests/ref/resvg/text/textPath/method=stretch.png
Binary file added tests/ref/resvg/text/textPath/side=right.png
Binary file added tests/ref/resvg/text/textPath/spacing=auto.png
Binary file added tests/ref/resvg/text/textPath/with-filter.png
Binary file added tests/ref/resvg/text/textPath/with-path.png
Binary file added tests/ref/resvg/text/tspan/tspan-bbox-1.png
Binary file added tests/ref/resvg/text/tspan/tspan-bbox-2.png
Binary file added tests/ref/resvg/text/tspan/with-clip-path.png
Binary file added tests/ref/resvg/text/tspan/with-filter.png
Binary file added tests/ref/resvg/text/tspan/with-mask.png
Binary file added tests/ref/resvg/text/tspan/with-opacity.png
Binary file added tests/ref/resvg/text/word-spacing/large-negative.png
Binary file added tests/ref/resvg/text/writing-mode/vertical-lr.png
Binary file added tests/ref/resvg/text/writing-mode/vertical-rl.png
119 changes: 118 additions & 1 deletion tests/scripts/gen-tests.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,124 @@
#!/usr/bin/env python3
import argparse
import shutil

from common import SVG_DIR, ROOT, TestFile
from pathlib import Path

OUT_PATH = ROOT / "src" / "test.rs"

NO_RELATIVE_PATHS = "no relative paths supported"
INVESTIGATE = "need to investigate"
NO_REFLECT = "spreadMethod reflect not supported"
NO_REPEAT = "spreadMethod repeat not supported"
NO_SUPPORT = "not supported in PDF"
NO_FONT = "font is not part of test suite yet"

IGNORE_TESTS = {
# The following test cases still need to be investigated
"svg/resvg/filters/fePointLight/primitiveUnits=objectBoundingBox.svg": INVESTIGATE,
"svg/resvg/filters/filter/with-mask-on-parent.svg": INVESTIGATE,
"svg/resvg/masking/mask/recursive-on-child.svg": INVESTIGATE,
"svg/resvg/paint-servers/pattern/nested-objectBoundingBox.svg": INVESTIGATE,
"svg/resvg/paint-servers/radialGradient/fr=0.2.svg": INVESTIGATE,
"svg/resvg/paint-servers/radialGradient/fr=0.5.svg": INVESTIGATE,
"svg/resvg/paint-servers/radialGradient/fr=0.7.svg": INVESTIGATE,
"svg/resvg/paint-servers/radialGradient/fr=-1.svg": INVESTIGATE,
"svg/resvg/paint-servers/radialGradient/invalid-gradientUnits.svg": INVESTIGATE,
"svg/resvg/painting/stroke-dasharray/n-0.svg": INVESTIGATE,
"svg/resvg/structure/image/image-with-float-size-scaling.svg": INVESTIGATE,
"svg/resvg/structure/svg/funcIRI-parsing.svg": INVESTIGATE,
"svg/resvg/structure/svg/funcIRI-with-invalid-characters.svg": INVESTIGATE,
"svg/resvg/text/font-weight/bolder-with-clamping.svg": INVESTIGATE,
"svg/resvg/text/font-weight/lighter-with-clamping.svg": INVESTIGATE,
"svg/resvg/text/font-weight/lighter-without-parent.svg": INVESTIGATE,
"svg/resvg/text/letter-spacing/mixed-scripts.svg": INVESTIGATE,
"svg/resvg/text/text/compound-emojis.svg": INVESTIGATE,
"svg/resvg/text/text/compound-emojis-and-coordinates-list.svg": INVESTIGATE,
"svg/resvg/text/text/emojis.svg": INVESTIGATE,

# The following test cases need to be excluded due to technical reasons
"svg/resvg/filters/feMorphology/huge-radius.svg": "will timeout CI",
"svg/resvg/filters/filter/huge-region.svg": "will sigkill",
"svg/resvg/structure/svg/negative-size.svg": "invalid size",
"svg/resvg/structure/svg/no-size.svg": "invalid size",
"svg/resvg/structure/svg/zero-size.svg": "invalid size",
"svg/resvg/structure/svg/not-UTF-8-encoding.svg": "invalid encoding",
"svg/resvg/filters/feImage/simple-case.svg": NO_RELATIVE_PATHS,
"svg/resvg/painting/marker/with-an-image-child.svg": NO_RELATIVE_PATHS,
"svg/resvg/painting/mix-blend-mode/color-dodge.svg": "pdfium bug",
"svg/resvg/painting/stroke-linecap/zero-length-path-with-round.svg": NO_SUPPORT,
"svg/resvg/painting/stroke-linecap/zero-length-path-with-square.svg": NO_SUPPORT,
"svg/resvg/painting/stroke-linejoin/miter-clip.svg": NO_SUPPORT,
"svg/resvg/structure/image/external-gif.svg": NO_RELATIVE_PATHS,
"svg/resvg/structure/image/external-jpeg.svg": NO_RELATIVE_PATHS,
"svg/resvg/structure/image/external-png.svg": NO_RELATIVE_PATHS,
"svg/resvg/structure/image/external-svg.svg": NO_RELATIVE_PATHS,
"svg/resvg/structure/image/external-svg-with-transform.svg": NO_RELATIVE_PATHS,
"svg/resvg/structure/image/external-svgz.svg": NO_RELATIVE_PATHS,
"svg/resvg/structure/image/float-size.svg": NO_RELATIVE_PATHS,
"svg/resvg/structure/image/no-height.svg": NO_RELATIVE_PATHS,
"svg/resvg/structure/image/no-height-on-svg.svg": NO_RELATIVE_PATHS,
"svg/resvg/structure/image/no-width.svg": NO_RELATIVE_PATHS,
"svg/resvg/structure/image/no-width-on-svg.svg": NO_RELATIVE_PATHS,
"svg/resvg/structure/image/no-width-and-height.svg": NO_RELATIVE_PATHS,
"svg/resvg/structure/image/no-width-and-height-on-svg.svg": NO_RELATIVE_PATHS,
"svg/resvg/structure/image/raster-image-and-size-with-odd-numbers.svg": NO_RELATIVE_PATHS,
"svg/resvg/structure/image/recursive-1.svg": NO_RELATIVE_PATHS,
"svg/resvg/structure/image/recursive-2.svg": NO_RELATIVE_PATHS,
"svg/resvg/structure/image/width-and-height-set-to-auto.svg": NO_RELATIVE_PATHS,
"svg/resvg/structure/image/zero-height.svg": NO_RELATIVE_PATHS,
"svg/resvg/structure/image/zero-width.svg": NO_RELATIVE_PATHS,

# The following test cases are not implemented in svg2pdf yet
"svg/resvg/paint-servers/linearGradient/attributes-via-xlink-href-complex-order.svg": NO_REFLECT,
"svg/resvg/paint-servers/linearGradient/attributes-via-xlink-href-from-radialGradient.svg": NO_REFLECT,
"svg/resvg/paint-servers/linearGradient/spreadMethod=reflect.svg": NO_REFLECT,
"svg/resvg/paint-servers/linearGradient/spreadMethod=repeat.svg": NO_REPEAT,
"svg/resvg/paint-servers/radialGradient/attributes-via-xlink-href-complex-order.svg":NO_REFLECT,
"svg/resvg/paint-servers/radialGradient/attributes-via-xlink-href-from-linearGradient.svg": NO_REFLECT,
"svg/resvg/paint-servers/radialGradient/spreadMethod=reflect.svg": NO_REFLECT,
"svg/resvg/paint-servers/radialGradient/spreadMethod=repeat.svg": NO_REPEAT,

# The following test cases don't work yet because we are not including
# all necessary fonts.
"svg/resvg/text/alignment-baseline/hanging-on-vertical.svg": NO_FONT,
"svg/resvg/text/direction/rtl.svg": NO_FONT,
"svg/resvg/text/direction/rtl-with-vertical-writing-mode.svg": NO_FONT,
"svg/resvg/text/dominant-baseline/hanging.svg": NO_FONT,
"svg/resvg/text/dominant-baseline/use-script.svg": NO_FONT,
"svg/resvg/text/font/simple-case.svg": NO_FONT,
"svg/resvg/text/font-family/bold-sans-serif.svg": NO_FONT,
"svg/resvg/text/font-family/cursive.svg": NO_FONT,
"svg/resvg/text/font-family/fallback-1.svg": NO_FONT,
"svg/resvg/text/font-family/fantasy.svg": NO_FONT,
"svg/resvg/text/font-family/monospace.svg": NO_FONT,
"svg/resvg/text/font-family/sans-serif.svg": NO_FONT,
"svg/resvg/text/font-family/serif.svg": NO_FONT,
"svg/resvg/text/font-family/source-sans-pro.svg": NO_FONT,
"svg/resvg/text/font-kerning/arabic-script.svg": NO_FONT,
"svg/resvg/text/letter-spacing/non-ASCII-character.svg": NO_FONT,
"svg/resvg/text/letter-spacing/on-Arabic.svg": NO_FONT,
"svg/resvg/text/text/bidi-reordering.svg": NO_FONT,
"svg/resvg/text/text/fill-rule=evenodd.svg": NO_FONT,
"svg/resvg/text/text/rotate-on-Arabic.svg": NO_FONT,
"svg/resvg/text/text/x-and-y-with-multiple-values-and-arabic-text.svg": NO_FONT,
"svg/resvg/text/text/xml-lang=ja.svg": NO_FONT,
"svg/resvg/text/text-anchor/on-tspan-with-arabic.svg": NO_FONT,
"svg/resvg/text/textLength/arabic.svg": NO_FONT,
"svg/resvg/text/textLength/arabic-with-lengthAdjust.svg": NO_FONT,
"svg/resvg/text/textPath/complex.svg": NO_FONT,
"svg/resvg/text/textPath/writing-mode=tb.svg": NO_FONT,
"svg/resvg/text/tspan/bidi-reordering.svg": NO_FONT,
"svg/resvg/text/unicode-bidi/bidi-override.svg": NO_FONT,
"svg/resvg/text/writing-mode/arabic-with-rl.svg": NO_FONT,
"svg/resvg/text/writing-mode/japanese-with-tb.svg": NO_FONT,
"svg/resvg/text/writing-mode/mixed-languages-with-tb.svg": NO_FONT,
"svg/resvg/text/writing-mode/mixed-languages-with-tb-and-underline.svg": NO_FONT,
"svg/resvg/text/writing-mode/tb-and-punctuation.svg": NO_FONT,
"svg/resvg/text/writing-mode/tb-with-rotate.svg": NO_FONT,
"svg/resvg/text/writing-mode/tb-with-rotate-and-underline.svg": NO_FONT,
}

def main():
parser = argparse.ArgumentParser(
Expand Down Expand Up @@ -33,7 +146,11 @@ def main():
.replace("#", "")
)

if not test_file.has_ref():
if str(test_file.svg_path()) in IGNORE_TESTS:
test_string += f"// {IGNORE_TESTS[str(test_file.svg_path())]}\n"
test_string += "#[ignore] "
elif not test_file.has_ref():
test_string += f"// unknown reason\n"
test_string += "#[ignore] "

test_string += "#[test] "
Expand Down
30 changes: 17 additions & 13 deletions tests/scripts/sync-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,30 @@
SVG2PDF_SVG_DIR = Path("../svg/resvg")
SVG2PDF_REF_DIR = Path("../ref/resvg")

resvg_svg_files = set([p.relative_to(RESVG_SVG_DIR) for p in RESVG_SVG_DIR.rglob("*")])
resvg_svg_files = set([p.relative_to(RESVG_SVG_DIR) for p in RESVG_SVG_DIR.rglob("*") if p.suffix == ".svg"])
svg2pdf_svg_files = set([p.relative_to(SVG2PDF_SVG_DIR) for p in SVG2PDF_SVG_DIR.rglob("*")])
svg2pdf_ref_files = set([p.relative_to(SVG2PDF_REF_DIR) for p in SVG2PDF_REF_DIR.rglob("*")])


def sync_existing_tests():
print("Sync tests...")
for file in resvg_svg_files:
if file.is_file() and file.suffix == ".svg":
with open(RESVG_SVG_DIR / file, "r", encoding="utf-8") as resvg_file:
content = resvg_file.read()

path = SVG2PDF_SVG_DIR / file
print(path)
print(path.parent)
if not path.parent.exists():
path.parent.mkdir(parents=True, exist_ok=True)

with open(path, "w+") as svg2pdf_file:
svg2pdf_file.write(content)
absolute_path = RESVG_SVG_DIR / file
assert absolute_path.is_file()

if str(file) == "structure/svg/not-UTF-8-encoding.svg":
continue

with open(absolute_path, "r") as resvg_file:
content = resvg_file.read()

path = SVG2PDF_SVG_DIR / file
if not path.parent.exists():
path.parent.mkdir(parents=True, exist_ok=True)

with open(path, "w+") as svg2pdf_file:
svg2pdf_file.write(content)



def find_superfluous_tests():
Expand Down
3 changes: 1 addition & 2 deletions tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,8 @@ fn is_pix_diff(pixel1: &Rgba<u8>, pixel2: &Rgba<u8>) -> bool {

/// Runs a single test instance.
pub fn run_test(svg_path: &str, ref_path: &str, diff_path: &str, replace: bool) -> i32 {
let expected_image = Reader::open(ref_path).unwrap().decode().unwrap().into_rgba8();

let (_, actual_image) = convert_svg(&fs::read_to_string(svg_path).unwrap());
let expected_image = Reader::open(ref_path).unwrap().decode().unwrap().into_rgba8();

let width = max(expected_image.width(), actual_image.width());
let height = max(expected_image.height(), actual_image.height());
Expand Down
Loading

0 comments on commit 5dfd1fe

Please sign in to comment.