| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526 |
- /*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
- ////////////////////////////////////////////////////////////////////////////////////////////////////
- #if defined(LYSHINE_INTERNAL_UNIT_TEST)
- #include <LyShine/Bus/UiCanvasBus.h>
- #include <regex>
- namespace
- {
- bool IsClose(float value1, float value2, float epsilon = 0.0001f)
- {
- return fabsf(value1 - value2) < epsilon;
- }
- using FontList = AZStd::list < IFFont * >;
- void AssertTextNotEmpty(const AZStd::list<UiTextComponent::DrawBatch>& drawBatches)
- {
- for (const UiTextComponent::DrawBatch& drawBatch : drawBatches)
- {
- AZ_Assert(!drawBatch.text.empty(), "Test failed");
- }
- }
- void AssertDrawBatchFontOrder(
- const AZStd::list<UiTextComponent::DrawBatch>& drawBatches,
- const FontList& fontList)
- {
- AZ_Assert(drawBatches.size() == fontList.size(), "Test failed");
- auto drawBatchIt = drawBatches.begin();
- auto fontsIt = fontList.begin();
- for (;
- drawBatchIt != drawBatches.end();
- ++drawBatchIt, ++fontsIt)
- {
- const UiTextComponent::DrawBatch& drawBatch = *drawBatchIt;
- const IFFont* font = *fontsIt;
- AZ_Assert(drawBatch.font == font, "Test failed");
- }
- }
- void AssertDrawBatchSingleColor(
- const AZStd::list<UiTextComponent::DrawBatch>& drawBatches,
- const AZ::Vector3& color)
- {
- auto drawBatchIt = drawBatches.begin();
- for (;
- drawBatchIt != drawBatches.end();
- ++drawBatchIt)
- {
- const UiTextComponent::DrawBatch& drawBatch = *drawBatchIt;
- AZ_Assert(drawBatch.color == color, "Test failed");
- }
- }
- using ColorList = AZStd::list < AZ::Vector3 >;
- void AssertDrawBatchMultiColor(
- const AZStd::list<UiTextComponent::DrawBatch>& drawBatches,
- const ColorList& colorList)
- {
- auto drawBatchIt = drawBatches.begin();
- auto colorIt = colorList.begin();
- for (;
- drawBatchIt != drawBatches.end();
- ++drawBatchIt, ++colorIt)
- {
- const UiTextComponent::DrawBatch& drawBatch = *drawBatchIt;
- const AZ::Vector3& color(*colorIt);
- AZ_Assert(drawBatch.color == color, "Test failed");
- }
- }
- using StringList = AZStd::list < LyShine::StringType >;
- void AssertDrawBatchTextContent(
- const AZStd::list<UiTextComponent::DrawBatch>& drawBatches,
- const StringList& stringList)
- {
- AZ_Assert(drawBatches.size() == stringList.size(), "Test failed");
- auto drawBatchIt = drawBatches.begin();
- auto stringIt = stringList.begin();
- for (;
- drawBatchIt != drawBatches.end();
- ++drawBatchIt, ++stringIt)
- {
- const UiTextComponent::DrawBatch& drawBatch = *drawBatchIt;
- const LyShine::StringType& text = *stringIt;
- AZ_Assert(drawBatch.text == text, "Test failed");
- }
- }
- void AssertDrawBatchTextNumNewlines(
- const AZStd::list<UiTextComponent::DrawBatch>& drawBatches,
- const int numNewlines)
- {
- int numNewlinesFound = 0;
- auto drawBatchIt = drawBatches.begin();
- for (;
- drawBatchIt != drawBatches.end();
- ++drawBatchIt)
- {
- const UiTextComponent::DrawBatch& drawBatch = *drawBatchIt;
- numNewlinesFound += static_cast<int>(AZStd::count_if(drawBatch.text.begin(), drawBatch.text.end(),
- [](char c) -> bool
- {
- return c == '\n';
- }));
- }
- AZ_Assert(numNewlines == numNewlinesFound, "Test failed");
- }
- FontFamilyPtr FontFamilyLoad(const char* fontFamilyFilename)
- {
- FontFamilyPtr fontFamily = gEnv->pCryFont->GetFontFamily(fontFamilyFilename);
- if (!fontFamily)
- {
- fontFamily = gEnv->pCryFont->LoadFontFamily(fontFamilyFilename);
- AZ_Assert(gEnv->pCryFont->GetFontFamily(fontFamilyFilename).get(), "Test failed");
- }
- // We need the font family to load correctly in order to test properly
- AZ_Assert(fontFamily.get(), "Test failed");
- return fontFamily;
- }
- //! \brief Verify fonts that ship with Open 3D Engine load correctly.
- //!
- //! This test depends on the LyShineExamples and UiBasics gems being
- //! included in the project.
- //!
- //! There are other fonts that ship in other projects (SamplesProject,
- //! FeatureTests), but that would call for project-specific unit-tests
- //! which don't belong here.
- void VerifyShippingFonts()
- {
- FontFamilyLoad("ui/fonts/lyshineexamples/notosans/notosans.fontfamily");
- FontFamilyLoad("ui/fonts/lyshineexamples/notoserif/notoserif.fontfamily");
- FontFamilyLoad("fonts/vera.fontfamily");
- }
- void NewlineSanitizeTests()
- {
- {
- AZStd::string inputString("Test\\nHi");
- SanitizeUserEnteredNewlineChar(inputString);
- const AZStd::string expectedOutput("Test\nHi");
- AZ_Assert(expectedOutput == inputString, "Test failed");
- // Sanity check that AZStd::regex and std::regex are functionally equivalent.
- {
- const std::string NewlineDelimiter("\n");
- const std::regex UserInputNewlineDelimiter("\\\\n");
- std::string inputStringCopy("Test\\nHi");
- inputStringCopy = std::regex_replace(inputStringCopy, UserInputNewlineDelimiter, NewlineDelimiter);
- AZ_Assert(inputStringCopy == std::string(inputString.c_str()), "Test failed");
- AZ_Assert(AZStd::string(inputStringCopy.c_str()) == inputString, "Test failed");
- }
- }
- }
- void BuildDrawBatchesTests(FontFamily* fontFamily)
- {
- UiTextComponent::InlineImageContainer inlineImages;
- const float defaultImageHeight = 32.0f;
- STextDrawContext fontContext;
- fontContext.SetEffect(0);
- fontContext.SetSizeIn800x600(false);
- fontContext.SetSize(Vec2(32.0f, 32.0f));
- const float defaultAscent = fontFamily->normal->GetAscender(fontContext);
- // Plain string
- {
- const LyShine::StringType markupTestString("this is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(1 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- FontList fontList;
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- AssertDrawBatchSingleColor(drawBatches, TextMarkup::ColorInvalid);
- }
- }
- // Plain string: newline
- {
- const LyShine::StringType markupTestString("Regular Bold Italic\n");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(1 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- FontList fontList;
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- AssertDrawBatchSingleColor(drawBatches, TextMarkup::ColorInvalid);
- }
- }
- // Single bold
- {
- const LyShine::StringType markupTestString("<b>this</b> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- FontList fontList;
- fontList.push_back(fontFamily->bold);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- AssertDrawBatchSingleColor(drawBatches, TextMarkup::ColorInvalid);
- }
- }
- // Single italic
- {
- const LyShine::StringType markupTestString("<i>this</i> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- FontList fontList;
- fontList.push_back(fontFamily->italic);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- AssertDrawBatchSingleColor(drawBatches, TextMarkup::ColorInvalid);
- }
- }
- // Bold-italic
- {
- const LyShine::StringType markupTestString("<b><i>this</i></b> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- FontList fontList;
- fontList.push_back(fontFamily->boldItalic);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- AssertDrawBatchSingleColor(drawBatches, TextMarkup::ColorInvalid);
- }
- }
- // Anchor tag
- {
- const LyShine::StringType markupTestString("<a action=\"action\" data=\"data\">this</a> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- auto drawBatchIter = drawBatches.begin();
- const auto& drawBatch = *drawBatchIter;
- AZ_Assert(drawBatch.IsClickable(), "Test failed");
- AZ_Assert(UiTextComponent::DrawBatch::Type::Text == drawBatch.GetType(), "Test failed");
- AZ_Assert(drawBatch.action == "action", "Test failed");
- AZ_Assert(drawBatch.data == "data", "Test failed");
- AZ_Assert(drawBatch.clickableId == 0, "Test failed");
- ++drawBatchIter;
- const auto& nextDrawBatch = *drawBatchIter;
- AZ_Assert(!nextDrawBatch.IsClickable(), "Test failed");
- AZ_Assert(UiTextComponent::DrawBatch::Type::Text == drawBatch.GetType(), "Test failed");
- AZ_Assert(nextDrawBatch.action.empty(), "Test failed");
- AZ_Assert(nextDrawBatch.data.empty(), "Test failed");
- AZ_Assert(nextDrawBatch.clickableId == -1, "Test failed");
- StringList stringList;
- stringList.push_back("this");
- stringList.push_back(" is a test!");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontList fontList;
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(TextMarkup::ColorInvalid);
- colorList.push_back(TextMarkup::ColorInvalid);
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- // Anchor tag: multiple anchor tags
- {
- const LyShine::StringType markupTestString(
- "<a action=\"action1\" data=\"data1\">this</a>"
- " is a <a action=\"action2\" data=\"data2\">test</a>!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(4 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- auto batchIter = drawBatches.begin();
- {
- const auto& drawBatch = *(batchIter++);
- AZ_Assert(drawBatch.IsClickable(), "Test failed");
- AZ_Assert(UiTextComponent::DrawBatch::Type::Text == drawBatch.GetType(), "Test failed");
- AZ_Assert(drawBatch.action == "action1", "Test failed");
- AZ_Assert(drawBatch.data == "data1", "Test failed");
- AZ_Assert(drawBatch.clickableId == 0, "Test failed");
- }
- {
- const auto& drawBatch = *(batchIter++);
- AZ_Assert(!drawBatch.IsClickable(), "Test failed");
- AZ_Assert(UiTextComponent::DrawBatch::Type::Text == drawBatch.GetType(), "Test failed");
- AZ_Assert(drawBatch.action.empty(), "Test failed");
- AZ_Assert(drawBatch.data.empty(), "Test failed");
- AZ_Assert(drawBatch.clickableId == -1, "Test failed");
- }
- {
- const auto& drawBatch = *(batchIter++);
- AZ_Assert(drawBatch.IsClickable(), "Test failed");
- AZ_Assert(UiTextComponent::DrawBatch::Type::Text == drawBatch.GetType(), "Test failed");
- AZ_Assert(drawBatch.action == "action2", "Test failed");
- AZ_Assert(drawBatch.data == "data2", "Test failed");
- AZ_Assert(drawBatch.clickableId == 1, "Test failed");
- }
- {
- const auto& drawBatch = *(batchIter++);
- AZ_Assert(!drawBatch.IsClickable(), "Test failed");
- AZ_Assert(UiTextComponent::DrawBatch::Type::Text == drawBatch.GetType(), "Test failed");
- AZ_Assert(drawBatch.action.empty(), "Test failed");
- AZ_Assert(drawBatch.data.empty(), "Test failed");
- AZ_Assert(drawBatch.clickableId == -1, "Test failed");
- }
- StringList stringList;
- stringList.push_back("this");
- stringList.push_back(" is a ");
- stringList.push_back("test");
- stringList.push_back("!");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontList fontList;
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(TextMarkup::ColorInvalid);
- colorList.push_back(TextMarkup::ColorInvalid);
- colorList.push_back(TextMarkup::ColorInvalid);
- colorList.push_back(TextMarkup::ColorInvalid);
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- {
- const LyShine::StringType markupTestString(
- "<a action=\"action1\" data=\"data1\">this</a>"
- "<a action=\"action2\" data=\"data2\"> is a test!</a>");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- auto batchIter = drawBatches.begin();
- {
- const auto& drawBatch = *(batchIter++);
- AZ_Assert(drawBatch.IsClickable(), "Test failed");
- AZ_Assert(UiTextComponent::DrawBatch::Type::Text == drawBatch.GetType(), "Test failed");
- AZ_Assert(drawBatch.action == "action1", "Test failed");
- AZ_Assert(drawBatch.data == "data1", "Test failed");
- AZ_Assert(drawBatch.clickableId == 0, "Test failed");
- }
- {
- const auto& drawBatch = *(batchIter++);
- AZ_Assert(drawBatch.IsClickable(), "Test failed");
- AZ_Assert(UiTextComponent::DrawBatch::Type::Text == drawBatch.GetType(), "Test failed");
- AZ_Assert(drawBatch.action == "action2", "Test failed");
- AZ_Assert(drawBatch.data == "data2", "Test failed");
- AZ_Assert(drawBatch.clickableId == 1, "Test failed");
- }
- StringList stringList;
- stringList.push_back("this");
- stringList.push_back(" is a test!");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontList fontList;
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(TextMarkup::ColorInvalid);
- colorList.push_back(TextMarkup::ColorInvalid);
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- {
- const LyShine::StringType markupTestString(
- "<b><a action=\"action1\" data=\"data1\">this</a></b> is "
- "<a action=\"action2\" data=\"data2\">a test!</a>");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(3 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- auto batchIter = drawBatches.begin();
- {
- const auto& drawBatch = *(batchIter++);
- AZ_Assert(drawBatch.IsClickable(), "Test failed");
- AZ_Assert(UiTextComponent::DrawBatch::Type::Text == drawBatch.GetType(), "Test failed");
- AZ_Assert(drawBatch.action == "action1", "Test failed");
- AZ_Assert(drawBatch.data == "data1", "Test failed");
- AZ_Assert(drawBatch.clickableId == 0, "Test failed");
- }
- {
- const auto& drawBatch = *(batchIter++);
- AZ_Assert(!drawBatch.IsClickable(), "Test failed");
- AZ_Assert(UiTextComponent::DrawBatch::Type::Text == drawBatch.GetType(), "Test failed");
- AZ_Assert(drawBatch.action.empty(), "Test failed");
- AZ_Assert(drawBatch.data.empty(), "Test failed");
- AZ_Assert(drawBatch.clickableId == -1, "Test failed");
- }
- {
- const auto& drawBatch = *(batchIter++);
- AZ_Assert(drawBatch.IsClickable(), "Test failed");
- AZ_Assert(UiTextComponent::DrawBatch::Type::Text == drawBatch.GetType(), "Test failed");
- AZ_Assert(drawBatch.action == "action2", "Test failed");
- AZ_Assert(drawBatch.data == "data2", "Test failed");
- AZ_Assert(drawBatch.clickableId == 1, "Test failed");
- }
- StringList stringList;
- stringList.push_back("this");
- stringList.push_back(" is ");
- stringList.push_back("a test!");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontList fontList;
- fontList.push_back(fontFamily->bold);
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(TextMarkup::ColorInvalid);
- colorList.push_back(TextMarkup::ColorInvalid);
- colorList.push_back(TextMarkup::ColorInvalid);
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- // Anchor tag with link color applied via markup
- {
- const LyShine::StringType markupTestString("<font color=\"#ff0000\"><a action=\"action\" data=\"data\">this</a></font> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- auto batchIter = drawBatches.begin();
- {
- const auto& drawBatch = *(batchIter++);
- AZ_Assert(drawBatch.IsClickable(), "Test failed");
- AZ_Assert(UiTextComponent::DrawBatch::Type::Text == drawBatch.GetType(), "Test failed");
- AZ_Assert(drawBatch.action == "action", "Test failed");
- AZ_Assert(drawBatch.data == "data", "Test failed");
- AZ_Assert(drawBatch.clickableId == 0, "Test failed");
- }
- {
- const auto& drawBatch = *(batchIter++);
- AZ_Assert(!drawBatch.IsClickable(), "Test failed");
- AZ_Assert(UiTextComponent::DrawBatch::Type::Text == drawBatch.GetType(), "Test failed");
- AZ_Assert(drawBatch.action.empty(), "Test failed");
- AZ_Assert(drawBatch.data.empty(), "Test failed");
- AZ_Assert(drawBatch.clickableId == -1, "Test failed");
- }
- StringList stringList;
- stringList.push_back("this");
- stringList.push_back(" is a test!");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontList fontList;
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(AZ::Vector3(1.0f, 0.0f, 0.0f));
- colorList.push_back(TextMarkup::ColorInvalid);
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- // Anchor tag with multiple colors within link
- {
- const LyShine::StringType markupTestString("<a action=\"action\" data=\"data\">this <font color=\"#ff0000\">is</font> a test!</a>");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(3 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- // All drawbatches should have the same clickable ID since there's only one link that
- // encompasses all of the text.
- for (auto& drawBatch : drawBatches)
- {
- AZ_Assert(drawBatch.IsClickable(), "Test failed");
- AZ_Assert(UiTextComponent::DrawBatch::Type::Text == drawBatch.GetType(), "Test failed");
- AZ_Assert(drawBatch.action == "action", "Test failed");
- AZ_Assert(drawBatch.data == "data", "Test failed");
- AZ_Assert(drawBatch.clickableId == 0, "Test failed");
- }
- StringList stringList;
- stringList.push_back("this ");
- stringList.push_back("is");
- stringList.push_back(" a test!");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontList fontList;
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(TextMarkup::ColorInvalid);
- colorList.push_back(AZ::Vector3(1.0f, 0.0f, 0.0f));
- colorList.push_back(TextMarkup::ColorInvalid);
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- // Multiple anchor tags with link colors applied within markup
- {
- const LyShine::StringType markupTestString("<a action=\"action1\" data=\"data1\">this <font color=\"#ff0000\">is</font></a> a <a action=\"action2\" data=\"data2\">te<font color=\"#ff0000\">st!</font></a>");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(5 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- auto batchIter = drawBatches.begin();
- {
- const auto& drawBatch = *(batchIter++);
- AZ_Assert(drawBatch.IsClickable(), "Test failed");
- AZ_Assert(UiTextComponent::DrawBatch::Type::Text == drawBatch.GetType(), "Test failed");
- AZ_Assert(drawBatch.action == "action1", "Test failed");
- AZ_Assert(drawBatch.data == "data1", "Test failed");
- AZ_Assert(drawBatch.clickableId == 0, "Test failed");
- }
- {
- const auto& drawBatch = *(batchIter++);
- AZ_Assert(drawBatch.IsClickable(), "Test failed");
- AZ_Assert(UiTextComponent::DrawBatch::Type::Text == drawBatch.GetType(), "Test failed");
- AZ_Assert(drawBatch.action == "action1", "Test failed");
- AZ_Assert(drawBatch.data == "data1", "Test failed");
- AZ_Assert(drawBatch.clickableId == 0, "Test failed");
- }
- {
- const auto& drawBatch = *(batchIter++);
- AZ_Assert(!drawBatch.IsClickable(), "Test failed");
- AZ_Assert(UiTextComponent::DrawBatch::Type::Text == drawBatch.GetType(), "Test failed");
- AZ_Assert(drawBatch.action.empty(), "Test failed");
- AZ_Assert(drawBatch.data.empty(), "Test failed");
- AZ_Assert(drawBatch.clickableId == -1, "Test failed");
- }
- {
- const auto& drawBatch = *(batchIter++);
- AZ_Assert(drawBatch.IsClickable(), "Test failed");
- AZ_Assert(UiTextComponent::DrawBatch::Type::Text == drawBatch.GetType(), "Test failed");
- AZ_Assert(drawBatch.action == "action2", "Test failed");
- AZ_Assert(drawBatch.data == "data2", "Test failed");
- AZ_Assert(drawBatch.clickableId == 1, "Test failed");
- }
- {
- const auto& drawBatch = *(batchIter++);
- AZ_Assert(drawBatch.IsClickable(), "Test failed");
- AZ_Assert(UiTextComponent::DrawBatch::Type::Text == drawBatch.GetType(), "Test failed");
- AZ_Assert(drawBatch.action == "action2", "Test failed");
- AZ_Assert(drawBatch.data == "data2", "Test failed");
- AZ_Assert(drawBatch.clickableId == 1, "Test failed");
- }
- StringList stringList;
- stringList.push_back("this ");
- stringList.push_back("is");
- stringList.push_back(" a ");
- stringList.push_back("te");
- stringList.push_back("st!");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontList fontList;
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(TextMarkup::ColorInvalid);
- colorList.push_back(AZ::Vector3(1.0f, 0.0f, 0.0f));
- colorList.push_back(TextMarkup::ColorInvalid);
- colorList.push_back(TextMarkup::ColorInvalid);
- colorList.push_back(AZ::Vector3(1.0f, 0.0f, 0.0f));
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- // Font tag: font face
- {
- const LyShine::StringType markupTestString("<font face=\"notoserif\">this</font> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(1 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- StringList stringList;
- stringList.push_back("this");
- stringList.push_back(" is a test!");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontFamilyPtr notoSerifFamily = gEnv->pCryFont->GetFontFamily("notoserif");
- AZ_Assert(notoSerifFamily, "Test failed");
- FontList fontList;
- fontList.push_back(notoSerifFamily->normal);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(TextMarkup::ColorInvalid);
- colorList.push_back(TextMarkup::ColorInvalid);
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- // Font tag: font face (different font)
- {
- const LyShine::StringType markupTestString("<font face=\"notosans\">this</font> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(1 == fontFamilyRefs.size(), "Test failed", "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed", "Test failed");
- AssertTextNotEmpty(drawBatches);
- StringList stringList;
- stringList.push_back("this");
- stringList.push_back(" is a test!");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontFamilyPtr notoSansFamily = gEnv->pCryFont->GetFontFamily("notosans");
- AZ_Assert(notoSansFamily, "Test failed");
- FontList fontList;
- fontList.push_back(notoSansFamily->normal);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(TextMarkup::ColorInvalid);
- colorList.push_back(TextMarkup::ColorInvalid);
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- // Font tag: font face (leading space)
- {
- const LyShine::StringType markupTestString("<font face=\" notosans\">this</font> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(1 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- StringList stringList;
- stringList.push_back("this");
- stringList.push_back(" is a test!");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontFamilyPtr notoSansFamily = gEnv->pCryFont->GetFontFamily("notosans");
- AZ_Assert(notoSansFamily, "Test failed");
- FontList fontList;
- fontList.push_back(notoSansFamily->normal);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(TextMarkup::ColorInvalid);
- colorList.push_back(TextMarkup::ColorInvalid);
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- // Font tag: font face (trailing space)
- {
- const LyShine::StringType markupTestString("<font face=\"notosans \">this</font> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(1 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- StringList stringList;
- stringList.push_back("this");
- stringList.push_back(" is a test!");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontFamilyPtr notoSansFamily = gEnv->pCryFont->GetFontFamily("notosans");
- AZ_Assert(notoSansFamily, "Test failed");
- FontList fontList;
- fontList.push_back(notoSansFamily->normal);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(TextMarkup::ColorInvalid);
- colorList.push_back(TextMarkup::ColorInvalid);
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- // Font tag: font face (leading and trailing space)
- {
- const LyShine::StringType markupTestString("<font face=\" notosans \">this</font> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(1 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- StringList stringList;
- stringList.push_back("this");
- stringList.push_back(" is a test!");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontFamilyPtr notoSansFamily = gEnv->pCryFont->GetFontFamily("notosans");
- AZ_Assert(notoSansFamily, "Test failed");
- FontList fontList;
- fontList.push_back(notoSansFamily->normal);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(TextMarkup::ColorInvalid);
- colorList.push_back(TextMarkup::ColorInvalid);
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- // Font tag: font face ("pass-through" font)
- {
- const LyShine::StringType markupTestString("<font face=\"default-ui\">this</font> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(1 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- StringList stringList;
- stringList.push_back("this");
- stringList.push_back(" is a test!");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontFamilyPtr defaultUiFamily = gEnv->pCryFont->GetFontFamily("default-ui");
- AZ_Assert(defaultUiFamily, "Test failed");
- FontList fontList;
- fontList.push_back(defaultUiFamily->normal);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(TextMarkup::ColorInvalid);
- colorList.push_back(TextMarkup::ColorInvalid);
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- // Font tag: font face (invalid font)
- {
- const LyShine::StringType markupTestString("<font face=\"invalidFontName\">this</font> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- StringList stringList;
- stringList.push_back("this");
- stringList.push_back(" is a test!");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontList fontList;
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(TextMarkup::ColorInvalid);
- colorList.push_back(TextMarkup::ColorInvalid);
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- // Font tag: font face (invalid empty string)
- {
- const LyShine::StringType markupTestString("<font face=\"\">this</font> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- StringList stringList;
- stringList.push_back("this");
- stringList.push_back(" is a test!");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontList fontList;
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(TextMarkup::ColorInvalid);
- colorList.push_back(TextMarkup::ColorInvalid);
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- // Font tag: font color (red, lower case)
- {
- const LyShine::StringType markupTestString("<font color=\"#ff0000\">this</font> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- StringList stringList;
- stringList.push_back("this");
- stringList.push_back(" is a test!");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontList fontList;
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(AZ::Vector3(1.0f, 0.0f, 0.0f));
- colorList.push_back(TextMarkup::ColorInvalid);
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- // Font tag: font color (red, upper case)
- {
- const LyShine::StringType markupTestString("<font color=\"#FF0000\">this</font> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- StringList stringList;
- stringList.push_back("this");
- stringList.push_back(" is a test!");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontList fontList;
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(AZ::Vector3(1.0f, 0.0f, 0.0f));
- colorList.push_back(TextMarkup::ColorInvalid);
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- // Font tag: font color (red, mixed case) 1
- {
- const LyShine::StringType markupTestString("<font color=\"#fF0000\">this</font> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- StringList stringList;
- stringList.push_back("this");
- stringList.push_back(" is a test!");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontList fontList;
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(AZ::Vector3(1.0f, 0.0f, 0.0f));
- colorList.push_back(TextMarkup::ColorInvalid);
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- // Font tag: font color (red, mixed case) 2
- {
- const LyShine::StringType markupTestString("<font color=\"#Ff0000\">this</font> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- StringList stringList;
- stringList.push_back("this");
- stringList.push_back(" is a test!");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontList fontList;
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(AZ::Vector3(1.0f, 0.0f, 0.0f));
- colorList.push_back(TextMarkup::ColorInvalid);
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- // Font tag: font color (red, upper case, leading space)
- {
- const LyShine::StringType markupTestString("<font color=\" #FF0000\">this</font> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- StringList stringList;
- stringList.push_back("this");
- stringList.push_back(" is a test!");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontList fontList;
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(AZ::Vector3(1.0f, 0.0f, 0.0f));
- colorList.push_back(TextMarkup::ColorInvalid);
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- // Font tag: font color (red, upper case, trailing space)
- {
- const LyShine::StringType markupTestString("<font color=\"#FF0000 \">this</font> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- StringList stringList;
- stringList.push_back("this");
- stringList.push_back(" is a test!");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontList fontList;
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(AZ::Vector3(1.0f, 0.0f, 0.0f));
- colorList.push_back(TextMarkup::ColorInvalid);
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- // Font tag: font color (red, upper case, leading and trailing space)
- {
- const LyShine::StringType markupTestString("<font color=\" #FF0000 \">this</font> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- StringList stringList;
- stringList.push_back("this");
- stringList.push_back(" is a test!");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontList fontList;
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(AZ::Vector3(1.0f, 0.0f, 0.0f));
- colorList.push_back(TextMarkup::ColorInvalid);
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- // Font tag: font color (green, upper case)
- {
- const LyShine::StringType markupTestString("<font color=\"#00FF00\">this</font> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- StringList stringList;
- stringList.push_back("this");
- stringList.push_back(" is a test!");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontList fontList;
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(AZ::Vector3(0.0f, 1.0f, 0.0f));
- colorList.push_back(TextMarkup::ColorInvalid);
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- // Font tag: font color (blue, upper case)
- {
- const LyShine::StringType markupTestString("<font color=\"#0000FF\">this</font> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- StringList stringList;
- stringList.push_back("this");
- stringList.push_back(" is a test!");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontList fontList;
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(AZ::Vector3(0.0f, 0.0f, 1.0f));
- colorList.push_back(TextMarkup::ColorInvalid);
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- // Font tag: font color (invalid hex value)
- {
- const LyShine::StringType markupTestString("<font color=\"#GGGGGG\">this</font> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- StringList stringList;
- stringList.push_back("this");
- stringList.push_back(" is a test!");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontList fontList;
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(AZ::Vector3(0.0f, 0.0f, 0.0f));
- colorList.push_back(TextMarkup::ColorInvalid);
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- // Font tag: font color (invalid hex value)
- {
- const LyShine::StringType markupTestString("<font color=\"#FF\">this</font> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- StringList stringList;
- stringList.push_back("this");
- stringList.push_back(" is a test!");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontList fontList;
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(TextMarkup::ColorInvalid);
- colorList.push_back(TextMarkup::ColorInvalid);
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- // Font tag: font color (invalid formatting)
- {
- const LyShine::StringType markupTestString("<font color=\"FF0000\">this</font> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- StringList stringList;
- stringList.push_back("this");
- stringList.push_back(" is a test!");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontList fontList;
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(TextMarkup::ColorInvalid);
- colorList.push_back(TextMarkup::ColorInvalid);
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- // Font tag: font color (invalid formatting)
- {
- const LyShine::StringType markupTestString("<font color=\"gluten\">this</font> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- StringList stringList;
- stringList.push_back("this");
- stringList.push_back(" is a test!");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontList fontList;
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(TextMarkup::ColorInvalid);
- colorList.push_back(TextMarkup::ColorInvalid);
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- // Font tag: font color (invalid value, empty string)
- {
- const LyShine::StringType markupTestString("<font color=\"\">this</font> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- StringList stringList;
- stringList.push_back("this");
- stringList.push_back(" is a test!");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontList fontList;
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(TextMarkup::ColorInvalid);
- colorList.push_back(TextMarkup::ColorInvalid);
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- // Font tag: font color (invalid value, empty string, spaces)
- {
- const LyShine::StringType markupTestString("<font color=\" \">this</font> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- StringList stringList;
- stringList.push_back("this");
- stringList.push_back(" is a test!");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontList fontList;
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(TextMarkup::ColorInvalid);
- colorList.push_back(TextMarkup::ColorInvalid);
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- // Font tag: font color (invalid value, leading hash, empty following)
- {
- const LyShine::StringType markupTestString("<font color=\"#\">this</font> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- StringList stringList;
- stringList.push_back("this");
- stringList.push_back(" is a test!");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontList fontList;
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(TextMarkup::ColorInvalid);
- colorList.push_back(TextMarkup::ColorInvalid);
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- // Font tag: font color (invalid value, leading spaces with hash)
- {
- const LyShine::StringType markupTestString("<font color=\" #\">this</font> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- StringList stringList;
- stringList.push_back("this");
- stringList.push_back(" is a test!");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontList fontList;
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(TextMarkup::ColorInvalid);
- colorList.push_back(TextMarkup::ColorInvalid);
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- // Font tag: font color (invalid value, trailing spaces with hash)
- {
- const LyShine::StringType markupTestString("<font color=\"# \">this</font> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- StringList stringList;
- stringList.push_back("this");
- stringList.push_back(" is a test!");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontList fontList;
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(TextMarkup::ColorInvalid);
- colorList.push_back(TextMarkup::ColorInvalid);
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- // Font tag: font color (invalid value, leading and trailing spaces with hash)
- {
- const LyShine::StringType markupTestString("<font color=\" # \">this</font> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- StringList stringList;
- stringList.push_back("this");
- stringList.push_back(" is a test!");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontList fontList;
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(TextMarkup::ColorInvalid);
- colorList.push_back(TextMarkup::ColorInvalid);
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- // Font tag: font face and color
- {
- const LyShine::StringType markupTestString("<font face=\"notoserif\" color=\"#FF0000\">this</font> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(1 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- StringList stringList;
- stringList.push_back("this");
- stringList.push_back(" is a test!");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontFamilyPtr notoSerifFamily = gEnv->pCryFont->GetFontFamily("notoserif");
- AZ_Assert(notoSerifFamily, "Test failed");
- FontList fontList;
- fontList.push_back(notoSerifFamily->normal);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(AZ::Vector3(1.0f, 0.0f, 0.0f));
- colorList.push_back(TextMarkup::ColorInvalid);
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- // Font tag: font color and face
- {
- const LyShine::StringType markupTestString("<font color=\"#FF0000\" face=\"notoserif\">this</font> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(1 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- StringList stringList;
- stringList.push_back("this");
- stringList.push_back(" is a test!");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontFamilyPtr notoSerifFamily = gEnv->pCryFont->GetFontFamily("notoserif");
- AZ_Assert(notoSerifFamily, "Test failed");
- FontList fontList;
- fontList.push_back(notoSerifFamily->normal);
- fontList.push_back(fontFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(AZ::Vector3(1.0f, 0.0f, 0.0f));
- colorList.push_back(TextMarkup::ColorInvalid);
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- // Font tag: invalid attribute
- {
- const LyShine::StringType markupTestString("<font cllor=\"#FF0000\">this</font> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(false == TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- }
- }
- // Mixed test: Bold, italic, bold-italic
- {
- const LyShine::StringType markupTestString("Regular <b>Bold</b> <i>Italic\n<b>Bold-Italic</b></i>");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(5 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- StringList stringList;
- stringList.push_back("Regular ");
- stringList.push_back("Bold");
- stringList.push_back(" ");
- stringList.push_back("Italic\n");
- stringList.push_back("Bold-Italic");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontList fontList;
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->bold);
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->italic);
- fontList.push_back(fontFamily->boldItalic);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- AssertDrawBatchSingleColor(drawBatches, TextMarkup::ColorInvalid);
- }
- }
- // Mixed test: Font color, font face, bold
- {
- const LyShine::StringType markupTestString("<font color=\"#00ff00\">Regular <font face=\"notoserif\"><b>Bold</b></font></font>");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(1 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- StringList stringList;
- stringList.push_back("Regular ");
- stringList.push_back("Bold");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontFamilyPtr notoSerifFamily = gEnv->pCryFont->GetFontFamily("notoserif");
- AZ_Assert(notoSerifFamily, "Test failed");
- FontList fontList;
- fontList.push_back(fontFamily->normal);
- fontList.push_back(notoSerifFamily->bold);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(AZ::Vector3(0.0f, 1.0f, 0.0f));
- colorList.push_back(AZ::Vector3(0.0f, 1.0f, 0.0f));
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- // Mixed test: Multiple font faces, color, bold
- {
- const LyShine::StringType markupTestString("<font color=\"#00ff00\">Regular </font><font face=\"notoserif\"><b>Bold</b></font> <i>Italic<b> Bold-Italic</b></i>\nHere is <font face=\"default-ui\">default-ui</font>");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(2 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(7 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- StringList stringList;
- stringList.push_back("Regular ");
- stringList.push_back("Bold");
- stringList.push_back(" ");
- stringList.push_back("Italic");
- stringList.push_back(" Bold-Italic");
- stringList.push_back("\nHere is ");
- stringList.push_back("default-ui");
- AssertDrawBatchTextContent(drawBatches, stringList);
- FontFamilyPtr notoSerifFamily = gEnv->pCryFont->GetFontFamily("notoserif");
- AZ_Assert(notoSerifFamily, "Test failed");
- FontFamilyPtr defaultUiFamily = gEnv->pCryFont->GetFontFamily("default-ui");
- AZ_Assert(notoSerifFamily, "Test failed");
- FontList fontList;
- fontList.push_back(fontFamily->normal);
- fontList.push_back(notoSerifFamily->bold);
- fontList.push_back(fontFamily->normal);
- fontList.push_back(fontFamily->italic);
- fontList.push_back(fontFamily->boldItalic);
- fontList.push_back(fontFamily->normal);
- fontList.push_back(defaultUiFamily->normal);
- AssertDrawBatchFontOrder(drawBatches, fontList);
- ColorList colorList;
- colorList.push_back(AZ::Vector3(0.0f, 1.0f, 0.0f));
- colorList.push_back(TextMarkup::ColorInvalid);
- colorList.push_back(TextMarkup::ColorInvalid);
- colorList.push_back(TextMarkup::ColorInvalid);
- colorList.push_back(TextMarkup::ColorInvalid);
- colorList.push_back(TextMarkup::ColorInvalid);
- colorList.push_back(TextMarkup::ColorInvalid);
- AssertDrawBatchMultiColor(drawBatches, colorList);
- }
- }
- }
- using SizeList = AZStd::list < size_t >;
- void AssertBatchLineSizes(
- const UiTextComponent::DrawBatchLines& batchLines,
- const SizeList& batchSizes)
- {
- AZ_Assert(batchLines.batchLines.size() == batchSizes.size(), "Test failed");
- auto linesIt = batchLines.batchLines.begin();
- auto sizesIt = batchSizes.begin();
- for (;
- linesIt != batchLines.batchLines.end();
- ++linesIt, ++sizesIt)
- {
- const UiTextComponent::DrawBatchContainer& batchLine = (*linesIt).drawBatchList;
- const size_t batchSize = *sizesIt;
- AZ_Assert(batchLine.size() == batchSize, "Test failed");
- }
- }
- using DrawBatchLines = UiTextComponent::DrawBatchLines;
- using DrawBatchContainer = UiTextComponent::DrawBatchContainer;
- using DrawBatch = UiTextComponent::DrawBatch;
- void WrapTextTests(FontFamily* fontFamily)
- {
- UiTextComponent::InlineImageContainer inlineImages;
- const float defaultImageHeight = 32.0f;
- STextDrawContext fontContext;
- fontContext.SetEffect(0);
- fontContext.SetSizeIn800x600(false);
- fontContext.SetSize(Vec2(32.0f, 32.0f));
- const float defaultAscent = fontFamily->normal->GetAscender(fontContext);
- {
- const LyShine::StringType testMarkup("Regular Bold Italic\n");
- DrawBatchContainer drawBatches;
- DrawBatch b1;
- b1.font = fontFamily->normal;
- b1.text = testMarkup;
- drawBatches.push_back(b1);
- InsertNewlinesToWrapText(drawBatches, fontContext, 1000.0f);
- AZ_Assert(drawBatches.front().text == testMarkup, "Test failed");
- }
- {
- // "Regular Bold v .<i>Italic\n</i>Bold-Italic"
- StringList stringList;
- stringList.push_back("Regular Bold v .");
- stringList.push_back("Italic\n");
- stringList.push_back("Bold-Italic");
- StringList::const_iterator citer = stringList.begin();
- DrawBatchContainer drawBatches;
- DrawBatch b1;
- b1.font = fontFamily->normal;
- b1.text = *citer; ++citer;
- drawBatches.push_back(b1);
- DrawBatch b2;
- b2.font = fontFamily->italic;
- b2.text = *citer; ++citer;
- drawBatches.push_back(b2);
- DrawBatch b3;
- b3.font = fontFamily->normal;
- b3.text = *citer; ++citer;
- drawBatches.push_back(b3);
- InsertNewlinesToWrapText(drawBatches, fontContext, 1000.0f);
- AssertDrawBatchTextContent(drawBatches, stringList);
- }
- // Anchor tag: single line, no wrapping
- {
- const LyShine::StringType textNoMarkup("this is a test!");
- const LyShine::StringType markupTestString("<a action=\"action\" data=\"data\">this</a> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- StringList stringList;
- stringList.push_back("this");
- stringList.push_back(" is a test!");
- // 1000.0f should be too big to cause any newlines to be inserted
- const float wrapWidth = 1000.0f;
- InsertNewlinesToWrapText(drawBatches, fontContext, wrapWidth);
- AssertDrawBatchTextContent(drawBatches, stringList);
- }
- // Anchor tag: word-wrap cases
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- // Element size 75% of text length should insert one newline
- const float textWidth = fontFamily->normal->GetTextSize(textNoMarkup.c_str(), true, fontContext).x;
- const float wrapWidth = textWidth * 0.75f;
- InsertNewlinesToWrapText(drawBatches, fontContext, wrapWidth);
- const int numNewlines = 1;
- AssertDrawBatchTextNumNewlines(drawBatches, numNewlines);
- }
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- AZ_Assert(0 == fontFamilyRefs.size(), "Test failed");
- AZ_Assert(2 == drawBatches.size(), "Test failed");
- AssertTextNotEmpty(drawBatches);
- // Element size 45% of text length should insert two newlines
- const float textWidth = fontFamily->normal->GetTextSize(textNoMarkup.c_str(), true, fontContext).x;
- const float wrapWidth = textWidth * 0.45f;
- InsertNewlinesToWrapText(drawBatches, fontContext, wrapWidth);
- const int numNewlines = 2;
- AssertDrawBatchTextNumNewlines(drawBatches, numNewlines);
- }
- }
- }
- void BatchLinesTests(FontFamily* fontFamily)
- {
- STextDrawContext fontContext;
- fontContext.SetEffect(0);
- fontContext.SetSizeIn800x600(false);
- fontContext.SetSize(Vec2(32.0f, 32.0f));
- UiTextComponent::InlineImageContainer inlineImages;
- float defaultImageHeight = 32.0f;
- const float defaultAscent = fontFamily->normal->GetAscender(fontContext);
- UiTextInterface::DisplayedTextFunction displayedTextFunction(DefaultDisplayedTextFunction);
- {
- DrawBatchLines batchLines;
- DrawBatchContainer drawBatches;
- DrawBatch b1;
- b1.font = fontFamily->normal;
- b1.text = "a";
- drawBatches.push_back(b1);
- CreateBatchLines(batchLines, drawBatches, fontFamily);
- AZ_Assert(1 == batchLines.batchLines.size(), "Test failed");
- SizeList sizeList;
- sizeList.push_back(1);
- AssertBatchLineSizes(batchLines, sizeList);
- }
- {
- DrawBatchLines batchLines;
- DrawBatchContainer drawBatches;
- DrawBatch b1;
- b1.font = fontFamily->normal;
- b1.text = "a\n";
- drawBatches.push_back(b1);
- CreateBatchLines(batchLines, drawBatches, fontFamily);
- AZ_Assert(2 == batchLines.batchLines.size(), "Test failed");
- SizeList sizeList;
- sizeList.push_back(1);
- sizeList.push_back(1);
- AssertBatchLineSizes(batchLines, sizeList);
- }
- {
- DrawBatchLines batchLines;
- DrawBatchContainer drawBatches;
- DrawBatch b1;
- b1.font = fontFamily->normal;
- b1.text = "a\nb";
- drawBatches.push_back(b1);
- CreateBatchLines(batchLines, drawBatches, fontFamily);
- AZ_Assert(2 == batchLines.batchLines.size(), "Test failed");
- SizeList sizeList;
- sizeList.push_back(1);
- sizeList.push_back(1);
- AssertBatchLineSizes(batchLines, sizeList);
- }
- {
- DrawBatchLines batchLines;
- DrawBatchContainer drawBatches;
- DrawBatch b1;
- b1.font = fontFamily->normal;
- b1.text = "a\n\nb";
- drawBatches.push_back(b1);
- CreateBatchLines(batchLines, drawBatches, fontFamily);
- AZ_Assert(3 == batchLines.batchLines.size(), "Test failed");
- SizeList sizeList;
- sizeList.push_back(1);
- sizeList.push_back(1);
- sizeList.push_back(1);
- AssertBatchLineSizes(batchLines, sizeList);
- }
- {
- DrawBatchLines batchLines;
- DrawBatchContainer drawBatches;
- DrawBatch b1;
- b1.font = fontFamily->normal;
- b1.text = "a\n\n\nb";
- drawBatches.push_back(b1);
- CreateBatchLines(batchLines, drawBatches, fontFamily);
- AZ_Assert(4 == batchLines.batchLines.size(), "Test failed");
- SizeList sizeList;
- sizeList.push_back(1);
- sizeList.push_back(1);
- sizeList.push_back(1);
- sizeList.push_back(1);
- AssertBatchLineSizes(batchLines, sizeList);
- }
- {
- DrawBatchLines batchLines;
- DrawBatchContainer drawBatches;
- DrawBatch b1;
- b1.font = fontFamily->normal;
- b1.text = "Regular Bold Italic\n";
- drawBatches.push_back(b1);
- CreateBatchLines(batchLines, drawBatches, fontFamily);
- AZ_Assert(2 == batchLines.batchLines.size(), "Test failed");
- SizeList sizeList;
- sizeList.push_back(1);
- sizeList.push_back(1);
- AssertBatchLineSizes(batchLines, sizeList);
- }
- {
- const LyShine::StringType markupTestString("Regular Bold <i>Italic</i>Bold-Italic");
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- DrawBatchLines batchLines;
- BatchAwareWrapText(batchLines, drawBatches, fontFamily, fontContext, 290.0f);
- AZ_Assert(2 == batchLines.batchLines.size(), "Test failed");
- SizeList sizeList;
- sizeList.push_back(1);
- sizeList.push_back(2);
- AssertBatchLineSizes(batchLines, sizeList);
- }
- {
- const LyShine::StringType markupTestString("Regular <b>Bold</b> <i>Italic\n<b>Bold-Italic</b></i>");
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- DrawBatchLines batchLines;
- CreateBatchLines(batchLines, drawBatches, fontFamily);
- AZ_Assert(2 == batchLines.batchLines.size(), "Test failed");
- SizeList sizeList;
- sizeList.push_back(4);
- sizeList.push_back(1);
- AssertBatchLineSizes(batchLines, sizeList);
- }
- // Anchor tag: word-wrap, anchor doesn't span multiple lines
- {
- const LyShine::StringType textNoMarkup("this is a test!");
- const LyShine::StringType markupTestString("<a action=\"action\" data=\"data\">this</a> is a test!");
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- // 1000.0f should be too big to cause any newlines to be inserted
- const float wrapWidth = 1000.0f;
- InsertNewlinesToWrapText(drawBatches, fontContext, wrapWidth);
- DrawBatchLines batchLines;
- CreateBatchLines(batchLines, drawBatches, fontFamily);
- AZ_Assert(1 == batchLines.batchLines.size(), "Test failed");
- SizeList sizeList;
- sizeList.push_back(2);
- AssertBatchLineSizes(batchLines, sizeList);
- }
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- // Element size 75% of text length should insert one newline
- const float textWidth = fontFamily->normal->GetTextSize(textNoMarkup.c_str(), true, fontContext).x;
- const float wrapWidth = textWidth * 0.75f;
- InsertNewlinesToWrapText(drawBatches, fontContext, wrapWidth);
- DrawBatchLines batchLines;
- CreateBatchLines(batchLines, drawBatches, fontFamily);
- AZ_Assert(2 == batchLines.batchLines.size(), "Test failed");
- SizeList sizeList;
- sizeList.push_back(2);
- sizeList.push_back(1);
- AssertBatchLineSizes(batchLines, sizeList);
- }
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- // Element size 45% of text length should insert two newlines
- const float textWidth = fontFamily->normal->GetTextSize(textNoMarkup.c_str(), true, fontContext).x;
- const float wrapWidth = textWidth * 0.45f;
- InsertNewlinesToWrapText(drawBatches, fontContext, wrapWidth);
- DrawBatchLines batchLines;
- CreateBatchLines(batchLines, drawBatches, fontFamily);
- AZ_Assert(3 == batchLines.batchLines.size(), "Test failed");
- SizeList sizeList;
- sizeList.push_back(2);
- sizeList.push_back(1);
- sizeList.push_back(1);
- AssertBatchLineSizes(batchLines, sizeList);
- }
- }
- // Anchor tag: word-wrap, single anchor spans multiple lines
- {
- const LyShine::StringType textNoMarkup("this is a test!");
- const LyShine::StringType markupTestString("<a action=\"action\" data=\"data\">this is a test!</a>");
- // Sanity check: single-line case
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- // 1000.0f should be too big to cause any newlines to be inserted
- const float wrapWidth = 1000.0f;
- InsertNewlinesToWrapText(drawBatches, fontContext, wrapWidth);
- DrawBatchLines batchLines;
- CreateBatchLines(batchLines, drawBatches, fontFamily);
- AZ_Assert(1 == batchLines.batchLines.size(), "Test failed");
- SizeList sizeList;
- sizeList.push_back(1);
- AssertBatchLineSizes(batchLines, sizeList);
- // Since a single anchor tag spans the entirety of the text,
- // we can just iterate over all drawbatches for all lines
- // and verify that the anchor tag information exists across
- // all drawbatch lines.
- for (auto& batchLine : batchLines.batchLines)
- {
- for (auto& drawBatch : batchLine.drawBatchList)
- {
- AZ_Assert(drawBatch.IsClickable(), "Test failed");
- AZ_Assert(UiTextComponent::DrawBatch::Type::Text == drawBatch.GetType(), "Test failed");
- AZ_Assert(drawBatch.action == "action", "Test failed");
- AZ_Assert(drawBatch.data == "data", "Test failed");
- AZ_Assert(drawBatch.clickableId == 0, "Test failed");
- }
- }
- }
- // Verify that anchor tag on word-wrapped text expands to both lines
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- // Element size 75% of text length should insert one newline
- const float textWidth = fontFamily->normal->GetTextSize(textNoMarkup.c_str(), true, fontContext).x;
- const float wrapWidth = textWidth * 0.75f;
- InsertNewlinesToWrapText(drawBatches, fontContext, wrapWidth);
- DrawBatchLines batchLines;
- CreateBatchLines(batchLines, drawBatches, fontFamily);
- AZ_Assert(2 == batchLines.batchLines.size(), "Test failed");
- SizeList sizeList;
- sizeList.push_back(1);
- sizeList.push_back(1);
- AssertBatchLineSizes(batchLines, sizeList);
- // Since a single anchor tag spans the entirety of the text,
- // we can just iterate over all drawbatches for all lines
- // and verify that the anchor tag information exists across
- // all drawbatch lines.
- for (auto& batchLine : batchLines.batchLines)
- {
- for (auto& drawBatch : batchLine.drawBatchList)
- {
- AZ_Assert(drawBatch.IsClickable(), "Test failed");
- AZ_Assert(UiTextComponent::DrawBatch::Type::Text == drawBatch.GetType(), "Test failed");
- AZ_Assert(drawBatch.action == "action", "Test failed");
- AZ_Assert(drawBatch.data == "data", "Test failed");
- AZ_Assert(drawBatch.clickableId == 0, "Test failed");
- }
- }
- }
- {
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- // Element size 45% of text length should insert two newlines
- const float textWidth = fontFamily->normal->GetTextSize(textNoMarkup.c_str(), true, fontContext).x;
- const float wrapWidth = textWidth * 0.45f;
- InsertNewlinesToWrapText(drawBatches, fontContext, wrapWidth);
- DrawBatchLines batchLines;
- CreateBatchLines(batchLines, drawBatches, fontFamily);
- AZ_Assert(3 == batchLines.batchLines.size(), "Test failed");
- SizeList sizeList;
- sizeList.push_back(1);
- sizeList.push_back(1);
- sizeList.push_back(1);
- AssertBatchLineSizes(batchLines, sizeList);
- // Since a single anchor tag spans the entirety of the text,
- // we can just iterate over all drawbatches for all lines
- // and verify that the anchor tag information exists across
- // all drawbatch lines.
- for (auto& batchLine : batchLines.batchLines)
- {
- for (auto& drawBatch : batchLine.drawBatchList)
- {
- AZ_Assert(drawBatch.IsClickable(), "Test failed");
- AZ_Assert(UiTextComponent::DrawBatch::Type::Text == drawBatch.GetType(), "Test failed");
- AZ_Assert(drawBatch.action == "action", "Test failed");
- AZ_Assert(drawBatch.data == "data", "Test failed");
- AZ_Assert(drawBatch.clickableId == 0, "Test failed");
- }
- }
- }
- }
- /////////////////////////////////////////////////////////////
- // Anchor tag: word-wrap, multiple anchor spans multiple lines
- {
- {
- const LyShine::StringType textNoMarkup("this is a test!");
- const LyShine::StringType markupTestString(
- "<a action=\"action1\" data=\"data1\">this is a test</a>"
- "<a action=\"action2\" data=\"data2\">!</a>"
- );
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- // Element size 75% of text length should insert one newline
- const float textWidth = fontFamily->normal->GetTextSize(textNoMarkup.c_str(), true, fontContext).x;
- const float wrapWidth = textWidth * 0.75f;
- InsertNewlinesToWrapText(drawBatches, fontContext, wrapWidth);
- DrawBatchLines batchLines;
- CreateBatchLines(batchLines, drawBatches, fontFamily);
- AZ_Assert(2 == batchLines.batchLines.size(), "Test failed");
- SizeList sizeList;
- sizeList.push_back(1);
- sizeList.push_back(2);
- AssertBatchLineSizes(batchLines, sizeList);
- auto batchLineIter = batchLines.batchLines.begin();
- {
- const auto& batchLine = *batchLineIter;
- auto drawBatchIter = batchLine.drawBatchList.begin();
- {
- const DrawBatch& drawBatch = *drawBatchIter;
- AZ_Assert(drawBatch.IsClickable(), "Test failed");
- AZ_Assert(UiTextComponent::DrawBatch::Type::Text == drawBatch.GetType(), "Test failed");
- AZ_Assert(drawBatch.action == "action1", "Test failed");
- AZ_Assert(drawBatch.data == "data1", "Test failed");
- AZ_Assert(drawBatch.clickableId == 0, "Test failed");
- }
- }
- // Next line
- ++batchLineIter;
- {
- const auto& batchLine = *batchLineIter;
- auto drawBatchIter = batchLine.drawBatchList.begin();
- {
- const DrawBatch& drawBatch = *drawBatchIter;
- AZ_Assert(drawBatch.IsClickable(), "Test failed");
- AZ_Assert(UiTextComponent::DrawBatch::Type::Text == drawBatch.GetType(), "Test failed");
- AZ_Assert(drawBatch.action == "action1", "Test failed");
- AZ_Assert(drawBatch.data == "data1", "Test failed");
- AZ_Assert(drawBatch.clickableId == 0, "Test failed");
- }
- // Next batch
- ++drawBatchIter;
- {
- const DrawBatch& drawBatch = *drawBatchIter;
- AZ_Assert(drawBatch.text == "!", "Test failed");
- AZ_Assert(drawBatch.IsClickable(), "Test failed");
- AZ_Assert(UiTextComponent::DrawBatch::Type::Text == drawBatch.GetType(), "Test failed");
- AZ_Assert(drawBatch.action == "action2", "Test failed");
- AZ_Assert(drawBatch.data == "data2", "Test failed");
- AZ_Assert(drawBatch.clickableId == 1, "Test failed");
- }
- }
- }
- {
- const LyShine::StringType textNoMarkup("this is a test!");
- const LyShine::StringType markupTestString(
- "<a action=\"action1\" data=\"data1\">t</a>"
- "<a action=\"action2\" data=\"data2\">his is a test!</a>"
- );
- TextMarkup::Tag markupRoot;
- AZ_Assert(TextMarkup::ParseMarkupBuffer(markupTestString, markupRoot), "Test failed");
- AZStd::list<UiTextComponent::DrawBatch> drawBatches;
- AZStd::stack<UiTextComponent::DrawBatch> batchStack;
- AZStd::stack<FontFamily*> fontFamilyStack;
- fontFamilyStack.push(fontFamily);
- UiTextComponent::FontFamilyRefSet fontFamilyRefs;
- BuildDrawBatchesAndAssignClickableIds(drawBatches, fontFamilyRefs, inlineImages, defaultImageHeight, defaultAscent, batchStack, fontFamilyStack, &markupRoot);
- // Element size 75% of text length should insert one newline
- const float textWidth = fontFamily->normal->GetTextSize(textNoMarkup.c_str(), true, fontContext).x;
- const float wrapWidth = textWidth * 0.75f;
- InsertNewlinesToWrapText(drawBatches, fontContext, wrapWidth);
- DrawBatchLines batchLines;
- CreateBatchLines(batchLines, drawBatches, fontFamily);
- AZ_Assert(2 == batchLines.batchLines.size(), "Test failed");
- SizeList sizeList;
- sizeList.push_back(2);
- sizeList.push_back(1);
- AssertBatchLineSizes(batchLines, sizeList);
- auto batchLineIter = batchLines.batchLines.begin();
- {
- const auto& batchLine = *batchLineIter;
- auto drawBatchIter = batchLine.drawBatchList.begin();
- {
- const DrawBatch& drawBatch = *drawBatchIter;
- AZ_Assert(drawBatch.text == "t", "Test failed");
- AZ_Assert(drawBatch.IsClickable(), "Test failed");
- AZ_Assert(UiTextComponent::DrawBatch::Type::Text == drawBatch.GetType(), "Test failed");
- AZ_Assert(drawBatch.action == "action1", "Test failed");
- AZ_Assert(drawBatch.data == "data1", "Test failed");
- AZ_Assert(drawBatch.clickableId == 0, "Test failed");
- }
- // Next batch
- ++drawBatchIter;
- {
- const DrawBatch& drawBatch = *drawBatchIter;
- AZ_Assert(drawBatch.IsClickable(), "Test failed");
- AZ_Assert(UiTextComponent::DrawBatch::Type::Text == drawBatch.GetType(), "Test failed");
- AZ_Assert(drawBatch.action == "action2", "Test failed");
- AZ_Assert(drawBatch.data == "data2", "Test failed");
- AZ_Assert(drawBatch.clickableId == 1, "Test failed");
- }
- }
- // Next line
- ++batchLineIter;
- {
- const auto& batchLine = *batchLineIter;
- auto drawBatchIter = batchLine.drawBatchList.begin();
- {
- const DrawBatch& drawBatch = *drawBatchIter;
- AZ_Assert(drawBatch.IsClickable(), "Test failed");
- AZ_Assert(UiTextComponent::DrawBatch::Type::Text == drawBatch.GetType(), "Test failed");
- AZ_Assert(drawBatch.action == "action2", "Test failed");
- AZ_Assert(drawBatch.data == "data2", "Test failed");
- AZ_Assert(drawBatch.clickableId == 1, "Test failed");
- }
- }
- }
- }
- }
- void CreateComponent(AZ::Entity* entity, const AZ::Uuid& componentTypeId)
- {
- entity->Deactivate();
- entity->CreateComponent(componentTypeId);
- entity->Activate();
- }
- void TestCharacterSpacing(CLyShine* lyshine, const AZStd::string& fontPath, float fontSize, const AZStd::string& testString, float characterSpacing, const char* testName)
- {
- AZ::EntityId canvasEntityId = lyshine->CreateCanvas();
- UiCanvasInterface* canvas = UiCanvasBus::FindFirstHandler(canvasEntityId);
- AZ_Assert(canvas, "Test failed");
- AZ::Entity* testElem = canvas->CreateChildElement("TrackingTestElement");
- AZ_Assert(testElem, "Test failed");
- CreateComponent(testElem, LyShine::UiTransform2dComponentUuid);
- CreateComponent(testElem, LyShine::UiTextComponentUuid);
- AZ::EntityId testElemId = testElem->GetId();
- UiTextBus::Event(testElemId, &UiTextBus::Events::SetText, testString);
- UiTextBus::Event(testElemId, &UiTextBus::Events::SetFont, fontPath);
- UiTextBus::Event(testElemId, &UiTextBus::Events::SetFontSize, fontSize);
- float baseWidth;
- UiLayoutCellDefaultBus::EventResult(
- baseWidth, testElemId, &UiLayoutCellDefaultBus::Events::GetTargetWidth, LyShine::UiLayoutCellUnspecifiedSize);
- UiTextBus::Event(testElemId, &UiTextBus::Events::SetCharacterSpacing, characterSpacing);
- float newWidth;
- UiLayoutCellDefaultBus::EventResult(newWidth, testElemId, &UiLayoutCellDefaultBus::Events::GetTargetWidth, LyShine::UiLayoutCellUnspecifiedSize);
- const int testStringLength = static_cast<int>(testString.length());
- const int numGapsBetweenCharacters = testStringLength >= 1 ? testStringLength - 1 : 0;
- const float ems = characterSpacing * 0.001f;
- float expectedWidth = baseWidth + numGapsBetweenCharacters * ems * fontSize;
- if (expectedWidth < 0.0f)
- {
- expectedWidth = 0.0f;
- }
- AZ_Assert(IsClose(newWidth, expectedWidth), "Test failed: Character Spacing, %s. Expected: %f, actual: %f", testName, expectedWidth, newWidth);
- lyshine->ReleaseCanvas(canvasEntityId, false);
- }
- void TestLineSpacing(CLyShine* lyshine, const AZStd::string& fontPath, float fontSize, const AZStd::string& testString, int numNewlines, float lineSpacing, const char* testName)
- {
- AZ::EntityId canvasEntityId = lyshine->CreateCanvas();
- UiCanvasInterface* canvas = UiCanvasBus::FindFirstHandler(canvasEntityId);
- AZ_Assert(canvas, "Test failed");
- AZ::Entity* testElem = canvas->CreateChildElement("LeadingTestElement");
- AZ_Assert(testElem, "Test failed");
- CreateComponent(testElem, LyShine::UiTransform2dComponentUuid);
- CreateComponent(testElem, LyShine::UiTextComponentUuid);
- AZ::EntityId testElemId = testElem->GetId();
- UiTextBus::Event(testElemId, &UiTextBus::Events::SetText, testString);
- UiTextBus::Event(testElemId, &UiTextBus::Events::SetFont, fontPath);
- UiTextBus::Event(testElemId, &UiTextBus::Events::SetFontSize, fontSize);
- float baseHeight;
- UiLayoutCellDefaultBus::EventResult(
- baseHeight, testElemId, &UiLayoutCellDefaultBus::Events::GetTargetHeight, LyShine::UiLayoutCellUnspecifiedSize);
- UiTextBus::Event(testElemId, &UiTextBus::Events::SetLineSpacing, lineSpacing);
- float newHeight;
- UiLayoutCellDefaultBus::EventResult(
- newHeight, testElemId, &UiLayoutCellDefaultBus::Events::GetTargetHeight, LyShine::UiLayoutCellUnspecifiedSize);
- float expectedHeight = baseHeight + numNewlines * lineSpacing;
- if (expectedHeight < 0.0f)
- {
- expectedHeight = 0.0f;
- }
- AZ_Assert(IsClose(newHeight, expectedHeight), "Test failed: Line Spacing, %s. Expected: %f, actual: %f", testName, expectedHeight, newHeight);
- lyshine->ReleaseCanvas(canvasEntityId, false);
- }
- void TrackingLeadingTests(CLyShine* lyshine)
- {
- // Character Spacing
- TestCharacterSpacing(lyshine, "default-ui", 32.0f, "Hi", 1000.0f, "one space");
- TestCharacterSpacing(lyshine, "default-ui", 32.0f, "W", 1000.0f, "no spaces");
- TestCharacterSpacing(lyshine, "default-ui", 32.0f, "", 1000.0f, "empty string");
- TestCharacterSpacing(lyshine, "default-ui", 32.0f, "Hi", 4500.0f, "bigger spacing");
- TestCharacterSpacing(lyshine, "default-ui", 32.0f, "abcde", 1000.0f, "four spaces");
- TestCharacterSpacing(lyshine, "default-ui", 32.0f, "abcde", 3500.0f, "four spaces, larger spacing");
- TestCharacterSpacing(lyshine, "default-ui", 32.0f, "12345678", 5432.1f, "seven spaces, non-round spacing");
- TestCharacterSpacing(lyshine, "default-ui", 32.0f, "12345678", 5432.1f, "seven spaces, non-round spacing, lots of kerning");
- TestCharacterSpacing(lyshine, "default-ui", 32.0f, "Hi", -1000.0f, "negative spacing");
- TestCharacterSpacing(lyshine, "default-ui", 32.0f, "abcde", -1000.0f, "negative spacing, 4 spaces");
- TestCharacterSpacing(lyshine, "default-ui", 16.0f, "Hi", 1000.0f, "smaller font size, one space");
- TestCharacterSpacing(lyshine, "default-ui", 16.0f, "abcdefghijk", 1000.0f, "smaller font size, ten spaces");
- TestCharacterSpacing(lyshine, "default-ui", 16.0f, "abcdefghijk", 3500.0f, "smaller font size, ten spaces, larger spacing");
- TestCharacterSpacing(lyshine, "default-ui", 64.0f, "Hi", 1000.0f, "larger font size, one space");
- TestCharacterSpacing(lyshine, "default-ui", 64.0f, "abcdefgh", 1000.0f, "larger font size, seven spaces");
- TestCharacterSpacing(lyshine, "default-ui", 64.0f, "abcdefgh", 5200.0f, "larger font size, seven spaces, larger spacing");
- TestCharacterSpacing(lyshine, "default", 32.0f, "abcdefgh", 1000.0f, "default (monospace) font, seven spaces");
- TestCharacterSpacing(lyshine, "notosans-regular", 32.0f, "WAW.AWA|WAW", 2500.0f, "noto sans font, 10 spaces, larger spacing");
- TestCharacterSpacing(lyshine, "notosans-regular", 32.0f, "WAW.AWA|WAW", 25.0f, "noto sans font, 10 spaces, smaller spacing");
- TestCharacterSpacing(lyshine, "notosans-regular", 32.0f, "WAW.AWA|WAW", -25.0f, "noto sans font, 10 spaces, smaller negative spacing");
- // Line Spacing
- TestLineSpacing(lyshine, "default-ui", 32.0f, "Hi\nHello", 1, 5.0f, "one newline");
- TestLineSpacing(lyshine, "default-ui", 32.0f, "1\n2\n3\n4\n5", 4, 5.0f, "four newlines");
- TestLineSpacing(lyshine, "default-ui", 32.0f, "1\n2\n3\n4\n5\n6\n7\n8", 7, 8.3f, "seven newlines, larger spacing");
- TestLineSpacing(lyshine, "default-ui", 32.0f, "1\n2", 1, -1.0f, "one newline, negative spacing");
- TestLineSpacing(lyshine, "default-ui", 32.0f, "1\n2\n3\n4", 3, -2.2f, "three newlines, negative spacing, larger spacing");
- TestLineSpacing(lyshine, "default-ui", 18.0f, "1\n2", 1, 1.0f, "one newlines, smaller font");
- TestLineSpacing(lyshine, "default-ui", 18.0f, "1\n2\n3\n4\n5", 4, 1.0f, "four newlines, smaller font");
- TestLineSpacing(lyshine, "default-ui", 64.0f, "1\n2", 1, 1.0f, "one newlines, larger font");
- TestLineSpacing(lyshine, "default-ui", 64.0f, "1\n2\n3\n4\n5", 4, 1.0f, "four newlines, larger font");
- TestLineSpacing(lyshine, "default", 16.0f, "1\n2\n3\n4\n5", 4, 1.0f, "four newlines, default (mono) font");
- TestLineSpacing(lyshine, "notosans-regular", 20.0f, "1\n2\n3\n4\n5", 4, 1.0f, "four newlines, notosans font");
- }
- void ComponentGetSetTextTests(CLyShine* lyshine)
- {
- {
- AZ::EntityId canvasEntityId = lyshine->CreateCanvas();
- UiCanvasInterface* canvas = UiCanvasBus::FindFirstHandler(canvasEntityId);
- AZ_Assert(canvas, "Test failed");
- AZ::Entity* testElem = canvas->CreateChildElement("Test1");
- AZ_Assert(testElem, "Test failed");
- CreateComponent(testElem, LyShine::UiTransform2dComponentUuid);
- CreateComponent(testElem, LyShine::UiTextComponentUuid);
- AZ::EntityId testElemId = testElem->GetId();
- const AZStd::string testString("Hi");
- UiTextBus::Event(testElemId, &UiTextBus::Events::SetText, testString);
- AZStd::string resultString;
- UiTextBus::EventResult(resultString, testElemId, &UiTextBus::Events::GetText);
- AZ_Assert(testString == resultString, "Test failed");
- resultString.clear();
- UiTextBus::EventResult(resultString, testElemId, &UiTextBus::Events::GetTextWithFlags, UiTextInterface::GetTextFlags::GetAsIs);
- AZ_Assert(testString == resultString, "Test failed");
- lyshine->ReleaseCanvas(canvasEntityId, false);
- }
- {
- AZ::EntityId canvasEntityId = lyshine->CreateCanvas();
- UiCanvasInterface* canvas = UiCanvasBus::FindFirstHandler(canvasEntityId);
- AZ_Assert(canvas, "Test failed");
- AZ::Entity* testElem = canvas->CreateChildElement("Test1");
- AZ_Assert(testElem, "Test failed");
- CreateComponent(testElem, LyShine::UiTransform2dComponentUuid);
- CreateComponent(testElem, LyShine::UiTextComponentUuid);
- AZ::EntityId testElemId = testElem->GetId();
- const AZStd::string testString("Hi");
- UiTextBus::Event(testElemId, &UiTextBus::Events::SetTextWithFlags, testString, UiTextInterface::SetAsIs);
- AZStd::string resultString;
- UiTextBus::EventResult(resultString, testElemId, &UiTextBus::Events::GetText);
- AZ_Assert(testString == resultString, "Test failed");
- resultString.clear();
- UiTextBus::EventResult(resultString, testElemId, &UiTextBus::Events::GetTextWithFlags, UiTextInterface::GetTextFlags::GetAsIs);
- AZ_Assert(testString == resultString, "Test failed");
- lyshine->ReleaseCanvas(canvasEntityId, false);
- }
- {
- AZ::EntityId canvasEntityId = lyshine->CreateCanvas();
- UiCanvasInterface* canvas = UiCanvasBus::FindFirstHandler(canvasEntityId);
- AZ_Assert(canvas, "Test failed");
- AZ::Entity* testElem = canvas->CreateChildElement("Test1");
- AZ_Assert(testElem, "Test failed");
- CreateComponent(testElem, LyShine::UiTransform2dComponentUuid);
- CreateComponent(testElem, LyShine::UiTextComponentUuid);
- AZ::EntityId testElemId = testElem->GetId();
- const AZStd::string testString("&<>%");
- UiTextBus::Event(testElemId, &UiTextBus::Events::SetTextWithFlags, testString, UiTextInterface::SetAsIs);
- AZStd::string resultString;
- UiTextBus::EventResult(resultString, testElemId, &UiTextBus::Events::GetText);
- AZ_Assert(testString == resultString, "Test failed");
- resultString.clear();
- UiTextBus::EventResult(resultString, testElemId, &UiTextBus::Events::GetTextWithFlags, UiTextInterface::GetTextFlags::GetAsIs);
- AZ_Assert(testString == resultString, "Test failed");
- lyshine->ReleaseCanvas(canvasEntityId, false);
- }
- {
- AZ::EntityId canvasEntityId = lyshine->CreateCanvas();
- UiCanvasInterface* canvas = UiCanvasBus::FindFirstHandler(canvasEntityId);
- AZ_Assert(canvas, "Test failed");
- AZ::Entity* testElem = canvas->CreateChildElement("Test1");
- AZ_Assert(testElem, "Test failed");
- CreateComponent(testElem, LyShine::UiTransform2dComponentUuid);
- CreateComponent(testElem, LyShine::UiTextComponentUuid);
- AZ::EntityId testElemId = testElem->GetId();
- const AZStd::string testString("&<>%");
- UiTextBus::Event(testElemId, &UiTextBus::Events::SetTextWithFlags, testString, UiTextInterface::SetAsIs);
- AZStd::string resultString;
- UiTextBus::EventResult(resultString, testElemId, &UiTextBus::Events::GetText);
- AZ_Assert(testString == resultString, "Test failed");
- resultString.clear();
- UiTextBus::EventResult(resultString, testElemId, &UiTextBus::Events::GetTextWithFlags, UiTextInterface::GetTextFlags::GetAsIs);
- AZ_Assert(testString == resultString, "Test failed");
- lyshine->ReleaseCanvas(canvasEntityId, false);
- }
- {
- AZ::EntityId canvasEntityId = lyshine->CreateCanvas();
- UiCanvasInterface* canvas = UiCanvasBus::FindFirstHandler(canvasEntityId);
- AZ_Assert(canvas, "Test failed");
- AZ::Entity* testElem = canvas->CreateChildElement("Test1");
- AZ_Assert(testElem, "Test failed");
- CreateComponent(testElem, LyShine::UiTransform2dComponentUuid);
- CreateComponent(testElem, LyShine::UiTextComponentUuid);
- AZ::EntityId testElemId = testElem->GetId();
- const AZStd::string testString("&<>%");
- UiTextBus::Event(testElemId, &UiTextBus::Events::SetTextWithFlags, testString, UiTextInterface::SetEscapeMarkup);
- AZStd::string resultString;
- UiTextBus::EventResult(resultString, testElemId, &UiTextBus::Events::GetText);
- AZ_Assert(testString == resultString, "Test failed");
- resultString.clear();
- UiTextBus::EventResult(resultString, testElemId, &UiTextBus::Events::GetTextWithFlags, UiTextInterface::GetTextFlags::GetAsIs);
- AZ_Assert(testString == resultString, "Test failed");
- lyshine->ReleaseCanvas(canvasEntityId, false);
- }
- }
- void ComponentGetSetTextTestsLoc(CLyShine* lyshine)
- {
- if (AZStd::string("korean") == GetISystem()->GetLocalizationManager()->GetLanguage())
- {
- static const LyShine::StringType koreanHello("\xEC\x95\x88\xEB\x85\x95\xED\x95\x98\xEC\x84\xB8\xEC\x9A\x94");
- // Tests: Get/SetText with localization
- {
- AZ::EntityId canvasEntityId = lyshine->CreateCanvas();
- UiCanvasInterface* canvas = UiCanvasBus::FindFirstHandler(canvasEntityId);
- AZ_Assert(canvas, "Test failed");
- AZ::Entity* testElem = canvas->CreateChildElement("Test1");
- AZ_Assert(testElem, "Test failed");
- CreateComponent(testElem, LyShine::UiTransform2dComponentUuid);
- CreateComponent(testElem, LyShine::UiTextComponentUuid);
- AZ::EntityId testElemId = testElem->GetId();
- // Verify that GetText and GetAsIs returns the unlocalized key "@ui_Hello"
- {
- AZStd::string testString("@ui_Hello");
- UiTextBus::Event(testElemId, &UiTextBus::Events::SetTextWithFlags, testString, UiTextInterface::SetLocalized);
- AZStd::string resultString;
- UiTextBus::EventResult(resultString, testElemId, &UiTextBus::Events::GetText);
- AZ_Assert(testString == resultString, "Test failed");
- resultString.clear();
- UiTextBus::EventResult(
- resultString, testElemId, &UiTextBus::Events::GetTextWithFlags, UiTextInterface::GetTextFlags::GetAsIs);
- AZ_Assert(testString == resultString, "Test failed");
- resultString.clear();
- }
- // Verify that passing GetLocalized to GetTextWithFlags returns the localized content of "@ui_Hello"
- {
- AZStd::string testString = koreanHello;
- AZStd::string resultString;
- UiTextBus::EventResult(resultString, testElemId, &UiTextBus::Events::GetTextWithFlags, UiTextInterface::GetLocalized);
- AZ_Assert(testString == resultString, "Test failed");
- resultString.clear();
- }
- lyshine->ReleaseCanvas(canvasEntityId, false);
- }
- // Tests: Get/SetText with localization and escaping markup
- {
- AZ::EntityId canvasEntityId = lyshine->CreateCanvas();
- UiCanvasInterface* canvas = UiCanvasBus::FindFirstHandler(canvasEntityId);
- AZ_Assert(canvas, "Test failed");
- AZ::Entity* testElem = canvas->CreateChildElement("Test1");
- AZ_Assert(testElem, "Test failed");
- CreateComponent(testElem, LyShine::UiTransform2dComponentUuid);
- CreateComponent(testElem, LyShine::UiTextComponentUuid);
- AZ::EntityId testElemId = testElem->GetId();
- // Verify that GetText and GetAsIs returns the unlocalized key "@ui_Hello" along
- // with the original (escaped) markup characters
- {
- AZStd::string testString("&<>% @ui_Hello");
- UiTextInterface::SetTextFlags setTextFlags = static_cast<UiTextInterface::SetTextFlags>(UiTextInterface::SetEscapeMarkup | UiTextInterface::SetLocalized);
- UiTextBus::Event(testElemId, &UiTextBus::Events::SetTextWithFlags, testString, setTextFlags);
- AZStd::string resultString;
- UiTextBus::EventResult(resultString, testElemId, &UiTextBus::Events::GetText);
- AZ_Assert(testString == resultString, "Test failed");
- resultString.clear();
- UiTextBus::EventResult(
- resultString, testElemId, &UiTextBus::Events::GetTextWithFlags, UiTextInterface::GetTextFlags::GetAsIs);
- AZ_Assert(testString == resultString, "Test failed");
- resultString.clear();
- }
- // Verify that passing GetLocalized to GetTextWithFlags returns the localized content of "@ui_Hello"
- // along with the original (escaped) markup characters in the string
- {
- AZStd::string testString = LyShine::StringType("&<>% ") + koreanHello;
- AZStd::string resultString;
- UiTextBus::EventResult(resultString, testElemId, &UiTextBus::Events::GetTextWithFlags, UiTextInterface::GetLocalized);
- AZ_Assert(testString == resultString, "Test failed");
- resultString.clear();
- }
- lyshine->ReleaseCanvas(canvasEntityId, false);
- }
- // Tests: Setting localized text with abutting invalid localization key chars
- //
- // Purpose: localization tokens appear in strings surrounded by characters that
- // shouldn't be part of the localization key.
- //
- // For example:
- // "@ui_Hello, @ui_Welcome!"
- //
- // This should only consider "@ui_Hello" and "@ui_Hello" for localization. The
- // abutting punctuation characters - comma, exclamation point - should not be
- // considered as part of the localization key.
- //
- // Markup example:
- // "<font color="#FF0000">@ui_DeathStatus</font>"
- //
- // The end font-tag text ("</font>") following the loc key "@ui_DeathStatus" should
- // not be considered for localization.
- //
- // Abutting loc keys example:
- // "@ui_item1@ui_item2"
- //
- // There are two loc keys in the above example and should be localized independently
- // of each other..
- {
- AZ::EntityId canvasEntityId = lyshine->CreateCanvas();
- UiCanvasInterface* canvas = UiCanvasBus::FindFirstHandler(canvasEntityId);
- AZ_Assert(canvas, "Test failed");
- AZ::Entity* testElem = canvas->CreateChildElement("Test1");
- AZ_Assert(testElem, "Test failed");
- CreateComponent(testElem, LyShine::UiTransform2dComponentUuid);
- CreateComponent(testElem, LyShine::UiTextComponentUuid);
- AZ::EntityId testElemId = testElem->GetId();
- // Verify that localizing keys won't consider punctuation as part
- // of the localization key.
- {
- AZStd::string testString("@ui_Hello, @ui_Hello!");
- UiTextInterface::SetTextFlags setTextFlags = static_cast<UiTextInterface::SetTextFlags>(UiTextInterface::SetLocalized);
- UiTextBus::Event(testElemId, &UiTextBus::Events::SetTextWithFlags, testString, setTextFlags);
- testString = koreanHello + ", " + koreanHello + "!";
- AZStd::string resultString;
- UiTextBus::EventResult(resultString, testElemId, &UiTextBus::Events::GetTextWithFlags, UiTextInterface::GetLocalized);
- AZ_Assert(testString == resultString, "Test failed");
- }
- // Verify that localizing keys won't consider markup as part
- // of the localization key.
- {
- AZStd::string testString("<font color=\"#FF0000\">@ui_Hello</font>");
- UiTextInterface::SetTextFlags setTextFlags = static_cast<UiTextInterface::SetTextFlags>(UiTextInterface::SetLocalized);
- UiTextBus::Event(testElemId, &UiTextBus::Events::SetTextWithFlags, testString, setTextFlags);
- testString = LyShine::StringType("<font color=\"#FF0000\">") + koreanHello + "</font>";
- AZStd::string resultString;
- UiTextBus::EventResult(resultString, testElemId, &UiTextBus::Events::GetTextWithFlags, UiTextInterface::GetLocalized);
- AZ_Assert(testString == resultString, "Test failed");
- }
- // Verify that localizing adjacent keys will localize the keys separately
- // and not consider them to be one single key
- {
- AZStd::string testString("@ui_Hello@ui_Hello");
- UiTextInterface::SetTextFlags setTextFlags = static_cast<UiTextInterface::SetTextFlags>(UiTextInterface::SetLocalized);
- UiTextBus::Event(testElemId, &UiTextBus::Events::SetTextWithFlags, testString, setTextFlags);
- testString = koreanHello + koreanHello;
- AZStd::string resultString;
- UiTextBus::EventResult(resultString, testElemId, &UiTextBus::Events::GetTextWithFlags, UiTextInterface::GetLocalized);
- AZ_Assert(testString == resultString, "Test failed");
- }
- lyshine->ReleaseCanvas(canvasEntityId, false);
- }
- }
- }
- // This tests for whether or not the MarkupFlag is functioning properly
- void MarkupFlagTest(CLyShine* lyshine)
- {
- AZ::EntityId canvasEntityId = lyshine->CreateCanvas();
- UiCanvasInterface* canvas = UiCanvasBus::FindFirstHandler(canvasEntityId);
- AZ_Assert(canvas, "Test failed");
- AZ::Entity* testElem = canvas->CreateChildElement("Test1");
- AZ_Assert(testElem, "Test failed");
- CreateComponent(testElem, LyShine::UiTransform2dComponentUuid);
- CreateComponent(testElem, LyShine::UiTextComponentUuid);
- AZ::EntityId testElemId = testElem->GetId();
- UiTextBus::Event(testElemId, &UiTextBus::Events::SetText, "<font color=\"red\"> </font>");
- bool enabled(true);
- AZ::Vector2 NewSize(0, 0);
- // Sizes expected based on the default font
- AZ::Vector2 MarkUpEnabledSize(8, 32);
- AZ::Vector2 MarkUpDisabledSize(354, 32);
- // Test that markup is disabled by default.
- UiTextBus::EventResult(enabled, testElemId, &UiTextBus::Events::GetIsMarkupEnabled);
- AZ_Assert(!enabled, "Test failed");
- // Test that setting it to false when it is already false, does not set it to true.
- UiTextBus::Event(testElemId, &UiTextBus::Events::SetIsMarkupEnabled, false);
- UiTextBus::EventResult(enabled, testElemId, &UiTextBus::Events::GetIsMarkupEnabled);
- AZ_Assert(!enabled, "Test failed");
- // Check that the flag is actually disabled by checking the size of the textbox
- UiTextBus::EventResult(NewSize, testElemId, &UiTextBus::Events::GetTextSize);
- AZ_Assert(NewSize == MarkUpDisabledSize, "Test failed");
- // Test that setting it to true when it is false, sets it to true
- UiTextBus::Event(testElemId, &UiTextBus::Events::SetIsMarkupEnabled, true);
- UiTextBus::EventResult(enabled, testElemId, &UiTextBus::Events::GetIsMarkupEnabled);
- AZ_Assert(enabled, "Test failed");
- // Check that the flag is actually enabled by checking the size of the textbox
- UiTextBus::EventResult(NewSize, testElemId, &UiTextBus::Events::GetTextSize);
- AZ_Assert(NewSize == MarkUpEnabledSize, "Test failed");
- // Test that setting it to true when it is true, does not set it to false
- UiTextBus::Event(testElemId, &UiTextBus::Events::SetIsMarkupEnabled, true);
- UiTextBus::EventResult(enabled, testElemId, &UiTextBus::Events::GetIsMarkupEnabled);
- AZ_Assert(enabled, "Test failed");
- // Check that the flag is actually enabled by checking the size of the textbox
- UiTextBus::EventResult(NewSize, testElemId, &UiTextBus::Events::GetTextSize);
- AZ_Assert(NewSize == MarkUpEnabledSize, "Test failed");
- // Test that setting it to false when it is true, properly sets it to false.
- UiTextBus::Event(testElemId, &UiTextBus::Events::SetIsMarkupEnabled, false);
- UiTextBus::EventResult(enabled, testElemId, &UiTextBus::Events::GetIsMarkupEnabled);
- AZ_Assert(!enabled, "Test failed");
- // Check that the flag is actually disabled by checking the size of the textbox
- UiTextBus::EventResult(NewSize, testElemId, &UiTextBus::Events::GetTextSize);
- AZ_Assert(NewSize == MarkUpDisabledSize, "Test failed");
- lyshine->ReleaseCanvas(canvasEntityId, false);
- }
- }
- void FontSharedPtrTests()
- {
- // Verify test font isn't loaded
- {
- const char* fontName = "notosans-regular";
- AZ_Assert(nullptr == GetISystem()->GetICryFont()->GetFont(fontName), "Test failed");
- }
- // Basic font load and unload
- {
- const char* fontName = "notosans-regular";
- IFFont* font = GetISystem()->GetICryFont()->NewFont(fontName);
- AZ_Assert(font, "Test failed");
- AZ_Assert(font == GetISystem()->GetICryFont()->GetFont(fontName), "Test failed");
- const bool loadSuccess = font->Load("ui/fonts/lyshineexamples/notosans/notosans-regular.font");
- AZ_Assert(loadSuccess, "Test failed");
- font->AddRef();
- AZ_Assert(1 == font->Release(), "Test failed");
- AZ_Assert(0 == font->Release(), "Test failed");
- AZ_Assert(nullptr == GetISystem()->GetICryFont()->GetFont(fontName), "Test failed");
- }
- // Font and font family case sensitivity checks
- {
- // IFFont case sensitivity checks
- {
- const char* fontName = "notosans-regular";
- const char* fontNameUpper = "NOTOSANS-REGULAR";
- const char* fontNameMixed1 = "Notosans-regular";
- const char* fontNameMixed2 = "Notosans-Regular";
- const char* fontNameMixed3 = "NoToSaNs-ReGuLaR";
- IFFont* const font = GetISystem()->GetICryFont()->NewFont(fontName);
- AZ_Assert(font, "Test failed");
- AZ_Assert(2 == font->AddRef(), "Test failed");
- AZ_Assert(1 == font->Release(), "Test failed");
- // Verify that creating a new font for a font that's already created returns
- // that same font
- AZ_Assert(font == GetISystem()->GetICryFont()->NewFont(fontName), "Test failed");
- AZ_Assert(font == GetISystem()->GetICryFont()->NewFont(fontNameUpper), "Test failed");
- AZ_Assert(font == GetISystem()->GetICryFont()->NewFont(fontNameMixed1), "Test failed");
- AZ_Assert(font == GetISystem()->GetICryFont()->NewFont(fontNameMixed2), "Test failed");
- AZ_Assert(font == GetISystem()->GetICryFont()->NewFont(fontNameMixed3), "Test failed");
- // Getting the font with the expected name returns the same font
- AZ_Assert(font == GetISystem()->GetICryFont()->GetFont(fontName), "Test failed");
- AZ_Assert(font == GetISystem()->GetICryFont()->GetFont(fontNameUpper), "Test failed");
- AZ_Assert(font == GetISystem()->GetICryFont()->GetFont(fontNameMixed1), "Test failed");
- AZ_Assert(font == GetISystem()->GetICryFont()->GetFont(fontNameMixed2), "Test failed");
- AZ_Assert(font == GetISystem()->GetICryFont()->GetFont(fontNameMixed3), "Test failed");
- // Release the font
- AZ_Assert(0 == font->Release(), "Test failed");
- }
- // FontFamily case sensitivity checks
- {
- const char* notoSansFontFamily = "ui/fonts/lyshineexamples/notosans/notosans.fontfamily";
- const char* notoSansName = "notosans";
- // Shouldn't be loaded yet
- FontFamilyPtr fontFamily = gEnv->pCryFont->GetFontFamily(notoSansFontFamily);
- AZ_Assert(!fontFamily.get(), "Test failed");
- fontFamily = gEnv->pCryFont->GetFontFamily(notoSansName);
- AZ_Assert(!fontFamily.get(), "Test failed");
- // Should load successfully
- fontFamily = gEnv->pCryFont->LoadFontFamily(notoSansFontFamily);
- AZ_Assert(fontFamily.get(), "Test failed");
- // GetFontFamily case-sensitivity tests by filepath
- {
- AZ_Assert(fontFamily == gEnv->pCryFont->GetFontFamily(notoSansFontFamily), "Test failed");
- const char* notoSansFontFamilyUpper = "UI/FONTS/LYSHINEEXAMPLES/NOTOSANS/NOTOSANS.FONTFAMILY";
- const char* notoSansFontFamilyMixed1 = "ui/fonts/lyshineexamples/notosans/Notosans.fontfamily";
- const char* notoSansFontFamilyMixed2 = "ui/fonts/lyshineexamples/notosans/Notosans.Fontfamily";
- const char* notoSansFontFamilyMixed3 = "ui/fonts/lyshineexamples/notosans/NotoSans.Fontfamily";
- const char* notoSansFontFamilyMixed4 = "ui/fonts/lyshineexamples/notosans/notosans.FONTFAMILY";
- const char* notoSansFontFamilyMixed5 = "ui/fonts/lyshineexamples/notosans/NOTOSANS.fontfamily";
- const char* notoSansFontFamilyMixed6 = "Ui/fonts/lyshineexamples/notosans/notosans.fontfamily";
- const char* notoSansFontFamilyMixed7 = "ui/fonts/lyshineexamples/Notosans/notosans.fontfamily";
- AZ_Assert(fontFamily == gEnv->pCryFont->GetFontFamily(notoSansFontFamilyUpper), "Test failed");
- AZ_Assert(fontFamily == gEnv->pCryFont->GetFontFamily(notoSansFontFamilyMixed1), "Test failed");
- AZ_Assert(fontFamily == gEnv->pCryFont->GetFontFamily(notoSansFontFamilyMixed2), "Test failed");
- AZ_Assert(fontFamily == gEnv->pCryFont->GetFontFamily(notoSansFontFamilyMixed3), "Test failed");
- AZ_Assert(fontFamily == gEnv->pCryFont->GetFontFamily(notoSansFontFamilyMixed4), "Test failed");
- AZ_Assert(fontFamily == gEnv->pCryFont->GetFontFamily(notoSansFontFamilyMixed5), "Test failed");
- AZ_Assert(fontFamily == gEnv->pCryFont->GetFontFamily(notoSansFontFamilyMixed6), "Test failed");
- AZ_Assert(fontFamily == gEnv->pCryFont->GetFontFamily(notoSansFontFamilyMixed7), "Test failed");
- }
- // GetFontFamily case-sensitivity tests by font name
- {
- AZ_Assert(fontFamily == gEnv->pCryFont->GetFontFamily(notoSansName), "Test failed");
- const char* notoSansNameUpper = "NOTOSANS";
- const char* notoSansNameMixed1 = "Notosans";
- const char* notoSansNameMixed2 = "NotoSans";
- AZ_Assert(fontFamily == gEnv->pCryFont->GetFontFamily(notoSansNameUpper), "Test failed");
- AZ_Assert(fontFamily == gEnv->pCryFont->GetFontFamily(notoSansNameMixed1), "Test failed");
- AZ_Assert(fontFamily == gEnv->pCryFont->GetFontFamily(notoSansNameMixed2), "Test failed");
- }
- }
- }
- // Font family ref count test
- {
- const char* notoSansFontFamily = "ui/fonts/lyshineexamples/notosans/notosans.fontfamily";
- const char* notoSansRegularPath = "ui/fonts/lyshineexamples/notosans/notosans-regular.font";
- const char* notoSansItalicPath = "ui/fonts/lyshineexamples/notosans/notosans-italic.font";
- const char* notoSansBoldPath = "ui/fonts/lyshineexamples/notosans/notosans-bold.font";
- const char* notoSansBoldItalicPath = "ui/fonts/lyshineexamples/notosans/notosans-bolditalic.font";
- const char* notoSansRegular = "notosans-regular";
- const char* notoSansBold = "notosans-bold";
- const char* notoSansItalic = "notosans-italic";
- const char* notoSansBoldItalic = "notosans-boldItalic";
- {
- FontFamilyPtr notoSans = FontFamilyLoad(notoSansFontFamily);
- AZ_Assert(2 == notoSans->normal->AddRef(), "Test failed");
- AZ_Assert(1 == notoSans->normal->Release(), "Test failed");
- AZ_Assert(2 == notoSans->bold->AddRef(), "Test failed");
- AZ_Assert(1 == notoSans->bold->Release(), "Test failed");
- AZ_Assert(2 == notoSans->italic->AddRef(), "Test failed");
- AZ_Assert(1 == notoSans->italic->Release(), "Test failed");
- AZ_Assert(2 == notoSans->boldItalic->AddRef(), "Test failed");
- AZ_Assert(1 == notoSans->boldItalic->Release(), "Test failed");
- // This is a negative test which is difficult to support currently.
- // Uncommenting this line should trigger an assert in CryFont because
- // the font was de-allocated while still being referenced by a
- // FontFamily
- //notoSans->normal->Release();
- // Attempt to load FontFamily already loaded
- {
- FontFamilyPtr dupeFamily = GetISystem()->GetICryFont()->LoadFontFamily(notoSansFontFamily);
- AZ_Assert(nullptr == dupeFamily, "Test failed");
- //Ref counts should remain the same
- AZ_Assert(2 == notoSans->normal->AddRef(), "Test failed");
- AZ_Assert(1 == notoSans->normal->Release(), "Test failed");
- AZ_Assert(2 == notoSans->bold->AddRef(), "Test failed");
- AZ_Assert(1 == notoSans->bold->Release(), "Test failed");
- AZ_Assert(2 == notoSans->italic->AddRef(), "Test failed");
- AZ_Assert(1 == notoSans->italic->Release(), "Test failed");
- AZ_Assert(2 == notoSans->boldItalic->AddRef(), "Test failed");
- AZ_Assert(1 == notoSans->boldItalic->Release(), "Test failed");
- }
- IFFont* fontRegular = GetISystem()->GetICryFont()->GetFont(notoSansRegularPath);
- AZ_Assert(fontRegular, "Test failed");
- AZ_Assert(fontRegular == notoSans->normal, "Test failed");
- // Verify that ref counts are handled properly when font family
- // fonts are referenced outside of the font family.
- {
- // NewFont shouldn't increment ref count
- IFFont* checkFont = GetISystem()->GetICryFont()->NewFont(notoSansRegularPath);
- AZ_Assert(fontRegular == checkFont, "Test failed");
- AZ_Assert(2 == checkFont->AddRef(), "Test failed");
- AZ_Assert(1 == checkFont->Release(), "Test failed");
- // Load also doesn't increment ref count
- AZ_Assert(checkFont->Load(notoSansRegularPath), "Test failed");
- AZ_Assert(2 == checkFont->AddRef(), "Test failed");
- AZ_Assert(1 == checkFont->Release(), "Test failed");
- // If font is loaded as a Font Family, then ref counts will increment
- FontFamilyPtr notoSansRegularFamily = FontFamilyLoad(notoSansRegularPath);
- // Verify that every font of the single-font font family are the same
- AZ_Assert(notoSansRegularFamily->normal == notoSansRegularFamily->bold, "Test failed");
- AZ_Assert(notoSansRegularFamily->bold == notoSansRegularFamily->italic, "Test failed");
- AZ_Assert(notoSansRegularFamily->italic == notoSansRegularFamily->boldItalic, "Test failed");
- // Verify that the single-font is the same font in the original font family
- AZ_Assert(notoSansRegularFamily->normal == notoSans->normal, "Test failed");
- // Check "single font as a font family" ref counts
- AZ_Assert(6 == notoSansRegularFamily->normal->AddRef(), "Test failed");
- AZ_Assert(5 == notoSansRegularFamily->normal->Release(), "Test failed");
- AZ_Assert(6 == notoSansRegularFamily->bold->AddRef(), "Test failed");
- AZ_Assert(5 == notoSansRegularFamily->bold->Release(), "Test failed");
- AZ_Assert(6 == notoSansRegularFamily->italic->AddRef(), "Test failed");
- AZ_Assert(5 == notoSansRegularFamily->italic->Release(), "Test failed");
- AZ_Assert(6 == notoSansRegularFamily->boldItalic->AddRef(), "Test failed");
- AZ_Assert(5 == notoSansRegularFamily->boldItalic->Release(), "Test failed");
- // Check ref counts of the original font family
- AZ_Assert(6 == notoSans->normal->AddRef(), "Test failed");
- AZ_Assert(5 == notoSans->normal->Release(), "Test failed");
- AZ_Assert(2 == notoSans->bold->AddRef(), "Test failed");
- AZ_Assert(1 == notoSans->bold->Release(), "Test failed");
- AZ_Assert(2 == notoSans->italic->AddRef(), "Test failed");
- AZ_Assert(1 == notoSans->italic->Release(), "Test failed");
- AZ_Assert(2 == notoSans->boldItalic->AddRef(), "Test failed");
- AZ_Assert(1 == notoSans->boldItalic->Release(), "Test failed");
- // Attempt to load single-font font-family again
- {
- FontFamilyPtr dupeFamily = GetISystem()->GetICryFont()->LoadFontFamily(notoSansRegularPath);
- AZ_Assert(nullptr == dupeFamily, "Test failed");
- //Ref counts should remain the same
- AZ_Assert(6 == notoSansRegularFamily->normal->AddRef(), "Test failed");
- AZ_Assert(5 == notoSansRegularFamily->normal->Release(), "Test failed");
- AZ_Assert(6 == notoSansRegularFamily->bold->AddRef(), "Test failed");
- AZ_Assert(5 == notoSansRegularFamily->bold->Release(), "Test failed");
- AZ_Assert(6 == notoSansRegularFamily->italic->AddRef(), "Test failed");
- AZ_Assert(5 == notoSansRegularFamily->italic->Release(), "Test failed");
- AZ_Assert(6 == notoSansRegularFamily->boldItalic->AddRef(), "Test failed");
- AZ_Assert(5 == notoSansRegularFamily->boldItalic->Release(), "Test failed");
- }
- }
- // BEGIN JAV_LY_FORK: r_persistFontFamilies keeps font families loaded for lifetime of application.
- // In this case, the normal/regular font has already been loaded as a "pass through" font family,
- // so it has been persisted in memory. Even though the FontFamilyPtr used has gone out of scope.
- // notoSansRegularFamily should now be out of scope, so the original font family's
- // ref counts should return to their original values
- {
- AZ_Assert(6 == notoSans->normal->AddRef(), "Test failed");
- AZ_Assert(5 == notoSans->normal->Release(), "Test failed");
- AZ_Assert(2 == notoSans->bold->AddRef(), "Test failed");
- AZ_Assert(1 == notoSans->bold->Release(), "Test failed");
- AZ_Assert(2 == notoSans->italic->AddRef(), "Test failed");
- AZ_Assert(1 == notoSans->italic->Release(), "Test failed");
- AZ_Assert(2 == notoSans->boldItalic->AddRef(), "Test failed");
- AZ_Assert(1 == notoSans->boldItalic->Release(), "Test failed");
- }
- // Reference a FontFamily already loaded
- {
- FontFamilyPtr dupeFamily = GetISystem()->GetICryFont()->GetFontFamily("notosans");
- // Ref couts for underlying fonts should stay the same
- AZ_Assert(6 == notoSans->normal->AddRef(), "Test failed");
- AZ_Assert(5 == notoSans->normal->Release(), "Test failed");
- AZ_Assert(2 == notoSans->bold->AddRef(), "Test failed");
- AZ_Assert(1 == notoSans->bold->Release(), "Test failed");
- AZ_Assert(2 == notoSans->italic->AddRef(), "Test failed");
- AZ_Assert(1 == notoSans->italic->Release(), "Test failed");
- AZ_Assert(2 == notoSans->boldItalic->AddRef(), "Test failed");
- AZ_Assert(1 == notoSans->boldItalic->Release(), "Test failed");
- }
- // END JAV_LY_FORK
- IFFont* fontBold = GetISystem()->GetICryFont()->GetFont(notoSansBoldPath);
- AZ_Assert(fontBold, "Test failed");
- AZ_Assert(fontBold == notoSans->bold, "Test failed");
- IFFont* fontItalic = GetISystem()->GetICryFont()->GetFont(notoSansItalicPath);
- AZ_Assert(fontItalic, "Test failed");
- AZ_Assert(fontItalic == notoSans->italic, "Test failed");
- IFFont* fontBoldItalic = GetISystem()->GetICryFont()->GetFont(notoSansBoldItalicPath);
- AZ_Assert(fontBoldItalic, "Test failed");
- AZ_Assert(fontBoldItalic == notoSans->boldItalic, "Test failed");
- }
- // Once FontFamilyPtr goes out of scope, all associated font family
- // fonts should get unloaded too.
- IFFont* fontRegular = GetISystem()->GetICryFont()->GetFont(notoSansRegular);
- AZ_Assert(!fontRegular, "Test failed");
- IFFont* fontBold = GetISystem()->GetICryFont()->GetFont(notoSansBold);
- AZ_Assert(!fontBold, "Test failed");
- IFFont* fontItalic = GetISystem()->GetICryFont()->GetFont(notoSansItalic);
- AZ_Assert(!fontItalic, "Test failed");
- IFFont* fontBoldItalic = GetISystem()->GetICryFont()->GetFont(notoSansBoldItalic);
- AZ_Assert(!fontBoldItalic, "Test failed");
- }
- // Load Vera.font as a font family, then load Vera.fontfamily that also
- // uses Vera.font as a font
- {
- const char* veraFontFile = "fonts/vera.font";
- FontFamilyPtr veraFont = gEnv->pCryFont->LoadFontFamily(veraFontFile);
- AZ_Assert(veraFont.get(), "Test failed");
- // Verify that vera.font has been referenced 4 times for all four
- // font styles in the font family markup (single fonts loaded as
- // font families get re-used for each of the font styles)
- AZ_Assert(5 == veraFont->normal->AddRef(), "Test failed");
- AZ_Assert(4 == veraFont->normal->Release(), "Test failed");
- AZ_Assert(5 == veraFont->bold->AddRef(), "Test failed");
- AZ_Assert(4 == veraFont->bold->Release(), "Test failed");
- AZ_Assert(5 == veraFont->italic->AddRef(), "Test failed");
- AZ_Assert(4 == veraFont->italic->Release(), "Test failed");
- AZ_Assert(5 == veraFont->boldItalic->AddRef(), "Test failed");
- AZ_Assert(4 == veraFont->boldItalic->Release(), "Test failed");
- const char* veraFontFamilyFile = "fonts/vera.fontfamily";
- FontFamilyPtr veraFontFamily = gEnv->pCryFont->LoadFontFamily(veraFontFamilyFile);
- // BEGIN JAV_LY_FORK: The above "vera.font" is a pass-through font (not a font family)
- // and is now mapped by by its full filepath rather than just the filename.
- AZ_Assert(veraFontFamily.get(), "Test failed");
- // The vera font family uses vera.font for its regular-weighted font,
- // so the ref count for vera.font increases by one, from 4 to 5.
- AZ_Assert(6 == veraFont->normal->AddRef(), "Test failed");
- AZ_Assert(5 == veraFont->normal->Release(), "Test failed");
- AZ_Assert(6 == veraFont->bold->AddRef(), "Test failed");
- AZ_Assert(5 == veraFont->bold->Release(), "Test failed");
- AZ_Assert(6 == veraFont->italic->AddRef(), "Test failed");
- AZ_Assert(5 == veraFont->italic->Release(), "Test failed");
- AZ_Assert(6 == veraFont->boldItalic->AddRef(), "Test failed");
- AZ_Assert(5 == veraFont->boldItalic->Release(), "Test failed");
- // END JAV_LY_FORK
- }
- }
- void UiTextComponent::UnitTest(CLyShine* lyshine, IConsoleCmdArgs* cmdArgs)
- {
- const bool testsRunningAtStartup = cmdArgs == nullptr;
- if (testsRunningAtStartup)
- {
- FontSharedPtrTests();
- }
- else
- {
- // These tests assume the unit-tests run at startup in order for ref count
- // values to make sense.
- AZ_Warning("LyShine", false,
- "Unit-tests: skipping FontSharedPtrTests due to tests running "
- "ad-hoc. Run unit tests at startup for full coverage. See ui_RunUnitTestsOnStartup.");
- }
- VerifyShippingFonts();
- // These fonts are required for subsequent unit-tests to work.
- FontFamilyPtr notoSans = FontFamilyLoad("ui/fonts/lyshineexamples/notosans/notosans.fontfamily");
- FontFamilyPtr notoSerif = FontFamilyLoad("ui/fonts/lyshineexamples/notoserif/notoserif.fontfamily");
- NewlineSanitizeTests();
- BuildDrawBatchesTests(notoSans.get());
- WrapTextTests(notoSans.get());
- BatchLinesTests(notoSans.get());
- TrackingLeadingTests(lyshine);
- ComponentGetSetTextTests(lyshine);
- MarkupFlagTest(lyshine);
- }
- void UiTextComponent::UnitTestLocalization(CLyShine* lyshine, IConsoleCmdArgs* /* cmdArgs */)
- {
- ILocalizationManager* pLocMan = GetISystem()->GetLocalizationManager();
- AZStd::string localizationXml("libs/localization/localization.xml");
- if (!pLocMan || !pLocMan->InitLocalizationData(localizationXml.c_str()) || !pLocMan->LoadLocalizationDataByTag("init"))
- {
- AZ_Assert(false, "Failed to load localization");
- }
- ComponentGetSetTextTestsLoc(lyshine);
- }
- #endif
|