Implemented 2D Fonts
Selecting 2D fonts
In any class implementing mrpt::utils::CCanvas, the text font can be selected using CCanvas::selectTextFont. Next, text can be drawn with CCanvas::textOut. Note that one of the most commonly used implementations of CCanvas is CImage.
List of fonts
- “6×13”
- “6x13B” (bold)
- “6x13O” (italic)
- “9×15”
- “9x15B” (bold)
- “10×20”
- “18x18ja” (Japanese, UNICODE character values)
The following image is taken from the example MRPT/samples/textFonts
, refer to the source code for further details.
[spoiler title=”See C++ code” style=”2″]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
#include <mrpt/utils.h> #include <mrpt/gui.h> using namespace mrpt; using namespace mrpt::gui; using namespace mrpt::utils; using namespace std; // ------------------------------------------------------ // TestFonts // ------------------------------------------------------ void TestFonts() { CImage img(400,300); img.filledRectangle(0,0,400,300, TColor(0x50,0x50,0x50) ); int y = 10; img.selectTextFont("5x7"); img.textOut(10,y,"Hello World! with font \"5x7\"", TColor::white); y+=20; img.selectTextFont("6x13"); img.textOut(10,y,"Hello World! with font \"6x13\"", TColor::white); y+=20; img.selectTextFont("6x13B"); img.textOut(10,y,"Hello World! with font \"6x13B\"", TColor::white); y+=20; img.selectTextFont("6x13O"); img.textOut(10,y,"Hello World! with font \"6x13O\"", TColor::white); y+=20; img.selectTextFont("9x15"); img.textOut(10,y,"Hello World! with font \"9x15\"", TColor::white); y+=20; img.selectTextFont("9x15B"); img.textOut(10,y,"Hello World! with font \"9x15B\"", TColor::white); y+=20; img.selectTextFont("18x18ja"); img.textOut(10,y,"MRPTのフォントは易しいです!", TColor::white); y+=20; img.selectTextFont("10x20"); img.textOut(10,y,"Hello World! with font \"10x20\"", TColor::white); y+=20; CDisplayWindow win1("MRPT - Demo of text fonts render"); win1.setPos(10,10); win1.showImage( img ); cout << "Push a key in the console or in the window to continue..."; win1.waitForKey(); cout << "Done" << endl; } // ------------------------------------------------------ // MAIN // ------------------------------------------------------ int main() { try { TestFonts(); return 0; } catch (std::exception &e) { std::cout << "MRPT exception caught: " << e.what() << std::endl; return -1; } catch (...) { printf("Untyped exception!!"); return -1; } } |