2
2
3
3
#define NO_IMPORT_ARRAY
4
4
5
- #include < string>
6
5
#include < algorithm>
6
+ #include < stdexcept>
7
+ #include < string>
7
8
8
9
#include " ft2font.h"
9
10
#include " mplutils.h"
@@ -115,7 +116,7 @@ void FT2Image::draw_bitmap(FT_Bitmap *bitmap, FT_Int x, FT_Int y)
115
116
}
116
117
}
117
118
} else {
118
- throw " Unknown pixel mode" ;
119
+ throw std::runtime_error ( " Unknown pixel mode" ) ;
119
120
}
120
121
121
122
m_dirty = true ;
@@ -124,7 +125,7 @@ void FT2Image::draw_bitmap(FT_Bitmap *bitmap, FT_Int x, FT_Int y)
124
125
void FT2Image::draw_rect (unsigned long x0, unsigned long y0, unsigned long x1, unsigned long y1)
125
126
{
126
127
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" ) ;
128
129
}
129
130
130
131
size_t top = y0 * m_width;
@@ -170,7 +171,7 @@ int FT2Font::get_path_count()
170
171
// this code is from agg's decompose_ft_outline with minor modifications
171
172
172
173
if (!face->glyph ) {
173
- throw " No glyph loaded" ;
174
+ throw std::runtime_error ( " No glyph loaded" ) ;
174
175
}
175
176
176
177
FT_Outline &outline = face->glyph ->outline ;
@@ -208,7 +209,7 @@ int FT2Font::get_path_count()
208
209
209
210
// A contour cannot start with a cubic control point!
210
211
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" ) ;
212
213
} else if (tag == FT_CURVE_TAG_CONIC) {
213
214
starts_with_last = true ;
214
215
} else {
@@ -246,7 +247,7 @@ int FT2Font::get_path_count()
246
247
}
247
248
248
249
if (tag != FT_CURVE_TAG_CONIC) {
249
- throw " Invalid font" ;
250
+ throw std::runtime_error ( " Invalid font" ) ;
250
251
}
251
252
252
253
count += 2 ;
@@ -262,7 +263,7 @@ int FT2Font::get_path_count()
262
263
default : // FT_CURVE_TAG_CUBIC
263
264
{
264
265
if (point + 1 > limit || FT_CURVE_TAG (tags[1 ]) != FT_CURVE_TAG_CUBIC) {
265
- throw " Invalid font" ;
266
+ throw std::runtime_error ( " Invalid font" ) ;
266
267
}
267
268
268
269
point += 2 ;
@@ -492,13 +493,13 @@ FT2Font::FT2Font(FT_Open_Args &open_args, long hinting_factor_) : image(), face(
492
493
int error = FT_Open_Face (_ft2Library, &open_args, 0 , &face);
493
494
494
495
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." ) ;
496
497
} 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." ) ;
498
499
} 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." ) ;
500
501
} else if (error) {
501
- throw " Can not load face." ;
502
+ throw std::runtime_error ( " Can not load face." ) ;
502
503
}
503
504
504
505
// set a default fontsize 12 pt at 72dpi
@@ -507,7 +508,7 @@ FT2Font::FT2Font(FT_Open_Args &open_args, long hinting_factor_) : image(), face(
507
508
error = FT_Set_Char_Size (face, 12 * 64 , 0 , 72 * (unsigned int )hinting_factor, 72 );
508
509
if (error) {
509
510
FT_Done_Face (face);
510
- throw " Could not set the fontsize" ;
511
+ throw std::runtime_error ( " Could not set the fontsize" ) ;
511
512
}
512
513
513
514
if (open_args.stream != NULL ) {
@@ -551,25 +552,25 @@ void FT2Font::set_size(double ptsize, double dpi)
551
552
FT_Set_Transform (face, &transform, 0 );
552
553
553
554
if (error) {
554
- throw " Could not set the fontsize" ;
555
+ throw std::runtime_error ( " Could not set the fontsize" ) ;
555
556
}
556
557
}
557
558
558
559
void FT2Font::set_charmap (int i)
559
560
{
560
561
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" ) ;
562
563
}
563
564
FT_CharMap charmap = face->charmaps [i];
564
565
if (FT_Set_Charmap (face, charmap)) {
565
- throw " Could not set the charmap" ;
566
+ throw std::runtime_error ( " Could not set the charmap" ) ;
566
567
}
567
568
}
568
569
569
570
void FT2Font::select_charmap (unsigned long i)
570
571
{
571
572
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" ) ;
573
574
}
574
575
}
575
576
@@ -624,7 +625,7 @@ void FT2Font::set_text(
624
625
}
625
626
error = FT_Load_Glyph (face, glyph_index, flags);
626
627
if (error) {
627
- throw " could not load glyph" ;
628
+ throw std::runtime_error ( " could not load glyph" ) ;
628
629
}
629
630
// ignore errors, jump to next glyph
630
631
@@ -634,7 +635,7 @@ void FT2Font::set_text(
634
635
error = FT_Get_Glyph (face->glyph , &thisGlyph);
635
636
636
637
if (error) {
637
- throw " could not get glyph" ;
638
+ throw std::runtime_error ( " could not get glyph" ) ;
638
639
}
639
640
// ignore errors, jump to next glyph
640
641
@@ -670,14 +671,14 @@ void FT2Font::load_char(long charcode, FT_Int32 flags)
670
671
int error = FT_Load_Char (face, (unsigned long )charcode, flags);
671
672
672
673
if (error) {
673
- throw " Could not load charcode" ;
674
+ throw std::runtime_error ( " Could not load charcode" ) ;
674
675
}
675
676
676
677
FT_Glyph thisGlyph;
677
678
error = FT_Get_Glyph (face->glyph , &thisGlyph);
678
679
679
680
if (error) {
680
- throw " Could not get glyph" ;
681
+ throw std::runtime_error ( " Could not get glyph" ) ;
681
682
}
682
683
683
684
glyphs.push_back (thisGlyph);
@@ -688,14 +689,14 @@ void FT2Font::load_glyph(FT_UInt glyph_index, FT_Int32 flags)
688
689
int error = FT_Load_Glyph (face, glyph_index, flags);
689
690
690
691
if (error) {
691
- throw " Could not load glyph" ;
692
+ throw std::runtime_error ( " Could not load glyph" ) ;
692
693
}
693
694
694
695
FT_Glyph thisGlyph;
695
696
error = FT_Get_Glyph (face->glyph , &thisGlyph);
696
697
697
698
if (error) {
698
- throw " Could not load glyph" ;
699
+ throw std::runtime_error ( " Could not load glyph" ) ;
699
700
}
700
701
701
702
glyphs.push_back (thisGlyph);
@@ -729,7 +730,7 @@ void FT2Font::draw_glyphs_to_bitmap(bool antialiased)
729
730
error = FT_Glyph_To_Bitmap (
730
731
&glyphs[n], antialiased ? FT_RENDER_MODE_NORMAL : FT_RENDER_MODE_MONO, 0 , 1 );
731
732
if (error) {
732
- throw " Could not convert glyph to bitmap" ;
733
+ throw std::runtime_error ( " Could not convert glyph to bitmap" ) ;
733
734
}
734
735
735
736
FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyphs[n];
@@ -750,7 +751,7 @@ void FT2Font::get_xys(bool antialiased, std::vector<double> &xys)
750
751
error = FT_Glyph_To_Bitmap (
751
752
&glyphs[n], antialiased ? FT_RENDER_MODE_NORMAL : FT_RENDER_MODE_MONO, 0 , 1 );
752
753
if (error) {
753
- throw " Could not convert glyph to bitmap" ;
754
+ throw std::runtime_error ( " Could not convert glyph to bitmap" ) ;
754
755
}
755
756
756
757
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,
773
774
sub_offset.y = 0 ; // int((yd - (double)y) * 64.0);
774
775
775
776
if (glyphInd >= glyphs.size ()) {
776
- throw " glyph num is out of range" ;
777
+ throw std::runtime_error ( " glyph num is out of range" ) ;
777
778
}
778
779
779
780
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,
782
783
1 // destroy image
783
784
);
784
785
if (error) {
785
- throw " Could not convert glyph to bitmap" ;
786
+ throw std::runtime_error ( " Could not convert glyph to bitmap" ) ;
786
787
}
787
788
788
789
FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyphs[glyphInd];
@@ -798,7 +799,7 @@ void FT2Font::get_glyph_name(unsigned int glyph_number, char *buffer)
798
799
PyOS_snprintf (buffer, 128 , " uni%08x" , glyph_number);
799
800
} else {
800
801
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." ) ;
802
803
}
803
804
}
804
805
}
0 commit comments