[truetype] Provide function to apply `HVAR' advance width variation. * src/truetype/ttgxvar.c (tt_hadvance_adjust): New function. * src/truetype/ttgxvar.h: Updated.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
diff --git a/ChangeLog b/ChangeLog
index 26abc08..5408870 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,14 @@
2016-12-15 Dave Arnold <darnold@adobe.com>
Werner Lemberg <wl@gnu.org>
+ [truetype] Provide function to apply `HVAR' advance width variation.
+
+ * src/truetype/ttgxvar.c (tt_hadvance_adjust): New function.
+ * src/truetype/ttgxvar.h: Updated.
+
+2016-12-15 Dave Arnold <darnold@adobe.com>
+ Werner Lemberg <wl@gnu.org>
+
[truetype] Add `HVAR' table parsing.
Note that this is not complete yet; it only handles advance width
diff --git a/src/truetype/ttgxvar.c b/src/truetype/ttgxvar.c
index 8eb6454..c4eb125 100644
--- a/src/truetype/ttgxvar.c
+++ b/src/truetype/ttgxvar.c
@@ -748,6 +748,151 @@
}
+ /*************************************************************************/
+ /* */
+ /* <Function> */
+ /* tt_hadvance_adjust */
+ /* */
+ /* <Description> */
+ /* Apply HVAR advance width adjustment of a given glyph. */
+ /* */
+ /* <Input> */
+ /* gindex :: The glyph index. */
+ /* */
+ /* <InOut> */
+ /* face :: The font face. */
+ /* */
+ /* adelta :: Points to width value that gets modified. */
+ /* */
+ FT_LOCAL_DEF( FT_Error )
+ tt_hadvance_adjust( TT_Face face,
+ FT_UInt gindex,
+ FT_Int *avalue )
+ {
+ FT_Error error = FT_Err_Ok;
+
+ GX_HVarData varData;
+
+ FT_UInt innerIndex, outerIndex;
+ FT_UInt master, j;
+ FT_Fixed netAdjustment = 0; /* accumulated adjustment */
+ FT_Fixed scaledDelta;
+ FT_Short* deltaSet;
+ FT_Fixed delta;
+
+
+ if ( !face->blend )
+ goto Exit;
+
+ if ( !face->blend->hvar_loaded )
+ {
+ /* initialize hvar table */
+ face->blend->hvar_error = ft_var_load_hvar( face );
+ }
+
+ if ( !face->blend->hvar_checked )
+ {
+ error = face->blend->hvar_error;
+ goto Exit;
+ }
+
+ if ( gindex >= face->blend->hvar_table->widthMap.mapCount )
+ {
+ FT_TRACE2(( "gindex %d out of range\n", gindex ));
+ error = FT_THROW( Invalid_Argument );
+ goto Exit;
+ }
+
+ /* trust that HVAR parser has checked indices */
+ outerIndex = face->blend->hvar_table->widthMap.outerIndex[gindex];
+ innerIndex = face->blend->hvar_table->widthMap.innerIndex[gindex];
+ varData = &face->blend->hvar_table->itemStore.varData[outerIndex];
+ deltaSet = &varData->deltaSet[varData->regionIdxCount * innerIndex];
+
+ /* See pseudo code from `Font Variations Overview' */
+ /* in the OpenType specification. */
+
+ /* outer loop steps through master designs to be blended */
+ for ( master = 0; master < varData->regionIdxCount; master++ )
+ {
+ FT_Fixed scalar = FT_FIXED_ONE;
+ FT_UInt regionIndex = varData->regionIndices[master];
+
+ GX_AxisCoords axis = face->blend
+ ->hvar_table
+ ->itemStore.varRegionList[regionIndex]
+ .axisList;
+
+
+ /* inner loop steps through axes in this region */
+ for ( j = 0;
+ j < face->blend->hvar_table->itemStore.axisCount;
+ j++, axis++ )
+ {
+ FT_Fixed axisScalar;
+
+
+ /* compute the scalar contribution of this axis; */
+ /* ignore invalid ranges */
+ if ( axis->startCoord > axis->peakCoord ||
+ axis->peakCoord > axis->endCoord )
+ axisScalar = FT_FIXED_ONE;
+
+ else if ( axis->startCoord < 0 &&
+ axis->endCoord > 0 &&
+ axis->peakCoord != 0 )
+ axisScalar = FT_FIXED_ONE;
+
+ /* peak of 0 means ignore this axis */
+ else if ( axis->peakCoord == 0 )
+ axisScalar = FT_FIXED_ONE;
+
+ /* ignore this region if coords are out of range */
+ else if ( face->blend->normalizedcoords[j] < axis->startCoord ||
+ face->blend->normalizedcoords[j] > axis->endCoord )
+ axisScalar = 0;
+
+ /* calculate a proportional factor */
+ else
+ {
+ if ( face->blend->normalizedcoords[j] == axis->peakCoord )
+ axisScalar = FT_FIXED_ONE;
+ else if ( face->blend->normalizedcoords[j] < axis->peakCoord )
+ axisScalar =
+ FT_DivFix( face->blend->normalizedcoords[j] - axis->startCoord,
+ axis->peakCoord - axis->startCoord );
+ else
+ axisScalar =
+ FT_DivFix( axis->endCoord - face->blend->normalizedcoords[j],
+ axis->endCoord - axis->peakCoord );
+ }
+
+ /* take product of all the axis scalars */
+ scalar = FT_MulFix( scalar, axisScalar );
+
+ } /* per-axis loop */
+
+ FT_TRACE4(( ", %f ", scalar / 65536.0 ));
+
+ /* get the scaled delta for this region */
+ delta = FT_intToFixed( deltaSet[master] );
+ scaledDelta = FT_MulFix( scalar, delta );
+
+ /* accumulate the adjustments from each region */
+ netAdjustment = netAdjustment + scaledDelta;
+
+ } /* per-region loop */
+
+ FT_TRACE4(( "]\n" ));
+
+ /* apply the accumulated adjustment to derive the interpolated value */
+ *avalue += FT_fixedToInt( netAdjustment );
+
+ Exit:
+ return error;
+ }
+
+
typedef struct GX_GVar_Head_
{
FT_Long version;
diff --git a/src/truetype/ttgxvar.h b/src/truetype/ttgxvar.h
index c5c98ea..95f991f 100644
--- a/src/truetype/ttgxvar.h
+++ b/src/truetype/ttgxvar.h
@@ -254,6 +254,10 @@ FT_BEGIN_HEADER
FT_Outline* outline,
FT_UInt n_points );
+ FT_LOCAL( FT_Error )
+ tt_hadvance_adjust( TT_Face face,
+ FT_UInt gindex,
+ FT_Int *adelta );
FT_LOCAL( FT_Error )
tt_get_var_blend( TT_Face face,