newTextField could not load font....

Hi, I have a warning in corona simulator when I insert a newTextField, this is the message: Warning: could not load font font. Using default font

Now, I write a newText and no problem with font, if I insert newTextField I receive the warning, why this?

This is the main.lua code:

local opensans = native.newFont( “opensans.ttf” , 18 )

local text = display.newText( “Hello” , 100, 0, opensans, 40 )
local input_text = native.newTextField( 120, 20, 200, 30 )
input_text.Font = opensans

I also receive warning if I put this : input_text.Font = native.newFont( native.systemFont , 18 )

I install Corona SDK on Windows 7. opensans.ttf placed in root directory with main.lua

Please help me thanks

When it comes to using the Simulator I think you need to install the font and then use the font name, not the font file name.

To get the font names:

-- Set the string to query for (part of the font name to locate) local searchString = "sans" -- Display each font in the Terminal/console for i, fontName in ipairs( systemFonts ) do local j, k = string.find( string.lower(fontName), string.lower(searchString) ) if ( j ~= nil ) then print( "Font Name = " .. tostring( fontName ) ) end end

This worked for me when I tried:

local text = display.newText( "Hello" , 100, 0, "Open Sans", 32)

Best regards,

Tomas

@cruero

You’re getting an error because there is a typo in your code.  The text field’s “font” property is case sensitive and must start with a lower case ‘f’.  So, change the following…

   input_text.Font = opensans

…to this…

   input_text.font = opensans

@tomaswesterlund

The Windows and Android versions of Corona support loading fonts by “file name” and “font family name”.  When loading it by font file name, the font file is expected to be in your project’s resource directory (ie: the root folder of your Corona project, next to the main.lua file).

Currently, only the iOS and OS X versions of Corona are limited to loading fonts by “Font Family Name”.

Thanks for the explanation Joshua.

Best regards,

Tomas

Thanks Joshua, but if I put input_text.font = opensans I have the same result, warning for not font loaded… also if I put input_text.font = native.newFont( native.systemFont , 18 ) always warning… instead with local text = display.newText( “Hello” , 100, 0, opensans, 40 ) no problem, it’s strange!!!

I installed sublime text 3 with corona plugin code, when I write code sublime suggest me input_text.Font and not input_text.font

, however result is the same…

Warning message is: Could not load font font. Using default font   

I don’t declared font …

Maybe is Windows system? Corona simulator use android platform: GT-I9300 / x86 / 6.1 / Asus EAH4350 series / 3.3.10243 Compatibility profile context / 2015.2646

Ahh… that’s the problem.  You are using build #2646.  The Windows version of the Corona SDK doesn’t actually support native TextFields/TextBoxes in older builds.  Instead, the Corona Simulator will just display a rectangle where the TextField is supposed to be and we stub out the implementation.

But you’re in luck!  We’ve added real TextField/TextBox support to Windows as of daily build #2695.

   https://developer.coronalabs.com/release/2015/2695/

So, I recommend that you grab the newest daily build.  :slight_smile:

Thanks Joshua, with the new release TextField works fine :slight_smile:

When it comes to using the Simulator I think you need to install the font and then use the font name, not the font file name.

To get the font names:

-- Set the string to query for (part of the font name to locate) local searchString = "sans" -- Display each font in the Terminal/console for i, fontName in ipairs( systemFonts ) do local j, k = string.find( string.lower(fontName), string.lower(searchString) ) if ( j ~= nil ) then print( "Font Name = " .. tostring( fontName ) ) end end

This worked for me when I tried:

local text = display.newText( "Hello" , 100, 0, "Open Sans", 32)

Best regards,

Tomas

@cruero

You’re getting an error because there is a typo in your code.  The text field’s “font” property is case sensitive and must start with a lower case ‘f’.  So, change the following…

   input_text.Font = opensans

…to this…

   input_text.font = opensans

@tomaswesterlund

The Windows and Android versions of Corona support loading fonts by “file name” and “font family name”.  When loading it by font file name, the font file is expected to be in your project’s resource directory (ie: the root folder of your Corona project, next to the main.lua file).

Currently, only the iOS and OS X versions of Corona are limited to loading fonts by “Font Family Name”.

Thanks for the explanation Joshua.

Best regards,

Tomas

Thanks Joshua, but if I put input_text.font = opensans I have the same result, warning for not font loaded… also if I put input_text.font = native.newFont( native.systemFont , 18 ) always warning… instead with local text = display.newText( “Hello” , 100, 0, opensans, 40 ) no problem, it’s strange!!!

I installed sublime text 3 with corona plugin code, when I write code sublime suggest me input_text.Font and not input_text.font

, however result is the same…

Warning message is: Could not load font font. Using default font   

I don’t declared font …

Maybe is Windows system? Corona simulator use android platform: GT-I9300 / x86 / 6.1 / Asus EAH4350 series / 3.3.10243 Compatibility profile context / 2015.2646

Ahh… that’s the problem.  You are using build #2646.  The Windows version of the Corona SDK doesn’t actually support native TextFields/TextBoxes in older builds.  Instead, the Corona Simulator will just display a rectangle where the TextField is supposed to be and we stub out the implementation.

But you’re in luck!  We’ve added real TextField/TextBox support to Windows as of daily build #2695.

   https://developer.coronalabs.com/release/2015/2695/

So, I recommend that you grab the newest daily build.  :slight_smile:

Thanks Joshua, with the new release TextField works fine :slight_smile: