Commit Graph

4955 Commits

Author SHA1 Message Date
Anuj Verma 6218c942ad [sdf] Fix compiler warnings.
* src/sdf/ftsdf.c (get_control_box): Use goto instead of letting the next case statement
  execute to avoid compiler warning [-Wimplicit-fallthrough=].

* src/sdf/ftsdf.c (sdf_generate_bounding_box): Fix compiler warning due to signed
  unsigned mismatch.

* src/sdf/ftsdfrend.c (ft_sdf_done): The function must have a return type of `void'
  to match the signature of `FT_Module_Destructor'.
2020-08-24 09:40:46 +05:30
Anuj Verma d2d939098d [sdf, bsdf] Fix compiler warnings.
* src/sdf/ftsdf.c, src/sdf/ftbsdf.c (*): Fix compiler warnings caused due to signed
  unsigned mismatch (-Wsign-compare).
2020-08-23 18:03:39 +05:30
Anuj Verma 7c2a64b709 [sdf] Added debugging function.
* src/sdf/ftsdf.c (sdf_shape_dump): Added a debugging function which can be used
  to debug issues with the outline, contours, edges etc.
2020-08-21 04:59:08 -07:00
Anuj Verma ed49facfe0 [sdf] Bug fix.
* src/sdf/ftsdf.c (*): Only track memory when `FT_DEBUG_MEMORY' is defined. Some
  variables used internally by the freetype memory debugger are only defined when
  we are tracking memory. If `FT_DEBUG_MEMORY' is not defined those variable
  are not defined and we get undefined reference error.
2020-08-21 04:55:15 -07:00
Anuj Verma 644a6c24fd [sdf] Added brief technical overview of both the rasterizers.
* src/sdf/ftsdf.c (*): Added a technical overview of the working of the `sdf' rasterizer.

* src/sdf/ftbsdf,c (*) : Added a technical overview of the working of the `bsdf'
  rasterizer.
2020-08-21 03:59:23 -07:00
Anuj Verma 56e4100aad [sdf] Added the `bsdf' renderer to the `sdf' module.
* src/sdf/ftsdfrend.c (ft_bsdf_render): Added the `bsdf' renderer, render function 
  which is essentially what is called from the FreeType core to render a glyph.

* src/sdf/ftsdfrend.c (ft_bitmap_sdf_renderer_class): Added the `bsdf' renderer
  definition.
2020-08-20 21:57:43 -07:00
Anuj Verma 67652386e2 [bsdf] Added forward declaration of the `bsdf' rasterizer.
* src/sdf/ftsdf.h (ft_bitmap_sdf_raster): Added forward declaration of the rasterizer
  so that it can be added to the renderer.
2020-08-20 21:27:59 -07:00
Anuj Verma d1e95d734c [bsdf] Added the interface functions for the `bsdf' rasterizer.
* src/sdf/ftsdf.c (bsdf_raster_): Added interface functions which are called from the
  FreeType core library to rasterize and do various other stuff with the rasterizer.
2020-08-20 21:25:46 -07:00
Anuj Verma f2545feda9 [bsdf] Added function to copy the SDF data into the output bitmap.
* src/sdf/ftbsdf.c (finalize_sdf): The function uses the final data present in the 
  distance map and copies is to the output bitmap. It also converts our data into the
  desired format.
2020-08-20 21:21:33 -07:00
Anuj Verma c6b4053a76 [bsdf] Added the 8SED algorithm.
* src/sdf/ftbsdf.c (edt8): Added function to do the euclidean transform to the 
  distance map. The function basically does the 8SED algorithm on the distance map 
  to compute the distance transform of the bitmap.

* src/sdf/ftbsdf.c (first_pass, second_pass): The first and the second pass of the 8SED
  algorithm.

* src/sdf/ftbsdf.c (compare_neighbor): Helper function to compare the neighbor of
  a pixel which is required in the 8SED algorithm.
