1 /* testbench.cpp -- A companion library to SDL for working with Pango.
2 Copyright (C) 2004 NAKAMURA Ken'ichi
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 #include "SDL_Pango.h"
23 SDLPango_Context
*context
;
26 int resizeLoop(SDL_Surface
**framebuf
)
30 while( SDL_PollEvent( &event
) ){
36 *framebuf
= SDL_SetVideoMode(event
.resize
.w
, event
.resize
.h
, 32, SDL_SWSURFACE
| SDL_RESIZABLE
);
40 if(event
.key
.keysym
.sym
== SDLK_RETURN
)
41 SDLPango_SetMarkup(context
, text
, -1);
42 else if(event
.key
.keysym
.sym
== SDLK_SPACE
)
43 SDLPango_SetText(context
, text
, -1);
54 char *readFile(const char *filename
)
58 FILE *file
= fopen(filename
, "rb");
62 fseek(file
, 0, SEEK_END
);
63 file_size
= ftell(file
);
64 fseek(file
, 0, SEEK_SET
);
65 text
= (char *)malloc(file_size
+ 1);
66 fread(text
, file_size
, 1, file
);
67 text
[file_size
] = '\0';
72 int main(int argc
, char *argv
[])
74 SDL_Surface
*framebuf
;
79 SDL_Init(SDL_INIT_VIDEO
);
82 framebuf
= SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE
| SDL_RESIZABLE
);
84 context
= SDLPango_CreateContext();
87 SDLPango_SetDpi(context
, 200.0, 200.0);
90 SDLPango_SetDefaultColor(context
, MATRIX_TRANSPARENT_BACK_WHITE_LETTER
);
92 SDLPango_SetMinimumSize(context
, 640, 0);
94 #ifdef SET_BASE_DIRECTION
95 SDLPango_SetBaseDirection(context
, SDLPANGO_DIRECTION_RTL
);
98 text
= readFile(argv
[1]);
101 SDLPango_SetMarkup(context
, text
, -1);
103 while(resizeLoop(&framebuf
)) {
104 SDL_Surface
*surface
;
106 SDLPango_SetMinimumSize(context
, framebuf
->w
, 0);
108 #ifdef GET_LAUOUT_WIDTH
111 w
= SDLPango_GetLayoutWidth(context
);
112 h
= SDLPango_GetLayoutHeight(context
);
116 #ifdef CREATE_SURFACE_DRAW
117 surface
= SDLPango_CreateSurfaceDraw(context
);
119 surface
= SDL_CreateRGBSurface(SDL_SWSURFACE
, framebuf
->w
, framebuf
->h
,
120 32, (Uint32
)(255 << (8 * 3)), (Uint32
)(255 << (8 * 2)),
121 (Uint32
)(255 << (8 * 1)), 255);
122 SDLPango_Draw(context
, surface
, 0, 0);
125 SDL_FillRect(framebuf
, NULL
, SDL_MapRGBA(framebuf
->format
, 0, 0, 0, 0));
126 SDL_BlitSurface(surface
, NULL
, framebuf
, NULL
);
127 SDL_UpdateRect(framebuf
, 0, 0, framebuf
->w
, framebuf
->h
);
129 SDL_FreeSurface(surface
);
134 SDLPango_FreeContext(context
);