Commit Graph

417 Commits

Author SHA1 Message Date
Ewald Hew 78df3c27b6 Extract width parsing from Type 1 parser.
Duplicate the fast advance width calculations from the old parser. This
is to facilitate adding options for compiling out the old parser.

* src/psaux/t1decode.{c,h} (t1_decoder_parse_metrics): New function.
* include/freetype/internal/psaux.h (T1_Decoder_Funcs): New entry
`parse_metrics'.
* src/psaux/psauxmod.c: Set the new entry.

* src/type1/t1gload.c (T1_Parse_Glyph_And_Get_Char_String),
src/cid/cidgload.c (cid_load_glyph): Separate
conditional for selecting engine.
2017-10-12 18:32:50 +08:00
Werner Lemberg 179caf5a61 [psaux] Formatting, minor fixes, whitespace, copyright notices. 2017-10-01 01:40:12 +02:00
Werner Lemberg ec7d2e5f68 * src/psaux/psintrp.c (cf2_doStems): Fix integer overflow.
Reported as

  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=3510
2017-09-28 14:21:34 +02:00
Ewald Hew dd40d10e81 Fix compiler warning.
* src/psaux/pshints.c (cf2_hintmap_dump): Add switch for tracing code.
2017-09-28 10:49:38 +08:00
Werner Lemberg 12ae57d992 Copyright notices, formatting, whitespace, minor doc fixes. 2017-09-26 12:53:41 +02:00
Werner Lemberg 4cdbac05b9 Fix compiler warnings.
* src/psaux/psft.c (cf2_initLocalRegionBuffer): Remove redundant
test.

* src/psaux/psintrp.c (cf2_interpT2CharString)
<cf2_escCALLOTHERSUBR>: Add casts.

* src/psaux/psobjs.c (ps_decoder_init): Add cast.
2017-09-25 09:26:59 +02:00
Ewald Hew a1a6a1f679 Minor fixes.
* include/freetype/internal/psaux.h, src/psaux/psobjs.{c,h}:
Rearrange `ps_builder_init' arguments to conventional order.

* src/psaux/psft.c (cf2_decoder_parse_charstrings): Add a check and
notice for `SubFont' in Type 1 mode.
2017-09-25 09:26:59 +02:00
Ewald Hew 6e7da50bc3 Documentation fixes. 2017-09-25 09:26:59 +02:00
Ewald Hew ebb1735aa7 Move `psdecode' into `psobjs'.
As the former only contains a single procedure, move it into
`psobjs' for simplicity.  Also change the parameter order to the
conventional one.

* src/psaux/psdecode.c (ps_decoder_init): Moved to...
* src/psaux/psobjs.c: ...Here.
* src/psaux/psdecode.h, src/psaux/psobjs.h: Ditto.

* include/freetype/internal/psaux.h (PSAux_ServiceRec): Update
`ps_decoder_init' function signature.

* src/cff/cffgload.c, src/cid/cidgload.c, src/type1/t1gload.c:
Update calls.

* src/psaux/psaux.c, src/psaux/psauxmod.c: Update includes.

* src/psaux/Jamfile (_sources), src/psaux/rules.mk (PSAUX_DRV_SRC):
Update file references.
2017-09-25 09:26:59 +02:00
Ewald Hew d52dd7f31d Fix Type 1 hinting.
Type 1 hinting breaks sometimes when mid-charstring hints should
have been in the initial hintmap.  This fix adds a preprocessing
pass that reads all hints and builds the correct initial hintmap
first, before proceeding to build the glyph outline.

* src/psaux/psintrp.c (cf2_interpT2CharString): New
`initial_map_ready' boolean flag.
Ignore outline commands and hint changes on first pass.
<cf2_cmdENDCHAR>: Add section to build hintmap and rewind.
2017-09-25 09:26:59 +02:00
Ewald Hew 2f0e114068 Add tracing for hints.
* src/psaux/pshints.c (cf2_hintmap_dump): New function.
(cf2_hintmap_insertHint): Trace incoming and inserted hints.
(cf2_hintmap_build): Dump hintmap before and after hint adjustment.
2017-09-25 09:26:59 +02:00
Ewald Hew 999a75b6db Minor fixes.
* src/psaux/psintrp.c (cf2_interpT2CharString): Fix check for pop
results.
s/font->decoder/decoder/ where necessary.
<cf2_cmdHSTEM, cf2_cmdVSTEM, cf2_escHSTEM3, cf2_escVSTEM3>: Use
offset parameter in `cf2_doStems' instead of doing correction for
left-sidebearing.
2017-09-25 09:26:59 +02:00
Ewald Hew 93e3cffddf Change subfont synthesis for CID fonts.
Change `t1_make_subfont' to take in the Private dict record as an
argument.  This is because Type 1 and CID font records in FreeType
have this in different places.

* src/psaux/psobjs.c (t1_make_subfont): Change `T1_Face' to
`FT_Face' so that CID is also accepted.
Take `PS_Private' as an argument and let caller figure out where the
Private dict actually is.
Update references.

* include/freetype/internal/psaux.h, src/psaux/psobjs.h: Update
declaration.

* src/type1/t1gload.c (T1_Parse_Glyph_And_Get_Char_String): Update
call.
2017-09-25 09:26:59 +02:00
Ewald Hew d813b5da59 Extend Adobe interpreter (seac).
This concludes the changes needed to add Type 1 support.

* src/psaux/psintrp.c: Update includes.
(cf2_interpT2CharString) <cf2_escSEAC>: Implement this similarly to
implied seac for CFF.

* src/psaux/t1decode.c (t1_lookup_glyph_by_stdcharcode_ps): New
function to look up the glyph index.

* src/psaux/psft.c (cf2_getT1SeacComponent,
cf2_freeT1SeacComponent): New functions to get the charstrings for
seac components.

* src/psaux/t1decode.h, src/psaux/psft.h: Update declarations.
2017-09-25 09:26:59 +02:00
Ewald Hew d55a701de6 Extend Adobe interpreter (flex in callothersubr).
* src/psaux/psintrp.c (cf2_interpT2CharString)
<cf2_escCALLOTHERSUBR>: Fix Flex feature handling (OtherSubrs 0, 1,
2).
<cf2_cmdRMOVETO>: Do not actually move the `glyphPath' while doing
flex.  This is to avoid closing the current contour.
2017-09-25 09:26:59 +02:00
Ewald Hew 9668255965 Extend Adobe interpreter (callothersubr).
* src/psaux/psintrp.c (cf2_interpT2CharString)
<cf2_escCALLOTHERSUBR>: Copy code from
`t1_decoder_parse_charstrings' (in `t1decode.c').
OtherSubr 3 (change hints) should reset the hintmask, so that the
new hints are applied.
Fix function calls and stack access.
2017-09-25 09:26:59 +02:00
Ewald Hew 77c1b331f6 Extend Adobe interpreter (pop).
* src/psaux/psintrp.c (cf2_interpT2CharString): Change how unhandled
OtherSubr results are stored.  Implement the PostScript stack using
an array.
<cf2_escPOP>: Ensure that the stack is not cleared after getting
`OtherSubr' results.
Fix stack access.
2017-09-25 09:26:59 +02:00
Ewald Hew 1e4d3dc8ea Extend Adobe interpreter (callsubr).
* src/psaux/psintrp.c (cf2_interpT2CharString) <cf2_cmdCALLSUBR>:
Type 1 mode.

* src/psaux/psft.c (cf2_initLocalRegionBuffer): Add Type 1 mode.
2017-09-25 09:26:59 +02:00
Ewald Hew 4b58c518c9 Extend Adobe interpreter (div, four-byte numbers).
* src/psaux/psintrp.c (cf2_interpT2CharString) <cf2_escDIV>: Add
Type 1 mode.  Type 1 requires large integers to be followed by
`div'; cf. `Adobe Type 1 Font Format', section 6.2.
<op == 255>: Push Type 1 four-byte numbers as `Int' always.  This is
to ensure `div' and `callsubr' get values they can use.
2017-09-25 09:26:59 +02:00
Ewald Hew 81b86c459c Extend Adobe interpreter (hstem, vstem, hstem3, vstem3).
* src/psaux/psintrp.c (cf2_interpT2CharString) <cf2_cmdHSTEM,
cf2_cmdVSTEM>: Add correction for left sidebearing in Type 1 mode.
Allow adding hints mid-charstring.
<cf2_escVSTEM3, cf2_escHSTEM3>: Translate into equivalent commands
for three normal stem hints.  This requires some recalculation of
stem positions.
Correction for left sidebearing.
2017-09-25 09:26:59 +02:00
Ewald Hew e180afa951 Extend Adobe interpreter (hsbw, sbw).
* src/psaux/psintrp.c (cf2_doStems): `hsbw' or `sbw' must be the
first operation in a Type 1 charstring.
(cf2_interpT2CharString): Remove unused variables.
<cf2_cmdHMOVETO, cf2_cmdVMOVETO, cf2_cmdRMOVETO>: `hsbw' or `sbw'
must be the first operation in a Type 1 charstring.
<cf2_cmdHSBW, cf2_escSBW>: Fix data access and add correction for
left sidebearing.
2017-09-25 09:26:59 +02:00
Ewald Hew 2f4abaec38 Extend Adobe interpreter (setcurrentpoint).
* src/psaux/psintrp.c (cf2_interpT2CharString)
<cf2_escSETCURRENTPT>: Fix stack access.
2017-09-25 09:26:59 +02:00
Ewald Hew 4ed1b98dbd Extend Adobe interpreter (closepath).
* src/psaux/psintrp.c (cf2_interpT2CharString) <c2f_cmdCLOSEPATH>:
Use the right builder function.  We can use the `haveWidth' boolean
already present, instead of implementing `parse_state'.
2017-09-25 09:26:59 +02:00
Ewald Hew 37ed70f628 Add Type 1 operations to Adobe CFF interpreter.
The following Type 1 specific ops have been added (copied from
`t1decode'):

  closepath
  vstem3
  hstem3
  seac
  sbw
  callothersubr
  pop
  setcurrentpoint
  hsbw

The following require a Type 1 mode, because of differences in
specification:

  hstem
  vstem
  vmoveto
  callsubr
  div
  rmoveto
  hmoveto
  Numbers

The subsequent commits will implement these changes and adapt
accesses of data and objects to the new interpreter.

NOTE: Will not compile in the meantime!

* src/psaux/psintrp.c: Add opcodes to enum.
(cf2_interpT2CharString): Copy relevant code over from
`t1_decoder_parse_charstrings' (in `t1decode.c').
2017-09-25 09:26:59 +02:00
Ewald Hew 6eb03f8f5a Add missing objects (2/2).
Synthesize a `SubFont' object for Type 1 fonts.  This is used in the
interpreter to access Private dict data, which are stored in
different places for Type 1 and CFF.  This allows the same data to
be used in either mode.

* src/psaux/psobjs.c (t1_make_subfont): New procedure to copy
required values to a dummy `CFF_SubFont' object.  This is similar to
`cff_make_private_dict'.
* src/psaux/psobjs.h: Add the new declaration.

* include/freetype/internal/psaux.h, src/psaux/psauxmod.c: Ditto.
Add this to the PSAux Service for future use with CID fonts.

* src/type1/t1gload.c: Include FT_INTERNAL_CFF_TYPES_H.
(T1_Parse_Glyph_And_Get_Char_String): Add the call.
2017-09-25 09:26:59 +02:00
Ewald Hew cb3f4c610d Add missing objects for Type 1 (1/2).
Move `CF2_Font' instance to `PS_Decoder'.  This is the context for
the interpreter and since it is currently stored in `CFF_Font', is
unavailable in Type 1 mode.

* include/freetype/internal/psaux.h (T1_Decoder, PS_Decoder): New
`cf2_instance' field.

