void GradientText(int x, int y, intraFont *font, const char *text, g2dColor colorBegin, g2dColor colorEnd, float size, float angle, int center) { int i, textSize = strlen(text); int posX = x; int posY = y; int Rc = (G2D_GET_R(colorEnd) - G2D_GET_R(colorBegin))/(textSize-1); int Gc = (G2D_GET_G(colorEnd) - G2D_GET_G(colorBegin))/(textSize-1); int Bc = (G2D_GET_B(colorEnd) - G2D_GET_B(colorBegin))/(textSize-1); g2dColor ColorJ = 0; char help[2] = {0}; intraFontSetStyle(font, size, ColorJ, 0, angle, center); for(i = 0; i < textSize; i++) { ColorJ = G2D_RGBA(i * Rc+G2D_GET_R(colorBegin), i * Gc+G2D_GET_G(colorBegin), i * Bc+G2D_GET_B(colorBegin), 255); help[0] = text[i]; intraFontPrint(font, posX, posY, help); posX += intraFontMeasureText(font, help); } }
float BackgroundColorText(int x, int y, intraFont *font, const char *text, float size, g2dColor colorText, g2dColor colorBackground, int center) { int width = intraFontMeasureText(font, text); g2dBeginRects(NULL); g2dSetColor(colorBackground); g2dSetCoordMode(G2D_UP_LEFT); g2dSetScaleWH(width+4, intraFontTextHeight(font, text) + 3); switch(center) { case INTRAFONT_ALIGN_LEFT: g2dSetCoordXY(x-2, y-intraFontTextHeight(font, text)); break; case INTRAFONT_ALIGN_CENTER: g2dSetCoordXY(x - 2 - width/2, y-intraFontTextHeight(font, text)); break; case INTRAFONT_ALIGN_RIGHT: g2dSetCoordXY(x-width-2, y-intraFontTextHeight(font, text)); break; default: g2dSetCoordXY(x-2, y-intraFontTextHeight(font, text)); break; } g2dAdd(); g2dEnd(); intraFontSetStyle(font, size, colorText, 0, 0.0f, center); return intraFontPrint(font, x, y, text); }
float StrikedText(int x, int y, intraFont *font, const char *text, float size, float angle, g2dColor colorText, g2dColor colorLine, int center) { int width = intraFontMeasureText(font, text); int height = intraFontTextHeight(font, text); intraFontSetStyle(font, size, colorText, 0, 0.0f, center); g2dBeginLines(G2D_VOID); g2dSetColor(colorLine); switch(center) { case INTRAFONT_ALIGN_LEFT: g2dSetCoordXY(x, y-height/2); g2dAdd(); g2dSetCoordXY(x+width, y-height/2); g2dAdd(); break; case INTRAFONT_ALIGN_CENTER: g2dSetCoordXY(x - width/2, y-height/2); g2dAdd(); g2dSetCoordXY(x+width/2, y-height/2); g2dAdd(); break; case INTRAFONT_ALIGN_RIGHT: g2dSetCoordXY(x-width, y-height/2); g2dAdd(); g2dSetCoordXY(x, y-height/2); g2dAdd(); break; default: g2dSetCoordXY(x, y-height/2); g2dAdd(); g2dSetCoordXY(x+width, y-height/2); g2dAdd(); break; } g2dEnd(); return intraFontPrint(font, x, y, text); }
int oslGetStringWidth(const char *str) { if (!osl_curFont) return 0; u32 x = 0; if (osl_curFont->fontType == OSL_FONT_OFT){ unsigned char c; //Parcourt tous les caractères while(*str) { c = *(unsigned char*)str++; x += osl_curFont->charWidths[c]; } }else if (osl_curFont->fontType == OSL_FONT_INTRA){ x = (int)intraFontMeasureText(osl_curFont->intra, str); } return x; }
int updateIntraFontCharWidth(OSL_FONT *font, intraFont *intra) { if (!font || !intra) return 0; font->charHeight = intra->texYSize; if (!font->charWidths){ font->charWidths = (u8*)malloc(256*sizeof(char)); if (!font->charWidths) return -1; } int i = 0; char tchar[2] = ""; for (i=0; i<256; i++){ tchar[0] = i; font->charWidths[i] = (int)intraFontMeasureText(intra, tchar); } return 0; }