8
8
/* *
9
9
To improve the hinting of the fonts, this code uses a hack
10
10
presented here:
11
-
11
+
12
12
http://antigrain.com/research/font_rasterization/index.html
13
-
13
+
14
14
The idea is to limit the effect of hinting in the x-direction, while
15
15
preserving hinting in the y-direction. Since freetype does not
16
16
support this directly, the dpi in the x-direction is set higher than
20
20
hinting, whereas the global transform does not, this is documented
21
21
behavior of freetype, and therefore hopefully unlikely to change.
22
22
The freetype 2 tutorial says:
23
-
23
+
24
24
NOTE: The transformation is applied to every glyph that is
25
25
loaded through FT_Load_Glyph and is completely independent of
26
26
any hinting process. This means that you won't get the same
42
42
43
43
FT_Library _ft2Library;
44
44
45
- // FT2Image::FT2Image() :
45
+ // FT2Image::FT2Image() :
46
46
// _isDirty(true),
47
47
// _buffer(NULL),
48
48
// _width(0), _height(0),
@@ -53,18 +53,18 @@ FT_Library _ft2Library;
53
53
54
54
FT2Image::FT2Image (unsigned long width, unsigned long height) :
55
55
_isDirty(true ),
56
- _buffer(NULL ),
56
+ _buffer(NULL ),
57
57
_width(0 ), _height(0 ),
58
58
_rgbCopy(NULL ),
59
59
_rgbaCopy(NULL ) {
60
60
_VERBOSE (" FT2Image::FT2Image" );
61
61
resize (width, height);
62
62
}
63
63
64
- FT2Image::~FT2Image () {
64
+ FT2Image::~FT2Image () {
65
65
_VERBOSE (" FT2Image::~FT2Image" );
66
- delete [] _buffer;
67
- _buffer=NULL ;
66
+ delete [] _buffer;
67
+ _buffer=NULL ;
68
68
delete _rgbCopy;
69
69
delete _rgbaCopy;
70
70
}
@@ -151,7 +151,7 @@ FT2Image::py_write_bitmap(const Py::Tuple & args) {
151
151
}
152
152
153
153
void
154
- FT2Image::draw_rect (unsigned long x0, unsigned long y0,
154
+ FT2Image::draw_rect (unsigned long x0, unsigned long y0,
155
155
unsigned long x1, unsigned long y1) {
156
156
if ( x0<0 || y0 <0 || x1<0 || y1 <0 ||
157
157
x0>_width || x1>_width ||
@@ -195,7 +195,7 @@ FT2Image::py_draw_rect(const Py::Tuple & args) {
195
195
return Py::Object ();
196
196
}
197
197
198
- void FT2Image::draw_rect_filled (unsigned long x0, unsigned long y0,
198
+ void FT2Image::draw_rect_filled (unsigned long x0, unsigned long y0,
199
199
unsigned long x1, unsigned long y1) {
200
200
x0 = CLAMP (x0, 0 , _width);
201
201
y0 = CLAMP (y0 , 0 , _height);
@@ -209,7 +209,7 @@ void FT2Image::draw_rect_filled(unsigned long x0, unsigned long y0,
209
209
}
210
210
211
211
_isDirty = true ;
212
- }
212
+ }
213
213
214
214
char FT2Image::draw_rect_filled__doc__[] =
215
215
" draw_rect_filled(x0, y0, x1, y1)\n "
@@ -245,7 +245,7 @@ FT2Image::py_as_str(const Py::Tuple & args) {
245
245
args.verify_length (0 );
246
246
247
247
return Py::asObject
248
- (PyString_FromStringAndSize ((const char *)_buffer,
248
+ (PyString_FromStringAndSize ((const char *)_buffer,
249
249
_width*_height)
250
250
);
251
251
}
@@ -284,7 +284,7 @@ FT2Image::py_as_rgb_str(const Py::Tuple & args) {
284
284
args.verify_length (0 );
285
285
286
286
makeRgbCopy ();
287
-
287
+
288
288
return _rgbCopy->py_as_str (args);
289
289
}
290
290
@@ -321,7 +321,7 @@ FT2Image::py_as_rgba_str(const Py::Tuple & args) {
321
321
args.verify_length (0 );
322
322
323
323
makeRgbaCopy ();
324
-
324
+
325
325
return _rgbaCopy->py_as_str (args);
326
326
}
327
327
@@ -671,7 +671,7 @@ FT2Font::FT2Font(std::string facefile) :
671
671
}
672
672
673
673
// set a default fontsize 12 pt at 72dpi
674
- #ifdef VERTICAL_HINTING
674
+ #ifdef VERTICAL_HINTING
675
675
error = FT_Set_Char_Size ( face, 12 * 64 , 0 , 72 * HORIZ_HINTING, 72 );
676
676
static FT_Matrix transform = { 65536 / HORIZ_HINTING, 0 , 0 , 65536 };
677
677
FT_Set_Transform ( face, &transform, 0 );
@@ -829,7 +829,7 @@ FT2Font::set_size(const Py::Tuple & args) {
829
829
int error = FT_Set_Char_Size ( face, (long )(ptsize * 64 ), 0 ,
830
830
(unsigned int )dpi,
831
831
(unsigned int )dpi );
832
- #endif
832
+ #endif
833
833
if (error)
834
834
throw Py::RuntimeError (" Could not set the fontsize" );
835
835
return Py::Object ();
@@ -1036,7 +1036,6 @@ FT2Font::get_glyph(const Py::Tuple & args){
1036
1036
if ( (size_t )num >= gms.size ())
1037
1037
throw Py::ValueError (" Glyph index out of range" );
1038
1038
1039
- Py_INCREF (gms[num]);
1040
1039
return Py::asObject (gms[num]);
1041
1040
}
1042
1041
@@ -1078,7 +1077,7 @@ FT2Font::load_char(const Py::Tuple & args, const Py::Dict & kwargs) {
1078
1077
long charcode = Py::Long (args[0 ]), flags = Py::Long (FT_LOAD_FORCE_AUTOHINT);
1079
1078
if (kwargs.hasKey (" flags" ))
1080
1079
flags = Py::Long (kwargs[" flags" ]);
1081
-
1080
+
1082
1081
int error = FT_Load_Char ( face, (unsigned long )charcode, flags);
1083
1082
1084
1083
if (error)
@@ -1094,7 +1093,6 @@ FT2Font::load_char(const Py::Tuple & args, const Py::Dict & kwargs) {
1094
1093
glyphs.push_back (thisGlyph);
1095
1094
Glyph* gm = new Glyph (face, thisGlyph, num);
1096
1095
gms.push_back (gm);
1097
- Py_INCREF (gm); // todo: refcount correct?
1098
1096
return Py::asObject ( gm);
1099
1097
}
1100
1098
@@ -1659,7 +1657,7 @@ FT2Font::get_sfnt_table(const Py::Tuple & args) {
1659
1657
}
1660
1658
}
1661
1659
1662
- char FT2Font::get_image__doc__ [] =
1660
+ char FT2Font::get_image__doc__ [] =
1663
1661
" get_image()\n "
1664
1662
" \n "
1665
1663
" Returns the underlying image buffer for this font object.\n " ;
@@ -1669,7 +1667,7 @@ FT2Font::get_image (const Py::Tuple &args) {
1669
1667
if (image) {
1670
1668
Py_XINCREF (image);
1671
1669
return Py::asObject (image);
1672
- }
1670
+ }
1673
1671
throw Py::RuntimeError (" You must call .set_text() before .get_image()" );
1674
1672
}
1675
1673
@@ -1684,7 +1682,7 @@ FT2Font::attach_file (const Py::Tuple &args) {
1684
1682
args.verify_length (1 );
1685
1683
1686
1684
std::string filename = Py::String (args[0 ]);
1687
- FT_Error error =
1685
+ FT_Error error =
1688
1686
FT_Attach_File (face, filename.c_str ());
1689
1687
1690
1688
if (error) {
@@ -1884,7 +1882,7 @@ initft2font(void)
1884
1882
d[" KERNING_DEFAULT" ] = Py::Int (FT_KERNING_DEFAULT);
1885
1883
d[" KERNING_UNFITTED" ] = Py::Int (FT_KERNING_UNFITTED);
1886
1884
d[" KERNING_UNSCALED" ] = Py::Int (FT_KERNING_UNSCALED);
1887
-
1885
+
1888
1886
d[" LOAD_DEFAULT" ] = Py::Long (FT_LOAD_DEFAULT);
1889
1887
d[" LOAD_NO_SCALE" ] = Py::Long (FT_LOAD_NO_SCALE);
1890
1888
d[" LOAD_NO_HINTING" ] = Py::Long (FT_LOAD_NO_HINTING);
@@ -1894,7 +1892,7 @@ initft2font(void)
1894
1892
d[" LOAD_FORCE_AUTOHINT" ] = Py::Long (FT_LOAD_FORCE_AUTOHINT);
1895
1893
d[" LOAD_CROP_BITMAP" ] = Py::Long (FT_LOAD_CROP_BITMAP);
1896
1894
d[" LOAD_PEDANTIC" ] = Py::Long (FT_LOAD_PEDANTIC);
1897
- d[" LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH" ] =
1895
+ d[" LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH" ] =
1898
1896
Py::Long (FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH);
1899
1897
d[" LOAD_NO_RECURSE" ] = Py::Long (FT_LOAD_NO_RECURSE);
1900
1898
d[" LOAD_IGNORE_TRANSFORM" ] = Py::Long (FT_LOAD_IGNORE_TRANSFORM);
0 commit comments