* src/psaux/psdecode.c (ps_decoder_init): Copy `cf2_instance' to
`PS_Decoder'.

* src/psaux/t1decode.c (t1_decoder_done): Add finalization code.

* src/psaux/psft.c (cf2_decoder_parse_charstrings): Update accesses.
2017-09-25 09:26:59 +02:00
Ewald Hew 7e185dcd79 Allow `type1' module to use the Adobe engine.
Add the callback and some conditionals to switch between the two
engines.

* include/freetype/internal/psaux.h (T1_Decoder_FuncsRec): Change
function declarations.
* src/psaux/psauxmod.c (T1_Decoder_FuncsRec): Register the
callbacks.

* src/psaux/psobjs.c (ps_builder_add_point): Add conditionals for
number conversion.

* src/type1/t1gload.c (T1_Parse_Glyph_And_Get_Char_String): Add code
to choose which renderer to use.

* src/cid/cidgload.c (cid_load_glyph): Update call.
* src/base/ftobjs.c, src/psaux/psobjs.c, src/type1/t1gload.c: Update
includes.
2017-09-25 09:26:59 +02:00
Ewald Hew 645d1b86ad Move and rename `CFF_Driver'.
This is so that we can use the same hinting engine parameters for
Type 1.

* include/freetype/internal/cffotypes.h (CFF_Driver): Rename and
move to...
* include/freetype/internal/psaux.h (PS_Driver): ...here.

* src/cff/cffdrivr.c, src/cff/cffgload.c, src/cff/cffload.c,
src/cff/cffobjs.c, src/cff/cffobjs.h, src/psaux/psft.c,
src/psaux/psobjs.c: Update references.
2017-09-25 09:26:59 +02:00
Ewald Hew d23affe1ef Reorganize object fields.
Make some fields more generic, so that we can access them the same
way regardless of Type 1 or CFF.

* include/freetype/internal/psaux.h (PS_Builder): Change `TT_Face'
to `FT_Face'.
Remove unused fields.

* src/psaux/psft.c: Update all accesses of `PS_Builder.face'.
Add some asserts to guard against casting `T1_Face' as `TT_Face'.

* src/type1/t1objs.h (T1_GlyphSlot): Reorder fields to follow
`CFF_GlyphSlot', so that we can pretend they are the same in the
interpreter.

* src/psaux/psobjs.c (ps_builder_init, ps_builder_add_point):
Updated with above changes.
2017-09-25 09:26:59 +02:00
Ewald Hew 9428ee42c0 Prepare for Type 1 mode.
Add some checks for Type 1 data passing through.

* src/psaux/psfont.h (CF2_Font): Add `isT1' flag.
* src/psaux/psfont.c (cf2_font_setup): Skip the variations and blend
code which is not applicable for Type 1.

* src/psaux/psft.c (cf2_decoder_parse_charstrings): Avoid accessing
`decoder->cff' in Type 1 mode.
Copy `is_t1' flag to `CF2_Font'.
2017-09-25 09:26:59 +02:00
Ewald Hew 0589e3c012 Use the new objects.
* include/freetype/internal/psaux.h, src/psaux/psauxmod.c: Fix
switching between new and old engines.

* src/cff/cffgload.c, src/cff/cffparse.c: Update calls.

* src/psaux/psblues.c, src/psaux/psfont.c, src/psaux/psfont.h,
src/psaux/psft.c, src/psaux/psft.h, src/psaux/psintrp.c: Update all
to use new objects.
2017-09-25 09:26:59 +02:00
Ewald Hew 43c015823f Objects for new interpreter (part 2).
Make the new objects copy over values.  They are essentially wrapper
types for the different decoders/builders.

* include/freetype/internal/psaux.h: Update declarations.
(PS_Builder): Add `is_t1' flag.
(PS_Decoder_{Get,Free}_Glyph_Callback): Renamed to...
(CFF_Decoder_{Get,Free}_Glyph_Callback: ... this.
(PS_Decoder): Updated.
Add `t1_parse_callback' member.
(PSAux_ServiceRec): Add `ps_decoder_init' member.

* src/psaux/psdecode.h, src/psaux/psobjs.h: Update declarations.

* src/psaux/psdecode.c, src/psaux/psobjs.c: Implement copy with two
modes.

* src/psaux/psauxmod.c: Add builder and decoder functions to `PSAux'
service.
2017-09-25 09:26:59 +02:00
Ewald Hew eba54c28dc Add objects for new interpreter.
Introduce `PS_Decoder' and `PS_Builder' which include all fields
from either Type 1 or CFF decoders/builders.

* include/freetype/internal/psaux.h (PS_Builder, PS_Decoder): New
structs.

* src/psaux/psobjs.c, src/psaux/psobjs.h: Add `PS_Builder'
functions.

* src/psaux/psdecode.c, src/psaux/psdecode.h: New files to hold
`PS_Decoder' initialization functions.

* src/psaux/psaux.c, src/psaux/Jamfile (_sources),
src/psaux/rules.mk (PSAUX_DRV_SRC): Updated.
2017-09-25 09:26:59 +02:00
Ewald Hew 766f529a31 Rename files.
Replace the `cf2' file name prefix with `ps' as the Adobe engine
will be used for both PostScript Types 1 and 2 (CFF) instead of just
CFF.

s/cf2/ps/ for all following.

