Commit Graph

5199 Commits

Author SHA1 Message Date
Nikolaus Waxweiler ebf9e5ac71 [CMake] Update dependency finders.
1. Fixes CMake using any found HarfBuzz version lower than the minimum
required. This is based on HALX99's merge request at
https://gitlab.freedesktop.org/freetype/freetype/-/merge_requests/31
2. Update FindHarfBuzz.cmake from
https://github.com/WebKit/WebKit/blob/1ce32454/Source/cmake/FindHarfBuzz.cmake
and guard post-CMake-3.1 features to keep the minimum version unchanged
3. Update FindBrotliDec.cmake to stop the warnings, based on what
https://github.com/google/woff2/blob/a0d0ed7d/cmake/FindBrotliDec.cmake
is doing

* CMakeLists.txt, builds/cmake/FindHarfBuzz.cmake: Implement 1 and 2.
* builds/cmake/FindBrotliDec.cmake: Implement 3.
2021-05-19 21:53:21 +01:00
Ben Wagner 06e21ffedf [gzip] Use exact type for `ft_gzip_alloc` and `ft_gzip_free`.
While a function pointer may be cast to another function pointer
type, it is required to cast the function pointer back to the
original function pointer type before calling it.  If a parameter is
a pointer the exact pointer type is required.  Using a pointer to a
different underlying type is technically undefined behavior.  The
wrapper functions `ft_gzip_alloc` and `ft_gzip_free` took
`FT_Memory` (a `FT_MemoryRec_*`) instead of `voidpf` (`void*`), so
when gzip calls these callbacks through `alloc_func` or `free_func`
it invokes undefined behavior.  On most platforms this works out as
expected, but newer undefined behavior detectors and targets like
wasm can detect this and will produce an error.

