--------------------------------------------------------------------------------
--  CLEARFONT BY KIRKBURN
--  v11000-1     28.03.06
--------------------------------------------------------------------------------
--  Home page:  http://ui.worldofwar.net/ui.php?id=1424
--  Rewritten for patch 1.10 - please report any errors you find!
--  For details on how to modify this file, refer to the official website
--------------------------------------------------------------------------------


--------------------------------------------------------------------------------
-- FUNCTION TO DETECT ADDONS FOR OVERRIDES
-- (by Iriel)
--------------------------------------------------------------------------------

local function CanSetFont(object) 
   return (type(object)=="table" 
	   and object.SetFont and object.IsObjectType 
	      and not object:IsObjectType("SimpleHTML")); 
end


--------------------------------------------------------------------------------
-- MAIN SECTION (OVERRIDES FONTS.XML)
-- Some of the overrides are unnecessary, but are included for future updates
-- The "inherits" lines are made up to help me remember what inherits what!
--------------------------------------------------------------------------------

ClearFont = CreateFrame("Frame", "ClearFont");

-- This needs to appear BEFORE you reference it, or it won't work right
local refRAID_CLASS_COLORS = nil;

-- Set up an OnEvent handler to re-apply font settings whenever Fonts.xml is overridden
ClearFont:SetScript("OnEvent",
		    function() 
		       if (event == "ADDON_LOADED") then
			  if (refRAID_CLASS_COLORS ~= RAID_CLASS_COLORS) then
			     ClearFont:ApplySystemFonts()
			  end
			  -- Apply addon fonts each time, just in case one of the supported addons is a load on demand addon
			  ClearFont:ApplyAddOnFonts();
		       end
		    end);
ClearFont:RegisterEvent("ADDON_LOADED");

-- Set up font locals for brevity later
local CLEAR_FONT_BASE = "Interface\\AddOns\\ClearFont\\Fonts\\";
local CLEAR_FONT = CLEAR_FONT_BASE .. "ClearFont.ttf";
local CLEAR_FONT_BOLD = CLEAR_FONT_BASE .. "ClearFontBold.ttf";
local CLEAR_FONT_ITALIC = CLEAR_FONT_BASE .. "ClearFontItalic.ttf";
local CLEAR_FONT_BOLDITALIC = CLEAR_FONT_BASE .. "ClearFontBoldItalic.ttf";
local CLEAR_FONT_NUMBER = CLEAR_FONT_BASE .. "ClearFontNumber.ttf";


--------------------------------------------------------------------------------
-- OVERRIDES
-- Subject to changes!
--------------------------------------------------------------------------------

function ClearFont:ApplyAddOnFonts()
   refRAID_CLASS_COLORS = RAID_CLASS_COLORS;


-- MonkeyQuest 2.1
--------------------------------------------------------------------------------

   if (CanSetFont(MonkeyQuestFont)) then 
      MonkeyQuestFont:SetFont(CLEAR_FONT, 12);
   end 

   if (CanSetFont(MonkeyQuestTitleFont)) then 
      MonkeyQuestTitleFont:SetFont(CLEAR_FONT, 14);
   end 


-- SCT 3.5.4 (Scrolling Combat Text)
--------------------------------------------------------------------------------

   if (CanSetFont(GameFontLarger)) then 
      GameFontLarger:SetFont(CLEAR_FONT, 24);
   end 


-- EngInventory 23.03.06
--------------------------------------------------------------------------------

   if (CanSetFont(EngInventory_BigFont)) then 
      EngInventory_BigFont:SetFont(CLEAR_FONT, 16);
   end 


-- TitanHonorPlus (TitanPanel 2.14.2)
--------------------------------------------------------------------------------

   if (CanSetFont(TitanHonorPlus_TipBuddy_TargetName_Text)) then 
      TitanHonorPlus_TipBuddy_TargetName_Text:SetFont(CLEAR_FONT, 12);
   end 


-- TipBuddy 2.09
--------------------------------------------------------------------------------

   if (CanSetFont(TBGameFontNormal)) then 
      TBGameFontNormal:SetFont(CLEAR_FONT, 11);
   end 

   if (CanSetFont(TBGameFontNormalSmall)) then 
      TBGameFontNormalSmall:SetFont(CLEAR_FONT, 8);
   end 

   if (CanSetFont(ToolTipBuddyTextOutline)) then 
      ToolTipBuddyTextOutline:SetFont(CLEAR_FONT, 15, "OUTLINE");
   end 

   if (CanSetFont(TB_TTGameFontNormalSmall)) then 
      TB_TTGameFontNormalSmall:SetFont(CLEAR_FONT, 10);
   end 

   if (CanSetFont(TB_TTGameFontNormalSmallHighlight)) then 
      TB_TTGameFontNormalSmall:SetFont(CLEAR_FONT, 10);
   end 


