27#define DEFAULT_PTSIZE 30
30#define DEFAULT_FONT "/System/Library/Fonts/华文细黑.ttf"
33#define DEFAULT_FONT "C:\\Windows\\Fonts\\yugothic.ttf"
35#define DEFAULT_FONT "NoDefaultFont.ttf"
38#define DEFAULT_FONT "unifont-9.0.02.hex"
40#define MAX_TEXT_LENGTH 256
52#define UNIFONT_MAX_CODEPOINT 0x1ffff
53#define UNIFONT_NUM_GLYPHS 0x20000
55#define UNIFONT_TEXTURE_WIDTH 512
56#define UNIFONT_GLYPHS_IN_ROW (UNIFONT_TEXTURE_WIDTH / 16)
57#define UNIFONT_GLYPHS_IN_TEXTURE (UNIFONT_GLYPHS_IN_ROW * UNIFONT_GLYPHS_IN_ROW)
58#define UNIFONT_NUM_TEXTURES ((UNIFONT_NUM_GLYPHS + UNIFONT_GLYPHS_IN_TEXTURE - 1) / UNIFONT_GLYPHS_IN_TEXTURE)
59#define UNIFONT_TEXTURE_SIZE (UNIFONT_TEXTURE_WIDTH * UNIFONT_TEXTURE_WIDTH * 4)
60#define UNIFONT_TEXTURE_PITCH (UNIFONT_TEXTURE_WIDTH * 4)
61#define UNIFONT_DRAW_SCALE 2
73 if (
c >=
'0' &&
c <=
'9')
75 else if (
c >=
'a' &&
c <=
'f')
77 else if (
c >=
'A' &&
c <=
'F')
139 int i, codepointHexSize;
140 size_t bytesOverread;
144 bytesRead =
SDL_RWread(hexFile, hexBuffer, 1, 9);
154 if (hexBuffer[2] ==
':')
155 codepointHexSize = 2;
156 else if (hexBuffer[4] ==
':')
157 codepointHexSize = 4;
158 else if (hexBuffer[6] ==
':')
159 codepointHexSize = 6;
160 else if (hexBuffer[8] ==
':')
161 codepointHexSize = 8;
168 if (!
validate_hex((
const char *)hexBuffer, codepointHexSize, &codepoint))
177 bytesOverread = 8 - codepointHexSize;
178 if (codepointHexSize < 8)
179 SDL_memmove(hexBuffer, hexBuffer + codepointHexSize + 1, bytesOverread);
180 bytesRead =
SDL_RWread(hexFile, hexBuffer + bytesOverread, 1, 33 - bytesOverread);
181 if (bytesRead < (33 - bytesOverread))
186 if (hexBuffer[32] ==
'\n')
191 bytesRead =
SDL_RWread(hexFile, hexBuffer + 33, 1, 32);
213 for (
i = 0;
i < glyphWidth * 2;
i++)
220 }
while (bytesRead > 0);
235 for (
j = 0;
j < 8;
j++)
275 if (textureRGBA ==
NULL)
311 SDL_Log(
"unifont error: Failed to update texture %u data for renderer %d.\n", textureID,
i);
325 srcrect.
w = srcrect.
h = 16;
373 c = (
unsigned char)(0xff &
c);
376 else if ((
c >> 5) ==0x6)
378 else if ((
c >> 4) == 0xe)
380 else if ((
c >> 3) == 0x1e)
422 codepoint = (0xff >>
len) & *
p;
426 codepoint |= 0x3f & *
p;
438 SDL_Log(
"usage: testime [--font fontfile]\n");
469 SDL_Rect drawnTextRect, cursorRect, underlineRect;
484 drawnTextRect.
w = textSur->
w;
485 drawnTextRect.
h = textSur->
h;
502 drawnTextRect.
y = dstrect.
y;
503 drawnTextRect.
h = dstrect.
h;
508 dstrect.
x += advance;
509 drawnTextRect.
w += advance;
528 cursorRect = drawnTextRect;
529 cursorRect.
x += cursorRect.
w;
531 cursorRect.
h = drawnTextRect.
h;
533 drawnTextRect.
x += drawnTextRect.
w;
554 cursorRect.
x += drawnTextRect.
w;
560 drawnTextRect.
w = textSur->
w;
561 drawnTextRect.
h = textSur->
h;
575 dstrect.
x = drawnTextRect.
x;
579 drawnTextRect.
y = dstrect.
y;
580 drawnTextRect.
h = dstrect.
h;
585 dstrect.
x += advance;
586 drawnTextRect.
w += advance;
588 cursorRect.
x += advance;
596 cursorRect.
y = drawnTextRect.
y;
597 cursorRect.
h = drawnTextRect.
h;
601 underlineRect.
y = drawnTextRect.
y + drawnTextRect.
h - 2;
603 underlineRect.
w = drawnTextRect.
w;
632int main(
int argc,
char *argv[])
646 for (
i = 1;
i < argc;
i++) {
649 for (argc--, argv++; argc > 0; argc--, argv++)
651 if (strcmp(argv[0],
"--help") == 0) {
656 else if (strcmp(argv[0],
"--font") == 0)
691 SDL_Log(
"Using font: %s\n", fontname);
710 switch (
event.key.keysym.sym)
727 if ((
text[textlen-1] & 0x80) == 0x00)
730 text[textlen-1]=0x00;
733 if ((
text[textlen-1] & 0xC0) == 0x80)
736 text[textlen-1]=0x00;
739 if ((
text[textlen-1] & 0xC0) == 0xC0)
742 text[textlen-1]=0x00;
757 SDL_Log(
"Keyboard: scancode 0x%08X = %s, keycode 0x%08X = %s\n",
758 event.key.keysym.scancode,
764 if (
event.text.text[0] ==
'\0' ||
event.text.text[0] ==
'\n' ||
768 SDL_Log(
"Keyboard: text input \"%s\"\n",
event.text.text);
782 SDL_Log(
"text editing \"%s\", selected range (%d, %d)\n",
786 cursor =
event.edit.start;
#define SDL_RenderPresent
#define SDL_RenderFillRect
#define SDL_DestroyTexture
#define SDL_SetRenderDrawColor
#define SDL_CreateTextureFromSurface
#define SDL_CreateTexture
#define SDL_GetScancodeName
#define SDL_SetRenderDrawBlendMode
#define SDL_SetTextInputRect
#define SDL_StartTextInput
#define SDL_StopTextInput
#define SDL_SetTextureBlendMode
#define SDL_UpdateTexture
#define SDL_LogSetPriority
#define SDL_TEXTEDITINGEVENT_TEXT_SIZE
@ SDL_LOG_CATEGORY_APPLICATION
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLint GLint GLsizei width
GLenum const void GLbitfield GLsizei numGlyphs
GLsizei GLsizei GLfloat distance
GLenum GLenum GLuint texture
@ SDL_PIXELFORMAT_ARGB8888
@ SDL_TEXTUREACCESS_STATIC
void SDLTest_CommonQuit(SDLTest_CommonState *state)
Close test window.
SDLTest_CommonState * SDLTest_CommonCreateState(char **argv, Uint32 flags)
Parse command line parameters and create common state.
void SDLTest_CommonEvent(SDLTest_CommonState *state, SDL_Event *event, int *done)
Common event handler for test windows.
#define DEFAULT_WINDOW_WIDTH
int SDLTest_CommonArg(SDLTest_CommonState *state, int index)
Process one common argument.
SDL_bool SDLTest_CommonInit(SDLTest_CommonState *state)
Open test window.
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int int in j)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
A rectangle, with the origin at the upper left (integer).
A collection of pixels used in software blitting.
SDL_Renderer ** renderers
static SDL_Renderer * renderer
static SDL_Color backColor
static Uint8 unifontTextureLoaded[UNIFONT_NUM_TEXTURES]
int main(int argc, char *argv[])
#define UNIFONT_TEXTURE_WIDTH
void _Redraw(int rendererID)
static int unifont_load_texture(Uint32 textureID)
#define UNIFONT_DRAW_SCALE
static void unifont_cleanup()
static SDL_Rect markedRect
static Sint32 unifont_draw_glyph(Uint32 codepoint, int rendererID, SDL_Rect *dstrect)
static SDL_Color lineColor
static char text[MAX_TEXT_LENGTH]
static SDL_Color textColor
static int unifont_init(const char *fontname)
static char markedText[SDL_TEXTEDITINGEVENT_TEXT_SIZE]
static Uint8 dehex2(char c1, char c2)
#define UNIFONT_TEXTURE_PITCH
#define UNIFONT_GLYPHS_IN_ROW
struct UnifontGlyph * unifontGlyph
char * utf8_advance(char *p, size_t distance)
static SDL_Texture ** unifontTexture
size_t utf8_length(unsigned char c)
static Uint8 dehex(char c)
#define UNIFONT_TEXTURE_SIZE
static Uint8 validate_hex(const char *cp, size_t len, Uint32 *np)
static void unifont_make_rgba(Uint8 *src, Uint8 *dst, Uint8 width)
static SDLTest_CommonState * state
#define UNIFONT_MAX_CODEPOINT
#define UNIFONT_GLYPHS_IN_TEXTURE
#define UNIFONT_NUM_TEXTURES
Uint32 utf8_decode(char *p, size_t len)
#define UNIFONT_NUM_GLYPHS
char * utf8_next(char *p)