You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Design a Text object that allows you to set its size, color, and value. Its most important feature is to retrieve the text width and height so that developers can check whether they fit in a given region. For example, the feature allows you to check whether the text could fit inside a box of a given height and width.
A possible solution would be to create an image object, drawtext on it, then retrieve the objects resulting width and height as described here. The suggested code is shown below for reference:
CImg<unsignedchar> imgtext;
unsignedchar color = 1;
imgtext.draw_text(0,0,"Hello guys !",&color,0,1,23); // Draw with font height 23.// Now, imgtext.width() and imgtext.height() gives you the dimensions you want.
You could also implement this as helper methods rather than exposing it as a text object. For example, there could be a helper method int graphics::GetTextWidth(std::string text, int font_size).
Activity
dektar commentedon Jan 12, 2021
You could also implement this as helper methods rather than exposing it as a text object. For example, there could be a helper method
int graphics::GetTextWidth(std::string text, int font_size).pinventado commentedon Jan 12, 2021
Hmm that's a good point. Thanks :)