|
@@ -13,36 +13,35 @@
|
|
|
|
|
|
// 打开字库
|
|
|
|
|
|
-CvxText::CvxText(CHostApi* pHostApi, const char *freeType)
|
|
|
+CvxText::CvxText( const char *freeType)
|
|
|
{
|
|
|
assert(freeType != NULL);
|
|
|
|
|
|
// 打开字库文件, 创建一个字体
|
|
|
|
|
|
- FT_Error error = FT_Init_FreeType(&m_library);
|
|
|
- if (error)
|
|
|
- {
|
|
|
- pHostApi->Debug(RECORD_LOG_DEBUG, "library FT_Init_FreeType error");
|
|
|
- return;
|
|
|
- }
|
|
|
- error = FT_New_Face(m_library, freeType, 0, &m_face);
|
|
|
- if (error == FT_Err_Unknown_File_Format)
|
|
|
- {
|
|
|
- pHostApi->Debug(RECORD_LOG_DEBUG, "FT_New_Face unsupported font format!");
|
|
|
- return;
|
|
|
- }
|
|
|
- else if (error)
|
|
|
- {
|
|
|
- pHostApi->Debug(RECORD_LOG_DEBUG, "FT_New_Face can not open font files, error: %d", error);
|
|
|
- return;
|
|
|
- }
|
|
|
- /*
|
|
|
+ //FT_Error error = FT_Init_FreeType(&m_library);
|
|
|
+ //if (error)
|
|
|
+ //{
|
|
|
+ // pHostApi->Debug(RECORD_LOG_DEBUG, "library FT_Init_FreeType error");
|
|
|
+ // return;
|
|
|
+ //}
|
|
|
+ //error = FT_New_Face(m_library, freeType, 0, &m_face);
|
|
|
+ //if (error == FT_Err_Unknown_File_Format)
|
|
|
+ //{
|
|
|
+ // pHostApi->Debug(RECORD_LOG_DEBUG, "FT_New_Face unsupported font format!");
|
|
|
+ // return;
|
|
|
+ //}
|
|
|
+ //else if (error)
|
|
|
+ //{
|
|
|
+ // pHostApi->Debug(RECORD_LOG_DEBUG, "FT_New_Face can not open font files, error: %d", error);
|
|
|
+ // return;
|
|
|
+ //}
|
|
|
+
|
|
|
if(FT_Init_FreeType(&m_library)) throw;
|
|
|
if(FT_New_Face(m_library, freeType, 0, &m_face)) throw;
|
|
|
- */
|
|
|
+
|
|
|
|
|
|
// 设置字体输出参数
|
|
|
-
|
|
|
restoreFont();
|
|
|
|
|
|
// 设置C语言的字符集环境
|
|
@@ -54,7 +53,7 @@ CvxText::CvxText(CHostApi* pHostApi, const char *freeType)
|
|
|
|
|
|
CvxText::~CvxText()
|
|
|
{
|
|
|
- FT_Done_Face (m_face);
|
|
|
+ FT_Done_Face(m_face);
|
|
|
FT_Done_FreeType(m_library);
|
|
|
}
|
|
|
|
|
@@ -116,7 +115,6 @@ void CvxText::restoreFont()
|
|
|
m_fontDiaphaneity = 1.0; // 色彩比例(可产生透明效果)
|
|
|
|
|
|
// 设置字符大小
|
|
|
-
|
|
|
FT_Set_Pixel_Sizes(m_face, (int)m_fontSize.val[0], 0);
|
|
|
}
|
|
|
|
|
@@ -156,6 +154,8 @@ int CvxText::putText(IplImage *img, const char *text, CvPoint pos, CvScalar colo
|
|
|
}
|
|
|
return i;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
int CvxText::putText(IplImage *img, const wchar_t *text, CvPoint pos, CvScalar color)
|
|
|
{
|
|
|
if(img == NULL) return -1;
|
|
@@ -177,14 +177,11 @@ int CvxText::putText(IplImage *img, const wchar_t *text, CvPoint pos, CvScalar c
|
|
|
|
|
|
void CvxText::putWChar(IplImage *img, wchar_t wc, CvPoint &pos, CvScalar color)
|
|
|
{
|
|
|
- // add by ly at 2016/12/28
|
|
|
- if (wc == 0x4E00)
|
|
|
- {
|
|
|
+ if (wc == 0x4E00){
|
|
|
pos.y -= (int)(m_fontSize.val[0]/2);
|
|
|
}
|
|
|
|
|
|
// 根据unicode生成字体的二值位图
|
|
|
-
|
|
|
FT_UInt glyph_index = FT_Get_Char_Index(m_face, wc);
|
|
|
FT_Load_Glyph(m_face, glyph_index, FT_LOAD_DEFAULT);
|
|
|
FT_Render_Glyph(m_face->glyph, FT_RENDER_MODE_MONO);
|