void initializeBitmapFont(FontDefinition& fontDefinition, int texture_id, const Color& fillColor) { int width = 0; int height = 0; ID3D11ShaderResourceView* texture = assets::getRawTexture(texture_id); assert(texture != 0); BYTE* data = getImageData(texture, &width, &height); int x = fontDefinition.startX + fontDefinition.padding - 1; int y = fontDefinition.startY + fontDefinition.padding; uint32 ascii = fontDefinition.startChar; Color c = getColor(data, x, y, width); bool running = true; bool isChar = false; int charStartedX = 0; int charStartedY = 0; int charCount = 0; while (running) { ++x; if (x > (fontDefinition.startX + fontDefinition.width)) { x = fontDefinition.startX + fontDefinition.padding - 1; y += fontDefinition.padding + fontDefinition.gridHeight;// - 1; isChar = false; charCount = 0; } if (y >= (fontDefinition.startY + fontDefinition.height)) { running = false; } if (y >= height) { running = false; } if (running) { c = getColor(data, x, y, width); if ( c != fillColor && !isChar) { isChar = true; charStartedX = x; charStartedY = y; } else if (c == fillColor && isChar) { isChar = false; int width = x - charStartedX - 1; ++charCount; fontDefinition.addChar(ascii, charStartedX + 1, charStartedY, width); ++ascii; } } } delete[] data; }
TEST_F(LUATest, testFontDefinition) { FontDefinition d; ASSERT_FALSE(d.begin() == d.end()) << "no fonts found"; // 5 font definitions ASSERT_EQ((int)std::distance(d.begin(), d.end()), 5); for (auto i = d.begin(); i != d.end(); ++i) { const FontDefPtr& def = i->second; ASSERT_EQ(def->getFontChar('%'), nullptr); ASSERT_EQ(def->getFontChar('a')->getCharacter(), 'a'); ASSERT_EQ(def->getFontChar('A')->getCharacter(), 'A'); ASSERT_EQ(def->getFontChar(' ')->getCharacter(), ' '); ASSERT_EQ(def->getFontChar('1')->getCharacter(), '1'); ASSERT_NE(def->getFontChar('a')->getH(), 0); ASSERT_NE(def->getFontChar('a')->getW(), 0); ASSERT_NE(def->textureHeight, 0); ASSERT_NE(def->textureWidth, 0); ASSERT_NE(def->textureName, ""); ASSERT_NE(def->id, ""); } }
TEST_F(LUATest, testFontDefinition) { FontDefinition d; ASSERT_FALSE(d.begin() == d.end()) << "no fonts found"; }