[docxrenderer] Compiled version

This commit is contained in:
Oleg Korshul
2021-07-18 15:49:35 +03:00
parent 132c979174
commit e9e9a954ac
17 changed files with 790 additions and 935 deletions

View File

@ -13,8 +13,7 @@ CONFIG += core_static_link_libstd
DEFINES += KERNEL_USE_DYNAMIC_LIBRARY_BUILDING
# CONFIG
HEADERS += ./kernel_config.h \
../DesktopEditor/common/StringUTF32.hpp
HEADERS += ./kernel_config.h
CORE_ROOT_DIR = $$PWD/..
PWD_ROOT_DIR = $$PWD
@ -34,7 +33,6 @@ HEADERS += \
./../DesktopEditor/graphics/TemporaryCS.h
SOURCES += \
../DesktopEditor/common/StringUTF32.cpp \
./../DesktopEditor/graphics/TemporaryCS.cpp
# THREAD
@ -62,6 +60,9 @@ SOURCES += ./../DesktopEditor/common/StringBuilder.cpp
HEADERS += ./../DesktopEditor/common/StringExt.h
SOURCES += ./../DesktopEditor/common/StringExt.cpp
HEADERS += ./../DesktopEditor/common/StringUTF32.h
SOURCES += ./../DesktopEditor/common/StringUTF32.cpp
# BYTE BUILDER
HEADERS += ./../DesktopEditor/common/ByteBuilder.h
SOURCES += ./../DesktopEditor/common/ByteBuilder.cpp

View File