* src/psaux/cf2*: Rename files.
* src/psaux/*: Update includes.

* src/psaux/Jamfile (_sources), src/psaux/rules.mk (PSAUX_DRC_SRC,
PSAUX_DRV_H): Update file references.
2017-09-25 09:26:59 +02:00
Ewald Hew 8a1b5c0c6d Minor fix.
Use `MultiMasters' service in `psaux' instead of a call to `cff'.
The project builds if CFF_CONFIG_OPTION_OLD_ENGINE is not defined.

* src/psaux/cf2ft.c: Update includes.
(cf2_getNormalizedVector): Use `mm->get_var_blend' instead of
`cff_get_var_blend'.
2017-09-25 09:26:59 +02:00
Ewald Hew b624868b8e Move `cff_random' into `psaux' service.
NOTE: Does not compile!

Minor fix to allow both `cff' and `psaux' to use `cff_random'.

* src/cff/cffload.c (cff_random): Move to...
* src/psaux/psobjs.c: Here.
* src/cff/cffload.h: Move corresponding declaration to
`src/psaux/psobjs.h'.

* include/freetype/internal/psaux.h (PSAux_ServiceRec): Register the
function here...
* src/psaux/psauxmod.c: And here.

* src/cff/cffload.c, src/psaux/cf2intrp.c: Update code.
2017-09-25 09:26:59 +02:00
Ewald Hew df11628b76 Move struct declarations to `freetype/internal'.
NOTE: Does not compile!

This is so that the CFF functions moved to `psaux' can access the
same structs that they need.

* src/cff/cfftypes.h: Moved to...
* include/freetype/internal/cfftypes.h: ...Here.

* src/cff/cffobjs.h: Moved the struct declarations to...
* include/freetype/internal/cffotypes.h: ... this new file.

* include/freetype/internal/internal.h (FT_INTERNAL_CFF_TYPES_H,
FT_INTERNAL_CFF_OBJECT_TYPES_H): New macros.

* src/cff/cffcmap.h, src/cff/cffdrivr.c, src/cff/cffgload.c,
src/cff/cffgload.h, src/cff/cffload.h, src/cff/cffobjs.c,
src/cff/cffobjs.h, src/cff/cffparse.h, src/psaux/psobjs.h,
include/freetype/internal/psaux.h,
include/freetype/internal/services/svcfftl.h: Update includes.

* src/cff/rules.mk (CFF_DRV_H): Updated.
2017-09-25 09:26:59 +02:00
Ewald Hew edacde60e3 Add new service for inter-module calls.
NOTE: Does not compile!

This is to allow CFF functions moved to `psaux' to call functions
declared in `src/cff/cffload.h'.

* include/freetype/internal/services/svcfftl.h: New file, setting up
a `CFFLoad' service.

* include/freetype/internal/ftserv.h (FT_DEFINE_SERVICEDESCREC10,
FT_DEFINE_SERVICEDESCREC): New macros.
(FT_SERVICE_CFF_TABLE_LOAD_H): New macro.

* src/cff/cffdrivr.c, src/cff/cffpic.h: Register the new service.

* src/cff/cfftypes.h (CFF_FontRec), src/psaux/cf2font.h
(CF2_FontRec): Add service interface.

* src/cff/cffobjs.c, src/psaux/cf2font.c, src/psaux/cf2ft.c,
src/psaux/cf2intrp.c, src/psaux/cffdecode.c: Use the new service.
2017-09-25 09:26:59 +02:00
Ewald Hew 9578e07a83 Add callbacks for inter-module calls.
NOTE: Does not compile!

* include/freetype/internal/psaux.h: Add function pointer
declarations.

* src/psaux/cffdecode.c (cff_decoder_init): Update to take in
callbacks.
* src/psaux/cffdecode.h: Ditto.

* src/cff/cffgload.c (cff_compute_max_advance, cff_slot_load):
Update calls to pass in callbacks.
* src/psaux/cf2ft.c, src/psaux/cffdecode.c: Use them.
2017-09-25 09:26:59 +02:00
Ewald Hew 1487be586e Create new `PSAux' service interface entries.
NOTE: Does not compile!

* include/freetype/internal/psaux.h: Include
FT_INTERNAL_TRUETYPE_TYPES_H.
(CFF_Builder_FuncsRec, CFF_Decocer_FuncsRec): New function tables.
(CFF_Builder): Updated.
Fix for forward declaration.
(PSAux_ServiceRec): New field `cff_decoder_funcs'.

* src/psaux/psauxmod.c (cff_builder_funcs, cff_decoder_funcs): New
function tables.
(PSAux_Interface): Updated.

* include/freetype/internal/tttypes.h (TT_FaceRec): Add `psaux'
service interface.

* src/cff/cffgload.c, src/cff/cffobjs.c, src/cff/cffparse.c: Update
function calls to use psaux service.
2017-09-25 09:26:59 +02:00
Ewald Hew 816c9c1f83 Move CFF builder components into `psaux' module.
NOTE: Does not compile!

* src/cff/cffgload.c
(cff_builder_{init,done,add_point,add_point1,add_contour,start_point,close_contour},
cff_check_points): Move to...
* src/psaux/psobjs.c: Here.

* src/cff/cffgload.h: Move corresponding declarations to
`src/psaux/psobjs.h'.

* src/cff/cffgload.h (CFF_Builder): Move struct declaration to...
* include/freetype/internal/psaux.h: Here.
2017-09-25 09:26:59 +02:00
Ewald Hew 705bbe7c7b Move CFF decoder components into `psaux' module.
NOTE: Does not compile!

* src/cff/cffgload.c (CFF_Operator,
CFF_COUNT_{CHECK_WIDTH,EXACT,CLEAR_STACK}, cff_argument_counts,
cff_operator_seac, cff_compute_bias,
cff_lookup_glyph_by_stdcharcode,
cff_decoder_{parse_charstrings,init,prepare}): Move to...
* src/psaux/cffdecode.c: This new file.

* src/cff/cffgload.h: Move corresponding declarations to...
* src/psaux/cffdecode.h: This new file.

* src/cff/cffgload.h (CFF_MAX_{OPERANDS,SUBRS_CALLS,TRANS_ELEMENTS},
CFF_Decoder_Zone, CFF_Decoder): Move declarations to...
* include/freetype/internal/psaux.h: Here.

* src/psaux/cf2ft.h: Update include.

* src/psaux/psaux.c, src/psaux/rules.mk (PSAUX_DRV_SRC): Update with
the new file.
2017-09-25 09:26:59 +02:00
Ewald Hew 62f095f046 [psaux, cff] Move Adobe's engine components into `psaux' module.
This is the first patch of a sequence to move the Type 2 charstring
processing capability from the `cff' module to the `psaux' module.

NOTE: Does not compile!

* src/cff/cf2*: Move these files to...
* src/psaux/cf2*: Here.

* src/cff/Jamfile (_sources), src/cff/rules.mk (CFF_DRV_SRC,
CFF_DRV_H), src/cff/cff.c, src/cff/cffgload.c: Remove file
references.

* src/psaux/Jamfile (_sources), src/psaux/rules.mk, src/psaux/psaux.c
(PSAUX_DRV_SRC, PSAUX_DRV_H): Add file references.
2017-09-25 09:25:55 +02:00
Werner Lemberg dcd8de272f */*: Remove `OVERFLOW_' prefix.
This increases readability.
2017-06-09 11:21:58 +02:00
Werner Lemberg 4a1f1a6d2a [psaux] 32bit integer overflow tun-time errors (#46149).
* src/psaux/t1decode.c (t1_decoder_parse_charstrings): Use
OVERFLOW_ADD_LONG and OVERFLOW_SUB_LONG where appropriate.
2017-06-01 13:15:54 +02:00
Werner Lemberg 0e7b9f864f [psaux] Correctly handle sequences of multiple number signs.
* src/psaux/psconv.c (PS_Conv_Strtol, PS_Conv_ToFixed): Return zero
if we encounter more than a single sign.
2017-05-30 22:22:19 +02:00
Werner Lemberg 5412d8869b Introduce `FT_Size_InternalRec' structure.
We are going to extend this later on.

* include/freetype/internal/ftobjs.h (FT_Size_InternalRec): New
structure with a single field `module_data'.

* src/base/ftobjs.c (FT_New_Size): Allocate `internal' field of
`FT_Size' structure.

* src/cff/cffgload.c (cff_builder_init, cff_decoder_prepare): Use
`size->internal->module_data' instead of `size->internal'.

* src/cff/cffobjs.c (cff_size_done): Deallocate `module_data'.
(cff_size_init, cff_size_select, cff_size_request): Use
`size->internal->module_data' instead of `size->internal'.

* src/cif/cidobjs.c (cid_size_done, cid_size_init,
cid_size_request): Use `size->internal->module_data' instead of
`size->internal'.

* src/psaux/psobjs.c (t1_builder_ini): Use
`size->internal->module_data' instead of `size->internal'.

* src/type1/t1objs.c (T1_Size_Done, T1_Size_Init, T1_Size_Request):
Use `size->internal->module_data' instead of `size->internal'.
2017-04-22 12:48:50 +02:00
Werner Lemberg 3774fc08b5 * src/psaux/psobjs.c (t1_builder_close_contour): Add safety guard.
Reported as

  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=941
2017-03-26 08:32:09 +02:00
Werner Lemberg f958c48ee4 [psaux] Better protect `flex' handling.
Reported as

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

* src/psaux/t1decode.c (t1_decoder_parse_charstrings)
<callothersubr>: Since there is not a single flex operator but a
series of subroutine calls, malformed fonts can call arbitrary other
operators after the start of a flex, possibly adding points.  For
this reason we have to check the available number of points before
inserting a point.
2017-03-24 09:15:10 +01:00
Werner Lemberg 9931175dcc Improve `make multi'.
* src/autofit/aflatin2.c: Guard file with FT_OPTION_AUTOFIT2.

