<commit_before>require "wow/Frame";
require "rainback/AnchoredBound";
require "rainback/Graphics";

local Delegate = OOP.Class();

function Delegate:Constructor(frame)
    self.frame = frame;
    self.text = "";

    self.font = Rainback.Font();

    self.color = {1, 1, 1, 1};

    frame:OnDelegateSet(function(category, delegate)
        if category ~= "layout" then
            return;
        end;
        self:AttachLayout(delegate);
    end);
    if frame:GetDelegate("layout") then
        self:AttachLayout(delegate);
    end;
end;

function Delegate:AttachLayout(delegate)
    if not delegate.GetBounds then
        return;
    end;
    local bounds = delegate:GetBounds();
    if type(bounds) ~= "table" then
        return;
    end;
    if not bounds.GetNaturalHeight or not bounds.GetNaturalWidth then
        return;
    end;
    bounds.GetNaturalHeight = Curry(self, "GetNaturalHeight");
    bounds.GetNaturalWidth = Curry(self, "GetNaturalWidth");
end;

function Delegate:GetText()
    return self.text;
end;

function Delegate:SetText(text)
    self.text = tostring(text);
end;

function Delegate:GetNaturalWidth(height)
    return self.font:width(self.text);
end;

function Delegate:GetNaturalHeight(width)
    return self.font:height(self.text, width);
end;

function Delegate:GetWrappedWidth()
    return self:GetNaturalWidth();
end;

function Delegate:GetStringWidth()
    return self:GetNaturalWidth();
end;

function Delegate:GetStringHeight()<commit_msg>Fix GetNaturalWidth/Height invocations<commit_after>require "wow/Frame";
require "rainback/AnchoredBound";
require "rainback/Graphics";

local Delegate = OOP.Class();

function Delegate:Constructor(frame)
    self.frame = frame;
    self.text = "";

    self.font = Rainback.Font();

    self.color = {1, 1, 1, 1};

    frame:OnDelegateSet(function(category, delegate)
        if category ~= "layout" then
            return;
        end;
        self:AttachLayout(delegate);
    end);
    if frame:GetDelegate("layout") then
        self:AttachLayout(delegate);
    end;
end;

function Delegate:AttachLayout(delegate)
    if not delegate.GetBounds then
        return;
    end;
    local bounds = delegate:GetBounds();
    if type(bounds) ~= "table" then
        return;
    end;
    if not bounds.GetNaturalHeight or not bounds.GetNaturalWidth then
        return;
    end;
    bounds.GetNaturalHeight = Override(self, "GetNaturalHeight");
    bounds.GetNaturalWidth = Override(self, "GetNaturalWidth");
end;

function Delegate:GetText()
    return self.text;
end;

function Delegate:SetText(text)
    self.text = tostring(text);
end;

function Delegate:GetNaturalWidth(height)
    return self.font:width(self.text);
end;

function Delegate:GetNaturalHeight(width)
    return self.font:height(self.text, width);
end;

function Delegate:GetWrappedWidth()
    return self:GetNaturalWidth();
end;

function Delegate:GetStringWidth()
    return self:GetNaturalWidth();
end;

function Delegate:GetStringHeight()
{'fraction_non_alphanumeric': 0.11289782244556114, 'fraction_numerical': 0.002680067001675042, 'mean_word_length': 3.831715210355987, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3904602', 'n_tokens_mistral': 981, 'n_tokens_neox': 907, 'n_words': 207}