@ -817,6 +817,14 @@ namespace NSStringUtils
WriteHexByteNoSafe((value >> 8) & 0xFF);
WriteHexByteNoSafe(value & 0xFF);
}
void CStringBuilder::WriteHexInt4(const unsigned int& value)
{
AddSize(8);
WriteHexByteNoSafe((value >> 24) & 0xFF);
WriteHexByteNoSafe((value >> 16) & 0xFF);
WriteHexByteNoSafe((value >> 8) & 0xFF);
WriteHexByteNoSafe(value & 0xFF);
}
void CStringBuilder::WriteHexColor3(const unsigned char& r, const unsigned char& g, const unsigned char& b)
{
AddSize(7);

View File

@ -144,6 +144,7 @@ namespace NSStringUtils
void WriteHexByteNoSafe(const unsigned char& value);
void WriteHexByte(const unsigned char& value);
void WriteHexInt3(const unsigned int& value);
void WriteHexInt4(const unsigned int& value);
void WriteHexColor3(const unsigned char& r, const unsigned char& g, const unsigned char& b);
void WriteHexColor3(const unsigned int& value);

View File

@ -29,121 +29,124 @@
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#include "StringUTF32.hpp"
#include "StringUTF32.h"
using namespace std;
using namespace NSStringExt;
using namespace NSStringUtils;
StringUTF32::StringUTF32() {}
CStringUTF32::CStringUTF32() {}
CStringUTF32::CStringUTF32(const CStringUTF32 &other): m_vec(other.m_vec) {}
CStringUTF32::CStringUTF32(const wchar_t *other) { *this = other; }
CStringUTF32::CStringUTF32(const wstring &other) { *this = other; }
CStringUTF32::CStringUTF32(const vector<uint32_t> &other): m_vec(other) {}
StringUTF32::StringUTF32(const StringUTF32 &other): _vec(other._vec) {}
StringUTF32::StringUTF32(const wchar_t *other) {
*this = other;
CStringUTF32::CStringUTF32(const uint32_t* data, const size_t& len)
{
m_vec.reserve(len);
for (size_t i = 0; i < len; ++i)
this->m_vec.push_back(data[i]);
}
StringUTF32::StringUTF32(const wstring &other) {
*this = other;
CStringUTF32::~CStringUTF32() {}
bool CStringUTF32::empty() const
{
return this->m_vec.empty();
}
StringUTF32::StringUTF32(const vector<uint32_t> &other): _vec(other) {}
StringUTF32::~StringUTF32() {}
size_t StringUTF32::Length() const {
return this->_vec.size();
size_t CStringUTF32::length() const
{
return this->m_vec.size();
}
void StringUTF32::Swap(StringUTF32 &other) {
StringUTF32 tmp = *this;
*this = other;
other = tmp;
wstring CStringUTF32::ToStdWString() const
{
return NSStringExt::CConverter::GetUnicodeFromUTF32(&this->m_vec[0], static_cast<long>(this->length()));
}
wstring StringUTF32::ToUTF16() const {
return CConverter::GetUnicodeFromUTF32(&this->_vec[0], static_cast<long>(this->Length()));
bool CStringUTF32::operator == (const CStringUTF32 &right) const
{
return this->m_vec == right.m_vec;
}
bool StringUTF32::Equals(const StringUTF32 &other) const {
return this->_vec == other._vec;
bool CStringUTF32::operator != (const CStringUTF32 &right) const
{
return !(this->m_vec == right.m_vec);
}
uint32_t &StringUTF32::GetCharAt(size_t index) {
return this->_vec[index];
uint32_t& CStringUTF32::operator [] (size_t index)
{
return this->m_vec[index];
}
StringUTF32 &StringUTF32::Concatenate(const StringUTF32 &other) {
this->_vec.reserve(this->Length() + other.Length());
for (size_t i = 0; i < other.Length(); ++i)
this->_vec.push_back(other._vec[i]);
CStringUTF32& CStringUTF32::operator = (const CStringUTF32 &right)
{
this->m_vec = right.m_vec;
return *this;
}
bool StringUTF32::operator == (const StringUTF32 &right) const {
return this->Equals(right);
}
bool StringUTF32::operator != (const StringUTF32 &right) const {
return !this->Equals(right);
}
uint32_t &StringUTF32::operator [] (size_t index) {
return this->GetCharAt(index);
}
StringUTF32 &StringUTF32::operator = (const StringUTF32 &right) {
this->_vec = right._vec;
return *this;
}
StringUTF32 &StringUTF32::operator = (const wchar_t *right) {
if (!right) {
throw runtime_error("Invalid argument! \"right\" must be a valid non-NULL pointer.");
CStringUTF32& CStringUTF32::operator = (const wchar_t *right)
{
if (!right)
{
m_vec.clear();
return *this;
}
wstring tmp = L"";
size_t length = 0;
while (right[length] != '\0') {
tmp += right[length++];
}
return (*this = tmp);
return (*this = std::wstring(right));
}
StringUTF32 &StringUTF32::operator = (const wstring &right) {
CStringUTF32& CStringUTF32::operator = (const wstring &right)
{
if (right.empty())
{
m_vec.clear();
return *this;
}
unsigned int utf32_len = 0;
uint32_t *utf32 = CConverter::GetUtf32FromUnicode(right, utf32_len);
if (!utf32) {
throw runtime_error("Operation aborted! Function \"GetUtf32FromUnicode\" returned NULL-pointer.");
}
this->_vec.clear();
this->_vec.reserve(utf32_len);
for (size_t i = 0; i < utf32_len; ++i) {
this->_vec.push_back(utf32[i]);
}
unsigned int* utf32 = NSStringExt::CConverter::GetUtf32FromUnicode(right, utf32_len);
this->m_vec.clear();
this->m_vec.reserve(utf32_len);
for (size_t i = 0; i < utf32_len; ++i)
this->m_vec.push_back(utf32[i]);
delete [] utf32;
return *this;
}
StringUTF32 &StringUTF32::operator = (const std::vector<uint32_t> &right) {
this->_vec = right;
CStringUTF32& CStringUTF32::operator = (const std::vector<uint32_t> &right)
{
this->m_vec = right;
return *this;
}
StringUTF32 StringUTF32::operator + (const StringUTF32 &right) const {
StringUTF32 result;
result._vec.reserve(this->Length() + right.Length());
return result.Concatenate(*this).Concatenate(right);
CStringUTF32 CStringUTF32::operator + (const CStringUTF32 &right) const
{
CStringUTF32 result;
result.m_vec.reserve(this->length() + right.length());
result.m_vec.insert(result.m_vec.end(), m_vec.begin(), m_vec.end());
result.m_vec.insert(result.m_vec.end(), right.m_vec.begin(), right.m_vec.end());
return result;
}
StringUTF32 &StringUTF32::operator += (const StringUTF32 &right) {
return this->Concatenate(right);
CStringUTF32& CStringUTF32::operator += (const CStringUTF32 &right)
{
m_vec.insert(m_vec.end(), right.m_vec.begin(), right.m_vec.end());
return *this;
}
CStringUTF32& CStringUTF32::operator += (const uint32_t& symbol)
{
m_vec.push_back(symbol);
return *this;
}
CStringUTF32 CStringUTF32::substr(size_t start, size_t count) const
{
CStringUTF32 result;
result.m_vec.reserve(count);
result.m_vec.insert(result.m_vec.end(), m_vec.begin() + start, m_vec.begin() + start + count);
return result;
}

View File

@ -34,40 +34,42 @@
#include <string>
#include <vector>
#include <stdint.h>
#include "StringExt.h"
namespace NSStringUtils {
class KERNEL_DECL StringUTF32 {
std::vector<uint32_t> _vec;
namespace NSStringUtils
{
class KERNEL_DECL CStringUTF32
{
std::vector<uint32_t> m_vec;
public:
StringUTF32();
StringUTF32(const StringUTF32 &other);
StringUTF32(const wchar_t *other);
StringUTF32(const std::wstring &other);
StringUTF32(const std::vector<uint32_t> &other);
virtual ~StringUTF32();
CStringUTF32();
CStringUTF32(const CStringUTF32 &other);
CStringUTF32(const wchar_t *other);
CStringUTF32(const std::wstring &other);
CStringUTF32(const std::vector<uint32_t> &other);
CStringUTF32(const uint32_t* data, const size_t& count);
virtual ~CStringUTF32();
virtual size_t Length() const;
virtual void Swap(StringUTF32 &other);
bool empty() const;
size_t length() const;
virtual std::wstring ToUTF16() const;
std::wstring ToStdWString() const;
virtual bool Equals(const StringUTF32 &other) const;
virtual uint32_t &GetCharAt(size_t index);
virtual StringUTF32 &Concatenate(const StringUTF32 &other);
bool operator == (const CStringUTF32 &right) const;
bool operator != (const CStringUTF32 &right) const;
uint32_t &operator [] (size_t index);
virtual bool operator == (const StringUTF32 &right) const;
virtual bool operator != (const StringUTF32 &right) const;
virtual uint32_t &operator [] (size_t index);
CStringUTF32 &operator = (const CStringUTF32 &right);
CStringUTF32 &operator = (const wchar_t *right);
CStringUTF32 &operator = (const std::wstring &right);
CStringUTF32 &operator = (const std::vector<uint32_t> &right);
virtual StringUTF32 &operator = (const StringUTF32 &right);
virtual StringUTF32 &operator = (const wchar_t *right);
virtual StringUTF32 &operator = (const std::wstring &right);
virtual StringUTF32 &operator = (const std::vector<uint32_t> &right);
CStringUTF32 operator + (const CStringUTF32 &right) const;
CStringUTF32 &operator += (const CStringUTF32 &right);
CStringUTF32 &operator += (const uint32_t& symbol);
virtual StringUTF32 operator + (const StringUTF32 &right) const;
virtual StringUTF32 &operator += (const StringUTF32 &right);
CStringUTF32 substr(size_t start, size_t count) const;
};
}

View File

@ -37,16 +37,14 @@ class CDocxRenderer_Private
{
public:
NSDocxRenderer::CDocument m_oDocument;
CApplicationFonts* m_pApplicationFonts;
std::wstring m_strDstFilePath;
std::wstring m_strTempFileDir;
std::wstring m_strTempFileName;
public:
CDocxRenderer_Private(CApplicationFonts* pFonts)
CDocxRenderer_Private(NSFonts::IApplicationFonts* pFonts, IRenderer* pRenderer) : m_oDocument(pRenderer, pFonts)
{
m_pApplicationFonts = pFonts;
}
~CDocxRenderer_Private()
{
@ -54,9 +52,9 @@ public:
}
};
CDocxRenderer::CDocxRenderer(CApplicationFonts* pAppFonts)
CDocxRenderer::CDocxRenderer(NSFonts::IApplicationFonts* pAppFonts)
{
m_pInternal = new CDocxRenderer_Private(pAppFonts);
m_pInternal = new CDocxRenderer_Private(pAppFonts, this);
}
CDocxRenderer::~CDocxRenderer()

View File

@ -61,7 +61,7 @@ class CDocxRenderer_Private;
class DOCXRENDERER_DECL_EXPORT CDocxRenderer : public IRenderer
{
public:
CDocxRenderer(CApplicationFonts* pAppFonts);
CDocxRenderer(NSFonts::IApplicationFonts* pAppFonts);
~CDocxRenderer();
HRESULT CreateNewFile(const std::wstring& wsPath);

View File

@ -26,20 +26,20 @@ LIBS += -lgdi32 \
}
HEADERS += \
src/resources/resources.h
HEADERS += \
src/resources/resources.h \
\
src/logic/Common.h \
src/logic/Page.h \
src/logic/Document.h \
src/logic/ElementImage.h \
src/logic/ElementParagraph.h \
src/logic/ElementShape.h \
src/logic/FontManager.h \
src/logic/FontManagerBase.h \
src/logic/Page.h
HEADERS += \
\
DocxRenderer.h
SOURCES += \
src/resources/resources.cpp \
\
DocxRenderer.cpp

View File

@ -2,6 +2,7 @@
#define DOCX_RENDERER_COMMON_H
#include "../DesktopEditor/common/StringBuilder.h"
#include "../DesktopEditor/common/StringUTF32.h"
#include "../DesktopEditor/common/CalculatorCRC32.h"
#include "../DesktopEditor/graphics/Matrix.h"
#include "../DesktopEditor/graphics/structures.h"
@ -9,12 +10,10 @@
#include "../DesktopEditor/raster/BgraFrame.h"
#include "../DesktopEditor/common/Directory.h"
#include "../DesktopEditor/xml/include/xmlutils.h"
#include "../DesktopEditor/graphics/pro/Graphics.h"
#include <algorithm>
#include <map>
#ifndef max
#define max(x, y) x < y ? y : x
#endif
namespace NSDocxRenderer
{
inline LONG ConvertColor(LONG lBGR)
@ -22,16 +21,6 @@ namespace NSDocxRenderer
return (0x00FFFFFF & (((lBGR & 0xFF) << 16) | (lBGR & 0x0000FF00) | ((lBGR >> 16) & 0xFF)));
}
std::wstring StringFormat(const std::wstring& format, ...)
{
// TODO: уйти от формата вообще
wchar_t buffer[1000];
va_list args;
va_start(args, format);
vswprintf(buffer, 1000, format.c_str(), args);
va_end (args);
}
class CBaseItem
{
public:
@ -106,7 +95,7 @@ namespace NSDocxRenderer
}
public:
CImageInfo WriteImage(CBgraFrame* pImage, double& x, double& y, double& width, double& height)
CImageInfo WriteImage(Aggplus::CImage* pImage, double& x, double& y, double& width, double& height)
{
if (height < 0)
{
@ -117,7 +106,7 @@ namespace NSDocxRenderer
return GenerateImageID(pImage);
}
CImageInfo WriteImage(std::wstring& strFile, double& x, double& y, double& width, double& height)
CImageInfo WriteImage(const std::wstring& strFile, double& x, double& y, double& width, double& height)
{
return GenerateImageID(strFile);
}
@ -127,19 +116,19 @@ namespace NSDocxRenderer
{
NSFile::CFileBinary::Copy(strFileSrc, strFileDst);
}
void SaveImage(std::wstring& strFileSrc, CImageInfo& oInfo)
void SaveImage(const std::wstring& strFileSrc, CImageInfo& oInfo)
{
CBgraFrame oFrame;
if (oFrame.OpenFile(strFileSrc))
Aggplus::CImage oFrame(strFileSrc);
if (NULL != oFrame.GetData())
return SaveImage(&oFrame, oInfo);
}
void SaveImage(CBgraFrame* pImage, CImageInfo& oInfo)
void SaveImage(Aggplus::CImage* pImage, CImageInfo& oInfo)
{
if (NULL == pImage)
return;
int w = pImage->get_Width();
int h = pImage->get_Height();
int w = pImage->GetWidth();
int h = pImage->GetHeight();
oInfo.m_eType = GetImageType(pImage);
@ -173,10 +162,10 @@ namespace NSDocxRenderer
}
}
CImageInfo GenerateImageID(CBgraFrame* pImage)
CImageInfo GenerateImageID(Aggplus::CImage* pImage)
{
BYTE* pData = pImage->get_Data();
int nSize = pImage->get_Stride() * pImage->get_Height();
BYTE* pData = pImage->GetData();
int nSize = pImage->GetStride() * pImage->GetHeight();
if (nSize < 0)
nSize = -nSize;
@ -195,7 +184,7 @@ namespace NSDocxRenderer
return oInfo;
}
CImageInfo GenerateImageID(std::wstring& strFileName)
CImageInfo GenerateImageID(const std::wstring& strFileName)
{
std::map<std::wstring, CImageInfo>::iterator find = m_mapImagesFile.find(strFileName);
if (find != m_mapImagesFile.end())
@ -210,11 +199,11 @@ namespace NSDocxRenderer
return oInfo;
}
CImageInfo::ImageType GetImageType(CBgraFrame* pFrame)
CImageInfo::ImageType GetImageType(Aggplus::CImage* pFrame)
{
int w = pFrame->get_Width();
int h = pFrame->get_Height();
BYTE* pBuffer = pFrame->get_Data();
int w = pFrame->GetWidth();
int h = pFrame->GetHeight();
BYTE* pBuffer = pFrame->GetData();
BYTE* pBufferMem = pBuffer + 3;
LONG lCountPix = w * h;
@ -227,15 +216,15 @@ namespace NSDocxRenderer
return CImageInfo::itJPG;
}
void FlipY(CBgraFrame* pImage)
void FlipY(Aggplus::CImage* pImage)
{
if (NULL == pImage)
return;
int w = pImage->get_Width();
int h = pImage->get_Height();
BYTE* pBuffer = pImage->get_Data();
int stride = pImage->get_Stride();
int w = pImage->GetWidth();
int h = pImage->GetHeight();
BYTE* pBuffer = pImage->GetData();
int stride = pImage->GetStride();
if (stride < 0)
stride = -stride;

File diff suppressed because it is too large Load Diff

View File

@ -85,49 +85,25 @@ namespace NSDocxRenderer
}
}
static std::wstring g_bstr_text_run_Start = L"<w:r><w:rPr>";
static std::wstring g_bstr_text_run_PropEnd = L"</w:rPr>";
static std::wstring g_bstr_text_run_End = L"</w:r>";
static std::wstring g_bstr_text_run_text1 = L"<w:t xml:space=\"preserve\">";
static std::wstring g_bstr_text_run_text2 = L"</w:t>";
static std::wstring g_bstr_text_bold_true = L"<w:b w:val=\"true\"/>";
static std::wstring g_bstr_text_italic_true = L"<w:i w:val=\"true\"/>";
static std::wstring g_string_text_font_size = L"<w:sz w:val=\"%d\"/><w:szCs w:val=\"%d\"/>";
static std::wstring g_string_text_font_name = L"<w:rFonts w:ascii=\"%s\" w:hAnsi=\"%s\" w:cs=\"%s\"/>";
static std::wstring g_string_text_color = L"<w:color w:val=\"%06x\"/>";
static std::wstring g_string_text_paragraph_noframes = L"<w:pPr><w:spacing w:before=\"%d\" w:line=\"%d\" w:lineRule=\"exact\"/><w:ind w:left=\"%d\"/></w:pPr>";
static std::wstring g_bstr_text_par_start = L"<w:p>";
static std::wstring g_bstr_text_par_end = L"</w:p>";
static std::wstring g_string_spacing_character = L"<w:spacing w:val=\"%d\"/>";
static std::wstring g_string_spacing_character2 = L"<w:spacing w:val=\"%.3lfpt\"/>";
static std::wstring g_string_par_props_mode2 = L"<w:pPr><w:framePr w:hAnchor=\"page\" w:vAnchor=\"page\" w:x=\"%d\" w:y=\"%d\"/></w:pPr>";
inline void DeleteSpaces(std::wstring& strText)
inline void DeleteSpaces(NSStringUtils::CStringUTF32& oText)
{
std::wstring::size_type nLen = strText.length();
std::wstring::size_type nStart = 0;
size_t nLen = oText.length();
size_t nStart = 0;
while ((nStart < nLen) && (' ' == strText[nStart]))
while ((nStart < nLen) && (' ' == oText[nStart]))
++nStart;
if (nStart == nLen)
{
strText = L"";
oText = L"";
return;
}
std::wstring::size_type nEnd = nLen - 1;
while ((nEnd > nStart) && (' ' == strText[nEnd]))
while ((nEnd > nStart) && (' ' == oText[nEnd]))
--nEnd;
strText = strText.substr(nStart, nEnd - nStart + 1);
oText = oText.substr(nStart, nEnd - nStart + 1);
}
class CContText
@ -139,8 +115,8 @@ namespace NSDocxRenderer
std::wstring m_strPickFontName;
LONG m_lPickFontStyle;
std::wstring m_strText;
std::wstring m_strGidText;
NSStringUtils::CStringUTF32 m_oText;
NSStringUtils::CStringUTF32 m_oGidText;
double m_dX;
double m_dY;
@ -158,9 +134,6 @@ namespace NSDocxRenderer
public:
CContText()
{
m_strText = L"";
m_strGidText = L"";
m_strPickFontName = L"";
m_lPickFontStyle = 0;
@ -194,8 +167,8 @@ namespace NSDocxRenderer
m_oFont = oSrc.m_oFont;
m_oBrush = oSrc.m_oBrush;
m_strText = oSrc.m_strText;
m_strGidText = oSrc.m_strGidText;
m_oText = oSrc.m_oText;
m_oGidText = oSrc.m_oGidText;
m_strPickFontName = oSrc.m_strPickFontName;
m_lPickFontStyle = oSrc.m_lPickFontStyle;
@ -227,114 +200,139 @@ namespace NSDocxRenderer
inline void Write(NSStringUtils::CStringBuilder& oWriter, CFontManagerLight* pManagerLight, bool bIsAddSpace = false)
{
oWriter.WriteString(g_bstr_text_run_Start);
oWriter.WriteString(L"<w:r><w:rPr>");
if (m_dWidth != m_dWidthWithoutSpaces)
{
DeleteSpaces(m_strText);
DeleteSpaces(m_oText);
m_dWidth = m_dWidthWithoutSpaces;
}
if (m_strPickFontName.empty())
{
if (m_oFont.Bold)
oWriter.WriteString(g_bstr_text_bold_true);
oWriter.WriteString(L"<w:b w:val=\"true\"/>");
if (m_oFont.Italic)
oWriter.WriteString(g_bstr_text_italic_true);
oWriter.WriteString(L"<w:i w:val=\"true\"/>");
if (bIsAddSpace)
{
m_dWidth += m_dSpaceWidthMM;
m_strText += L" ";
m_oText += L" ";
}
}
else
{
if (0x01 == (0x01 & m_lPickFontStyle))
oWriter.WriteString(g_bstr_text_bold_true);
oWriter.WriteString(L"<w:b w:val=\"true\"/>");
if (0x02 == (0x02 & m_lPickFontStyle))
oWriter.WriteString(g_bstr_text_italic_true);
oWriter.WriteString(L"<w:i w:val=\"true\"/>");
if (bIsAddSpace)
{
m_dWidth += pManagerLight->GetSpaceWidth();
m_strText += L" ";
m_oText += L" ";
}
// нужно перемерять...
double ___dSize = (double)((LONG)(m_oFont.Size * 2)) / 2;
pManagerLight->LoadFont(m_strPickFontName, m_lPickFontStyle, ___dSize, FALSE);
double dWidth = pManagerLight->MeasureStringWidth(m_strText);
double dWidth = pManagerLight->MeasureStringWidth(m_oText.ToStdWString());
if (fabs(dWidth - m_dWidth) > 2)
{
double dSpacing = (m_dWidth - dWidth) / (m_strText.length() + 1);
double dSpacing = (m_dWidth - dWidth) / (m_oText.length() + 1);
dSpacing *= c_dMMToDx;
oWriter.WriteString(StringFormat(g_string_spacing_character, (int)dSpacing));
oWriter.WriteString(L"<w:spacing w:val=\"");
oWriter.AddInt((int)dSpacing);
oWriter.WriteString(L"\"/>");
}
}
LONG lSize = (LONG)(2 * m_oFont.Size);
oWriter.WriteString(StringFormat(g_string_text_font_size, lSize, lSize));
int lSize = (int)(2 * m_oFont.Size);
oWriter.WriteString(L"<w:sz w:val=\"");
oWriter.AddInt(lSize);
oWriter.WriteString(L"\"/><w:szCs w:val=\"");
oWriter.AddInt(lSize);
oWriter.WriteString(L"\"/>");
const wchar_t* strFontName = m_strPickFontName.empty() ? m_oFont.Name.c_str() : m_strPickFontName.c_str();
oWriter.WriteString(StringFormat(g_string_text_font_name, strFontName, strFontName, strFontName));
std::wstring& strFontName = m_strPickFontName.empty() ? m_oFont.Name : m_strPickFontName;
oWriter.WriteString(L"<w:rFonts w:ascii=\"");
oWriter.WriteEncodeXmlString(strFontName);
oWriter.WriteString(L"\" w:hAnsi=\"");
oWriter.WriteEncodeXmlString(strFontName);
oWriter.WriteString(L"\" w:cs=\"");
oWriter.WriteEncodeXmlString(strFontName);
oWriter.WriteString(L"\"/>");
oWriter.WriteString(StringFormat(g_string_text_color, ConvertColor(m_oBrush.Color1)));
oWriter.WriteString(L"<w:color w:val=\"");
oWriter.WriteHexInt3(ConvertColor(m_oBrush.Color1));
oWriter.WriteString(L"\"/>");
oWriter.WriteString(g_bstr_text_run_PropEnd);
oWriter.WriteString(L"</w:rPr>");
oWriter.WriteString(g_bstr_text_run_text1);
oWriter.WriteString(L"<w:t xml:space=\"preserve\">");
oWriter.WriteEncodeXmlString(m_oText.ToStdWString());
oWriter.WriteString(L"</w:t>");
oWriter.WriteEncodeXmlString(m_strText);
oWriter.WriteString(g_bstr_text_run_text2);
oWriter.WriteString(g_bstr_text_run_End);
oWriter.WriteString(L"</w:r>");
}
void WriteTo(double dSpacingMM, NSStringUtils::CStringBuilder& oWriter, CFontManagerLight* pManagerLight)
{
oWriter.WriteString(g_bstr_text_run_Start);
oWriter.WriteString(L"<w:r><w:rPr>");
double dSpaceMMSize = m_dSpaceWidthMM;
if (m_strPickFontName.empty())
{
if (m_oFont.Bold)
oWriter.WriteString(g_bstr_text_bold_true);
oWriter.WriteString(L"<w:b w:val=\"true\"/>");
if (m_oFont.Italic)
oWriter.WriteString(g_bstr_text_italic_true);
oWriter.WriteString(L"<w:i w:val=\"true\"/>");
}
else
{
if (0x01 == (0x01 & m_lPickFontStyle))
oWriter.WriteString(g_bstr_text_bold_true);
oWriter.WriteString(L"<w:b w:val=\"true\"/>");
if (0x02 == (0x02 & m_lPickFontStyle))
oWriter.WriteString(g_bstr_text_italic_true);
oWriter.WriteString(L"<w:i w:val=\"true\"/>");
dSpaceMMSize = pManagerLight->GetSpaceWidth();
}
LONG lSize = (LONG)(2 * m_oFont.Size);
oWriter.WriteString(StringFormat(g_string_text_font_size, lSize, lSize));
int lSize = (int)(2 * m_oFont.Size);
oWriter.WriteString(L"<w:sz w:val=\"");
oWriter.AddInt(lSize);
oWriter.WriteString(L"\"/><w:szCs w:val=\"");
oWriter.AddInt(lSize);
oWriter.WriteString(L"\"/>");
const wchar_t* strFontName = m_strPickFontName.empty() ? m_oFont.Name.c_str() : m_strPickFontName.c_str();
oWriter.WriteString(StringFormat(g_string_text_font_name, strFontName, strFontName, strFontName));
std::wstring& strFontName = m_strPickFontName.empty() ? m_oFont.Name : m_strPickFontName;
oWriter.WriteString(L"<w:rFonts w:ascii=\"");
oWriter.WriteEncodeXmlString(strFontName);
oWriter.WriteString(L"\" w:hAnsi=\"");
oWriter.WriteEncodeXmlString(strFontName);
oWriter.WriteString(L"\" w:cs=\"");
oWriter.WriteEncodeXmlString(strFontName);
oWriter.WriteString(L"\"/>");
oWriter.WriteString(StringFormat(g_string_text_color, ConvertColor(m_oBrush.Color1)));
oWriter.WriteString(L"<w:color w:val=\"");
oWriter.WriteHexInt3(ConvertColor(m_oBrush.Color1));
oWriter.WriteString(L"\"/>");
LONG lSpacing = (LONG)((dSpacingMM - dSpaceMMSize) * c_dMMToDx);
oWriter.WriteString(StringFormat(g_string_spacing_character, lSpacing));
oWriter.WriteString(L"<w:spacing w:val=\"");
oWriter.AddInt((int)lSpacing);
oWriter.WriteString(L"\"/>");
oWriter.WriteString(g_bstr_text_run_PropEnd);
oWriter.WriteString(g_bstr_text_run_text1);
oWriter.WriteString(L"</w:rPr>");
oWriter.WriteString(L"<w:t xml:space=\"preserve\">");
oWriter.WriteString(L" ");
oWriter.WriteString(g_bstr_text_run_text2);
oWriter.WriteString(L"</w:t>");
oWriter.WriteString(g_bstr_text_run_End);
oWriter.WriteString(L"</w:r>");
}
};
@ -583,34 +581,37 @@ namespace NSDocxRenderer
virtual void ToXml(NSStringUtils::CStringBuilder& oWriter)
{
oWriter.WriteString(g_bstr_text_par_start);
oWriter.WriteString(L"<w:p>");
switch (m_eTextAssociationType)
{
case TextAssociationTypeDefault:
case TextAssociationTypeLine:
{
LONG lX = (LONG)(m_dLeft * c_dMMToDx);
LONG lY = (LONG)(m_dTop * c_dMMToDx);
oWriter.WriteString(StringFormat(g_string_par_props_mode2, lX, lY));
oWriter.WriteString(L"<w:pPr><w:framePr w:hAnchor=\"page\" w:vAnchor=\"page\" w:x=\"");
oWriter.AddInt((int)(m_dLeft * c_dMMToDx));
oWriter.WriteString(L"\" w:y=\"");
oWriter.AddInt((int)(m_dTop * c_dMMToDx));
oWriter.WriteString(L"\"/></w:pPr>");
break;
}
case TextAssociationTypeBlock:
{
LONG lX = (LONG)(m_dLeft * c_dMMToDx);
LONG lY = (LONG)(m_dTop * c_dMMToDx);
oWriter.WriteString(StringFormat(g_string_par_props_mode2, lX, lY));
break;
oWriter.WriteString(L"<w:pPr><w:framePr w:hAnchor=\"page\" w:vAnchor=\"page\" w:x=\"");
oWriter.AddInt((int)(m_dLeft * c_dMMToDx));
oWriter.WriteString(L"\" w:y=\"");
oWriter.AddInt((int)(m_dTop * c_dMMToDx));
oWriter.WriteString(L"\"/></w:pPr>");
}
case TextAssociationTypeNoFrames:
{
LONG lSpaceBefore = (LONG)(m_dSpaceBefore * c_dMMToDx);
LONG lHeight = (LONG)(m_dHeight * c_dMMToDx);
LONG lLeft = (LONG)(m_dLeft * c_dMMToDx);
oWriter.WriteString(StringFormat(g_string_text_paragraph_noframes, lSpaceBefore, lHeight, lLeft));
oWriter.WriteString(L"<w:pPr><w:spacing w:before=\"");
oWriter.AddInt((int)(m_dSpaceBefore * c_dMMToDx));
oWriter.WriteString(L"\" w:line=\"");
oWriter.AddInt((int)(m_dHeight * c_dMMToDx));
oWriter.WriteString(L"\" w:lineRule=\"exact\"/><w:ind w:left=\"");
oWriter.AddInt((int)(m_dLeft * c_dMMToDx));
oWriter.WriteString(L"\"/></w:pPr>");
break;
}
default:
@ -625,7 +626,7 @@ namespace NSDocxRenderer
pTextLine->ToXml(oWriter, m_pManagerLight);
}
oWriter.WriteString(g_bstr_text_par_end);
oWriter.WriteString(L"</w:p>");
}
};
}

View File

@ -40,7 +40,7 @@ namespace NSDocxRenderer
{
if (NULL == m_pData)
{
m_lSize = max(nSize, 500);
m_lSize = std::max(nSize, (size_t)500);
m_pData = (double*)malloc(m_lSize * sizeof(double));
m_lSizeCur = 0;

View File

@ -1,6 +1,7 @@
#pragma once
#include "Common.h"
#include "FontManagerBase.h"
#include "../../DocxRenderer.h"
namespace NSDocxRenderer
{
@ -9,28 +10,20 @@ namespace NSDocxRenderer
const double c_dDpiX = 72.0;
const double c_dDpiY = 72.0;
enum TextAssociationType
{
TextAssociationTypeDefault = 0,
TextAssociationTypeLine = 1,
TextAssociationTypeNoFrames = 2,
TextAssociationTypeBlock = 3
};
class CFontTableEntry
{
public:
CString m_strFamilyName;
CString m_strPANOSE;
LONG m_lStyle;
CAtlArray<DWORD> m_arSignature;
bool m_bIsFixedWidth;
std::wstring m_strFamilyName;
std::wstring m_strPANOSE;
LONG m_lStyle;
std::vector<UINT> m_arSignature;
bool m_bIsFixedWidth;
public:
CFontTableEntry() : m_arSignature()
{
m_strFamilyName = _T("");
m_strPANOSE = _T("");
m_strFamilyName = L"";
m_strPANOSE = L"";
m_lStyle = 0;
m_bIsFixedWidth = false;
}
@ -46,7 +39,7 @@ namespace NSDocxRenderer
m_strFamilyName = oSrc.m_strFamilyName;
m_strPANOSE = oSrc.m_strPANOSE;
m_lStyle = oSrc.m_lStyle;
m_arSignature.Copy(oSrc.m_arSignature);
m_arSignature = oSrc.m_arSignature;
m_bIsFixedWidth = oSrc.m_bIsFixedWidth;
return *this;
@ -56,7 +49,7 @@ namespace NSDocxRenderer
class CFontTable
{
public:
CAtlMap<CString, CFontTableEntry> m_mapTable;
std::map<std::wstring, CFontTableEntry> m_mapTable;
public:
CFontTable() : m_mapTable()
@ -67,18 +60,17 @@ namespace NSDocxRenderer
class CFontManager : public CFontManagerBase
{
public:
NSStructures::CFont* m_pFont;
NSDocxRenderer::CMatrix* m_pTransform;
double m_dSpaceWidthMM;
NSStructures::CFont* m_pFont;
Aggplus::CMatrix* m_pTransform;
double m_dSpaceWidthMM;
public:
CFontTable m_oFontTable;
CFontTable m_oFontTable;
public:
CFontManager() : m_pFont(NULL), CFontManagerBase()
CFontManager(NSFonts::IApplicationFonts* pFonts) : m_pFont(NULL), CFontManagerBase(pFonts)
{
m_pTransform = NULL;
m_dSpaceWidthMM = 0;
}
virtual ~CFontManager()
@ -86,24 +78,23 @@ namespace NSDocxRenderer
}
public:
AVSINLINE void Init()
void Init()
{
m_oFontTable.m_mapTable.RemoveAll();
m_oFontTable.m_mapTable.clear();
}
AVSINLINE void AddFontToMap()
void AddFontToMap()
{
CAtlMap<CString, CFontTableEntry>::CPair* pPair = m_oFontTable.m_mapTable.Lookup(m_oFont.m_strFamilyName);
if (NULL == pPair)
{
CFontTableEntry oEntry;
oEntry.m_strFamilyName = m_oFont.m_strFamilyName;
oEntry.m_strPANOSE = m_oFont.m_strPANOSE;
oEntry.m_lStyle = m_oFont.m_lStyle;
oEntry.m_bIsFixedWidth = m_oFont.m_bIsFixedWidth;
oEntry.m_arSignature.Copy(m_oFont.m_arSignature);
if (m_oFontTable.m_mapTable.end() != m_oFontTable.m_mapTable.find(m_oFont.m_strFamilyName))
{
CFontTableEntry oEntry;
oEntry.m_strFamilyName = m_oFont.m_strFamilyName;
oEntry.m_strPANOSE = m_oFont.m_strPANOSE;
oEntry.m_lStyle = m_oFont.m_lStyle;
oEntry.m_bIsFixedWidth = m_oFont.m_bIsFixedWidth;
oEntry.m_arSignature = m_oFont.m_arSignature;
m_oFontTable.m_mapTable.SetAt(m_oFont.m_strFamilyName, oEntry);
}
m_oFontTable.m_mapTable.insert(std::pair<std::wstring, CFontTableEntry>(m_oFont.m_strFamilyName, oEntry));
}
}
public:
@ -113,13 +104,13 @@ namespace NSDocxRenderer
return;
double dSize = m_pFont->Size;
double dSizeFont = dSize * ((m_pTransform->m_agg_mtx.sx + m_pTransform->m_agg_mtx.sy) / 2);
double dSizeFont = dSize * ((m_pTransform->sx() + m_pTransform->sy()) / 2);
double dPix = m_pFont->CharSpace / c_dPixToMM;
m_pFont->Size = dSizeFont;
if (m_pFont->IsEqual2(&m_oFont.m_oFont))
if (m_pFont->IsEqual(&m_oFont.m_oFont))
{
m_pFont->Size = dSize;
m_pManager->SetCharSpacing(dPix);
@ -132,7 +123,7 @@ namespace NSDocxRenderer
bool bIsPath = false;
if (_T("") == m_pFont->Path)
if (m_pFont->Path.empty())
{
CFontManagerBase::LoadFontByName(m_oFont.m_oFont.Name, m_oFont.m_oFont.Size, m_oFont.m_oFont.GetStyle(), c_dDpiX, c_dDpiY);
}
@ -146,25 +137,19 @@ namespace NSDocxRenderer
bIsPath = true;
}
long lGid = 0;
m_pManager->GetStringGID(&lGid);
int bIsGID = m_pManager->GetStringGID();
m_pManager->SetStringGID(FALSE);
m_pManager->LoadString(L" ", 0, 0);
float _x = 0;
float _y = 0;
float _w = 0;
float _h = 0;
m_pManager->LoadString2(L" ", 0, 0);
TBBox bbox = m_pManager->MeasureString2();
m_pManager->MeasureString2(&_x, &_y, &_w, &_h);
m_dSpaceWidthMM = (double)_w * c_dPixToMM;
m_dSpaceWidthMM = (double)(bbox.fMaxX - bbox.fMinX) * c_dPixToMM;
if (0 >= m_dSpaceWidthMM)
{
m_dSpaceWidthMM = 1.0;
}
m_pManager->SetStringGID(lGid);
m_pManager->SetStringGID(bIsGID);
LoadFontMetrics();
LoadFontParams(bIsPath);
@ -173,25 +158,7 @@ namespace NSDocxRenderer
AddFontToMap();
}
AVSINLINE void MeasureString(const CString& strText, double x, double y, double& dBoxX, double& dBoxY, double& dBoxWidth, double& dBoxHeight, MeasureType measureType)
{
BSTR bsText = strText.AllocSysString();
MeasureString(bsText, x, y, dBoxX, dBoxY, dBoxWidth, dBoxHeight, measureType);
SysFreeString(bsText);
}
AVSINLINE void MeasureStringUNICODE(const CString& strText, double x, double y, double& dBoxX, double& dBoxY, double& dBoxWidth, double& dBoxHeight, MeasureType measureType)
{
m_pManager->SetStringGID(FALSE);
MeasureString(strText, x, y, dBoxX, dBoxY, dBoxWidth, dBoxHeight, measureType);
m_pManager->SetStringGID(TRUE);
}
AVSINLINE void MeasureStringUNICODE(BSTR strText, double x, double y, double& dBoxX, double& dBoxY, double& dBoxWidth, double& dBoxHeight, MeasureType measureType)
{
m_pManager->SetStringGID(FALSE);
MeasureString(strText, x, y, dBoxX, dBoxY, dBoxWidth, dBoxHeight, measureType);
m_pManager->SetStringGID(TRUE);
}
void MeasureString(BSTR bsText, double x, double y, double& dBoxX, double& dBoxY, double& dBoxWidth, double& dBoxHeight, MeasureType measureType)
void MeasureString(std::wstring sText, double x, double y, double& dBoxX, double& dBoxY, double& dBoxWidth, double& dBoxHeight, MeasureType measureType)
{
LoadFont();
@ -203,26 +170,22 @@ namespace NSDocxRenderer
if (NULL == m_pManager)
return;
m_pManager->LoadString(bsText, (float)x, (float)y);
float fx = 0;
float fy = 0;
float fwidth = 0;
float fheight = 0;
m_pManager->LoadString1(sText, (float)x, (float)y);
TBBox bbox;
if (MeasureTypeGlyph == measureType)
{
m_pManager->MeasureString(&fx, &fy, &fwidth, &fheight);
bbox = m_pManager->MeasureString();
}
else if (MeasureTypePosition == measureType)
{
m_pManager->MeasureString2(&fx, &fy, &fwidth, &fheight);
bbox = m_pManager->MeasureString2();
}
dBoxX = (double)fx;
dBoxY = (double)fy;
dBoxWidth = (double)fwidth;
dBoxHeight = (double)fheight;
dBoxX = (double)bbox.fMinX;
dBoxY = (double)bbox.fMinY;
dBoxWidth = (double)(bbox.fMaxX - bbox.fMinX);
dBoxHeight = (double)(bbox.fMaxY - bbox.fMinY);
// переводим в миллиметры
dBoxX *= c_dPixToMM;
@ -230,9 +193,43 @@ namespace NSDocxRenderer
dBoxWidth *= c_dPixToMM;
dBoxHeight *= c_dPixToMM;
}
void MeasureStringGids(unsigned int* pGids, unsigned int count, double x, double y, double& dBoxX, double& dBoxY, double& dBoxWidth, double& dBoxHeight, MeasureType measureType)
{
LoadFont();
dBoxX = 0;
dBoxY = 0;
dBoxWidth = 0;
dBoxHeight = 0;
__forceinline double GetBaseLineOffset()
if (NULL == m_pManager)
return;
m_pManager->LoadString1(pGids, count, (float)x, (float)y);
TBBox bbox;
if (MeasureTypeGlyph == measureType)
{
bbox = m_pManager->MeasureString();
}
else if (MeasureTypePosition == measureType)
{
bbox = m_pManager->MeasureString2();
}
dBoxX = (double)bbox.fMinX;
dBoxY = (double)bbox.fMinY;
dBoxWidth = (double)(bbox.fMaxX - bbox.fMinX);
dBoxHeight = (double)(bbox.fMaxY - bbox.fMinY);
// переводим в миллиметры
dBoxX *= c_dPixToMM;
dBoxY *= c_dPixToMM;
dBoxWidth *= c_dPixToMM;
dBoxHeight *= c_dPixToMM;
}
inline double GetBaseLineOffset()
{
LoadFont();
@ -243,35 +240,34 @@ namespace NSDocxRenderer
return d1;
}
__forceinline double GetFontHeight()
inline double GetFontHeight()
{
return c_dPtToMM * (m_oFont.m_dLineSpacing * m_oFont.m_oFont.Size ) / m_oFont.m_dEmHeight;
}
__forceinline void SetStringGid(const LONG& lGid)
inline void SetStringGid(const LONG& lGid)
{
if (NULL != m_pManager)
m_pManager->SetStringGID(lGid);
}
__forceinline void GenerateFontName2(CString& strText)
inline void GenerateFontName2(NSStringUtils::CStringUTF32& oText)
{
bool bIsNeedAddToMap = CFontManagerBase::GenerateFontName(strText);
bool bIsNeedAddToMap = CFontManagerBase::GenerateFontName(oText);
if (bIsNeedAddToMap)
{
CAtlMap<CString, CFontTableEntry>::CPair* pPair = m_oFontTable.m_mapTable.Lookup(m_strCurrentPickFont);
if (NULL == pPair)
{
CFontTableEntry oEntry;
oEntry.m_strFamilyName = m_strCurrentPickFont;
oEntry.m_strPANOSE = m_oFont.m_strPANOSE;
oEntry.m_lStyle = m_oFont.m_lStyle;
oEntry.m_bIsFixedWidth = m_oFont.m_bIsFixedWidth;
oEntry.m_arSignature.Copy(m_oFont.m_arSignature);
if (m_oFontTable.m_mapTable.end() != m_oFontTable.m_mapTable.find(m_strCurrentPickFont))
{
CFontTableEntry oEntry;
oEntry.m_strFamilyName = m_strCurrentPickFont;
oEntry.m_strPANOSE = m_oFont.m_strPANOSE;
oEntry.m_lStyle = m_oFont.m_lStyle;
oEntry.m_bIsFixedWidth = m_oFont.m_bIsFixedWidth;
oEntry.m_arSignature = m_oFont.m_arSignature;
m_oFontTable.m_mapTable.SetAt(m_oFont.m_oFont.Path, oEntry);
}
m_oFontTable.m_mapTable.insert(std::pair<std::wstring, CFontTableEntry>(m_oFont.m_strFamilyName, oEntry));
}
}
}
};
@ -279,40 +275,36 @@ namespace NSDocxRenderer
class CFontManagerLight
{
private:
CString m_strFontName;
std::wstring m_strFontName;
LONG m_lFontStyle;
double m_dSize;
double m_dSpaceWidth;
AVSGraphics::IASCFontManager* m_pManager;
NSFonts::IFontManager* m_pManager;
public:
CFontManagerLight()
{
m_strFontName = _T("");
m_strFontName = L"";
m_lFontStyle = 0;
m_dSize = 0;
m_dSpaceWidth = 0;
m_dSpaceWidth = 0;
m_pManager = NULL;
CoCreateInstance(AVSGraphics::CLSID_CASCFontManager, NULL, CLSCTX_ALL, AVSGraphics::IID_IASCFontManager, (void**)&m_pManager);
m_pManager->Initialize(L"");
m_pManager->SetDefaultFont(L"Arial");
// TODO: создать менеджер
}
~CFontManagerLight()
{
RELEASEINTERFACE(m_pManager);
}
AVSINLINE double GetSpaceWidth()
inline double GetSpaceWidth()
{
return m_dSpaceWidth;
}
public:
AVSINLINE void LoadFont(CString& strFontName, LONG& lStyle, double& dSize, const BOOL& bIsGID)
void LoadFont(std::wstring& strFontName, LONG& lStyle, double& dSize, const BOOL& bIsGID)
{
if ((strFontName == m_strFontName) && (lStyle == m_lFontStyle) && (dSize == m_dSize))
{
@ -324,31 +316,19 @@ namespace NSDocxRenderer
m_lFontStyle = lStyle;
m_dSize = dSize;
BSTR bsName = m_strFontName.AllocSysString();
m_pManager->LoadFontByName(bsName, (float)m_dSize, m_lFontStyle, c_dDpiX, c_dDpiY);
SysFreeString(bsName);
CString strSpace = _T(" ");
m_dSpaceWidth = MeasureStringWidth(strSpace);
m_pManager->LoadFontByName(strFontName, (float)m_dSize, m_lFontStyle, c_dDpiX, c_dDpiY);
m_dSpaceWidth = MeasureStringWidth(L" ");
m_pManager->SetStringGID(bIsGID);
}
AVSINLINE double MeasureStringWidth(CString& sText)
double MeasureStringWidth(const std::wstring& sText)
{
BSTR bsText = sText.AllocSysString();
m_pManager->LoadString(bsText, (float)0, (float)0);
SysFreeString(bsText);
m_pManager->LoadString2(sText, (float)0, (float)0);
TBBox bbox = m_pManager->MeasureString2();
float fx = 0;
float fy = 0;
float fwidth = 0;
float fheight = 0;
m_pManager->MeasureString2(&fx, &fy, &fwidth, &fheight);
return fwidth * c_dPixToMM;
return (bbox.fMaxX - bbox.fMinX) * c_dPixToMM;
}
};
}
}

View File

@ -200,19 +200,21 @@ namespace NSFontManager
m_oFont.m_lAvgWidth = -1;
wchar_t wsDrive[MAX_PATH], wsDir[MAX_PATH], wsFilename[MAX_PATH], wsExt[MAX_PATH];
_wsplitpath( strPath.GetBuffer(), wsDrive, wsDir, wsFilename, wsExt );
CString wsEncodingPath = CString(wsDrive) + CString(wsDir) + CString(wsFilename) + CString(_T(".enc"));
bool bIsCID = false;
std::wstring sFileExt = NSFile::GetFileExtention(strPath);
if (std::wstring::npos != sFileExt.find(L"cid"))
bIsCID = true;
bool bIsCID = false;
CString strExt(wsExt);
if (-1 != strExt.Find(_T("cid")))
bIsCID = true;
std::wstring sFileName = NSFile::GetFileName(strPath);
std::wstring::size_type pos = sFileName.rfind('.');
if (std::wstring::npos != pos)
sFileName = sFileName.substr(0, pos);
std::wstring sEncFilePath = NSFile::GetDirectoryName(strPath) + L"/" + sFileName + L".enc";
XmlUtils::CXmlNode oMainNode;
oMainNode.FromXmlFile(wsEncodingPath);
oMainNode.FromXmlFile(sEncFilePath);
if (_T("PDF-resources") == oMainNode.GetName())
if (L"PDF-resources" == oMainNode.GetName())
{
if (bIsCID)
{
@ -245,7 +247,7 @@ namespace NSFontManager
XmlUtils::CXmlNode oCurNode;
if ( oNode.GetNode( L"AvgWidth", oCurNode ) )
{
std::wstring sValue = oCurNode.GetAttribute(_T("value"));
std::wstring sValue = oCurNode.GetAttribute(L"value");
try {
m_oFont.m_lAvgWidth = std::stol(sValue);
} catch (std::invalid_argument &) {}
@ -256,26 +258,7 @@ namespace NSFontManager
}
public:
void MeasureString(const CString& strText, double x, double y, double& dBoxX, double& dBoxY, double& dBoxWidth, double& dBoxHeight, MeasureType measureType)
{
BSTR bsText = strText.AllocSysString();
MeasureString(bsText, x, y, dBoxX, dBoxY, dBoxWidth, dBoxHeight, measureType);
SysFreeString(bsText);
}
void MeasureStringUNICODE(const CString& strText, double x, double y, double& dBoxX, double& dBoxY, double& dBoxWidth, double& dBoxHeight, MeasureType measureType)
{
m_pManager->SetStringGID(FALSE);
MeasureString(strText, x, y, dBoxX, dBoxY, dBoxWidth, dBoxHeight, measureType);
m_pManager->SetStringGID(TRUE);
}
void MeasureStringUNICODE(BSTR strText, double x, double y, double& dBoxX, double& dBoxY, double& dBoxWidth, double& dBoxHeight, MeasureType measureType)
{
m_pManager->SetStringGID(FALSE);
MeasureString(strText, x, y, dBoxX, dBoxY, dBoxWidth, dBoxHeight, measureType);
m_pManager->SetStringGID(TRUE);
}
virtual void MeasureString(BSTR bsText, double x, double y, double& dBoxX, double& dBoxY, double& dBoxWidth, double& dBoxHeight, MeasureType measureType)
virtual void MeasureString(const std::wstring& sText, double x, double y, double& dBoxX, double& dBoxY, double& dBoxWidth, double& dBoxHeight, MeasureType measureType)
{
}
virtual void CalculateBaselineOffset()
@ -302,7 +285,12 @@ namespace NSFontManager
std::wstring ToHexString( BYTE uc )
{
return StringFormat(L"%02X", uc);
std::wstring sRet = L"";
char c1 = (char)(uc >> 4);
char c2 = (char)(uc & 0x0F);
sRet += (wchar_t)((c1 < 10) ? ('0' + c1) : ('A' + c1 - 10));
sRet += (wchar_t)((c2 < 10) ? ('0' + c2) : ('A' + c2 - 10));
return sRet;
}
void LoadFontParams(bool bIsPath = true)
@ -311,18 +299,7 @@ namespace NSFontManager
if (NULL == m_pManager)
return;
if (m_oFont.m_oFont.Name.empty())
{
// FamilyName
BSTR bsFamilyName = NULL;
m_pManager->GetFamilyNameEx(_bstr_t("<DeletePDFPrefix/>"), &bsFamilyName);
m_oFont.m_strFamilyName = (CString)bsFamilyName;
SysFreeString(bsFamilyName);
}
else
{
m_oFont.m_strFamilyName = m_oFont.m_oFont.Name;
}
m_oFont.m_strFamilyName = m_oFont.m_oFont.Name;
m_oFont.m_lStyle = 0x00;
if (m_pManager->GetFile()->IsBold())
@ -1191,7 +1168,7 @@ namespace NSFontManager
//case 31: sUCRName = "Reserved for process-internal usage"; break;
}
inline bool GetRange(const WCHAR& symbol, BYTE& lRangeNum, BYTE& lRange)
inline bool GetRange(const int& symbol, BYTE& lRangeNum, BYTE& lRange)
{
lRangeNum = m_pRangesNums[symbol];
lRange = m_pRanges[symbol];
@ -1236,9 +1213,9 @@ namespace NSFontManager
public:
bool GenerateFontName(std::wstring& strText)
bool GenerateFontName(NSStringUtils::CStringUTF32& oText)
{
if (m_oFont.m_oFont.Path.empty() || strText.empty())
if (m_oFont.m_oFont.Path.empty() || oText.empty())
{
m_strCurrentPickFont = m_oFont.m_strFamilyName;
m_lCurrentPictFontStyle = m_oFont.m_lStyle;
@ -1248,7 +1225,7 @@ namespace NSFontManager
BYTE lRangeNum = 0xFF;
BYTE lRange = 0xFF;
GetRange(strText[0], lRangeNum, lRange);
GetRange(oText[0], lRangeNum, lRange);
std::list<CFontPickUp>::iterator posStart, pos;
posStart = pos = m_arListPicUps.begin();
//POSITION posStart = m_arListPicUps.GetHeadPosition();
@ -1339,6 +1316,6 @@ namespace NSFontManager
return true;
}
};
};
}
#endif // DOCX_RENDERER_FMB_H

View File

@ -8,19 +8,14 @@ namespace NSDocxRenderer
const double STANDART_STRING_HEIGHT_MM = 4.2333333333333334;
const double THE_SAME_STRING_Y_PRECISION_MM = 0.01;
static std::wstring g_bstr_sectStart = L"<w:p><w:pPr><w:sectPr>";
static std::wstring g_bstr_lastSect = L"<w:type w:val=\"continuous\"/>";
static std::wstring g_bstr_sectEnd = L"<w:pgMar w:top=\"0\" w:right=\"0\" w:bottom=\"0\" w:left=\"0\"/></w:sectPr><w:spacing w:line=\"1\" w:lineRule=\"exact\"/></w:pPr></w:p>";
static std::wstring g_string_sectSizeVer = L"<w:pgSz w:w=\"%d\" w:h=\"%d\" w:orient=\"portrait\"/>";
static std::wstring g_string_sectSizeHor = L"<w:pgSz w:w=\"%d\" w:h=\"%d\" w:orient=\"landscape\"/>";
inline bool IsSpaceUtf32(NSStringUtils::CStringUTF32& oText)
{
if (1 != oText.length())
return false;
return (' ' == oText[0]) ? true : false;
}
static std::wstring g_bstr_drawingParStart = L"<w:p><w:pPr><w:spacing w:line=\"1\" w:lineRule=\"exact\"/></w:pPr>";
static std::wstring g_bstr_ParEnd = L"</w:p>";
static std::wstring g_bstr_lastsection1 = L"<w:sectPr>";
static std::wstring g_bstr_lastsection2 = L"<w:pgMar w:top=\"0\" w:right=\"0\" w:bottom=\"0\" w:left=\"0\" w:header=\"0\" w:footer=\"0\" w:gutter=\"0\"/></w:sectPr>";
inline bool IsUnicodeSymbol( wchar_t symbol )
inline bool IsUnicodeSymbol( int symbol )
{
bool result = false;
@ -43,8 +38,8 @@ namespace NSDocxRenderer
NSStructures::CShadow* m_pShadow;
NSStructures::CEdgeText* m_pEdgeText;
NSDocxRenderer::CMatrix* m_pTransform;
AVSGraphics::IASCGraphicSimpleComverter* m_pSimpleGraphicsConverter;
Aggplus::CMatrix* m_pTransform;
Aggplus::CGraphicsPathSimpleConverter* m_pSimpleGraphicsConverter;
CVectorGraphics m_oVector;
@ -69,7 +64,7 @@ namespace NSDocxRenderer
bool m_bIsDeleteTextClipPage;
public:
CPage() : m_oManager(), m_oManagerLight()
CPage(NSFonts::IApplicationFonts* pFonts) : m_oManager(pFonts), m_oManagerLight()
{
m_pFont = NULL;
m_pBrush = NULL;
@ -91,7 +86,7 @@ namespace NSDocxRenderer
public:
void Init(NSStructures::CFont* pFont, NSStructures::CPen* pPen, NSStructures::CBrush* pBrush,
NSStructures::CShadow* pShadow, NSStructures::CEdgeText* pEdge, NSDocxRenderer::CMatrix* pMatrix, AVSGraphics::IASCGraphicSimpleComverter* pSimple)
NSStructures::CShadow* pShadow, NSStructures::CEdgeText* pEdge, Aggplus::CMatrix* pMatrix, Aggplus::CGraphicsPathSimpleConverter* pSimple)
{
m_pFont = pFont;
m_pPen = pPen;
@ -107,36 +102,36 @@ namespace NSDocxRenderer
m_pCurrentLine = NULL;
m_oWriterVML.AddSize(1000, 1000);
m_oWriterVML.AddSize(1000);
}
void Clear()
{
size_t nCount = 0;
nCount = m_arTextLine.GetCount();
nCount = m_arTextLine.size();
for (size_t i = 0; i < nCount; ++i)
{
CTextLine* pTemp = m_arTextLine[i];
RELEASEOBJECT(pTemp);
}
m_arTextLine.RemoveAll();
m_arTextLine.clear();
nCount = m_arGraphicItems.GetCount();
nCount = m_arGraphicItems.size();
for (size_t i = 0; i < nCount; ++i)
{
CBaseItem* pTemp = m_arGraphicItems[i];
RELEASEOBJECT(pTemp);
}
m_arGraphicItems.RemoveAll();
m_arGraphicItems.clear();
nCount = m_arParagraphs.GetCount();
nCount = m_arParagraphs.size();
for (size_t i = 0; i < nCount; ++i)
{
CParagraph* pTemp = m_arParagraphs[i];
RELEASEOBJECT(pTemp);
}
m_arParagraphs.RemoveAll();
m_arParagraphs.clear();
m_pCurrentLine = NULL;
@ -156,14 +151,14 @@ namespace NSDocxRenderer
m_pCurrentLine = new CTextLine();
m_pCurrentLine->m_dBaselinePos = dBaseLinePos;
m_arTextLine.Add(m_pCurrentLine);
m_arTextLine.push_back(m_pCurrentLine);
return;
}
if (fabs(m_pCurrentLine->m_dBaselinePos - dBaseLinePos) <= THE_SAME_STRING_Y_PRECISION_MM)
{
return;
}
size_t nCount = m_arTextLine.GetCount();
size_t nCount = m_arTextLine.size();
for (size_t i = 0; i < nCount; ++i)
{
if (fabs(m_arTextLine[i]->m_dBaselinePos - dBaseLinePos) <= THE_SAME_STRING_Y_PRECISION_MM)
@ -176,14 +171,14 @@ namespace NSDocxRenderer
// лини¤ не нашлась - не беда - создадим новую
m_pCurrentLine = new CTextLine();
m_pCurrentLine->m_dBaselinePos = dBaseLinePos;
m_arTextLine.Add(m_pCurrentLine);
m_arTextLine.push_back(m_pCurrentLine);
return;
}
// image commands
void WriteImage(CImageInfo& oInfo, double& fX, double& fY, double& fWidth, double& fHeight)
{
CImage* pImage = new CImage(oInfo, _T(""));
CImage* pImage = new CImage(oInfo, L"");
double dRotation = m_pTransform->z_Rotation();
@ -228,7 +223,7 @@ namespace NSDocxRenderer
double x2 = fX + fWidth;
double y2 = fY + fHeight;
NSDocxRenderer::CMatrix oTemp = *m_pTransform;
Aggplus::CMatrix oTemp = *m_pTransform;
double dCx = (x1 + x2) / 2;
double dCy = (y1 + y2) / 2;
@ -263,7 +258,7 @@ namespace NSDocxRenderer
pImage->m_dRotate = dRotation;
}
m_arGraphicItems.Add(pImage);
m_arGraphicItems.push_back(pImage);
}
// path commands
@ -310,7 +305,7 @@ namespace NSDocxRenderer
pShape->m_oBrush = *m_pBrush;
// нормализуем толщину линии
double dScaleTransform = (m_pTransform->m_agg_mtx.sx + m_pTransform->m_agg_mtx.sy) / 2.0;
double dScaleTransform = (m_pTransform->sx() + m_pTransform->sy()) / 2.0;
pShape->m_oPen.Size *= dScaleTransform;
if ((lType & 0x01) == 0x00)
@ -330,7 +325,7 @@ namespace NSDocxRenderer
}
}
void WriteText(int* pUnicodes, int* pGids, int nCount, double fX, double fY, double fWidth, double fHeight, double fBaseLineOffset, bool bIsPDFAnalyzer)
void WriteText(unsigned int* pUnicodes, unsigned int* pGids, unsigned int nCount, double fX, double fY, double fWidth, double fHeight, double fBaseLineOffset, bool bIsPDFAnalyzer)
{
double dTextX = fX;
double dTextY = fY;
@ -343,34 +338,25 @@ namespace NSDocxRenderer
double dTextW = dTextR - dTextX;
double dTextH = dTextB - dTextY;
std::wstring strText = L"";
NSStringUtils::CStringUTF32 oText((uint32_t*)pUnicodes, nCount);
if ((pUnicodes != NULL) && (pGids != NULL))
{
for (unsigned int i = 0; i < nCount; ++i)
{
wchar_t c = pUnicodes[i];
if ( IsUnicodeSymbol( c ) )
if ( IsUnicodeSymbol( pUnicodes[i] ) )
{
strText += c;
}
else
{
strText += L" ";
}
oText[i] = ' ';
}
}
}
else
{
strText = (CString)bsText;
}
bool bIsPath = ((NULL == pGids) && !bIsPDFAnalyzer) ? false : true;
m_oManager.LoadFont(0, !bIsPath);
if (bIsPath)
m_oManager.GenerateFontName2(strText);
m_oManager.GenerateFontName2(oText);
if ((0 == dTextW) || (dTextW > 5 * m_oManager.m_dSpaceWidthMM))
{
@ -379,16 +365,16 @@ namespace NSDocxRenderer
double _w = 0;
double _h = 0;
if (NULL != bsGid)
if (NULL != pGids)
{
m_oManager.SetStringGid(1);
m_oManager.MeasureString(bsGid, dTextX, dTextY, _x, _y, _w, _h, CFontManager::MeasureTypePosition);
m_oManager.MeasureStringGids(pGids, nCount, dTextX, dTextY, _x, _y, _w, _h, CFontManager::MeasureTypePosition);
}
else
{
// такого быть не должно (только из xps)
m_oManager.SetStringGid(0);
m_oManager.MeasureString(bsText, dTextX, dTextY, _x, _y, _w, _h, CFontManager::MeasureTypePosition);
m_oManager.MeasureStringGids(pUnicodes, nCount, dTextX, dTextY, _x, _y, _w, _h, CFontManager::MeasureTypePosition);
}
dTextW = _w;
@ -416,7 +402,7 @@ namespace NSDocxRenderer
pCont->m_dWidth = dTextW;
pCont->m_dHeight = dTextH;
if (L" " == strText)
if (IsSpaceUtf32(oText))
{
pCont->m_dWidthWithoutSpaces = 0;
pCont->m_dLeftWithoutSpaces = dTextX + dTextW;
@ -427,7 +413,7 @@ namespace NSDocxRenderer
pCont->m_dLeftWithoutSpaces = dTextX;
}
pCont->m_strText = strText;
pCont->m_oText = oText;
pCont->m_oFont = m_oManager.m_oFont.m_oFont;
pCont->m_oBrush = *m_pBrush;
@ -461,10 +447,10 @@ namespace NSDocxRenderer
if (fabs(dRight - dTextX) < 0.5)
{
// продолжаем слово
pLastCont->m_strText += strText;
pLastCont->m_oText += oText;
pLastCont->m_dWidth = (dTextX + dTextW - pLastCont->m_dX);
if (L" " != strText)
if (!IsSpaceUtf32(oText))
{
if (0 == pLastCont->m_dWidthWithoutSpaces)
pLastCont->m_dLeftWithoutSpaces = dTextX;
@ -481,10 +467,11 @@ namespace NSDocxRenderer
else if ((dRight < dTextX) && ((dTextX - dRight) < m_oManager.m_dSpaceWidthMM))
{
// продолжаем слово с пробелом
pLastCont->m_strText += (L" " + strText);
pLastCont->m_oText += uint32_t(' ');
pLastCont->m_oText += oText;
pLastCont->m_dWidth = (dTextX + dTextW - pLastCont->m_dX);
if (_T(" ") != strText)
if (!IsSpaceUtf32(oText))
{
if (0 == pLastCont->m_dWidthWithoutSpaces)
pLastCont->m_dLeftWithoutSpaces = dTextX;
@ -510,7 +497,7 @@ namespace NSDocxRenderer
pCont->m_dWidth = dTextW;
pCont->m_dHeight = dTextH;
if (L" " == strText)
if (IsSpaceUtf32(oText))
{
pCont->m_dWidthWithoutSpaces = 0;
pCont->m_dLeftWithoutSpaces = dTextX + dTextW;
@ -521,7 +508,7 @@ namespace NSDocxRenderer
pCont->m_dLeftWithoutSpaces = dTextX;
}
pCont->m_strText = strText;
pCont->m_oText = oText;
pCont->m_oFont = m_oManager.m_oFont.m_oFont;
pCont->m_oBrush = *m_pBrush;
@ -654,7 +641,7 @@ namespace NSDocxRenderer
double dBeforeSpacing = (pTextLine->m_dBaselinePos - previousStringOffset - pTextLine->m_dHeight + pTextLine->m_dBaselineOffset);
pParagraph->m_dSpaceBefore = max(dBeforeSpacing, 0);
pParagraph->m_dSpaceBefore = std::max(dBeforeSpacing, 0.0);
double dHeight = 1;
if (pTextLine->m_dHeight != 0)
@ -712,14 +699,14 @@ namespace NSDocxRenderer
size_t nCountDrawings = m_arGraphicItems.size();
if (0 != nCountDrawings)
{
oWriter.WriteString(g_bstr_drawingParStart);
oWriter.WriteString(L"<w:p><w:pPr><w:spacing w:line=\"1\" w:lineRule=\"exact\"/></w:pPr>");
for (size_t i = 0; i < nCountDrawings; ++i)
{
m_arGraphicItems[i]->ToXml(oWriter);
}
oWriter.WriteString(g_bstr_ParEnd);
oWriter.WriteString(L"</w:p>");
}
size_t nCountParagraphs = m_arParagraphs.size();
@ -732,27 +719,26 @@ namespace NSDocxRenderer
void WriteSectionToFile(bool bLastPage, NSStringUtils::CStringBuilder& oWriter)
{
// section
LONG lWidthDx = (LONG)(m_dWidth * c_dMMToDx);
LONG lHeightDx = (LONG)(m_dHeight * c_dMMToDx);
int lWidthDx = (int)(m_dWidth * c_dMMToDx);
int lHeightDx = (int)(m_dHeight * c_dMMToDx);
if (!bLastPage)
oWriter.WriteString(g_bstr_sectStart);
oWriter.WriteString(L"<w:p><w:pPr><w:sectPr>");
else
oWriter.WriteString(g_bstr_lastsection1);
if (lWidthDx >= lHeightDx)
{
oWriter.WriteString(StringFormat(g_string_sectSizeHor, lWidthDx, lHeightDx));
}
else
{
oWriter.WriteString(StringFormat(g_string_sectSizeVer, lWidthDx, lHeightDx));
}
oWriter.WriteString(L"<w:sectPr>");
oWriter.WriteString(L"<w:pgSz w:w=\"");
oWriter.AddInt((int)(m_dWidth * c_dMMToDx));
oWriter.WriteString(L"\" w:h=\"");
oWriter.AddInt((int)(m_dHeight * c_dMMToDx));
oWriter.WriteString(L"\" w:orient=\"");
(lWidthDx >= lHeightDx) ? oWriter.WriteString(L"landscape") : oWriter.WriteString(L"portrait");
oWriter.WriteString(L"\"/>");
if (!bLastPage)
oWriter.WriteString(g_bstr_sectEnd);
oWriter.WriteString(L"<w:pgMar w:top=\"0\" w:right=\"0\" w:bottom=\"0\" w:left=\"0\"/></w:sectPr><w:spacing w:line=\"1\" w:lineRule=\"exact\"/></w:pPr></w:p>");
else
oWriter.WriteString(g_bstr_lastsection2);
oWriter.WriteString(L"<w:pgMar w:top=\"0\" w:right=\"0\" w:bottom=\"0\" w:left=\"0\" w:header=\"0\" w:footer=\"0\" w:gutter=\"0\"/></w:sectPr>");
}
};
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long