MCPcopy Create free account
hub / github.com/davisking/dlib / compute_string_dims

Function compute_string_dims

dlib/image_transforms/draw.h:246–282  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

244 typename alloc
245 >
246 string_dims compute_string_dims (
247 const std::basic_string<T, traits, alloc>& str,
248 const std::shared_ptr<font>& f_ptr = default_font::get_font()
249 )
250 {
251 using string = std::basic_string<T, traits, alloc>;
252
253 const font& f = *f_ptr;
254
255 long height = f.height();
256 long width = 0;
257 for (typename string::size_type i = 0; i < str.size(); ++i)
258 {
259 // ignore the '\r' character
260 if (str[i] == '\r')
261 continue;
262
263 // A combining character should be applied to the previous character, and we
264 // therefore make one step back. If a combining comes right after a newline,
265 // then there must be some kind of error in the string, and we don't combine.
266 if (is_combining_char(str[i]))
267 {
268 width -= f[str[i]].width();
269 }
270
271 if (str[i] == '\n')
272 {
273 height += f.height();
274 width = f.left_overflow();
275 continue;
276 }
277
278 const letter& l = f[str[i]];
279 width += l.width();
280 }
281 return string_dims(width, height);
282 }
283
284// ----------------------------------------------------------------------------------------
285

Callers

nothing calls this directly

Calls 6

is_combining_charFunction · 0.85
string_dimsClass · 0.70
heightMethod · 0.45
sizeMethod · 0.45
widthMethod · 0.45
left_overflowMethod · 0.45

Tested by

no test coverage detected