- printerframework_src.zip
- Devp
- Bin
- Printer.dll
- Test.exe
- Include
- Lib
- Sources
- Printer
- Doc
- AccentCesure.sty
- html
- Image
- ArchitectureMFC.png
- MFC.png
- PreviewRefactor.png
- PrinterPath.png
- PrintMfc.png
- PrintRefactor.png
- UMLPrinter.png
- IntroPrinter.doc
- Licence
- MAKEDOC.BAT
- MAKEPDF.BAT
- MAKEPS.BAT
- manual.pdf
- printer.dox
- printer.log
- printer.tag
- Readme.txt
- Sources
- Test
|
// FormatString.cpp: implementation of the CFormatString class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "FormatString.h"
namespace printer {
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CFormatString::CFormatString(const CString& strText)
{
m_strText=strText;
}
CFormatString::~CFormatString()
{
}
//////////////////////////////////////////////////////////////////////
// Static
//////////////////////////////////////////////////////////////////////
void
CFormatString::GetCesure(CDC* pDC, int nLon, CString& strText, int& nFirst, int& nLast)
{
CSize size;
nLast =0;
// Avaler les blancs
CString strTrim = strText;
strTrim.TrimLeft();
int nLength = strTrim.GetLength();
nFirst = strText.GetLength()-nLength;
for(int i=0; i< nLength; i++) {
if(strTrim[i]==' ') {
CString strTmp =strTrim.Left(i);
size = pDC->GetTextExtent(strTrim.Left(i));
if (size.cx > nLon) {
break;
}
nLast = i+nFirst;
}
}
// Si sortie sur fin de list
if (i==nLength) {
size = pDC->GetTextExtent(strTrim);
if ( size.cx <= nLon ) {
nLast = i+ nFirst;
}
}
// TRACE ("%d %d\n", nFirst, nLast);
// Si nLast =0 => Le mot + long que la taille
// => c�sure arbitraitre au max
if (nLast==0) {
for(int i=0; i< nLength; i++) {
size = pDC->GetTextExtent(strTrim.Left(i));
if (size.cx > nLon) {
break;
}
}
nLast = i+nFirst;
}
}
void
CFormatString::Initialize(CDC* pDC, int nLon)
{
m_listFirstLast.clear();
int nFirst;
int nLast;
int nOld =0;
CString strText = m_strText;
CString strTmp;
do {
GetCesure(pDC, nLon, strText, nFirst, nLast);
strTmp = strText.Mid(nFirst, nLast-nFirst);
strText = strText.Mid(nLast);
m_listFirstLast.push_back( std::pair<int,int>(nOld+nFirst, nOld+nLast) );
nOld += nLast;
// TRACE("'%s'\n ", strTmp);
} while (!strText.IsEmpty());
}
int
CFormatString::GetNbLignes()
{
return m_listFirstLast.size();
}
CString
CFormatString::GetSubLigne(int nIndex)
{
ASSERT( nIndex < GetNbLignes() );
ASSERT( nIndex >= 0);
int nFirst =m_listFirstLast[nIndex].first;
int nLast = m_listFirstLast[nIndex].second;
return m_strText.Mid(nFirst, nLast-nFirst);
}
int
CFormatString::GetLength(int nIndex)
{
return GetSubLigne(nIndex).GetLength();
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.