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
@@ -622,7 +623,7 @@ void FT2Font::set_text(
622623 }
623624 error = FT_Load_Glyph (face, glyph_index, flags);
624625 if (error) {
625- throw " could not load glyph" ;
626+ throw std::runtime_error ( " could not load glyph" ) ;
626627 }
627628 // ignore errors, jump to next glyph
628629
@@ -632,7 +633,7 @@ void FT2Font::set_text(
632633 error = FT_Get_Glyph (face->glyph , &thisGlyph);
633634
634635 if (error) {
635- throw " could not get glyph" ;
636+ throw std::runtime_error ( " could not get glyph" ) ;
636637 }
637638 // ignore errors, jump to next glyph
638639
@@ -668,14 +669,14 @@ void FT2Font::load_char(long charcode, FT_Int32 flags)
668669 int error = FT_Load_Char (face, (unsigned long )charcode, flags);
669670
670671 if (error) {
671- throw " Could not load charcode" ;
672+ throw std::runtime_error ( " Could not load charcode" ) ;
672673 }
673674
674675 FT_Glyph thisGlyph;
675676 error = FT_Get_Glyph (face->glyph , &thisGlyph);
676677
677678 if (error) {
678- throw " Could not get glyph" ;
679+ throw std::runtime_error ( " Could not get glyph" ) ;
679680 }
680681
681682 glyphs.push_back (thisGlyph);
@@ -686,14 +687,14 @@ void FT2Font::load_glyph(FT_UInt glyph_index, FT_Int32 flags)
686687 int error = FT_Load_Glyph (face, glyph_index, flags);
687688
688689 if (error) {
689- throw " Could not load glyph" ;
690+ throw std::runtime_error ( " Could not load glyph" ) ;
690691 }
691692
692693 FT_Glyph thisGlyph;
693694 error = FT_Get_Glyph (face->glyph , &thisGlyph);
694695
695696 if (error) {
696- throw " Could not load glyph" ;
697+ throw std::runtime_error ( " Could not load glyph" ) ;
697698 }
698699
699700 glyphs.push_back (thisGlyph);
@@ -727,7 +728,7 @@ void FT2Font::draw_glyphs_to_bitmap(bool antialiased)
727728 error = FT_Glyph_To_Bitmap (
728729 &glyphs[n], antialiased ? FT_RENDER_MODE_NORMAL : FT_RENDER_MODE_MONO, 0 , 1 );
729730 if (error) {
730- throw " Could not convert glyph to bitmap" ;
731+ throw std::runtime_error ( " Could not convert glyph to bitmap" ) ;
731732 }
732733
733734 FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyphs[n];
@@ -748,7 +749,7 @@ void FT2Font::get_xys(bool antialiased, std::vector<double> &xys)
748749 error = FT_Glyph_To_Bitmap (
749750 &glyphs[n], antialiased ? FT_RENDER_MODE_NORMAL : FT_RENDER_MODE_MONO, 0 , 1 );
750751 if (error) {
751- throw " Could not convert glyph to bitmap" ;
752+ throw std::runtime_error ( " Could not convert glyph to bitmap" ) ;
752753 }
753754
754755 FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyphs[n];
@@ -771,7 +772,7 @@ void FT2Font::draw_glyph_to_bitmap(FT2Image &im, int x, int y, size_t glyphInd,
771772 sub_offset.y = 0 ; // int((yd - (double)y) * 64.0);
772773
773774 if (glyphInd >= glyphs.size ()) {
774- throw " glyph num is out of range" ;
775+ throw std::runtime_error ( " glyph num is out of range" ) ;
775776 }
776777
777778 error = FT_Glyph_To_Bitmap (&glyphs[glyphInd],
@@ -780,7 +781,7 @@ void FT2Font::draw_glyph_to_bitmap(FT2Image &im, int x, int y, size_t glyphInd,
780781 1 // destroy image
781782 );
782783 if (error) {
783- throw " Could not convert glyph to bitmap" ;
784+ throw std::runtime_error ( " Could not convert glyph to bitmap" ) ;
784785 }
785786
786787 FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyphs[glyphInd];
@@ -796,7 +797,7 @@ void FT2Font::get_glyph_name(unsigned int glyph_number, char *buffer)
796797 PyOS_snprintf (buffer, 128 , " uni%08x" , glyph_number);
797798 } else {
798799 if (FT_Get_Glyph_Name (face, glyph_number, buffer, 128 )) {
799- throw " Could not get glyph names." ;
800+ throw std::runtime_error ( " Could not get glyph names." ) ;
800801 }
801802 }
802803}
0 commit comments