Search Unity

unity-sysfont: Unity3D plugin for rendering dynamic text using device/platform fonts

Discussion in 'Made With Unity' started by Deleted User, Jun 21, 2012.

  1. Deleted User

    Deleted User

    Guest

    I just published unity-sysfont is a Unity3D plugin for rendering dynamic text using the fonts available on the mobile device/computer.

    Features
    • Multi-platform: iOS/Android/MacOSX support.
    • Unity Editor support: customize the text within the editor and confirm the results immediately.
    • Customizable: change the font family, size, style, color, and more.
    • Optimized: Alpha-only textures and dynamic texture size adjustment.
    • Programmable: the same fields available in the editor are exposed as properties that you can change programatically.

    Requirements
    Unity 3.4.x and above.

    Download Installation

    For Unity 3.x check here.
    For Unity 4.x check here.

    You can also download the demo package and double click it to import it to your project.

    Demonstration

    Here is a screenshot of unity-sysfont demo running on Unity Editor.



    And here is a picture of the demo running on and Android and an iPhone.



    More details available on the project page.
     
    Last edited by a moderator: May 8, 2013
  2. Games Unity

    Games Unity

    Joined:
    Apr 15, 2012
    Posts:
    27
    This plugin is very useful and you can create with it quality fonts.
    I like it that you support both iOS and Android.
     
  3. Deleted User

    Deleted User

    Guest

    Thank you.

    Just to let you know I fixed 'could not be loaded when loading game object' errors and uploaded a new version of the package.
     
  4. liverolA

    liverolA

    Joined:
    Feb 10, 2009
    Posts:
    347
    useful,thanks for share!
     
  5. crystani

    crystani

    Joined:
    Jul 29, 2011
    Posts:
    68
    Hi imkira,

    It is really great package! I have done similar implementation https://github.com/jangyungi/Dynamic-Font-Texture-for-Unity3d, and yours is much better, so I want to move on this for my game project.

    Just one question: With my use of this kind of native fonts, it is necessary to find out the size of specific text with current font/size of the font. (In other words, I need getting the value in order to make scrolling texts or so... Maybe this is a very specific/strange use of native texts though.) For example, http://unity3d.com/support/documentation/ScriptReference/GUIStyle.CalcSize.html describes its way of getting size of specific text with given gui style. I tried to find such a functionality that are exposed, but failed. Is it possible to do that with your package?

    Thanks,
     
  6. liverolA

    liverolA

    Joined:
    Feb 10, 2009
    Posts:
    347
    how about windows webplayer support?
     
    Last edited: Jun 25, 2012
  7. Deleted User

    Deleted User

    Guest

    Hi crystani! Thank you for your compliment.
    I would like to have found your implementation before doing Unity SysFont. I have checked yours, and it seems really good too.

    With unity-sysfont, I always measure the size of the text and the required texture size (nextPowerOfTwoIfNotAlready(textSize.width, textSize.height)) in the native code so I never need to specify that in the code or inspector, You only specify the maximum dimensions of the texture in the inspector (by default 2048x2048 which should be enough for most purposes).

    There are basically 2 classes: SysFontText and SysFontTexture. SysFontTexture is as the name implies, a class that handles a Texture2D containing the text bitmap and information about the text. The SysFontText extends from SysFontTexture and just basically creates a mesh that is trimmed to the text size.

    With this said, if you have a SysFontText or SysFontTexture object, you can use the following proporties:

    Code (csharp):
    1.  
    2.   public int MaxWidthPixels; // the same value you set in the inspector (it is used for forcing word wrapping of text and controlling maximum OpenGL texture size)
    3.  
    4.   public int MaxHeightPixels; // the same value you set in the inspector (it is used for forcing cropping of text and controlling maximum OpenGL texture size)
    5.  
    6.   public int TextWidthPixels; // this is the width (in pixels) of the current text (including font size, font name, font style, etc.).
    7.  
    8.   public int TextHeightPixels; // this is the height (in pixels) of the current text (including font size, font name, font style, etc.).
    9.  
    10.   public int WidthPixels; // this is the basically nextPowerOfTwoIfNotAlready(TextWidthPixels)
    11.  
    12.   public int HeightPixels; // this is the basically nextPowerOfTwoIfNotAlready(TextHeightPixels)
    13.  
    Please, also note that although TextWidthPixels and TextHeightPixels reflect the size of the text, there are two special cases I need to tell you about:

    1. text gets wrapped because MaxWidthPixels is reached or you have newline characters in the text
    2. your text gets cropped due to the MaxHeightPixels limit being reached (horizontal cropping only happens if MaxWidthPixels is set to an extremely small value that even if you wrap characters it is not enough)

    If text gets wrapped (either because MaxWidthPixels is reached or because you have multi-line text), TextWidthPixels will be the maximum width in pixels of all lines. TextHeightPixels will be sum of the heights of each line.

    If text gets cropped in the vertical direction, TextHeightPixels will be equal to MaxHeightPixels.
    If text gets cropped in the horizontal direction (which should rarely happen like I explained before), TextWidthPixels will be equal to MaxWidthPixels.

    SysFontText reflects these two properties (TextWidthPixels, TextHeightPixels) in the localScale of the GameObject it is attached too: every time you change a SysFontText, it updates localScale.x and localScale.y to match (TextWidthPixels, TextHeightPixels) in order to easily achieve pixel perfect rendering.

    I hope it helps!
     
    Last edited by a moderator: Jun 25, 2012
  8. Deleted User

    Deleted User

    Guest

    Thank you very much for your comment.
    I am seriously thinking about it because I would also like that feature too.
    I will keep you posted when I get news about it!
     
  9. GamerCB

    GamerCB

    Joined:
    Jul 5, 2012
    Posts:
    3
    Hi,

    I'm using UnityPro 3.5.3f3 with iOS and Android Pro on WIndows 7 Pro. I created a new project and added both the sysfont and sysfont demo packages. When I open the unity-sysfont-demo scene I get lots of errors:


    DllNotFoundException: SysFont
    SysFont.QueueTexture (System.String text, System.String fontName, Int32 fontSize, Boolean isBold, Boolean isItalic, Alignment alignment, Boolean isMultiLine, Int32 maxWidthPixels, Int32 maxHeightPixels, Int32 textureID) (at Assets/Plugins/SysFont/SysFont.cs:241)
    SysFontTexture.ForceUpdate () (at Assets/Plugins/SysFont/SysFontTexture.cs:343)
    SysFontTexture.Update () (at Assets/Plugins/SysFont/SysFontTexture.cs:326)
    SysFontText.Update () (at Assets/Plugins/SysFont/SysFontText.cs:101)
    UnityEditor.DockArea:OnGUI()

    If I run it on and Android device I get the demo screen seen above for a few seconds before dropping out (using an HTC Desire S, Android 2.3.5)

    Would you be able to help as I think this will be really useful.

    Thanks
     
  10. Deleted User

    Deleted User

    Guest

    Hello GamerCB,
    It is not currently possible to use the plugin on Unity Editor for Windows (only on the Mac), although iOS/Android export feature should work fine.
    I plan to include Windows support still during this month.

    Sorry for the inconvenience.
    I will give news soon.

     
  11. Deleted User

    Deleted User

    Guest

    I have just released a new version of the plugin:
    - added: support for (left, center, right) text alignment
    - improved: webbuild is not supported (and will probably never be due to limitations on the Unity WebPlayer architecture itself), but at least web player builds will now not fail due to unity-sysfont by disabling all rendering by the plugin.
     
  12. GamerCB

    GamerCB

    Joined:
    Jul 5, 2012
    Posts:
    3
    Thanks Imkira, I finally realised that the supported formats also apply to the editor and not just the targets. I've since got it going under Mac and it looks exactly like what we need. We were desperate to find a way to have fonts showing chinese characters sitting in a 3D world and this fits the bill.

    The only trouble is that I *HATE* working on a mac (why doesn't home and end work any more!!!) and so would be happy to help test the PC version.

    Building it for the HTC once more under Mac resulted in a similar version that crashed after a few seconds. Building on an iPod Touch however worked fine. Any idea on the Android crash?

    Ta
     
  13. Deleted User

    Deleted User

    Guest

    Hi GamerCB,

    Thank you very much for your contact!

    Can you tell me how the crash happened? I assume it crashed right after the unity logo disappeared during launch?
    Anyway, if you could provide me with a log of the android app I would be happy to track the cause of the problem.
    One of the ways you can debug is by following this procedure:

    1. Connect the device via USB to your computer
    2. Open a command line terminal window, and execute: adb logcat
    3. Make note of where the log ends
    4. Start your app on your Android device by tapping it to launch and wait until it crashes
    5. Take the part of the log that was generated after step 3

    adb is part of the Android SDK platform tools. It should be found on the platform-tools folder of your Android SDK installation.
    Please use that path when executing adb like stated on step 2.

    Please report me the log and I will be happy to track and hopefully fix that problem.

    Best regards

     
  14. Deleted User

    Deleted User

    Guest

    I have just updated unity-sysfont to support NGUI's clipping functionality.
    Now you can just put your labels inside a scrolling list or a UIPanel with clipping enabled, and it will simply work.



    More info at the usual place:
    http://github.com/imkira/unity-sysfont
     
  15. Deleted User

    Deleted User

    Guest

    I have just noticed that unity-sysfont does not render text properly on my new MBPro + Lion.
    I don't know whether that is related to some hardware change introduced or to Lion, but I have just released an update fixing the problem.
     
  16. felix_berninger

    felix_berninger

    Joined:
    Aug 19, 2011
    Posts:
    30
    it seems to be the one thing we are looking for...

    but we need the windows support... is this happening anytime soon?
     
    Last edited: Sep 4, 2012
  17. Meteor0679

    Meteor0679

    Joined:
    Sep 18, 2012
    Posts:
    10
  18. Cooper.D

    Cooper.D

    Joined:
    Sep 22, 2012
    Posts:
    1
    Hi,imkira:
    I really think this is a great package! It's very useful, but I want to get unity-sysfont of support EZGUI, will you develop it?
     
  19. zinzin

    zinzin

    Joined:
    Oct 12, 2012
    Posts:
    1
    that is a life saver!!
     
  20. karlhulme

    karlhulme

    Joined:
    Nov 5, 2012
    Posts:
    33
    Hi Imkira,

    Excellent work! Can I ask, do you intend to add windows support to your plugin?

    Also, could you comment on how it works? I think the unity dynamic fonts works by finding the TTF and rendering using the freefont library, whereas yours offloads the rendering to the OS - is that right?

    Kind regards
    Karl
     
  21. chbin

    chbin

    Joined:
    Dec 27, 2012
    Posts:
    2
    very nice,but it can't support ngui's encoding like "[ff0000]hello[-]",:(
    hope for next version support that featur
     
  22. funasylum

    funasylum

    Joined:
    Feb 5, 2011
    Posts:
    48
    hey bravo, man. this is really tremendous. thank you so much!!!

    you should totally sell this in the store-- i'd be happy to pay for it-- especially if you added a couple things like kerning and leading.

    thanks again!
     
  23. Deleted User

    Deleted User

    Guest

    Hi, I am sorry but I don't have enough time in the moment for porting it to windows.
    Furthermore, I know that for Windows projects you have to choose between DirectX and OpenGL, isn't that right?
     
  24. Deleted User

    Deleted User

    Guest

    Hi Cooper, thank you very much for your comments!

    It's been a long time I don't use EZGUI :neutral:
    I don't think it should be very difficult to do it so.
    I currently know people who have managed to do it not only for NGUI but also for UniSWF, so EZGUI should not be that difficult I think.

    If you feel adventurous and try to make a compatibility package for EZGUI, I think the only two files you would need to care about are:

    https://github.com/imkira/unity-sys.../Compatibility/NGUI/Scripts/UISysFontLabel.cs
    https://github.com/imkira/unity-sys...atibility/NGUI/Editor/UISysFontLabelEditor.cs

    Let me know if you hit a roadblock.
    Best of luck!
     
  25. Deleted User

    Deleted User

    Guest

    Yeah, I am also one of the users who think it should have such feature!
    Unfortunately it is more complicated than it seems, since my original objective was to provide almost the exact same features for both Android and iOS.
    I confess either implementation is very simple, so I think the best would be to integrate with existing libraries (e.g.: https://github.com/mattt/TTTAttributedLabel) rather than reinventing the wheel.
     
  26. Deleted User

    Deleted User

    Guest

    Hello funasylum, thank you very much for your comments!

    I think this would be pretty easy now with the availability of iOS6 which provides an API for kerning and leading. I don't know if this is good enough though? Also, I would need to check Android docs for support too.
     
  27. techmage

    techmage

    Joined:
    Oct 31, 2009
    Posts:
    2,133
    This is really cool.

    One question though, how does this render the font? Is the text rasterizer all c# based?

    And can you use your own TTF files? On iOS and OSX? Or only built in ones?
     
    Last edited: Apr 11, 2013
  28. larrykirschner

    larrykirschner

    Joined:
    Oct 27, 2010
    Posts:
    22
    @imkira or anyone who knows...

    Has anyone gotten unity-sysfont package to work with unity 4? We're trying to upgrade now and getting linking errors in XCode:

    Undefined symbols for architecture armv7:
    "__context", referenced from:
    -[UnitySysFontTextureManager processQueue] in UnitySysFont.o
    ld: symbol(s) not found for architecture armv7
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
     
  29. gussk

    gussk

    Joined:
    Jun 29, 2012
    Posts:
    3
    We're in a similar situation and would greatly appreciate any pointers to help us solve this. At the moment we're removing all references to _context in UnitySysFont.mm to be able to continue developing, but we will have to solve this before we can push an update.

     
  30. Deleted User

    Deleted User

    Guest

    Sorry for the delay.

    If you're using Unity 4.x please check out the new development branch:
    https://github.com/imkira/unity-sysfont/tree/unity4x

    I also updated NGUI compatibility package to match the latest version on the Asset Store.
     
  31. Deleted User

    Deleted User

    Guest

    Sorry for the delay.

    If you're using Unity 4.x please check out the new development branch:
    https://github.com/imkira/unity-sysfont/tree/unity4x

    I also updated NGUI compatibility package to match the latest version on the Asset Store.
     
  32. gussk

    gussk

    Joined:
    Jun 29, 2012
    Posts:
    3
    Thank you imkira! Keep up the good work.

     
  33. gauara

    gauara

    Joined:
    Feb 5, 2013
    Posts:
    1
    Hey Imkira,

    Awesome work !! It solves a lot of problems for us !
    I am wondering if this plugin can have NGUI UIInput support as well.
    The plugin in current state, works great for labels and stuff but we want to use it for user generated content where it
    can take user text ( asian fonts/locale) in an Input box style. NGUI UIInput text like functionality but with awesomeness of SysFont.

    Your response will be highly appreciated.

    Thanks.
     
  34. MikeJH

    MikeJH

    Joined:
    Aug 15, 2012
    Posts:
    9
    DllNotFoundException: SysFont
    SysFont.QueueTexture (System.String text, System.String fontName, Int32 fontSize, Boolean isBold, Boolean isItalic, Alignment alignment, Boolean isMultiLine, Int32 maxWidthPixels, Int32 maxHeightPixels, Int32 textureID) (at Assets/Plugins/SysFont/SysFont.cs:241)
    SysFontTexture.Update () (at Assets/Plugins/SysFont/SysFontTexture.cs:319)
    SysFontText.Update () (at Assets/Plugins/SysFont/SysFontText.cs:414)
    zhe unity-sysfont-demo scene in this plugin. run on mac Machine,using unity 4.1.5 ,log this error. i am using For Unity 4.x check here. mac os 10.8.
     
  35. dibdab

    dibdab

    Joined:
    Jul 5, 2011
    Posts:
    976
    hello
    is it possible to save text file (and read by the plugin)?

    also
    can you use your own TTF files?
     
  36. Deleted User

    Deleted User

    Guest

    Is sysfont compatible with NGUI 2.7 or 3.0? (or both?)

    I just imported NGUI 2.7 with the sysfont compatibility package (latest version 1.0.5) and get the following error:

    Assets/SysFont/Compatibility/NGUI/Scripts/UISysFontLabel.cs(212,30): error CS0115: `UISysFontLabel.keepMaterial' is marked as an override but no suitable property found to override
     
  37. Breakmachine

    Breakmachine

    Joined:
    Sep 19, 2009
    Posts:
    39
    I'm also curious about NGUI 3.0 compability. I'm getting the same error as technicat and I've tried to comment that code out but the font/label doesn't show when exporting to android (while the demo does).
     
  38. GarthSmith

    GarthSmith

    Joined:
    Apr 26, 2012
    Posts:
    1,240
    I am getting this same error message. Did anyone come up with a fix? Is there something I need to know about how Unity imports DLLs? I don't even see a SysFont.dll file anywhere...
     
  39. Keepabee

    Keepabee

    Joined:
    Jul 12, 2012
    Posts:
    58
    I was looking for this plugin to use with NGUI very recently myself, but then I figured out NGUI and Unity had both been updated and both support dynamic fonts now. Unity has dynamic fonts (drag and drop into project, setup as dynamic and not to copy font data, setup fallback font names to look for in target systems), then use NGUI labels with font set to use Unity font and refer to the font you just set up.

    Some links on the matter:
    http://docs.unity3d.com/Documentation/Components/class-Font.html
    https://docs.unity3d.com/Documentation/ScriptReference/TrueTypeFontImporter-fontNames.html

    I'm sorry about this derail, since I really appreciate this plugin - it helped us out a lot in the past and I really was looking for it to use again when I ran across some compatibility issues and found out about the features now being included in Unity and NGUI. Just read about there still being other people who don't know about this and may be looking for the same answers I needed.
     
  40. Palringo GBG

    Palringo GBG

    Joined:
    Aug 27, 2014
    Posts:
    1
    This is a really neat plugin, but would it be possible to render emojis in color? Right now they will be the same color as the text, even though they should be in colors on both iOS and Android.
     
  41. hassen66

    hassen66

    Joined:
    Sep 7, 2015
    Posts:
    7
    font does'nt show in android
    i am using unity 4.6.5 in windows 8.1
     
  42. wwu39

    wwu39

    Joined:
    Nov 21, 2018
    Posts:
    28
    DllNotFoundException: SysFont
    getting this error on my mac too
    any ideas?