* src/base/ftmac.c: Guard more parts of the file with FT_MACINTOSH.

* src/psaux/afmparse.c: Guard file with T1_CONFIG_OPTION_NO_AFM.

* src/sfnt/pngshim.c: Guard file with
TT_CONFIG_OPTION_EMBEDDED_BITMAPS also.

* src/sfnt/ttbdf.c: Avoid empty source file.
* src/sfnt/ttpost.c: Guard file with
TT_CONFIG_OPTION_POSTSCRIPT_NAMES.
* src/sfnt/ttsbit.c: Guard file with
TT_CONFIG_OPTION_EMBEDDED_BITMAPS.

* src/truetype/ttgxvar.c, src/truetype/ttinterp.c: Avoid empty
source file.

* src/truetype/ttsubpix.c: Guard file with
TT_USE_BYTECODE_INTERPRETER also.

* src/type1/t1afm.c: Guard file with T1_CONFIG_OPTION_NO_AFM.

* src/autofit/autofit.c, src/base/ftbase.c, src/cache/ftcache.c,
src/cff/cff.c, src/cid/type1cid.c, src/gxvalid/gxvalid.c,
src/pcf/pcf.c, src/pfr/pfr.c, src/psaux/psaux.c,
src/pshinter/pshinter.c, src/psnames/psnames.c, src/raster/raster.c,
src/sfnt/sfnt.c, src/smooth/smooth.c, src/truetype/truetype.c,
src/type1/type1.c, src/type42/type42.c: Remove conditionals; sort
entries.
2017-03-18 07:06:49 +01:00
Werner Lemberg 563ae78022 Update copyright year. 2017-01-04 20:16:34 +01:00
Werner Lemberg 248eaa4f60 Various fixes for clang's undefined behaviour sanitizer.
* src/cff/cffload.c (FT_fdot14ToFixed): Fix casting.
(cff_blend_doBlend): Don't left-shift negative numbers.
Handle 5-byte numbers byte by byte to avoid alignment issues.

* src/cff/cffparse.c (cff_parse): Handle 5-byte numbers byte by byte
to avoid alignment issues.

* src/cid/cidload (cid_read_subrs): Do nothing if we don't have any
subrs.

* src/psaux/t1decode.c (t1_decode_parse_charstring): Fix tracing.

* src/tools/glnames.py (main): Put `DEFINE_PSTABLES' guard around
definition of `ft_get_adobe_glyph_index'.

* src/psnames/pstables.h: Regenerated.

* src/psnames/psmodule.c: Inlude `pstables.h' twice to get both
declaration and definition.

* src/truetype/ttgxvar.c (FT_fdot14ToFixed, FT_intToFixed): Fix
casting.
2017-01-03 00:27:07 +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 37c72f66a5 Minor formatting. 2016-12-25 22:55:25 +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 9c54d1246a [psaux] Fix handling of invalid flex subrs.
Problem reported as

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

* src/psaux/t1decode.c (t1_decoder_parse_charstrings)
<op_callothersubr>: Set `flex_state' after error checking.
2016-10-11 08:57:55 +02:00
Werner Lemberg 45cad2e5e1 More FT_ZERO usage.
* src/gxvalid/gxvcommn.c (gxv_ClassTable_validate):
s/ft_memset/FT_MEM_ZERO/.

* src/psaux/t1decode.c (t1_decoder_parse_charstrings):
s/ft_memset/FT_ARRAY_ZERO/.

* src/raster/ftraster.c (FT_ZERO): Define.
(ft_black_new): Use it.
* src/raster/ftrend1.c (ft_raster1_get_cbox):
s/FT_MEM_ZERO/FT_ZERO/.

