Merge pull request #3265 from BKNio:putText_develop

This commit is contained in:
Vadim Pisarevsky 2014-10-11 18:06:25 +00:00
commit b11b08b478

View File

@ -1925,7 +1925,11 @@ static const int HersheyComplex[] = {
2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026, 2223, 2084,
2224, 2247, 587, 2249, 2101, 2102, 2103, 2104, 2105, 2106, 2107, 2108, 2109, 2110, 2111,
2112, 2113, 2114, 2115, 2116, 2117, 2118, 2119, 2120, 2121, 2122, 2123, 2124, 2125, 2126,
2225, 2229, 2226, 2246 };
2225, 2229, 2226, 2246, 2801, 2802, 2803, 2804, 2805, 2806, 2807, 2808, 2809, 2810, 2811,
2812, 2813, 2814, 2815, 2816, 2817, 2818, 2819, 2820, 2821, 2822, 2823, 2824, 2825, 2826,
2827, 2828, 2829, 2830, 2831, 2832, 2901, 2902, 2903, 2904, 2905, 2906, 2907, 2908, 2909,
2910, 2911, 2912, 2913, 2914, 2915, 2916, 2917, 2918, 2919, 2920, 2921, 2922, 2923, 2924,
2925, 2926, 2927, 2928, 2929, 2930, 2931, 2932};
static const int HersheyComplexItalic[] = {
(9 + 12*16) + FONT_ITALIC_ALPHA + FONT_ITALIC_DIGIT + FONT_ITALIC_PUNCT +
@ -2017,6 +2021,51 @@ static const int* getFontData(int fontFace)
return ascii;
}
inline void readCheck(int &c, int &i, const string &text, int fontFace)
{
int leftBoundary = ' ', rightBoundary = 127;
if(c >= 0x80 && fontFace == FONT_HERSHEY_COMPLEX)
{
if(c >= 0xC0 && c <= 0xDF) //2 bytes utf
{
if(c & 1)
{
c = (uchar)text[++i] + 47;
leftBoundary = 175;
rightBoundary = 191;
}
else
{
c = (uchar)text[++i] - 17;
leftBoundary = 127;
rightBoundary = 175;
}
}
else
{
if(c >= 0xE0) //3 bytes utf
i++;
if(c >= 0xF0) //4 bytes utf
i++;
if(c >= 0xF8) //5 bytes utf
i++;
if(c >= 0xFC) //6 bytes utf
i++;
i++;
c = '?';
}
}
if(c >= rightBoundary || c < leftBoundary)
c = '?';
}
void putText( Mat& img, const string& text, Point org,
int fontFace, double fontScale, Scalar color,
@ -2048,8 +2097,7 @@ void putText( Mat& img, const string& text, Point org,
int c = (uchar)text[i];
Point p;
if( c >= 127 || c < ' ' )
c = '?';
readCheck(c, i, text, fontFace);
const char* ptr = faces[ascii[(c-' ')+1]];
p.x = (uchar)ptr[0] - 'R';
@ -2096,8 +2144,7 @@ Size getTextSize( const string& text, int fontFace, double fontScale, int thickn
int c = (uchar)text[i];
Point p;
if( c >= 127 || c < ' ' )
c = '?';
readCheck(c, i, text, fontFace);
const char* ptr = faces[ascii[(c-' ')+1]];
p.x = (uchar)ptr[0] - 'R';