| 889 | } |
| 890 | |
| 891 | void GFont::importStrip(const char *fileName, U32 padding, U32 kerning) |
| 892 | { |
| 893 | // Wipe our texture sheets, and reload bitmap data from the specified file. |
| 894 | // Also deal with kerning. |
| 895 | // Also, we may have to load RGBA instead of RGB. |
| 896 | |
| 897 | // Wipe our texture sheets. |
| 898 | mCurSheet = mCurX = mCurY = 0; |
| 899 | mTextureSheets.clear(); |
| 900 | |
| 901 | // Now, load the font strip. |
| 902 | Resource<GBitmap> strip = GBitmap::load(fileName); |
| 903 | |
| 904 | if(!strip) |
| 905 | { |
| 906 | Con::errorf("GFont::importStrip - could not load file '%s'!", fileName); |
| 907 | return; |
| 908 | } |
| 909 | |
| 910 | // And get parsing and copying - load up all the characters as separate |
| 911 | // GBitmaps, sort, then pack. Not terribly efficient but this is basically |
| 912 | // on offline task anyway. |
| 913 | |
| 914 | // Ok, snag some glyphs. |
| 915 | Vector<GlyphMap> glyphList; |
| 916 | glyphList.reserve(mCharInfoList.size()); |
| 917 | |
| 918 | U32 curWidth = 0; |
| 919 | for(S32 i=0; i<mCharInfoList.size(); i++) |
| 920 | { |
| 921 | // Skip invalid stuff. |
| 922 | if(mCharInfoList[i].bitmapIndex == -1 || mCharInfoList[i].height == 0 || mCharInfoList[i].width == 0) |
| 923 | continue; |
| 924 | |
| 925 | // Allocate a new bitmap for this glyph, taking into account kerning and padding. |
| 926 | glyphList.increment(); |
| 927 | GlyphMap& lastGlyphMap = glyphList.last(); |
| 928 | lastGlyphMap.bitmap = new GBitmap(mCharInfoList[i].width + kerning + 2 * padding, mCharInfoList[i].height + 2 * padding, false, strip->getFormat()); |
| 929 | lastGlyphMap.charId = i; |
| 930 | |
| 931 | // Copy the rect. |
| 932 | RectI ri(curWidth, getBaseline() - mCharInfoList[i].yOrigin, lastGlyphMap.bitmap->getWidth(), lastGlyphMap.bitmap->getHeight()); |
| 933 | Point2I outRi(0,0); |
| 934 | lastGlyphMap.bitmap->copyRect(strip, ri, outRi); |
| 935 | |
| 936 | // Update glyph attributes. |
| 937 | mCharInfoList[i].width = lastGlyphMap.bitmap->getWidth(); |
| 938 | mCharInfoList[i].height = lastGlyphMap.bitmap->getHeight(); |
| 939 | mCharInfoList[i].xOffset -= kerning + padding; |
| 940 | mCharInfoList[i].xIncrement += kerning; |
| 941 | mCharInfoList[i].yOffset -= padding; |
| 942 | |
| 943 | // Advance. |
| 944 | curWidth += ri.extent.x; |
| 945 | } |
| 946 | |
| 947 | // Ok, we have a big list of glyphmaps now. So let's sort them, then pack them. |
| 948 | dQsort(glyphList.address(), glyphList.size(), sizeof(GlyphMap), GlyphMapCompare); |
no test coverage detected