gree / lwf

LWF - Lightweight SWF
http://gree.github.com/lwf/
zlib License
627 stars 167 forks source link

Fonts in Unity #136

Closed DelSystem32 closed 9 years ago

DelSystem32 commented 9 years ago

I'm trying to use a font in flash and have it appear correctly in Unity. I can't find any information on how to do this.

In the forum thread on 12sep2014 it was written: "Yes, fontconv.rb works only on OS X. And I’m afraid I have a bad news about that. BitmapFontRenderer had been deprecated. You can render text using the latest LWF without BitmapFontRenderer nor SystemFontRenderer. LWF uses TextGenerator API right now." But I just can't figure out how to actually get the font to show up in Unity.

How am I supposed to set up the text field in my FLA project? I know the text engine should be "Classic Text" and the type should be "Dynamic Text". But how should the anti-alias be set up? "Use device fonts"? "Bitmap text"? I'm trying to get family "Arial" with style "Black" to show up in Unity. I think I should not embed the font into the flash file, correct?

How am I supposed to insert "Arial Black" in Unity using C#? I've tried so much but I just can't figure it out. I've searched and searched online for how to do it as well, all the info I find seems to be deprecated. If you could give me a complete code example on how to do it using Font.CreateDynamicFontFromOSFont("Arial Black", 32) in Unity I would be very happy.

splhack commented 9 years ago

Create a "Dynamic Text". The font name of the dynamic text would be embedded into LWF data after swf2lwf.rb conversion (It's a part of LWFS).

swf2lwf.rb loads swf2lwf.conf. For example, all fonts that the name starts "_" would be "_system", other fonts would be "font" in the runtime.

font:
  - regexp: ^_
    name: _system
  - regexp: .*
    name: font

So if you want to use "Arial Black" in Unity, swf2lwf.conf font block should be

font:
  - regexp: .*
    name: Arial Black
DelSystem32 commented 9 years ago

I can't get it to work. You're saying that I should manually edit "LWFS-win-20150716-1509\LWFS.a\lwfs\lib\swf2lwf\swf2lwf.conf" in notepad before placing the .swf file in the "LWFS_work" folder, correct? Here is how my swf2lwf.conf looks:

font:
  - regexp: ^_
    name: _system
  - regexp: .*
    name: font
  - regexp: .*
    name: Arial Black
  - regexp: .*
    name: Anime Ace 2.0 BB
#format: 0x131211

Nothing happens from this, inside Unity the fonts of the flash is still just "Arial" even though they should be "Arial Black" and (in a different text field) "Anime Ace 2.0 BB". What am I doing wrong? Do the fonts need to be embedded in the swf file? I've tried that with Anime Ace 2.0 BB and it didn't work. There's no way to embed the fonts from inside Unity instead?

I don't understand what you mean with:

all fonts that the name starts "_" would be "_system", other fonts would be "font" in the runtime

Here is a screenshot of the two textfields in Flash CS6 and how it looks in the flash editor. As you can see it looks incorrect in Unity (both textfields just uses the Arial font).

screen

Note: I've also tried with just this in the config file:

font:
  - regexp: .*
    name: Arial Black
#format: 0x131211

It gave the same incorrect result.

splhack commented 9 years ago

swf2lwf.conf

IIRC, you can have swf2lwf.conf file in each folder in LWFS_work instead of modifying the system swf2lwf.conf. For example, LWFS_work/data1/swf2lwf.conf, LWFS_work/data2/swf2lwf.conf. BTW, we recommend to create a folder for each fla/swf pair in LWFS_work folder.

@KojiNakamaru It's correct?

font

Each regexp/name combination is a rule for font name conversion. If "The font name on Flash" matches the regexp, then use the name in LWF data. Two "regexp: .*" entries don't make sense.

splhack commented 9 years ago

The converted font name would be used in https://github.com/gree/lwf/blob/78393d0e463f45b12668e1764fec875dcbdfdf74/csharp/unity/renderer/common/lwf_unity_text.cs#L77-L79 . You may need to have a ttf file which is the same name as the name in Resources.

DelSystem32 commented 9 years ago

I've gotten it to work, thanks! It was indeed possible to have a "swf2lwf.conf" file inside the LWFS_work folder (same folder as the swf file). I made it look like this:

font:
  - regexp: .*
    name: SWF/Fonts/ariblk
#format: 0x131211

Then I copied the font to: Assets\Resources\SWF\Fonts\ariblk.ttf

All fonts in the flash then got the Arial Black appearance.

However I'm having problems with getting the regular expression right. I've tried many different regular expressions here, the latest try was this:

font:
  - regexp: arial/i
    name: SWF/Fonts/ariblk
  - regexp: anime/i
    name: SWF/Fonts/anime_ace_2.0
#format: 0x131211

It simply isn't finding the text fields. I'm assuming it's trying to match all text fields that contains a font that matches the regexp. Or is it matching against the text field names?

What should I write after the two "regexp:" in the example above?

splhack commented 9 years ago

regexp matches the font name in Adobe Flash. If you use Arial font of dynamic text in Adobe Flash, regexp: Arial would be matched.

DelSystem32 commented 9 years ago

I was trying to figure out how to do a case insensitive regular expression in ruby. It's true that "Arial" matches but I want to match "arial" and "aRiAl" as well, just in case. I thought /i was the option for a case-insensitive regexp in ruby but it's not working. "/arial/i" isn't working either. (This is the last piece of the puzzle then we can close the issue.)

splhack commented 9 years ago

Updated a6451b223bd5683e0bb2c732a9efe0c51dbb4944 for ignoring case for regexp.

DelSystem32 commented 9 years ago

Much obliged mate! Though it is a little strange not being able to pass in a real regular expression to something called "regexp".