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> 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> 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() /// <summary>
{ /// Calculates font size that is roughly equal in size on "all" displays
Debug.Log("Screen dpi: " + Screen.dpi); /// </summary>
}
public float GetFontsize(FontsizeClass sizeClass) public float GetFontsize(FontsizeClass sizeClass)
{ {
var dpi = 420;//Screen.dpi; var dpi = Screen.dpi;
var res = Screen.currentResolution; 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 // Screen diagonal in px
var diagonal = Mathf.Sqrt(Mathf.Pow(res.height, 2) + Mathf.Pow(res.width, 2)); var diagonal = Mathf.Sqrt(Mathf.Pow(res.height, 2) + Mathf.Pow(res.width, 2));
// Screen diagonal in logical inches // Screen diagonal in logical inches
var diagonalIn = diagonal / dpi; var diagonalIn = diagonal / dpi;
var ratio = diagonalIn * sizes[sizeClass]; // ratio of font size to screen size
var fontsizePx = diagonal * ratio; var ratio = sizes[sizeClass] * InchPerPt / diagonalIn;
var fontsizePt = fontsizePx * 0.75f;
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.enableAutoSizing = true;
tmproText.fontSizeMax = FontsizeManager.Instance.GetFontsize(this.SizeClass); 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; public UnityEngine.UI.Slider ProgressBar;
private float afterDownloadWaitTime = 300f;
public VersioncheckAnswer VersionAnswer { get; set; } public VersioncheckAnswer VersionAnswer { get; set; }
private List<HttpHandler> httpHandlers = new List<HttpHandler>(); private List<HttpHandler> httpHandlers = new List<HttpHandler>();
@@ -234,7 +236,6 @@ namespace RothenburgAR.Updater
} }
private DateTime downloadEndedTime = DateTime.Now.AddSeconds(1); private DateTime downloadEndedTime = DateTime.Now.AddSeconds(1);
private float afterDownloadWaitTime = 10f;
void Update() void Update()
{ {

View File

@@ -720,7 +720,7 @@ RectTransform:
m_Father: {fileID: 562107609} m_Father: {fileID: 562107609}
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0.9} m_AnchorMin: {x: 0, y: 0.5}
m_AnchorMax: {x: 1, y: 1} m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0} m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0} m_SizeDelta: {x: 0, y: 0}
@@ -772,10 +772,10 @@ MonoBehaviour:
m_outlineColor: m_outlineColor:
serializedVersion: 2 serializedVersion: 2
rgba: 4278190080 rgba: 4278190080
m_fontSize: 50.35 m_fontSize: 38.4
m_fontSizeBase: 38.4 m_fontSizeBase: 38.4
m_fontWeight: 400 m_fontWeight: 400
m_enableAutoSizing: 1 m_enableAutoSizing: 0
m_fontSizeMin: 15 m_fontSizeMin: 15
m_fontSizeMax: 1000 m_fontSizeMax: 1000
m_fontStyle: 0 m_fontStyle: 0