2013-04-13 15:02:31 +02:00
|
|
|
/***************************************************************************/
|
|
|
|
/* */
|
2017-09-25 08:29:38 +02:00
|
|
|
/* pshints.h */
|
2013-04-13 15:02:31 +02:00
|
|
|
/* */
|
|
|
|
/* Adobe's code for handling CFF hints (body). */
|
|
|
|
/* */
|
|
|
|
/* Copyright 2007-2013 Adobe Systems Incorporated. */
|
|
|
|
/* */
|
|
|
|
/* This software, and all works of authorship, whether in source or */
|
|
|
|
/* object code form as indicated by the copyright notice(s) included */
|
|
|
|
/* herein (collectively, the "Work") is made available, and may only be */
|
|
|
|
/* used, modified, and distributed under the FreeType Project License, */
|
|
|
|
/* LICENSE.TXT. Additionally, subject to the terms and conditions of the */
|
|
|
|
/* FreeType Project License, each contributor to the Work hereby grants */
|
|
|
|
/* to any individual or legal entity exercising permissions granted by */
|
|
|
|
/* the FreeType Project License and this section (hereafter, "You" or */
|
|
|
|
/* "Your") a perpetual, worldwide, non-exclusive, no-charge, */
|
|
|
|
/* royalty-free, irrevocable (except as stated in this section) patent */
|
|
|
|
/* license to make, have made, use, offer to sell, sell, import, and */
|
|
|
|
/* otherwise transfer the Work, where such license applies only to those */
|
|
|
|
/* patent claims licensable by such contributor that are necessarily */
|
|
|
|
/* infringed by their contribution(s) alone or by combination of their */
|
|
|
|
/* contribution(s) with the Work to which such contribution(s) was */
|
|
|
|
/* submitted. If You institute patent litigation against any entity */
|
|
|
|
/* (including a cross-claim or counterclaim in a lawsuit) alleging that */
|
|
|
|
/* the Work or a contribution incorporated within the Work constitutes */
|
|
|
|
/* direct or contributory patent infringement, then any patent licenses */
|
|
|
|
/* granted to You under this License for that Work shall terminate as of */
|
|
|
|
/* the date such litigation is filed. */
|
|
|
|
/* */
|
|
|
|
/* By using, modifying, or distributing the Work you indicate that you */
|
|
|
|
/* have read and understood the terms and conditions of the */
|
|
|
|
/* FreeType Project License as well as those provided in this section, */
|
|
|
|
/* and you accept them fully. */
|
|
|
|
/* */
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
|
2017-10-01 01:39:27 +02:00
|
|
|
#ifndef PSHINT_H_
|
|
|
|
#define PSHINT_H_
|
2013-04-13 15:02:31 +02:00
|
|
|
|
|
|
|
FT_BEGIN_HEADER
|
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
CF2_MAX_HINTS = 96 /* maximum # of hints */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A HintMask object stores a bit mask that specifies which hints in the
|
|
|
|
* charstring are active at a given time. Hints in CFF must be declared
|
|
|
|
* at the start, before any drawing operators, with horizontal hints
|
|
|
|
* preceding vertical hints. The HintMask is ordered the same way, with
|
|
|
|
* horizontal hints immediately followed by vertical hints. Clients are
|
|
|
|
* responsible for knowing how many of each type are present.
|
|
|
|
*
|
|
|
|
* The maximum total number of hints is 96, as specified by the CFF
|
|
|
|
* specification.
|
|
|
|
*
|
|
|
|
* A HintMask is built 0 or more times while interpreting a charstring, by
|
|
|
|
* the HintMask operator. There is only one HintMask, but it is built or
|
|
|
|
* rebuilt each time there is a hint substitution (HintMask operator) in
|
|
|
|
* the charstring. A default HintMask with all bits set is built if there
|
|
|
|
* has been no HintMask operator prior to the first drawing operator.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct CF2_HintMaskRec_
|
|
|
|
{
|
|
|
|
FT_Error* error;
|
|
|
|
|
|
|
|
FT_Bool isValid;
|
|
|
|
FT_Bool isNew;
|
|
|
|
|
|
|
|
size_t bitCount;
|
|
|
|
size_t byteCount;
|
|
|
|
|
|
|
|
FT_Byte mask[( CF2_MAX_HINTS + 7 ) / 8];
|
|
|
|
|
|
|
|
} CF2_HintMaskRec, *CF2_HintMask;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct CF2_StemHintRec_
|
|
|
|
{
|
|
|
|
FT_Bool used; /* DS positions are valid */
|
|
|
|
|
|
|
|
CF2_Fixed min; /* original character space value */
|
|
|
|
CF2_Fixed max;
|
|
|
|
|
|
|
|
CF2_Fixed minDS; /* DS position after first use */
|
|
|
|
CF2_Fixed maxDS;
|
|
|
|
|
|
|
|
} CF2_StemHintRec, *CF2_StemHint;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A HintMap object stores a piecewise linear function for mapping
|
|
|
|
* y-coordinates from character space to device space, providing
|
|
|
|
* appropriate pixel alignment to stem edges.
|
|
|
|
*
|
|
|
|
* The map is implemented as an array of `CF2_Hint' elements, each
|
|
|
|
* representing an edge. When edges are paired, as from stem hints, the
|
|
|
|
* bottom edge must immediately precede the top edge in the array.
|
|
|
|
* Element character space AND device space positions must both increase
|
|
|
|
* monotonically in the array. `CF2_Hint' elements are also used as
|
|
|
|
* parameters to `cf2_blues_capture'.
|
|
|
|
*
|
|
|
|
* The `cf2_hintmap_build' method must be called before any drawing
|
|
|
|
* operation (beginning with a Move operator) and at each hint
|
|
|
|
* substitution (HintMask operator).
|
|
|
|
*
|
|
|
|
* The `cf2_hintmap_map' method is called to transform y-coordinates at
|
|
|
|
* each drawing operation (move, line, curve).
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* TODO: make this a CF2_ArrStack and add a deep copy method */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
CF2_MAX_HINT_EDGES = CF2_MAX_HINTS * 2
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct CF2_HintMapRec_
|
|
|
|
{
|
|
|
|
CF2_Font font;
|
|
|
|
|
|
|
|
/* initial map based on blue zones */
|
|
|
|
struct CF2_HintMapRec_* initialHintMap;
|
|
|
|
|
|
|
|
/* working storage for 2nd pass adjustHints */
|
|
|
|
CF2_ArrStack hintMoves;
|
|
|
|
|
|
|
|
FT_Bool isValid;
|
|
|
|
FT_Bool hinted;
|
|
|
|
|
|
|
|
CF2_Fixed scale;
|
|
|
|
CF2_UInt count;
|
|
|
|
|
|
|
|
/* start search from this index */
|
|
|
|
CF2_UInt lastIndex;
|
|
|
|
|
|
|
|
CF2_HintRec edge[CF2_MAX_HINT_EDGES]; /* 192 */
|
|
|
|
|
|
|
|
} CF2_HintMapRec, *CF2_HintMap;
|
|
|
|
|
|
|
|
|
|
|
|
FT_LOCAL( FT_Bool )
|
|
|
|
cf2_hint_isValid( const CF2_Hint hint );
|
|
|
|
FT_LOCAL( FT_Bool )
|
|
|
|
cf2_hint_isTop( const CF2_Hint hint );
|
|
|
|
FT_LOCAL( FT_Bool )
|
|
|
|
cf2_hint_isBottom( const CF2_Hint hint );
|
|
|
|
FT_LOCAL( void )
|
|
|
|
cf2_hint_lock( CF2_Hint hint );
|
|
|
|
|
|
|
|
|
|
|
|
FT_LOCAL( void )
|
|
|
|
cf2_hintmap_init( CF2_HintMap hintmap,
|
|
|
|
CF2_Font font,
|
|
|
|
CF2_HintMap initialMap,
|
|
|
|
CF2_ArrStack hintMoves,
|
|
|
|
CF2_Fixed scale );
|
|
|
|
FT_LOCAL( void )
|
|
|
|
cf2_hintmap_build( CF2_HintMap hintmap,
|
|
|
|
CF2_ArrStack hStemHintArray,
|
|
|
|
CF2_ArrStack vStemHintArray,
|
|
|
|
CF2_HintMask hintMask,
|
|
|
|
CF2_Fixed hintOrigin,
|
|
|
|
FT_Bool initialMap );
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* GlyphPath is a wrapper for drawing operations that scales the
|
|
|
|
* coordinates according to the render matrix and HintMap. It also tracks
|
|
|
|
* open paths to control ClosePath and to insert MoveTo for broken fonts.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
typedef struct CF2_GlyphPathRec_
|
|
|
|
{
|
|
|
|
/* TODO: gather some of these into a hinting context */
|
|
|
|
|
|
|
|
CF2_Font font; /* font instance */
|
|
|
|
CF2_OutlineCallbacks callbacks; /* outline consumer */
|
|
|
|
|
|
|
|
|
|
|
|
CF2_HintMapRec hintMap; /* current hint map */
|
|
|
|
CF2_HintMapRec firstHintMap; /* saved copy */
|
|
|
|
CF2_HintMapRec initialHintMap; /* based on all captured hints */
|
|
|
|
|
|
|
|
CF2_ArrStackRec hintMoves; /* list of hint moves for 2nd pass */
|
|
|
|
|
|
|
|
CF2_Fixed scaleX; /* matrix a */
|
|
|
|
CF2_Fixed scaleC; /* matrix c */
|
|
|
|
CF2_Fixed scaleY; /* matrix d */
|
|
|
|
|
|
|
|
FT_Vector fractionalTranslation; /* including deviceXScale */
|
|
|
|
#if 0
|
|
|
|
CF2_Fixed hShift; /* character space horizontal shift */
|
|
|
|
/* (for fauxing) */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
FT_Bool pathIsOpen; /* true after MoveTo */
|
Fix Savannah bug #39295.
The bug was caused by switching to the initial hintmap (the one in
effect when `moveto' executes) just before drawing the final element
in the charstring. This ensured that the path was closed (in both
Character Space and Device Space). But if the final element was a
curve and if the final hintmap was different enough from the initial
one, then the curve was visibly distorted.
The first part of the fix is to draw the final curve using the final
hintmap as specified by the charstring. This corrects the
distortion but does not ensure closing in Device Space. It may
require the rasterizer to automatically generate an extra closing
line. Depending on the hintmap differences, this line could be from
zero to a couple pixels in length.
The second part of the fix covers the case where the charstring
subpath is closed with an explicit line. We now modify that line's
end point to avoid the distortion.
Some glyphs in the bug report font (TexGyreHeros-Regular) that show
the change are:
25ppem S (98)
24ppem eight (52)
25.5ppem p (85)
Curves at the *end* of a subpath are no longer distorted. However,
some of these glyphs have bad hint substitutions in the middle of a
subpath, and these are not affected.
The patch has been tested with a set of 106 fonts that shipped with
Adobe Creative Suite 4, together with 756 Open Source CFF fonts from
Google Fonts. There are 1.5 million glyphs, of which some 20k are
changed with the fix. A sampling of a few hundred of these changes
have been examined more closely, and the changes look good (or at
least acceptable).
* src/cff/cf2hints.h (CF2_GlyphPathRec): New element `pathIsClosing'
to indicate that we synthesize a closepath line.
* src/cff/cf2hints.c (cf2_glyphpath_init): Updated.
(cf2_glyphpath_pushPrevElem): If closing, use first hint map (for
`lineto' operator) and adjust hint zone.
For synthesized closing lines, use end point in first hint zone.
(cf2_glyphpath_lineTo): Take care of synthesized closing lines. In
particular, shift the detection of zero-length lines from character
space to device space.
(cf2_glyphpath_closeOpenPath): Remove assertion.
Updated.
2013-09-29 16:17:02 +02:00
|
|
|
FT_Bool pathIsClosing; /* true when synthesizing closepath line */
|
2013-04-13 15:02:31 +02:00
|
|
|
FT_Bool darken; /* true if stem darkening */
|
|
|
|
FT_Bool moveIsPending; /* true between MoveTo and offset MoveTo */
|
|
|
|
|
|
|
|
/* references used to call `cf2_hintmap_build', if necessary */
|
|
|
|
CF2_ArrStack hStemHintArray;
|
|
|
|
CF2_ArrStack vStemHintArray;
|
|
|
|
CF2_HintMask hintMask; /* ptr to the current mask */
|
|
|
|
CF2_Fixed hintOriginY; /* copy of current origin */
|
|
|
|
const CF2_BluesRec* blues;
|
|
|
|
|
|
|
|
CF2_Fixed xOffset; /* character space offsets */
|
|
|
|
CF2_Fixed yOffset;
|
|
|
|
|
|
|
|
/* character space miter limit threshold */
|
|
|
|
CF2_Fixed miterLimit;
|
2016-04-09 05:21:34 +02:00
|
|
|
/* vertical/horizontal snap distance in character space */
|
2013-04-13 15:02:31 +02:00
|
|
|
CF2_Fixed snapThreshold;
|
|
|
|
|
|
|
|
FT_Vector offsetStart0; /* first and second points of first */
|
|
|
|
FT_Vector offsetStart1; /* element with offset applied */
|
|
|
|
|
|
|
|
/* current point, character space, before offset */
|
|
|
|
FT_Vector currentCS;
|
|
|
|
/* current point, device space */
|
|
|
|
FT_Vector currentDS;
|
Fix Savannah bug #39295.
The bug was caused by switching to the initial hintmap (the one in
effect when `moveto' executes) just before drawing the final element
in the charstring. This ensured that the path was closed (in both
Character Space and Device Space). But if the final element was a
curve and if the final hintmap was different enough from the initial
one, then the curve was visibly distorted.
The first part of the fix is to draw the final curve using the final
hintmap as specified by the charstring. This corrects the
distortion but does not ensure closing in Device Space. It may
require the rasterizer to automatically generate an extra closing
line. Depending on the hintmap differences, this line could be from
zero to a couple pixels in length.
The second part of the fix covers the case where the charstring
subpath is closed with an explicit line. We now modify that line's
end point to avoid the distortion.
Some glyphs in the bug report font (TexGyreHeros-Regular) that show
the change are:
25ppem S (98)
24ppem eight (52)
25.5ppem p (85)
Curves at the *end* of a subpath are no longer distorted. However,
some of these glyphs have bad hint substitutions in the middle of a
subpath, and these are not affected.
The patch has been tested with a set of 106 fonts that shipped with
Adobe Creative Suite 4, together with 756 Open Source CFF fonts from
Google Fonts. There are 1.5 million glyphs, of which some 20k are
changed with the fix. A sampling of a few hundred of these changes
have been examined more closely, and the changes look good (or at
least acceptable).
* src/cff/cf2hints.h (CF2_GlyphPathRec): New element `pathIsClosing'
to indicate that we synthesize a closepath line.
* src/cff/cf2hints.c (cf2_glyphpath_init): Updated.
(cf2_glyphpath_pushPrevElem): If closing, use first hint map (for
`lineto' operator) and adjust hint zone.
For synthesized closing lines, use end point in first hint zone.
(cf2_glyphpath_lineTo): Take care of synthesized closing lines. In
particular, shift the detection of zero-length lines from character
space to device space.
(cf2_glyphpath_closeOpenPath): Remove assertion.
Updated.
2013-09-29 16:17:02 +02:00
|
|
|
/* start point of subpath, character space */
|
|
|
|
FT_Vector start;
|
2013-04-13 15:02:31 +02:00
|
|
|
|
|
|
|
/* the following members constitute the `queue' of one element */
|
|
|
|
FT_Bool elemIsQueued;
|
|
|
|
CF2_Int prevElemOp;
|
|
|
|
|
|
|
|
FT_Vector prevElemP0;
|
|
|
|
FT_Vector prevElemP1;
|
|
|
|
FT_Vector prevElemP2;
|
|
|
|
FT_Vector prevElemP3;
|
|
|
|
|
|
|
|
} CF2_GlyphPathRec, *CF2_GlyphPath;
|
|
|
|
|
|
|
|
|
|
|
|
FT_LOCAL( void )
|
|
|
|
cf2_glyphpath_init( CF2_GlyphPath glyphpath,
|
|
|
|
CF2_Font font,
|
|
|
|
CF2_OutlineCallbacks callbacks,
|
|
|
|
CF2_Fixed scaleY,
|
|
|
|
/* CF2_Fixed hShift, */
|
|
|
|
CF2_ArrStack hStemHintArray,
|
|
|
|
CF2_ArrStack vStemHintArray,
|
|
|
|
CF2_HintMask hintMask,
|
|
|
|
CF2_Fixed hintOrigin,
|
|
|
|
const CF2_Blues blues,
|
|
|
|
const FT_Vector* fractionalTranslation );
|
|
|
|
FT_LOCAL( void )
|
|
|
|
cf2_glyphpath_finalize( CF2_GlyphPath glyphpath );
|
|
|
|
|
|
|
|
FT_LOCAL( void )
|
|
|
|
cf2_glyphpath_moveTo( CF2_GlyphPath glyphpath,
|
|
|
|
CF2_Fixed x,
|
|
|
|
CF2_Fixed y );
|
|
|
|
FT_LOCAL( void )
|
|
|
|
cf2_glyphpath_lineTo( CF2_GlyphPath glyphpath,
|
|
|
|
CF2_Fixed x,
|
|
|
|
CF2_Fixed y );
|
|
|
|
FT_LOCAL( void )
|
|
|
|
cf2_glyphpath_curveTo( CF2_GlyphPath glyphpath,
|
|
|
|
CF2_Fixed x1,
|
|
|
|
CF2_Fixed y1,
|
|
|
|
CF2_Fixed x2,
|
|
|
|
CF2_Fixed y2,
|
|
|
|
CF2_Fixed x3,
|
|
|
|
CF2_Fixed y3 );
|
|
|
|
FT_LOCAL( void )
|
|
|
|
cf2_glyphpath_closeOpenPath( CF2_GlyphPath glyphpath );
|
|
|
|
|
|
|
|
|
|
|
|
FT_END_HEADER
|
|
|
|
|
|
|
|
|
2017-10-01 01:39:27 +02:00
|
|
|
#endif /* PSHINT_H_ */
|
2013-04-13 15:02:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* END */
|