Jump to content
Sign in to follow this  
  • entries
    125
  • comments
    7
  • views
    4003

Introducing new font metrics APIs, plus a new plugin

Sign in to follow this  
CoronaRob

815 views

Corona’s engineers have added two new APIs for getting information about fonts, with the intent of helping you better align text in your apps. We’ve also added a new plugin that you might want to take advantage of.

Font metrics APIs

Starting with daily build 2017.3121, there is a new API call, graphics.getFontMetrics(), which returns a table that contains values like the height of the font, font leading, and the ascent/descent values for the font. Ascent is the amount of recommended space above the baseline for single-spaced text, while descent is the suggested space below the baseline for single-spaced text. Leading is the recommended additional space between lines of text.

In addition, all TextObject objects (those created via display.newText()) have a new read-only property called baselineOffset which lets you adjust the position of the object so that you can easily align it with other objects, including graphics or other text objects that may be constructed with different fonts or font sizes.

Consider this output:

text-gem-baseline-fontmetrics-1.png

By using the baselineOffset property, you can easily align the baseline of each text object with the bottom of the gem for a more appealing display!

Battery State plugin

We also introduced a new plugin that lets you get the current state of the device’s battery. It offers an event-based update callback where you receive an event when the battery state changes (charging, unplugged, etc.). You can also call the batteryState.getState() function to get a one-time status on the device’s battery.

To use this plugin, visit the Corona Marketplace, activate the plugin, and then follow the integration documentation to add it to your project.


View the full article

Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!