コード例 #1
0
ファイル: nuiLayout.cpp プロジェクト: JamesLinus/nui3
void nuiLayout::SetConstraint(nuiWidget* pWidget, const nglString& rDescription)
{
  nuiLayoutConstraint constraintH, constraintV;
  int pos = rDescription.Find('/');
  if (pos < 0)
  {
    nglString desc(rDescription);
    desc.Trim();
    constraintH.Set(desc);
  }
  else if (pos == 0)
  {
    nglString desc2 = rDescription.Extract(pos+1, rDescription.GetLength() - (pos + 1));
    desc2.Trim();
    constraintV.Set(desc2);
  }
  else
  {
    nglString desc1 = rDescription.Extract(0, pos);
    nglString desc2 = rDescription.Extract(pos+1, rDescription.GetLength() - (pos + 1));
    desc1.Trim();
    desc2.Trim();
    constraintH.Set(desc1);
    constraintV.Set(desc2);
  }

  SetConstraint(pWidget, constraintH, constraintV);
}
コード例 #2
0
// Stolen from nglPath!
static int32 GetRootPart(const nglString& rStr)
{
	if (rStr[0] == _T('/'))
	{
		if (rStr[1] != _T('/'))
			return 1;
    
		// //host[/path] (network address)
		// or /volume[/path] (standard unix like path)
		int32 end = rStr.Find(_T('/'), 2);
		return ((end > 0) ? end : rStr.GetLength());
	}
  
  // Find the protocol name:
  int col = rStr.Find(_T("://"), 0, true);
  
  return MIN(col + 3, rStr.GetLength());
}
コード例 #3
0
static bool Canonize(nglString& rStr)
{
  nglString canon;
  int32 len = rStr.GetLength();
  int32 root_part = GetRootPart(rStr);
  int32 last_slash = root_part;
  int32 slash = 0;
  
  canon = rStr.GetLeft(root_part);
  while (slash < len)
  {
    slash = rStr.Find(_T('/'), last_slash);
    if (slash == - 1)
      slash = len;
    
    if (((slash - last_slash) == 1) && (rStr.GetChar(last_slash) == _T('.')))
    {
      // Ignore '.'
    }
    else
      if (((slash - last_slash) == 2) && (!rStr.Compare(_T(".."), last_slash, 2)))
      {
        // Interpret '..'
        int32 prev_slash = canon.FindLast(_T('/'));
        if (prev_slash < root_part)
          prev_slash = root_part;
        
        if (!canon.IsEmpty() && canon.Compare(_T(".."), canon.GetLength() - 2, 2))
          canon.Delete(prev_slash);
        else
        {
          if (canon.GetLength() > root_part)
            canon += _T('/');
          canon += _T("..");
        }
      }
      else
      {
        // Simply append path node
        nglString node = rStr.Extract(last_slash, (slash - last_slash));
        if (canon.GetLength() > root_part)
          canon += _T('/');
        canon += node;
      }
    
    last_slash = slash + 1;
  }
  
  rStr = canon;
  return true;
}
コード例 #4
0
ファイル: nglKernel_WinXX.cpp プロジェクト: JamesLinus/nui3
bool nglKernel::SetClipboard(const nglString& rString)
{
  if (OpenClipboard(mHWnd))
  {
    EmptyClipboard();

    HGLOBAL hglbCopy = GlobalAlloc(GMEM_MOVEABLE, rString.GetLength()+1); 
    if (hglbCopy == NULL) 
    { 
      CloseClipboard(); 
      return false; 
    } 

    char* lptstrCopy = (char*)GlobalLock(hglbCopy); 
    memcpy(lptstrCopy, rString.GetChars(), rString.GetLength()+1); 
    GlobalUnlock(hglbCopy); 

    SetClipboardData(CF_TEXT, hglbCopy); 
    CloseClipboard();
    return true;
  }
  return false;
}
コード例 #5
0
ファイル: nglImageCodec.cpp プロジェクト: hamedmohammadi/nui3
bool nglImageCodecInfo::ExtensionMatch(nglString& rFileName)
{
  std::vector<nglString>::iterator ext;
  int filename_len = rFileName.GetLength();

  for (ext = mExtensions.begin(); ext < mExtensions.end(); ++ext)
  {
    int ext_size = (*ext).GetLength();

    if (!rFileName.Compare (*ext, filename_len - ext_size, ext_size, false))
      return true;
  }
  return false;
}
コード例 #6
0
ファイル: nglConsole_WinXX.cpp プロジェクト: JamesLinus/nui3
void nglConsole::OnOutput(const nglString& rText)
{
  // 'char' mode : string buffer is considered to use the locale's encoding
  Append(rText.GetChars());

  // Write to the standard win32 console:
#ifdef USE_STANDARD_WIN32_CONSOLE
  unsigned long res = 0;
  WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE),rText.GetChars(),rText.GetLength(),&res,NULL);
