12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080 |
- using System;
- using UnityEngine;
- using UnityEngine.Serialization;
- using UnityEngine.TextCore;
- using UnityEngine.TextCore.LowLevel;
- using Unity.Profiling;
- using System.Collections.Generic;
- using System.Linq;
- #if UNITY_EDITOR && UNITY_2018_4_OR_NEWER && !UNITY_2018_4_0 && !UNITY_2018_4_1 && !UNITY_2018_4_2 && !UNITY_2018_4_3 && !UNITY_2018_4_4
- using UnityEditor.TextCore.LowLevel;
- #endif
- namespace TMPro
- {
- public enum AtlasPopulationMode
- {
- Static = 0x0,
- Dynamic = 0x1,
- }
- [Serializable][ExcludeFromPresetAttribute]
- public class TMP_FontAsset : TMP_Asset
- {
-
-
-
-
- public string version
- {
- get { return m_Version; }
- internal set { m_Version = value; }
- }
- [SerializeField]
- private string m_Version;
-
-
-
- [SerializeField]
- internal string m_SourceFontFileGUID;
- #if UNITY_EDITOR
-
-
-
- [SerializeField]
- internal Font m_SourceFontFile_EditorRef;
- #endif
-
-
-
- public Font sourceFontFile
- {
- get { return m_SourceFontFile; }
- internal set { m_SourceFontFile = value; }
- }
- [SerializeField]
- private Font m_SourceFontFile;
- public AtlasPopulationMode atlasPopulationMode
- {
- get { return m_AtlasPopulationMode; }
- set
- {
- m_AtlasPopulationMode = value;
- #if UNITY_EDITOR
- if (m_AtlasPopulationMode == AtlasPopulationMode.Static)
- m_SourceFontFile = null;
- else if (m_AtlasPopulationMode == AtlasPopulationMode.Dynamic)
- m_SourceFontFile = m_SourceFontFile_EditorRef;
- #endif
- }
- }
- [SerializeField]
- private AtlasPopulationMode m_AtlasPopulationMode;
-
-
-
- public FaceInfo faceInfo
- {
- get { return m_FaceInfo; }
- set { m_FaceInfo = value; }
- }
- [SerializeField]
- internal FaceInfo m_FaceInfo;
-
-
-
- public List<Glyph> glyphTable
- {
- get { return m_GlyphTable; }
- internal set { m_GlyphTable = value; }
- }
- [SerializeField]
- internal List<Glyph> m_GlyphTable = new List<Glyph>();
-
-
-
- public Dictionary<uint, Glyph> glyphLookupTable
- {
- get
- {
- if (m_GlyphLookupDictionary == null)
- ReadFontAssetDefinition();
- return m_GlyphLookupDictionary;
- }
- }
- internal Dictionary<uint, Glyph> m_GlyphLookupDictionary;
-
-
-
- public List<TMP_Character> characterTable
- {
- get { return m_CharacterTable; }
- internal set { m_CharacterTable = value; }
- }
- [SerializeField]
- internal List<TMP_Character> m_CharacterTable = new List<TMP_Character>();
-
-
-
- public Dictionary<uint, TMP_Character> characterLookupTable
- {
- get
- {
- if (m_CharacterLookupDictionary == null)
- ReadFontAssetDefinition();
- return m_CharacterLookupDictionary;
- }
- }
- internal Dictionary<uint, TMP_Character> m_CharacterLookupDictionary;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public Texture2D atlasTexture
- {
- get
- {
- if (m_AtlasTexture == null)
- {
- m_AtlasTexture = atlasTextures[0];
- }
- return m_AtlasTexture;
- }
- }
- internal Texture2D m_AtlasTexture;
-
-
-
- public Texture2D[] atlasTextures
- {
- get
- {
- if (m_AtlasTextures == null)
- {
-
- }
-
-
- return m_AtlasTextures;
- }
- set
- {
- m_AtlasTextures = value;
- }
- }
- [SerializeField]
- internal Texture2D[] m_AtlasTextures;
-
-
-
- [SerializeField]
- internal int m_AtlasTextureIndex;
-
-
-
- public int atlasTextureCount { get { return m_AtlasTextureIndex + 1; } }
-
-
-
- public bool isMultiAtlasTexturesEnabled
- {
- get { return m_IsMultiAtlasTexturesEnabled; }
- set { m_IsMultiAtlasTexturesEnabled = value; }
- }
- [SerializeField]
- private bool m_IsMultiAtlasTexturesEnabled;
-
-
-
- internal bool clearDynamicDataOnBuild
- {
- get { return m_ClearDynamicDataOnBuild; }
- set { m_ClearDynamicDataOnBuild = value; }
- }
- [SerializeField]
- private bool m_ClearDynamicDataOnBuild;
-
-
-
- internal List<GlyphRect> usedGlyphRects
- {
- get { return m_UsedGlyphRects; }
- set { m_UsedGlyphRects = value; }
- }
- [SerializeField]
- private List<GlyphRect> m_UsedGlyphRects;
-
-
-
- internal List<GlyphRect> freeGlyphRects
- {
- get { return m_FreeGlyphRects; }
- set { m_FreeGlyphRects = value; }
- }
- [SerializeField]
- private List<GlyphRect> m_FreeGlyphRects;
-
-
-
-
- [Obsolete("The fontInfo property and underlying type is now obsolete. Please use the faceInfo property and FaceInfo type instead.")]
- public FaceInfo_Legacy fontInfo
- {
- get { return m_fontInfo; }
- }
- [SerializeField]
- private FaceInfo_Legacy m_fontInfo = null;
-
-
-
- [SerializeField]
- public Texture2D atlas;
-
-
-
- public int atlasWidth
- {
- get { return m_AtlasWidth; }
- internal set { m_AtlasWidth = value; }
- }
- [SerializeField]
- internal int m_AtlasWidth;
-
-
-
- public int atlasHeight
- {
- get { return m_AtlasHeight; }
- internal set { m_AtlasHeight = value; }
- }
- [SerializeField]
- internal int m_AtlasHeight;
-
-
-
- public int atlasPadding
- {
- get { return m_AtlasPadding; }
- internal set { m_AtlasPadding = value; }
- }
- [SerializeField]
- internal int m_AtlasPadding;
- public GlyphRenderMode atlasRenderMode
- {
- get { return m_AtlasRenderMode; }
- internal set { m_AtlasRenderMode = value; }
- }
- [SerializeField]
- internal GlyphRenderMode m_AtlasRenderMode;
-
- [SerializeField]
- internal List<TMP_Glyph> m_glyphInfoList;
- [SerializeField]
- [FormerlySerializedAs("m_kerningInfo")]
- internal KerningTable m_KerningTable = new KerningTable();
-
-
-
- public TMP_FontFeatureTable fontFeatureTable
- {
- get { return m_FontFeatureTable; }
- internal set { m_FontFeatureTable = value; }
- }
- [SerializeField]
- internal TMP_FontFeatureTable m_FontFeatureTable = new TMP_FontFeatureTable();
-
- [SerializeField]
- #pragma warning disable 0649
- private List<TMP_FontAsset> fallbackFontAssets;
-
-
-
- public List<TMP_FontAsset> fallbackFontAssetTable
- {
- get { return m_FallbackFontAssetTable; }
- set { m_FallbackFontAssetTable = value; }
- }
- [SerializeField]
- internal List<TMP_FontAsset> m_FallbackFontAssetTable;
-
-
-
- public FontAssetCreationSettings creationSettings
- {
- get { return m_CreationSettings; }
- set { m_CreationSettings = value; }
- }
- [SerializeField]
- internal FontAssetCreationSettings m_CreationSettings;
-
-
-
- public TMP_FontWeightPair[] fontWeightTable
- {
- get { return m_FontWeightTable; }
- internal set { m_FontWeightTable = value; }
- }
- [SerializeField]
- private TMP_FontWeightPair[] m_FontWeightTable = new TMP_FontWeightPair[10];
-
-
-
-
-
- [SerializeField]
- private TMP_FontWeightPair[] fontWeights = null;
-
-
-
-
- public float normalStyle = 0;
-
-
-
- public float normalSpacingOffset = 0;
-
-
-
- public float boldStyle = 0.75f;
-
-
-
- public float boldSpacing = 7f;
-
-
-
- public byte italicStyle = 35;
- public byte tabSize = 10;
- internal bool IsFontAssetLookupTablesDirty;
-
- private static ProfilerMarker k_ReadFontAssetDefinitionMarker = new ProfilerMarker("TMP.ReadFontAssetDefinition");
- private static ProfilerMarker k_AddSynthesizedCharactersMarker = new ProfilerMarker("TMP.AddSynthesizedCharacters");
- private static ProfilerMarker k_TryAddCharacterMarker = new ProfilerMarker("TMP.TryAddCharacter");
- private static ProfilerMarker k_TryAddCharactersMarker = new ProfilerMarker("TMP.TryAddCharacters");
- private static ProfilerMarker k_UpdateGlyphAdjustmentRecordsMarker = new ProfilerMarker("TMP.UpdateGlyphAdjustmentRecords");
- private static ProfilerMarker k_ClearFontAssetDataMarker = new ProfilerMarker("TMP.ClearFontAssetData");
- private static ProfilerMarker k_UpdateFontAssetDataMarker = new ProfilerMarker("TMP.UpdateFontAssetData");
-
-
-
-
-
- public static TMP_FontAsset CreateFontAsset(Font font)
- {
- return CreateFontAsset(font, 90, 9, GlyphRenderMode.SDFAA, 1024, 1024, AtlasPopulationMode.Dynamic);
- }
-
-
-
-
-
-
-
-
-
-
-
- public static TMP_FontAsset CreateFontAsset(Font font, int samplingPointSize, int atlasPadding, GlyphRenderMode renderMode, int atlasWidth, int atlasHeight, AtlasPopulationMode atlasPopulationMode = AtlasPopulationMode.Dynamic, bool enableMultiAtlasSupport = true)
- {
-
- FontEngine.InitializeFontEngine();
-
- if (FontEngine.LoadFontFace(font, samplingPointSize) != FontEngineError.Success)
- {
- Debug.LogWarning("Unable to load font face for [" + font.name + "]. Make sure \"Include Font Data\" is enabled in the Font Import Settings.", font);
- return null;
- }
-
- TMP_FontAsset fontAsset = ScriptableObject.CreateInstance<TMP_FontAsset>();
- fontAsset.m_Version = "1.1.0";
- fontAsset.faceInfo = FontEngine.GetFaceInfo();
-
- if (atlasPopulationMode == AtlasPopulationMode.Dynamic)
- fontAsset.sourceFontFile = font;
-
- #if UNITY_EDITOR
- string guid;
- long localID;
- UnityEditor.AssetDatabase.TryGetGUIDAndLocalFileIdentifier(font, out guid, out localID);
- fontAsset.m_SourceFontFileGUID = guid;
- fontAsset.m_SourceFontFile_EditorRef = font;
- #endif
- fontAsset.atlasPopulationMode = atlasPopulationMode;
- fontAsset.atlasWidth = atlasWidth;
- fontAsset.atlasHeight = atlasHeight;
- fontAsset.atlasPadding = atlasPadding;
- fontAsset.atlasRenderMode = renderMode;
-
- fontAsset.atlasTextures = new Texture2D[1];
-
- Texture2D texture = new Texture2D(0, 0, TextureFormat.Alpha8, false);
- fontAsset.atlasTextures[0] = texture;
- fontAsset.isMultiAtlasTexturesEnabled = enableMultiAtlasSupport;
-
- int packingModifier;
- if (((GlyphRasterModes)renderMode & GlyphRasterModes.RASTER_MODE_BITMAP) == GlyphRasterModes.RASTER_MODE_BITMAP)
- {
- packingModifier = 0;
-
- Material tmp_material = new Material(ShaderUtilities.ShaderRef_MobileBitmap);
-
- tmp_material.SetTexture(ShaderUtilities.ID_MainTex, texture);
- tmp_material.SetFloat(ShaderUtilities.ID_TextureWidth, atlasWidth);
- tmp_material.SetFloat(ShaderUtilities.ID_TextureHeight, atlasHeight);
- fontAsset.material = tmp_material;
- }
- else
- {
- packingModifier = 1;
-
- Material tmp_material = new Material(ShaderUtilities.ShaderRef_MobileSDF);
-
- tmp_material.SetTexture(ShaderUtilities.ID_MainTex, texture);
- tmp_material.SetFloat(ShaderUtilities.ID_TextureWidth, atlasWidth);
- tmp_material.SetFloat(ShaderUtilities.ID_TextureHeight, atlasHeight);
- tmp_material.SetFloat(ShaderUtilities.ID_GradientScale, atlasPadding + packingModifier);
- tmp_material.SetFloat(ShaderUtilities.ID_WeightNormal, fontAsset.normalStyle);
- tmp_material.SetFloat(ShaderUtilities.ID_WeightBold, fontAsset.boldStyle);
- fontAsset.material = tmp_material;
- }
- fontAsset.freeGlyphRects = new List<GlyphRect>(8) { new GlyphRect(0, 0, atlasWidth - packingModifier, atlasHeight - packingModifier) };
- fontAsset.usedGlyphRects = new List<GlyphRect>(8);
-
- fontAsset.ReadFontAssetDefinition();
- return fontAsset;
- }
- void Awake()
- {
-
- if (this.material != null && string.IsNullOrEmpty(m_Version))
- UpgradeFontAsset();
- }
- #if UNITY_EDITOR
- private void OnValidate()
- {
-
- if (m_CharacterLookupDictionary == null || m_GlyphLookupDictionary == null)
- ReadFontAssetDefinition();
- }
- #endif
- private static string s_DefaultMaterialSuffix = " Atlas Material";
- public void ReadFontAssetDefinition()
- {
- k_ReadFontAssetDefinitionMarker.Begin();
-
-
- if (this.material != null && string.IsNullOrEmpty(m_Version))
- UpgradeFontAsset();
-
- InitializeDictionaryLookupTables();
-
- AddSynthesizedCharactersAndFaceMetrics();
-
- if (m_FaceInfo.scale == 0)
- m_FaceInfo.scale = 1.0f;
-
- if (m_FaceInfo.strikethroughOffset == 0)
- m_FaceInfo.strikethroughOffset = m_FaceInfo.capLine / 2.5f;
-
- if (m_AtlasPadding == 0)
- {
- if (material.HasProperty(ShaderUtilities.ID_GradientScale))
- m_AtlasPadding = (int)material.GetFloat(ShaderUtilities.ID_GradientScale) - 1;
- }
-
- hashCode = TMP_TextUtilities.GetSimpleHashCode(this.name);
-
- materialHashCode = TMP_TextUtilities.GetSimpleHashCode(this.name + s_DefaultMaterialSuffix);
-
-
- IsFontAssetLookupTablesDirty = false;
- k_ReadFontAssetDefinitionMarker.End();
- }
-
-
-
- internal void InitializeDictionaryLookupTables()
- {
-
- InitializeGlyphLookupDictionary();
-
- InitializeCharacterLookupDictionary();
-
- InitializeGlyphPaidAdjustmentRecordsLookupDictionary();
- }
- internal void InitializeGlyphLookupDictionary()
- {
-
- if (m_GlyphLookupDictionary == null)
- m_GlyphLookupDictionary = new Dictionary<uint, Glyph>();
- else
- m_GlyphLookupDictionary.Clear();
-
- if (m_GlyphIndexList == null)
- m_GlyphIndexList = new List<uint>();
- else
- m_GlyphIndexList.Clear();
-
- if (m_GlyphIndexListNewlyAdded == null)
- m_GlyphIndexListNewlyAdded = new List<uint>();
- else
- m_GlyphIndexListNewlyAdded.Clear();
-
- int glyphCount = m_GlyphTable.Count;
-
- for (int i = 0; i < glyphCount; i++)
- {
- Glyph glyph = m_GlyphTable[i];
- uint index = glyph.index;
-
- if (m_GlyphLookupDictionary.ContainsKey(index) == false)
- {
- m_GlyphLookupDictionary.Add(index, glyph);
- m_GlyphIndexList.Add(index);
- }
- }
- }
- internal void InitializeCharacterLookupDictionary()
- {
-
- if (m_CharacterLookupDictionary == null)
- m_CharacterLookupDictionary = new Dictionary<uint, TMP_Character>();
- else
- m_CharacterLookupDictionary.Clear();
-
- for (int i = 0; i < m_CharacterTable.Count; i++)
- {
- TMP_Character character = m_CharacterTable[i];
- uint unicode = character.unicode;
- uint glyphIndex = character.glyphIndex;
-
- if (m_CharacterLookupDictionary.ContainsKey(unicode) == false)
- {
- m_CharacterLookupDictionary.Add(unicode, character);
- character.textAsset = this;
- character.glyph = m_GlyphLookupDictionary[glyphIndex];
- }
- }
-
- if (FallbackSearchQueryLookup == null)
- FallbackSearchQueryLookup = new HashSet<int>();
- else
- FallbackSearchQueryLookup.Clear();
- }
- internal void InitializeGlyphPaidAdjustmentRecordsLookupDictionary()
- {
-
- if (m_KerningTable != null && m_KerningTable.kerningPairs != null && m_KerningTable.kerningPairs.Count > 0)
- UpgradeGlyphAdjustmentTableToFontFeatureTable();
-
- if (m_FontFeatureTable.m_GlyphPairAdjustmentRecordLookupDictionary == null)
- m_FontFeatureTable.m_GlyphPairAdjustmentRecordLookupDictionary = new Dictionary<uint, TMP_GlyphPairAdjustmentRecord>();
- else
- m_FontFeatureTable.m_GlyphPairAdjustmentRecordLookupDictionary.Clear();
- List<TMP_GlyphPairAdjustmentRecord> glyphPairAdjustmentRecords = m_FontFeatureTable.m_GlyphPairAdjustmentRecords;
- if (glyphPairAdjustmentRecords != null)
- {
- for (int i = 0; i < glyphPairAdjustmentRecords.Count; i++)
- {
- TMP_GlyphPairAdjustmentRecord record = glyphPairAdjustmentRecords[i];
- uint key = new GlyphPairKey(record).key;
- if (!m_FontFeatureTable.m_GlyphPairAdjustmentRecordLookupDictionary.ContainsKey(key))
- m_FontFeatureTable.m_GlyphPairAdjustmentRecordLookupDictionary.Add(key, record);
- }
- }
- }
- internal void AddSynthesizedCharactersAndFaceMetrics()
- {
- k_AddSynthesizedCharactersMarker.Begin();
- bool isFontFaceLoaded = false;
- if (m_AtlasPopulationMode == AtlasPopulationMode.Dynamic)
- isFontFaceLoaded = FontEngine.LoadFontFace(sourceFontFile, m_FaceInfo.pointSize) == FontEngineError.Success;
-
-
-
- AddSynthesizedCharacter(0x03, isFontFaceLoaded, true);
-
- AddSynthesizedCharacter(0x09, isFontFaceLoaded, true);
-
- AddSynthesizedCharacter(0x0A, isFontFaceLoaded);
-
- AddSynthesizedCharacter(0x0B, isFontFaceLoaded);
-
- AddSynthesizedCharacter(0x0D, isFontFaceLoaded);
-
- AddSynthesizedCharacter(0x061C, isFontFaceLoaded);
-
- AddSynthesizedCharacter(0x200B, isFontFaceLoaded);
-
- AddSynthesizedCharacter(0x200E, isFontFaceLoaded);
-
- AddSynthesizedCharacter(0x200F, isFontFaceLoaded);
-
- AddSynthesizedCharacter(0x2028, isFontFaceLoaded);
-
- AddSynthesizedCharacter(0x2029, isFontFaceLoaded);
-
- AddSynthesizedCharacter(0x2060, isFontFaceLoaded);
-
- if (m_FaceInfo.capLine == 0 && m_CharacterLookupDictionary.ContainsKey('X'))
- {
- uint glyphIndex = m_CharacterLookupDictionary['X'].glyphIndex;
- m_FaceInfo.capLine = m_GlyphLookupDictionary[glyphIndex].metrics.horizontalBearingY;
- }
-
- if (m_FaceInfo.meanLine == 0 && m_CharacterLookupDictionary.ContainsKey('x'))
- {
- uint glyphIndex = m_CharacterLookupDictionary['x'].glyphIndex;
- m_FaceInfo.meanLine = m_GlyphLookupDictionary[glyphIndex].metrics.horizontalBearingY;
- }
- k_AddSynthesizedCharactersMarker.End();
- }
- void AddSynthesizedCharacter(uint unicode, bool isFontFaceLoaded, bool addImmediately = false)
- {
-
- if (m_CharacterLookupDictionary.ContainsKey(unicode))
- return;
- Glyph glyph;
- if (isFontFaceLoaded)
- {
-
- if (FontEngine.GetGlyphIndex(unicode) != 0)
- {
- if (addImmediately == false)
- return;
-
- GlyphLoadFlags glyphLoadFlags = ((GlyphRasterModes)m_AtlasRenderMode & GlyphRasterModes.RASTER_MODE_NO_HINTING) == GlyphRasterModes.RASTER_MODE_NO_HINTING
- ? GlyphLoadFlags.LOAD_NO_BITMAP | GlyphLoadFlags.LOAD_NO_HINTING
- : GlyphLoadFlags.LOAD_NO_BITMAP;
- if (FontEngine.TryGetGlyphWithUnicodeValue(unicode, glyphLoadFlags, out glyph))
- m_CharacterLookupDictionary.Add(unicode, new TMP_Character(unicode, this, glyph));
- return;
- }
- }
-
-
- glyph = new Glyph(0, new GlyphMetrics(0, 0, 0, 0, 0), GlyphRect.zero, 1.0f, 0);
- m_CharacterLookupDictionary.Add(unicode, new TMP_Character(unicode, this, glyph));
- }
- internal HashSet<int> FallbackSearchQueryLookup = new HashSet<int>();
- internal void AddCharacterToLookupCache(uint unicode, TMP_Character character)
- {
- m_CharacterLookupDictionary.Add(unicode, character);
-
- FallbackSearchQueryLookup.Add(character.textAsset.instanceID);
- }
-
-
-
- internal void SortCharacterTable()
- {
- if (m_CharacterTable != null && m_CharacterTable.Count > 0)
- m_CharacterTable = m_CharacterTable.OrderBy(c => c.unicode).ToList();
- }
-
-
-
- internal void SortGlyphTable()
- {
- if (m_GlyphTable != null && m_GlyphTable.Count > 0)
- m_GlyphTable = m_GlyphTable.OrderBy(c => c.index).ToList();
- }
- internal void SortFontFeatureTable()
- {
- m_FontFeatureTable.SortGlyphPairAdjustmentRecords();
- }
-
-
-
- internal void SortAllTables()
- {
- SortGlyphTable();
- SortCharacterTable();
- SortFontFeatureTable();
- }
-
-
-
- private static HashSet<int> k_SearchedFontAssetLookup;
-
-
-
-
-
- public bool HasCharacter(int character)
- {
- if (m_CharacterLookupDictionary == null)
- return false;
- return m_CharacterLookupDictionary.ContainsKey((uint)character);
- }
-
-
-
-
-
-
-
- public bool HasCharacter(char character, bool searchFallbacks = false, bool tryAddCharacter = false)
- {
-
- if (m_CharacterLookupDictionary == null)
- {
- ReadFontAssetDefinition();
- if (m_CharacterLookupDictionary == null)
- return false;
- }
-
- if (m_CharacterLookupDictionary.ContainsKey(character))
- return true;
-
- if (tryAddCharacter && m_AtlasPopulationMode == AtlasPopulationMode.Dynamic)
- {
- TMP_Character returnedCharacter;
- if (TryAddCharacterInternal(character, out returnedCharacter))
- return true;
- }
- if (searchFallbacks)
- {
-
- if (k_SearchedFontAssetLookup == null)
- k_SearchedFontAssetLookup = new HashSet<int>();
- else
- k_SearchedFontAssetLookup.Clear();
-
- k_SearchedFontAssetLookup.Add(GetInstanceID());
-
- if (fallbackFontAssetTable != null && fallbackFontAssetTable.Count > 0)
- {
- for (int i = 0; i < fallbackFontAssetTable.Count && fallbackFontAssetTable[i] != null; i++)
- {
- TMP_FontAsset fallback = fallbackFontAssetTable[i];
- int fallbackID = fallback.GetInstanceID();
-
- if (k_SearchedFontAssetLookup.Add(fallbackID))
- {
- if (fallback.HasCharacter_Internal(character, true, tryAddCharacter))
- return true;
- }
- }
- }
-
- if (TMP_Settings.fallbackFontAssets != null && TMP_Settings.fallbackFontAssets.Count > 0)
- {
- for (int i = 0; i < TMP_Settings.fallbackFontAssets.Count && TMP_Settings.fallbackFontAssets[i] != null; i++)
- {
- TMP_FontAsset fallback = TMP_Settings.fallbackFontAssets[i];
- int fallbackID = fallback.GetInstanceID();
-
- if (k_SearchedFontAssetLookup.Add(fallbackID))
- {
- if (fallback.HasCharacter_Internal(character, true, tryAddCharacter))
- return true;
- }
- }
- }
-
- if (TMP_Settings.defaultFontAsset != null)
- {
- TMP_FontAsset fallback = TMP_Settings.defaultFontAsset;
- int fallbackID = fallback.GetInstanceID();
-
- if (k_SearchedFontAssetLookup.Add(fallbackID))
- {
- if (fallback.HasCharacter_Internal(character, true, tryAddCharacter))
- return true;
- }
- }
- }
- return false;
- }
-
-
-
-
-
-
-
-
- bool HasCharacter_Internal(uint character, bool searchFallbacks = false, bool tryAddCharacter = false)
- {
-
- if (m_CharacterLookupDictionary == null)
- {
- ReadFontAssetDefinition();
- if (m_CharacterLookupDictionary == null)
- return false;
- }
-
- if (m_CharacterLookupDictionary.ContainsKey(character))
- return true;
-
- if (tryAddCharacter && atlasPopulationMode == AtlasPopulationMode.Dynamic)
- {
- TMP_Character returnedCharacter;
- if (TryAddCharacterInternal(character, out returnedCharacter))
- return true;
- }
- if (searchFallbacks)
- {
-
- if (fallbackFontAssetTable == null || fallbackFontAssetTable.Count == 0)
- return false;
- for (int i = 0; i < fallbackFontAssetTable.Count && fallbackFontAssetTable[i] != null; i++)
- {
- TMP_FontAsset fallback = fallbackFontAssetTable[i];
- int fallbackID = fallback.GetInstanceID();
-
- if (k_SearchedFontAssetLookup.Add(fallbackID))
- {
- if (fallback.HasCharacter_Internal(character, true, tryAddCharacter))
- return true;
- }
- }
- }
- return false;
- }
-
-
-
-
-
-
- public bool HasCharacters(string text, out List<char> missingCharacters)
- {
- if (m_CharacterLookupDictionary == null)
- {
- missingCharacters = null;
- return false;
- }
- missingCharacters = new List<char>();
- for (int i = 0; i < text.Length; i++)
- {
- if (!m_CharacterLookupDictionary.ContainsKey(text[i]))
- missingCharacters.Add(text[i]);
- }
- if (missingCharacters.Count == 0)
- return true;
- return false;
- }
-
-
-
-
-
-
-
-
- public bool HasCharacters(string text, out uint[] missingCharacters, bool searchFallbacks = false, bool tryAddCharacter = false)
- {
- missingCharacters = null;
-
- if (m_CharacterLookupDictionary == null)
- {
- ReadFontAssetDefinition();
- if (m_CharacterLookupDictionary == null)
- return false;
- }
-
- s_MissingCharacterList.Clear();
- for (int i = 0; i < text.Length; i++)
- {
- bool isMissingCharacter = true;
- uint character = text[i];
- if (m_CharacterLookupDictionary.ContainsKey(character))
- continue;
-
- if (tryAddCharacter && atlasPopulationMode == AtlasPopulationMode.Dynamic)
- {
- TMP_Character returnedCharacter;
- if (TryAddCharacterInternal(character, out returnedCharacter))
- continue;
- }
- if (searchFallbacks)
- {
-
- if (k_SearchedFontAssetLookup == null)
- k_SearchedFontAssetLookup = new HashSet<int>();
- else
- k_SearchedFontAssetLookup.Clear();
-
- k_SearchedFontAssetLookup.Add(GetInstanceID());
-
- if (fallbackFontAssetTable != null && fallbackFontAssetTable.Count > 0)
- {
- for (int j = 0; j < fallbackFontAssetTable.Count && fallbackFontAssetTable[j] != null; j++)
- {
- TMP_FontAsset fallback = fallbackFontAssetTable[j];
- int fallbackID = fallback.GetInstanceID();
-
- if (k_SearchedFontAssetLookup.Add(fallbackID))
- {
- if (fallback.HasCharacter_Internal(character, true, tryAddCharacter) == false)
- continue;
- isMissingCharacter = false;
- break;
- }
- }
- }
-
- if (isMissingCharacter && TMP_Settings.fallbackFontAssets != null && TMP_Settings.fallbackFontAssets.Count > 0)
- {
- for (int j = 0; j < TMP_Settings.fallbackFontAssets.Count && TMP_Settings.fallbackFontAssets[j] != null; j++)
- {
- TMP_FontAsset fallback = TMP_Settings.fallbackFontAssets[j];
- int fallbackID = fallback.GetInstanceID();
-
- if (k_SearchedFontAssetLookup.Add(fallbackID))
- {
- if (fallback.HasCharacter_Internal(character, true, tryAddCharacter) == false)
- continue;
- isMissingCharacter = false;
- break;
- }
- }
- }
-
- if (isMissingCharacter && TMP_Settings.defaultFontAsset != null)
- {
- TMP_FontAsset fallback = TMP_Settings.defaultFontAsset;
- int fallbackID = fallback.GetInstanceID();
-
- if (k_SearchedFontAssetLookup.Add(fallbackID))
- {
- if (fallback.HasCharacter_Internal(character, true, tryAddCharacter))
- isMissingCharacter = false;
- }
- }
- }
- if (isMissingCharacter)
- s_MissingCharacterList.Add(character);
- }
- if (s_MissingCharacterList.Count > 0)
- {
- missingCharacters = s_MissingCharacterList.ToArray();
- return false;
- }
- return true;
- }
-
-
-
-
-
- public bool HasCharacters(string text)
- {
- if (m_CharacterLookupDictionary == null)
- return false;
- for (int i = 0; i < text.Length; i++)
- {
- if (!m_CharacterLookupDictionary.ContainsKey(text[i]))
- return false;
- }
- return true;
- }
-
-
-
-
-
- public static string GetCharacters(TMP_FontAsset fontAsset)
- {
- string characters = string.Empty;
- for (int i = 0; i < fontAsset.characterTable.Count; i++)
- {
- characters += (char)fontAsset.characterTable[i].unicode;
- }
- return characters;
- }
-
-
-
-
-
- public static int[] GetCharactersArray(TMP_FontAsset fontAsset)
- {
- int[] characters = new int[fontAsset.characterTable.Count];
- for (int i = 0; i < fontAsset.characterTable.Count; i++)
- {
- characters[i] = (int)fontAsset.characterTable[i].unicode;
- }
- return characters;
- }
-
-
-
-
-
- internal uint GetGlyphIndex(uint unicode)
- {
-
- if (m_CharacterLookupDictionary.ContainsKey(unicode))
- return m_CharacterLookupDictionary[unicode].glyphIndex;
-
- if (FontEngine.LoadFontFace(sourceFontFile, m_FaceInfo.pointSize) != FontEngineError.Success)
- return 0;
- return FontEngine.GetGlyphIndex(unicode);
- }
-
-
-
-
-
- private static List<TMP_FontAsset> k_FontAssets_FontFeaturesUpdateQueue = new List<TMP_FontAsset>();
- private static HashSet<int> k_FontAssets_FontFeaturesUpdateQueueLookup = new HashSet<int>();
- private static List<TMP_FontAsset> k_FontAssets_AtlasTexturesUpdateQueue = new List<TMP_FontAsset>();
- private static HashSet<int> k_FontAssets_AtlasTexturesUpdateQueueLookup = new HashSet<int>();
-
-
-
-
- internal static void RegisterFontAssetForFontFeatureUpdate(TMP_FontAsset fontAsset)
- {
- int instanceID = fontAsset.instanceID;
- if (k_FontAssets_FontFeaturesUpdateQueueLookup.Add(instanceID))
- k_FontAssets_FontFeaturesUpdateQueue.Add(fontAsset);
- }
-
-
-
-
- internal static void UpdateFontFeaturesForFontAssetsInQueue()
- {
- int count = k_FontAssets_FontFeaturesUpdateQueue.Count;
- for (int i = 0; i < count; i++)
- k_FontAssets_FontFeaturesUpdateQueue[i].UpdateGlyphAdjustmentRecords();
- if (count > 0)
- {
- k_FontAssets_FontFeaturesUpdateQueue.Clear();
- k_FontAssets_FontFeaturesUpdateQueueLookup.Clear();
- }
- }
-
-
-
-
- internal static void RegisterFontAssetForAtlasTextureUpdate(TMP_FontAsset fontAsset)
- {
- int instanceID = fontAsset.instanceID;
- if (k_FontAssets_AtlasTexturesUpdateQueueLookup.Add(instanceID))
- k_FontAssets_AtlasTexturesUpdateQueue.Add(fontAsset);
- }
-
-
-
- internal static void UpdateAtlasTexturesForFontAssetsInQueue()
- {
- int count = k_FontAssets_AtlasTexturesUpdateQueueLookup.Count;
- for (int i = 0; i < count; i++)
- k_FontAssets_AtlasTexturesUpdateQueue[i].TryAddGlyphsToAtlasTextures();
- if (count > 0)
- {
- k_FontAssets_AtlasTexturesUpdateQueue.Clear();
- k_FontAssets_AtlasTexturesUpdateQueueLookup.Clear();
- }
- }
-
-
-
-
-
-
-
- private List<Glyph> m_GlyphsToRender = new List<Glyph>();
-
-
-
- private List<Glyph> m_GlyphsRendered = new List<Glyph>();
-
-
-
- private List<uint> m_GlyphIndexList = new List<uint>();
-
-
-
-
- private List<uint> m_GlyphIndexListNewlyAdded = new List<uint>();
-
-
-
- internal List<uint> m_GlyphsToAdd = new List<uint>();
- internal HashSet<uint> m_GlyphsToAddLookup = new HashSet<uint>();
- internal List<TMP_Character> m_CharactersToAdd = new List<TMP_Character>();
- internal HashSet<uint> m_CharactersToAddLookup = new HashSet<uint>();
-
-
-
- internal List<uint> s_MissingCharacterList = new List<uint>();
-
-
-
- internal HashSet<uint> m_MissingUnicodesFromFontFile = new HashSet<uint>();
-
-
-
- internal static uint[] k_GlyphIndexArray;
-
-
-
-
-
-
- public bool TryAddCharacters(uint[] unicodes, bool includeFontFeatures = false)
- {
- uint[] missingUnicodes;
- return TryAddCharacters(unicodes, out missingUnicodes, includeFontFeatures);
- }
-
-
-
-
-
-
-
- public bool TryAddCharacters(uint[] unicodes, out uint[] missingUnicodes, bool includeFontFeatures = false)
- {
- k_TryAddCharactersMarker.Begin();
-
- if (unicodes == null || unicodes.Length == 0 || m_AtlasPopulationMode == AtlasPopulationMode.Static)
- {
- if (m_AtlasPopulationMode == AtlasPopulationMode.Static)
- Debug.LogWarning("Unable to add characters to font asset [" + this.name + "] because its AtlasPopulationMode is set to Static.", this);
- else
- Debug.LogWarning("Unable to add characters to font asset [" + this.name + "] because the provided Unicode list is Null or Empty.", this);
- missingUnicodes = null;
- k_TryAddCharactersMarker.End();
- return false;
- }
-
- if (FontEngine.LoadFontFace(m_SourceFontFile, m_FaceInfo.pointSize) != FontEngineError.Success)
- {
- missingUnicodes = unicodes.ToArray();
- k_TryAddCharactersMarker.End();
- return false;
- }
-
- if (m_CharacterLookupDictionary == null || m_GlyphLookupDictionary == null)
- ReadFontAssetDefinition();
-
- m_GlyphsToAdd.Clear();
- m_GlyphsToAddLookup.Clear();
- m_CharactersToAdd.Clear();
- m_CharactersToAddLookup.Clear();
- s_MissingCharacterList.Clear();
- bool isMissingCharacters = false;
- int unicodeCount = unicodes.Length;
- for (int i = 0; i < unicodeCount; i++)
- {
- uint unicode = unicodes[i];
-
- if (m_CharacterLookupDictionary.ContainsKey(unicode))
- continue;
-
- uint glyphIndex = FontEngine.GetGlyphIndex(unicode);
-
- if (glyphIndex == 0)
- {
-
- switch (unicode)
- {
- case 0xA0:
-
- glyphIndex = FontEngine.GetGlyphIndex(0x20);
- break;
- case 0xAD:
- case 0x2011:
-
- glyphIndex = FontEngine.GetGlyphIndex(0x2D);
- break;
- }
-
- if (glyphIndex == 0)
- {
-
- s_MissingCharacterList.Add(unicode);
- isMissingCharacters = true;
- continue;
- }
- }
- TMP_Character character = new TMP_Character(unicode, glyphIndex);
-
- if (m_GlyphLookupDictionary.ContainsKey(glyphIndex))
- {
-
- character.glyph = m_GlyphLookupDictionary[glyphIndex];
- character.textAsset = this;
- m_CharacterTable.Add(character);
- m_CharacterLookupDictionary.Add(unicode, character);
- continue;
- }
-
- if (m_GlyphsToAddLookup.Add(glyphIndex))
- m_GlyphsToAdd.Add(glyphIndex);
-
- if (m_CharactersToAddLookup.Add(unicode))
- m_CharactersToAdd.Add(character);
- }
- if (m_GlyphsToAdd.Count == 0)
- {
-
- missingUnicodes = unicodes;
- k_TryAddCharactersMarker.End();
- return false;
- }
-
- if (m_AtlasTextures[m_AtlasTextureIndex].width == 0 || m_AtlasTextures[m_AtlasTextureIndex].height == 0)
- {
- m_AtlasTextures[m_AtlasTextureIndex].Resize(m_AtlasWidth, m_AtlasHeight);
- FontEngine.ResetAtlasTexture(m_AtlasTextures[m_AtlasTextureIndex]);
- }
- Glyph[] glyphs;
- bool allGlyphsAddedToTexture = FontEngine.TryAddGlyphsToTexture(m_GlyphsToAdd, m_AtlasPadding, GlyphPackingMode.BestShortSideFit, m_FreeGlyphRects, m_UsedGlyphRects, m_AtlasRenderMode, m_AtlasTextures[m_AtlasTextureIndex], out glyphs);
-
- for (int i = 0; i < glyphs.Length && glyphs[i] != null; i++)
- {
- Glyph glyph = glyphs[i];
- uint glyphIndex = glyph.index;
- glyph.atlasIndex = m_AtlasTextureIndex;
-
- m_GlyphTable.Add(glyph);
- m_GlyphLookupDictionary.Add(glyphIndex, glyph);
- m_GlyphIndexListNewlyAdded.Add(glyphIndex);
- m_GlyphIndexList.Add(glyphIndex);
- }
-
- m_GlyphsToAdd.Clear();
-
- for (int i = 0; i < m_CharactersToAdd.Count; i++)
- {
- TMP_Character character = m_CharactersToAdd[i];
- Glyph glyph;
- if (m_GlyphLookupDictionary.TryGetValue(character.glyphIndex, out glyph) == false)
- {
- m_GlyphsToAdd.Add(character.glyphIndex);
- continue;
- }
-
- character.glyph = glyph;
- character.textAsset = this;
- m_CharacterTable.Add(character);
- m_CharacterLookupDictionary.Add(character.unicode, character);
-
- m_CharactersToAdd.RemoveAt(i);
- i -= 1;
- }
-
- if (m_IsMultiAtlasTexturesEnabled && allGlyphsAddedToTexture == false)
- {
- while (allGlyphsAddedToTexture == false)
- allGlyphsAddedToTexture = TryAddGlyphsToNewAtlasTexture();
- }
-
- if (includeFontFeatures)
- UpdateGlyphAdjustmentRecords();
- #if UNITY_EDITOR
-
- if (UnityEditor.EditorUtility.IsPersistent(this))
- {
- TMP_EditorResourceManager.RegisterResourceForUpdate(this);
- }
- #endif
-
- for (int i = 0; i < m_CharactersToAdd.Count; i++)
- {
- TMP_Character character = m_CharactersToAdd[i];
- s_MissingCharacterList.Add(character.unicode);
- }
- missingUnicodes = null;
- if (s_MissingCharacterList.Count > 0)
- missingUnicodes = s_MissingCharacterList.ToArray();
- k_TryAddCharactersMarker.End();
- return allGlyphsAddedToTexture && !isMissingCharacters;
- }
-
-
-
-
-
-
- public bool TryAddCharacters(string characters, bool includeFontFeatures = false)
- {
- string missingCharacters;
- return TryAddCharacters(characters, out missingCharacters, includeFontFeatures);
- }
-
-
-
-
-
-
-
- public bool TryAddCharacters(string characters, out string missingCharacters, bool includeFontFeatures = false)
- {
- k_TryAddCharactersMarker.Begin();
-
- if (string.IsNullOrEmpty(characters) || m_AtlasPopulationMode == AtlasPopulationMode.Static)
- {
- if (m_AtlasPopulationMode == AtlasPopulationMode.Static)
- Debug.LogWarning("Unable to add characters to font asset [" + this.name + "] because its AtlasPopulationMode is set to Static.", this);
- else
- {
- Debug.LogWarning("Unable to add characters to font asset [" + this.name + "] because the provided character list is Null or Empty.", this);
- }
- missingCharacters = characters;
- k_TryAddCharactersMarker.End();
- return false;
- }
-
- if (FontEngine.LoadFontFace(m_SourceFontFile, m_FaceInfo.pointSize) != FontEngineError.Success)
- {
- missingCharacters = characters;
- k_TryAddCharactersMarker.End();
- return false;
- }
-
- if (m_CharacterLookupDictionary == null || m_GlyphLookupDictionary == null)
- ReadFontAssetDefinition();
-
- m_GlyphsToAdd.Clear();
- m_GlyphsToAddLookup.Clear();
- m_CharactersToAdd.Clear();
- m_CharactersToAddLookup.Clear();
- s_MissingCharacterList.Clear();
- bool isMissingCharacters = false;
- int characterCount = characters.Length;
-
- for (int i = 0; i < characterCount; i++)
- {
- uint unicode = characters[i];
-
- if (m_CharacterLookupDictionary.ContainsKey(unicode))
- continue;
-
- uint glyphIndex = FontEngine.GetGlyphIndex(unicode);
-
- if (glyphIndex == 0)
- {
-
- switch (unicode)
- {
- case 0xA0:
-
- glyphIndex = FontEngine.GetGlyphIndex(0x20);
- break;
- case 0xAD:
- case 0x2011:
-
- glyphIndex = FontEngine.GetGlyphIndex(0x2D);
- break;
- }
-
- if (glyphIndex == 0)
- {
-
- s_MissingCharacterList.Add(unicode);
- isMissingCharacters = true;
- continue;
- }
- }
- TMP_Character character = new TMP_Character(unicode, glyphIndex);
-
- if (m_GlyphLookupDictionary.ContainsKey(glyphIndex))
- {
-
- character.glyph = m_GlyphLookupDictionary[glyphIndex];
- character.textAsset = this;
- m_CharacterTable.Add(character);
- m_CharacterLookupDictionary.Add(unicode, character);
- continue;
- }
-
- if (m_GlyphsToAddLookup.Add(glyphIndex))
- m_GlyphsToAdd.Add(glyphIndex);
-
- if (m_CharactersToAddLookup.Add(unicode))
- m_CharactersToAdd.Add(character);
- }
- if (m_GlyphsToAdd.Count == 0)
- {
- missingCharacters = characters;
- k_TryAddCharactersMarker.End();
- return false;
- }
-
- if (m_AtlasTextures[m_AtlasTextureIndex].width == 0 || m_AtlasTextures[m_AtlasTextureIndex].height == 0)
- {
-
- m_AtlasTextures[m_AtlasTextureIndex].Resize(m_AtlasWidth, m_AtlasHeight);
- FontEngine.ResetAtlasTexture(m_AtlasTextures[m_AtlasTextureIndex]);
- }
- Glyph[] glyphs;
- bool allGlyphsAddedToTexture = FontEngine.TryAddGlyphsToTexture(m_GlyphsToAdd, m_AtlasPadding, GlyphPackingMode.BestShortSideFit, m_FreeGlyphRects, m_UsedGlyphRects, m_AtlasRenderMode, m_AtlasTextures[m_AtlasTextureIndex], out glyphs);
- for (int i = 0; i < glyphs.Length && glyphs[i] != null; i++)
- {
- Glyph glyph = glyphs[i];
- uint glyphIndex = glyph.index;
- glyph.atlasIndex = m_AtlasTextureIndex;
-
- m_GlyphTable.Add(glyph);
- m_GlyphLookupDictionary.Add(glyphIndex, glyph);
- m_GlyphIndexListNewlyAdded.Add(glyphIndex);
- m_GlyphIndexList.Add(glyphIndex);
- }
-
- m_GlyphsToAdd.Clear();
-
- for (int i = 0; i < m_CharactersToAdd.Count; i++)
- {
- TMP_Character character = m_CharactersToAdd[i];
- Glyph glyph;
- if (m_GlyphLookupDictionary.TryGetValue(character.glyphIndex, out glyph) == false)
- {
- m_GlyphsToAdd.Add(character.glyphIndex);
- continue;
- }
-
- character.glyph = glyph;
- character.textAsset = this;
- m_CharacterTable.Add(character);
- m_CharacterLookupDictionary.Add(character.unicode, character);
-
- m_CharactersToAdd.RemoveAt(i);
- i -= 1;
- }
-
- if (m_IsMultiAtlasTexturesEnabled && allGlyphsAddedToTexture == false)
- {
- while (allGlyphsAddedToTexture == false)
- allGlyphsAddedToTexture = TryAddGlyphsToNewAtlasTexture();
- }
-
- if (includeFontFeatures)
- UpdateGlyphAdjustmentRecords();
- #if UNITY_EDITOR
-
- if (UnityEditor.EditorUtility.IsPersistent(this))
- {
- TMP_EditorResourceManager.RegisterResourceForUpdate(this);
- }
- #endif
- missingCharacters = string.Empty;
-
- for (int i = 0; i < m_CharactersToAdd.Count; i++)
- {
- TMP_Character character = m_CharactersToAdd[i];
- s_MissingCharacterList.Add(character.unicode);
- }
- if (s_MissingCharacterList.Count > 0)
- missingCharacters = s_MissingCharacterList.UintToString();
- k_TryAddCharactersMarker.End();
- return allGlyphsAddedToTexture && !isMissingCharacters;
- }
-
-
-
-
-
-
-
-
-
- internal bool TryAddCharacterInternal(uint unicode, out TMP_Character character)
- {
- k_TryAddCharacterMarker.Begin();
- character = null;
-
- if (m_MissingUnicodesFromFontFile.Contains(unicode))
- {
- k_TryAddCharacterMarker.End();
- return false;
- }
-
- if (FontEngine.LoadFontFace(sourceFontFile, m_FaceInfo.pointSize) != FontEngineError.Success)
- {
- k_TryAddCharacterMarker.End();
- return false;
- }
- uint glyphIndex = FontEngine.GetGlyphIndex(unicode);
- if (glyphIndex == 0)
- {
-
- switch (unicode)
- {
- case 0xA0:
-
- glyphIndex = FontEngine.GetGlyphIndex(0x20);
- break;
- case 0xAD:
- case 0x2011:
-
- glyphIndex = FontEngine.GetGlyphIndex(0x2D);
- break;
- }
-
- if (glyphIndex == 0)
- {
- m_MissingUnicodesFromFontFile.Add(unicode);
- k_TryAddCharacterMarker.End();
- return false;
- }
- }
-
- if (m_GlyphLookupDictionary.ContainsKey(glyphIndex))
- {
- character = new TMP_Character(unicode, this, m_GlyphLookupDictionary[glyphIndex]);
- m_CharacterTable.Add(character);
- m_CharacterLookupDictionary.Add(unicode, character);
- #if UNITY_EDITOR
-
-
-
-
- if (UnityEditor.EditorUtility.IsPersistent(this))
- {
- TMP_EditorResourceManager.RegisterResourceForUpdate(this);
- }
- #endif
- k_TryAddCharacterMarker.End();
- return true;
- }
- Glyph glyph = null;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if (m_AtlasTextures[m_AtlasTextureIndex].isReadable == false)
- {
- Debug.LogWarning("Unable to add the requested character to font asset [" + this.name + "]'s atlas texture. Please make the texture [" + m_AtlasTextures[m_AtlasTextureIndex].name + "] readable.", m_AtlasTextures[m_AtlasTextureIndex]);
- k_TryAddCharacterMarker.End();
- return false;
- }
-
- if (m_AtlasTextures[m_AtlasTextureIndex].width == 0 || m_AtlasTextures[m_AtlasTextureIndex].height == 0)
- {
- m_AtlasTextures[m_AtlasTextureIndex].Resize(m_AtlasWidth, m_AtlasHeight);
- FontEngine.ResetAtlasTexture(m_AtlasTextures[m_AtlasTextureIndex]);
- }
-
- if (FontEngine.TryAddGlyphToTexture(glyphIndex, m_AtlasPadding, GlyphPackingMode.BestShortSideFit, m_FreeGlyphRects, m_UsedGlyphRects, m_AtlasRenderMode, m_AtlasTextures[m_AtlasTextureIndex], out glyph))
- {
-
- glyph.atlasIndex = m_AtlasTextureIndex;
-
- m_GlyphTable.Add(glyph);
- m_GlyphLookupDictionary.Add(glyphIndex, glyph);
-
- character = new TMP_Character(unicode, this, glyph);
- m_CharacterTable.Add(character);
- m_CharacterLookupDictionary.Add(unicode, character);
- m_GlyphIndexList.Add(glyphIndex);
- m_GlyphIndexListNewlyAdded.Add(glyphIndex);
- if (TMP_Settings.getFontFeaturesAtRuntime)
- RegisterFontAssetForFontFeatureUpdate(this);
- #if UNITY_EDITOR
-
-
-
-
- if (UnityEditor.EditorUtility.IsPersistent(this))
- {
- TMP_EditorResourceManager.RegisterResourceForUpdate(this);
- }
- #endif
- k_TryAddCharacterMarker.End();
- return true;
- }
-
- if (m_IsMultiAtlasTexturesEnabled)
- {
-
- SetupNewAtlasTexture();
-
- if (FontEngine.TryAddGlyphToTexture(glyphIndex, m_AtlasPadding, GlyphPackingMode.BestShortSideFit, m_FreeGlyphRects, m_UsedGlyphRects, m_AtlasRenderMode, m_AtlasTextures[m_AtlasTextureIndex], out glyph))
- {
-
- glyph.atlasIndex = m_AtlasTextureIndex;
-
- m_GlyphTable.Add(glyph);
- m_GlyphLookupDictionary.Add(glyphIndex, glyph);
-
- character = new TMP_Character(unicode, this, glyph);
- m_CharacterTable.Add(character);
- m_CharacterLookupDictionary.Add(unicode, character);
- m_GlyphIndexList.Add(glyphIndex);
- m_GlyphIndexListNewlyAdded.Add(glyphIndex);
- if (TMP_Settings.getFontFeaturesAtRuntime)
- RegisterFontAssetForFontFeatureUpdate(this);
- #if UNITY_EDITOR
-
- if (UnityEditor.EditorUtility.IsPersistent(this))
- {
- TMP_EditorResourceManager.RegisterResourceForUpdate(this);
- }
- #endif
- k_TryAddCharacterMarker.End();
- return true;
- }
- }
- k_TryAddCharacterMarker.End();
- return false;
- }
- internal bool TryGetCharacter_and_QueueRenderToTexture(uint unicode, out TMP_Character character)
- {
- k_TryAddCharacterMarker.Begin();
- character = null;
-
- if (m_MissingUnicodesFromFontFile.Contains(unicode))
- {
- k_TryAddCharacterMarker.End();
- return false;
- }
-
- if (FontEngine.LoadFontFace(sourceFontFile, m_FaceInfo.pointSize) != FontEngineError.Success)
- {
- k_TryAddCharacterMarker.End();
- return false;
- }
- uint glyphIndex = FontEngine.GetGlyphIndex(unicode);
- if (glyphIndex == 0)
- {
-
- switch (unicode)
- {
- case 0xA0:
-
- glyphIndex = FontEngine.GetGlyphIndex(0x20);
- break;
- case 0xAD:
- case 0x2011:
-
- glyphIndex = FontEngine.GetGlyphIndex(0x2D);
- break;
- }
-
- if (glyphIndex == 0)
- {
- m_MissingUnicodesFromFontFile.Add(unicode);
- k_TryAddCharacterMarker.End();
- return false;
- }
- }
-
- if (m_GlyphLookupDictionary.ContainsKey(glyphIndex))
- {
- character = new TMP_Character(unicode, this, m_GlyphLookupDictionary[glyphIndex]);
- m_CharacterTable.Add(character);
- m_CharacterLookupDictionary.Add(unicode, character);
- #if UNITY_EDITOR
-
-
-
-
- if (UnityEditor.EditorUtility.IsPersistent(this))
- {
- TMP_EditorResourceManager.RegisterResourceForUpdate(this);
- }
- #endif
- k_TryAddCharacterMarker.End();
- return true;
- }
- GlyphLoadFlags glyphLoadFlags = (GlyphRasterModes.RASTER_MODE_NO_HINTING & (GlyphRasterModes)m_AtlasRenderMode) == GlyphRasterModes.RASTER_MODE_NO_HINTING
- ? GlyphLoadFlags.LOAD_NO_BITMAP | GlyphLoadFlags.LOAD_NO_HINTING
- : GlyphLoadFlags.LOAD_NO_BITMAP;
- Glyph glyph = null;
- if (FontEngine.TryGetGlyphWithIndexValue(glyphIndex, glyphLoadFlags, out glyph))
- {
-
- m_GlyphTable.Add(glyph);
- m_GlyphLookupDictionary.Add(glyphIndex, glyph);
-
- character = new TMP_Character(unicode, this, glyph);
- m_CharacterTable.Add(character);
- m_CharacterLookupDictionary.Add(unicode, character);
- m_GlyphIndexList.Add(glyphIndex);
- m_GlyphIndexListNewlyAdded.Add(glyphIndex);
- if (TMP_Settings.getFontFeaturesAtRuntime)
- RegisterFontAssetForFontFeatureUpdate(this);
-
- m_GlyphsToRender.Add(glyph);
-
- RegisterFontAssetForAtlasTextureUpdate(this);
- #if UNITY_EDITOR
-
-
-
-
- if (UnityEditor.EditorUtility.IsPersistent(this))
- {
- TMP_EditorResourceManager.RegisterResourceForUpdate(this);
- }
- #endif
- k_TryAddCharacterMarker.End();
- return true;
- }
- k_TryAddCharacterMarker.End();
- return false;
- }
-
-
-
- internal void TryAddGlyphsToAtlasTextures()
- {
-
- }
-
-
-
-
- bool TryAddGlyphsToNewAtlasTexture()
- {
-
- SetupNewAtlasTexture();
- Glyph[] glyphs;
-
- bool allGlyphsAddedToTexture = FontEngine.TryAddGlyphsToTexture(m_GlyphsToAdd, m_AtlasPadding, GlyphPackingMode.BestShortSideFit, m_FreeGlyphRects, m_UsedGlyphRects, m_AtlasRenderMode, m_AtlasTextures[m_AtlasTextureIndex], out glyphs);
-
- for (int i = 0; i < glyphs.Length && glyphs[i] != null; i++)
- {
- Glyph glyph = glyphs[i];
- uint glyphIndex = glyph.index;
- glyph.atlasIndex = m_AtlasTextureIndex;
-
- m_GlyphTable.Add(glyph);
- m_GlyphLookupDictionary.Add(glyphIndex, glyph);
- m_GlyphIndexListNewlyAdded.Add(glyphIndex);
- m_GlyphIndexList.Add(glyphIndex);
- }
-
- m_GlyphsToAdd.Clear();
-
- for (int i = 0; i < m_CharactersToAdd.Count; i++)
- {
- TMP_Character character = m_CharactersToAdd[i];
- Glyph glyph;
- if (m_GlyphLookupDictionary.TryGetValue(character.glyphIndex, out glyph) == false)
- {
- m_GlyphsToAdd.Add(character.glyphIndex);
- continue;
- }
-
- character.glyph = glyph;
- character.textAsset = this;
- m_CharacterTable.Add(character);
- m_CharacterLookupDictionary.Add(character.unicode, character);
-
- m_CharactersToAdd.RemoveAt(i);
- i -= 1;
- }
- return allGlyphsAddedToTexture;
- }
-
-
-
- void SetupNewAtlasTexture()
- {
- m_AtlasTextureIndex += 1;
-
- if (m_AtlasTextures.Length == m_AtlasTextureIndex)
- Array.Resize(ref m_AtlasTextures, m_AtlasTextures.Length * 2);
-
- m_AtlasTextures[m_AtlasTextureIndex] = new Texture2D(m_AtlasWidth, m_AtlasHeight, TextureFormat.Alpha8, false);
- FontEngine.ResetAtlasTexture(m_AtlasTextures[m_AtlasTextureIndex]);
-
- int packingModifier = ((GlyphRasterModes)m_AtlasRenderMode & GlyphRasterModes.RASTER_MODE_BITMAP) == GlyphRasterModes.RASTER_MODE_BITMAP ? 0 : 1;
- m_FreeGlyphRects.Clear();
- m_FreeGlyphRects.Add(new GlyphRect(0, 0, m_AtlasWidth - packingModifier, m_AtlasHeight - packingModifier));
- m_UsedGlyphRects.Clear();
- #if UNITY_EDITOR
-
- if (UnityEditor.EditorUtility.IsPersistent(this))
- {
- Texture2D tex = m_AtlasTextures[m_AtlasTextureIndex];
- tex.name = m_AtlasTexture.name + " " + m_AtlasTextureIndex;
- UnityEditor.AssetDatabase.AddObjectToAsset(m_AtlasTextures[m_AtlasTextureIndex], this);
- TMP_EditorResourceManager.RegisterResourceForReimport(this);
- }
- #endif
- }
-
-
-
- internal void UpdateAtlasTexture()
- {
-
- if (m_GlyphsToRender.Count == 0)
- return;
-
-
-
-
-
-
- if (m_AtlasTextures[m_AtlasTextureIndex].width == 0 || m_AtlasTextures[m_AtlasTextureIndex].height == 0)
- {
-
- m_AtlasTextures[m_AtlasTextureIndex].Resize(m_AtlasWidth, m_AtlasHeight);
- FontEngine.ResetAtlasTexture(m_AtlasTextures[m_AtlasTextureIndex]);
- }
-
-
- m_AtlasTextures[m_AtlasTextureIndex].Apply(false, false);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #if UNITY_EDITOR
-
-
- TMP_EditorResourceManager.RegisterResourceForUpdate(this);
- #endif
- }
-
-
-
- internal void UpdateGlyphAdjustmentRecords()
- {
- k_UpdateGlyphAdjustmentRecordsMarker.Begin();
-
- #if UNITY_2018_3 || UNITY_2019_1 || UNITY_2019_2 || UNITY_2019_3
- CopyListDataToArray(m_GlyphIndexList, ref k_GlyphIndexArray);
- GlyphPairAdjustmentRecord[] pairAdjustmentRecords = FontEngine.GetGlyphPairAdjustmentTable(k_GlyphIndexArray);
- #else
-
- GlyphPairAdjustmentRecord[] pairAdjustmentRecords = FontEngine.GetGlyphPairAdjustmentRecords(m_GlyphIndexList, out int recordCount);
- #endif
-
- m_GlyphIndexListNewlyAdded.Clear();
- if (pairAdjustmentRecords == null || pairAdjustmentRecords.Length == 0)
- {
- k_UpdateGlyphAdjustmentRecordsMarker.End();
- return;
- }
- if (m_FontFeatureTable == null)
- m_FontFeatureTable = new TMP_FontFeatureTable();
- for (int i = 0; i < pairAdjustmentRecords.Length && pairAdjustmentRecords[i].firstAdjustmentRecord.glyphIndex != 0; i++)
- {
- uint pairKey = pairAdjustmentRecords[i].secondAdjustmentRecord.glyphIndex << 16 | pairAdjustmentRecords[i].firstAdjustmentRecord.glyphIndex;
-
- if (m_FontFeatureTable.m_GlyphPairAdjustmentRecordLookupDictionary.ContainsKey(pairKey))
- continue;
- TMP_GlyphPairAdjustmentRecord record = new TMP_GlyphPairAdjustmentRecord(pairAdjustmentRecords[i]);
- m_FontFeatureTable.m_GlyphPairAdjustmentRecords.Add(record);
- m_FontFeatureTable.m_GlyphPairAdjustmentRecordLookupDictionary.Add(pairKey, record);
- }
- k_UpdateGlyphAdjustmentRecordsMarker.End();
- }
-
-
-
-
- internal void UpdateGlyphAdjustmentRecords(uint[] glyphIndexes)
- {
- k_UpdateGlyphAdjustmentRecordsMarker.Begin();
-
- GlyphPairAdjustmentRecord[] pairAdjustmentRecords = FontEngine.GetGlyphPairAdjustmentTable(glyphIndexes);
-
-
- if (pairAdjustmentRecords == null || pairAdjustmentRecords.Length == 0)
- {
- k_UpdateGlyphAdjustmentRecordsMarker.End();
- return;
- }
- if (m_FontFeatureTable == null)
- m_FontFeatureTable = new TMP_FontFeatureTable();
- for (int i = 0; i < pairAdjustmentRecords.Length && pairAdjustmentRecords[i].firstAdjustmentRecord.glyphIndex != 0; i++)
- {
- uint pairKey = pairAdjustmentRecords[i].secondAdjustmentRecord.glyphIndex << 16 | pairAdjustmentRecords[i].firstAdjustmentRecord.glyphIndex;
-
- if (m_FontFeatureTable.m_GlyphPairAdjustmentRecordLookupDictionary.ContainsKey(pairKey))
- continue;
- TMP_GlyphPairAdjustmentRecord record = new TMP_GlyphPairAdjustmentRecord(pairAdjustmentRecords[i]);
- m_FontFeatureTable.m_GlyphPairAdjustmentRecords.Add(record);
- m_FontFeatureTable.m_GlyphPairAdjustmentRecordLookupDictionary.Add(pairKey, record);
- }
- k_UpdateGlyphAdjustmentRecordsMarker.End();
- }
-
-
-
-
- internal void UpdateGlyphAdjustmentRecords(List<uint> glyphIndexes)
- {
-
- }
-
-
-
-
-
- internal void UpdateGlyphAdjustmentRecords(List<uint> newGlyphIndexes, List<uint> allGlyphIndexes)
- {
-
- }
-
-
-
-
-
-
- void CopyListDataToArray<T>(List<T> srcList, ref T[] dstArray)
- {
- int size = srcList.Count;
-
- if (dstArray == null)
- dstArray = new T[size];
- else
- Array.Resize(ref dstArray, size);
- for (int i = 0; i < size; i++)
- dstArray[i] = srcList[i];
- }
-
-
-
-
-
- public void ClearFontAssetData(bool setAtlasSizeToZero = false)
- {
- k_ClearFontAssetDataMarker.Begin();
- #if UNITY_EDITOR
-
-
- #endif
-
- ClearFontAssetTables();
-
- ClearAtlasTextures(setAtlasSizeToZero);
- ReadFontAssetDefinition();
-
- #if UNITY_EDITOR
-
- TMP_EditorResourceManager.RegisterResourceForUpdate(this);
- #endif
- k_ClearFontAssetDataMarker.End();
- }
- internal void ClearFontAssetDataInternal()
- {
-
- ClearFontAssetTables();
-
- ClearAtlasTextures(true);
- #if UNITY_EDITOR
-
- TMP_EditorResourceManager.RegisterResourceForUpdate(this);
- #endif
- }
-
-
-
- internal void UpdateFontAssetData()
- {
- k_UpdateFontAssetDataMarker.Begin();
-
- uint[] unicodeCharacters = new uint[m_CharacterTable.Count];
- for (int i = 0; i < m_CharacterTable.Count; i++)
- unicodeCharacters[i] = m_CharacterTable[i].unicode;
-
- ClearFontAssetTables();
-
- ClearAtlasTextures(true);
- ReadFontAssetDefinition();
-
-
- if (unicodeCharacters.Length > 0)
- TryAddCharacters(unicodeCharacters, true);
- k_UpdateFontAssetDataMarker.End();
- }
-
-
-
- internal void ClearFontAssetTables()
- {
-
- if (m_GlyphTable != null)
- m_GlyphTable.Clear();
- if (m_CharacterTable != null)
- m_CharacterTable.Clear();
-
- if (m_UsedGlyphRects != null)
- m_UsedGlyphRects.Clear();
- if (m_FreeGlyphRects != null)
- {
- int packingModifier = ((GlyphRasterModes)m_AtlasRenderMode & GlyphRasterModes.RASTER_MODE_BITMAP) == GlyphRasterModes.RASTER_MODE_BITMAP ? 0 : 1;
- m_FreeGlyphRects.Clear();
- m_FreeGlyphRects.Add(new GlyphRect(0, 0, m_AtlasWidth - packingModifier, m_AtlasHeight - packingModifier));
- }
- if (m_GlyphsToRender != null)
- m_GlyphsToRender.Clear();
- if (m_GlyphsRendered != null)
- m_GlyphsRendered.Clear();
-
- if (m_FontFeatureTable != null && m_FontFeatureTable.m_GlyphPairAdjustmentRecords != null)
- m_FontFeatureTable.glyphPairAdjustmentRecords.Clear();
- }
-
-
-
-
- internal void ClearAtlasTextures(bool setAtlasSizeToZero = false)
- {
- m_AtlasTextureIndex = 0;
-
- if (m_AtlasTextures == null)
- return;
- Texture2D texture = null;
-
- for (int i = 1; i < m_AtlasTextures.Length; i++)
- {
- texture = m_AtlasTextures[i];
- if (texture == null)
- continue;
- DestroyImmediate(texture, true);
- #if UNITY_EDITOR
- if (UnityEditor.EditorUtility.IsPersistent(this))
- TMP_EditorResourceManager.RegisterResourceForReimport(this);
- #endif
- }
-
- Array.Resize(ref m_AtlasTextures, 1);
- texture = m_AtlasTexture = m_AtlasTextures[0];
-
- if (texture.isReadable == false)
- {
- #if UNITY_EDITOR && UNITY_2018_4_OR_NEWER && !UNITY_2018_4_0 && !UNITY_2018_4_1 && !UNITY_2018_4_2 && !UNITY_2018_4_3 && !UNITY_2018_4_4
- FontEngineEditorUtilities.SetAtlasTextureIsReadable(texture, true);
- #else
- Debug.LogWarning("Unable to reset font asset [" + this.name + "]'s atlas texture. Please make the texture [" + texture.name + "] readable.", texture);
- return;
- #endif
- }
- if (setAtlasSizeToZero)
- {
- texture.Resize(0, 0, TextureFormat.Alpha8, false);
- }
- else if (texture.width != m_AtlasWidth || texture.height != m_AtlasHeight)
- {
- texture.Resize(m_AtlasWidth, m_AtlasHeight, TextureFormat.Alpha8, false);
- }
-
- FontEngine.ResetAtlasTexture(texture);
- texture.Apply();
- }
-
-
-
- internal void UpgradeFontAsset()
- {
- m_Version = "1.1.0";
- Debug.Log("Upgrading font asset [" + this.name + "] to version " + m_Version + ".", this);
- m_FaceInfo.familyName = m_fontInfo.Name;
- m_FaceInfo.styleName = string.Empty;
- m_FaceInfo.pointSize = (int)m_fontInfo.PointSize;
- m_FaceInfo.scale = m_fontInfo.Scale;
- m_FaceInfo.lineHeight = m_fontInfo.LineHeight;
- m_FaceInfo.ascentLine = m_fontInfo.Ascender;
- m_FaceInfo.capLine = m_fontInfo.CapHeight;
- m_FaceInfo.meanLine = m_fontInfo.CenterLine;
- m_FaceInfo.baseline = m_fontInfo.Baseline;
- m_FaceInfo.descentLine = m_fontInfo.Descender;
- m_FaceInfo.superscriptOffset = m_fontInfo.SuperscriptOffset;
- m_FaceInfo.superscriptSize = m_fontInfo.SubSize;
- m_FaceInfo.subscriptOffset = m_fontInfo.SubscriptOffset;
- m_FaceInfo.subscriptSize = m_fontInfo.SubSize;
- m_FaceInfo.underlineOffset = m_fontInfo.Underline;
- m_FaceInfo.underlineThickness = m_fontInfo.UnderlineThickness;
- m_FaceInfo.strikethroughOffset = m_fontInfo.strikethrough;
- m_FaceInfo.strikethroughThickness = m_fontInfo.strikethroughThickness;
- m_FaceInfo.tabWidth = m_fontInfo.TabWidth;
- if (m_AtlasTextures == null || m_AtlasTextures.Length == 0)
- m_AtlasTextures = new Texture2D[1];
- m_AtlasTextures[0] = atlas;
-
- m_AtlasWidth = (int)m_fontInfo.AtlasWidth;
- m_AtlasHeight = (int)m_fontInfo.AtlasHeight;
- m_AtlasPadding = (int)m_fontInfo.Padding;
- switch(m_CreationSettings.renderMode)
- {
- case 0:
- m_AtlasRenderMode = GlyphRenderMode.SMOOTH_HINTED;
- break;
- case 1:
- m_AtlasRenderMode = GlyphRenderMode.SMOOTH;
- break;
- case 2:
- m_AtlasRenderMode = GlyphRenderMode.RASTER_HINTED;
- break;
- case 3:
- m_AtlasRenderMode = GlyphRenderMode.RASTER;
- break;
- case 6:
- m_AtlasRenderMode = GlyphRenderMode.SDF16;
- break;
- case 7:
- m_AtlasRenderMode = GlyphRenderMode.SDF32;
- break;
- }
-
-
- if (fontWeights != null && fontWeights.Length > 0)
- {
- m_FontWeightTable[4] = fontWeights[4];
- m_FontWeightTable[7] = fontWeights[7];
-
-
- }
-
- if (fallbackFontAssets != null && fallbackFontAssets.Count > 0)
- {
- if (m_FallbackFontAssetTable == null)
- m_FallbackFontAssetTable = new List<TMP_FontAsset>(fallbackFontAssets.Count);
- for (int i = 0; i < fallbackFontAssets.Count; i++)
- m_FallbackFontAssetTable.Add(fallbackFontAssets[i]);
-
-
- }
-
- if (m_CreationSettings.sourceFontFileGUID != null || m_CreationSettings.sourceFontFileGUID != string.Empty)
- {
- m_SourceFontFileGUID = m_CreationSettings.sourceFontFileGUID;
- }
- else
- {
- Debug.LogWarning("Font asset [" + this.name + "] doesn't have a reference to its source font file. Please assign the appropriate source font file for this asset in the Font Atlas & Material section of font asset inspector.", this);
- }
-
- m_GlyphTable.Clear();
- m_CharacterTable.Clear();
-
-
-
-
-
-
-
-
-
-
- bool isSpaceCharacterPresent = false;
- for (int i = 0; i < m_glyphInfoList.Count; i++)
- {
- TMP_Glyph oldGlyph = m_glyphInfoList[i];
- Glyph glyph = new Glyph();
- uint glyphIndex = (uint)i + 1;
-
-
-
-
- glyph.index = glyphIndex;
- glyph.glyphRect = new GlyphRect((int)oldGlyph.x, m_AtlasHeight - (int)(oldGlyph.y + oldGlyph.height + 0.5f), (int)(oldGlyph.width + 0.5f), (int)(oldGlyph.height + 0.5f));
- glyph.metrics = new GlyphMetrics(oldGlyph.width, oldGlyph.height, oldGlyph.xOffset, oldGlyph.yOffset, oldGlyph.xAdvance);
- glyph.scale = oldGlyph.scale;
- glyph.atlasIndex = 0;
- m_GlyphTable.Add(glyph);
- TMP_Character character = new TMP_Character((uint)oldGlyph.id, this, glyph);
- if (oldGlyph.id == 32)
- isSpaceCharacterPresent = true;
- m_CharacterTable.Add(character);
- }
-
- if (!isSpaceCharacterPresent)
- {
- Debug.Log("Synthesizing Space for [" + this.name + "]");
- Glyph glyph = new Glyph(0, new GlyphMetrics(0, 0, 0, 0, m_FaceInfo.ascentLine / 5), GlyphRect.zero, 1.0f, 0);
- m_GlyphTable.Add(glyph);
- m_CharacterTable.Add(new TMP_Character(32, this, glyph));
- }
-
-
- ReadFontAssetDefinition();
-
-
- #if UNITY_EDITOR
- if (UnityEditor.EditorUtility.IsPersistent(this))
- {
- TMP_EditorResourceManager.RegisterResourceForUpdate(this);
- }
- #endif
- }
-
-
-
- void UpgradeGlyphAdjustmentTableToFontFeatureTable()
- {
- Debug.Log("Upgrading font asset [" + this.name + "] Glyph Adjustment Table.", this);
- if (m_FontFeatureTable == null)
- m_FontFeatureTable = new TMP_FontFeatureTable();
- int pairCount = m_KerningTable.kerningPairs.Count;
- m_FontFeatureTable.m_GlyphPairAdjustmentRecords = new List<TMP_GlyphPairAdjustmentRecord>(pairCount);
- for (int i = 0; i < pairCount; i++)
- {
- KerningPair pair = m_KerningTable.kerningPairs[i];
- uint firstGlyphIndex = 0;
- TMP_Character firstCharacter;
- if (m_CharacterLookupDictionary.TryGetValue(pair.firstGlyph, out firstCharacter))
- firstGlyphIndex = firstCharacter.glyphIndex;
- uint secondGlyphIndex = 0;
- TMP_Character secondCharacter;
- if (m_CharacterLookupDictionary.TryGetValue(pair.secondGlyph, out secondCharacter))
- secondGlyphIndex = secondCharacter.glyphIndex;
- TMP_GlyphAdjustmentRecord firstAdjustmentRecord = new TMP_GlyphAdjustmentRecord(firstGlyphIndex, new TMP_GlyphValueRecord(pair.firstGlyphAdjustments.xPlacement, pair.firstGlyphAdjustments.yPlacement, pair.firstGlyphAdjustments.xAdvance, pair.firstGlyphAdjustments.yAdvance));
- TMP_GlyphAdjustmentRecord secondAdjustmentRecord = new TMP_GlyphAdjustmentRecord(secondGlyphIndex, new TMP_GlyphValueRecord(pair.secondGlyphAdjustments.xPlacement, pair.secondGlyphAdjustments.yPlacement, pair.secondGlyphAdjustments.xAdvance, pair.secondGlyphAdjustments.yAdvance));
- TMP_GlyphPairAdjustmentRecord record = new TMP_GlyphPairAdjustmentRecord(firstAdjustmentRecord, secondAdjustmentRecord);
- m_FontFeatureTable.m_GlyphPairAdjustmentRecords.Add(record);
- }
-
- m_KerningTable.kerningPairs = null;
- m_KerningTable = null;
- #if UNITY_EDITOR
- if (UnityEditor.EditorUtility.IsPersistent(this))
- {
- TMP_EditorResourceManager.RegisterResourceForUpdate(this);
- }
- #endif
- }
- }
- }
|