app_check_string_size.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. #include <stdio.h>
  2. #include "gui_engine.h"
  3. #include "device_font.h"
  4. #include "util.h"
  5. #include "ui_wingetinfo.inc"
  6. #include "app_gui.h"
  7. //#define CHK_LEN_DEBUG
  8. #ifdef CHK_LEN_DEBUG
  9. #define DEBUG_MSG(fmt, arg...) printf(fmt, ##arg)
  10. #else
  11. #define DEBUG_MSG(fmt, arg...) ((void) 0)
  12. #endif
  13. #define CONTROL_STATE_MAX (4)
  14. static int menuID = 0;
  15. static int controlID = 0;
  16. static int state = 0;
  17. static char *stateArray[] =
  18. {
  19. "Normal",
  20. "Focused",
  21. "Disabled",
  22. "Clicked",
  23. };
  24. static int APP_Check_StringIDList(UINT8 ucFontSize, FixWidth_t eFixCharWidth, String_id_t *stringIDList, int totalStr, RECT textPos)
  25. {
  26. int i = 0;
  27. UINT8 *pStr = NULL;
  28. int languageID = 0;
  29. int ret = 0;
  30. UINT16 width = 0, height = 0;
  31. DEBUG_MSG("%s-%s, total_count=%d\n", allAppletes[menuID].pMenuName, allAppletes[menuID].pWidgetName[controlID], totalStr);
  32. for (languageID = 0; languageID < TV_UI_LANG_NUM; languageID++)
  33. {
  34. Font_setCurLang(languageID);
  35. for (i = 0; i < totalStr; i++)
  36. {
  37. if (STRING_ID_INVALID == stringIDList[i] || GEL_GetStr(stringIDList[i], &pStr) != GUI_SUCCESS)
  38. {
  39. continue;
  40. }
  41. Font_getStrWH(pStr, ucFontSize, eFixCharWidth, &width, &height);
  42. if (width > textPos.width)
  43. {
  44. printf("%s - %s @ %s - %s - %s, string.width=%d, rect.width=%d\n", allLangName[languageID], allStrName[stringIDList[i]],
  45. allAppletes[menuID].pMenuName, allAppletes[menuID].pWidgetName[controlID], stateArray[state], width, textPos.width);
  46. ret = 1;
  47. }
  48. }
  49. }
  50. return ret;
  51. }
  52. static int APP_Check_Combox(WinControl_t *combox)
  53. {
  54. combo_t *ctrl = NULL;
  55. UINT8 ucFontSize = 0;
  56. FixWidth_t eFixCharWidth = 0;
  57. int ret = 0;
  58. if (NULL == combox || (ctrl = combox->param) == NULL)
  59. {
  60. return 0;
  61. }
  62. if (NULL == ctrl->string_id)
  63. {
  64. return 0;
  65. }
  66. eFixCharWidth = ctrl->bFixCharWidth > 0 ? FIXWIDTH_ALLCHARS : 0;
  67. for (state = 0; state < CONTROL_STATE_MAX; state++)
  68. {
  69. ucFontSize = GUIENG_GetFontStyle(combox, STATE_NORMAL << state);
  70. ret = APP_Check_StringIDList(ucFontSize, eFixCharWidth, ctrl->string_id, ctrl->total_count, ctrl->text_pos);
  71. }
  72. return ret;
  73. }
  74. static int APP_Check_Listview(WinControl_t *listview)
  75. {
  76. listview_t *ctrl = NULL;
  77. UINT8 ucFontSize = 0;
  78. FixWidth_t eFixCharWidth = 0;
  79. int ret = 0;
  80. if (NULL == listview || (ctrl = listview->param) == NULL)
  81. {
  82. return 0;
  83. }
  84. if (NULL == ctrl->string_id)
  85. {
  86. return 0;
  87. }
  88. eFixCharWidth = ctrl->bFixCharWidth > 0 ? FIXWIDTH_ALLCHARS : 0;
  89. for (state = 0; state < CONTROL_STATE_MAX; state++)
  90. {
  91. ucFontSize = GUIENG_GetFontStyle(listview, STATE_NORMAL << state);
  92. ret = APP_Check_StringIDList(ucFontSize, eFixCharWidth, ctrl->string_id, ctrl->total_count, ctrl->text_pos);
  93. }
  94. return ret;
  95. }
  96. static int APP_Check_ButtonGroup(WinControl_t *buttonGroup)
  97. {
  98. UINT8 ucFontSize = 0;
  99. FixWidth_t eFixCharWidth = 0;
  100. int ret = 0;
  101. if (NULL == buttonGroup || (buttonGroup->param) == NULL)
  102. {
  103. return 0;
  104. }
  105. if (GET_WIDGET_STYLE(buttonGroup) & S_BTN_TEXT)
  106. {
  107. btng_text_t *ctrl = buttonGroup->param;
  108. if (NULL == ctrl->string_id)
  109. {
  110. return 0;
  111. }
  112. eFixCharWidth = ctrl->bFixCharWidth > 0 ? FIXWIDTH_ALLCHARS : 0;
  113. for (state = 0; state < CONTROL_STATE_MAX; state++)
  114. {
  115. ucFontSize = GUIENG_GetFontStyle(buttonGroup, STATE_NORMAL << state);
  116. ret = APP_Check_StringIDList(ucFontSize, eFixCharWidth, ctrl->string_id, ctrl->total_count, ctrl->text_pos);
  117. }
  118. }
  119. else if (GET_WIDGET_STYLE(buttonGroup) & S_BTN_ICON)
  120. {
  121. }
  122. else if (GET_WIDGET_STYLE(buttonGroup) & S_BTN_MIX)
  123. {
  124. btng_mix_t *ctrl = buttonGroup->param;
  125. if (NULL == ctrl->string_id)
  126. {
  127. return 0;
  128. }
  129. eFixCharWidth = ctrl->bFixCharWidth > 0 ? FIXWIDTH_ALLCHARS : 0;
  130. for (state = 0; state < CONTROL_STATE_MAX; state++)
  131. {
  132. ucFontSize = GUIENG_GetFontStyle(buttonGroup, STATE_NORMAL << state);
  133. ret = APP_Check_StringIDList(ucFontSize, eFixCharWidth, ctrl->string_id, ctrl->total_count, ctrl->fg_text_pos);
  134. }
  135. }
  136. return ret;
  137. }
  138. static int APP_Check_Button(WinControl_t *button)
  139. {
  140. UINT8 ucFontSize = 0;
  141. FixWidth_t eFixCharWidth = 0;
  142. int ret = 0;
  143. if (NULL == button || (button->param) == NULL)
  144. {
  145. return 0;
  146. }
  147. if (GET_WIDGET_STYLE(button) & S_BTN_TEXT)
  148. {
  149. btn_text_t *ctrl = button->param;
  150. if (STRING_ID_INVALID == ctrl->string_id)
  151. {
  152. return 0;
  153. }
  154. eFixCharWidth = ctrl->bFixCharWidth > 0 ? FIXWIDTH_ALLCHARS : 0;
  155. for (state = 0; state < CONTROL_STATE_MAX; state++)
  156. {
  157. ucFontSize = GUIENG_GetFontStyle(button, STATE_NORMAL << state);
  158. ret = APP_Check_StringIDList(ucFontSize, eFixCharWidth, &ctrl->string_id, 1, ctrl->text_pos);
  159. }
  160. }
  161. else if (GET_WIDGET_STYLE(button) & S_BTN_MIX)
  162. {
  163. btn_mix_t *ctrl = button->param;
  164. if (STRING_ID_INVALID == ctrl->string_id)
  165. {
  166. return 0;
  167. }
  168. eFixCharWidth = ctrl->bFixCharWidth > 0 ? FIXWIDTH_ALLCHARS : 0;
  169. for (state = 0; state < CONTROL_STATE_MAX; state++)
  170. {
  171. ucFontSize = GUIENG_GetFontStyle(button, STATE_NORMAL << state);
  172. ret = APP_Check_StringIDList(ucFontSize, eFixCharWidth, &ctrl->string_id, 1, ctrl->fg_text_pos);
  173. }
  174. }
  175. return ret;
  176. }
  177. static int APP_Check_Textbox(WinControl_t *text)
  178. {
  179. text_box_t *ctrl = NULL;
  180. UINT8 ucFontSize = 0;
  181. FixWidth_t eFixCharWidth = 0;
  182. int ret = 0;
  183. if (NULL == text || text->param == NULL)
  184. {
  185. return 0;
  186. }
  187. if (GET_WIDGET_STYLE(text) & S_TXT_MULTI)
  188. {
  189. int languageID = 0;
  190. TextInfo_t stTextInfo;
  191. pgrhInfo_t stPgrhInfo;
  192. UINT8 *pStr = NULL;
  193. text_box_multi_t *multi = text->param;
  194. if (STRING_ID_INVALID == multi->text_info->string_id)
  195. {
  196. return 0;
  197. }
  198. memset(&stTextInfo, 0, sizeof(stTextInfo));
  199. stTextInfo.ucLineSpacing = multi->line_spacing;
  200. stTextInfo.stRect = multi->text_info->text_pos;
  201. stTextInfo.eFixCharWidth = multi->text_info->bFixCharWidth > 0 ? FIXWIDTH_ALLCHARS : 0;
  202. stTextInfo.ucTextAlign = GUIENG_GetFontAlign(GET_COMMON_STYLE(text));
  203. for (state = 0; state < CONTROL_STATE_MAX; state++)
  204. {
  205. stTextInfo.ucFontSize = GUIENG_GetFontStyle(text, STATE_NORMAL << state);
  206. for (languageID = 0; languageID < TV_UI_LANG_NUM; languageID++)
  207. {
  208. Font_setCurLang(languageID);
  209. if (GEL_GetStr(multi->text_info->string_id, &pStr) != GUI_SUCCESS)
  210. {
  211. continue;
  212. }
  213. memset(&stPgrhInfo, 0, sizeof(stPgrhInfo));
  214. Font_getPgrhInfo(pStr, &stTextInfo, &stPgrhInfo);
  215. if (stPgrhInfo.usTotalLine > stPgrhInfo.usPageLine)
  216. {
  217. printf("%s - %s @ %s - %s - %s, usTotalLine=%d, usPageLine=%d\n", allLangName[languageID],
  218. allStrName[multi->text_info->string_id], allAppletes[menuID].pMenuName, allAppletes[menuID].pWidgetName[controlID],
  219. stateArray[state], stPgrhInfo.usTotalLine, stPgrhInfo.usPageLine);
  220. ret = 1;
  221. }
  222. Font_freePgrhInfo(&stPgrhInfo);
  223. }
  224. }
  225. }
  226. else
  227. {
  228. ctrl = text->param;
  229. if (STRING_ID_INVALID == ctrl->string_id)
  230. {
  231. return 0;
  232. }
  233. eFixCharWidth = ctrl->bFixCharWidth > 0 ? FIXWIDTH_ALLCHARS : 0;
  234. for (state = 0; state < CONTROL_STATE_MAX; state++)
  235. {
  236. ucFontSize = GUIENG_GetFontStyle(text, STATE_NORMAL << state);
  237. ret = APP_Check_StringIDList(ucFontSize, eFixCharWidth, &ctrl->string_id, 1, ctrl->text_pos);
  238. }
  239. }
  240. return ret;
  241. }
  242. int APP_Check_Control_StringSize(void)
  243. {
  244. int ret = 0;
  245. int languageBK = 0;
  246. STRUCT_APPLET *pApplet;
  247. WinControl_t *controlList;
  248. languageBK = Font_getCurLang();
  249. printf("Start checking...\n");
  250. for (menuID = 0; (pApplet = allAppletes[menuID].stApplet) != NULL; menuID++)
  251. {
  252. controlList = pApplet->control_list;
  253. DEBUG_MSG("[%s %d] pApplet = %p, no_of_controls = %d\n", __FUNCTION__, __LINE__, pApplet, pApplet->no_of_controls);
  254. for (controlID = 0; controlID < pApplet->no_of_controls; controlID++)
  255. {
  256. switch(controlList[controlID].type)
  257. {
  258. case CLASS_TEXT:
  259. ret = APP_Check_Textbox(&controlList[controlID]);
  260. break;
  261. case CLASS_BUTTON:
  262. ret = APP_Check_Button(&controlList[controlID]);
  263. break;
  264. case CLASS_BUTTON_GROUP:
  265. ret = APP_Check_ButtonGroup(&controlList[controlID]);
  266. break;
  267. case CLASS_LISTVIEW:
  268. ret = APP_Check_Listview(&controlList[controlID]);
  269. break;
  270. case CLASS_COMBO:
  271. ret = APP_Check_Combox(&controlList[controlID]);
  272. break;
  273. default:
  274. break;
  275. }
  276. }
  277. }
  278. printf("Check finished!\n");
  279. Font_setCurLang(languageBK);
  280. return ret;
  281. }