Ressource::~Ressource() { //oslDeleteSound(click_); oslDeleteImage(grid_); oslDeleteImage(backgroundpic_); intraFontUnload(ltn_); }
int intraFont_free(lua_State *L) { if (lua_gettop(L) != 1) return luaL_error(L, "intraFont.unload(font): wrong number of arguments"); intraFontUnload(*getintraFont(L, 1)); return 0; }
void oslDeleteFont(OSL_FONT *f) { if (f->fontType == OSL_FONT_INTRA){ if (f->intra->altFont){ intraFontUnload(f->intra->altFont); f->intra->altFont = NULL; } intraFontUnload(f->intra); f->intra = NULL; }else if (f->fontType == OSL_FONT_OFT){ oslDeleteImage(f->img); free(f->charPositions); f->charPositions = NULL; free(f->charWidths); f->charWidths = NULL; } free(f); f = NULL; }
int main() { sf2d_init(); sf2d_set_clear_color(RGBA8(0x40, 0x40, 0x40, 0xFF)); consoleInit(GFX_BOTTOM, NULL); printf("intraFont test sinusoid\n"); intraFontInit(); intraFont *font = intraFontLoad("/ltn8.pgf", INTRAFONT_CACHE_ASCII); intraFontSetStyle(font, 1.0f, 0, 0, 0.0f, INTRAFONT_ALIGN_CENTER); struct Sinusoid { float angle; // In degrees float amplitude; float step; float speed; float speed_inc; char str[64]; } sinus = {0.f,35.f,10.f,0.f,0.007f,"intraFont 0.31 - 2009 by BenHur"}; float x = 0.0f; float y = 0.0f; float size = 0.65f; float tmp_angle; int i; u32 held; while (aptMainLoop()) { hidScanInput(); held = hidKeysHeld(); if (held & KEY_START) { break; } else if (held & KEY_L) { size += 0.1f; } else if (held & KEY_R) { size -= 0.1f; } if (held & KEY_UP) { y -= 3.0f; } else if (held & KEY_DOWN) { y += 3.0f; } if (held & KEY_RIGHT) { x += 3.0f; } else if (held & KEY_LEFT) { x -= 3.0f; } sf2d_start_frame(GFX_TOP, GFX_LEFT); //sf2d_draw_rectangle(50, 60, 50, 50, RGBA8(0,255,0,255)); intraFontSetStyle(font, size, RGBA8(255,0,0,255), RGBA8(0,255,0,255), 0.0f, INTRAFONT_ALIGN_LEFT); intraFontPrint(font, x, y, "ola k ase"); // * Draw the sinusoid * /*float draw_x = x - intraFontMeasureText(font,sinus.str)/2; // Get the x position of the 1st char // Increment the speed if (fabsf(sinus.speed += sinus.speed_inc) > 10.f) sinus.speed_inc = -sinus.speed_inc; // Increment the angle tmp_angle = (sinus.angle += sinus.speed); if (sinus.angle > 360.f) sinus.angle -= 360.f; // Draw one by one for (i = 0; i != strlen(sinus.str); i++, tmp_angle += sinus.step) { intraFontSetStyle(font, 1.0f, WHITE, BLACK, 45.f*cosf(tmp_angle*M_PI/180.f), INTRAFONT_ALIGN_LEFT); draw_x = intraFontPrintEx(font, draw_x, y + sinus.amplitude*sinf(tmp_angle*M_PI/180.f), sinus.str+i,1); }*/ sf2d_end_frame(); sf2d_swapbuffers(); } intraFontUnload(font); intraFontShutdown(); sf2d_fini(); return 0; }
int main() { pspDebugScreenInit(); SetupCallbacks(); // Colors enum colors { RED = 0xFF0000FF, GREEN = 0xFF00FF00, BLUE = 0xFFFF0000, WHITE = 0xFFFFFFFF, LITEGRAY = 0xFFBFBFBF, GRAY = 0xFF7F7F7F, DARKGRAY = 0xFF3F3F3F, BLACK = 0xFF000000, }; pspDebugScreenPrintf("intraFont 0.31 - 2009 by BenHur\n\nLoading fonts: 0%%"); // Init intraFont library intraFontInit(); // Load fonts intraFont* ltn[16]; //latin fonts (large/small, with/without serif, regular/italic/bold/italic&bold) char file[40]; int i; for (i = 0; i < 16; i++) { sprintf(file, "flash0:/font/ltn%d.pgf", i); ltn[i] = intraFontLoad(file,0); //<- this is where the actual loading happens intraFontSetStyle(ltn[i], 1.0f, WHITE, DARKGRAY, 0); pspDebugScreenSetXY(15,2); pspDebugScreenPrintf("%d%%",(i+1)*100/20); } intraFont* jpn0 = intraFontLoad("flash0:/font/jpn0.pgf",INTRAFONT_STRING_SJIS); //japanese font with SJIS text string encoding intraFontSetStyle(jpn0, 0.8f, WHITE, DARKGRAY, 0); //scale to 80% pspDebugScreenSetXY(15,2); pspDebugScreenPrintf("%d%%",17*100/20); intraFont* kr0 = intraFontLoad("flash0:/font/kr0.pgf", INTRAFONT_STRING_UTF8); //Korean font (not available on all systems) with UTF-8 encoding intraFontSetStyle(kr0, 0.8f, WHITE, DARKGRAY, 0); //scale to 80% pspDebugScreenSetXY(15,2); pspDebugScreenPrintf("%d%%",18*100/20); intraFont* arib = intraFontLoad("flash0:/font/arib.pgf",0); //Symbols (not available on all systems) intraFontSetStyle(arib, 0.8f, WHITE, DARKGRAY, 0); //scale to 80% pspDebugScreenSetXY(15,2); pspDebugScreenPrintf("%d%%",19*100/20); intraFont* chn = intraFontLoad("flash0:/font/gb3s1518.bwfon", 0); //chinese font intraFontSetStyle(chn, 0.8f, WHITE, DARKGRAY, 0); //scale to 80% pspDebugScreenSetXY(15,2); pspDebugScreenPrintf("done\n"); // Make sure the important fonts for this application are loaded if(!ltn[0] || !ltn[4] || !ltn[8]) sceKernelExitGame(); // Set alternative fonts that are used in case a certain char does not exist in the main font intraFontSetAltFont(ltn[8], jpn0); //japanese font is used for chars that don't exist in latin intraFontSetAltFont(jpn0, chn); //chinese font (bwfon) is used for chars that don't exist in japanese (and latin) intraFontSetAltFont(chn, kr0); //korean font is used for chars that don't exist in chinese (and jap and ltn) intraFontSetAltFont(kr0, arib); //symbol font is used for chars that don't exist in korean (and chn, jap & ltn) // NB: This is an extreme case - usually you need only one alternative font (e.g. japanese & chinese) // Also: if one of the fonts failed to load (e.g. chn) the chain breaks and all subequent fonts are not used (e.g. kr0 and arib) initGraphics(); float x_scroll1 = 80, x_scroll2 = 225, x_scroll3 = 370, x_scroll4 = 385; while(running) { clearScreen(GRAY); // Must be called before any of the intraFont functions guStart(); // Draw various text float x,y = 20; intraFontSetStyle(ltn[4], 1.0f,BLACK,WHITE,INTRAFONT_ALIGN_CENTER); intraFontPrint(ltn[4], 240, y, "intraFont 0.31 - 2009 by BenHur"); intraFontSetStyle(ltn[4], 1.0f,WHITE,DARKGRAY,0); y += 21; intraFontPrint(ltn[8], 10, y, "Latin Sans-Serif:"); intraFontPrint(ltn[0], 180, y, "regular,"); intraFontPrint(ltn[2], 270, y, "italic,"); intraFontPrint(ltn[4], 330, y, "bold,"); intraFontPrint(ltn[6], 390, y, "both"); y += 17; intraFontPrint(ltn[8], 10, y, "Latin Sans-Serif small:"); intraFontPrint(ltn[8], 180, y, "regular,"); intraFontPrint(ltn[10], 270, y, "italic,"); intraFontPrint(ltn[12], 330, y, "bold,"); intraFontPrint(ltn[14], 390, y, "both"); y += 17; intraFontPrint(ltn[8], 10, y, "Latin with Serif:"); intraFontPrint(ltn[1], 180, y, "regular,"); intraFontPrint(ltn[3], 270, y, "italic,"); intraFontPrint(ltn[5], 330, y, "bold,"); intraFontPrint(ltn[7], 390, y, "both"); y += 17; intraFontPrint(ltn[8], 10, y, "Latin with Serif small:"); intraFontPrint(ltn[9], 180, y, "regular,"); intraFontPrint(ltn[11], 270, y, "italic,"); intraFontPrint(ltn[13], 330, y, "bold,"); intraFontPrint(ltn[15], 390, y, "both"); y += 17; intraFontSetEncoding(ltn[8], INTRAFONT_STRING_UTF8); //set text string encoding to UTF-8 intraFontPrint(ltn[8], 10, y, "LTN (UTF8):"); //(has no effect on std ascii) intraFontPrint(ltn[8], 110, y, "\xC3\xA5 \xC3\xA8 \xC3\xAD \xC3\xB4 \xC3\xBC \xC3\xB1"); //UTF-8 encoded chars with accents on top of them intraFontPrint(ltn[8], 250, y, "Symbols: "); unsigned short ucs2_arib[] = { 57786, 57787, 57788, 57789, 57790, 0 }; x = intraFontPrintUCS2(arib, 350, y, ucs2_arib); if (x == 350) intraFontPrint(ltn[8], 350, y, "[n/a]"); y += 17; intraFontPrint(ltn[8], 10, y, "JPN (UTF8):"); char utf8_jpn[] = {0xE3, 0x81, 0x93, 0xE3, 0x82, 0x93, 0xE3, 0x81, 0xAB, 0xE3, 0x81, 0xA1, 0xE3, 0x81, 0xAF, 0x20, 0xE4, 0xB8, 0x96, 0xE7, 0x95, 0x8C, 0}; intraFontSetEncoding(jpn0, INTRAFONT_STRING_UTF8); //temporarely switch to UTF-8 (INTRAFONT_STRING_SJIS was set in intraFontLoad call) x = intraFontPrint(jpn0, 110, y, utf8_jpn); //print UTF-8 encoded string if (x == 110) intraFontPrint(ltn[8], 110, y, "[n/a]"); intraFontSetEncoding(jpn0, INTRAFONT_STRING_SJIS); //switch back to S-JIS intraFontPrint(ltn[8], 250, y, "JPN (S-JIS):"); x = intraFontPrint(jpn0, 350, y, "イントラフォント"); //S-JIS encoded text string (flag INTRAFONT_STRING_SJIS set in intraFontLoad call) if (x == 350) intraFontPrint(ltn[8], 350, y, "[n/a]"); y += 17; intraFontPrint(ltn[8], 10, y, "CHN (GBK):"); char gbk_chn[] = { 0xbc,0xf2, 0xcc,0xe5, 0xd6,0xd0, 0xce,0xc4, 0}; intraFontSetEncoding(chn, INTRAFONT_STRING_GBK); x = intraFontPrint(chn, 110, y, gbk_chn); //print GBK-encoded string (simplified chinese) if (x == 110) intraFontPrint(ltn[8], 110, y, "[n/a]"); intraFontPrint(ltn[8], 250, y, "CHN (BIG5):"); char big5_chn[] = { 0xc1,0x63, 0xc5,0xe9, 0xa4,0xa4, 0xa4,0xe5, 0}; intraFontSetEncoding(chn, INTRAFONT_STRING_BIG5); x = intraFontPrint(chn, 350, y, big5_chn); //print BIG5-encoded string (trad. chinese) if (x == 350) intraFontPrint(ltn[8], 350, y, "[n/a]"); y += 17; intraFontPrint(ltn[8], 10, y, "KOR (UTF8):"); char utf8_kr[] = {0xed, 0x99, 0x98, 0xec, 0x98, 0x81, 0x20, 0xeb, 0x8c, 0x80, 0xed, 0x95, 0x9c, 0xeb, 0xaf, 0xbc, 0xea, 0xb5, 0xad, 0}; x = intraFontPrint(kr0, 110, y, utf8_kr); //print UTF-8 string (flag INTRAFONT_STRING_UTF8 set in intraFontLoad call) if (x == 110) intraFontPrint(ltn[8], 110, y, "[n/a]"); intraFontPrint(ltn[8], 250, y, "MIX (UCS2):"); unsigned short ucs2_all[] = { 0x0041, 0x0192, 0x3401, 0x3402, 0x4E01, 0x4E02, 0xAC01, 0xAC02, 0xE1BE, 0}; x = intraFontPrintUCS2(ltn[8], 350, y, ucs2_all); //print chars from all fonts (using alternative fonts, which were set after font loading) y += 17; intraFontPrint(ltn[8], 10, y, "Colors: "); intraFontSetStyle(ltn[8], 1.0f,RED,BLUE,0); x = intraFontPrint(ltn[8], 80, y, "colorful, "); intraFontSetStyle(ltn[8], 1.0f,WHITE,0,0); x = intraFontPrint(ltn[8], x, y, "no shadow, "); intraFontSetStyle(ltn[8], 1.0f,0,DARKGRAY,0); x = intraFontPrint(ltn[8], x, y, "no text, "); intraFontSetStyle(ltn[8], 1.0f,0x7FFFFFFF,DARKGRAY,0); x = intraFontPrint(ltn[8], x, y, "transparent, "); intraFontSetStyle(ltn[8], 1.0f,GRAY,WHITE,0); x = intraFontPrint(ltn[8], x, y, "glowing, "); float t = ((float)(clock() % CLOCKS_PER_SEC)) / ((float)CLOCKS_PER_SEC); int val = (t < 0.5f) ? t*511 : (1.0f-t)*511; intraFontSetStyle(ltn[8], 1.0f,LITEGRAY,(0xFF<<24)+(val<<16)+(val<<8)+(val),0); x = intraFontPrint(ltn[8], x, y, "flashing"); intraFontSetStyle(ltn[8], 1.0f,WHITE,DARKGRAY,0); y += 17; intraFontPrint(ltn[8], 10, y, "Spacing: "); intraFontSetStyle(ltn[8], 1.0f,WHITE,DARKGRAY,INTRAFONT_WIDTH_FIX); x = intraFontPrint(ltn[8], 80, y, "fixed (default), "); intraFontSetStyle(ltn[8], 1.0f,WHITE,DARKGRAY,INTRAFONT_WIDTH_FIX | 12); x = intraFontPrint(ltn[8], x, y, "fixed (12), "); intraFontSetStyle(ltn[8], 1.0f,WHITE,DARKGRAY,0); x = intraFontPrint(ltn[8], x, y, "variable width"); y += 22; intraFontPrint(ltn[8], 10, y, "Scaling: "); intraFontSetStyle(ltn[0], 0.5f,WHITE,DARKGRAY,0); x = intraFontPrint(ltn[0], 80, y, "tiny, "); intraFontSetStyle(ltn[0], 0.75f,WHITE,DARKGRAY,0); x = intraFontPrint(ltn[0], x, y, "small, "); intraFontSetStyle(ltn[0], 1.0f,WHITE,DARKGRAY,0); x = intraFontPrint(ltn[0], x, y, "regular, "); intraFontSetStyle(ltn[0], 1.25f,WHITE,DARKGRAY,0); x = intraFontPrint(ltn[0], x, y, "large, "); intraFontSetStyle(ltn[0], 1.5f,WHITE,DARKGRAY,0); x = intraFontPrint(ltn[0], x, y, "huge"); intraFontSetStyle(ltn[0], 1.0f,WHITE,DARKGRAY,0); y += 17; intraFontPrint(ltn[8], 10, y, "Align: "); intraFontSetStyle(ltn[8], 1.0f,WHITE,DARKGRAY,INTRAFONT_ALIGN_LEFT); t = ((float)(clock() % (CLOCKS_PER_SEC*10))) / ((float)CLOCKS_PER_SEC); int length = (t < 5.0f) ? t*5.8f : (10.0f-t)*5.8f; intraFontPrintColumnEx(ltn[8], 80, y, 90, "left aligned w. linebreaks ", length); //NB: intraFontPrintColumnEx() is used to print a sub-string of a given length (last parameter) // if you want to print the whole string, simply use intraFontPrintColumn() and omit the length parameter intraFontSetStyle(ltn[8], 1.0f,WHITE,DARKGRAY,INTRAFONT_ALIGN_CENTER); intraFontPrintColumnEx(ltn[8], 225, y, 110, "center aligned w. linebreaks", length); intraFontSetStyle(ltn[8], 1.0f,WHITE,DARKGRAY,INTRAFONT_ALIGN_RIGHT); intraFontPrintColumnEx(ltn[8], 370, y, 90, "right aligned w. linebreaks ", length); intraFontSetStyle(ltn[8], 1.0f,WHITE,DARKGRAY,INTRAFONT_ALIGN_FULL); intraFontPrintColumnEx(ltn[8], 380, y, 90, "full justified w. linebreaks", length); intraFontSetStyle(ltn[8], 1.0f,WHITE,DARKGRAY,0); y += 28; intraFontPrint(ltn[8], 10, y, "Scrolling: "); intraFontSetStyle(ltn[8], 1.0f,WHITE,DARKGRAY,INTRAFONT_SCROLL_LEFT); x_scroll1 = intraFontPrintColumn(ltn[8], x_scroll1, y, 80, "This text is scrolled to the left."); intraFontSetStyle(ltn[8], 1.0f,WHITE,DARKGRAY,INTRAFONT_SCROLL_SEESAW); x_scroll2 = intraFontPrintColumn(ltn[8], x_scroll2, y, 90, "Back & forth like a seesaw."); intraFontSetStyle(ltn[8], 1.0f,WHITE,DARKGRAY,INTRAFONT_SCROLL_RIGHT); x_scroll3 = intraFontPrintColumn(ltn[8], x_scroll3, y, 80, "Scrolling to the right..."); intraFontSetStyle(ltn[8], 1.0f,WHITE,DARKGRAY,INTRAFONT_SCROLL_THROUGH); x_scroll4 = intraFontPrintColumn(ltn[8], x_scroll4, y, 80, "This text is scrolled through."); intraFontSetStyle(ltn[8], 1.0f,WHITE,DARKGRAY,0); // End drawing sceGuFinish(); sceGuSync(0,0); // Swap buffers (waiting for vsync) sceDisplayWaitVblankStart(); flipScreen(); } //create screenshot (optional) //saveImage("scrshot.png", getVramDisplayBuffer(), SCREEN_WIDTH, SCREEN_HEIGHT, PSP_LINE_SIZE, 0); // Unload our fonts for (i = 0; i < 16; i++) { intraFontUnload(ltn[i]); } intraFontUnload(jpn0); intraFontUnload(kr0); intraFontUnload(arib); intraFontUnload(chn); // Shutdown font library intraFontShutdown(); sceKernelExitGame(); return 0; }