質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.47%
Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

font

近年は、コンピュータ上、紙面上で利用できる書体データのことをfontといいます。数える時の単位は「書体」で、データとしてのフォントは、デジタルフォントと呼ばれる場合があります。 HTML/CSSでは要素を指定し、フォント情報を調整することができます。

Q&A

解決済

1回答

594閲覧

TextMeshProの日本語フォントを導入したが一部の文字が文字化けする

Azec

総合スコア1

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

font

近年は、コンピュータ上、紙面上で利用できる書体データのことをfontといいます。数える時の単位は「書体」で、データとしてのフォントは、デジタルフォントと呼ばれる場合があります。 HTML/CSSでは要素を指定し、フォント情報を調整することができます。

0グッド

0クリップ

投稿2024/01/12 03:55

実現したいこと

文字化けを無くしたい

発生している問題・分からないこと

FontAssetCreatorのCustumCharacterListの欄にhttps://gist.github.com/kgsi/ed2f1c5696a2211c1fd1e1e198c96ee4
こちらでダウンロードしたファイルからコピペしてフォントを作成したのですが一部の文字が□で表示されます。すべての文字という訳ではなく礼や巌、隙など一部の漢字のみです。
また文字化けは発生していますがConsole、VisualStudioのどちらにもエラーの表記はありません。
こちらの問題の解決方法が分かる方いらっしゃいましたらご教授いただければ幸いです。

エラーメッセージ

error

1The character with Unicode value \u5DCC was not found in the [SawarabiMincho-Regular SDF] font asset or any potential fallbacks. It was replaced by Unicode character \u25A1 in text object [Text (TMP)]. 2UnityEngine.Debug:LogWarning (object,UnityEngine.Object) 3TMPro.TextMeshProUGUI:SetArraySizes (TMPro.TMP_Text/UnicodeChar[]) (at ./Library/PackageCache/com.unity.textmeshpro@3.0.6/Scripts/Runtime/TMPro_UGUI_Private.cs:1274) 4TMPro.TMP_Text:ParseInputText () (at ./Library/PackageCache/com.unity.textmeshpro@3.0.6/Scripts/Runtime/TMP_Text.cs:1902) 5TMPro.TMP_Text:GetPreferredWidth () (at ./Library/PackageCache/com.unity.textmeshpro@3.0.6/Scripts/Runtime/TMP_Text.cs:3755) 6TMPro.TMP_Text:get_preferredWidth () (at ./Library/PackageCache/com.unity.textmeshpro@3.0.6/Scripts/Runtime/TMP_Text.cs:1384) 7UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

該当のソースコード

