@@ -67,7 +67,7 @@ class CV_EXPORTS_W FreeType2Impl CV_FINAL : public FreeType2
6767 FreeType2Impl ();
6868 ~FreeType2Impl ();
6969 void loadFontData (String fontFileName, int idx) CV_OVERRIDE;
70- void loadFontData (uchar * pBuf, size_t bufSize, int idx) CV_OVERRIDE;
70+ void loadFontData (char * pBuf, size_t bufSize, int idx) CV_OVERRIDE;
7171 void setSplitNumber ( int num ) CV_OVERRIDE;
7272 void putText (
7373 InputOutputArray img, const String& text, Point org,
@@ -88,6 +88,8 @@ class CV_EXPORTS_W FreeType2Impl CV_FINAL : public FreeType2
8888 int mCtoL ;
8989 hb_font_t *mHb_font ;
9090
91+ void loadFontData (FT_Open_Args &args, int idx);
92+
9193 void putTextBitmapMono (
9294 InputOutputArray img, const String& text, Point org,
9395 int fontHeight, Scalar color,
@@ -181,27 +183,41 @@ FreeType2Impl::~FreeType2Impl()
181183
182184void FreeType2Impl::loadFontData (String fontFileName, int idx)
183185{
184- CV_Assert ( idx >= 0 );
185- if ( mIsFaceAvailable == true )
186+ FT_Open_Args args
186187 {
187- hb_font_destroy (mHb_font );
188- CV_Assert (!FT_Done_Face (mFace ));
189- }
188+ FT_OPEN_PATHNAME,
189+ nullptr , // memory_base
190+ 0 , // memory_size
191+ const_cast <FT_String*>(fontFileName.c_str ()),
192+ nullptr , // stream
193+ nullptr , // driver
194+ 0 , // num_params
195+ nullptr // params
196+ };
190197
191- mIsFaceAvailable = false ;
192- CV_Assert ( ! FT_New_Face ( mLibrary , fontFileName. c_str (), static_cast <FT_Long>(idx), & mFace ) );
198+ this -> loadFontData (args, idx) ;
199+ }
193200
194- mHb_font = hb_ft_font_create (mFace , NULL );
195- if ( mHb_font == NULL )
201+ void FreeType2Impl::loadFontData (char * pBuf, size_t bufSize, int idx)
202+ {
203+ CV_Assert ( pBuf != nullptr );
204+
205+ FT_Open_Args args
196206 {
197- CV_Assert (!FT_Done_Face (mFace ));
198- return ;
199- }
200- CV_Assert ( mHb_font != NULL );
201- mIsFaceAvailable = true ;
207+ FT_OPEN_MEMORY,
208+ reinterpret_cast <FT_Byte*>(pBuf),
209+ static_cast <FT_Long>(bufSize),
210+ nullptr , // pathname
211+ nullptr , // stream
212+ nullptr , // driver
213+ 0 , // num_params
214+ nullptr // params
215+ };
216+
217+ this ->loadFontData (args, idx);
202218}
203219
204- void FreeType2Impl::loadFontData (uchar* pBuf, size_t bufSize , int idx)
220+ void FreeType2Impl::loadFontData (FT_Open_Args &args , int idx)
205221{
206222 CV_Assert ( idx >= 0 );
207223 if ( mIsFaceAvailable == true )
@@ -211,7 +227,6 @@ void FreeType2Impl::loadFontData(uchar* pBuf, size_t bufSize, int idx)
211227 }
212228
213229 mIsFaceAvailable = false ;
214- FT_Open_Args args{ FT_OPEN_MEMORY, (FT_Byte*)pBuf, static_cast <FT_Long>(bufSize), nullptr , nullptr , nullptr , 0 , nullptr };
215230 CV_Assert ( !FT_Open_Face (mLibrary , &args, idx, &mFace ) );
216231
217232 mHb_font = hb_ft_font_create (mFace , NULL );
0 commit comments