解决水印不支持中文的问题

This commit is contained in:
luoliangyi 2022-06-15 09:50:21 +08:00
parent 5dede65275
commit e74e0aeba6
7 changed files with 77 additions and 34 deletions

View File

@ -138,9 +138,9 @@ HGResult CvxText::DrawString(HGImage image, const HGChar* text, HGColor color, H
#endif
{
#if defined(HG_CMP_MSC)
DrawChar(image, pUnicode[i], locationX + vPos[i].left, locationY + vPos[i].top, color, fontSize, bold, italic);
DrawChar(image, pUnicode[i], color, locationX + vPos[i].left, locationY + vPos[i].top, fontSize, bold, italic);
#else
DrawChar(image, pUnicodeEx[i], locationX + vPos[i].left, locationY + vPos[i].top, color, fontSize, bold, italic);
DrawChar(image, pUnicodeEx[i], color, locationX + vPos[i].left, locationY + vPos[i].top, fontSize, bold, italic);
#endif
++i;
}
@ -149,17 +149,18 @@ HGResult CvxText::DrawString(HGImage image, const HGChar* text, HGColor color, H
if (underline)
{
HGImgProc_ImageDrawLine(image, locationX, locationY + height - 1, locationX + width, locationY + height - 1, 1, color);
HGImgProc_ImageDrawLine(image, locationX, locationY + height - 1,
locationX + width, locationY + height - 1, color, 1, HGIMGPROC_LINETYPE_SOLID);
}
if (strikeout)
{
if (underline)
HGImgProc_ImageDrawLine(image, locationX, locationY + (height - 1) / 2,
locationX + width, locationY + (height - 1) / 2, 1, color);
locationX + width, locationY + (height - 1) / 2, color, 1, HGIMGPROC_LINETYPE_SOLID);
else
HGImgProc_ImageDrawLine(image, locationX, locationY + height / 2,
locationX + width, locationY + height / 2, 1, color);
locationX + width, locationY + height / 2, color, 1, HGIMGPROC_LINETYPE_SOLID);
}
return HGBASE_ERR_OK;
@ -243,7 +244,7 @@ void CvxText::MeasureChar(HGUInt wc, HGUInt fontSize, HGBool bold, HGBool italic
{
FT_Matrix matrix;
matrix.xx = 0x10000L;
matrix.xy = 0.5f * 0x10000L;
matrix.xy = 0.4f * 0x10000L;
matrix.yx = 0;
matrix.yy = 0x10000L;
FT_Outline_Transform(&m_face->glyph->outline, &matrix);
@ -336,9 +337,11 @@ void CvxText::GetStringLocation(const HGChar* text, HGUInt fontSize, HGBool bold
}
}
void CvxText::DrawChar(HGImage image, HGUInt wc, HGInt x, HGInt y, HGColor color, HGUInt fontSize, HGBool bold, HGBool italic)
void CvxText::DrawChar(HGImage image, HGUInt wc, HGColor color, HGInt x, HGInt y, HGUInt fontSize, HGBool bold, HGBool italic)
{
assert(NULL != m_face);
assert(NULL != image);
assert(0 != fontSize);
FT_Set_Pixel_Sizes(m_face, fontSize, fontSize);
FT_UInt glyph_index = FT_Get_Char_Index(m_face, wc);
@ -358,7 +361,7 @@ void CvxText::DrawChar(HGImage image, HGUInt wc, HGInt x, HGInt y, HGColor color
{
FT_Matrix matrix;
matrix.xx = 0x10000L;
matrix.xy = 0.5f * 0x10000L;
matrix.xy = 0.4f * 0x10000L;
matrix.yx = 0;
matrix.yy = 0x10000L;
FT_Outline_Transform(&m_face->glyph->outline, &matrix);

View File

@ -24,7 +24,7 @@ private:
void MeasureChar(HGUInt wc, HGUInt fontSize, HGBool bold, HGBool italic, FT_BBox& acbox);
void GetStringLocation(const HGChar* text, HGUInt fontSize, HGBool bold, HGBool underline, HGBool italic, HGBool strikeout,
HGUInt &width, HGUInt &height, std::vector<HGRect> &vPos);
void DrawChar(HGImage image, HGUInt wc, HGInt x, HGInt y, HGColor color, HGUInt fontSize, HGBool bold, HGBool italic);
void DrawChar(HGImage image, HGUInt wc, HGColor color, HGInt x, HGInt y, HGUInt fontSize, HGBool bold, HGBool italic);
private:
FT_Library m_library;

View File

@ -366,32 +366,23 @@ HGResult HGAPI HGImgProc_ImageBlankCheck(HGImage image, const HGImgBlankCheckPar
return HGBASE_ERR_OK;
}
HGResult HGAPI HGImgProc_ImageDrawLine(HGImage image, HGInt x1, HGInt y1, HGInt x2, HGInt y2, HGUInt lineWidth, HGColor color)
HGResult HGAPI HGImgProc_ImageDrawLine(HGImage image, HGInt x1, HGInt y1, HGInt x2, HGInt y2,
HGColor color, HGUInt width, HGUInt type)
{
if (NULL == image || 0 == lineWidth)
if (NULL == image || 0 == width || type < HGIMGPROC_LINETYPE_SOLID || type > HGIMGPROC_LINETYPE_DASH)
{
return HGBASE_ERR_INVALIDARG;
}
HGImageInfo imgInfo;
HGBase_GetImageInfo(image, &imgInfo);
uint32_t type = imgInfo.type;
HGByte* data = NULL;
HGBase_GetImageData(image, &data);
HGImageRoi roi;
HGBase_GetImageROI(image, &roi);
HGUInt roiWidth = roi.right - roi.left;
HGUInt roiHeight = roi.bottom - roi.top;
if (HGBASE_IMGTYPE_BINARY == type || HGBASE_IMGTYPE_GRAY == type)
if (HGBASE_IMGTYPE_BINARY == imgInfo.type || HGBASE_IMGTYPE_GRAY == imgInfo.type)
{
HGImage imageTmp = NULL;
HGResult ret = HGBase_CloneImage(image, HGBASE_IMGTYPE_RGB, 0, &imageTmp);
if (HGBASE_ERR_OK == ret)
{
ret = HGImgProc_ImageDrawLine(imageTmp, x1, y1, x2, y2, lineWidth, color);
ret = HGImgProc_ImageDrawLine(imageTmp, x1, y1, x2, y2, color, width, type);
if (HGBASE_ERR_OK == ret)
{
ret = HGBase_CopyImage(imageTmp, image);
@ -403,8 +394,16 @@ HGResult HGAPI HGImgProc_ImageDrawLine(HGImage image, HGInt x1, HGInt y1, HGInt
return ret;
}
HGByte* data = NULL;
HGBase_GetImageData(image, &data);
HGImageRoi roi;
HGBase_GetImageROI(image, &roi);
HGUInt roiWidth = roi.right - roi.left;
HGUInt roiHeight = roi.bottom - roi.top;
uint32_t channels = 3;
if (HGBASE_IMGTYPE_BGRA == type || HGBASE_IMGTYPE_RGBA == type)
if (HGBASE_IMGTYPE_BGRA == imgInfo.type || HGBASE_IMGTYPE_RGBA == imgInfo.type)
channels = 4;
uint8_t* p = data + roi.top * imgInfo.widthStep + roi.left * channels;
@ -423,14 +422,14 @@ HGResult HGAPI HGImgProc_ImageDrawLine(HGImage image, HGInt x1, HGInt y1, HGInt
HGUInt r = HG_GETCOLOR_R(color);
HGUInt g = HG_GETCOLOR_G(color);
HGUInt b = HG_GETCOLOR_B(color);
if (HGBASE_IMGTYPE_BGR == type || HGBASE_IMGTYPE_BGRA == type)
if (HGBASE_IMGTYPE_BGR == imgInfo.type || HGBASE_IMGTYPE_BGRA == imgInfo.type)
{
r = HG_GETCOLOR_B(color);
g = HG_GETCOLOR_G(color);
b = HG_GETCOLOR_R(color);
}
cvLine(pImg, cvPoint(x1, y1), cvPoint(x2, y2), cvScalar(r, g, b), lineWidth);
cvLine(pImg, cvPoint(x1, y1), cvPoint(x2, y2), cvScalar(r, g, b), width);
cvReleaseImageHeader(&pImg);
return HGBASE_ERR_OK;
}

View File

@ -11,16 +11,30 @@
/* 双线性插值 */
#define HGIMGPROC_INTERPOTYPE_LINEAR 2L
/* 水印位置 */
/* 线条类型-实线 */
#define HGIMGPROC_LINETYPE_SOLID 1L
/* 线条类型-虚线 */
#define HGIMGPROC_LINETYPE_DASH 2L
/* 水印位置-左侧 */
#define HGIMGPROC_WMPOSTYPE_LEFT 1L
/* 水印位置-上侧 */
#define HGIMGPROC_WMPOSTYPE_TOP 2L
/* 水印位置-右侧 */
#define HGIMGPROC_WMPOSTYPE_RIGHT 3L
/* 水印位置-下侧 */
#define HGIMGPROC_WMPOSTYPE_BOTTOM 4L
/* 水印位置-左上 */
#define HGIMGPROC_WMPOSTYPE_LEFTTOP 5L
/* 水印位置-右上 */
#define HGIMGPROC_WMPOSTYPE_RIGHTTOP 6L
/* 水印位置-左下 */
#define HGIMGPROC_WMPOSTYPE_LEFTBOTTOM 7L
/* 水印位置-右下 */
#define HGIMGPROC_WMPOSTYPE_RIGHTBOTTOM 8L
/* 水印位置-中间 */
#define HGIMGPROC_WMPOSTYPE_CENTER 9L
/* 水印位置-自定义 */
#define HGIMGPROC_WMPOSTYPE_LOCATION 10L
/* 自动裁剪参数 */
@ -112,9 +126,20 @@ HGEXPORT HGResult HGAPI HGImgProc_ImageAutoCrop(HGImage image, HGBool autoCrop,
*/
HGEXPORT HGResult HGAPI HGImgProc_ImageBlankCheck(HGImage image, const HGImgBlankCheckParam *param, HGBool *blank);
/* 画线
/* 图像画线
* 1) image: in,
* 2) x1: in, x坐标
* 3) y1: in, y坐标
* 4) x2: in, x坐标
* 5) y2: in, y坐标
* 6) color: in,
* 7) width: in, 线
* 8) type: in, 线, HGIMGPROC_LINETYPE_*
* :
* 1) ROI区域
*/
HGEXPORT HGResult HGAPI HGImgProc_ImageDrawLine(HGImage image, HGInt x1, HGInt y1, HGInt x2, HGInt y2, HGUInt lineWidth, HGColor color);
HGEXPORT HGResult HGAPI HGImgProc_ImageDrawLine(HGImage image, HGInt x1, HGInt y1, HGInt x2, HGInt y2,
HGColor color, HGUInt width, HGUInt type);
/* 添加图像水印
* 1) image: in,

View File

@ -3602,6 +3602,22 @@ namespace ver_2
FindClose(hFind);
#else
DIR* dir = opendir(m_bindFolder.c_str());
if (NULL != dir)
{
struct dirent* dire = NULL;
while (dire = readdir(dir))
{
char fileName[256];
sprintf(fileName, "%s%s", m_bindFolder.c_str(), dire->d_name);
if (!IS_DIR(fileName))
{
HGBase_DeleteFile(fileName);
}
}
closedir(dir);
}
#endif
}
@ -3743,9 +3759,9 @@ namespace ver_2
char destName[256];
sprintf(destName, fmt, m_bindFolder.c_str(), m_bindNameBase + tables[i].idx - value, tables[i].format.c_str());
#if defined(HG_CMP_MSC)
MoveFileA(fileName, destName);
MoveFileA(fileName, destName);
#else
rename(fileName, destName);
rename(fileName, destName);
#endif
}
}

View File

@ -1775,7 +1775,7 @@ namespace ver_2
assert(NULL != json);
std::string imagePath = Utf8ToStdString(GetJsonStringValue(json, "image_path"));
std::string text = GetJsonStringValue(json, "text");
std::string text = Utf8ToStdString(GetJsonStringValue(json, "text"));
bool find;
std::string textColor = GetJsonStringValue(json, "text_color", &find);
@ -4129,7 +4129,7 @@ namespace ver_2
assert(NULL != json);
int imageIndex = GetJsonIntValue(json, "image_index");
std::string text = GetJsonStringValue(json, "text");
std::string text = Utf8ToStdString(GetJsonStringValue(json, "text"));
bool find;
std::string textColor = GetJsonStringValue(json, "text_color", &find);

View File

@ -369,7 +369,7 @@
socket.send(JSON.stringify({
'func':'local_image_add_watermark',
'image_path':'D:\\1.jpg',
'text':'1234567890',
'text':'扫描仪1234qwer',
'text_color':'#FF0000',
'text_pos':'right_top',
'font_size':60,