22
33#define NO_IMPORT_ARRAY
44
5- #include < string>
65#include < algorithm>
6+ #include < stdexcept>
7+ #include < string>
78
89#include " ft2font.h"
910#include " mplutils.h"
@@ -115,7 +116,7 @@ void FT2Image::draw_bitmap(FT_Bitmap *bitmap, FT_Int x, FT_Int y)
115116 }
116117 }
117118 } else {
118- throw " Unknown pixel mode" ;
119+ throw std::runtime_error ( " Unknown pixel mode" ) ;
119120 }
120121
121122 m_dirty = true ;
@@ -124,7 +125,7 @@ void FT2Image::draw_bitmap(FT_Bitmap *bitmap, FT_Int x, FT_Int y)
124125void FT2Image::draw_rect (unsigned long x0, unsigned long y0, unsigned long x1, unsigned long y1)
125126{
126127 if (x0 > m_width || x1 > m_width || y0 > m_height || y1 > m_height) {
127- throw " Rect coords outside image bounds" ;
128+ throw std::runtime_error ( " Rect coords outside image bounds" ) ;
128129 }
129130
130131 size_t top = y0 * m_width;
@@ -170,7 +171,7 @@ int FT2Font::get_path_count()
170171 // this code is from agg's decompose_ft_outline with minor modifications
171172
172173 if (!face->glyph ) {
173- throw " No glyph loaded" ;
174+ throw std::runtime_error ( " No glyph loaded" ) ;
174175 }
175176
176177 FT_Outline &outline = face->glyph ->outline ;
@@ -208,7 +209,7 @@ int FT2Font::get_path_count()
208209
209210 // A contour cannot start with a cubic control point!
210211 if (tag == FT_CURVE_TAG_CUBIC) {
211- throw " A contour cannot start with a cubic control point" ;
212+ throw std::runtime_error ( " A contour cannot start with a cubic control point" ) ;
212213 } else if (tag == FT_CURVE_TAG_CONIC) {
213214 starts_with_last = true ;
214215 } else {
@@ -246,7 +247,7 @@ int FT2Font::get_path_count()
246247 }
247248
248249 if (tag != FT_CURVE_TAG_CONIC) {
249- throw " Invalid font" ;
250+ throw std::runtime_error ( " Invalid font" ) ;
250251 }
251252
252253 count += 2 ;
@@ -262,7 +263,7 @@ int FT2Font::get_path_count()
262263 default : // FT_CURVE_TAG_CUBIC
263264 {
264265 if (point + 1 > limit || FT_CURVE_TAG (tags[1 ]) != FT_CURVE_TAG_CUBIC) {
265- throw " Invalid font" ;
266+ throw std::runtime_error ( " Invalid font" ) ;
266267 }
267268
268269 point += 2 ;
@@ -492,13 +493,13 @@ FT2Font::FT2Font(FT_Open_Args &open_args, long hinting_factor_) : image(), face(
492493 int error = FT_Open_Face (_ft2Library, &open_args, 0 , &face);
493494
494495 if (error == FT_Err_Unknown_File_Format) {
495- throw " Can not load face. Unknown file format." ;
496+ throw std::runtime_error ( " Can not load face. Unknown file format." ) ;
496497 } else if (error == FT_Err_Cannot_Open_Resource) {
497- throw " Can not load face. Can not open resource." ;
498+ throw std::runtime_error ( " Can not load face. Can not open resource." ) ;
498499 } else if (error == FT_Err_Invalid_File_Format) {
499- throw " Can not load face. Invalid file format." ;
500+ throw std::runtime_error ( " Can not load face. Invalid file format." ) ;
500501 } else if (error) {
501- throw " Can not load face." ;
502+ throw std::runtime_error ( " Can not load face." ) ;
502503 }
503504
504505 // set a default fontsize 12 pt at 72dpi
@@ -507,7 +508,7 @@ FT2Font::FT2Font(FT_Open_Args &open_args, long hinting_factor_) : image(), face(
507508 error = FT_Set_Char_Size (face, 12 * 64 , 0 , 72 * (unsigned int )hinting_factor, 72 );
508509 if (error) {
509510 FT_Done_Face (face);
510- throw " Could not set the fontsize" ;
511+ throw std::runtime_error ( " Could not set the fontsize" ) ;
511512 }
512513
513514 if (open_args.stream != NULL ) {
@@ -551,25 +552,25 @@ void FT2Font::set_size(double ptsize, double dpi)
551552 FT_Set_Transform (face, &transform, 0 );
552553
553554 if (error) {
554- throw " Could not set the fontsize" ;
555+ throw std::runtime_error ( " Could not set the fontsize" ) ;
555556 }
556557}
557558
558559void FT2Font::set_charmap (int i)
559560{
560561 if (i >= face->num_charmaps ) {
561- throw " i exceeds the available number of char maps" ;
562+ throw std::runtime_error ( " i exceeds the available number of char maps" ) ;
562563 }
563564 FT_CharMap charmap = face->charmaps [i];
564565 if (FT_Set_Charmap (face, charmap)) {
565- throw " Could not set the charmap" ;
566+ throw std::runtime_error ( " Could not set the charmap" ) ;
566567 }
567568}
568569
569570void FT2Font::select_charmap (unsigned long i)
570571{
571572 if (FT_Select_Charmap (face, (FT_Encoding)i)) {
572- throw " Could not set the charmap" ;
573+ throw std::runtime_error ( " Could not set the charmap" ) ;
573574 }
574575}
575576
@@ -624,7 +625,7 @@ void FT2Font::set_text(
624625 }
625626 error = FT_Load_Glyph (face, glyph_index, flags);
626627 if (error) {
627- throw " could not load glyph" ;
628+ throw std::runtime_error ( " could not load glyph" ) ;
628629 }
629630 // ignore errors, jump to next glyph
630631
@@ -634,7 +635,7 @@ void FT2Font::set_text(
634635 error = FT_Get_Glyph (face->glyph , &thisGlyph);
635636
636637 if (error) {
637- throw " could not get glyph" ;
638+ throw std::runtime_error ( " could not get glyph" ) ;
638639 }
639640 // ignore errors, jump to next glyph
640641
@@ -670,14 +671,14 @@ void FT2Font::load_char(long charcode, FT_Int32 flags)
670671 int error = FT_Load_Char (face, (unsigned long )charcode, flags);
671672
672673 if (error) {
673- throw " Could not load charcode" ;
674+ throw std::runtime_error ( " Could not load charcode" ) ;
674675 }
675676
676677 FT_Glyph thisGlyph;
677678 error = FT_Get_Glyph (face->glyph , &thisGlyph);
678679
679680 if (error) {
680- throw " Could not get glyph" ;
681+ throw std::runtime_error ( " Could not get glyph" ) ;
681682 }
682683
683684 glyphs.push_back (thisGlyph);
@@ -688,14 +689,14 @@ void FT2Font::load_glyph(FT_UInt glyph_index, FT_Int32 flags)
688689 int error = FT_Load_Glyph (face, glyph_index, flags);
689690
690691 if (error) {
691- throw " Could not load glyph" ;
692+ throw std::runtime_error ( " Could not load glyph" ) ;
692693 }
693694
694695 FT_Glyph thisGlyph;
695696 error = FT_Get_Glyph (face->glyph , &thisGlyph);
696697
697698 if (error) {
698- throw " Could not load glyph" ;
699+ throw std::runtime_error ( " Could not load glyph" ) ;
699700 }
700701
701702 glyphs.push_back (thisGlyph);
@@ -729,7 +730,7 @@ void FT2Font::draw_glyphs_to_bitmap(bool antialiased)
729730 error = FT_Glyph_To_Bitmap (
730731 &glyphs[n], antialiased ? FT_RENDER_MODE_NORMAL : FT_RENDER_MODE_MONO, 0 , 1 );
731732 if (error) {
732- throw " Could not convert glyph to bitmap" ;
733+ throw std::runtime_error ( " Could not convert glyph to bitmap" ) ;
733734 }
734735
735736 FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyphs[n];
@@ -750,7 +751,7 @@ void FT2Font::get_xys(bool antialiased, std::vector<double> &xys)
750751 error = FT_Glyph_To_Bitmap (
751752 &glyphs[n], antialiased ? FT_RENDER_MODE_NORMAL : FT_RENDER_MODE_MONO, 0 , 1 );
752753 if (error) {
753- throw " Could not convert glyph to bitmap" ;
754+ throw std::runtime_error ( " Could not convert glyph to bitmap" ) ;
754755 }
755756
756757 FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyphs[n];
@@ -773,7 +774,7 @@ void FT2Font::draw_glyph_to_bitmap(FT2Image &im, int x, int y, size_t glyphInd,
773774 sub_offset.y = 0 ; // int((yd - (double)y) * 64.0);
774775
775776 if (glyphInd >= glyphs.size ()) {
776- throw " glyph num is out of range" ;
777+ throw std::runtime_error ( " glyph num is out of range" ) ;
777778 }
778779
779780 error = FT_Glyph_To_Bitmap (&glyphs[glyphInd],
@@ -782,7 +783,7 @@ void FT2Font::draw_glyph_to_bitmap(FT2Image &im, int x, int y, size_t glyphInd,
782783 1 // destroy image
783784 );
784785 if (error) {
785- throw " Could not convert glyph to bitmap" ;
786+ throw std::runtime_error ( " Could not convert glyph to bitmap" ) ;
786787 }
787788
788789 FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyphs[glyphInd];
@@ -798,7 +799,7 @@ void FT2Font::get_glyph_name(unsigned int glyph_number, char *buffer)
798799 PyOS_snprintf (buffer, 128 , " uni%08x" , glyph_number);
799800 } else {
800801 if (FT_Get_Glyph_Name (face, glyph_number, buffer, 128 )) {
801- throw " Could not get glyph names." ;
802+ throw std::runtime_error ( " Could not get glyph names." ) ;
802803 }
803804 }
804805}
0 commit comments