mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-07-11 01:11:43 +08:00
274 lines
9.7 KiB
C++
274 lines
9.7 KiB
C++
/*
|
|
* (c) Copyright Ascensio System SIA 2010-2019
|
|
*
|
|
* This program is a free software product. You can redistribute it and/or
|
|
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
|
* version 3 as published by the Free Software Foundation. In accordance with
|
|
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
|
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
|
* of any third-party rights.
|
|
*
|
|
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
|
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
|
*
|
|
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
|
|
* street, Riga, Latvia, EU, LV-1050.
|
|
*
|
|
* The interactive user interfaces in modified source and object code versions
|
|
* of the Program must display Appropriate Legal Notices, as required under
|
|
* Section 5 of the GNU AGPL version 3.
|
|
*
|
|
* Pursuant to Section 7(b) of the License you must retain the original Product
|
|
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
|
* grant you any rights under trademark law for use of our trademarks.
|
|
*
|
|
* All the Product's GUI elements, including illustrations and icon sets, as
|
|
* well as technical writing content are licensed under the terms of the
|
|
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
|
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
|
*
|
|
*/
|
|
#ifndef _BUILD_FONT_ENGINE_FONTMANAGER_H_
|
|
#define _BUILD_FONT_ENGINE_FONTMANAGER_H_
|
|
|
|
#include <map>
|
|
#include <list>
|
|
#include "FontFile.h"
|
|
|
|
class CFontStream : public NSFonts::IFontStream
|
|
{
|
|
public:
|
|
BYTE* m_pData;
|
|
LONG m_lSize;
|
|
bool m_bIsAttach;
|
|
|
|
public:
|
|
CFontStream();
|
|
virtual ~CFontStream();
|
|
|
|
public:
|
|
virtual int CreateFromFile(const std::wstring& strFileName, BYTE* pDataUse = NULL);
|
|
virtual int CreateFromMemory(BYTE* pData, LONG lSize);
|
|
};
|
|
|
|
class CGlobalFontsMemoryStorage
|
|
{
|
|
private:
|
|
std::map<std::string, CFontStream*> m_mapStreams;
|
|
|
|
void string_replaceA(std::string& text, const std::string& replaceFrom, const std::string& replaceTo)
|
|
{
|
|
size_t posn = 0;
|
|
while (std::string::npos != (posn = text.find(replaceFrom, posn)))
|
|
{
|
|
text.replace(posn, replaceFrom.length(), replaceTo);
|
|
posn += replaceTo.length();
|
|
}
|
|
}
|
|
public:
|
|
CGlobalFontsMemoryStorage(){}
|
|
~CGlobalFontsMemoryStorage()
|
|
{
|
|
for (std::map<std::string, CFontStream*>::iterator it = m_mapStreams.begin(); it != m_mapStreams.end(); it++)
|
|
RELEASEOBJECT(it->second);
|
|
m_mapStreams.clear();
|
|
}
|
|
|
|
void Add(const std::string& id, BYTE* data, LONG size)
|
|
{
|
|
std::string sFileA = id;
|
|
string_replaceA(sFileA, "\\", "/");
|
|
std::map<std::string, CFontStream*>::iterator it = m_mapStreams.find(sFileA);
|
|
if (it == m_mapStreams.end())
|
|
{
|
|
CFontStream* pStream = (CFontStream*)NSFonts::NSStream::Create();
|
|
pStream->CreateFromMemory(data, size);
|
|
m_mapStreams.insert({sFileA, pStream});
|
|
}
|
|
}
|
|
void Remove(const std::string& id)
|
|
{
|
|
std::string sFileA = id;
|
|
string_replaceA(sFileA, "\\", "/");
|
|
std::map<std::string, CFontStream*>::iterator it = m_mapStreams.find(sFileA);
|
|
if (it != m_mapStreams.end())
|
|
{
|
|
RELEASEOBJECT(it->second);
|
|
m_mapStreams.erase(it);
|
|
}
|
|
}
|
|
|
|
CFontStream* Get(const std::wstring& sFile)
|
|
{
|
|
std::string sFileA = U_TO_UTF8(sFile);
|
|
string_replaceA(sFileA, "\\", "/");
|
|
std::map<std::string, CFontStream*>::iterator it = m_mapStreams.find(sFileA);
|
|
return it != m_mapStreams.end() ? it->second : NULL;
|
|
}
|
|
};
|
|
|
|
class CApplicationFontStreams : public NSFonts::IApplicationFontStreams
|
|
{
|
|
private:
|
|
// этот мап нужно периодически опрашивать и удалять неиспользуемые стримы
|
|
std::map<std::wstring, CFontStream*> m_mapStreams;
|
|
public:
|
|
static CGlobalFontsMemoryStorage* m_pMemoryStorage;
|
|
|
|
CApplicationFontStreams();
|
|
virtual ~CApplicationFontStreams();
|
|
|
|
public:
|
|
NSFonts::IFontStream* GetStream(const std::wstring& strFile);
|
|
void CheckStreams(std::map<std::wstring, bool>& mapFiles);
|
|
void Clear();
|
|
};
|
|
|
|
class CFontsCache : public NSFonts::IFontsCache
|
|
{
|
|
friend class CFontManager;
|
|
friend class CApplicationFonts;
|
|
private:
|
|
std::map<std::string, CFontFile*> m_mapFiles;
|
|
NSFonts::IApplicationFontStreams* m_pApplicationFontStreams;
|
|
|
|
private:
|
|
std::list<std::string> m_arFiles;
|
|
int m_lCacheSize;
|
|
|
|
public:
|
|
CFontsCache() : NSFonts::IFontsCache()
|
|
{
|
|
m_pApplicationFontStreams = NULL;
|
|
m_lCacheSize = -1;
|
|
}
|
|
virtual ~CFontsCache()
|
|
{
|
|
Clear();
|
|
}
|
|
virtual void Clear()
|
|
{
|
|
for (std::map<std::string, CFontFile*>::iterator iter = m_mapFiles.begin(); iter != m_mapFiles.end(); ++iter)
|
|
{
|
|
CFontFile* pFile = iter->second;
|
|
RELEASEOBJECT(pFile);
|
|
}
|
|
m_mapFiles.clear();
|
|
|
|
if (-1 != m_lCacheSize)
|
|
m_arFiles.clear();
|
|
}
|
|
virtual void SetCacheSize(const int& lMaxSize)
|
|
{
|
|
if (lMaxSize <= 0)
|
|
m_lCacheSize = -1;
|
|
else
|
|
m_lCacheSize = lMaxSize;
|
|
}
|
|
|
|
public:
|
|
virtual void SetStreams(NSFonts::IApplicationFontStreams* pStreams) { m_pApplicationFontStreams = pStreams; }
|
|
virtual NSFonts::IFontFile* LockFont(NSFonts::CLibrary& library, const std::wstring& strFileName, const int& lFaceIndex, const double& dSize);
|
|
};
|
|
|
|
class CApplicationFonts;
|
|
class CFontManager : public NSFonts::IFontManager
|
|
{
|
|
friend class CApplicationFonts;
|
|
|
|
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;
|
|
int m_nRENDER_MODE;
|
|
|
|
CApplicationFonts* m_pApplication;
|
|
CFontsCache* m_pOwnerCache;
|
|
|
|
public:
|
|
CFontManager();
|
|
~CFontManager();
|
|
|
|
public:
|
|
virtual void AfterLoad();
|
|
|
|
virtual void Initialize();
|
|
virtual void SetOwnerCache(NSFonts::IFontsCache* pCache);
|
|
|
|
virtual NSFonts::IFontsCache* GetCache();
|
|
virtual NSFonts::IApplicationFonts* GetApplication();
|
|
virtual NSFonts::IFontFile* GetFile();
|
|
|
|
virtual double GetCharSpacing() { return m_fCharSpacing; }
|
|
virtual void SetCharSpacing(const double &dCharSpacing);
|
|
|
|
virtual int GetStringGID() { return m_bStringGID; }
|
|
virtual void SetStringGID(const int& bStringGID);
|
|
|
|
virtual int GetUnitsPerEm() { return m_lUnits_Per_Em; }
|
|
virtual int GetAscender() { return m_lAscender; }
|
|
virtual int GetDescender() { return m_lDescender; }
|
|
virtual int GetLineHeight() { return m_lLineHeight; }
|
|
|
|
virtual std::wstring GetName() { return m_sName; }
|
|
|
|
virtual double UpdateSize(const double& dOldSize, const double& dDpi, const double& dNewDpi);
|
|
|
|
virtual INT LoadString1(const std::wstring& wsBuffer, const float& fX, const float& fY);
|
|
virtual INT LoadString2(const std::wstring& wsBuffer, const float& fX, const float& fY);
|
|
virtual INT LoadString1(const unsigned int* pGids, const unsigned int& nGidsCount, const float& fX, const float& fY);
|
|
virtual INT LoadString2(const unsigned int* pGids, const unsigned int& nGidsCount, const float& fX, const float& fY);
|
|
virtual INT LoadString3(const int& gid, const float& fX, const float& fY);
|
|
virtual INT LoadString3C(const int& gid, const float& fX, const float& fY);
|
|
virtual INT LoadString2C(const int& wsBuffer, const float& fX, const float& fY);
|
|
|
|
virtual int GetKerning(UINT unPrevGID, UINT unGID);
|
|
virtual INT GetUnderline(float *pfStartX, float *pfStartY, float *pfEndX, float *pfEndY, float *pfSize);
|
|
|
|
virtual TFontCacheSizes MeasureChar(const LONG& lUnicode);
|
|
|
|
virtual TBBoxAdvance MeasureChar2(const LONG& lUnicode);
|
|
virtual TBBox MeasureString();
|
|
virtual TBBox MeasureString2();
|
|
|
|
virtual INT GetNextChar2(TGlyph*& pGlyph, float& fX, float& fY);
|
|
|
|
virtual INT SetTextMatrix(const double& fA, const double& fB, const double& fC, const double& fD, const double& fE, const double& fF);
|
|
virtual INT SetTextMatrix2(const double& fA, const double& fB, const double& fC, const double& fD, const double& fE, const double& fF);
|
|
|
|
virtual INT GetStringPath(NSFonts::ISimpleGraphicsPath* pPath);
|
|
|
|
virtual NSFonts::CFontInfo* GetFontInfoByParams(NSFonts::CFontSelectFormat& oFormat, bool bIsDictionaryUse = true);
|
|
virtual std::vector<NSFonts::CFontInfo*> GetAllStylesByFontName(const std::wstring& strName);
|
|
virtual INT LoadFontByName(const std::wstring& sName, const double& dSize, const int& lStyle, const double& dDpiX, const double& dDpiY);
|
|
virtual INT LoadFontFromFile(const std::wstring& sPath, const int& lFaceIndex, const double& dSize, const double& dDpiX, const double& dDpiY);
|
|
virtual INT LoadFontFromFile2(NSFonts::IFontsCache* pCache, const std::wstring& sPath, const int& lFaceIndex, const double& dSize, const double& dDpiX, const double& dDpiY);
|
|
virtual void CloseFont();
|
|
|
|
virtual std::wstring GetFontType();
|
|
virtual unsigned int GetNameIndex(const std::wstring& wsName);
|
|
|
|
virtual void SetSubpixelRendering(const bool& hmul, const bool& vmul);
|
|
|
|
virtual void GetFace(double& d0, double& d1, double& d2);
|
|
|
|
CFontFile* GetFontFileBySymbol(CFontFile* pFile, int code);
|
|
};
|
|
|
|
#endif // _BUILD_FONT_ENGINE_FONTMANAGER_H_
|