diff --git a/.gitattributes b/.gitattributes index bae5aac131ffc99b6ca2595c873615046c9a60c5..e98102e130418fd969a48e6205744f77b7a539e5 100644 --- a/.gitattributes +++ b/.gitattributes @@ -82,3 +82,11 @@ hug/lib/python3.12/site-packages/fontTools/feaLib/lexer.cpython-312-x86_64-linux hug/lib/python3.12/site-packages/fontTools/misc/bezierTools.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text hug/lib/python3.12/site-packages/fontTools/otlLib/__pycache__/builder.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text hug/lib/python3.12/site-packages/fontTools/pens/momentsPen.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text +hug/lib/python3.12/site-packages/fontTools/qu2cu/qu2cu.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text +hug/lib/python3.12/site-packages/fontTools/subset/__pycache__/__init__.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text +hug/lib/python3.12/site-packages/fontTools/ttLib/tables/__pycache__/_g_l_y_f.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text +hug/lib/python3.12/site-packages/fontTools/ttLib/tables/__pycache__/otConverters.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text +hug/lib/python3.12/site-packages/fontTools/ttLib/tables/__pycache__/otData.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text +hug/lib/python3.12/site-packages/fontTools/ttLib/tables/__pycache__/otTables.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text +hug/lib/python3.12/site-packages/fontTools/varLib/instancer/__pycache__/__init__.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text +hug/lib/python3.12/site-packages/fontTools/varLib/iup.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text diff --git a/hug/lib/python3.12/site-packages/fontTools/qu2cu/qu2cu.cpython-312-x86_64-linux-gnu.so b/hug/lib/python3.12/site-packages/fontTools/qu2cu/qu2cu.cpython-312-x86_64-linux-gnu.so new file mode 100644 index 0000000000000000000000000000000000000000..47d2ddaf92896f67848c3eba65e26973cfb9f22a --- /dev/null +++ b/hug/lib/python3.12/site-packages/fontTools/qu2cu/qu2cu.cpython-312-x86_64-linux-gnu.so @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2fbd70ae5a59ce150f1ec69d7de9e42473a039b81d9487253aceb698de7b46b6 +size 1476144 diff --git a/hug/lib/python3.12/site-packages/fontTools/qu2cu/qu2cu.py b/hug/lib/python3.12/site-packages/fontTools/qu2cu/qu2cu.py new file mode 100644 index 0000000000000000000000000000000000000000..b3ca651c3839d95a0b40c07b871f8005fa388ae0 --- /dev/null +++ b/hug/lib/python3.12/site-packages/fontTools/qu2cu/qu2cu.py @@ -0,0 +1,433 @@ +# cython: language_level=3 +# distutils: define_macros=CYTHON_TRACE_NOGIL=1 + +# Copyright 2023 Google Inc. All Rights Reserved. +# Copyright 2023 Behdad Esfahbod. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +try: + import cython +except (AttributeError, ImportError): + # if cython not installed, use mock module with no-op decorators and types + from fontTools.misc import cython +COMPILED = cython.compiled + +from fontTools.misc.bezierTools import splitCubicAtTC +from collections import namedtuple +import math +from typing import ( + List, + Sequence, + Tuple, + Union, +) + +__all__ = ["quadratic_to_curves"] + + +# Copied from cu2qu +@cython.cfunc +@cython.returns(cython.int) +@cython.locals( + tolerance=cython.double, + p0=cython.complex, + p1=cython.complex, + p2=cython.complex, + p3=cython.complex, +) +@cython.locals(mid=cython.complex, deriv3=cython.complex) +def cubic_farthest_fit_inside(p0, p1, p2, p3, tolerance): + """Check if a cubic Bezier lies within a given distance of the origin. + + "Origin" means *the* origin (0,0), not the start of the curve. Note that no + checks are made on the start and end positions of the curve; this function + only checks the inside of the curve. + + Args: + p0 (complex): Start point of curve. + p1 (complex): First handle of curve. + p2 (complex): Second handle of curve. + p3 (complex): End point of curve. + tolerance (double): Distance from origin. + + Returns: + bool: True if the cubic Bezier ``p`` entirely lies within a distance + ``tolerance`` of the origin, False otherwise. + """ + # First check p2 then p1, as p2 has higher error early on. + if abs(p2) <= tolerance and abs(p1) <= tolerance: + return True + + # Split. + mid = (p0 + 3 * (p1 + p2) + p3) * 0.125 + if abs(mid) > tolerance: + return False + deriv3 = (p3 + p2 - p1 - p0) * 0.125 + return cubic_farthest_fit_inside( + p0, (p0 + p1) * 0.5, mid - deriv3, mid, tolerance + ) and cubic_farthest_fit_inside(mid, mid + deriv3, (p2 + p3) * 0.5, p3, tolerance) + + +@cython.locals( + p0=cython.complex, + p1=cython.complex, + p2=cython.complex, + p1_2_3=cython.complex, +) +def elevate_quadratic(p0, p1, p2): + """Given a quadratic bezier curve, return its degree-elevated cubic.""" + + # https://pomax.github.io/bezierinfo/#reordering + p1_2_3 = p1 * (2 / 3) + return ( + p0, + (p0 * (1 / 3) + p1_2_3), + (p2 * (1 / 3) + p1_2_3), + p2, + ) + + +@cython.cfunc +@cython.locals( + start=cython.int, + n=cython.int, + k=cython.int, + prod_ratio=cython.double, + sum_ratio=cython.double, + ratio=cython.double, + t=cython.double, + p0=cython.complex, + p1=cython.complex, + p2=cython.complex, + p3=cython.complex, +) +def merge_curves(curves, start, n): + """Give a cubic-Bezier spline, reconstruct one cubic-Bezier + that has the same endpoints and tangents and approxmates + the spline.""" + + # Reconstruct the t values of the cut segments + prod_ratio = 1.0 + sum_ratio = 1.0 + ts = [1] + for k in range(1, n): + ck = curves[start + k] + c_before = curves[start + k - 1] + + # |t_(k+1) - t_k| / |t_k - t_(k - 1)| = ratio + assert ck[0] == c_before[3] + ratio = abs(ck[1] - ck[0]) / abs(c_before[3] - c_before[2]) + + prod_ratio *= ratio + sum_ratio += prod_ratio + ts.append(sum_ratio) + + # (t(n) - t(n - 1)) / (t_(1) - t(0)) = prod_ratio + + ts = [t / sum_ratio for t in ts[:-1]] + + p0 = curves[start][0] + p1 = curves[start][1] + p2 = curves[start + n - 1][2] + p3 = curves[start + n - 1][3] + + # Build the curve by scaling the control-points. + p1 = p0 + (p1 - p0) / (ts[0] if ts else 1) + p2 = p3 + (p2 - p3) / ((1 - ts[-1]) if ts else 1) + + curve = (p0, p1, p2, p3) + + return curve, ts + + +@cython.locals( + count=cython.int, + num_offcurves=cython.int, + i=cython.int, + off1=cython.complex, + off2=cython.complex, + on=cython.complex, +) +def add_implicit_on_curves(p): + q = list(p) + count = 0 + num_offcurves = len(p) - 2 + for i in range(1, num_offcurves): + off1 = p[i] + off2 = p[i + 1] + on = off1 + (off2 - off1) * 0.5 + q.insert(i + 1 + count, on) + count += 1 + return q + + +Point = Union[Tuple[float, float], complex] + + +def _raise_incompatible_point(point, previous_point): + raise ValueError( + f"Quadratic splines must connect end-to-start; got {previous_point!r} then {point!r}" + ) + + +def _validate_spline_length(spline): + if len(spline) < 3: + raise ValueError("Quadratic splines must contain at least 3 points") + + +def _validate_positive_tolerance(max_err): + if max_err <= 0: + raise ValueError("max_err must be greater than zero") + + +@cython.locals( + cost=cython.int, + is_complex=cython.int, +) +def quadratic_to_curves( + quads: List[Sequence[Point]], + max_err: float = 0.5, + all_cubic: bool = False, +) -> List[Tuple[Point, ...]]: + """Converts a connecting list of quadratic splines to a list of quadratic + and cubic curves. + + A quadratic spline is specified as a sequence of points. Either each point is + a 2-tuple of X,Y coordinates, or each point is a complex number with + real/imaginary components representing X,Y coordinates. + + The first and last points are on-curve points and the rest are off-curve + points, with an implied on-curve point in the middle between every two + consequtive off-curve points. + + Returns: + The output is a list of tuples of points. Points are represented + in the same format as the input, either as 2-tuples or complex numbers. + If ``quads`` is empty, returns an empty list. + + Each tuple is either of length three, for a quadratic curve, or four, + for a cubic curve. Each curve's last point is the same as the next + curve's first point. + + Args: + quads: quadratic splines + + max_err: absolute error tolerance; defaults to 0.5 + + all_cubic: if True, only cubic curves are generated; defaults to False + + Raises: + ValueError: if an input spline has fewer than 3 points, or if adjacent + splines do not connect end-to-start. + """ + if not quads: + return [] + _validate_positive_tolerance(max_err) + for spline in quads: + _validate_spline_length(spline) + + is_complex = type(quads[0][0]) is complex + if not is_complex: + quads = [[complex(x, y) for (x, y) in p] for p in quads] + + q = [quads[0][0]] + costs = [1] + cost = 1 + for p in quads: + if q[-1] != p[0]: + _raise_incompatible_point(p[0], q[-1]) + for i in range(len(p) - 2): + cost += 1 + costs.append(cost) + costs.append(cost) + qq = add_implicit_on_curves(p)[1:] + costs.pop() + q.extend(qq) + cost += 1 + costs.append(cost) + + curves = spline_to_curves(q, costs, max_err, all_cubic) + + if not is_complex: + curves = [tuple((c.real, c.imag) for c in curve) for curve in curves] + return curves + + +Solution = namedtuple("Solution", ["num_points", "error", "start_index", "is_cubic"]) + + +@cython.locals( + i=cython.int, + j=cython.int, + k=cython.int, + start=cython.int, + i_sol_count=cython.int, + j_sol_count=cython.int, + this_sol_count=cython.int, + tolerance=cython.double, + err=cython.double, + error=cython.double, + i_sol_error=cython.double, + j_sol_error=cython.double, + all_cubic=cython.int, + is_cubic=cython.int, + count=cython.int, + p0=cython.complex, + p1=cython.complex, + p2=cython.complex, + p3=cython.complex, + v=cython.complex, + u=cython.complex, +) +def spline_to_curves(q, costs, tolerance=0.5, all_cubic=False): + """ + q: quadratic spline with alternating on-curve / off-curve points. + + costs: cumulative list of encoding cost of q in terms of number of + points that need to be encoded. Implied on-curve points do not + contribute to the cost. If all points need to be encoded, then + costs will be range(1, len(q)+1). + """ + + assert len(q) >= 3, "quadratic spline requires at least 3 points" + + # Elevate quadratic segments to cubic + elevated_quadratics = [ + elevate_quadratic(*q[i : i + 3]) for i in range(0, len(q) - 2, 2) + ] + + # Find sharp corners; they have to be oncurves for sure. + forced = set() + for i in range(1, len(elevated_quadratics)): + p0 = elevated_quadratics[i - 1][2] + p1 = elevated_quadratics[i][0] + p2 = elevated_quadratics[i][1] + if abs(p1 - p0) + abs(p2 - p1) > tolerance + abs(p2 - p0): + forced.add(i) + + # Dynamic-Programming to find the solution with fewest number of + # cubic curves, and within those the one with smallest error. + sols = [Solution(0, 0, 0, False)] + impossible = Solution(len(elevated_quadratics) * 3 + 1, 0, 1, False) + start = 0 + for i in range(1, len(elevated_quadratics) + 1): + best_sol = impossible + for j in range(start, i): + j_sol_count, j_sol_error = sols[j].num_points, sols[j].error + + if not all_cubic: + # Solution with quadratics between j:i + this_count = costs[2 * i - 1] - costs[2 * j] + 1 + i_sol_count = j_sol_count + this_count + i_sol_error = j_sol_error + i_sol = Solution(i_sol_count, i_sol_error, i - j, False) + if i_sol < best_sol: + best_sol = i_sol + + if this_count <= 3: + # Can't get any better than this in the path below + continue + + # Fit elevated_quadratics[j:i] into one cubic + try: + curve, ts = merge_curves(elevated_quadratics, j, i - j) + except ZeroDivisionError: + continue + + # Now reconstruct the segments from the fitted curve + reconstructed_iter = splitCubicAtTC(*curve, *ts) + reconstructed = [] + + # Knot errors + error = 0 + for k, reconst in enumerate(reconstructed_iter): + orig = elevated_quadratics[j + k] + err = abs(reconst[3] - orig[3]) + error = max(error, err) + if error > tolerance: + break + reconstructed.append(reconst) + if error > tolerance: + # Not feasible + continue + + # Interior errors + for k, reconst in enumerate(reconstructed): + orig = elevated_quadratics[j + k] + p0, p1, p2, p3 = tuple(v - u for v, u in zip(reconst, orig)) + + if not cubic_farthest_fit_inside(p0, p1, p2, p3, tolerance): + error = tolerance + 1 + break + if error > tolerance: + # Not feasible + continue + + # Save best solution + i_sol_count = j_sol_count + 3 + i_sol_error = max(j_sol_error, error) + i_sol = Solution(i_sol_count, i_sol_error, i - j, True) + if i_sol < best_sol: + best_sol = i_sol + + if i_sol_count == 3: + # Can't get any better than this + break + + sols.append(best_sol) + if i in forced: + start = i + + # Reconstruct solution + splits = [] + cubic = [] + i = len(sols) - 1 + while i: + count, is_cubic = sols[i].start_index, sols[i].is_cubic + splits.append(i) + cubic.append(is_cubic) + i -= count + curves = [] + j = 0 + for i, is_cubic in reversed(list(zip(splits, cubic))): + if is_cubic: + curves.append(merge_curves(elevated_quadratics, j, i - j)[0]) + else: + for k in range(j, i): + curves.append(q[k * 2 : k * 2 + 3]) + j = i + + return curves + + +def main(): + from fontTools.cu2qu.benchmark import generate_curve + from fontTools.cu2qu import curve_to_quadratic + + tolerance = 0.05 + reconstruct_tolerance = tolerance * 1 + curve = generate_curve() + quadratics = curve_to_quadratic(curve, tolerance) + print( + "cu2qu tolerance %g. qu2cu tolerance %g." % (tolerance, reconstruct_tolerance) + ) + print("One random cubic turned into %d quadratics." % len(quadratics)) + curves = quadratic_to_curves([quadratics], reconstruct_tolerance) + print("Those quadratics turned back into %d cubics. " % len(curves)) + print("Original curve:", curve) + print("Reconstructed curve(s):", curves) + + +if __name__ == "__main__": + main() diff --git a/hug/lib/python3.12/site-packages/fontTools/subset/__init__.py b/hug/lib/python3.12/site-packages/fontTools/subset/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..04f1df6fee9f68c2dd6d1e284560e66c4d542430 --- /dev/null +++ b/hug/lib/python3.12/site-packages/fontTools/subset/__init__.py @@ -0,0 +1,4348 @@ +# Copyright 2013 Google, Inc. All Rights Reserved. +# +# Google Author(s): Behdad Esfahbod + +from __future__ import annotations + +from fontTools import config +from fontTools.misc.roundTools import otRound +from fontTools import ttLib +from fontTools.ttLib.tables import otTables +from fontTools.ttLib.tables.otBase import USE_HARFBUZZ_REPACKER +from fontTools.ttLib.beyond64k import _compact_layout_tables +from fontTools.otlLib.maxContextCalc import maxCtxFont +from fontTools.pens.basePen import NullPen +from fontTools.misc.loggingTools import Timer +from fontTools.misc.cliTools import makeOutputFileName +from fontTools.subset.util import _add_method, _uniq_sort +from fontTools.subset.cff import * +from fontTools.subset.svg import * +from fontTools.varLib import varStore, multiVarStore # For monkey-patching +from fontTools.ttLib.tables._n_a_m_e import NameRecordVisitor, makeName +from fontTools.unicodedata import mirrored +import sys +import struct +import array +import logging +from collections import Counter, defaultdict +from functools import reduce +from types import MethodType + +__usage__ = "fonttools subset font-file [glyph...] [--option=value]..." + +__doc__ = ( + """\ +fonttools subset -- OpenType font subsetter and optimizer + +fonttools subset is an OpenType font subsetter and optimizer, based on +fontTools. It accepts any TT- or CFF-flavored OpenType (.otf or .ttf) +or WOFF (.woff) font file. The subsetted glyph set is based on the +specified glyphs or characters, and specified OpenType layout features. + +The tool also performs some size-reducing optimizations, aimed for using +subset fonts as webfonts. Individual optimizations can be enabled or +disabled, and are enabled by default when they are safe. + +Usage: """ + + __usage__ + + """ + +At least one glyph or one of --gids, --gids-file, --glyphs, --glyphs-file, +--text, --text-file, --unicodes, or --unicodes-file, must be specified. + +Args: + +font-file + The input font file. +glyph + Specify one or more glyph identifiers to include in the subset. Must be + PS glyph names, or the special string '*' to keep the entire glyph set. + +Initial glyph set specification +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +These options populate the initial glyph set. Same option can appear +multiple times, and the results are accummulated. + +--gids=[,...] + Specify comma/whitespace-separated list of glyph IDs or ranges as decimal + numbers. For example, --gids=10-12,14 adds glyphs with numbers 10, 11, + 12, and 14. + +--gids-file= + Like --gids but reads from a file. Anything after a '#' on any line is + ignored as comments. + +--glyphs=[,...] + Specify comma/whitespace-separated PS glyph names to add to the subset. + Note that only PS glyph names are accepted, not gidNNN, U+XXXX, etc + that are accepted on the command line. The special string '*' will keep + the entire glyph set. + +--glyphs-file= + Like --glyphs but reads from a file. Anything after a '#' on any line + is ignored as comments. + +--text= + Specify characters to include in the subset, as UTF-8 string. + +--text-file= + Like --text but reads from a file. Newline character are not added to + the subset. + +--unicodes=[,...] + Specify comma/whitespace-separated list of Unicode codepoints or + ranges as hex numbers, optionally prefixed with 'U+', 'u', etc. + For example, --unicodes=41-5a,61-7a adds ASCII letters, so does + the more verbose --unicodes=U+0041-005A,U+0061-007A. + The special strings '*' will choose all Unicode characters mapped + by the font. + +--unicodes-file= + Like --unicodes, but reads from a file. Anything after a '#' on any + line in the file is ignored as comments. + +--ignore-missing-glyphs + Do not fail if some requested glyphs or gids are not available in + the font. + +--no-ignore-missing-glyphs + Stop and fail if some requested glyphs or gids are not available + in the font. [default] + +--ignore-missing-unicodes [default] + Do not fail if some requested Unicode characters (including those + indirectly specified using --text or --text-file) are not available + in the font. + +--no-ignore-missing-unicodes + Stop and fail if some requested Unicode characters are not available + in the font. + Note the default discrepancy between ignoring missing glyphs versus + unicodes. This is for historical reasons and in the future + --no-ignore-missing-unicodes might become default. + +Other options +^^^^^^^^^^^^^ + +For the other options listed below, to see the current value of the option, +pass a value of '?' to it, with or without a '='. In some environments, +you might need to escape the question mark, like this: '--glyph-names\\?'. + +Examples:: + + $ fonttools subset --glyph-names? + Current setting for 'glyph-names' is: False + $ fonttools subset --name-IDs=? + Current setting for 'name-IDs' is: [0, 1, 2, 3, 4, 5, 6] + $ fonttools subset --hinting? --no-hinting --hinting? + Current setting for 'hinting' is: True + Current setting for 'hinting' is: False + +Output options +^^^^^^^^^^^^^^ + +--output-file= + The output font file. If not specified, the subsetted font + will be saved in as font-file.subset. + +--flavor= + Specify flavor of output font file. May be 'woff' or 'woff2', or + 'none' (case-insensitive) for uncompressed OpenType. By default, + the flavor of the input font is preserved. + Note that WOFF2 requires the Brotli Python extension, available + at https://github.com/google/brotli + +--with-zopfli + Use the Google Zopfli algorithm to compress WOFF. The output is 3-8 % + smaller than pure zlib, but the compression speed is much slower. + The Zopfli Python bindings are available at: + https://pypi.python.org/pypi/zopfli + +--harfbuzz-repacker + By default, we serialize GPOS/GSUB using the HarfBuzz Repacker when + uharfbuzz can be imported and is successful, otherwise fall back to + the pure-python serializer. Set the option to force using the HarfBuzz + Repacker (raises an error if uharfbuzz can't be found or fails). + +--no-harfbuzz-repacker + Always use the pure-python serializer even if uharfbuzz is available. + +Glyph set expansion +^^^^^^^^^^^^^^^^^^^ + +These options control how additional glyphs are added to the subset. + +--retain-gids + Retain glyph indices; just empty glyphs not needed in-place. + +--notdef-glyph + Add the '.notdef' glyph to the subset (ie, keep it). [default] + +--no-notdef-glyph + Drop the '.notdef' glyph unless specified in the glyph set. This + saves a few bytes, but is not possible for Postscript-flavored + fonts, as those require '.notdef'. For TrueType-flavored fonts, + this works fine as long as no unsupported glyphs are requested + from the font. + +--notdef-outline + Keep the outline of '.notdef' glyph. The '.notdef' glyph outline is + used when glyphs not supported by the font are to be shown. It is not + needed otherwise. + +--no-notdef-outline + When including a '.notdef' glyph, remove its outline. This saves + a few bytes. [default] + +--recommended-glyphs + Add glyphs 0, 1, 2, and 3 to the subset, as recommended for + TrueType-flavored fonts: '.notdef', 'NULL' or '.null', 'CR', 'space'. + Some legacy software might require this, but no modern system does. + +--no-recommended-glyphs + Do not add glyphs 0, 1, 2, and 3 to the subset, unless specified in + glyph set. [default] + +--no-layout-closure + Do not expand glyph set to add glyphs produced by OpenType layout + features. Instead, OpenType layout features will be subset to only + rules that are relevant to the otherwise-specified glyph set. + +--layout-features[+|-]=[,...] + Specify (=), add to (+=) or exclude from (-=) the comma-separated + set of OpenType layout feature tags that will be preserved. + Glyph variants used by the preserved features are added to the + specified subset glyph set. By default, 'calt', 'ccmp', 'clig', 'curs', + 'dnom', 'frac', 'kern', 'liga', 'locl', 'mark', 'mkmk', 'numr', 'rclt', + 'rlig', 'rvrn', and all features required for script shaping are + preserved. To see the full list, try '--layout-features=?'. + Use '*' to keep all features. + Multiple --layout-features options can be provided if necessary. + Examples: + + --layout-features+=onum,pnum,ss01 + * Keep the default set of features and 'onum', 'pnum', 'ss01'. + --layout-features-='mark','mkmk' + * Keep the default set of features but drop 'mark' and 'mkmk'. + --layout-features='kern' + * Only keep the 'kern' feature, drop all others. + --layout-features='' + * Drop all features. + --layout-features='*' + * Keep all features. + --layout-features+=aalt --layout-features-=vrt2 + * Keep default set of features plus 'aalt', but drop 'vrt2'. + +--layout-scripts[+|-]=