Bladeren bron

Z991239-5104 #comment 优化录像库

80274480 1 jaar geleden
bovenliggende
commit
8607331f00

+ 24 - 27
Other/unix/libvideorecord/CvxText.cpp

@@ -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);

+ 1 - 3
Other/unix/libvideorecord/CvxText.h

@@ -28,8 +28,6 @@
 //#include"opnecv2/opencv.hpp"
 #include <opencv2/opencv.hpp>
 
-#include "libvideorecord.h"
-
 class CvxText  
 {
    // 禁止copy
@@ -45,7 +43,7 @@ public:
     * 装载字库文件
     */
 
-   CvxText(CHostApi* pHostApi, const char *freeType);
+   CvxText(const char *freeType);
    virtual ~CvxText();
 
    //================================================================

+ 1 - 1
Other/unix/libvideorecord/libvideorecord_impl.cpp

@@ -1316,7 +1316,7 @@ bool libvideorecord_impl::InitCvxText()
 	{
 		//m_pHostApi->Debug(RECORD_LOG_INFO, "Fontfile:%s", fontfile.c_str());
 		TtcDir += fontfile;
-		m_pText = new CvxText(m_pHostApi, TtcDir.c_str());
+		m_pText = new CvxText(TtcDir.c_str());
 		int type = 0;
 		CvScalar scalar = { 16, 0.3, 0.2, 0 }; //字体大小/空白比例/间隔比例/旋转角度
 		bool underline = false;

+ 3 - 0
Other/win/libvideorecord/CvxText.cpp

@@ -60,6 +60,7 @@ void CvxText::setFont(int *type, CvScalar *size, bool *underline, float *diaphan
    {
       if(type >= 0) m_fontType = *type;
    }
+
    if(size)
    {
       m_fontSize.val[0] = fabs(size->val[0]);
@@ -67,10 +68,12 @@ void CvxText::setFont(int *type, CvScalar *size, bool *underline, float *diaphan
       m_fontSize.val[2] = fabs(size->val[2]);
       m_fontSize.val[3] = fabs(size->val[3]);
    }
+
    if(underline)
    {
       m_fontUnderline   = *underline;
    }
+
    if(diaphaneity)
    {
       m_fontDiaphaneity = *diaphaneity;