MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / exportStrip

Method exportStrip

Engine/source/gfx/gFont.cpp:827–882  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

825}
826
827void GFont::exportStrip(const char *fileName, U32 padding, U32 kerning)
828{
829 // Figure dimensions of our strip by iterating over all the char infos.
830 U32 totalHeight = 0;
831 U32 totalWidth = 0;
832
833 S32 heightMin=0, heightMax=0;
834
835 for(S32 i=0; i<mCharInfoList.size(); i++)
836 {
837 totalWidth += mCharInfoList[i].width + kerning + 2*padding;
838 heightMin = getMin((S32)heightMin, (S32)getBaseline() - (S32)mCharInfoList[i].yOrigin);
839 heightMax = getMax((S32)heightMax, (S32)getBaseline() - (S32)mCharInfoList[i].yOrigin + (S32)mCharInfoList[i].height);
840 }
841
842 totalHeight = heightMax - heightMin + 2*padding;
843
844 // Make the bitmap.
845 GBitmap gb(totalWidth, totalHeight, false, mTextureSheets[0].getBitmap()->getFormat());
846
847 dMemset(gb.getWritableBits(), 0, sizeof(U8) * totalHeight * totalWidth );
848
849 // Ok, copy some rects, taking into account padding, kerning, offset.
850 U32 curWidth = kerning + padding;
851
852 for(S32 i=0; i<mCharInfoList.size(); i++)
853 {
854 // Skip invalid stuff.
855 if(mCharInfoList[i].bitmapIndex == -1 || mCharInfoList[i].height == 0 || mCharInfoList[i].width == 0)
856 continue;
857
858 // Copy the rect.
859 U32 bitmap = mCharInfoList[i].bitmapIndex;
860
861 RectI ri(mCharInfoList[i].xOffset, mCharInfoList[i].yOffset, mCharInfoList[i].width, mCharInfoList[i].height );
862 Point2I outRi(curWidth, padding + getBaseline() - mCharInfoList[i].yOrigin);
863 gb.copyRect(mTextureSheets[bitmap].getBitmap(), ri, outRi);
864
865 // Advance.
866 curWidth += mCharInfoList[i].width + kerning + 2*padding;
867 }
868
869 // Write the image!
870 FileStream fs;
871
872 fs.open( fileName, Torque::FS::File::Write );
873
874 if(fs.getStatus() != Stream::Ok)
875 {
876 Con::errorf("GFont::exportStrip - failed to open '%s' for writing.", fileName);
877 return;
878 }
879
880 // Done!
881 gb.writeBitmap("png", fs);
882}
883
884void GFont::setPlatformFont(PlatformFont *inPlatformFont)

Callers 1

gFont.cppFile · 0.80

Calls 11

getMaxFunction · 0.85
getWritableBitsMethod · 0.80
copyRectMethod · 0.80
writeBitmapMethod · 0.80
openMethod · 0.65
dMemsetFunction · 0.50
errorfFunction · 0.50
sizeMethod · 0.45
getFormatMethod · 0.45
getBitmapMethod · 0.45
getStatusMethod · 0.45

Tested by

no test coverage detected