-- Discord
--------------------------------------------------------------------------------

   if (CanSetFont(DUF_TextBoxFont1)) then 
      DUF_TextBoxFont1:SetFont(CLEAR_FONT, 10);
   end 


-- SuperInspect
--------------------------------------------------------------------------------

   if (CanSetFont(SuperInspect_NameText)) then 
      SuperInspect_NameText:SetFont(CLEAR_FONT, 12);
   end 

   if (CanSetFont(SuperInspect_TitleText)) then 
      SuperInspect_TitleText:SetFont(CLEAR_FONT, 10);
   end 

   if (CanSetFont(SuperInspect_BonusesText)) then 
      SuperInspect_BonusesText:SetFont(CLEAR_FONT, 10);
   end 

   if (CanSetFont(SuperInspect_BonusesTextR)) then 
      SuperInspect_BonusesTextR:SetFont(CLEAR_FONT, 10);
   end 

   if (CanSetFont(SIDurabilityNumberFont)) then 
      SIDurabilityNumberFont:SetFont(CLEAR_FONT, 14, "OUTLINE");
   end 

   if (CanSetFont(SINumberFontNormal)) then 
      SINumberFontNormal:SetFont(CLEAR_FONT, 13, "THICKOUTLINE");
   end 

   if (CanSetFont(SuperInspect_ButtonText)) then 
      SuperInspect_ButtonText:SetFont(CLEAR_FONT, 11);
   end 

   if (CanSetFont(SuperInspect_HonorText)) then 
      SuperInspect_HonorText:SetFont(CLEAR_FONT, 10);
   end 

   if (CanSetFont(SuperInspect_HonorTextLarge)) then 
      SuperInspect_HonorTextLarge:SetFont(CLEAR_FONT, 12);
   end 

   if (CanSetFont(SuperInspect_HonorTextSmall)) then 
      SuperInspect_HonorTextSmall:SetFont(CLEAR_FONT, 9);
   end 

   if (CanSetFont(SuperInspect_HonorTextHighlightSmall)) then 
      SuperInspect_HonorTextHighlightSmall:SetFont(CLEAR_FONT, 9);
   end 

   if (CanSetFont(SuperInspect_ButtonTextHighlight)) then 
      SuperInspect_ButtonTextHighlight:SetFont(CLEAR_FONT, 11);
   end 

   if (CanSetFont(SuperInspect_ButtonTextDisable)) then 
      SuperInspect_ButtonTextDisable:SetFont(CLEAR_FONT, 11);
   end 


-- eCastingBar
--------------------------------------------------------------------------------

   if (CanSetFont(eCastingBarFont)) then 
      eCastingBarFont:SetFont(CLEAR_FONT, 12);
   end


-- BMRecLevel
--------------------------------------------------------------------------------

   if (CanSetFont(BMRecLevelWorldMapText)) then 
      BMRecLevelWorldMapText:SetFont(CLEAR_FONT, 10, "OUTLINE");
   end

end

function ClearFont:ApplySystemFonts()
   refRAID_CLASS_COLORS = RAID_CLASS_COLORS;



-- 3D Nameplates (above character heads), Damage Fonts (thanks Dark Imakuni)
--------------------------------------------------------------------------------

   STANDARD_TEXT_FONT = CLEAR_FONT;
   UNIT_NAME_FONT = CLEAR_FONT;
   DAMAGE_TEXT_FONT = CLEAR_FONT;
   NAMEPLATE_FONT = CLEAR_FONT;
   CHAT_FONT_HEIGHTS = {
      [1] = 7,
      [2] = 8,
      [3] = 9,
      [4] = 10,
      [5] = 11,
      [6] = 12,
      [7] = 13,
      [8] = 14,
      [9] = 15,
      [10] = 16,
      [11] = 17,
      [12] = 18,
      [13] = 19,
      [14] = 20,
      [15] = 21,
      [16] = 22
   };


-- Master Fonts
--------------------------------------------------------------------------------

   MasterFont:SetShadowColor(0, 0, 0);
   MasterFont:SetShadowOffset(1, -1);


-- System Fonts
--------------------------------------------------------------------------------

   SystemFont:SetFont(CLEAR_FONT, 17);
   SystemFont:SetTextColor(1.0, 1.0, 0);
   SystemFont:SetShadowColor(0, 0, 0);
   SystemFont:SetShadowOffset(1, -1);


-- Primary Game Fonts
--------------------------------------------------------------------------------

   GameFontNormal:SetFont(CLEAR_FONT, 13);
   GameFontNormal:SetTextColor(1.0, 0.82, 0);
   GameFontNormal:SetShadowColor(0, 0, 0);
   GameFontNormal:SetShadowOffset(1, -1);

   GameFontHighlight:SetTextColor(1.0, 1.0, 1.0);
