/********************************************************************* * * GUI__WrapGetNumCharsToNextLine */ int GUI__WrapGetNumCharsToNextLine(const char GUI_UNI_PTR * pText, int xSize, GUI_WRAPMODE WrapMode) { int NumChars; U16 Char; NumChars = GUI__WrapGetNumCharsDisp(pText, xSize, WrapMode); pText += GUI_UC__NumChars2NumBytes(pText, NumChars); Char = GUI_UC__GetCharCodeInc(&pText); if (Char == '\n') { NumChars++; } else if(Char == '\r') //modified by Derek 2010.12.02.10:07 { NumChars++; Char = GUI_UC__GetCharCodeInc(&pText); if(Char == '\n') { NumChars++; } } else { if (WrapMode == GUI_WRAPMODE_WORD) { while (Char == ' ') { NumChars++; Char = GUI_UC__GetCharCodeInc(&pText); } } } //end modified return NumChars; }
/********************************************************************* * * GUI_GetTextExtend */ void GUI_GetTextExtend(GUI_RECT* pRect, const char GUI_UNI_PTR * s, int MaxNumChars) { int xMax = 0; int NumLines = 0; int LineSizeX = 0; U16 Char; pRect->x0 = GUI_Context.DispPosX[GUI_Context.SelLayer]; pRect->y0 = GUI_Context.DispPosY[GUI_Context.SelLayer]; while (MaxNumChars--) { Char = GUI_UC__GetCharCodeInc(&s); if ((Char == '\n') || (Char == 0)) { if (LineSizeX > xMax) { xMax = LineSizeX; } LineSizeX = 0; NumLines++; if (!Char) { break; } } else { LineSizeX += GUI_GetCharDistX(Char); } } if (LineSizeX > xMax) { xMax = LineSizeX; } if (!NumLines) { NumLines = 1; } pRect->x1 = pRect->x0 + xMax - 1; pRect->y1 = pRect->y0 + GUI__GetFontSizeY() * NumLines - 1; }
/********************************************************************* * * GUI__GetNumChars */ int GUI__GetNumChars(const char GUI_UNI_PTR *s) { int NumChars = 0; if (s) { while (GUI_UC__GetCharCodeInc(&s)) { NumChars++; } } return NumChars; }
/********************************************************************* * * GUI_DispStringLen */ void GUI_DispStringLen(const char GUI_UNI_PTR *s, int MaxNumChars) { U16 Char; GUI_LOCK(); while (MaxNumChars && ((Char = GUI_UC__GetCharCodeInc(&s)) != 0)) { GUI_DispChar(Char); MaxNumChars--; } while (MaxNumChars--) { GUI_DispChar(' '); } GUI_UNLOCK(); }
/********************************************************************* * * GUI__GetCursorPosX * * Purpose: * Returns the cursor position in pixels by the given index * * Parameters: * s : Pointer to the string * Index : Index of cursor character * MaxNumChars : Number of charaters in the string */ int GUI__GetCursorPosX(const char GUI_UNI_PTR * s, int Index, int MaxNumChars) { #if GUI_SUPPORT_ARABIC return GUI__GetCursorPosXArabic(s, Index, MaxNumChars); #else int CursorPosX = 0; U16 Char; GUI_USE_PARA(MaxNumChars); while (Index--) { Char = GUI_UC__GetCharCodeInc(&s); CursorPosX += GUI_GetCharDistX(Char); } return CursorPosX; #endif }
/********************************************************************* * * GUI_GetLineDistX * * This routine is used to calculate the length of a line in pixels. */ int GUI__GetLineDistX(const char GUI_UNI_PTR *s, int MaxNumChars) { int Dist = 0; if (s) { U16 Char; #if GUI_COMPILER_SUPPORTS_FP if (GUI_Context.pAFont->pafEncode) { return GUI_Context.pAFont->pafEncode->pfGetLineDistX(s, MaxNumChars); } #endif while (--MaxNumChars >= 0) { Char = GUI_UC__GetCharCodeInc(&s); Dist += GUI_GetCharDistX(Char); } } return Dist; }
/********************************************************************* * * _GetCharWrap */ static int _GetCharWrap(const char GUI_UNI_PTR * s, int xSize) { int xDist = 0, NumChars = 0; U16 Char; while ((Char = GUI_UC__GetCharCodeInc(&s)) != 0) { xDist += GUI_GetCharDistX(Char); if ((NumChars && (xDist > xSize)) || (Char == '\n') || (Char == '\r')) { break; } NumChars++; } return NumChars; }
/********************************************************************* * * GUI__GetLineNumChars */ int GUI__GetLineNumChars(const char GUI_UNI_PTR *s, int MaxNumChars) { int NumChars = 0; if (s) { #if GUI_COMPILER_SUPPORTS_FP if (GUI_Context.pAFont->pafEncode) { return GUI_Context.pAFont->pafEncode->pfGetLineLen(s, MaxNumChars); } #endif for (; NumChars < MaxNumChars; NumChars++) { U16 Data = GUI_UC__GetCharCodeInc(&s); if ((Data == 0) || (Data == '\n')) { break; } } } return NumChars; }
/********************************************************************* * * _GetWordWrap */ static int _GetWordWrap(const char GUI_UNI_PTR * s, int xSize) { int xDist = 0, NumChars = 0, WordWrap = 0; U16 Char, PrevChar = 0; while (1) { Char = GUI_UC__GetCharCodeInc(&s); /* Similar to: *s++ */ /* Let's first check if the line end is reached. In this case we are done. */ if (_IsLineEnd(Char,s)) { WordWrap = NumChars; break; } /* If current character is a space, we found a wrap position */ if ((Char == ' ') && (Char != PrevChar)) { WordWrap = NumChars; } PrevChar = Char; xDist += GUI_GetCharDistX(Char); if ((xDist <= xSize) || (NumChars == 0)) { NumChars++; } else { break; } } if (!WordWrap) { WordWrap = NumChars; } return WordWrap; }
/********************************************************************* * * _DispLine */ static void _DispLine(const char GUI_UNI_PTR *s, int MaxNumChars, const GUI_RECT *pRect) { /* Check if we have anything to do at all ... */ if (GUI_Context.pClipRect_HL) { if (GUI_RectsIntersect(GUI_Context.pClipRect_HL, pRect) == 0) return; } // #if GUI_COMPILER_SUPPORTS_FP //if (GUI_Context.pAFont->pafEncode) { // GUI_Context.pAFont->pafEncode->pfDispLine(s, MaxNumChars); // } else { // #else { // #endif U16 Char; while (--MaxNumChars >= 0) { Char = GUI_UC__GetCharCodeInc(&s); GUI_Context.pAFont->pfDispChar(Char); if (GUI_pfDispCharStyle) { GUI_pfDispCharStyle(Char); } } } }