2020-08-20 21:19:32 -07:00
Anuj Verma 461d693c29 [bsdf] Added function to copy source bitmap to the distance map.
* src/sdf/ftbsdf.c (bsdf_init_distance_map): The function copies the source bitmap to
  the intermediate distance map which is present within the `worker'.
2020-08-20 21:09:23 -07:00
Anuj Verma e883c6dc50 [bsdf] Added function to approximate edge distances.
* src/sdf/ftbsdf.c (compute_edge_distance): Added function to approximate edges 
  given only the array of alpha values representing pixel coverage. This function uses
  the Gustavson's algorithm for approximating.

* src/sdf/ftbsdf.c (bsdf_approximate_edge): This function loops through the entire
  bitmap and for edge pixel (found using `bsdf_is_edge') compute approximate edge
  distances (using `compute_edge_distance').
2020-08-20 09:25:15 +05:30
Anuj Verma 44e9d12f0f [bsdf] Added function to find edge pixels given a grid of alpha values.
* src/sdf/ftbsdf.c (bsdf_is_edge): The function find the edge pixel in a distance map
  which is basically a 2D array of alpha values which represent coverage in the
  original input bitmap.
2020-08-20 09:20:26 +05:30
Anuj Verma 2aeee74c0c [bsdf] Added essential structures required by the `bsdf' rasterizer.
* src/sdf/ftbsdf.c (*): Added all the essential structures required internally by the
  `bsdf' rasterizer as well as the initializer for the `ED' struct.
2020-08-20 09:17:38 +05:30
Anuj Verma d5397730b4 [sdf] Added basic overlapping contour support.
* src/sdf/ftsdf.c (sdf_generate_with_overlaps): Added another `sdf_generate_' 
  function which can generate SDF for glyphs with overlapping contour. Note that
  it cannot generate proper SDF for glyphs with self intersecting contours.
2020-08-20 07:54:13 +05:30
Anuj Verma a538f17928 [sdf] Add the `sdf' module to `modules.cg' and fix makefiles.
* src/sdf/module.mk, src/sdf/rules.mk: Fix file names, they were reversed.

* include/freetype/ftmoderr.h (FT_MODERRDEF): Add error definition for the `sdf'
  module.

* include/freetype/internal/fttrace.h (FT_TRACE_DEF): Add trace definition for the 
  `sdf' module.

* modules.cfg (RASTER_MODULES): Add the `sdf' module to the list of rasterizers.
2020-08-19 17:30:44 +05:30
Anuj Verma c76b653829 [sdf] Added makefiles to build the `sdf' module.
* src/sdf/ftsdf.c (module.mk, rules.mk): Added makefiled to build the `sdf' module.

* src/sdf/ftsdf.c (ft_sdf_raster): Added forward declaration of the `sdf' rasterizer.
2020-08-19 16:57:38 +05:30
Anuj Verma 8359cb3501 [sdf] Added the interface functions for the `sdf' rasterizer.
* src/sdf/ftsdf.c (sdf_raster_): Added interface functions which are called from the
  FreeType core library to rasterize and do various other stuff with the rasterizer.
2020-08-19 16:29:51 +05:30
Anuj Verma 5cee930937 [sdf] Added the subdivision and bounding box optimization.
* src/sdf/ftsdf.c (sdf_generate_bounding_box): Added function to generate SDF by
  only checking grid point around the bounding box of any edge.

* src/sdf/ftsdf.c (sdf_generate_subdivision): Added function to generate SDF by 
  splitting the shape into a number of line segments and then only checking grid
  points around the neighborhood of the lines.
2020-08-19 16:25:08 +05:30
Anuj Verma 596bcfd340 [sdf] Added function to generate SDF.
* src/sdf/ftsdf.c (sdf_generate): Added function to generate SDF. This one doesn't use
  any optimization, it simply check all grid point against all contours.
2020-08-19 12:56:58 +05:30
Anuj Verma 75182d8ad1 [sdf] Added functions to get shortest distance from any edge/contour.
* src/sdf/ftsdf,c (sdf_edge_get_min_distance): Added function to get shortest distance
  from any arbitary edge.

* src/sdf/ftsdf.c (sdf_contour_get_min_distance): Added function to get shortest
  distance from a contour. It basically returns the shortest distance from the nearest
  edge.
2020-08-19 12:22:34 +05:30
Anuj Verma c39b5dd849 [sdf] Added shortest distance finding functions.
* src/sdf/ftsdf.c (get_min_distance_): Added function to find the closest distance
  from a point to a curves of all three different types (i.e. line segment, conic
  bezier and cubic bezier).
2020-08-18 17:49:56 +05:30
Anuj Verma 68032a77e3 [sdf] Added function to resolve corner distances.
* src/sdf/ftsdf.c (resolve_corner): Added function to resolve corner distances
  because at corner two equal distance can have opposite sign.
2020-08-18 10:28:16 +05:30
Anuj Verma 0fcd73fb4a [sdf] Added essential math functions.
* src/sdf/ftsdf.c (cube_root, arc_cos): Added functions to compute cube root and
  cosine inverse of a 16.16 fixed point number.

* src/sdf/ftsdf.c (solve_quadratic_equation, solve_cubic_equation): Added
  functions to find roots of quadratic and cubic polynomial equations.
2020-08-18 10:17:46 +05:30
Anuj Verma 4dc90dc8d0 [sdf] Added utility functions for contours.
* src/sdf/ftsdf.c (get_control_box, get_contour_orientation): Added functions to
  get control box and orientation of any `SDF_Contour'.

* src/sdf/ftsdf.c (split_sdf_shape): Added function to split a complete shape (i.e.
  a collection of contours) into a number of small lines.
2020-08-18 10:14:20 +05:30
Anuj Verma e4e81c0168 [sdf] Added functions to decompose `FT_Outline'.
* src/sdf/ftsdf.c (sdf_outline_decompose): Added a function which decompose
  a `FT_Outline' using `FT_Outline_Decompose' and adds the outline data to a
  `SDF_Shape' for easier handling later on.
2020-08-17 16:36:30 +05:30
Anuj Verma 286fc7e42c [sdf] Added essential structs, enums and macros for `sdf' rasterizer.
* src/sdf/ftsdf.c (SDF_): Added the essential structures and enums which will
  be used internally by the `sdf' rasterizer. Also added allocator and deallocator
  functions for the structs.

* src/sdf/ftsdf.c (SDF_MemoryUser): Added a custom memory allocator which
  is used to track intermediate memory usage while generate SDF.

* src/sdf/ftsdf.c (definations): Added various definitions which can be used to
  modify the `sdf' rasterizer and also added a few helper macros.
2020-08-17 16:24:39 +05:30
Anuj Verma b8f4ab8304 [sdf] Added raster params struct.
* src/sdf/ftsdf.h (SDF_Raster_Params): Added struct which is used to pass 
  params to both `sdf' and `bsdf' rasterizer.

* src/sdf/sdf.c (*): Include source files in order to make a single object of the
  module.

* src/sdf/ftsdfrend.h (SDF_Renderer_Module): Add a '*' to make the comment
  similar to the rest in the module.
2020-08-17 16:11:56 +05:30
Anuj Verma ed7d2f5789 [sdf] Added the `sdf' renderer.
* src/sdf/ftsdf.c (*): Added `sdf' renderer along with
  it's interface functions and functions to set and get
  properties.
2020-08-17 11:47:26 +05:30
Anuj Verma e087e937e8 [sdf] Added common elements for `sdf' and `bsdf' renderers.
* src/sdf/ftsdfrend.c (*): Added common renderer struct and
  declaration of both the renderers.

* src/sdf/ftsdfcommon.h (*): Added common properties, typedefs,
  macros etc.

* src/sdf/ftsdferrs.h (*): Error definitions for the module.
2020-08-17 11:40:57 +05:30
Anuj Verma 29de1ff668 [sdf] Added all the necessary filed required by the module.
Added the necessary files required by the `sdf' module. These include files
for both the `sdf' and the `bsdf' renderers. Here is breakdown of what the
specific files will contain:

* src/sdf/ftsdfrend.*: Both the renderers.

* src/sdf/ftsdf.*: The rasterizer for the `sdf' renderer.

* src/sdf/ftbsdf.c: The rasterizer for the `bsdf' renderer.

* src/sdf/ftsdfcommon.h: Commmon properties and functions for both the
  rasterizers.

* src/sdf/ftsdferrs.h: Common error define.

* src/sdf/sdf.c: For building a single object of the entire module.
2020-08-16 17:09:22 +05:30
Anuj Verma 6ed3c34a0e [base] Make necessary changes to allow renderers of different formats.
* src/base/ftobjs.c (FT_Render_Glyph_Internal): Do not return if the glyph's slot
  format is `FT_GLYPH_FORMAT_BITMAP'. The `bsdf' renderer will require bitmaps 
  for processing.

* src/base/ftobjs.c (ft_add_renderer, ft_remove_renderer): Remove renderer's glyph
  format check before adding and removing them. The `bsdf' renderer will have a
  format of `FT_GLYPH_FORMAT_BITMAP'. So, if we do not remove this check it will
  not get initialized and will not work.
2020-08-16 09:06:59 +05:30
Alexei Podtelezhnikov f9f6adb625 [truetype] Retain OVERLAP_SIMPLE and OVERLAP_COMPOUND.
For glyphs with OVERLAP_SIMPLE or OVERLAP_COMPOUND, set
FT_OUTLINE_OVERLAP to render them with direct oversampling, which
mitigates artifacts (see 3bb512bc9f).

* include/freetype/ftimage.h (FT_OUTLINE_OVERLAP): Redefine to rhyme
with OVERLAP_SIMPLE.
* src/base/ftgloadr.c (FT_GlyphLoader_Rewind): Reset outline flags.
* src/truetype/ttgload.c
(TT_Load_Simple_Glyph): Retain OVERLAP_SIMPLE.
(load_truetype_glyph): Retain OVERLAP_COMPOUND.
2020-08-05 08:24:15 -04:00
Alexei Podtelezhnikov 3a1f4b7aaa * src/truetype/ttgload.c (TT_Load_Glyph): More tracing. 2020-08-04 22:17:05 -04:00
Priyesh Kumar 53be1753de Fix `-Wformat' compiler warnings.
* src/*: Fix format specifiers.

* builds/unix/ftsystem.c (FT_Stream_Open): Ditto.
2020-07-28 07:33:40 +02:00
Werner Lemberg 8cfc41ae95 Fix `-Wformat' compiler warnings.
Problem reported by Priyesh kumar <priyeshkkumar@gmail.com>

* src/base/ftoutln.c (FT_Outline_Decompose): Fix number of arguments
to tracing macro.

* src/bdf/bdfdrivr.c (bdf_cmap_char_next, bdf_get_bdf_property):
Ditto.

* src/cache/ftcbasic.c (ftc_basic_family_get_count): Ditto.
Reformulate message.

* src/pcf/pcfdrivr.c (pcf_get_bdf_property): Ditto.

* src/sfnt/sfwoff2.c (woff2_open_font): Ditto.
Trace table offset, too.

* src/truetype/ttgxvar.c (ft_var_apply_tuple): Ditto.
2020-07-25 12:23:22 +02:00
Werner Lemberg b6183ea369 * src/sfnt/sfwoff2.c (woff2_decompress): Fix compiler warning.
Reported by Hin-Tak.
2020-07-23 13:03:22 +02:00
Werner Lemberg 96fb73efd5 Fix clang warnings.
* include/freetype/internal/autohint.h
(FT_DECLARE_AUTOHINTER_INTERFACE): New macro.
* src/autofit/afmodule.h: Use it to declare
`af_autofitter_interface'.

* include/freetype/internal/ftobjs.h (FT_DECLARE_GLYPH): New macro.
* src/base/ftbase.h: Use it to declare `ft_bitmap_glyph_class' and
`ft_outline_glyph_class'.

* src/base/ftglyph.c: Include `ftbase.h'.

* src/cff/cffparse.c (cff_parser_run): Fix type of `t2_size'.

* src/pcf/pcfdrivr.c (pcf_cmap_char_next): Fix type of `result'.

* src/psaux/psauxmod.c (psaux_module_class): Use `FT_DEFINE_MODULE'.
* src/psaux/psauxmod.h: Declare `afm_parser_funcs',
`t1_cmap_classes', `cff_decoder_funcs', and `psaux_module_class'.

* src/pshinter/pshmod.c: Include `pshmod.h'.

* src/sfnt/sfwoff2.c (ROUND4, WRITE_SHORT): Fix implicit sign
conversion.
(compute_ULong_sum): Fix return type.
Fix implicit sign conversion.
(store_points): Fix type of `last_flag', `repeat_count', and `flag'.
Use casts to avoid warnings.
(reconstruct_glyf): Fix implicit sign conversion.
Use cast to avoid warning.
(get_x_mins): Fix implicit sign conversion.
* src/sfnt/ttcmap.c: Undef `TTCMAPCITEM'.
* src/sfnt/ttcmap.h: Define `TTCMAPCITEM' and include `ttcmapc.h' to
declare cmap classes.

* src/smooth/ftsmooth.c (ft_smooth_overlap_spans): Use cast.

* src/truetype/ttinterp.c (Ins_MIAP): Fix typo.
2020-07-07 16:58:14 +02:00
David Turner 0f35b042e0 [build] Really fix multi and C++ builds.
The following builds were still failing due to previous changes:

  make multi
  make multi CC="c++"
  make CC="c++"

This patch fixes the issues, which were missing includes to get the
right macro definitions in multi-build mode.

Also, `FT_UNUSED' is actually used by third-party code, so move it
back to `public-macros.h' to avoid breaking it.

* include/freetype/config/public-macros.h (FT_EXPORT): Remove
special definition for C++.
(FT_UNUSED): Define here instead of...
* include/freetype/config/compiler-macros.h: ... here.
(FT_FUNCTION_DECLARATION): Remove special definition for C++.
(FT_LOCAL_ARRAY_DEF): Fix definition.

* src/cache/ftccback.h, src/lzw/ftzopen.h, src/gxvalid/gxvmort.h,
src/gxvalid/gxvmorx.h: Add `FT_BEGIN_HEADER' and `FT_END_HEADER'.
2020-07-07 06:51:09 +02:00
David Turner cb4a943bc4 [build] Fix multi and C++ builds.
The following builds were failing due to previous changes:

  make multi
  make multi CC="c++"

* include/freetype/config/ftconfig.h: Remove `FT_END_HEADER'.

* include/freetype/config/ftheader.h (FT_BEGIN_HEADER,
FT_END_HEADER): Protect against redefinition.

* src/cache/ftccache.h, src/cache/ftcmru.h, src/pcf/pcfutil.h,
src/psaux/pserror.h, src/psaux/psft.h, src/psaux/psstack.h,
src/sfnt/woff2tags.h: Include `compiler-macros.h'.

* src/sfnt/woff2tags.c: Include `woff2tags.h'.
2020-07-06 11:49:00 +02:00
Werner Lemberg 2eb8f88626 [psaux] Improve `t1_decoder_parse_metrics' (#58646).
* src/psaux/t1decode.c (t1_decoder_parse_metrics): Copy
corresponding code from old engine's `t1_decoder_parse_charstrings'
function to handle `op_callsubr' and `op_return'.
2020-07-06 09:21:03 +02:00
David Turner bb66c8d8cf [build] Split off more stuff from `ftconfig.h'.
* builds/unix/ftconfig.h.in, builds/vms/ftconfig.h,
include/freetype/config/ftconfig.h: Split off macro definitions
required by the FreeType API headers to...
* include/freetype/config/public-macros.h: ...this new file.

* builds/unix/ftconfig.h.in, builds/vms/ftconfig.h,
include/freetype/config/ftconfig.h: Split off macro definitions used
by the library but not to be exposed to clients to...
* include/freetype/config/compiler-macros.h: ...this new file.

* include/freetype/internal/*.h, src/raster/ftraster.h: Include
`compiler-macros.h' where needed.
2020-07-05 10:42:23 +02:00
Alexei Podtelezhnikov 3bb512bc9f [smooth] Introduce direct oversampling for overlaps.
This implements oversampling to metigate artifacts in pixels partially
covered by overlapping contours.  It turns out that the 4x4
oversampling is sufficient but, at least, quadruples the rendering
time.  The outline has to set FT_OUTLINE_OVERLAP to use this method.

* include/freetype/ftimage.h (FT_OUTLINE_OVERLAP): New flag.
* src/smooth/ftsmooth.c (ft_smooth_render): Check it to...
(ft_smooth_raster_overlap): ... inflate outline and set up direct
rendering for oversampling with...
(ft_smooth_overlap_spans): ... new span function that integrates them.
2020-07-03 22:29:34 -04:00
Alexei Podtelezhnikov 19d39f43d2 [smooth] Use direct rendering mode in Harmony.
Instead of rendering 3 bitmaps side by side and reshuffling, we use
direct rendering to deliver the bitmaps on each third byte.

* src/smooth/ftsmooth.c (ft_smooth_raster_lcd)
[!FT_CONFIG_OPTION_SUBPIXEL_RENDERING]: Set up direct mode with...
(ft_smooth_lcd_spans): ... new span function.
2020-07-03 09:17:22 -04:00
Alexei Podtelezhnikov 2d67511a14 [smooth] Separate LCD paths from gray rendering.
This makes `ft_smooth_render' a lot smaller and easier to follow. It
also cleanly separates Harmony and ClearType-style LCD rendering
algorithms. Now I only wish to move LCD filtering and geometry from
FT_Library to FT_Renderer.

* src/smooth/ftsmooth.c (ft_smooth_render): Move LCD code from here...
(ft_smooth_raster_lcd, ft_smooth_raster_lcdv): ... to here.
[FT_CONFIG_OPTION_SUBPIXEL_RENDERING]: Reorganize #ifdef's.
2020-07-03 09:02:09 -04:00
Sebastian Rasmussen a443474755 [cff] Fix handling of `style_name == NULL' (#58630).
* src/cff/cffobjs.c (cff_face_init): If a call to `cff_strcpy' fails
by returning NULL in `cff_face_init', `remove_style' is still
called.  This means that the NULL pointer is dereferenced, causing a
crash.
2020-06-20 05:31:34 +02:00
Sebastian Rasmussen f594ffdc35 [cff] Fix another two memory leaks (#58629).
* src/cff/cffobjs.c (cff_size_init): If a call to `funcs->create'
fails to allocate one of the `internal->subfont' variables, make
sure to free `internal->topfont' and any successfully allocated
subfonts.
2020-06-19 18:55:49 +02:00
Sebastian Rasmussen 2e2f3cb5ba [psaux] Fix memory leak (#58626).
* src/psaux/psstack.c (cf2_stack_init): If `cf2_stack_init' fails to
allocate the stack, return error early.
2020-06-19 18:51:33 +02:00
Sebastian Rasmussen 09b98060d3 Fix memory leak (#58624).
* src/base/ftobjs.c (FT_New_Size): Avoid trying to free
  `size->internal`, unless `size' has been allocated. This
  mistake appeared in the fix for 58611.
2020-06-19 18:49:36 +02:00
Alexei Podtelezhnikov 6e722f2eaa [base] Rework d1180b5f95 until further notice.
* src/base/ftoutln.c (FT_Outline_Get_Orientation): Reject large
outlines.
2020-06-19 08:39:23 -04:00