Skip to content

Commit a40faeb

Browse files
author
Oskari Leppäaho
committed
First attemt at fixing the font size
Try to calculate a factor for the font size based on the aspect ratio and inch size of the screen. With this solution iPad pro and iPad 2 have a similar looking font size, but an iPhone 6S has too small size.
1 parent 079ddb1 commit a40faeb

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

release/NativeEditPlugin/Plugins/iOS/EditBox_iOS.m

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
NSMutableDictionary* dictEditBox = nil;
1010
EditBoxHoldView* viewPlugin = nil;
1111

12-
#define DEF_PixelPerPoint 2.2639f // 72 points per inch. iPhone 163DPI
1312
char g_unityName[64];
1413

1514
bool approxEqualFloat(float x, float y)
@@ -297,8 +296,6 @@ -(void) create:(JsonObject*)json
297296
valign = UIControlContentVerticalAlignmentBottom;
298297
halign = UIControlContentHorizontalAlignmentRight;
299298
}
300-
301-
fontSize = fontSize / DEF_PixelPerPoint;
302299

303300
if (withDoneButton)
304301
{
@@ -328,9 +325,17 @@ -(void) create:(JsonObject*)json
328325

329326
UIFont* uiFont;
330327
if ([font length] > 0)
328+
{
331329
uiFont = [UIFont fontWithName:font size:fontSize];
330+
NSLog(@"Font lenth more than 0");
331+
}
332332
else
333+
{
333334
uiFont = [UIFont systemFontOfSize:fontSize];
335+
NSLog(@"Font length less than 0");
336+
}
337+
338+
NSLog([NSString stringWithFormat:@"%@/%f", @"font size", fontSize]);
334339

335340
if (multiline)
336341
{

release/NativeEditPlugin/demo/demo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void Start () {
1818
tempTest.transform.position += new Vector3(0.0f, -250.0f, 0.0f);
1919

2020
NativeEditBox tempNB = tempTest.GetComponent<NativeEditBox>();;
21-
tempNB.SetTextNative("fdfdsfsd");
21+
// tempNB.SetTextNative("fdfdsfsd");
2222
}
2323

2424
// Update is called once per frame
@@ -57,7 +57,7 @@ public void OnButton1()
5757
{
5858
bTempFocus = !bTempFocus;
5959
Debug.Log("OnButton1 clicked");
60-
testNativeEdit.SetFocusNative(bTempFocus);
60+
// testNativeEdit.SetFocusNative(bTempFocus);
6161
}
6262

6363
public void OnButton2()
@@ -77,7 +77,7 @@ public void OnButton3()
7777
public void OnButton5()
7878
{
7979
Debug.Log("OnButton5 clicked");
80-
testNativeEdit.SetTextNative("TestText Set!!@#@5");
80+
// testNativeEdit.SetTextNative("TestText Set!!@#@5");
8181
}
8282

8383

release/NativeEditPlugin/scripts/NativeEditBox.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,14 @@ private void PrepareNativeEdit()
203203

204204
Rect rectScreen = GetScreenRectFromRectTransform(this.objUnityText.rectTransform);
205205
float fHeightRatio = rectScreen.height / objUnityText.rectTransform.rect.height;
206-
mConfig.fontSize = ((float) objUnityText.fontSize) * fHeightRatio;
206+
207+
var screenSizeInches = (float) Screen.height / (float) Screen.dpi;
208+
var screenAspectRatio = (float) Screen.width / (float) Screen.height;
209+
210+
211+
UnityEngine.Debug.Log("screen width: " + Screen.width + " Screen height: " + Screen.height + "screenAspectRatio: " + screenAspectRatio + " unity font size: " + objUnityText.fontSize + " screensizeinches: " + screenSizeInches);
212+
213+
mConfig.fontSize = ((float)objUnityText.fontSize) * screenSizeInches * 0.23f * screenAspectRatio / 1.779f;
207214

208215
mConfig.textColor = objUnityText.color;
209216
mConfig.align = objUnityText.alignment.ToString();

0 commit comments

Comments
 (0)