Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions code/graphics/software/font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,15 @@ namespace font
return w;
}

int force_fit_string(SCP_string &str, size_t max_str_len, int max_width, float scale)
{
// the char* overload only ever shortens the string, so operating on the buffer
// in-place and resizing to the new length afterward is safe
int width = force_fit_string(str.data(), max_str_len, max_width, scale);
str.resize(strlen(str.c_str()));
return width;
}

void stuff_first(SCP_string &firstFont)
{
try
Expand Down
11 changes: 11 additions & 0 deletions code/graphics/software/font.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ namespace font
*/
int force_fit_string(char *str, size_t max_str_len, int max_width, float scale = 1.0f);

/**
* Crops a string if required to force it to not exceed max_width pixels when printed.
* Does this by dropping characters at the end of the string and adding '...' to the end.
*
* @param str string to crop. Modifies this string directly
* @param max_str_len max characters allowed in str (not including \0)
* @param max_width number of pixels to limit string to (less than or equal to).
* @return The width of the string
*/
int force_fit_string(SCP_string &str, size_t max_str_len, int max_width, float scale = 1.0f);

/**
* @brief Inites the font system
*
Expand Down
Loading
Loading