Commit Graph

6840 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 8cce50b9b8 Be more explicit about the output of the SDF rasterizers.
* include/freetype/fttypes.h (FT_F6Dot10): Add a new data type which can be\
  used to convert the output buffer appropriately.

* include/freetype/freetype.h (FT_Render_Mode): Add information about the
  output while using `FT_RENDER_MODE_SDF'.

* include/freetype/ftimage.h (FT_Pixel_Mode): Add more information about the
  `FT_PIXEL_MODE_GRAY16' pixel mode.
2020-08-23 05:35:46 +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 1df094bd7a [sdf] Added `sdf' module to non gnumake build systems.
* include/freetype/config/ftmodule.h (*): Add both the renderers to the list of 
  modules. This allows build systems other than GNU Make to use the renderers.

* CMakeLists.txt (BASE_SRCS): Add the `sdf' module single object to the list of source
  files.
2020-08-20 08:28:14 +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 6b81c538ed Added render mode and data type required for the `sdf' module.
* include/freetype/freetype.h (FT_Render_Mode): Added a new render mode
  `FT_RENDER_MODE_SDF', which will be used to generate SDF.

* include/freetype/ftimage.h (FT_Pixel_Mode): Added a new pixel mode
  `FT_PIXEL_MODE_GRAY16', which will be the output of the `sdf' module.

* include/freetype/ftimage.h (FT_RASTER_FLAG_SDF): Added a new raster flag
  to be used internally by the `sdf' module.
2020-08-16 10:47:41 +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
Werner Lemberg 8b3601324f Minor typos, formatting. 2020-08-04 10:48:42 +02:00
Alexei Podtelezhnikov 986a340dd5 Unbreak compilation. 2020-07-28 23:20:59 -04:00
Alexei Podtelezhnikov f76f7fdecd Hide internal functions with SunPro.
* include/freetype/internal/compiler-macros.h
(FT_INTERNAL_FUNCTION_ATTRIBUTE) <__SUNPRO_C>: Define as __hidden.
2020-07-28 23:13:51 -04:00
Anuj Verma 3273521f40 Fix static compilation with Visual C.
* include/freetype/internal/compiler-macros.h
(FT_INTERNAL_FUNCTION_ATTRIBUTE) <_WIN32>: Define as empty.
2020-07-28 18:34:37 +02:00
Werner Lemberg fffc303a7f Formatting, improving comments. 2020-07-28 18:33:15 +02: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
David Turner ee19a6cbbc Add .clang-format file
This file can be used to reformat FreeType sources and commits
using one of these methods:

- Direct formatting of a whole file:

    clang-format -i path/to/file

  For example, to reformat all sources at once:

    echo builds/unix/ftconfig.h.in $(git ls-files *.[hc]) | xargs clang-format -i

- Only reformat the changed lines in the current work directoy:

    git clang-format

The style settings in this file are very close to the FreeType
formatting style, with the following exceptions which are not supported
here:

- Mminimal 2-space margin on each non-empty line.
  (no left margin instead).

- 2 empty lines between variable declarations and statements in C blocks.
  (only 1 is kept).

    {
      int  x = ...;

      foo(x);
    }

  becomes

    {
      int x = ...;

      foo(x);
    }

- Aignment of declarations uses 2 spaces to separate types and variable
  names (only 1 space is kept).

     int  x;    =>   int x;
     int  y;         int y;

- The start used for output parameters in function signature should be
  near the variable name (always near the type).

    void foo(int* input_ptr, int *output_ptr)
      => void foo(int* input_ptr, int* output_ptr)
2020-07-16 15:51:06 +02:00
Werner Lemberg b7c467b6ef [doc] Stem darkening is off by default for CFF driver.
Bug reported by Ishi Tatsuyuki <ishitatsuyuki@gmail.com>.
2020-07-15 09:15:25 +02:00
David Turner 5fe7c044c2 freetype.h (FT_Set_Transform): Minor documentation update.
In order to mention the limited accuracy of `FT_Matrix' coefficients
and encourage client code to perform the transform themselves with
floating point values instead.
2020-07-14 16:25:59 +02:00
Werner Lemberg 95de21ab19 README: Add information on contributing patches. 2020-07-14 08:32:45 +02:00
Werner Lemberg c922ffa5d2 * builds/unix/configure.raw: Fix inclusion of `ftoption.h'. 2020-07-12 07:52:55 +02:00