-- inherits GameFontNormal

   GameFontDisable:SetTextColor(0.6, 0.6, 0.6);
-- inherits GameFontNormal

   GameFontGreen:SetTextColor(0.1, 1.0, 0.1);
-- inherits GameFontNormal

   GameFontRed:SetTextColor(1.0, 0.1, 0.1);
-- inherits GameFontNormal

   GameFontWhite:SetTextColor(1.0, 1.0, 1.0);
-- inherits GameFontNormal

   GameFontBlack:SetFont(CLEAR_FONT, 13);
   GameFontBlack:SetTextColor(0, 0, 0);


-- Small Game Fonts
--------------------------------------------------------------------------------

   GameFontNormalSmall:SetFont(CLEAR_FONT_BOLD, 12);
   GameFontNormalSmall:SetTextColor(1.0, 0.82, 0);
   GameFontNormalSmall:SetShadowColor(0, 0, 0);
   GameFontNormalSmall:SetShadowOffset(1, -1);

   GameFontDisableSmall:SetTextColor(0.6, 0.6, 0.6);
-- inherits GameFontNormalSmall

   GameFontDarkGraySmall:SetTextColor(0.4, 0.4, 0.4);
-- inherits GameFontNormalSmall

   GameFontGreenSmall:SetTextColor(0.1, 1.0, 0.1);
-- inherits GameFontNormalSmall

   GameFontRedSmall:SetTextColor(1.0, 0.1, 0.1);
-- inherits GameFontNormalSmall

   GameFontHighlightSmall:SetTextColor(1.0, 1.0, 1.0);
-- inherits GameFontNormalSmall

-- GameFontHighlightSmallOutline
-- normal outline
-- inherits GameFontHighlightSmall

-- Large Game Fonts
--------------------------------------------------------------------------------

   GameFontNormalLarge:SetFont(CLEAR_FONT, 17);
   GameFontNormalLarge:SetTextColor(1.0, 0.82, 0);
   GameFontNormalLarge:SetShadowColor(0, 0, 0);
   GameFontNormalLarge:SetShadowOffset(1, -1);

   GameFontHighlightLarge:SetTextColor(1.0, 1.0, 1.0);
-- inherits GameFontNormalLarge

   GameFontDisableLarge:SetTextColor(0.6, 0.6, 0.6);
-- inherits GameFontNormalLarge

   GameFontGreenLarge:SetTextColor(0.1, 1.0, 0.1);
-- inherits GameFontNormalLarge

   GameFontRedLarge:SetTextColor(1.0, 0.1, 0.1);
-- inherits GameFontNormalLarge


-- Number Fonts: Used in Auction House, Money, Keybinding, and Quantity Overlays
--------------------------------------------------------------------------------

   NumberFontNormal:SetFont(CLEAR_FONT_NUMBER, 15, "OUTLINE");
   NumberFontNormal:SetTextColor(1.0, 1.0, 1.0);

   NumberFontNormalYellow:SetTextColor(1.0, 0.82, 0);
-- inherits NumberFontNormal

   NumberFontNormalSmall:SetFont(CLEAR_FONT_NUMBER, 14, "OUTLINE");
   NumberFontNormalSmall:SetTextColor(1.0, 1.0, 1.0);

   NumberFontNormalSmallGray:SetTextColor(0.6, 0.6, 0.6);
-- inherits NumberFontNormalSmall

   NumberFontNormalLarge:SetFont(CLEAR_FONT_NUMBER, 18, "OUTLINE");
   NumberFontNormalLarge:SetTextColor(1.0, 1.0, 1.0);

   NumberFontNormalHuge:SetFont(CLEAR_FONT_NUMBER, 30, "THICKOUTLINE");
   NumberFontNormalHuge:SetTextColor(1.0, 1.0, 1.0);


-- Chat Window Font
--------------------------------------------------------------------------------

   ChatFontNormal:SetFont(CLEAR_FONT, 14);
   ChatFontNormal:SetTextColor(1.0, 1.0, 1.0);
   ChatFontNormal:SetShadowColor(0, 0, 0);
   ChatFontNormal:SetShadowOffset(1, -1);


-- Combat Log: "Another Action is in Progress", "Can't do that while Stunned", etc.
--------------------------------------------------------------------------------

-- CombatLogFont inherits GameFontHighlight


