Я просто хочу добавить еще одно решение к предложенному Энди, которое является скорее научным подходом и требует немного практики, чтобы овладеть им.
Предположим, вам нужно найти функцию F, котораясопоставляет одну или несколько переменных желаемому единственному значению. В вашем случае это была бы функция F, которая принимает соотношение сторон окна в качестве входных данных и выводит соответствующий размер шрифта.
Как найти такую функцию? Ну ... вам не нужно делать какую-либо математику самостоятельно!
Во-первых, вам нужно начать с некоторых данных:
1. Resize the window randomly
2. Calculate aspect ration (X)
3. Pick an appropriate font size that looks good enough (Y)
4. Repeat the measurement 7 to 10 times (sorry data scientists)
5. Enter the data in Excel - one column for X and another one for Y
6. Insert a scatter chart
7. Choose the best trendline for your data, but avoid the polynomial one
8. Display the trendline equation and use the expression in your code
Теперь я должен упомянуть плюсы и минусы этогоТехника регрессии.
Плюсы:
1. It can solve a wide range of tricky problems:
"I use this 3rd party control, but when the text is too long it overlaps the title bar. How to trim it so it doesn't go beyond the top border?. Deadline is coming!"
2. Even if it doesn't solve the problem perfectly, the results are often acceptable
3. It takes minutes to try out unlike spending a day refreshing your math skills
Минусы:
1. The biggest problem is that to keep it simple, you often lower the number of
variables by assuming some of them to be constant. In this post I've assumed that
the font family won't change for example, neither the font weight.
2. If any of the assumptions does not hold the final result could be even worse
Эта техника хрупкая, но мощная. Используйте его как свое последнее оружие и никогда не оставляйте магическое выражение вроде fontSize = (int) (0.76 + 1.2 * aspectRation), не документируя, как оно появилось.