summaryrefslogtreecommitdiff
path: root/src/sfnt.c
AgeCommit message (Collapse)Author
2026-05-26ARRAYELTS → countofPaul Eggert
C2y will standardize countof as the macro that Emacs uses the name ARRAYELTS for. Switch to the standard name, which is supported by GCC 16+, by Clang 21, and by the Gnulib stdcountof-h module already in use for compilers that do not support countof. Also, use countof in a few places where we missed using ARRAYELTS. * admin/coccinelle/arrayelts.cocci: Suggest countof, not ARRAYELTS. * admin/merge-gnulib (GNULIB_MODULES): Add stdcountof-h, as it is now a direct rather than an indirect dependency. * exec/trace.c, src/lisp.h, src/sfnt.c: Include <stdcountof.h>. (ARRAYELTS): Remove. All uses replaced by countof. * lib-src/ebrowse.c, lib-src/etags.c, lib-src/make-docfile.c: * lib-src/seccomp-filter.c, lwlib/lwlib-Xaw.c: Prefer <stdcountof.h> and countof to doing things by hand.
2026-05-25Fix parsing of font metadata tables on AndroidPo Lu
* src/sfnt.c (sfnt_read_meta_table): Allocate `directory->length' bytes after the map rather than in place of it.
2026-05-25Fix the Android buildPo Lu
* src/sfnt.c (sfnt_fill_span) [NDEBUG]: Don't access `row_end' when not defined.
2026-05-23sfnt.c eassert vs assertPaul Eggert
Use eassert uniformly, instead of assert. * src/sfnt.c [!TEST]: Do not include <assert.h> or use assert. (eassert) [TEST]: New macro.
2026-05-23Better size overflow checking for sfnt.cPaul Eggert
* src/sfnt.c (memory_full_up) [TEST]: New static function. (xmalloc, xcalloc, xrealloc): Use it instead of aborting. (eassert) [TEST]: Remove; no longer needed. (xaddmalloc, xaddrealloc): New static convenience functions. (sfnt_read_cmap_format_12, sfnt_read_loca_table_short) (sfnt_read_loca_table_long, sfnt_read_glyf_table) (sfnt_read_simple_glyph, sfnt_read_compound_glyph) (sfnt_read_glyph, sfnt_build_append, sfnt_build_outline_edges) (sfnt_raster_glyph_outline, sfnt_build_outline_fedges) (sfnt_raster_glyph_outline_exact, sfnt_read_hmtx_table) (sfnt_read_name_table, sfnt_read_meta_table) (sfnt_read_ttc_header, sfnt_read_fpgm_table) (sfnt_read_prep_table, sfnt_create_uvs_context) (sfnt_read_gvar_table, sfnt_read_packed_deltas) (sfnt_vary_simple_glyph, sfnt_vary_compound_glyph): Use the new functions to test for size overflow more reliably. Use a cleaner way to decide whether a pointer addresses the heap not the stack and thus needs freeing. Fix a few more unlikely overflows. (sfnt_read_cmap_format_12): The recently-added eassert is no longer needed, so remove it. (sfnt_read_simple_glyph): Initialize glyph->simple early to simplify later code, as is done in similar functions. Complicate size test to avoid potential unsigned overflow.
2026-05-23Simplify sfnt.c by using long longPaul Eggert
Even the earliest Android had plain ‘long long’, so use that instead of doing it by hand. * src/sfnt.c (struct sfnt_large_integer, sfnt_multiply_divide_1) (sfnt_multiply_divide_2, sfnt_large_integer_add) (sfnt_multiply_divide_round) [!INT64_MAX]: Remove. (sfnt_multiply_divide, sfnt_multiply_divide_rounded) (sfnt_mul_fixed, sfnt_mul_fixed_round, sfnt_div_fixed) (sfnt_div_f26dot6, sfnt_mul_f26dot6, sfnt_mul_f26dot6_round) (sfnt_mul_f2dot14, sfnt_dot_fix_14): Simplify by using long long.
2026-05-23Be more careful about size multiplicationPaul Eggert
* src/alloc.c (xcalloc): New function. * src/dispnew.c (save_current_matrix): * src/fns.c (Finternal__hash_table_histogram): * src/nsfns.m (Fns_display_monitor_attributes_list): * src/pgtkfns.c (Fpgtk_display_monitor_attributes_list): * src/pgtkselect.c (pgtk_own_selection): * src/profiler.c (make_log): * src/sfnt.c (sfnt_poly_edges_exact): * src/xfns.c (x_get_monitor_attributes_xinerama) (x_get_monitor_attributes_xrandr, Fx_display_monitor_attributes_list): Use it instead of multiplying by hand, conceivably with overflow. * src/profiler.c (make_log): Check for overflow in internal size calculations. Use xnmalloc instead of multiply + xmalloc. * src/sfnt.c (xzalloc) [TEST]: Remove, replacing with ... (xicalloc) [TEST]: ... this new function. All callers changed. (eassert) [TEST]: New macro. * src/treesit.c (treesit_calloc_wrapper): Remove, replacing its use with xcalloc.
2026-05-15; * src/sfnt.c (sfnt_read_cmap_format_12): Assert there's no overflow.Eli Zaretskii
2026-05-02; * src/sfnt.c (sfnt_read_name_table): Avoid 32-bit overflow.Eli Zaretskii
2026-01-01; Add 2026 to copyright years.Sean Whitton
2025-03-09Avoid reserved names in sfnt.cPo Lu
* src/sfnt.c (_MIN, _MAX): Rename to INS_MIN and INS_MAX. (sfnt_interpret_run): Adjust accordingly.
2025-01-01Update copyright year to 2025Paul Eggert
Run "TZ=UTC0 admin/update-copyright".
2024-08-20Correct Android failure to open an old CJK fontPo Lu
* src/sfnt.c (sfnt_read_cmap_format_2): Properly compute subtable count, and append the empty table at position 0. (sfnt_lookup_glyph_2): Update commentary.
2024-08-11Fix format 2 cmap handling in sfnt.cPip Cet
This code is untested as no font with a format 2 cmap could be found. * src/sfnt.c (sfnt_lookup_glyph_2): Fix typos. Assume single-byte encodings use character codes 0, 1, ..., 255 rather than 0, 256, ..., 65280.
2024-08-11Fix coordinate transformations in sfnt.cPip Cet
Backport. * src/sfnt.c (sfnt_transform_coordinates): (sfnt_transform_f26dot6): Fix calculation of transformed coordinates in the very rare case of arbitrary transformation matrices.
2024-08-03Revert "Remove redundant byte-swapping boundary"Po Lu
This reverts commit daefd6771a4879bb8e71ea67f69522700155df01. * src/sfnt.c (sfnt_read_OS_2_table): Restore realignment after s_family_class, as it occupies byte 32, not 34. Reported by Pip Cet <pipcet@protonmail.com>.
2024-07-18; Fix typosStefan Kangas
2024-05-20; Stylistic adjustments to sfnt.cPo Lu
* src/sfnt.c (sfnt_map_table, sfnt_read_table): Adapt to coding style of another project using this module.
2024-05-19Pacify -Wanalyzer-null-dereference in sfnt.cPaul Eggert
* src/sfnt.c (sfnt_map_table, sfnt_read_table) (sfnt_read_cvar_table): Pacify GCC -Wanalyzer-null-dereference. The change to sfnt_read_cvar_table fixes what appears to be an actual null-dereference bug.
2024-05-18Simplify 32-bit Android bit fiddlingPaul Eggert
* src/sfnt.c: Include stdbit.h. (sfnt_count_leading_zero_bits) [!INT64_MAX]: Remove this function, which was confusingly named as it actually returned 31 minus the number of leading zero bits. (sfnt_multiply_divide_2) [!INT64_MAX]: Use stdc_leading_zeros instead.
2024-04-04Remove redundant byte-swapping boundaryPo Lu
* src/sfnt.c (sfnt_read_OS_2_table): * src/sfnt.h (struct sfnt_OS_2_table): Don't redundantly realign after s_family_class.
2024-02-05Don't respect ROUND_XY_TO_GRID when decomposing uninterpreted glyphPo Lu
* src/sfnt.c (sfnt_decompose_compound_glyph): Remove useless code; don't pretend to round glyph coordinates.
2024-01-29; * src/sfnt.c: Fix standalone compilation.Po Lu
2024-01-28Prefer C23 ckd_* to Gnulib *_WRAPV and *_OK macrosPaul Eggert
* src/alloc.c (android_make_lisp_symbol) [HAVE_ANDROID && !__clang__]: * src/android.c (android_blit_copy, android_blit_xor) (android_get_image): * src/androidmenu.c (android_menu_show): * src/androidselect.c (Fandroid_get_clipboard_data) (android_notifications_notify_1): * src/androidterm.c (android_decode_utf16) (android_text_to_string): * src/haiku_select.cc (be_display_notification): * src/sfnt.c (sfnt_read_cmap_format_8, sfnt_read_cmap_format_12) (sfnt_read_cmap_format_14, sfnt_read_cmap_table_1) (sfnt_expand_compound_glyph_context, sfnt_poly_edges_exact) (sfnt_read_meta_table, sfnt_read_ttc_header) (sfnt_read_cvt_table, sfnt_read_fpgm_table) (sfnt_read_prep_table, sfnt_make_interpreter) (sfnt_interpret_simple_glyph, sfnt_interpret_compound_glyph_2) (sfnt_interpret_compound_glyph, sfnt_read_default_uvs_table) (sfnt_read_nondefault_uvs_table, sfnt_create_uvs_context) (sfnt_read_fvar_table, sfnt_read_gvar_table) (sfnt_read_avar_table, sfnt_read_cvar_table): * src/sfntfont-android.c (GET_SCANLINE_BUFFER): * src/textconv.c (really_commit_text, really_set_composing_text) (really_replace_text, get_surrounding_text): Prefer C2x stdckdint.h macros to intprops.h macros.
2024-01-23Correct crash when executing IP within twilight zonePo Lu
* src/sfnt.c (sfnt_address_zp2, sfnt_address_zp1) (sfnt_address_zp0): Don't save into X or Y if the zone is set to the twilight zone and they are NULL.
2024-01-23* src/sfnt.c (sfnt_mul_f26dot6_fixed): Correct typo in last change.Po Lu
2024-01-22Do not overwrite flags of succeeding points during generic movePo Lu
* src/sfnt.c (sfnt_move): Save FLAGS and restore it after X axis movement loop.
2024-01-22Correct values of INSTCTRL flags testedPo Lu
* src/sfnt.c (sfnt_mul_f26dot6_round): New function. (sfnt_mul_f26dot6_fixed): Replace by call to sfnt_mul_fixed_round. (MUL): Round result, as the Apple and MS scalers do. (sfnt_interpret_control_value_program): The instruction control flag which reverts CVT modifications is 2, not 4.
2024-01-20Be more systematic about parens in C source codePaul Eggert
Be more systematic about putting space before paren in calls, and in avoiding unnecessary parentheses in macros. This was partly inspired by my wading through gcc -E output while debugging something else, and seeing too many parens. This patch does not change the generated .o files on my platform.
2024-01-20Round projs computed executing IP/ISECT instructions and improve IUPPo Lu
* src/sfnt.c (sfnt_multiply_divide_rounded): New function. (sfnt_multiply_divide_signed): Always round values, as fonts which rely on IP to move points in concert with prior motion and subsequently round such points with MDAP are sensitive to minor deviations in the behavior of the former instruction. (load_unscaled): New macro. (IUP_SINGLE_PAIR, sfnt_interpret_iup_1): Compute ratio w/ unscaled points if possible.
2024-01-17Increase accuracy of IP instructionPo Lu
* src/sfnt.c (sfnt_interpret_ip): Avoid precision loss by retrieving original positions from the unscaled outline, whenever possible.
2024-01-14Correct implementations of FLIPRGON and FLIPRGOFFPo Lu
* src/sfnt.c (sfnt_interpret_fliprgoff) (sfnt_interpret_fliprgon): Reorder arguments to match the order in which arguments are popped by macro wrappers. Fix sundry typos.
2024-01-10; Minor edits to PROBLEMS and sfnt.cPo Lu
* etc/PROBLEMS: Improve description of issues with Droid Sans Mono. * src/sfnt.c (sfnt_poly_edges_exact): Remove extraneous undef.
2024-01-08; Fix a crash in sfnt_read_fvar_tablePo Lu
* src/sfnt.c (sfnt_read_fvar_table): Derive padding from correct type.
2024-01-08Properly instruct Italic Arial or BS Mono at small PPEM sizesPo Lu
* src/sfnt.c (sfnt_read_simple_glyph): Correct alignment errors. (PUSH2_UNCHECKED): Don't shift negative signed value to the left. (SLOOP): Permit LOOP to be set to 0, which inhibits the execution of instructions it affects. (sfnt_address_zp2, sfnt_address_zp1, sfnt_address_zp0): Permit X and Y to be NULL. (sfnt_dot_fix_14): Guarantee that the final value is rounded to negative infinity, not zero. (sfnt_project_zp1_zp0_org): New function. (sfnt_interpret_mdrp): Avoid rounding issues by computing original distance from unscaled coordinates, if at all possible. (sfnt_interpret_simple_glyph, sfnt_interpret_compound_glyph_2): Set zone->simple. (all_tests) <LOOP>: Update test. (sfnt_identify_instruction, main): Adjust tests. * src/sfnt.h (struct sfnt_interpreter_zone): New field simple.
2024-01-06Properly parse TTC tables with digital signaturesPo Lu
* src/sfnt.c (sfnt_read_ttc_header): Don't inadvertently overwrite first two offsets while reading the digital signature.
2024-01-03Don't magnify extent of shifts by variable glyph interpolationPo Lu
* src/sfnt.c (sfnt_infer_deltas_2): Correctly index x_coordinates and y_coordinates computing deltas for plain shift. (sfnt_vary_simple_glyph): Copy glyph contents to original_x and original_y not the first time is create, but before each tuple is applied.
2024-01-02Improve rounding of projection vector versorsPo Lu
* src/sfnt.c (sfnt_short_frac_dot): New function. (sfnt_validate_gs): Guarantee dot product of freedom and projection vectors are properly rounded. If the final product is short of 1/16th of a vector, reset it to an entire vector.
2024-01-02; Add 2024 to copyright yearsPo Lu
2024-01-01Bring GX point interpolation further into standards compliancePo Lu
* src/sfnt.c (sfnt_infer_deltas_2): New function; factor much of sfnt_infer_deltas_1 into this function, then modify its treatment of untouched points positioned at their reference points to align with standard GX treatment. (sfnt_infer_deltas_1): Remove all code not concerning anchor point discovery. (main): Adjust tests.
2023-12-29Obey USE_MY_METRICS in compound glyphsPo Lu
* src/sfnt.c (struct sfnt_compound_glyph_context): New fields holding the positions of both phantom points. (sfnt_decompose_compound_glyph): New argument METRICS_RETURN; return the metrics of components with USE_MY_METRICS within this field. (sfnt_decompose_glyph): New argument METRICS_RETURN, which serves the same purpose. (sfnt_build_glyph_outline): Apply glyph advance and origin distortion to METRICS, and return the metrics as altered by compound glyphs in there. (sfnt_lookup_glyph_metrics): Trim away two unused parameters, PIXEL_SIZE and HEAD, whose functionality has been superseeded by sfnt_scale_metrics and the implicit scaling the interpreter performs. (sfnt_interpret_compound_glyph_2): Save phantom points within fields provided to that end in CONTEXT. (sfnt_interpret_compound_glyph_1): Save and source phantom points for each glyph to and from the context. (sfnt_test_get_metrics, main): Adjust tests correspondingly. * src/sfnt.h: Update prototypes. * src/sfntfont.c (sfntfont_get_metrics): Remove obsolete parameters. (sfntfont_get_glyph_outline): Don't change temp by the metrics distortions, which is now the task of sfnt_decompose_glyph.
2023-12-25Apply TTF advance width rounding to uninstructed glyphsPo Lu
* src/sfnt.c (sfnt_scale_metrics): * src/sfntfont.c (sfntfont_get_glyph_outline): Round advance and floor lbearing scaling glyph metrics. (sfntfont_measure_pcm): Don't round or truncate metrics which have already been.
2023-12-25Optimize font edge filling loopPo Lu
* src/sfnt.c (sfnt_fedge_sort): Delete function. (sfnt_poly_edges_exact): Don't sort edges, iterate through each instead. (main): Adjust tests.
2023-12-23; * src/sfnt.c (sfnt_interpret_compound_glyph_2): Reword a comment.Eli Zaretskii
2023-12-23Respect glyph metrics modified by instruction codePo Lu
* src/sfnt.c (sfnt_read_glyph): Clear advance and origin distortion returning an empty glyph. (sfnt_build_instructed_outline): New parameter *ADVANCE_WIDTH, in which the glyph's advance width is saved. (sfnt_interpret_compound_glyph_1): Refine commentary. (sfnt_verbose, main): Adjust tests. * src/sfnt.h: Update prototypes correspondingly. * src/sfntfont.c (sfntfont_get_glyph_outline): If an instructed outline is available, derive the advance and lbearing from the measurements within. (sfntfont_probe_widths): Call sfntfont_measure_pcm to establish average widths. (sfntfont_open): Do so after instruction code initialization completes. (sfntfont_measure_pcm): Revise commentary.
2023-12-22Properly instruct compound glyphs with compound componentsPo Lu
* src/sfnt.c (sfnt_interpret_compound_glyph_2): Don't grow the compound decomposition context for saving compound points into, since the space for them already exists.
2023-12-21Implement an undocumented TrueType "feature"Po Lu
* src/sfnt.c (sfnt_move): Correct commentary. (sfnt_interpret_control_value_program): Reset dual projection, freedom and projection vectors, in addition to the reference points, zone pointers and loop counter.
2023-12-21* src/sfnt.c (GETINFO): Implement undocumented selector bit 5.Po Lu
2023-12-21Accept empty contours in glyphsPo Lu
* src/sfnt.c (sfnt_decompose_glyph_1, sfnt_decompose_glyph_2): Accept empty contours, for they are not invalid, just redundant.
2023-12-19Improve efficiency of operations involving font interpreter scalePo Lu
* src/sfnt.c (sfnt_mul_f26dot6_fixed): Correct rounding constant. (sfnt_make_interpreter, SSW, WCVTF, sfnt_compute_phantom_points) (sfnt_interpret_simple_glyph, sfnt_interpret_compound_glyph_1) (sfnt_vary_interpreter, sfnt_check_ssw): Account for the fractional bits in a f26dot6 when computing the interpreter scale factor.