HWndMessage.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. #include "HWndMessage.h"
  2. #include "HalconCpp.h"
  3. #include <QDebug>
  4. #include <QString>
  5. using namespace HalconCpp;
  6. HWndMessage::HWndMessage()
  7. {
  8. isInitialized=false;
  9. row = 0;
  10. colunm = 0;
  11. size = 0;
  12. }
  13. HWndMessage::HWndMessage(HTuple message, int row, int colunm, int size, HTuple color)
  14. {
  15. this->message = message;
  16. this->size = size;
  17. this->row = row;
  18. this->colunm = colunm;
  19. this->color = color;
  20. isInitialized=true;
  21. }
  22. HWndMessage::HWndMessage(HTuple message, int row, int colunm)
  23. {
  24. this->message = message;
  25. this->row = row;
  26. this->colunm = colunm;
  27. isInitialized=true;
  28. }
  29. void HWndMessage::dispMessage(HTuple winID,QString coordSystem,double zoom)
  30. {
  31. try
  32. {
  33. setDisplayFont(winID, size * zoom, "serif", "true", "false");
  34. dispMessage(winID, message, coordSystem.toLocal8Bit().data(), row, colunm, color, "false");
  35. }
  36. catch (...)
  37. {
  38. qDebug() << "error";
  39. }
  40. }
  41. bool HWndMessage::IsInitialized() const
  42. {
  43. return isInitialized;
  44. }
  45. HWndMessage HWndMessage::clone() const
  46. {
  47. HWndMessage tmp=HWndMessage(this->message,this->row,this->colunm,
  48. this->size,this->color);
  49. return tmp;
  50. }
  51. void HWndMessage::dispMessage(HTuple hv_WindowHandle, HTuple hv_String,
  52. HTuple hv_CoordSystem, HTuple hv_Row,
  53. HTuple hv_Column, HTuple hv_Color,
  54. HTuple hv_Box)
  55. {
  56. // Local iconic variables
  57. // Local control variables
  58. HTuple hv_Red, hv_Green, hv_Blue, hv_Row1Part;
  59. HTuple hv_Column1Part, hv_Row2Part, hv_Column2Part, hv_RowWin;
  60. HTuple hv_ColumnWin, hv_WidthWin, hv_HeightWin, hv_MaxAscent;
  61. HTuple hv_MaxDescent, hv_MaxWidth, hv_MaxHeight, hv_R1;
  62. HTuple hv_C1, hv_FactorRow, hv_FactorColumn, hv_UseShadow;
  63. HTuple hv_ShadowColor, hv_Exception, hv_Width, hv_Index;
  64. HTuple hv_Ascent, hv_Descent, hv_W, hv_H, hv_FrameHeight;
  65. HTuple hv_FrameWidth, hv_R2, hv_C2, hv_DrawMode, hv_CurrentColor;
  66. //This procedure displays text in a graphics window.
  67. //
  68. //Input parameters:
  69. //WindowHandle: The WindowHandle of the graphics window, where
  70. // the message should be displayed
  71. //String: A tuple of strings containing the text message to be displayed
  72. //CoordSystem: If set to 'window', the text position is given
  73. // with respect to the window coordinate system.
  74. // If set to 'image', image coordinates are used.
  75. // (This may be useful in zoomed images.)
  76. //Row: The row coordinate of the desired text position
  77. // If set to -1, a default value of 12 is used.
  78. //Column: The column coordinate of the desired text position
  79. // If set to -1, a default value of 12 is used.
  80. //Color: defines the color of the text as string.
  81. // If set to [], '' or 'auto' the currently set color is used.
  82. // If a tuple of strings is passed, the colors are used cyclically
  83. // for each new textline.
  84. //Box: If Box[0] is set to 'true', the text is written within an orange box.
  85. // If set to' false', no box is displayed.
  86. // If set to a color string (e.g. 'white', '#FF00CC', etc.),
  87. // the text is written in a box of that color.
  88. // An optional second value for Box (Box[1]) controls if a shadow is displayed:
  89. // 'true' -> display a shadow in a default color
  90. // 'false' -> display no shadow (same as if no second value is given)
  91. // otherwise -> use given string as color string for the shadow color
  92. //
  93. //Prepare window
  94. GetRgb(hv_WindowHandle, &hv_Red, &hv_Green, &hv_Blue);
  95. GetPart(hv_WindowHandle, &hv_Row1Part, &hv_Column1Part, &hv_Row2Part, &hv_Column2Part);
  96. GetWindowExtents(hv_WindowHandle, &hv_RowWin, &hv_ColumnWin, &hv_WidthWin, &hv_HeightWin);
  97. SetPart(hv_WindowHandle, 0, 0, hv_HeightWin - 1, hv_WidthWin - 1);
  98. //
  99. //default settings
  100. if (0 != (hv_Row == -1))
  101. {
  102. hv_Row = 12;
  103. }
  104. if (0 != (hv_Column == -1))
  105. {
  106. hv_Column = 12;
  107. }
  108. if (0 != (hv_Color == HTuple()))
  109. {
  110. hv_Color = "";
  111. }
  112. //
  113. hv_String = (("" + hv_String) + "").TupleSplit("\n");
  114. //
  115. //Estimate extentions of text depending on font size.
  116. GetFontExtents(hv_WindowHandle, &hv_MaxAscent, &hv_MaxDescent, &hv_MaxWidth, &hv_MaxHeight);
  117. if (0 != (hv_CoordSystem == HTuple("window")))
  118. {
  119. hv_R1 = hv_Row;
  120. hv_C1 = hv_Column;
  121. }
  122. else
  123. {
  124. //Transform image to window coordinates
  125. hv_FactorRow = (1.*hv_HeightWin) / ((hv_Row2Part - hv_Row1Part) + 1);
  126. hv_FactorColumn = (1.*hv_WidthWin) / ((hv_Column2Part - hv_Column1Part) + 1);
  127. hv_R1 = ((hv_Row - hv_Row1Part) + 0.5)*hv_FactorRow;
  128. hv_C1 = ((hv_Column - hv_Column1Part) + 0.5)*hv_FactorColumn;
  129. }
  130. //
  131. //Display text box depending on text size
  132. hv_UseShadow = 1;
  133. hv_ShadowColor = "gray";
  134. if (0 != (HTuple(hv_Box[0]) == HTuple("true")))
  135. {
  136. hv_Box[0] = "#fce9d4";
  137. hv_ShadowColor = "#f28d26";
  138. }
  139. if (0 != ((hv_Box.TupleLength()) > 1))
  140. {
  141. if (0 != (HTuple(hv_Box[1]) == HTuple("true")))
  142. {
  143. //Use default ShadowColor set above
  144. }
  145. else if (0 != (HTuple(hv_Box[1]) == HTuple("false")))
  146. {
  147. hv_UseShadow = 0;
  148. }
  149. else
  150. {
  151. hv_ShadowColor = ((const HTuple&)hv_Box)[1];
  152. //Valid color?
  153. try
  154. {
  155. SetColor(hv_WindowHandle, HTuple(hv_Box[1]));
  156. }
  157. // catch (Exception)
  158. catch (HalconCpp::HException &HDevExpDefaultException)
  159. {
  160. HDevExpDefaultException.ToHTuple(&hv_Exception);
  161. hv_Exception = "Wrong value of control parameter Box[1] (must be a 'true', 'false', or a valid color string)";
  162. throw HalconCpp::HException(hv_Exception);
  163. }
  164. }
  165. }
  166. if (0 != (HTuple(hv_Box[0]) != HTuple("false")))
  167. {
  168. //Valid color?
  169. try
  170. {
  171. SetColor(hv_WindowHandle, HTuple(hv_Box[0]));
  172. }
  173. // catch (Exception)
  174. catch (HalconCpp::HException &HDevExpDefaultException)
  175. {
  176. HDevExpDefaultException.ToHTuple(&hv_Exception);
  177. hv_Exception = "Wrong value of control parameter Box[0] (must be a 'true', 'false', or a valid color string)";
  178. throw HalconCpp::HException(hv_Exception);
  179. }
  180. //Calculate box extents
  181. hv_String = (" " + hv_String) + " ";
  182. hv_Width = HTuple();
  183. {
  184. HTuple end_val93 = (hv_String.TupleLength()) - 1;
  185. HTuple step_val93 = 1;
  186. for (hv_Index = 0; hv_Index.Continue(end_val93, step_val93); hv_Index += step_val93)
  187. {
  188. GetStringExtents(hv_WindowHandle, HTuple(hv_String[hv_Index]), &hv_Ascent,
  189. &hv_Descent, &hv_W, &hv_H);
  190. hv_Width = hv_Width.TupleConcat(hv_W);
  191. }
  192. }
  193. hv_FrameHeight = hv_MaxHeight*(hv_String.TupleLength());
  194. hv_FrameWidth = (HTuple(0).TupleConcat(hv_Width)).TupleMax();
  195. hv_R2 = hv_R1 + hv_FrameHeight;
  196. hv_C2 = hv_C1 + hv_FrameWidth;
  197. //Display rectangles
  198. GetDraw(hv_WindowHandle, &hv_DrawMode);
  199. SetDraw(hv_WindowHandle, "fill");
  200. //Set shadow color
  201. SetColor(hv_WindowHandle, hv_ShadowColor);
  202. if (0 != hv_UseShadow)
  203. {
  204. DispRectangle1(hv_WindowHandle, hv_R1 + 1, hv_C1 + 1, hv_R2 + 1, hv_C2 + 1);
  205. }
  206. //Set box color
  207. SetColor(hv_WindowHandle, HTuple(hv_Box[0]));
  208. DispRectangle1(hv_WindowHandle, hv_R1, hv_C1, hv_R2, hv_C2);
  209. SetDraw(hv_WindowHandle, hv_DrawMode);
  210. }
  211. //Write text.
  212. {
  213. HTuple end_val115 = (hv_String.TupleLength()) - 1;
  214. HTuple step_val115 = 1;
  215. for (hv_Index = 0; hv_Index.Continue(end_val115, step_val115); hv_Index += step_val115)
  216. {
  217. hv_CurrentColor = ((const HTuple&)hv_Color)[hv_Index % (hv_Color.TupleLength())];
  218. if (0 != (HTuple(hv_CurrentColor != HTuple("")).TupleAnd(hv_CurrentColor != HTuple("auto"))))
  219. {
  220. SetColor(hv_WindowHandle, hv_CurrentColor);
  221. }
  222. else
  223. {
  224. SetRgb(hv_WindowHandle, hv_Red, hv_Green, hv_Blue);
  225. }
  226. hv_Row = hv_R1 + (hv_MaxHeight*hv_Index);
  227. SetTposition(hv_WindowHandle, hv_Row, hv_C1);
  228. WriteString(hv_WindowHandle, HTuple(hv_String[hv_Index]));
  229. }
  230. }
  231. //Reset changed window settings
  232. SetRgb(hv_WindowHandle, hv_Red, hv_Green, hv_Blue);
  233. SetPart(hv_WindowHandle, hv_Row1Part, hv_Column1Part, hv_Row2Part, hv_Column2Part);
  234. return;
  235. }
  236. void HWndMessage::setDisplayFont(HTuple hv_WindowHandle,
  237. HTuple hv_Size, HTuple hv_Font,
  238. HTuple hv_Bold, HTuple hv_Slant)
  239. {
  240. // Local iconic variables
  241. // Local control variables
  242. HTuple hv_OS, hv_BufferWindowHandle, hv_Ascent;
  243. HTuple hv_Descent, hv_Width, hv_Height, hv_Scale, hv_Exception;
  244. HTuple hv_SubFamily, hv_Fonts, hv_SystemFonts, hv_Guess;
  245. HTuple hv_I, hv_Index, hv_AllowedFontSizes, hv_Distances;
  246. HTuple hv_Indices, hv_FontSelRegexp, hv_FontsCourier;
  247. //This procedure sets the text font of the current window with
  248. //the specified attributes.
  249. //It is assumed that following fonts are installed on the system:
  250. //Windows: Courier New, Arial Times New Roman
  251. //Mac OS X: CourierNewPS, Arial, TimesNewRomanPS
  252. //Linux: courier, helvetica, times
  253. //Because fonts are displayed smaller on Linux than on Windows,
  254. //a scaling factor of 1.25 is used the get comparable results.
  255. //For Linux, only a limited number of font sizes is supported,
  256. //to get comparable results, it is recommended to use one of the
  257. //following sizes: 9, 11, 14, 16, 20, 27
  258. //(which will be mapped internally on Linux systems to 11, 14, 17, 20, 25, 34)
  259. //
  260. //Input parameters:
  261. //WindowHandle: The graphics window for which the font will be set
  262. //Size: The font size. If Size=-1, the default of 16 is used.
  263. //Bold: If set to 'true', a bold font is used
  264. //Slant: If set to 'true', a slanted font is used
  265. //
  266. GetSystem("operating_system", &hv_OS);
  267. // dev_get_preferences(...); only in hdevelop
  268. // dev_set_preferences(...); only in hdevelop
  269. if (0 != (HTuple(hv_Size == HTuple()).TupleOr(hv_Size == -1)))
  270. {
  271. hv_Size = 16;
  272. }
  273. if (0 != ((hv_OS.TupleSubstr(0, 2)) == HTuple("Win")))
  274. {
  275. //Set font on Windows systems
  276. try
  277. {
  278. //Check, if font scaling is switched on
  279. OpenWindow(0, 0, 256, 256, 0, "buffer", "", &hv_BufferWindowHandle);
  280. HTuple hv_Fonts, hv_FontWithSize;
  281. QueryFont(hv_BufferWindowHandle, &hv_Fonts);
  282. hv_FontWithSize = HTuple(hv_Fonts[0]) + "-16";
  283. SetFont(hv_BufferWindowHandle, hv_FontWithSize);
  284. // SetFont(hv_BufferWindowHandle, "-Consolas-16-*-0-*-*-1-");
  285. GetStringExtents(hv_BufferWindowHandle, "test_string", &hv_Ascent, &hv_Descent,
  286. &hv_Width, &hv_Height);
  287. //Expected width is 110
  288. hv_Scale = 110.0 / hv_Width;
  289. hv_Size = (hv_Size*hv_Scale).TupleInt();
  290. CloseWindow(hv_BufferWindowHandle);
  291. }
  292. // catch (Exception)
  293. catch (HalconCpp::HException &HDevExpDefaultException)
  294. {
  295. HDevExpDefaultException.ToHTuple(&hv_Exception);
  296. //throw (Exception)
  297. }
  298. if (0 != (HTuple(hv_Font == HTuple("Courier")).TupleOr(hv_Font == HTuple("courier"))))
  299. {
  300. hv_Font = "Courier New";
  301. }
  302. else if (0 != (hv_Font == HTuple("mono")))
  303. {
  304. hv_Font = "Consolas";
  305. }
  306. else if (0 != (hv_Font == HTuple("sans")))
  307. {
  308. hv_Font = "Arial";
  309. }
  310. else if (0 != (hv_Font == HTuple("serif")))
  311. {
  312. hv_Font = "Times New Roman";
  313. }
  314. if (0 != (hv_Bold == HTuple("true")))
  315. {
  316. hv_Bold = 1;
  317. }
  318. else if (0 != (hv_Bold == HTuple("false")))
  319. {
  320. hv_Bold = 0;
  321. }
  322. else
  323. {
  324. hv_Exception = "Wrong value of control parameter Bold";
  325. throw HalconCpp::HException(hv_Exception);
  326. }
  327. if (0 != (hv_Slant == HTuple("true")))
  328. {
  329. hv_Slant = 1;
  330. }
  331. else if (0 != (hv_Slant == HTuple("false")))
  332. {
  333. hv_Slant = 0;
  334. }
  335. else
  336. {
  337. hv_Exception = "Wrong value of control parameter Slant";
  338. throw HalconCpp::HException(hv_Exception);
  339. }
  340. try
  341. {
  342. HTuple hv_Fonts, hv_FontWithSize;
  343. QueryFont(hv_WindowHandle, &hv_Fonts);
  344. hv_FontWithSize = HTuple(hv_Fonts[0]) + "-16";
  345. SetFont(hv_WindowHandle, hv_FontWithSize);
  346. // SetFont(hv_WindowHandle, ((((((("-" + hv_Font) + "-") + hv_Size) + "-*-") + hv_Slant) + "-*-*-") + hv_Bold) + "-");
  347. }
  348. // catch (Exception)
  349. catch (HalconCpp::HException &HDevExpDefaultException)
  350. {
  351. HDevExpDefaultException.ToHTuple(&hv_Exception);
  352. //throw (Exception)
  353. }
  354. }
  355. else if (0 != ((hv_OS.TupleSubstr(0, 2)) == HTuple("Dar")))
  356. {
  357. //Set font on Mac OS X systems. Since OS X does not have a strict naming
  358. //scheme for font attributes, we use tables to determine the correct font
  359. //name.
  360. hv_SubFamily = 0;
  361. if (0 != (hv_Slant == HTuple("true")))
  362. {
  363. hv_SubFamily = hv_SubFamily | 1;
  364. }
  365. else if (0 != (hv_Slant != HTuple("false")))
  366. {
  367. hv_Exception = "Wrong value of control parameter Slant";
  368. throw HalconCpp::HException(hv_Exception);
  369. }
  370. if (0 != (hv_Bold == HTuple("true")))
  371. {
  372. hv_SubFamily = hv_SubFamily | 2;
  373. }
  374. else if (0 != (hv_Bold != HTuple("false")))
  375. {
  376. hv_Exception = "Wrong value of control parameter Bold";
  377. throw HalconCpp::HException(hv_Exception);
  378. }
  379. if (0 != (hv_Font == HTuple("mono")))
  380. {
  381. hv_Fonts.Clear();
  382. hv_Fonts[0] = "Menlo-Regular";
  383. hv_Fonts[1] = "Menlo-Italic";
  384. hv_Fonts[2] = "Menlo-Bold";
  385. hv_Fonts[3] = "Menlo-BoldItalic";
  386. }
  387. else if (0 != (HTuple(hv_Font == HTuple("Courier")).TupleOr(hv_Font == HTuple("courier"))))
  388. {
  389. hv_Fonts.Clear();
  390. hv_Fonts[0] = "CourierNewPSMT";
  391. hv_Fonts[1] = "CourierNewPS-ItalicMT";
  392. hv_Fonts[2] = "CourierNewPS-BoldMT";
  393. hv_Fonts[3] = "CourierNewPS-BoldItalicMT";
  394. }
  395. else if (0 != (hv_Font == HTuple("sans")))
  396. {
  397. hv_Fonts.Clear();
  398. hv_Fonts[0] = "ArialMT";
  399. hv_Fonts[1] = "Arial-ItalicMT";
  400. hv_Fonts[2] = "Arial-BoldMT";
  401. hv_Fonts[3] = "Arial-BoldItalicMT";
  402. }
  403. else if (0 != (hv_Font == HTuple("serif")))
  404. {
  405. hv_Fonts.Clear();
  406. hv_Fonts[0] = "TimesNewRomanPSMT";
  407. hv_Fonts[1] = "TimesNewRomanPS-ItalicMT";
  408. hv_Fonts[2] = "TimesNewRomanPS-BoldMT";
  409. hv_Fonts[3] = "TimesNewRomanPS-BoldItalicMT";
  410. }
  411. else
  412. {
  413. //Attempt to figure out which of the fonts installed on the system
  414. //the user could have meant.
  415. QueryFont(hv_WindowHandle, &hv_SystemFonts);
  416. hv_Fonts.Clear();
  417. hv_Fonts.Append(hv_Font);
  418. hv_Fonts.Append(hv_Font);
  419. hv_Fonts.Append(hv_Font);
  420. hv_Fonts.Append(hv_Font);
  421. hv_Guess.Clear();
  422. hv_Guess.Append(hv_Font);
  423. hv_Guess.Append(hv_Font + "-Regular");
  424. hv_Guess.Append(hv_Font + "MT");
  425. {
  426. HTuple end_val100 = (hv_Guess.TupleLength()) - 1;
  427. HTuple step_val100 = 1;
  428. for (hv_I = 0; hv_I.Continue(end_val100, step_val100); hv_I += step_val100)
  429. {
  430. TupleFind(hv_SystemFonts, HTuple(hv_Guess[hv_I]), &hv_Index);
  431. if (0 != (hv_Index != -1))
  432. {
  433. hv_Fonts[0] = HTuple(hv_Guess[hv_I]);
  434. break;
  435. }
  436. }
  437. }
  438. //Guess name of slanted font
  439. hv_Guess.Clear();
  440. hv_Guess.Append(hv_Font + "-Italic");
  441. hv_Guess.Append(hv_Font + "-ItalicMT");
  442. hv_Guess.Append(hv_Font + "-Oblique");
  443. {
  444. HTuple end_val109 = (hv_Guess.TupleLength()) - 1;
  445. HTuple step_val109 = 1;
  446. for (hv_I = 0; hv_I.Continue(end_val109, step_val109); hv_I += step_val109)
  447. {
  448. TupleFind(hv_SystemFonts, HTuple(hv_Guess[hv_I]), &hv_Index);
  449. if (0 != (hv_Index != -1))
  450. {
  451. hv_Fonts[1] = HTuple(hv_Guess[hv_I]);
  452. break;
  453. }
  454. }
  455. }
  456. //Guess name of bold font
  457. hv_Guess.Clear();
  458. hv_Guess.Append(hv_Font + "-Bold");
  459. hv_Guess.Append(hv_Font + "-BoldMT");
  460. {
  461. HTuple end_val118 = (hv_Guess.TupleLength()) - 1;
  462. HTuple step_val118 = 1;
  463. for (hv_I = 0; hv_I.Continue(end_val118, step_val118); hv_I += step_val118)
  464. {
  465. TupleFind(hv_SystemFonts, HTuple(hv_Guess[hv_I]), &hv_Index);
  466. if (0 != (hv_Index != -1))
  467. {
  468. hv_Fonts[2] = HTuple(hv_Guess[hv_I]);
  469. break;
  470. }
  471. }
  472. }
  473. //Guess name of bold slanted font
  474. hv_Guess.Clear();
  475. hv_Guess.Append(hv_Font + "-BoldItalic");
  476. hv_Guess.Append(hv_Font + "-BoldItalicMT");
  477. hv_Guess.Append(hv_Font + "-BoldOblique");
  478. {
  479. HTuple end_val127 = (hv_Guess.TupleLength()) - 1;
  480. HTuple step_val127 = 1;
  481. for (hv_I = 0; hv_I.Continue(end_val127, step_val127); hv_I += step_val127)
  482. {
  483. TupleFind(hv_SystemFonts, HTuple(hv_Guess[hv_I]), &hv_Index);
  484. if (0 != (hv_Index != -1))
  485. {
  486. hv_Fonts[3] = HTuple(hv_Guess[hv_I]);
  487. break;
  488. }
  489. }
  490. }
  491. }
  492. hv_Font = ((const HTuple&)hv_Fonts)[hv_SubFamily];
  493. try
  494. {
  495. SetFont(hv_WindowHandle, (hv_Font + "-") + hv_Size);
  496. }
  497. // catch (Exception)
  498. catch (HalconCpp::HException &HDevExpDefaultException)
  499. {
  500. HDevExpDefaultException.ToHTuple(&hv_Exception);
  501. //throw (Exception)
  502. }
  503. }
  504. else
  505. {
  506. //Set font for UNIX systems
  507. hv_Size = hv_Size*1.25;
  508. hv_AllowedFontSizes.Clear();
  509. hv_AllowedFontSizes[0] = 11;
  510. hv_AllowedFontSizes[1] = 14;
  511. hv_AllowedFontSizes[2] = 17;
  512. hv_AllowedFontSizes[3] = 20;
  513. hv_AllowedFontSizes[4] = 25;
  514. hv_AllowedFontSizes[5] = 34;
  515. if (0 != ((hv_AllowedFontSizes.TupleFind(hv_Size)) == -1))
  516. {
  517. hv_Distances = (hv_AllowedFontSizes - hv_Size).TupleAbs();
  518. TupleSortIndex(hv_Distances, &hv_Indices);
  519. hv_Size = ((const HTuple&)hv_AllowedFontSizes)[HTuple(hv_Indices[0])];
  520. }
  521. if (0 != (HTuple(hv_Font == HTuple("mono")).TupleOr(hv_Font == HTuple("Courier"))))
  522. {
  523. hv_Font = "courier";
  524. }
  525. else if (0 != (hv_Font == HTuple("sans")))
  526. {
  527. hv_Font = "helvetica";
  528. }
  529. else if (0 != (hv_Font == HTuple("serif")))
  530. {
  531. hv_Font = "times";
  532. }
  533. if (0 != (hv_Bold == HTuple("true")))
  534. {
  535. hv_Bold = "bold";
  536. }
  537. else if (0 != (hv_Bold == HTuple("false")))
  538. {
  539. hv_Bold = "medium";
  540. }
  541. else
  542. {
  543. hv_Exception = "Wrong value of control parameter Bold";
  544. throw HalconCpp::HException(hv_Exception);
  545. }
  546. if (0 != (hv_Slant == HTuple("true")))
  547. {
  548. if (0 != (hv_Font == HTuple("times")))
  549. {
  550. hv_Slant = "i";
  551. }
  552. else
  553. {
  554. hv_Slant = "o";
  555. }
  556. }
  557. else if (0 != (hv_Slant == HTuple("false")))
  558. {
  559. hv_Slant = "r";
  560. }
  561. else
  562. {
  563. hv_Exception = "Wrong value of control parameter Slant";
  564. throw HalconCpp::HException(hv_Exception);
  565. }
  566. try
  567. {
  568. SetFont(hv_WindowHandle, ((((((("-adobe-" + hv_Font) + "-") + hv_Bold) + "-") + hv_Slant) + "-normal-*-") + hv_Size) + "-*-*-*-*-*-*-*");
  569. }
  570. // catch (Exception)
  571. catch (HalconCpp::HException &HDevExpDefaultException)
  572. {
  573. HDevExpDefaultException.ToHTuple(&hv_Exception);
  574. if (0 != (HTuple((hv_OS.TupleSubstr(0, 4)) == HTuple("Linux")).TupleAnd(hv_Font == HTuple("courier"))))
  575. {
  576. QueryFont(hv_WindowHandle, &hv_Fonts);
  577. hv_FontSelRegexp = (("^-[^-]*-[^-]*[Cc]ourier[^-]*-" + hv_Bold) + "-") + hv_Slant;
  578. hv_FontsCourier = (hv_Fonts.TupleRegexpSelect(hv_FontSelRegexp)).TupleRegexpMatch(hv_FontSelRegexp);
  579. if (0 != ((hv_FontsCourier.TupleLength()) == 0))
  580. {
  581. hv_Exception = "Wrong font name";
  582. //throw (Exception)
  583. }
  584. else
  585. {
  586. try
  587. {
  588. SetFont(hv_WindowHandle, ((HTuple(hv_FontsCourier[0]) + "-normal-*-") + hv_Size) + "-*-*-*-*-*-*-*");
  589. }
  590. // catch (Exception)
  591. catch (HalconCpp::HException &HDevExpDefaultException)
  592. {
  593. HDevExpDefaultException.ToHTuple(&hv_Exception);
  594. //throw (Exception)
  595. }
  596. }
  597. }
  598. //throw (Exception)
  599. }
  600. }
  601. // dev_set_preferences(...); only in hdevelop
  602. return;
  603. }