Search Unity

TextMesh Pro *** Preview 3 Release of Version 2.2.0 and 3.2.0 Now Available! ***

Discussion in 'UGUI & TextMesh Pro' started by Stephan_B, Mar 9, 2022.

  1. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The following releases of the TMP package are now available via the Package Manager. These are version 2.2.0-preview.3 for Unity 2019.4 and version 3.2.0-pre.3 for Unity 2020.x or newer.

    These two (2) releases are identical in terms of features and functionality but specific to each Unity releases which is required to address some API and other changes to Unity.

    Release Notes for Preview 3
    ******************

    • Fixed a potential IndexOutOfRangeException when trying to select any portions of text in an Input Field whose child text component is using Overflow mode Truncate or Ellipsis where due to RectTransform width and / or height restrictions have results in the text being fully truncated. Case #1361032
    • Fixed incorrect character sequencing in the Input Field when using Japanese IME in UWP builds. Case #1374755
    • Fixed several potential IndexOutOfRangeException in the Input Field when text is fully truncated when using Text Overflow mode Ellipsis or Truncate.
    • Fixed Input Field incorrect caretPosition and / or stringPosition properties when updating these via scripting. Case #1334622
    • Fixed incorrect event handling on UWP and Hololens 2. Case #1357718 and Case #1351006
    • Fixed Input Field OnSelect event potentially firing twice on some mobile devices including Microsoft Surfaces.
    • Fixed Input Field incorrect caret insertion position when text contains a Carriage Return <CR> at the end of a line. Case #1362068
    • Added support for <CR> markup tag.
    • Added value range check for the text component margins located in the text component extra settings. Case #1365554
    • Added new overload to the TMP_FontAsset.CreateFontAsset() to enable creating font asset instances using a file path.
    • Added new TMP_ResourceManager.RemoveFontAsset() function to remove a font asset from the TMP Resource Manager. This new function would typically be used prior to unloading bundles and / or resources.
    • Warnings about potentially missing character 0x5F used to display underline or strikethrough will only be displayed when using those features when Display Warning is enabled in the TMP Settings.
    • Fixed incorrect handling of '-' at the end of a line when using Text Overflow Page mode. Case #1382173
    • Fixed incorrect line breaking when a hyphen '-' is preceded by a space. Case #1391990
    • When using Text Wrapping Mode - Preserve White Space or Preserve White Space No Wrap, the <ZWSP> character will now contribute to the preferred height when it is the first and only character on a new line.
    • Added ClearFontAssetGlyphCache() function to the TMP_ResourcesManager to enable clearing the font asset fallback glyph cache.
    • Added new <ZWJ> markup tag.
    • Added ability to define a list of fallback text assets in the TMP Settings to be used for Emojis.
    • Added new property "emojiFallbackSupport" to text components which is also exposed in the extra settings section of the text component inspector. When enabled, this will prioritize searching the Emoji Fallback Text Assets before the primary font asset for characters defined as Emoji in Unicode 14.0. See [forum post](https://forum.unity.com/threads/fallback-to-emojis-before-fonts.1186174/) for details.
    • Fixed duplicated character when using custom validator in conjunction with soft keyboard. Case #1387772
    • The <noparse> markup tag will now also affect inline markup tags like <br>, <shy>, etc.
    • Fixed newly created StyleSheets having two Normal styles.
    • Added new Double Pass SDF shader and example scene to the TMP Examples & Extras to showcase this new shader.
    • Added new context menu option to manually "clear dynamic data" of a dynamic font asset. This performs the same clearing of data as the "Clear Dynamic Data on Build" option when manually triggered.
    • Added new <a href="url"> markup tag which can be used as follows: "See <a href="http://url...">this link</a> for details.". This new markup tag is similar to the <link> tag but does not use an ID.
    • Added new "A" style to the Default Style Sheet referenced in the TMP Settings. This "A" style defines the styling of the new <a> markup tag.
    • The TMP_Text.parseCtrlCharacters property which controls the interpretation and parsing of escape characters in the text component's Text Input box in the inspector, will now apply to all methods of setting the text on the component. Case #1400008
    • Fixed potential Null Reference Exception when editing the name of a sprite character. Case #1396591
    • Fixed issue where TMP_FontAsset.HasCharacters would return false when called prior to font asset initialization. Case #1394817
    • Minor TMP_InputField UI improvement where "Hide Mobile Input" property will be disabled when "Hide Soft Keyboard" property is disabled. Case #1388243
    See ChangeLog in Package Manager for changes contained in previous releases.


    Changes Worth Noting
    *****************************
    • TrueType Collection (TTC) support.



    • Support for new OpenType Font Features such as Ligatures and Diacritical Marks.

      upload_2022-3-9_15-3-37.png



      upload_2022-3-9_15-5-21.png

    • Dynamic OS Font Assets

    • Text Wrapping Mode



    • Double Pass Shader

      upload_2022-3-9_15-18-1.png


      This latest release actually contains most of the changes to support native emoji and additional font features but these will require a new version of the Unity Editor as some of this functionality is contained in the TextCore FontEngine which is implemented on the native side which I am still working on. Although my release estimates have been horrible lately, I am hoping to have these changes to the FontEngine available within the next 45 - 60 days.

      Here is an example of color glyph / native emoji support which includes Emoji modifier support as well as those are OpenType font features.
      upload_2022-3-9_15-15-47.png

      Please post any potential issues you uncover with these latest release in this thread.

     
    Last edited: Mar 9, 2022
    lilacsky824, cxode, Nemikolh and 4 others like this.
  2. Ferazel

    Ferazel

    Joined:
    Apr 18, 2010
    Posts:
    517
    Yay, thanks for getting it out the door! I look forward to updating and integrating this into our project and finalizing our text/font features for our game. Some questions:

    What specific features need a new TextCore (new Unity version)? Could you mark them in the changelog or in the post above? Also when you know which version, the version they'll be in?

    Do you have ligatures exposed on a per label or runtime accessible settings so can use to enable/disable ligatures in our GameOptions? Some of our ligatures can be a little "extreme" and we want to provide our users with that option.

    Is this the targeted feature set for 3.2 final or are you planning on squeezing in a few others?

    This may be a problem custom to my project or I might need to wait on a Unity upgrade, but we're still not seeing either the ligatures or glyph pair kerning implemented (one of the big reasons we're trying to upgrade). I tried creating the font from the .ttf and .otf version of the font and they're still not being included? Neither the ligatures or the glyph adjustment pairs are being exported. Let me know if you want me to DM you one of our fonts so you can see if this is an authoring problem.

    upload_2022-3-10_12-38-32.png
    upload_2022-3-10_12-37-43.png
     
    Last edited: Mar 10, 2022
  3. ewittkowske_unity

    ewittkowske_unity

    Joined:
    Mar 5, 2020
    Posts:
    4
    With the upcoming editor update for emoji support will there be an update to the TMP Input field to have an option to block emoji input? We currently only support emojis in chat and don't want players to be able to enter them in their names. This would be helpful option.
     
    Fribur likes this.
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The main ones are the automatic extraction of OpenType features from the font files and the ability to raster color glyphs into RGBA atlas texture.

    I am planning on replacing the "Kerning" option in the Extra Settings of text components by a list of features that users can enable / disable per text component. For instance, you would see the "liga" and "dlig" feature where you may choose to have default "liga" enabled but have discretionary ligatures "dlig" disabled.

    I am planning on adding full support for OpenType features in this preview cycle while keeping these releases stable where what is considered beta / preview are those new features while the core existing functionality remains stable where it actually contains bug fixes to issues reported in 3.0.6 and previous preview releases.

    The ability to extract those font features from the font file is the functionality that is part of the TextCore FontEngine which will require a Unity upgrade.

    Until then you will have to manually populate those tables in the font asset, if you want need any of those features. You will also need to make sure the data is also relative to the sampling point size. For example, in the case of positional adjustments, the values in the font file are specified at the font's Unit per EM scale so if your sampling point size is 100 then you have to adjust / scale your values to be 1/10 of those in the font file.
     
    Ferazel likes this.
  5. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    In the TMP Settings, a new table was added which is the "Fallback Emoji Text Assets" which defines which assets are to be searched for characters that are defined in the Unicode as Emojis. If no asset is defined there then the text system will search thru font assets and fallbacks as it been doing previously. Ie. no change here.

    upload_2022-3-10_14-28-18.png

    A new option was also added in the text component Extra Settings where you can disable Emoji Fallback Support.
     
  6. bsweileh

    bsweileh

    Joined:
    Jun 1, 2018
    Posts:
    15
    This is great! Thanks Stephan!

    Just to clarify, with this preview release on its own, can I get Arabic fonts working in Unity out-of-the-box, or is this dependent on the completion of the changes in the TextCore FontEngine you spoke about above?

    Also, will these changes allow Arabic fonts/text to render correctly within the Unity editor interface (and editor plugin UI), or is this only relevant to in-game UI elements that use TextMeshPro?
     
  7. Zephus

    Zephus

    Joined:
    May 25, 2015
    Posts:
    356
    Are there any more plans for 'native integration', for lack of a better term? It seems that newer Unity versions moved Text to the Legacy menu. I teach Unity and every single new user is completely confused what this TextMeshPro in the menu is supposed to be and how UI works now.

    I've noticed that they just want to add text or a button, so basically something that should be extremely simple and quick. But then they get a popup asking them to import TMP essentials. Some close the window, because they don't want to break anything. Or they want to import a font and have no idea why they can't just add it to the component, and are confused when I tell them to open this kind of hidden menu to create font assets. And then they want to script with it and I have to explain that UI.Text isn't actually what they want, but they need this TextMeshProUGUI thing and import TMPro instead of the UI package, which you would never know without googling explicitily for TextMeshPro.

    With the de facto 'removal' of the old Text component, I feel like you really need to streamline the entire Text functionality. People shouldn't have to import these essentials manually if TMP is to be used as the default text. Adding and changing text through code should just work out of the box without much explanation.
     
  8. pez

    pez

    Joined:
    Jul 6, 2013
    Posts:
    52
    Hi, not sure if this is the best place to post my problem, but I can't get access the download for the pre release TMP in package manager no matter what I try.



    I am on Unity 2021.2.1 & am not shown any preview packages for TMP.

    Is there a specific git URL I can use for version 3.2?

    Thanks,

    EDIT:

    Ok found a solution. If anyone else is having this issue enter this into the "add package by name" option:



    com.unity.textmeshpro
    3.2.0-pre.3
     
    Last edited: Mar 27, 2022
  9. ComputerKim

    ComputerKim

    Joined:
    Jan 6, 2019
    Posts:
    15
    This is great! Does Dynamic OS Font Assets work on WebGL? I have not been able to get it to work.

    EDIT: I noticed that you can load a font binary into FontEngine.LoadFontFace, however I don't know how to get the Font from there into a TMP_FontAsset. I could not find any documentation on how it works.

    Does anybody know how to do this?

    Alternatively, could the font asset keep a reference to byte[] and just use that?

    This would allow us to load font files from streamingAssets at runtime.

    EDIT 2: Did a few changes myself and got it working, now i just need to see if this is stable.

    If you want to do this yourself, google how to modify a package, and here is the code i modified.
    Code (CSharp):
    1.         // CUSTOM : Added data field and function for data
    2.         byte[] data;
    3.         public static TMP_FontAsset CreateFontAsset(byte[] data)
    4.         {
    5.             return CreateFontAssetInstance(null, 9, GlyphRenderMode.SDFAA, 1024, 1024, AtlasPopulationMode.Dynamic, true, data);
    6.         }
    7.  
    8.         // CUSTOM : Modified CreateFontAssetInstance to add data parameter
    9.         static TMP_FontAsset CreateFontAssetInstance(Font font, int atlasPadding, GlyphRenderMode renderMode, int atlasWidth, int atlasHeight, AtlasPopulationMode atlasPopulationMode, bool enableMultiAtlasSupport, byte[] data = null)
    10.         {
    11.            // CUSTOM : If data, load it
    12.            if (data != null) {
    13.                 var result = FontEngine.LoadFontFace(data, 90);
    14.                 if (result != FontEngineError.Success) throw new($"Failed to load font. {result}");
    15.             }
    16.  
    17.             // Create new font asset
    18.             TMP_FontAsset fontAsset = CreateInstance<TMP_FontAsset>();
    19.          
    20.            // CUSTOM : Assign data
    21.             fontAsset.data = data;
    22.  
    23. /// Find the LoadFontFace function, and modify it with
    24.         FontEngineError LoadFontFace()
    25.         {
    26.             if (m_AtlasPopulationMode == AtlasPopulationMode.Dynamic)
    27.             {
    28.                 // Font Asset should have a valid reference to a font in the Editor.
    29.                 #if UNITY_EDITOR
    30.                 if (m_SourceFontFile == null)
    31.                     m_SourceFontFile = SourceFont_EditorRef;
    32.                 #endif
    33.  
    34.                 // CUSTOM : If data, load it
    35.                 if (data != null) return FontEngine.LoadFontFace(data, m_FaceInfo.pointSize, m_FaceInfo.faceIndex);
    36.  
    37.  
    EDIT 3: Usage example.
    Code (CSharp):
    1. public class Test : MonoBehaviour {
    2.     public TMP_Text tmp;
    3.  
    4.     IEnumerator Start() {
    5.         using var request = UnityWebRequest.Get($"{Application.streamingAssetsPath}/fonts/NotoSansSC-Regular.otf");
    6.         yield return request.SendWebRequest();
    7.         if (request.result != UnityWebRequest.Result.Success) throw new("Failed to get font file.");
    8.  
    9.         TMP_Settings.fallbackFontAssets.Add(TMP_FontAsset.CreateFontAsset(request.downloadHandler.data));
    10.  
    11.         tmp.text = "Hello 你好 World";
    12.     }
    13. }
     
    Last edited: Mar 29, 2022
  10. Rickmc3280

    Rickmc3280

    Joined:
    Jun 28, 2014
    Posts:
    189
    Is there a fix for TMPro in World Space/VR? (or can yall add something in a new update)? Posting a picture below of how it looks in VR - Basically like perspective view. (It is from another post that was "resovled" and not exactly related to my issue). When I disable "Additional Shader Channels" - (select nothing) it renders fine, but then automatically enables itself. Would it be possible to create an override when using worldspace canvas? 2nd Image shows my setup that "works" - but after a little bit, Text Mesh Pro reenabled the other shader channels and it needs to be disabled again during runtime.
    upload_2022-3-30_21-58-54.png
    upload_2022-3-30_22-3-57.png
     
  11. Ferazel

    Ferazel

    Joined:
    Apr 18, 2010
    Posts:
    517
    Would these TextCore OpenType features by chance going to be backported to the 2021 LTS (our targeted release version) or has that ship sailed and will require 2022.x?
     
  12. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The plan is to have these changes and functionality available in Unity 2020.3 and up.
     
    AliAlbarrak and Ferazel like this.
  13. david910

    david910

    Joined:
    Jan 2, 2016
    Posts:
    5
    Hi Stephan, thank you for the great work.
    I would like to report an issue with the Text Wrapping Mode.

    The spacing seems not be correctly preserved once a word is pushed into a new line by leading spaces.
    How to replicate:
    1. Create new Text - TextMeshPro object
    2. Set Text Wrapping Mode to "Preserve White spaces"
    3. (optional) Stretch Rect Transform to fill the entire screen and have better visual clue of line ending.
    4. In the editor set Text Input to "Sample Text".
    5. Start adding leading spaces until "Text" word is pushed to new line.
    6. ISSUE: Any additional leading space added at this time will cause "Sample" to advance forward, but "Text" will not move. After a certain amount of spaces (possibly depending on the word length and font used) "Sample" is pushed in the new line too. Again, multiple additional spaces will be required to make the words move forwards.

    -- EDIT --

    One note on my previous post, just discovered that other text editors behave in similar manner (notably Office Word and Notepad++).
    If this is intended behavior please ignore this report.
     
    Last edited: Apr 15, 2022
  14. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I will still review the above but I did indeed tried to mirror the behavior from MS Word, Notepad ++, etc.
     
  15. iMer

    iMer

    Joined:
    May 21, 2013
    Posts:
    29
    Any chance you could add an option to never save to dynamic font assets in the first place instead of clearing them?
    Kinda annoying to have them reload before/after every build due to the clear option if one doesn't care about the contents anyways (and having random version control changes even though nobody actually changed the asset)
     
    Peter77 likes this.
  16. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Since we have users who want this data to be persistent, I am still looking for a clean way to provide for both behaviors.

    Disabling serialization of dynamic data would mean they are always repopulated at runtime as characters and glyphs are requested.

    Having dynamic data persist means larger build size since the atlas texture is not empty as you ship but It also means better performance at runtime as characters and glyphs contained in those assets does not have to be re-added and glyphs re-rastered into the atlas texture.

    The only issue with the currently handling is source control related as you can control what happens to this data when you create a build. Note that Clear Dynamic Data on Build now also clears this data when you close the Editor. It can now also be manually cleared via the font asset context menu option seen below,

    upload_2022-4-28_15-8-1.png

    To avoid confusion, I do understand the desire to not have this dynamic data serialized at all. Thus the only use case for this is source control related. I will continue to explore how we could provide this functionality.
     
    iMer likes this.
  17. StefanoCecere

    StefanoCecere

    Joined:
    Jun 10, 2011
    Posts:
    211
    the Mark to Base and Mark to Mark adjustment tables are fantastic.
    we developed something similar to manage arabic diacritics, but we used the unicodes as IDs, now you ask for the glyph ID...
    what happens if we reimport the font? will IDs change? could we use char unicodes as IDs?

    thank you!
     
  18. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    OpenType Layout features reference glyph indexes (IDs).

    It is pretty common to have several characters point to the same glyph index.

    It is also pretty common for fonts to contain many glyphs that are not mapped to any specific code point. For instance, the glyph used for the "ffi" Ligature typically does not have a Unicode code point associated with it.

    Another example is Alternate Substitutions where a single glyph can be replaced by many alternate forms / glyphs. In this case you have a single unicode code point potentially pointing to several other glyphs.

    If you look at the character table of a font asset, you will notice that a character is assigned a Unicode code point and points to a glyph index. Many characters can point to the same glyph index. The glyph table contains the glyphs and their metrics.

    Once I am done implementing all of this, these OpenType Layout features and relevant data will be automatically extracted from the font file and populated in the font asset provide such data exists in the font. If the selected font doesn't contain any OpenType Layout features, users will be able to manually add such data if desired.

    With respect to Diacritical Marks, since both the base and mark are inputted sequentially by the user, the marks are assigned a Unicode code point. Although you could make this work by referencing these Unicode code point for Diacritical Marks, this is not the case for all OpenType Layout feature hence why the Mark-to-Base and Mark-to-Ligature and Mark-to-Mark tables in the GPOS table of the font file reference these glyphs by the index.

    Re-importing or creating a new font asset from the same font file should have no affect on this. Having said that, if whoever designed the font created a new version with new glyphs and features, you would have to treat this like a new font (which it is) and either Reset the font asset to clear the existing font data which may now be invalid or create a new font asset.
     
    StefanoCecere likes this.
  19. dazaizone

    dazaizone

    Joined:
    Mar 6, 2020
    Posts:
    43
  20. ewittkowske_unity

    ewittkowske_unity

    Joined:
    Mar 5, 2020
    Posts:
    4
    Any updates on when the changes to the FontEngine will be available in a Unity upgrade? I haven't seen anything mentioned in the release notes.
     
  21. jiraphatK

    jiraphatK

    Joined:
    Sep 29, 2018
    Posts:
    300
    I suggest you wait until it comes out on its own. Even if Stephan comes and gives you another ETA, it will be delayed from the new date again anyway.
     
  22. KurtGokhan

    KurtGokhan

    Joined:
    Jan 16, 2013
    Posts:
    37
    Can TMP version 3.x work in Unity 2019.4? As far as I understand, only thing preventing it from working it is usage of VersionControlSettings class. If that part of code is wrapped inside "define", wouldn't that be enough to make it work in 2019.4 (LTS)? That would be a life saver for people like me who switch between versions frequently.
     
  23. Rickmc3280

    Rickmc3280

    Joined:
    Jun 28, 2014
    Posts:
    189
    When using VR/XR - Disabling the channels (none) makes Text Mesh Pro objects look high quality when scaling which is necessary for world space canvases. However, Unity somewhere in the system reenables it at random intervals and when using it, the text goes blurry and becomes unreadable as shown in my previous post. It would be great if yall can find a fix with the text mesh pro and canvas/ui teams. I would like to permanently disable it, polling is not desirable.
    upload_2022-5-25_13-53-52.png
     
  24. keni4

    keni4

    Joined:
    Nov 30, 2014
    Posts:
    31
    Hi @Stephan_B, Great work! Is there any chance for TextMeshPro will react to softness in RectMask2D?
     
  25. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    It should be already be with these latest releases. However, be sure to update to TMP Essential Resources as this functionality is partly contained in the updated shaders contained in those.
     
    skilani and keni4 like this.
  26. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Version 2.2.0-preview.3 is the same from a feature point of view as version 3.2.0-pre.3. There is no reason to try to use version 3.2.0. Furthermore, version 3.2.0 contains updated UV Layout which will not work in 2019.4.
     
  27. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Can you submit a bug report on this along with simple project? This will make it easier to track and review.
     
  28. daani121

    daani121

    Joined:
    May 23, 2022
    Posts:
    2
    It should be already be with these latest releases. However, be sure to update to TMP Essential Resources as this functionality is partly contained in the updated shaders contained in those.
     
  29. Rickmc3280

    Rickmc3280

    Joined:
    Jun 28, 2014
    Posts:
    189
    Submit following this guide? https://unity3d.com/unity/qa/bug-reporting

    Ill have to just create a basic project with TextMeshPro Canvas scaled to .1/.01 in world space. Happens every time.
     
  30. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,311
    Nice update. I'm curious about the .ttc workflow, not something I've heard of before.

    How to you generate a .ttc file from many .ttf files?
    Does TMP import and recognize .ttc files?
    How do you generate Font Assets from a .ttc?
     
  31. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I am planning / need to create a nice video about all of this. In the meantime, here is some additional information.

    Most font creation and editing tools should enable you to create .ttc files. For instance, it is pretty easy to do this in FontForge.

    For example, I downloaded the entire font family for Inter which is 18 font files (one for each font weight and then their italic variant) and then created a single .ttc file for all of them.

    Unity is able to import .ttc files from which you can create font assets via the Font Asset Creator or the Create context menu options.

    After creating a font asset from a .ttc font file, you can then select which font face from within the collection you want to use as seen below.

    upload_2022-6-10_13-43-51.png
     
  32. skilani

    skilani

    Joined:
    Aug 31, 2013
    Posts:
    7
    All my TMPs turned into unrecognisable blobs when I updated from 3.0.6 to 3.2.0-pre3. This fixed it, just highlighting and going to slam a few keywords in here for anyone else Ctrl+F'ing: Blobs, text blobs, blocky text, blocks.

    Thanks again, TMP is a great asset.
     
  33. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    @Stephan_B I'm finally on 2021.3 LTS, and I've updated to TMP 3.2.0-pre.3. My whole goal with the HDRP-compatible TMP has been to be able to set the rendering of TMP text to "After post-processing" to avoid having the text affected by motion blur. Could you advise how to set the render queue for TMP under the new package? Thanks.

    Nevermind. I just hadn't assigned the new HDRP shader to the material. Upon doing so, I see the material has the expected HDRP settings, like Rendering Pass. So, all set. Thanks. :)
     
    Last edited: Jun 26, 2022
  34. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    Using the new HDRP Unlit shader, I'm seeing this in cases where the text is bold (contains <b></b> tags):

    Code (CSharp):
    1. Material 'Visor Diagnostics Text - Aldrich Material' with Shader 'TextMeshPro/SRP/TMP_SDF-HDRP UNLIT' doesn't have a float or range property '_ScaleRatioA'
    2. UnityEngine.Material:GetFloat (int)
    3. TMPro.TextMeshProUGUI:GenerateTextMesh () (at Library/PackageCache/com.unity.textmeshpro@3.2.0-pre.3/Scripts/Runtime/TMPro_UGUI_Private.cs:2364)
    4. TMPro.TextMeshProUGUI:OnPreRenderCanvas () (at Library/PackageCache/com.unity.textmeshpro@3.2.0-pre.3/Scripts/Runtime/TMPro_UGUI_Private.cs:1737)
    5. TMPro.TextMeshProUGUI:Rebuild (UnityEngine.UI.CanvasUpdate) (at Library/PackageCache/com.unity.textmeshpro@3.2.0-pre.3/Scripts/Runtime/TextMeshProUGUI.cs:216)
    6. UnityEngine.Canvas:SendWillRenderCanvases ()
    Seems the HDRP shaders don't have _ScaleRatioA, and the code's not checking for that.
     
  35. gewl

    gewl

    Joined:
    May 19, 2016
    Posts:
    95
    I'm getting this as well.
     
  36. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    FWIW, I just edited the shader and added a dummy _ScaleRatioA field, just to mute the error. Not a good long term solution, but a quick hack that doesn't seem to cause any issues (so far).
     
  37. Alexander_V

    Alexander_V

    Joined:
    Feb 26, 2020
    Posts:
    8
    Good day! Our studio is converting all Unity text labels into TMP ones, and we stumbled upon a couple of blockers. Maybe we are missing some not very obvious solutions?

    1. Kerning is distorted when text is italicized, leading to character overlap.
    That happens due to an incorrect italicization pivot. Right now, each character uses its' quad middle and skews around it, leading to non-uniform offsets of symbols like "." or ",". We've tried to extend quads of affected chars in the font asset and make them the same height as letters, but it starts grabbing neighbor chars from the atlas.
    Here is an example video:


    2. Outline(stroke) scales with the font
    Is there any way to compensate for font size and modify outline/deviation values at runtime without breaking batching? We have multiple text sizes on a screen that use the same outline material - a simple 50% opacity black stroke.
    Here is an example of the issue

    We thought if text size were somewhere in vertex data, we could compensate for that in a shader.
     
    Last edited: Jul 13, 2022
    mrtenda likes this.
  38. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Unless you are using and have assign an actual Italic variant of the font in the Font Weight table, Italic style is simulated by shearing the glyphs. Unfortunately, this faking of the italic style has its limitations.

    My suggestion would be to use the true italic font for whatever font weight you are using if it is available. Alternatively, I am open to suggestions on any potential alternative implementation of the Italic style simulation.

    P.S. Note that you can change the shearing amount which might lessen the issue.



    I presume you are looking for a fix width on the Outline as opposed to relative width. Correct?

    Not currently without breaking batching. We would need to pass some additional data into the vertex stream which the shader could then use.
     
  39. Alexander_V

    Alexander_V

    Joined:
    Feb 26, 2020
    Posts:
    8
    Unfortunately, we can not add a separate variant because of the memory issues on mobile at the moment (as many long-running service games are :) )
    There are multiple ways to address it though. It depends on where you shear the vertices - CPU or GPU.
    If it's CPU, you could just use font baseline as a vertical coordinate for transformation (shearing).
    If it's GPU, the world pos of the current characters' baseline OR delta between mesh center world pos. and baseline world pos. must be recorded in vertex steam.

    Yeah, that would be perfect! that's why I thought of writing font size in a vertex stream to avoid breaking batching.
     
    Last edited: Jul 15, 2022
  40. jiraphatK

    jiraphatK

    Joined:
    Sep 29, 2018
    Posts:
    300
    @Stephan_B Unity 2022.2 beta is out now, will your work on updating the core engine be available in that version?
    NVIDIA_Share_cK9WWzJ9yJ.png
     
    Last edited: Jul 15, 2022
  41. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I can certainly improve the faking of the italic style where depending on the slanting angle / shear I should be adjusting the advance value which is what is kind of leading to this tightening.

    Reflecting on the Outline width, you should be able to use the SDF Scale which is passed to shader. This SDF Scale is the relationship of the sampling point size to display size where for instance, if the sampling point size is 90 and displayed point size is 90 then the SDF Scale will be 1.0.

    In version 3.2.0-pre.3, the SDF Scale is passed in the "w" component of UV0.
     
  42. Dasp

    Dasp

    Joined:
    Sep 25, 2012
    Posts:
    38
  43. riez_

    riez_

    Joined:
    Aug 16, 2022
    Posts:
    2
    Hi @Stephan_B,

    I’m still struggeling with getting the ligatures to work. I found the Ligature Table but have no clue, how to add the actual ligatures. As far as I understand the glyphs need to be included in the font atlas, but I simply don’t understand how. If I type them in like they are named in the file (for example: «f_i») during the creation of the font atlas, it will treat them as three sperate glyphs instead of looking for the one with that name. Am I missing something?


    Thanks.
     
    Last edited: Aug 16, 2022
  44. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    OpenType Layout features such as Ligatures reference glyphs by their index. Most of the time, you can lookup the glyph index in the Character or Glyph tables but in the case of glyphs that have never been added, you have to use an external tool like FontForge, FontLab (free) or FontCreator to find those indexes.

    Here is an example using FontCreator (free version would work here) to look at Roboto-Bold.ttf.

    upload_2022-8-16_16-50-36.png

    Here is what some of those ligatures look like in the Ligature Table

    upload_2022-8-16_16-53-9.png

    Having to manually populate these OpenType tables is not fun and this process will get much easier once the changes I have been working on for a while make it into Unity. These changes will make it where this data is extracted automatically from the font file. The plan is to have these changes available in some future version of Unity 2020.3 and newer.

    In terms of referencing glyph by index, I think it would be nice to also be able to reference glyphs by name. Having said that, not all font designers follow established naming conventions where for instance the glyph for the Ligature for "f" + "f" + "i" is typically named "f_f_i" but that is not the case in many font files.
     
  45. riez_

    riez_

    Joined:
    Aug 16, 2022
    Posts:
    2
    I found the index number of the ligatures in the font file using ‹Glyphs›. When I now try to include these by entering the numbers in the character sequence while creating the font atlas, the atlas creator simply refuses to include them, as seen in the screenshot.

    Another thing with the index is that the glyph index in TMP is off by one number and in some cases the numbers don’t align at all (‹f› in TMP ID 95 in the font file ID 93).

    [edit:] It seems when I set the font to dynamic and use the letter combination in some text field, that I’m then able to trial and error myself towards finding the ligature (plus minus 1–2 index numbers).

    I attached screenshots and hope they illustrate my problem.

    Glyph Index
    index_fontfile.png
    Asset Creator excluding the Ligatures
    glyphs_get_excluded.png


    Thanks again.
     
    Last edited: Aug 17, 2022
  46. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Referencing the glyph index in the Font Asset Creator Character Sequence window won't work as these values represent the Unicode code point for those characters. The glyph index is a reference to the glyph index in an array of glyphs contained in the font file.

    Here is an example using FontCreator from High-Logic for the font Roboto - Bold

    In the image below, you can the Unicode code point for the character "A" is 0x41.

    upload_2022-8-18_23-44-27.png

    However, the index of this glyph is glyph index = 37 as seen below.

    upload_2022-8-18_23-46-4.png

    and here as seen in the font asset inspector of this font asset.

    upload_2022-8-18_23-48-7.png

    Note that the Unicode code point for the character "A" will never change as this its designed address / code point in the Unicode Standards. However, the glyph index for this character can and will most likely be different from font to font. This glyph index simply represent the index of the glyph in an array of glyphs. As such, depending on the font file and glyphs present, the index of any given glyph will vary.

    For example, the glyph index of the character "A" in the LiberationSans - Regular font file is 36 as seen below.

    upload_2022-8-18_23-51-38.png

    and in the NotoSans-Bold font file, its index 17.

    upload_2022-8-18_23-52-41.png

    As a reference, a Character is mapped to a specific Unicode Code Point where for instance the letter "A" is assigned the Unicode 0x41 or decimal value of 65. A character references a glyph index where such glyph is the visual representation of this character.

    Note that it is possible for multiple characters to reference the same glyph index. For instance, the Latin letter "T" 0x54, the Greek letter "T" 0x3A4 and the Cyrillic letter "T" 0x422.

    Back on the topic of Ligatures, most of the time, the resulting glyph that is used in a ligature is not assigned to a Unicode Code Point. As such, these glyphs can only be referenced via their glyph index.
     
  47. DanTaylor

    DanTaylor

    Joined:
    Jul 6, 2013
    Posts:
    119
    Thanks for this - it's been driving me mad!
    Don't know why it doesn't just show up when you enable experimental packages in the settings. Grrrr!
    <3
     
  48. Noisecrime

    Noisecrime

    Joined:
    Apr 7, 2010
    Posts:
    2,054
    Its great to see TMPro actively being improved.

    I was very excited in the ability to select a font style/weight from a TT collection, alas for my purposes it doesn't appear to work. I think its a misunderstanding on my end as I wanted to use it to extract the different weights from Googles new Material Symbols variable font files ( e.g. MaterialSymbolsOutlined[FILL,GRAD,opsz,wght].ttf) and it seems these are not collections, but a base font with embedded parameters that allow different wieghts to be generated at runtime.

    Assuming I'm correct with the above, is there any chance TMPro could support this in the future?

    I have a workaround currently where I download the WOFF2 web file for a specific MaterialSymbol font style and weight, convert it to ttf and import that into Unity, but its a bit of pain, especially as it generates so many different files for all the variations. Though I'm hoping to work out how to combine those conversions into a collection and leverage the new support for TT collections.

    [Edit - New Suggestion]
    I don't seem to find any 'default' settings for the Font Asset Creator - having to create a large number of TMPro font assets from font files is quite a bit of a pain. While you can select multiple fonts and create TMPro Font Assets, you still have to go in by hand and set up all the options, even if they are sharing the same ones.

    Maybe something like Unity 'Presets' process would work here, though as the Font Asset Creator isn't technically an importer i'm not sure they could be used directly.
    [Edit - end]

    Finally I've recently had to start using Unity with Preferences > UI Scaling > Custom Scaling of 125% and noticed the Font Asset Creator in TMPro side bar with all the settings is always clipped horizontally, forcing you to scroll left/right constantly when changing settings. Pretty sure this occurs 100% of the time, but it definately happens every time I try to 'Update Atlas Texture' from a created TMPro font asset.

    Strangely opening 'Font Asset Creator' from the menus does not exhibit the clipping issue. Its only when you use 'Update Atlas Texture' from an existing Font Asset.

    FontAssetCreator.PNG
     
    Last edited: Sep 2, 2022
  49. Noisecrime

    Noisecrime

    Joined:
    Apr 7, 2010
    Posts:
    2,054
    After further investigation, it would seem that maybe the way I was creating TMPro Font Assets was not the optimum approach for my objective. I guess I was using it as you would with other Unity assets - create each TMPro asset per font file asset - then use 'Update Texture Atlas' to populate the texture within the asset.

    Whilst doing this I noticed that I could simply open the 'Font Asset Creator', assign the font, set the various settings, generate Font Atlas and then use 'Save as' to create a specific TMPro Font Asset for a specific font, with bonus ability of for a specific font face ( via pre-release ). The obvious benefit being that it maintains all the settings between switching font face.

    Although slightly counter intuitive it would seem far more efficient than my original process and broadly address my complaint/suggest with regard to preset/default creator settings in the post above.

    The only issue with this approach that I've noticed is that 'save as' will populate the file name with the 'Source Font' name, instead of the 'Font Face' name. If that could be addressed then this makes dealing with creating many fonts, especially with the new TTC support, much more streamlined.

    Suggestion:
    In Font Asset Creator, have 'save as' use the selected FontFace name as the filename.
     
    Last edited: Sep 2, 2022
  50. Noisecrime

    Noisecrime

    Joined:
    Apr 7, 2010
    Posts:
    2,054
    Edit - I might be dumb ;)

    I had reported a potential bug with TTC support, where TMPro would only report 5 FontFaces instead of the 6 that I added to the collection in FontForge. Yet FontForge would report that there were 6 fonts in the same ttc file. I carried out several different tests and originally had the same results, but later tests appeared to work.

    Long story short I finally discovered that two of the fonts i'd added to the collection were duplicates, due to a naming bug. The font files were byte for byte exactly the same. Replacing the duplicate with the correct file, would appear to have address the whole TTC issue I was experiencing.

    Have created half a dozen TTC files in FontForge now and all of them come in via TMPro correctly, so it would appear that accidently having a file that was a duplicate of another and instead of being a different file was the cause of my problems.

    Previous post deleted.
     
    Last edited: Sep 2, 2022