CString CIconv::ConvertRTF(CString str) { LoadRTF(); return m_CodingRTF.Encode(str); }
int show_rtf(SDL_Surface *screen, char *fontname, char *filename, int offset) { int i; int done; int height; RTF_Context *ctx; RTF_FontEngine fontEngine; Uint32 white; Uint8 *keystate; FontList[FontFamilyToIndex(RTF_FontDefault)] = strdup(fontname); white = SDL_MapRGB(screen->format, 255, 255, 255); /* Create and load the RTF document */ fontEngine.version = RTF_FONT_ENGINE_VERSION; fontEngine.CreateFont = CreateFont; fontEngine.GetLineSpacing = GetLineSpacing; fontEngine.GetCharacterOffsets = GetCharacterOffsets; fontEngine.RenderText = RenderText; fontEngine.FreeFont = FreeFont; ctx = RTF_CreateContext(&fontEngine); if ( ctx == NULL ) { fprintf(stderr, "Couldn't create RTF context: %s\n", RTF_GetError()); return(offset); } // This loads from a file. I adde MakeRtf() to load from mem for pspmaps. if (0 != LoadRTF(ctx, filename)) return(offset); /* Render the document to the screen */ done = 0; if (offset < 0) offset = 0; height = RTF_GetHeight(ctx, screen->w); if ( offset > (height - screen->h) ) offset = (height - screen->h); while (!done) { SDL_Event event; while (SDL_PollEvent(&event)) { if (event.type == SDL_VIDEORESIZE) { float ratio = (float)offset / height; screen = SDL_SetVideoMode(event.resize.w, event.resize.h, 0, SDL_RESIZABLE); height = RTF_GetHeight(ctx, screen->w); offset = (int)(ratio * height); } if (event.type == SDL_KEYDOWN) { switch(event.key.keysym.sym) { case SDLK_ESCAPE: case SDLK_RETURN: case SDLK_TAB: case SDLK_BACKSPACE: done = 1; break; case SDLK_LEFT: case SDLK_RIGHT: break; case SDLK_HOME: offset = 0; break; case SDLK_END: offset = (height - screen->h); break; case SDLK_PAGEUP: case SDLK_COMMA: offset -= screen->h; if ( offset < 0 ) offset = 0; break; case SDLK_PAGEDOWN: case SDLK_PERIOD: case SDLK_SPACE: offset += screen->h; if ( offset > (height - screen->h) ) offset = (height - screen->h); break; default: break; } } if (event.type == SDL_QUIT) { done = 1; } } keystate = SDL_GetKeyState(NULL); if ( keystate[SDLK_UP] ) { offset -= 1; if ( offset < 0 ) offset = 0; } if ( keystate[SDLK_DOWN] ) { offset += 1; if ( offset > (height - screen->h) ) offset = (height - screen->h); } SDL_FillRect(screen, NULL, white); RTF_Render(ctx, screen, NULL, offset); SDL_UpdateRect(screen, 0, 0, 0, 0); } /* Clean up and exit */ RTF_FreeContext(ctx); return(offset); }