GLYPH *TBBFRenderer::FindNext(UCS4 cp, int x) { int width = m_img->Width(); int height = m_img->Height(); uint32 *data32 = m_img->Data(); if (x >= width) return nullptr; GLYPH *glyph = new GLYPH; if (!glyph) return nullptr; glyph->x = -1; glyph->w = -1; // Find the left edge of the glyph for (int i = x; i < width && glyph->x == -1; i++) { for (int j = 0; j < height; j++) if (GetAlpha(data32[i + j * width])) { glyph->x = x = i; break; } } // Find the right edge of the glyph for (int i = x; i < width; i++) { int j; for (j = 0; j < height; j++) { if (GetAlpha(data32[i + j * width])) break; } if (j == height) // The whole col was clear, so we found the edge { glyph->w = i - glyph->x; break; } } if (glyph->x == -1 || glyph->w == -1) { delete glyph; return nullptr; } return glyph; }
bool TBBFRenderer::RenderGlyph(TBFontGlyphData *data, UCS4 cp) { if (cp == ' ') return false; GLYPH *glyph; if ((glyph = m_glyph_table.Get(cp)) || (glyph = m_glyph_table.Get('?'))) { data->w = glyph->w; data->h = m_img->Height(); data->stride = m_img->Width(); data->data32 = m_img->Data() + glyph->x; data->rgb = m_rgb ? true : false; return true; } return false; }
TBBitmapFragment *TBBitmapFragmentManager::GetFragmentFromFile(const char *filename, bool dedicated_map) { TBID id(filename); // If we already have a fragment for this filename, return that TBBitmapFragment *frag = m_fragments.Get(id); if (frag) return frag; // Load the file TBImageLoader *img = TBImageLoader::CreateFromFile(filename); if (!img) return nullptr; frag = CreateNewFragment(id, dedicated_map, img->Width(), img->Height(), img->Width(), img->Data()); delete img; return frag; }