示例#1
0
void CReportCtrl::RemoveEditOptions(CXTPReportRecordItem *pItem,DWORD_PTR dwData)
{
	CXTPReportRecordItemEditOptions *pEditOptions = pItem->GetEditOptions(NULL);
	ASSERT(pEditOptions != NULL);

	CXTPReportRecordItemConstraints *pConstraints = pEditOptions->GetConstraints();
	ASSERT(pConstraints != NULL);

	CXTPReportRecordItemConstraint *pConstraint = pEditOptions->FindConstraint(dwData);
	ASSERT (pConstraint != NULL);

	CDWordArray dwDatas;
	CStringArray strConstraints;

	for (int i=0; i<pConstraints->GetCount(); ++i)
	{
		CXTPReportRecordItemConstraint *pConstraint = pConstraints->GetAt(i);
		if (pConstraint->m_dwData != dwData)
		{
			dwDatas.Add(pConstraint->m_dwData);
			strConstraints.Add(pConstraint->m_strConstraint);
		}
	}

	pConstraints->RemoveAll();
	for (int i=0; i<dwDatas.GetCount(); ++i)
		pEditOptions->AddConstraint(strConstraints[i],dwDatas[i]);
}
示例#2
0
bool
EmbedeedFontMan::AddFont(const CString sFontFolder, const CString sFontName){
	CString sDir = sFontFolder;
	if( sDir.GetAt(sDir.GetLength() - 1) != '\\' )
		sDir += _T("\\");

	EmbedeedFont* pFont = new EmbedeedFont();

	// Load characters code map. {{
	BYTE*	lpContent	= NULL;
	int		nSize		= 0;
	if( Path::ReadFileContent(sDir + _T("codes.txt"), lpContent, nSize) && nSize > 0 ){
		CString sContent;
		memcpy(sContent.GetBufferSetLength(nSize), lpContent, nSize);

		CStringArray arrStrings;
		StringHelper::Split(&sContent, _T(";"), arrStrings);

		CString sCharCode;
		for(int i=0; i<arrStrings.GetCount(); i++){
			sCharCode		= arrStrings.GetAt(i);
			int nCharCode	= 0;
			// Hex value
			if( sCharCode.GetAt(0) == '#' )
				nCharCode = StringHelper::HexStringIntoInt(&((TCHAR*)sCharCode.GetBuffer())[1], sCharCode.GetLength() - 1);
			else
				nCharCode = _ttoi(sCharCode.GetBuffer());
			pFont->m_arrCharacters.Add((void*)nCharCode, (void*)i);
			}
		}
	else{
#ifdef _DEBUG
		CString sMsg;
		sMsg.Format(_T("Couldn't find %s"), sDir + _T("codes.txt"));
		AfxMessageBox(sMsg);
#endif
		if( lpContent )
			delete [] lpContent;
		delete pFont;
		return false;
		}
	// }}

	if( lpContent ){
		delete [] lpContent;
		lpContent = NULL;
		}

	CStringArray arrFileNames;
	if( Path::GetFilesByExtention(sDir, _T("*.bmp"), arrFileNames, true) == 0 ){
		delete pFont;
		return false;
		}
	
	for(int i=0; i<arrFileNames.GetCount(); i++){
		CString sName = arrFileNames.GetAt(i);
		CString sName2 = sName;
		CString sFile = sDir + sName;

		if( sName.Left(sFontName.GetLength()) != sFontName )
			continue; // Skip wrong file name.

		sName.Delete	(0, sFontName.GetLength());
		sName.MakeLower	();

		int nIndex = 0;
		EmbedeedFontItemInfo* pInfo = new EmbedeedFontItemInfo();
		pInfo->ZeroInit();

		// Bold
		if( sName.GetAt(nIndex) == 'b' ){
			pInfo->m_nCharFlags |= EmbedeedFontItemInfo::EMBEDEED_FONT_FLAG_BOLD;
			nIndex ++;
			}
		// Underline
		if( sName.GetAt(nIndex) == 'u' ){
			pInfo->m_nCharFlags |= EmbedeedFontItemInfo::EMBEDEED_FONT_FLAG_UNDERLINE;
			nIndex ++;
			}
		// Italic
		if( sName.GetAt(nIndex) == 'i' ){
			pInfo->m_nCharFlags |= EmbedeedFontItemInfo::EMBEDEED_FONT_FLAG_ITALIC;
			nIndex ++;
			}

		// Load characters map image and detect characters left offset and width (in pixels). {{
		CImage* pImage = ImageHelper::LoadImage(sFile, -1, -1, false);
		if( pImage ){
			BITMAP bmImage;
			GetObject(*pImage, sizeof(BITMAP), &bmImage);

			int			nWidthLimit				= bmImage.bmWidth;
			int			nSymbolCt				= 0;
			BYTE*		pBits					= (BYTE*)bmImage.bmBits;
			int			nXOffset				= 0;
			int			nBPP					= bmImage.bmBitsPixel/8;
			int			nSymbolMostLeftOffset	= -1;
			int			nSymbolMostRightOffset	= -1;
			CDWordArray arrSymbolLeftOffsetAndWidth;
			CString		sSymbolStartPointAndWidth;

			int nMaxXOffset = bmImage.bmWidth;
			for(int x=nXOffset; x<nMaxXOffset; x++){
				bool bClearLine = true;
				for(int y=0; y<bmImage.bmHeight; y++){
					BYTE* pLineStartingBits = &pBits[((bmImage.bmHeight - y - 1)*bmImage.bmWidthBytes)];
					BYTE* pPixel			= &pLineStartingBits[x*nBPP];

					// Is pixel visible.
					if( pPixel[0] > 10 ){
						bClearLine = false;
						if( nSymbolMostLeftOffset > -1 )
							nSymbolMostRightOffset = x;
						else
							nSymbolMostLeftOffset = x;
						continue;
						}
		
					pPixel = &pPixel[nBPP];
					}

				if( bClearLine && nSymbolMostLeftOffset > -1 ){
					if( nSymbolMostRightOffset == -1 )
						nSymbolMostRightOffset = nSymbolMostLeftOffset;
					DWORD dwCombineVal = (nSymbolMostLeftOffset << 16) | ((nSymbolMostRightOffset - nSymbolMostLeftOffset + 1)&0xFFFF);
					arrSymbolLeftOffsetAndWidth.Add(dwCombineVal);

#ifdef _DEBUG
					CString sFormat;
					sFormat.Format(_T("%d:%d;"), nSymbolMostLeftOffset, nSymbolMostRightOffset - nSymbolMostLeftOffset + 1);
					sSymbolStartPointAndWidth += sFormat;
#endif
					nSymbolMostLeftOffset	= -1;
					nSymbolMostRightOffset	= -1;
					}
				}

			pInfo->m_imageCharacters.Attach(pImage->Detach());
			delete pImage;

			if( (arrSymbolLeftOffsetAndWidth.GetCount() == pFont->m_arrCharacters.GetCount()) ){
				pInfo->m_pCharPoints = new CPoint[arrSymbolLeftOffsetAndWidth.GetCount()];
				for(int j=0; j<arrSymbolLeftOffsetAndWidth.GetCount(); j++){
					DWORD dwCombineVal = arrSymbolLeftOffsetAndWidth.GetAt(j);
					pInfo->m_pCharPoints[j].x = (int)(dwCombineVal>>16);
					pInfo->m_pCharPoints[j].y = (int)(dwCombineVal&0xFFFF);
					}
				}
			else{
#ifdef _DEBUG
				CBitmap bmImg;
				ImageHelper::CreateDIBBitmap(pInfo->m_imageCharacters.GetBPP(), bmImg, RGB(0, 0, 0), pInfo->m_imageCharacters.GetWidth(),
					pInfo->m_imageCharacters.GetHeight()*2, 0);

				CDC memDC;
				memDC.CreateCompatibleDC(NULL);
				::SelectObject(memDC, bmImg.m_hObject);

				CDC srcDC;
				srcDC.CreateCompatibleDC(NULL);
				::SelectObject(srcDC, pInfo->m_imageCharacters);
				memDC.BitBlt(0, 0, pInfo->m_imageCharacters.GetWidth(), pInfo->m_imageCharacters.GetHeight(), &srcDC, 0, 0, SRCCOPY);

				int nHeight = pInfo->m_imageCharacters.GetHeight();
				for(int j=0; j<arrSymbolLeftOffsetAndWidth.GetCount(); j++){
					DWORD dwCombineVal = arrSymbolLeftOffsetAndWidth.GetAt(j);
					int nLeft = (int)(dwCombineVal>>16);
					int nWidth = (int)(dwCombineVal&0xFFFF);

					memDC.FillSolidRect(nLeft, nHeight, nWidth, nHeight, RGB(255, 255, 0));
					}

				DeleteFile(sDir + _T("__") + sName2);
				CImage img;
				img.Attach((HBITMAP)bmImg.Detach());
				img.Save(sDir + _T("__") + sName2);
				img.Destroy();
				
				CString sMsg;
				sMsg.Format(_T("Characters count is not the same for font '%s' item '%s'"), sFontName, sName);
				AfxMessageBox(sMsg);
#endif
				delete pInfo;
				continue;
				}

			pInfo->m_nCharCount = arrSymbolLeftOffsetAndWidth.GetCount();
			}