Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Conversation

montegoulding
Copy link
Member

measure the text drawn with the effective font attributes of an object

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this issue (the problem if the object isn't open), it might be better to refactor the act of measuring text relative to an object into MCObject. i.e. add a 'measuretext' function to MCObject:

MCRectangle MCObject::measuretext(const MCString& p_text, bool p_is_unicode)
{
    bool t_mapped_font;
    t_mapped_font = false;
    if (!opened && m_font == nil)
    {
       mapfont();
       t_mapped_font = true;
    }

   MCRectangle t_bounds;
   t_bounds . x = 0;
   t_bounds . width = MCFontMeasureText(m_font, p_text . getstring(), p_text . getlength(), p_is_unicode);
   t_bounds . y = -MCFontGetAscent(t_font);
   t_bounds . height = MCFontGetDescent(t_font) + MCFontGetAscent(t_font);

   if (t_mapped_font)
     unmapfont();

   return t_bounds;
}

This encapsulates ensuring the object has a fontref inside the object and would be useful in a couple of places elsewhere which have a need to get metrics of the text in an object when the object isn't necessarily open.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

… for the engine elsewhere. Removed object not open error.
@runrevmark
Copy link
Contributor

Hi Monte, thanks for this.

I've pulled this into develop. I also refactored the external calls to mapfont()/unmapfont() in MCGroup to use MCObject::measuretext() and made mapfont/unmapfont private for better encapsulation.

Warmest Regards,

Mark.

@runrevmark runrevmark closed this Aug 23, 2013
trevordevore pushed a commit to trevordevore/livecode that referenced this pull request Jul 7, 2015
[[ Bug 15007 ]] Include .lci file in packages when present
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants