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
@@ -622,7 +623,7 @@ void FT2Font::set_text(
622
623
}
623
624
error = FT_Load_Glyph (face, glyph_index, flags);
624
625
if (error) {
625
- throw " could not load glyph" ;
626
+ throw std::runtime_error ( " could not load glyph" ) ;
626
627
}
627
628
// ignore errors, jump to next glyph
628
629
@@ -632,7 +633,7 @@ void FT2Font::set_text(
632
633
error = FT_Get_Glyph (face->glyph , &thisGlyph);
633
634
634
635
if (error) {
635
- throw " could not get glyph" ;
636
+ throw std::runtime_error ( " could not get glyph" ) ;
636
637
}
637
638
// ignore errors, jump to next glyph
638
639
@@ -668,14 +669,14 @@ void FT2Font::load_char(long charcode, FT_Int32 flags)
668
669
int error = FT_Load_Char (face, (unsigned long )charcode, flags);
669
670
670
671
if (error) {
671
- throw " Could not load charcode" ;
672
+ throw std::runtime_error ( " Could not load charcode" ) ;
672
673
}
673
674
674
675
FT_Glyph thisGlyph;
675
676
error = FT_Get_Glyph (face->glyph , &thisGlyph);
676
677
677
678
if (error) {
678
- throw " Could not get glyph" ;
679
+ throw std::runtime_error ( " Could not get glyph" ) ;
679
680
}
680
681
681
682
glyphs.push_back (thisGlyph);
@@ -686,14 +687,14 @@ void FT2Font::load_glyph(FT_UInt glyph_index, FT_Int32 flags)
686
687
int error = FT_Load_Glyph (face, glyph_index, flags);
687
688
688
689
if (error) {
689
- throw " Could not load glyph" ;
690
+ throw std::runtime_error ( " Could not load glyph" ) ;
690
691
}
691
692
692
693
FT_Glyph thisGlyph;
693
694
error = FT_Get_Glyph (face->glyph , &thisGlyph);
694
695
695
696
if (error) {
696
- throw " Could not load glyph" ;
697
+ throw std::runtime_error ( " Could not load glyph" ) ;
697
698
}
698
699
699
700
glyphs.push_back (thisGlyph);
@@ -727,7 +728,7 @@ void FT2Font::draw_glyphs_to_bitmap(bool antialiased)
727
728
error = FT_Glyph_To_Bitmap (
728
729
&glyphs[n], antialiased ? FT_RENDER_MODE_NORMAL : FT_RENDER_MODE_MONO, 0 , 1 );
729
730
if (error) {
730
- throw " Could not convert glyph to bitmap" ;
731
+ throw std::runtime_error ( " Could not convert glyph to bitmap" ) ;
731
732
}
732
733
733
734
FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyphs[n];
@@ -748,7 +749,7 @@ void FT2Font::get_xys(bool antialiased, std::vector<double> &xys)
748
749
error = FT_Glyph_To_Bitmap (
749
750
&glyphs[n], antialiased ? FT_RENDER_MODE_NORMAL : FT_RENDER_MODE_MONO, 0 , 1 );
750
751
if (error) {
751
- throw " Could not convert glyph to bitmap" ;
752
+ throw std::runtime_error ( " Could not convert glyph to bitmap" ) ;
752
753
}
753
754
754
755
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,
771
772
sub_offset.y = 0 ; // int((yd - (double)y) * 64.0);
772
773
773
774
if (glyphInd >= glyphs.size ()) {
774
- throw " glyph num is out of range" ;
775
+ throw std::runtime_error ( " glyph num is out of range" ) ;
775
776
}
776
777
777
778
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,
780
781
1 // destroy image
781
782
);
782
783
if (error) {
783
- throw " Could not convert glyph to bitmap" ;
784
+ throw std::runtime_error ( " Could not convert glyph to bitmap" ) ;
784
785
}
785
786
786
787
FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyphs[glyphInd];
@@ -796,7 +797,7 @@ void FT2Font::get_glyph_name(unsigned int glyph_number, char *buffer)
796
797
PyOS_snprintf (buffer, 128 , " uni%08x" , glyph_number);
797
798
} else {
798
799
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." ) ;
800
801
}
801
802
}
802
803
}
0 commit comments