-- Quest Log Fonts: Title, Description, Description, Objectives (respectively)
--------------------------------------------------------------------------------

   QuestTitleFont:SetFont(CLEAR_FONT_BOLD, 19);
   QuestTitleFont:SetTextColor(0, 0, 0);
   QuestTitleFont:SetShadowColor(0.54, 0.4, 0.1);
   QuestTitleFont:SetShadowOffset(1, -1);

   QuestFont:SetFont(CLEAR_FONT_ITALIC, 14);
   QuestFont:SetTextColor(0.15, 0.09, 0.04);

   QuestFontNormalSmall:SetFont(CLEAR_FONT_BOLD, 13);
   QuestFontNormalSmall:SetTextColor(0.30, 0.18, 0);
   QuestFontNormalSmall:SetShadowColor(0.54, 0.4, 0.1);
   QuestFontNormalSmall:SetShadowOffset(1, -1);

   QuestFontHighlight:SetFont(CLEAR_FONT, 15);
   QuestFontHighlight:SetTextColor(0, 0, 0);


-- Item Info
--------------------------------------------------------------------------------

   ItemTextFontNormal:SetFont(CLEAR_FONT, 17);
   ItemTextFontNormal:SetTextColor(0.18, 0.12, 0.06);


-- Spell Book: Subtitles
--------------------------------------------------------------------------------

   SubSpellFont:SetFont(CLEAR_FONT_BOLD, 12);
   SubSpellFont:SetTextColor(0.35, 0.2, 0);


-- Dialog Buttons
--------------------------------------------------------------------------------

   DialogButtonNormalText:SetFont(CLEAR_FONT, 17);
   DialogButtonNormalText:SetTextColor(1.0, 0.82, 0);

-- DialogButtonHighlightText:inherits(DialogButtonNormalText);
   DialogButtonHighlightText:SetTextColor(1.0, 1.0, 1.0);


-- Zone Changes: On-screen Notifications
--------------------------------------------------------------------------------

   ZoneTextFont:SetFont(CLEAR_FONT_BOLDITALIC, 100, "THICKOUTLINE");
   ZoneTextFont:SetTextColor(1.0, 0.9294, 0.7607);
   ZoneTextFont:SetShadowColor(0, 0, 0);
   ZoneTextFont:SetShadowOffset(1, -1);

   SubZoneTextFont:SetFont(CLEAR_FONT_BOLDITALIC, 32, "THICKOUTLINE");


-- Error Messages
--------------------------------------------------------------------------------

-- ErrorFont inherits GameFontNormalLarge


-- Status Bars
--------------------------------------------------------------------------------

-- TextStatusBarText inherits NumberFontNormal

   TextStatusBarTextSmall:SetFont(CLEAR_FONT, 14);
   TextStatusBarTextSmall:SetTextColor(1.0, 1.0, 1.0);


-- Tooltips
--------------------------------------------------------------------------------

   GameTooltipText:SetFont(CLEAR_FONT, 13);
   GameTooltipText:SetTextColor(1.0, 1.0, 1.0);

   GameTooltipTextSmall:SetFont(CLEAR_FONT_BOLD, 12);
   GameTooltipTextSmall:SetTextColor(1.0, 1.0, 1.0);

   GameTooltipHeaderText:SetFont(CLEAR_FONT, 15, "OUTLINE");
   GameTooltipHeaderText:SetTextColor(1.0, 1.0, 1.0);


-- World Map Titles
--------------------------------------------------------------------------------
   WorldMapTextFont:SetFont(CLEAR_FONT_BOLDITALIC, 102, "THICKOUTLINE");
   WorldMapTextFont:SetTextColor(1.0, 0.9294, 0.7607);
   WorldMapTextFont:SetShadowColor(0, 0, 0);
   WorldMapTextFont:SetShadowOffset(1, -1);

-- Mail Text, added 1.8: In-game Mails
--------------------------------------------------------------------------------
   MailTextFontNormal:SetFont(CLEAR_FONT_ITALIC, 15);
   MailTextFontNormal:SetTextColor(0.15, 0.09, 0.04);
   MailTextFontNormal:SetShadowColor(0.54, 0.4, 0.1);
   MailTextFontNormal:SetShadowOffset(1, -1);


-- Invoice Text, added 1.9: Auction House Sale Invoices
--------------------------------------------------------------------------------
   InvoiceTextFontNormal:SetFont(CLEAR_FONT_ITALIC, 14);
   InvoiceTextFontNormal:SetTextColor(0.15, 0.09, 0.04);

   InvoiceTextFontSmall:SetFont(CLEAR_FONT_ITALIC, 12);
   InvoiceTextFontSmall:SetTextColor(0.15, 0.09, 0.04);
end


--------------------------------------------------------------------------------
-- Apply all the first time explicitly, for sanity
--------------------------------------------------------------------------------
ClearFont:ApplySystemFonts()
ClearFont:ApplyAddOnFonts()

