added optional button to restart game (door, panel and touch variants)
[rocksndiamonds.git] / src / libgame / text.c
1 // ============================================================================
2 // Artsoft Retro-Game Library
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
5 //                  Holger Schemel
6 //                  info@artsoft.org
7 //                  https://www.artsoft.org/
8 // ----------------------------------------------------------------------------
9 // text.c
10 // ============================================================================
11
12 #include <stdio.h>
13 #include <stdarg.h>
14
15 #include "text.h"
16 #include "misc.h"
17
18
19 // ============================================================================
20 // static font variables
21 // ============================================================================
22
23 boolean text_drawing_enabled = TRUE;
24
25
26 // ============================================================================
27 // font functions
28 // ============================================================================
29
30 void EnableDrawingText(void)
31 {
32   text_drawing_enabled = TRUE;
33 }
34
35 void DisableDrawingText(void)
36 {
37   text_drawing_enabled = FALSE;
38 }
39
40 void InitFontInfo(struct FontBitmapInfo *font_bitmap_info, int num_fonts,
41                   int (*select_font_function)(int),
42                   int (*get_font_from_token_function)(char *),
43                   char * (*get_token_from_font_function)(int))
44 {
45   gfx.num_fonts = num_fonts;
46   gfx.font_bitmap_info = font_bitmap_info;
47   gfx.select_font_function = select_font_function;
48   gfx.get_font_from_token_function = get_font_from_token_function;
49   gfx.get_token_from_font_function = get_token_from_font_function;
50 }
51
52 void FreeFontInfo(struct FontBitmapInfo *font_bitmap_info)
53 {
54   if (font_bitmap_info == NULL)
55     return;
56
57   free(font_bitmap_info);
58 }
59
60 struct FontBitmapInfo *getFontBitmapInfo(int font_nr)
61 {
62   int font_bitmap_id = gfx.select_font_function(font_nr);
63
64   return &gfx.font_bitmap_info[font_bitmap_id];
65 }
66
67 int getFontWidth(int font_nr)
68 {
69   int font_bitmap_id = gfx.select_font_function(font_nr);
70
71   return gfx.font_bitmap_info[font_bitmap_id].width;
72 }
73
74 int getFontHeight(int font_nr)
75 {
76   int font_bitmap_id = gfx.select_font_function(font_nr);
77
78   return gfx.font_bitmap_info[font_bitmap_id].height;
79 }
80
81 int getFontDrawOffsetX(int font_nr)
82 {
83   int font_bitmap_id = gfx.select_font_function(font_nr);
84
85   return gfx.font_bitmap_info[font_bitmap_id].draw_xoffset;
86 }
87
88 int getFontDrawOffsetY(int font_nr)
89 {
90   int font_bitmap_id = gfx.select_font_function(font_nr);
91
92   return gfx.font_bitmap_info[font_bitmap_id].draw_yoffset;
93 }
94
95 int getTextWidth(char *text, int font_nr)
96 {
97   return (text != NULL ? strlen(text) * getFontWidth(font_nr) : 0);
98 }
99
100 static int getFontCharPosition(int font_nr, char c)
101 {
102   int font_bitmap_id = gfx.select_font_function(font_nr);
103   struct FontBitmapInfo *font = &gfx.font_bitmap_info[font_bitmap_id];
104   boolean default_font = (font->num_chars == DEFAULT_NUM_CHARS_PER_FONT);
105   int font_pos = (unsigned char)c - 32;
106
107   // map some special characters to their ascii values in default font
108   if (default_font)
109     font_pos = MAP_FONT_ASCII(c) - 32;
110
111   // this allows dynamic special characters together with special font
112   if (font_pos < 0 || font_pos >= font->num_chars)
113     font_pos = 0;
114
115   return font_pos;
116 }
117
118 void getFontCharSource(int font_nr, char c, Bitmap **bitmap, int *x, int *y)
119 {
120   int font_bitmap_id = gfx.select_font_function(font_nr);
121   struct FontBitmapInfo *font = &gfx.font_bitmap_info[font_bitmap_id];
122   int font_pos = getFontCharPosition(font_nr, c);
123   int offset_x = (font->offset_x != 0 ? font->offset_x : font->width);
124   int offset_y = (font->offset_y != 0 ? font->offset_y : font->height);
125
126   *bitmap = font->bitmap;
127   *x = font->src_x + (font_pos % font->num_chars_per_line) * offset_x;
128   *y = font->src_y + (font_pos / font->num_chars_per_line) * offset_y;
129 }
130
131
132 // ============================================================================
133 // text string helper functions
134 // ============================================================================
135
136 int maxWordLengthInRequestString(char *text)
137 {
138   char *text_ptr;
139   int word_len = 0, max_word_len = 0;
140
141   for (text_ptr = text; *text_ptr; text_ptr++)
142   {
143     word_len = (*text_ptr != ' ' &&
144                 *text_ptr != '?' &&
145                 *text_ptr != '!' ? word_len + 1 : 0);
146
147     max_word_len = MAX(word_len, max_word_len);
148   }
149
150   return max_word_len;
151 }
152
153
154 // ============================================================================
155 // simple text drawing functions
156 // ============================================================================
157
158 static void DrawInitTextExt(char *text, int ypos, int font_nr, boolean update)
159 {
160   LimitScreenUpdates(TRUE);
161
162   UPDATE_BUSY_STATE();
163
164   if (!text_drawing_enabled)
165     return;
166
167   if (window != NULL &&
168       gfx.draw_init_text &&
169       gfx.num_fonts > 0 &&
170       gfx.font_bitmap_info[font_nr].bitmap != NULL)
171   {
172     int x = (video.width - getTextWidth(text, font_nr)) / 2;
173     int y = ypos;
174     int width = video.width;
175     int height = getFontHeight(font_nr);
176
177     ClearRectangleOnBackground(drawto, 0, y, width, height);
178     DrawTextExt(drawto, x, y, text, font_nr, BLIT_MASKED);
179
180     if (update)
181       BlitBitmap(drawto, window, 0, 0, video.width, video.height, 0, 0);
182   }
183 }
184
185 void DrawInitText(char *text, int ypos, int font_nr)
186 {
187   DrawInitTextExt(text, ypos, font_nr, FALSE);
188 }
189
190 void DrawInitTextHead(char *text)
191 {
192   DrawInitTextExt(text, 120, FC_GREEN, FALSE);
193 }
194
195 void DrawInitTextItem(char *text)
196 {
197   DrawInitTextExt(text, 150, FC_YELLOW, TRUE);
198 }
199
200 void DrawTextF(int x, int y, int font_nr, char *format, ...)
201 {
202   char buffer[MAX_OUTPUT_LINESIZE + 1];
203   va_list ap;
204
205   va_start(ap, format);
206   vsprintf(buffer, format, ap);
207   va_end(ap);
208
209   if (strlen(buffer) > MAX_OUTPUT_LINESIZE)
210     Fail("string too long in DrawTextF() -- aborting");
211
212   DrawText(gfx.sx + x, gfx.sy + y, buffer, font_nr);
213 }
214
215 void DrawTextFCentered(int y, int font_nr, char *format, ...)
216 {
217   char buffer[MAX_OUTPUT_LINESIZE + 1];
218   va_list ap;
219
220   va_start(ap, format);
221   vsprintf(buffer, format, ap);
222   va_end(ap);
223
224   if (strlen(buffer) > MAX_OUTPUT_LINESIZE)
225     Fail("string too long in DrawTextFCentered() -- aborting");
226
227   DrawText(gfx.sx + (gfx.sxsize - getTextWidth(buffer, font_nr)) / 2,
228            gfx.sy + y, buffer, font_nr);
229 }
230
231 void DrawTextS(int x, int y, int font_nr, char *text)
232 {
233   DrawText(gfx.sx + x, gfx.sy + y, text, font_nr);
234 }
235
236 void DrawTextSCentered(int y, int font_nr, char *text)
237 {
238   DrawText(gfx.sx + (gfx.sxsize - getTextWidth(text, font_nr)) / 2,
239            gfx.sy + y, text, font_nr);
240 }
241
242 void DrawTextSAligned(int x, int y, char *text, int font_nr, int align)
243 {
244   DrawText(gfx.sx + ALIGNED_XPOS(x, getTextWidth(text, font_nr), align),
245            gfx.sy + y, text, font_nr);
246 }
247
248 void DrawText(int x, int y, char *text, int font_nr)
249 {
250   int mask_mode = BLIT_OPAQUE;
251
252   if (DrawingOnBackground(x, y))
253     mask_mode = BLIT_ON_BACKGROUND;
254
255   DrawTextExt(drawto, x, y, text, font_nr, mask_mode);
256
257   if (IN_GFX_FIELD_FULL(x, y))
258     redraw_mask |= REDRAW_FIELD;
259   else if (IN_GFX_DOOR_1(x, y))
260     redraw_mask |= REDRAW_DOOR_1;
261   else if (IN_GFX_DOOR_2(x, y))
262     redraw_mask |= REDRAW_DOOR_2;
263   else if (IN_GFX_DOOR_3(x, y))
264     redraw_mask |= REDRAW_DOOR_3;
265   else
266     redraw_mask |= REDRAW_ALL;
267 }
268
269 void DrawTextExt(DrawBuffer *dst_bitmap, int dst_x, int dst_y, char *text,
270                  int font_nr, int mask_mode)
271 {
272   struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
273   int font_width = getFontWidth(font_nr);
274   int font_height = getFontHeight(font_nr);
275   Bitmap *src_bitmap;
276   int src_x, src_y;
277   char *text_ptr = text;
278
279   if (!text_drawing_enabled)
280     return;
281
282 #if DEBUG
283   Debug("font:token", "'%s' / '%s'",
284         gfx.get_token_from_font_function(font_nr), text);
285 #endif
286
287   if (font->bitmap == NULL)
288     return;
289
290   // skip text to be printed outside the window (left/right will be clipped)
291   if (dst_y < 0 || dst_y + font_height > video.height)
292     return;
293
294   // add offset for drawing font characters
295   dst_x += font->draw_xoffset;
296   dst_y += font->draw_yoffset;
297
298   while (*text_ptr)
299   {
300     char c = *text_ptr++;
301
302     if (c == '\n')
303       c = ' ';          // print space instead of newline
304
305     getFontCharSource(font_nr, c, &src_bitmap, &src_x, &src_y);
306
307     // clip text at the left side of the window
308     if (dst_x < 0)
309     {
310       dst_x += font_width;
311
312       continue;
313     }
314
315     // clip text at the right side of the window
316     if (dst_x + font_width > video.width)
317       break;
318
319     if (mask_mode == BLIT_INVERSE)      // special mode for text gadgets
320     {
321       // first step: draw solid colored rectangle (use "cursor" character)
322       if (strlen(text) == 1)    // only one char inverted => draw cursor
323       {
324         Bitmap *cursor_bitmap;
325         int cursor_x, cursor_y;
326
327         getFontCharSource(font_nr, FONT_ASCII_CURSOR, &cursor_bitmap,
328                           &cursor_x, &cursor_y);
329
330         BlitBitmap(cursor_bitmap, dst_bitmap, cursor_x, cursor_y,
331                    font_width, font_height, dst_x, dst_y);
332       }
333
334       // second step: draw masked inverted character
335       SDLCopyInverseMasked(src_bitmap, dst_bitmap, src_x, src_y,
336                            font_width, font_height, dst_x, dst_y);
337     }
338     else if (mask_mode == BLIT_MASKED || mask_mode == BLIT_ON_BACKGROUND)
339     {
340       if (mask_mode == BLIT_ON_BACKGROUND)
341       {
342         // clear font character background
343         ClearRectangleOnBackground(dst_bitmap, dst_x, dst_y,
344                                    font_width, font_height);
345       }
346
347       BlitBitmapMasked(src_bitmap, dst_bitmap, src_x, src_y,
348                        font_width, font_height, dst_x, dst_y);
349     }
350     else        // normal, non-masked font blitting
351     {
352       BlitBitmap(src_bitmap, dst_bitmap, src_x, src_y,
353                  font_width, font_height, dst_x, dst_y);
354     }
355
356     dst_x += font_width;
357   }
358 }
359
360
361 // ============================================================================
362 // text buffer drawing functions
363 // ============================================================================
364
365 #define MAX_LINES_FROM_FILE             1024
366
367 char *GetTextBufferFromFile(char *filename, int max_lines)
368 {
369   File *file;
370   char *buffer;
371   int num_lines = 0;
372
373   if (filename == NULL)
374     return NULL;
375
376   if (!(file = openFile(filename, MODE_READ)))
377     return NULL;
378
379   buffer = checked_calloc(1);   // start with valid, but empty text buffer
380
381   while (!checkEndOfFile(file) && num_lines < max_lines)
382   {
383     char line[MAX_LINE_LEN];
384     char *line_ptr;
385     int line_len;
386
387     // read next line of input file
388     if (!getStringFromFile(file, line, MAX_LINE_LEN))
389       break;
390
391     line_len = strlen(line);
392
393     // cut trailing line break (this can be newline and/or carriage return)
394     for (line_ptr = &line[line_len]; line_ptr >= line; line_ptr--)
395       if ((*line_ptr == '\n' || *line_ptr == '\r') && *(line_ptr + 1) == '\0')
396         *line_ptr = '\0';
397
398     // re-add newline (so the result is terminated by newline, but not CR/LF)
399     if (strlen(line) != line_len)
400       strcat(line, "\n");
401
402     buffer = checked_realloc(buffer, strlen(buffer) + strlen(line) + 1);
403
404     strcat(buffer, line);
405
406     num_lines++;
407   }
408
409   closeFile(file);
410
411   if (getTextEncoding(buffer) == TEXT_ENCODING_UTF_8)
412   {
413     char *body_latin1 = getLatin1FromUTF8(buffer);
414
415     checked_free(buffer);
416
417     buffer = body_latin1;
418   }
419
420   return buffer;
421 }
422
423 static boolean RenderLineToBuffer(char **src_buffer_ptr, char *dst_buffer,
424                                   int *dst_buffer_len, int line_length,
425                                   boolean last_line_was_empty)
426 {
427   char *text_ptr = *src_buffer_ptr;
428   char *buffer = dst_buffer;
429   int buffer_len = *dst_buffer_len;
430   boolean buffer_filled = FALSE;
431
432   while (*text_ptr)
433   {
434     char *word_ptr;
435     int word_len;
436
437     if (strEqual(text_ptr, "  "))       // special case: force line break
438       buffer_filled = TRUE;
439
440     // skip leading whitespaces
441     while (*text_ptr == ' ' || *text_ptr == '\t')
442       text_ptr++;
443
444     word_ptr = text_ptr;
445     word_len = 0;
446
447     // look for end of next word
448     while (*word_ptr != ' ' && *word_ptr != '\t' && *word_ptr != '\0')
449     {
450       word_ptr++;
451       word_len++;
452     }
453
454     if (word_len == 0)
455     {
456       continue;
457     }
458     else if (*text_ptr == '\n')         // special case: force empty line
459     {
460       if (buffer_len == 0)
461         text_ptr++;
462
463       // prevent printing of multiple empty lines
464       if (buffer_len > 0 || !last_line_was_empty)
465         buffer_filled = TRUE;
466     }
467     else if (word_len < line_length - buffer_len)
468     {
469       // word fits into text buffer -- add word
470
471       if (buffer_len > 0)
472         buffer[buffer_len++] = ' ';
473
474       strncpy(&buffer[buffer_len], text_ptr, word_len);
475       buffer_len += word_len;
476       buffer[buffer_len] = '\0';
477       text_ptr += word_len;
478     }
479     else if (buffer_len > 0)
480     {
481       // not enough space left for word in text buffer -- print buffer
482
483       buffer_filled = TRUE;
484     }
485     else
486     {
487       // word does not fit at all into empty text buffer -- cut word
488
489       strncpy(buffer, text_ptr, line_length);
490       buffer[line_length] = '\0';
491       text_ptr += line_length;
492       buffer_filled = TRUE;
493     }
494
495     if (buffer_filled)
496       break;
497   }
498
499   *src_buffer_ptr = text_ptr;
500   *dst_buffer_len = buffer_len;
501
502   return buffer_filled;
503 }
504
505 static boolean getCheckedTokenValueFromString(char *string, char **token,
506                                               char **value)
507 {
508   char *ptr;
509
510   if (!getTokenValueFromString(string, token, value))
511     return FALSE;
512
513   if (**token != '.')                   // token should begin with dot
514     return FALSE;
515
516   for (ptr = *token; *ptr; ptr++)       // token should contain no whitespace
517     if (*ptr == ' ' || *ptr == '\t')
518       return FALSE;
519
520   for (ptr = *value; *ptr; ptr++)       // value should contain no whitespace
521     if (*ptr == ' ' || *ptr == '\t')
522       return FALSE;
523
524   return TRUE;
525 }
526
527 static void DrawTextBuffer_Flush(int x, int y, char *buffer, int base_font_nr,
528                                  int font_nr, int line_length, int cut_length,
529                                  int mask_mode, boolean centered,
530                                  int current_ypos)
531 {
532   int buffer_len = strlen(buffer);
533   int base_font_width = getFontWidth(base_font_nr);
534   int font_width = getFontWidth(font_nr);
535   int offset_chars = (centered ? (line_length - buffer_len) / 2 : 0);
536   int line_width = base_font_width * line_length;
537   int buffer_width = font_width * buffer_len;
538   int offset_xsize = (centered ? (line_width - buffer_width) / 2 : 0);
539   int final_cut_length = MAX(0, cut_length - offset_chars);
540   int xx = x + offset_xsize;
541   int yy = y + current_ypos;
542
543   buffer[final_cut_length] = '\0';
544
545   if (mask_mode != -1)
546     DrawTextExt(drawto, xx, yy, buffer, font_nr, mask_mode);
547   else
548     DrawText(xx, yy, buffer, font_nr);
549 }
550
551 static int DrawTextBufferExt(int x, int y, char *text_buffer, int base_font_nr,
552                              int line_length, int cut_length, int max_lines,
553                              int line_spacing, int mask_mode, boolean autowrap,
554                              boolean centered, boolean parse_comments,
555                              boolean is_text_area)
556 {
557   char buffer[line_length + 1];
558   int buffer_len;
559   int font_nr = base_font_nr;
560   int font_height = getFontHeight(font_nr);
561   int line_height = font_height + line_spacing;
562   int current_line = 0;
563   int current_ypos = 0;
564   int max_ysize = max_lines * line_height;
565
566   if (text_buffer == NULL || *text_buffer == '\0')
567     return 0;
568
569   if (current_line >= max_lines)
570     return 0;
571
572   if (cut_length == -1)
573     cut_length = line_length;
574
575   buffer[0] = '\0';
576   buffer_len = 0;
577
578   while (*text_buffer && current_ypos < max_ysize)
579   {
580     char line[MAX_LINE_LEN + 1];
581     char *line_ptr;
582     boolean last_line_was_empty = TRUE;
583     int num_line_chars = MAX_LINE_LEN;
584     int i;
585
586     // copy next line from text buffer to line buffer (nearly fgets() style)
587     for (i = 0; i < num_line_chars && *text_buffer; i++)
588     {
589       if ((line[i] = *text_buffer++) == '\n')
590       {
591         // in text areas, 'line_length' sized lines cause additional empty line
592         if (i == line_length && is_text_area)
593           text_buffer--;
594
595         break;
596       }
597     }
598     line[i] = '\0';
599
600     // prevent 'num_line_chars' sized lines to cause additional empty line
601     if (i == num_line_chars && *text_buffer == '\n')
602       text_buffer++;
603
604     // skip comments (lines directly beginning with '#')
605     if (line[0] == '#' && parse_comments)
606     {
607       char *token, *value;
608
609       // try to read generic token/value pair definition after comment sign
610       if (getCheckedTokenValueFromString(line + 1, &token, &value))
611       {
612         // if found, flush the current buffer, if non-empty
613         if (buffer_len > 0 && current_ypos < max_ysize)
614         {
615           DrawTextBuffer_Flush(x, y, buffer, base_font_nr, font_nr, line_length,
616                                cut_length, mask_mode, centered, current_ypos);
617           current_ypos += line_height;
618           current_line++;
619
620           buffer[0] = '\0';
621           buffer_len = 0;
622         }
623
624         if (strEqual(token, ".font"))
625           font_nr = gfx.get_font_from_token_function(value);
626         else if (strEqual(token, ".autowrap"))
627           autowrap = get_boolean_from_string(value);
628         else if (strEqual(token, ".centered"))
629           centered = get_boolean_from_string(value);
630         else if (strEqual(token, ".parse_comments"))
631           parse_comments = get_boolean_from_string(value);
632
633         // if font has changed, depending values need to be updated as well
634         font_height = getFontHeight(font_nr);
635         line_height = font_height + line_spacing;
636       }
637
638       continue;
639     }
640
641     // cut trailing newline and carriage return from input line
642     for (line_ptr = line; *line_ptr; line_ptr++)
643     {
644       if (*line_ptr == '\n' || *line_ptr == '\r')
645       {
646         *line_ptr = '\0';
647         break;
648       }
649     }
650
651     if (strlen(line) == 0)              // special case: force empty line
652       strcpy(line, "\n");
653
654     line_ptr = line;
655
656     while (*line_ptr && current_ypos < max_ysize)
657     {
658       boolean buffer_filled;
659
660       if (autowrap)
661       {
662         buffer_filled = RenderLineToBuffer(&line_ptr, buffer, &buffer_len,
663                                            line_length, last_line_was_empty);
664       }
665       else
666       {
667         if (strlen(line_ptr) <= line_length)
668         {
669           buffer_len = strlen(line_ptr);
670           strcpy(buffer, line_ptr);
671         }
672         else
673         {
674           buffer_len = line_length;
675           strncpy(buffer, line_ptr, line_length);
676         }
677
678         buffer[buffer_len] = '\0';
679         line_ptr += buffer_len;
680
681         buffer_filled = TRUE;
682       }
683
684       if (buffer_filled)
685       {
686         DrawTextBuffer_Flush(x, y, buffer, base_font_nr, font_nr, line_length,
687                              cut_length, mask_mode, centered, current_ypos);
688         current_ypos += line_height;
689         current_line++;
690
691         last_line_was_empty = (buffer_len == 0);
692
693         buffer[0] = '\0';
694         buffer_len = 0;
695       }
696     }
697   }
698
699   if (buffer_len > 0 && current_ypos < max_ysize)
700   {
701     DrawTextBuffer_Flush(x, y, buffer, base_font_nr, font_nr, line_length,
702                          cut_length, mask_mode, centered, current_ypos);
703     current_ypos += line_height;
704     current_line++;
705   }
706
707   return current_line;
708 }
709
710 int DrawTextArea(int x, int y, char *text_buffer, int font_nr,
711                  int line_length, int cut_length, int max_lines,
712                  int line_spacing, int mask_mode, boolean autowrap,
713                  boolean centered, boolean parse_comments)
714 {
715   return DrawTextBufferExt(x, y, text_buffer, font_nr,
716                            line_length, cut_length, max_lines,
717                            line_spacing, mask_mode, autowrap,
718                            centered, parse_comments, TRUE);
719 }
720
721 int DrawTextBuffer(int x, int y, char *text_buffer, int font_nr,
722                    int line_length, int cut_length, int max_lines,
723                    int line_spacing, int mask_mode, boolean autowrap,
724                    boolean centered, boolean parse_comments)
725 {
726   return DrawTextBufferExt(x, y, text_buffer, font_nr,
727                            line_length, cut_length, max_lines,
728                            line_spacing, mask_mode, autowrap,
729                            centered, parse_comments, FALSE);
730 }
731
732 int DrawTextBufferS(int x, int y, char *text_buffer, int font_nr,
733                     int line_length, int cut_length, int max_lines,
734                     int line_spacing, int mask_mode, boolean autowrap,
735                     boolean centered, boolean parse_comments)
736 {
737   return DrawTextBuffer(gfx.sx + x, gfx.sy + y, text_buffer, font_nr,
738                         line_length, cut_length, max_lines,
739                         line_spacing, mask_mode, autowrap,
740                         centered, parse_comments);
741 }
742
743 int DrawTextBufferVA(int x, int y, char *format, va_list ap, int font_nr,
744                      int line_length, int cut_length, int max_lines,
745                      int line_spacing, int mask_mode, boolean autowrap,
746                      boolean centered, boolean parse_comments)
747 {
748   char text_buffer[MAX_OUTPUT_LINESIZE];
749   int text_length = vsnprintf(text_buffer, MAX_OUTPUT_LINESIZE, format, ap);
750
751   if (text_length >= MAX_OUTPUT_LINESIZE)
752     Warn("string too long in DrawTextBufferVA() -- truncated");
753
754   int num_lines_printed = DrawTextBuffer(x, y, text_buffer, font_nr,
755                                          line_length, cut_length, max_lines,
756                                          line_spacing, mask_mode, autowrap,
757                                          centered, parse_comments);
758   return num_lines_printed;
759 }
760
761 int DrawTextFile(int x, int y, char *filename, int font_nr,
762                  int line_length, int cut_length, int max_lines,
763                  int line_spacing, int mask_mode, boolean autowrap,
764                  boolean centered, boolean parse_comments)
765 {
766   char *text_buffer = GetTextBufferFromFile(filename, MAX_LINES_FROM_FILE);
767   int num_lines_printed = DrawTextBuffer(x, y, text_buffer, font_nr,
768                                          line_length, cut_length, max_lines,
769                                          line_spacing, mask_mode, autowrap,
770                                          centered, parse_comments);
771   checked_free(text_buffer);
772
773   return num_lines_printed;
774 }