MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / get_text_line_width

Method get_text_line_width

2dlib/pentext.cpp:231–259  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

229// returns length in pixels of text line using current text spacing settings
230
231int grViewport::get_text_line_width(char *str) {
232 int line_width = 0;
233 int rgb_define_mode = 0;
234
235 for (int i = 0; i < (int)strlen(str); i++) {
236 int width;
237
238 // note that if we hit the GR_COLOR_CHAR then the next three values should
239 // not count when defining the width of the line.
240 if (rgb_define_mode == 3)
241 rgb_define_mode = 0;
242 else if (str[i] == GR_COLOR_CHAR)
243 rgb_define_mode = 1;
244 if (!rgb_define_mode) {
245 if (str[i] == '\t') { // tab char
246 int space_width;
247 text_Font.get_char_info(' ', &space_width);
248 space_width += text_Spacing;
249 line_width = (line_width + space_width - 1) / space_width * space_width;
250 } else {
251 text_Font.get_char_info((int)str[i], &width);
252 line_width += (width + get_text_spacing());
253 }
254 } else
255 rgb_define_mode++;
256 }
257
258 return line_width - get_text_spacing();
259}
260
261/* These internal routines just draw a line of text. depending on the function
262 we clip or don't clip

Callers

nothing calls this directly

Calls 1

get_char_infoMethod · 0.80

Tested by

no test coverage detected