Handle properties in `FREETYPE_PROPERTIES' environment variable. This commit covers the most important one. * src/autofit/afmodule.c (af_property_set): Handle `warping', `darkening-parameters', and `no-stem-darkening'. * src/cff/cffdrivr.c (cff_property_set): Handle `darkening-parameters', `hinting-engine', and `no-stem-darkening'. * src/truetype/ttdriver.c (tt_property_set): Handle `interpreter-version'.
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 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
diff --git a/ChangeLog b/ChangeLog
index 830840e..1a1b4a5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
2016-07-11 Werner Lemberg <wl@gnu.org>
+ Handle properties in `FREETYPE_PROPERTIES' environment variable.
+
+ This commit covers the most important one.
+
+ * src/autofit/afmodule.c (af_property_set): Handle `warping',
+ `darkening-parameters', and `no-stem-darkening'.
+
+ * src/cff/cffdrivr.c (cff_property_set): Handle
+ `darkening-parameters', `hinting-engine', and `no-stem-darkening'.
+
+ * src/truetype/ttdriver.c (tt_property_set): Handle
+ `interpreter-version'.
+
+2016-07-11 Werner Lemberg <wl@gnu.org>
+
Replace calls to `atol' with `strtol'.
We later on need strtol's `endptr' feature.
diff --git a/include/freetype/ftautoh.h b/include/freetype/ftautoh.h
index 40c8003..48ff1aa 100644
--- a/include/freetype/ftautoh.h
+++ b/include/freetype/ftautoh.h
@@ -428,6 +428,9 @@ FT_BEGIN_HEADER
* @note:
* This property can be used with @FT_Property_Get also.
*
+ * This property can be set via the `FREETYPE_PROPERTIES' environment
+ * variable (using values 1 and 0 for `on' and `off', respectively).
+ *
* The warping code can also change advance widths. Have a look at the
* `lsb_delta' and `rsb_delta' fields in the @FT_GlyphSlotRec structure
* for details on improving inter-glyph distances while rendering.
@@ -473,6 +476,9 @@ FT_BEGIN_HEADER
* The smaller the size (especially 9ppem and down), the higher the loss
* of emboldening versus the CFF driver.
*
+ * This property can be set via the `FREETYPE_PROPERTIES' environment
+ * variable similar to the CFF driver.
+ *
*/
@@ -489,6 +495,8 @@ FT_BEGIN_HEADER
* CFF_CONFIG_OPTION_DARKENING_PARAMETER_* #defines for consistency.
* Note the differences described in @no-stem-darkening[autofit].
*
+ * This property can be set via the `FREETYPE_PROPERTIES' environment
+ * variable similar to the CFF driver.
*/
diff --git a/include/freetype/ftcffdrv.h b/include/freetype/ftcffdrv.h
index ad34541..8f88cc4 100644
--- a/include/freetype/ftcffdrv.h
+++ b/include/freetype/ftcffdrv.h
@@ -148,6 +148,8 @@ FT_BEGIN_HEADER
* @note:
* This property can be used with @FT_Property_Get also.
*
+ * This property can be set via the `FREETYPE_PROPERTIES' environment
+ * variable (using values `adobe' or `freetype').
*/
@@ -199,6 +201,9 @@ FT_BEGIN_HEADER
* @note:
* This property can be used with @FT_Property_Get also.
*
+ * This property can be set via the `FREETYPE_PROPERTIES' environment
+ * variable (using values 1 and 0 for `on' and `off', respectively).
+ *
*/
@@ -248,6 +253,14 @@ FT_BEGIN_HEADER
* @note:
* This property can be used with @FT_Property_Get also.
*
+ * This property can be set via the `FREETYPE_PROPERTIES' environment
+ * variable, using eight comma-separated integers without spaces. Here
+ * the above example, using `\' to break the line for readability.
+ *
+ * {
+ * FREETYPE_PROPERTIES=\
+ * cff:darkening-parameters=500,300,1000,200,1500,100,2000,0
+ * }
*/
/* */
diff --git a/include/freetype/ftttdrv.h b/include/freetype/ftttdrv.h
index 0d868bc..22186ee 100644
--- a/include/freetype/ftttdrv.h
+++ b/include/freetype/ftttdrv.h
@@ -181,6 +181,8 @@ FT_BEGIN_HEADER
* @note:
* This property can be used with @FT_Property_Get also.
*
+ * This property can be set via the `FREETYPE_PROPERTIES' environment
+ * variable (using values `35', `38', or `40').
*/
diff --git a/src/autofit/afmodule.c b/src/autofit/afmodule.c
index 03680be..4a6b049 100644
--- a/src/autofit/afmodule.c
+++ b/src/autofit/afmodule.c
@@ -184,15 +184,26 @@
#ifdef AF_CONFIG_OPTION_USE_WARPER
else if ( !ft_strcmp( property_name, "warping" ) )
{
- FT_Bool* warping;
+ if ( value_is_string )
+ {
+ const char* s = (const char*)value;
+ long w = ft_strtol( s, NULL, 10 );
- if ( value_is_string )
- return FT_THROW( Invalid_Argument );
+ if ( w == 0 )
+ module->warping = 0;
+ else if ( w == 1 )
+ module->warping = 1;
+ else
+ return FT_THROW( Invalid_Argument );
+ }
+ else
+ {
+ FT_Bool* warping = (FT_Bool*)value;
- warping = (FT_Bool*)value;
- module->warping = *warping;
+ module->warping = *warping;
+ }
return error;
}
@@ -201,12 +212,34 @@
{
FT_Int* darken_params;
FT_Int x1, y1, x2, y2, x3, y3, x4, y4;
+ FT_Int dp[8];
if ( value_is_string )
- return FT_THROW( Invalid_Argument );
+ {
+ const char* s = (const char*)value;
+ char* ep;
+ int i;
- darken_params = (FT_Int*)value;
+
+ /* eight comma-separated numbers */
+ for ( i = 0; i < 7; i++ )
+ {
+ dp[i] = (FT_Int)ft_strtol( s, &ep, 10 );
+ if ( *ep != ',' || s == ep )
+ return FT_THROW( Invalid_Argument );
+
+ s = ep + 1;
+ }
+
+ dp[7] = (FT_Int)ft_strtol( s, &ep, 10 );
+ if ( !( *ep == '\0' || *ep == ' ' ) || s == ep )
+ return FT_THROW( Invalid_Argument );
+
+ darken_params = dp;
+ }
+ else
+ darken_params = (FT_Int*)value;
x1 = darken_params[0];
y1 = darken_params[1];
@@ -236,15 +269,26 @@
}
else if ( !ft_strcmp( property_name, "no-stem-darkening" ) )
{
- FT_Bool* no_stem_darkening;
+ if ( value_is_string )
+ {
+ const char* s = (const char*)value;
+ long nsd = ft_strtol( s, NULL, 10 );
- if ( value_is_string )
- return FT_THROW( Invalid_Argument );
+ if ( nsd == 0 )
+ module->no_stem_darkening = 0;
+ else if ( nsd == 1 )
+ module->no_stem_darkening = 1;
+ else
+ return FT_THROW( Invalid_Argument );
+ }
+ else
+ {
+ FT_Bool* no_stem_darkening = (FT_Bool*)value;
- no_stem_darkening = (FT_Bool*)value;
- module->no_stem_darkening = *no_stem_darkening;
+ module->no_stem_darkening = *no_stem_darkening;
+ }
return error;
}
diff --git a/src/cff/cffdrivr.c b/src/cff/cffdrivr.c
index 88bb7e6..2e2a437 100644
--- a/src/cff/cffdrivr.c
+++ b/src/cff/cffdrivr.c
@@ -670,12 +670,34 @@
{
FT_Int* darken_params;
FT_Int x1, y1, x2, y2, x3, y3, x4, y4;
+ FT_Int dp[8];
if ( value_is_string )
- return FT_THROW( Invalid_Argument );
+ {
+ const char* s = (const char*)value;
+ char* ep;
+ int i;
+
+
+ /* eight comma-separated numbers */
+ for ( i = 0; i < 7; i++ )
+ {
+ dp[i] = (FT_Int)ft_strtol( s, &ep, 10 );
+ if ( *ep != ',' || s == ep )
+ return FT_THROW( Invalid_Argument );
+
+ s = ep + 1;
+ }
- darken_params = (FT_Int*)value;
+ dp[7] = (FT_Int)ft_strtol( s, &ep, 10 );
+ if ( !( *ep == '\0' || *ep == ' ' ) || s == ep )
+ return FT_THROW( Invalid_Argument );
+
+ darken_params = dp;
+ }
+ else
+ darken_params = (FT_Int*)value;
x1 = darken_params[0];
y1 = darken_params[1];
@@ -705,36 +727,58 @@
}
else if ( !ft_strcmp( property_name, "hinting-engine" ) )
{
- FT_UInt* hinting_engine;
-
-
if ( value_is_string )
- return FT_THROW( Invalid_Argument );
+ {
+ const char* s = (const char*)value;
- hinting_engine = (FT_UInt*)value;
- if ( *hinting_engine == FT_CFF_HINTING_ADOBE
+ if ( !ft_strcmp( s, "adobe" ) )
+ driver->hinting_engine = FT_CFF_HINTING_ADOBE;
#ifdef CFF_CONFIG_OPTION_OLD_ENGINE
- || *hinting_engine == FT_CFF_HINTING_FREETYPE
+ else if ( !ft_strcmp( s, "freetype" ) )
+ driver->hinting_engine = FT_CFF_HINTING_FREETYPE;
#endif
- )
- driver->hinting_engine = *hinting_engine;
+ else
+ return FT_THROW( Invalid_Argument );
+ }
else
- error = FT_ERR( Unimplemented_Feature );
+ {
+ FT_UInt* hinting_engine = (FT_UInt*)value;
- return error;
+ if ( *hinting_engine == FT_CFF_HINTING_ADOBE
+#ifdef CFF_CONFIG_OPTION_OLD_ENGINE
+ || *hinting_engine == FT_CFF_HINTING_FREETYPE
+#endif
+ )
+ driver->hinting_engine = *hinting_engine;
+ else
+ error = FT_ERR( Unimplemented_Feature );
+
+ return error;
+ }
}
else if ( !ft_strcmp( property_name, "no-stem-darkening" ) )
{
- FT_Bool* no_stem_darkening;
+ if ( value_is_string )
+ {
+ const char* s = (const char*)value;
+ long nsd = ft_strtol( s, NULL, 10 );
- if ( value_is_string )
- return FT_THROW( Invalid_Argument );
+ if ( nsd == 0 )
+ driver->no_stem_darkening = 0;
+ else if ( nsd == 1 )
+ driver->no_stem_darkening = 1;
+ else
+ return FT_THROW( Invalid_Argument );
+ }
+ else
+ {
+ FT_Bool* no_stem_darkening = (FT_Bool*)value;
- no_stem_darkening = (FT_Bool*)value;
- driver->no_stem_darkening = *no_stem_darkening;
+ driver->no_stem_darkening = *no_stem_darkening;
+ }
return error;
}
diff --git a/src/truetype/ttdriver.c b/src/truetype/ttdriver.c
index 83a8042..3debf78 100644
--- a/src/truetype/ttdriver.c
+++ b/src/truetype/ttdriver.c
@@ -70,23 +70,33 @@
if ( !ft_strcmp( property_name, "interpreter-version" ) )
{
- FT_UInt* interpreter_version;
+ FT_UInt interpreter_version;
if ( value_is_string )
- return FT_THROW( Invalid_Argument );
+ {
+ const char* s = (const char*)value;
+
+
+ interpreter_version = (FT_UInt)ft_strtol( s, NULL, 10 );
+ }
+ else
+ {
+ FT_UInt* iv = (FT_UInt*)value;
- interpreter_version = (FT_UInt*)value;
- if ( *interpreter_version == TT_INTERPRETER_VERSION_35
+ interpreter_version = *iv;
+ }
+
+ if ( interpreter_version == TT_INTERPRETER_VERSION_35
#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY
- || *interpreter_version == TT_INTERPRETER_VERSION_38
+ || interpreter_version == TT_INTERPRETER_VERSION_38
#endif
#ifdef TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL
- || *interpreter_version == TT_INTERPRETER_VERSION_40
+ || interpreter_version == TT_INTERPRETER_VERSION_40
#endif
)
- driver->interpreter_version = *interpreter_version;
+ driver->interpreter_version = interpreter_version;
else
error = FT_ERR( Unimplemented_Feature );