Skip to content

Instantly share code, notes, and snippets.

@Shtille
Created February 21, 2025 13:14
Show Gist options
  • Save Shtille/5dce58aa019ed841c26e6579f006a9d1 to your computer and use it in GitHub Desktop.
Save Shtille/5dce58aa019ed841c26e6579f006a9d1 to your computer and use it in GitHub Desktop.
Text size convertation from point size to pixel size and vice versa
static inline float PointsToPixels(float points, float dpi)
{
// 1 pt = 0.352778 mm
float mm = 0.352778f * points;
// 1 inch = 25.4 mm
float inches = mm / 25.4f;
return dpi * inches;
}
static inline float PixelsToPoints(float pixels, float dpi)
{
float inches = pixels / dpi;
float mm = inches * 25.4f;
return mm / 0.352778f;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment