Skip to content

Commit

Permalink
Merge pull request #104 from googlefonts/resvg
Browse files Browse the repository at this point in the history
Use resvg instead of cairosvg for Skia rasterization tests
  • Loading branch information
anthrotype authored Aug 19, 2020
2 parents a0d4948 + a0b1a3d commit 8c27a69
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 20 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ See https://googlefonts.github.io/python#make-a-release.
## QA

To help confirm valid output `nanoemoji` can optionally perform image diffs
between cairosvg rendering and Skia rendering from the compiled font. Usage:
between resvg rendering of the original SVGs and Skia rendering from the compiled font. Usage:

```
# Mac only for now, make sure colr_test is compiled and on PATH
Expand All @@ -30,6 +30,10 @@ git clone [email protected]:rsheeter/skia_colr.git
export PATH="$PATH:$(cd skia_colr/out/Static/ && pwd)"
which colr_test
# Make sure resvg tool is compiled and on PATH. E.g. you can use cargo to install it
cargo install resvg
which resvg
# Get some svgs to play with
git clone --recursive [email protected]:googlefonts/color-fonts.git
Expand Down
13 changes: 3 additions & 10 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,23 @@ absl-py==0.9.0 # via nanoemoji (setup.py)
appdirs==1.4.4 # via fs
attrs==19.3.0 # via ufolib2
booleanoperations==0.9.0 # via ufo2ft
cairocffi==1.1.0 # via cairosvg
cairosvg==2.4.2 # via nanoemoji (setup.py)
cffi==1.14.1 # via cairocffi
cffsubr==0.2.7 # via ufo2ft
compreffor==0.5.0 # via ufo2ft
cssselect2==0.3.0 # via cairosvg
cu2qu==1.6.7 # via ufo2ft
defusedxml==0.6.0 # via cairosvg
fonttools[ufo]==4.14.0 # via booleanoperations, cffsubr, compreffor, cu2qu, nanoemoji (setup.py), ufo2ft, ufolib2
fs==2.4.11 # via fonttools
lxml==4.5.2 # via nanoemoji (setup.py), picosvg
ninja==1.10.0.post1 # via nanoemoji (setup.py)
picosvg==0.6.1 # via nanoemoji (setup.py)
pillow==7.2.0 # via cairosvg, nanoemoji (setup.py)
pillow==7.2.0 # via nanoemoji (setup.py)
pyclipper==1.2.0 # via booleanoperations
pycparser==2.20 # via cffi
pytz==2020.1 # via fs
regex==2020.7.14 # via nanoemoji (setup.py)
six==1.15.0 # via absl-py, fs
skia-pathops==0.4.1 # via picosvg
tinycss2==1.0.2 # via cairosvg, cssselect2
typing-extensions==3.7.4.2 # via ufolib2
ufo2ft[cffsubr]==2.15.0 # via nanoemoji (setup.py)
ufolib2==0.6.2 # via nanoemoji (setup.py)
webencodings==0.5.1 # via cssselect2, tinycss2
ufolib2==0.8.0 # via nanoemoji (setup.py)

# The following packages are considered to be unsafe in a requirements file:
# setuptools
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
setup_requires=["setuptools_scm"],
install_requires=[
"absl-py>=0.9.0",
"cairosvg>=2.4.2",
"fonttools[ufo]>=4.13.0",
"lxml>=4.0",
"ninja>=1.10.0.post1",
Expand Down
14 changes: 7 additions & 7 deletions src/nanoemoji/nanoemoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def module_rule(mod_name, arg_pattern):
if FLAGS.gen_svg_font_diffs:
nw.rule(
"write_svg2png",
f"cairosvg -H {FLAGS.svg_font_diff_resolution} -W {FLAGS.svg_font_diff_resolution} -f png -o $out $in",
f"resvg -h {FLAGS.svg_font_diff_resolution} -w {FLAGS.svg_font_diff_resolution} $in $out",
)
module_rule(
"write_font2png",
Expand All @@ -111,7 +111,7 @@ def module_rule(mod_name, arg_pattern):
)
module_rule(
"write_diffreport",
f"--lhs_dir cairo_png --rhs_dir skia_png --output_file $out $in",
f"--lhs_dir resvg_png --rhs_dir skia_png --output_file $out $in",
)
nw.newline()

Expand All @@ -120,9 +120,9 @@ def picosvg_dest(input_svg: str) -> str:
return os.path.join("picosvg", os.path.basename(input_svg))


def cairo_png_dest(input_svg: str) -> str:
def resvg_png_dest(input_svg: str) -> str:
dest_file = os.path.splitext(os.path.basename(input_svg))[0] + ".png"
return os.path.join("cairo_png", dest_file)
return os.path.join("resvg_png", dest_file)


def font_dest() -> str:
Expand Down Expand Up @@ -169,7 +169,7 @@ def write_svg_font_diff_build(nw: ninja_syntax.Writer, svg_files: Sequence[str])

# render each svg => png
for svg_file in svg_files:
nw.build(cairo_png_dest(svg_file), "write_svg2png", rel_build(svg_file))
nw.build(resvg_png_dest(svg_file), "write_svg2png", rel_build(svg_file))
nw.newline()

# render each input from the font => png
Expand All @@ -184,7 +184,7 @@ def write_svg_font_diff_build(nw: ninja_syntax.Writer, svg_files: Sequence[str])
# create comparison images
for svg_file in svg_files:
inputs = [
cairo_png_dest(svg_file),
resvg_png_dest(svg_file),
skia_png_dest(svg_file),
]
nw.build(diff_png_dest(svg_file), "write_pngdiff", inputs)
Expand All @@ -202,7 +202,7 @@ def _run(argv):

os.makedirs(build_dir(), exist_ok=True)
if FLAGS.gen_svg_font_diffs:
os.makedirs(os.path.join(build_dir(), "cairo_png"), exist_ok=True)
os.makedirs(os.path.join(build_dir(), "resvg_png"), exist_ok=True)
os.makedirs(os.path.join(build_dir(), "skia_png"), exist_ok=True)
os.makedirs(os.path.join(build_dir(), "diff_png"), exist_ok=True)

Expand Down
2 changes: 1 addition & 1 deletion src/nanoemoji/write_diffreport.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def main(argv):
<body>
<div>
<span class="title">Cairo</span>
<span class="title">resvg</span>
<span class="title">Bad Pixels</span>
<span class="title">Skia</span>
</div>
Expand Down

0 comments on commit 8c27a69

Please sign in to comment.