Files
indd-utils/tools/validate.sh
T
aiongg a9985b3775 fix: validate every corpus output and fix the two schema failures
compare.py --all now also converts the INDD and INDT files that have no
same-version IDML (any version, either byte order), validates them and
counts converter warnings by kind. validate.sh runs Jing once per schema
instead of once per file, which makes validating the whole corpus take
about 3 minutes.

Two schema failures showed up in files without an IDML:

- Gradient swatch midpoints are stored as positions from the start of
  the gradient. IDML wants them relative to the gap between two stops,
  as for opacity gradient stops. Values outside 13-87 are left out with
  a warning.
- The style kind is a u16, not a u32. One InDesign 7.5 template has a
  non-zero u16 after it, which made 151 character styles paragraph
  styles.
2026-10-07 03:50:08 +00:00

40 lines
1.8 KiB
Bash
Executable File

#!/bin/sh
# Validate the XML parts of an IDML package against IDML RelaxNG compact
# schemas (the package schemas InDesign generates with generateIDMLSchema).
#
# Usage: tools/validate.sh <file.idml> <schema-dir> <jing-dir>
# schema-dir: directory with designmap.rnc, Spreads/Spread.rnc, ...
# jing-dir: directory with jing.jar, isorelax.jar, saxon.jar
# The schemas and Jing are not part of this repository.
set -eu
idml=$1; schemas=$(cd "$2" && pwd); jing=$(cd "$3" && pwd)
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
unzip -qq "$idml" -d "$tmp"
# The generated schemas pin DOMVersion to the generating InDesign's version;
# validate structure regardless of the version written.
dom=$(grep -o 'DOMVersion="[^"]*"' "$schemas/designmap.rnc" | head -1)
[ -z "$dom" ] && dom=$(grep -o '"[0-9][0-9]*\.[0-9]"' "$schemas/designmap.rnc" | head -1 | sed 's/^/DOMVersion=/')
find "$tmp" -name '*.xml' -exec sed -i "s/DOMVersion=\"[^\"]*\"/$dom/" {} +
cp="$jing/jing.jar:$jing/isorelax.jar:$jing/saxon.jar"
status=0
check() { # schema file... (one Jing run per schema)
schema=$1; shift
[ $# -gt 0 ] || return 0
if ! out=$(java -cp "$cp" com.thaiopensource.relaxng.util.Driver -c "$schemas/$schema" "$@" 2>&1); then
status=1
fi
[ -n "$out" ] && printf '%s\n' "$out" | sed "s|$tmp/||"
return 0
}
existing() { for f in "$@"; do [ -f "$f" ] && printf '%s\n' "$f"; done; }
cd "$tmp"
check designmap.rnc $(existing designmap.xml)
check Spreads/Spread.rnc $(existing Spreads/*.xml)
check MasterSpreads/MasterSpread.rnc $(existing MasterSpreads/*.xml)
check Stories/Story.rnc $(existing Stories/*.xml)
for p in Fonts Graphic Preferences Styles; do check "Resources/$p.rnc" $(existing "Resources/$p.xml"); done
check XML/BackingStory.rnc $(existing XML/BackingStory.xml)
check XML/Tags.rnc $(existing XML/Tags.xml)
exit $status