|
@@ -12,6 +12,65 @@ void GetStringSize(HDC hDC, const char* str, int* w, int* h)
|
|
if (h != 0) *h = size.cy;
|
|
if (h != 0) *h = size.cy;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+cv::Size GetTextSize(const char* str, int fontSize, const char* fn, bool italic, bool underline)
|
|
|
|
+{
|
|
|
|
+ HDC hDC = CreateCompatibleDC(0);
|
|
|
|
+ LOGFONTA lf;
|
|
|
|
+ lf.lfHeight = -fontSize;
|
|
|
|
+ lf.lfWidth = 0;
|
|
|
|
+ lf.lfEscapement = 0;
|
|
|
|
+ lf.lfOrientation = 0;
|
|
|
|
+ lf.lfWeight = 5;
|
|
|
|
+ lf.lfItalic = italic; //斜体
|
|
|
|
+ lf.lfUnderline = underline; //下划线
|
|
|
|
+ lf.lfStrikeOut = 0;
|
|
|
|
+ lf.lfCharSet = DEFAULT_CHARSET;
|
|
|
|
+ lf.lfOutPrecision = 0;
|
|
|
|
+ lf.lfClipPrecision = 0;
|
|
|
|
+ lf.lfQuality = PROOF_QUALITY;
|
|
|
|
+ lf.lfPitchAndFamily = 0;
|
|
|
|
+ strcpy_s(lf.lfFaceName, fn);
|
|
|
|
+
|
|
|
|
+ HFONT hf = CreateFontIndirectA(&lf);
|
|
|
|
+ HFONT hOldFont = (HFONT)SelectObject(hDC, hf);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ int strBaseW = 0, strBaseH = 0;
|
|
|
|
+ int singleRow = 0;
|
|
|
|
+ char buf[1 << 12];
|
|
|
|
+ strcpy_s(buf, str);
|
|
|
|
+ char *bufT[1 << 12]; // 这个用于分隔字符串后剩余的字符,可能会超出。
|
|
|
|
+ //处理多行
|
|
|
|
+ {
|
|
|
|
+ int nnh = 0;
|
|
|
|
+ int cw, ch;
|
|
|
|
+
|
|
|
|
+ const char* ln = strtok_s(buf, "\n", bufT);
|
|
|
|
+ while (ln != 0)
|
|
|
|
+ {
|
|
|
|
+ GetStringSize(hDC, ln, &cw, &ch);
|
|
|
|
+ strBaseW = max(strBaseW, cw);
|
|
|
|
+ strBaseH = max(strBaseH, ch);
|
|
|
|
+
|
|
|
|
+ ln = strtok_s(0, "\n", bufT);
|
|
|
|
+ nnh++;
|
|
|
|
+ }
|
|
|
|
+ singleRow = strBaseH;
|
|
|
|
+ strBaseH *= nnh;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ SelectObject(hDC, hOldFont);
|
|
|
|
+ DeleteObject(hf);
|
|
|
|
+ DeleteDC(hDC);
|
|
|
|
+
|
|
|
|
+ cv::Size size;
|
|
|
|
+ size.width = strBaseW;
|
|
|
|
+ size.height = strBaseH;
|
|
|
|
+ return size;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
void putTextZH(cv::Mat &dst, cv::Size & rSize, const char* str, Point org, Scalar color, int fontSize, const char* fn, bool italic, bool underline)
|
|
void putTextZH(cv::Mat &dst, cv::Size & rSize, const char* str, Point org, Scalar color, int fontSize, const char* fn, bool italic, bool underline)
|
|
{
|
|
{
|
|
CV_Assert(dst.data != 0 && (dst.channels() == 1 || dst.channels() == 3));
|
|
CV_Assert(dst.data != 0 && (dst.channels() == 1 || dst.channels() == 3));
|