You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This commit was created on GitHub.com and signed with GitHub’s verified signature.
Added
Page::emitPath() and ContentStream::emitPath() take the modes 'fill-evenodd' (f*) and 'fillstroke-evenodd' (B*), which fill by
the even-odd rule: a subpath inside another is a hole whichever way round
it is drawn.
Page::fillPathWithPattern() and ContentStream::fillPathWithPattern()
fill any path with a registered shading pattern.
emitPath() and fillPathWithPattern() take any iterable of commands,
so a generator is written as it is read. A generator is consumed once.
SVG gradients fill paths, polygons, circles, ellipses and transformed
rectangles, not only plain rectangles, and honour gradientUnits="userSpaceOnUse". The pattern follows the shape's
transforms, its bounding box and gradientTransform. Before, those
shapes printed black. The objectBoundingBox of a curved path is the
curve's own extent, not the box of its control points, as in a browser.
TtfFile::exportState() and TtfFile::fromState() save a parsed font,
kerning included, as plain data and restore it without parsing — for a
cache across requests. A restore takes well under a millisecond against
0.4–3.6 ms to parse. The state carries TtfFile::STATE_FORMAT and a fingerprint of the
font's table directory: fromState() refuses, with an InvalidArgumentException, a state of another format, of another font
file, or a damaged one, nested values included. KerningTable::exportState()
and KerningTable::fromState() do the same for a kerning table. The four
methods are experimental: the state is for the application's own,
trusted cache, and a release that changes its layout bumps STATE_FORMAT, which only makes such a cache parse again. Documented in docs/*/USAGE.md under Custom fonts.
PdfFont::$compressionLevel sets the zlib level for embedded font
bodies (default 6, as before). Level 1 compresses a subset two to five
times faster and the stream is within a few percent of the level-6 size.
A level outside -1..9 is refused with an InvalidArgumentException.
Changed
Kerning is no longer expanded into glyph pairs. GPOS class-based
subtables (PairPos format 2) are kept as classes, and the whole table is
held as packed binary strings — for the usual value format, slices of the
font itself — searched in place. Fonts with class kerning parsed for tens
of milliseconds and held tens of megabytes: Inter Regular took 35 ms and
26 MB for its 447,676 pairs, Fira Sans 37 ms and 27 MB. They now take
about 1 ms and 0.25 MB; Merriweather's 102,000 explicit pairs take
0.7 ms and 0.5 MB instead of 38 ms and 7 MB. Every lookup answers as
before: compared pair by pair on 77 fonts.
KerningTable::addPairs() and KerningTable::addClasses() add packed
pairs and class subtables.
KerningTable::pairCount() returns the same number as before, but now
counts by expanding every class subtable into glyph pairs: it is meant
for diagnostics, not the render path. On a font with class kerning it
takes milliseconds and megabytes, as parsing did before; on a damaged GPOS table it can take far more.
Font subsetting is about twice as fast: table checksums are summed from
one unpack() instead of one call per 32-bit word. Inter Regular
subsets in 0.8 ms instead of 1.9 ms, Noto Sans JP in 4.0 ms instead of
8.2 ms; the subsets are byte-identical.
Fonts parse two to three times faster: the cmap (formats 4 and 12) and hmtx tables are read with one unpack() per array instead of one call
per value. Inter Regular parses in 0.7 ms instead of 1.9 ms, Noto Sans JP
(17,000 glyphs) in 3.4 ms instead of 9.2 ms. The parsed tables are
unchanged: identical on 241 fonts compared, the 8 others rejected with
the same errors as before.
Fixed
SVG ignored fill-rule, so every path and polygon filled by the nonzero
rule: a hole drawn the same way round as its outline — a ring of two
circles in one path, a single-path letter O, nested squares — filled
solid, and a five-point star with fill-rule="evenodd" had a filled
centre. fill-rule="evenodd" on the element, in its style, in a style
sheet or inherited from a group fills with f* (B* with a stroke).
A gradient fill on a <rect> inside a <g> printed black: walking into
a group dropped the document's gradients.
fill, stroke, stroke-width, fill-opacity and stroke-opacity
were read from each shape's own attribute only, so a group's <g fill="#f00"> was ignored and its shapes printed black. They are
inherited now, and read from inline style too, like the text properties.
Inside a transformed group, the transform of a nested group or shape
was ignored: <g transform="scale(2)"><g transform="translate(2,2)">, as
QR code generators write it, lost its translate. Nested transforms
compose now, and stroke widths follow the combined scale.
SVG circles and ellipses are drawn as four cubic Béziers instead of
36-sided polygons, so they are round at any size, and filled and
stroked as one path. A 25,000-dot scatter plot renders in half the
time with less than half the memory, and its PDF is a third of the size
(1.8 MB instead of 5.2 MB). A zero radius draws nothing, as SVG defines.
SVG path data is parsed and written as it is read. A dense chart or map
with a million path points peaked at about 500 MB, a PHP array per
command; it now peaks at about 11 MB, mostly the page's content stream.
<use> copies are capped at SvgRenderer::MAX_USE_COPIES (50,000)
elements per document. <use> elements that refer to groups of <use> elements, or a group with <use> references to itself, could
make a small file expand into millions of shapes and take minutes to
draw. A <use> that would pass the cap is left out, and later
references to the same element are refused without counting it again,
so thousands of <use> elements on one oversized group stay fast.
fill="url('#g')" — a gradient reference in quotes or with spaces —
filled paths and other shapes but printed a plain <rect> black.
opacity, fill-opacity and stroke-opacity were applied only to
untransformed rectangles, circles, ellipses and polygons: shapes under a transform, and every <path> and <line>, printed opaque.
Embedded font subsets kept the source font's head.checkSumAdjustment,
and the head entry of their table directory was summed with it, so the
subset's checksums were wrong: strict validators and font tools flag such
a font. The adjustment is zeroed for the table checksums and set so the
whole subset sums to 0xB1B0AFBA, as OpenType requires.
Embedded TrueType subsets were named after the whole font. Their /BaseFont and /FontName now start with a six-letter tag
(ISO 32000-1 §9.6.4), taken from a hash of the subset's bytes, so two
subsets of one font no longer share a name and the output stays
reproducible. The names in the output change: /BaseFont /LiberationSans
becomes /ABCDEF+LiberationSans. Fonts embedded whole and CFF fonts keep
the plain name.
PostScript names are written as PDF names (§7.3.5): delimiters, #,
whitespace and characters outside printable ASCII are escaped as #xx.
A TrueType subset carries a /CIDSet in its font descriptor, which
PDF/A-1 requires for a subset font (ISO 19005-1 §6.3.5). It lists every
glyph of the subset, as PDF/A-2 and 3 require of a CIDSet.