Commit 8c404a4a authored by Oleg.Korshul's avatar Oleg.Korshul Committed by Alexander Trofimov

подбор похожих шрифтов

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@65330 954022d7-b5bf-4e40-9824-e11837661b57
parent f1222fca
...@@ -882,7 +882,7 @@ int CFontList::GetFixedPitchPenalty(INT bCandFixed, INT bReqFixed) ...@@ -882,7 +882,7 @@ int CFontList::GetFixedPitchPenalty(INT bCandFixed, INT bReqFixed)
return nPenalty; return nPenalty;
} }
int CFontList::GetFaceNamePenalty(std::wstring sCandName, std::wstring sReqName) int CFontList::GetFaceNamePenalty(std::wstring sCandName, std::wstring sReqName, std::vector<std::wstring>* pArrayLikes)
{ {
// На MSDN написано, что если имена не совпадают, то вес 10000. // На MSDN написано, что если имена не совпадают, то вес 10000.
// Мы будем сравнивать сколько совпало символов у запрашиваемого // Мы будем сравнивать сколько совпало символов у запрашиваемого
...@@ -909,6 +909,15 @@ int CFontList::GetFaceNamePenalty(std::wstring sCandName, std::wstring sReqName) ...@@ -909,6 +909,15 @@ int CFontList::GetFaceNamePenalty(std::wstring sCandName, std::wstring sReqName)
else if ( std::wstring::npos != sReqName.find( sCandName ) || std::wstring::npos != sCandName.find( sReqName ) ) else if ( std::wstring::npos != sReqName.find( sCandName ) || std::wstring::npos != sCandName.find( sReqName ) )
return 1000; return 1000;
if (NULL != pArrayLikes)
{
for (std::vector<std::wstring>::iterator iter = pArrayLikes->begin(); iter != pArrayLikes->end(); iter++)
{
if (sCandName == *iter)
return 2000;
}
}
return 10000; return 10000;
} }
...@@ -1132,6 +1141,16 @@ CFontInfo* CFontList::GetByParams(CFontSelectFormat& oSelect, bool bIsDictionary ...@@ -1132,6 +1141,16 @@ CFontInfo* CFontList::GetByParams(CFontSelectFormat& oSelect, bool bIsDictionary
int nDefPenalty = 2147483647; int nDefPenalty = 2147483647;
std::vector<std::wstring>* pArrayLikes = NULL;
if (oSelect.wsName != NULL)
{
std::map<std::wstring, int>::iterator iterLikeIndex = m_mapNamesToIndex.find(*oSelect.wsName);
if (iterLikeIndex != m_mapNamesToIndex.end())
{
pArrayLikes = &m_listLikes[iterLikeIndex->second];
}
}
for ( int nIndex = 0; nIndex < nFontsCount; ++nIndex ) for ( int nIndex = 0; nIndex < nFontsCount; ++nIndex )
{ {
int nCurPenalty = 0; int nCurPenalty = 0;
...@@ -1169,12 +1188,13 @@ CFontInfo* CFontList::GetByParams(CFontSelectFormat& oSelect, bool bIsDictionary ...@@ -1169,12 +1188,13 @@ CFontInfo* CFontList::GetByParams(CFontSelectFormat& oSelect, bool bIsDictionary
if ( oSelect.wsName != NULL && oSelect.wsAltName != NULL ) if ( oSelect.wsName != NULL && oSelect.wsAltName != NULL )
{ {
nCurPenalty += min( GetFaceNamePenalty( pInfo->m_wsFontName, *oSelect.wsName ), GetFaceNamePenalty( pInfo->m_wsFontName, *oSelect.wsAltName ) ); nCurPenalty += min( GetFaceNamePenalty( pInfo->m_wsFontName, *oSelect.wsName, pArrayLikes ),
GetFaceNamePenalty( pInfo->m_wsFontName, *oSelect.wsAltName, pArrayLikes ) );
} }
else if ( oSelect.wsName != NULL ) else if ( oSelect.wsName != NULL )
nCurPenalty += GetFaceNamePenalty( pInfo->m_wsFontName, *oSelect.wsName ); nCurPenalty += GetFaceNamePenalty( pInfo->m_wsFontName, *oSelect.wsName, pArrayLikes );
else if ( oSelect.wsAltName != NULL ) else if ( oSelect.wsAltName != NULL )
nCurPenalty += GetFaceNamePenalty( pInfo->m_wsFontName, *oSelect.wsAltName ); nCurPenalty += GetFaceNamePenalty( pInfo->m_wsFontName, *oSelect.wsAltName, pArrayLikes );
if ( NULL != oSelect.usWidth ) if ( NULL != oSelect.usWidth )
nCurPenalty += GetWidthPenalty( pInfo->m_usWidth, *oSelect.usWidth ); nCurPenalty += GetWidthPenalty( pInfo->m_usWidth, *oSelect.usWidth );
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
// на самом деле charset не учитывается // на самом деле charset не учитывается
#include "FontManager.h" #include "FontManager.h"
#include <vector>
class CFontSelectFormat class CFontSelectFormat
{ {
...@@ -142,10 +143,33 @@ private: ...@@ -142,10 +143,33 @@ private:
std::wstring m_sDirectory; std::wstring m_sDirectory;
LONG m_lDefIndex; // Номер стандартного шрифта (-1, если не задан) LONG m_lDefIndex; // Номер стандартного шрифта (-1, если не задан)
// вспомогогательные данные для подбора "похожих шрифтов"
std::map<std::wstring, int> m_mapNamesToIndex;
std::vector<std::vector<std::wstring>> m_listLikes;
public: public:
CFontList() CFontList()
{ {
m_lDefIndex = -1; m_lDefIndex = -1;
// 0
m_mapNamesToIndex.insert(std::pair<std::wstring, int>(L"Cambria Math", 0));
m_mapNamesToIndex.insert(std::pair<std::wstring, int>(L"Asana Math", 0));
m_mapNamesToIndex.insert(std::pair<std::wstring, int>(L"XITS Math", 0));
m_mapNamesToIndex.insert(std::pair<std::wstring, int>(L"Latin Modern", 0));
std::vector<std::wstring> ar0;
ar0.push_back(L"Cambria Math");
ar0.push_back(L"Asana Math");
ar0.push_back(L"XITS Math");
ar0.push_back(L"Latin Modern");
m_listLikes.push_back(ar0);
// 1
m_mapNamesToIndex.insert(std::pair<std::wstring, int>(L"Symbol", 1));
std::vector<std::wstring> ar1;
ar1.push_back(L"OpenSymbol");
m_listLikes.push_back(ar1);
} }
~CFontList() ~CFontList()
{ {
...@@ -163,7 +187,7 @@ private: ...@@ -163,7 +187,7 @@ private:
int GetCharsetPenalty(ULONG ulCandRanges[6], unsigned char unReqCharset); int GetCharsetPenalty(ULONG ulCandRanges[6], unsigned char unReqCharset);
int GetSigPenalty(ULONG ulCandRanges[6], ULONG ulReqRanges[6], double dRangeWeight = 1, double dRangeWeightSuferflouous = 0); int GetSigPenalty(ULONG ulCandRanges[6], ULONG ulReqRanges[6], double dRangeWeight = 1, double dRangeWeightSuferflouous = 0);
int GetFixedPitchPenalty(INT bCandFixed, INT bReqFixed); int GetFixedPitchPenalty(INT bCandFixed, INT bReqFixed);
int GetFaceNamePenalty(std::wstring sCandName, std::wstring sReqName); int GetFaceNamePenalty(std::wstring sCandName, std::wstring sReqName, std::vector<std::wstring>* pArrayLikes = NULL);
int GetFamilyUnlikelyPenalty(SHORT nCandFamilyClass, SHORT nReqFamilyClass); int GetFamilyUnlikelyPenalty(SHORT nCandFamilyClass, SHORT nReqFamilyClass);
int GetFamilyUnlikelyPenalty(int nCandFamilyClass, std::wstring sReqFamilyClass); int GetFamilyUnlikelyPenalty(int nCandFamilyClass, std::wstring sReqFamilyClass);
int GetWidthPenalty(USHORT usCandWidth, USHORT usReqWidth); int GetWidthPenalty(USHORT usCandWidth, USHORT usReqWidth);
......
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