1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
|
void CDonneesView::OnPrint(CDC * pDC, CPrintInfo * pInfo)
{
CDonneesView * pView;
CDonneesDoc * pDoc = reinterpret_cast<CDonneesDoc*>(GetDocument());
int nMargins = 150;
int iVerticalSize = (pDC->GetDeviceCaps(VERTRES)) - nMargins;
CString str;
CRect strRect(0,0,0,0);
CRect rcCalcText(0,0,0,0);
int nStringheight=0, nRowSpace=0;
TEXTMETRIC tm;
pDC->SetMapMode(MM_TEXT);
int nPage=1;
CStdioFile File;
File.Open(pDoc->GetTitle(), CFile::modeNoTruncate | CFile::modeRead | CFile::typeText);
int iY = 300;
pDC->StartPage();
while(File.ReadString(str)) // Tant qu'on lit une chaïne de caractères dans le fichier
{
pDC->GetTextMetrics(&tm);
CString text = str; // On déclare une variable tampon qui contient la ligne en lecture
//MessageBox(text);
nRowSpace = tm.tmExternalLeading;
strRect.top=iY;
strRect.left = 200;
//strRect.bottom = (strRect.top + nStringheight);
pInfo->m_rectDraw.SetRect(0,0,pDC->GetDeviceCaps(HORZRES),pDC->GetDeviceCaps(VERTRES));
pInfo->m_nCurPage = nPage;
//Pour optimisation, déclarer une variable pour remplacer GetLength()
int Length = text.GetLength();
if(Length == 0)
{
pDC->DrawText(text, rcCalcText, DT_CALCRECT);
strRect.right = pDC->GetDeviceCaps(HORZRES);
nStringheight = rcCalcText.Height();
strRect.bottom = (strRect.top + nStringheight);
pDC->DrawText(text,strRect,DT_WORDBREAK | DT_EXPANDTABS);
}
//SI ** ou -> ON COLORISE EN ROUGE
if((Length > 1) && ((text.Left(2) == "**") || (text.Left(2)=="->")))
{
//toute la ligne en couleur de bloc
for(int i=0; i<Length ; i++)
{
pDC->SetTextColor(RGB(255,0,0));
pDC->DrawText(text, rcCalcText, DT_CALCRECT);
strRect.right = pDC->GetDeviceCaps(HORZRES);
nStringheight = rcCalcText.Height();
strRect.bottom = (strRect.top + nStringheight);
pDC->DrawText(text,strRect,DT_WORDBREAK | DT_EXPANDTABS);
}
}
//FIN COLORATION ROUGE
//TITRE COLORISATION EN ORANGE
else
if((Length > 0) && (text.Left(1) == "*")
&& !((Length > 1) && (text.Left(2) == "**")))
{
//toute la ligne en couleur de titre
for(int i=0; i<Length; i++)
{
pDC->SetTextColor(RGB(255,100,0));
pDC->DrawText(text, rcCalcText, DT_CALCRECT);
strRect.right = pDC->GetDeviceCaps(HORZRES);
nStringheight = rcCalcText.Height();
strRect.bottom = (strRect.top + nStringheight);
pDC->DrawText(text,strRect,DT_WORDBREAK | DT_EXPANDTABS);
}
}
//TITRE COLORISATION EN ORANGE
//COMMENTAIRE COLORISATION EN VERT
else
if ((Length > 1) && (text.Left(2) == "c ") || (text.Left(2) == "C ") || (text.Left(1) == "!"))
{
//COULEUR DE COMMENTAIRE
for(int i=0; i<Length; i++)
{
pDC->SetTextColor(RGB(0,180,0));
pDC->DrawText(text, rcCalcText, DT_CALCRECT);
strRect.right = pDC->GetDeviceCaps(HORZRES);
nStringheight = rcCalcText.Height();
strRect.bottom = (strRect.top + nStringheight);
pDC->DrawText(text,strRect,DT_WORDBREAK | DT_EXPANDTABS);
}
}
//FIN COMMENTAIRE COLORISATION EN VERT
//lignes spéciales
else if((Length > 1) &&
((text.Left(2) == "M ") || (text.Left(2) == "M*")
|| (text.Left(2) == "C*")|| (text.Left(2) == "m ")
|| (text.Left(2) == "m*")|| (text.Left(2) == "c*")
|| (text.Left(2) == "$M")|| (text.Left(2) == "$E")))
{
//toute la ligne en couleur de spéciale
for(int i=0; i<Length; i++)
{
pDC->SetTextColor(RGB(0,0,255));
pDC->DrawText(text, rcCalcText, DT_CALCRECT);
strRect.right = pDC->GetDeviceCaps(HORZRES);
nStringheight = rcCalcText.Height();
strRect.bottom = (strRect.top + nStringheight);
pDC->DrawText(text,strRect,DT_WORDBREAK | DT_EXPANDTABS);
}
}
//CAS PARTICULIER DECOUPAGE DE CHAINES
else
{
CRect rcWord(0,0,0,0);
CString reste = text;
CString word;
CString txtCalc = "";
int i = 0;
//MessageBox(_T("Salut toi !"));
while(reste.GetLength() > 0)
{
i++;
if(reste.GetAt(i) == ' ')
{
word = reste.Left(i);//Sûre
//MessageBox(_T(word)); // affiche le bon word
reste = reste.Right(reste.GetLength() - i - 1);//Sûre
//MessageBox(_T(reste.Right(1)));
//MessageBox(_T(reste)); // affiche le bon reste
txtCalc = txtCalc + word + " ";//Sûre
//MessageBox(_T(txtCalc)); //affiche le bon txtCalc
if((word == "$I") || (word == "$R")
|| (word == "$c")
|| (word == "$o") || (word == "$M") || (word == "$E")
|| (word == "$B") || (word == "$F") || (word == "$Si")
|| (word == "Alors") || (word == "$Sinon") || (word == "$Sifin")
|| (word == "@") || (word == "$G") || (word == "$P")
|| (word == "+") || (word == "-") || (word == "*")
|| (word == "^") || (word == "cos") || (word == "sin")
|| (word == "tan") || (word == "abs") || (word == "int")
|| (word == "TY") || (word == "EL") || (word == "NO")
|| (word == "DA") || (word == "CA") || (word == "XX")
|| (word == "YY") || (word == "ZZ") || (word == "FIC")
|| (word == "N1") || (word == "N2") || (word == "N3")
|| (word == "N4") || (word == "IX") || (word == "IY")
|| (word == "IZ") || (word == "MO") || (word == "NU")
|| (word == "DE") || (word == "SE") || (word == "CE")
|| (word == "CN") || (word == "MAT") || (word == "EP")
|| (word == "MOD") || (word == "EP") || (word == "SL")
|| (word == "SL") || (word == "MOD") || (word == "NI")
|| (word == "FC") || (word == "CO") || (word == "DEN"))
{
//strRect.bottom = 0;
pDC->DrawText(word, rcWord, DT_CALCRECT);
pDC->DrawText(txtCalc, rcCalcText, DT_CALCRECT);//On calcule le rectangle pour le mot en fonction des mots précédents
pDC->SetTextColor(RGB(0,0,255));// On indique au DC qu'on souhaite que notre mot soit colorié en bleu
strRect.right = pDC->GetDeviceCaps(HORZRES);//rcCalcText.right; // On étend en largeur (vers la droite) notre rectangle de dessin
nStringheight = rcCalcText.Height(); // On indique la hauteur de notre mot (la taille du mot en hauteur)
strRect.left = rcCalcText.right - rcWord.right;
strRect.bottom = (strRect.top + nStringheight); //On indique au côté du bas l'extension qu'il doit prendre
pDC->DrawText(word, strRect, DT_WORDBREAK | DT_EXPANDTABS);
}
else
{
//strRect.bottom = 0;
pDC->DrawText(word, rcWord, DT_CALCRECT);
pDC->DrawText(txtCalc, rcCalcText, DT_CALCRECT);//On calcule le rectangle pour le mot en fonction des mots précédents
if(word.Left(2) == "$.")
pDC->SetTextColor(RGB(255,0,255));
else
pDC->SetTextColor(RGB(0,0,0));// On indique au DC qu'on souhaite que notre mot soit colorié en bleu
strRect.right = rcCalcText.right; // On étend en largeur (vers la droite) notre rectangle de dessin
nStringheight = rcCalcText.Height();// On indique la hauteur de notre mot (la taille du mot en hauteur)
strRect.bottom = (strRect.top + nStringheight); //On indique au côté du bas l'extension qu'il doit prendre
strRect.left = rcCalcText.right - rcWord.right;
pDC->DrawText(word, strRect, DT_WORDBREAK | DT_EXPANDTABS);
}
i=0;
}
if(reste.GetAt(i+1) == NULL)
{
word = reste;
txtCalc = txtCalc + " " + word;
if((word == "$I") || (word == "$R") || (word == "$c")
|| (word == "$o") || (word == "$M") || (word == "$E")
|| (word == "$B") || (word == "$F") || (word == "$Si")
|| (word == "Alors") || (word == "$Sinon") || (word == "$Sifin")
|| (word == "@") || (word == "$G") || (word == "$P")
|| (word == "+") || (word == "-") || (word == "*")
|| (word == "^") || (word == "cos") || (word == "sin")
|| (word == "tan") || (word == "abs") || (word == "int")
|| (word == "TY") || (word == "EL") || (word == "NO")
|| (word == "DA") || (word == "CA") || (word == "XX")
|| (word == "YY") || (word == "ZZ") || (word == "FIC")
|| (word == "N1") || (word == "N2") || (word == "N3")
|| (word == "N4") || (word == "IX") || (word == "IY")
|| (word == "IZ") || (word == "MO") || (word == "NU")
|| (word == "DE") || (word == "SE") || (word == "CE")
|| (word == "CN") || (word == "MAT") || (word == "EP")
|| (word == "MOD") || (word == "EP") || (word == "SL")
|| (word == "SL") || (word == "MOD") || (word == "NI")
|| (word == "FC") || (word == "CO") || (word == "DEN"))
{
//strRect.bottom = 0;
pDC->DrawText(word, rcWord, DT_CALCRECT);
pDC->DrawText(txtCalc, rcCalcText, DT_CALCRECT);//On calcule le rectangle pour le mot en fonction des mots précédents
pDC->SetTextColor(RGB(0,0,255));// On indique au DC qu'on souhaite que notre mot soit colorié en bleu
strRect.right = pDC->GetDeviceCaps(HORZRES);//rcCalcText.right; // On étend en largeur (vers la droite) notre rectangle de dessin
nStringheight = rcCalcText.Height(); // On indique la hauteur de notre mot (la taille du mot en hauteur)
strRect.left = rcCalcText.right - rcWord.right;
strRect.bottom = (strRect.top + nStringheight); //On indique au côté du bas l'extension qu'il doit prendre
pDC->DrawText(word, strRect, DT_WORDBREAK | DT_EXPANDTABS);
}
else
{
//strRect.bottom = 0;
pDC->DrawText(word, rcWord, DT_CALCRECT);
pDC->DrawText(txtCalc, rcCalcText, DT_CALCRECT);//On calcule le rectangle pour le mot en fonction des mots précédents
if(word.Left(2) == "$.")
pDC->SetTextColor(RGB(255,0,255));
else
pDC->SetTextColor(RGB(0,0,0));// On indique au DC qu'on souhaite que notre mot soit colorié en bleu
strRect.right = rcCalcText.right; // On étend en largeur (vers la droite) notre rectangle de dessin
nStringheight = rcCalcText.Height();// On indique la hauteur de notre mot (la taille du mot en hauteur)
strRect.bottom = (strRect.top + nStringheight); //On indique au côté du bas l'extension qu'il doit prendre
strRect.left = rcCalcText.right - rcWord.right;
pDC->DrawText(word, strRect, DT_WORDBREAK | DT_EXPANDTABS);
}
reste = "";
}
}
}
// Calcule la position suivante
int x = strRect.bottom;
iY = (nRowSpace + x);
if(iY > iVerticalSize)
{
MessageBox("ça coince ici");
iY = 300;
pDC->EndPage();
pDC->StartPage();
nPage++;
}
}
} |