if (character == null) { // Save the original unicode character int srcGlyph = unicode; // Try replacing the missing glyph character by TMP Settings Missing Glyph or Square (9633) character. unicode = unicodeChars[i].unicode = TMP_Settings.missingGlyphCharacter == 0 ? 9633 : TMP_Settings.missingGlyphCharacter; // Check for the missing glyph character in the currently assigned font asset and its fallbacks character = TMP_FontAssetUtilities.GetCharacterFromFontAsset((uint)unicode, m_currentFontAsset, true, m_FontStyleInternal, m_FontWeightInternal, out isUsingAlternativeTypeface); if (character == null) { // Search for the missing glyph character in the TMP Settings Fallback list. if (TMP_Settings.fallbackFontAssets != null && TMP_Settings.fallbackFontAssets.Count > 0) character = TMP_FontAssetUtilities.GetCharacterFromFontAssets((uint)unicode, m_currentFontAsset, TMP_Settings.fallbackFontAssets, true, m_FontStyleInternal, m_FontWeightInternal, out isUsingAlternativeTypeface); } if (character == null) { // Search for the missing glyph in the TMP Settings Default Font Asset. if (TMP_Settings.defaultFontAsset != null) character = TMP_FontAssetUtilities.GetCharacterFromFontAsset((uint)unicode, TMP_Settings.defaultFontAsset, true, m_FontStyleInternal, m_FontWeightInternal, out isUsingAlternativeTypeface); } if (character == null) { // Use Space (32) Glyph from the currently assigned font asset. unicode = unicodeChars[i].unicode = 32; character = TMP_FontAssetUtilities.GetCharacterFromFontAsset((uint)unicode, m_currentFontAsset, true, m_FontStyleInternal, m_FontWeightInternal, out isUsingAlternativeTypeface); } if (character == null) { // Use End of Text (0x03) Glyph from the currently assigned font asset. unicode = unicodeChars[i].unicode = 0x03; character = TMP_FontAssetUtilities.GetCharacterFromFontAsset((uint)unicode, m_currentFontAsset, true, m_FontStyleInternal, m_FontWeightInternal, out isUsingAlternativeTypeface); } if (!TMP_Settings.warningsDisabled) { string formattedWarning = srcGlyph > 0xFFFF ? string.Format("The character with Unicode value \\U{0:X8} was not found in the [{1}] font asset or any potential fallbacks. It was replaced by Unicode character \\u{2:X4} in text object [{3}].", srcGlyph, m_fontAsset.name, character.unicode, this.name) : string.Format("The character with Unicode value \\u{0:X4} was not found in the [{1}] font asset or any potential fallbacks. It was replaced by Unicode character \\u{2:X4} in text object [{3}].", srcGlyph, m_fontAsset.name, character.unicode, this.name); Debug.LogWarning(formattedWarning, this); } }
protected void ParseInputText() { k_ParseTextMarker.Begin(); switch (m_inputSource) { case TextInputSources.TextString: case TextInputSources.TextInputBox: PopulateTextBackingArray(m_TextPreprocessor == null ? m_text : m_TextPreprocessor.PreprocessText(m_text)); PopulateTextProcessingArray(); break; case TextInputSources.SetText: break; case TextInputSources.SetTextArray: break; } SetArraySizes(m_TextProcessingArray); k_ParseTextMarker.End(); }
protected float GetPreferredWidth() { if (TMP_Settings.instance == null) return 0; // Return cached preferred height if already computed if (!m_isPreferredWidthDirty) return m_preferredWidth; float fontSize = m_enableAutoSizing ? m_fontSizeMax : m_fontSize; // Reset auto sizing point size bounds m_minFontSize = m_fontSizeMin; m_maxFontSize = m_fontSizeMax; m_charWidthAdjDelta = 0; // Set Margins to Infinity Vector2 margin = k_LargePositiveVector2; m_isCalculatingPreferredValues = true; ParseInputText(); m_AutoSizeIterationCount = 0; float preferredWidth = CalculatePreferredValues(ref fontSize, margin, false, false).x; m_isPreferredWidthDirty = false; //Debug.Log("GetPreferredWidth() called on Object ID: " + GetInstanceID() + " on frame: " + Time.frameCount + ". Returning width of " + preferredWidth); return preferredWidth; }
public virtual float preferredWidth { get { m_preferredWidth = GetPreferredWidth(); return m_preferredWidth; } }

試したこと・調べたこと

  • teratailやGoogle等で検索した
  • ソースコードを自分なりに変更した
  • 知人に聞いた
  • その他
上記の詳細・結果

「TextMeshPro 日本語 フォント 文字化け」で調べた結果出てくるのがフォント追加前の文字化けをフォント追加で対処というものだったのであまり参考になりませんでした。
またフォントの種類によっては文字化けしないものもありましたが今のフォントからなるべく変更しないようにしたいです。

補足

使用しているUnityのバージョンは2022.3.15f1
使用しているフォントはGoogleFontのSawarabi Minchoです

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

Sawarabi Minchoをダウンロードしてきて、
「礼巌隙」の3文字だけでFontAssetを作ってみました。

イメージ説明

「巌」と「隙」についてはフォントに含まれていないようです。
「礼」は問題なく書き出されていて、画面上も表示できていました。

Assets/TextMesh Pro/Glyph Report.txtに
ログが吐き出されているので他のMissing Charactersも確認できると思います。

投稿2024/01/12 10:00

Ratnaraj

総合スコア120

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Azec

2024/01/13 05:10

このフォントでそれらの漢字を扱うのは難しい、ということで大丈夫ですか?
Ratnaraj

2024/01/13 05:43

そうですね。漢字が含まれていないようなので無理かと。 ・使いたい文字が全て使用できるフォントに変更する ・使えない文字を使わないようにする のどちらかしかないように思います。 Sawarabi Minchoに含まれない文字を別のフォントで生成しておいて、 フォールバックさせることも出来ますが、 文章中に別のフォントが混じることになるのでおすすめはしません。
Azec

2024/01/13 15:17

分かりました。 丁寧に教えていただきありがとうございました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.47%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問