#endif

  // I don't care if this is slow, its really mandatory in win32.
  vector<nglString> vec;
  uint ret=rText.Tokenize(vec, _T('\n'));
  for (uint i=0; i<ret; i++)
  {
    OutputDebugString(vec[i].GetChars()); // fixme! to be removed ?
    OutputDebugString(_T("\n"));
  }
}
コード例 #7
0
int nglConsole::GetHistory (list<const nglString*>& rMatches, nglString& rFilter, bool IsCaseSensitive)
{
  #if NGL_DISABLE_CONSOLE
  return 0;
  #else

  int count = 0;
  list<nglString*>::reverse_iterator h_entry;
  list<nglString*>::reverse_iterator h_begin = mHistory.rbegin();

  rMatches.clear();
  int size = rFilter.GetLength();
  for (h_entry = mHistory.rend(); h_entry != h_begin; h_entry--)
    if (!rFilter.Compare(**h_entry, 0, size, IsCaseSensitive))
    {
      rMatches.push_front(*h_entry);
      count++;
    }

  return count;
  #endif
}
コード例 #8
0
void nglConsole::AddToHistory (const nglString& rLine)
{
  #if NGL_DISABLE_CONSOLE
  return;
  #else

  nglString* newline;
  uint new_linecnt, new_charcnt;

  if (!mUseHistory) return;

  // Filter empty lines
  nglString trimmed = rLine;
  trimmed.Trim();
  if (trimmed.GetLength() == 0) return;

  new_linecnt = mLineCnt + 1;
  new_charcnt = mCharCnt + rLine.GetLength();
  // Adjust history size according user-set limits
  while ((!mHistory.empty()) &&
         (((mLineMax > 0) && (new_linecnt > mLineMax)) ||
          ((mCharMax > 0) && (new_charcnt > mCharMax))))
  {
    list<nglString*>::iterator tail = mHistory.end();
    tail--; // mHistory.end() return an iterator just past the last element
    if (*tail)
    {
      new_charcnt -= (*tail)->GetLength();
      new_linecnt--;
      delete (*tail);
      mHistory.erase (tail);
    }
  }
  newline = new nglString (rLine);
  mHistory.push_front (newline);
  mLineCnt = new_linecnt;
  mCharCnt = new_charcnt;
  #endif
}
コード例 #9
0
ファイル: nuiUnicode.cpp プロジェクト: YetToCome/nui3
bool nuiSplitText(const nglString& rSourceString, nuiTextRangeList& rRanges, nuiSplitTextFlag flags)
{
  uint32 size = rSourceString.GetLength();

  rRanges.clear();
  if (!size)
    return true;

  const bool scriptchange = flags & nuiST_ScriptChange;
  const bool rangechange = flags & nuiST_RangeChange;
  const bool wordboundary = flags & nuiST_WordBoundary;
  const bool directionchange = flags & nuiST_DirectionChange;
  const bool mergecommonscript = flags & nuiST_MergeCommonScript;
  uint32 lastpos = 0;
  uint32 curpos = 0;
  const nglChar& ch = rSourceString[curpos];
  int32 direction = nuiGetUnicodeDirection(ch);
  int32 newdirection = direction;
  
  nglChar scriptlow = 0;
  nglChar scripthi = 0;
  nuiUnicodeScript script = nuiGetUnicodeScript(ch, scriptlow, scripthi);
  nuiUnicodeScript newscript = script;

  nglChar rangelow = 0;
  nglChar rangehi = 0;
  nuiUnicodeRange range = nuiGetUnicodeRange(ch, rangelow, rangehi);
  nuiUnicodeRange newrange = range;
  bool blank = nuiIsUnicodeBlank(ch);
  bool newblank = blank;
  curpos++;
  
  while (curpos != size)
  {
    bool brk = false;
    const nglChar& ch = rSourceString[curpos];

    if (wordboundary)
    {
      newblank = nuiIsUnicodeBlank(ch);
      if (newblank != blank)
        brk = true;
    }
    
    if (scriptchange)
    {
      if (ch < scriptlow || ch > scripthi) // still in the last range?
      {
        if (!wordboundary)
          newblank = nuiIsUnicodeBlank(ch);
        if (!newblank)
        {
          newscript = nuiGetUnicodeScript(ch, scriptlow, scripthi);
          if ((newscript != script) && !(mergecommonscript && newscript == eScriptCommon))
          {
            brk = true;
          }
        }
      }
    }
    
    if (rangechange)
    {
      if (ch < rangelow || ch > rangehi) // still in the last range?
      {
        if (!wordboundary)
          newblank = nuiIsUnicodeBlank(ch);
        if (!newblank)
        {
          newrange = nuiGetUnicodeRange(ch, rangelow, rangehi);
          if (newrange != range)
            brk = true;
        }
      }
    }
    
    
    if (directionchange)
    {
      newdirection = nuiGetUnicodeDirection(ch);
      if (newdirection != direction)
        brk = true;
    }
    
    if (brk)
    {
      nuiTextRange r;
      r.mLength = curpos - lastpos; // count of unicode code points
      r.mDirection = direction; // even: Left to right, odd: right to left
      r.mScript = script; // What script if this range of text
      r.mRange = range; // What script if this range of text
      r.mBlank = blank; // Does this range contains strictly blank (space, tab, return, etc.) code points.
      
      rRanges.push_back(r);
      
      lastpos = curpos;
      direction = newdirection;
      script = newscript;
      range = newrange;
      blank = newblank;
    }
    
    curpos++;
  }

  // Last range:
  nuiTextRange r;
  r.mLength = curpos - lastpos; // count of unicode code points
  r.mDirection = direction; // even: Left to right, odd: right to left
  r.mScript = script; // What script if this range of text
  r.mRange = range; // What script if this range of text
  r.mBlank = blank; // Does this range contains strictly blank (space, tab, return, etc.) code points.
  
  rRanges.push_back(r);
  
  
  return true;
}
コード例 #10
0
ファイル: nuiTextLayout.cpp プロジェクト: kentvv/nui3
bool nuiTextLayout::Layout(const nglString& rString)
{
  // Transform the string in a vector of nglUChar, also keep the offsets from the original chars to the nglUChar and vice versa
  int32 len = rString.GetLength();
  int32 i = 0;
  
  //printf("layout ");
  while (i < len)
  {
    nglUChar ch = rString.GetNextUChar(i);
    //printf("'%c' (%d) ", (char)ch, ch);
    mUnicode.push_back(ch);
    mOffsetInString.push_back(i);
    mOffsetInUnicode.push_back(mUnicode.size() - 1);
  }
  
  //printf("\n");
  
  // General algorithm:
  // 1. Split text into paragraphs (LayoutText)
  // 2. Split paragraphs into ranges (LayoutParagraph)
  // 3. Split ranges into fonts
  // 4. Split ranges into lines / words if needed
  
  int32 start = 0;
  int32 position = 0;
  int32 count = mUnicode.size();
  while (position < count)
  {
    // Scan through the text and look for end of line markers
    nglUChar ch = mUnicode[position];
    if (ch == '\n' || ch == 0xb || ch == 0x2028 || ch == 0x2029)
    {
      // Found a paragraph
      //printf("Paragraph %d -> %d (%d chars)\n", start, position, position - start);
      LayoutParagraph(start, position - start); // Eat the \n char
      start = position + 1;
    }
    position++;
  }
  
  if (start < position)
  {
    //printf("last Paragraph %d -> %d (%d chars)\n", start, position, position - start);
    LayoutParagraph(start, position - start); // Eat the \n char
    start = position;
  }

  mAscender = 0;
  mDescender = 0;

  //printf("Map scripts to fonts:\n");
  int32 c = 0;
  // Find the needed fonts for each script:
  std::map<nuiUnicodeScript, nuiFontBase*> FontSet;
  {
    std::map<nuiUnicodeScript, std::set<nglUChar> >::iterator it = mCharsets.begin();
    std::map<nuiUnicodeScript, std::set<nglUChar> >::iterator end = mCharsets.end();
    while (it != end)
    {
      //printf("%d %s -> ", c, nuiGetUnicodeScriptName(it->first).GetChars());
      const std::set<nglUChar>& charset(it->second);
      nuiFontBase* pFont = NULL;
      // First try the requested font
      {
        std::set<nglUChar>::const_iterator it = charset.begin();
        std::set<nglUChar>::const_iterator end = charset.end();
        
        while (it != end && mStyle.GetFont()->GetGlyphIndex(*it) > 0)
          ++it;
        
        // If all the glyphs are available in the font we're done...
        if (it == end)
          pFont = mStyle.GetFont();
        else
        {
          //printf("[couldn't find glyph %d '%c' in requested font] ", *it, *it);
        }
      }

      // If the requested font doesn't work, try to find one that does:
      if (!pFont)
      {
        nuiFontRequest request(mStyle.GetFont());
        request.MustHaveGlyphs(charset, 500, false);
        pFont = nuiFontManager::GetManager().GetFont(request);
      }
      
      FontSet[it->first] = pFont;
      
      //printf("%s\n", pFont->GetFamilyName().GetChars());
      
      ++it;
      c++;
    }
  }
  //printf("Map scripts to fonts DONE\n");

  i = 0;
  nuiRect rect;
  float PenX = 0;
  float PenY = 0;
  // Assign the correct font to each run
  for (uint32 p = 0; p < mpParagraphs.size(); p++)
  {
    Paragraph* pParagraph = mpParagraphs[p];
    for (uint32 l = 0; l < pParagraph->size(); l++)
    {
      nuiTextLine* pLine = (*pParagraph)[l];
      
      pLine->SetPosition(PenX, PenY);
      
      PenX = 0;
      float x = 0;
      float y = 0;
      for (uint32 r = 0; r < pLine->GetRunCount(); r++)
      { 
        nuiTextRun* pRun = pLine->GetRun(r);
        pRun->mX = x;
        pRun->mY = y;
        nuiFontBase* pFont = FontSet[pRun->GetScript()];
        if (!pRun->IsDummy())
        {
          // Only shape real runs.
          pRun->SetFont(pFont);
          pFont->Shape(pRun);

          nuiFontInfo finfo;
          pFont->GetInfo(finfo);
          
          
          // Prepare glyphs:
          std::vector<nuiTextGlyph>& rGlyphs(pRun->GetGlyphs());
          for (int32 g = 0; g < rGlyphs.size(); g++)
          {
            nuiTextGlyph& rGlyph(rGlyphs.at(g));
            
            pFont->PrepareGlyph(PenX + x, PenY + y, rGlyph);
            
            const nuiSize W = rGlyph.AdvanceX;
            //    nuiSize h = finfo.AdvanceMaxH;
            const nuiSize X = rGlyph.mX + rGlyph.BearingX;
            const nuiSize Y = rGlyph.mY - finfo.Ascender;
            const nuiSize H = finfo.Height;
            
            nuiRect rr(rect);
            rect.Union(rr, nuiRect(PenX + x + X, PenY + y + Y, W, H));
          }
        }
        
        x += pRun->GetAdvanceX();
        //y += pRun->GetAdvanceY();


        //printf("\trange %d <%d.%d.%d> (%d - %d) (%s --> %s / %s) (advance: %f / %f)\n", i, p, l, r, pRun->GetPosition(), pRun->GetLength(), nuiGetUnicodeScriptName(pRun->GetScript()).GetChars(), pFont->GetFamilyName().GetChars(), pFont->GetStyleName().GetChars(), pRun->GetAdvanceX(), pRun->GetAdvanceY());

        i++;
      }
      PenY += pLine->GetAdvanceY();
    }
  }
  
  nuiTextLine* pFirstLine = NULL;
  if (GetParagraphCount() > 0)
    if (GetLineCount(0) > 0)
      pFirstLine = GetLine(0, 0);
  
  if (pFirstLine)
    mAscender = pFirstLine->GetAscender();
    
  nuiTextLine* pLastLine = NULL;
  if (GetParagraphCount() > 0)
    if (GetLineCount(GetParagraphCount() - 1) > 0)
      pLastLine = GetLine(GetParagraphCount() - 1, GetLineCount(GetParagraphCount() - 1) - 1);
  
  if (pLastLine)
    mDescender = pLastLine->GetDescender();


  mXMin = rect.Left();
  mXMax = rect.Right();
  mYMin = rect.Top();
  mYMax = rect.Bottom();

  mCharsets.clear();
  return true;
}
コード例 #11
0
ファイル: nuiTCPClient.cpp プロジェクト: JamesLinus/nui3
int nuiTCPClient::Send(const nglString& rString)
{
  return Send((uint8*)rString.GetChars(), rString.GetLength());
}
コード例 #12
0
ファイル: nuiTCPClient.cpp プロジェクト: JamesLinus/nui3
size_t nuiPipe::Write(const nglString& rString)
{
  return Write((const uint8*)rString.GetChars(), rString.GetLength());
}
コード例 #13
0
ファイル: nuiTCPClient.cpp プロジェクト: JamesLinus/nui3
size_t nuiTCPClient::BufferedSend(const nglString& rString, bool BufferOnly)
{
  return BufferedSend((uint8*)rString.GetChars(), rString.GetLength(), BufferOnly);
}
コード例 #14
0
ファイル: AMXClient.cpp プロジェクト: vincent-bongiorno/home
bool AMXClient::Send(const nglString& rData)
{
  return (mpClient->Send(rData) == rData.GetLength());
}