Code Monkey home page Code Monkey logo

unity-freetype's Introduction

unity-freetype

Yet another Unity font provider with freetype

Why?

There is a built-in FreeType based dynamic font provider has been involved since Unity 4.x. However, this font provider is not extensible for advanced usage, such as it is hard for you to make a perfect stroke by FreeType APIs.

This project is a mock font provider implemention by getting and rendering glyphs from the FreeType source. And with this source you will be able to change anything you want in the FreeType level.

How to use?

Build the plugin

To build the native plugins you should have cmake installed. Then under the Plugin folder you will find such scripts:

make_android.sh
make_ios.sh
make_macos.sh
make_windows.bat

You may also need the NDK/Xcode/Visual Studio installed for each platform.

After the building finish put the output binaries into the right place in your Unity project.

Integrate the code

  1. Copy the folder FreeTypeFont into you Unity project.
  2. Add -unsafe to the file smcs.rsp and gmcs.rsp. If you don't have them just create a new one.

    This -unsafe option is used to enable direct memory operation for performance purpose. If you don't like it you could change those parts of code to Marshals.

  3. To use this font provide with NGUI:
    1. Seach all the Font in the NGUI source code and replace it with FreeTypeFont. Backup is strongly recommanded.
    2. Copy all the files under Shaders into the NGUI shader folder.
    3. Create a prefab with two components: UIFont(From NGUI) and FreeTypeFont(From this project).
    4. Change the extension of the TTF font file to .bytes, or any other TextAsset extensions, and drag it to the Font Asset field of the FreeTypeFont.
    5. Change the Font Type of UIFont to Dynamic and drag this FreeTypeFont component to its TTF Font field.

Know issues

This project (might) isn't so good as the Unity built-in one because:

  1. It uses a poor, but quick, algorithm to packing glyphs. A little more space wasting than the built-in one.
  2. It uses a 16 bit texture in order to render the glyph stroke. It needs an extra 8 bit channels for the stroke alpha.
  3. It need to two vertex color channels for the glyph face and stroke. However, the Unity Mesh component only has one Colors property so it compose these two color chanels into one. Which means the each channel will have only 16 bit colors.

Do I need it?

If you think the text apperance in your project is good enough don't look into this. If you want to tweak the text in the FreeType level, clone this repo and make any changes you like.

unity-freetype's People

Contributors

jayatubi avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.