Ejemplo n.º 1
0
void VCFont::Initialize()
{
	std::ifstream f (m_fntPath, std::ios::in | std::ios::binary);
	if (!f.is_open())
	{
		std::cout << "Failed to open file: " << m_fntPath << std::endl;
		return;
	}

	// Header
	char c1, c2, c3, c4;
	f >> c1 >> c2 >> c3 >> c4;
	if (c1 != 66 || c2 != 77 || c3 != 70 || c4 != 3)
	{
		std::cout << "FNT must be binary, version 3!" << std::endl;
		return;
	}
	
	if (!ParseInfo(f))
		return;

	if (!ParseCommon(f) )
		return;

	if (!ParsePages(f) )
		return;

	if (!ParseCharacters(f) )
		return;

	if (!ParseKerning(f) )
		return;

	PreCompileQuads();

	f.close();

	// Load DDS
	//m_ddsTexture = VCTexture::CreateUnfilteredTexture(m_ddsPath.c_str());
	VCTextureParams tparam;
	tparam.Filtering = VCTextureFiltering::None;
	m_ddsTexture = VCResourceManager::GetTexure(m_ddsPath, tparam);

	// Name
	std::ostringstream ss;
	ss << FontName << "-" << Info.fontSize;

	if ( Info.bitField & 32)
		ss << "-Italic";

	if ( Info.bitField & 16)
		ss << "-Bold";

	Name = ss.str();
}
Ejemplo n.º 2
0
// Atom ::= "(" Expression ")" | "[" [^] Range "]" | Characters
Instruction* ParseAtom(const char **ppc, ParseInfo &info)
{
  Instruction *i = 0;
  const char *pc = *ppc;
  
  switch (*pc)
  {
    case '(':
    {
      Group::TriState dnl = Group::Inherit;
      Group::TriState nc = Group::Inherit;
      Group::TriState ml = Group::Inherit;
      bool capture = true;
      bool consume = true;
      bool invert = false;
      bool reverse = false;
      std::string name = "";
      
      ++pc;
      
      if (*pc == '?')
      {
        ++pc;
        if (*pc == '#')
        {
          // skip everything until ) and from behave as if ParseAtom was
          // called starting next character
          ++pc;
          while (*pc != ')')
          {
            if (*pc == '\0')
            {
              return 0;
            }
            ++pc;
          }
          *ppc = ++pc;
          return ParseAtom(ppc, info);
        }
        if (*pc == ':')
        {
          capture = false;
          ++pc;
        }
        else if (*pc == '(')
        {
          // conditional
          ++pc;
          
          std::string cond;
          while (*pc != ')')
          {
            if (*pc == '\0')
            {
              return 0;
            }
            cond.push_back(*pc);
            ++pc;
          }
          ++pc;
          
          Instruction *ci = ParseExpression(&pc, info);
          if (!ci || *pc != ')')
          {
            if (ci)
            {
              delete ci;
            }
            return 0;
          }
          ++pc;
          
          Alternative *alt = dynamic_cast<Alternative*>(ci);
          Instruction *ifTrue, *ifFalse;
          if (alt == 0)
          {
            ifTrue = ci;
            ifFalse = 0;
          }
          else
          {
            ifTrue = alt->first()->clone();
            ifFalse = alt->second()->clone();
            delete alt;
          }
          
          *ppc = pc;
          int index = 0;
          if (sscanf(cond.c_str(), "%d", &index) != 1)
          {
            return new Conditional(cond, ifTrue, ifFalse);
          }
          else
          {
            return new Conditional(index, ifTrue, ifFalse);
          }
        }
        else if (*pc == 'P')
        {
          ++pc;
          if (*pc == '<')
          {
            ++pc;
            while (*pc != '>')
            {
              if (*pc == '\0')
              {
                return 0;
              }
              name.push_back(*pc);
              ++pc;
            }
            ++pc;
          }
          else if (*pc == '=')
          {
            std::string name;
            ++pc;
            while (*pc != ')')
            {
              if (*pc == '\0')
              {
                return 0;
              }
              name.push_back(*pc);
              ++pc;
            }
            ++pc;
            *ppc = pc;
            return new Backsubst(name);
          }
          else
          {
            return 0;
          }
        }
        else if (*pc == '=')
        {
          // positive lookahead
          capture = false;
          consume = false;
          ++pc;
        }
        else if (*pc == '!')
        {
          // negative lookahead
          capture = false;
          consume = false;
          invert = true;
          ++pc;
        }
        else if (*pc == '<')
        {
          ++pc;
          if (*pc == '=')
          {
            // positive lookbehind
            capture = false;
            consume = false;
            reverse = true;
            ++pc;
          }
          else if (*pc == '!')
          {
            // negative lookbehind
            capture = false;
            consume = false;
            reverse = true;
            invert = true;
            ++pc;
          }
          else
          {
            Log::PrintError("[gcore] rex/ParseAtom: Invalid group format");
            return 0;
          }
        }
        else if (*pc == 'i' || *pc == 'm' || *pc == 's' || *pc == '-')
        {
          //capture = false;
          //consume = false;
          if (*pc == 'i')
          {
            // case sensitive off
            nc = Group::On;
            ++pc;
          }
          if (*pc == 'm')
          {
            // multiline on (. matches \r\n)
            ml = Group::On;
            ++pc;
          }
          if (*pc == 's')
          {
            // dot matches new line on
            dnl = Group::On;
            ++pc;
          }
          if (*pc == '-')
          {
            ++pc;
            if (*pc == 'i')
            {
              // case sensitive on
              nc = Group::Off;
              ++pc;
            }
            if (*pc == 'm')
            {
              // multiline off
              ml = Group::Off;
              ++pc;
            }
            if (*pc == 's')
            {
              // dot matches newline off
              dnl = Group::Off;
              ++pc;
            }
          }
          if (*pc != ':' && *pc != ')')
          {
            // either followed by : or group end (meaning we just want to change exp exec flags)
            Log::PrintError("[gcore] rex/ParseAtom: Invalid group format");
            return 0;
          }
          
          if (*pc == ':')
          {
            ++pc;
            // would having a closing parent here be problematic
          }
          else
          {
            capture = false;
            consume = false;
          }
        }
      }
      
      int gidx = (capture ? (++(info.numGroups)) : -1);
      unsigned short flags = (unsigned short)(reverse ? Rex::Reverse : 0);
      
      if (*pc != ')')
      {
        i = ParseExpression(&pc, info);
      }

      if (*pc != ')')
      {
        if (i)
        {
          delete i;
        }
        return 0;
      }
      
#ifdef _DEBUG_REX
      Log::PrintDebug("[gcore] rex/ParseAtom: Create group");
      Log::SetIndentLevel(Log::GetIndentLevel()+1);
      Log::PrintDebug("index: %d", gidx);
      Log::PrintDebug("invert: %d", invert);
      Log::PrintDebug("consume: %d", consume);
      Log::PrintDebug("flags: %d", flags);
      Log::PrintDebug("nc: %d", nc);
      Log::PrintDebug("ml: %d", ml);
      Log::PrintDebug("dnl: %d", dnl);
      Log::PrintDebug("name: %d", name.c_str());
      Log::PrintDebug("code: ");
      if (i)
      {
        std::ostringstream oss;
        
        Log::SetIndentLevel(Log::GetIndentLevel()+1)
        i->toStream(oss);
        Log::PrintDebug(oss.str().c_str());
        Log::SetIndentLevel(Log::GetIndentLevel()-1)
      }
      Log::SetIndentLevel(Log::GetIndentLevel()-1);
#endif
      
      i = new Group(gidx, i, !consume, invert, flags, nc, ml, dnl, name);
      
#ifdef _DEBUG_REX
      Log::PrintDebug("[gcore] rex/ParseAtom: Group created");
#endif
      ++pc;
      
      break;
    }
    case '[':
    {
      bool inv = false;
      ++pc;
      if (*pc == '^')
      {
        inv = true;
        ++pc;
      }
      i = ParseRange(&pc, inv, info);
      if (!i)
      {
        return 0;
      }
      if (*pc != ']')
      {
        Log::PrintError("[gcore] rex/ParseAtom: Invalid character '%c' in expression, expected ']'", *pc);
        if (i)
        {
          delete i;
        }
        return 0;
      }
      ++pc;
      break;
    }
    default:
      i = ParseCharacters(&pc, info);
      if (!i)
      {
        i = ParseZerowidth(&pc, info);
        if (!i)
        {
          return 0;
        }
      }
  }
  *ppc = pc;
  return i;
}