CStdStringW FacadeDocumentProviderImpl::GetDefaultSaveExtensionFromFormatString(const CStdStringW& sAvailableFormats, long lIndex)
{
	if(sAvailableFormats.IsEmpty())
		return _T("wdf");

	int iStartPos = -1;
	int lSkip = (lIndex-1)*2;
	for (int i=0; i<lSkip; i++)
	{
		iStartPos = sAvailableFormats.Find(_T('|'),iStartPos);
	}

	int iFirstDelimeterPos = sAvailableFormats.Find(_T('|'), iStartPos);
	if (iFirstDelimeterPos == iStartPos+1) // we've hit the "||" at the end ...
		iFirstDelimeterPos = sAvailableFormats.Find(_T('|')); // go back to default
	int iNextDelimeterPos = sAvailableFormats.Find(_T('|'),iFirstDelimeterPos);

	CStdStringW sExt = sAvailableFormats.Mid(iFirstDelimeterPos + 1 ,iNextDelimeterPos - iFirstDelimeterPos - 1  );

	int iPeriodPos = sExt.Find(_T('.'));
	sExt = sExt.Mid(iPeriodPos + 1, sExt.length() - iPeriodPos );

	return sExt;

}
Пример #2
0
void DocReader::StripFieldContents(CStdStringW& sText)
{
	int iPos = -1;
	while ((iPos = sText.Find(19)) != -1)
	{
		int iEndPos = sText.Find(21, iPos);
		sText.erase(iPos, iEndPos - iPos);
	}
}
Пример #3
0
void CHTMLUtil::ConvertHTMLToW(const CStdStringW& strHTML, CStdStringW& strStripped)
{
  if (strHTML.size() == 0)
  {
    strStripped.Empty();
    return ;
  }
  int iPos = 0;
  strStripped = strHTML;
  while (mappings[iPos].html)
  {
    strStripped.Replace(mappings[iPos].html,CStdStringW(1, mappings[iPos].w));
    iPos++;
  }

  iPos = strStripped.Find(L"&#");
  while (iPos > 0 && iPos < (int)strStripped.size()-4)
  {
    int iStart = iPos + 1;
    iPos += 2;
    CStdStringW num;
    int base = 10;
    if (strStripped[iPos+1] == L'x')
    {
      base = 16;
      iPos++;
    }

    int i=iPos;
    while ( iPos < (int)strStripped.size() && 
           (base==16?iswxdigit(strStripped[iPos]):iswdigit(strStripped[iPos])))
      iPos++; 

    num = strStripped.Mid(i,iPos-i);
    wchar_t val = (wchar_t)wcstol(num.c_str(),NULL,base);
    if (base == 10)
      num.Format(L"&#%ls;",num.c_str());
    else
      num.Format(L"&#x%ls;",num.c_str());

    strStripped.Replace(num,CStdStringW(1,val));
    iPos = strStripped.Find(L"&#", iStart);
  }
}
void CAcceleratorManager::UpdateMenu(HMENU menu)
{
  int count = GetMenuItemCount(menu);

  MENUITEMINFO info;
  wchar_t ss[128];
  ZeroMemory(&info, sizeof(info));
  info.cbSize = sizeof(info);
  info.fMask = MIIM_ID | MIIM_SUBMENU;
  for(int i = 0; i < count; i++) {
    GetMenuItemInfo(menu, i, TRUE, &info);

    if(info.hSubMenu != NULL) {
      UpdateMenu(info.hSubMenu);
    } else {
      if(info.wID != -1) {
        MENUITEMINFOW info2;
        ZeroMemory(&info2, sizeof(info2));
        info2.cbSize = sizeof(info2);
        info2.fMask = MIIM_STRING;
        info2.dwTypeData = ss;
        info2.cch = 128;
        GetMenuItemInfoW(menu, i, MF_BYPOSITION, &info2);
        CStdStringW str = ss;
        int index = str.Find('\t');
        if(index != -1)
          str = str.Left(index);

        CMapWordToCCmdAccelOb::iterator it = m_mapAccelTable.find(info.wID);

        if(it != m_mapAccelTable.end()) {
          CCmdAccelOb *o = it->second;
          if(o->m_Accels.begin() != o->m_Accels.end()) {
            std::list<CAccelsOb*>::iterator j = o->m_Accels.begin();

            CAccelsOb *accel = *j;

            CStdString s;
            accel->GetString(s);
            str += "\t";
            str += s;
          }
        }
        if(str != ss)
          ModifyMenuW(menu, i, MF_BYPOSITION | MF_STRING, info.wID, str);
      }
    }
  }
}
Пример #5
0
void CGUITextLayout::ParseText(const CStdStringW &text, uint32_t defaultStyle, color_t defaultColor, vecColors &colors, vecText &parsedText)
{
  // run through the string, searching for:
  // [B] or [/B] -> toggle bold on and off
  // [I] or [/I] -> toggle italics on and off
  // [COLOR ffab007f] or [/COLOR] -> toggle color on and off
  // [CAPS <option>] or [/CAPS] -> toggle capatilization on and off

  uint32_t currentStyle = defaultStyle; // start with the default font's style
  color_t currentColor = 0;

  colors.push_back(defaultColor);
  stack<color_t> colorStack;
  colorStack.push(0);

  // these aren't independent, but that's probably not too much of an issue
  // eg [UPPERCASE]Glah[LOWERCASE]FReD[/LOWERCASE]Georeg[/UPPERCASE] will work (lower case >> upper case)
  // but [LOWERCASE]Glah[UPPERCASE]FReD[/UPPERCASE]Georeg[/LOWERCASE] won't

  int startPos = 0;
  size_t pos = text.Find(L'[');
  while (pos != CStdString::npos && pos + 1 < text.size())
  {
    uint32_t newStyle = 0;
    color_t newColor = currentColor;
    bool colorTagChange = false;
    bool newLine = false;
    // have a [ - check if it's an ON or OFF switch
    bool on(true);
    int endPos = pos++; // finish of string
    if (text[pos] == L'/')
    {
      on = false;
      pos++;
    }
    // check for each type
    if (text.Mid(pos,2) == L"B]")
    { // bold - finish the current text block and assign the bold state
      pos += 2;
      if ((on && text.Find(L"[/B]",pos) >= 0) ||          // check for a matching end point
         (!on && (currentStyle & FONT_STYLE_BOLD)))       // or matching start point
        newStyle = FONT_STYLE_BOLD;
    }
    else if (text.Mid(pos,2) == L"I]")
    { // italics
      pos += 2;
      if ((on && text.Find(L"[/I]",pos) >= 0) ||          // check for a matching end point
         (!on && (currentStyle & FONT_STYLE_ITALICS)))    // or matching start point
        newStyle = FONT_STYLE_ITALICS;
    }
    else if (text.Mid(pos,10) == L"UPPERCASE]")
    {
      pos += 10;
      if ((on && text.Find(L"[/UPPERCASE]",pos) >= 0) ||  // check for a matching end point
         (!on && (currentStyle & FONT_STYLE_UPPERCASE)))  // or matching start point
        newStyle = FONT_STYLE_UPPERCASE;
    }
    else if (text.Mid(pos,10) == L"LOWERCASE]")
    {
      pos += 10;
      if ((on && text.Find(L"[/LOWERCASE]",pos) >= 0) ||  // check for a matching end point
         (!on && (currentStyle & FONT_STYLE_LOWERCASE)))  // or matching start point
        newStyle = FONT_STYLE_LOWERCASE;
    }
    else if (text.Mid(pos,3) == L"CR]" && on)
    {
      newLine = true;
      pos += 3;
    }
    else if (text.Mid(pos,5) == L"COLOR")
    { // color
      size_t finish = text.Find(L']', pos + 5);
      if (on && finish != CStdString::npos && (size_t)text.Find(L"[/COLOR]",finish) != CStdString::npos)
      {
        color_t color = g_colorManager.GetColor(text.Mid(pos + 5, finish - pos - 5));
        vecColors::const_iterator it = std::find(colors.begin(), colors.end(), color);
        if (it == colors.end())
        { // create new color
          if (colors.size() <= 0xFF)
          {
            newColor = colors.size();
            colors.push_back(color);
          }
          else // we have only 8 bits for color index, fallback to first color if reach max.
            newColor = 0;
        }
        else
          // reuse existing color
          newColor = it - colors.begin();
        colorStack.push(newColor);
        colorTagChange = true;
      }
      else if (!on && finish == pos + 5 && colorStack.size() > 1)
      { // revert to previous color
        colorStack.pop();
        newColor = colorStack.top();
        colorTagChange = true;
      }
      if (finish != CStdString::npos)
        pos = finish + 1;
    }

    if (newStyle || colorTagChange || newLine)
    { // we have a new style or a new color, so format up the previous segment
      CStdStringW subText = text.Mid(startPos, endPos - startPos);
      if (currentStyle & FONT_STYLE_UPPERCASE)
        subText.ToUpper();
      if (currentStyle & FONT_STYLE_LOWERCASE)
        subText.ToLower();
      AppendToUTF32(subText, ((currentStyle & 3) << 24) | (currentColor << 16), parsedText);
      if (newLine)
        parsedText.push_back(L'\n');

      // and switch to the new style
      startPos = pos;
      currentColor = newColor;
      if (on)
        currentStyle |= newStyle;
      else
        currentStyle &= ~newStyle;
    }
    pos = text.Find(L'[',pos);
  }
  // now grab the remainder of the string
  CStdStringW subText = text.Mid(startPos, text.GetLength() - startPos);
  if (currentStyle & FONT_STYLE_UPPERCASE)
    subText.ToUpper();
  if (currentStyle & FONT_STYLE_LOWERCASE)
    subText.ToLower();
  AppendToUTF32(subText, ((currentStyle & 3) << 24) | (currentColor << 16), parsedText);
}
Пример #6
0
void CGUITextLayout::ParseText(const CStdStringW &text, uint32_t defaultStyle, vecColors &colors, vecText &parsedText)
{
  // run through the string, searching for:
  // [B] or [/B] -> toggle bold on and off
  // [I] or [/I] -> toggle italics on and off
  // [COLOR ffab007f] or [/COLOR] -> toggle color on and off
  // [CAPS <option>] or [/CAPS] -> toggle capatilization on and off

//  uint32_t currentStyle = defaultStyle; // start with the default font's style
//  color_t currentColor = 0;

  stack<color_t> colorStack;
  colorStack.push(0);

  // these aren't independent, but that's probably not too much of an issue
  // eg [UPPERCASE]Glah[LOWERCASE]FReD[/LOWERCASE]Georeg[/UPPERCASE] will work (lower case >> upper case)
  // but [LOWERCASE]Glah[UPPERCASE]FReD[/UPPERCASE]Georeg[/LOWERCASE] won't
#define FONT_STYLE_UPPERCASE 4
#define FONT_STYLE_LOWERCASE 8

  int boldCounter = 0;
  int italicsCoutner = 0;
  int upperCounter = 0;
  int lowerCounter = 0;
  color_t color = 0;

  int startPos = 0;
  size_t pos = text.Find(L'[');
  while (pos != CStdString::npos && pos + 1 < text.size())
  {
    int style = 0;

    if (pos - startPos > 0)
    {
      if (boldCounter)
        style |= FONT_STYLE_BOLD;

      if (italicsCoutner)
        style |= FONT_STYLE_ITALICS;

      CStdStringW subText = text.Mid(startPos, pos - startPos);

      if (upperCounter)
      {
#if defined(_LINUX) && !defined(__APPLE__)
        std::transform(subText.begin(), subText.end(), subText.begin(),
                       (gunichar(*)(gunichar)) g_unichar_toupper);
#else
        subText.ToUpper();
#endif
      }

      if (lowerCounter)
      {
#if defined(_LINUX) && !defined(__APPLE__)
        std::transform(subText.begin(), subText.end(), subText.begin(),
                       (gunichar(*)(gunichar)) g_unichar_tolower);
#else
        subText.ToLower();
#endif
      }

      AppendToUTF32(subText, ((style & 3) << 24) | (color << 16), parsedText);

      startPos = pos;
    }

    // have a [ - check if it's an ON or OFF switch
    bool ignoreTag = false;
    ++pos;

    bool on = true;
    if (text[pos] == L'/')
    {
      on = false;
      pos++;
    }

    // check for each type
    if (text.Mid(pos,2) == L"B]")
    { // bold - finish the current text block and assign the bold state
      pos += 2;
      on ? ++boldCounter : --boldCounter;
    }
    else if (text.Mid(pos,2) == L"I]")
    { // italics
      pos += 2;
      on ? ++italicsCoutner : --italicsCoutner;
    }
    else if (text.Mid(pos,10) == L"UPPERCASE]")
    {
      pos += 10;
      on ? ++upperCounter : --upperCounter;
    }
    else if (text.Mid(pos,10) == L"LOWERCASE]")
    {
      pos += 10;
      on ? ++lowerCounter : --lowerCounter;
    }
    else if (text.Mid(pos,3) == L"CR]" && on)
    {
      pos += 3;
      parsedText.push_back(L'\n');
    }
    else if (text.Mid(pos,5) == L"COLOR")
    { // color
      size_t finish = text.Find(L']', pos + 5);
      if (on && finish != CStdString::npos && (size_t) text.Find(L"[/COLOR]",finish) != CStdString::npos)
      { // create new color
        color = colors.size();
        colors.push_back(g_colorManager.GetColor(text.Mid(pos + 5, finish - pos - 5)));
        colorStack.push(color);
      }
      else if (!on && finish == pos + 5 && colorStack.size() > 1)
      { // revert to previous color
        colorStack.pop();
        color = colorStack.top();
      }
      pos = finish + 1;
    }
    else
    {
      ignoreTag = true;
    }

    if (!ignoreTag)
    {
      startPos = pos;
    }

    pos = text.Find(L'[',pos);
  }

  // now grab the remainder of the string
  CStdStringW subText = text.Mid(startPos, text.GetLength() - startPos);
  int style = 0;
  if (upperCounter)
  {
#if defined(_LINUX) && !defined(__APPLE__)
        std::transform(subText.begin(), subText.end(), subText.begin(),
                       (gunichar(*)(gunichar)) g_unichar_toupper);
#else
        subText.ToUpper();
#endif
  }

  if (lowerCounter)
  {
#if defined(_LINUX) && !defined(__APPLE__)
    std::transform(subText.begin(), subText.end(), subText.begin(),
                   (gunichar(*)(gunichar)) g_unichar_tolower);
#else
    subText.ToLower();
#endif
  }

  if (boldCounter)
    style |= FONT_STYLE_BOLD;
  if (italicsCoutner)
    style |= FONT_STYLE_ITALICS;
  AppendToUTF32(subText, ((style & 3) << 24) | (color << 16), parsedText);
}
Пример #7
0
void TestDocReader::TestExtractBodyTextOnly()
{
	DocReader dr;
	dr.OpenFile(TEST_REALLY_COMPLEX_DOC);

	CStdStringW sDocText = dr.GetMainDocumentText();

	assertTest(sDocText.Left(9) == L"Once upon");
	assertTest(sDocText.Right(12) == L"ever after.\r");

	assertMessage(sDocText.Find(L"Nested") != -1, _T("expected to get the nested table contents, but didnt"));
	assertMessage(sDocText.Find(L"Four") != -1, _T("expected to get the table contents, but didnt"));
	assertMessage(sDocText.Find(L"a comment") == -1, _T("didnt expect to get the comment contents, but did"));
	assertMessage(sDocText.Find(L"header") == -1, _T("didnt expect to get the header contents, but did"));
	assertMessage(sDocText.Find(L"footer") == -1, _T("didnt expect to get the footer contents, but did"));
	assertMessage(sDocText.Find(L"text box") == -1, _T("didnt expect to get the text box contents, but did"));

	assertMessage(sDocText.Find(L"MERGEFORMAT") == -1, _T("didnt expect to get the field code contents, but did"));
	assertMessage(sDocText.Find(L"allsorts") != -1, _T("expected to get the field result contents, but didny"));
	assertMessage(sDocText.Find(L"be footnote") == -1, _T("didnt expect to get the footnote, but did"));

	assertMessage(sDocText.Find(L"Line Break\013") != -1, _T("expected char 11 as line break"));
	assertMessage(sDocText.Find(L"Section Break\014") != -1, _T("expected char 12 as section break"));
//	assertMessage(sDocText.Find(L"Symbol Char\050") != -1, _T("expected char 40 as symbol char"));
	assertMessage(sDocText.Find(L"NonBreakSpace\240char") != -1, _T("expected char 160 as non breaking space"));
	//assertMessage(sDocText.Find(L"EnDash\226") != -1, _T("expected char 150 as En dash"));
	//assertMessage(sDocText.Find(L"EnDash\227") != -1, _T("expected char 150 as Em dash"));
//	assertMessage(sDocText.Find(L"the \025 document") != -1, _T("expected char 21 as field char"));

	assertMessage(sDocText.Find(L"One\007Two") != -1, _T("expected char 7 as cell char"));

}
Пример #8
0
void CGUITextLayout::ParseText(const CStdStringW &text, DWORD defaultStyle, vector<DWORD> &colors, vector<DWORD> &parsedText)
{
  // run through the string, searching for:
  // [B] or [/B] -> toggle bold on and off
  // [I] or [/I] -> toggle italics on and off
  // [COLOR ffab007f] or [/COLOR] -> toggle color on and off
  // [CAPS <option>] or [/CAPS] -> toggle capatilization on and off

  DWORD currentStyle = defaultStyle; // start with the default font's style
  DWORD currentColor = 0;

  stack<DWORD> colorStack;
  colorStack.push(0);

  // these aren't independent, but that's probably not too much of an issue
  // eg [UPPERCASE]Glah[LOWERCASE]FReD[/LOWERCASE]Georeg[/UPPERCASE] will work (lower case >> upper case)
  // but [LOWERCASE]Glah[UPPERCASE]FReD[/UPPERCASE]Georeg[/LOWERCASE] won't
#define FONT_STYLE_UPPERCASE 4
#define FONT_STYLE_LOWERCASE 8

  int startPos = 0;
  size_t pos = text.Find(L'[');
  while (pos != CStdString::npos && pos + 1 < text.size())
  {
    DWORD newStyle = 0;
    DWORD newColor = currentColor;
    bool newLine = false;
    // have a [ - check if it's an ON or OFF switch
    bool on(true);
    int endPos = pos++; // finish of string
    if (text[pos] == L'/')
    {
      on = false;
      pos++;
    }
    // check for each type
    if (text.Mid(pos,2) == L"B]")
    { // bold - finish the current text block and assign the bold state
      newStyle = FONT_STYLE_BOLD;
      pos += 2;
    }
    else if (text.Mid(pos,2) == L"I]")
    { // italics
      newStyle = FONT_STYLE_ITALICS;
      pos += 2;
    }
    else if (text.Mid(pos,10) == L"UPPERCASE]")
    {
      newStyle = FONT_STYLE_UPPERCASE;
      pos += 10;
    }
    else if (text.Mid(pos,10) == L"LOWERCASE]")
    {
      newStyle = FONT_STYLE_LOWERCASE;
      pos += 10;
    }
    else if (text.Mid(pos,3) == L"CR]" && on)
    {
      newLine = true;
      pos += 3;
    }
    else if (text.Mid(pos,5) == L"COLOR")
    { // color
      size_t finish = text.Find(L']', pos + 5);
      if (on && finish != CStdString::npos)
      { // create new color
        newColor = colors.size();
        colors.push_back(g_colorManager.GetColor(text.Mid(pos + 5, finish - pos - 5)));
        colorStack.push(newColor);
      }
      else if (!on && finish == pos + 5)
      { // revert to previous color
        if (colorStack.size() > 1)
          colorStack.pop();
        newColor = colorStack.top();
      }
      pos = finish + 1;
    }

    if (newStyle || newColor != currentColor || newLine)
    { // we have a new style or a new color, so format up the previous segment
      CStdStringW subText = text.Mid(startPos, endPos - startPos);
      if (currentStyle & FONT_STYLE_UPPERCASE)
        subText.ToUpper();
      if (currentStyle & FONT_STYLE_LOWERCASE)
        subText.ToLower();
      AppendToUTF32(subText, ((currentStyle & 3) << 24) | (currentColor << 16), parsedText);
      if (newLine)
        parsedText.push_back(L'\n');

      // and switch to the new style
      startPos = pos;
      currentColor = newColor;
      if (on)
        currentStyle |= newStyle;
      else
        currentStyle &= ~newStyle;
    }
    pos = text.Find(L'[',pos);
  }
  // now grab the remainder of the string
  CStdStringW subText = text.Mid(startPos, text.GetLength() - startPos);
  if (currentStyle & FONT_STYLE_UPPERCASE)
    subText.ToUpper();
  if (currentStyle & FONT_STYLE_LOWERCASE)
    subText.ToLower();
  AppendToUTF32(subText, ((currentStyle & 3) << 24) | (currentColor << 16), parsedText);
}