@@ -551,6 +551,92 @@ function Text.WOW_ZmienKody(message, target)
551551end
552552
553553-- Expand unit info and shape Arabic text for display in a FontString-like region.
554+ local textMeasureFrame
555+ local textMeasureFontString
556+
557+ local function normalizeFontPath (fontPath )
558+ if type (fontPath ) ~= " string" or fontPath == " " then return nil end
559+ return (fontPath :gsub (" /" , " \\ " ):lower ())
560+ end
561+
562+ local function isFont1 (fontPath )
563+ return normalizeFontPath (fontPath ) == normalizeFontPath (rawget (_G , " WOWTR_Font1" ))
564+ end
565+
566+ local function ensureTextMeasureFontString ()
567+ if textMeasureFontString then return textMeasureFontString end
568+ textMeasureFrame = CreateFrame (" Frame" , nil , UIParent )
569+ textMeasureFrame :SetSize (2048 , 256 )
570+ textMeasureFrame :Hide ()
571+ textMeasureFontString = textMeasureFrame :CreateFontString (nil , " ARTWORK" , " GameFontHighlight" )
572+ textMeasureFontString :SetPoint (" TOPLEFT" , textMeasureFrame , " TOPLEFT" , 0 , 0 )
573+ textMeasureFontString :SetJustifyH (" LEFT" )
574+ return textMeasureFontString
575+ end
576+
577+ local function measureFontLineHeight (fontPath , fontSize , fontFlags )
578+ if (not fontPath ) or (not fontSize ) then return nil end
579+ local fs = ensureTextMeasureFontString ()
580+ fs :SetWidth (2048 )
581+ if fs .SetSpacing then
582+ pcall (fs .SetSpacing , fs , 0 )
583+ end
584+ pcall (fs .SetFont , fs , fontPath , fontSize , fontFlags or " " )
585+ fs :SetText (" Hg" )
586+ local measuredHeight = fs :GetHeight ()
587+ if measuredHeight and measuredHeight > 0 then
588+ return measuredHeight
589+ end
590+ return nil
591+ end
592+
593+ local function resolveSpacingTarget (obj )
594+ if not obj then return nil end
595+ if obj .SetSpacing and obj .GetSpacing then
596+ return obj
597+ end
598+ if obj .Text and obj .Text .SetSpacing and obj .Text .GetSpacing then
599+ return obj .Text
600+ end
601+ if obj .GetRegions then
602+ local regions = { obj :GetRegions () }
603+ for _ , region in ipairs (regions ) do
604+ if region and region .GetObjectType and region :GetObjectType () == " FontString" and region .SetSpacing and region .GetSpacing then
605+ return region
606+ end
607+ end
608+ end
609+ return nil
610+ end
611+
612+ local function applyDynamicFontSpacing (obj , sourceFont , targetFont , fontSize , fontFlags )
613+ local spacingTarget = resolveSpacingTarget (obj )
614+ if not spacingTarget then return end
615+
616+ if spacingTarget .WoWAR_DefaultSpacing == nil then
617+ local ok , currentSpacing = pcall (spacingTarget .GetSpacing , spacingTarget )
618+ spacingTarget .WoWAR_DefaultSpacing = ok and currentSpacing or 0
619+ end
620+
621+ local defaultSpacing = spacingTarget .WoWAR_DefaultSpacing or 0
622+ local desiredSpacing = defaultSpacing
623+
624+ if isFont1 (targetFont ) then
625+ local spacingFromMetrics = 0
626+ local sourceLineHeight = measureFontLineHeight (sourceFont or targetFont , fontSize , fontFlags )
627+ local targetLineHeight = measureFontLineHeight (targetFont , fontSize , fontFlags )
628+ if sourceLineHeight and targetLineHeight and (targetLineHeight + 0.5 < sourceLineHeight ) then
629+ spacingFromMetrics = math.floor ((sourceLineHeight - targetLineHeight ) + 0.5 )
630+ end
631+ desiredSpacing = math.max (defaultSpacing , spacingFromMetrics + 2 )
632+ end
633+
634+ local ok , currentSpacing = pcall (spacingTarget .GetSpacing , spacingTarget )
635+ if (not ok ) or (not currentSpacing ) or (math.abs (currentSpacing - desiredSpacing ) > 0.1 ) then
636+ pcall (spacingTarget .SetSpacing , spacingTarget , desiredSpacing )
637+ end
638+ end
639+
554640function Text .ExpandUnitInfo (msg , OnObjectives , AR_obj , AR_font , AR_corr , AR_RIGHT )
555641 if (msg == nil ) then msg = " " end
556642 msg = Text .WOW_ZmienKody (msg )
@@ -559,18 +645,19 @@ function Text.ExpandUnitInfo(msg, OnObjectives, AR_obj, AR_font, AR_corr, AR_RIG
559645 msg = FixCurlyColorSpansForRTL (msg )
560646 local _font = WOWTR_Font2
561647 local AR_size = 13
648+ local _flags = " "
562649 if AR_obj .GetFont then
563- local ok , f , s = pcall (AR_obj .GetFont , AR_obj , " P" )
564- if ok and f then _font = f ; AR_size = s or AR_size else
565- ok , f , s = pcall (AR_obj .GetFont , AR_obj )
566- if ok and f then _font = f ; AR_size = s or AR_size end
650+ local ok , f , s , fl = pcall (AR_obj .GetFont , AR_obj , " P" )
651+ if ok and f then _font = f ; AR_size = s or AR_size ; _flags = fl or _flags else
652+ ok , f , s , fl = pcall (AR_obj .GetFont , AR_obj )
653+ if ok and f then _font = f ; AR_size = s or AR_size ; _flags = fl or _flags end
567654 end
568655 elseif AR_obj .GetRegions then
569656 local regions = { AR_obj :GetRegions () }
570657 for _ , v in pairs (regions ) do
571658 if (v .GetObjectType and v :GetObjectType () == " FontString" and v .GetFont ) then
572- local ok , f , s = pcall (v .GetFont , v )
573- if ok and f then _font = f ; AR_size = s or AR_size ; break end
659+ local ok , f , s , fl = pcall (v .GetFont , v )
660+ if ok and f then _font = f ; AR_size = s or AR_size ; _flags = fl or _flags ; break end
574661 end
575662 end
576663 end
@@ -614,6 +701,8 @@ function Text.ExpandUnitInfo(msg, OnObjectives, AR_obj, AR_font, AR_corr, AR_RIG
614701 msg = AS_ReverseAndPrepareLineText (msg , AR_obj :GetWidth () + _corr , AR_font or _font , AR_size )
615702 end
616703
704+ applyDynamicFontSpacing (AR_obj , _font , AR_font or _font , AR_size , _flags )
705+
617706 msg = Text .RestoreWoWSpecialCodes (msg , specialCodes )
618707 msg = (prefix or " " ) .. msg
619708 end
0 commit comments