-- [[ FonZii by Tillï-Draenor ]]

local fontPath = [[Interface\AddOns\FonZii\BarlowCondensed-Bold.ttf]]

local function Apply()
    -- Direct Engine Overrides: High-level variables (Safe)
    STANDARD_TEXT_FONT = fontPath
    DAMAGE_TEXT_FONT = fontPath
    CHATTING_FONT = fontPath
    
    -- Classic/SoD Compatibility
    if WOW_PROJECT_ID ~= WOW_PROJECT_MAINLINE then
        UIDROPDOWNMENU_DEFAULT_TEXT_FONT = fontPath
        NAMEPLATE_SPELL_CAST_FONT = fontPath
        FRIENDS_FONT = fontPath 
        MORPHEUS_FONT = fontPath 
    end

    -- Targeted UI Whitelist: Only touches specific interface frames.
    -- This prevents the code from touching 3D NPC anchors.
    local uiFonts = {
        "SystemFont_Shadow_Huge1", "SystemFont_Shadow_Large", "SystemFont_Shadow_Med1",
        "SystemFont_Shadow_Med3", "SystemFont_Med1", "SystemFont_Med3",
        "QuestFont_Large", "QuestFont_Shadow_Huge", "QuestFont_Shadow_Small",
        "MailTextFontNormal", "NumberFont_Normal_Med", "GameFont_Gigantic",
        "GameFontNormalSmall", "GameFontHighlightSmall", "GameFontNormal",
        "GameFontHighlight", "GameFontNormalLarge", "GameFontHighlightLarge"
    }

    for _, fontName in ipairs(uiFonts) do
        local fontObj = _G[fontName]
        if fontObj and fontObj.SetFont then
            local _, size, flags = fontObj:GetFont()
            fontObj:SetFont(fontPath, size, flags)
        end
    end
end

local f = CreateFrame("Frame")
f:RegisterEvent("PLAYER_LOGIN")
f:SetScript("OnEvent", function()
    Apply()
    f:UnregisterAllEvents()
end)

if IsLoggedIn() then Apply() end