* src/smooth/ftgrays.c (FT_ZERO): Define.
(gray_raster_new): Use it.
* src/smooth/ftsmooth.c (ft_smooth_get_cbox):
s/FT_MEM_ZERO/FT_ZERO/.
2016-09-28 19:10:52 +02:00
Werner Lemberg 2ecf89b481 */*: s/FT_MEM_ZERO/FT_ZERO/ where appropriate. 2016-09-28 19:06:21 +02:00
Werner Lemberg c95b7652d8 s/0/NULL/ for function pointers; comments, formatting. 2016-09-17 17:12:50 +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 9adeab6452 Update copyright year. 2016-01-13 11:54:10 +01:00
Werner Lemberg 37412ff9f4 Don't use macro names that contain `__' [1/2].
Such macro names are reserved for both C and C++.

*/*: Replace macros of the form `__XXX_H__' with `XXX_H_'.
2016-01-12 21:37:13 +01:00
Werner Lemberg bd4b8976a3 [type1, psaux] Handle large values of num_subrs correctly (#46692).
We now use a hash to map from subr indices to array elements holding
the subroutines, if necessary.

* include/freetype/internal/t1types.h: Include FT_INTERNAL_HASH_H.
(T1_FontRec): Add `subrs_hash' field.

* include/freetype/internal/psaux.h: Include FT_INTERNAL_HASH_H.
(T1_DecoderRec): Add `subrs_hash' field.

* src/type1/t1load.h (T1_LoaderRec): Add `subrs_hash' field.

* src/type1/t1driver.c: Include FT_INTERNAL_HASH_H.
(t1_ps_get_font_value) [PS_DICT_SUBR]: Look up hash if necessary.

* src/type1/t1load.c: Include FT_INTERNAL_HASH_H.
(parse_subrs): Use hash for subr indices that exceed the allocated
number of subr slots.
(t1_init_loader): Remove unnecessary code.
(t1_done_loader, T1_Open_Face): Updated.

* src/type1/t1gload.c (T1_Compute_Max_Advance, T1_Get_Advances,
T1_Load_Glyph): Updated.

* src/type1/t1objs.c (T1_Face_Done): Updated.

* src/psaux/t1decode.c: Include FT_INTERNAL_HASH_H.
(t1_decoder_parse_charstrings) [op_callsubr]: Look up hash if
necessary.

* src/cid/cidgload.c (cid_load_glyph): Updated.
2015-12-20 19:36:04 +01:00
Werner Lemberg 24cee3a8a3 [psaux] Fix tracing of negative numbers.
Due to incorrect casting negative numbers were shown as very large
(positive) integers on 64bit systems.

* src/psaux/t1decode.c (t1_decoder_parse_charstrings) <op_none>:
Use division instead of shift.
2015-10-19 23:00:28 +02:00
Werner Lemberg 8edfcbed53 [psaux] Fix heap buffer overflow (#46221).
* src/psaux/t1decode.c (t1_decoder_parse_charstring) <operator 12>:
Fix limit check.
2015-10-17 08:11:16 +02:00
Werner Lemberg 4942c2bb72 [psaux] Fix memory leak (#45986).
* src/psaux/psobjs.c (ps_parser_load_field) <T1_FIELD_TYPE_MM_BBOX>:
Free `temp' in case of error.
2015-09-17 17:56:53 +02:00
Werner Lemberg 7d364b7e51 [psaux] Improve tracing message.
* src/psaux/psobjs.c (ps_parser_load_field) <T1_FIELD_TYPE_MM_BBOX>:
Handle plural correctly.
2015-09-17 16:31:58 +02:00
Werner Lemberg db5a4a9ae7 [psaux] Fix potential buffer overflow (#45922).
* src/psaux/psobjs.c (ps_parser_skip_PS_token): If a token is
enclosed in balanced expressions, ensure that the cursor position
doesn't get larger than the current limit.
2015-09-12 08:32:55 +02:00
Werner Lemberg 31d97df99f Make Jam support work again.
This is just very basic stuff and just a little bit tested on
GNU/Linux only.  I won't delve into this since I'm not a Jam user.

* Jamfile: Call `HDRMACRO' for `ftserv.h' also.
(DEFINES): Replace with...
(CCFLAGS): ... this.

* src/Jamfile: Don't call `HDRMACRO' for `internal.h'; this is
already handled in the top-level Jamfile.

* src/autofit/Jamfile (DEFINES): Replace with...
(CCFLAGS): ... this.
(_sources): Add missing files.

* src/cache/Jamfile: Don't call `HDRMACRO' for `ftcache.h'; it no
longer contains macro header definitions.

* src/base/Jamfile, src/cff/Jamfile, src/sfnt/Jamfile,
src/truetype/Jamfile (_sources): Add missing files.
2015-06-21 19:12:12 +02:00
Alexei Podtelezhnikov eabc8d72e0 [psaux,psnames,type1,type42] NULL. 2015-04-12 23:16:48 -04:00
Werner Lemberg 851e815127 Various compiler warning fixes for `make multi'.
* src/autofit/afcjk.c (af_cjk_hints_compute_blue_edges),
src/autofit/aflatin.c (af_latin_hint_compute_blue_edges,
af_latin_hint_edges), src/autofit/aflatin2.c
(af_latin2_hints_compute_blue_edges, af_latin2_hint_edges): Declare
as `static'.

* src/cache/ftccmap.c (FTC_CMAP_QUERY_HASH, FTC_CMAP_NODE_HASH):
Removed.  Unused.
* src/cache/ftcimage.c: Include FT_INTERNAL_OBJECTS_H.
* src/cache/ftcmanag.c (FTC_LRU_GET_MANAGER): Removed.  Unused.

* src/cff/cf2intrp.c: Include `cf2intrp.h'.
* src/cff/cffdrivr.c (PAIR_TAG): Removed.  Unused.

* src/gzip/ftgzip.c (NO_DUMMY_DECL): Removed.  Unused.

* src/psaux/afmparse.c (afm_parser_read_int): Declare as `static'.

* src/pshinter/pshalgo.c (STRONGER, PSH_ZONE_MIN, PSH_ZONE_MAX):
Removed.  Unused.

* src/raster/ftraster.c (Render_Glyph): Declare as `static'.

* src/sfnt/ttpost.c (load_format_20): Fix signedness warning.

* src/truetype/ttdriver.c (PAIR_TAG): Removed.  Unused.
* src/truetype/ttsubpix.c (is_member_of_family_class,
is_member_of_style_class): Declare as `static'.

* src/type1/t1gload.c (T1_Parse_Glyph_And_Get_Char_String): Declare
as `static'.
* src/type1/t1load.c (mm_axis_unmap, mm_weights_unmap): Declare as
`static'.
(T1_FIELD_COUNT): Removed.  Unused.
* src/type1/t1parse.h (T1_Done_Table): Removed.  Unused.

* src/type42/t42parse.c (T1_Done_Table): Removed.  Unused.
2015-03-01 19:27:09 +01:00
Werner Lemberg 04c223703a [psaux] Signedness fixes.
* include/internal/psaux.h, src/psaux/afmparse.c,
src/psaux/afmparse.h, src/psaux/psconv.c, src/psaux/psobjs.c,
src/psaux/t1cmap.c, src/psaux/t1decode.c: Apply.
2015-02-25 11:20:20 +01:00
Werner Lemberg 3b5f332c5b [type1] Fix signedness issues.
* include/internal/psaux.h, include/internal/t1types.h,
src/psaux/psobjs.c, src/psaux/psobjs.h, src/psaux/t1decode.c,
src/type1/t1gload.c, src/type1/t1load.c, src/type1/t1parse.c: Apply.
2015-02-18 11:45:22 +01:00
Werner Lemberg 272e3cd077 [psaux, type1] Fix minor AFM issues.
* include/internal/t1types.h (AFM_KernPairRec): Make indices
unsigned.
Update users.
(AFM_FontInfoRec): Make element counters unsigned.
Update users.
* src/psaux/afmparse.h (AFM_ValueRec): Add union member for unsigned
int.

* src/psaux/afmparse.c (afm_parse_track_kern, afm_parse_kern_pairs):
Reject negative values for number of kerning elements.

* src/type1/t1afm.c, src/tools/test_afm.c: Updated.
2015-02-18 11:38:46 +01:00
Werner Lemberg 6bd7d28fc7 Don't use `FT_PtrDist' for lengths.
Use FT_UInt instead.

* include/internal/psaux.h (PS_Table_FuncsRec, PS_TableRec,
T1_DecoderRec): Do it.

* include/internal/t1types.h (T1_FontRec): Ditto.

* src/cid/cidload.c (cid_parse_dict): Updated.
* src/pfr/pfrload.c (pfr_extra_item_load_font_id): Ditto.
* src/psaux/psobjs.c (ps_table_add), src/psaux/psobjs.h: Ditto.
* src/type1/t1load.c (parse_blend_axis_types, parse_encoding,
parse_chharstrings, parse_dict): Ditto.
* src/type42/t42parse.c (t42_parse_encoding, t42_parse_charstrings,
t42_parse_dict): Ditto.
2015-02-18 09:22:06 +01:00
Werner Lemberg f57fc59e01 Run `src/tools/update-copyright'. 2015-01-17 20:41:43 +01:00
Werner Lemberg 36d03c9f58 Fix Savannah bug #43976.
Assure that FreeType's internal include directories are found before
`CPPFLAGS' (which might be set by the user in the environment), and
`CPPFLAGS' before `CFLAGS'.

* builds/freetype.mk (FT_CFLAGS): Don't add `INCLUDE_FLAGS'.
(FT_COMPILE): Make this a special variable for compiling only the
files handled in `freetype.mk'.
(.c.$O): Removed, unused.

* src/*/rules.mk (*_COMPILE): Fix order of include directories.
2015-01-12 11:26:30 +01:00
Werner Lemberg 0098d5502d Uppercase all hex digits for orthogonality. 2014-12-07 11:03:57 +01:00
Werner Lemberg 6689a009ce [Savannah bug #43682] Properly handle missing return errors.
The functions in this patch *do* return non-trivial errors that must
be taken care of.

* src/autofit/afloader.c (af_loader_load_g), src/base/ftobjs.c
(FT_Render_Glyph_Internal), src/base/ftoutln.c (FT_Outline_Render),
src/cff/cffgload.c (cff_decoder_parse_charstrings) <cff_op_endchar>,
src/psaux/psobjs.c (ps_parser_load_field_table), src/psaux/t1decode
(t1_decoder_parse_charstrings) <op_endchar>, src/truetype/ttgload.c
(load_truetype_glyph <subglyph loop>, tt_loader_init,
TT_Load_Glyph), src/truetype/ttgxvar.c (TT_Set_MM_Blend),
src/truetype/ttobjs.c (tt_size_run_fpgm, tt_size_run_prep): Do it.
2014-11-25 08:53:09 +01:00
Jarkko Pöyry 96341dc378 [cff, pfr, psaux, winfonts] Fix Savannah bug #43676.
Don't cast cmap init function pointers to an incompatible type.

Without this patch, the number of parameters between declaration and
the real signature differs.  Calling such a function results in
undefined behavior.

  ISO/IEC 9899:TC3 (Committee Draft September 7, 2007)
    6.5.2.2 Function calls
      9 If the function is defined with a type that is not
        compatible with the type (of the expression) pointed to by
        the expression that denotes the called function, the
        behavior is undefined.

On certain platforms (c -> js with emscripten) this causes
termination of execution or invalid calls because in the emscripten
implementation, function pointers of different types are stored in
different pointer arrays.  Incorrect pointer type here results in
indexing of an incorrect array.

* src/cff/cffcmap.c (cff_cmap_encoding_init, cff_cmap_unicode_init),
src/pfr/pfrcmap.c (pfr_cmap_init), src/psaux/t1cmap.c
t1_cmap_standard_init, t1_cmap_expert_init, t1_cmap_custom_init,
t1_cmap_unicode_init), src/winfonts/winfnt.c (fnt_cmap_init): Fix
signature.
2014-11-24 09:53:07 +01:00
Alexei Podtelezhnikov bc12d9e9ac Fix Savannah bug #43153.
* src/psaux/psconv.c (PS_Conv_ToFixed): Add protection against
overflow in `divider'.
2014-09-08 21:27:43 -04:00
Werner Lemberg 8b281f83e8 Fix Savannah bug #41309.
* src/type1/t1load.c (t1_parse_font_matrix): Properly handle result
of `T1_ToFixedArray'.

* src/cid/cidload.c (cid_parse_font_matrix): Synchronize with
`t1_parse_font_matrix'.

* src/type42/t42parse.c (t42_parse_font_matrix): Synchronize with
`t1_parse_font_matrix'.
(t42_parse_encoding): Synchronize with `t1_parse_encoding'.

* src/psaux/psobjs.c (ps_parser_load_field) <T1_FIELD_TYPE_BBOX>,
<T1_FIELD_TYPE_MMOX>: Properly handle result of `ps_tofixedarray'.
2014-01-23 08:14:53 +01:00
Werner Lemberg badf317840 Next round of compiler fixes.
* builds/win32/ftdebug.c, builds/wince/ftdebug.c (ft_debug_init):
Add proper cast.

* include/freetype/internal/ftserv.h (FT_SERVICE_UNAVAILABLE): Fix
cast.
* include/freetype/internal/ftstream.h: Decorate stream and frame
macros with `FT_Long' and `FT_ULong' as appropriate.

* src/base/ftrfork.c (raccess_guess_darwin_hfsplus,
raccess_guess_darwin_newvfs): Use cast.

* src/bdf/bdflib.c (_bdf_set_default_spacing): Use cast.

* src/cache/ftcmanag.c (FTC_Manager_Check): Fix cast.
* src/cache/ftcmanag.h (FTC_ManagerRec): Ditto.

* src/cff/cf2arrst.c (cf2_arrstack_setNum_Elements): Use cast.
* src/cff/cf2ft.c (cf2_freeSeacComponent): Ditto.
* src/cff/cffobjs.c (remove_subset_prefix, remove_style): Ditto.

* src/cid/cidparse.c (cid_parser_new): Use cast.

* src/pcf/pcfdrivr.c (PCF_Glyph_Load): Use cast.

* src/psaux/psobjs.c (reallocate_t1_table): Fix argument type.

* src/raster/ftraster.c (ft_black_reset): Use cast.

* src/truetype/ttgxvar.c (FT_Stream_FTell): Use cast.
(ALL_POINTS): Fix cast.

* src/type1/t1driver.c (t1_ps_get_font_value): Add casts.
* src/type1/t1parse.c (T1_Get_Private_Dict): Add cast.
2013-06-06 09:16:38 +02:00
Werner Lemberg dc624ca4dc Apply fixes for cppcheck nitpicks.
http://cppcheck.sourceforge.net/

Note that the current version heavily chokes on FreeType, delivering
even wrong results.  I will report those issues to the cppcheck team
so that a newer version gives improved results hopefully.

*/* Improve variable scopes.
*/* Remove redundant initializations which get overwritten.

* src/base/ftmac.c ,builds/mac/ftmac.c (count_faces_scalable):
Remove unused variable.

* src/base/ftdbgmem.c (ft_mem_table_destroy): `table' can't be zero.

* src/gxvalid/gxvkern.c (gxv_kern_subtable_fmt1_entry_validate):
Remove functionless code.

* src/tools/ftrandom.c (main): Fix memory leak.
2013-06-04 10:30:48 +02:00
Werner Lemberg e6e8362728 Fix clang fixes.
* src/base/fttrigon.c (ft_trig_prenorm, FT_Vector_Rotate): Use
correct types.

* src/cff/cf2intrp.c (cf2_interpT2CharString) <default>: Force
unsigned for computations.
* src/cff/cffgload.c (cff_decoder_parse_charstrings): Ditto.
* src/cff/cffparse.c (cff_parse_integer): Ditto.

* src/psaux/t1decode.c (t1_decoder_parse_charstrings): Ditto.
2013-05-04 18:57:56 +02:00
Werner Lemberg 94152819b0 More fixes for clang's `sanitize' feature.
* src/base/ftcalc.c (FT_DivFix): Use unsigned values for
computations which use the left shift operator and convert to signed
as the last step.
* src/base/fttrigon.c (ft_trig_prenorm, FT_Vector_Rotate,
FT_Vector_Length, FT_Vector_Polarize): Ditto.

* src/cff/cffgload.c (cff_decoder_parse_charstrings): Simplify.
* src/cff/cffload.c (cff_subfont_load): Fix constant.
* src/cff/cffparse.c (cff_parse_integer, cff_parse_real, do_fixed,
cff_parse_fixed_dynamic): Use unsigned values for computations which
use the left shift operator and convert to signed as the last step.

* src/cid/cidload.c (cid_get_offset): Ditto.

* src/psaux/psconv.c (PS_Conv_ToFixed): Ditto.
* src/psaux/t1decode.c (t1_decoder_parse_charstrings): Ditto.

* src/truetype/ttinterp.c (TT_MulFix14, TT_DotFix14): Ditto.
2013-05-04 16:40:12 +02:00
Werner Lemberg 89f5064765 */*: Use FT_ERR_EQ, FT_ERR_NEQ, and FT_ERR where appropriate.
FT_Err_XXX and friends are no longer directly used in the source
code.
2013-03-14 17:50:49 +01:00
Werner Lemberg e3c9301581 */*: Use FT_Err_Ok only.
This is a purely mechanical conversion.
2013-03-14 11:21:17 +01:00
Werner Lemberg 059bc335ce */*: Use `FT_THROW'.
This is essentially a mechanical conversion, adding inclusion of
`FT_INTERNAL_DEBUG_H' where necessary, and providing the macros for
stand-alone compiling modes of the rasterizer modules.

To convert the remaining occurrences of FT_Err_XXX and friends it is
necessary to rewrite the code.  Note, however, that it doesn't harm
if some cases are not handled since FT_THROW is a no-op.
2013-03-14 10:27:35 +01:00
Werner Lemberg 2ef0a19842 [type1] Fix handling of /FontBBox in MM fonts.
Problem reported by Del Merritt <del@alum.mit.edu>

If we have

  /FontBBox { { 11 12 13 14 15 16 17 18 }
              { 21 22 23 24 25 26 27 28 }
              { 31 32 33 34 35 36 37 38 }
              { 41 42 43 44 45 46 47 48 } }

in the /Blend dictionary,  then the first BBox is { 11 21 31 41 },
the second { 12 22 32 42 }, etc.

* include/freetype/internal/psaux.h (T1_FieldType): Add
`T1_FIELD_TYPE_MM_BBOX' (for temporary use).

* src/psaux/psobjs.c (ps_parser_load_field) <T1_FIELD_TYPE_MM_BBOX>:
Implement it.
2012-12-23 21:14:37 +01:00
Werner Lemberg 8e82a961e7 [psaux] Improve parsing of invalid numbers.
* src/psaux/psconv.c (PS_Conv_Strtol): Always parse complete number,
even in case of overflow.
(PS_Conv_ToInt): Only increase cursor if parsing was successful.
(PS_Conv_ToFixed): Ditto.
Trace underflow and data error.
2012-10-21 11:02:50 +02:00
Werner Lemberg eaf0afb4c7 [psaux] Fix some value overflows and improve tracing.
* src/psaux/psconv.c: Include FT_INTERNAL_DEBUG_H.
(FT_COMPONENT): Define.
(PS_Conv_Strtol): Return FT_Long.
Handle bad data and overflow.
Emit some tracing messages in case of error.
(PS_Conv_ToInt): Return FT_Long.
(PS_Conv_ToFixed): Updated.
* src/psaux/psconv.h: Updated.

* include/freetype/internal/fttrace.h: Add `psconv'.
2012-10-20 11:27:25 +02:00
Werner Lemberg 0708b23e80 [psaux] Fix some value overflows.
* src/psaux/psconv.c (PS_Conv_ToFixed): Implement it.
2012-10-17 21:38:19 +02:00
Werner Lemberg 6b440425fc Fix Savannah bug #36833.
* src/psaux/t1decode.c (t1operator_seac): `seac' is not a valid
operator if we want metrics only.
2012-07-18 10:39:18 +02:00
Vinnie Falco 26dfeb6d63 Prepare source code for amalgamation.
* src\autofit\aferrors.h, src\bdf\bdferror.h, src\bzip2\ftbzip2.c,
src\cache\ftcerror.h, src\cff\cfferrs.h, src\cid\ciderrs.h,
src\gxvalid\gxverror.h, src\gzip\ftgzip.c, src\lzw\ftlzw.c,
src\otvalid\otverror.h, src\pcf\pcferror.h, src\pfr\pfrerror.h,
src\psaux\psauxerr.h, src\pshinter\pshnterr.h,
src\psnames\psnamerr.h, src\raster\rasterrs.h, src\sfnt\sferrors.h,
src\smooth\ftsmerrs.h, src\truetype\tterrors.h,
src\type1\t1errors.h, src\type42\t42error.h, src\winfonts\fnterrs.h:
Add #undef FT_ERR_PREFIX before #define FT_ERR_PREFIX.
2012-03-08 06:04:03 +01:00
Werner Lemberg ceed93e328 [psaux] Fix handling of track kerning.
* src/psaux/afmparse.c (afm_parse_track_kern): Don't inverse sign
for `min_kern'.  It is indeed quite common that track kerning
*increases* spacing for very small sizes.
2012-03-03 07:03:08 +01:00
Werner Lemberg 292144b44a [psaux] Fix Savannah bug #35657.
If in function `skip_spaces' the routine `skip_comment' comes to the
end of buffer, `cur' is still increased by one, so we need to check
for `p >= limit' and not `p == limit'.

* src/psaux/psconv.c (PS_Conv_Strtol, PS_Conv_ToFixed,
PS_Conv_ASCIIHexDecode, PS_Conv_EexecDecode): Fix boundary checking.
2012-03-01 14:54:47 +01:00
Werner Lemberg 22fff25385 Whitespace. 2012-02-26 08:47:20 +01:00
Werner Lemberg 58cbc465d2 [type1] Fix Savannah bug #35606.
* src/type1/t1load.c (parse_subrs): Add proper guards for `strncmp'.

* src/psaux/psobjs.c (ps_parser_skip_PS_token): Emit error message
only if cur < limit.
2012-02-26 05:26:56 +01:00
Werner Lemberg 6b5b6f39e7 Prepare source code for amalgamation (6/6).
* src/cff/cffdrivr.c: s/Load_Glyph/cff_glyph_load/.

* src/cid/cidload.c: s/parse_font_matrix/cid_parse_font_matrix/.
s/t1_init_loader/cid_init_loader/.
s/t1_done_loader/cid_done_loader/.

* src/pxaux/t1cmap.c: s/t1_get_glyph_name/psaux_get_glyph_name/.

* src/truetype/ttdriver.c: s/Load_Glyph/tt_glyph_load/.

* src/type1/t1load.c: s/parse_font_matrix/t1_parse_font_matrix/.
2012-02-24 12:26:25 +01:00
suzuki toshiya 1749d8bc6a Remove trailing spaces. 2012-01-17 02:00:24 +09:00
Werner Lemberg c52f44d4fd Whitespace. 2011-11-30 10:46:53 +01:00
Werner Lemberg 9c98fbf634 Handle some border cases.
* include/freetype/config/ftstdlib.h (FT_USHORT_MAX): New macro.

* src/base/ftbitmap.c (FT_Bitmap_Convert): Protect against invalid
value of `target->rows'.

* src/psaux/t1decode.c (t1_decoder_parse_charstrings): Add check for
flex start.

* src/raster/ftrend1.c (ft_raster1_render): Check `width' and
`height'.

* src/truetype/ttgxvar.c (TT_Vary_Get_Glyph_Deltas): Protect against
invalid values in `localpoints' array.
2011-10-01 09:25:55 +02:00
Dirk Müller b03c4a0a3f [psaux, type1] Fix null pointer dereferences.
Found with font fuzzying.

* src/psaux/t1decode.c (t1_decoder_parse_charstrings): Check
`decoder->buildchar'.

* src/type1/t1load.c (t1_load_keyword): Check `blend->num_designs'.
2011-07-22 05:24:11 +02:00
Matthias Drochner 143799d4a9 [psaux] Fix potential sign extension problems.
When shifting right a signed value, it is not defined by the
C standard whether one gets a sign extension or not.  Use a macro to
do an explicit cast from a signed short (assuming that this is
16bit) to an int.

* src/psaux/t1decode.c (Fix2Int): New macro.
Use it where appropriate.
2011-07-14 07:35:51 +02:00
Werner Lemberg 60f8371353 * src/psaux/t1decode.c (t1_decoder_parse_charstrings)
<op_callothersubr>: Better handling of subroutine index 0.
From Matthias Drochner <M.Drochner@fz-juelich.de>.
2011-07-14 07:34:12 +02:00
Werner Lemberg 403559b84a Sort case in switch statement numerically. 2011-07-14 07:21:11 +02:00
Алексей Подтележников dc33b4a155 [psaux] Optimize previous commit.
* src/psaux/t1decode.c (t1_decoder_parse_charstrings)
<op_callothersubr>: Move error check down to avoid testing twice for
good cases.
2011-07-10 07:08:51 +02:00
Werner Lemberg c46b1e2476 [psaux] Add better argument check for `callothersubr'.
* src/psaux/t1decode.c (t1_decoder_parse_charstrings)
<op_callothersubr>: Reject negative arguments.
2011-07-08 13:46:42 +02:00
Werner Lemberg 9b00875093 Fix Savannah bug #33047.
Patch submitted by anonymous reporter.

* src/psaux/psobjs.c (ps_table_add): Use FT_PtrDist for pointer
difference.
2011-04-13 13:37:37 +02:00
John Tytgat ed7d1a59ff * src/psaux/t1decode.c (t1_decoder_parse_charstring): Expand
start_point, check_points, add_point, add_point1, close_contour
macros.
Remove add_contour macro.
Return error code from t1_builder_start_point and
t1_builder_check_points when there was one (instead of returning 0).
2010-11-23 19:30:38 +01:00
Werner Lemberg c8f5b98be2 Remove C++ warnings.
*/*: Initialize pointers where necessary to make g++ happy.
2010-07-12 21:13:22 +02:00
Werner Lemberg 90b07bd541 Fix Savannah bug #30145.
* src/psaux/psobjs.c (t1_builder_add_contour): Protect against
`outline == NULL' which might happen in invalid fonts.
2010-06-20 16:27:36 +02:00
Werner Lemberg 370aea802c Formatting. 2010-06-08 08:37:11 +02:00
Werner Lemberg 30b8480bbb Whitespace. 2010-05-11 00:06:02 +02:00
Ken Sharp 88169b107a Fix Savannah bug #29846.
Previously we discovered fonts which used `setcurrentpoint' to set
the initial point of a contour to 0,0.  This caused FreeType to
raise an error, because the `setcurrentpoint' operator is only
supposed to be used with the results from an OtherSubr subroutine.

This was fixed by simply ignoring the error and carrying on.

Now we have found a font which uses setcurrentpoint to actually
establish a non-zero point for a contour during the course of a
glyph program.  FWIW, these files may be produced by an application
called `Intaglio' on the Mac, when converting TrueType fonts to
Type 1.

The fix allows the new invalid behaviour, the old invalid behaviour
and real proper usage of the operator to work the same way as Adobe
interpreters apparently do.

(t1_decoder_parse_charstrings): Make `setcurrentpoint' use the top
two elements of the stack to establish unconditionally the current x
and y coordinates.

Make the `flex' subroutine handling (OtherSubr 0) put the current
x,y coordinates onto the stack, instead of two dummy uninitialised
values.
2010-05-11 00:03:33 +02:00
Ken Sharp 54e63755f3 Fix Savannah bug #29444.
* src/psaux/psobjs.c (t1_builder_start_point): Accept (invalid)
`lineto' immediately after `hsbw', in accordance with Acrobat, GS,
and others.
2010-04-14 23:38:35 +02:00
Ken Sharp 8ea31415f4 Fix Savannah bug #28521.
Issue #28226 involved a work-around for a font which used the
`setcurrentpoint' operator in an invalid way; this operator is only
supposed to be used with the result of OtherSubrs, and the font used
it directly.  The supplied patch removed the block of code which
checked this usage entirely.

This turns out to be a Bad Thing.  If `setcurrentpoint' is being
used correctly it should reset the flex flag in the decoder.  If we
don't do this then the flag never gets reset and we omit any further
contours from the glyph (at least until we close the path or
similar).

* src/psaux/t1decode.c (t1_decoder_parse_charstrings)
<op_setcurrentpoint>: Handle `flex_state' correctly.
2010-01-08 18:13:02 +01:00
Werner Lemberg fe6da50d04 Thinkos. 2010-01-05 10:10:15 +01:00
Ken Sharp dbe5622335 Make Type 1 `seac' operator work with incremental interface.
* src/psaux/t1decode.c (t1operator_seac): Don't check `glyph_names'
if incremental interface is used.
2010-01-05 09:43:01 +01:00
Ken Sharp ce41259372 Ignore invalid `setcurrentpoint' operations in Type 1 fonts.
This fixes Savannah bug #28226.

At least two wild PostScript files of unknown provenance contain
Type 1 fonts, apparently converted from TrueType fonts in earlier
PDF versions of the files, which use the `setcurrentpoint' operator
inappropriately.

FreeType currently throws an error in this case, but Ghostscript and
Adobe Distiller both accept the fonts and ignore the problem.  This
commit #ifdefs out the check so PostScript interpreters using
FreeType can render these files.

The specification says `setcurrentpoint' should only be used to set
the point after a `Subr' call, but these fonts use it to set the
initial point to (0,0).  Unnecessarily so, as they correctly use an
`hsbw' operation which implicitly sets the initial point.
2009-12-14 22:32:32 +01:00
suzuki toshiya f2647ddabb [cache, psaux, type1] Fix for multi build. 2009-09-26 00:48:37 +09:00
suzuki toshiya 0729bc9f52 [Win64] Improve the computation of random seed from stack address. 2009-09-10 16:09:55 +09:00
John Tytgat 03e8b2f763 Fix custom cmap for empty Type 1 font (Savannah bug #27294).
* include/freetype/internal/t1types.h (T1_EncodingRecRec_): Update
comment to reflect revised code_last meaning.
* src/type1/t1load.c (T1_Open_Face), src/type42/t42objs.c
(T42_Open_Face): Assign max_char as highest character code + 1 and
use this for T1_EncodingRecRec_::code_last.
* src/psaux/t1cmap.c (t1_cmap_custom_init): Follow revised
T1_EncodingRecRec_::code_last meaning.
2009-09-01 08:10:24 +02:00
suzuki toshiya e6d0c1fb9c psaux: Fix a few casts to FT_Int32 value. 2009-08-01 00:37:58 +09:00
suzuki toshiya 259568cf68 psaux: Handle the string length by FT_Offset variables. 2009-08-01 00:32:13 +09:00
suzuki toshiya 3f0f2e462b XXX_cmap_encoding_char_next() return FT_UInt32 values. 2009-08-01 00:32:09 +09:00
suzuki toshiya d3ed6d1bba psaux: Prevent invalid arguments to afm_parser_read_vals(). 2009-08-01 00:30:43 +09:00
suzuki toshiya d200982d8b psaux: Use size_t variable to pass the buffer size. 2009-08-01 00:30:17 +09:00
suzuki toshiya d1ee378566 type1: Use size_t variable to pass the string length. 2009-08-01 00:30:16 +09:00
Werner Lemberg 24370d67f5 Uff, another thinko. 2009-06-28 02:11:51 +02:00
Werner Lemberg e7389a4405 [psaux, cff] Protect against nested `seac' calls.
* include/freetype/internal/psaux.h (T1_Decoder), src/cff/cffgload.h
(CFF_Decoder): Add `seac' boolean variable.

* src/cff/cffgload.c (cff_operator_seac,
cff_decoder_parse_charstrings), src/psaux/t1decode.c
(t1operator_seac, t1_decoder_parse_charstrings): Use it.
2009-06-28 01:25:55 +02:00
Werner Lemberg 6bb34880e8 Thinko.
* src/psaux/t1decode.c (t1operator_seac)
[FT_CONFIG_OPTION_INCREMENTAL]: Test for existence of incremental
interface.
2009-06-28 00:43:37 +02:00
Werner Lemberg 858abbedc0 For warning messages, replace FT_ERROR with FT_TRACE0.
FT_ERROR is now used only if a function produces a non-zero `error'
value.

Formatting, improving and harmonizing debug strings.
2009-06-26 06:15:41 +02:00
Werner Lemberg e15d9c52bc Formatting etc. 2009-06-25 21:31:53 +02:00
Werner Lemberg 1e8bf5831a Thinko. 2009-06-23 15:48:52 +02:00
Werner Lemberg 11cb8c36ed Use 16.16 format while parsing Type 1 charstrings.
This fixes Savannah bug #26867.

Previously, only integers have been used which can lead to serious
rounding errors.

However, fractional values are only used internally; after the
charstrings (of either Type 1 or 2) have been processed, the
resulting coordinates get rounded to integers currently -- before
applying scaling.  This should be fixed; at the same time a new load
flag should be introduced, to be used in combination with
FT_LOAD_NO_SCALE, which indicates that font units are returned in
16.16 format.  Similarly, the incremental interface should be
extended to allow fractional values for metrics.

* include/freetype/internal/psaux.h (T1_BuilderRec): Remove `shift'
field.
* include/freetype/internal/pshints.h (T1_Hints_SetStemFunc,
T1_Hints_SetStem3Func): Use FT_Fixed for coordinates.

* src/psaux/psobjs.c: Include FT_INTERNAL_CALC_H.
(t1_build_add_point): Always convert fixed to integer.
* src/psaux/t1decode.c (t1_decoder_parse_charstrings):
Use 16.16 format everywhere (except for large integers followed by a
`div').
[CAN_HANDLE_NON_INTEGRAL_T1_OPERANDS]: Remove #ifdef and activate
code uncoditionally.
Add support for random numbers and update remaining code
accordingly; this should work now.
(t1_operator_seac): Updated.
* src/psaux/pshrec.c: Include FT_INTERNAL_CALC_H.
(ps_hints_t1stem3, t1_hints_stem): Updated.

* src/cid/cidgload.c: Include FT_INTERNAL_CALC_H.
(cid_load_glyph) [FT_CONFIG_OPTION_INCREMENTAL],
(cid_face_compute_max_advance, cid_slot_load_glyph): Updated.

* src/type1/t1gload.c (T1_Parse_Glyph_And_Get_Char_String)
[FT_CONFIG_OPTION_INCREMENTAL], (T1_Get_Advances, T1_Load_Glyph):
Updated.
* src/type1/t1load.c: Include FT_INTERNAL_CALC_H.
* src/type1/t1objs.c (T1_Face_Init): Updated.
2009-06-22 16:56:47 +02:00
Werner Lemberg 1f540eff0b Remove unused variables.
* include/freetype/internal/psaux.h (T1_BuilderRec),
src/cff/cffgload.h (CFF_Builder): Remove `last'.
Update all users.
2009-06-20 13:24:08 +02:00
Werner Lemberg 41821f8a8a [psaux] Check large integers while parsing charstrings.
* src/psaux/t1decode.c (t1_decoder_parse_charstrings): Large
integers must be followed by a `div' operator.
2009-06-20 09:31:19 +02:00
Werner Lemberg 86fa2ebc1f Improve debug messages for Type1 charstrings.
* src/psaux/t1decode.c (t1_decoder_parse_charstrings): Emit newlines
after instructions.
Prettify output.
2009-06-19 14:56:26 +02:00
Ralph Giles 04a7858c61 Make `seac' operator work correctly with incremental interface.
SEAC (Single Encoding Accented Characters) are composed of (basically) two
indices specifying two other glyphs, and a movement to position the accent
properly with respect to the main glyph.

To make it work with the incremental interface we now demand that the caller
handles the encoding by itself.
2009-04-30 20:32:31 +02:00
Oran Agra 1dcd0f2399 Add #error to modules and files that do not support PIC yet.
When FT_CONFIG_OPTION_PIC is defined the following files will
create #error:
* src/bdf/bdfdrivr.h
* src/cache/ftcmanag.c
* src/cid/cidriver.h
* src/gxvalid/gxvmod.h
* src/gzip/ftgzip.c
* src/lzw/ftlzw.c
* src/otvalid/otvmod.h
* src/pcf/pcfdrivr.h
* src/pfr/pfrdrivr.h
* src/psaux/psauxmod.h
* src/type1/t1driver.h
* src/type42/t42drivr.h
* src/winfonts/winfnt.h
2009-04-05 18:25:14 +03:00
Werner Lemberg 86e041b5a8 Remove redundant header inclusions.
This covers many Ghostscript Coverity issues.

* src/*: Do it.
2009-03-21 08:51:44 +01:00
Werner Lemberg e85baf4f8e Fix stdlib dependencies.
Problem reported by Mickey Gabel <mickey@monfort.co.il>.

* include/freetype/config/ftstdlib.h (ft_exit): Removed.  Unused.

* src/autofit/afhints.c, src/base/ftlcdfil.c, src/smooth/ftsmooth.c:
s/memcpy/ft_memcpy/.
* src/psaux/t1decode.c: s/memset/ft_memset/, s/memcpy/ft_memcpy/.
2009-01-12 20:01:10 +00:00
Werner Lemberg 9d83d29028 Fix problem with T1_FIELD_{NUM,FIXED}_TABLE2.
* src/psaux/psobjs.c (ps_parser_load_field_table): Don't handle
`count_offset' if it is zero (i.e., unused).  Otherwise, the first
element of the structure which holds the data is erroneously
modified.  Problem reported by Chi Nguyen <chint@necsv.com>.
2009-01-09 07:58:08 +00:00
Werner Lemberg ce33a312da FT_USE_MODULE declares things as:
extern const FT_Module_Class

(or similar for C++).  However, the actual types of the variables
being declared are often different, e.g., FT_Driver_ClassRec or
FT_Renderer_Class.  (Some are, indeed, FT_Module_Class.)

This works with most C compilers (since those structs begin with an
FT_Module_Class struct), but technically it's undefined behavior.

To quote the ISO/IEC 9899:TC2 final committee draft, section 6.2.7
paragraph 2:

  All declarations that refer to the same object or function shall
  have compatible type; otherwise, the behavior is undefined.

(And they are not compatible types.)

Most C compilers don't reject (or even detect!) code which has this
issue, but the GCC LTO development branch compiler does.  (It
outputs the types of the objects while generating .o files, along
with a bunch of other information, then compares them when doing the
final link-time code generation pass.)

Patch from Savannah bug #25133.

* src/base/ftinit.c (FT_USE_MODULE): Include variable type.

* builds/amiga/include/freetype/config/ftmodule.h,
include/freetype/config/ftmodule.h, */module.mk: Updated to declare
pass correct types to FT_USE_MODULE.
2008-12-21 10:29:30 +00:00
Werner Lemberg 52cd0fc8b9 Fixes from the gnuwin32 port.
* src/base/ftlcdfil.c: s/EXPORT/EXPORT_DEF/.

* src/base/ftotval.c: Include FT_OPENTYPE_VALIDATE_H.

* src/psaux/psobjs.c (ps_table_add): Check `length'.
2008-11-24 08:15:05 +00:00
Werner Lemberg e0ed07d767 * src/type1/t1load.c (parse_subrs): Use an endless loop. There are
fonts (like HELVI.PFB version 003.001, used on OS/2) which define
some `subrs' elements more than once.  Problem reported by Peter
Weilbacher <mozilla@weilbacher.org>.
2008-11-04 10:37:30 +00:00
Werner Lemberg a4cb0d95d9 * src/type/t1afm.c (compare_kern_pairs), src/pxaux/afmparse.c
(afm_compare_kern_pairs): Fix comparison.  This fixes Savannah bug
#24119.
2008-08-23 19:54:06 +00:00