* src/gzip/ftgzip.c (ft_gzip_alloc, ft_gzip_free): Update signatures
to exactly match `alloc_func` and `free_func`, respectively.
Internally, cast the `void*` opaque pointer to `FT_Memory`.
2021-05-19 09:07:33 +02:00
Alexei Podtelezhnikov 81852fbccc Prioritize the anti-aliasing renderer module.
* modules.cfg: Reorder the renderers.
* include/freetype/config/ftmodule.h: Ditto.
2021-05-18 22:18:17 -04:00
Alexei Podtelezhnikov 1bc801b0d6 [sfnt] Additional guards on the POST table.
Fixes timeout (#1055) analyzed by Ben Wagner, reported as

  https://crbug.com/1194092

* src/sfnt/ttload.c (tt_face_load_post): Check POST format.
* src/sfnt/sfobjs.c (sfnt_load_face): Synthesize the missing unicode
charmap only if the glyph names exist.
* src/psnames/psmodule.c (ps_unicode_value): Short cut ".notdef" and
".null".
2021-05-16 23:12:01 -04:00
Daniel McArdle de15165774 [psaux] Use doubling allocation strategy for CF2_ArrStack.
Fixes timeout reported as

  https://crbug.com/1206181

* src/psaux/psarrst.c (cf2_arrstack_{push,init}): Implement it.
* src/psaux/psarrst.h (CF2_ArrStackiRec): Drop `chunk'.
2021-05-13 23:08:31 -04:00
Alexei Podtelezhnikov 2d3f5dd294 * src/smooth/ftgrays.c (FT_MAX_GRAY_SPANS): Increase from 10 to 16.
Ten was barely enough for two slanted stems. Sixteen can actually fit
a bit more complicated scanlines.
2021-05-12 17:24:35 -04:00
Alexei Podtelezhnikov c653b8d2f1 * src/smooth/ftgrays.c (FT_GRAY_SET): Adjust for better code. 2021-05-12 16:17:21 -04:00
Alexei Podtelezhnikov 8f43d324d1 [smooth] Faster bitmap sweeping.
Selecting the fill rule or checking the direct mode each time we call
`gray_hline' is sub-optimal.  This effectively splits the direct mode
into a separate code path while inlining `gray_hline' and saving 5-7%
of rendering time.

* src/smooth/ftgrays.c (gray_hline): Eliminated in favor of...
(FT_FILL_RULE, FT_GRAY_SET): ... these new macros...
(gray_sweep): ... inlined here.
(gray_sweep_direct): New function that handles the direct span buffer.
(gray_TWorker): Remove the span buffer.
(gray_raster_render, gray_convert_glyph): Updated.
2021-05-12 00:04:59 -04:00
Alexei Podtelezhnikov b070264521 * src/smooth/ftgrays.c (gray_hline): Simplify even-odd computations.
It is too bad the even-odd rule is not used much.
2021-05-10 22:06:01 -04:00
Alexei Podtelezhnikov 967a34eee3 [type1] Avoid MM memory zeroing.
* src/type1/t1load.c (t1_allocate_blend, parse_blend_design_map):
Tweak allocation macros.
* src/type1/t1objs.c (T1_Face_Done): Minor.
2021-05-07 19:17:48 -04:00
Alexei Podtelezhnikov 2f62d8e075 * src/bdf/bdflib.c (_bdf_list_ensure): Tweak allocation macro. 2021-05-07 09:33:41 -04:00
Alexei Podtelezhnikov 79ed536d01 * src/psaux/psobjs.c (ps_parser_load_field): Tweak allocation macro. 2021-05-06 23:46:46 -04:00
Alexei Podtelezhnikov 44c59414eb * src/sfnt/sfobjs.c (sfnt_load_face): Tweak allocation macro. 2021-05-06 22:54:03 -04:00
Alexei Podtelezhnikov 998c7c0f1c * src/cid/cidload.c (cid_read_subrs): Tweak allocation macro. 2021-05-06 22:51:37 -04:00
Alexei Podtelezhnikov 2d95784885 * src/base/ftrfork.c (FT_Raccess_Get_DataOffsets): Tweak allocation. 2021-05-06 22:49:13 -04:00
Alexei Podtelezhnikov 8150ed0db2 [cff,psaux] Avoid memory zeroing (contd.).
* src/cff/cffload.c (cff_blend_doBlend, cff_blend_build_vector): Tweak
allocation macros.
* src/psaux/psarrst.c (cf2_arrstack_setNumElements): Ditto.
* src/psaux/psstack.c (cf2_stack_init): Ditto.
2021-05-05 23:30:46 -04:00
Ben Wagner 82fd32d674 * src/cid/cidload.c (cid_hex_to_binary): Improve return value.
Add argument to return the actual number of bytes that were decoded.
The actual number of bytes decoded can be quite variable depending
on the number of ignored 'whitespace' bytes or early termination
with `>`.
(cid_face_open): Updated to use this calculated value.  This avoids
trusting `parser->binary_length` is always be correct and reading
uninitialized bits if fewer are actually decoded.

First reported as

  https://crbug.com/1203240
2021-05-04 08:56:10 +02:00
Alexei Podtelezhnikov 66630d882c [sfnt] Streamline POST format 2.0 handing.
To reduce memory allocations, we read an entire Pascal-string buffer
and convert it to a C-string buffer.  We also reject tables with
Postscript glyph names exceeding 63 bytes.

* src/sfnt/ttpost.c (load_format20): Implement it.
(load_post_names): Check the minimal POST table size.
(load_format25, tt_face_free_ps_names): Updated accordingly.
2021-05-03 22:40:16 -04:00
Alexei Podtelezhnikov ec95f9c921 [bdf,pcf] Avoid memory zeroing (contd.).
* src/bdf/bdflib.c (bdf_create_property, _bdf_add_comment,
_bdf_add_property, bdf_load_font): Tweak allocation macros.
* src/pcf/pcfread.c (pcf_get_properties, pcf_get_metrics): Ditto.
2021-05-02 18:30:22 -04:00
Alexei Podtelezhnikov d911cb5392 * src/cid/cidload.c (cid_read_subrs): Tweak allocaton macro. 2021-05-01 23:49:11 -04:00
Alexei Podtelezhnikov dc42f826af [sfnt] Avoid some memory zeroing.
* src/sfnt/sfobjs.c (sfnt_open_font, sfnt_init_face,
tt_name_ascii_from_{utf16,other}): Tweak allocaton macros.
* src/sfnt/ttload.c (tt_face_load_name): Ditto.
2021-05-01 12:46:44 -04:00
Alexei Podtelezhnikov b8968d666e * src/sfnt/ttpost.c (load_format_{20,25}): Tweak allocaton macros. 2021-05-01 12:24:44 -04:00
Alexei Podtelezhnikov 2583b6085e * src/sfnt/pngshim.c (Load_SBit_Png): Tweak allocaton macro. 2021-05-01 09:22:26 -04:00
Alexei Podtelezhnikov 56ae943050 [truetype] Avoid some memory zeroing.
* src/truetype/ttinterp.c (Init_Context): Tweak allocation macro.
* src/truetype/ttpload.c (tt_face_load_cvt): Ditto.
2021-05-01 09:14:04 -04:00
Alexei Podtelezhnikov c177cc354d [woff2] Avoid some memory zeroing.
* src/sfnt/sfwoff2.c (store_loca, woff2_open_font): Tweak macros.
2021-05-01 09:09:52 -04:00
Alexei Podtelezhnikov 4e1c6a12e5 * src/gzip/ftgzip.c (ft_gzip_alloc): Zero out memory again. 2021-04-30 09:35:21 -04:00
Alexei Podtelezhnikov f631542dae [lzw] Preserve decompression stack when relocating to heap.
* src/lzw/ftzopen.c (ft_lzwstate_stack_grow): Copy stack when
relocating to heap.
2021-04-27 11:39:58 -04:00
Alexei Podtelezhnikov c213c8a9bb * src/cid/cidgload.c (cid_load_glyph): Restore the glyph_length check. 2021-04-27 08:54:19 -04:00
Werner Lemberg 2ec6feaf39 * src/psmodule.c (ps_unicodes_init): Ignore empty glyph names.
Reported as

  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=33637
2021-04-27 13:28:35 +02:00
Alexei Podtelezhnikov caff87b1f9 * src/sfnt/sfobjs.c (sfnt_init_face): Revert macro change. 2021-04-26 22:45:40 -04:00
Alexei Podtelezhnikov 8750e843df [cff] Avoid some memory zeroing.
* src/cff/cffparse.c (cff_parser_init): Tweak memory macro.
* src/cff/cffload.c (cff_index_load_offsets, cff_index_get_pointers,
cff_charset_load, cff_vstore_load): Ditto.
2021-04-26 17:21:51 -04:00
Alexei Podtelezhnikov 618d0834c7 [pfr] Avoid some memory zeroing.
* src/pfr/pfrobjs.c (pfr_face_init) : Tweak memory macro.
* src/pfr/pfrload.c (pfr_extra_item_load_stem_snaps,
pfr_phy_font_load): Ditto.
2021-04-26 17:14:28 -04:00
Alexei Podtelezhnikov b0a281974d * src/winfonts/winfnt.c (FNT_Face_Init): Tweak memory macro. 2021-04-26 17:10:28 -04:00
Alexei Podtelezhnikov deee5b7017 [psaux,psnames] Avoid some memory zeroing.
* src/psaux/psstack.c (cf2_stack_init): Tweak memory macro.
* src/psnames/psmodule.c (ps_unicodes_init): Ditto.
2021-04-26 17:07:44 -04:00
Alexei Podtelezhnikov 270ff52f62 [base] Avoid some memory zeroing.
* src/base/ftrfork.c (FT_Raccess_Get_DataOffsets): Use FT_QNEW_ARRAY.
* src/base/ftsnames.c (FT_Get_Sfnt_{Name,LangTag}): Ditto.
2021-04-25 23:40:59 -04:00
Alexei Podtelezhnikov c2d283143a [bdf,pcf] Avoid some memory zeroing.
* src/pcf/pcfread.c (pcf_read_TOC, pcf_get_properties, pcf_load_font):
Tweak memory macros.
* src/bdf/bdfdrivr.c (BDF_Face_Init): Ditto.
* src/bdf/bdflib.c (_bdf_readstreami, bdf_create_property,
_bdf_parse_glyphs, _bdf_parse_start): Ditto.
(_bdf_add_property): Do not handle zero size.
2021-04-25 23:33:15 -04:00
Issam E. Maghni f998eaf972 * builds/meson/process_ftoption_h.py: Add LF at EOF.
This fixes

  .../ftoption.h:1030:10: error:
    no newline at end of file [-Werror,-Wnewline-eof]

for the generated `ftoption.h` file.
2021-04-25 20:30:43 +02:00
Alexei Podtelezhnikov c78f78fab4 * src/cff/cffload.c (cff_index_get_pointers): s/FT_QALLOC/FT_ALLOC/. 2021-04-24 22:38:48 -04:00
Alexei Podtelezhnikov 0bd5d95d66 * src/base/ftobjs.c (Mac_Read_POST_Resource): s/FT_ALLOC/FT_QALLOC/.
* builds/mac/ftmac.c (FT_New_Face_From_SFNT, read_lwfn): Ditto.
2021-04-23 22:04:05 -04:00
Alexei Podtelezhnikov e6e5b67db3 * src/sdf/ftsdf.c (sdf_{edge,contour,shape}_new): Use FT_QALLOC. 2021-04-23 21:33:03 -04:00
Alexei Podtelezhnikov 6ada59ab7c [sfnt] s/FT_ALLOC/FT_QALLOC/ for initialized buffers.
* src/sfnt/sfdriver.c (get_win_string, get_apple_string,
sfnt_get_var_ps_name): Do not zero out the buffer.
* src/sfnt/sfobjs.c (sfnt_init_face): Ditto.
* src/sfnt/sfwoff.c (woff_open_font): Ditto.
* src/sfnt/sfwoff2.c (woff2_open_font): Ditto.
2021-04-23 19:22:51 -04:00
Alexei Podtelezhnikov ec9e5114b1 [cff,type1,type42] s/FT_ALLOC/FT_QALLOC/ for initialized buffers.
* src/cff/cffload.c (cff_index_get_pointers, cff_index_get_name):
Do not zero out the buffer.
* src/cff/cffdrivr.c (cff_ps_get_font_info): Ditto.
* src/type1/t1load.c (parse_subrs, parse_charstrings,
parse_blend_axis_types): Ditto.
* src/type1/t1parse.c (T1_New_Parser, T1_Get_Private_Dict): Ditto.
* src/type42/t42parse.c (t42_parser_init): Ditto.
2021-04-23 14:03:03 -04:00
Alexei Podtelezhnikov baa0f71ddf [cid] s/FT_ALLOC/FT_QALLOC/ and clean up.
* src/cid/cidgload.c (cid_load_glyph): Do not zero out the buffer.
* src/cid/cidload.c (cid_face_open, cid_read_subrs): Ditto.
2021-04-23 13:48:34 -04:00
Alexei Podtelezhnikov b3438ccb31 [pfr] s/FT_ALLOC/FT_QALLOC/ for initialized buffers.
* src/pfr/pfrload.c (pfr_extra_item_load_font_id, pfr_aux_name_load):
Do not zero out the buffer.
2021-04-23 08:35:02 -04:00
Alexei Podtelezhnikov 1e525c62ae [bzip2,gzip] s/FT_ALLOC/FT_QALLOC/ for initialized buffers.
* src/bzip2/ftbzip2.c (ft_bzip2_alloc): Do not zero out the buffer.
* src/gzip/ftgzip.c (ft_gzip_alloc, FT_Stream_OpenGzip): Ditto.
2021-04-23 08:24:22 -04:00
Alexei Podtelezhnikov a0fb6dbcd9 [pcf,bdf,winfonts] s/FT_ALLOC/FT_QALLOC/ for initialized buffers.
* src/pcf/pcfread.c (pcf_interpret_style): Do not zero out the buffer.
* src/bdf/bdfdrivr.c (bdf_interpret_style): Ditto.
* src/winfonts/winfnt.c (FNT_Face_Init, FNT_Load_Glyph): Ditto.
2021-04-23 00:05:18 -04:00
Alexei Podtelezhnikov 23f85c8a98 [cache] Optimize SBit copying.
* src/cache/ftcsbits.c (ftc_snode_load): Do not initialize the buffer.
(ftc_sbit_copy_bitmap): Accept zero size, s/FT_ALLOC/FT_QALLOC/.
2021-04-22 23:34:08 -04:00
Alexei Podtelezhnikov 93715ab2c4 [gxvalid,otvalid] s/FT_ALLOC/FT_QALLOC/ for initialized buffers.
* src/gxvalid/gxvmod.c (gxv_load_table): Do not zero out the buffer.
* src/otvalid/otvmod.c (otv_load_table): Ditto.
2021-04-22 23:07:01 -04:00
Alexei Podtelezhnikov 90b97a833d [psaux] s/FT_ALLOC/FT_QALLOC/ for initialized buffers.
* src/psaux/psobjs.c (ps_table_done, ps_parser_load_field): Do not
zero out the buffer.
2021-04-22 23:00:40 -04:00
Alexei Podtelezhnikov 44b1ebe514 [base] s/FT_ALLOC/FT_QALLOC/ for initialized buffers.
* src/base/ftobjs.c (open_face_PS_from_sfnt_stream,
Mac_Read_sfnt_Resource): Do not zero out the buffer.
* src/base/ftmac.c (FT_New_Face_From_SFNT, read_lwfn): Ditto.
* src/base/ftrfork.c (raccess_make_file_name,
raccess_guess_darwin_hfsplus, raccess_guess_darwin_newvfs): Ditto.
2021-04-22 22:34:05 -04:00
Alexei Podtelezhnikov 8a459e5172 [cache] Restore SBit copying for unowned (BDF) bitmaps.
* src/cache/ftcsbits.c (ftc_sbit_copy_bitmap): Restore.
(ftc_snode_load): Check ownership and copy unowned bitmaps.
2021-04-20 22:53:13 -04:00
Dominik Röttsches e662a9500f [sfnt] Return in 'COLR' v1 when layer pointer outside table
* src/sfnt/ttcolr.c (tt_face_get_paint_layers): Add missing return
when paint pointer outside table.
(read_paint): Add missing return when paint pointer outside table.
2021-04-19 12:49:16 +03:00
Alexei Podtelezhnikov 7c685cb3f6 [cache] Switch to lazy SBit setting.
* src/cache/ftcsbits.c (ftc_sbit_copy_bitmap): Removed.
(ftc_snode_load): Take the bitmap ownership instead of copying.
2021-04-18 22:31:13 -04:00
Daniel Welty 2e68785e08 * src/cache/ftcsbits.c (ftc_snode_load): Properly handle short pitch. 2021-04-17 09:00:40 -04:00
Werner Lemberg 6f6ad87638 * builds/unix/freetype2.m4: Fix help string formatting.
The indented `dnl` macros inserted unwanted horizontal space.

Problem reported by Ozkan Sezer <sezeroz@gmail.com>.
2021-04-16 20:50:27 +02:00
Dominik Röttsches 7f8a1edd3a [sfnt] Safeguard 'COLR' v1 layer extraction
* src/sfnt/ttcolr.c (tt_face_get_paint_layers): Do not output
layer pointer to iterator if it is outside the 'COLR' table.
(read_paint): Do not attempt to read layers that are outside the
table.
2021-04-16 12:41:58 +03:00
Ben Wagner f9350be1e4 [base] Complete `ft_glyphslot_clear`.
* src/base/ftobjs.c (ft_glyphslot_clear): This function is intended
to reset all the values of a glyph slot.  However, it was not
resetting the values of the advances and `glyph_index`.  Reset the
advances and `glyph_index` to zero.
2021-04-02 11:09:01 +02:00
Ben Wagner 369d8be97f [truetype] Prevent glyph program state from persisting.
`FDEF` instructions are specified as allowed only in 'prep' or
'fpgm'.  FreeType has attempted to prevent their use in the glyph
program, but they were still allowed in glyph programs if defined in
a function defined in 'prep' or 'fpgm' and called from the glyph
program.

Similarly, `IDEF` instructions are specified not to be able to
modify any existing instruction.  FreeType has attempted to prevent
their use in the glyph program, but they can still be used like
`FDEF`.

This change stores the initial bytecode range type and disallows the
use of `FDEF` and `IDEF` while running the glyph program.

Most other state is copied from the `TT_Size` into the execution
context.  However, it is possible for a glyph program to use `WS` to
write to the storage area or `WCVTP`, `WCVTF`, and `DELTAC[123]` to
write to the control value table.

Allowing any change to the global state from the glyph program is
problematic as the outlines of any given glyph may change based on
the order the glyphs are loaded or even how many times they are
loaded.  There exist fonts that write to the storage area or the
control value table in the glyph program, so their use should not be
an error.

Possible solutions to using these in the glyph program are

  * ignore the writes;
  * value-level copy on write, discard modified values when finished;
  * array-level copy on write, discard the copy when finished;
  * array-level copy up-front.

Ignoring the writes may break otherwise good uses.  A full copy
up-front was implemented, but was quite heavy as even well behaved
fonts required a full copy and the memory management that goes along
with it.  Value-level copy on write could use less memory but
requires a great deal more record keeping and complexity.  This
change implements array-level copy on write.  If any attempt is made
to write to the control value table or the storage area when the
initial bytecode range was in a glyph program, the relevant array
will be copied to a designated storage area and the copy used for
the rest of the glyph program's execution.

* src/truetype/ttinterp.h (TT_ExecContextRec): New fields
`iniRange`, `glyfCvtSize`, `glyfCvt`, `origCvt`, `glyfStoreSize`,
`glyfStorage`, and `origStorage`.

* src/truetype/ttinterp.c (Modify_CVT_Check): New function to handle
`exc->glyfCvt`.
(Write_CVT, Write_CVT_Stretched, Move_CVT, Move_CVT_Stretched): Use
it.
(Ins_WS): Handle `exc->glyfStorage`.
(Ins_FDEF, Ins_IDEF): Updated.
(TT_RunIns): Updated.
(TT_Done_Context): Free 'glyf' CVT working and storage area.
(TT_Load_Context): Fix/add casts.

* src/truetype/ttgload.c (TT_Load_Simple_Glyph): Fix cast.
2021-04-02 10:31:39 +02:00
Dominik Röttsches 1c0862938d [sfnt] Check validity of pointer location of `read_color_line`.
* src/sfnt/ttcolr.c (get_child_table_pointer): New function to fetch
child table pointer early for all paint formats that compute a child
table pointer.
(read_color_line, read_paint): Updated.
(tt_face_get_colorline_stops): Check `colr->table`.
2021-04-02 07:09:47 +02:00
nikramakrishnan c1e1a07f79 [docs] Update docwriter stylesheet for 1.3.1.
This change is required to support docwriter 1.3.1.

See

  https://gitlab.freedesktop.org/freetype/docwriter/-/merge_requests/101

for more information.

* docs/markdown/stylesheets/extra.css:
(.wy-nav-content, .md-sidebar--secondary): Remove.
2021-03-28 15:07:05 +05:30
Alexei Podtelezhnikov e9c50fa77d * src/sfnt/pngshim.c (Load_SBit_Png): Free `rows` once later. 2021-03-16 22:12:41 -04:00
Ben Wagner b0729b8fbb [sfnt] Fix memory leak in png loading.
Reported as

  https://bugs.chromium.org/p/chromium/issues/detail?id=1182552

Memory is allocated and the pointer assigned to `rows` inside a
'setjmp' scope.  This memory must be freed outside the 'setjmp'
scope after a 'longjmp'.  Since `rows` is a local and modified
inside the 'setjmp' scope it must be marked volatile or it will have
an indeterminate value after the 'longjmp'.

* src/sfnt/pngshim.c (Load_SBit_Png): Fix memory leak of `rows`.
2021-03-16 08:47:45 +01:00
Christopher Degawa 66005cbae1 * CMakeLists.txt: Don't limit generation of 'pkg-config' file to UNIX.
mingw-w64 uses the 'pkg-config' files but does not set UNIX.
2021-03-16 08:36:54 +01:00
Alexei Podtelezhnikov fb9bf2efae * src/smooth/ftgrays.c (gray_set_cell): Refactor to fix VC++ warning. 2021-03-15 22:33:17 -04:00
Werner Lemberg 2149b51f25 Handle various VC++ compiler warnings.
Fixes #1039.

* src/base/ftstroke.c (ft_stroker_inside, ft_stroker_outside):
Initialize `sigma`.

* src/sdf/ftsdf.c (sdf_generate_with_overlaps): Exit immediately if
function arguments are invalid.
* src/sdf/ftsdfrend.c (sdf_property_set) <"overlaps">: Fix cast.

* src/sfnt/sfwoff2.c (woff2_decompress)
[!FT_CONFIG_OPTION_USE_BROTLI]: Use `FT_UNUSED`.

* src/truetype/ttgxvar.c (TT_Get_MM_Var): Initialize `fvar_head`.
2021-03-13 19:08:09 +01:00
Alexei Podtelezhnikov 80bda804d5 [smooth] Reduce copying during integration phase.
We now record `cover' and `area' directly into the linked list. This
makes rendering faster by 10% or even more at larger sizes.

* src/smooth/ftgrays.c (FT_INTEGRATE): Write directly.
(gray_TWorker): Add direct cell reference and remove unused fields.
(gray_set_cell): Consolidate the linked list management and pointers.
(gray_convert_glyph, gray_convert_glyph_inner): Updated.
2021-03-11 22:40:19 -05:00
Alexei Podtelezhnikov d5b7de5541 * src/smooth/ftgrays.c (FT_INTEGRATE): New convenience macro.
(gray_render_line, gray_render_scanline): Use it.
2021-03-11 22:08:45 -05:00
Alexei Podtelezhnikov 8516849977 * src/smooth/ftgrays.c (gray_render_line): Rearrange conditionals.
These produce faster or more optimizable code.
2021-03-09 22:14:44 -05:00
Tim-Philipp Müller 7252e35ed2 [meson] Fix 'mmap' handling on Windows.
* meson.build (ft2_sources): Always use `windows/ftsystem.c` on
Windows unless mmap has been disabled.

  https://gitlab.freedesktop.org/freetype/freetype/-/merge_requests/5#note_829289
2021-03-08 10:24:07 +01:00
Tim-Philipp Müller e222932810 [ci] Add basic support for Meson builds with MSVC on Windows.
This adds meson jobs for VS2017 (x86 and x86_64).

* .gitlab-ci.yml: New file.
2021-03-07 18:01:31 +01:00
Tim-Philipp Müller bb42afbda0 [meson] Add subproject fallbacks for 'libpng' and 'zlib'.
* subprojects/libpng.wrap, subprojects/zlib.wrap: New files.

* meson.build: Updated.
2021-03-07 17:54:21 +01:00
Xavier Claessens d69d9c2397 [meson] Make it work with Windows.
* meson.build: Do not process `ftconfig.h` when not using
`ftconfig.h.in`.

Fixes #1029.
2021-03-07 17:48:15 +01:00
Werner Lemberg 7227aabb3e Revert "[sfnt] Fix crash in `Load_SBit_Png` on Windows x64."
This reverts commit dbf9142f7e, as discussed
in #1037.
2021-03-04 06:41:30 +01:00
Jesse Towner dbf9142f7e [sfnt] Fix crash in `Load_SBit_Png` on Windows x64.
This change fixes a crash that occurs in `Load_SBit_Png` when
running on a 64-bit Windows OS.  A memory access violation exception
would be raised by `setjmp` if the `jmp_buf` is not aligned to a
16-byte memory boundary.  This is due to setjmp executing `movdqa`
instructions to store 128-bit XMM registers to memory, which require
correct memory alignment.  This problem occurs because
`png_create_read_struct` uses `malloc` and `free` for memory
management, which only guarantees 8-byte alignment on Windows.

Instead, to fix the problem, `png_create_read_struct_2` is used on
64-bit Windows, which allows for user-defined memory allocation and
deallocation callbacks to be specified.  These callbacks forward the
allocation and deallocation requests to `_aligned_alloc` and
`_aligned_free`, ensuring that the allocated `png_struct` and
internal `jmp_buf` have the requisite 16-byte alignment.

* src/sfnt/pngshim.c <_WIN64>: Include `malloc.h`.
(malloc_callback, free_callback) <_WIN64>: New functions.
(Load_SBit_Png) <_WIN64>: Use `png_create_read_struct_2` instead of
`png_create_read_struct`
2021-02-27 13:28:13 +01:00
Werner Lemberg e1f364e509 [woff2] Fix memory leak.
Reported as

  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=28148

* src/sfnt/sfwoff2.c (woff2_open_font): Reject fonts that have
multiple tables with the same tag.  While not explicitly forbidden
in the OpenType specification, it is implicitly forbidden by
describing a binary search algorithm for tables that only works
reliably if table tags are unique.
2021-02-25 20:00:07 +01:00
Werner Lemberg df7fcafe6e * CMakeLists.txt: Update location of `LICENSE.TXT`.
Fixes #1035.
2021-02-22 15:33:23 +01:00
Werner Lemberg 111f2f27b5 * builds/unix/ax_pthread.m4: Update from 'autoconf-archive'.
A bunch of fixes were added recently to its git repository.
2021-02-19 20:33:50 +01:00
Werner Lemberg eca35e04fc [unix] Updates for autoconf 2.71.
This fixes warnings reported by autoupdate.

* builds/unix/ax_pthread.m4: Replace `as_echo` with `AS_ECHO`.

* builds/unix/configure.raw: Remove obsolete `AC_HEADER_STDC`.
Don't escape back quotes in messages for `AC_MSG_WARN`.
2021-02-17 21:10:34 +01:00
Werner Lemberg 635d394fe3 * builds/toplevel.mk: Fix previous commit.
<top_level>: Use `TOP_DIR` in `wildcard` function.
(check_out_submodule, copy_submodule): Move down to come after
definition of `all` rule.
Call `mkdir` conditionally.
2021-02-16 19:24:15 +01:00
Werner Lemberg c3a0b43ec6 * builds/toplevel.mk: Use rules for handling 'dlg'.
Suggested by Alexei.

(check_out_submodule, copy_submodule): New targets.
<top-level>: Replace calls to `shell` with rules.
2021-02-16 17:04:51 +01:00
Werner Lemberg dfa7cca5f3 * builds/toplevel.mk: Avoid side effects of `shell`.
We use a dummy variable to catch its output.  Otherwise the `make`
program is going to interpret the return value of `shell`; this can
cause obscure warning or error messages or even be harmful.
2021-02-16 14:29:45 +01:00
Werner Lemberg 92bd99bd25 Move 'dlg' submodule to `subprojects` directory.
This is for future changes with Meson, which doesn't allow a
different name for its `subprojects` directory.  Having both a
`submodules` and a `subprojects` directory is confusing.

* .gitmodules, autogen.sh (copy_submodule_files, DLG_INC_DIR,
DLG_SRC_DIR): Updated.

* builds/toplevel.mk (<top-level>, do-dist),
builds/windows/vc2010/script.bat: Updated.

* src/tools/no-copyright: Updated.
2021-02-16 14:07:18 +01:00
Dominik Röttsches 215ae25330 [sfnt] Update paint format values to support non-variable paints.
* freetype.h (FT_PaintFormat): Update paint format identifiers after
a specification change.  The specification was updated to have
sibling formats, variable and non-variable variants for each.
Reflect that here.

* sfnt/ttcolr.c (read_paint): Remove parsing of variable indices as
the non-variable formats no longer have them.
2021-02-16 13:15:41 +01:00
Daniel E b2aeca5fda * CMakeLists.txt: Improve 'bz2' support.
Not all distributions such as FreeBSD provide a `.pc` file for
'(lib)bz2' so follow autotools and add it to `Libs.private` instead.
2021-02-15 09:09:09 +01:00
Werner Lemberg 7849316ccf * src/tools/update-copyright-year: Fix single-year entry handling.
The fix from 2021-01-17 didn't cover the case where the year to be
updated is identical to the current year.
2021-02-13 09:21:37 +01:00
Werner Lemberg d51452e3ec Add new function `FT_Get_Transform`.
See

  https://github.com/harfbuzz/harfbuzz/issues/2428

for some reasons to introduce this function.

* include/freetype/freetype.h, src/base/ftobjs.c (FT_Get_Transform):
Implement it.
2021-02-13 08:52:58 +01:00
Werner Lemberg d93a011933 Minor editing of last commit; formatting. 2021-02-13 07:50:04 +01:00
Alexei Podtelezhnikov 70fd20e67e Decorate qsort callbacks with cdecl.
* include/freetype/internal/compiler-macros.h (FT_COMPARE_DEF):
Add new macro.
* src/base/ftrfork.c, src/bdf/bdflib.c, src/gxvalid/gxvcommn.c,
src/psaux/afmparse.c, src/psnames/psmodule.c, src/type1/t1afm.c,
src/sfnt/sfwoff.c, src/sfnt/sfwoff2.c: Update qsort callbacks.

Fixes #1026 when compiling FreeType with an unusual calling convention
while the C library qsort still expects cdecl.
2021-02-12 19:28:05 -05:00
Dominik Röttsches 54c5ad5c92 [sfnt] Implement 'COLR' v1 sweep gradients.
* freetype.h (FT_PaintSweepGradient): Add `FT_PaintSweepGradient` to
represent a 'COLR' v1 sweep gradient.
Update format.
(FT_PaintFormat): Update shifted paint formats.
Sync with spec.
* sfnt/ttcolr.c (read_paint): Logic to parse sweep gradients.
Fix struct access in radial gradient implementation.
2021-02-11 14:20:03 +01:00
Dominik Röttsches 64f01bfedd [sfnt] Provide optional root transform for 'COLR' v1 glyph graph.
* include/freetype/freetype.h (FT_Get_Color_Glyph_Paint):
Additional function argument root_transform to control whether
root transform should be returned.
(FT_OpaquePaint): Additional tracking field to denote whether
root transform is to be returned.
* include/freetype/internal/sfnt.h
(TT_Get_Color_Glyph_Paint_Func): Propagate additional argument.
* src/base/ftobjs.c (FT_Get_Color_Glyph_Paint): Ditto.
* src/sfnt/ttcolr.c (tt_face_get_colr_glyph_paint): Return root
transform reflecting the size and tranform configured on
FT_Face.
(read_paint): Initialize and track status of insert_root_transform
flag.
2021-02-10 18:51:04 +01:00
Xavier Claessens cc90307d71 * meson.build: s/freetype2_dep/freetype_dep/.
Many projects (e.g., fontconfig, cairo) hardcode the `freetype_dep`
variable name to use FreeType as subproject because that was the
variable name in Centricular's Meson port of FreeType.  While they
should stop hardcoding that variable name, it does not cost us
anything to keep using that name to ease transition.
2021-02-10 18:14:47 +01:00
Xavier Claessens 3dbdb78a25 [meson] Fix handling of HarfBuzz library.
* meson.build (harfbuzz_dep): Do not fall back to HarfBuzz by
default.

Otherwise it causes a dependency cycle:

  cairo => fontconfig => freetype2 => harfbuzz => cairo

Meson will still fall back to HarfBuzz subprojects if the `harfbuzz`
option is set to `enabled` instead of `auto` and a
`subprojects/harfbuzz.wrap` file is present.  In that case it is the
responsibility of the main project to set the proper options on each
subproject to break the dependency cycle.

Fixes: #1028.
2021-02-10 18:10:59 +01:00
Xavier Claessens 2c40559609 Meson: Fix dependency lookup and generate ftconfig.h
[meson] Fix dependency lookup and generate `ftconfig.h`.

- zlib: If not found on the system, meson can build it as a
  subproject.  We thus never use the (outdated) zlib support that
  comes with FreeType.  Doing so has the additional advantage that
  the zlib code can be shared with other projects like GLib if both
  are subprojects of an application.
- harfbuzz: Build as a subproject if not found on the system.
- 'QUESTION: What if the compiler doesn't support `-D` but uses `/D`
  instead as on Windows?'  Answer: Meson translate arguments for us.
- visibility: Replace self-made code with meson-specific solution.

* meson.build (ft2_defines): Rewrite logic to set and handle it.
(process_header_command): New variable, previously called
`ftoption_command`.
(ftoption_command, ftconfig_command): New variables.
(zlib_option): Removed.
(zlib_dep): New variable.
(ft2_deps): Updated.
(harfbuzz_dep): Updated.
(ftconfig_h_in, ftconfig_h): New variables.
(ft2_sources): Updated.
(ft2_lib): Updated, handle visibility.
(summary): Updted.

* meson_options.txt (zlib): Updated.
2021-02-09 16:11:39 +01:00
Xavier Claessens e11cc40a2e * meson.build: Fix resource compilation on Windows.
This is copied from GStreamer's meson port of FreeType.

(ft2_sources): Add both debug and resource file (the latter for
Windows only).
(ft2_debug_src): Removed.
2021-02-09 16:11:39 +01:00
Xavier Claessens 69e0faa893 * meson.build: s/ft2_libtool_version/ft2_pkgconfig_version/.
(freetype2_dep): Use it.

`ft2_libtool_version` would be the shared library version, not the
one we should use in file `freetype2.pc`.
2021-02-09 16:11:39 +01:00
Xavier Claessens 0565c5ba2b * meson.build: Use `meson.override_dependency`.
This is a new meson mechanism to avoid other projects to hard-code
the `freetype2_dep` variable name in their build definition.  It
also ensures that meson does not mix system and subproject versions
of FreeType inside of the same project.

Also remove outdated TODO because `declare_dependency` was already
there.
2021-02-09 16:11:39 +01:00
Xavier Claessens 5c81e09b17 * meson.build (bzip2_dep): Simplify.
We remove `static:false` from `find_library('bz2')`.

I don't know whether the previous code was a workaround for an old
meson bug, but at least with version >=0.55.0 (which FreeType uses)
it picks the shared library when both are available.

With this commit, file `freetype2.pc` no longer contains the full path to
file `libbz2.so`; instead, it correctly uses `-lbz2`.  Note that this is a
meson bug is still present in the current version (0.57.0).
2021-02-09 16:09:04 +01:00
Xavier Claessens 1b69fb9bdb * meson.build: Set project version. 2021-02-09 15:54:54 +01:00
Werner Lemberg 947e475283 [base] Fix Netpbm tracing message.
* src/base/ftobjs.c (FT_Render_Glyph_Internal): Don't emit Netpbm
warning if there is nothing to output.
2021-02-04 10:19:26 +01:00
Werner Lemberg d924a66a5c * src/*: Don't use more than one '\n' in `FT_TRACE` and `FT_ERROR`.
This ensures good logging output, with all lines having a proper
prefix (if requested).

This is a continuation of a similar patch from 2020-12-02, which
missed some locations.
2021-02-04 07:46:46 +01:00