@@ -22,10 +22,13 @@ Glyph::Glyph( const FT_Face& face, const FT_Glyph& glyph, size_t ind) :
2222 setattr (" horiBearingX" , Py::Int ( face->glyph ->metrics .horiBearingX ) );
2323 setattr (" horiBearingY" , Py::Int ( face->glyph ->metrics .horiBearingY ) );
2424 setattr (" horiAdvance" , Py::Int ( face->glyph ->metrics .horiAdvance ) );
25+ setattr (" linearHoriAdvance" , Py::Int ( face->glyph ->linearHoriAdvance ) );
2526 setattr (" vertBearingX" , Py::Int ( face->glyph ->metrics .vertBearingX ) );
2627
2728 setattr (" vertBearingY" , Py::Int ( face->glyph ->metrics .vertBearingY ) );
2829 setattr (" vertAdvance" , Py::Int ( face->glyph ->metrics .vertAdvance ) );
30+ // setattr("bitmap_left", Py::Int( face->glyph->bitmap_left) );
31+ // setattr("bitmap_top", Py::Int( face->glyph->bitmap_top) );
2932
3033 Py::Tuple abbox (4 );
3134
@@ -616,25 +619,33 @@ FT2Font::compute_string_bbox( ) {
616619
617620
618621char FT2Font::get_kerning__doc__[] =
619- " dx = get_kerning(left, right)\n "
622+ " dx = get_kerning(left, right, mode )\n "
620623" \n "
621624" Get the kerning between left char and right glyph indices\n "
625+ " mode is a kerning mode constant\n "
626+ " KERNING_DEFAULT - Return scaled and grid-fitted kerning distances\n "
627+ " KERNING_UNFITTED - Return scaled but un-grid-fitted kerning distances\n "
628+ " KERNING_UNSCALED - Return the kerning vector in original font units\n "
622629;
623630Py::Object
624631FT2Font::get_kerning (const Py::Tuple & args) {
625632 _VERBOSE (" FT2Font::get_kerning" );
626- args.verify_length (2 );
633+ args.verify_length (3 );
627634 int left = Py::Int (args[0 ]);
628635 int right = Py::Int (args[1 ]);
629-
636+ int mode = Py::Int (args[2 ]);
637+
630638
631639 if (!FT_HAS_KERNING ( face )) return Py::Int (0 );
632640 FT_Vector delta;
633641
634- FT_Get_Kerning ( face, left, right,
635- FT_KERNING_DEFAULT , &delta );
642+ if (FT_Get_Kerning ( face, left, right, mode, &delta )) {
643+ return Py::Int (0 );
644+ }
645+ else {
646+ return Py::Int (delta.x );
636647
637- return Py::Int (delta. x );
648+ }
638649}
639650
640651
@@ -686,10 +697,6 @@ FT2Font::set_text(const Py::Tuple & args) {
686697 std::string thischar (" ?" );
687698 FT_UInt glyph_index;
688699
689- Py::Tuple xy (2 );
690- xy[0 ] = Py::Float (pen.x );
691- xy[1 ] = Py::Float (pen.y );
692- xys[n] = xy;
693700
694701 if (pcode==NULL ) {
695702 // plain ol string
@@ -727,6 +734,10 @@ FT2Font::set_text(const Py::Tuple & args) {
727734 // ignore errors, jump to next glyph
728735
729736 FT_Glyph_Transform ( thisGlyph, 0 , &pen);
737+ Py::Tuple xy (2 );
738+ xy[0 ] = Py::Float (pen.x );
739+ xy[1 ] = Py::Float (pen.y );
740+ xys[n] = xy;
730741 pen.x += face->glyph ->advance .x ;
731742
732743 previous = glyph_index;
@@ -797,6 +808,8 @@ FT2Font::load_char(const Py::Tuple & args) {
797808 long charcode = Py::Int (args[0 ]);
798809
799810 int error = FT_Load_Char ( face, (unsigned long )charcode, FT_LOAD_DEFAULT );
811+ // int error = FT_Load_Char( face, (unsigned long)charcode, FT_LOAD_LINEAR_DESIGN);
812+ // int error = FT_Load_Char( face, (unsigned long)charcode, FT_LOAD_RENDER);
800813
801814 if (error)
802815 throw Py::RuntimeError (Printf (" Could not load charcode %d" , charcode).str ());
@@ -868,7 +881,7 @@ FT2Font::draw_bitmap( FT_Bitmap* bitmap,
868881 {
869882 if ( i >= width || j >= height )
870883 continue ;
871- image.buffer [i + j*width] |= bitmap->buffer [q*bitmap->width + p ];
884+ image.buffer [i + j*width] |= bitmap->buffer [p + q*bitmap->width ];
872885
873886 }
874887 }
@@ -1022,6 +1035,54 @@ FT2Font::draw_glyphs_to_bitmap(const Py::Tuple & args) {
10221035 return Py::Object ();
10231036}
10241037
1038+
1039+ char FT2Font::get_xys__doc__[] =
1040+ " get_xys()\n "
1041+ " \n "
1042+ " Get the xy locations of the current glyphs\n "
1043+ ;
1044+ Py::Object
1045+ FT2Font::get_xys (const Py::Tuple & args) {
1046+
1047+ _VERBOSE (" FT2Font::get_xys" );
1048+ args.verify_length (0 );
1049+
1050+ FT_BBox string_bbox = compute_string_bbox ();
1051+ Py::Tuple xys (glyphs.size ());
1052+
1053+ for ( size_t n = 0 ; n < glyphs.size (); n++ )
1054+ {
1055+
1056+ FT_BBox bbox;
1057+ FT_Glyph_Get_CBox (glyphs[n], ft_glyph_bbox_pixels, &bbox);
1058+
1059+ error = FT_Glyph_To_Bitmap (&glyphs[n],
1060+ ft_render_mode_normal,
1061+ 0 ,
1062+ // &pos[n],
1063+ 1 // destroy image;
1064+ );
1065+ if (error)
1066+ throw Py::RuntimeError (" Could not convert glyph to bitmap" );
1067+
1068+ FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyphs[n];
1069+
1070+
1071+ // bitmap left and top in pixel, string bbox in subpixel
1072+ FT_Int x = (FT_Int)(bitmap->left -string_bbox.xMin /64 .);
1073+ FT_Int y = (FT_Int)(string_bbox.yMax /64 .-bitmap->top +1 );
1074+ // make sure the index is non-neg
1075+ x = x<0 ?0 :x;
1076+ y = y<0 ?0 :y;
1077+ Py::Tuple xy (2 );
1078+ xy[0 ] = Py::Float (x);
1079+ xy[1 ] = Py::Float (y);
1080+ xys[n] = xy;
1081+ }
1082+
1083+ return xys;
1084+ }
1085+
10251086char FT2Font::draw_glyph_to_bitmap__doc__[] =
10261087" draw_glyph_to_bitmap(x, y, glyph)\n "
10271088" \n "
@@ -1494,6 +1555,9 @@ FT2Font::init_type() {
14941555 FT2Font::draw_glyph_to_bitmap__doc__);
14951556 add_varargs_method (" draw_glyphs_to_bitmap" , &FT2Font::draw_glyphs_to_bitmap,
14961557 FT2Font::draw_glyphs_to_bitmap__doc__);
1558+ add_varargs_method (" get_xys" , &FT2Font::get_xys,
1559+ FT2Font::get_xys__doc__);
1560+
14971561 add_varargs_method (" get_glyph" , &FT2Font::get_glyph,
14981562 FT2Font::get_glyph__doc__);
14991563 add_varargs_method (" get_num_glyphs" , &FT2Font::get_num_glyphs,
@@ -1612,6 +1676,9 @@ initft2font(void)
16121676 d[" EXTERNAL_STREAM" ] = Py::Int (FT_FACE_FLAG_EXTERNAL_STREAM );
16131677 d[" ITALIC" ] = Py::Int (FT_STYLE_FLAG_ITALIC );
16141678 d[" BOLD" ] = Py::Int (FT_STYLE_FLAG_BOLD );
1679+ d[" KERNING_DEFAULT" ] = Py::Int (FT_KERNING_DEFAULT );
1680+ d[" KERNING_UNFITTED" ] = Py::Int (FT_KERNING_UNFITTED );
1681+ d[" KERNING_UNSCALED" ] = Py::Int (FT_KERNING_UNSCALED );
16151682
16161683 // initialize library
16171684 int error = FT_Init_FreeType ( &_ft2Library );
0 commit comments