私は最近、SDL2を使用して小さなテキストアドベンチャーゲームをプログラミングしていて、行の折り返しに関する問題に遭遇しました。私はTTF_RenderText_Blended_Wrapped()を使って文字列をレンダリングしています。しかし、行の高さは問題であり、行は一緒に盛り上がっているように見え、 'jqg'のような文字は 'tli'のような文字と重なっています。SDL TTF - 行の折り返しと改行の高さの変更?
誰かが行の高さを変更する方法があるかどうか知っていますか? TTF_RenderText_Blended_Wrapped()はまだSDL_ttfのドキュメントでさえありません。私は自分のテキストラッピング関数を書くべきですか?
フォントサイズは16pt、スタイリングはTTF_STYLE_BOLD、フォントはhereです。以下のコードはエラーを再現するはずですが、エラーはほとんどありませんが、自己責任で使用してください。ここでは、コードの出力は次のようになります。
#include <stdio.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
int main(int argc, char *argv[]) {
SDL_Window *gui;
SDL_Surface *screen, *text;
SDL_Event ev;
TTF_Font *font;
int running = 1;
const char *SAMPLETEXT = "This is an example of my problem, for most lines it works fine, albeit it looks a bit tight. But for any letters that \"hang\" below the line, there is a chance of overlapping with the letters below. This isn\'t the end of the world, but I think it makes for rather cluttered text.\n\nNotice the p and k on line 1/2, and the g/t on 2/3 and 3/4.";
// init SDL/TTF
SDL_Init(SDL_INIT_EVERYTHING);
TTF_Init();
// Open and set up font
font = TTF_OpenFont("Anonymous.ttf", 16);
if(font == NULL) {
fprintf(stderr, "Error: font could not be opened.\n");
return 0;
}
TTF_SetFontStyle(font, TTF_STYLE_BOLD);
// Create GUI
gui = SDL_CreateWindow("Example", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
640, 480, SDL_WINDOW_SHOWN);
// Grab GUI surface
screen = SDL_GetWindowSurface(gui);
// Clear screen black
SDL_FillRect(screen, NULL, 0);
// Draw some text to screen
SDL_Color color = {0xff, 0xff, 0xff, 0xff};
text = TTF_RenderText_Blended_Wrapped(font, SAMPLETEXT, color, screen->w);
SDL_BlitSurface(text, NULL, screen, NULL);
while(running) { // Main loop
while(SDL_PollEvent(&ev)) {
switch(ev.type){
case SDL_QUIT:
running = 0;
break;
}
}
SDL_UpdateWindowSurface(gui); // Refresh window
SDL_Delay(20); // Delay loop
}
// Destroy resources and quit
TTF_CloseFont(font);
TTF_Quit();
SDL_FreeSurface(text);
SDL_DestroyWindow(gui);
SDL_Quit();
return 0;
}
Iは、ライン間隔を制御するためにどのような方法があることが表示されません。 [こちらはソースコードへのリンクです](https://fossies.org/dox/SDL2_ttf-2.0.14/SDL__ttf_8c_source.html#l01876)。あなたは別のフォントを試しましたか?あなたは 'TTF_FontHeight()'と 'TTF_FontLineSkip()'によって返された値を比較しましたか? –
リンクありがとうございます。ラインスキップは高さよりも大きく、私はいくつかのフォントを試しました。私はどこかで動作するフォントがあると確信していますが、私はむしろ検索しないでください。 –
使用しているフォントを投稿できますか?私は自分のシステム上でいくつかのフォントを試してみたところ、問題を再現できませんでした。 – Tim