finalized dpi dependant fontsize calculation

This commit is contained in:
2018-08-25 02:46:37 +02:00
parent cfcfb4b5b9
commit 9d7d0c38d6
4 changed files with 25 additions and 17 deletions

View File

@@ -7,37 +7,44 @@ namespace RothenburgAR.UI
{
public class FontsizeManager : Singleton<FontsizeManager>
{
private const float InchPerPt = 1f / 72f;
private const float PtPerPixel = 0.75f;
// font size in pt relative to dpi specific logical inch
private Dictionary<FontsizeClass, float> sizes = new Dictionary<FontsizeClass, float>
{
{
FontsizeClass.Header, 0.5f
FontsizeClass.Header, 25f
},
{
FontsizeClass.Body, 0.2f
FontsizeClass.Body, 12f
}
};
private void Start()
{
Debug.Log("Screen dpi: " + Screen.dpi);
}
/// <summary>
/// Calculates font size that is roughly equal in size on "all" displays
/// </summary>
public float GetFontsize(FontsizeClass sizeClass)
{
var dpi = 420;//Screen.dpi;
var dpi = Screen.dpi;
var res = Screen.currentResolution;
//TODO remove, just a hack to get readable fonts in the unity preview window
dpi = dpi == 96 ? 320 : dpi;
// Screen diagonal in px
var diagonal = Mathf.Sqrt(Mathf.Pow(res.height, 2) + Mathf.Pow(res.width, 2));
// Screen diagonal in logical inches
var diagonalIn = diagonal / dpi;
var ratio = diagonalIn * sizes[sizeClass];
var fontsizePx = diagonal * ratio;
var fontsizePt = fontsizePx * 0.75f;
// ratio of font size to screen size
var ratio = sizes[sizeClass] * InchPerPt / diagonalIn;
return dpi * sizes[sizeClass];
// final font size in pt
var fontsizePt = diagonal * ratio * PtPerPixel;
return fontsizePt;
}
}

View File

@@ -15,7 +15,7 @@ namespace RothenburgAR.UI
{
tmproText.enableAutoSizing = true;
tmproText.fontSizeMax = FontsizeManager.Instance.GetFontsize(this.SizeClass);
tmproText.fontSizeMin = tmproText.fontSizeMax * 0.5f;
tmproText.fontSizeMin = tmproText.fontSizeMax * 0.8f;
}
}

View File

@@ -13,6 +13,8 @@ namespace RothenburgAR.Updater
{
public UnityEngine.UI.Slider ProgressBar;
private float afterDownloadWaitTime = 300f;
public VersioncheckAnswer VersionAnswer { get; set; }
private List<HttpHandler> httpHandlers = new List<HttpHandler>();
@@ -234,7 +236,6 @@ namespace RothenburgAR.Updater
}
private DateTime downloadEndedTime = DateTime.Now.AddSeconds(1);
private float afterDownloadWaitTime = 10f;
void Update()
{