36
36
at the size at 12 pixels scaled by 2 through a transform,
37
37
because the hints will have been computed differently (except
38
38
you have disabled hints).
39
-
40
- This hack is enabled only when VERTICAL_HINTING is defined, and will
41
- only be effective when load_char and set_text are called with 'flags=
42
- LOAD_DEFAULT', which is the default.
43
39
*/
44
- #define VERTICAL_HINTING
45
- #ifdef VERTICAL_HINTING
46
- #define HORIZ_HINTING 8
47
- #else
48
- #define HORIZ_HINTING 1
49
- #endif
50
40
51
41
FT_Library _ft2Library;
52
42
@@ -408,7 +398,7 @@ FT2Image::py_get_height(const Py::Tuple & args)
408
398
PYCXX_VARARGS_METHOD_DECL (FT2Image, py_get_height)
409
399
410
400
Py::PythonClassObject<Glyph> Glyph::factory(
411
- const FT_Face& face, const FT_Glyph& glyph, size_t ind)
401
+ const FT_Face& face, const FT_Glyph& glyph, size_t ind, long hinting_factor )
412
402
{
413
403
Py::Callable class_type (type ());
414
404
Py::PythonClassObject<Glyph> obj = Py::PythonClassObject<Glyph>(
@@ -419,12 +409,12 @@ Py::PythonClassObject<Glyph> Glyph::factory(
419
409
FT_BBox bbox;
420
410
FT_Glyph_Get_CBox (glyph, ft_glyph_bbox_subpixels, &bbox);
421
411
422
- o->setattro (" width" , Py::Int (face->glyph ->metrics .width / HORIZ_HINTING ));
412
+ o->setattro (" width" , Py::Int (face->glyph ->metrics .width / hinting_factor ));
423
413
o->setattro (" height" , Py::Int (face->glyph ->metrics .height ));
424
- o->setattro (" horiBearingX" , Py::Int (face->glyph ->metrics .horiBearingX / HORIZ_HINTING ));
414
+ o->setattro (" horiBearingX" , Py::Int (face->glyph ->metrics .horiBearingX / hinting_factor ));
425
415
o->setattro (" horiBearingY" , Py::Int (face->glyph ->metrics .horiBearingY ));
426
416
o->setattro (" horiAdvance" , Py::Int (face->glyph ->metrics .horiAdvance ));
427
- o->setattro (" linearHoriAdvance" , Py::Int (face->glyph ->linearHoriAdvance / HORIZ_HINTING ));
417
+ o->setattro (" linearHoriAdvance" , Py::Int (face->glyph ->linearHoriAdvance / hinting_factor ));
428
418
o->setattro (" vertBearingX" , Py::Int (face->glyph ->metrics .vertBearingX ));
429
419
430
420
o->setattro (" vertBearingY" , Py::Int (face->glyph ->metrics .vertBearingY ));
@@ -847,14 +837,15 @@ FT2Font::FT2Font(Py::PythonClassInstance *self, Py::Tuple &args, Py::Dict &kwds)
847
837
}
848
838
849
839
// set a default fontsize 12 pt at 72dpi
850
- #ifdef VERTICAL_HINTING
851
- error = FT_Set_Char_Size (face, 12 * 64 , 0 , 72 * HORIZ_HINTING, 72 );
852
- static FT_Matrix transform = { 65536 / HORIZ_HINTING, 0 , 0 , 65536 };
840
+ hinting_factor = 8 ;
841
+ if (kwds.hasKey (" hinting_factor" ))
842
+ {
843
+ hinting_factor = Py::Long (kwds[" hinting_factor" ]);
844
+ }
845
+
846
+ error = FT_Set_Char_Size (face, 12 * 64 , 0 , 72 * hinting_factor, 72 );
847
+ static FT_Matrix transform = { 65536 / hinting_factor, 0 , 0 , 65536 };
853
848
FT_Set_Transform (face, &transform, 0 );
854
- #else
855
- error = FT_Set_Char_Size (face, 12 * 64 , 0 , 72 , 72 );
856
- #endif
857
- // error = FT_Set_Char_Size( face, 20 * 64, 0, 80, 80 );
858
849
if (error)
859
850
{
860
851
std::ostringstream s;
@@ -993,17 +984,12 @@ FT2Font::set_size(const Py::Tuple & args)
993
984
double ptsize = Py::Float (args[0 ]);
994
985
double dpi = Py::Float (args[1 ]);
995
986
996
- #ifdef VERTICAL_HINTING
997
987
int error = FT_Set_Char_Size (face, (long )(ptsize * 64 ), 0 ,
998
- (unsigned int )dpi * HORIZ_HINTING ,
988
+ (unsigned int )dpi * hinting_factor ,
999
989
(unsigned int )dpi);
1000
- static FT_Matrix transform = { 65536 / HORIZ_HINTING , 0 , 0 , 65536 };
990
+ static FT_Matrix transform = { 65536 / hinting_factor , 0 , 0 , 65536 };
1001
991
FT_Set_Transform (face, &transform, 0 );
1002
- #else
1003
- int error = FT_Set_Char_Size (face, (long )(ptsize * 64 ), 0 ,
1004
- (unsigned int )dpi,
1005
- (unsigned int )dpi);
1006
- #endif
992
+
1007
993
if (error)
1008
994
{
1009
995
throw Py::RuntimeError (" Could not set the fontsize" );
@@ -1126,7 +1112,7 @@ FT2Font::get_kerning(const Py::Tuple & args)
1126
1112
1127
1113
if (!FT_Get_Kerning (face, left, right, mode, &delta))
1128
1114
{
1129
- return Py::Int (delta.x / HORIZ_HINTING );
1115
+ return Py::Int (delta.x / hinting_factor );
1130
1116
}
1131
1117
else
1132
1118
{
@@ -1214,7 +1200,7 @@ FT2Font::set_text(const Py::Tuple & args, const Py::Dict & kwargs)
1214
1200
FT_Vector delta;
1215
1201
FT_Get_Kerning (face, previous, glyph_index,
1216
1202
FT_KERNING_DEFAULT, &delta);
1217
- pen.x += delta.x / HORIZ_HINTING ;
1203
+ pen.x += delta.x / hinting_factor ;
1218
1204
}
1219
1205
error = FT_Load_Glyph (face, glyph_index, flags);
1220
1206
if (error)
@@ -1319,7 +1305,7 @@ FT2Font::load_char(const Py::Tuple & args, const Py::Dict & kwargs)
1319
1305
1320
1306
size_t num = glyphs.size(); //the index into the glyphs list
1321
1307
glyphs.push_back(thisGlyph);
1322
- return Glyph::factory(face, thisGlyph, num);
1308
+ return Glyph::factory(face, thisGlyph, num, hinting_factor );
1323
1309
}
1324
1310
PYCXX_KEYWORDS_METHOD_DECL(FT2Font, load_char)
1325
1311
@@ -1369,7 +1355,7 @@ FT2Font::load_glyph(const Py::Tuple & args, const Py::Dict & kwargs)
1369
1355
1370
1356
size_t num = glyphs.size(); //the index into the glyphs list
1371
1357
glyphs.push_back(thisGlyph);
1372
- return Glyph::factory(face, thisGlyph, num);
1358
+ return Glyph::factory(face, thisGlyph, num, hinting_factor );
1373
1359
}
1374
1360
PYCXX_KEYWORDS_METHOD_DECL(FT2Font, load_glyph)
1375
1361
0 commit comments