• 显示下一页

      1. int ShowNextPage(void)
      2. {
      3. int iError;
      4. PT_PageDesc ptPage; /* 定义页信息的指针 */
      5. unsigned char *pucTextFileMemCurPos; /* 当前指向text文件的位置 */
      6. if (g_ptCurPage) /* 判断当前page是否存在 */
      7. {
      8. /* 将下一page的起始位置取出来 */
      9. pucTextFileMemCurPos = g_ptCurPage->pucLcdNextPageFirstPosAtFile;
      10. }
      11. else
      12. {
      13. /* 否则将初始的其实位置取出来 */
      14. pucTextFileMemCurPos = g_pucLcdFirstPosAtFile;
      15. }
      16. /* 执行显示page操作 */
      17. iError = ShowOnePage(pucTextFileMemCurPos);
      18. DBG_PRINTF("%s %d, %d\n", __FUNCTION__, __LINE__, iError);
      19. if (iError == 0)
      20. {
      21. if (g_ptCurPage && g_ptCurPage->ptNextPage)
      22. {
      23. g_ptCurPage = g_ptCurPage->ptNextPage;
      24. return 0;
      25. }
      26. ptPage = malloc(sizeof(T_PageDesc));
      27. if (ptPage)
      28. {
      29. ptPage->pucLcdFirstPosAtFile = pucTextFileMemCurPos;
      30. ptPage->pucLcdNextPageFirstPosAtFile = g_pucLcdNextPosAtFile;
      31. ptPage->ptPrePage = NULL;
      32. ptPage->ptNextPage = NULL;
      33. g_ptCurPage = ptPage;
      34. DBG_PRINTF("%s %d, pos = 0x%x\n", __FUNCTION__, __LINE__, (unsigned int)ptPage->pucLcdFirstPosAtFile);
      35. RecordPage(ptPage);
      36. return 0;
      37. }
      38. else
      39. {
      40. return -1;
      41. }
      42. }
      43. return iError;
      44. }
    • 显示一页 ```c int ShowOnePage(unsigned char pucTextFileMemCurPos) { int iLen; int iError; unsigned char pucBufStart; unsigned int dwCode; PT_FontOpr ptFontOpr; T_FontBitMap tFontBitMap;

      int bHasNotClrSceen = 1; / 清屏标志 / int bHasGetCode = 0; / /

      tFontBitMap.iCurOriginX = 0; / x / tFontBitMap.iCurOriginY = g_dwFontSize; / y / pucBufStart = pucTextFileMemCurPos; / 设置buf起始位置 /

    1. while (1)
    2. {
    3. /* */
    4. iLen = g_ptEncodingOprForFile->GetCodeFrmBuf(pucBufStart, g_pucTextFileMemEnd, &dwCode);
    5. if (0 == iLen)
    6. {
    7. /* 文件结束 */
    8. if (!bHasGetCode)
    9. {
    10. return -1;
    11. }
    12. else
    13. {
    14. return 0;
    15. }
    16. }
    17. bHasGetCode = 1; /* 成功获取code */
    18. pucBufStart += iLen;
    19. /* 有些文本, \n\r两个一起才表示回车换行
    20. * 碰到这种连续的\n\r, 只处理一次
    21. */
    22. if (dwCode == '\n')
    23. {
    24. g_pucLcdNextPosAtFile = pucBufStart;
    25. /* 回车换行 */
    26. tFontBitMap.iCurOriginX = 0;
    27. tFontBitMap.iCurOriginY = IncLcdY(tFontBitMap.iCurOriginY);
    28. if (0 == tFontBitMap.iCurOriginY)
    29. {
    30. /* 显示完当前一屏了 */
    31. return 0;
    32. }
    33. else
    34. {
    35. continue;
    36. }
    37. }
    38. else if (dwCode == '\r')
    39. {
    40. continue;
    41. }
    42. else if (dwCode == '\t')
    43. {
    44. /* TAB键用一个空格代替 */
    45. dwCode = ' ';
    46. }
    47. DBG_PRINTF("dwCode = 0x%x\n", dwCode);
    48. ptFontOpr = g_ptEncodingOprForFile->ptFontOprSupportedHead;
    49. while (ptFontOpr)
    50. {
    51. DBG_PRINTF("%s %s %d\n", __FILE__, __FUNCTION__, __LINE__);
    52. iError = ptFontOpr->GetFontBitmap(dwCode, &tFontBitMap);
    53. DBG_PRINTF("%s %s %d, ptFontOpr->name = %s, %d\n", __FILE__, __FUNCTION__, __LINE__, ptFontOpr->name, iError);
    54. if (0 == iError)
    55. {
    56. DBG_PRINTF("%s %s %d\n", __FILE__, __FUNCTION__, __LINE__);
    57. if (RelocateFontPos(&tFontBitMap))
    58. {
    59. /* 剩下的LCD空间不能满足显示这个字符 */
    60. return 0;
    61. }
    62. DBG_PRINTF("%s %s %d\n", __FILE__, __FUNCTION__, __LINE__);
    63. if (bHasNotClrSceen)
    64. {
    65. /* 首先清屏 */
    66. g_ptDispOpr->CleanScreen(COLOR_BACKGROUND);
    67. bHasNotClrSceen = 0;
    68. }
    69. DBG_PRINTF("%s %s %d\n", __FILE__, __FUNCTION__, __LINE__);
    70. /* 显示一个字符 */
    71. if (ShowOneFont(&tFontBitMap))
    72. {
    73. return -1;
    74. }
    75. tFontBitMap.iCurOriginX = tFontBitMap.iNextOriginX;
    76. tFontBitMap.iCurOriginY = tFontBitMap.iNextOriginY;
    77. g_pucLcdNextPosAtFile = pucBufStart;
    78. /* 继续取出下一个编码来显示 */
    79. break;
    80. }
    81. ptFontOpr = ptFontOpr->ptNext;
    82. }
    83. }

    ```