Commit 46ea5f7e authored by Elen.Subbotina's avatar Elen.Subbotina Committed by Alexander Trofimov

.....

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@61946 954022d7-b5bf-4e40-9824-e11837661b57
parent e89cf2f5
This diff is collapsed.
#ifndef _BUILD_APPLICATIONFONTS_H_
#define _BUILD_APPLICATIONFONTS_H_
#define UNKNOWN_CHARSET 3 // для случаев, когда задано значение DEFAULT_CHARSET, но
// на самом деле charset не учитывается
#include "FontManager.h"
class CFontSelectFormat
{
public:
std::wstring* wsName;
std::wstring* wsAltName;
std::wstring* wsFamilyClass;
SHORT* sFamilyClass;
INT* bBold;
INT* bItalic;
INT* bFixedWidth;
BYTE* pPanose;
ULONG* ulRange1;
ULONG* ulRange2;
ULONG* ulRange3;
ULONG* ulRange4;
ULONG* ulCodeRange1;
ULONG* ulCodeRange2;
USHORT* usWeight;
USHORT* usWidth;
int* nFontFormat;
BYTE* unCharset;
SHORT* shAvgCharWidth;
SHORT* shAscent;
SHORT* shDescent;
SHORT* shLineGap;
SHORT* shXHeight;
SHORT* shCapHeight;
public:
CFontSelectFormat();
~CFontSelectFormat();
void CreateDuplicate(CFontSelectFormat& oFormat);
void Destroy();
};
//-------------------------------------------------------------------------------------------------------------------------------
// CWinFontInfo
//-------------------------------------------------------------------------------------------------------------------------------
enum EFontFormat
{
fontWindowsFNT = 0, // *.fon
fontTrueType = 1, // *.ttf
fontOpenType = 2, // *.ttf, *.otf (CFF формат)
fontUnknown = 3
};
class CFontInfo
{
public:
CFontInfo(const std::wstring& wsFontName,
const std::wstring& wsStyle,
const std::wstring& wsFontPath,
long lIndex,
INT bBold,
INT bItalic,
INT bFixedWidth,
BYTE *pPanose,
ULONG ulRange1,
ULONG ulRange2,
ULONG ulRange3,
ULONG ulRange4,
ULONG ulCodeRange1,
ULONG ulCodeRange2,
USHORT usWeigth,
USHORT usWidth,
SHORT sFamilyClass,
EFontFormat eFormat,
SHORT shAvgCharWidth,
SHORT shAscent,
SHORT shDescent,
SHORT shLineGap,
SHORT shXHeight,
SHORT shCapHeight);
~CFontInfo();
INT Equals(const CFontInfo *pFontInfo);
static CFontInfo* FromBuffer(BYTE*& pBuffer, std::wstring strDir);
LONG GetBufferLen(std::wstring strDirectory = L"", bool bIsOnlyFileName = false);
void ToBuffer(BYTE*& pBuffer, std::wstring strDirectory = L"", bool bIsOnlyFileName = false);
public:
std::wstring m_wsFontName; // Имя шрифта
std::wstring m_wsFontPath; // Путь к файлу с шрифтом
long m_lIndex; // Номер шрифта в файле(если в файле больше 1 шрифта)
std::wstring m_wsStyle;
INT m_bBold; // Bold text
INT m_bItalic; // Italic text
INT m_bIsFixed; // Моноширинный шрифт?
BYTE m_aPanose[10];
ULONG m_ulUnicodeRange1; // Bits 0-31
ULONG m_ulUnicodeRange2; // Bits 32-63
ULONG m_ulUnicodeRange3; // Bits 64-95
ULONG m_ulUnicodeRange4; // Bits 96-127
ULONG m_ulCodePageRange1; // Bits 0-31
ULONG m_ulCodePageRange2; // Bits 32-63
USHORT m_usWeigth;
USHORT m_usWidth;
SHORT m_sFamilyClass;
EFontFormat m_eFontFormat;
SHORT m_shAvgCharWidth; // Средняя ширина символов
SHORT m_shAscent; // Ascent
SHORT m_shDescent; // Descent
SHORT m_shLineGap; // Межсимвольный интервал
SHORT m_shXHeight; // Высота буквы 'x' (в нижнем регистре)
SHORT m_shCapHeight; // Высота буквы 'H' (в верхнем регистре)
};
namespace NSCharsets
{
static void GetCodePageByCharset(unsigned char unCharset, unsigned long *pulBit, unsigned int *punLongIndex);
static int GetDefaultCharset(INT bUseDefCharset = TRUE);
}
class CFontList
{
private:
CArray<CFontInfo*> m_pList;
std::wstring m_sDirectory;
LONG m_lDefIndex; // Номер стандартного шрифта (-1, если не задан)
public:
CFontList()
{
m_lDefIndex = -1;
}
~CFontList()
{
int nCount = m_pList.GetCount();
for ( int nIndex = 0; nIndex < nCount; ++nIndex )
{
CFontInfo* pTemp = m_pList[nIndex];
RELEASEOBJECT(pTemp);
}
m_pList.RemoveAll();
}
CArray<CFontInfo*>* GetFonts() { return &m_pList; }
private:
int GetCharsetPenalty(ULONG ulCandRanges[6], unsigned char unReqCharset);
int GetSigPenalty(ULONG ulCandRanges[6], ULONG ulReqRanges[6], double dRangeWeight = 1, double dRangeWeightSuferflouous = 0);
int GetFixedPitchPenalty(INT bCandFixed, INT bReqFixed);
int GetFaceNamePenalty(std::wstring sCandName, std::wstring sReqName);
int GetFamilyUnlikelyPenalty(SHORT nCandFamilyClass, SHORT nReqFamilyClass);
int GetFamilyUnlikelyPenalty(int nCandFamilyClass, std::wstring sReqFamilyClass);
int GetWidthPenalty(USHORT usCandWidth, USHORT usReqWidth);
int GetWeightPenalty(USHORT usCandWeight, USHORT usReqWeight);
int GetItalicPenalty(INT bCandItalic, INT bReqItalic);
int GetBoldPenalty(INT bCandBold, INT bReqBold);
int GetFontFormatPenalty(EFontFormat eCandFormat, EFontFormat eReqFormat);
int GetPanosePenalty(BYTE *pCandPanose, BYTE *pReqPanose);
int GetAvgWidthPenalty(SHORT shCandWidth, SHORT shReqWidth);
int GetAscentPenalty(SHORT shCandAscent, SHORT shReqAscent);
int GetDescentPenalty(SHORT shCandDescent, SHORT shReqDescent);
int GetLineGapPenalty(SHORT shCandLineGap, SHORT shReqLineGap);
int GetXHeightPenalty(SHORT shCandXHeight, SHORT shReqXHeight);
int GetCapHeightPenalty(SHORT shCandCapHeight, SHORT shReqCapHeight);
public:
static EFontFormat GetFontFormat(FT_Face pFace);
void ToBuffer(BYTE** pDstData, LONG* pLen, std::wstring strDirectory = L"", bool bIsOnlyFileName = false);
public:
void LoadFromArrayFiles(CArray<std::wstring>& arrFiles);
void LoadFromFolder(const std::wstring& strDirectory);
bool CheckLoadFromFolderBin(const std::wstring& strDirectory);
void Add(CFontInfo* pInfo);
CFontInfo* GetByParams(CFontSelectFormat& oSelect);
CArray<CFontInfo*> GetAllByName(const std::wstring& strFontName);
void SetDefaultFont(std::wstring& sName);
};
class CApplicationFonts
{
private:
CApplicationFontStreams m_oStreams;
CFontsCache m_oCache;
CFontList m_oList;
public:
CApplicationFonts();
~CApplicationFonts();
public:
CFontsCache* GetCache();
CFontList* GetList();
CApplicationFontStreams* GetStreams();
void InitializeFromFolder(std::wstring strFolder, bool bIsCheckSelection = true);
void Initialize(bool bIsCheckSelection = true);
CArray<std::wstring> GetSetupFontFiles();
void InitializeFromArrayFiles(CArray<std::wstring>& files);
#ifdef WIN32
void InitFromReg();
#endif
#ifdef _IOS
CArray<std::wstring> GetSetupFontFiles_ios();
#endif
CFontManager* GenerateFontManager();
};
#endif
This diff is collapsed.
#ifndef _BUILD_APPLICATIONFONTSWORKER_H_
#define _BUILD_APPLICATIONFONTSWORKER_H_
#include <string>
#include <vector>
class CApplicationFontsWorker
{
public:
std::vector<std::wstring> m_arAdditionalFolders;
public:
CApplicationFontsWorker();
~CApplicationFontsWorker();
std::vector<std::wstring> CheckApplication(bool bIsNeedSystemFonts,
unsigned char* pDataSrc, unsigned int nLenSrc,
unsigned char*& pDataDst, unsigned int& nLenDst);
};
#endif // _BUILD_APPLICATIONFONTSWORKER_H_
#include "ApplicationFonts.h"
#include "../common/Directory.h"
#ifdef BOOL
#undef BOOL
#endif
#import <UIKit/UIKit.h>
CArray<std::wstring> CApplicationFonts::GetSetupFontFiles_ios()
{
CArray<std::wstring> oArray;
NSDirectory::GetFiles2(L"/System/Library/Fonts", oArray, true);
if (oArray.GetCount() == 0)
{
NSDirectory::GetFiles2(L"/Library/Fonts", oArray, true);
}
return oArray;
}
namespace NSDirectory
{
void GetFiles2_ios(std::wstring strDirectory, CArray<std::wstring>& oArray, bool bIsRecursion)
{
NSString* directoryPath = [ [ NSString alloc ]
initWithBytes : (char*)strDirectory.data()
length : strDirectory.size() * sizeof(wchar_t)
encoding : CFStringConvertEncodingToNSStringEncoding ( kCFStringEncodingUTF32LE ) ];
int count;
NSArray* directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:directoryPath error:NULL];
for (count = 0; count < (int)[directoryContent count]; count++)
{
NSStringEncoding pEncode = CFStringConvertEncodingToNSStringEncoding ( kCFStringEncodingUTF32LE );
NSData* pSData = [[ directoryContent objectAtIndex:count] dataUsingEncoding : pEncode ];
std::wstring sTmp( (wchar_t*) [ pSData bytes ], [ pSData length] / sizeof ( wchar_t ) );
oArray.Add(sTmp);
}
}
}
This diff is collapsed.
#ifndef _BUILD_FONT_ENGINE_FONTFILE_H_
#define _BUILD_FONT_ENGINE_FONTFILE_H_
// freetype
#include <ft2build.h>
#include FT_OUTLINE_H
#include FT_SIZES_H
#include FT_GLYPH_H
#include FT_TRUETYPE_IDS_H
#include FT_TRUETYPE_TABLES_H
#include FT_XFREE86_H
#include FT_ADVANCES_H
#include "FontPath.h"
#include "GlyphString.h"
//-------------------------------------------------------------------------------------------------------------------------------
// TODO: RasterHeep
//-------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------
// TODO: TFontCacheSizes
//-------------------------------------------------------------------------------------------------------------------------------
class TFontCacheSizes
{
public:
int ushUnicode; // Значение символа в юникоде
EGlyphState eState; // Есть ли символ в шрифте/стандартном шрифте
int nCMapIndex; // Номер таблицы 'cmap', в которой был найден данный символ
USHORT ushGID;
float fAdvanceX;
TBBox oBBox;
TMetrics oMetrics;
bool bBitmap;
TGlyphBitmap oBitmap;
public:
TFontCacheSizes()
{
fAdvanceX = 0;
}
~TFontCacheSizes()
{
}
};
class CFontCacheSizes
{
public:
CFontCacheSizes()
{
}
~CFontCacheSizes()
{
}
inline void Init()
{
m_arrSizes.RemoveAll();
}
inline void Clear(bool bIsFree = false)
{
if (bIsFree)
{
int nCount = m_arrSizes.GetCount();
for (int i = 0; i < nCount; ++i)
{
m_arrSizes[i].oBitmap.bFreeData = TRUE;
}
}
m_arrSizes.RemoveAll();
}
int Add(const TFontCacheSizes& oSizes)
{
m_arrSizes.Add( oSizes );
return m_arrSizes.GetSize() - 1;
}
inline TFontCacheSizes& Get(int nIndex)
{
return m_arrSizes[nIndex];
}
const TFontCacheSizes& operator[] (int nIndex) const
{
return m_arrSizes[nIndex];
}
TFontCacheSizes& operator[] (int nIndex)
{
return m_arrSizes[nIndex];
}
private:
CArray<TFontCacheSizes> m_arrSizes;
};
#define LOAD_MODE FT_LOAD_NO_HINTING | FT_LOAD_NO_AUTOHINT | FT_LOAD_NO_BITMAP | FT_LOAD_LINEAR_DESIGN
#define REND_MODE FT_RENDER_MODE_NORMAL
#define FONT_ITALIC_ANGLE 0.3090169943749 // Синус 18 градусов (подбиралось под Word 2007)
#define MAX_UNICODE_VALUE 0x10FFFF
#define MAX_UNICODE_COUNT 0x110000
#define MAX_UNICODE_COUNT2 0x220000
#define FONT_CASHE_SIZES_SIZE 255
#define FONT_CACHE_SIZES_INDEXES_SIZE MAX_UNICODE_COUNT
#define FONT_CACHE_SIZES_INDEXES_SIZE_2 MAX_UNICODE_COUNT2 // MAX_UNICODE_COUNT * sizeof(unsigned short)
class CFontStream;
class CFontManager;
class CFontFile
{
public:
double m_arrdFontMatrix[6];
double m_arrdTextMatrix[6];
bool m_bAntiAliasing;
bool m_bUseKerning;
double m_dSize; // Размер шрифта
UINT m_unHorDpi; // Горизонтальное разрешение
UINT m_unVerDpi; // Вертикальное разрешение
INT m_bNeedDoItalic;
INT m_bNeedDoBold;
double m_dCharSpacing;
int m_nMinX; //
int m_nMinY; // Glyph BBox
int m_nMaxX; //
int m_nMaxY; //
CFontStream* m_pStream;
std::wstring m_sFileName;
int m_lFaceIndex;
FT_Face m_pFace;
double m_dUnitsKoef;
int m_nDefaultChar;
int m_nSymbolic;
double m_dTextScale;
INT m_bStringGID;
FT_Matrix m_oFontMatrix;
FT_Matrix m_oTextMatrix;
int m_nNum_charmaps;
int m_lAscender;
int m_lDescender;
int m_lLineHeight;
int m_lUnits_Per_Em;
// cache
CFontCacheSizes m_oCacheSizes;
// вот так экономим память. нету пока таких шрифтов, в которых глифов больше 0xFFFF
USHORT m_arrCacheSizesIndexs[FONT_CACHE_SIZES_INDEXES_SIZE];
INT m_bUseDefaultFont;
CFontFile* m_pDefaultFont;
INT m_bIsNeedUpdateMatrix12;
CFontManager* m_pFontManager;
INT m_bHintsSupport;
public:
CFontFile();
~CFontFile();
void SetDefaultFont(CFontFile* pDefFont);
void LoadDefaultCharAndSymbolicCmapIndex();
void ResetFontMatrix();
void ResetTextMatrix();
void CheckTextMatrix();
void UpdateMatrix0();
void UpdateMatrix1();
void UpdateMatrix2();
void SetSizeAndDpi(double dSize, UINT unHorDpi, UINT unVerDpi);
void ClearCache();
void ClearCacheNoAttack(bool bIsFree = false);
void Destroy();
bool SetTextMatrix(const double& fA, const double& fB, const double& fC, const double fD, double fE, double fF);
void SetFontMatrix(const double& fA, const double& fB, const double& fC, const double fD, double fE, double fF);
INT GetString(CGlyphString& oString);
INT GetString2(CGlyphString& oString);
INT GetString2C(CGlyphString& oString);
TFontCacheSizes GetChar(LONG lUnicode);
void AddToSizesCache(const TFontCacheSizes& oSizes);
int SetCMapForCharCode(long lUnicode, int *pnCMapIndex);
int SetCMapForCharCode2(long lUnicode);
int GetKerning(FT_UInt unPrevGID, FT_UInt unGID);
void SetStringGID(const INT& bGID);
INT GetStringGID();
void SetUseDefaultFont(const INT& bUse);
INT GetUseDefaultFont();
void SetCharSpacing(const double& dCharSpacing);
double GetCharSpacing();
std::string GetStyleName();
void UpdateStyles(const INT& bBold, const INT& bItalic);
void SetItalic(const INT& value);
void SetNeedBold(const INT& value);
int GetAscender();
int GetDescender();
int GetHeight();
int Units_Per_Em();
void CheckHintsSupport();
// path
CFontPath* GetGlyphPath(int nCode);
};
//-------------------------------------------------------------------------------------------------------------------------------
struct TFreeTypeFontPath
{
CFontPath* pPath;
INT bNeedClose;
};
static int GlyphPathMoveTo(const FT_Vector *pPoint, void *pPath);
static int GlyphPathLineTo(const FT_Vector *pPoint, void *pPath);
static int GlyphPathConicTo(const FT_Vector *pControlPoint, const FT_Vector *pEndPoint, void *pPath);
static int GlyphPathCubicTo(const FT_Vector *pFirstControlPoint, const FT_Vector *pSecondControlPoint, const FT_Vector *pEndPoint, void *pPath);
#endif // _BUILD_FONT_ENGINE_FONTFILE_H_
\ No newline at end of file
This diff is collapsed.
#ifndef _BUILD_FONT_ENGINE_FONTMANAGER_H_
#define _BUILD_FONT_ENGINE_FONTMANAGER_H_
#include "FontFile.h"
#include <map>
class CFontSelectFormat;
class CFontInfo;
class CFontStream
{
private:
int m_lRef;
public:
BYTE* m_pData;
LONG m_lSize;
bool m_bIsAttach;
public:
CFontStream();
virtual ~CFontStream();
virtual int AddRef();
virtual int Release();
public:
virtual INT CreateFromFile(const std::wstring& strFileName, BYTE* pDataUse = NULL);
};
class CApplicationFontStreams
{
private:
// этот мап нужно периодически опрашивать и удалять неиспользуемые стримы
std::map<std::wstring, CFontStream*> m_mapStreams;
public:
CApplicationFontStreams();
~CApplicationFontStreams();
public:
CFontStream* GetStream(const std::wstring& strFile);
void CheckStreams(std::map<std::wstring, bool>& mapFiles);
};
class CFontsCache
{
friend class CFontManager;
friend class CApplicationFonts;
private:
std::map<std::string, CFontFile*> m_mapFiles;
CApplicationFontStreams* m_pApplicationFontStreams;
public:
CFontsCache()
{
m_pApplicationFontStreams = NULL;
}
~CFontsCache()
{
for (std::map<std::string, CFontFile*>::iterator iter = m_mapFiles.begin(); iter != m_mapFiles.end(); ++iter)
{
CFontFile* pFile = iter->second;
RELEASEOBJECT(pFile);
}
}
public:
inline void SetStreams(CApplicationFontStreams* pStreams) { m_pApplicationFontStreams = pStreams; }
CFontFile* LockFont(FT_Library library, const std::wstring& strFileName, const LONG& lFaceIndex, const double& dSize);
};
class CApplicationFonts;
class CFontManager
{
friend class CApplicationFonts;
private:
int m_lRef;
public:
FT_Library m_pLibrary;
CFontFile* m_pFont;
CGlyphString m_oString;
std::wstring m_sName;
INT m_bUseDefaultFont;
double m_fCharSpacing;
INT m_bStringGID;
int m_lUnits_Per_Em;
int m_lAscender;
int m_lDescender;
int m_lLineHeight;
int m_nLOAD_MODE;
CApplicationFonts* m_pApplication;
CFontsCache* m_pOwnerCache;
public:
CFontManager();
~CFontManager();
public:
void AfterLoad();
void Initialize();
void SetOwnerCache(CFontsCache* pCache);
double UpdateSize(const double& dOldSize, const double& dDpi, const double& dNewDpi);
INT LoadString1(const std::wstring& wsBuffer, const float& fX, const float& fY);
INT LoadString2(const std::wstring& wsBuffer, const float& fX, const float& fY);
INT LoadString3(const LONG& gid, const float& fX, const float& fY);
INT LoadString3C(const LONG& gid, const float& fX, const float& fY);
INT LoadString2C(const LONG& wsBuffer, const float& fX, const float& fY);
int GetKerning(UINT unPrevGID, UINT unGID);
INT GetUnderline(float *pfStartX, float *pfStartY, float *pfEndX, float *pfEndY, float *pfSize);
TFontCacheSizes MeasureChar(const LONG& lUnicode);
TBBox MeasureString();
TBBox MeasureString2();
INT GetNextChar2(TGlyph*& pGlyph, float& fX, float& fY);
INT SetTextMatrix(const double& fA, const double& fB, const double& fC, const double& fD, const double& fE, const double& fF);
INT SetTextMatrix2(const double& fA, const double& fB, const double& fC, const double& fD, const double& fE, const double& fF);
void SetStringGID(const INT& bStringGID);
void SetCharSpacing(const double &dCharSpacing);
INT GetStringPath(ISimpleGraphicsPath* pPath);
// addref/release
virtual int AddRef();
virtual int Release();
CFontInfo* GetFontInfoByParams(CFontSelectFormat& oFormat);
CArray<CFontInfo*> GetAllStylesByFontName(const std::wstring& strName);
INT LoadFontByName(const std::wstring& sName, const double& dSize, const LONG& lStyle, const double& dDpiX, const double& dDpiY);
INT LoadFontFromFile(const std::wstring& sPath, const int& lFaceIndex, const double& dSize, const double& dDpiX, const double& dDpiY);
INT LoadFontFromFile2(CFontsCache* pCache, const std::wstring& sPath, const int& lFaceIndex, const double& dSize, const double& dDpiX, const double& dDpiY);
public:
static CFontFile* LoadFontFile(FT_Library library, CFontStream* pStream, LONG lFaceIndex);
};
#endif // _BUILD_FONT_ENGINE_FONTMANAGER_H_
\ No newline at end of file
#include "FontPath.h"
//-------------------------------------------------------------------------------------------------------------------------------
// CPath
//-------------------------------------------------------------------------------------------------------------------------------
// Path может быть в одном из трех следующий состояний:
//
// 1. Нет текущей точки -- ни одного или более законченных SubPaths
// [m_nCurSubpath == m_nPointsCount]
//
// 2. Одна точка в SubPaths
// [m_nCurSubpath == m_nPointsCount - 1]
//
// 3. Открытый SubPaths c двумя или более точками
// [m_nCurSubpath < m_nPointsCount - 1]
CFontPath::CFontPath()
{
m_pPoints = NULL;
m_pFlags = NULL;
m_nPointsCount = m_nSize = 0;
m_nCurSubpath = 0;
m_pHints = NULL;
m_nHintsCount = m_nHintsSize = 0;
}
CFontPath::CFontPath(CFontPath *pPath)
{
m_nPointsCount = pPath->m_nPointsCount;
m_nSize = pPath->m_nSize;
m_pPoints = (TPathPoint *)malloc( m_nSize * sizeof(TPathPoint) );
m_pFlags = (unsigned char *)malloc( m_nSize * sizeof(unsigned char) );
memcpy( m_pPoints, pPath->m_pPoints, m_nPointsCount * sizeof(TPathPoint) );
memcpy( m_pFlags, pPath->m_pFlags, m_nPointsCount * sizeof(unsigned char) );
m_nCurSubpath = pPath->m_nCurSubpath;
if ( pPath->m_pHints )
{
m_nHintsCount = m_nHintsSize = pPath->m_nHintsCount;
m_pHints = (TPathHint *)malloc( m_nHintsSize * sizeof(TPathHint) );
memcpy( m_pHints, pPath->m_pHints, m_nHintsCount * sizeof(TPathHint) );
}
else
{
m_pHints = NULL;
}
}
CFontPath::~CFontPath()
{
free( m_pPoints );
free( m_pFlags );
free( m_pHints );
}
void CFontPath::Resize(int nPointsCount)
{
if ( m_nPointsCount + nPointsCount > m_nSize )
{
if ( m_nSize == 0 )
{
m_nSize = 32;
}
while ( m_nSize < m_nPointsCount + nPointsCount )
{
m_nSize *= 2;
}
m_pPoints = (TPathPoint *)realloc( m_pPoints, m_nSize * sizeof(TPathPoint) );
m_pFlags = (unsigned char *)realloc( m_pFlags, m_nSize * sizeof(unsigned char) );
}
}
void CFontPath::Append(CFontPath *pPath)
{
m_nCurSubpath = m_nPointsCount + pPath->m_nCurSubpath;
Resize( pPath->m_nPointsCount );
for ( int nIndex = 0; nIndex < pPath->m_nPointsCount; ++nIndex )
{
m_pPoints[m_nPointsCount] = pPath->m_pPoints[nIndex];
m_pFlags[m_nPointsCount] = pPath->m_pFlags[nIndex];
++m_nPointsCount;
}
}
int CFontPath::MoveTo(double dX, double dY)
{
if ( OnePointSubpath() )
{
return -1;
}
Resize(1);
m_pPoints[m_nPointsCount].dX = dX;
m_pPoints[m_nPointsCount].dY = dY;
m_pFlags[m_nPointsCount] = PathFirst | PathLast;
m_nCurSubpath = m_nPointsCount++;
return 0;
}
int CFontPath::LineTo(double dX, double dY)
{
if ( NoCurrentPoint() )
{
return -1;
}
m_pFlags[m_nPointsCount - 1] &= ~PathLast;
Resize(1);
m_pPoints[m_nPointsCount].dX = dX;
m_pPoints[m_nPointsCount].dY = dY;
m_pFlags[m_nPointsCount] = PathLast;
++m_nPointsCount;
return 0;
}
int CFontPath::CurveTo(double dX1, double dY1, double dX2, double dY2, double dX3, double dY3)
{
if ( NoCurrentPoint() )
{
return -1;
}
m_pFlags[m_nPointsCount-1] &= ~PathLast;
Resize(3);
m_pPoints[m_nPointsCount].dX = dX1;
m_pPoints[m_nPointsCount].dY = dY1;
m_pFlags[m_nPointsCount] = PathCurve;
++m_nPointsCount;
m_pPoints[m_nPointsCount].dX = dX2;
m_pPoints[m_nPointsCount].dY = dY2;
m_pFlags[m_nPointsCount] = PathCurve;
++m_nPointsCount;
m_pPoints[m_nPointsCount].dX = dX3;
m_pPoints[m_nPointsCount].dY = dY3;
m_pFlags[m_nPointsCount] = PathLast;
++m_nPointsCount;
return 0;
}
int CFontPath::Close()
{
if ( NoCurrentPoint() )
{
return -1;
}
if ( m_nCurSubpath == m_nPointsCount - 1 || m_pPoints[m_nPointsCount - 1].dX != m_pPoints[m_nCurSubpath].dX || m_pPoints[m_nPointsCount - 1].dY != m_pPoints[m_nCurSubpath].dY )
{
LineTo( m_pPoints[m_nCurSubpath].dX, m_pPoints[m_nCurSubpath].dY );
}
m_pFlags[m_nCurSubpath] |= PathClosed;
m_pFlags[m_nPointsCount - 1] |= PathClosed;
m_nCurSubpath = m_nPointsCount;
return 0;
}
void CFontPath::AddStrokeAdjustHint(int nFirstControl, int nSecondControl, int nFirstPoint, int nLastPoint)
{
if ( m_nHintsCount == m_nHintsSize )
{
m_nHintsSize = m_nHintsCount ? 2 * m_nHintsCount : 8;
m_pHints = (TPathHint *)realloc( m_pHints, m_nHintsSize * sizeof(TPathHint) );
}
m_pHints[m_nHintsCount].nFirstControl = nFirstControl;
m_pHints[m_nHintsCount].nSecondControl = nSecondControl;
m_pHints[m_nHintsCount].nFirstPoint = nFirstPoint;
m_pHints[m_nHintsCount].nLastPoint = nLastPoint;
++m_nHintsCount;
}
void CFontPath::Offset(double dDx, double dDy)
{
for ( int nIndex = 0; nIndex < m_nPointsCount; ++nIndex )
{
m_pPoints[nIndex].dX += dDx;
m_pPoints[nIndex].dY += dDy;
}
}
void CFontPath::Reverse()
{
for ( int nIndex = 0; nIndex < m_nPointsCount; ++nIndex )
{
m_pPoints[nIndex].dY = -m_pPoints[nIndex].dY;
}
}
void CFontPath::ToMM(double dHorDpi, double dVerDpi)
{
for ( int nIndex = 0; nIndex < m_nPointsCount; ++nIndex )
{
m_pPoints[nIndex].dX *= 25.4 / dHorDpi;
m_pPoints[nIndex].dY *= 25.4 / dVerDpi;
}
}
INT CFontPath::GetCurPoint(double *pdX, double *pdY)
{
if ( NoCurrentPoint() )
{
return FALSE;
}
*pdX = m_pPoints[m_nPointsCount - 1].dX;
*pdY = m_pPoints[m_nPointsCount - 1].dY;
return TRUE;
}
INT CFontPath::ToInterface(ISimpleGraphicsPath* pPath)
{
if ( !pPath )
return FALSE;
for ( int nIndex = 0; nIndex < m_nPointsCount; )
{
TPathPoint oPoint = m_pPoints[nIndex];
unsigned char nFlag = m_pFlags[nIndex];
if ( nFlag & PathFirst )
{
pPath->_MoveTo( oPoint.dX, oPoint.dY );
nIndex++;
}
else if ( nFlag & PathCurve )
{
pPath->_CurveTo( m_pPoints[nIndex + 0].dX, m_pPoints[nIndex + 0].dY, m_pPoints[nIndex + 1].dX, m_pPoints[nIndex + 1].dY, m_pPoints[nIndex + 2].dX, m_pPoints[nIndex + 2].dY );
nIndex += 3;
}
else
{
pPath->_LineTo( oPoint.dX, oPoint.dY );
nIndex++;
}
if ( nFlag & PathClosed && nFlag & PathLast )
{
pPath->_Close();
}
}
return TRUE;
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment