+ int font_bitmap_id = gfx.select_font_function(font_nr);
+ struct FontBitmapInfo *font = &gfx.font_bitmap_info[font_bitmap_id];
+ int font_width = getFontWidth(font_nr);
+ int font_height = getFontHeight(font_nr);
+ Bitmap *src_bitmap;
+ int src_x, src_y;
+ char *text_ptr = text;
+
+ if (font->bitmap == NULL)
+ return;
+
+ /* add offset for drawing font characters */
+ dst_x += font->draw_x;
+ dst_y += font->draw_y;
+
+ while (*text_ptr)
+ {
+ char c = *text_ptr++;
+
+ if (c == '\n')
+ c = ' '; /* print space instaed of newline */
+
+ getFontCharSource(font_nr, c, &src_bitmap, &src_x, &src_y);
+
+ if (mask_mode == BLIT_INVERSE) /* special mode for text gadgets */
+ {
+ /* first step: draw solid colored rectangle (use "cursor" character) */
+ if (strlen(text) == 1) /* only one char inverted => draw cursor */
+ {
+ Bitmap *cursor_bitmap;
+ int cursor_x, cursor_y;
+
+ getFontCharSource(font_nr, FONT_ASCII_CURSOR, &cursor_bitmap,
+ &cursor_x, &cursor_y);
+
+ BlitBitmap(cursor_bitmap, dst_bitmap, cursor_x, cursor_y,
+ font_width, font_height, dst_x, dst_y);
+ }
+
+#if defined(TARGET_SDL)
+ /* second step: draw masked inverted character */
+ SDLCopyInverseMasked(src_bitmap, dst_bitmap, src_x, src_y,
+ font_width, font_height, dst_x, dst_y);
+#else
+ /* second step: draw masked black rectangle (use "space" character) */
+ SetClipOrigin(src_bitmap, src_bitmap->stored_clip_gc,
+ dst_x - src_x, dst_y - src_y);
+ BlitBitmapMasked(src_bitmap, dst_bitmap, 0, 0,
+ font_width, font_height, dst_x, dst_y);
+#endif
+ }
+ else if (mask_mode == BLIT_MASKED || mask_mode == BLIT_ON_BACKGROUND)
+ {
+ if (mask_mode == BLIT_ON_BACKGROUND)
+ {
+ /* clear font character background */
+ ClearRectangleOnBackground(dst_bitmap, dst_x, dst_y,
+ font_width, font_height);
+ }
+
+#if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
+ /* use special font tile clipmasks */
+ {
+ int font_pos = getFontCharPosition(font_nr, c);
+
+ SetClipMask(src_bitmap, font_clip_gc, font->clip_mask[font_pos]);
+ SetClipOrigin(src_bitmap, font_clip_gc, dst_x, dst_y);
+ }
+#else
+ SetClipOrigin(src_bitmap, src_bitmap->stored_clip_gc,
+ dst_x - src_x, dst_y - src_y);
+#endif