Created
February 21, 2025 13:14
-
-
Save Shtille/5dce58aa019ed841c26e6579f006a9d1 to your computer and use it in GitHub Desktop.
Text size convertation from point size to pixel size and vice versa
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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