Commit Graph

461 Commits

Author SHA1 Message Date
Nikolaus Waxweiler 2e9519885b Add face property for LCD filter weights.
* include/freetype/ftlcdfil.h (FT_PARAM_TAG_LCD_FILTER_WEIGHTS,
FT_LCD_FILTER_FIVE_TAPS): New macros.
(FT_LcdFiveTapFilter): New typedef.

* include/freetype/ftobjs.h (FT_Face_InternalRec)
[FT_CONFIG_OPTION_SUBPIXEL_RENDERING]: Add `lcd_weights' field.
(FT_Bitmap_LcdFilterFunc): Change third argument to weights array.
(ft_lcd_filter_fir): New prototype.
(FT_LibraryRec): Updated.

* src/base/ftlcdfil.c (_ft_lcd_filter_fir): Renamed to...
(ft_lcd_filter_dir): ... this base function.
Updated.
(_ft_lcd_filter_legacy): Updated.
(FT_Library_SetLcdFilterWeights, FT_Library_SetLcdFilter): Updated.

* src/base/ftobjs.c (ft_open_face_internal): Updated.
(FT_Face_Properties): Handle FT_PARAM_TAG_LCD_FILTER_WEIGHTS.

* src/smooth/ftsmooth.c (ft_smooth_render_generic)
[FT_CONFIG_OPTION_SUBPIXEL_RENDERING: Handle LCD weights from
`FT_Face_Internal'.
2017-02-16 20:45:45 +01:00
Nikolaus Waxweiler 64cdee7348 Add new function `FT_Face_Properties'.
This commit provides the framework, to be filled with something
useful in the next commits.

* include/freetype/freetype.h (FT_Face_Properties): Declare.

* src/base/ftobjs.c (FT_Face_Properties): New function.
2017-02-15 08:06:35 +01:00
Werner Lemberg c529885b0b * src/base/ftobjs.c (ft_open_face_internal): Improve tracing. 2017-01-12 08:42:55 +01:00
Werner Lemberg 563ae78022 Update copyright year. 2017-01-04 20:16:34 +01:00
Werner Lemberg 24be60b5f1 */*: Use hex numbers for errors in tracing messages. 2017-01-01 08:20:38 +01:00
Werner Lemberg f80c4473b6 Replace `++foo' and `--foo' with `foo++' and `foo--', resp. 2016-12-26 23:57:45 +01:00
Werner Lemberg 4441f7b246 Replace `foo == NULL' and `foo != NULL' with `!foo' and `foo', resp.
Other minor formatting.
2016-12-26 17:08:17 +01:00
Werner Lemberg 57a6733dcf [base] Improve sanity check for Mac resources (#49888).
* src/base/ftobjs.c (Mac_Read_sfnt_Resource): Abort if `rlen' is not
positive.
2016-12-21 06:52:23 +01:00
Werner Lemberg b55730320c ftobjs.c: Formatting. 2016-12-20 23:22:06 +01:00
Werner Lemberg d5fe8da774 Spelling. 2016-12-20 22:03:40 +01:00
Werner Lemberg 5743df7718 [base] Fix invalid mac font recursion.
Reported as

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

* src/base/ftobjs.c (FT_Open_Face): Code moved to...
(ft_open_face_internal): ... this function.
Add a parameter to control whether we try special Mac font handling
in case of failure.
(FT_Open_Face, FT_New_Face, FT_New_Memory_Face,
open_face_from_buffer): Use `ft_open_face_internal'.
2016-12-18 21:01:03 +01:00
Werner Lemberg 5d664b6d51 Use FT_SET_ERROR where useful. Other minor code formatting. 2016-12-17 20:47:42 +01:00
Werner Lemberg 3b125e9594 Improve tracing of `FT_Open_Face'.
* src/base/ftobjs.c (FT_Open_Face): Return info on number of
available faces and numbered instances, or the indices of the
requested face and numbered instance.

* src/sfnt/sfobjs. (sfnt_open_font): Trace number of subfonts.
2016-12-17 10:02:19 +01:00
Werner Lemberg a7dc0c3554 Extend functionality of `ft_module_get_service'.
It can now differentiate between local and global searches.

* src/base/ftobjs.c (ft_module_get_service): Add `global' argument.
(FT_Get_TrueType_Engine_Type): Updated.

* src/cff/cffdrivr.c (cff_get_ps_name, cff_get_cmap_info): Updated.

* include/freetype/internal/ftobjs.h: Updated.
* include/freetype/internal/ftserv.h (FT_FACE_FIND_GLOBAL_SERVICE):
Updated.
2016-12-14 18:54:21 +01:00
Werner Lemberg e1ee5476a4 * src/base/ftobjs.c (FT_Render_Glyph_Internal): Fix tracing. 2016-11-06 12:39:05 +01:00
Werner Lemberg 37e193e935 Introduce a way of quickly retrieving (embedded) bitmap metrics.
`FT_Load_Glyph' doesn't generate a bitmap for a non-bitmap glyph
until the user calls `FT_Render_Glyph'.  However, it always
allocates memory for bitmaps and copies or decodes the contents of a
bitmap glyph, which can be quite slow for PNG data.

* include/freetype/freetype.h (FT_LOAD_BITMAP_METRICS_ONLY): New
macro.

* src/base/ftobjs.c (FT_Load_Glyph): Unset FT_LOAD_RENDER if
FT_LOAD_BITMAP_METRICS_ONLY is used.

* src/sfnt/ttsbit.c (tt_sbit_decoder_alloc_bitmap,
tt_sbit_decoder_load_bitmap): Add argument to control allocation of
the glyph slot.
(tt_sbit_decoder_load_image, tt_sbit_decoder_load_compound,
tt_face_load_sbit_image): Updated.

* src/pcf/pcfdrivr.c (PCF_Glyph_Load): Quickly exit if
`FT_LOAD_BITMAP_METRICS_ONLY' is set.

* src/pfr/pfrsbit.c, src/pfr/pfrsbit.h (pfr_slot_load_bitmap): Add
argument to control allocation of the glyph slot.
* src/pfr/pfrobjs (pfr_slot_load): Updated.

* src/winfonts/winfnt.c (FNT_Load_Glyph): Ditto.

* docs/CHANGES: Updated.
2016-11-06 12:32:51 +01:00
Werner Lemberg d609b7c158 [sfnt] Don't provide (completely) broken strike data.
FreeType tries to sanitize strike header data; we now reject
completely broken ones.

* include/freetype/internal/tttypes.h (TT_FaceRec): New
`sbit_strike_map' array pointer.

* src/base/ftobjs.c (FT_Match_Size): Reject matches where either
width or height would be zero.
Add tracing message in case of error.

* src/sfnt/sfobjs.c (sfnt_load_face): Populate `sbit_strike_map',
only using (more or less) valid strike header data for
FT_Face's `available_sizes' array.
(sfnt_done_face): Updated.

* src/sfnt/ttsbit.c (tt_face_set_sbit_strike): Use
`sbit_strike_map'.
(tt_face_load_strike_metrics): Improve tracing.

* src/truetype/ttdriver.c (tt_size_select): Use `sbit_strike_map'.
2016-09-09 22:11:07 +02:00
Werner Lemberg b98dfda392 [base] Avoid negative bitmap stroke dimensions (#48985).
* src/base/ftobjs.c (FT_Open_Face): Check whether negation was
actually successful.  For example, this can fail for value
-32768 if the type is `signed short'.  If there are problems,
disable the stroke.
2016-09-03 08:20:31 +02:00
Werner Lemberg 605946af6d Conditionally compile environment support.
* include/freetype/internal/ftobjs.h, src/autofit/afmodule.c,
src/base/ftobjs.c, src/cff/cffdrivr.c, src/truetype/ttdriver.c:
Decorate with `FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES' where
necessary.
2016-07-11 16:14:36 +02:00
Werner Lemberg c3beb30a21 Add function `ft_property_string_set'.
This is a preparation for handling an `FREETYPE_PROPERTIES'
environment variable to control (some) driver properties.

No change in functionality.

* src/base/ftobjs.c (ft_property_do): Add `value_is_string'
parameter.
(ft_property_string_set): New function.
(FT_Property_Set, FT_Property_Get): Updated.

* include/freetype/internal/ftobjs.h: Updated.

* include/freetype/internal/services/svprop.h
(FT_Properties_SetFunc): Add `value_is_string' parameter.

* src/autofit/afmodule.c (af_property_set), src/cff/cffdrivr.c
(cff_property_set), src/truetype/ttdriver.c (tt_property_set):
Updated, emitting an error currently if `value_is_string' is set.
2016-07-10 07:11:45 +02:00
Werner Lemberg 5485a34c77 [truetype] Fix missed test for named instances (#48122).
* src/truetype/ftobjs.c (Mac_Read_sfnt_Resource): Implement.
2016-06-04 06:57:32 +02:00
Werner Lemberg d583561e1d Minor clang++ fixes.
* src/base/ftobjs.c (FT_Add_Module), src/psaux/psobjs.c
(ps_parser_load_field), src/type1/t1load.c (parse_subrs): Add
initializer.

* src/cache/ftccache.h (FTC_CACHE_TRYLOOP_END): Avoid implicit
conversion from NULL to boolean.
2016-05-21 11:20:42 +02:00
Werner Lemberg bebac3cf5b [base] Reject invalid sfnt Mac resource (#47891).
* src/base/ftobjs.c (open_face_PS_from_sfnt_stream): Check validity
of `CID ' and `TYPE1' table offset and length.
2016-05-16 20:16:35 +02:00
Alexei Podtelezhnikov e85422606d Typos. 2016-04-08 23:21:34 -04:00
Werner Lemberg 0d053bac84 Fix runtime errors found by clang's sanitizer (#47082).
* src/base/ftobjs.c (FT_Render_Glyph_Internal), src/base/ftoutln.c
(FT_Outline_Copy), src/cache/ftcsbits.c (ftc_sbit_copy_bitmap):
Properly handle empty input buffer.
2016-02-07 19:25:56 +01:00
Nikolaus Waxweiler 1d8d0b4ef9 Remove unpatented hinter (3/3).
* include/freetype/config/ftoption.h
(TT_CONFIG_OPTION_UNPATENTED_HINTING): Remove.

* include/freetype/internal/ftobjs.h (FT_Face_InternalRec): Remove
`ignore_unpatented_hinter' field.
Update users.
(FT_DEBUG_HOOK_UNPATENTED_HINTING): Remove.
Update users.

* include/freetype/internal/tttypes.h (TT_FaceRec): Remove
`unpatented_hinting' field.
Update users.

* src/base/ftpatent.c (_tt_check_patents_in_range,
_tt_check_patents_in_table, _tt_face_check_patents): Remove.
(FT_Face_CheckTrueTypePatents, FT_Face_SetUnpatentedHinting):
Replace code with dummies.

* src/truetype/ttobjs.c (tt_face_init): Remove now defunct code.
* src/truetype/ttobjs.h (TT_GraphicsState): Remove `both_x_axis'
field.
2016-01-28 14:11:14 +01:00
Werner Lemberg 9adeab6452 Update copyright year. 2016-01-13 11:54:10 +01:00
Werner Lemberg 4099281f6e [base] Fix calls to `FT_Stream_Seek'.
* src/base/ftobjs.c (Mac_Read_sfnt_Resource, FT_Open_Face): Set
`error'.
2015-12-14 07:51:25 +01:00
Ben Wagner f0cc1738e2 [base] Check error when seeking to data supplied offset (#46635).
* src/base/ftobjs.c (open_face_PS_from_sfnt_stream):
`ft_lookup_PS_in_sfnt_stream' returns offset and and length from
user supplied data.  Use of this these values must be checked.
2015-12-14 07:00:41 +01:00
Jan Alexander Steffens (heftig) ccd3188af1 Allow native CFF hinter in FT_RENDER_MODE_LIGHT.
Both the native CFF hinter and the auto-hinter now have a very
similar rendering style.

* include/freetype/freetype.h: Mention that FT_LOAD_TARGET_LIGHT no
longer implies FT_LOAD_FORCE_AUTOHINT.

* include/freetype/ftmodapi.h (FT_MODULE_DRIVER_HINTS_LIGHTLY): New
macro.

* include/freetype/internal/ftobjs.h (FT_DRIVER_HINTS_LIGHTLY): New
macro.

* src/cff/cffdrivr.c (cff_driver_class): Use it.

* src/base/ftobjs.c (FT_Load_Glyph): Update auto-hinter selection
logic.
2015-11-10 22:33:45 +01:00
Werner Lemberg e03214e166 [base] Compute MD5 checksums only if explicitly requested.
This improves profiling accuracy.

* src/base/ftobjs.c (FT_Render_Glyph_Internal): Implement it.
2015-10-15 16:58:13 +02:00
Werner Lemberg 2a20c92c4b [base] Use `FT_' namespace for MD5 functions (#42366).
* src/base/ftobjs.c (MD5_*): Define as `FT_MD5_*'.
Undefine HAVE_OPENSSL.
2015-10-14 15:23:15 +02:00
suzuki toshiya fb5268cf7b [base] Fix a leak by broken sfnt-PS or resource fork (#46028).
open_face_from_buffer() frees passed buffer if valid font
is not found.  But if copying to the buffer is failed,
the allocated buffer should be freed within the caller.

* src/base/ftobjs.c (open_face_PS_from_sfnt_stream): Free
the buffer `sfnt_ps' if an error caused before calling
open_face_from_buffer().
(Mac_Read_sfnt_Resource): Free the buffer `sfnt_data' if
an error caused before calling open_face_from_buffer();
2015-09-28 02:01:43 +09:00
Werner Lemberg d57f227121 * src/base/ftobjs.c (Mac_Read_sfnt_Resource): Add cast. 2015-09-26 08:44:26 +02:00
Werner Lemberg c409eb18ae [base, sfnt] Better checks for invalid cmaps (1/2).
* src/base/ftobjs.c (FT_Get_Char_Index): Don't return out-of-bounds
glyph indices.
(FT_Get_First_Char): Updated.

* src/sfnt/ttcmap.c (tt_cmap6_char_next): Don't return character
codes greater than 0xFFFF.

(tt_cmap8_char_index): Avoid integer overflow in computation of
glyph index.
(tt_cmap8_char_next): Avoid integer overflows in computation of
both next character code and glyph index.

(tt_cmap10_char_index): Fix unsigned integer logic.
(tt_cmap10_char_next): Avoid integer overflow in computation of
next character code.

(tt_cmap12_next): Avoid integer overflows in computation of both
next character code and glyph index.
(tt_cmap12_char_map_binary): Ditto.
(tt_cmap12_char_next): Simplify.

(tt_cmap13_char_map_binary): Avoid integer overflow in computation
of next character code.
(tt_cmap13_char_next): Simplify.
2015-09-24 12:39:38 +02:00
suzuki toshiya e982f5b78a [base] Check too long POST and sfnt resource (#45919).
* src/base/ftbase.h (FT_MAC_RFORK_MAX_LEN): Maximum length
of the resource fork for Mac OS.  The resource fork larger
than 16 MB can be written but could not be handled
correctly, at least in Carbon routine.
See https://support.microsoft.com/en-us/kb/130437

* src/base/ftobjs.c (Mac_Read_POST_Resource): No need `0x'
for `%p' formatter.

* src/base/ftbase.c (Mac_Read_POST_Resource): Check the
fragment and total size of the concatenated POST resource
before buffer allocation.
(Mac_Read_sfnt_Resource): Check the declared size of
sfnt resource before buffer allocation.

* src/base/ftmac.c (read_lwfn, FT_New_Face_From_SFNT):
Check the total resource size before buffer allocation.
2015-09-21 23:12:09 +09:00
Werner Lemberg 19b82cfbed [base] Avoid crash while tracing `load_mac_face'.
Reported in Savannah bug #45919.

* src/base/ftobjs.c (load_mac_face): Honour FT_OPEN_MEMORY while
tracing.
2015-09-11 20:25:32 +02:00
Werner Lemberg 78b014031d [base] Improve kerning tracing and documentation.
* src/base/ftobjs.c (FT_Get_Kerning): Emit tracing message if
scaled-down kerning values differ.
2015-08-25 07:23:01 +02:00
Werner Lemberg 14d6b5d748 [truetype] Introduce named instance access to GX fonts.
For functions querying a face, bits 16-30 of the face index can hold
the named instance index if we have a GX font.  The indices start
with value 1; value 0 indicates font access without GX variation
data.

* include/freetype/freetype.h (FT_FaceRec): Update documentation.
* include/freetype/internal/sfnt.h: Ditto.

* src/sfnt/sfobjs.c (sfnt_init_face)
[TT_CONFIG_OPTION_GX_VAR_SUPPORT]: Get number of named instances and
do argument checks.
(sfnt_load_face): Updated.

* src/truetype/ttobjs.c (tt_face_init)
[TT_CONFIG_OPTION_GX_VAR_SUPPORT]: Use named instance, overwriting
the style name.

* src/base/ftobjs.c (open_face_from_buffer,
open_face_PS_from_sfnt_stream): Updated.
* src/bdf/bdfdrivr.c (BDF_Face_Init): Updated.
* src/cff/cffload.c (cff_font_load): Updated.

* src/cff/cffobjs.c (cff_face_init): Make function exit early for
pure CFF fonts if `font_index < 0'.
Updated.

* src/cid/cidobjs.c (cid_face_init): Updated.
* src/pcf/pcfdrivr.c (PCF_Face_Init): Updated.
* src/pfr/pfrobjs.c (pfr_face_init): Updated.
* src/type1/t1objs.c (T1_Face_Init): Updated.
* src/type42/t42objs.c (T42_Face_Init): Updated.
* src/winfonts/winfnt.c (fnt_face_get_dll_font, FNT_Face_Init):
Updated.

* docs/CHANGES: Updated.
2015-08-13 15:22:17 +02:00
Werner Lemberg eb22ef26d9 Another left-shift bug (#45681).
* src/base/ftobjs.c (IsMacBinary): Only accept positive values for
`dlen'.
2015-08-04 06:50:04 +02:00
Alexei Podtelezhnikov 9de55e0355 [base] NULL. 2015-04-10 23:45:11 -04:00
Werner Lemberg eee7d8baa1 [base] Rename `FT_Bitmap_New' to `FT_Bitmap_Init'.
* include/ftbitmap.h, src/base/ftbitmap.c: Implement it.
Update all callers.

* docs/CHANGES: Updated.
2015-03-10 11:15:15 +01:00
Werner Lemberg 82235d0474 Next round of minor compiler warning fixes.
* include/internal/ftrfork.h (FT_RFork_Ref): Change `offset' member
type to `FT_Long'.
(CONST_FT_RFORK_RULE_ARRAY_BEGIN): Add `static' keyword.

* include/internal/ftstream.h (FT_Stream_Pos): Return `FT_ULong'.

* src/base/ftoutln.c, src/base/ftrfork.c, src/base/ftstream.c:
Signedess fixes.
2015-02-16 19:35:16 +01:00
Werner Lemberg 3cfa4d124c Various minor signedness fixes.
* include/ftadvanc.h, include/internal/ftobjs.h,
src/base/ftgloadr.c, src/base/ftobjs.c: Apply.
2015-02-16 17:59:06 +01:00
Werner Lemberg 79a5ac603a * src/base/ftobjs.c (FT_New_Library): Fix compiler warning. 2015-01-18 07:30:04 +01:00
Werner Lemberg f57fc59e01 Run `src/tools/update-copyright'. 2015-01-17 20:41:43 +01:00
Behdad Esfahbod 603292d7b0 [base] Don't initialize unused `driver->glyph_loader'.
* src/base/ftobjs.c (Destroy_Driver): Don't call
`FT_GlyphLoader_Done'.
(FT_Add_Module): Don't call `FT_GlyphLoader_New'.
2015-01-14 18:35:56 +01:00
Behdad Esfahbod 5163425344 [base] Don't allocate `library->raster_pool' anymore.
It's unused after the following commits:

  [raster] Allocate render pool for mono rasterizer on the stack.
  [raster] Remove 5-level gray AA mode from monochrome rasterizer.

The value of FT_RENDER_POOL_SIZE still serves the purpose it used to
serve, which is, to adjust the pool size.  But the pool is now
allocated on the stack on demand.

* src/base/ftobjs.c (FT_New_Library, FT_Done_Library): Implement.
2015-01-14 18:30:59 +01:00
Behdad Esfahbod 6dfdaf4d99 [base] Do not reorder library->renderers upon use.
Instead of keeping `library->renderers' in a MRU order, just leave
it as-is.  The MRU machinery wasn't thread-safe.

With this patch, rasterizing glyphs from different faces from
different threads doesn't fail choosing rasterizer
(FT_Err_Cannot_Render_Glyph).

Easiest to see that crash was to add a `printf' (or otherwise let
thread yield in FT_Throw with debugging enabled).

* src/base/ftobjs.c (FT_Render_Glyph_Internal), src/base/ftoutln.c
(FT_Outline_Render): Don't call `FT_Set_Renderer'.
2015-01-14 18:21:13 +01:00
Werner Lemberg c9ca6ffc94 * src/base/ftobjs.c (FT_Get_Glyph_Name): Fix off-by-one check.
Problem reported by Dennis Felsing <dennis@felsin9.de>.
2014-12-11 13:39:39 +01:00