MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / grfont_TranslateToBitmaps

Function grfont_TranslateToBitmaps

grtext/grfont.cpp:821–911  ·  view source on GitHub ↗

translates raw font data to bitmaps.

Source from the content-addressed store, hash-verified

819
820// translates raw font data to bitmaps.
821void grfont_TranslateToBitmaps(int handle) {
822 tFontFileInfo *fntfile;
823 tFontInfo *fnt;
824 int i;
825
826 fnt = &Fonts[handle];
827 fntfile = &Fonts[handle].font;
828
829 // start creating font surfaces, map these surfaces onto bitmaps created via bitmap library
830 // this is needed for the renderer library.
831 // create a 128x128 bitmap.
832 // draw each character into bitmap until we need to create another
833 // surface.
834 uint8_t u = 0, v = 0, w;
835 int ch, num_ch;
836 uint8_t surf_index = 0;
837
838 num_ch = fntfile->max_ascii - fntfile->min_ascii + 1;
839
840 // initialize memory
841 fnt->ch_w = new uint8_t[num_ch];
842 fnt->ch_h = new uint8_t[num_ch];
843 fnt->ch_u = new uint8_t[num_ch];
844 fnt->ch_v = new uint8_t[num_ch];
845 fnt->ch_bmp = new int[num_ch];
846 fnt->ch_uf = new float[num_ch];
847 fnt->ch_vf = new float[num_ch];
848 fnt->ch_wf = new float[num_ch];
849 fnt->ch_hf = new float[num_ch];
850
851 for (i = 0; i < MAX_FONT_BITMAPS; i++)
852 fnt->bmps[i] = -1;
853
854 fnt->bmps[surf_index] = bm_AllocBitmap(GRFONT_SURFACE_WIDTH, GRFONT_SURFACE_HEIGHT, 0);
855 if (fnt->bmps[surf_index] == -1 || fnt->bmps[surf_index] == BAD_BITMAP_HANDLE)
856 Error("TranslateToBitmaps <Bitmap allocation error>");
857 if (fntfile->flags & FT_FMT4444) {
858 GameBitmaps[fnt->bmps[surf_index]].format = BITMAP_FORMAT_4444;
859 }
860
861 grfont_ClearBitmap(fnt->bmps[surf_index]);
862 surf_index++;
863
864 for (ch = 0; ch < num_ch; ch++) {
865 if (fntfile->flags & FT_PROPORTIONAL)
866 w = (int)fntfile->char_widths[ch];
867 else
868 w = (int)fntfile->width;
869
870 if ((u + w) > GRFONT_SURFACE_WIDTH) {
871 u = 0;
872 v += fntfile->height;
873 if ((v + fntfile->height) > GRFONT_SURFACE_HEIGHT) {
874 if (surf_index == MAX_FONT_BITMAPS)
875 Int3();
876 fnt->bmps[surf_index] = bm_AllocBitmap(GRFONT_SURFACE_WIDTH, GRFONT_SURFACE_HEIGHT, 0);
877 if (fnt->bmps[surf_index] == -1 || fnt->bmps[surf_index] == BAD_BITMAP_HANDLE)
878 Error("TranslateToBitmaps <Bitmap allocation error>");

Callers 1

grfont_LoadFunction · 0.85

Calls 6

bm_AllocBitmapFunction · 0.85
ErrorFunction · 0.85
grfont_ClearBitmapFunction · 0.85
grfont_XlateColorCharFunction · 0.85
grfont_XlateMonoCharFunction · 0.85

Tested by

no test coverage detected