GME  13
AnnotationUtil.cpp
Go to the documentation of this file.
00001 // AnnotationUtil.cpp: implementation of the CAnnotationNode class.
00002 //
00004 
00005 #include "stdafx.h"
00006 #include "AnnotationUtil.h"
00007 #include "..\Annotator\AnnotationDefs.h"
00008 
00009 #ifdef _DEBUG
00010 #undef THIS_FILE
00011 static char THIS_FILE[]=__FILE__;
00012 #define new DEBUG_NEW
00013 #endif
00014 
00015 
00016 void CAnnotationUtil::LogfontEncode(CString &str, const LOGFONT* lfp)
00017 {       
00018         TCHAR buff[6];
00019         buff[5] = _T('0');
00020 
00021         str.Empty();
00022         for (int i = 0; i < sizeof(LOGFONT); i++) {
00023                 unsigned int ch = ((const unsigned char *)lfp)[i];
00024                 _sntprintf(buff, 5, _T("%02x "), ch);
00025                 str += buff;
00026         }
00027 }
00028 
00029 bool CAnnotationUtil::LogfontDecode(const CString &str, LOGFONT* lfp)
00030 {
00031         int i = 0;
00032         int pos = 0;
00033         int epos = 0;
00034         epos = str.Find(_T(' '), pos);
00035         while (epos > 0) {
00036                 unsigned int ch;
00037                 if (_stscanf(str.Mid(pos,epos-pos), _T("%2x"), &ch) != 1) {
00038                         return false;
00039                 }
00040                 ((unsigned char *)lfp)[i++] = ch;
00041                 pos = epos+1;
00042                 epos = str.Find(_T(' '), pos);
00043         }
00044         return (i == sizeof(LOGFONT));
00045 }
00046 
00047 void CAnnotationUtil::FillLogFontWithDefault(LOGFONT* lfp)
00048 {
00049         ASSERT(lfp != NULL);
00050         memset(lfp, 0, sizeof(LOGFONT));
00051         HDC tempDC = ::GetWindowDC(NULL);
00052         lfp->lfHeight                   = -MulDiv(AN_DEFAULT_FONT_HEIGHT, GetDeviceCaps(tempDC, LOGPIXELSY), 72);
00053         _tcsncpy(lfp->lfFaceName, AN_DEFAULT_FONT_FACE, LF_FACESIZE);
00054         ::ReleaseDC(NULL, tempDC);
00055         lfp->lfPitchAndFamily   = FF_DONTCARE | DEFAULT_PITCH;
00056         lfp->lfQuality                  = DEFAULT_QUALITY;
00057         lfp->lfClipPrecision    = CLIP_DEFAULT_PRECIS;
00058         lfp->lfOutPrecision             = OUT_DEFAULT_PRECIS;
00059         lfp->lfCharSet                  = ANSI_CHARSET;
00060         lfp->lfItalic                   = FALSE;
00061         lfp->lfUnderline                = FALSE;
00062         lfp->lfStrikeOut                = FALSE;
00063         lfp->lfWeight                   = FW_DONTCARE;
00064         lfp->lfWidth                    = 0;
00065 }
00066 
00067 CString CAnnotationUtil::ResolveNewLinesToCRLF(const CString& str)
00068 {
00069         CString outStr;
00070         for (int i = 0; i < str.GetLength(); i++) {
00071                 if (str[i] == '\x0A') {
00072                         if (i > 0 && str[i - 1] != '\x0D')
00073                                 outStr.Append(_T("\x0D"));
00074                 }
00075                 outStr.Append(CString(str[i]));
00076                 if (str[i] == '\x0D') {
00077                         if (i < str.GetLength() - 1 && str[i + 1] != '\x0A')
00078                                 outStr.Append(_T("\x0A"));
00079                 }
00080         }
00081         return outStr;
00082 }
00083 
00084 CString CAnnotationUtil::ResolveNewLinesToLF(const CString& str)
00085 {
00086         CString outStr = str;
00087         outStr.Replace(_T("\x0D\x0A"), _T("\x0A"));
00088         outStr.Replace(_T("\x0D"), _T("\x0A"));
00089         return outStr;
00090 }