Skip to content

Instantly share code, notes, and snippets.

@Shtille
Last active March 28, 2025 15:43
Show Gist options
  • Save Shtille/b8cde04d7dbb093119c7d20f95addb94 to your computer and use it in GitHub Desktop.
Save Shtille/b8cde04d7dbb093119c7d20f95addb94 to your computer and use it in GitHub Desktop.
Get font weight by its style name
static int GetFontWeight(const std::string& styleStr)
{
std::string lowerStr = ::ToLower(styleStr);
const char* style = lowerStr.c_str();
if (std::strlen(style) == 0 ||
std::strstr(style, "normal") != nullptr ||
std::strstr(style, "regular") != nullptr)
return 400;
else if (std::strstr(style, "thin") != nullptr)
return 100;
else if (std::strstr(style, "extralight") != nullptr ||
std::strstr(style, "ultralight") != nullptr)
return 200;
else if (std::strstr(style, "semilight") != nullptr ||
std::strstr(style, "demilight") != nullptr)
return 350;
else if (std::strstr(style, "light") != nullptr)
return 300;
else if (std::strstr(style, "medium") != nullptr)
return 500;
else if (std::strstr(style, "semibold") != nullptr ||
std::strstr(style, "demibold") != nullptr)
return 600;
else if (std::strstr(style, "extrabold") != nullptr ||
std::strstr(style, "ultrabold") != nullptr)
return 800;
else if (std::strstr(style, "bold") != nullptr)
return 700;
else if (std::strstr(style, "extrablack") != nullptr)
return 950;
else if (std::strstr(style, "black") != nullptr ||
std::strstr(style, "heavy") != nullptr)
return 900;
else
return 400;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment