Commit 150ff1fa authored by Oleg Korshul's avatar Oleg Korshul

.

parent dd1b9ca9
...@@ -30,11 +30,179 @@ ...@@ -30,11 +30,179 @@
* *
*/ */
#include "src/logic/Document.h"
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)
{
m_pApplicationFonts = pFonts;
}
~CDocxRenderer_Private()
{
}
};
CDocxRenderer::CDocxRenderer(CApplicationFonts* pAppFonts)
{
m_pInternal = new CDocxRenderer_Private(pAppFonts);
}
CDocxRenderer::~CDocxRenderer()
{
RELEASEOBJECT(m_pInternal);
}
void CreateFile(const std::wstring& wsPath);
void Close();
void SetTextAssociationType(const NSDocxRenderer::TextAssociationType& eType);
void SetTempFolder(const std::wstring& wsPath);
//----------------------------------------------------------------------------------------
// Тип рендерера
//----------------------------------------------------------------------------------------
virtual HRESULT get_Type(LONG* lType);
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
// // Функции для работы со страницей
// CDocxRenderer //----------------------------------------------------------------------------------------
// virtual HRESULT NewPage();
virtual HRESULT get_Height(double* dHeight);
virtual HRESULT put_Height(const double& dHeight);
virtual HRESULT get_Width(double* dWidth);
virtual HRESULT put_Width(const double& dWidth);
virtual HRESULT get_DpiX(double* dDpiX);
virtual HRESULT get_DpiY(double* dDpiY);
//----------------------------------------------------------------------------------------
// Функции для работы с Pen
//----------------------------------------------------------------------------------------
virtual HRESULT get_PenColor(LONG* lColor);
virtual HRESULT put_PenColor(const LONG& lColor);
virtual HRESULT get_PenAlpha(LONG* lAlpha);
virtual HRESULT put_PenAlpha(const LONG& lAlpha);
virtual HRESULT get_PenSize(double* dSize);
virtual HRESULT put_PenSize(const double& dSize);
virtual HRESULT get_PenDashStyle(BYTE* nDashStyle);
virtual HRESULT put_PenDashStyle(const BYTE& nDashStyle);
virtual HRESULT get_PenLineStartCap(BYTE* nCapStyle);
virtual HRESULT put_PenLineStartCap(const BYTE& nCapStyle);
virtual HRESULT get_PenLineEndCap(BYTE* nCapStyle);
virtual HRESULT put_PenLineEndCap(const BYTE& nCapStyle);
virtual HRESULT get_PenLineJoin(BYTE* nJoinStyle);
virtual HRESULT put_PenLineJoin(const BYTE& nJoinStyle);
virtual HRESULT get_PenDashOffset(double* dOffset);
virtual HRESULT put_PenDashOffset(const double& dOffset);
virtual HRESULT get_PenAlign(LONG* lAlign);
virtual HRESULT put_PenAlign(const LONG& lAlign);
virtual HRESULT get_PenMiterLimit(double* dMiter);
virtual HRESULT put_PenMiterLimit(const double& dMiter);
virtual HRESULT PenDashPattern(double* pPattern, LONG lCount);
//----------------------------------------------------------------------------------------
// Функции для работы с Brush
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
virtual HRESULT get_BrushType(LONG* lType);
virtual HRESULT put_BrushType(const LONG& lType);
virtual HRESULT get_BrushColor1(LONG* lColor);
virtual HRESULT put_BrushColor1(const LONG& lColor);
virtual HRESULT get_BrushAlpha1(LONG* lAlpha);
virtual HRESULT put_BrushAlpha1(const LONG& lAlpha);
virtual HRESULT get_BrushColor2(LONG* lColor);
virtual HRESULT put_BrushColor2(const LONG& lColor);
virtual HRESULT get_BrushAlpha2(LONG* lAlpha);
virtual HRESULT put_BrushAlpha2(const LONG& lAlpha);
virtual HRESULT get_BrushTexturePath(std::wstring* wsPath);
virtual HRESULT put_BrushTexturePath(const std::wstring& wsPath);
virtual HRESULT get_BrushTextureMode(LONG* lMode);
virtual HRESULT put_BrushTextureMode(const LONG& lMode);
virtual HRESULT get_BrushTextureAlpha(LONG* lAlpha);
virtual HRESULT put_BrushTextureAlpha(const LONG& lAlpha);
virtual HRESULT get_BrushLinearAngle(double* dAngle);
virtual HRESULT put_BrushLinearAngle(const double& dAngle);
virtual HRESULT BrushRect(const INT& nVal, const double& dLeft, const double& dTop, const double& dWidth, const double& dHeight);
virtual HRESULT BrushBounds(const double& dLeft, const double& dTop, const double& dWidth, const double& dHeight);
virtual HRESULT put_BrushGradientColors(LONG* pColors, double* pPositions, LONG lCount);
//----------------------------------------------------------------------------------------
// Функции для работы со шрифтами
//----------------------------------------------------------------------------------------
virtual HRESULT get_FontName(std::wstring* wsName);
virtual HRESULT put_FontName(const std::wstring& wsName);
virtual HRESULT get_FontPath(std::wstring* wsPath);
virtual HRESULT put_FontPath(const std::wstring& wsPath);
virtual HRESULT get_FontSize(double* dSize);
virtual HRESULT put_FontSize(const double& dSize);
virtual HRESULT get_FontStyle(LONG* lStyle);
virtual HRESULT put_FontStyle(const LONG& lStyle);
virtual HRESULT get_FontStringGID(INT* bGid);
virtual HRESULT put_FontStringGID(const INT& bGid);
virtual HRESULT get_FontCharSpace(double* dSpace);
virtual HRESULT put_FontCharSpace(const double& dSpace);
virtual HRESULT get_FontFaceIndex(int* lFaceIndex);
virtual HRESULT put_FontFaceIndex(const int& lFaceIndex);
//----------------------------------------------------------------------------------------
// Функции для вывода текста
//----------------------------------------------------------------------------------------
virtual HRESULT CommandDrawTextCHAR (const LONG& lUnicode, const double& dX, const double& dY, const double& dW, const double& dH);
virtual HRESULT CommandDrawTextExCHAR(const LONG& lUnicode, const LONG& lGid, const double& dX, const double& dY, const double& dW, const double& dH);
virtual HRESULT CommandDrawText (const std::wstring& wsUnicodeText, const double& dX, const double& dY, const double& dW, const double& dH);
virtual HRESULT CommandDrawTextEx (const std::wstring& wsUnicodeText, const unsigned int* pGids, const unsigned int nGidsCount, const double& dX, const double& dY, const double& dW, const double& dH);
//----------------------------------------------------------------------------------------
// Маркеры команд
//----------------------------------------------------------------------------------------
virtual HRESULT BeginCommand(const DWORD& lType);
virtual HRESULT EndCommand(const DWORD& lType);
//----------------------------------------------------------------------------------------
// Функции для работы с патом
//----------------------------------------------------------------------------------------
virtual HRESULT PathCommandMoveTo(const double& dX, const double& dY);
virtual HRESULT PathCommandLineTo(const double& dX, const double& dY);
virtual HRESULT PathCommandLinesTo(double* pPoints, const int& nCount);
virtual HRESULT PathCommandCurveTo(const double& dX1, const double& dY1, const double& dX2, const double& dY2, const double& dXe, const double& dYe);
virtual HRESULT PathCommandCurvesTo(double* pPoints, const int& nCount);
virtual HRESULT PathCommandArcTo(const double& dX, const double& dY, const double& dW, const double& dH, const double& dStartAngle, const double& dSweepAngle);
virtual HRESULT PathCommandClose();
virtual HRESULT PathCommandEnd();
virtual HRESULT DrawPath(const LONG& lType);
virtual HRESULT PathCommandStart();
virtual HRESULT PathCommandGetCurrentPoint(double* dX, double* dY);
virtual HRESULT PathCommandTextCHAR (const LONG& lUnicode, const double& dX, const double& dY, const double& dW, const double& dH);
virtual HRESULT PathCommandTextExCHAR(const LONG& lUnicode, const LONG& lGid, const double& dX, const double& dY, const double& dW, const double& dH);
virtual HRESULT PathCommandText (const std::wstring& wsUnicodeText, const double& dX, const double& dY, const double& dW, const double& dH);
virtual HRESULT PathCommandTextEx (const std::wstring& wsUnicodeText, const unsigned int* pGids, const unsigned int nGidsCount, const double& dX, const double& dY, const double& dW, const double& dH);
//----------------------------------------------------------------------------------------
// Функции для вывода изображений
//----------------------------------------------------------------------------------------
virtual HRESULT DrawImage(IGrObject* pImage, const double& dX, const double& dY, const double& dW, const double& dH);
virtual HRESULT DrawImageFromFile(const std::wstring& wsImagePath, const double& dX, const double& dY, const double& dW, const double& dH, const BYTE& nAlpha = 255);
//----------------------------------------------------------------------------------------
// Функции для выставления преобразования
//----------------------------------------------------------------------------------------
virtual HRESULT SetTransform(const double& dM11, const double& dM12, const double& dM21, const double& dM22, const double& dX, const double& dY);
virtual HRESULT GetTransform(double* dM11, double* dM12, double* dM21, double* dM22, double* dX, double* dY);
virtual HRESULT ResetTransform();
//----------------------------------------------------------------------------------------
// Тип клипа
//----------------------------------------------------------------------------------------
virtual HRESULT get_ClipMode(LONG* lMode);
virtual HRESULT put_ClipMode(const LONG& lMode);
//----------------------------------------------------------------------------------------
// Дополнительные функции
//----------------------------------------------------------------------------------------
virtual HRESULT CommandLong(const LONG& lType, const LONG& lCommand);
virtual HRESULT CommandDouble(const LONG& lType, const double& dCommand);
virtual HRESULT CommandString(const LONG& lType, const std::wstring& sCommand);
CPdfRenderer::CPdfRenderer(CApplicationFonts* pAppFonts) : m_oCommandManager(this) CPdfRenderer::CPdfRenderer(CApplicationFonts* pAppFonts) : m_oCommandManager(this)
{ {
m_pAppFonts = pAppFonts; m_pAppFonts = pAppFonts;
......
#pragma once #ifndef DOCX_RENDERER_COMMON_H
#define DOCX_RENDERER_COMMON_H
#ifndef AVSINLINE
#if defined(_MSC_VER) #include "../DesktopEditor/common/StringBuilder.h"
#define AVSINLINE __forceinline #include "../DesktopEditor/common/CalculatorCRC32.h"
#else #include "../DesktopEditor/graphics/Matrix.h"
#define AVSINLINE inline #include "../DesktopEditor/graphics/structures.h"
#endif #include "../DesktopEditor/graphics/TemporaryCS.h"
#endif #include "../DesktopEditor/raster/BgraFrame.h"
#include "../DesktopEditor/common/Directory.h"
#include "../../Common/TemporaryCS.h"
#include "../Graphics/Matrix.h" #include <map>
#include "../Graphics/Structures.h"
#include "StringWriter.h"
#include "CalculatorCRC32.h"
namespace NSDocxRenderer namespace NSDocxRenderer
{ {
AVSINLINE LONG ConvertColor(LONG lBGR) inline LONG ConvertColor(LONG lBGR)
{ {
return (0x00FFFFFF & (((lBGR & 0xFF) << 16) | (lBGR & 0x0000FF00) | ((lBGR >> 16) & 0xFF))); return (0x00FFFFFF & (((lBGR & 0xFF) << 16) | (lBGR & 0x0000FF00) | ((lBGR >> 16) & 0xFF)));
} }
AVSINLINE void CorrectString(CString& strValue)
{
strValue.Replace(_T("&"), _T("&amp;"));
strValue.Replace(_T("'"), _T("&apos;"));
strValue.Replace(_T("<"), _T("&lt;"));
strValue.Replace(_T(">"), _T("&gt;"));
strValue.Replace(_T("\""), _T("&quot;"));
}
class CBaseItem class CBaseItem
{ {
...@@ -47,299 +35,171 @@ namespace NSDocxRenderer ...@@ -47,299 +35,171 @@ namespace NSDocxRenderer
m_eType = etShape; m_eType = etShape;
} }
virtual void ToXml(NSDocxRenderer::CStringWriter& oWriter) = 0; virtual void ToXml(NSStringUtils::CStringBuilder& oWriter) = 0;
}; };
class CImageInfo
{
public:
enum ImageType
{
itPNG = 0,
itJPG = 1
};
public:
ImageType m_eType;
int m_nId;
CImageInfo()
{
m_eType = itPNG;
m_nId = 0;
}
};
class CImageManager class CImageManager
{ {
public: public:
CAtlMap<CString, CImageInfo> m_mapImagesFile; std::map<std::wstring, CImageInfo> m_mapImagesFile;
CAtlMap<DWORD, CImageInfo> m_mapImageData; std::map<DWORD, CImageInfo> m_mapImageData;
CString m_strDstMedia; std::wstring m_strDstMedia;
LONG m_lMaxSizeImage; int m_lMaxSizeImage;
LONG m_lNextIDImage; int m_lNextIDImage;
CCalculatorCRC32 m_oCRC; CCalculatorCRC32 m_oCRC;
public: public:
CImageManager() CImageManager()
{ {
m_strDstMedia = _T(""); m_strDstMedia = L"";
m_lMaxSizeImage = 800; m_lMaxSizeImage = 1200;
m_lNextIDImage = 0; m_lNextIDImage = 0;
} }
AVSINLINE void NewDocument() inline void NewDocument()
{ {
m_strDstMedia = _T(""); m_strDstMedia = L"";
m_lMaxSizeImage = 800; m_lMaxSizeImage = 1200;
m_lNextIDImage = 0; m_lNextIDImage = 0;
m_mapImageData.RemoveAll(); m_mapImageData.clear();
m_mapImagesFile.RemoveAll(); m_mapImagesFile.clear();
} }
public: public:
CImageInfo WriteImage(IUnknown* punkImage, double& x, double& y, double& width, double& height) CImageInfo WriteImage(CBgraFrame* pImage, double& x, double& y, double& width, double& height)
{ {
if (height < 0) if (height < 0)
{ {
FlipY(punkImage); FlipY(pImage);
height = -height; height = -height;
y -= height; y -= height;
} }
return GenerateImageID(punkImage); return GenerateImageID(pImage);
} }
CImageInfo WriteImage(CString& strFile, double& x, double& y, double& width, double& height) CImageInfo WriteImage(std::wstring& strFile, double& x, double& y, double& width, double& height)
{ {
return GenerateImageID(strFile); return GenerateImageID(strFile);
} }
protected: protected:
inline void CopyFile(CString& strFileSrc, CString& strFileDst) inline void CopyFile(std::wstring& strFileSrc, std::wstring& strFileDst)
{ {
CDirectory::CopyFile(strFileSrc, strFileDst, NULL, NULL); NSFile::CFileBinary::Copy(strFileSrc, strFileDst);
} }
void SaveImage(CString& strFileSrc, CImageInfo& oInfo) void SaveImage(std::wstring& strFileSrc, CImageInfo& oInfo)
{ {
CString strLoadXml = _T("<transforms><ImageFile-LoadImage sourcepath=\"") + strFileSrc + _T("\"/></transforms>"); CBgraFrame oFrame;
if (oFrame.OpenFile(strFileSrc))
ImageStudio::IImageTransforms* pTransform = NULL; return SaveImage(&oFrame, oInfo);
CoCreateInstance(ImageStudio::CLSID_ImageTransforms, NULL, CLSCTX_INPROC_SERVER, ImageStudio::IID_IImageTransforms, (void**)&pTransform);
VARIANT_BOOL vbRes = VARIANT_FALSE;
BSTR bsLoad = strLoadXml.AllocSysString();
pTransform->SetXml(bsLoad, &vbRes);
SysFreeString(bsLoad);
pTransform->Transform(&vbRes);
VARIANT var;
var.punkVal = NULL;
pTransform->GetResult(0, &var);
if (NULL == var.punkVal)
{
RELEASEINTERFACE(pTransform);
return;
}
MediaCore::IAVSUncompressedVideoFrame* pFrame = NULL;
var.punkVal->QueryInterface(MediaCore::IID_IAVSUncompressedVideoFrame, (void**)&pFrame);
RELEASEINTERFACE((var.punkVal));
if (NULL == pFrame)
{
RELEASEINTERFACE(pTransform);
return;
}
LONG lWidth = 0;
LONG lHeight = 0;
pFrame->get_Width(&lWidth);
pFrame->get_Height(&lHeight);
oInfo.m_eType = GetImageType(pFrame);
RELEASEINTERFACE(pFrame);
CString strSaveItem = _T("");
strSaveItem.Format(_T("\\image%d."), oInfo.m_lID);
if (itJPG == oInfo.m_eType)
{
strSaveItem = _T("<ImageFile-SaveAsJpeg destinationpath=\"") + m_strDstMedia + strSaveItem + _T("jpg\" format=\"888\"/>");
}
else
{
strSaveItem = _T("<ImageFile-SaveAsPng destinationpath=\"") + m_strDstMedia + strSaveItem + _T("png\" format=\"888\"/>");
}
CString strXml = _T("");
if ((lWidth <= m_lMaxSizeImage) && (lHeight <= m_lMaxSizeImage))
{
strXml = _T("<transforms>") + strSaveItem + _T("</transforms>");
}
else
{
LONG lW = 0;
LONG lH = 0;
double dAspect = (double)lWidth / lHeight;
if (lWidth >= lHeight)
{
lW = m_lMaxSizeImage;
lH = (LONG)((double)lW / dAspect);
}
else
{
lH = m_lMaxSizeImage;
lW = (LONG)(dAspect * lH);
}
CString strResize = _T("");
strResize.Format(_T("<ImageTransform-TransformResize width=\"%d\" height=\"%d\"/>"), lW, lH);
strXml = _T("<transforms>") + strResize + strSaveItem + _T("</transforms>");
}
VARIANT_BOOL vbSuccess = VARIANT_FALSE;
BSTR bsXml = strXml.AllocSysString();
pTransform->SetXml(bsXml, &vbSuccess);
SysFreeString(bsXml);
pTransform->Transform(&vbSuccess);
RELEASEINTERFACE(pTransform);
} }
void SaveImage(IUnknown* punkImage, CImageInfo& oInfo) void SaveImage(CBgraFrame* pImage, CImageInfo& oInfo)
{ {
MediaCore::IAVSUncompressedVideoFrame* pFrame = NULL; if (NULL == pImage)
punkImage->QueryInterface(MediaCore::IID_IAVSUncompressedVideoFrame, (void**)&pFrame);
if (NULL == pFrame)
return; return;
LONG lWidth = 0; int w = pImage->get_Width();
LONG lHeight = 0; int h = pImage->get_Height();
pFrame->get_Width(&lWidth);
pFrame->get_Height(&lHeight); oInfo.m_eType = GetImageType(pImage);
oInfo.m_eType = GetImageType(pFrame); int format = (oInfo.m_eType == CImageInfo::itJPG) ? 3 : 4;
std::wstring sSavedFile = m_strDstMedia + L"/image" + std::to_wstring(oInfo.m_nId);
RELEASEINTERFACE(pFrame); sSavedFile += ((oInfo.m_eType == CImageInfo::itJPG) ? L".jpg" : L".png");
ImageStudio::IImageTransforms* pTransform = NULL; if (w <= m_lMaxSizeImage && h <= m_lMaxSizeImage)
CoCreateInstance(ImageStudio::CLSID_ImageTransforms, NULL ,CLSCTX_INPROC_SERVER, ImageStudio::IID_IImageTransforms, (void**)&pTransform); {
pImage->SaveFile(sSavedFile, format);
VARIANT var; }
var.vt = VT_UNKNOWN; else
var.punkVal = punkImage; {
pTransform->SetSource(0, var); int lW = 0;
int lH = 0;
CString strSaveItem = _T(""); double dAspect = (double)w / h;
strSaveItem.Format(_T("\\image%d."), oInfo.m_lID);
if (itJPG == oInfo.m_eType) if (w >= h)
{ {
strSaveItem = _T("<ImageFile-SaveAsJpeg destinationpath=\"") + m_strDstMedia + strSaveItem + _T("jpg\" format=\"888\"/>"); lW = m_lMaxSizeImage;
} lH = (int)((double)lW / dAspect);
else }
{ else
strSaveItem = _T("<ImageFile-SaveAsPng destinationpath=\"") + m_strDstMedia + strSaveItem + _T("png\" format=\"888\"/>"); {
} lH = m_lMaxSizeImage;
lW = (LONG)(dAspect * lH);
CString strXml = _T(""); }
if ((lWidth <= m_lMaxSizeImage) && (lHeight <= m_lMaxSizeImage))
{ // TODO: resize
strXml = _T("<transforms>") + strSaveItem + _T("</transforms>"); pImage->SaveFile(sSavedFile, format);
} }
else
{
LONG lW = 0;
LONG lH = 0;
double dAspect = (double)lWidth / lHeight;
if (lWidth >= lHeight)
{
lW = m_lMaxSizeImage;
lH = (LONG)((double)lW / dAspect);
}
else
{
lH = m_lMaxSizeImage;
lW = (LONG)(dAspect * lH);
}
CString strResize = _T("");
strResize.Format(_T("<ImageTransform-TransformResize width=\"%d\" height=\"%d\"/>"), lW, lH);
strXml = _T("<transforms>") + strResize + strSaveItem + _T("</transforms>");
}
VARIANT_BOOL vbSuccess = VARIANT_FALSE;
BSTR bsXml = strXml.AllocSysString();
pTransform->SetXml(bsXml, &vbSuccess);
SysFreeString(bsXml);
pTransform->Transform(&vbSuccess);
RELEASEINTERFACE(pTransform);
} }
CImageInfo GenerateImageID(IUnknown* punkData) CImageInfo GenerateImageID(CBgraFrame* pImage)
{ {
CImageInfo oInfo; BYTE* pData = pImage->get_Data();
int nSize = pImage->get_Stride() * pImage->get_Height();
if (NULL == punkData) if (nSize < 0)
return oInfo; nSize = -nSize;
MediaCore::IAVSUncompressedVideoFrame* pFrame = NULL;
punkData->QueryInterface(MediaCore::IID_IAVSUncompressedVideoFrame, (void**)&pFrame);
BYTE* pBuffer = NULL;
LONG lLen = 0;
pFrame->get_Buffer(&pBuffer); DWORD dwSum = m_oCRC.Calc(pData, nSize);
pFrame->get_BufferSize(&lLen);
DWORD dwSum = m_oCRC.Calc(pBuffer, lLen); std::map<DWORD, CImageInfo>::iterator find = m_mapImageData.find(dwSum);
if (find != m_mapImageData.end())
CAtlMap<DWORD, CImageInfo>::CPair* pPair = m_mapImageData.Lookup(dwSum); return *find;
if (NULL == pPair)
{
//
++m_lNextIDImage;
oInfo.m_lID = m_lNextIDImage;
SaveImage(punkData, oInfo);
m_mapImageData.SetAt(dwSum, oInfo);
}
else
{
oInfo = pPair->m_value;
}
RELEASEINTERFACE(pFrame); ++m_lNextIDImage;
CImageInfo oInfo;
oInfo.m_lID = m_lNextIDImage;
SaveImage(pImage, oInfo);
m_mapImageData.insert(std::pair<std::DWORD, CImageInfo>(dwSum, oInfo);
return oInfo; return oInfo;
} }
CImageInfo GenerateImageID(CString& strFileName) CImageInfo GenerateImageID(std::wstring& strFileName)
{ {
CImageInfo oInfo; std::map<std::wstring, CImageInfo>::iterator find = m_mapImagesFile.find(strFileName);
CAtlMap<CString, CImageInfo>::CPair* pPair = m_mapImagesFile.Lookup(strFileName); if (find != m_mapImagesFile.end())
return *find;
if (NULL == pPair) ++m_lNextIDImage;
{ CImageInfo oInfo;
// oInfo.m_lID = m_lNextIDImage;
++m_lNextIDImage; SaveImage(strFileName, oInfo);
m_mapImagesFile.insert(std::pair<std::wstring, CImageInfo>(strFileName, oInfo);
oInfo.m_lID = m_lNextIDImage;
SaveImage(strFileName, oInfo);
m_mapImagesFile.SetAt(strFileName, oInfo);
}
else
{
oInfo = pPair->m_value;
}
return oInfo; return oInfo;
} }
ImageType GetImageType(MediaCore::IAVSUncompressedVideoFrame* pFrame) CImageInfo::ImageType GetImageType(CBgraFrame* pFrame)
{ {
LONG lWidth = 0; int w = pFrame->get_Width();
LONG lHeight = 0; int h = pFrame->get_Height();
BYTE* pBuffer = NULL; BYTE* pBuffer = pFrame->get_Data();
pFrame->get_Width(&lWidth);
pFrame->get_Height(&lHeight);
pFrame->get_Buffer(&pBuffer);
BYTE* pBufferMem = pBuffer + 3; BYTE* pBufferMem = pBuffer + 3;
LONG lCountPix = lWidth * lHeight; LONG lCountPix = lWidth * lHeight;
...@@ -347,95 +207,66 @@ namespace NSDocxRenderer ...@@ -347,95 +207,66 @@ namespace NSDocxRenderer
for (LONG i = 0; i < lCountPix; ++i, pBufferMem += 4) for (LONG i = 0; i < lCountPix; ++i, pBufferMem += 4)
{ {
if (255 != *pBufferMem) if (255 != *pBufferMem)
return itPNG; return CImageInfo::itPNG;
} }
return itJPG; return CImageInfo::itJPG;
} }
void FlipY(IUnknown* punkImage) void FlipY(CBgraFrame* pImage)
{ {
if (NULL == punkImage) if (NULL == pImage)
return; return;
MediaCore::IAVSUncompressedVideoFrame* pFrame = NULL; int w = pImage->get_Width();
punkImage->QueryInterface(MediaCore::IID_IAVSUncompressedVideoFrame, (void**)&pFrame); int h = pImage->get_Height();
BYTE* pBuffer = pImage->get_Data();
if (NULL == pFrame) int stride = pImage->get_Stride();
return;
BYTE* pBuffer = NULL; if (stride < 0)
LONG lWidth = 0; stride = -stride;
LONG lHeight = 0;
LONG lStride = 0;
pFrame->get_Buffer(&pBuffer);
pFrame->get_Width(&lWidth);
pFrame->get_Height(&lHeight);
pFrame->get_Stride(0, &lStride);
if (lStride < 0)
lStride = -lStride;
if ((lWidth * 4) != lStride) if ((w * 4) != stride)
{
RELEASEINTERFACE(pFrame);
return; return;
}
BYTE* pBufferMem = new BYTE[lStride]; BYTE* pBufferMem = new BYTE[stride];
BYTE* pBufferEnd = pBuffer + lStride * (lHeight - 1); BYTE* pBufferEnd = pBuffer + stride * (h - 1);
LONG lCountV = lHeight / 2; LONG lCountV = h / 2;
for (LONG lIndexV = 0; lIndexV < lCountV; ++lIndexV) for (LONG lIndexV = 0; lIndexV < lCountV; ++lIndexV)
{ {
memcpy(pBufferMem, pBuffer, lStride); memcpy(pBufferMem, pBuffer, stride);
memcpy(pBuffer, pBufferEnd, lStride); memcpy(pBuffer, pBufferEnd, stride);
memcpy(pBufferEnd, pBufferMem, lStride); memcpy(pBufferEnd, pBufferMem, stride);
pBuffer += lStride; pBuffer += stride;
pBufferEnd -= lStride; pBufferEnd -= stride;
} }
RELEASEARRAYOBJECTS(pBufferMem); RELEASEARRAYOBJECTS(pBufferMem);
RELEASEINTERFACE(pFrame);
} }
void FlipX(IUnknown* punkImage) void FlipX(CBgraFrame* pImage)
{ {
if (NULL == punkImage) if (NULL == pImage)
return;
MediaCore::IAVSUncompressedVideoFrame* pFrame = NULL;
punkImage->QueryInterface(MediaCore::IID_IAVSUncompressedVideoFrame, (void**)&pFrame);
if (NULL == pFrame)
return; return;
BYTE* pBuffer = NULL; int w = pImage->get_Width();
LONG lWidth = 0; int h = pImage->get_Height();
LONG lHeight = 0; BYTE* pBuffer = pImage->get_Data();
LONG lStride = 0; int stride = pImage->get_Stride();
pFrame->get_Buffer(&pBuffer); if (stride < 0)
pFrame->get_Width(&lWidth); stride = -stride;
pFrame->get_Height(&lHeight);
pFrame->get_Stride(0, &lStride);
if (lStride < 0) if ((w * 4) != stride)
lStride = -lStride; return;
if ((lWidth * 4) != lStride)
{
RELEASEINTERFACE(pFrame);
return;
}
DWORD* pBufferDWORD = (DWORD*)pBuffer; DWORD* pBufferDWORD = (DWORD*)pBuffer;
LONG lW2 = lWidth / 2; LONG lW2 = w / 2;
for (LONG lIndexV = 0; lIndexV < lHeight; ++lIndexV) for (LONG lIndexV = 0; lIndexV < h; ++lIndexV)
{ {
DWORD* pMem1 = pBufferDWORD; DWORD* pMem1 = pBufferDWORD;
DWORD* pMem2 = pBufferDWORD + lWidth - 1; DWORD* pMem2 = pBufferDWORD + lWidth - 1;
...@@ -447,9 +278,7 @@ namespace NSDocxRenderer ...@@ -447,9 +278,7 @@ namespace NSDocxRenderer
*pMem1++ = *pMem2; *pMem1++ = *pMem2;
*pMem2-- = dwMem; *pMem2-- = dwMem;
} }
} }
RELEASEINTERFACE(pFrame);
} }
}; };
...@@ -470,49 +299,6 @@ namespace NSDocxRenderer ...@@ -470,49 +299,6 @@ namespace NSDocxRenderer
{ {
return ( ( i & 0xff ) << 24 ) + ( ( i & 0xff00 ) << 8 ) + ( ( i & 0xff0000 ) >> 8 ) + ( ( i >> 24 ) & 0xff ); return ( ( i & 0xff ) << 24 ) + ( ( i & 0xff00 ) << 8 ) + ( ( i & 0xff0000 ) >> 8 ) + ( ( i >> 24 ) & 0xff );
} }
}
AVSINLINE CString ToHexString( unsigned int ui ) #endif // DOCX_RENDERER_COMMON_H
{
CString strRes = _T("");
strRes.Format(_T("%08X"), ui);
return strRes;
}
/*========================================================================================================*/
AVSINLINE CString ToHexString( short s )
{
CString strRes = _T("");
strRes.Format(_T("%04X"), s);
return strRes;
}
/*========================================================================================================*/
AVSINLINE CString ToHexString( unsigned short us )
{
CString strRes = _T("");
strRes.Format(_T("%04X"), us);
return strRes;
}
/*========================================================================================================*/
AVSINLINE CString ToHexString( char c )
{
CString strRes = _T("");
strRes.Format(_T("%02X"), c);
return strRes;
}
/*========================================================================================================*/
AVSINLINE CString ToHexString( BYTE uc )
{
CString strRes = _T("");
strRes.Format(_T("%02X"), uc);
return strRes;
}
/*========================================================================================================*/
}
\ No newline at end of file
#pragma once #ifndef DOCX_RENDERER_ELEMENT_IMAGE_H
#define DOCX_RENDERER_ELEMENT_IMAGE_H
#include "Common.h" #include "Common.h"
namespace NSDocxRenderer namespace NSDocxRenderer
{ {
static _bstr_t g_bstr_image_1 = L"<w:r><w:pict><v:shape id=\"\" type=\"\" style=\"position:absolute;"; class CImage : public CBaseItem
static _bstr_t g_bstr_image_2 = L"z-index:-1;mso-position-horizontal-relative:page;mso-position-vertical-relative:page\" filled=\"f\">";
static _bstr_t g_bstr_image_3 = L"</v:shape></w:pict></w:r>";
static CString g_string_image_position = _T("margin-left:%.2lfmm;margin-top:%.2lfmm;width:%.2lfmm;height:%.2lfmm;");
static CString g_string_image_position_rotate = _T("margin-left:%.2lfmm;margin-top:%.2lfmm;width:%.2lfmm;height:%.2lfmm;rotation:%d;");
static CString g_string_image_rid = _T("<v:imagedata r:id=\"rId%d\" o:title=\"\"/>");
class CImage : public CBaseItem
{ {
public: public:
CString m_strPath; std::wstring m_strPath;
LONG m_lID; int m_lID;
double m_dLeft; double m_dLeft;
double m_dTop; double m_dTop;
...@@ -28,18 +22,18 @@ namespace NSDocxRenderer ...@@ -28,18 +22,18 @@ namespace NSDocxRenderer
CImage() CImage()
{ {
m_eType = etImage; m_eType = etImage;
m_strPath = _T(""); m_strPath = L"";
m_lID = -1; m_lID = -1;
} }
CImage(const CImage& oSrc) CImage(const CImage& oSrc)
{ {
*this = oSrc; *this = oSrc;
} }
CImage(const CImageInfo& oInfo, const CString& strDstMedia) CImage(const CImageInfo& oInfo, const std::wstring& strDstMedia)
{ {
m_eType = etImage; m_eType = etImage;
m_strPath = strDstMedia; m_strPath = strDstMedia;
m_lID = oInfo.m_lID; m_lID = oInfo.m_nId;
} }
CImage& operator=(const CImage& oSrc) CImage& operator=(const CImage& oSrc)
{ {
...@@ -57,31 +51,36 @@ namespace NSDocxRenderer ...@@ -57,31 +51,36 @@ namespace NSDocxRenderer
return *this; return *this;
} }
virtual void ToXml(NSDocxRenderer::CStringWriter& oWriter) virtual void ToXml(NSStringUtils::CStringBuilder& oWriter)
{ {
oWriter.WriteString(g_bstr_image_1); oWriter.WriteString(L"<w:r><w:pict><v:shape id=\"\" type=\"\" style=\"position:absolute;");
if (0.0 == m_dRotate) oWriter.WriteString(L"margin-left:");
{ oWriter.AddDouble(m_dLeft, 2);
CString strPosition = _T(""); oWriter.WriteString(L"mm;margin-top:");
strPosition.Format(g_string_image_position, m_dLeft, m_dTop, m_dWidth, m_dHeight); oWriter.AddDouble(m_dTop, 2);
oWriter.WriteString(strPosition); oWriter.WriteString(L"mm;width:");
} oWriter.AddDouble(m_dWidth, 2);
else oWriter.WriteString(L"mm;height:");
oWriter.AddDouble(m_dHeight, 2);
oWriter.WriteString(L"mm;");
if (fabs(m_dRotate) > 0.01)
{ {
CString strPosition = _T(""); oWriter.WriteString(L"rotation:");
strPosition.Format(g_string_image_position_rotate, m_dLeft, m_dTop, m_dWidth, m_dHeight, (int)m_dRotate); oWriter.AddInt((int)m_dRotate);
oWriter.WriteString(strPosition); oWriter.AddCharSafe(';');
} }
oWriter.WriteString(g_bstr_image_2); oWriter.WriteString(L"z-index:-1;mso-position-horizontal-relative:page;mso-position-vertical-relative:page\" filled=\"f\">");
CString strRid = _T(""); oWriter.WriteString(L"<v:imagedata r:id=\"rId");
strRid.Format(g_string_image_rid, 10 + m_lID); oWriter.AddInt(10 + m_lID);
oWriter.WriteString(L"\" o:title=\"\"/>");
oWriter.WriteString(strRid); oWriter.WriteString(L"</v:shape></w:pict></w:r>");
oWriter.WriteString(g_bstr_image_3);
} }
}; };
} }
\ No newline at end of file
#endif // DOCX_RENDERER_ELEMENT_IMAGE_H
#pragma once #pragma once
#include "Common.h" #include "Common.h"
//#include "../../Common/DocxFormat/Source/DocxFormat/Logic/Paragraph.h"
#include "FontManager.h" #include "FontManager.h"
namespace NSDocxRenderer namespace NSDocxRenderer
...@@ -10,7 +9,7 @@ namespace NSDocxRenderer ...@@ -10,7 +9,7 @@ namespace NSDocxRenderer
// T IsBigger, IsBiggerOrEqual // T IsBigger, IsBiggerOrEqual
template<typename T> template<typename T>
void SortElements(CAtlArray<T*>& oArray) void SortElements(CArray<T*>& oArray)
{ {
int nSize = (int)oArray.GetCount(); int nSize = (int)oArray.GetCount();
...@@ -111,7 +110,7 @@ namespace NSDocxRenderer ...@@ -111,7 +110,7 @@ namespace NSDocxRenderer
static CString g_string_par_props_mode2 = _T("<w:pPr><w:framePr w:hAnchor=\"page\" w:vAnchor=\"page\" w:x=\"%d\" w:y=\"%d\"/></w:pPr>"); static CString g_string_par_props_mode2 = _T("<w:pPr><w:framePr w:hAnchor=\"page\" w:vAnchor=\"page\" w:x=\"%d\" w:y=\"%d\"/></w:pPr>");
AVSINLINE void DeleteSpaces(CString& strText) inline void DeleteSpaces(CString& strText)
{ {
int nLen = strText.GetLength(); int nLen = strText.GetLength();
int nStart = 0; int nStart = 0;
...@@ -666,4 +665,4 @@ namespace NSDocxRenderer ...@@ -666,4 +665,4 @@ namespace NSDocxRenderer
oWriter.WriteString(g_bstr_text_par_end); oWriter.WriteString(g_bstr_text_par_end);
} }
}; };
} }
\ No newline at end of file
#pragma once #ifndef DOCX_RENDERER_ELEMENT_SHAPE_H
#define DOCX_RENDERER_ELEMENT_SHAPE_H
#include "Common.h" #include "Common.h"
namespace NSDocxRenderer namespace NSDocxRenderer
{ {
static _bstr_t g_vml_bstr_ClosePath = L"x";
static _bstr_t g_vml_bstr_EndPath = L"e";
static _bstr_t g_vml_bstr_NoFill = L"nf";
static _bstr_t g_vml_bstr_NoStroke = L"ns";
static CString g_vml_string_MoveTo = _T("m%d,%d");
static CString g_vml_string_LineTo = _T("l%d,%d");
static CString g_vml_string_CurveTo = _T("c%d,%d %d,%d %d,%d");
static _bstr_t g_bstr_shape1 = L"<w:r><w:pict><v:shape id=\"\" o:spid=\"\" style=\"position:absolute;";
static _bstr_t g_bstr_shape2 = L"z-index:-1;mso-position-horizontal-relative:page;mso-position-vertical-relative:page;\"";
static CString g_string_shape_position = _T("margin-left:%.2lfmm;margin-top:%.2lfmm;width:%.2lfmm;height:%.2lfmm;");
static CString g_string_shape_geometry = _T(" coordsize=\"%d,%d\" path=\"%s\" fillcolor=\"#%06x\" strokecolor=\"#%06x\" strokeweight=\"%.2lfmm\">");
static CString g_string_tx_rid = _T("<v:imagedata r:id=\"rId%d\" o:title=\"\"/>");
static CString g_string_fill_opacity = _T("<v:fill opacity=\"%.2lf\"/>");
static CString g_string_stroke_opacity = _T("<v:stroke opacity=\"%.2lf\"/>");
static _bstr_t g_bstr_shape3 = L"<w10:wrap anchorx=\"page\" anchory=\"page\"/></v:shape></w:pict></w:r>";
class CVectorGraphics class CVectorGraphics
{ {
public: public:
...@@ -54,7 +36,7 @@ namespace NSDocxRenderer ...@@ -54,7 +36,7 @@ namespace NSDocxRenderer
RELEASEMEM(m_pData); RELEASEMEM(m_pData);
} }
AVSINLINE void AddSize(size_t nSize) inline void AddSize(size_t nSize)
{ {
if (NULL == m_pData) if (NULL == m_pData)
{ {
...@@ -93,7 +75,7 @@ namespace NSDocxRenderer ...@@ -93,7 +75,7 @@ namespace NSDocxRenderer
} }
public: public:
AVSINLINE void MoveTo(const double& x1, const double& y1) inline void MoveTo(const double& x1, const double& y1)
{ {
AddSize(3); AddSize(3);
*m_pDataCur = 0; ++m_pDataCur; *m_pDataCur = 0; ++m_pDataCur;
...@@ -105,7 +87,7 @@ namespace NSDocxRenderer ...@@ -105,7 +87,7 @@ namespace NSDocxRenderer
CheckPoint(x1, y1); CheckPoint(x1, y1);
} }
AVSINLINE void LineTo(const double& x1, const double& y1) inline void LineTo(const double& x1, const double& y1)
{ {
AddSize(3); AddSize(3);
*m_pDataCur = 1; ++m_pDataCur; *m_pDataCur = 1; ++m_pDataCur;
...@@ -117,7 +99,7 @@ namespace NSDocxRenderer ...@@ -117,7 +99,7 @@ namespace NSDocxRenderer
CheckPoint(x1, y1); CheckPoint(x1, y1);
} }
AVSINLINE void CurveTo(const double& x1, const double& y1, const double& x2, const double& y2, const double& x3, const double& y3) inline void CurveTo(const double& x1, const double& y1, const double& x2, const double& y2, const double& x3, const double& y3)
{ {
AddSize(7); AddSize(7);
*m_pDataCur = 2; ++m_pDataCur; *m_pDataCur = 2; ++m_pDataCur;
...@@ -135,7 +117,7 @@ namespace NSDocxRenderer ...@@ -135,7 +117,7 @@ namespace NSDocxRenderer
CheckPoint(x2, y2); CheckPoint(x2, y2);
CheckPoint(x3, y3); CheckPoint(x3, y3);
} }
AVSINLINE void Close() inline void Close()
{ {
AddSize(1); AddSize(1);
*m_pDataCur = 3; ++m_pDataCur; *m_pDataCur = 3; ++m_pDataCur;
...@@ -143,12 +125,12 @@ namespace NSDocxRenderer ...@@ -143,12 +125,12 @@ namespace NSDocxRenderer
m_lSizeCur += 1; m_lSizeCur += 1;
} }
AVSINLINE size_t GetCurSize() inline size_t GetCurSize()
{ {
return m_lSizeCur; return m_lSizeCur;
} }
AVSINLINE void Clear() inline void Clear()
{ {
RELEASEMEM(m_pData); RELEASEMEM(m_pData);
...@@ -158,13 +140,13 @@ namespace NSDocxRenderer ...@@ -158,13 +140,13 @@ namespace NSDocxRenderer
m_pDataCur = m_pData; m_pDataCur = m_pData;
m_lSizeCur = 0; m_lSizeCur = 0;
} }
AVSINLINE void ClearNoAttack() inline void ClearNoAttack()
{ {
m_pDataCur = m_pData; m_pDataCur = m_pData;
m_lSizeCur = 0; m_lSizeCur = 0;
} }
AVSINLINE void End() inline void End()
{ {
ClearNoAttack(); ClearNoAttack();
...@@ -174,7 +156,7 @@ namespace NSDocxRenderer ...@@ -174,7 +156,7 @@ namespace NSDocxRenderer
m_dBottom = -0xFFFFFF; m_dBottom = -0xFFFFFF;
} }
AVSINLINE void CheckPoint(const double& x, const double& y) inline void CheckPoint(const double& x, const double& y)
{ {
if (m_dLeft > x) if (m_dLeft > x)
m_dLeft = x; m_dLeft = x;
...@@ -190,7 +172,7 @@ namespace NSDocxRenderer ...@@ -190,7 +172,7 @@ namespace NSDocxRenderer
class CShape : public CBaseItem class CShape : public CBaseItem
{ {
public: public:
CString m_strPath; std::wstring m_strPath;
NSStructures::CBrush m_oBrush; NSStructures::CBrush m_oBrush;
NSStructures::CPen m_oPen; NSStructures::CPen m_oPen;
...@@ -250,7 +232,7 @@ namespace NSDocxRenderer ...@@ -250,7 +232,7 @@ namespace NSDocxRenderer
return *this; return *this;
} }
void CreateFromVectorData(CVectorGraphics* pVector, NSDocxRenderer::CStringWriter& oWriter, const LONG& lCoordSize, LONG lType) void CreateFromVectorData(CVectorGraphics* pVector, NSStringUtils::CStringBuilder& oWriter, const LONG& lCoordSize, LONG lType)
{ {
m_dLeft = pVector->m_dLeft; m_dLeft = pVector->m_dLeft;
m_dTop = pVector->m_dTop; m_dTop = pVector->m_dTop;
...@@ -272,10 +254,10 @@ namespace NSDocxRenderer ...@@ -272,10 +254,10 @@ namespace NSDocxRenderer
LONG lY = (LONG)((*pData - m_dTop) * lCoordSize / m_dHeight); LONG lY = (LONG)((*pData - m_dTop) * lCoordSize / m_dHeight);
++pData; ++pData;
CString strPath = _T(""); oWriter.AddCharSafe('m');
strPath.Format(g_vml_string_MoveTo, lX, lY); oWriter.AddInt(lX);
oWriter.AddCharSafe(',');
oWriter.WriteString(strPath); oWriter.AddInt(lY);
nCount -= 3; nCount -= 3;
} }
...@@ -286,10 +268,10 @@ namespace NSDocxRenderer ...@@ -286,10 +268,10 @@ namespace NSDocxRenderer
LONG lY = (LONG)((*pData - m_dTop) * lCoordSize / m_dHeight); LONG lY = (LONG)((*pData - m_dTop) * lCoordSize / m_dHeight);
++pData; ++pData;
CString strPath = _T(""); oWriter.AddCharSafe('l');
strPath.Format(g_vml_string_LineTo, lX, lY); oWriter.AddInt(lX);
oWriter.AddCharSafe(',');
oWriter.WriteString(strPath); oWriter.AddInt(lY);
nCount -= 3; nCount -= 3;
} }
...@@ -310,76 +292,104 @@ namespace NSDocxRenderer ...@@ -310,76 +292,104 @@ namespace NSDocxRenderer
LONG lY3 = (LONG)((*pData - m_dTop) * lCoordSize / m_dHeight); LONG lY3 = (LONG)((*pData - m_dTop) * lCoordSize / m_dHeight);
++pData; ++pData;
CString strPath = _T(""); oWriter.AddCharSafe('c');
strPath.Format(g_vml_string_CurveTo, lX1, lY1, lX2, lY2, lX3, lY3); oWriter.AddInt(lX1);
oWriter.AddCharSafe(',');
oWriter.WriteString(strPath); oWriter.AddInt(lY1);
oWriter.AddCharSafe(',');
oWriter.AddInt(lX2);
oWriter.AddCharSafe(',');
oWriter.AddInt(lY2);
oWriter.AddCharSafe(',');
oWriter.AddInt(lX3);
oWriter.AddCharSafe(',');
oWriter.AddInt(lY3);
nCount -= 7; nCount -= 7;
} }
else else
{ {
oWriter.WriteString(g_vml_bstr_ClosePath); oWriter.AddCharSafe('x');
--nCount; --nCount;
} }
} }
if (0x00 == (lType & 0x01)) if (0x00 == (lType & 0x01))
oWriter.WriteString(g_vml_bstr_NoStroke); oWriter.WriteString(L"ns");
if (0x00 == (lType >> 8)) if (0x00 == (lType >> 8))
oWriter.WriteString(g_vml_bstr_NoFill); oWriter.WriteString(L"nf");
oWriter.WriteString(g_vml_bstr_EndPath); oWriter.AddCharSafe('e');
m_strPath = oWriter.GetData(); m_strPath = oWriter.GetData();
oWriter.ClearNoAttack(); oWriter.ClearNoAttack();
} }
virtual void ToXml(NSDocxRenderer::CStringWriter& oWriter) virtual void ToXml(NSStringUtils::CStringBuilder& oWriter)
{ {
oWriter.WriteString(g_bstr_shape1); oWriter.WriteString(L"<w:r><w:pict><v:shape id=\"\" o:spid=\"\" style=\"position:absolute;");
CString strPosition = _T(""); oWriter.WriteString(L"margin-left:");
strPosition.Format(g_string_shape_position, m_dLeft, m_dTop, m_dWidth, m_dHeight); oWriter.AddDouble(m_dLeft, 2);
oWriter.WriteString(strPosition); oWriter.WriteString(L"mm;margin-top:");
oWriter.AddDouble(m_dTop, 2);
oWriter.WriteString(strPosition); oWriter.WriteString(L"mm;width:");
oWriter.WriteString(g_bstr_shape2); oWriter.AddDouble(m_dWidth, 2);
oWriter.WriteString(L"mm;height:");
CString strStyle = _T(""); oWriter.AddDouble(m_dHeight, 2);
strStyle.Format(g_string_shape_geometry, m_lCoordSizeX, m_lCoordSizeY, m_strPath, ConvertColor(m_oBrush.Color1), ConvertColor(m_oPen.Color), m_oPen.Size); oWriter.WriteString(L"mm;");
oWriter.WriteString(strStyle);
oWriter.WriteString(L"z-index:-1;mso-position-horizontal-relative:page;mso-position-vertical-relative:page;\"");
if (c_BrushTypeTexture == m_oBrush.Type)
oWriter.WriteString(L" coordsize=\"");
oWriter.AddInt((int)m_lCoordSizeX);
oWriter.AddCharSafe(',');
oWriter.AddInt((int)m_lCoordSizeY);
oWriter.WriteString(L"\" path=\"");
oWriter.WriteString(m_strPath);
oWriter.WriteString(L"\" fillcolor=\"");
oWriter.WriteHexInt3((int)ConvertColor(m_oBrush.Color1));
oWriter.WriteString(L"\" strokecolor=\"");
oWriter.WriteHexInt3((int)ConvertColor(m_oPen.Color));
oWriter.WriteString(L"\" strokeweight=\"");
oWriter.AddDouble(m_oPen.Size, 2);
oWriter.WriteString(L"mm\">");
static CString g_string_fill_opacity = _T("<v:fill opacity=\"%.2lf\"/>");
static CString g_string_stroke_opacity = _T("<v:stroke opacity=\"%.2lf\"/>");
if (c_BrushTypeTexture == m_oBrush.Type)
{ {
CString strImage = _T(""); oWriter.WriteString(L"<v:imagedata r:id=\"rId");
strImage.Format(g_string_tx_rid, 10 + m_lTxId); oWriter.AddInt(10 + m_lTxId);
oWriter.WriteString(strImage); oWriter.WriteString(L"\" o:title=\"\"/>");
if (0xFF != m_oBrush.TextureAlpha) if (0xFF != m_oBrush.TextureAlpha)
{ {
CString strFillOpacity = _T(""); oWriter.WriteString(L"<v:fill opacity=\"");
strFillOpacity.Format(g_string_fill_opacity, (double)m_oBrush.TextureAlpha / 255.0); oWriter.AddDouble((double)m_oBrush.TextureAlpha / 255.0, 2);
oWriter.WriteString(strFillOpacity); oWriter.WriteString(L"\"/>");
} }
} }
else else
{ {
if (0xFF != m_oBrush.Alpha1) if (0xFF != m_oBrush.Alpha1)
{ {
CString strFillOpacity = _T(""); oWriter.WriteString(L"<v:fill opacity=\"");
strFillOpacity.Format(g_string_fill_opacity, (double)m_oBrush.Alpha1 / 255.0); oWriter.AddDouble((double)m_oBrush.Alpha1 / 255.0, 2);
oWriter.WriteString(strFillOpacity); oWriter.WriteString(L"\"/>");
} }
if (0xFF != m_oPen.Alpha) if (0xFF != m_oPen.Alpha)
{ {
CString strPenOpacity = _T(""); oWriter.WriteString(L"<v:stroke opacity=\"");
strPenOpacity.Format(g_string_stroke_opacity, (double)m_oPen.Alpha / 255.0); oWriter.AddDouble((double)m_oPen.Alpha / 255.0, 2);
oWriter.WriteString(strPenOpacity); oWriter.WriteString(L"\"/>");
} }
} }
oWriter.WriteString(g_bstr_shape3); oWriter.WriteString(L"<w10:wrap anchorx=\"page\" anchory=\"page\"/></v:shape></w:pict></w:r>");
} }
}; };
} }
\ No newline at end of file
#endif // DOCX_RENDERER_ELEMENT_SHAPE_H
#pragma once #ifndef DOCX_RENDERER_FMB_H
#define DOCX_RENDERER_FMB_H
#include "..\stdafx.h" #include "Common.h"
#include "StringWriter.h" #include "../DesktopEditor/fontengine/ApplicationFonts.h"
#include "..\Graphics\Structures.h"
#include "..\Graphics\Matrix.h"
namespace NSFontManager namespace NSFontManager
{ {
...@@ -28,10 +27,10 @@ namespace NSFontManager ...@@ -28,10 +27,10 @@ namespace NSFontManager
double m_dSpaceWidthMM; double m_dSpaceWidthMM;
// font params // font params
CString m_strFamilyName; std::wstring m_strFamilyName;
CString m_strPANOSE; std::wstring m_strPANOSE;
LONG m_lStyle; LONG m_lStyle;
CAtlArray<DWORD> m_arSignature; CArray<DWORD> m_arSignature;
bool m_bIsFixedWidth; bool m_bIsFixedWidth;
LONG m_lAvgWidth; LONG m_lAvgWidth;
...@@ -49,8 +48,8 @@ namespace NSFontManager ...@@ -49,8 +48,8 @@ namespace NSFontManager
m_dSpaceWidthMM = 0; m_dSpaceWidthMM = 0;
m_strFamilyName = _T(""); m_strFamilyName = L"";
m_strPANOSE = _T(""); m_strPANOSE = L"";
m_lStyle = 0; m_lStyle = 0;
m_arSignature.RemoveAll(); m_arSignature.RemoveAll();
m_bIsFixedWidth = false; m_bIsFixedWidth = false;
...@@ -78,7 +77,7 @@ namespace NSFontManager ...@@ -78,7 +77,7 @@ namespace NSFontManager
m_strFamilyName = oSrc.m_strFamilyName; m_strFamilyName = oSrc.m_strFamilyName;
m_strPANOSE = oSrc.m_strPANOSE; m_strPANOSE = oSrc.m_strPANOSE;
m_lStyle = oSrc.m_lStyle; m_lStyle = oSrc.m_lStyle;
m_arSignature.Copy(oSrc.m_arSignature); m_arSignature = m_arSignature;
m_bIsFixedWidth = oSrc.m_bIsFixedWidth; m_bIsFixedWidth = oSrc.m_bIsFixedWidth;
m_lAvgWidth = oSrc.m_lAvgWidth; m_lAvgWidth = oSrc.m_lAvgWidth;
...@@ -92,7 +91,7 @@ namespace NSFontManager ...@@ -92,7 +91,7 @@ namespace NSFontManager
CFontAdvanced m_oFont; CFontAdvanced m_oFont;
BYTE m_lRangeNum; BYTE m_lRangeNum;
BYTE m_lRange; BYTE m_lRange;
CString m_strPickFont; std::wstring m_strPickFont;
LONG m_lPickStyle; LONG m_lPickStyle;
public: public:
...@@ -100,7 +99,7 @@ namespace NSFontManager ...@@ -100,7 +99,7 @@ namespace NSFontManager
{ {
m_lRangeNum = 0xFF; m_lRangeNum = 0xFF;
m_lRange = 0xFF; m_lRange = 0xFF;
m_strPickFont = _T(""); m_strPickFont = L"";
m_lPickStyle = 0; m_lPickStyle = 0;
} }
CFontPickUp(const CFontPickUp& oSrc) CFontPickUp(const CFontPickUp& oSrc)
...@@ -129,9 +128,9 @@ namespace NSFontManager ...@@ -129,9 +128,9 @@ namespace NSFontManager
}; };
protected: protected:
AVSGraphics::IASCWinFonts* m_pWinFonts; CApplicationFonts* m_pFonts;
AVSGraphics::IASCFontManager* m_pManager; CFontManager* m_pManager;
CString m_strDefaultFont; std::wstring m_strDefaultFont;
public: public:
...@@ -141,8 +140,8 @@ namespace NSFontManager ...@@ -141,8 +140,8 @@ namespace NSFontManager
BYTE m_pRanges[0xFFFF]; BYTE m_pRanges[0xFFFF];
BYTE m_pRangesNums[0xFFFF]; BYTE m_pRangesNums[0xFFFF];
CAtlList<CFontPickUp> m_arListPicUps; std::list<CFontPickUp> m_arListPicUps;
CString m_strCurrentPickFont; std::wstring m_strCurrentPickFont;
LONG m_lCurrentPictFontStyle; LONG m_lCurrentPictFontStyle;
public: public:
...@@ -303,7 +302,7 @@ namespace NSFontManager ...@@ -303,7 +302,7 @@ namespace NSFontManager
void LoadFontMetrics() void LoadFontMetrics()
{ {
unsigned short iTemp = 0; unsigned short iTemp = 0;
m_pManager->GetCellAscent(&iTemp); m_pManager->GetCellAscent(&iTemp);
m_oFont.m_dAscent = iTemp; m_oFont.m_dAscent = iTemp;
m_pManager->GetCellDescent(&iTemp); m_pManager->GetCellDescent(&iTemp);
m_oFont.m_dDescent = iTemp; m_oFont.m_dDescent = iTemp;
...@@ -1236,7 +1235,7 @@ namespace NSFontManager ...@@ -1236,7 +1235,7 @@ namespace NSFontManager
//case 31: sUCRName = "Reserved for process-internal usage"; break; //case 31: sUCRName = "Reserved for process-internal usage"; break;
} }
__forceinline bool GetRange(const WCHAR& symbol, BYTE& lRangeNum, BYTE& lRange) inline bool GetRange(const WCHAR& symbol, BYTE& lRangeNum, BYTE& lRange)
{ {
lRangeNum = m_pRangesNums[symbol]; lRangeNum = m_pRangesNums[symbol];
lRange = m_pRanges[symbol]; lRange = m_pRanges[symbol];
...@@ -1244,10 +1243,10 @@ namespace NSFontManager ...@@ -1244,10 +1243,10 @@ namespace NSFontManager
return (0xFF != lRangeNum); return (0xFF != lRangeNum);
} }
__forceinline void CheckRanges(DWORD& lRange1, DWORD& lRange2, DWORD& lRange3, DWORD& lRange4, CString strText) inline void CheckRanges(DWORD& lRange1, DWORD& lRange2, DWORD& lRange3, DWORD& lRange4, const std::wstring& strText)
{ {
int lCount = strText.GetLength(); int lCount = (int)strText.length();
WCHAR* pData = strText.GetBuffer(); WCHAR* pData = strText.c_str();
BYTE lRangeNum = 0xFF; BYTE lRangeNum = 0xFF;
BYTE lRange = 0xFF; BYTE lRange = 0xFF;
...@@ -1266,7 +1265,7 @@ namespace NSFontManager ...@@ -1266,7 +1265,7 @@ namespace NSFontManager
} }
} }
} }
__forceinline void CheckRanges(DWORD& lRange1, DWORD& lRange2, DWORD& lRange3, DWORD& lRange4, BYTE& lRangeNum, BYTE& lRange) inline void CheckRanges(DWORD& lRange1, DWORD& lRange2, DWORD& lRange3, DWORD& lRange4, BYTE& lRangeNum, BYTE& lRange)
{ {
if (0 == lRangeNum) if (0 == lRangeNum)
lRange1 |= 1 << lRange; lRange1 |= 1 << lRange;
...@@ -1371,4 +1370,6 @@ namespace NSFontManager ...@@ -1371,4 +1370,6 @@ namespace NSFontManager
return true; return true;
} }
}; };
}; };
\ No newline at end of file
#endif // DOCX_RENDERER_FMB_H
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