bool
ESSimpleRenderView::CalcLineSize(RenderLine* pLine){
	if( !pLine ) return false;
	_Size		szLine(0, 0);
	RenderItem* pItem			= pLine->m_pFirstItem;
	int			nLineWidthMax	= -1;
	bool		bBreakLine		= false;

	while( pItem ){
		if( bBreakLine ){
			szLine.cy	+= std::max(szLine.cy, pItem->m_szItem.cy);
			szLine.cx	= pItem->m_szItem.cx;
			}
		else{
			szLine.cy	= std::max(szLine.cy, pItem->m_szItem.cy);
			szLine.cx	+= pItem->m_szItem.cx;
			}

		if( pItem->m_bBreakLine ){
			bBreakLine = true;
			if( nLineWidthMax < szLine.cx )
				nLineWidthMax = szLine.cx;
			szLine.cx = 0;
			}
		else
			bBreakLine = false;
		pItem = pItem->m_pNext;
		}

	// In case when line break occures.
	if( nLineWidthMax != -1 )
		szLine.cx = nLineWidthMax;
	pLine->m_szLine	= szLine;
	return true;
	}
Example #2
0
size_t CSegmentDownloader::ProcessHeader(char* ptr, size_t size, size_t nmemb, int index)
{
	if( IS_LOG_ENABLED(THE_LOGGER, log4cplus::DEBUG_LOG_LEVEL) )
	{
		CString szLine(ptr, size * nmemb);
		CCommonUtils::ReplaceCRLF(szLine);
		
		CString szMsg;
		szMsg.Format("Task[%02d]: %d - %s", m_dlParam.m_nTaskID, index, szLine);
		LOG4CPLUS_DEBUG_STR(THE_LOGGER, (LPCTSTR)szMsg)
	}
	
	CSegmentInfoEx* pSegmentInfo = GetSegmentInfo(index);
	fwrite(ptr, size, nmemb, pSegmentInfo->m_lpFileHeader);
	
	//Parse
	CString szScratch(ptr, size * nmemb);
	int nc;
	do 
	{
		//1. check if status line
		int nRspCode = CCommonUtils::GetHTTPStatusCode(szScratch);
		
		//This is a status line
		if(nRspCode > 0)
		{
			pSegmentInfo->m_headerInfo.Reset();
			pSegmentInfo->m_headerInfo.m_nHTTPCode = nRspCode;
			pSegmentInfo->m_headerInfo.m_szStatusLine = szScratch;
			CCommonUtils::ReplaceCRLF(pSegmentInfo->m_headerInfo.m_szStatusLine, NULL, NULL);
			break;
		}
		
		
		//2. check if Content-Length line
		int nContentLength = -1;
		nc = sscanf((LPCTSTR)szScratch, "Content-Length: %d", &nContentLength);
		if(nContentLength >= 0)
		{
			pSegmentInfo->m_headerInfo.m_nContentLength = nContentLength;
			break;
		}
		
		//3. check if Content-Range line
		int x, y, total;
		nc = sscanf((LPCTSTR)szScratch, "Content-Range: bytes %d-%d/%d", &x, &y, &total);
		if(nc == 3)
		{
			pSegmentInfo->m_headerInfo.m_nContentRangeX = x;
			pSegmentInfo->m_headerInfo.m_nContentRangeY = y;
			pSegmentInfo->m_headerInfo.m_nContentRangeTotal = total;
			break;
		}
		
		//we don't care other things
		
	} while ( 0 );
	
	return (size_t)(size * nmemb);
}
Example #3
0
CString Recognize(CString szUrl)
{
    CString szResult("");
    if (hasInit == FALSE || chkFilePath.IsEmpty())
	{
		CString szFileName;
		DWORD nProcID = ::GetCurrentProcessId();
		GetProcessNameByProcessID(nProcID, szFileName);

		int index = szFileName.ReverseFind('\\');
		chkFilePath = szFileName.Left(index) + "\\chkcode.txt";

		hasInit = TRUE;
	}
	
    CStdioFile file;
    if (szLastUrl != szUrl)
    {
        if (file.Open(chkFilePath, CFile::modeCreate | CFile::modeReadWrite))
        {
            file.WriteString(szUrl);
            szLastUrl = szUrl;
            file.Close();
        }
    }

	CString szLine("");
    if (file.Open(chkFilePath, CFile::modeRead))
    {
        file.ReadString(szLine);
        if (szLine.GetLength() > szUrl.GetLength() + 1)
        {
            szResult = szLine.Mid(szUrl.GetLength() + 1);
        }
        file.Close();
    }
	
	return szResult;
}