<commit_before>#include <TextField.h>
#include <Tilesheet.h>
#include <Utils.h>
#include <Surface.h>
#include <KeyCodes.h>
#include "XML/tinyxml.h"
#include <ctype.h>
#include <time.h>
#include <sstream>

#ifndef iswalpha
#define iswalpha isalpha
#endif


namespace nme
{

int gPasswordChar = 42; // *

TextField::TextField(bool inInitRef) : DisplayObject(inInitRef),
   alwaysShowSelection(false),
   antiAliasType(aaNormal),
   autoSize(asNone),
   background(false),
   backgroundColor(0xffffffff),
   border(false),
   borderColor(0x00000000),
   condenseWhite(false),
   defaultTextFormat( TextFormat::Default() ),
   displayAsPassword(false),
   embedFonts(false),
   gridFitType(gftPixel),
   maxChars(0),
   mouseWheelEnabled(true),
   multiline(false),
   restrict(WString()),
   scrollH(0),
   scrollV(1),
   selectable(true),
   sharpness(0),
   styleSheet(0),
   textColor(0x000000),
   thickness(0),
   useRichTextClipboard(false),
   wordWrap(false),
   isInput(false)
{
   mStringState = ssText;
   mLinesDirty = true;
   mGfxDirty = true;
   boundsWidth = 100.0;
   boundsHeight = 100.0;
   mActiveRect = Rect(100,100);
   mFontsDirty = false;
   mSelectMin = mSelectMax = 0;
   mSelectDownChar = 0;
   caretIndex = 0;
   mCaretGfx = 0;
   mHighlightGfx = 0;
   mLastCaretHeight = -1;
   mSelectKeyDown = -1;
   maxScrollH  = 0;
   maxScrollV  = 1;
   setText(L"");
   textWidth = 0;
   textHeight = 0;
   mLastUpDownX = -1;
   mLayoutScaleH = mLayoutScaleV = -1.0;
   mLayoutRotation = gr0;
   needsSoftKeyboard = true;
   mHasCaret = false;
}

TextField::~TextField()
{
   if (mCaretGfx)
      mCaretGfx->DecRef();
   if (mHighlightGfx)
      mHighlightGfx->DecRef();
   defaultTextFormat->DecRef();
   mCharGroups.DeleteAll();
}

void TextField::setWidth(double inWidth)
{
   boundsWidth = inWidth;
   mLinesDirty = true;
   mGfxDirty = true;
}

double TextField::getWidth()
{
   if (autoSize != asNone)
   {
      if (mLinesDirty)
         Layout();
      return textWidth;
   }
   return boundsWidth;
}

double TextField::getHeight()
{
   if (autoSize != asNone)
   {
      if (mLinesDirty)
         Layout();
      return textHeight;
   }
   return boundsHeight;
}
 


void TextField::setHeight(double inHeight)
{
   boundsHeight = inHeight;
   mLinesDirty = true;
   mGfxDirty = true;
}


const TextFormat *TextField::getDefaultTextFormat()
{
   return defaultTextFormat;<commit_msg>Return scaled dimensions for TextField width and height (but still not sure why on Flash, setting a height of 55 might report 64?)<commit_after>#include <TextField.h>
#include <Tilesheet.h>
#include <Utils.h>
#include <Surface.h>
#include <KeyCodes.h>
#include "XML/tinyxml.h"
#include <ctype.h>
#include <time.h>
#include <sstream>

#ifndef iswalpha
#define iswalpha isalpha
#endif


namespace nme
{

int gPasswordChar = 42; // *

TextField::TextField(bool inInitRef) : DisplayObject(inInitRef),
   alwaysShowSelection(false),
   antiAliasType(aaNormal),
   autoSize(asNone),
   background(false),
   backgroundColor(0xffffffff),
   border(false),
   borderColor(0x00000000),
   condenseWhite(false),
   defaultTextFormat( TextFormat::Default() ),
   displayAsPassword(false),
   embedFonts(false),
   gridFitType(gftPixel),
   maxChars(0),
   mouseWheelEnabled(true),
   multiline(false),
   restrict(WString()),
   scrollH(0),
   scrollV(1),
   selectable(true),
   sharpness(0),
   styleSheet(0),
   textColor(0x000000),
   thickness(0),
   useRichTextClipboard(false),
   wordWrap(false),
   isInput(false)
{
   mStringState = ssText;
   mLinesDirty = true;
   mGfxDirty = true;
   boundsWidth = 100.0;
   boundsHeight = 100.0;
   mActiveRect = Rect(100,100);
   mFontsDirty = false;
   mSelectMin = mSelectMax = 0;
   mSelectDownChar = 0;
   caretIndex = 0;
   mCaretGfx = 0;
   mHighlightGfx = 0;
   mLastCaretHeight = -1;
   mSelectKeyDown = -1;
   maxScrollH  = 0;
   maxScrollV  = 1;
   setText(L"");
   textWidth = 0;
   textHeight = 0;
   mLastUpDownX = -1;
   mLayoutScaleH = mLayoutScaleV = -1.0;
   mLayoutRotation = gr0;
   needsSoftKeyboard = true;
   mHasCaret = false;
}

TextField::~TextField()
{
   if (mCaretGfx)
      mCaretGfx->DecRef();
   if (mHighlightGfx)
      mHighlightGfx->DecRef();
   defaultTextFormat->DecRef();
   mCharGroups.DeleteAll();
}

void TextField::setWidth(double inWidth)
{
   boundsWidth = inWidth;
   mLinesDirty = true;
   mGfxDirty = true;
}

double TextField::getWidth()
{
   /*if (autoSize != asNone)
   {
      if (mLinesDirty)
         Layout();
      return textWidth;
   }
   return boundsWidth;*/
   Transform trans;
   trans.mMatrix = &GetLocalMatrix();
   Extent2DF ext;
   GetExtent(trans,ext,false,true);

   if (!ext.Valid())
   {
      return 0;
   }

   return ext.Width();
}

double TextField::getHeight()
{
   /*if (autoSize != asNone)
   {
      if (mLinesDirty)
         Layout();
      return textHeight;
   }
   return boundsHeight;*/
   Transform trans;
   trans.mMatrix = &GetLocalMatrix();
   Extent2DF ext;
   GetExtent(trans,ext,false,true);
   if (!ext.Valid())
      return 0;

   return ext.Height();
}
 


void TextField::setHeight(double inHeight)
{
   boundsHeight = inHeight;
   mLinesDirty = true;
   mGfxDirty = true;
}


const TextFormat *TextField::getDefaultTextFormat()
{
   return defaultTextFormat;
{'fraction_non_alphanumeric': 0.12653446647780925, 'fraction_numerical': 0.021907459867799812, 'mean_word_length': 3.5734024179620034, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 4, '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': '4484763', 'n_tokens_mistral': 1987, 'n_tokens_neox': 1891, 'n_words': 375}